From dca34cc2ffa4dd36e6e015c9aeacd6f08cfff587 Mon Sep 17 00:00:00 2001 From: Kinglykrab <89047260+Kinglykrab@users.noreply.github.com> Date: Sat, 7 May 2022 06:03:58 -0400 Subject: [PATCH] [Commands] Cleanup #time and #timezone Command. (#2147) * [Commands] Cleanup #time and #timezone Command. - Cleanup messages and logic. * Cleanup. --- zone/command.cpp | 4 +- zone/gm_commands/time.cpp | 144 ++++++++++++++++++++++++++++------ zone/gm_commands/timezone.cpp | 89 +++++++++++++++------ 3 files changed, 189 insertions(+), 48 deletions(-) diff --git a/zone/command.cpp b/zone/command.cpp index 3062f825b..abfb4d701 100755 --- a/zone/command.cpp +++ b/zone/command.cpp @@ -357,9 +357,9 @@ int command_init(void) command_add("tempname", "[newname] - Temporarily renames your target. Leave name blank to restore the original name.", AccountStatus::GMAdmin, command_tempname) || command_add("petname", "[newname] - Temporarily renames your pet. Leave name blank to restore the original name.", AccountStatus::GMAdmin, command_petname) || command_add("texture", "[Texture] [Helmet Texture] - Change your or your target's texture (Helmet Texture defaults to 0 if not used)", AccountStatus::Steward, command_texture) || - command_add("time", "[HH] [MM] - Set EQ time", AccountStatus::EQSupport, command_time) || + command_add("time", "[Hour] [Minute] - Set world time to specified time", AccountStatus::EQSupport, command_time) || command_add("timers", "- Display persistent timers for target", AccountStatus::GMMgmt, command_timers) || - command_add("timezone", "[HH] [MM] - Set timezone. Minutes are optional", AccountStatus::EQSupport, command_timezone) || + command_add("timezone", "[Hour] [Minutes] - Set timezone (Minutes are optional)", AccountStatus::EQSupport, command_timezone) || command_add("title", "[Remove|Title] [Save (0 = False, 1 = True)] - Set your or your player target's title (use remove to remove title, Save defaults to false if not used)", AccountStatus::Guide, command_title) || command_add("titlesuffix", "[Remove|Title Suffix] [Save (0 = False, 1 = True)] - Set your or your player target's title suffix (use remove to remove title suffix, Save defaults to false if not used)", AccountStatus::Guide, command_titlesuffix) || command_add("traindisc", "[level] - Trains all the disciplines usable by the target, up to level specified. (may freeze client for a few seconds)", AccountStatus::GMLeadAdmin, command_traindisc) || diff --git a/zone/gm_commands/time.cpp b/zone/gm_commands/time.cpp index fd241d75f..8254a3de1 100755 --- a/zone/gm_commands/time.cpp +++ b/zone/gm_commands/time.cpp @@ -2,31 +2,127 @@ void command_time(Client *c, const Seperator *sep) { - char timeMessage[255]; - int minutes = 0; - if (sep->IsNumber(1)) { - if (sep->IsNumber(2)) { - minutes = atoi(sep->arg[2]); - } - c->Message(Chat::Red, "Setting world time to %s:%i (Timezone: 0)...", sep->arg[1], minutes); - zone->SetTime(atoi(sep->arg[1]) + 1, minutes); - LogInfo("{} :: Setting world time to {}:{} (Timezone: 0)...", c->GetCleanName(), sep->arg[1], minutes); - } - else { - c->Message(Chat::Red, "To set the Time: #time HH [MM]"); - TimeOfDay_Struct eqTime; - zone->zone_time.GetCurrentEQTimeOfDay(time(0), &eqTime); - sprintf( - timeMessage, "%02d:%s%d %s (Timezone: %ih %im)", - ((eqTime.hour - 1) % 12) == 0 ? 12 : ((eqTime.hour - 1) % 12), - (eqTime.minute < 10) ? "0" : "", - eqTime.minute, - (eqTime.hour >= 13) ? "pm" : "am", - zone->zone_time.getEQTimeZoneHr(), - zone->zone_time.getEQTimeZoneMin() + int arguments = sep->argnum; + if (!arguments || !sep->IsNumber(1)) { + c->Message(Chat::White, "Usage: #time [Hour] [Minute]"); + + TimeOfDay_Struct world_time; + zone->zone_time.GetCurrentEQTimeOfDay(time(0), &world_time); + + auto time_string = fmt::format( + "{:02}:{:02} {} (Timezone: {:02}:{:02} {})", + ( + ((world_time.hour - 1) % 12) == 0 ? + 12 : + ((world_time.hour - 1) % 12) + ), + world_time.minute, + ( + world_time.hour >= 13 ? + "PM" : + "AM" + ), + ( + ((zone->zone_time.getEQTimeZoneHr() - 1) % 12) == 0 ? + 12 : + ((zone->zone_time.getEQTimeZoneHr() - 1) % 12) + ), + zone->zone_time.getEQTimeZoneMin(), + ( + zone->zone_time.getEQTimeZoneHr() >= 13 ? + "PM" : + "AM" + ) ); - c->Message(Chat::Red, "It is now %s.", timeMessage); - LogInfo("Current Time is: {}", timeMessage); + + c->Message( + Chat::White, + fmt::format( + "It is currently {}.", + time_string + ).c_str() + ); + + return; } + + uint8 minutes = 0; + auto hours = static_cast(std::stoul(sep->arg[1]) + 1); + + if (hours > 24) { + hours = 24; + } + + uint8 real_hours = ( + (hours - 1) > 0 ? + (hours - 1) : + 0 + ); + + if (sep->IsNumber(2)) { + minutes = static_cast(std::stoul(sep->arg[2])); + + if (minutes > 59) { + minutes = 59; + } + } + + c->Message( + Chat::White, + fmt::format( + "Setting world time to {:02}:{:02} {} (Timezone: {:02}:{:02} {}).", + ( + (hours % 12) == 0 ? + 12 : + (hours % 12) + ), + minutes, + ( + hours >= 13 ? + "PM" : + "AM" + ), + ( + ((zone->zone_time.getEQTimeZoneHr() - 1) % 12) == 0 ? + 12 : + ((zone->zone_time.getEQTimeZoneHr() - 1) % 12) + ), + zone->zone_time.getEQTimeZoneMin(), + ( + zone->zone_time.getEQTimeZoneHr() >= 13 ? + "PM" : + "AM" + ) + ).c_str() + ); + + zone->SetTime(real_hours, minutes); + + LogInfo( + "{} :: Setting world time to {:02}:{:02} {} (Timezone: {:02}:{:02} {})", + c->GetCleanName(), + ( + (hours % 12) == 0 ? + 12 : + (hours % 12) + ), + minutes, + ( + hours >= 13 ? + "PM" : + "AM" + ), + ( + ((zone->zone_time.getEQTimeZoneHr() - 1) % 12) == 0 ? + 12 : + ((zone->zone_time.getEQTimeZoneHr() - 1) % 12) + ), + zone->zone_time.getEQTimeZoneMin(), + ( + zone->zone_time.getEQTimeZoneHr() >= 13 ? + "PM" : + "AM" + ) + ); } diff --git a/zone/gm_commands/timezone.cpp b/zone/gm_commands/timezone.cpp index d4e628cc0..4e73a8108 100755 --- a/zone/gm_commands/timezone.cpp +++ b/zone/gm_commands/timezone.cpp @@ -2,31 +2,76 @@ void command_timezone(Client *c, const Seperator *sep) { - if (sep->arg[1][0] == 0 && !sep->IsNumber(1)) { - c->Message(Chat::Red, "Usage: #timezone HH [MM]"); + int arguments = sep->argnum; + if (!arguments || !sep->IsNumber(1)) { + c->Message(Chat::White, "Usage: #timezone [Hour] [Minute]"); c->Message( - Chat::Red, - "Current timezone is: %ih %im", - zone->zone_time.getEQTimeZoneHr(), - zone->zone_time.getEQTimeZoneMin()); + Chat::White, + fmt::format( + "Current timezone is {:02}:{:02} {}.", + ( + ((zone->zone_time.getEQTimeZoneHr() - 1) % 12) == 0 ? + 12 : + ((zone->zone_time.getEQTimeZoneHr() - 1) % 12) + ), + zone->zone_time.getEQTimeZoneMin(), + ( + zone->zone_time.getEQTimeZoneHr() >= 13 ? + "PM" : + "AM" + ) + ).c_str() + ); + return; } - else { - uint8 hours = atoi(sep->arg[1]); - uint8 minutes = atoi(sep->arg[2]); - if (!sep->IsNumber(2)) { - minutes = 0; - } - c->Message(Chat::Red, "Setting timezone to %i h %i m", hours, minutes); - uint32 ntz = (hours * 60) + minutes; - zone->zone_time.setEQTimeZone(ntz); - content_db.SetZoneTZ(zone->GetZoneID(), zone->GetInstanceVersion(), ntz); - // Update all clients with new TZ. - auto outapp = new EQApplicationPacket(OP_TimeOfDay, sizeof(TimeOfDay_Struct)); - TimeOfDay_Struct *tod = (TimeOfDay_Struct *) outapp->pBuffer; - zone->zone_time.GetCurrentEQTimeOfDay(time(0), tod); - entity_list.QueueClients(c, outapp); - safe_delete(outapp); + uint8 minutes = 0; + auto hours = static_cast(std::stoul(sep->arg[1])); + + if (hours > 24) { + hours = 24; } + + uint8 real_hours = ( + (hours - 1) > 0 ? + (hours - 1) : + 0 + ); + + if (sep->IsNumber(2)) { + minutes = static_cast(std::stoul(sep->arg[2])); + + if (minutes > 59) { + minutes = 59; + } + } + + c->Message( + Chat::White, + fmt::format( + "Setting timezone to {:02}:{:02} {}.", + ( + (real_hours % 12) == 0 ? + 12 : + (real_hours % 12) + ), + minutes, + ( + hours >= 13 ? + "PM" : + "AM" + ) + ).c_str() + ); + + uint32 new_timezone = ((hours * 60) + minutes); + zone->zone_time.setEQTimeZone(new_timezone); + content_db.SetZoneTZ(zone->GetZoneID(), zone->GetInstanceVersion(), new_timezone); + + auto outapp = new EQApplicationPacket(OP_TimeOfDay, sizeof(TimeOfDay_Struct)); + TimeOfDay_Struct *tod = (TimeOfDay_Struct *) outapp->pBuffer; + zone->zone_time.GetCurrentEQTimeOfDay(time(0), tod); + entity_list.QueueClients(c, outapp); + safe_delete(outapp); }