further work fixing groups
This commit is contained in:
parent
c783176588
commit
81bae77beb
3
.gitignore
vendored
3
.gitignore
vendored
@ -22,3 +22,6 @@ go.work
|
|||||||
/world_config.json
|
/world_config.json
|
||||||
/world_server
|
/world_server
|
||||||
/world.db
|
/world.db
|
||||||
|
/login_config.json
|
||||||
|
/login_server
|
||||||
|
/login.db
|
@ -549,6 +549,22 @@ func (g *Group) GetGroupMemberByPosition(seeker Entity, mappedPosition int32) En
|
|||||||
return g.Members[mappedPosition].Member
|
return g.Members[mappedPosition].Member
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RemoveClientReference removes client references when a client disconnects
|
||||||
|
// This is used for cleanup when a player disconnects but stays in the group
|
||||||
|
func (g *Group) RemoveClientReference(client any) {
|
||||||
|
g.membersMutex.Lock()
|
||||||
|
defer g.membersMutex.Unlock()
|
||||||
|
|
||||||
|
for _, gmi := range g.Members {
|
||||||
|
if gmi.Client != nil && gmi.Client == client {
|
||||||
|
gmi.Client = nil
|
||||||
|
// Don't set Member to nil as the entity might still exist
|
||||||
|
// Only clear the client reference
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// GetGroupOptions returns a copy of the group options
|
// GetGroupOptions returns a copy of the group options
|
||||||
func (g *Group) GetGroupOptions() GroupOptions {
|
func (g *Group) GetGroupOptions() GroupOptions {
|
||||||
g.optionsMutex.RLock()
|
g.optionsMutex.RLock()
|
||||||
|
@ -515,3 +515,14 @@ func (m *Manager) fireGroupInviteDeclinedEvent(leader, member Entity) {
|
|||||||
go handler.OnGroupInviteDeclined(leader, member)
|
go handler.OnGroupInviteDeclined(leader, member)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RemoveClientReference removes client references from all groups when a client disconnects
|
||||||
|
func (m *Manager) RemoveClientReference(client any) {
|
||||||
|
// Get all groups from the master list
|
||||||
|
groups := m.MasterList.GetAllGroups()
|
||||||
|
|
||||||
|
// Remove client reference from all groups
|
||||||
|
for _, group := range groups {
|
||||||
|
group.RemoveClientReference(client)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -141,12 +141,33 @@ func (ml *MasterList) refreshMetaCache() {
|
|||||||
|
|
||||||
// updateGroupIndices updates all indices for a group
|
// updateGroupIndices updates all indices for a group
|
||||||
func (ml *MasterList) updateGroupIndices(group *Group, add bool) {
|
func (ml *MasterList) updateGroupIndices(group *Group, add bool) {
|
||||||
|
// Get all group data in one go to minimize lock contention
|
||||||
|
// This avoids holding the master list lock while calling multiple group methods
|
||||||
groupID := group.GetID()
|
groupID := group.GetID()
|
||||||
size := group.GetSize()
|
|
||||||
leaderName := group.GetLeaderName()
|
// Create a snapshot of group data to avoid repeated method calls
|
||||||
isRaid := group.IsGroupRaid()
|
groupData := struct {
|
||||||
isDisbanded := group.IsDisbanded()
|
id int32
|
||||||
members := group.GetMembers()
|
size int32
|
||||||
|
leaderName string
|
||||||
|
isRaid bool
|
||||||
|
isDisbanded bool
|
||||||
|
members []*GroupMemberInfo
|
||||||
|
}{
|
||||||
|
id: groupID,
|
||||||
|
size: group.GetSize(),
|
||||||
|
leaderName: group.GetLeaderName(),
|
||||||
|
isRaid: group.IsGroupRaid(),
|
||||||
|
isDisbanded: group.IsDisbanded(),
|
||||||
|
members: group.GetMembers(),
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use the snapshot data for indexing
|
||||||
|
size := groupData.size
|
||||||
|
leaderName := groupData.leaderName
|
||||||
|
isRaid := groupData.isRaid
|
||||||
|
isDisbanded := groupData.isDisbanded
|
||||||
|
members := groupData.members
|
||||||
|
|
||||||
if add {
|
if add {
|
||||||
// Add to size index
|
// Add to size index
|
||||||
|
BIN
login_server
BIN
login_server
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user