mirror of
https://github.com/Mezeporta/Erupe.git
synced 2026-03-22 07:32:32 +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,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,
|
||||
|
||||
Reference in New Issue
Block a user