/// <summary> /// Handler for the NotifyGameServerReady message. /// </summary> /// <param name="netMsg">Network message that was received.</param> protected virtual void OnNotifiedGameServerReady(NetworkMessage netMsg) { var msg = netMsg.ReadMessage <NotifyGameServerReadyMessage>(); if (msg != null) { var connection = awaitingPlayerConnections.Find(x => x.connectionId == msg.playerConnectionId); if (connection != null) { var responseMsg = new ResponseCreateGameRoomMessage(); responseMsg.success = true; responseMsg.ip = msg.ip; responseMsg.port = msg.port; connection.Send(GameRoomsNetworkProtocol.ResponseCreateGameRoom, responseMsg); awaitingPlayerConnections.Remove(connection); } } }
/// <summary> /// Creates a new game room. /// </summary> /// <param name="playerConnection">The network connection of the player requesting the creation of a game room.</param> /// <param name="msg">The network message containing the information of the game room to create.</param> protected virtual void CreateGameRoom(NetworkConnection playerConnection, RequestCreateGameRoomMessage msg) { var zoneServer = SelectZoneServer(); if (zoneServer != null) { ConnectToZoneServer(zoneServer.ip, zoneServer.port) .Then(client => { awaitingPlayerConnections.Add(playerConnection); msg.playerConnectionId = playerConnection.connectionId; return(RequestCreateGameRoom(client, msg)); }) .Then(responseSpawnGameServerMessage => { if (!responseSpawnGameServerMessage.success) { var connection = awaitingPlayerConnections.Find(x => x.connectionId == responseSpawnGameServerMessage.playerConnectionId); if (connection != null) { var responseMsg = new ResponseCreateGameRoomMessage(); responseMsg.success = false; connection.Send(GameRoomsNetworkProtocol.ResponseCreateGameRoom, responseMsg); awaitingPlayerConnections.Remove(connection); } } }) .Catch(e => { Debug.Log(e.Message); }); } else { var responseMsg = new ResponseCreateGameRoomMessage(); responseMsg.success = false; responseMsg.error = CreateGameRoomError.ZoneServerUnavailable; playerConnection.Send(GameRoomsNetworkProtocol.ResponseCreateGameRoom, responseMsg); } }