1using Microsoft.Xna.Framework;
 
    3using System.Collections.Generic;
 
   14        internal static readonly IDictionary<string, List<ModCommand>> Commands = 
new Dictionary<string, List<ModCommand>>(StringComparer.OrdinalIgnoreCase);
 
   18                if (Main.netMode == 2)
 
   20                else if (Main.netMode == 0)
 
   23            return (callerType & commandType) != 0;
 
   27            List<ModCommand> cmdList;
 
   28            if (!Commands.TryGetValue(cmd.
Command, out cmdList))
 
   29                Commands.Add(cmd.
Command, cmdList = 
new List<ModCommand>());
 
   34        internal static void Unload() {
 
   42        internal static bool GetCommand(CommandCaller caller, 
string name, out ModCommand mc) {
 
   43            string modName = 
null;
 
   44            if (name.Contains(
':')) {
 
   45                var split = name.Split(
':');
 
   52            List<ModCommand> cmdList;
 
   53            if (!Commands.TryGetValue(name, out cmdList))
 
   56            cmdList = cmdList.Where(c => 
Matches(c.Type, caller.CommandType)).ToList();
 
   57            if (cmdList.Count == 0)
 
   60            if (modName != 
null) {
 
   61                Mod mod = ModLoader.GetMod(modName);
 
   63                    caller.Reply(
"Unknown Mod: " + modName, Color.Red);
 
   66                    mc = cmdList.SingleOrDefault(c => c.mod == mod);
 
   68                        caller.Reply(
"Mod: " + modName + 
" does not have a " + name + 
" command.", Color.Red);
 
   71            else if (cmdList.Count > 1) {
 
   72                caller.Reply(
"Multiple definitions of command /" + name + 
". Try:", Color.Red);
 
   73                foreach (var c 
in cmdList)
 
   74                    caller.Reply(c.mod.Name + 
":" + c.Command, Color.LawnGreen);
 
   82        internal static bool HandleCommand(
string input, CommandCaller caller) {
 
   83            var args = input.TrimEnd().Split(
' ');
 
   85            args = args.Skip(1).ToArray();
 
   91                name = name.Substring(1);
 
   95            if (!GetCommand(caller, name, out mc))
 
  102                mc.Action(caller, input, args);
 
  105                var ue = e as UsageException;
 
  107                    caller.Reply(ue.msg, ue.color);
 
  109                    caller.Reply(
"Usage: " + mc.Usage, Color.Red);
 
  115            var list = 
new List<Tuple<string, string>>();
 
  116            foreach (var entry 
in Commands) {
 
  117                var cmdList = entry.Value.Where(mc => 
Matches(mc.Type, type)).ToList();
 
  118                foreach (var mc 
in cmdList) {
 
  120                    if (cmdList.Count > 1)
 
  121                        cmd = mc.mod.Name + 
":" + cmd;
 
  123                    list.Add(Tuple.Create(cmd, mc.Description));
 
This serves as the central class from which ModCommand functions are supported and carried out.
 
static bool Matches(CommandType commandType, CommandType callerType)
 
static List< Tuple< string, string > > GetHelp(CommandType type)
 
This class represents a chat or console command. Use the CommandType to specify the scope of the comm...
 
abstract string Command
The desired text to trigger this command.
 
CommandType
A flag enum representing context where this command operates.