示例#1
0
        /// <summary>
        /// Kicks the player from the server.
        /// </summary>
        /// <param name="reason">The reason the player is being kicked.</param>
        /// <param name="log">if true, sends a message notifing everyone of the kick, and adds it to the player's kick counter.</param>
        public void KickPlayer(string reason, bool log = false)
        {
            var dc = new Disconnect {Reason = reason};
            SendQueue.Enqueue(dc);

            Thread.Sleep(100);

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

            if (CS.LoggedIn && log) {
                ServerCore.Logger.Log("Client", CS.LoginName + " has been kicked. (" + reason + ")", LogType.Info);
                ServerCore.Luahandler.RunFunction("E_PlayerKicked", CS.LoginName, reason);
                Chat.SendGlobalChat(CS.FormattedName + ServerCore.TextFormats.SystemMessage + " has been kicked. (" + reason + ")");

                var values = new Dictionary<string, string>
                {
                    {
                        "KickCounter",
                        (ServerCore.DB.GetDatabaseInt(CS.LoginName, "PlayerDB", "KickCounter") + 1).ToString()
                    },
                    {"KickMessage", reason}
                };

                ServerCore.DB.Update("PlayerDB", values, "Name='" + CS.LoginName + "'");
            }

            ServerCore.Nh.HandleDisconnect(this);
        }
示例#2
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);
            }
        }