/// <summary>
        /// Informs the PlayFab game server hosting service that the indicated user has left the Game Server Instance specified
        /// </summary>
        public static void PlayerLeft(PlayerLeftRequest request, PlayerLeftCallback resultCallback, ErrorCallback errorCallback, object customData = null)
        {
            if (PlayFabSettings.DeveloperSecretKey == null)
            {
                throw new Exception("Must have PlayFabSettings.DeveloperSecretKey set to call this method");
            }

            string serializedJson = JsonConvert.SerializeObject(request, Util.JsonFormatting, Util.JsonSettings);
            Action <CallRequestContainer> callback = delegate(CallRequestContainer requestContainer)
            {
                PlayerLeftResponse result = ResultContainer <PlayerLeftResponse> .HandleResults(requestContainer, resultCallback, errorCallback);

                if (result != null)
                {
                }
            };

            PlayFabHTTP.Post("/Matchmaker/PlayerLeft", serializedJson, "X-SecretKey", PlayFabSettings.DeveloperSecretKey, callback, request, customData);
        }
Exemplo n.º 2
0
    // called when a client disconnects
    private void OnServerDisconnect(NetworkMessage netMsg)
    {
        if (UnityNetworkingData.ConnectedClients - 1 >= 0)
        {
            UnityNetworkingData.ConnectedClients--;
        }

        if (UnityNetworkingData.ConnectedClients == 0)
        {
            StartCoroutine(CheckForConnectionsOrClose());
        }

        var connection = UnityNetworkingData.Connections.Find(c => c.ConnectionId == netMsg.conn.connectionId);

        if (connection != null)
        {
            if (connection.IsAuthenticated && ServerSettingsData.GameId > 0)
            {
                PlayerLeftResponse.AddOnce((playerLeftResponse) =>
                {
                    ClientDisconnectedSignal.Dispatch(connection.ConnectionId, connection.PlayFabId);
                    Logger.Dispatch(LoggerTypes.Info, string.Format("Player Has Left:{0}", connection.PlayFabId));
                    UnityNetworkingData.Connections.Remove(connection);
                });

                PlayerLeftSignal.Dispatch(new NotifyMatchmakerPlayerLeftRequest()
                {
                    PlayFabId = connection.PlayFabId,
                    LobbyId   = ServerSettingsData.GameId.ToString()
                });
            }
            else
            {
                ClientDisconnectedSignal.Dispatch(connection.ConnectionId, connection.PlayFabId);
                UnityNetworkingData.Connections.Remove(connection);
            }
        }

        Logger.Dispatch(LoggerTypes.Info, "A Unity Client Disconnected");
    }