protected override void getPlayerModelByID(PlayerAuthenticationModel playerAuthModel, PlayerCombatBehaviourBase playerCombatBehaviourInstance, Action <ServerPlayerModel> onSuccessHandler, Action onFailureHandler) { GetUserDataRequest request = new GetUserDataRequest(); request.PlayFabId = playerAuthModel.UserID; request.Keys = USER_DATA_KEYS; PlayFabServerAPI.GetUserDataAsync(request).ContinueWith(t => { if (t.Result.Error != null) { onFailureHandler(); } else { try { ServerPlayerModel serverPlayerModel = parseServerPlayerModelFromData(t.Result.Result.Data, playerCombatBehaviourInstance); onSuccessHandler(serverPlayerModel); } catch (Exception e) { Log.Warning("PlayFabPlayerService unable to parse player with ID: " + playerAuthModel.UserID + " " + e.Message); onFailureHandler(); } } }); }
public bool RejoinPlayer(PlayerAuthenticationModel playerAuthModel, IClientConnection clientConnection) { if (isGameCompleted) { Log.Info("Can't rejoin player, game is completed."); return(false); } ServerPlayerModel originalServerPlayerModel; originalPlayerIDToModel.TryGetValue(playerAuthModel.UserID, out originalServerPlayerModel); if (originalServerPlayerModel == null) { return(false); } // If the player is still connected through a previous connection, disconnect it. if (originalServerPlayerModel.ClientConnection.Connected) { originalServerPlayerModel.ClientConnection.Disconnect(); } originalServerPlayerModel.IsRejoining = true; originalServerPlayerModel.ClientConnection = clientConnection; // Replace stale connection Log.Info("Sending rejoining player SendLoadWorldEventsCMD"); new SendLoadWorldEventsCMD(worldModel, new List <ServerPlayerModel>(new ServerPlayerModel[] { originalServerPlayerModel }), onPlayersLoadedWorld).Execute(); return(true); }
public void AddPlayerForConnection(PlayerAuthenticationModel playerAuthModel, IClientConnection clientConnection) { clientPeerConnectionToPlayerID.Add(clientConnection, playerAuthModel.UserID); playerIDToConnection.Add(playerAuthModel.UserID, clientConnection); clientConnection.Disconnected += onClientDisconnected; PlayerCombatBehaviourBase playerCombatBehaviour = DIContainer.CreateInstanceByContextID <PlayerCombatBehaviourBase>(InstanceServerApplication.CONTEXT_ID); playerService.GetPlayerModelByID(playerAuthModel, playerCombatBehaviour, onPlayerModelReceived, onGetPlayerModelFailed); }
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); } }
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); }
public void GetPlayerModelByID(PlayerAuthenticationModel playerAuthModel, PlayerCombatBehaviourBase playerCombatBehaviourInstance, Action <ServerPlayerModel> onSuccessHandler, Action <PlayerAuthenticationModel> onFailureHandler) { getPlayerModelByID(playerAuthModel, playerCombatBehaviourInstance, serverPlayerModel => { try { parseEquipmentAndCombatantModel(serverPlayerModel); } catch (Exception) { Log.Warning("PlayerServerBase unable to parse ServerPlayerModel for player with ID: " + playerAuthModel.UserID); onFailureHandler(playerAuthModel); } serverPlayerModel.PlayerID = playerAuthModel.UserID; serverPlayerModel.Name = playerAuthModel.UserName; onSuccessHandler(serverPlayerModel); }, () => { onFailureHandler(playerAuthModel); }); }
protected override void validateSession(string sessionID, Action <PlayerAuthenticationModel> successHandler, Action failureHandler) { AuthenticateSessionTicketRequest request = new AuthenticateSessionTicketRequest(); request.SessionTicket = sessionID; PlayFabServerAPI.AuthenticateSessionTicketAsync(request).ContinueWith(t => { if (t.Result.Error != null) { failureHandler(); } else { PlayerAuthenticationModel playerAuthModel = new PlayerAuthenticationModel(sessionID, t.Result.Result.UserInfo.PlayFabId, t.Result.Result.UserInfo.TitleInfo.DisplayName); successHandler(playerAuthModel); } }); }
protected override void getPlayerModelByID(PlayerAuthenticationModel playerAuthModel, PlayerCombatBehaviourBase playerCombatBehaviourBase, Action <ServerPlayerModel> onSuccessHandler, Action onFailureHandler) { if (playerAuthModel.UserID == "testFail") { onFailureHandler(); return; } ServerPlayerModel playerModel = new ServerPlayerModel(playerCombatBehaviourBase); playerModel.PlayerID = playerAuthModel.UserID; playerModel.Name = playerAuthModel.UserName; AbilityItemModel[] mockAbilities = new AbilityItemModel[] { MockCatalogService.FIREBALL_ABILITY }; playerModel.CombatantModel = new CombatantModel(1, 100, 1, 100, 1, 1, 1, 10, 0f, 10, 0f, PlayerModel.DEFAULT_TEAM_ID, mockAbilities); Task.Delay(100).ContinueWith(t => { onSuccessHandler(playerModel); }); }
private void onGetPlayerModelFailed(PlayerAuthenticationModel failedPlayerAuthModel) { Log.Info("LobbyController.onGetPlayerModelFailed: Failed to load ServerPlayerModel for player with ID: " + failedPlayerAuthModel.UserID); playerIDToConnection[failedPlayerAuthModel.UserID].Disconnect(); }
private void onValidated(PlayerAuthenticationModel playerAuthModel) { successHandler(playerAuthModel, clientPeerConnection, joinRoomOpRequest); }
protected abstract void getPlayerModelByID(PlayerAuthenticationModel playerAuthModel, PlayerCombatBehaviourBase playerCombatBehaviourInstance, Action <ServerPlayerModel> onSuccessHandler, Action onFailureHandler);