refactor(channelserver): extract UserBinaryStore and MinidataStore

The userBinary and minidata maps with their locks were spread across
Server as raw fields with manual lock management. Cross-channel session
searches also required acquiring nested locks (server lock + binary
lock). Encapsulating in dedicated types eliminates the nested locking
and reduces Server's field count by 4.
This commit is contained in:
Houmgaor
2026-02-21 13:39:44 +01:00
parent 2757a5432f
commit c04fa504cc
15 changed files with 111 additions and 68 deletions

View File

@@ -0,0 +1,29 @@
package channelserver
import "sync"
// MinidataStore is a thread-safe store for per-character enhanced minidata.
type MinidataStore struct {
mu sync.RWMutex
data map[uint32][]byte
}
// NewMinidataStore creates an empty MinidataStore.
func NewMinidataStore() *MinidataStore {
return &MinidataStore{data: make(map[uint32][]byte)}
}
// Get returns the minidata for the given character ID.
func (s *MinidataStore) Get(charID uint32) ([]byte, bool) {
s.mu.RLock()
data, ok := s.data[charID]
s.mu.RUnlock()
return data, ok
}
// Set stores minidata for the given character ID.
func (s *MinidataStore) Set(charID uint32, data []byte) {
s.mu.Lock()
s.data[charID] = data
s.mu.Unlock()
}