public JoinRoomResponseCode TryAddClientConnection(PlayerAuthenticationModel playerAuthModel, IClientConnection clientConnection, string roomPassword) { lock (_lock) { if (roomPassword != Password) { Log.Info("Invalid room password specified"); return(JoinRoomResponseCode.InvalidRoomPassword); } if (disposed) { Log.Info("Room has expired"); return(JoinRoomResponseCode.RoomExpired); } JoinRoomResponseCode responseCode = JoinRoomResponseCode.UnknownFailure; if (gameController.IsGameActive) { // TODO: rejoin if (!gameController.RejoinPlayer(playerAuthModel, clientConnection)) { return(responseCode); } responseCode = JoinRoomResponseCode.AddedToExistingGame; } else { // Add to lobby lobbyController.AddPlayerForConnection(playerAuthModel, clientConnection); responseCode = JoinRoomResponseCode.AddedToLobby; } if (responseCode != JoinRoomResponseCode.AddedToExistingGame && responseCode != JoinRoomResponseCode.AddedToLobby) { Log.Info("Failed to join room"); return(responseCode); } if (tearDownTimer.Enabled) { Log.Info(">>>> Player successfully joined room, disabling tearDownTimer."); tearDownTimer.Enabled = false; } Log.Info("Player ID: " + playerAuthModel.UserID + " joined room. State: " + responseCode.ToString()); connections.Add(clientConnection); clientConnection.Disconnected += onClientPeerDisconnected; return(responseCode); } }