static void ReadVersion1(string[] lines, List <string> cmdNames) { foreach (string line in lines) { if (line == "" || line[0] == '#') { continue; } rankAllowance perms = new rankAllowance(); string key = line.Split('=')[0].Trim().ToLower(); string value = line.Split('=')[1].Trim().ToLower(); if (!cmdNames.Contains(key)) { Server.s.Log("Incorrect command name: " + key); } else if (Level.PermissionFromName(value) == LevelPermission.Null) { Server.s.Log("Incorrect value given for " + key + ", using default value."); } else { perms.commandName = key; perms.lowestRank = Level.PermissionFromName(value); for (int i = 0; i < allowedCommands.Count; i++) { if (allowedCommands[i].commandName == key) { allowedCommands[i] = perms; break; } } } } }
static void ReadVersion2(string[] lines, List <string> cmdNames) { char[] colon = new char[] { ':' }; foreach (string line in lines) { if (line == "" || line[0] == '#') { continue; } rankAllowance perms = new rankAllowance(); //Name : Lowest : Disallow : Allow string[] args = line.Replace(" ", "").Split(colon); if (!cmdNames.Contains(args[0])) { Server.s.Log("Incorrect command name: " + args[0]); continue; } perms.commandName = args[0]; string[] disallow = new string[0]; if (args[2] != "") { disallow = args[2].Split(','); } string[] allow = new string[0]; if (args[3] != "") { allow = args[3].Split(','); } try { perms.lowestRank = (LevelPermission)int.Parse(args[1]); foreach (string s in disallow) { perms.disallow.Add((LevelPermission)int.Parse(s)); } foreach (string s in allow) { perms.allow.Add((LevelPermission)int.Parse(s)); } } catch { Server.s.Log("Hit an error on the command " + line); continue; } for (int i = 0; i < allowedCommands.Count; i++) { if (args[0] == allowedCommands[i].commandName) { allowedCommands[i] = perms; break; } } } }
public static void fillRanks() { List <string> cmdNames = Command.all.commandNames(); allowedCommands = new List <rankAllowance>(); rankAllowance allowVar; foreach (Command cmd in Command.all.All()) { allowVar = new rankAllowance(); allowVar.commandName = cmd.name; allowVar.lowestRank = cmd.defaultRank; allowedCommands.Add(allowVar); } if (File.Exists("properties/command.properties")) { string[] lines = File.ReadAllLines("properties/command.properties"); //if (lines.Length == 0) ; // this is useless? if (lines[0] == "#Version 2") { ReadVersion2(lines, cmdNames); } else { ReadVersion1(lines, cmdNames); } } else { Save(allowedCommands); } foreach (Group grp in Group.GroupList) { grp.fillCommands(); } }
public static void fillRanks() { foundCommands = Command.all.commandNames(); allowedCommands = new List<rankAllowance>(); rankAllowance allowVar; foreach (Command cmd in Command.all.All()) { allowVar = new rankAllowance(); allowVar.commandName = cmd.name; allowVar.lowestRank = cmd.defaultRank; allowedCommands.Add(allowVar); } if (File.Exists("properties/command.properties")) { string[] lines = File.ReadAllLines("properties/command.properties"); if (lines.Length == 0) ; else if (lines[0] == "#Version 2") { string[] colon = new string[] { " : " }; foreach (string line in lines) { allowVar = new rankAllowance(); if (line != "" && line[0] != '#') { //Name : Lowest : Disallow : Allow string[] command = line.Split(colon, StringSplitOptions.None); if (!foundCommands.Contains(command[0])) { Server.s.Log("Incorrect command name: " + command[0]); continue; } allowVar.commandName = command[0]; string[] disallow = new string[0]; if (command[2] != "") disallow = command[2].Split(','); string[] allow = new string[0]; if (command[3] != "") allow = command[3].Split(','); try { allowVar.lowestRank = (LevelPermission)int.Parse(command[1]); foreach (string s in disallow) { allowVar.disallow.Add((LevelPermission)int.Parse(s)); } foreach (string s in allow) { allowVar.allow.Add((LevelPermission)int.Parse(s)); } } catch { Server.s.Log("Hit an error on the command " + line); continue; } int current = 0; foreach (rankAllowance aV in allowedCommands) { if (command[0] == aV.commandName) { allowedCommands[current] = allowVar; break; } current++; } } } } else { foreach (string line in lines) { if (line != "" && line[0] != '#') { allowVar = new rankAllowance(); string key = line.Split('=')[0].Trim().ToLower(); string value = line.Split('=')[1].Trim().ToLower(); if (!foundCommands.Contains(key)) { Server.s.Log("Incorrect command name: " + key); } else if (Level.PermissionFromName(value) == LevelPermission.Null) { Server.s.Log("Incorrect value given for " + key + ", using default value."); } else { allowVar.commandName = key; allowVar.lowestRank = Level.PermissionFromName(value); int current = 0; foreach (rankAllowance aV in allowedCommands) { if (key == aV.commandName) { allowedCommands[current] = allowVar; break; } current++; } } } } } Save(allowedCommands); } else Save(allowedCommands); foreach (Group grp in Group.GroupList) { grp.fillCommands(); } }
public static void fillRanks() { foundCommands = Command.all.commandNames(); allowedCommands = new List <rankAllowance>(); rankAllowance allowVar; foreach (Command cmd in Command.all.All()) { allowVar = new rankAllowance(); allowVar.commandName = cmd.name; allowVar.lowestRank = cmd.defaultRank; allowedCommands.Add(allowVar); } if (File.Exists("properties/command.properties")) { string[] lines = File.ReadAllLines("properties/command.properties"); if (lines.Length == 0) { ; } else if (lines[0] == "#Version 2") { string[] colon = new string[] { " : " }; foreach (string line in lines) { allowVar = new rankAllowance(); if (line != "" && line[0] != '#') { //Name : Lowest : Disallow : Allow string[] command = line.Split(colon, StringSplitOptions.None); if (!foundCommands.Contains(command[0])) { Server.s.Log("Incorrect command name: " + command[0]); continue; } allowVar.commandName = command[0]; string[] disallow = new string[0]; if (command[2] != "") { disallow = command[2].Split(','); } string[] allow = new string[0]; if (command[3] != "") { allow = command[3].Split(','); } try { allowVar.lowestRank = (LevelPermission)int.Parse(command[1]); foreach (string s in disallow) { allowVar.disallow.Add((LevelPermission)int.Parse(s)); } foreach (string s in allow) { allowVar.allow.Add((LevelPermission)int.Parse(s)); } } catch { Server.s.Log("Hit an error on the command " + line); continue; } int current = 0; foreach (rankAllowance aV in allowedCommands) { if (command[0] == aV.commandName) { allowedCommands[current] = allowVar; break; } current++; } } } } else { foreach (string line in lines) { if (line != "" && line[0] != '#') { allowVar = new rankAllowance(); string key = line.Split('=')[0].Trim().ToLower(); string value = line.Split('=')[1].Trim().ToLower(); if (!foundCommands.Contains(key)) { Server.s.Log("Incorrect command name: " + key); } else if (Level.PermissionFromName(value) == LevelPermission.Null) { Server.s.Log("Incorrect value given for " + key + ", using default value."); } else { allowVar.commandName = key; allowVar.lowestRank = Level.PermissionFromName(value); int current = 0; foreach (rankAllowance aV in allowedCommands) { if (key == aV.commandName) { allowedCommands[current] = allowVar; break; } current++; } } } } } Save(allowedCommands); } else { Save(allowedCommands); } foreach (Group grp in Group.GroupList) { grp.fillCommands(); } }
public static void LoadPermissions() { foundCommands = Command.all.commandNames(); allowedCommands = new List<rankAllowance>(); rankAllowance allowVar; foreach (Command cmd in Command.all.All()) { allowVar = new rankAllowance(); allowVar.commandName = cmd.name; allowVar.lowestRank = cmd.defaultRank; allowedCommands.Add(allowVar); } if (File.Exists("properties/command.properties")) File.Move("properties/command.properties", "properties/bc_command.config"); if (File.Exists("properties/bc_command.config")) { string[] lines = File.ReadAllLines("properties/bc_command.config"); //if (lines.Length == 0) ; // this is useless? /*else */if (lines[0] == "#Version 2") { string[] colon = new[] { " : " }; foreach (string line in lines) { allowVar = new rankAllowance(); if (line == "" || line[0] == '#') continue; //Name : Lowest : Disallow : Allow string[] command = line.Split(colon, StringSplitOptions.None); if (!foundCommands.Contains(command[0])) { Server.Log("Incorrect command name: " + command[0]); continue; } allowVar.commandName = command[0]; string[] disallow = new string[0]; if (command[2] != "") disallow = command[2].Split(','); string[] allow = new string[0]; if (command[3] != "") allow = command[3].Split(','); try { allowVar.lowestRank = (LevelPermission)int.Parse(command[1]); foreach (string s in disallow) { allowVar.disallow.Add((LevelPermission)int.Parse(s)); } foreach (string s in allow) { allowVar.allow.Add((LevelPermission)int.Parse(s)); } } catch { Server.Log("Hit an error on the command " + line); continue; } int current = 0; foreach (rankAllowance aV in allowedCommands) { if (command[0] == aV.commandName) { allowedCommands[current] = allowVar; break; } current++; } } } else { foreach (string line in lines.Where(line => line != "" && line[0] != '#')) { allowVar = new rankAllowance(); string key = line.Split('=')[0].Trim().ToLower(); string value = line.Split('=')[1].Trim().ToLower(); if (!foundCommands.Contains(key)) { Server.Log("Incorrect command name: " + key); } else if (PermissionFromName(value) == LevelPermission.Null) { Server.Log("Incorrect value given for " + key + ", using default value."); } else { allowVar.commandName = key; allowVar.lowestRank = PermissionFromName(value); int current = 0; foreach (rankAllowance aV in allowedCommands) { if (key == aV.commandName) { allowedCommands[current] = allowVar; break; } current++; } } } } Save(allowedCommands); } else Save(allowedCommands); for (int i = 0; i < Group.getGroupList().size(); i++) { Group g = (Group)Group.getGroupList().get(i); CommandList commands = new CommandList(); foreach (rankAllowance aV in allowedCommands.Where(aV => (aV.lowestRank <= (LevelPermission)g.permissionlevel && !aV.disallow.Contains((LevelPermission)g.permissionlevel)) || aV.allow.Contains((LevelPermission)g.permissionlevel))) commands.Add(Command.all.Find(aV.commandName)); Command.permission.Add(g, commands); } }