Exemple #1
0
        void PlayerClient_ClientDisconnected(object sender, ClientDisconnectedEventArgs e)
        {
            e.Client.InternalClientDisconnected -= PlayerClient_ClientDisconnected;

            if (e.Client.Server != null && e.Client.Server.PlayerClient != null)
            {
                if (e.Client.Server.Player == null)
                {
                    SharpStarLogger.DefaultLogger.Info("{0} has disconnected", e.Client.Server.PlayerClient.RemoteEndPoint);
                }
                else
                {
                    SharpStarLogger.DefaultLogger.Info("Player {0} ({1}) has disconnected", e.Client.Server.Player.Name, e.Client.Server.PlayerClient.RemoteEndPoint);
                }
            }

            if (e.Client.Server != null)
            {
                _clients.Remove(e.Client.Server);
            }

            try
            {
                if (e.Client.Server != null && e.Client.Server.ServerClient != null)
                {
                    e.Client.Server.ServerClient.ForceDisconnect();
                }

                e.Client.Dispose();
            }
            catch
            {
            }
        }
Exemple #2
0
        private void ServerClient_ClientDisconnected(object sender, ClientDisconnectedEventArgs e)
        {
            e.Client.InternalClientDisconnected -= ServerClient_ClientDisconnected;

            if (e.Client.Server != null)
            {
                _clients.Remove(e.Client.Server);
            }

            try
            {
                if (e.Client.Server != null && e.Client.Server.PlayerClient != null)
                {
                    e.Client.Server.PlayerClient.ForceDisconnect();
                }

                e.Client.Dispose();

                if (e.Client.Server != null)
                {
                    e.Client.Server.Dispose();
                }
            }
            catch
            {
            }
            finally
            {
                e.Client.Server = null;
                e.Client        = null;
            }
        }