EventArgs used for the PlayerHooks.PlayerCommand event.
Inheritance: System.ComponentModel.HandledEventArgs
Esempio n. 1
0
		private void OnPlayerCommand(PlayerCommandEventArgs e)
		{
			if (e.Handled || e.Player == null)
			{
				return;
			}

			Command command = e.CommandList.FirstOrDefault();
			if (command == null || (command.Permissions.Any() && !command.Permissions.Any(s => e.Player.Group.HasPermission(s))))
			{
				return;
			}

			if (e.Player.TPlayer.hostile &&
				command.Names.Select(s => s.ToLowerInvariant())
					.Intersect(Config.DisabledCommandsInPvp.Select(s => s.ToLowerInvariant()))
					.Any())
			{
				e.Player.SendErrorMessage("This command is blocked while in PvP!");
				e.Handled = true;
			}
			else if (e.Player.Group.HasPermission(Permissions.LastCommand) && command.CommandDelegate != Commands.RepeatLast)
			{
				e.Player.GetPlayerInfo().LastCommand = e.CommandText;
			}
		}
 void OnCommand(PlayerCommandEventArgs args)
 {
     if (args.CommandName == "register")
     {
         if (args.Parameters[0].ToUpper() == args.Player.Name.ToUpper())
         {
             args.Player.SendErrorMessage("ERROR: Your password cannot be the same as your name.");
             args.Handled = true;
             return;
         }
         if (args.Parameters[0].Length < 6)
         {
             args.Player.SendErrorMessage("ERROR: Your password is too short.");
             args.Handled = true;
             return;
         }
         if (args.Parameters[0].Contains("password"))
         {
             args.Player.SendErrorMessage("ERROR: Your password cannot contain 'password'.");
             args.Handled = true;
             return;
         }
         Match match = Regex.Match(args.Parameters[0], @"^(?=.*\d)(?=.*[a-zA-Z]).*$");
         if (!match.Success)
         {
             args.Player.SendErrorMessage("ERROR: Your password requires both letters and numbers.");
             args.Handled = true;
             return;
         }
     }
     if (args.CommandName == "password")
     {
         if (args.Parameters[1].ToUpper() == args.Player.Name.ToUpper())
         {
             args.Player.SendErrorMessage("ERROR: Your password cannot be the same as your name.");
             args.Handled = true;
             return;
         }
         if (args.Parameters[1].Length < 6)
         {
             args.Player.SendErrorMessage("ERROR: Your password is too short.");
             args.Handled = true;
             return;
         }
         if (args.Parameters[1].Contains("password"))
         {
             args.Player.SendErrorMessage("ERROR: Your password cannot contain 'password'.");
             args.Handled = true;
             return;
         }
         Match match = Regex.Match(args.Parameters[1], @"^(?=.*\d)(?=.*[a-zA-Z]).*$");
         if (!match.Success)
         {
             args.Player.SendErrorMessage("ERROR: Your password requires both letters and numbers.");
             args.Handled = true;
             return;
         }
     }
 }
Esempio n. 3
0
 private void onPlayerCommand(TShockAPI.Hooks.PlayerCommandEventArgs e)
 {
     if (e.Parameters.Count >= 2 && e.CommandName.ToLower() == "region" && new string[] { "delete", "resize", "expand" }.Contains(e.Parameters[0].ToLower()))
     {
         if (Commands.ChatCommands.Any(c => c.HasAlias("region") && c.CanRun(e.Player)))
         {
             refreshTimer.Interval = 1500;
         }
     }
 }
Esempio n. 4
0
        public static bool OnPlayerCommand(TSPlayer player, string cmdName, string cmdText, List <string> args)
        {
            if (PlayerCommand == null)
            {
                return(false);
            }
            PlayerCommandEventArgs playerCommandEventArgs = new PlayerCommandEventArgs()
            {
                Player      = player,
                CommandName = cmdName,
                CommandText = cmdText,
                Parameters  = args
            };

            PlayerCommand(playerCommandEventArgs);
            return(playerCommandEventArgs.Handled);
        }
