This repository has been archived on 2026-01-07. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
Game/Server/gateway/handler/ws_handler/manager.go

43 lines
634 B
Go

package ws_handler
import (
"sync"
)
var UserMgr *userManager
type userManager struct {
userMap map[int32]*Client
sync.RWMutex
}
func init() {
UserMgr = &userManager{
userMap: make(map[int32]*Client),
}
}
func (m *userManager) Add(uid int32, client *Client) {
m.Lock()
defer m.Unlock()
m.userMap[uid] = client
}
func (m *userManager) Delete(uid int32) {
m.Lock()
defer m.Unlock()
delete(m.userMap, uid)
}
func (m *userManager) GetAll() map[int32]*Client {
m.RLock()
defer m.RUnlock()
return m.userMap
}
func (m *userManager) GetByUID(uid int32) *Client {
m.RLock()
defer m.RUnlock()
return m.userMap[uid]
}