本文整理匯總了Golang中NetCore.Client.AddCloseCB方法的典型用法代碼示例。如果您正苦於以下問題:Golang Client.AddCloseCB方法的具體用法?Golang Client.AddCloseCB怎麽用?Golang Client.AddCloseCB使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類NetCore.Client
的用法示例。
在下文中一共展示了Client.AddCloseCB方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: handleRegist
func handleRegist(client *NetCore.Client, msg *NetCore.NetMsg) {
stype := binary.LittleEndian.Uint32(msg.Buf)
NetCore.MarkServer(client, stype)
addServerToMap(client)
client.AddCloseCB("removeServer", removeServerFromMap)
Logger.Info(LogConf.CourierServerJob, LogConf.SERVER, "Server Regist client idx: %d buf len: %d %d", client.GetIdx(), len(msg.Buf), stype)
binary.LittleEndian.PutUint32(msg.Buf[0:4], NetConf.Courier)
client.SendMsg(msg)
}
示例2: handleClientEnterRoom
//.........這裏部分代碼省略.........
Logger.Info(LogConf.WorkerClientJob, client.Idx, "handleClientEnterRoom client Idx: %d id: %d RoomId: %d", client.Idx, client.Id, req.RoomId)
} else {
Logger.Info(LogConf.WorkerClientJob, client.Idx, "handleClientEnterRoom xxxx")
}
}
if err := json.Unmarshal([]byte(msg.Buf), &req); err != nil {
rsp.Ret = ErrConf.INVALID_JSON
enterRoomRsp()
return false
}
if room, ok = rooms[req.RoomId]; ok {
if _, ok2 := room.Guests[client.Id]; ok2 {
rsp.Ret = ErrConf.ID_HAS_BEEN_IN_ROOM
enterRoomRsp()
Logger.Info(LogConf.WorkerClientJob, client.Idx, "handleClientEnterRoom 111")
return true
}
if req.Passwd != room.Passwd {
rsp.Ret = ErrConf.ERROR_PASSWD_FOR_ROOM
enterRoomRsp()
Logger.Info(LogConf.WorkerClientJob, client.Idx, "handleClientEnterRoom 111")
return true
}
Logger.Info(LogConf.WorkerClientJob, client.Idx, "handleClientEnterRoom 222")
notify := &EnterRoomNotify{
Id: NetCore.ClientIDType(client.Id),
}
notifyMsg := &NetCore.NetMsg{
Cmd: MsgConf.ClientEnterRoomNotify,
}
if buf, err := json.Marshal(notify); err == nil {
notifyMsg.Buf = buf
} else {
Logger.Info(LogConf.WorkerClientJob, client.Idx, "handleClientEnterRoom 333")
return false
}
for _, v := range room.Guests {
v.SendMsg(notifyMsg)
}
enterRoomRsp()
Logger.Info(LogConf.WorkerClientJob, client.Idx, "handleClientEnterRoom 444")
room.Guests[client.Id] = client
idRoomMap[client.Id] = room
} else {
room = &Room{
Id: req.RoomId,
Passwd: req.Passwd,
Guests: make(map[NetCore.ClientIDType]*NetCore.Client),
}
enterRoomRsp()
room.Guests[client.Id] = client
idRoomMap[client.Id] = room
rooms[req.RoomId] = room
Logger.Info(LogConf.WorkerClientJob, client.Idx, "handleClientEnterRoom 555")
}
client.AddCloseCB("leaveRoom", func(c *NetCore.Client) {
//Logger.Info(LogConf.WorkerClientJob, client.Idx, "handleClientEnterRoom 666")
var tmproom *Room
if tmproom, ok = idRoomMap[c.Id]; ok {
delete(tmproom.Guests, c.Id)
leaveMsg := &NetCore.NetMsg{
Cmd: MsgConf.ClientLeaveRoomNotify,
}
notify := &LeaveRoomNotify{
Id: NetCore.ClientIDType(c.Id),
}
if buf, err := json.Marshal(notify); err == nil {
leaveMsg.Buf = buf
} else {
return
}
if len(tmproom.Guests) > 0 {
for _, v := range tmproom.Guests {
v.SendMsg(leaveMsg)
}
} else {
delete(rooms, tmproom.Id)
}
Logger.Info(LogConf.WorkerClientJob, client.Idx, "client leave room %d", client.Id)
}
})
return true
}