mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-28 07:56:20 -04:00
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:
parent
d1b09a5254
commit
9f9396a54b
@ -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");
|
||||||
|
@ -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");
|
||||||
|
@ -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
|
||||||
|
@ -26,34 +26,26 @@ namespace MCGalaxy.Commands
|
|||||||
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
|
|
||||||
{
|
|
||||||
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, "&9User: &e" + message);
|
||||||
Player.SendMessage(p, "&9Banned by: &e" + data[0]);
|
Player.SendMessage(p, "&9Banned by: &e" + data[0]);
|
||||||
Player.SendMessage(p, "&9Reason: &e" + reason);
|
Player.SendMessage(p, "&9Reason: &e" + data[1]);
|
||||||
Player.SendMessage(p, "&9Date and time: &e" + datetime);
|
Player.SendMessage(p, "&9Date and time: &e" + data[2]);
|
||||||
Player.SendMessage(p, "&9Old rank: &e" + data[3]);
|
Player.SendMessage(p, "&9Old rank: &e" + data[3]);
|
||||||
string stealth; if (data[4] == "true") stealth = "&aYes"; else stealth = "&cNo";
|
string stealth = data[4] == "true" ? "&aYes" : "&cNo";
|
||||||
Player.SendMessage(p, "&9Stealth banned: " + stealth);
|
Player.SendMessage(p, "&9Stealth banned: " + stealth);
|
||||||
}
|
} else if (!Group.findPerm(LevelPermission.Banned).playerList.Contains(message)) {
|
||||||
else if (!Group.findPerm(LevelPermission.Banned).playerList.Contains(message)) Player.SendMessage(p, "That player isn't banned");
|
Player.SendMessage(p, "That player isn't banned");
|
||||||
else if (!Ban.IsBanned(message)) Player.SendMessage(p, "Couldn't find ban info about " + message + ".");
|
} 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 <player> - returns info about banned player.");
|
Player.SendMessage(p, "/baninfo <player> - returns info about banned player.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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 null;
|
||||||
return new[] { bannedby, reason, timedate, oldrank, stealth };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <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();
|
||||||
|
|
||||||
|
@ -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);
|
||||||
|
@ -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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user