Ejemplo n.º 1
0
Archivo: Room.go Proyecto: 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
}
Ejemplo n.º 2
0
Archivo: Room.go Proyecto: cokeboL/ZIM
func handleClientRoomChat(client *NetCore.Client, msg *NetCore.NetMsg) bool {
	if room, ok := idRoomMap[client.Id]; ok {
		msg.Cmd = MsgConf.ClientRoomChatBroad
		for id, v := range room.Guests {
			v.SendMsg(msg)
			Logger.Info(LogConf.WorkerClientJob, client.Idx, "handleClientRoomChat send to client: %d", id)
		}
		return true
	}

	Logger.Info(LogConf.WorkerClientJob, client.Idx, "handleClientRoomChat err: not in room id: %d", client.Id)

	return true
}
Ejemplo n.º 3
0
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
}