Exemple #1
0
 /// <summary>
 /// 离开
 /// </summary>
 /// <param name="client"></param>
 private void leave(ClientPeer client)
 {
     SingleExecute.Instance.Execute(
         delegate()
     {
         int userId = userCache.GetId(client);
         //用户没有匹配 不能退出 非法操作
         if (matchCache.IsMatching(userId) == false)
         {
             //  client.Send(OpCode.MATCH, MatchCode.LEAVE_SRES, -1);
             return;
         }
         MatchRoom room = matchCache.GetRoom(userId);
         if (room.UIdClientDict.Keys.Count > 1)
         {
             //正常离开
             room = matchCache.Leave(userId);
             //广播给房间所有人 有人离开了 参数:离开的用户id
             room.Brocast(OpCode.MATCH, MatchCode.LEAVE_BRO, userId);
         }
         else
         {
             matchCache.Destroy(room);
             client.Send(OpCode.MATCH, MatchCode.BACK_BRO, null);
             return;
         }
         Console.WriteLine("有玩家退出匹配房间");
     });
 }
 /// <summary>
 /// 用户进入了房间  获取房间信息  发送给客户端
 /// </summary>
 /// <param name="client"></param>
 private void EnterRoom(ClientPeer client)
 {
     SingleExecute.Instance.Execute(() => {
         MatchRoom room = match.GetRoom(user.GetId(client));
         var roomDto    = MakeRoomDto(room);
         client.StartSend(OpCode.MATCHROOM, MatchRoomCode.ENTERROOM_SRES, roomDto);
         Console.WriteLine(string.Format("玩家 : {0}  进入房间 :{1}", user.GetModelByClient(client).name, room.id));
     });
 }
 public void Chat(ClientPeer client, int type)
 {
     SingleExecute.Instance.Execute(() => {
         if (!user.IsOnLine(client))
         {
             return;
         }
         int userId = user.GetId(client);
         //匹配场景
         if (match.IsMatching(userId))
         {
             MatchRoom mr = match.GetRoom(userId);
             ChatDto dto  = new ChatDto(userId, type);
             mr.Brocast(OpCode.CHAT, ChatCode.CHAT_SRES, dto);
         }
         else if (fight.IsFighting(userId))
         {
             //战斗场景
             FightRoom mr = fight.GetRoom(userId);
             ChatDto dto  = new ChatDto(userId, type);
             //fight.(OpCode.CHAT, ChatCode.CHAT_SRES, dto);
             Brocast(mr, OpCode.CHAT, ChatCode.CHAT_SRES, dto);
         }
     });
 }
Exemple #4
0
        /// <summary>
        /// 准备
        /// </summary>
        /// <param name="client"></param>
        private void ready(ClientPeer client)
        {
            SingleExecute.Instance.Execute(
                () =>
            {
                if (userCache.IsOnline(client) == false)
                {
                    return;
                }
                int userId = userCache.GetId(client);
                if (matchCache.IsMatching(userId) == false)
                {
                    return;
                }
                //一定要注意安全的验证
                MatchRoom room = matchCache.GetRoom(userId);
                room.Ready(userId);
                //之前忘记了 &&&……%……&¥&¥&%#%#&¥&……%&
                room.Brocast(OpCode.MATCH, MatchCode.READY_BRO, userId);

                //检测:是否所有玩家都准备了
                if (room.IsAllReady())
                {
                    //开始战斗
                    startFight(room.GetUIdList());
                    //通知房间内的玩家  要进行战斗了 给客户端群发消息
                    room.Brocast(OpCode.MATCH, MatchCode.START_BRO, null);
                    //销毁房间
                    matchCache.Destroy(room);
                }
            }
                );
        }
