From fab0fc421be11750264f3dae0f6603fc439a118b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francesco=20Borz=C3=AC?= Date: Sun, 18 Jul 2021 13:25:44 +0200 Subject: [PATCH] refactor(Scripts/Commands): code cleanup (part 4) (#6921) --- src/server/scripts/Commands/cs_ban.cpp | 20 +++++++-------- src/server/scripts/Commands/cs_list.cpp | 1 - src/server/scripts/Commands/cs_misc.cpp | 30 +++++++++++++---------- src/server/scripts/Commands/cs_mmaps.cpp | 15 +----------- src/server/scripts/Commands/cs_npc.cpp | 4 +-- src/server/scripts/Commands/cs_player.cpp | 27 ++++++++++++++------ src/server/scripts/Commands/cs_server.cpp | 1 - src/server/scripts/Commands/cs_tele.cpp | 2 +- src/server/scripts/Commands/cs_ticket.cpp | 6 ++--- 9 files changed, 53 insertions(+), 53 deletions(-) diff --git a/src/server/scripts/Commands/cs_ban.cpp b/src/server/scripts/Commands/cs_ban.cpp index 08a2e3afa..dae95cd3b 100644 --- a/src/server/scripts/Commands/cs_ban.cpp +++ b/src/server/scripts/Commands/cs_ban.cpp @@ -389,14 +389,14 @@ public: if (filter.empty()) { - LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_BANNED_ALL); - result = LoginDatabase.Query(stmt); + LoginDatabasePreparedStatement* stmt2 = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_BANNED_ALL); + result = LoginDatabase.Query(stmt2); } else { - LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_BANNED_BY_USERNAME); - stmt->setString(0, filter); - result = LoginDatabase.Query(stmt); + LoginDatabasePreparedStatement* stmt2 = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_BANNED_BY_USERNAME); + stmt2->setString(0, filter); + result = LoginDatabase.Query(stmt2); } if (!result) @@ -586,14 +586,14 @@ public: if (filter.empty()) { - LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_IP_BANNED_ALL); - result = LoginDatabase.Query(stmt); + LoginDatabasePreparedStatement* stmt2 = LoginDatabase.GetPreparedStatement(LOGIN_SEL_IP_BANNED_ALL); + result = LoginDatabase.Query(stmt2); } else { - LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_IP_BANNED_BY_IP); - stmt->setString(0, filter); - result = LoginDatabase.Query(stmt); + LoginDatabasePreparedStatement* stmt2 = LoginDatabase.GetPreparedStatement(LOGIN_SEL_IP_BANNED_BY_IP); + stmt2->setString(0, filter); + result = LoginDatabase.Query(stmt2); } if (!result) diff --git a/src/server/scripts/Commands/cs_list.cpp b/src/server/scripts/Commands/cs_list.cpp index 060615807..bfa55aeba 100644 --- a/src/server/scripts/Commands/cs_list.cpp +++ b/src/server/scripts/Commands/cs_list.cpp @@ -13,7 +13,6 @@ EndScriptData */ #include "Chat.h" #include "Language.h" -#include "ObjectAccessor.h" #include "ObjectMgr.h" #include "Player.h" #include "ScriptMgr.h" diff --git a/src/server/scripts/Commands/cs_misc.cpp b/src/server/scripts/Commands/cs_misc.cpp index c4099745f..92eb40ef9 100644 --- a/src/server/scripts/Commands/cs_misc.cpp +++ b/src/server/scripts/Commands/cs_misc.cpp @@ -131,10 +131,10 @@ public: return false; } - Tokenizer::const_iterator i = tokens.begin(); + Tokenizer::const_iterator tokensItr = tokens.begin(); std::set allowedArenas; - std::string arenasStr = *(i++); + std::string arenasStr = *(tokensItr++); std::string tmpStr; Tokenizer arenaTokens(arenasStr, ','); for (Tokenizer::const_iterator itr = arenaTokens.begin(); itr != arenaTokens.end(); ++itr) @@ -175,9 +175,9 @@ public: BattlegroundTypeId randomizedArenaBgTypeId = Acore::Containers::SelectRandomContainerElement(allowedArenas); uint8 count = 0; - if (i != tokens.end()) + if (tokensItr != tokens.end()) { - std::string mode = *(i++); + std::string mode = *(tokensItr++); if (mode == "1v1") count = 2; else if (mode == "2v2") count = 4; else if (mode == "3v3") count = 6; @@ -204,9 +204,9 @@ public: Player* plr = nullptr; Player* players[10] = {nullptr}; uint8 cnt = 0; - for (; i != tokens.end(); ++i) + for (; tokensItr != tokens.end(); ++tokensItr) { - last_name = std::string(*i); + last_name = std::string(*tokensItr); plr = ObjectAccessor::FindPlayerByName(last_name, false); if (!plr) { error = 1; break; } if (!plr->IsInWorld() || !plr->FindMap() || plr->IsBeingTeleported()) { error = 2; break; } @@ -234,13 +234,17 @@ public: } for (uint8 i = 0; i < cnt && !error; ++i) + { for (uint8 j = i + 1; j < cnt; ++j) + { if (players[i]->GetGUID() == players[j]->GetGUID()) { last_name = players[i]->GetName(); error = 13; break; } + } + } switch (error) { @@ -830,7 +834,7 @@ public: std::string plNameLink = handler->GetNameLink(player); - if (player->IsBeingTeleported() == true) + if (player->IsBeingTeleported()) { handler->PSendSysMessage(LANG_IS_TELEPORTED, plNameLink.c_str()); handler->SetSentErrorMessage(true); @@ -2002,12 +2006,12 @@ public: PreparedQueryResult guildInfoResult = CharacterDatabase.Query(guildQuery); if (guildInfoResult) { - Field* fields = guildInfoResult->Fetch(); - guildId = fields[0].GetUInt32(); - guildName = fields[1].GetString(); - guildRank = fields[2].GetString(); - note = fields[3].GetString(); - officeNote = fields[4].GetString(); + Field* guildInfoFields = guildInfoResult->Fetch(); + guildId = guildInfoFields[0].GetUInt32(); + guildName = guildInfoFields[1].GetString(); + guildRank = guildInfoFields[2].GetString(); + note = guildInfoFields[3].GetString(); + officeNote = guildInfoFields[4].GetString(); } } } diff --git a/src/server/scripts/Commands/cs_mmaps.cpp b/src/server/scripts/Commands/cs_mmaps.cpp index b06becdfe..0673c72b2 100644 --- a/src/server/scripts/Commands/cs_mmaps.cpp +++ b/src/server/scripts/Commands/cs_mmaps.cpp @@ -1,18 +1,6 @@ /* + * Copyright (C) 2016+ AzerothCore , released under GNU AGPL v3 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-AGPL3 * Copyright (C) 2008-2016 TrinityCore - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . */ /** @@ -25,7 +13,6 @@ #include "CellImpl.h" #include "Chat.h" -#include "DisableMgr.h" #include "GridNotifiers.h" #include "GridNotifiersImpl.h" #include "Map.h" diff --git a/src/server/scripts/Commands/cs_npc.cpp b/src/server/scripts/Commands/cs_npc.cpp index c92b725fb..88008c187 100644 --- a/src/server/scripts/Commands/cs_npc.cpp +++ b/src/server/scripts/Commands/cs_npc.cpp @@ -1085,7 +1085,7 @@ public: if (creature) { // update movement type - if (doNotDelete == false) + if (!doNotDelete) creature->LoadPath(0); creature->SetDefaultMovementType(move_type); @@ -1097,7 +1097,7 @@ public: } creature->SaveToDB(); } - if (doNotDelete == false) + if (!doNotDelete) { handler->PSendSysMessage(LANG_MOVE_TYPE_SET, type_str); } diff --git a/src/server/scripts/Commands/cs_player.cpp b/src/server/scripts/Commands/cs_player.cpp index a88e7972e..30b9c08d0 100644 --- a/src/server/scripts/Commands/cs_player.cpp +++ b/src/server/scripts/Commands/cs_player.cpp @@ -34,15 +34,20 @@ public: return false; char* playerName = strtok((char*)args, " "); - char* spellid = strtok(nullptr, " "); + char* spellId = strtok(nullptr, " "); char const* all = strtok(nullptr, " "); Player* targetPlayer = FindPlayer(handler, playerName); - if (!spellid || !targetPlayer) + if (!spellId || !targetPlayer) + { return false; + } + + uint32 spell = handler->extractSpellIdFromLink(spellId); - uint32 spell = handler->extractSpellIdFromLink(spellid); if (!spell) + { return false; + } return Learn(handler, targetPlayer, spell, all); } @@ -53,15 +58,21 @@ public: return false; char* playerName = strtok((char*)args, " "); - char* spellid = strtok(nullptr, " "); + char* spellId = strtok(nullptr, " "); char const* all = strtok(nullptr, " "); Player* targetPlayer = FindPlayer(handler, playerName); - if (!spellid || !targetPlayer) - return false; - uint32 spell = handler->extractSpellIdFromLink(spellid); - if (!spell) + if (!spellId || !targetPlayer) + { return false; + } + + uint32 spell = handler->extractSpellIdFromLink(spellId); + + if (!spell) + { + return false; + } return UnLearn(handler, targetPlayer, spell, all); } diff --git a/src/server/scripts/Commands/cs_server.cpp b/src/server/scripts/Commands/cs_server.cpp index 441207b78..e43dcf754 100644 --- a/src/server/scripts/Commands/cs_server.cpp +++ b/src/server/scripts/Commands/cs_server.cpp @@ -17,7 +17,6 @@ EndScriptData */ #include "GitRevision.h" #include "Language.h" #include "MySQLThreading.h" -#include "ObjectAccessor.h" #include "Player.h" #include "Realm.h" #include "ScriptMgr.h" diff --git a/src/server/scripts/Commands/cs_tele.cpp b/src/server/scripts/Commands/cs_tele.cpp index fbbd5ea35..5c123c0a3 100644 --- a/src/server/scripts/Commands/cs_tele.cpp +++ b/src/server/scripts/Commands/cs_tele.cpp @@ -158,7 +158,7 @@ public: std::string chrNameLink = handler->playerLink(target_name); - if (target->IsBeingTeleported() == true) + if (target->IsBeingTeleported()) { handler->PSendSysMessage(LANG_IS_TELEPORTED, chrNameLink.c_str()); handler->SetSentErrorMessage(true); diff --git a/src/server/scripts/Commands/cs_ticket.cpp b/src/server/scripts/Commands/cs_ticket.cpp index 2a2c5ea40..fc0aac76e 100644 --- a/src/server/scripts/Commands/cs_ticket.cpp +++ b/src/server/scripts/Commands/cs_ticket.cpp @@ -235,10 +235,10 @@ public: if (response) ticket->AppendResponse(response); - if (Player* player = ticket->GetPlayer()) + if (Player* player2 = ticket->GetPlayer()) { - ticket->SendResponse(player->GetSession()); - ChatHandler(player->GetSession()).SendSysMessage(LANG_TICKET_COMPLETED); + ticket->SendResponse(player2->GetSession()); + ChatHandler(player2->GetSession()).SendSysMessage(LANG_TICKET_COMPLETED); } Player* gm = handler->GetSession() ? handler->GetSession()->GetPlayer() : nullptr;