From 26c728799731c711f7c461d31f985f93c26b72da Mon Sep 17 00:00:00 2001 From: Kinglykrab <89047260+Kinglykrab@users.noreply.github.com> Date: Mon, 22 Nov 2021 21:16:42 -0500 Subject: [PATCH] [Commands] Cleanup #zunderworld Command. (#1809) * [Commands] Cleanup #zunderworld Command. - Cleanup message and logic. - Add parameter to allow data to be saved to database. * Update zunderworld.cpp --- zone/command.cpp | 2 +- zone/gm_commands/zunderworld.cpp | 39 +++++++++++++++++++++++++++----- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/zone/command.cpp b/zone/command.cpp index 5742da04f..2ea3a98d5 100755 --- a/zone/command.cpp +++ b/zone/command.cpp @@ -405,7 +405,7 @@ int command_init(void) command_add("zsave", " - Saves zheader to the database", AccountStatus::QuestTroupe, command_zsave) || command_add("zsky", "[skytype] - Change zone sky type", AccountStatus::QuestTroupe, command_zsky) || command_add("zstats", "- Show info about zone header", AccountStatus::QuestTroupe, command_zstats) || - command_add("zunderworld", "[zcoord] - Sets the underworld using zcoord", AccountStatus::QuestTroupe, command_zunderworld) || + command_add("zunderworld", "[Z] [Permanent (0 = False, 1 = True)] - Change zone underworld Z", AccountStatus::QuestTroupe, command_zunderworld) || command_add("zuwcoords", "[z coord] - Set underworld coord", AccountStatus::QuestTroupe, command_zuwcoords) ) { command_deinit(); diff --git a/zone/gm_commands/zunderworld.cpp b/zone/gm_commands/zunderworld.cpp index 0ba52f156..88499dc2e 100755 --- a/zone/gm_commands/zunderworld.cpp +++ b/zone/gm_commands/zunderworld.cpp @@ -2,11 +2,38 @@ void command_zunderworld(Client *c, const Seperator *sep) { - if (sep->arg[1][0] == 0) { - c->Message(Chat::White, "Usage: #zunderworld "); + int arguments = sep->argnum; + if (!arguments || !sep->IsNumber(1)) { + c->Message(Chat::White, "Usage: #zunderworld [Z] [Permanent (0 = False, 1 = True)]"); + return; } - else { - zone->newzone_data.underworld = atof(sep->arg[1]); - } -} + auto z = std::stof(sep->arg[1]); + auto permanent = sep->arg[2] ? atobool(sep->arg[2]) : false; + if (permanent) { + auto query = fmt::format( + "UPDATE zone SET underworld = {:.2f} WHERE zoneidnumber = {} AND version = {}", + z, + zone->GetZoneID(), + zone->GetInstanceVersion() + ); + database.QueryDatabase(query); + } + + zone->newzone_data.underworld = z; + auto outapp = new EQApplicationPacket(OP_NewZone, sizeof(NewZone_Struct)); + memcpy(outapp->pBuffer, &zone->newzone_data, outapp->size); + entity_list.QueueClients(c, outapp); + safe_delete(outapp); + + c->Message( + Chat::White, + fmt::format( + "Underworld Z Changed | Zone: {} ({}) Z: {:.2f} Permanent: {}", + zone->GetLongName(), + zone->GetZoneID(), + z, + permanent ? "Yes" : "No" + ).c_str() + ); +}