Пример #1
0
 public void onJoin(int who, HandledEventArgs args)
 {
     lock (scPlayers)
     {
         string name = TShock.Players[who].Name;
         scPlayer add = new scPlayer(who);
         if (offlineCooldowns.ContainsKey(name))
         {
             add.Cooldowns = offlineCooldowns[name];
             offlineCooldowns.Remove(name);
             add.removeOldCooldowns();
         }
         scPlayers.Add(add);
     }
 }
Пример #2
0
 public static bool hasCooldown(scPlayer sPly, scCommand command)
 {
     if (sPly.tsPly.Group.HasPermission("shortcmd.nocooldown") || command.cooldown < 1) return false;
     if (sPly.Cooldowns.ContainsKey(command.alias))
     {
         var seconds = (DateTime.UtcNow - sPly.Cooldowns[command.alias]).TotalSeconds;
         if (seconds < command.cooldown)
         {
             sPly.tsPly.SendMessage("You must wait another {0} seconds before using that command!".SFormat((int)(command.cooldown - seconds)), Color.Red);
             return true;
         }
     }
     return false;
 }
Пример #3
0
        public static void parseCommand(scPlayer sPly, string Text, scCommand command, bool CanBypassPermissions)
        {
            List<string> Parameters = parseParameters(Text, true);
            Parameters.RemoveAt(0); //remove the cmd alias (/cmd)

            List<Command> validCommands = new List<Command>();
            List<string> validText = new List<string>();
            List<List<string>> validArgs = new List<List<string>>();

            bool IsError = false;
            int maxParameters = 0;
            List<string> invalidCommands = new List<string>();
            List<string> cantRun = new List<string>();
            List<string> formatException = new List<string>();
            foreach (var executeCmd in command.commands)
            {
                //Commands.HandleCommand(sPly.tsPly, string.Format(cmd, Parameters));

                //Custom Handle:
                #region Custom Handle
                string cmdText = executeCmd.Remove(0, 1);

                int maxParams = maxFormat(cmdText) + 1;
                if (Parameters.Count >= maxParams)
                {
                    try
                    {
                        cmdText = string.Format(cmdText, Parameters.ToArray());
                    }
                    catch (FormatException)
                    {
                        formatException.Add(string.Concat("/", (cmdText.Contains(' ') ? cmdText.Split(' ')[0] : cmdText)));
                        continue;
                    }
                }
                else
                {
                    IsError = true;
                    if (maxParams > maxParameters)
                        maxParameters = maxParams;
                    continue;
                }

                if (cmdText.Contains("%account") && !sPly.tsPly.IsLoggedIn)
                {
                    sPly.tsPly.SendWarningMessage("You must be logged in to execute that command");
                    return;
                }
                cmdText = cmdText.Replace("%name", string.Format("\"{0}\"", sPly.tsPly.Name));
                cmdText = cmdText.Replace("%account", string.Format("\"{0}\"", sPly.tsPly.UserAccountName));
                cmdText = cmdText.Replace("%group", string.Format("\"{0}\"", sPly.tsPly.Group.Name));

                var args = parseParameters(cmdText);
                if (args.Count < 1 || string.IsNullOrWhiteSpace(cmdText))
                    continue;

                string cmdName = args[0].ToLower();
                args.RemoveAt(0);

                IEnumerable<Command> cmds = Commands.ChatCommands.Where(c => c.HasAlias(cmdName));

                if (cmds.Count() == 0)
                {
                    if (sPly.tsPly.AwaitingResponse.ContainsKey(cmdName))
                    {
                        Action<CommandArgs> call = sPly.tsPly.AwaitingResponse[cmdName];
                        sPly.tsPly.AwaitingResponse.Remove(cmdName);
                        call(new CommandArgs(cmdText, sPly.tsPly, args));
                        continue;
                    }
                    IsError = true;
                    invalidCommands.Add(string.Concat("/", (cmdText.Contains(' ') ? cmdText.Split(' ')[0] : cmdText)));
                    continue;
                }
                foreach (Command cmd in cmds)
                {
                    if (!CanBypassPermissions && !cmd.CanRun(sPly.tsPly))
                    {
                        IsError = true;
                        cantRun.Add(string.Concat("/", cmdText));
                        break;

                    }
                    else if (!cmd.AllowServer && !sPly.tsPly.RealPlayer)
                        break;
                    else
                    {
                        validCommands.Add(cmd);
                        validText.Add(cmdText);
                        validArgs.Add(args);
                    }
                }
                #endregion
            }
            if (validCommands.Count > 0)
            {
                handleCommad(sPly, Text, validCommands, validText, validArgs, CanBypassPermissions);
                if (sPly.Cooldowns.ContainsKey(command.alias))
                    sPly.Cooldowns[command.alias] = DateTime.UtcNow;
                else
                    sPly.Cooldowns.Add(command.alias, DateTime.UtcNow);
            }
            if (IsError)
            {
                if (maxParameters > 0)
                    sPly.tsPly.SendErrorMessage("{0} parameter{1} required.".SFormat(maxParameters, (maxParameters > 1 ? "s are" : " is")));
                if (invalidCommands.Count > 0)
                    sPly.tsPly.SendErrorMessage("Invalid command{0} {1}.".SFormat((invalidCommands.Count > 1 ? "s" : string.Empty), string.Join(", ", invalidCommands)));
                if (cantRun.Count > 0)
                    sPly.tsPly.SendErrorMessage("You do not have permission to execute {0}.".SFormat(string.Join(", ", cantRun)));
                if (formatException.Count > 0)
                    sPly.tsPly.SendErrorMessage("Format Exception in command{0} {1}.".SFormat((formatException.Count > 1 ? "s" : string.Empty), string.Join(", ", formatException)));
            }
        }
Пример #4
0
        public static void handleCommad(scPlayer sPly, string Text, List<Command> validCommands, List<string> validText, List<List<string>> validArgs, bool CanBypassPermissions)
        {
            TShock.Utils.SendLogs(string.Format("{0} executed ShortCommand: {1}.", sPly.tsPly.Name, Text), Color.Red);

            var oldGroup = sPly.tsPly.Group;
            var superGroup = new SuperAdminGroup();
            if (CanBypassPermissions)
                sPly.tsPly.Group = superGroup;

            for (int i = 0; i < validCommands.Count; i++)
            {
                Command cmd = validCommands[i];
                string cmdText = validText[i];
                List<string> args = validArgs[i];

                cmd.Run(cmdText, sPly.tsPly, args);

                if (CanBypassPermissions && sPly.tsPly.Group != superGroup)
                {
                    oldGroup = sPly.tsPly.Group;
                    sPly.tsPly.Group = superGroup;
                }
            }

            if (CanBypassPermissions)
                sPly.tsPly.Group = oldGroup;
        }