Exemple #1
0
        protected void Kick(string command, string arguments, ServerPlayer caller)
        {
            if (!PermissionProcessor.PlayerHasPermision(caller, PermissionNames.Kick))
            {
                State.Chat.SendChatToUser(null, caller, Resources.KickNonAuthMessage, false);
                return;
            }

            string       targetCallsign = string.Empty;
            ServerPlayer target         = PlayerFromArgs(arguments, ref targetCallsign);

            if (target == null)
            {
                State.Chat.SendChatToUser(null, caller, Resources.ArgumentNoUserMessage + targetCallsign, false);
                return;
            }

            if (target == caller)
            {
                State.Chat.SendChatToUser(null, caller, Resources.KickSelfMessage, false);
                return;
            }

            if (!PermissionProcessor.PlayerHasPermision(target, PermissionNames.KickImmunity))
            {
                State.Chat.SendChatToUser(null, caller, Resources.KickImmunityMessage + targetCallsign, false);
                return;
            }

            string logMessage = "Player " + caller.Callsign + " kicking target " + target.Callsign;

            Logger.Log1(logMessage);
            State.Chat.SendChatToGroup(null, State.Chat.AdminGroup, logMessage, false);

            string[] parts  = arguments.Split(" ".ToCharArray(), 2);
            string   reason = "Kicked";

            if (parts.Length > 1 && parts[1] != string.Empty)
            {
                reason = parts[1];
            }

            State.Chat.SendChatToUser(null, target, Resources.KickTargetMessagePrefix + reason, false);
            target.FlushTCP();

            API.KickUser(target);
            State.Chat.SendChatToUser(null, caller, Resources.KickCompleteMessage + targetCallsign, false);
        }
Exemple #2
0
        protected void Ban(string command, string arguments, ServerPlayer caller)
        {
            if (!PermissionProcessor.PlayerHasPermision(caller, PermissionNames.Ban))
            {
                State.Chat.SendChatToUser(null, caller, Resources.BanNonAuthMessage, false);
                return;
            }

            string       targetCallsign = string.Empty;
            ServerPlayer target         = PlayerFromArgs(arguments, ref targetCallsign);

            if (target == null)
            {
                State.Chat.SendChatToUser(null, caller, Resources.ArgumentNoUserMessage + targetCallsign, false);
                return;
            }

            if (target == caller)
            {
                State.Chat.SendChatToUser(null, caller, Resources.BanSelfMessage, false);
                return;
            }

            if (!PermissionProcessor.PlayerHasPermision(target, PermissionNames.BanImmunity))
            {
                State.Chat.SendChatToUser(null, caller, Resources.BanImmunityMessage + targetCallsign, false);
                return;
            }

            string[] parts = arguments.Split(" ".ToCharArray(), 4);

            string banType      = string.Empty;
            string reason       = Resources.BanDefaultReason;
            string banDurration = string.Empty;

            if (parts.Length >= 3)
            {
                banType      = parts[1].ToUpperInvariant();
                banDurration = parts[2].ToUpperInvariant();
                if (parts.Length == 4)
                {
                    reason = parts[3];
                }
            }

            bool validArgs = true;

            bool strongBan = false;

            if (banType == "WEAK")
            {
                strongBan = false;
            }
            else if (banType == "STRONG")
            {
                strongBan = true;
            }
            else
            {
                validArgs = false;
            }

            int banTime = ParseBanTime(banDurration);

            if (banTime == int.MinValue)
            {
                validArgs = false;
            }

            if (!validArgs)
            {
                State.Chat.SendChatToUser(null, caller, Resources.BanMalformedMessage, false);
                return;
            }

            string logMessage = "Player " + caller.Callsign + " kick/baning target " + target.Callsign;

            Logger.Log1(logMessage);
            State.Chat.SendChatToGroup(null, State.Chat.AdminGroup, logMessage, false);

            // build up the ban

            string address = target.GetIPAsString();
            string host    = target.HostEntry.ToString();

            if (!strongBan)
            {
                if (target.GetIPAddress().AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6)
                {
                    string[] addressParts = address.Split(":".ToCharArray());
                    if (addressParts.Length > State.ConfigData.Security.IPV6SubnetBanRange)
                    {
                        Array.Resize(ref addressParts, addressParts.Length - State.ConfigData.Security.IPV6SubnetBanRange);
                    }

                    address = String.Join(":", addressParts);
                }
                else
                {
                    string[] addressParts = address.Split(".".ToCharArray());
                    if (addressParts.Length > State.ConfigData.Security.IPV4SubnetBanRange)
                    {
                        Array.Resize(ref addressParts, addressParts.Length - State.ConfigData.Security.IPV4SubnetBanRange);
                    }

                    address = String.Join(".", addressParts);
                }
            }

            API.AddBan(target.BZID, address, host, reason, caller.Callsign, 0, banTime);

            if (reason != string.Empty)
            {
                State.Chat.SendChatToUser(null, target, Resources.KickTargetMessagePrefix + parts[1], false);
                target.FlushTCP();
            }

            API.KickUser(target);
            State.Chat.SendChatToUser(null, caller, Resources.BanCompleteMessage + targetCallsign, false);
        }