Example #1
0
        private void OnPlayerDisconnect(ClientPlayerDisconnect playerDisconnect)
        {
            var id       = playerDisconnect.Id;
            var username = playerDisconnect.Username;

            Logger.Get().Info(this, $"Received PlayerDisconnect data for ID: {id}");

            // Destroy player object
            _playerManager.DestroyPlayer(id);

            // Destroy map icon
            _mapManager.RemovePlayerIcon(id);

            UI.UIManager.InfoBox.AddMessage($"Player '{username}' disconnected from the server");
        }
Example #2
0
        /// <summary>
        /// Callback method for when a player disconnects from the server.
        /// </summary>
        /// <param name="playerDisconnect">The ClientPlayerDisconnect packet data.</param>
        private void OnPlayerDisconnect(ClientPlayerDisconnect playerDisconnect)
        {
            var id       = playerDisconnect.Id;
            var username = playerDisconnect.Username;

            Logger.Get().Info(this,
                              $"Received PlayerDisconnect data for ID: {id}, timed out: {playerDisconnect.TimedOut}");

            // Instruct the player manager to recycle the player object
            _playerManager.RecyclePlayer(id);

            // Destroy map icon
            _mapManager.RemovePlayerIcon(id);

            // Store a reference of the player data before removing it to pass to the API event
            _playerData.TryGetValue(id, out var playerData);

            // Clear the player from the player data mapping
            _playerData.Remove(id);

            if (playerDisconnect.TimedOut)
            {
                UiManager.InternalChatBox.AddMessage($"Player '{username}' timed out");
            }
            else
            {
                UiManager.InternalChatBox.AddMessage($"Player '{username}' disconnected from the server");
            }

            try {
                PlayerDisconnectEvent?.Invoke(playerData);
            } catch (Exception e) {
                Logger.Get().Warn(this,
                                  $"Exception thrown while invoking PlayerDisconnect event, {e.GetType()}, {e.Message}, {e.StackTrace}");
            }
        }