mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-25 14:17:29 -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, "> > 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");
|
||||
|
@ -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");
|
||||
|
@ -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
|
||||
|
@ -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 <player> - returns info about banned player.");
|
||||
}
|
||||
}
|
||||
|
@ -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.");
|
||||
|
@ -59,22 +59,19 @@ namespace MCGalaxy {
|
||||
}
|
||||
|
||||
/// <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) {
|
||||
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;
|
||||
}
|
||||
|
||||
/// <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>
|
||||
public static string EditReason(string who, string reason) {
|
||||
who = who.ToLower();
|
||||
reason = reason.Replace(" ", "%20");
|
||||
bool found = false;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user