mirror of
https://github.com/Mezeporta/Erupe.git
synced 2026-03-22 23:54:33 +01:00
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.
30 lines
695 B
Go
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()
|
|
}
|