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

@@ -29,12 +29,6 @@ type Config struct {
Enable bool
}
// Map key type for a user binary part.
type userBinaryPartID struct {
charID uint32
index uint8
}
// Server is a MHF channel server.
type Server struct {
sync.Mutex
@@ -81,13 +75,8 @@ type Server struct {
// Used to map different languages
i18n i18n
// UserBinary
userBinaryPartsLock sync.RWMutex
userBinaryParts map[userBinaryPartID][]byte
// EnhancedMinidata
minidataLock sync.RWMutex
minidataParts map[uint32][]byte
userBinary *UserBinaryStore
minidata *MinidataStore
// Semaphore
semaphoreLock sync.RWMutex
@@ -118,8 +107,8 @@ func NewServer(config *Config) *Server {
done: make(chan struct{}),
sessions: make(map[net.Conn]*Session),
stages: make(map[string]*Stage),
userBinaryParts: make(map[userBinaryPartID][]byte),
minidataParts: make(map[uint32][]byte),
userBinary: NewUserBinaryStore(),
minidata: NewMinidataStore(),
semaphore: make(map[string]*Semaphore),
semaphoreIndex: 7,
discordBot: config.DiscordBot,