further work fixing groups

This commit is contained in:
Sky Johnson 2025-08-22 23:17:25 -05:00
parent c783176588
commit 81bae77beb
5 changed files with 56 additions and 5 deletions

3
.gitignore vendored
View File

@ -22,3 +22,6 @@ go.work
/world_config.json
/world_server
/world.db
/login_config.json
/login_server
/login.db

View File

@ -549,6 +549,22 @@ func (g *Group) GetGroupMemberByPosition(seeker Entity, mappedPosition int32) En
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
func (g *Group) GetGroupOptions() GroupOptions {
g.optionsMutex.RLock()

View File

@ -515,3 +515,14 @@ func (m *Manager) fireGroupInviteDeclinedEvent(leader, member Entity) {
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)
}
}

View File

@ -141,12 +141,33 @@ func (ml *MasterList) refreshMetaCache() {
// updateGroupIndices updates all indices for a group
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()
size := group.GetSize()
leaderName := group.GetLeaderName()
isRaid := group.IsGroupRaid()
isDisbanded := group.IsDisbanded()
members := group.GetMembers()
// Create a snapshot of group data to avoid repeated method calls
groupData := struct {
id int32
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 {
// Add to size index

Binary file not shown.