From 4672e48fbd4ecdd0e90b5b487ec4ccc34d73076b Mon Sep 17 00:00:00 2001 From: Kinglykrab <89047260+Kinglykrab@users.noreply.github.com> Date: Tue, 23 Nov 2021 16:45:31 -0500 Subject: [PATCH] [Commands] Cleanup #zcolor Command. (#1813) * [Commands] Cleanup #zcolor Command. - Cleanup message and logic. - Add parameter to allow data to be saved to database. * Update zcolor.cpp --- zone/command.cpp | 4 +- zone/gm_commands/zcolor.cpp | 86 ++++++++++++++++++++++++++----------- 2 files changed, 65 insertions(+), 25 deletions(-) diff --git a/zone/command.cpp b/zone/command.cpp index 93aeb69a2..5d5187769 100755 --- a/zone/command.cpp +++ b/zone/command.cpp @@ -390,8 +390,10 @@ int command_init(void) command_add("wpinfo", "- Show waypoint info about your NPC target", AccountStatus::GMAreas, command_wpinfo) || command_add("worldwide", "Performs world-wide GM functions such as cast (can be extended for other commands). Use caution", AccountStatus::GMImpossible, command_worldwide) || command_add("xtargets", "Show your targets Extended Targets and optionally set how many xtargets they can have.", AccountStatus::GMImpossible, command_xtargets) || + command_add("zclip", "[min] [max] - modifies and resends zhdr packet", AccountStatus::QuestTroupe, command_zclip) || + command_add("zheader", "[zonename] - Load zheader for zonename from the database", AccountStatus::QuestTroupe, command_zheader) || command_add("zclip", "[Minimum Clip] [Maximum Clip] [Fog Minimum Clip] [Fog Maximum Clip] [Permanent (0 = False, 1 = True)] - Change zone clipping", AccountStatus::QuestTroupe, command_zclip) || - command_add("zcolor", "[red] [green] [blue] - Change sky color", AccountStatus::QuestTroupe, command_zcolor) || + command_add("zcolor", "[Red] [Green] [Blue] [Permanent (0 = False, 1 = True)] - Change sky color", AccountStatus::QuestTroupe, command_zcolor) || command_add("zheader", "[Zone ID|Zone Short Name] [Version] - Load a zone header from the database", AccountStatus::QuestTroupe, command_zheader) || command_add("zone", "[zonename] [x] [y] [z] - Go to specified zone (coords optional)", AccountStatus::Guide, command_zone) || command_add("zonebootup", "[ZoneServerID] [shortname] - Make a zone server boot a specific zone", AccountStatus::GMLeadAdmin, command_zonebootup) || diff --git a/zone/gm_commands/zcolor.cpp b/zone/gm_commands/zcolor.cpp index feac259b9..bfe8cbd44 100755 --- a/zone/gm_commands/zcolor.cpp +++ b/zone/gm_commands/zcolor.cpp @@ -2,29 +2,67 @@ void command_zcolor(Client *c, const Seperator *sep) { - // modifys and resends zhdr packet - if (sep->arg[3][0] == 0) { - c->Message(Chat::White, "Usage: #zcolor "); + int arguments = sep->argnum; + if ( + !arguments || + !sep->IsNumber(1) || + !sep->IsNumber(2) || + !sep->IsNumber(3) + ) { + c->Message(Chat::White, "Usage: #zcolor [Red] [Green] [Blue] [Permanent (0 = False, 1 = True)]"); + return; } - else if (atoi(sep->arg[1]) < 0 || atoi(sep->arg[1]) > 255) { - c->Message(Chat::White, "ERROR: Red can not be less than 0 or greater than 255!"); - } - else if (atoi(sep->arg[2]) < 0 || atoi(sep->arg[2]) > 255) { - c->Message(Chat::White, "ERROR: Green can not be less than 0 or greater than 255!"); - } - else if (atoi(sep->arg[3]) < 0 || atoi(sep->arg[3]) > 255) { - c->Message(Chat::White, "ERROR: Blue can not be less than 0 or greater than 255!"); - } - else { - for (int z = 0; z < 4; z++) { - zone->newzone_data.fog_red[z] = atoi(sep->arg[1]); - zone->newzone_data.fog_green[z] = atoi(sep->arg[2]); - zone->newzone_data.fog_blue[z] = atoi(sep->arg[3]); - } - 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); - } -} + auto red = std::stoul(sep->arg[1]); + auto green = std::stoul(sep->arg[2]); + auto blue = std::stoul(sep->arg[3]); + auto permanent = sep->arg[4] ? atobool(sep->arg[4]) : false; + if ( + red < 0 || + red > 255 || + green < 0 || + green > 255 || + blue < 0 || + blue > 255 + ) { + c->Message(Chat::White, "Colors cannot be less than 0 or greater than 255."); + return; + } + + if (permanent) { + auto query = fmt::format( + "UPDATE zone SET fog_red = {}, fog_green = {}, fog_blue = {} " + "WHERE zoneidnumber = {} AND version = {}", + red, + green, + blue, + zone->GetZoneID(), + zone->GetInstanceVersion() + ); + database.QueryDatabase(query); + } + + for (int fog_index = 0; fog_index < 4; fog_index++) { + zone->newzone_data.fog_red[fog_index] = static_cast(red); + zone->newzone_data.fog_green[fog_index] = static_cast(green); + zone->newzone_data.fog_blue[fog_index] = static_cast(blue); + } + + 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( + "Fog Color Changed | Zone: {} ({}) Red: {} Green: {} Blue: {} Permanent: {}", + zone->GetLongName(), + zone->GetZoneID(), + red, + green, + blue, + permanent ? "Yes" : "No" + ).c_str() + ); +}