Esempio n. 1
0
        private void OnDisconnectedEvent(NetPeer peer, DisconnectInfo info)
        {
            var pid = _playerEndPoints.Get(peer.EndPoint);

            if (!string.IsNullOrEmpty(pid))
            {
                GameLiftServerAPI.RemovePlayerSession(pid);
                _logger.InfoFormat("remove player session: {0}", pid);
                _playerEndPoints.Delete(peer.EndPoint);
            }

            _peerList.Delete(peer.EndPoint);
            Console.WriteLine("disconnected: {0}, {1}", peer.EndPoint, info.Reason);
            if (!_peerList.IsEmpty())
            {
                var json = CreateAdminMessage($"[{peer.EndPoint}]さんが抜けました").Serialize();
                var w    = new NetDataWriter();
                _peerList.ForEach(p =>
                {
                    w.Reset();
                    w.Put(json);
                    p.Send(w, DeliveryMethod.ReliableOrdered);
                });
                return;
            }

            // 全員セッションから抜けたら終了する
            GameLiftServerAPI.TerminateGameSession();
            _logger.InfoFormat("terminate game session: {0}", _session.GameSessionId);
        }
        // Called from MLAPI on client disconnect
        // Called on MLAPI connection exception
        public void DisconnectPlayer(ulong clientId)
        {
            // if player slots never re-open, just skip this entire thing.
            try {
                var playerSessionId = playerSessions[clientId];
                try {
                    //Notifies the GameLift service that a player with the specified player session ID has disconnected
                    //from the server process. In response, GameLift changes the player slot to available,
                    //which allows it to be assigned to a new player.
                    var outcome = GameLiftServerAPI.RemovePlayerSession(playerSessionId);
                    GameLiftServerAPI.ProcessEnding(); // For now, killing game session on player leaving.
                    Debug.Log(outcome.Success
            ? ":) PLAYER SESSION REMOVED"
            : $":( PLAYER SESSION REMOVE FAILED. RemovePlayerSession() returned {outcome.Error}");
                }
                catch (Exception e) {
                    Debug.Log($":( PLAYER SESSION REMOVE FAILED. RemovePlayerSession() exception\n{e.Message}");
                    throw;
                }

                playerSessions.Remove(clientId);
            }
            catch (KeyNotFoundException e) {
                Debug.Log($":( INVALID PLAYER SESSION. Exception \n{e.Message}");
                throw; // should never happen
            }
        }
Esempio n. 3
0
 public override void Disconnected(BoltConnection connection)
 {
     if (BoltNetwork.IsServer)
     {
         GameLiftServerAPI.RemovePlayerSession((string)connection.UserData);
     }
 }
Esempio n. 4
0
    public void DisconnectPlayer(int playerIdx)
    {
        // if player slots never re-open, just skip this entire thing.
        try
        {
            string playerSessionId = playerSessions[playerIdx];
            try
            {
                var outcome = GameLiftServerAPI.RemovePlayerSession(playerSessionId);
                if (outcome.Success)
                {
                    Debug.Log(":) PLAYER SESSION REMOVED");
                }
                else
                {
                    Debug.Log(":( PLAYER SESSION REMOVE FAILED. RemovePlayerSession() returned " + outcome.Error.ToString());
                }
            }
            catch (Exception e)
            {
                Debug.Log(":( PLAYER SESSION REMOVE FAILED. RemovePlayerSession() exception " + Environment.NewLine + e.Message);
                throw;
            }

            playerSessions.Remove(playerIdx);
        }
        catch (KeyNotFoundException e)
        {
            Debug.Log(":( INVALID PLAYER SESSION. Exception " + Environment.NewLine + e.Message);
            throw; // should never happen
        }
    }
 private void HandlePlayerExit(string playerSessionId, int remaining)
 {
     LogOutcome("player term", GameLiftServerAPI.RemovePlayerSession(playerSessionId));
     if (remaining == 0)
     {
         LogOutcome("game term", GameLiftServerAPI.TerminateGameSession());
         LogOutcome("ending", GameLiftServerAPI.ProcessEnding());
         Application.Quit(0);
     }
 }
Esempio n. 6
0
    public void RemovePlayer(string playerSessionId)
    {
        var removePlayerSessionOutcome = GameLiftServerAPI.RemovePlayerSession(playerSessionId);

        if (removePlayerSessionOutcome.Success)
        {
            LogModule.WriteToLogFile("[GameLift] Remove Player Session Success : " + playerSessionId);
        }
        else
        {
            LogModule.WriteToLogFile("[GameLift] Remove Player Session Failed. Result : " + removePlayerSessionOutcome.Error.ToString());
        }
    }
Esempio n. 7
0
    public void RemovePlayerSession(string playerSessionId)
    {
        Debug.Log("RemovePlayerSession for player session id: " + playerSessionId);

        try
        {
            // Remove players from the game session that disconnected
            var outcome = GameLiftServerAPI.RemovePlayerSession(playerSessionId);

            if (outcome.Success)
            {
                Debug.Log("PLAYER SESSION REMOVED");
            }
            else
            {
                Debug.Log("PLAYER SESSION REMOVE FAILED. RemovePlayerSession() returned " + outcome.Error.ToString());
            }
        }
        catch (Exception e)
        {
            Debug.Log("PLAYER SESSION REMOVE FAILED. RemovePlayerSession() exception " + Environment.NewLine + e.Message);
            throw;
        }
    }
Esempio n. 8
0
 private void ProcessEnding()
 {
     _playerEndPoints.ForEach(pid => GameLiftServerAPI.RemovePlayerSession(pid));
     _peerList.ForEach(p => p.Disconnect());
     GameLiftServerAPI.ProcessEnding();
 }
        public bool RemovePlayerSession(string playerSessionId)
        {
            var disconnectOutcome = GameLiftServerAPI.RemovePlayerSession(playerSessionId);

            return(disconnectOutcome.Success);
        }