Files
bl/common/cool/rpc.go

26 lines
698 B
Go
Raw Normal View History

package cool
// 存值示例
func AddClient(id uint16, client *ClientHandler) {
// 普通mapClientmap[id] = client
Clientmap.Store(id, client) // sync.Map存值
}
// 取值示例
func GetClient(id uint16) (*ClientHandler, bool) {
// 普通mapclient, ok := Clientmap[id]
val, ok := Clientmap.Load(id) // sync.Map取值
if !ok {
return nil, false
}
// 类型断言确保value是*ClientHandler
client, ok := val.(*ClientHandler)
return client, ok
}
type ClientHandler struct {
KickPerson func(uint32) error //踢人,这里是返回具体的logic
QuitSelf func(int) error //关闭服务器进程
Broadcast func(string) int //全服广播,返回的是在线人数
}