mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-24 05:03:34 -04:00
Try to fix issue where time component of dates saved to the DB was being saved/loaded with culture specific time separator instead of : (Thanks Fam0r)
This commit is contained in:
parent
82ba8b5054
commit
0fd9dd802b
@ -54,7 +54,7 @@ namespace MCGalaxy.Commands.Chatting
|
|||||||
}
|
}
|
||||||
|
|
||||||
Database.AddRow("Inbox" + name, "PlayerFrom, TimeSent, Contents",
|
Database.AddRow("Inbox" + name, "PlayerFrom, TimeSent, Contents",
|
||||||
p.name, DateTime.Now.ToString(Database.DateFormat), message);
|
p.name, DateTime.Now.ToInvariantDateString(), message);
|
||||||
p.CheckForMessageSpam();
|
p.CheckForMessageSpam();
|
||||||
|
|
||||||
Player target = PlayerInfo.FindExact(name);
|
Player target = PlayerInfo.FindExact(name);
|
||||||
|
@ -30,7 +30,7 @@ namespace MCGalaxy.Commands.Info
|
|||||||
public override bool UseableWhenFrozen { get { return true; } }
|
public override bool UseableWhenFrozen { get { return true; } }
|
||||||
|
|
||||||
public override void Use(Player p, string message, CommandData data) {
|
public override void Use(Player p, string message, CommandData data) {
|
||||||
string end = DateTime.Now.ToString(Database.DateFormat);
|
string end = DateTime.Now.ToInvariantDateString();
|
||||||
string start = "thismonth", name = null;
|
string start = "thismonth", name = null;
|
||||||
string[] args = message.SplitSpaces();
|
string[] args = message.SplitSpaces();
|
||||||
|
|
||||||
|
@ -146,13 +146,13 @@ namespace MCGalaxy.Commands.Maintenance {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
DateTime date;
|
DateTime dt;
|
||||||
if (!DateTime.TryParseExact(args[2], Database.DateFormat, null, 0, out date)) {
|
if (!args[2].TryParseInvariantDateString(out dt)) {
|
||||||
p.Message("Invalid date. It must be in format: " + Database.DateFormat);
|
p.Message("Invalid date. It must be in format: " + Database.DateFormat);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (who != null) setter(date);
|
if (who != null) setter(dt);
|
||||||
PlayerDB.Update(args[0], column, args[2]);
|
PlayerDB.Update(args[0], column, args[2]);
|
||||||
MessageDataChanged(p, args[0], args[1], args[2]);
|
MessageDataChanged(p, args[0], args[1], args[2]);
|
||||||
}
|
}
|
||||||
|
@ -241,7 +241,7 @@ namespace MCGalaxy.SQL
|
|||||||
|
|
||||||
string RawGetDateTime(int col) {
|
string RawGetDateTime(int col) {
|
||||||
DateTime date = GetDateTime(col);
|
DateTime date = GetDateTime(col);
|
||||||
return date.ToString(Database.DateFormat);
|
return date.ToInvariantDateString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string GetStringValue(int col) {
|
public override string GetStringValue(int col) {
|
||||||
|
@ -244,9 +244,10 @@ namespace MCGalaxy.SQL
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static DateTime ParseDBDate(string value) {
|
public static DateTime ParseDBDate(string value) {
|
||||||
DateTime date;
|
DateTime dt;
|
||||||
// prefer the exact format
|
// prefer the exact format
|
||||||
if (DateTime.TryParseExact(value, DateFormat, null, 0, out date)) return date;
|
if (value.TryParseInvariantDateString(out dt)) return dt;
|
||||||
|
|
||||||
return DateTime.Parse(value);
|
return DateTime.Parse(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ namespace MCGalaxy.DB
|
|||||||
p.FirstLogin = DateTime.Now;
|
p.FirstLogin = DateTime.Now;
|
||||||
p.TimesVisited = 1;
|
p.TimesVisited = 1;
|
||||||
|
|
||||||
string now = DateTime.Now.ToString(Database.DateFormat);
|
string now = DateTime.Now.ToInvariantDateString();
|
||||||
Database.AddRow("Players", "Name, IP, FirstLogin, LastLogin, totalLogin, Title, " +
|
Database.AddRow("Players", "Name, IP, FirstLogin, LastLogin, totalLogin, Title, " +
|
||||||
"totalDeaths, Money, totalBlocks, totalKicked, Messages, TimeSpent",
|
"totalDeaths, Money, totalBlocks, totalKicked, Messages, TimeSpent",
|
||||||
p.name, p.ip, now, now, 1, "", 0, 0, 0, 0, 0, (long)p.TotalTime.TotalSeconds);
|
p.name, p.ip, now, now, 1, "", 0, 0, 0, 0, 0, (long)p.TotalTime.TotalSeconds);
|
||||||
@ -155,11 +155,12 @@ namespace MCGalaxy.DB
|
|||||||
|
|
||||||
static DateTime ParseDateTime(ISqlRecord record, string name) {
|
static DateTime ParseDateTime(ISqlRecord record, string name) {
|
||||||
int i = record.GetOrdinal(name);
|
int i = record.GetOrdinal(name);
|
||||||
|
DateTime dt;
|
||||||
|
|
||||||
// dates are a major pain
|
// dates are a major pain
|
||||||
try {
|
|
||||||
string raw = record.GetStringValue(i);
|
string raw = record.GetStringValue(i);
|
||||||
return DateTime.ParseExact(raw, Database.DateFormat, null);
|
if (raw.TryParseInvariantDateString(out dt)) return dt;
|
||||||
} catch {
|
|
||||||
try {
|
try {
|
||||||
return record.GetDateTime(i);
|
return record.GetDateTime(i);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
@ -167,7 +168,6 @@ namespace MCGalaxy.DB
|
|||||||
return DateTime.MinValue;
|
return DateTime.MinValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
internal static long UnpackHi(long value) {
|
internal static long UnpackHi(long value) {
|
||||||
|
@ -203,10 +203,10 @@ namespace MCGalaxy.Modules.Relay.Discord
|
|||||||
Session.LastSeq = (string)sequence;
|
Session.LastSeq = (string)sequence;
|
||||||
|
|
||||||
string eventName = (string)obj["t"];
|
string eventName = (string)obj["t"];
|
||||||
object rawData;
|
|
||||||
|
|
||||||
|
object rawData;
|
||||||
obj.TryGetValue("d", out rawData);
|
obj.TryGetValue("d", out rawData);
|
||||||
JsonObject data = (JsonObject)rawData;
|
JsonObject data = rawData as JsonObject;
|
||||||
|
|
||||||
if (eventName == "READY") {
|
if (eventName == "READY") {
|
||||||
HandleReady(data);
|
HandleReady(data);
|
||||||
|
@ -665,7 +665,7 @@ namespace MCGalaxy
|
|||||||
try { //opstats patch (since 5.5.11)
|
try { //opstats patch (since 5.5.11)
|
||||||
if (Server.Opstats.CaselessContains(cmd) || (cmd.CaselessEq("review") && args.CaselessEq("next") && Server.reviewlist.Count > 0)) {
|
if (Server.Opstats.CaselessContains(cmd) || (cmd.CaselessEq("review") && args.CaselessEq("next") && Server.reviewlist.Count > 0)) {
|
||||||
Database.AddRow("Opstats", "Time, Name, Cmd, Cmdmsg",
|
Database.AddRow("Opstats", "Time, Name, Cmd, Cmdmsg",
|
||||||
DateTime.Now.ToString(Database.DateFormat), name, cmd, args);
|
DateTime.Now.ToInvariantDateString(), name, cmd, args);
|
||||||
}
|
}
|
||||||
} catch { }
|
} catch { }
|
||||||
|
|
||||||
|
@ -182,7 +182,7 @@ namespace MCGalaxy {
|
|||||||
long drawn = PlayerData.Pack(TotalDeleted, TotalDrawn);
|
long drawn = PlayerData.Pack(TotalDeleted, TotalDrawn);
|
||||||
Database.UpdateRows("Players", "IP=@0, LastLogin=@1, totalLogin=@2, totalDeaths=@3, Money=@4, " +
|
Database.UpdateRows("Players", "IP=@0, LastLogin=@1, totalLogin=@2, totalDeaths=@3, Money=@4, " +
|
||||||
"totalBlocks=@5, totalCuboided=@6, totalKicked=@7, TimeSpent=@8, Messages=@9", "WHERE Name=@10",
|
"totalBlocks=@5, totalCuboided=@6, totalKicked=@7, TimeSpent=@8, Messages=@9", "WHERE Name=@10",
|
||||||
ip, LastLogin.ToString(Database.DateFormat),
|
ip, LastLogin.ToInvariantDateString(),
|
||||||
TimesVisited, TimesDied, money, blocks,
|
TimesVisited, TimesDied, money, blocks,
|
||||||
drawn, TimesBeenKicked, (long)TotalTime.TotalSeconds, TotalMessagesSent, name);
|
drawn, TimesBeenKicked, (long)TotalTime.TotalSeconds, TotalMessagesSent, name);
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ namespace MCGalaxy
|
|||||||
bool didJoin = false;
|
bool didJoin = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
didJoin = name == null ? GotoLevel(p, lvl) : GotoMap(p, name);
|
didJoin = name == null ? GotoLevel(p, lvl, false) : GotoMap(p, name);
|
||||||
} finally {
|
} finally {
|
||||||
Interlocked.Exchange(ref p.UsingGoto, 0);
|
Interlocked.Exchange(ref p.UsingGoto, 0);
|
||||||
Server.DoGC();
|
Server.DoGC();
|
||||||
@ -50,14 +50,14 @@ namespace MCGalaxy
|
|||||||
|
|
||||||
static bool GotoMap(Player p, string name) {
|
static bool GotoMap(Player p, string name) {
|
||||||
Level lvl = LevelInfo.FindExact(name);
|
Level lvl = LevelInfo.FindExact(name);
|
||||||
if (lvl != null) return GotoLevel(p, lvl);
|
if (lvl != null) return GotoLevel(p, lvl, false);
|
||||||
|
|
||||||
if (Server.Config.AutoLoadMaps) {
|
if (Server.Config.AutoLoadMaps) {
|
||||||
string map = Matcher.FindMaps(p, name);
|
string map = Matcher.FindMaps(p, name);
|
||||||
if (map == null) return false;
|
if (map == null) return false;
|
||||||
|
|
||||||
lvl = LevelInfo.FindExact(map);
|
lvl = LevelInfo.FindExact(map);
|
||||||
if (lvl != null) return GotoLevel(p, lvl);
|
if (lvl != null) return GotoLevel(p, lvl, false);
|
||||||
return LoadOfflineLevel(p, map);
|
return LoadOfflineLevel(p, map);
|
||||||
} else {
|
} else {
|
||||||
lvl = Matcher.FindLevels(p, name);
|
lvl = Matcher.FindLevels(p, name);
|
||||||
@ -66,7 +66,7 @@ namespace MCGalaxy
|
|||||||
Command.Find("Search").Use(p, "levels " + name);
|
Command.Find("Search").Use(p, "levels " + name);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return GotoLevel(p, lvl);
|
return GotoLevel(p, lvl, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,13 +87,13 @@ namespace MCGalaxy
|
|||||||
|
|
||||||
LevelActions.Load(p, map, false);
|
LevelActions.Load(p, map, false);
|
||||||
Level lvl = LevelInfo.FindExact(map);
|
Level lvl = LevelInfo.FindExact(map);
|
||||||
if (lvl != null) return GotoLevel(p, lvl);
|
if (lvl != null) return GotoLevel(p, lvl, true);
|
||||||
|
|
||||||
p.Message("Level \"{0}\" failed to be auto-loaded.", map);
|
p.Message("Level \"{0}\" failed to be auto-loaded.", map);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool GotoLevel(Player p, Level lvl) {
|
static bool GotoLevel(Player p, Level lvl, bool autoloaded) {
|
||||||
if (p.level == lvl) { p.Message("You are already in {0}&S.", lvl.ColoredName); return false; }
|
if (p.level == lvl) { p.Message("You are already in {0}&S.", lvl.ColoredName); return false; }
|
||||||
|
|
||||||
bool canJoin = lvl.CanJoin(p);
|
bool canJoin = lvl.CanJoin(p);
|
||||||
|
@ -46,5 +46,18 @@ namespace MCGalaxy
|
|||||||
TimeSpan oldestDelta = now - log[0];
|
TimeSpan oldestDelta = now - log[0];
|
||||||
return oldestDelta > checkInterval;
|
return oldestDelta > checkInterval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Can't just use HH:mm:ss, as e.g. Finnish converts : to .
|
||||||
|
// https://learn.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings#timeSeparator
|
||||||
|
const string INVARIANT_DATE_FORMAT = "yyyy-MM-dd HH':'mm':'ss";
|
||||||
|
|
||||||
|
public static string ToInvariantDateString(this DateTime time) {
|
||||||
|
return time.ToString(INVARIANT_DATE_FORMAT);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool TryParseInvariantDateString(this string str, out DateTime dt) {
|
||||||
|
return DateTime.TryParseExact(str, INVARIANT_DATE_FORMAT, null, 0, out dt);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user