diff --git a/MCGalaxy/Blocks/BlockPerms.cs b/MCGalaxy/Blocks/BlockPerms.cs index 89569cc91..c8d2adf00 100644 --- a/MCGalaxy/Blocks/BlockPerms.cs +++ b/MCGalaxy/Blocks/BlockPerms.cs @@ -61,7 +61,7 @@ namespace MCGalaxy.Blocks { } public void MessageCannotUse(Player p, string action) { - Player.Message(p, "Only {0} can {1} {2}", + Player.Message(p, "Only {0} can {1} {2}", Describe(), action, Block.GetName(p, ID)); } @@ -92,8 +92,9 @@ namespace MCGalaxy.Blocks { // Custom permissions set by the user. if (File.Exists(Paths.BlockPermsFile)) { - string[] lines = File.ReadAllLines(Paths.BlockPermsFile); - ProcessLines(lines); + using (StreamReader r = new StreamReader(Paths.BlockPermsFile)) { + ProcessLines(r); + } } else { Save(); } @@ -103,9 +104,11 @@ namespace MCGalaxy.Blocks { } } - static void ProcessLines(string[] lines) { + static void ProcessLines(StreamReader r) { string[] args = new string[4]; - foreach (string line in lines) { + string line; + + while ((line = r.ReadLine()) != null) { if (line.Length == 0 || line[0] == '#') continue; // Format - ID : Lowest : Disallow : Allow line.Replace(" ", "").FixedSplit(args, ':'); diff --git a/MCGalaxy/Commands/CommandExtraPerms.cs b/MCGalaxy/Commands/CommandExtraPerms.cs index 25c95c67e..d43331ac1 100644 --- a/MCGalaxy/Commands/CommandExtraPerms.cs +++ b/MCGalaxy/Commands/CommandExtraPerms.cs @@ -109,36 +109,37 @@ namespace MCGalaxy.Commands { lock (ioLock) { if (!File.Exists(Paths.CmdExtraPermsFile)) Save(); - LoadCore(); + using (StreamReader r = new StreamReader(Paths.CmdExtraPermsFile)) { + ProcessLines(r); + } } } - static void LoadCore() { + static void ProcessLines(StreamReader r) { string[] args = new string[5]; - using (StreamReader r = new StreamReader(Paths.CmdExtraPermsFile)) { - string line; - while ((line = r.ReadLine()) != null) { - if (line.Length == 0 || line[0] == '#' || line.IndexOf(':') == -1) continue; - // Format - Name:Num : Lowest : Disallow : Allow - line.Replace(" ", "").FixedSplit(args, ':'); + string line; + + while ((line = r.ReadLine()) != null) { + if (line.Length == 0 || line[0] == '#' || line.IndexOf(':') == -1) continue; + // Format - Name:Num : Lowest : Disallow : Allow + line.Replace(" ", "").FixedSplit(args, ':'); + + try { + LevelPermission min; + List allowed, disallowed; - try { - LevelPermission min; - List allowed, disallowed; - - // Old format - Name:Num : Lowest : Description - if (IsDescription(args[3])) { - min = (LevelPermission)int.Parse(args[2]); - allowed = null; disallowed = null; - } else { - Deserialise(args, 2, out min, out allowed, out disallowed); - } - - Set(args[0], int.Parse(args[1]), "", min, allowed, disallowed); - } catch (Exception ex) { - Logger.Log(LogType.Warning, "Hit an error on the extra command perms " + line); - Logger.LogError(ex); + // Old format - Name:Num : Lowest : Description + if (IsDescription(args[3])) { + min = (LevelPermission)int.Parse(args[2]); + allowed = null; disallowed = null; + } else { + Deserialise(args, 2, out min, out allowed, out disallowed); } + + Set(args[0], int.Parse(args[1]), "", min, allowed, disallowed); + } catch (Exception ex) { + Logger.Log(LogType.Warning, "Hit an error on the extra command perms " + line); + Logger.LogError(ex); } } } diff --git a/MCGalaxy/Commands/CommandPerms.cs b/MCGalaxy/Commands/CommandPerms.cs index 8f9765044..cb66c27ae 100644 --- a/MCGalaxy/Commands/CommandPerms.cs +++ b/MCGalaxy/Commands/CommandPerms.cs @@ -97,8 +97,9 @@ namespace MCGalaxy.Commands { } if (File.Exists(Paths.CmdPermsFile)) { - string[] lines = File.ReadAllLines(Paths.CmdPermsFile); - ProcessLines(lines); + using (StreamReader r = new StreamReader(Paths.CmdPermsFile)) { + ProcessLines(r); + } } else { Save(); } @@ -108,9 +109,11 @@ namespace MCGalaxy.Commands { } } - static void ProcessLines(string[] lines) { + static void ProcessLines(StreamReader r) { string[] args = new string[4]; - foreach (string line in lines) { + string line; + + while ((line = r.ReadLine()) != null) { if (line.Length == 0 || line[0] == '#') continue; // Format - Name : Lowest : Disallow : Allow line.Replace(" ", "").FixedSplit(args, ':'); @@ -120,7 +123,7 @@ namespace MCGalaxy.Commands { List allowed, disallowed; Deserialise(args, 1, out min, out allowed, out disallowed); - Set(args[0], min, allowed, disallowed); + Set(args[0], min, allowed, disallowed); } catch { Logger.Log(LogType.Warning, "Hit an error on the command " + line); continue; } diff --git a/MCGalaxy/Commands/Moderation/CmdReport.cs b/MCGalaxy/Commands/Moderation/CmdReport.cs index 8a730ad25..422d8b432 100644 --- a/MCGalaxy/Commands/Moderation/CmdReport.cs +++ b/MCGalaxy/Commands/Moderation/CmdReport.cs @@ -148,7 +148,7 @@ namespace MCGalaxy.Commands.Moderation { List reports = new List(); if (File.Exists("extra/reported/" + target + ".txt")) { - reports = new List(File.ReadAllLines("extra/reported/" + target + ".txt")); + reports = Utils.ReadAllLinesList("extra/reported/" + target + ".txt"); } ItemPerms checkPerms = CommandExtraPerms.Find(name, 1); diff --git a/MCGalaxy/Commands/building/CmdReplaceAll.cs b/MCGalaxy/Commands/building/CmdReplaceAll.cs index 001682bc4..9aff5c7c6 100644 --- a/MCGalaxy/Commands/building/CmdReplaceAll.cs +++ b/MCGalaxy/Commands/building/CmdReplaceAll.cs @@ -30,8 +30,8 @@ namespace MCGalaxy.Commands.Building { public override LevelPermission defaultRank { get { return LevelPermission.Admin; } } public override void Use(Player p, string message) { - BrushArgs args = new BrushArgs(p, message.ToLower(), Block.Air); - Brush brush = BrushFactory.Find("replace").Construct(args); + BrushArgs args = new BrushArgs(p, message, Block.Air); + Brush brush = BrushFactory.Find("Replace").Construct(args); if (brush == null) return; Vec3S32 max = new Vec3S32(p.level.Width - 1, p.level.Height - 1, p.level.Length - 1); diff --git a/MCGalaxy/Config/PropertiesFile.cs b/MCGalaxy/Config/PropertiesFile.cs index cb144afe0..24b5be954 100644 --- a/MCGalaxy/Config/PropertiesFile.cs +++ b/MCGalaxy/Config/PropertiesFile.cs @@ -38,9 +38,9 @@ namespace MCGalaxy { char separator = '=', bool trimValue = true) { if (!File.Exists(path)) return false; - using (StreamReader reader = new StreamReader(path)) { + using (StreamReader r = new StreamReader(path)) { string line, key, value; - while ((line = reader.ReadLine()) != null) { + while ((line = r.ReadLine()) != null) { ParseLine(line, separator, out key, out value); if (key == null) continue; diff --git a/MCGalaxy/Drawing/BrushFactories/FrequencyBrushes.cs b/MCGalaxy/Drawing/BrushFactories/FrequencyBrushes.cs index 04e7cd4f7..23b04903c 100644 --- a/MCGalaxy/Drawing/BrushFactories/FrequencyBrushes.cs +++ b/MCGalaxy/Drawing/BrushFactories/FrequencyBrushes.cs @@ -22,12 +22,12 @@ using BlockID = System.UInt16; namespace MCGalaxy.Drawing.Brushes { - /// Contains helper methods for brushes that have blocks with + /// Contains helper methods for brushes that have blocks with /// optional frequency counts (e.g. random and cloudy brushes) public static class FrequencyBrush { public static BlockID[] GetBlocks(BrushArgs args, out int[] count, - Predicate argFilter, Predicate argHandler) { + Predicate argFilter, Predicate argHandler) { string[] parts = args.Message.SplitSpaces(); Player p = args.Player; BlockID[] blocks; @@ -45,18 +45,14 @@ namespace MCGalaxy.Drawing.Brushes { continue; } - BlockID block; - int sepIndex = parts[i].IndexOf('/'); - string name = sepIndex >= 0 ? parts[i].Substring(0, sepIndex) : parts[i]; - if (!CommandParser.GetBlockIfAllowed(p, name, out block, true)) return null; + int sepIndex = parts[i].IndexOf('/'); + string arg = sepIndex >= 0 ? parts[i].Substring(0, sepIndex) : parts[i]; + if (!CommandParser.GetBlockIfAllowed(p, arg, out blocks[j], true)) return null; - blocks[j] = block; - if (sepIndex < 0) { j++; continue; } - - int chance = 0; - if (!CommandParser.GetInt(p, parts[i].Substring(sepIndex + 1), "Frequency", ref chance, 1, 10000)) return null; - - count[j] = chance; + if (sepIndex >= 0) { + arg = parts[i].Substring(sepIndex + 1); + if (!CommandParser.GetInt(p, arg, "Frequency", ref count[j], 1, 10000)) return null; + } j++; } return blocks; @@ -96,7 +92,7 @@ namespace MCGalaxy.Drawing.Brushes { } public sealed class RandomBrushFactory : BrushFactory { - public override string Name { get { return "Random"; } } + public override string Name { get { return "Random"; } } public override string[] Help { get { return HelpString; } } static string[] HelpString = new string[] { diff --git a/MCGalaxy/Games/CTF/CtfGame.Round.cs b/MCGalaxy/Games/CTF/CtfGame.Round.cs index 86fa19eb9..6498dc5c3 100644 --- a/MCGalaxy/Games/CTF/CtfGame.Round.cs +++ b/MCGalaxy/Games/CTF/CtfGame.Round.cs @@ -41,7 +41,7 @@ namespace MCGalaxy.Games { if (Running) EndRound(); if (Running) VoteAndMoveToNextMap(); } - + protected override bool SetMap(string map) { bool success = base.SetMap(map); if (success) UpdateMapConfig(); diff --git a/MCGalaxy/Player/Group/Group.cs b/MCGalaxy/Player/Group/Group.cs index c43257f8f..06e1bf641 100644 --- a/MCGalaxy/Player/Group/Group.cs +++ b/MCGalaxy/Player/Group/Group.cs @@ -46,23 +46,23 @@ namespace MCGalaxy { public string Color; public string ColoredName { get { return Color + Name; } } - [ConfigInt("Limit", null, 0)] + [ConfigInt("Limit", null, 0, 0)] public int DrawLimit; - [ConfigInt("MaxUndo", null, 0)] + [ConfigInt("MaxUndo", null, 0, 0)] public int MaxUndo; [ConfigString("MOTD", null, "", true)] public string MOTD = ""; [ConfigInt("GenVolume", null, mapGenLimit)] public int GenVolume = mapGenLimit; - [ConfigInt("OSMaps", null, 3)] + [ConfigInt("OSMaps", null, 3, 0)] public int OverseerMaps = 3; [ConfigBool("AfkKicked", null, true)] public bool AfkKicked = true; - [ConfigInt("AfkKickMinutes", null, 45)] + [ConfigInt("AfkKickMinutes", null, 45, 0)] public int AfkKickMinutes = 45; [ConfigString("Prefix", null, "", true)] public string Prefix = ""; - [ConfigInt("CopySlots", null, 0)] + [ConfigInt("CopySlots", null, 0, 0)] public int CopySlots = 1; [ConfigString("Filename", null, "", true, ".,_-+=")] internal string filename; diff --git a/MCGalaxy/Player/Player.Handlers.cs b/MCGalaxy/Player/Player.Handlers.cs index 4d3d4038f..7c17b90ed 100644 --- a/MCGalaxy/Player/Player.Handlers.cs +++ b/MCGalaxy/Player/Player.Handlers.cs @@ -683,7 +683,10 @@ namespace MCGalaxy { byte bindIndex; if (byte.TryParse(cmdName, out bindIndex) && bindIndex < CmdBindings.Length) { - if (CmdArgsBindings[bindIndex] == null) { SendMessage("No command is bound to: /" + cmdName); return null; } + if (CmdArgsBindings[bindIndex] == null) { + SendMessage("No command is bound to: %T/" + cmdName); return null; + } + cmdName = CmdBindings[bindIndex]; cmdArgs = CmdArgsBindings[bindIndex] + " " + cmdArgs; cmdArgs = cmdArgs.TrimEnd(' '); @@ -695,7 +698,7 @@ namespace MCGalaxy { Command command = Command.Find(cmdName); if (command == null) { if (Block.Parse(this, cmdName) != Block.Invalid) { - cmdArgs = cmdName.ToLower(); cmdName = "mode"; + cmdArgs = cmdName; cmdName = "mode"; command = Command.Find("Mode"); } else { Logger.Log(LogType.CommandUsage, "{0} tried to use unknown command: /{1} {2}", name, cmdName, cmdArgs); diff --git a/MCGalaxy/Scripting/Scripting.cs b/MCGalaxy/Scripting/Scripting.cs index c5f87d924..cdeb934bc 100644 --- a/MCGalaxy/Scripting/Scripting.cs +++ b/MCGalaxy/Scripting/Scripting.cs @@ -34,10 +34,8 @@ namespace MCGalaxy.Scripting { public const string DllDir = "extra/commands/dll/"; public const string ErrorPath = "logs/errors/compiler.log"; - static readonly string divider = new string('-', 25); + static readonly string divider = new string('-', 25); protected CodeDomProvider compiler; - protected CompilerParameters args = new CompilerParameters(); - protected CompilerResults results; public abstract string Ext { get; } public abstract string ProviderName { get; } @@ -94,7 +92,7 @@ namespace MCGalaxy.Scripting { args.OutputAssembly = dstPath; List source = ReadSourceCode(srcPath, args); - results = CompileSource(source.Join(Environment.NewLine), args); + CompilerResults results = CompileSource(source.Join(Environment.NewLine), args); if (!results.Errors.HasErrors) return true; sb = new StringBuilder(); diff --git a/MCGalaxy/Server/BackupDB.cs b/MCGalaxy/Server/BackupDB.cs index 1ed28d690..e0090043e 100644 --- a/MCGalaxy/Server/BackupDB.cs +++ b/MCGalaxy/Server/BackupDB.cs @@ -109,11 +109,11 @@ namespace MCGalaxy { } } - static string NextStatement(StreamReader reader, List buffer) { + static string NextStatement(StreamReader r, List buffer) { buffer.Clear(); string line = null; - while ((line = reader.ReadLine()) != null) { + while ((line = r.ReadLine()) != null) { if (line.StartsWith("--")) continue; // comment line = line.Trim(); if (line.Length == 0) continue; // whitespace diff --git a/MCGalaxy/Server/Tasks/UpgradeTasks.cs b/MCGalaxy/Server/Tasks/UpgradeTasks.cs index 50ca61b2e..0d3550244 100644 --- a/MCGalaxy/Server/Tasks/UpgradeTasks.cs +++ b/MCGalaxy/Server/Tasks/UpgradeTasks.cs @@ -151,8 +151,8 @@ namespace MCGalaxy.Tasks { if (!File.Exists(Paths.TempRanksFile)) return; // Check if empty, or not old form - using (StreamReader reader = new StreamReader(Paths.TempRanksFile)) { - string line = reader.ReadLine(); + using (StreamReader r = new StreamReader(Paths.TempRanksFile)) { + string line = r.ReadLine(); if (line == null) return; string[] parts = line.SplitSpaces(); if (parts.Length < 9) return;