Ejemplo n.º 1
0
        static void ClassicServer_OnPlayerConnectionChanged(object sender, PlayerConnectionEventArgs e)
        {
            Event args = null;

            if (e.ConnectionState == LibMinecraft.Classic.Server.ConnectionState.Connected)
            {
                args = new PlayerConnectEvent(e.Client);
            }
            if (e.ConnectionState == LibMinecraft.Classic.Server.ConnectionState.Disconnected)
            {
                args = new PlayerDisconnectEvent(e.Client);
            }
            EventCache.Call(args);
        }
Ejemplo n.º 2
0
        private void HandlePlayerDisconnect(object sender, PlayerDisconnectEventArgs e)
        {
            if (e.Player == null)
            {
                return;
            }

            PlayerDisconnectEvent newEvent = new PlayerDisconnectEvent()
            {
                SteamID = e.Player.SteamID
            };

            CurrentTick.Events.Add(newEvent);
        }
Ejemplo n.º 3
0
 public void PlayerDisconnect(PlayerDisconnectEvent eventargs)
 {
     if (InvokeRequired)
     {
         BeginInvoke((MethodInvoker)delegate { PlayerDisconnect(eventargs); });
         return;
     }
     if (selectedPlayer == eventargs.getPlayer())
     {
         selectedPlayer = null;
         lstPlayers.SelectedIndex = -1;
         lstPlayers_SelectedIndexChanged(null, null);
     }
     lstPlayers.RemoveIfExists(eventargs.getPlayer().getName());
 }
Ejemplo n.º 4
0
        private void HandleDC(byte[] message)
        {
            Logger.Log(username + " Disconnected.");
            GlobalMessage(username + " Left.");

            /*if (OnDisconnect != null)
             *  OnDisconnect(this);
             * if (PlayerDisconnect != null)
             *  PlayerDisconnect(this);*/
            PlayerDisconnectEvent.Call(this);
            socket.Close();
            Disconnect();
            foreach (int i in VisibleEntities.ToArray())
            {
                try
                {
                    Entity e = Entity.Entities[i];
                    e.p.SendDespawn(id);
                }
                catch { /* Ignore Me */ }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Process a disconnect for the player with the given ID.
        /// </summary>
        /// <param name="id">The ID of the player.</param>
        /// <param name="timeout">Whether this player timed out or disconnected normally.</param>
        private void ProcessPlayerDisconnect(ushort id, bool timeout = false)
        {
            if (!timeout)
            {
                // If this isn't a timeout, then we need to propagate this packet to the NetServer
                _netServer.OnClientDisconnect(id);
            }

            if (!_playerData.TryGetValue(id, out var playerData))
            {
                return;
            }

            var username = playerData.Username;

            foreach (var idPlayerDataPair in _playerData.GetCopy())
            {
                if (idPlayerDataPair.Key == id)
                {
                    continue;
                }

                _netServer.GetUpdateManagerForClient(idPlayerDataPair.Key)?.AddPlayerDisconnectData(
                    id,
                    username,
                    timeout
                    );
            }

            // Now remove the client from the player data mapping
            _playerData.Remove(id);

            try {
                PlayerDisconnectEvent?.Invoke(playerData);
            } catch (Exception e) {
                Logger.Get().Warn(this, $"Exception thrown while invoking PlayerDisconnect event, {e.GetType()}, {e.Message}, {e.StackTrace}");
            }
        }
Ejemplo n.º 6
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}");
            }
        }