示例#1
0
文件: Room.go 项目: cokeboL/ZIM
func handleClientLeaveRoom(client *NetCore.Client, msg *NetCore.NetMsg) bool {
	client.RemoveCloseCB("leaveRoom")

	msg.Buf = ErrConf.GetEmptyRspBuffer(ErrConf.NO_ERR)
	client.SendMsg(msg)

	if room, ok := idRoomMap[client.Id]; ok {
		Logger.Info(LogConf.WorkerClientJob, client.Idx, "client leave room id: %d RoomId: %d", client.Id, room.Id)

		notify := &LeaveRoomNotify{
			Id: NetCore.ClientIDType(client.Id),
		}
		msg.Cmd = MsgConf.ClientLeaveRoomNotify
		if buf, err := json.Marshal(notify); err == nil {
			msg.Buf = buf
		} else {
			return false
		}

		delete(room.Guests, client.Id)

		if len(room.Guests) > 0 {
			for _, v := range room.Guests {
				v.SendMsg(msg)
			}
		} else {
			delete(rooms, room.Id)
		}
	}

	Logger.Info(LogConf.WorkerClientJob, client.Idx, "handleClientLeaveRoom client Idx: %d id: %d", client.Idx, client.Id)

	return true
}
示例#2
0
文件: Regist.go 项目: cokeboL/ZIM
func handleClientRegist(client *NetCore.Client, msg *NetCore.NetMsg) bool {
	var (
		req ClientRegistReq
	)

	if err := json.Unmarshal([]byte(msg.Buf), &req); err != nil {
		return false
	}

	id := req.Id

	client.CancelWaitRegist()

	msg.Buf = ErrConf.GetEmptyRspBuffer(ErrConf.NO_ERR)
	client.SendMsg(msg)

	NetCore.AddClientToManager(client, NetCore.ClientIDType(id))

	Logger.Info(LogConf.WorkerClientJob, client.Idx, "handleClientRegist client Idx: %d id: %d", client.Idx, id)

	return true
}