示例#1
0
    private void AddClientToRoom(int clientId, string roomId)
    {
        // Validate the room name (must be only letters, numbers, dashes and underscores, and no more than 10 characters
        // long)
        bool success = _channelRegex.Match(roomId).Success;

        if (success)
        {
            if (!_rooms.ContainsKey(roomId))
            {
                _rooms[roomId] = new Room(roomId);
            }
            success = _rooms[roomId].AddClient(clientId);
        }
        var roomJoin = new RoomJoinMessage {
            Success = success
        };

        NetworkServer.SendToClient(clientId, NoonMsgType.RoomJoin, roomJoin);

        // Update the room status
        WriteStatusToFile();

        // Notify all partners if the room was successfully joined
        if (!success)
        {
            return;
        }
        _clients[clientId] = roomId;
        var partnerJoin = new PartnerJoinMessage();

        BroadcastMessageToRoom(clientId, NoonMsgType.PartnerJoin, partnerJoin);
    }
示例#2
0
        void CreateRoom(RoomCreationMessage roomCreationMessage, Connection roomCreator)
        {
            Room newRoom = new Room(roomCreationMessage.roomName, roomCreationMessage.hostName, roomCreationMessage.maxPlayerCount);
            var  m       = new RoomJoinMessage(roomCreator.ClientId, newRoom.roomID, 0);

            roomCreator.Send(m);
            Server.instance.rooms.Add(newRoom);
            JoinRoom(newRoom, roomCreator);
        }