diff --git a/Commands/Information/CmdWhois.cs b/Commands/Information/CmdWhois.cs index 5e7713f53..d3a3b4146 100644 --- a/Commands/Information/CmdWhois.cs +++ b/Commands/Information/CmdWhois.cs @@ -52,10 +52,9 @@ namespace MCGalaxy.Commands Player.SendMessage(p, "> > first logged into the server on &a" + who.firstLogin.ToString("yyyy-MM-dd") + " at " + who.firstLogin.ToString("HH:mm:ss")); Player.SendMessage(p, "> > logged in &a" + who.totalLogins + " %Stimes, &c" + who.totalKicked + " %Sof which ended in a kick."); Player.SendMessage(p, "> > " + Awards.awardAmount(who.name) + " awards"); - if (Ban.IsBanned(who.name)) { - string[] data = Ban.GetBanData(who.name); + string[] data = Ban.GetBanData(who.name); + if (data != null) Player.SendMessage(p, "> > is banned for " + data[1] + " by " + data[0]); - } if (who.isDev) Player.SendMessage(p, "> > Player is a &9Developer"); else if (who.isMod) Player.SendMessage(p, "> > Player is a &9MCGalaxy Moderator"); diff --git a/Commands/Information/CmdWhowas.cs b/Commands/Information/CmdWhowas.cs index e21a0fd05..ee1eca13e 100644 --- a/Commands/Information/CmdWhowas.cs +++ b/Commands/Information/CmdWhowas.cs @@ -61,10 +61,9 @@ namespace MCGalaxy.Commands Player.SendMessage(p, "> > first logged into the server on &a" + target.firstLogin); Player.SendMessage(p, "> > logged in &a" + target.logins + " %Stimes, &c" + target.kicks + " %Sof which ended in a kick."); Player.SendMessage(p, "> > " + Awards.awardAmount(message) + " awards"); - if (Ban.IsBanned(message)) { - string[] data = Ban.GetBanData(message); + string[] data = Ban.GetBanData(message); + if (data != null) Player.SendMessage(p, "> > was banned by " + data[0] + " for " + data[1] + " on " + data[2]); - } if (Server.Devs.ContainsInsensitive(message)) Player.SendMessage(p, "> > Player is a &9Developer"); else if (Server.Mods.ContainsInsensitive(message)) Player.SendMessage(p, "> > Player is a &9MCGalaxy Moderator"); diff --git a/Commands/Moderation/CmdBanEdit.cs b/Commands/Moderation/CmdBanEdit.cs index b13399dbc..6881fd86d 100644 --- a/Commands/Moderation/CmdBanEdit.cs +++ b/Commands/Moderation/CmdBanEdit.cs @@ -31,7 +31,7 @@ namespace MCGalaxy.Commands { string[] args = message.Split(trimChars, 2); if (args.Length < 2) { Help(p); return; } - string err = Ban.EditReason(args[0], args[1].Replace(" ", "%20")); + string err = Ban.EditReason(args[0], args[1]); if (err != "") Player.SendMessage(p, err); else diff --git a/Commands/Moderation/CmdBaninfo.cs b/Commands/Moderation/CmdBaninfo.cs index fc645a108..685fed3fe 100644 --- a/Commands/Moderation/CmdBaninfo.cs +++ b/Commands/Moderation/CmdBaninfo.cs @@ -1,59 +1,51 @@ /* - Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/MCGalaxy) - - 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. -*/ + Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/MCGalaxy) + + 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. + */ namespace MCGalaxy.Commands { public sealed class CmdBaninfo : Command { public override string name { get { return "baninfo"; } } public override string shortcut { get { return ""; } } - public override string type { get { return CommandTypes.Moderation; } } + public override string type { get { return CommandTypes.Moderation; } } public override bool museumUsable { get { return true; } } public override LevelPermission defaultRank { get { return LevelPermission.Operator; } } public CmdBaninfo() { } - public override void Use(Player p, string message) - { - string[] data; - if (message == "") { Help(p); return; } - if (message.Length <= 3) { Help(p); } - else - { - if (Ban.IsBanned(message)) - { - data = Ban.GetBanData(message); - // string[] end = { bannedby, reason, timedate, oldrank, stealth }; - // usefull to know :-) - string reason = data[1].Replace("%20", " "); - string datetime = data[2].Replace("%20", " "); - Player.SendMessage(p, "&9User: &e" + message); - Player.SendMessage(p, "&9Banned by: &e" + data[0]); - Player.SendMessage(p, "&9Reason: &e" + reason); - Player.SendMessage(p, "&9Date and time: &e" + datetime); - Player.SendMessage(p, "&9Old rank: &e" + data[3]); - string stealth; if (data[4] == "true") stealth = "&aYes"; else stealth = "&cNo"; - Player.SendMessage(p, "&9Stealth banned: " + stealth); - } - else if (!Group.findPerm(LevelPermission.Banned).playerList.Contains(message)) Player.SendMessage(p, "That player isn't banned"); - else if (!Ban.IsBanned(message)) Player.SendMessage(p, "Couldn't find ban info about " + message + "."); + public override void Use(Player p, string message) { + if (message == "" || message.Length <= 3) { Help(p); return; } + + string[] data = Ban.GetBanData(message); + if (data != null) { + Player.SendMessage(p, "&9User: &e" + message); + Player.SendMessage(p, "&9Banned by: &e" + data[0]); + Player.SendMessage(p, "&9Reason: &e" + data[1]); + Player.SendMessage(p, "&9Date and time: &e" + data[2]); + Player.SendMessage(p, "&9Old rank: &e" + data[3]); + string stealth = data[4] == "true" ? "&aYes" : "&cNo"; + Player.SendMessage(p, "&9Stealth banned: " + stealth); + } else if (!Group.findPerm(LevelPermission.Banned).playerList.Contains(message)) { + Player.SendMessage(p, "That player isn't banned"); + } else if (data == null) { + Player.SendMessage(p, "Couldn't find ban info about " + message + "."); } } - public override void Help(Player p) - { + + public override void Help(Player p) { Player.SendMessage(p, "/baninfo - returns info about banned player."); } } diff --git a/Commands/Moderation/CmdTempBan.cs b/Commands/Moderation/CmdTempBan.cs index 7a6dd0089..ef51a51b2 100644 --- a/Commands/Moderation/CmdTempBan.cs +++ b/Commands/Moderation/CmdTempBan.cs @@ -54,8 +54,8 @@ namespace MCGalaxy.Commands { Server.tempBans.Add(tBan); if (who != null) { - string reason = String.IsNullOrEmpty(tBan.reason) ? "" - : " - (" + tBan.reason + ")"; + string reason = String.IsNullOrEmpty(tBan.reason) ? "" + : " - (" + tBan.reason + ")"; who.Kick("Banned for " + minutes + " minutes!" + reason); } Player.SendMessage(p, "Temp banned " + target + " for " + minutes + " minutes."); diff --git a/Player/Ban.cs b/Player/Ban.cs index a87a6c27a..30538ed55 100644 --- a/Player/Ban.cs +++ b/Player/Ban.cs @@ -59,22 +59,19 @@ namespace MCGalaxy { } /// Gives info about the ban of user, as a string array of - /// { banned by, ban reason, stealth ban, date and time, previous rank }. + /// {banned by, ban reason, date and time, previous rank, stealth}, + /// or null if no ban data was found. public static string[] GetBanData(string who) { who = who.ToLower(); - string bannedby = "", reason = "", timedate = "", oldrank = "", stealth = ""; foreach (string line in File.ReadAllLines("text/bans.txt")) { string[] parts = line.Split(' '); - if (parts.Length <= 5) continue; - if (parts[1] == who) { - bannedby = parts[0]; - reason = CP437Reader.ConvertToRaw(parts[2]); - stealth = parts[3]; - timedate = parts[4]; - oldrank = parts[5]; - } + if (parts.Length <= 5 || parts[1] != who) continue; + + parts[2] = CP437Reader.ConvertToRaw(parts[2]).Replace("%20", " "); + parts[4] = parts[4].Replace("%20", " "); + return new[] { parts[0], parts[2], parts[4], parts[5], parts[3] }; } - return new[] { bannedby, reason, timedate, oldrank, stealth }; + return null; } /// Unbans the given user, returning whether the player was originally banned. @@ -97,6 +94,7 @@ namespace MCGalaxy { /// Change the ban reason for the given user. public static string EditReason(string who, string reason) { who = who.ToLower(); + reason = reason.Replace(" ", "%20"); bool found = false; StringBuilder sb = new StringBuilder(); diff --git a/Player/Player.Handlers.cs b/Player/Player.Handlers.cs index 0cb2d7d7b..ab2eb1e50 100644 --- a/Player/Player.Handlers.cs +++ b/Player/Player.Handlers.cs @@ -312,8 +312,8 @@ namespace MCGalaxy { if (tBan.expiryTime < DateTime.UtcNow) { Server.tempBans.Remove(tBan); } else { - string reason = String.IsNullOrEmpty(tBan.reason) ? "" : - " (" + tBan.reason + ")"; + string reason = String.IsNullOrEmpty(tBan.reason) ? "" : + " (" + tBan.reason + ")"; Kick("You're still temp banned!" + reason, true); } } catch { } @@ -327,8 +327,8 @@ namespace MCGalaxy { if (Group.findPlayerGroup(name) == Group.findPerm(LevelPermission.Banned)) { if (!Server.useWhitelist || !onWhitelist) { - if (Ban.IsBanned(name)) { - string[] data = Ban.GetBanData(name); + string[] data = Ban.GetBanData(name); + if (data != null) { Kick("Banned for \"" + data[1] + "\" by " + data[0], true); } else { Kick(Server.customBanMessage, true); diff --git a/Server/Server.cs b/Server/Server.cs index 1cf963f3c..6d7883c5d 100644 --- a/Server/Server.cs +++ b/Server/Server.cs @@ -360,7 +360,6 @@ namespace MCGalaxy CheckFile("Newtonsoft.Json.dll"); CheckFile("LibNoise.dll"); - //UpdateGlobalSettings(); if (!Directory.Exists("properties")) Directory.CreateDirectory("properties"); if (!Directory.Exists("levels")) Directory.CreateDirectory("levels"); if (!Directory.Exists("bots")) Directory.CreateDirectory("bots"); @@ -370,19 +369,6 @@ namespace MCGalaxy if (!File.Exists("text/transexceptions.txt")) File.CreateText("text/transexceptions.txt").Dispose(); if (!File.Exists("text/gcaccepted.txt")) File.CreateText("text/gcaccepted.txt").Dispose(); if (!File.Exists("text/bans.txt")) File.CreateText("text/bans.txt").Dispose(); - // DO NOT STICK ANYTHING IN BETWEEN HERE!!!!!!!!!!!!!!! - else - { - string bantext = File.ReadAllText("text/bans.txt"); - if (!bantext.Contains("%20") && bantext != "") - { - bantext = bantext.Replace("~", "%20"); - bantext = bantext.Replace("-", "%20"); - File.WriteAllText("text/bans.txt", bantext); - } - } - - if (!Directory.Exists("extra")) Directory.CreateDirectory("extra"); if (!Directory.Exists("extra/undo")) Directory.CreateDirectory("extra/undo"); @@ -407,15 +393,10 @@ namespace MCGalaxy catch { } Chat.LoadCustomTokens(); - if (File.Exists("text/emotelist.txt")) - { + if (File.Exists("text/emotelist.txt")) { foreach (string s in File.ReadAllLines("text/emotelist.txt")) - { Player.emoteList.Add(s); - } - } - else - { + } else { File.Create("text/emotelist.txt").Dispose(); } @@ -535,19 +516,18 @@ namespace MCGalaxy if (p == null || p == "") return "Error"; var whois = new WhoWas(p); - if (whois.rank.Contains("banned")) + Group grp = Group.Find(whois.rank); + if (grp != null && grp.Permission == LevelPermission.Banned) whois.banned = true; else whois.banned = Ban.IsBanned(p); - string[] bandata; - if (whois.banned) - { - bandata = Ban.GetBanData(p); - whois.banned_by = bandata[0]; - whois.ban_reason = bandata[1].Replace("%20", " "); - whois.banned_time = bandata[2].Replace("%20", " "); - } + if (whois.banned) { + string[] bandata = Ban.GetBanData(p); + whois.banned_by = bandata[0]; + whois.ban_reason = bandata[1]; + whois.banned_time = bandata[2]; + } return JsonConvert.SerializeObject(whois, Formatting.Indented); } catch(Exception e)