Esempio n. 1
0
 internal void Load(Command.List commands,out string error)
 {
     groups.Clear();
     standard = null;
     int loaded = 0;
     int failed = 0;
     int cursor = Console.CursorLeft;
     error = null;
     if (!Directory.Exists("groups")) { return; }
     foreach (string file in Directory.GetFiles("groups","*."+host.Extension)) {
         string name = file.Substring(7,file.Length-host.Extension.Length-8);
         Group group = Group.Load(commands,name);
         if (group==null) { failed++; } else {
             if (group.standard) {
                 if (standard!=null) { error = "More than one standard group specified."; }
                 else { standard = group; }
             } loaded++;
             groups.Add(group.name.ToLower(),group);
         }
         Console.Write((loaded<0?-loaded:loaded)+" group"+(loaded==1?"":"s")+" loaded"+(failed==0?"":" ("+failed+" failed)")+".");
         Console.CursorLeft = cursor;
     }
     Console.Write((loaded<0?-loaded:loaded)+" group"+(loaded==1?"":"s")+" loaded"+(failed==0?"":" ("+failed+" failed)")+".");
     if (loaded==0) { error = "No groups loaded."; }
     else if (standard==null) { error = "No standard group specified."; }
 }
Esempio n. 2
0
 public Command Create(string name,string syntax,string help,UseHandler use)
 {
     int index = name.LastIndexOf(' ');
     if (index!=-1) {
         string cmd = name.Substring(0,index);
         Command supCommand = this[cmd];
         if (supCommand==null) { throw new Exception("Command '"+cmd+"' doesn't exist."); }
     } Command command = new Command(name,syntax,help,use);
     Command old = this[name];
     if (old!=null) {
         commands.Remove(name.ToLower());
         foreach (Group group in server.Groups.All)
             if (group.Commands.Contains(old)) {
             group.Commands.Remove(old);
             group.Commands.Add(command);
         }
     } commands.Add(name.ToLower(),command);
     return command;
 }
Esempio n. 3
0
 private static Group Load(Command.List commands,string name)
 {
     try {
         string filename = "groups/"+name+"."+host.Extension;
         string rootName;
         Node node = host.Load(filename,out rootName);
         if (rootName!="group") { return null; }
         string n = (string)node["name"].Value;
         if (n.ToLower()!=name.ToLower()) { return null; }
         Group group = new Group(n);
         group.standard = bool.Parse((string)node["standard"].Value);
         group.prefix = (string)node["prefix"].Value;
         group.postfix = (string)node["postfix"].Value;
         node["privileges"].ListForeach(group.LoadPrivilege);
         group.commands = commands.LoadPermissionList(node["commands"]);
         group.custom = node["custom"]??group.custom;
         return group;
     } catch { return null; }
 }