mirror of
https://github.com/Mezeporta/Erupe.git
synced 2026-03-26 17:43:21 +01:00
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:
29
server/channelserver/minidata_store.go
Normal file
29
server/channelserver/minidata_store.go
Normal 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()
|
||||
}
|
||||
Reference in New Issue
Block a user