Esempio n. 5
0
 void OnCommand(PlayerCommandEventArgs args)
 {
     if (args.CommandName == "ban")
     {
         if (args.Parameters.Count == 0 || args.Parameters[0].ToLower() == "help")
         {
             args.Handled = true;
             args.Player.SendInfoMessage("Syntax: /ban [option] [arguments]");
             args.Player.SendInfoMessage("Options: list, listip, clear, add, adduser, addsteam, addip, del, delip");
             args.Player.SendInfoMessage("Arguments: list, listip, clear [code], add [name], adduser [user], addsteam [user], addip [ip], del [name], delip [name]");
             args.Player.SendInfoMessage("In addition, a reason may be provided for all new bans after the arguments.");
             return;
         }
         if (args.Parameters[0].ToLower() == "adduser")
         {
             var user = TShock.Users.GetUserByName(args.Parameters[1]);
             if (user != null)
             {
                 args.Handled = true;
                 var ban = TShock.Bans.GetBanByName(args.Parameters[1]);
                 if (ban != null)
                 {
                     args.Player.SendInfoMessage(String.Format("{0} has already been banned by {1} for {2}", args.Parameters[1], ban.BanningUser, ban.Reason));
                     return;
                 }
                 string reason = args.Parameters.Count > 2
                                     ? String.Join(" ", args.Parameters.GetRange(2, args.Parameters.Count - 2))
                                     : "Misbehavior.";
                 List<String> KnownIps = new List<string>();
                 KnownIps = JsonConvert.DeserializeObject<List<String>>(user.KnownIps);
                 foreach (string ip in KnownIps)
                 {
                     TShock.Bans.AddBan(ip, user.Name, user.UUID, reason, false, args.Player.UserAccountName, "");
                 }
                 args.Player.SendSuccessMessage(String.Format("{0} has been banned for {1}", args.Parameters[1], reason));
             }
             else args.Player.SendErrorMessage("User could not be found.");
         }
         if (args.Parameters[0].ToLower() == "addsteam")
         {
             args.Handled = true;
             args.Player.SendWarningMessage("This command is not yet implemented.");
         }
     }
 }
Esempio n. 6
0
        /// <summary>
        /// Fires the <see cref="PlayerCommand"/> event.
        /// </summary>
        /// <param name="player">The player firing the event.</param>
        /// <param name="cmdName">The command name.</param>
        /// <param name="cmdText">The raw command text.</param>
        /// <param name="args">The command args extracted from the command text.</param>
        /// <param name="commands">The list of commands.</param>
        /// <param name="cmdPrefix">The command specifier used.</param>
        /// <returns>True if the event has been handled.</returns>
        public static bool OnPlayerCommand(TSPlayer player, string cmdName, string cmdText, List <string> args, ref IEnumerable <Command> commands, string cmdPrefix)
        {
            if (PlayerCommand == null)
            {
                return(false);
            }
            PlayerCommandEventArgs playerCommandEventArgs = new PlayerCommandEventArgs()
            {
                Player        = player,
                CommandName   = cmdName,
                CommandText   = cmdText,
                Parameters    = args,
                CommandList   = commands,
                CommandPrefix = cmdPrefix,
            };

            PlayerCommand(playerCommandEventArgs);
            return(playerCommandEventArgs.Handled);
        }
Esempio n. 7
0
        public static bool OnPlayerCommand(TSPlayer player, string cmdName, string cmdText, List<string> args)
        {
            if (PlayerCommand == null)
            {
                return false;
            }
            PlayerCommandEventArgs playerCommandEventArgs = new PlayerCommandEventArgs()
            {
                Player = player,
                CommandName = cmdName,
                CommandText = cmdText,
                Parameters = args

            };
            PlayerCommand(playerCommandEventArgs);
            return playerCommandEventArgs.Handled;
        }
Esempio n. 8
0
 void OnPlayerCommand(PlayerCommandEventArgs e)
 {
     if (!IrcClient.IsConnected)
         Connect();
     else if (e.Player.RealPlayer)
     {
         if (String.Equals(e.CommandName, "me", StringComparison.CurrentCultureIgnoreCase) && e.CommandText.Length > 2)
         {
             if (!e.Player.mute && e.Player.Group.HasPermission(Permissions.cantalkinthird) && !String.IsNullOrEmpty(Config.ServerActionMessageFormat))
                 SendMessage(Config.Channel, String.Format(Config.ServerActionMessageFormat, e.Player.Name, e.CommandText.Substring(3)));
         }
         else if (e.CommandList.Count() == 0 || e.CommandList.First().DoLog)
         {
             if (!String.IsNullOrEmpty(Config.ServerCommandMessageFormat))
                 SendMessage(Config.AdminChannel, String.Format(Config.ServerCommandMessageFormat, e.Player.Group.Prefix, e.Player.Name, e.CommandText));
         }
     }
 }
