Esempio n. 1
0
        public int CreateRoom(AceNetFrameWork.ace.UserToken token, SocketModel mes)
        {
            string roomName = mes.getMessage <string>();

            MatchRoom matchRoom = new MatchRoom(token);
            int       playerID  = cache.getId(token);
            string    account   = cache.getAccount(token);
            int       roomID    = atomic.getAndAdd();

            matchRoom.HostID      = playerID;
            matchRoom.hostAccount = account;
            if (matchRoomMap.TryAdd(roomID, matchRoom))
            {
                userMatch.TryAdd(playerID, roomID);
            }
            else
            {
                //如果添加房间失败,则发送失败消息
                Console.WriteLine("无法添加房间");
                write(token, TypeProtocol.TYPE_GAMEHALL_CREQ, 0, GameHallProtocol.GAMEHALL_CREATEROOM_CREQ, 0);
                return(0);
            }
            RoomInfoDTO info = new RoomInfoDTO();

            info.roomID = roomID; info.roomName = roomName; info.roomState = "正在等待"; info.roomOwner = account;
            roomInfoList.Add(info);


            write(token, TypeProtocol.TYPE_GAMEHALL_CREQ, 0, GameHallProtocol.GAMEHALL_CREATEROOM_CREQ, info);

            cache.removeGameHallAccMap(token);//将用户移除出大厅列表 加入到房间列表中
            cache.addToRoomAccMap(token);

            UpdateRoomListToAll();

            return(1);
        }