Files
Erupe/server/channelserver/minidata_store.go
Houmgaor c04fa504cc 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.
2026-02-21 13:39:44 +01:00

30 lines
695 B
Go

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()
}