Exemple #5
0
 /// <summary>
 /// 准备
 /// </summary>
 /// <param name="client"></param>
 private void Ready(ClientPeer client)
 {
     SingleExecute.Instance.Execute(() =>
     {
         //安全校验
         if (!userCache.IsOnLine(client))
         {
             return;
         }
         int userId = userCache.GetIdByClient(client);
         if (matchCache.IsMatching(userId) == false)
         {
             return;
         }
         //玩家准备list添加
         MatchRoom room = matchCache.GetRoom(userId);
         room.Ready(userId);
         room.Brocast(OpCode.MATCH, MatchCode.READY_BRO, userId);
         //每准备一个 判断一下是否全部准备
         if (room.IsReady())
         {
             //开始进入战斗
             //客户端群发进入战斗
             startFight(room.GetIdList());
             room.Brocast(OpCode.MATCH, MatchCode.START_BRO, null);
             //销毁准备房间
             matchCache.Destroy(room);
         }
     });
 }
Exemple #6
0
        /// <summary>
        /// 发送消息
        /// </summary>
        /// <param name="client"></param>
        /// <param name="socketMsg"></param>
        private void ChatRequest(ClientPeer client, SocketMsg socketMsg)
        {
            if (!userCache.IsOnline(client))
            {
                return;
            }
            int     userId  = userCache.GetClientUserId(client);
            ChatDto chatDto = new ChatDto
            {
                UserId = userId,
                Type   = (int)socketMsg.value
            };

            //向当前匹配房间所有玩家广播消息
            if (matchCache.IsMatching(userId))
            {
                MatchRoom room = matchCache.GetRoom(userId);
                socketMsg.OpCode  = MsgType.Chat;
                socketMsg.SubCode = ChatCode.Result;
                socketMsg.value   = chatDto;
                room.Brocast(socketMsg);
            }
            else if (true)
            {
            }
        }
Exemple #7
0
        /// <summary>
        /// 准备
        /// </summary>
        /// <param name="client"></param>
        private void ready(ClientPeer client)
        {
            SingleExecute.Instance.Execute(() =>
            {
                if (userCache.IsOnline(client) == false)
                {
                    return;
                }
                int userId = userCache.GetId(client);
                if (matchCache.IsMatching(userId) == false)
                {
                    return;
                }
                MatchRoom room = matchCache.GetRoom(userId);
                room.Ready(userId);
                room.Brocast(OpCode.MATCH, MatchCode.READY_BRO, userId);

                //检测: 是否所有玩家都准备了
                if (room.IsAllReady())
                {
                    //开始战斗
                    //TODO
                    //通知房间内玩家 要进行战斗了 给客户端群发消息
                    room.Brocast(OpCode.MATCH, MatchCode.START_BRO, null);
                    //销毁房间
                    matchCache.Destroy(room);
                }
            });
        }
        private void ChatRequest(ClientPeer client, int chatType)
        {
            //接收到的是类型
            //返回什么  ?  所以创建一个数据传输模型DTO

            //谁发的?
            //需要一个userId  所以获取userCache
            if (userCache.IsOnLine(client) == false)
            {
                return;
            }
            int     userId  = userCache.GetIdByClient(client);
            ChatDto chatDto = new ChatDto(userId, chatType);

            //发给谁?
            //通过matchCache 获取房间  通过房间告诉其他玩家(挨个告诉  全体广播)
            if (matchCache.IsMatching(userId))
            {
                MatchRoom mRoom = matchCache.GetRoom(userId);
                mRoom.Brocast(OpCode.CHAT, ChatCode.SRES, chatDto);
            }
            else if (false)
            {
                //在战斗房间内
                //TODO
            }
        }
Exemple #9
0
        /// <summary>
        /// player ready
        /// </summary>
        /// <param name="client"></param>
        private void ready(ClientPeer client)
        {
            SingleExecute.Instance.Execute(() =>
            {
                if (userCache.IsOnline(client) == false)
                {
                    return;
                }
                int userId = userCache.GetId(client);
                if (matchCache.IsMatching(userId) == false)
                {
                    return;
                }

                MatchRoom room = matchCache.GetRoom(userId);
                room.Ready(userId);
                room.Broadcast(OpCode.MATCH, MatchCode.READY_BROADCAST, userId);

                //check:all player is ready
                if (room.IsAllReady())
                {
                    //start play card,deal cards
                    startFight(room.GetUIdList);
                    //send all player start play cards
                    room.Broadcast(OpCode.MATCH, MatchCode.START_BROADCAST, null);
                    //destroy room
                    matchCache.Destroy(room);
                }
            });
        }
