diff --git a/MCGalaxy/Commands/Information/CmdRankInfo.cs b/MCGalaxy/Commands/Information/CmdRankInfo.cs index c7e2798d7..13360a0df 100644 --- a/MCGalaxy/Commands/Information/CmdRankInfo.cs +++ b/MCGalaxy/Commands/Information/CmdRankInfo.cs @@ -27,22 +27,28 @@ namespace MCGalaxy.Commands.Info { public override LevelPermission defaultRank { get { return LevelPermission.AdvBuilder; } } public override bool UseableWhenFrozen { get { return true; } } - public override void Use(Player p, string message) { - if (CheckSuper(p, message, "player name")) return; - if (message.Length == 0) message = p.name; + public override void Use(Player p, string name) { + if (CheckSuper(p, name, "player name")) return; + if (name.Length == 0) name = p.name; - List rankings = Server.RankInfo.FindMatches(p, message, "rankings"); - if (rankings == null) return; + name = PlayerInfo.FindMatchesPreferOnline(p, name); + if (name == null) return; - string target = PlayerMetaList.GetName(rankings[0]); - Player.Message(p, " Rankings for {0}:", PlayerInfo.GetColoredName(p, target)); + List rankings = Server.RankInfo.FindAllExact(name); + string target = PlayerInfo.GetColoredName(p, name); + + if (rankings.Count == 0) { + Player.Message(p, "{0} %Shas no rankings.", target); return; + } else { + Player.Message(p, " Rankings for {0}:", target); + } foreach (string line in rankings) { string[] args = line.SplitSpaces(); TimeSpan delta; string oldRank, newRank; int offset; - + if (args.Length <= 6) { delta = DateTime.UtcNow - long.Parse(args[2]).FromUnixTime(); newRank = args[3]; oldRank = args[4]; diff --git a/MCGalaxy/Commands/Moderation/CmdNotes.cs b/MCGalaxy/Commands/Moderation/CmdNotes.cs index 3e97fdb44..962902d89 100644 --- a/MCGalaxy/Commands/Moderation/CmdNotes.cs +++ b/MCGalaxy/Commands/Moderation/CmdNotes.cs @@ -35,16 +35,13 @@ namespace MCGalaxy.Commands.Moderation { name = PlayerInfo.FindMatchesPreferOnline(p, name); if (name == null) return; - List notes = new List(); - foreach (string note in Server.Notes.Find(name)) { - notes.Add(note); - } - + List notes = Server.Notes.FindAllExact(name); string target = PlayerInfo.GetColoredName(p, name); + if (notes.Count == 0) { Player.Message(p, "{0} %Shas no notes.", target); return; } else { - Player.Message(p, " Notes for {0}:", target); + Player.Message(p, " Notes for {0}:", target); } foreach (string line in notes) { diff --git a/MCGalaxy/Player/List/PlayerMetaList.cs b/MCGalaxy/Player/List/PlayerMetaList.cs index 6261f1cb6..3dd26f3f1 100644 --- a/MCGalaxy/Player/List/PlayerMetaList.cs +++ b/MCGalaxy/Player/List/PlayerMetaList.cs @@ -45,42 +45,18 @@ namespace MCGalaxy { } } - - /// Finds all lines which caselessly start with the given name. - public IEnumerable Find(string name) { - if (!File.Exists(file)) yield break; + public List FindAllExact(string name) { + List entries = new List(); + if (!File.Exists(file)) return entries; name += " "; using (StreamReader r = new StreamReader(file)) { string line; while ((line = r.ReadLine()) != null) { - if (line.CaselessStarts(name)) yield return line; + if (line.CaselessStarts(name)) entries.Add(line); } } - yield break; - } - - public List FindMatches(Player p, string name, string group) { - int matches; - return Matcher.FindMulti(p, name, out matches, AllLines(), - null, GetName, group); - } - - IEnumerable AllLines() { - if (!File.Exists(file)) yield break; - - using (StreamReader r = new StreamReader(file)) { - string line; - while ((line = r.ReadLine()) != null) { - yield return line; - } - } - yield break; - } - - public static string GetName(string line) { - int index = line.IndexOf(' '); - return index == -1 ? line : line.Substring(0, index); + return entries; } } } diff --git a/MCGalaxy/util/Utils.cs b/MCGalaxy/util/Utils.cs index f26e993c8..06ed6b896 100644 --- a/MCGalaxy/util/Utils.cs +++ b/MCGalaxy/util/Utils.cs @@ -19,6 +19,7 @@ using System; using System.Collections.Generic; using System.Globalization; using System.IO; +using System.Text; namespace MCGalaxy { public static class Utils { @@ -84,9 +85,9 @@ namespace MCGalaxy { public static List ReadAllLinesList(string path) { List lines = new List(); - using (StreamReader r = new StreamReader(path)) { - string item; - while ((item = r.ReadLine()) != null) { lines.Add(item); } + using (StreamReader r = new StreamReader(path, Encoding.UTF8)) { + string line; + while ((line = r.ReadLine()) != null) { lines.Add(line); } } return lines; }