Esempio n. 9
0
        void OnPlayerCommand(PlayerCommandEventArgs e)
        {
            if (!e.Handled && e.Player.RealPlayer)
            {
                switch (e.CommandName)
                {
                    case "me":
                    case "r":
                    case "reply":
                    case "tell":
                    case "w":
                    case "whisper":
                        if ((DateTime.Now - Times[e.Player.Index]).TotalSeconds > Config.Time)
                        {
                            Spams[e.Player.Index] = 0.0;
                            Times[e.Player.Index] = DateTime.Now;
                        }

                        string text = e.CommandText.Substring(e.CommandName.Length);
                        if ((double)text.Where(c => Char.IsUpper(c)).Count() / text.Length >= Config.CapsRatio)
                            Spams[e.Player.Index] += Config.CapsWeight;
                        else if (text.Trim().Length <= Config.ShortLength)
                            Spams[e.Player.Index] += Config.ShortWeight;
                        else
                            Spams[e.Player.Index] += Config.NormalWeight;

                        if (Spams[e.Player.Index] > Config.Threshold && !TShock.Players[e.Player.Index].Group.HasPermission("antispam.ignore"))
                        {
                            switch (Config.Action.ToLower())
                            {
                                case "ignore":
                                default:
                                    Times[e.Player.Index] = DateTime.Now;
                                    TShock.Players[e.Player.Index].SendErrorMessage("You have been ignored for spamming.");
                                    e.Handled = true;
                                    return;
                                case "kick":
                                    TShock.Utils.ForceKick(TShock.Players[e.Player.Index], "Spamming", false, true);
                                    e.Handled = true;
                                    return;
                            }
                        }
                        return;
                }
            }
        }
Esempio n. 10
0
        public void OnPlayerCommand(PlayerCommandEventArgs e)
        {
            if (e.Handled)
            {
                return;
            }

            if (e.Player.Index >= 0 && e.Player.Index <= 255)
            {
                if (e.CommandName != "=")
                {
                    esPlayers[e.Player.Index].LastCMD = string.Concat("/", e.CommandText);
                }

                if ((e.CommandName == "tp" && e.Player.Group.HasPermission(Permissions.tp)) ||
                    (e.CommandName == "home" && e.Player.Group.HasPermission(Permissions.home)) ||
                    (e.CommandName == "spawn" && e.Player.Group.HasPermission(Permissions.spawn)) ||
                    (e.CommandName == "warp" && e.Player.Group.HasPermission(Permissions.warp)))
                {
                    var ePly = esPlayers[e.Player.Index];
                    ePly.LastBackX = e.Player.TileX;
                    ePly.LastBackY = e.Player.TileY;
                    ePly.LastBackAction = BackAction.TP;
                }
            }
            else if (e.CommandName == "whisper" || e.CommandName == "w" || e.CommandName == "tell" ||
                    e.CommandName == "reply" || e.CommandName == "r")
            {
                if (!e.Player.Group.HasPermission(Permissions.whisper))
                {
                    return;
                }
                foreach (var player in esPlayers)
                {
                    if (player == null || !player.SocialSpy || player.Index == e.Player.Index)
                    {
                        continue;
                    }
                    if ((e.CommandName == "reply" || e.CommandName == "r") && e.Player.LastWhisper != null)
                    {
                        player.TSPlayer.SendMessage(string.Format("[SocialSpy] from {0} to {1}: /{2}", e.Player.Name, e.Player.LastWhisper.Name, e.CommandText), Color.Gray);
                    }
                    else
                    {
                        player.TSPlayer.SendMessage(string.Format("[SocialSpy] {0}: /{1}", e.Player.Name, e.CommandText), Color.Gray);
                    }
                }
            }
        }
Esempio n. 11
0
        private void OnPlayerCommand(PlayerCommandEventArgs args)
        {
            List<string> unAllowedCommands = new List<string>() { "tp", "tphere", "tpa" };

            if (args.Player.CurrentRegion != null && Database.IsNoTpRegion(args.Player.CurrentRegion.Name))
            {
                if (unAllowedCommands.Contains(args.CommandName))
                {
                    args.Handled = true;
                    args.Player.SendErrorMessage("You cannot use this command in this region.");
                    return;
                }
            }
        }
Esempio n. 12
0
 public static bool OnPlayerCommand(TSPlayer player, string cmdName, string cmdText, List<string> args, ref IEnumerable<Command> commands, string cmdPrefix)
 {
     if (PlayerCommand == null)
     {
         return false;
     }
     PlayerCommandEventArgs playerCommandEventArgs = new PlayerCommandEventArgs()
     {
         Player = player,
         CommandName = cmdName,
         CommandText = cmdText,
         Parameters = args,
         CommandList = commands,
         CommandPrefix = cmdPrefix,
     };
     PlayerCommand(playerCommandEventArgs);
     return playerCommandEventArgs.Handled;
 }