加入网络层

This commit is contained in:
2025-06-26 23:57:54 +08:00
parent 53106465ed
commit 0f29dccec4
57 changed files with 1859 additions and 1274 deletions

View File

@@ -0,0 +1,42 @@
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(cid int32, client *Client) {
m.Lock()
defer m.Unlock()
m.userMap[cid] = client
}
func (m *userManager) Delete(cid int32) {
m.Lock()
defer m.Unlock()
delete(m.userMap, cid)
}
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]
}