Ejemplo n.º 1
0
 public bool TryGetRoom(string roomId, out MasterServerRoom room)
 {
     room = MasterServerRoom.Empty;
     if (rooms.ContainsKey(roomId))
     {
         room = rooms[roomId];
         return(true);
     }
     return(false);
 }
Ejemplo n.º 2
0
    protected void OnServerRegisterGameServer(NetworkMessage netMsg)
    {
        if (writeLog)
        {
            Debug.Log("[" + name + "] OnServerRegisterGameServer");
        }
        var msg      = netMsg.ReadMessage <MasterServerMessages.RegisterGameServerMessage>();
        var response = new MasterServerMessages.RegisteredGameServerMessage();
        var gameType = string.IsNullOrEmpty(msg.gameType) ? DefaultGameType : msg.gameType;
        var rooms    = EnsureRoomsForGameType(gameType);
        var roomId   = System.Guid.NewGuid().ToString();
        var newRoom  = new MasterServerRoom();

        newRoom.roomId         = roomId;
        newRoom.gameType       = gameType;
        newRoom.title          = msg.title;
        newRoom.password       = msg.password;
        newRoom.scene          = msg.scene;
        newRoom.networkAddress = netMsg.conn.address;
        newRoom.networkPort    = msg.networkPort;
        newRoom.maxConnections = msg.maxConnections;
        newRoom.connectionId   = netMsg.conn.connectionId;

        var registeredRoom = RegisteredMasterServerRoom.Empty;

        if (!msg.registerKey.Equals(registerKey))
        {
            response.resultCode = (short)MasterServerMessages.ResultCodes.RegistrationFailedInvalidKey;
        }
        else if (!rooms.AddRoom(roomId, newRoom, out registeredRoom))
        {
            response.resultCode = (short)MasterServerMessages.ResultCodes.RegistrationFailedCannotCreateRoom;
        }
        else
        {
            response.resultCode = (short)MasterServerMessages.ResultCodes.RegistrationSucceeded;

            NetworkConnection spawnerConnection;
            if (!string.IsNullOrEmpty(msg.spawnToken) && spawners.TryGetValue(msg.spawnToken, out spawnerConnection))
            {
                spawners.Remove(msg.spawnToken);
                var spawnResponse = new MasterServerMessages.SpawnedGameServerMessage();
                spawnResponse.resultCode = (short)MasterServerMessages.ResultCodes.SpawnSucceeded;
                spawnResponse.room       = newRoom;
                spawnerConnection.Send(MasterServerMessages.SpawnedGameServerId, spawnResponse);
            }
        }

        response.registeredRoom = registeredRoom;

        netMsg.conn.Send(MasterServerMessages.RegisteredGameServerId, response);
    }
Ejemplo n.º 3
0
    public bool AddRoom(string roomId, MasterServerRoom room, out RegisteredMasterServerRoom registeredRoom)
    {
        registeredRoom = RegisteredMasterServerRoom.Empty;
        if (rooms.ContainsKey(roomId))
        {
            return(false);
        }

        rooms[roomId]                    = room;
        registeredRoom                   = new RegisteredMasterServerRoom();
        registeredRoom.roomId            = room.roomId;
        registeredRoom.gameType          = room.gameType;
        registeredRoom.title             = room.title;
        registeredRoom.scene             = room.scene;
        registeredRoom.passwordProtected = !string.IsNullOrEmpty(room.password);
        registeredRoom.maxConnections    = room.maxConnections;
        return(true);
    }