Exemple #10
0
        private void chatRequest(ClientPeer client, int chatType)
        {
            //接收到的是 聊天类型
            //返回的是什么?
            if (userCache.IsOnline(client) == false)
            {
                return;
            }
            int userId = userCache.GetId(client);
            //谁? 发送者的id  userID
            //发了什么?  聊天的类型  chatType
            ChatDto dto = new ChatDto(userId, chatType);

            //给谁?  房间内的每一个玩家
            if (matchCache.IsMatching(userId))
            {
                MatchRoom mRoom = matchCache.GetRoom(userId);
                mRoom.Brocast(OpCode.CHAT, ChatCode.SRES, dto);
            }
            else if (false)
            {
                //在这里检测战斗房间
                //TODO
            }
        }
Exemple #11
0
        private void chatRequest(ClientPeer client, int chatType)
        {
            if (userCache.IsOnline(client) == false)
            {
                return;
            }
            int     userId  = userCache.GetId(client);
            ChatDto chatDto = new ChatDto(userId, chatType);

            if (matchCache.IsMatching(userId))
            {
                MatchRoom mRoom = matchCache.GetRoom(userId);
                mRoom.Brocast(OpCode.CHAT, ChatCode.SERS, chatDto);
                Console.WriteLine("快捷喊话:" + chatDto.ChatType);
            }
            else if (fightCache.IsFighting(userId))
            {
                FightRoom fightRoom = fightCache.GetRoomByUId(userId);
                fightRoom.Brocast(OpCode.CHAT, ChatCode.SERS, chatDto);
                Console.WriteLine("快捷喊话:" + chatDto.ChatType);
            }
        }
Exemple #12
0
        /// <summary>
        /// 准备
        /// </summary>
        /// <param name="client"></param>
        private void Ready(ClientPeer client)
        {
            socketMsg.State   = MatchCode.Success;
            socketMsg.OpCode  = MsgType.Match;
            socketMsg.SubCode = MatchCode.Ready_Broadcast_Result;
            SingleExecute.Instance.Execute(() =>
            {
                if (!userCache.IsOnline(client))
                {
                    return;
                }
                int userId = userCache.GetClientUserId(client);
                if (!matchCache.IsMatching(userId))
                {
                    return;
                }
                //准备
                MatchRoom room = matchCache.GetRoom(userId);
                if (room.ReadyUIdList.Where(w => w == userId).ToList().Count > 0)
                {
                    return;
                }
                room.Ready(userId);
                socketMsg.value = userId;
                room.Brocast(socketMsg);

                //检测是否所有玩家都准备了
                if (room.IsAllReady())
                {
                    //开始游戏
                    startFight(room.ReadyUIdList);
                    //广播通知所有玩家游戏开始
                    socketMsg.SubCode = MatchCode.Start_Broadcast_Requst;
                    room.Brocast(socketMsg);
                    //销毁房间
                    matchCache.Destroy(room);
                }
            });
        }
Exemple #13
0
        private void chatRequest(ClientPeer client, int chatType)
        {
            if (userCache.IsOnline(client) == false)
            {
                return;
            }
            int userId = userCache.GetId(client);
            //获取发送者的id userId
            //发送
            ChatDto dto = new ChatDto(userId, chatType);

            //广播给房间内的玩家
            if (matchCache.IsMatching(userId))
            {
                MatchRoom mRoom = matchCache.GetRoom(userId);
                mRoom.Brocast(OpCode.CHAT, ChatCode.SRES, dto);
            }
            if (fightCache.IsFighting(userId))
            {
                FightRoom fRoom = fightCache.GetRoomByUId(userId);
                fRoom.Brocast(OpCode.CHAT, ChatCode.SRES, dto, client);
            }
        }