Avoid checking text/bans.txt twice when finding ban information for a user, also fix whois/whowas showing the escaped %20 instead of the space characters.

This commit is contained in:
UnknownShadow200 2016-04-08 12:21:12 +10:00
parent d1b09a5254
commit 9f9396a54b
8 changed files with 65 additions and 97 deletions

View File

@ -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, "> > 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, "> > logged in &a" + who.totalLogins + " %Stimes, &c" + who.totalKicked + " %Sof which ended in a kick.");
Player.SendMessage(p, "> > " + Awards.awardAmount(who.name) + " awards"); 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]); Player.SendMessage(p, "> > is banned for " + data[1] + " by " + data[0]);
}
if (who.isDev) Player.SendMessage(p, "> > Player is a &9Developer"); if (who.isDev) Player.SendMessage(p, "> > Player is a &9Developer");
else if (who.isMod) Player.SendMessage(p, "> > Player is a &9MCGalaxy Moderator"); else if (who.isMod) Player.SendMessage(p, "> > Player is a &9MCGalaxy Moderator");

View File

@ -61,10 +61,9 @@ namespace MCGalaxy.Commands
Player.SendMessage(p, "> > first logged into the server on &a" + target.firstLogin); 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, "> > logged in &a" + target.logins + " %Stimes, &c" + target.kicks + " %Sof which ended in a kick.");
Player.SendMessage(p, "> > " + Awards.awardAmount(message) + " awards"); 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]); 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"); 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"); else if (Server.Mods.ContainsInsensitive(message)) Player.SendMessage(p, "> > Player is a &9MCGalaxy Moderator");

View File

@ -31,7 +31,7 @@ namespace MCGalaxy.Commands {
string[] args = message.Split(trimChars, 2); string[] args = message.Split(trimChars, 2);
if (args.Length < 2) { Help(p); return; } 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 != "") if (err != "")
Player.SendMessage(p, err); Player.SendMessage(p, err);
else else

View File

