Example #1
0
		internal bool InvokeServerCommand(string command)
		{
			CommandEventArgs args = new CommandEventArgs
			{
				Command = command
			};

			this.ServerCommand.Invoke(args);
			return args.Handled;
		}
Example #2
0
        /// <summary>
        /// Called when a command is issued from the server console.
        /// </summary>
        /// <param name="args">The CommandEventArgs object</param>
        private void ServerHooks_OnCommand(CommandEventArgs args)
        {
            if (args.Handled)
                return;

            // Damn you ThreadStatic and Redigit
            if (Main.rand == null)
            {
                Main.rand = new Random();
            }
            if (WorldGen.genRand == null)
            {
                WorldGen.genRand = new Random();
            }

            if (args.Command == "autosave")
            {
                Main.autoSave = Config.AutoSave = !Config.AutoSave;
                Log.ConsoleInfo("AutoSave " + (Config.AutoSave ? "Enabled" : "Disabled"));
            }
            else if (args.Command.StartsWith(Commands.Specifier) || args.Command.StartsWith(Commands.SilentSpecifier))
            {
                Commands.HandleCommand(TSPlayer.Server, args.Command);
            }
            else
            {
                Commands.HandleCommand(TSPlayer.Server, "/" + args.Command);
            }
            args.Handled = true;
        }
Example #3
0
        /// <summary>
        /// When a server command is run.
        /// </summary>
        /// <param name="cmd"></param>
        /// <param name="e"></param>
        private void ServerHooks_OnCommand(CommandEventArgs args)
        {
            if (args.Handled)
                return;

            // Damn you ThreadStatic and Redigit
            if (Main.rand == null)
            {
                Main.rand = new Random();
            }
            if (WorldGen.genRand == null)
            {
                WorldGen.genRand = new Random();
            }

            if (args.Command.StartsWith("playing") || args.Command.StartsWith("/playing"))
            {
                int count = 0;
                foreach (TSPlayer player in Players)
                {
                    if (player != null && player.Active)
                    {
                        count++;
                        TSPlayer.Server.SendInfoMessage(string.Format("{0} ({1}) [{2}] <{3}>", player.Name, player.IP,
                                                                  player.Group.Name, player.UserAccountName));
                    }
                }
                TSPlayer.Server.SendInfoMessage(string.Format("{0} players connected.", count));
            }
            else if (args.Command == "autosave")
            {
                Main.autoSave = Config.AutoSave = !Config.AutoSave;
                Log.ConsoleInfo("AutoSave " + (Config.AutoSave ? "Enabled" : "Disabled"));
            }
            else if (args.Command.StartsWith("/"))
            {
                Commands.HandleCommand(TSPlayer.Server, args.Command);
            }
            else
            {
                Commands.HandleCommand(TSPlayer.Server, "/" + args.Command);
            }
            args.Handled = true;
        }
        private void Server_Command(CommandEventArgs args)
        {
            string command = null;
            string[] arguments = null;
            MatchCollection paramMatch = null;
            int paramCount = 0;

            if (commandNameRegex.IsMatch(args.Command) == false) {
                return;
            }

            command = args.Command;
            if (commandParamRegex.IsMatch(command) == true) {
                paramMatch = commandParamRegex.Matches(command);
                paramCount = paramMatch.Count;
            }

            if (paramCount > 0) {
                arguments = new string[paramCount - 1];
                for (int i = 1; i < paramCount; i++) {
                    arguments[i - 1] = paramMatch[i].Value;
                }
            }

            ProcessCommand(commandParamRegex.Match(command).Groups[0].Value, arguments);
            args.Handled = true;
        }
Example #5
0
 /// <summary>
 /// ServerCommand callback.
 /// </summary>
 /// <param name="args"></param>
 private void OnServerCommand(CommandEventArgs args)
 {
     lock (this.m_AddonsLock)
     {
         this.m_Addons.ForEach(a =>
             {
                 var ret = a.Value.InvokeEvent("ServerCommand", args);
                 if (ret != null && ret.Length >= 1)
                 {
                     bool result;
                     if (bool.TryParse(ret[0].ToString(), out result) && result)
                         args.Handled = true;
                 }
             });
     }
 }