mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-16 07:30:42 +01:00
Core/Server: correct timestamp format for shutdown/restart notification broadcasts (#24181)
* Core/SmartScripts: implement SMART_ACTION_OVERRIDE_LIGHT and SMART_ACTION_OVERRIDE_WEATHER
* Core/Server: correct timestamp format for shutdown/restart notification broadcasts
* remove unexpected changes
* move enum from Common to Util
* Use enum class instead of enum
* Fix width for seconds 0 to 9
(cherry picked from commit 69231581e4)
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
#include "StringFormat.h"
|
||||
#include <utf8.h>
|
||||
#include <algorithm>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <cctype>
|
||||
@@ -108,7 +109,7 @@ time_t GetLocalHourTimestamp(time_t time, uint8 hour, bool onlyAfterTime)
|
||||
return hourLocal;
|
||||
}
|
||||
|
||||
std::string secsToTimeString(uint64 timeInSecs, bool shortText, bool hoursOnly)
|
||||
std::string secsToTimeString(uint64 timeInSecs, TimeFormat timeFormat, bool hoursOnly)
|
||||
{
|
||||
uint64 secs = timeInSecs % MINUTE;
|
||||
uint64 minutes = timeInSecs % HOUR / MINUTE;
|
||||
@@ -117,15 +118,75 @@ std::string secsToTimeString(uint64 timeInSecs, bool shortText, bool hoursOnly)
|
||||
|
||||
std::ostringstream ss;
|
||||
if (days)
|
||||
ss << days << (shortText ? "d" : " Day(s) ");
|
||||
{
|
||||
ss << days;
|
||||
if (timeFormat == TimeFormat::Numeric)
|
||||
ss << ":";
|
||||
else if (timeFormat == TimeFormat::ShortText)
|
||||
ss << "d";
|
||||
else // if (timeFormat == TimeFormat::FullText)
|
||||
{
|
||||
if (days == 1)
|
||||
ss << " Day ";
|
||||
else
|
||||
ss << " Days ";
|
||||
}
|
||||
}
|
||||
if (hours || hoursOnly)
|
||||
ss << hours << (shortText ? "h" : " Hour(s) ");
|
||||
{
|
||||
ss << hours;
|
||||
if (timeFormat == TimeFormat::Numeric)
|
||||
ss << ":";
|
||||
else if (timeFormat == TimeFormat::ShortText)
|
||||
ss << "h";
|
||||
else // if (timeFormat == TimeFormat::FullText)
|
||||
{
|
||||
if (hours <= 1)
|
||||
ss << " Hour ";
|
||||
else
|
||||
ss << " Hours ";
|
||||
}
|
||||
}
|
||||
if (!hoursOnly)
|
||||
{
|
||||
if (minutes)
|
||||
ss << minutes << (shortText ? "m" : " Minute(s) ");
|
||||
if (secs || (!days && !hours && !minutes) )
|
||||
ss << secs << (shortText ? "s" : " Second(s).");
|
||||
{
|
||||
ss << minutes;
|
||||
if (timeFormat == TimeFormat::Numeric)
|
||||
ss << ":";
|
||||
else if (timeFormat == TimeFormat::ShortText)
|
||||
ss << "m";
|
||||
else // if (timeFormat == TimeFormat::FullText)
|
||||
{
|
||||
if (minutes == 1)
|
||||
ss << " Minute ";
|
||||
else
|
||||
ss << " Minutes ";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (timeFormat == TimeFormat::Numeric)
|
||||
ss << "0:";
|
||||
}
|
||||
if (secs || (!days && !hours && !minutes))
|
||||
{
|
||||
ss << std::setw(2) << std::setfill('0') << secs;
|
||||
if (timeFormat == TimeFormat::ShortText)
|
||||
ss << "s";
|
||||
else if (timeFormat == TimeFormat::FullText)
|
||||
{
|
||||
if (secs <= 1)
|
||||
ss << " Second.";
|
||||
else
|
||||
ss << " Seconds.";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (timeFormat == TimeFormat::Numeric)
|
||||
ss << "00";
|
||||
}
|
||||
}
|
||||
|
||||
return ss.str();
|
||||
|
||||
@@ -28,6 +28,13 @@
|
||||
|
||||
enum LocaleConstant : uint8;
|
||||
|
||||
enum class TimeFormat : uint8
|
||||
{
|
||||
FullText, // 1 Days 2 Hours 3 Minutes 4 Seconds
|
||||
ShortText, // 1d 2h 3m 4s
|
||||
Numeric // 1:2:3:4
|
||||
};
|
||||
|
||||
class TC_COMMON_API Tokenizer
|
||||
{
|
||||
public:
|
||||
@@ -63,7 +70,7 @@ TC_COMMON_API time_t LocalTimeToUTCTime(time_t time);
|
||||
TC_COMMON_API time_t GetLocalHourTimestamp(time_t time, uint8 hour, bool onlyAfterTime = true);
|
||||
TC_COMMON_API tm TimeBreakdown(time_t t);
|
||||
|
||||
TC_COMMON_API std::string secsToTimeString(uint64 timeInSecs, bool shortText = false, bool hoursOnly = false);
|
||||
TC_COMMON_API std::string secsToTimeString(uint64 timeInSecs, TimeFormat timeFormat = TimeFormat::FullText, bool hoursOnly = false);
|
||||
TC_COMMON_API uint32 TimeStringToSecs(std::string const& timestring);
|
||||
TC_COMMON_API std::string TimeToTimestampStr(time_t t);
|
||||
TC_COMMON_API std::string TimeToHumanReadable(time_t t);
|
||||
|
||||
@@ -162,7 +162,7 @@ std::string BugTicket::FormatViewMessageString(ChatHandler& handler, bool detail
|
||||
std::stringstream ss;
|
||||
ss << handler.PGetParseString(LANG_COMMAND_TICKETLISTGUID, _id);
|
||||
ss << handler.PGetParseString(LANG_COMMAND_TICKETLISTNAME, GetPlayerName().c_str());
|
||||
ss << handler.PGetParseString(LANG_COMMAND_TICKETLISTAGECREATE, (secsToTimeString(curTime - _createTime, true, false)).c_str());
|
||||
ss << handler.PGetParseString(LANG_COMMAND_TICKETLISTAGECREATE, (secsToTimeString(curTime - _createTime, TimeFormat::ShortText)).c_str());
|
||||
|
||||
if (!_assignedTo.IsEmpty())
|
||||
ss << handler.PGetParseString(LANG_COMMAND_TICKETLISTASSIGNEDTO, GetAssignedToName().c_str());
|
||||
@@ -286,7 +286,7 @@ std::string ComplaintTicket::FormatViewMessageString(ChatHandler& handler, bool
|
||||
std::stringstream ss;
|
||||
ss << handler.PGetParseString(LANG_COMMAND_TICKETLISTGUID, _id);
|
||||
ss << handler.PGetParseString(LANG_COMMAND_TICKETLISTNAME, GetPlayerName().c_str());
|
||||
ss << handler.PGetParseString(LANG_COMMAND_TICKETLISTAGECREATE, (secsToTimeString(curTime - _createTime, true, false)).c_str());
|
||||
ss << handler.PGetParseString(LANG_COMMAND_TICKETLISTAGECREATE, (secsToTimeString(curTime - _createTime, TimeFormat::ShortText)).c_str());
|
||||
|
||||
if (!_assignedTo.IsEmpty())
|
||||
ss << handler.PGetParseString(LANG_COMMAND_TICKETLISTASSIGNEDTO, GetAssignedToName().c_str());
|
||||
@@ -373,7 +373,7 @@ std::string SuggestionTicket::FormatViewMessageString(ChatHandler& handler, bool
|
||||
std::stringstream ss;
|
||||
ss << handler.PGetParseString(LANG_COMMAND_TICKETLISTGUID, _id);
|
||||
ss << handler.PGetParseString(LANG_COMMAND_TICKETLISTNAME, GetPlayerName().c_str());
|
||||
ss << handler.PGetParseString(LANG_COMMAND_TICKETLISTAGECREATE, (secsToTimeString(curTime - _createTime, true, false)).c_str());
|
||||
ss << handler.PGetParseString(LANG_COMMAND_TICKETLISTAGECREATE, (secsToTimeString(curTime - _createTime, TimeFormat::ShortText)).c_str());
|
||||
|
||||
if (!_assignedTo.IsEmpty())
|
||||
ss << handler.PGetParseString(LANG_COMMAND_TICKETLISTASSIGNEDTO, GetAssignedToName().c_str());
|
||||
|
||||
@@ -110,7 +110,7 @@ void Warden::Update()
|
||||
if (_clientResponseTimer > maxClientResponseDelay * IN_MILLISECONDS)
|
||||
{
|
||||
TC_LOG_WARN("warden", "%s (latency: %u, IP: %s) exceeded Warden module response delay for more than %s - disconnecting client",
|
||||
_session->GetPlayerInfo().c_str(), _session->GetLatency(), _session->GetRemoteAddress().c_str(), secsToTimeString(maxClientResponseDelay, true).c_str());
|
||||
_session->GetPlayerInfo().c_str(), _session->GetLatency(), _session->GetRemoteAddress().c_str(), secsToTimeString(maxClientResponseDelay, TimeFormat::ShortText).c_str());
|
||||
_session->KickPlayer();
|
||||
}
|
||||
else
|
||||
|
||||
@@ -3219,7 +3219,7 @@ void World::ShutdownMsg(bool show, Player* player, const std::string& reason)
|
||||
(m_ShutdownTimer < 12 * HOUR && (m_ShutdownTimer % HOUR) == 0) || // < 12 h ; every 1 h
|
||||
(m_ShutdownTimer > 12 * HOUR && (m_ShutdownTimer % (12 * HOUR)) == 0)) // > 12 h ; every 12 h
|
||||
{
|
||||
std::string str = secsToTimeString(m_ShutdownTimer);
|
||||
std::string str = secsToTimeString(m_ShutdownTimer, TimeFormat::Numeric);
|
||||
if (!reason.empty())
|
||||
str += " - " + reason;
|
||||
|
||||
|
||||
@@ -118,9 +118,9 @@ public:
|
||||
if (atoi(durationStr) > 0)
|
||||
{
|
||||
if (sWorld->getBoolConfig(CONFIG_SHOW_BAN_IN_WORLD))
|
||||
sWorld->SendWorldText(LANG_BAN_CHARACTER_YOUBANNEDMESSAGE_WORLD, author.c_str(), name.c_str(), secsToTimeString(TimeStringToSecs(durationStr), true).c_str(), reasonStr);
|
||||
sWorld->SendWorldText(LANG_BAN_CHARACTER_YOUBANNEDMESSAGE_WORLD, author.c_str(), name.c_str(), secsToTimeString(TimeStringToSecs(durationStr), TimeFormat::ShortText).c_str(), reasonStr);
|
||||
else
|
||||
handler->PSendSysMessage(LANG_BAN_YOUBANNED, name.c_str(), secsToTimeString(TimeStringToSecs(durationStr), true).c_str(), reasonStr);
|
||||
handler->PSendSysMessage(LANG_BAN_YOUBANNED, name.c_str(), secsToTimeString(TimeStringToSecs(durationStr), TimeFormat::ShortText).c_str(), reasonStr);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -205,9 +205,9 @@ public:
|
||||
if (atoi(durationStr) > 0)
|
||||
{
|
||||
if (sWorld->getBoolConfig(CONFIG_SHOW_BAN_IN_WORLD))
|
||||
sWorld->SendWorldText(LANG_BAN_ACCOUNT_YOUBANNEDMESSAGE_WORLD, author.c_str(), nameOrIP.c_str(), secsToTimeString(TimeStringToSecs(durationStr), true).c_str(), reasonStr);
|
||||
sWorld->SendWorldText(LANG_BAN_ACCOUNT_YOUBANNEDMESSAGE_WORLD, author.c_str(), nameOrIP.c_str(), secsToTimeString(TimeStringToSecs(durationStr), TimeFormat::ShortText).c_str(), reasonStr);
|
||||
else
|
||||
handler->PSendSysMessage(LANG_BAN_YOUBANNED, nameOrIP.c_str(), secsToTimeString(TimeStringToSecs(durationStr), true).c_str(), reasonStr);
|
||||
handler->PSendSysMessage(LANG_BAN_YOUBANNED, nameOrIP.c_str(), secsToTimeString(TimeStringToSecs(durationStr), TimeFormat::ShortText).c_str(), reasonStr);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -288,7 +288,7 @@ public:
|
||||
if (fields[2].GetBool() && (fields[1].GetUInt64() == uint64(0) || unbanDate >= GameTime::GetGameTime()))
|
||||
active = true;
|
||||
bool permanent = (fields[1].GetUInt64() == uint64(0));
|
||||
std::string banTime = permanent ? handler->GetTrinityString(LANG_BANINFO_INFINITE) : secsToTimeString(fields[1].GetUInt64(), true);
|
||||
std::string banTime = permanent ? handler->GetTrinityString(LANG_BANINFO_INFINITE) : secsToTimeString(fields[1].GetUInt64(), TimeFormat::ShortText);
|
||||
handler->PSendSysMessage(LANG_BANINFO_HISTORYENTRY,
|
||||
fields[0].GetCString(), banTime.c_str(), active ? handler->GetTrinityString(LANG_YES) : handler->GetTrinityString(LANG_NO), fields[4].GetCString(), fields[5].GetCString());
|
||||
}
|
||||
@@ -344,7 +344,7 @@ public:
|
||||
if (fields[2].GetUInt8() && (!fields[1].GetInt64() || unbanDate >= GameTime::GetGameTime()))
|
||||
active = true;
|
||||
bool permanent = (fields[1].GetInt64() == SI64LIT(0));
|
||||
std::string banTime = permanent ? handler->GetTrinityString(LANG_BANINFO_INFINITE) : secsToTimeString(fields[1].GetInt64(), true);
|
||||
std::string banTime = permanent ? handler->GetTrinityString(LANG_BANINFO_INFINITE) : secsToTimeString(fields[1].GetInt64(), TimeFormat::ShortText);
|
||||
handler->PSendSysMessage(LANG_BANINFO_HISTORYENTRY,
|
||||
TimeToTimestampStr(fields[0].GetInt64()).c_str(), banTime.c_str(), active ? handler->GetTrinityString(LANG_YES) : handler->GetTrinityString(LANG_NO), fields[4].GetCString(), fields[5].GetCString());
|
||||
}
|
||||
@@ -379,7 +379,7 @@ public:
|
||||
bool permanent = !fields[6].GetUInt64();
|
||||
handler->PSendSysMessage(LANG_BANINFO_IPENTRY,
|
||||
fields[0].GetCString(), fields[1].GetCString(), permanent ? handler->GetTrinityString(LANG_BANINFO_NEVER) : fields[2].GetCString(),
|
||||
permanent ? handler->GetTrinityString(LANG_BANINFO_INFINITE) : secsToTimeString(fields[3].GetUInt64(), true).c_str(), fields[4].GetCString(), fields[5].GetCString());
|
||||
permanent ? handler->GetTrinityString(LANG_BANINFO_INFINITE) : secsToTimeString(fields[3].GetUInt64(), TimeFormat::ShortText).c_str(), fields[4].GetCString(), fields[5].GetCString());
|
||||
|
||||
|
||||
return true;
|
||||
|
||||
@@ -332,8 +332,8 @@ public:
|
||||
if (curRespawnDelay < 0)
|
||||
curRespawnDelay = 0;
|
||||
|
||||
std::string curRespawnDelayStr = secsToTimeString(curRespawnDelay, true);
|
||||
std::string defRespawnDelayStr = secsToTimeString(target->GetRespawnDelay(), true);
|
||||
std::string curRespawnDelayStr = secsToTimeString(curRespawnDelay, TimeFormat::ShortText);
|
||||
std::string defRespawnDelayStr = secsToTimeString(target->GetRespawnDelay(), TimeFormat::ShortText);
|
||||
|
||||
handler->PSendSysMessage(LANG_COMMAND_RAWPAWNTIMES, defRespawnDelayStr.c_str(), curRespawnDelayStr.c_str());
|
||||
}
|
||||
|
||||
@@ -732,7 +732,7 @@ public:
|
||||
}
|
||||
uint32 gridY = ri->gridId / MAX_NUMBER_OF_GRIDS;
|
||||
uint32 gridX = ri->gridId % MAX_NUMBER_OF_GRIDS;
|
||||
std::string respawnTime = ri->respawnTime > GameTime::GetGameTime() ? secsToTimeString(uint64(ri->respawnTime - GameTime::GetGameTime()), true) : stringOverdue;
|
||||
std::string respawnTime = ri->respawnTime > GameTime::GetGameTime() ? secsToTimeString(uint64(ri->respawnTime - GameTime::GetGameTime()), TimeFormat::ShortText) : stringOverdue;
|
||||
handler->PSendSysMessage(UI64FMTD " | %u | [%02u,%02u] | %s (%u) | %s%s", ri->spawnId, ri->entry, gridX, gridY, GetZoneName(respawnZoneId, locale), respawnZoneId, respawnTime.c_str(), map->IsSpawnGroupActive(data->spawnGroupData->groupId) ? "" : " (inactive)");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1868,11 +1868,11 @@ public:
|
||||
|
||||
// Output III. LANG_PINFO_BANNED if ban exists and is applied
|
||||
if (banTime >= 0)
|
||||
handler->PSendSysMessage(LANG_PINFO_BANNED, banType.c_str(), banReason.c_str(), banTime > 0 ? secsToTimeString(banTime - GameTime::GetGameTime(), true).c_str() : handler->GetTrinityString(LANG_PERMANENTLY), bannedBy.c_str());
|
||||
handler->PSendSysMessage(LANG_PINFO_BANNED, banType.c_str(), banReason.c_str(), banTime > 0 ? secsToTimeString(banTime - GameTime::GetGameTime(), TimeFormat::ShortText).c_str() : handler->GetTrinityString(LANG_PERMANENTLY), bannedBy.c_str());
|
||||
|
||||
// Output IV. LANG_PINFO_MUTED if mute is applied
|
||||
if (muteTime > 0)
|
||||
handler->PSendSysMessage(LANG_PINFO_MUTED, muteReason.c_str(), secsToTimeString(muteTime - GameTime::GetGameTime(), true).c_str(), muteBy.c_str());
|
||||
handler->PSendSysMessage(LANG_PINFO_MUTED, muteReason.c_str(), secsToTimeString(muteTime - GameTime::GetGameTime(), TimeFormat::ShortText).c_str(), muteBy.c_str());
|
||||
|
||||
// Output V. LANG_PINFO_ACC_ACCOUNT
|
||||
handler->PSendSysMessage(LANG_PINFO_ACC_ACCOUNT, userName.c_str(), accId, security);
|
||||
@@ -1948,7 +1948,7 @@ public:
|
||||
}
|
||||
|
||||
// Output XX. LANG_PINFO_CHR_PLAYEDTIME
|
||||
handler->PSendSysMessage(LANG_PINFO_CHR_PLAYEDTIME, (secsToTimeString(totalPlayerTime, true, true)).c_str());
|
||||
handler->PSendSysMessage(LANG_PINFO_CHR_PLAYEDTIME, (secsToTimeString(totalPlayerTime, TimeFormat::ShortText, true)).c_str());
|
||||
|
||||
// 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` = ?"
|
||||
|
||||
@@ -659,8 +659,8 @@ public:
|
||||
|
||||
if (curRespawnDelay < 0)
|
||||
curRespawnDelay = 0;
|
||||
std::string curRespawnDelayStr = secsToTimeString(uint64(curRespawnDelay), true);
|
||||
std::string defRespawnDelayStr = secsToTimeString(target->GetRespawnDelay(), true);
|
||||
std::string curRespawnDelayStr = secsToTimeString(uint64(curRespawnDelay), TimeFormat::ShortText);
|
||||
std::string defRespawnDelayStr = secsToTimeString(target->GetRespawnDelay(), TimeFormat::ShortText);
|
||||
|
||||
handler->PSendSysMessage(LANG_NPCINFO_CHAR, target->GetName().c_str(), std::to_string(target->GetSpawnId()).c_str(), target->GetGUID().ToString().c_str(), entry, faction, std::to_string(npcflags).c_str(), displayid, nativeid);
|
||||
if (target->GetCreatureData() && target->GetCreatureData()->spawnGroupData->groupId)
|
||||
|
||||
Reference in New Issue
Block a user