From 2f962c2c8acb7e6351ad756f98e9581c4f1b6a8a Mon Sep 17 00:00:00 2001 From: Kinglykrab <89047260+Kinglykrab@users.noreply.github.com> Date: Fri, 6 May 2022 20:42:25 -0400 Subject: [PATCH] [Commands] Cleanup #refreshgroup Command. (#2119) - Cleanup messages and logic. --- zone/command.cpp | 2 +- zone/gm_commands/refreshgroup.cpp | 55 +++++++++++++++++++++++++++---- zone/zonedb.cpp | 29 ++++++++-------- 3 files changed, 65 insertions(+), 21 deletions(-) diff --git a/zone/command.cpp b/zone/command.cpp index 07be80419..bb308166d 100755 --- a/zone/command.cpp +++ b/zone/command.cpp @@ -286,7 +286,7 @@ int command_init(void) command_add("race", "[racenum] - Change your or your target's race. Use racenum 0 to return to normal", AccountStatus::Guide, command_race) || command_add("raidloot", "[All|GroupLeader|RaidLeader|Selected] - Sets your Raid Loot Type if you have permission to do so.", AccountStatus::Player, command_raidloot) || command_add("randomfeatures", "- Temporarily randomizes the Facial Features of your target", AccountStatus::QuestTroupe, command_randomfeatures) || - command_add("refreshgroup", "- Refreshes Group.", AccountStatus::Player, command_refreshgroup) || + command_add("refreshgroup", "- Refreshes Group for you or your player target.", AccountStatus::Player, command_refreshgroup) || command_add("reloadaa", "Reloads AA data", AccountStatus::GMMgmt, command_reloadaa) || command_add("reloadallrules", "Executes a reload of all rules globally.", AccountStatus::QuestTroupe, command_reloadallrules) || command_add("reloadcontentflags", "Executes a reload of all expansion and content flags", AccountStatus::QuestTroupe, command_reloadcontentflags) || diff --git a/zone/gm_commands/refreshgroup.cpp b/zone/gm_commands/refreshgroup.cpp index 243997141..d4ed1dedb 100755 --- a/zone/gm_commands/refreshgroup.cpp +++ b/zone/gm_commands/refreshgroup.cpp @@ -3,17 +3,58 @@ void command_refreshgroup(Client *c, const Seperator *sep) { - if (!c) { + auto target = c; + if (c->GetTarget() && c->GetTarget()->IsClient()) { + target = c->GetTarget()->CastToClient(); + } + + Group *group = target->GetGroup(); + + if (!group) { + c->Message( + Chat::White, + fmt::format( + "{} not in a group.", + ( + c == target ? + "You are" : + fmt::format( + "{} ({}} is", + target->GetCleanName(), + target->GetID() + ) + ) + ).c_str() + ); return; } - Group *g = c->GetGroup(); + database.RefreshGroupFromDB(target); - if (!g) { - return; + c->Message( + Chat::White, + fmt::format( + "Group has been refreshed for {}.", + ( + c == target ? + "yourself" : + fmt::format( + "{} ({})", + target->GetCleanName(), + target->GetID() + ) + ) + ).c_str() + ); + + if (c != target) { + target->Message( + Chat::White, + fmt::format( + "Your group has been refreshed by {}.", + c->GetCleanName() + ).c_str() + ); } - - database.RefreshGroupFromDB(c); - //g->SendUpdate(7, c); } diff --git a/zone/zonedb.cpp b/zone/zonedb.cpp index 6a4c2e2f4..fec2c6575 100755 --- a/zone/zonedb.cpp +++ b/zone/zonedb.cpp @@ -3205,13 +3205,15 @@ bool ZoneDatabase::SetZoneTZ(uint32 zoneid, uint32 version, uint32 tz) { } void ZoneDatabase::RefreshGroupFromDB(Client *client){ - if(!client) + if (!client) { return; + } Group *group = client->GetGroup(); - if(!group) + if (!group) { return; + } auto outapp = new EQApplicationPacket(OP_GroupUpdate, sizeof(GroupUpdate2_Struct)); GroupUpdate2_Struct* gu = (GroupUpdate2_Struct*)outapp->pBuffer; @@ -3223,19 +3225,21 @@ void ZoneDatabase::RefreshGroupFromDB(Client *client){ int index = 0; - std::string query = StringFormat("SELECT name FROM group_id WHERE groupid = %d", group->GetID()); + auto query = fmt::format( + "SELECT name FROM group_id WHERE groupid = {}", + group->GetID() + ); auto results = QueryDatabase(query); - if (!results.Success()) - { - } - else - { - for (auto row = results.begin(); row != results.end(); ++row) { - if(index >= 6) - continue; - if(strcmp(client->GetName(), row[0]) == 0) + if (results.Success()) { + for (auto row : results) { + if (index >= 6) { continue; + } + + if (!strcmp(client->GetName(), row[0])) { + continue; + } strcpy(gu->membername[index], row[0]); index++; @@ -3256,7 +3260,6 @@ void ZoneDatabase::RefreshGroupFromDB(Client *client){ group->NotifyTankTarget(client); group->NotifyPullerTarget(client); group->SendMarkedNPCsToMember(client); - } uint8 ZoneDatabase::GroupCount(uint32 groupid) {