mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-23 20:53:40 -04:00
Make /tempban save, better, show time left in kick message
This commit is contained in:
parent
07a1210a90
commit
44df804d3d
@ -163,8 +163,7 @@ namespace MCGalaxy.Commands {
|
||||
void SetToDefault() {
|
||||
foreach (var elem in Server.serverConfig)
|
||||
elem.Field.SetValue(null, elem.Attrib.DefaultValue);
|
||||
|
||||
Server.tempBans = new List<Server.TempBan>();
|
||||
|
||||
Server.ircafkset = new List<string>();
|
||||
Server.messages = new List<string>();
|
||||
Server.chatmod = false;
|
||||
|
@ -43,18 +43,18 @@ namespace MCGalaxy.Commands.Moderation {
|
||||
|
||||
TimeSpan time = TimeSpan.FromHours(1);
|
||||
if (args.Length > 1 && !args[1].TryParseShort(p, 'm', "temp ban for", out time)) return;
|
||||
if (time.TotalDays > 1) { Player.Message(p, "Cannot temp ban for more than a day."); return; }
|
||||
if (time.TotalSeconds < 1) { Player.Message(p, "Cannot temp ban someone for less than a second."); return; }
|
||||
|
||||
Server.TempBan tBan;
|
||||
tBan.name = target;
|
||||
tBan.reason = ModActionCmd.ExpandReason(p, reason);
|
||||
if (tBan.reason == null) return;
|
||||
reason = ModActionCmd.ExpandReason(p, reason);
|
||||
if (reason == null) return;
|
||||
string banner = p == null ? "(console)" : p.truename;
|
||||
|
||||
tBan.expiryTime = DateTime.UtcNow.Add(time);
|
||||
AddTempban(tBan);
|
||||
Server.tempBans.AddOrReplace(target,
|
||||
Ban.PackTempBanData(reason, banner, DateTime.UtcNow.Add(time)));
|
||||
Server.tempBans.Save();
|
||||
|
||||
if (who != null) {
|
||||
string kickReason = tBan.reason == "" ? "" : " - (" + tBan.reason + ")";
|
||||
string kickReason = reason == "" ? "" : " - (" + reason + ")";
|
||||
who.Kick("Banned for " + time.Shorten(true) + "." + kickReason);
|
||||
}
|
||||
|
||||
@ -63,20 +63,10 @@ namespace MCGalaxy.Commands.Moderation {
|
||||
else Player.AddNote(target, p, "T", reason);
|
||||
}
|
||||
|
||||
void AddTempban(Server.TempBan tBan) {
|
||||
for (int i = 0; i < Server.tempBans.Count; i++) {
|
||||
if (!Server.tempBans[i].name.CaselessEq(tBan.name)) continue;
|
||||
Server.tempBans[i] = tBan;
|
||||
return;
|
||||
}
|
||||
Server.tempBans.Add(tBan);
|
||||
}
|
||||
|
||||
public override void Help(Player p) {
|
||||
Player.Message(p, "%T/tempban [name] [timespan] <reason>");
|
||||
Player.Message(p, "%HBans [name] for [timespan]. Max is 1 day, default is 1 hour.");
|
||||
Player.Message(p, "%HBans [name] for [timespan]. Default is 1 hour.");
|
||||
Player.Message(p, "%H e.g. to tempban for 90 minutes, [timespan] would be %S1h30m");
|
||||
Player.Message(p, "%HTemp bans will reset on server restart");
|
||||
Player.Message(p, "%HFor <reason>, @number can be used as a shortcut for that rule.");
|
||||
}
|
||||
}
|
||||
|
@ -37,10 +37,9 @@ namespace MCGalaxy.Commands.Moderation {
|
||||
Group banned = Group.BannedRank;
|
||||
|
||||
// Check tempbans first
|
||||
foreach (Server.TempBan tban in Server.tempBans) {
|
||||
if (!tban.name.CaselessEq(name)) continue;
|
||||
|
||||
Server.tempBans.Remove(tban);
|
||||
if (Server.tempBans.Remove(name)) {
|
||||
Server.tempBans.Save();
|
||||
|
||||
Chat.MessageAll("{0} had their temporary ban lifted by {1}.", name, srcFull);
|
||||
Server.s.Log("UNBANNED: " + name + " by " + src);
|
||||
Server.IRC.Say(name + " was unbanned by " + src + ".");
|
||||
|
@ -93,12 +93,21 @@ namespace MCGalaxy.Core {
|
||||
|
||||
static bool CheckTempban(Player p) {
|
||||
try {
|
||||
Server.TempBan tBan = Server.tempBans.Find(tB => tB.name.CaselessEnds(p.name));
|
||||
if (tBan.expiryTime < DateTime.UtcNow) {
|
||||
Server.tempBans.Remove(tBan);
|
||||
string data = Server.tempBans.FindData(p.name);
|
||||
if (data == null) return true;
|
||||
|
||||
string banner, reason;
|
||||
DateTime expiry;
|
||||
Ban.UnpackTempBanData(data, out reason, out banner, out expiry);
|
||||
|
||||
if (expiry < DateTime.UtcNow) {
|
||||
Server.tempBans.Remove(p.name);
|
||||
Server.tempBans.Save();
|
||||
} else {
|
||||
string reason = String.IsNullOrEmpty(tBan.reason) ? "" :" (" + tBan.reason + ")";
|
||||
p.Kick(null, "You're still temp banned!" + reason, true);
|
||||
reason = reason == "" ? "" :" (" + reason + ")";
|
||||
string delta = (expiry - DateTime.UtcNow).Shorten(true);
|
||||
|
||||
p.Kick(null, "Banned by " + banner + " for another " + delta + reason, true);
|
||||
return false;
|
||||
}
|
||||
} catch { }
|
||||
|
@ -35,6 +35,17 @@ namespace MCGalaxy {
|
||||
|
||||
public static string FormatBan(string banner, string reason) {
|
||||
return "Banned by " + banner + ": " + reason;
|
||||
}
|
||||
|
||||
public static string PackTempBanData(string reason, string banner, DateTime expiry) {
|
||||
return banner + " " + expiry.Ticks + " " + reason;
|
||||
}
|
||||
|
||||
public static void UnpackTempBanData(string line, out string reason, out string banner, out DateTime expiry) {
|
||||
string[] parts = line.SplitSpaces(3);
|
||||
banner = parts[0];
|
||||
expiry = new DateTime(long.Parse(parts[1]), DateTimeKind.Utc);
|
||||
reason = parts.Length > 2 ? parts[2] : "";
|
||||
}
|
||||
|
||||
|
||||
|
@ -93,7 +93,7 @@ namespace MCGalaxy {
|
||||
public static CTFGame ctf = null;
|
||||
public static PlayerList bannedIP, whiteList, ircControllers, muted, invalidIds;
|
||||
public static PlayerList ignored, frozen, hidden, agreed, vip, noEmotes, lockdown;
|
||||
public static PlayerExtList jailed, models, skins, reach;
|
||||
public static PlayerExtList jailed, models, skins, reach, tempBans;
|
||||
|
||||
public static readonly List<string> Devs = new List<string>(), Mods = new List<string>();
|
||||
|
||||
@ -103,9 +103,6 @@ namespace MCGalaxy {
|
||||
);
|
||||
public static List<string> Opstats { get { return opstats; } }
|
||||
|
||||
public static List<TempBan> tempBans = new List<TempBan>();
|
||||
public struct TempBan { public string name, reason; public DateTime expiryTime; }
|
||||
|
||||
public static PerformanceCounter PCCounter = null;
|
||||
public static PerformanceCounter ProcessCounter = null;
|
||||
|
||||
|
@ -71,6 +71,7 @@ namespace MCGalaxy {
|
||||
skins = PlayerExtList.Load("extra/skins.txt");
|
||||
reach = PlayerExtList.Load("extra/reach.txt");
|
||||
invalidIds = PlayerList.Load("extra/invalidids.txt");
|
||||
tempBans = PlayerExtList.Load("text/tempbans.txt");
|
||||
|
||||
if (useWhitelist)
|
||||
whiteList = PlayerList.Load("whitelist.txt");
|
||||
|
Loading…
x
Reference in New Issue
Block a user