diff --git a/Commands/CommandList.cs b/Commands/CommandList.cs index 58e5f4485..390578ad0 100644 --- a/Commands/CommandList.cs +++ b/Commands/CommandList.cs @@ -16,11 +16,9 @@ permissions and limitations under the Licenses. */ using System.Collections.Generic; -using System.Linq; -namespace MCGalaxy -{ - public sealed class CommandList - { + +namespace MCGalaxy { + public sealed class CommandList { public List commands = new List(); public bool AddOtherPerms = false; @@ -54,7 +52,10 @@ namespace MCGalaxy public Command Find(string name) { name = name.ToLower(); - return commands.FirstOrDefault(cmd => cmd.name == name || cmd.shortcut == name); + foreach (Command cmd in commands) { + if (cmd.name == name || cmd.shortcut == name) return cmd; + } + return null; } public string FindShort(string shortcut) { diff --git a/Commands/CommandOtherPerms.cs b/Commands/CommandOtherPerms.cs index e62110cab..16aa78dc1 100644 --- a/Commands/CommandOtherPerms.cs +++ b/Commands/CommandOtherPerms.cs @@ -18,10 +18,8 @@ using System; using System.Collections.Generic; using System.IO; -using System.Linq; -namespace MCGalaxy { - +namespace MCGalaxy { /// These are extra permissions for certain commands public static class CommandOtherPerms { @@ -43,7 +41,10 @@ namespace MCGalaxy { } public static OtherPerms Find(Command cmd, int number = 1) { - return list.FirstOrDefault(OtPe => OtPe.cmd == cmd && OtPe.number == number); + foreach (OtherPerms perms in list) { + if (perms.cmd == cmd && perms.number == number) return perms; + } + return null; } public static void Add(Command command, int Perm, string desc, int number = 1) { diff --git a/Commands/Information/CmdUnloaded.cs b/Commands/Information/CmdUnloaded.cs index 3aa9e23dc..8846edbcd 100644 --- a/Commands/Information/CmdUnloaded.cs +++ b/Commands/Information/CmdUnloaded.cs @@ -17,7 +17,6 @@ */ using System; using System.IO; -using System.Linq; using System.Text; namespace MCGalaxy.Commands { @@ -72,8 +71,8 @@ namespace MCGalaxy.Commands { StringBuilder builder = new StringBuilder(); Level[] loaded = LevelInfo.Loaded.Items; for (int i = start; i < end; i++) { - string level = Path.GetFileNameWithoutExtension(files[i]); - if (!all && loaded.Any(l => l.name.CaselessEq(level))) continue; + string level = Path.GetFileNameWithoutExtension(files[i]); + if (!all && IsLoaded(loaded, level)) continue; LevelPermission visitP, buildP; bool loadOnGoto; @@ -85,6 +84,13 @@ namespace MCGalaxy.Commands { return builder; } + static bool IsLoaded(Level[] loaded, string level) { + foreach (Level lvl in loaded) { + if (lvl.name.CaselessEq(level)) return true; + } + return false; + } + static void RetrieveProps(string level, out LevelPermission visit, out LevelPermission build, out bool loadOnGoto) { visit = LevelPermission.Guest; diff --git a/Commands/Moderation/CmdPatrol.cs b/Commands/Moderation/CmdPatrol.cs index 7c8b7409c..0e3975089 100644 --- a/Commands/Moderation/CmdPatrol.cs +++ b/Commands/Moderation/CmdPatrol.cs @@ -2,28 +2,26 @@ Written by Jack1312 Copyright 2011 MCForge - - Dual-licensed under the Educational Community License, Version 2.0 and - the GNU General Public License, Version 3 (the "Licenses"); you may - not use this file except in compliance with the Licenses. You may - obtain a copy of the Licenses at - - http://www.opensource.org/licenses/ecl2.php - http://www.gnu.org/licenses/gpl-3.0.html - - Unless required by applicable law or agreed to in writing, - software distributed under the Licenses are distributed on an "AS IS" - BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - or implied. See the Licenses for the specific language governing - permissions and limitations under the Licenses. + + Dual-licensed under the Educational Community License, Version 2.0 and + the GNU General Public License, Version 3 (the "Licenses"); you may + not use this file except in compliance with the Licenses. You may + obtain a copy of the Licenses at + + http://www.opensource.org/licenses/ecl2.php + http://www.gnu.org/licenses/gpl-3.0.html + + Unless required by applicable law or agreed to in writing, + software distributed under the Licenses are distributed on an "AS IS" + BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + or implied. See the Licenses for the specific language governing + permissions and limitations under the Licenses. */ using System; using System.Collections.Generic; -using System.Linq; -namespace MCGalaxy.Commands -{ - public sealed class CmdPatrol : Command - { + +namespace MCGalaxy.Commands { + public sealed class CmdPatrol : Command { public override string name { get { return "patrol"; } } public override string shortcut { get { return ""; } } public override string type { get { return CommandTypes.Moderation; } } @@ -32,28 +30,33 @@ namespace MCGalaxy.Commands public override CommandPerm[] ExtraPerms { get { return new[] { new CommandPerm(LevelPermission.Guest, " and below are patrolled") }; } } - - - public override void Use(Player p, string message) - { - if (Player.IsSuper(p)) { MessageInGameOnly(p); return; } + public override void Use(Player p, string message) { + if (Player.IsSuper(p)) { MessageInGameOnly(p); return; } if (message != "") { Help(p); return; } - List getpatrol = (from pl in PlayerInfo.players where (int) pl.@group.Permission <= CommandOtherPerms.GetPerm(this) select pl.name).ToList(); - if (getpatrol.Count <= 0) - { - Player.Message(p, "There must be at least one guest online to use this command!"); - return; + List getpatrol = FindToPatrol(); + if (getpatrol.Count <= 0) { + Player.Message(p, "There must be at least one guest online to use this command!"); return; } - Random random = new Random(); - int index = random.Next(getpatrol.Count); - string value = getpatrol[index]; + + string value = getpatrol[new Random().Next(getpatrol.Count)]; Player who = PlayerInfo.FindExact(value); Command.all.Find("tp").Use(p, who.name); Player.Message(p, "Now visiting " + who.ColoredName + "%S."); } + List FindToPatrol() { + List players = new List(); + int perm = CommandOtherPerms.GetPerm(this); + Player[] online = PlayerInfo.Online.Items; + + foreach (Player p in online) { + if ((int)p.Rank <= perm) players.Add(p.name); + } + return players; + } + public override void Help(Player p) { Player.Message(p, "%T/patrol"); Player.Message(p, "%HTeleports you to a random " + Group.findPermInt(CommandOtherPerms.GetPerm(this)).name + " or lower"); diff --git a/Config/Properties.cs b/Config/Properties.cs index c7a7d085c..f54ec2bc7 100644 --- a/Config/Properties.cs +++ b/Config/Properties.cs @@ -17,7 +17,6 @@ */ using System; using System.IO; -using System.Linq; using System.Security.Cryptography; using System.Text; using System.Windows.Forms; diff --git a/util/Hasher.cs b/util/Hasher.cs index d28869e19..4146a9b58 100644 --- a/util/Hasher.cs +++ b/util/Hasher.cs @@ -17,7 +17,6 @@ */ using System; using System.IO; -using System.Linq; using System.Security.Cryptography; using System.Text; @@ -38,13 +37,13 @@ namespace MCGalaxy.Util { plainText = plainText.Replace(">", ")"); MD5 hash = MD5.Create(); - - byte[] textBuffer = Encoding.ASCII.GetBytes(plainText); - byte[] saltBuffer = Encoding.ASCII.GetBytes(salt); - - byte[] hashedTextBuffer = hash.ComputeHash(textBuffer); - byte[] hashedSaltBuffer = hash.ComputeHash(saltBuffer); - return hash.ComputeHash(hashedSaltBuffer.Concat(hashedTextBuffer).ToArray()); + byte[] saltB = hash.ComputeHash(Encoding.ASCII.GetBytes(salt)); + byte[] textB = hash.ComputeHash(Encoding.ASCII.GetBytes(plainText)); + + byte[] data = new byte[saltB.Length + textB.Length]; + Array.Copy(saltB, 0, data, 0, saltB.Length); + Array.Copy(textB, 0, data, saltB.Length, textB.Length); + return hash.ComputeHash(data); } internal static void StoreHash(string salt, string plainText) {