From ea878ed27f23ef73dc28ac259567334d05d2ee8d Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 30 Jul 2022 20:29:24 -0400 Subject: [PATCH] [Feature] GM State Change Persistance (#2328) * [Feature] GM State Change Persistance - Flymode and Invulnerable will now persist over zoning. - Appended GMSpeed, Flymode and Invulnerable to the hideme message GMs see when they first login. - Added #godmode [on/off] command to turn on or off hideme, flymode, gmspeed and invulnerable all in one shot. - /becomenpc will now disable tells to the target player. It will also automatically disable GM States that interfere with its functionality. - GM Command /toggle will not properly turn tells on/off - GMs will now be notified if they are ignoring tells when they first zone-in, provided their GM flag is up. - Added TellsOff variable to the output to #showstats * [Bug] Fix tells when gmhideme is turned off. * [Cleanup] Cleanup function and rename for consistancy. Remove un-needed this-> * Tweaks * Tweaks * Update db_update_manifest.txt * Move string building logic to a vector and use strings join * Update client_packet.cpp * Update 2022_07_28_gm_state_changes.sql * PR comment tweaks Co-authored-by: Akkadius --- .../base/base_account_repository.h | 134 +++++++++++------- common/shareddb.cpp | 57 +++++--- common/shareddb.h | 2 + utils/sql/db_update_manifest.txt | 1 + .../required/2022_07_28_gm_state_changes.sql | 4 + world/zoneserver.cpp | 16 +-- zone/client.cpp | 21 +-- zone/client.h | 2 + zone/client_packet.cpp | 94 ++++++++---- zone/command.cpp | 2 + zone/command.h | 1 + zone/gm_commands/flymode.cpp | 2 + zone/gm_commands/godmode.cpp | 33 +++++ zone/gm_commands/invul.cpp | 6 +- zone/inventory.cpp | 2 +- 15 files changed, 252 insertions(+), 125 deletions(-) create mode 100644 utils/sql/git/required/2022_07_28_gm_state_changes.sql create mode 100644 zone/gm_commands/godmode.cpp diff --git a/common/repositories/base/base_account_repository.h b/common/repositories/base/base_account_repository.h index 6c889c1de..a5d1d09ba 100644 --- a/common/repositories/base/base_account_repository.h +++ b/common/repositories/base/base_account_repository.h @@ -28,6 +28,9 @@ public: std::string ls_id; int lsaccount_id; int gmspeed; + int invulnerable; + int flymode; + int ignore_tells; int revoked; int karma; std::string minilogin_ip; @@ -60,6 +63,9 @@ public: "ls_id", "lsaccount_id", "gmspeed", + "invulnerable", + "flymode", + "ignore_tells", "revoked", "karma", "minilogin_ip", @@ -88,6 +94,9 @@ public: "ls_id", "lsaccount_id", "gmspeed", + "invulnerable", + "flymode", + "ignore_tells", "revoked", "karma", "minilogin_ip", @@ -150,6 +159,9 @@ public: entry.ls_id = "eqemu"; entry.lsaccount_id = 0; entry.gmspeed = 0; + entry.invulnerable = 0; + entry.flymode = 0; + entry.ignore_tells = 0; entry.revoked = 0; entry.karma = 0; entry.minilogin_ip = ""; @@ -207,19 +219,22 @@ public: entry.ls_id = row[6] ? row[6] : ""; entry.lsaccount_id = atoi(row[7]); entry.gmspeed = atoi(row[8]); - entry.revoked = atoi(row[9]); - entry.karma = atoi(row[10]); - entry.minilogin_ip = row[11] ? row[11] : ""; - entry.hideme = atoi(row[12]); - entry.rulesflag = atoi(row[13]); - entry.suspendeduntil = strtoll(row[14] ? row[14] : "-1", nullptr, 10); - entry.time_creation = atoi(row[15]); - entry.expansion = atoi(row[16]); - entry.ban_reason = row[17] ? row[17] : ""; - entry.suspend_reason = row[18] ? row[18] : ""; - entry.crc_eqgame = row[19] ? row[19] : ""; - entry.crc_skillcaps = row[20] ? row[20] : ""; - entry.crc_basedata = row[21] ? row[21] : ""; + entry.invulnerable = atoi(row[9]); + entry.flymode = atoi(row[10]); + entry.ignore_tells = atoi(row[11]); + entry.revoked = atoi(row[12]); + entry.karma = atoi(row[13]); + entry.minilogin_ip = row[14] ? row[14] : ""; + entry.hideme = atoi(row[15]); + entry.rulesflag = atoi(row[16]); + entry.suspendeduntil = strtoll(row[17] ? row[17] : "-1", nullptr, 10); + entry.time_creation = atoi(row[18]); + entry.expansion = atoi(row[19]); + entry.ban_reason = row[20] ? row[20] : ""; + entry.suspend_reason = row[21] ? row[21] : ""; + entry.crc_eqgame = row[22] ? row[22] : ""; + entry.crc_skillcaps = row[23] ? row[23] : ""; + entry.crc_basedata = row[24] ? row[24] : ""; return entry; } @@ -261,19 +276,22 @@ public: update_values.push_back(columns[6] + " = '" + Strings::Escape(account_entry.ls_id) + "'"); update_values.push_back(columns[7] + " = " + std::to_string(account_entry.lsaccount_id)); update_values.push_back(columns[8] + " = " + std::to_string(account_entry.gmspeed)); - update_values.push_back(columns[9] + " = " + std::to_string(account_entry.revoked)); - update_values.push_back(columns[10] + " = " + std::to_string(account_entry.karma)); - update_values.push_back(columns[11] + " = '" + Strings::Escape(account_entry.minilogin_ip) + "'"); - update_values.push_back(columns[12] + " = " + std::to_string(account_entry.hideme)); - update_values.push_back(columns[13] + " = " + std::to_string(account_entry.rulesflag)); - update_values.push_back(columns[14] + " = FROM_UNIXTIME(" + (account_entry.suspendeduntil > 0 ? std::to_string(account_entry.suspendeduntil) : "null") + ")"); - update_values.push_back(columns[15] + " = " + std::to_string(account_entry.time_creation)); - update_values.push_back(columns[16] + " = " + std::to_string(account_entry.expansion)); - update_values.push_back(columns[17] + " = '" + Strings::Escape(account_entry.ban_reason) + "'"); - update_values.push_back(columns[18] + " = '" + Strings::Escape(account_entry.suspend_reason) + "'"); - update_values.push_back(columns[19] + " = '" + Strings::Escape(account_entry.crc_eqgame) + "'"); - update_values.push_back(columns[20] + " = '" + Strings::Escape(account_entry.crc_skillcaps) + "'"); - update_values.push_back(columns[21] + " = '" + Strings::Escape(account_entry.crc_basedata) + "'"); + update_values.push_back(columns[9] + " = " + std::to_string(account_entry.invulnerable)); + update_values.push_back(columns[10] + " = " + std::to_string(account_entry.flymode)); + update_values.push_back(columns[11] + " = " + std::to_string(account_entry.ignore_tells)); + update_values.push_back(columns[12] + " = " + std::to_string(account_entry.revoked)); + update_values.push_back(columns[13] + " = " + std::to_string(account_entry.karma)); + update_values.push_back(columns[14] + " = '" + Strings::Escape(account_entry.minilogin_ip) + "'"); + update_values.push_back(columns[15] + " = " + std::to_string(account_entry.hideme)); + update_values.push_back(columns[16] + " = " + std::to_string(account_entry.rulesflag)); + update_values.push_back(columns[17] + " = FROM_UNIXTIME(" + (account_entry.suspendeduntil > 0 ? std::to_string(account_entry.suspendeduntil) : "null") + ")"); + update_values.push_back(columns[18] + " = " + std::to_string(account_entry.time_creation)); + update_values.push_back(columns[19] + " = " + std::to_string(account_entry.expansion)); + update_values.push_back(columns[20] + " = '" + Strings::Escape(account_entry.ban_reason) + "'"); + update_values.push_back(columns[21] + " = '" + Strings::Escape(account_entry.suspend_reason) + "'"); + update_values.push_back(columns[22] + " = '" + Strings::Escape(account_entry.crc_eqgame) + "'"); + update_values.push_back(columns[23] + " = '" + Strings::Escape(account_entry.crc_skillcaps) + "'"); + update_values.push_back(columns[24] + " = '" + Strings::Escape(account_entry.crc_basedata) + "'"); auto results = db.QueryDatabase( fmt::format( @@ -304,6 +322,9 @@ public: insert_values.push_back("'" + Strings::Escape(account_entry.ls_id) + "'"); insert_values.push_back(std::to_string(account_entry.lsaccount_id)); insert_values.push_back(std::to_string(account_entry.gmspeed)); + insert_values.push_back(std::to_string(account_entry.invulnerable)); + insert_values.push_back(std::to_string(account_entry.flymode)); + insert_values.push_back(std::to_string(account_entry.ignore_tells)); insert_values.push_back(std::to_string(account_entry.revoked)); insert_values.push_back(std::to_string(account_entry.karma)); insert_values.push_back("'" + Strings::Escape(account_entry.minilogin_ip) + "'"); @@ -355,6 +376,9 @@ public: insert_values.push_back("'" + Strings::Escape(account_entry.ls_id) + "'"); insert_values.push_back(std::to_string(account_entry.lsaccount_id)); insert_values.push_back(std::to_string(account_entry.gmspeed)); + insert_values.push_back(std::to_string(account_entry.invulnerable)); + insert_values.push_back(std::to_string(account_entry.flymode)); + insert_values.push_back(std::to_string(account_entry.ignore_tells)); insert_values.push_back(std::to_string(account_entry.revoked)); insert_values.push_back(std::to_string(account_entry.karma)); insert_values.push_back("'" + Strings::Escape(account_entry.minilogin_ip) + "'"); @@ -410,19 +434,22 @@ public: entry.ls_id = row[6] ? row[6] : ""; entry.lsaccount_id = atoi(row[7]); entry.gmspeed = atoi(row[8]); - entry.revoked = atoi(row[9]); - entry.karma = atoi(row[10]); - entry.minilogin_ip = row[11] ? row[11] : ""; - entry.hideme = atoi(row[12]); - entry.rulesflag = atoi(row[13]); - entry.suspendeduntil = strtoll(row[14] ? row[14] : "-1", nullptr, 10); - entry.time_creation = atoi(row[15]); - entry.expansion = atoi(row[16]); - entry.ban_reason = row[17] ? row[17] : ""; - entry.suspend_reason = row[18] ? row[18] : ""; - entry.crc_eqgame = row[19] ? row[19] : ""; - entry.crc_skillcaps = row[20] ? row[20] : ""; - entry.crc_basedata = row[21] ? row[21] : ""; + entry.invulnerable = atoi(row[9]); + entry.flymode = atoi(row[10]); + entry.ignore_tells = atoi(row[11]); + entry.revoked = atoi(row[12]); + entry.karma = atoi(row[13]); + entry.minilogin_ip = row[14] ? row[14] : ""; + entry.hideme = atoi(row[15]); + entry.rulesflag = atoi(row[16]); + entry.suspendeduntil = strtoll(row[17] ? row[17] : "-1", nullptr, 10); + entry.time_creation = atoi(row[18]); + entry.expansion = atoi(row[19]); + entry.ban_reason = row[20] ? row[20] : ""; + entry.suspend_reason = row[21] ? row[21] : ""; + entry.crc_eqgame = row[22] ? row[22] : ""; + entry.crc_skillcaps = row[23] ? row[23] : ""; + entry.crc_basedata = row[24] ? row[24] : ""; all_entries.push_back(entry); } @@ -456,19 +483,22 @@ public: entry.ls_id = row[6] ? row[6] : ""; entry.lsaccount_id = atoi(row[7]); entry.gmspeed = atoi(row[8]); - entry.revoked = atoi(row[9]); - entry.karma = atoi(row[10]); - entry.minilogin_ip = row[11] ? row[11] : ""; - entry.hideme = atoi(row[12]); - entry.rulesflag = atoi(row[13]); - entry.suspendeduntil = strtoll(row[14] ? row[14] : "-1", nullptr, 10); - entry.time_creation = atoi(row[15]); - entry.expansion = atoi(row[16]); - entry.ban_reason = row[17] ? row[17] : ""; - entry.suspend_reason = row[18] ? row[18] : ""; - entry.crc_eqgame = row[19] ? row[19] : ""; - entry.crc_skillcaps = row[20] ? row[20] : ""; - entry.crc_basedata = row[21] ? row[21] : ""; + entry.invulnerable = atoi(row[9]); + entry.flymode = atoi(row[10]); + entry.ignore_tells = atoi(row[11]); + entry.revoked = atoi(row[12]); + entry.karma = atoi(row[13]); + entry.minilogin_ip = row[14] ? row[14] : ""; + entry.hideme = atoi(row[15]); + entry.rulesflag = atoi(row[16]); + entry.suspendeduntil = strtoll(row[17] ? row[17] : "-1", nullptr, 10); + entry.time_creation = atoi(row[18]); + entry.expansion = atoi(row[19]); + entry.ban_reason = row[20] ? row[20] : ""; + entry.suspend_reason = row[21] ? row[21] : ""; + entry.crc_eqgame = row[22] ? row[22] : ""; + entry.crc_skillcaps = row[23] ? row[23] : ""; + entry.crc_basedata = row[24] ? row[24] : ""; all_entries.push_back(entry); } diff --git a/common/shareddb.cpp b/common/shareddb.cpp index 35cedb324..1798cebca 100644 --- a/common/shareddb.cpp +++ b/common/shareddb.cpp @@ -39,6 +39,7 @@ #include "eqemu_config.h" #include "data_verification.h" #include "repositories/criteria/content_filter_criteria.h" +#include "repositories/account_repository.h" namespace ItemField { @@ -65,40 +66,56 @@ SharedDatabase::~SharedDatabase() = default; bool SharedDatabase::SetHideMe(uint32 account_id, uint8 hideme) { - const std::string query = StringFormat("UPDATE account SET hideme = %i WHERE id = %i", hideme, account_id); - const auto results = QueryDatabase(query); - if (!results.Success()) { - return false; + auto a = AccountRepository::FindOne(*this, account_id); + if (a.id > 0) { + a.hideme = hideme ? 1 : 0; + AccountRepository::UpdateOne(*this, a); } - return true; + return a.id > 0; } uint8 SharedDatabase::GetGMSpeed(uint32 account_id) { - const std::string query = StringFormat("SELECT gmspeed FROM account WHERE id = '%i'", account_id); - auto results = QueryDatabase(query); - if (!results.Success()) { - return 0; + auto a = AccountRepository::FindOne(*this, account_id); + if (a.id > 0) { + return a.gmspeed; } - if (results.RowCount() != 1) - return 0; - - auto& row = results.begin(); - - return atoi(row[0]); + return 0; } bool SharedDatabase::SetGMSpeed(uint32 account_id, uint8 gmspeed) { - const std::string query = StringFormat("UPDATE account SET gmspeed = %i WHERE id = %i", gmspeed, account_id); - const auto results = QueryDatabase(query); - if (!results.Success()) { - return false; + auto a = AccountRepository::FindOne(*this, account_id); + if (a.id > 0) { + a.gmspeed = gmspeed ? 1 : 0; + AccountRepository::UpdateOne(*this, a); } - return true; + return a.id > 0; +} + +bool SharedDatabase::SetGMInvul(uint32 account_id, bool gminvul) +{ + auto a = AccountRepository::FindOne(*this, account_id); + if (a.id > 0) { + a.invulnerable = gminvul ? 1 : 0; + AccountRepository::UpdateOne(*this, a); + } + + return a.id > 0; +} + +bool SharedDatabase::SetGMFlymode(uint32 account_id, uint8 flymode) +{ + auto a = AccountRepository::FindOne(*this, account_id); + if (a.id > 0) { + a.flymode = flymode; + AccountRepository::UpdateOne(*this, a); + } + + return a.id > 0; } uint32 SharedDatabase::GetTotalTimeEntitledOnAccount(uint32 AccountID) { diff --git a/common/shareddb.h b/common/shareddb.h index f8b0ce6b7..49b9837c0 100644 --- a/common/shareddb.h +++ b/common/shareddb.h @@ -79,6 +79,8 @@ public: bool UpdateInjectedCommandSettings(const std::vector> &injected); bool UpdateOrphanedCommandSettings(const std::vector &orphaned); uint32 GetTotalTimeEntitledOnAccount(uint32 AccountID); + bool SetGMInvul(uint32 account_id, bool gminvul); + bool SetGMFlymode(uint32 account_id, uint8 flymode); void SetMailKey(int CharID, int IPAddress, int MailKey); std::string GetMailKey(int CharID, bool key_only = false); bool SaveCursor( diff --git a/utils/sql/db_update_manifest.txt b/utils/sql/db_update_manifest.txt index 58fd399a8..6a34ac161 100644 --- a/utils/sql/db_update_manifest.txt +++ b/utils/sql/db_update_manifest.txt @@ -444,6 +444,7 @@ 9188|2022_07_14_zone_expansion_revert.sql|SHOW COLUMNS FROM `zone` LIKE 'expansion'|empty| 9189|2022_07_10_character_task_rewarded.sql|SHOW COLUMNS FROM `character_tasks` LIKE 'was_rewarded'|empty| 9190|2022_07_13_task_reward_points.sql|SHOW COLUMNS FROM `tasks` LIKE 'reward_points'|empty| +9191|2022_07_28_gm_state_changes.sql|SHOW COLUMNS FROM `account` LIKE 'invulnerable'|empty| # Upgrade conditions: # This won't be needed after this system is implemented, but it is used database that are not diff --git a/utils/sql/git/required/2022_07_28_gm_state_changes.sql b/utils/sql/git/required/2022_07_28_gm_state_changes.sql new file mode 100644 index 000000000..ef61477d6 --- /dev/null +++ b/utils/sql/git/required/2022_07_28_gm_state_changes.sql @@ -0,0 +1,4 @@ +ALTER TABLE `account` + ADD COLUMN `invulnerable` TINYINT(4) NULL DEFAULT '0' AFTER `gmspeed`, + ADD COLUMN `flymode` TINYINT(4) NULL DEFAULT '0' AFTER `invulnerable`, + ADD COLUMN `ignore_tells` TINYINT(4) NULL DEFAULT '0' AFTER `flymode`; diff --git a/world/zoneserver.cpp b/world/zoneserver.cpp index 758307fc5..50b35351d 100644 --- a/world/zoneserver.cpp +++ b/world/zoneserver.cpp @@ -457,27 +457,25 @@ void ZoneServer::HandleMessage(uint16 opcode, const EQ::Net::Packet &p) { ( cle->TellsOff() && ( - ( - cle->Anon() == 1 && - scm->fromadmin < cle->Admin() - ) || - scm->fromadmin < AccountStatus::QuestTroupe + scm->fromadmin < cle->Admin() + || scm->fromadmin < AccountStatus::QuestTroupe ) ) - ) { + ) { if (!scm->noreply) { auto sender = client_list.FindCharacter(scm->from); if (!sender || !sender->Server()) { break; } - scm->noreply = true; - scm->queued = 3; // offline + scm->noreply = true; + scm->queued = 3; // offline scm->chan_num = ChatChannel_TellEcho; strcpy(scm->deliverto, scm->from); sender->Server()->SendPacket(pack); } - } else if (cle->Online() == CLE_Status::Zoning) { + } + else if (cle->Online() == CLE_Status::Zoning) { if (!scm->noreply) { auto sender = client_list.FindCharacter(scm->from); if (cle->TellQueueFull()) { diff --git a/zone/client.cpp b/zone/client.cpp index 0fcc69d3f..346a4c719 100644 --- a/zone/client.cpp +++ b/zone/client.cpp @@ -220,6 +220,7 @@ Client::Client(EQStreamInterface* ieqs) LFGComments[0] = '\0'; LFP = false; gmspeed = 0; + gminvul = false; playeraction = 0; SetTarget(0); auto_attack = false; @@ -3378,27 +3379,26 @@ void Client::SetTint(int16 in_slot, EQ::textures::Tint_Struct& color) { } -void Client::SetHideMe(bool flag) +void Client::SetHideMe(bool gm_hide_me) { EQApplicationPacket app; - gm_hide_me = flag; - - if(gm_hide_me) - { - database.SetHideMe(AccountID(),true); + if (gm_hide_me) { + database.SetHideMe(AccountID(), true); CreateDespawnPacket(&app, false); entity_list.RemoveFromTargets(this); trackable = false; + tellsoff = true; } - else - { - database.SetHideMe(AccountID(),false); + else { + database.SetHideMe(AccountID(), false); CreateSpawnPacket(&app); trackable = true; + tellsoff = false; } - entity_list.QueueClientsStatus(this, &app, true, 0, Admin()-1); + entity_list.QueueClientsStatus(this, &app, true, 0, Admin() - 1); + UpdateWho(); } void Client::SetLanguageSkill(int langid, int value) @@ -7092,6 +7092,7 @@ void Client::SendStatsWindow(Client* client, bool use_window) client->Message(Chat::White, " compute_tohit: %i TotalToHit: %i", compute_tohit(skill), GetTotalToHit(skill, 0)); client->Message(Chat::White, " compute_defense: %i TotalDefense: %i", compute_defense(), GetTotalDefense()); client->Message(Chat::White, " offense: %i mitigation ac: %i", offense(skill), GetMitigationAC()); + client->Message(Chat::White, " AFK: %i LFG: %i Anon: %i PVP: %i GM: %i Flymode: %i GMSpeed: %i Hideme: %i GMInvul: %d LD: %i ClientVersion: %i TellsOff: %i", AFK, LFG, GetAnon(), GetPVP(), GetGM(), flymode, GetGMSpeed(), GetHideMe(), GetGMInvul(), IsLD(), ClientVersionBit(), tellsoff); if(CalcMaxMana() > 0) client->Message(Chat::White, " Mana: %i/%i Mana Regen: %i/%i", GetMana(), GetMaxMana(), CalcManaRegen(), CalcManaRegenCap()); client->Message(Chat::White, " End.: %i/%i End. Regen: %i/%i",GetEndurance(), GetMaxEndurance(), CalcEnduranceRegen(), CalcEnduranceRegenCap()); diff --git a/zone/client.h b/zone/client.h index 99e02e002..c45914fc0 100644 --- a/zone/client.h +++ b/zone/client.h @@ -1040,6 +1040,7 @@ public: void SendRules(); const bool GetGMSpeed() const { return (gmspeed > 0); } + const bool GetGMInvul() const { return gminvul; } bool CanUseReport; //This is used to later set the buff duration of the spell, in slot to duration. @@ -1786,6 +1787,7 @@ private: bool auto_fire; bool runmode; uint8 gmspeed; + bool gminvul; bool medding; uint16 horseId; bool revoked; diff --git a/zone/client_packet.cpp b/zone/client_packet.cpp index ff72a57d5..252a940d6 100644 --- a/zone/client_packet.cpp +++ b/zone/client_packet.cpp @@ -68,6 +68,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "../common/shared_tasks.h" #include "gm_commands/door_manipulation.h" #include "client.h" +#include "../common/repositories/account_repository.h" #ifdef BOTS @@ -569,7 +570,31 @@ void Client::CompleteConnect() //SendAATable(); - if (GetHideMe()) Message(Chat::Red, "[GM] You are currently hidden to all clients"); + if (GetGM() && (GetHideMe() || GetGMSpeed() || GetGMInvul() || flymode != 0 || tellsoff)) { + std::vector state; + if (GetHideMe()) { + state.emplace_back("hidden to all clients"); + } + if (GetGMSpeed()) { + state.emplace_back("running at GM speed"); + } + if (GetGMInvul()) { + state.emplace_back("invulnerable to all damage"); + } + if (flymode == GravityBehavior::Flying) { + state.emplace_back("flying"); + } + else if (flymode == GravityBehavior::Levitating) { + state.emplace_back("levitating"); + } + if (tellsoff) { + state.emplace_back("ignoring tells"); + } + + if (!state.empty()) { + Message(Chat::Red, "[GM] You are currently %s.", Strings::Join(state, ", ").c_str()); + } + } uint32 raidid = database.GetRaidID(GetName()); Raid *raid = nullptr; @@ -1184,23 +1209,25 @@ void Client::Handle_Connect_OP_ZoneEntry(const EQApplicationPacket *app) database.RemoveTempFactions(this); database.LoadCharacterFactionValues(cid, factionvalues); - /* Load Character Account Data: Temp until I move */ - query = StringFormat("SELECT `status`, `name`, `ls_id`, `lsaccount_id`, `gmspeed`, `revoked`, `hideme`, `time_creation` FROM `account` WHERE `id` = %u", AccountID()); - auto results = database.QueryDatabase(query); - for (auto row = results.begin(); row != results.end(); ++row) { - admin = atoi(row[0]); - strn0cpy(account_name, row[1], sizeof(account_name)); - strn0cpy(loginserver, row[2], sizeof(loginserver)); - lsaccountid = atoi(row[3]); - gmspeed = atoi(row[4]); - revoked = atoi(row[5]); - gm_hide_me = atoi(row[6]); - account_creation = atoul(row[7]); + auto a = AccountRepository::FindOne(database, AccountID()); + if (a.id > 0) { + strn0cpy(account_name, a.name.c_str(), sizeof(account_name)); + strn0cpy(loginserver, a.ls_id.c_str(), sizeof(loginserver)); + + admin = a.status; + lsaccountid = a.lsaccount_id; + gmspeed = a.gmspeed; + revoked = a.revoked; + gm_hide_me = a.hideme; + account_creation = a.time_creation; + gminvul = a.invulnerable; + flymode = static_cast(a.flymode); + tellsoff = gm_hide_me; } /* Load Character Data */ query = StringFormat("SELECT `lfp`, `lfg`, `xtargets`, `firstlogon`, `guild_id`, `rank` FROM `character_data` LEFT JOIN `guild_members` ON `id` = `char_id` WHERE `id` = %i", cid); - results = database.QueryDatabase(query); + auto results = database.QueryDatabase(query); for (auto row = results.begin(); row != results.end(); ++row) { if (row[4] && atoi(row[4]) > 0) { guild_id = atoi(row[4]); @@ -1266,6 +1293,8 @@ void Client::Handle_Connect_OP_ZoneEntry(const EQApplicationPacket *app) /* If GM, not trackable */ if (gm_hide_me) { trackable = false; } + if (gminvul) { invulnerable = true; } + if (flymode > 0) { SendAppearancePacket(AT_Levitate, flymode); } /* Set Con State for Reporting */ conn_state = PlayerProfileLoaded; @@ -6117,17 +6146,26 @@ void Client::Handle_OP_GMBecomeNPC(const EQApplicationPacket *app) BecomeNPC_Struct* bnpc = (BecomeNPC_Struct*)app->pBuffer; Mob* cli = (Mob*)entity_list.GetMob(bnpc->id); - if (cli == 0) + if (cli == nullptr) { return; + } - if (cli->IsClient()) - cli->CastToClient()->QueuePacket(app); - cli->SendAppearancePacket(AT_NPCName, 1, true); - cli->CastToClient()->SetBecomeNPC(true); - cli->CastToClient()->SetBecomeNPCLevel(bnpc->maxlevel); - cli->MessageString(Chat::White, TOGGLE_OFF); - cli->CastToClient()->tellsoff = true; - //TODO: Make this toggle a BecomeNPC flag so that it gets updated when people zone in as well; Make combat work with this. + if (cli->IsClient()) { + Client* target = cli->CastToClient(); + target->QueuePacket(app); + if(target->GetGM()) { + target->SetInvul(false); + target->SetHideMe(false); + target->SetGM(false); + } + + cli->SendAppearancePacket(AT_NPCName, 1, true); + target->SetBecomeNPC(true); + target->SetBecomeNPCLevel(bnpc->maxlevel); + cli->MessageString(Chat::White, TOGGLE_OFF); + target->tellsoff = true; + target->UpdateWho(); + } return; } @@ -6532,16 +6570,12 @@ void Client::Handle_OP_GMToggle(const EQApplicationPacket *app) GMToggle_Struct *ts = (GMToggle_Struct *)app->pBuffer; if (ts->toggle == 0) { MessageString(Chat::White, TOGGLE_OFF); - //Message(0, "Turning tells OFF"); tellsoff = true; - } - else if (ts->toggle == 1) { - //Message(0, "Turning tells ON"); + } else if (ts->toggle == 1) { MessageString(Chat::White, TOGGLE_ON); tellsoff = false; - } - else { - Message(0, "Unkown value in /toggle packet"); + } else { + Message(Chat::White, "Unkown value in /toggle packet"); } UpdateWho(); return; diff --git a/zone/command.cpp b/zone/command.cpp index 13c697f98..629cd783f 100755 --- a/zone/command.cpp +++ b/zone/command.cpp @@ -166,6 +166,7 @@ int command_init(void) command_add("gm", "[On|Off] - Modify your or your target's GM Flag", AccountStatus::QuestTroupe, command_gm) || command_add("gmspeed", "[On|Off] - Turn GM Speed On or Off for you or your player target", AccountStatus::GMAdmin, command_gmspeed) || command_add("gmzone", "[Zone ID|Zone Short Name] [Version] [Instance Identifier] - Zones to a private GM instance (Version defaults to 0 and Instance Identifier defaults to 'gmzone' if not used)", AccountStatus::GMAdmin, command_gmzone) || + command_add("godmode", "[on/off] - Turns on/off hideme, gmspeed, invul, and flymode.", AccountStatus::GMMgmt, command_godmode) || command_add("goto", "[playername] or [x y z] [h] - Teleport to the provided coordinates or to your target", AccountStatus::Steward, command_goto) || command_add("grid", "[add/delete] [grid_num] [wandertype] [pausetype] - Create/delete a wandering grid", AccountStatus::GMAreas, command_grid) || command_add("guild", "Guild manipulation commands. Use argument help for more info.", AccountStatus::Steward, command_guild) || @@ -1007,6 +1008,7 @@ void command_bot(Client *c, const Seperator *sep) #include "gm_commands/gm.cpp" #include "gm_commands/gmspeed.cpp" #include "gm_commands/gmzone.cpp" +#include "gm_commands/godmode.cpp" #include "gm_commands/goto.cpp" #include "gm_commands/grid.cpp" #include "gm_commands/guild.cpp" diff --git a/zone/command.h b/zone/command.h index 1e3641096..9c8dcf5d4 100644 --- a/zone/command.h +++ b/zone/command.h @@ -105,6 +105,7 @@ void command_globalview(Client *c, const Seperator *sep); void command_gm(Client *c, const Seperator *sep); void command_gmspeed(Client *c, const Seperator *sep); void command_gmzone(Client *c, const Seperator *sep); +void command_godmode(Client* c, const Seperator *sep); void command_goto(Client *c, const Seperator *sep); void command_grid(Client *c, const Seperator *sep); void command_guild(Client *c, const Seperator *sep); diff --git a/zone/gm_commands/flymode.cpp b/zone/gm_commands/flymode.cpp index 58dcf0c7b..c22889b26 100755 --- a/zone/gm_commands/flymode.cpp +++ b/zone/gm_commands/flymode.cpp @@ -24,6 +24,8 @@ void command_flymode(Client *c, const Seperator *sep) target->SetFlyMode(static_cast(flymode_id)); target->SendAppearancePacket(AT_Levitate, flymode_id); + uint32 account = c->AccountID(); + database.SetGMFlymode(account, flymode_id); c->Message( Chat::White, fmt::format( diff --git a/zone/gm_commands/godmode.cpp b/zone/gm_commands/godmode.cpp new file mode 100644 index 000000000..81ecbe93d --- /dev/null +++ b/zone/gm_commands/godmode.cpp @@ -0,0 +1,33 @@ +#include "../client.h" +#include "../../common/repositories/account_repository.h" + +void command_godmode(Client *c, const Seperator *sep) +{ + bool state = atobool(sep->arg[1]); + uint32 account_id = c->AccountID(); + + if (sep->arg[1][0] != 0) { + auto a = AccountRepository::FindOne(database, c->AccountID()); + if (a.id > 0) { + a.flymode = state ? 1 : 0; + a.gmspeed = state ? 1 : 0; + a.invulnerable = state ? 1 : 0; + a.hideme = state ? 1 : 0; + } + + c->SetInvul(state); + c->SendAppearancePacket(AT_Levitate, state); + c->SetHideMe(state); + c->Message( + Chat::White, + "Turning GodMode %s for %s (zone for gmspeed to take effect)", + state ? "On" : "Off", + c->GetName() + ); + + AccountRepository::UpdateOne(database, a); + } + else { + c->Message(Chat::White, "Usage: #godmode [on/off]"); + } +} diff --git a/zone/gm_commands/invul.cpp b/zone/gm_commands/invul.cpp index 18fa2aa6a..398cd5174 100755 --- a/zone/gm_commands/invul.cpp +++ b/zone/gm_commands/invul.cpp @@ -1,7 +1,6 @@ #include "../client.h" -void command_invul(Client *c, const Seperator *sep) -{ +void command_invul(Client *c, const Seperator *sep) { int arguments = sep->argnum; if (!arguments) { c->Message(Chat::White, "Usage: #invul [On|Off]"); @@ -15,6 +14,8 @@ void command_invul(Client *c, const Seperator *sep) } target->SetInvul(invul_flag); + uint32 account = target->AccountID(); + database.SetGMInvul(account, invul_flag); c->Message( Chat::White, fmt::format( @@ -25,4 +26,3 @@ void command_invul(Client *c, const Seperator *sep) ).c_str() ); } - diff --git a/zone/inventory.cpp b/zone/inventory.cpp index 055b3931c..b7b5d33ce 100644 --- a/zone/inventory.cpp +++ b/zone/inventory.cpp @@ -1959,7 +1959,7 @@ bool Client::SwapItem(MoveItem_Struct* move_in) { // Check for No Drop Hacks Mob* with = trade->With(); - if (((with && with->IsClient() && dst_slot_id >= EQ::invslot::TRADE_BEGIN && dst_slot_id <= EQ::invslot::TRADE_END) || + if (((with && with->IsClient() && !with->CastToClient()->IsBecomeNPC() && dst_slot_id >= EQ::invslot::TRADE_BEGIN && dst_slot_id <= EQ::invslot::TRADE_END) || (dst_slot_id >= EQ::invslot::SHARED_BANK_BEGIN && dst_slot_id <= EQ::invbag::SHARED_BANK_BAGS_END)) && GetInv().CheckNoDrop(src_slot_id) && !CanTradeFVNoDropItem()) {