Core/Server: correct timestamp format for shutdown/restart notification broadcasts
Port From (https://github.com/TrinityCore/TrinityCore/commit/69f768605082222a3ca573c623d3fc019106be3b)
This commit is contained in:
@@ -16,6 +16,14 @@
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
public enum TimeFormat
|
||||
{
|
||||
FullText, // 1 Days 2 Hours 3 Minutes 4 Seconds
|
||||
ShortText, // 1d 2h 3m 4s
|
||||
Numeric // 1:2:3:4
|
||||
}
|
||||
|
||||
public static class Time
|
||||
{
|
||||
@@ -133,27 +141,87 @@ public static class Time
|
||||
return hourLocal;
|
||||
}
|
||||
|
||||
public static string secsToTimeString(ulong timeInSecs, bool shortText = false, bool hoursOnly = false)
|
||||
public static string secsToTimeString(ulong timeInSecs, TimeFormat timeFormat = TimeFormat.FullText, bool hoursOnly = false)
|
||||
{
|
||||
ulong secs = timeInSecs % Minute;
|
||||
ulong minutes = timeInSecs % Hour / Minute;
|
||||
ulong hours = timeInSecs % Day / Hour;
|
||||
ulong days = timeInSecs / Day;
|
||||
|
||||
string ss = "";
|
||||
StringBuilder ss = new();
|
||||
if (days != 0)
|
||||
ss += days + (shortText ? "d" : " Day(s) ");
|
||||
{
|
||||
ss.Append(days);
|
||||
if (timeFormat == TimeFormat.Numeric)
|
||||
ss.Append(":");
|
||||
else if (timeFormat == TimeFormat.ShortText)
|
||||
ss.Append("d");
|
||||
else // if (timeFormat == TimeFormat::FullText)
|
||||
{
|
||||
if (days == 1)
|
||||
ss.Append(" Day ");
|
||||
else
|
||||
ss.Append(" Days ");
|
||||
}
|
||||
}
|
||||
if (hours != 0 || hoursOnly)
|
||||
ss += hours + (shortText ? "h" : " Hour(s) ");
|
||||
{
|
||||
ss.Append(hours);
|
||||
if (timeFormat == TimeFormat.Numeric)
|
||||
ss.Append(":");
|
||||
else if (timeFormat == TimeFormat.ShortText)
|
||||
ss.Append("h");
|
||||
else // if (timeFormat == TimeFormat::FullText)
|
||||
{
|
||||
if (hours <= 1)
|
||||
ss.Append(" Hour ");
|
||||
else
|
||||
ss.Append(" Hours ");
|
||||
}
|
||||
}
|
||||
if (!hoursOnly)
|
||||
{
|
||||
if (minutes != 0)
|
||||
ss += minutes + (shortText ? "m" : " Minute(s) ");
|
||||
{
|
||||
ss.Append(minutes);
|
||||
if (timeFormat == TimeFormat.Numeric)
|
||||
ss.Append(":");
|
||||
else if (timeFormat == TimeFormat.ShortText)
|
||||
ss.Append("m");
|
||||
else // if (timeFormat == TimeFormat::FullText)
|
||||
{
|
||||
if (minutes == 1)
|
||||
ss.Append(" Minute ");
|
||||
else
|
||||
ss.Append(" Minutes ");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (timeFormat == TimeFormat.Numeric)
|
||||
ss.Append("0:");
|
||||
}
|
||||
if (secs != 0 || (days == 0 && hours == 0 && minutes == 0))
|
||||
ss += secs + (shortText ? "s" : " Second(s).");
|
||||
{
|
||||
ss.Append($"{secs:2}");
|
||||
if (timeFormat == TimeFormat.ShortText)
|
||||
ss.Append("s");
|
||||
else if (timeFormat == TimeFormat.FullText)
|
||||
{
|
||||
if (secs <= 1)
|
||||
ss.Append(" Second.");
|
||||
else
|
||||
ss.Append(" Seconds.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (timeFormat == TimeFormat.Numeric)
|
||||
ss.Append("00");
|
||||
}
|
||||
}
|
||||
|
||||
return ss;
|
||||
return ss.ToString();
|
||||
}
|
||||
|
||||
public static uint TimeStringToSecs(string timestring)
|
||||
|
||||
@@ -69,9 +69,9 @@ namespace Game.Chat.Commands
|
||||
if (duration > 0)
|
||||
{
|
||||
if (WorldConfig.GetBoolValue(WorldCfg.ShowBanInWorld))
|
||||
Global.WorldMgr.SendWorldText(CypherStrings.BanCharacterYoubannedmessageWorld, author, name, Time.secsToTimeString(Time.TimeStringToSecs(durationStr), true), reasonStr);
|
||||
Global.WorldMgr.SendWorldText(CypherStrings.BanCharacterYoubannedmessageWorld, author, name, Time.secsToTimeString(Time.TimeStringToSecs(durationStr), TimeFormat.ShortText), reasonStr);
|
||||
else
|
||||
handler.SendSysMessage(CypherStrings.BanYoubanned, name, Time.secsToTimeString(Time.TimeStringToSecs(durationStr), true), reasonStr);
|
||||
handler.SendSysMessage(CypherStrings.BanYoubanned, name, Time.secsToTimeString(Time.TimeStringToSecs(durationStr), TimeFormat.ShortText), reasonStr);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -147,7 +147,7 @@ namespace Game.Chat.Commands
|
||||
if (WorldConfig.GetBoolValue(WorldCfg.ShowBanInWorld))
|
||||
Global.WorldMgr.SendWorldText(CypherStrings.BanAccountYoubannedmessageWorld, author, nameOrIP, Time.secsToTimeString(Time.TimeStringToSecs(durationStr)), reasonStr);
|
||||
else
|
||||
handler.SendSysMessage(CypherStrings.BanYoubanned, nameOrIP, Time.secsToTimeString(Time.TimeStringToSecs(durationStr), true), reasonStr);
|
||||
handler.SendSysMessage(CypherStrings.BanYoubanned, nameOrIP, Time.secsToTimeString(Time.TimeStringToSecs(durationStr), TimeFormat.ShortText), reasonStr);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -250,7 +250,7 @@ namespace Game.Chat.Commands
|
||||
if (result.Read<bool>(2) && (result.Read<long>(1) == 0L || unbanDate >= GameTime.GetGameTime()))
|
||||
active = true;
|
||||
bool permanent = (result.Read<long>(1) == 0L);
|
||||
string banTime = permanent ? handler.GetCypherString(CypherStrings.BaninfoInfinite) : Time.secsToTimeString(result.Read<ulong>(1), true);
|
||||
string banTime = permanent ? handler.GetCypherString(CypherStrings.BaninfoInfinite) : Time.secsToTimeString(result.Read<ulong>(1), TimeFormat.ShortText);
|
||||
handler.SendSysMessage(CypherStrings.BaninfoHistoryentry, Time.UnixTimeToDateTime(result.Read<long>(0)).ToShortTimeString(), banTime,
|
||||
active ? handler.GetCypherString(CypherStrings.Yes) : handler.GetCypherString(CypherStrings.No), result.Read<string>(4), result.Read<string>(5));
|
||||
}
|
||||
@@ -278,7 +278,7 @@ namespace Game.Chat.Commands
|
||||
|
||||
bool permanent = result.Read<ulong>(6) == 0;
|
||||
handler.SendSysMessage(CypherStrings.BaninfoIpentry, result.Read<string>(0), result.Read<string>(1), permanent ? handler.GetCypherString( CypherStrings.BaninfoNever) : result.Read<string>(2),
|
||||
permanent ? handler.GetCypherString( CypherStrings.BaninfoInfinite) : Time.secsToTimeString(result.Read<ulong>(3), true), result.Read<string>(4), result.Read<string>(5));
|
||||
permanent ? handler.GetCypherString( CypherStrings.BaninfoInfinite) : Time.secsToTimeString(result.Read<ulong>(3), TimeFormat.ShortText), result.Read<string>(4), result.Read<string>(5));
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -300,7 +300,7 @@ namespace Game.Chat.Commands
|
||||
if (result.Read<bool>(2) && (result.Read<ulong>(1) == 0 || unbanDate >= GameTime.GetGameTime()))
|
||||
active = true;
|
||||
bool permanent = (result.Read<ulong>(1) == 0);
|
||||
string banTime = permanent ? handler.GetCypherString(CypherStrings.BaninfoInfinite) : Time.secsToTimeString(result.Read<ulong>(1), true);
|
||||
string banTime = permanent ? handler.GetCypherString(CypherStrings.BaninfoInfinite) : Time.secsToTimeString(result.Read<ulong>(1), TimeFormat.ShortText);
|
||||
handler.SendSysMessage(CypherStrings.BaninfoHistoryentry,
|
||||
result.Read<string>(0), banTime, active ? handler.GetCypherString(CypherStrings.Yes) : handler.GetCypherString(CypherStrings.No), result.Read<string>(4), result.Read<string>(5));
|
||||
}
|
||||
|
||||
@@ -495,8 +495,8 @@ namespace Game.Chat
|
||||
if (curRespawnDelay < 0)
|
||||
curRespawnDelay = 0;
|
||||
|
||||
string curRespawnDelayStr = Time.secsToTimeString((uint)curRespawnDelay, true);
|
||||
string defRespawnDelayStr = Time.secsToTimeString(target.GetRespawnDelay(), true);
|
||||
string curRespawnDelayStr = Time.secsToTimeString((uint)curRespawnDelay, TimeFormat.ShortText);
|
||||
string defRespawnDelayStr = Time.secsToTimeString(target.GetRespawnDelay(), TimeFormat.ShortText);
|
||||
|
||||
handler.SendSysMessage(CypherStrings.CommandRawpawntimes, defRespawnDelayStr, curRespawnDelayStr);
|
||||
}
|
||||
|
||||
@@ -616,7 +616,7 @@ namespace Game.Chat.Commands
|
||||
uint gridY = ri.gridId / MapConst.MaxGrids;
|
||||
uint gridX = ri.gridId % MapConst.MaxGrids;
|
||||
|
||||
string respawnTime = ri.respawnTime > GameTime.GetGameTime() ? Time.secsToTimeString((ulong)(ri.respawnTime - GameTime.GetGameTime()), true) : stringOverdue;
|
||||
string respawnTime = ri.respawnTime > GameTime.GetGameTime() ? Time.secsToTimeString((ulong)(ri.respawnTime - GameTime.GetGameTime()), TimeFormat.ShortText) : stringOverdue;
|
||||
handler.SendSysMessage($"{ri.spawnId} | {ri.entry} | [{gridX:2},{gridY:2}] | {GetZoneName(respawnZoneId, locale)} ({respawnZoneId}) | {respawnTime}{(map.IsSpawnGroupActive(data.spawnGroupData.groupId) ? "" : " (inactive)")}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1738,11 +1738,11 @@ namespace Game.Chat
|
||||
|
||||
// Output III. LANG_PINFO_BANNED if ban exists and is applied
|
||||
if (banTime >= 0)
|
||||
handler.SendSysMessage(CypherStrings.PinfoBanned, banType, banReason, banTime > 0 ? Time.secsToTimeString((ulong)(banTime - GameTime.GetGameTime()), true) : handler.GetCypherString(CypherStrings.Permanently), bannedBy);
|
||||
handler.SendSysMessage(CypherStrings.PinfoBanned, banType, banReason, banTime > 0 ? Time.secsToTimeString((ulong)(banTime - GameTime.GetGameTime()), TimeFormat.ShortText) : handler.GetCypherString(CypherStrings.Permanently), bannedBy);
|
||||
|
||||
// Output IV. LANG_PINFO_MUTED if mute is applied
|
||||
if (muteTime > 0)
|
||||
handler.SendSysMessage(CypherStrings.PinfoMuted, muteReason, Time.secsToTimeString((ulong)(muteTime - GameTime.GetGameTime()), true), muteBy);
|
||||
handler.SendSysMessage(CypherStrings.PinfoMuted, muteReason, Time.secsToTimeString((ulong)(muteTime - GameTime.GetGameTime()), TimeFormat.ShortText), muteBy);
|
||||
|
||||
// Output V. LANG_PINFO_ACC_ACCOUNT
|
||||
handler.SendSysMessage(CypherStrings.PinfoAccAccount, userName, accId, security);
|
||||
@@ -1817,7 +1817,7 @@ namespace Game.Chat
|
||||
}
|
||||
|
||||
// Output XX. LANG_PINFO_CHR_PLAYEDTIME
|
||||
handler.SendSysMessage(CypherStrings.PinfoChrPlayedtime, (Time.secsToTimeString(totalPlayerTime, true, true)));
|
||||
handler.SendSysMessage(CypherStrings.PinfoChrPlayedtime, (Time.secsToTimeString(totalPlayerTime, TimeFormat.ShortText, true)));
|
||||
|
||||
// Mail Data - an own query, because it may or may not be useful.
|
||||
// SQL: "SELECT SUM(CASE WHEN (checked & 1) THEN 1 ELSE 0 END) AS 'readmail', COUNT(*) AS 'totalmail' FROM mail WHERE `receiver` = ?"
|
||||
|
||||
@@ -135,8 +135,8 @@ namespace Game.Chat
|
||||
if (curRespawnDelay < 0)
|
||||
curRespawnDelay = 0;
|
||||
|
||||
string curRespawnDelayStr = Time.secsToTimeString((ulong)curRespawnDelay, true);
|
||||
string defRespawnDelayStr = Time.secsToTimeString(target.GetRespawnDelay(), true);
|
||||
string curRespawnDelayStr = Time.secsToTimeString((ulong)curRespawnDelay, TimeFormat.ShortText);
|
||||
string defRespawnDelayStr = Time.secsToTimeString(target.GetRespawnDelay(), TimeFormat.ShortText);
|
||||
|
||||
handler.SendSysMessage(CypherStrings.NpcinfoChar, target.GetName(), target.GetSpawnId(), target.GetGUID().ToString(), entry, faction, npcflags, displayid, nativeid);
|
||||
if (target.GetCreatureData() != null && target.GetCreatureData().spawnGroupData.groupId != 0)
|
||||
|
||||
@@ -1842,7 +1842,7 @@ namespace Game
|
||||
(m_ShutdownTimer < 12 * Time.Hour && (m_ShutdownTimer % Time.Hour) == 0) || // < 12 h ; every 1 h
|
||||
(m_ShutdownTimer > 12 * Time.Hour && (m_ShutdownTimer % (12 * Time.Hour)) == 0)) // > 12 h ; every 12 h
|
||||
{
|
||||
var str = Time.secsToTimeString(m_ShutdownTimer);
|
||||
var str = Time.secsToTimeString(m_ShutdownTimer, TimeFormat.Numeric);
|
||||
if (!reason.IsEmpty())
|
||||
str += " - " + reason;
|
||||
|
||||
|
||||
@@ -189,7 +189,7 @@ namespace Game.SupportSystem
|
||||
StringBuilder ss = new();
|
||||
ss.Append(handler.GetParsedString(CypherStrings.CommandTicketlistguid, _id));
|
||||
ss.Append(handler.GetParsedString(CypherStrings.CommandTicketlistname, GetPlayerName()));
|
||||
ss.Append(handler.GetParsedString(CypherStrings.CommandTicketlistagecreate, Time.secsToTimeString(curTime - _createTime, true, false)));
|
||||
ss.Append(handler.GetParsedString(CypherStrings.CommandTicketlistagecreate, Time.secsToTimeString(curTime - _createTime, TimeFormat.ShortText, false)));
|
||||
|
||||
if (!_assignedTo.IsEmpty())
|
||||
ss.Append(handler.GetParsedString(CypherStrings.CommandTicketlistassignedto, GetAssignedToName()));
|
||||
@@ -327,7 +327,7 @@ namespace Game.SupportSystem
|
||||
StringBuilder ss = new();
|
||||
ss.Append(handler.GetParsedString(CypherStrings.CommandTicketlistguid, _id));
|
||||
ss.Append(handler.GetParsedString(CypherStrings.CommandTicketlistname, GetPlayerName()));
|
||||
ss.Append(handler.GetParsedString(CypherStrings.CommandTicketlistagecreate, Time.secsToTimeString(curTime - _createTime, true, false)));
|
||||
ss.Append(handler.GetParsedString(CypherStrings.CommandTicketlistagecreate, Time.secsToTimeString(curTime - _createTime, TimeFormat.ShortText, false)));
|
||||
|
||||
if (!_assignedTo.IsEmpty())
|
||||
ss.Append(handler.GetParsedString(CypherStrings.CommandTicketlistassignedto, GetAssignedToName()));
|
||||
@@ -433,7 +433,7 @@ namespace Game.SupportSystem
|
||||
StringBuilder ss = new();
|
||||
ss.Append(handler.GetParsedString(CypherStrings.CommandTicketlistguid, _id));
|
||||
ss.Append(handler.GetParsedString(CypherStrings.CommandTicketlistname, GetPlayerName()));
|
||||
ss.Append(handler.GetParsedString(CypherStrings.CommandTicketlistagecreate, Time.secsToTimeString(curTime - _createTime, true, false)));
|
||||
ss.Append(handler.GetParsedString(CypherStrings.CommandTicketlistagecreate, Time.secsToTimeString(curTime - _createTime, TimeFormat.ShortText, false)));
|
||||
|
||||
if (!_assignedTo.IsEmpty())
|
||||
ss.Append(handler.GetParsedString(CypherStrings.CommandTicketlistassignedto, GetAssignedToName()));
|
||||
|
||||
@@ -100,7 +100,7 @@ namespace Game
|
||||
if (_clientResponseTimer > maxClientResponseDelay * Time.InMilliseconds)
|
||||
{
|
||||
Log.outWarn(LogFilter.Warden, "{0} (latency: {1}, IP: {2}) exceeded Warden module response delay for more than {3} - disconnecting client",
|
||||
_session.GetPlayerInfo(), _session.GetLatency(), _session.GetRemoteAddress(), Time.secsToTimeString(maxClientResponseDelay, true));
|
||||
_session.GetPlayerInfo(), _session.GetLatency(), _session.GetRemoteAddress(), Time.secsToTimeString(maxClientResponseDelay, TimeFormat.ShortText));
|
||||
_session.KickPlayer();
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user