Beispiel #1
0
        /// <summary>
        /// Blocking kick function that also performs all disconnection functions on the client before returning.
        /// Other players are simply told the client left.
        /// </summary>
        /// <param name="reason">The reason for the player being kicked.</param>
        public void KickNow(string reason)
        {
            ServerCore.Logger.Log("Client", "Played kicked: " + reason, LogType.Info);
            var dc = new Disconnect { Reason = reason };
            dc.Write(this);

            Thread.Sleep(100);

            if (DataRunner.IsAlive)
                DataRunner.Abort();

            if (EntityThread.IsAlive)
                EntityThread.Abort();

            if (BaseSocket.Connected)
                BaseSocket.Close();

            if (!CS.LoggedIn)
                return;

            lock (CS.CurrentMap.ClientLock) {
                CS.CurrentMap.Clients.Remove(CS.Id);
                CS.CurrentMap.CreateClientList();
            }

            if (CS.MyEntity != null) {
                CS.CurrentMap.DeleteEntity(ref CS.MyEntity);
                ServerCore.FreeEids.Push((short)CS.MyEntity.Id);
            }

            ServerCore.OnlinePlayers --;
            ServerCore.FreeIds.Push(CS.NameId);
            ServerCore.Nh.LoggedClients.Remove((CS.LoginName));
            ServerCore.Nh.IntLoggedClients.Remove(CS.Id);
            ServerCore.Nh.CreateLists();

            var remove = new ExtRemovePlayerName { NameId = CS.NameId };

            foreach (var c in ServerCore.Nh.ClientList) {
                int extVer;
                if (c.CS.CPEExtensions.TryGetValue("ExtPlayerList", out extVer))
                    c.SendQueue.Enqueue(remove);
            }

            ServerCore.Logger.Log("Network", "Player " + CS.LoginName + " has disconnected.", LogType.Info); // -- Notify of their disconnection.
            ServerCore.Luahandler.RunFunction("E_PlayerDisconnect", CS.LoginName);
            Chat.SendGlobalChat(ServerCore.TextFormats.SystemMessage + "Player " + CS.FormattedName + ServerCore.TextFormats.SystemMessage + " left.");
            CS.LoggedIn = false;

            lock (ServerCore.Nh.ClientLock) {
                ServerCore.Nh.Clients.Remove(this);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Handles a client that is disconnecting
        /// </summary>
        /// <param name="client">The client that has disconnected.</param>
        public void HandleDisconnect(NetworkClient client)
        {
            lock (ClientLock) {
                Clients.Remove(client);
            }

            try {
                client.BaseSocket.Close();
            } catch (IOException) {
            }

            if (!client.CS.LoggedIn)
                return;

            client.CS.LoggedIn = false;

            lock (client.CS.CurrentMap.ClientLock) {
                client.CS.CurrentMap.Clients.Remove(client.CS.Id);
                client.CS.CurrentMap.CreateClientList();
            }

            if (client.CS.MyEntity != null) {
                client.CS.CurrentMap.DeleteEntity(ref client.CS.MyEntity);
                ServerCore.FreeEids.Push((short)client.CS.MyEntity.Id);
            }

            ServerCore.OnlinePlayers -= 1;
            ServerCore.FreeIds.Push(client.CS.NameId);
            LoggedClients.Remove(client.CS.LoginName);
            IntLoggedClients.Remove(client.CS.Id);
            CreateLists();

            var remove = new ExtRemovePlayerName {NameId = client.CS.NameId};

            foreach (var c in ClientList) {
                if (c.CS.CPEExtensions.ContainsKey("ExtPlayerList"))
                    c.SendQueue.Enqueue(remove);
            }

            ServerCore.Logger.Log("Network", "Player " + client.CS.LoginName + " has disconnected.", LogType.Info); // -- Notify of their disconnection.
            ServerCore.Luahandler.RunFunction("E_PlayerDisconnect", client.CS.LoginName);
            Chat.SendGlobalChat(ServerCore.TextFormats.SystemMessage + "Player " + client.CS.FormattedName + ServerCore.TextFormats.SystemMessage + " left.");
        }