/// <summary>
        /// 用户离开匹配
        /// </summary>
        /// <param name="client"></param>
        private void CancelMatch(ClientPeer client)
        {
            SingleExecute.Instance.Execute(() => {
                if (!user.IsOnLine(client))
                {
                    //不在线
                    return;
                }

                int userId = user.GetId(client);
                //用户没有匹配
                if (!match.IsMatching(userId))
                {
                    return;//非法操作 不能离开
                }

                //正常离开
                MatchRoom room = match.Leave(userId);
                if (!room.IsEmpty())
                {
                    room.Brocast(OpCode.MATCHROOM, MatchRoomCode.CANCELMATCH_BRO, userId, client);
                }
                Console.WriteLine(string.Format("玩家 : {0}  取消进入房间 :{1}", user.GetModelByClient(client).name, room.id));
            });
        }
Beispiel #2
0
        //leave match room
        public MatchRoom Leave(int userId)
        {
            int       roomId = uidRoomIdDict[userId];
            MatchRoom room   = roomIdModelDict[roomId];

            room.Leave(userId);
            uidRoomIdDict.Remove(userId);
            if (room.IsEmpty())
            {
                roomIdModelDict.Remove(roomId);
                roomQueue.Enqueue(room);
            }
            return(room);
        }