@ -1,59 +1,51 @@
/* /*
Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/MCGalaxy) Copyright 2010 MCSharp team (Modified for use with MCZall/MCLawl/MCGalaxy)
Dual-licensed under the Educational Community License, Version 2.0 and Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php http://www.opensource.org/licenses/ecl2.php
http://www.gnu.org/licenses/gpl-3.0.html http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing, Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS" software distributed under the Licenses are distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses. permissions and limitations under the Licenses.
*/ */
namespace MCGalaxy.Commands namespace MCGalaxy.Commands
{ {
public sealed class CmdBaninfo : Command public sealed class CmdBaninfo : Command
{ {
public override string name { get { return "baninfo"; } } public override string name { get { return "baninfo"; } }
public override string shortcut { get { return ""; } } 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 bool museumUsable { get { return true; } }
public override LevelPermission defaultRank { get { return LevelPermission.Operator; } } public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
public CmdBaninfo() { } public CmdBaninfo() { }
public override void Use(Player p, string message) public override void Use(Player p, string message) {
{ if (message == "" || message.Length <= 3) { Help(p); return; }
string[] data;
if (message == "") { Help(p); return; } string[] data = Ban.GetBanData(message);
if (message.Length <= 3) { Help(p); } if (data != null) {
else Player.SendMessage(p, "&9User: &e" + message);
{ Player.SendMessage(p, "&9Banned by: &e" + data[0]);
if (Ban.IsBanned(message)) Player.SendMessage(p, "&9Reason: &e" + data[1]);
{ Player.SendMessage(p, "&9Date and time: &e" + data[2]);
data = Ban.GetBanData(message); Player.SendMessage(p, "&9Old rank: &e" + data[3]);
// string[] end = { bannedby, reason, timedate, oldrank, stealth }; string stealth = data[4] == "true" ? "&aYes" : "&cNo";
// usefull to know :-) Player.SendMessage(p, "&9Stealth banned: " + stealth);
string reason = data[1].Replace("%20", " "); } else if (!Group.findPerm(LevelPermission.Banned).playerList.Contains(message)) {
string datetime = data[2].Replace("%20", " "); Player.SendMessage(p, "That player isn't banned");
Player.SendMessage(p, "&9User: &e" + message); } else if (data == null) {
Player.SendMessage(p, "&9Banned by: &e" + data[0]); Player.SendMessage(p, "Couldn't find ban info about " + message + ".");
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 Help(Player p)
{ public override void Help(Player p) {
Player.SendMessage(p, "/baninfo <player> - returns info about banned player."); Player.SendMessage(p, "/baninfo <player> - returns info about banned player.");
} }
} }

View File

@ -54,8 +54,8 @@ namespace MCGalaxy.Commands {
Server.tempBans.Add(tBan); Server.tempBans.Add(tBan);
if (who != null) { if (who != null) {
string reason = String.IsNullOrEmpty(tBan.reason) ? "" string reason = String.IsNullOrEmpty(tBan.reason) ? ""
: " - (" + tBan.reason + ")"; : " - (" + tBan.reason + ")";
who.Kick("Banned for " + minutes + " minutes!" + reason); who.Kick("Banned for " + minutes + " minutes!" + reason);
} }
Player.SendMessage(p, "Temp banned " + target + " for " + minutes + " minutes."); Player.SendMessage(p, "Temp banned " + target + " for " + minutes + " minutes.");

View File

@ -59,22 +59,19 @@ namespace MCGalaxy {
} }
/// <summary> Gives info about the ban of user, as a string array of /// <summary> Gives info about the ban of user, as a string array of
/// { banned by, ban reason, stealth ban, date and time, previous rank }. </summary> /// {banned by, ban reason, date and time, previous rank, stealth},
/// or null if no ban data was found. </summary>
public static string[] GetBanData(string who) { public static string[] GetBanData(string who) {
who = who.ToLower(); who = who.ToLower();
string bannedby = "", reason = "", timedate = "", oldrank = "", stealth = "";
foreach (string line in File.ReadAllLines("text/bans.txt")) { foreach (string line in File.ReadAllLines("text/bans.txt")) {
string[] parts = line.Split(' '); string[] parts = line.Split(' ');
if (parts.Length <= 5) continue; if (parts.Length <= 5 || parts[1] != who) continue;
if (parts[1] == who) {
bannedby = parts[0]; parts[2] = CP437Reader.ConvertToRaw(parts[2]).Replace("%20", " ");
reason = CP437Reader.ConvertToRaw(parts[2]); parts[4] = parts[4].Replace("%20", " ");
stealth = parts[3]; return new[] { parts[0], parts[2], parts[4], parts[5], parts[3] };
timedate = parts[4];
oldrank = parts[5];
}
} }
return new[] { bannedby, reason, timedate, oldrank, stealth }; return null;
} }
/// <summary> Unbans the given user, returning whether the player was originally banned. /// <summary> Unbans the given user, returning whether the player was originally banned.
@ -97,6 +94,7 @@ namespace MCGalaxy {
/// <summary> Change the ban reason for the given user. </summary> /// <summary> Change the ban reason for the given user. </summary>
public static string EditReason(string who, string reason) { public static string EditReason(string who, string reason) {
who = who.ToLower(); who = who.ToLower();
reason = reason.Replace(" ", "%20");
bool found = false; bool found = false;
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();

View File

@ -312,8 +312,8 @@ namespace MCGalaxy {
if (tBan.expiryTime < DateTime.UtcNow) { if (tBan.expiryTime < DateTime.UtcNow) {
Server.tempBans.Remove(tBan); Server.tempBans.Remove(tBan);
} else { } else {
string reason = String.IsNullOrEmpty(tBan.reason) ? "" : string reason = String.IsNullOrEmpty(tBan.reason) ? "" :
" (" + tBan.reason + ")"; " (" + tBan.reason + ")";
Kick("You're still temp banned!" + reason, true); Kick("You're still temp banned!" + reason, true);
} }
} catch { } } catch { }
@ -327,8 +327,8 @@ namespace MCGalaxy {
if (Group.findPlayerGroup(name) == Group.findPerm(LevelPermission.Banned)) { if (Group.findPlayerGroup(name) == Group.findPerm(LevelPermission.Banned)) {
if (!Server.useWhitelist || !onWhitelist) { 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); Kick("Banned for \"" + data[1] + "\" by " + data[0], true);
} else { } else {
Kick(Server.customBanMessage, true); Kick(Server.customBanMessage, true);

View File

@ -360,7 +360,6 @@ namespace MCGalaxy
CheckFile("Newtonsoft.Json.dll"); CheckFile("Newtonsoft.Json.dll");
CheckFile("LibNoise.dll"); CheckFile("LibNoise.dll");
//UpdateGlobalSettings();
if (!Directory.Exists("properties")) Directory.CreateDirectory("properties"); if (!Directory.Exists("properties")) Directory.CreateDirectory("properties");
if (!Directory.Exists("levels")) Directory.CreateDirectory("levels"); if (!Directory.Exists("levels")) Directory.CreateDirectory("levels");
if (!Directory.Exists("bots")) Directory.CreateDirectory("bots"); 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/transexceptions.txt")) File.CreateText("text/transexceptions.txt").Dispose();
if (!File.Exists("text/gcaccepted.txt")) File.CreateText("text/gcaccepted.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(); 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")) Directory.CreateDirectory("extra");
if (!Directory.Exists("extra/undo")) Directory.CreateDirectory("extra/undo"); if (!Directory.Exists("extra/undo")) Directory.CreateDirectory("extra/undo");
@ -407,15 +393,10 @@ namespace MCGalaxy
catch { } catch { }
Chat.LoadCustomTokens(); Chat.LoadCustomTokens();
if (File.Exists("text/emotelist.txt")) if (File.Exists("text/emotelist.txt")) {
{
foreach (string s in File.ReadAllLines("text/emotelist.txt")) foreach (string s in File.ReadAllLines("text/emotelist.txt"))
{
Player.emoteList.Add(s); Player.emoteList.Add(s);
} } else {
}
else
{
File.Create("text/emotelist.txt").Dispose(); File.Create("text/emotelist.txt").Dispose();
} }
@ -535,19 +516,18 @@ namespace MCGalaxy
if (p == null || p == "") if (p == null || p == "")
return "Error"; return "Error";
var whois = new WhoWas(p); 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; whois.banned = true;
else else
whois.banned = Ban.IsBanned(p); 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); return JsonConvert.SerializeObject(whois, Formatting.Indented);
} }
catch(Exception e) catch(Exception e)