private void handleZoneFailure() { for (int i = 0; i < AllPlayersinZone.Count; i++) { // TODO: Send failure event to player; // Remove player references and disconnect after delay. IClientConnection connection = AllPlayersinZone[i].ClientConnection; removePlayerReferences(AllPlayersinZone[i]); connection.DisconnectAfterDelay(); } }
private void onSessionValidated(PlayerAuthenticationModel playerAuthModel, IClientConnection clientConnection, JoinRoomOpRequest joinRoomOpRequest) { Log.Info("JoinRoomController: player session validated " + playerAuthModel.UserID + " ==> " + joinRoomOpRequest.RoomID); // Once client's session is validated, determine if the room will be a new or existing one. RoomContext roomContext = null; if (!roomIDToContext.TryGetValue(joinRoomOpRequest.RoomID, out roomContext)) { Log.Info("Creating new room with ID: " + joinRoomOpRequest.RoomID); roomContext = new RoomContext(joinRoomOpRequest.RoomID, joinRoomOpRequest.Password); RoomContext addedRoomContext = roomIDToContext.GetOrAdd(roomContext.ID, roomContext); if (roomContext == addedRoomContext) { roomContext.Destroyed += onRoomDestroyed; } else { roomContext = addedRoomContext; } } else { Log.Info("Joining existing room with ID: " + roomContext.ID); } // Try adding client to the determined room. JoinRoomOpResponse joinRoomOpResponse = null; JoinRoomResponseCode joinRoomResponseCode = roomContext.TryAddClientConnection(playerAuthModel, clientConnection, joinRoomOpRequest.Password); // If we couldn't place the client into the room, respond with failure code. if (joinRoomResponseCode != JoinRoomResponseCode.AddedToLobby && joinRoomResponseCode != JoinRoomResponseCode.AddedToExistingGame) { joinRoomOpResponse = new JoinRoomOpResponse(false, joinRoomResponseCode); clientConnection.SendOperationResponse(joinRoomOpResponse.OperationResponse, joinRoomOpResponse.SendParameters); clientConnection.DisconnectAfterDelay(); Log.Info("JoinRoomController: Couldn't add clientPeerConnection with ID " + clientConnection.ConnectionId + " to room with ID " + roomContext.ID + ". Code : " + joinRoomResponseCode); return; } // If we reach this point, the client was successfully added to a room, so respond with success. joinRoomOpResponse = new JoinRoomOpResponse(true, JoinRoomResponseCode.AddedToLobby); clientConnection.SendOperationResponse(joinRoomOpResponse.OperationResponse, joinRoomOpResponse.SendParameters); }