From f4526029124ba36cfcb87f96b42ddc9d1bbeb2c1 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Fri, 11 Aug 2017 16:29:06 +1000 Subject: [PATCH] Tempbans now use UTC timestamp, for consistency with other timestamps stored in files. --- MCGalaxy/Player/Ban.cs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/MCGalaxy/Player/Ban.cs b/MCGalaxy/Player/Ban.cs index a42a78e67..efae2d799 100644 --- a/MCGalaxy/Player/Ban.cs +++ b/MCGalaxy/Player/Ban.cs @@ -35,17 +35,24 @@ 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) { if (reason == null) reason = "-"; - return banner + " " + expiry.Ticks + " " + reason; + return banner + " " + expiry.ToUnixTime() + " " + 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); + + // Timestamp used to be raw DateTime ticks, is now UTC timestamp + long timestamp = long.Parse(parts[1]); + try { + expiry = timestamp.FromUnixTime(); + } catch (ArgumentOutOfRangeException) { + expiry = new DateTime(long.Parse(parts[1]), DateTimeKind.Utc); + } reason = parts.Length > 2 ? parts[2] : ""; } @@ -70,11 +77,11 @@ namespace MCGalaxy { static string FormatDate() { DateTime now = DateTime.Now; - return now.DayOfWeek + "%20" + now.Day + "%20" + now.Month + + return now.DayOfWeek + "%20" + now.Day + "%20" + now.Month + "%20" + now.Year + ",%20at%20" + now.Hour + ":" + now.Minute; } - static void AddBanEntry(string pl, string who, string reason, + static void AddBanEntry(string pl, string who, string reason, string stealth, string datetime, string oldrank) { string data = pl + " " + who + " " + reason + " " + stealth + " " + datetime + " " + oldrank; bans.Append(data);