From a0e50ea35fca61447bf07fc45d93c98234ba59f7 Mon Sep 17 00:00:00 2001 From: Shauren Date: Sun, 14 Sep 2014 16:14:12 +0200 Subject: Core/Entities: Use ObjectGuid class in game project --- src/server/game/Server/WorldSession.cpp | 19 +++++----- src/server/game/Server/WorldSession.h | 61 ++++++++++++++++----------------- 2 files changed, 38 insertions(+), 42 deletions(-) (limited to 'src/server/game/Server') diff --git a/src/server/game/Server/WorldSession.cpp b/src/server/game/Server/WorldSession.cpp index 321bc707879..cc5fdcc8ca8 100644 --- a/src/server/game/Server/WorldSession.cpp +++ b/src/server/game/Server/WorldSession.cpp @@ -124,7 +124,7 @@ WorldSession::WorldSession(uint32 id, std::shared_ptr sock, Account _RBACData(NULL), expireTime(60000), // 1 min after socket loss, session is deleted forceExit(false), - m_currentBankerGUID(0) + m_currentBankerGUID() { memset(m_Tutorials, 0, sizeof(m_Tutorials)); @@ -173,7 +173,7 @@ std::string WorldSession::GetPlayerInfo() const std::ostringstream ss; ss << "[Player: " << GetPlayerName() - << " (Guid: " << (_player != NULL ? _player->GetGUID() : 0) + << " (Guid: " << (_player != NULL ? _player->GetGUID().ToString() : "") << ", Account: " << GetAccountId() << ")]"; return ss.str(); @@ -445,7 +445,7 @@ void WorldSession::LogoutPlayer(bool save) if (_player) { - if (uint64 lguid = _player->GetLootGUID()) + if (ObjectGuid lguid = _player->GetLootGUID()) DoLootRelease(lguid); ///- If the player just died before logging out, make him appear as a ghost @@ -512,7 +512,7 @@ void WorldSession::LogoutPlayer(bool save) for (int j = BUYBACK_SLOT_START; j < BUYBACK_SLOT_END; ++j) { eslot = j - BUYBACK_SLOT_START; - _player->SetUInt64Value(PLAYER_FIELD_VENDORBUYBACK_SLOT_1 + (eslot * 2), 0); + _player->SetGuidValue(PLAYER_FIELD_VENDORBUYBACK_SLOT_1 + (eslot * 2), ObjectGuid::Empty); _player->SetUInt32Value(PLAYER_FIELD_BUYBACK_PRICE_1 + eslot, 0); _player->SetUInt32Value(PLAYER_FIELD_BUYBACK_TIMESTAMP_1 + eslot, 0); } @@ -796,8 +796,7 @@ void WorldSession::ReadMovementInfo(WorldPacket &data, MovementInfo* mi) if (mi->HasMovementFlag(MOVEMENTFLAG_ONTRANSPORT)) { - data.readPackGUID(mi->transport.guid); - + data >> mi->transport.guid.ReadAsPacked(); data >> mi->transport.pos.PositionXYZOStream(); data >> mi->transport.time; data >> mi->transport.seat; @@ -904,8 +903,7 @@ void WorldSession::ReadMovementInfo(WorldPacket &data, MovementInfo* mi) void WorldSession::WriteMovementInfo(WorldPacket* data, MovementInfo* mi) { - data->appendPackGUID(mi->guid); - + *data << mi->guid.WriteAsPacked(); *data << mi->flags; *data << mi->flags2; *data << mi->time; @@ -913,8 +911,7 @@ void WorldSession::WriteMovementInfo(WorldPacket* data, MovementInfo* mi) if (mi->HasMovementFlag(MOVEMENTFLAG_ONTRANSPORT)) { - data->appendPackGUID(mi->transport.guid); - + *data << mi->transport.guid.WriteAsPacked(); *data << mi->transport.pos.PositionXYZOStream(); *data << mi->transport.time; *data << mi->transport.seat; @@ -1148,7 +1145,7 @@ void WorldSession::ProcessQueryCallbacks() //- SendStabledPet if (_sendStabledPetCallback.IsReady()) { - uint64 param = _sendStabledPetCallback.GetParam(); + ObjectGuid param = _sendStabledPetCallback.GetParam(); _sendStabledPetCallback.GetResult(result); SendStablePetCallback(result, param); _sendStabledPetCallback.FreeResult(); diff --git a/src/server/game/Server/WorldSession.h b/src/server/game/Server/WorldSession.h index 2e6a699fc7c..e46a58d5098 100644 --- a/src/server/game/Server/WorldSession.h +++ b/src/server/game/Server/WorldSession.h @@ -281,38 +281,37 @@ class WorldSession /// Handle the authentication waiting queue (to be completed) void SendAuthWaitQue(uint32 position); - //void SendTestCreatureQueryOpcode(uint32 entry, uint64 guid, uint32 testvalue); - void SendNameQueryOpcode(uint64 guid); - - void SendTrainerList(uint64 guid); - void SendTrainerList(uint64 guid, std::string const& strTitle); - void SendListInventory(uint64 guid); - void SendShowBank(uint64 guid); - bool CanOpenMailBox(uint64 guid); - void SendShowMailBox(uint64 guid); - void SendTabardVendorActivate(uint64 guid); + void SendNameQueryOpcode(ObjectGuid guid); + + void SendTrainerList(ObjectGuid guid); + void SendTrainerList(ObjectGuid guid, std::string const& strTitle); + void SendListInventory(ObjectGuid guid); + void SendShowBank(ObjectGuid guid); + bool CanOpenMailBox(ObjectGuid guid); + void SendShowMailBox(ObjectGuid guid); + void SendTabardVendorActivate(ObjectGuid guid); void SendSpiritResurrect(); void SendBindPoint(Creature* npc); void SendAttackStop(Unit const* enemy); - void SendBattleGroundList(uint64 guid, BattlegroundTypeId bgTypeId = BATTLEGROUND_RB); + void SendBattleGroundList(ObjectGuid guid, BattlegroundTypeId bgTypeId = BATTLEGROUND_RB); void SendTradeStatus(TradeStatusInfo const& status); void SendUpdateTrade(bool trader_data = true); void SendCancelTrade(); - void SendPetitionQueryOpcode(uint64 petitionguid); + void SendPetitionQueryOpcode(ObjectGuid petitionguid); // Spell - void HandleClientCastFlags(WorldPacket& recvPacket, uint8 castFlags, SpellCastTargets & targets); + void HandleClientCastFlags(WorldPacket& recvPacket, uint8 castFlags, SpellCastTargets& targets); // Pet - void SendPetNameQuery(uint64 guid, uint32 petnumber); - void SendStablePet(uint64 guid); - void SendStablePetCallback(PreparedQueryResult result, uint64 guid); + void SendPetNameQuery(ObjectGuid guid, uint32 petnumber); + void SendStablePet(ObjectGuid guid); + void SendStablePetCallback(PreparedQueryResult result, ObjectGuid guid); void SendStableResult(uint8 guid); - bool CheckStableMaster(uint64 guid); + bool CheckStableMaster(ObjectGuid guid); // Account Data AccountData* GetAccountData(AccountDataType type) { return &m_accountData[type]; } @@ -336,17 +335,17 @@ class WorldSession //used with item_page table bool SendItemInfo(uint32 itemid, WorldPacket data); //auction - void SendAuctionHello(uint64 guid, Creature* unit); + void SendAuctionHello(ObjectGuid guid, Creature* unit); void SendAuctionCommandResult(uint32 auctionId, uint32 Action, uint32 ErrorCode, uint32 bidError = 0); - void SendAuctionBidderNotification(uint32 location, uint32 auctionId, uint64 bidder, uint32 bidSum, uint32 diff, uint32 item_template); + void SendAuctionBidderNotification(uint32 location, uint32 auctionId, ObjectGuid bidder, uint32 bidSum, uint32 diff, uint32 item_template); void SendAuctionOwnerNotification(AuctionEntry* auction); //Item Enchantment - void SendEnchantmentLog(uint64 target, uint64 caster, uint32 itemId, uint32 enchantId); - void SendItemEnchantTimeUpdate(uint64 Playerguid, uint64 Itemguid, uint32 slot, uint32 Duration); + void SendEnchantmentLog(ObjectGuid target, ObjectGuid caster, uint32 itemId, uint32 enchantId); + void SendItemEnchantTimeUpdate(ObjectGuid Playerguid, ObjectGuid Itemguid, uint32 slot, uint32 Duration); //Taxi - void SendTaxiStatus(uint64 guid); + void SendTaxiStatus(ObjectGuid guid); void SendTaxiMenu(Creature* unit); void SendDoFlight(uint32 mountDisplayId, uint32 path, uint32 pathNode = 0); bool SendLearnNewTaxiNode(Creature* unit); @@ -355,11 +354,11 @@ class WorldSession // Guild/Arena Team void SendArenaTeamCommandResult(uint32 team_action, std::string const& team, std::string const& player, uint32 error_id = 0); void SendNotInArenaTeamPacket(uint8 type); - void SendPetitionShowList(uint64 guid); + void SendPetitionShowList(ObjectGuid guid); void BuildPartyMemberStatsChangedPacket(Player* player, WorldPacket* data); - void DoLootRelease(uint64 lguid); + void DoLootRelease(ObjectGuid lguid); // Account mute time time_t m_muteTime; @@ -738,7 +737,7 @@ class WorldSession //Pet void HandlePetAction(WorldPacket& recvData); void HandlePetStopAttack(WorldPacket& recvData); - void HandlePetActionHelper(Unit* pet, uint64 guid1, uint32 spellid, uint16 flag, uint64 guid2); + void HandlePetActionHelper(Unit* pet, ObjectGuid guid1, uint32 spellid, uint16 flag, ObjectGuid guid2); void HandlePetNameQuery(WorldPacket& recvData); void HandlePetSetAction(WorldPacket& recvData); void HandlePetAbandon(WorldPacket& recvData); @@ -811,7 +810,7 @@ class WorldSession void SendLfgUpdatePlayer(lfg::LfgUpdateData const& updateData); void SendLfgUpdateParty(lfg::LfgUpdateData const& updateData); - void SendLfgRoleChosen(uint64 guid, uint8 roles); + void SendLfgRoleChosen(ObjectGuid guid, uint8 roles); void SendLfgRoleCheckUpdate(lfg::LfgRoleCheck const& pRoleCheck); void SendLfgLfrList(bool update); void SendLfgJoinResult(lfg::LfgJoinResultData const& joinData); @@ -925,7 +924,7 @@ class WorldSession QueryCallback _addFriendCallback; QueryCallback _unstablePetCallback; QueryCallback _stableSwapCallback; - QueryCallback _sendStabledPetCallback; + QueryCallback _sendStabledPetCallback; QueryCallback _charCreateCallback; QueryResultHolderFuture _charLoginCallback; @@ -963,21 +962,21 @@ class WorldSession // private trade methods void moveItems(Item* myItems[], Item* hisItems[]); - bool CanUseBank(uint64 bankerGUID = 0) const; + bool CanUseBank(ObjectGuid bankerGUID = ObjectGuid::Empty) const; // logging helper void LogUnexpectedOpcode(WorldPacket* packet, const char* status, const char *reason); void LogUnprocessedTail(WorldPacket* packet); // EnumData helpers - bool IsLegitCharacterForAccount(uint32 lowGUID) + bool IsLegitCharacterForAccount(ObjectGuid lowGUID) { return _legitCharacters.find(lowGUID) != _legitCharacters.end(); } // this stores the GUIDs of the characters who can login // characters who failed on Player::BuildEnumData shouldn't login - std::set _legitCharacters; + GuidSet _legitCharacters; uint32 m_GUIDLow; // set logined or recently logout player (while m_playerRecentlyLogout set) Player* _player; @@ -1014,7 +1013,7 @@ class WorldSession rbac::RBACData* _RBACData; uint32 expireTime; bool forceExit; - uint64 m_currentBankerGUID; + ObjectGuid m_currentBankerGUID; WorldSession(WorldSession const& right) = delete; WorldSession& operator=(WorldSession const& right) = delete; -- cgit v1.2.3 From d72c4085de0b2ac0ff3bee24a5dae80c0d5dac2c Mon Sep 17 00:00:00 2001 From: Shauren Date: Sun, 14 Sep 2014 17:29:13 +0200 Subject: Core/Misc: Fixed build without pch --- src/server/game/Achievements/AchievementMgr.h | 1 + src/server/game/Battlegrounds/ArenaTeam.h | 1 + src/server/game/Battlegrounds/BattlegroundScore.h | 1 + src/server/game/Calendar/CalendarMgr.h | 1 + src/server/game/Combat/ThreatManager.h | 1 + src/server/game/DungeonFinding/LFG.h | 1 + src/server/game/Entities/Creature/GossipDef.h | 1 + src/server/game/Entities/Object/ObjectGuid.cpp | 2 +- src/server/game/Entities/Object/Updates/UpdateData.h | 1 + src/server/game/Loot/LootMgr.h | 2 +- src/server/game/Maps/Map.h | 1 + src/server/game/Server/WorldSession.cpp | 8 +++++--- 12 files changed, 16 insertions(+), 5 deletions(-) (limited to 'src/server/game/Server') diff --git a/src/server/game/Achievements/AchievementMgr.h b/src/server/game/Achievements/AchievementMgr.h index b71f401aa72..a72152782c3 100644 --- a/src/server/game/Achievements/AchievementMgr.h +++ b/src/server/game/Achievements/AchievementMgr.h @@ -26,6 +26,7 @@ #include "DatabaseEnv.h" #include "DBCEnums.h" #include "DBCStores.h" +#include "ObjectGuid.h" class Unit; class Player; diff --git a/src/server/game/Battlegrounds/ArenaTeam.h b/src/server/game/Battlegrounds/ArenaTeam.h index ec2b637a59a..2f6472eca90 100644 --- a/src/server/game/Battlegrounds/ArenaTeam.h +++ b/src/server/game/Battlegrounds/ArenaTeam.h @@ -20,6 +20,7 @@ #define TRINITYCORE_ARENATEAM_H #include "QueryResult.h" +#include "ObjectGuid.h" #include #include diff --git a/src/server/game/Battlegrounds/BattlegroundScore.h b/src/server/game/Battlegrounds/BattlegroundScore.h index fac0fed5427..acdeb44db84 100644 --- a/src/server/game/Battlegrounds/BattlegroundScore.h +++ b/src/server/game/Battlegrounds/BattlegroundScore.h @@ -19,6 +19,7 @@ #define TRINITY_BATTLEGROUND_SCORE_H #include "WorldPacket.h" +#include "ObjectGuid.h" enum ScoreType { diff --git a/src/server/game/Calendar/CalendarMgr.h b/src/server/game/Calendar/CalendarMgr.h index 26d2f516343..601190bac54 100644 --- a/src/server/game/Calendar/CalendarMgr.h +++ b/src/server/game/Calendar/CalendarMgr.h @@ -21,6 +21,7 @@ #include "Common.h" #include "DatabaseEnv.h" #include "WorldPacket.h" +#include "ObjectGuid.h" enum CalendarMailAnswers { diff --git a/src/server/game/Combat/ThreatManager.h b/src/server/game/Combat/ThreatManager.h index 87abbf0fcb0..62b3d10e554 100644 --- a/src/server/game/Combat/ThreatManager.h +++ b/src/server/game/Combat/ThreatManager.h @@ -23,6 +23,7 @@ #include "SharedDefines.h" #include "LinkedReference/Reference.h" #include "UnitEvents.h" +#include "ObjectGuid.h" #include diff --git a/src/server/game/DungeonFinding/LFG.h b/src/server/game/DungeonFinding/LFG.h index db219783699..c99366ce179 100644 --- a/src/server/game/DungeonFinding/LFG.h +++ b/src/server/game/DungeonFinding/LFG.h @@ -19,6 +19,7 @@ #define _LFG_H #include "Common.h" +#include "ObjectGuid.h" namespace lfg { diff --git a/src/server/game/Entities/Creature/GossipDef.h b/src/server/game/Entities/Creature/GossipDef.h index 5f8cf8e1355..81fa5bc8203 100644 --- a/src/server/game/Entities/Creature/GossipDef.h +++ b/src/server/game/Entities/Creature/GossipDef.h @@ -20,6 +20,7 @@ #define TRINITYCORE_GOSSIP_H #include "Common.h" +#include "ObjectGuid.h" #include "QuestDef.h" #include "NPCHandler.h" diff --git a/src/server/game/Entities/Object/ObjectGuid.cpp b/src/server/game/Entities/Object/ObjectGuid.cpp index 63d2b5c2dae..cf40e248808 100644 --- a/src/server/game/Entities/Object/ObjectGuid.cpp +++ b/src/server/game/Entities/Object/ObjectGuid.cpp @@ -48,7 +48,7 @@ char const* ObjectGuid::GetTypeName(HighGuid high) std::string ObjectGuid::ToString() const { std::ostringstream str; - str << "GUID Full: 0x" << std::hex << std::setw(16) << std::setfill('0') << m_guid; + str << "GUID Full: 0x" << std::hex << std::setw(16) << std::setfill('0') << m_guid << std::dec; str << " Type: " << GetTypeName(); if (HasEntry()) str << (IsPet() ? " Pet number: " : " Entry: ") << GetEntry() << " "; diff --git a/src/server/game/Entities/Object/Updates/UpdateData.h b/src/server/game/Entities/Object/Updates/UpdateData.h index 57d0c06d376..d1305deabd8 100644 --- a/src/server/game/Entities/Object/Updates/UpdateData.h +++ b/src/server/game/Entities/Object/Updates/UpdateData.h @@ -20,6 +20,7 @@ #define __UPDATEDATA_H #include "ByteBuffer.h" +#include "ObjectGuid.h" #include class WorldPacket; diff --git a/src/server/game/Loot/LootMgr.h b/src/server/game/Loot/LootMgr.h index 7de07d5877a..673e5b6841e 100644 --- a/src/server/game/Loot/LootMgr.h +++ b/src/server/game/Loot/LootMgr.h @@ -24,7 +24,7 @@ #include "RefManager.h" #include "SharedDefines.h" #include "ConditionMgr.h" - +#include "ObjectGuid.h" #include #include #include diff --git a/src/server/game/Maps/Map.h b/src/server/game/Maps/Map.h index 926752f4be8..87434d555aa 100644 --- a/src/server/game/Maps/Map.h +++ b/src/server/game/Maps/Map.h @@ -30,6 +30,7 @@ #include "MapRefManager.h" #include "DynamicTree.h" #include "GameObjectModel.h" +#include "ObjectGuid.h" #include #include diff --git a/src/server/game/Server/WorldSession.cpp b/src/server/game/Server/WorldSession.cpp index cc5fdcc8ca8..beb6ea54b32 100644 --- a/src/server/game/Server/WorldSession.cpp +++ b/src/server/game/Server/WorldSession.cpp @@ -172,9 +172,11 @@ std::string WorldSession::GetPlayerInfo() const { std::ostringstream ss; - ss << "[Player: " << GetPlayerName() - << " (Guid: " << (_player != NULL ? _player->GetGUID().ToString() : "") - << ", Account: " << GetAccountId() << ")]"; + ss << "[Player: " << GetPlayerName() << " ("; + if (_player != NULL) + ss << _player->GetGUID().ToString() << ", "; + + ss << "Account: " << GetAccountId() << ")]"; return ss.str(); } -- cgit v1.2.3 From e57a63939eca1988df87ff6dbd72150ee1fdb950 Mon Sep 17 00:00:00 2001 From: Shauren Date: Wed, 17 Sep 2014 23:06:34 +0200 Subject: Core/NetworkIO: Fixed queued packets not being properly sent causing players to be stuck during loading Closes #13120 --- src/server/game/Server/WorldSocket.cpp | 2 +- src/server/shared/Networking/Socket.h | 48 +++++++++++++++++----------------- 2 files changed, 25 insertions(+), 25 deletions(-) (limited to 'src/server/game/Server') diff --git a/src/server/game/Server/WorldSocket.cpp b/src/server/game/Server/WorldSocket.cpp index ef92a59a73d..cf76812473e 100644 --- a/src/server/game/Server/WorldSocket.cpp +++ b/src/server/game/Server/WorldSocket.cpp @@ -211,7 +211,7 @@ void WorldSocket::SendPacket(WorldPacket& packet) _authCrypt.EncryptSend(header.header, header.getHeaderLength()); -#ifndef BOOST_ASIO_HAS_IOCP +#ifndef TC_SOCKET_USE_IOCP if (_writeQueue.empty() && _writeBuffer.GetRemainingSpace() >= header.getHeaderLength() + packet.size()) { _writeBuffer.Write(header.header, header.getHeaderLength()); diff --git a/src/server/shared/Networking/Socket.h b/src/server/shared/Networking/Socket.h index dfff60a380b..d3e29ceaaea 100644 --- a/src/server/shared/Networking/Socket.h +++ b/src/server/shared/Networking/Socket.h @@ -34,6 +34,7 @@ using boost::asio::ip::tcp; #define READ_BLOCK_SIZE 4096 +#define TC_SOCKET_USE_IOCP BOOST_ASIO_HAS_IOCP template class Socket : public std::enable_shared_from_this @@ -58,11 +59,15 @@ public: if (!IsOpen()) return false; -#ifndef BOOST_ASIO_HAS_IOCP +#ifndef TC_SOCKET_USE_IOCP + std::unique_lock guard(_writeLock, std::try_to_lock); + if (!guard) + return true; + if (_isWritingAsync || (!_writeBuffer.GetActiveSize() && _writeQueue.empty())) return true; - for (; WriteHandler(boost::system::error_code(), 0);) + for (; WriteHandler(guard);) ; #endif @@ -113,7 +118,7 @@ public: { _writeQueue.push(std::move(buffer)); -#ifdef BOOST_ASIO_HAS_IOCP +#ifdef TC_SOCKET_USE_IOCP AsyncProcessQueue(guard); #else (void)guard; @@ -145,24 +150,25 @@ protected: bool AsyncProcessQueue(std::unique_lock&) { if (_isWritingAsync) - return true; + return false; _isWritingAsync = true; -#ifdef BOOST_ASIO_HAS_IOCP +#ifdef TC_SOCKET_USE_IOCP MessageBuffer& buffer = _writeQueue.front(); _socket.async_write_some(boost::asio::buffer(buffer.GetReadPointer(), buffer.GetActiveSize()), std::bind(&Socket::WriteHandler, this->shared_from_this(), std::placeholders::_1, std::placeholders::_2)); #else - _socket.async_write_some(boost::asio::null_buffers(), std::bind(&Socket::WriteHandler, this->shared_from_this(), std::placeholders::_1, std::placeholders::_2)); + _socket.async_write_some(boost::asio::null_buffers(), std::bind(&Socket::WriteHandlerWrapper, + this->shared_from_this(), std::placeholders::_1, std::placeholders::_2)); #endif - return true; + return false; } std::mutex _writeLock; std::queue _writeQueue; -#ifndef BOOST_ASIO_HAS_IOCP +#ifndef TC_SOCKET_USE_IOCP MessageBuffer _writeBuffer; #endif @@ -179,7 +185,7 @@ private: ReadHandler(); } -#ifdef BOOST_ASIO_HAS_IOCP +#ifdef TC_SOCKET_USE_IOCP void WriteHandler(boost::system::error_code error, std::size_t transferedBytes) { @@ -203,12 +209,15 @@ private: #else - bool WriteHandler(boost::system::error_code /*error*/, std::size_t /*transferedBytes*/) + void WriteHandlerWrapper(boost::system::error_code /*error*/, std::size_t /*transferedBytes*/) { - std::unique_lock guard(_writeLock, std::try_to_lock); - if (!guard) - return false; + std::unique_lock guard(_writeLock); + _isWritingAsync = false; + WriteHandler(guard); + } + bool WriteHandler(std::unique_lock& guard) + { if (!IsOpen()) return false; @@ -229,7 +238,7 @@ private: } else if (bytesWritten == 0) return false; - else if (bytesWritten < bytesToSend) //now n > 0 + else if (bytesWritten < bytesToSend) { _writeBuffer.ReadCompleted(bytesWritten); _writeBuffer.Normalize(); @@ -245,10 +254,7 @@ private: bool HandleQueue(std::unique_lock& guard) { if (_writeQueue.empty()) - { - _isWritingAsync = false; return false; - } MessageBuffer& queuedMessage = _writeQueue.front(); @@ -277,13 +283,7 @@ private: } _writeQueue.pop(); - if (_writeQueue.empty()) - { - _isWritingAsync = false; - return false; - } - - return true; + return !_writeQueue.empty(); } #endif -- cgit v1.2.3 From 72ed5bfc93af016722c115ef032f7cb1c43d9983 Mon Sep 17 00:00:00 2001 From: joschiwald Date: Thu, 18 Sep 2014 02:36:28 +0200 Subject: Core/Misc: changed trinity string id to unsigned and removed obsolete code --- src/server/game/Battlegrounds/Battleground.cpp | 27 +++----- src/server/game/Battlegrounds/Battleground.h | 10 ++- src/server/game/Chat/Chat.cpp | 10 +-- src/server/game/Chat/Chat.h | 14 ++-- src/server/game/Globals/ObjectMgr.cpp | 96 +++++--------------------- src/server/game/Globals/ObjectMgr.h | 27 ++++---- src/server/game/Miscellaneous/Language.h | 3 - src/server/game/Server/WorldSession.cpp | 2 +- src/server/game/Server/WorldSession.h | 2 +- src/server/game/World/World.cpp | 8 +-- src/server/game/World/World.h | 4 +- 11 files changed, 63 insertions(+), 140 deletions(-) (limited to 'src/server/game/Server') diff --git a/src/server/game/Battlegrounds/Battleground.cpp b/src/server/game/Battlegrounds/Battleground.cpp index 88c0035d21d..90a84774a81 100644 --- a/src/server/game/Battlegrounds/Battleground.cpp +++ b/src/server/game/Battlegrounds/Battleground.cpp @@ -41,7 +41,7 @@ namespace Trinity class BattlegroundChatBuilder { public: - BattlegroundChatBuilder(ChatMsg msgtype, int32 textId, Player const* source, va_list* args = NULL) + BattlegroundChatBuilder(ChatMsg msgtype, uint32 textId, Player const* source, va_list* args = NULL) : _msgtype(msgtype), _textId(textId), _source(source), _args(args) { } void operator()(WorldPacket& data, LocaleConstant loc_idx) @@ -70,7 +70,7 @@ namespace Trinity } ChatMsg _msgtype; - int32 _textId; + uint32 _textId; Player const* _source; va_list* _args; }; @@ -78,7 +78,7 @@ namespace Trinity class Battleground2ChatBuilder { public: - Battleground2ChatBuilder(ChatMsg msgtype, int32 textId, Player const* source, int32 arg1, int32 arg2) + Battleground2ChatBuilder(ChatMsg msgtype, uint32 textId, Player const* source, uint32 arg1, uint32 arg2) : _msgtype(msgtype), _textId(textId), _source(source), _arg1(arg1), _arg2(arg2) { } void operator()(WorldPacket& data, LocaleConstant loc_idx) @@ -95,10 +95,10 @@ namespace Trinity private: ChatMsg _msgtype; - int32 _textId; + uint32 _textId; Player const* _source; - int32 _arg1; - int32 _arg2; + uint32 _arg1; + uint32 _arg2; }; } // namespace Trinity @@ -1561,7 +1561,7 @@ bool Battleground::AddSpiritGuide(uint32 type, Position const& pos, TeamId teamI return AddSpiritGuide(type, pos.GetPositionX(), pos.GetPositionY(), pos.GetPositionZ(), pos.GetOrientation(), teamId); } -void Battleground::SendMessageToAll(int32 entry, ChatMsg type, Player const* source) +void Battleground::SendMessageToAll(uint32 entry, ChatMsg type, Player const* source) { if (!entry) return; @@ -1571,7 +1571,7 @@ void Battleground::SendMessageToAll(int32 entry, ChatMsg type, Player const* sou BroadcastWorker(bg_do); } -void Battleground::PSendMessageToAll(int32 entry, ChatMsg type, Player const* source, ...) +void Battleground::PSendMessageToAll(uint32 entry, ChatMsg type, Player const* source, ...) { if (!entry) return; @@ -1586,7 +1586,7 @@ void Battleground::PSendMessageToAll(int32 entry, ChatMsg type, Player const* so va_end(ap); } -void Battleground::SendWarningToAll(int32 entry, ...) +void Battleground::SendWarningToAll(uint32 entry, ...) { if (!entry) return; @@ -1612,7 +1612,7 @@ void Battleground::SendWarningToAll(int32 entry, ...) } } -void Battleground::SendMessage2ToAll(int32 entry, ChatMsg type, Player const* source, int32 arg1, int32 arg2) +void Battleground::SendMessage2ToAll(uint32 entry, ChatMsg type, Player const* source, uint32 arg1, uint32 arg2) { Trinity::Battleground2ChatBuilder bg_builder(type, entry, source, arg1, arg2); Trinity::LocalizedPacketDo bg_do(bg_builder); @@ -1626,13 +1626,6 @@ void Battleground::EndNow() SetEndTime(0); } -// To be removed -char const* Battleground::GetTrinityString(int32 entry) -{ - // FIXME: now we have different DBC locales and need localized message for each target client - return sObjectMgr->GetTrinityStringForDBCLocale(entry); -} - // IMPORTANT NOTICE: // buffs aren't spawned/despawned when players captures anything // buffs are in their positions when battleground starts diff --git a/src/server/game/Battlegrounds/Battleground.h b/src/server/game/Battlegrounds/Battleground.h index ab411e3cfc6..001c33cba40 100644 --- a/src/server/game/Battlegrounds/Battleground.h +++ b/src/server/game/Battlegrounds/Battleground.h @@ -360,12 +360,12 @@ class Battleground virtual void EndBattleground(uint32 winner); void BlockMovement(Player* player); - void SendWarningToAll(int32 entry, ...); - void SendMessageToAll(int32 entry, ChatMsg type, Player const* source = NULL); - void PSendMessageToAll(int32 entry, ChatMsg type, Player const* source, ...); + void SendWarningToAll(uint32 entry, ...); + void SendMessageToAll(uint32 entry, ChatMsg type, Player const* source = NULL); + void PSendMessageToAll(uint32 entry, ChatMsg type, Player const* source, ...); // specialized version with 2 string id args - void SendMessage2ToAll(int32 entry, ChatMsg type, Player const* source, int32 strId1 = 0, int32 strId2 = 0); + void SendMessage2ToAll(uint32 entry, ChatMsg type, Player const* source, uint32 strId1 = 0, uint32 strId2 = 0); // Raid Group Group* GetBgRaid(uint32 TeamID) const { return TeamID == ALLIANCE ? m_BgRaids[TEAM_ALLIANCE] : m_BgRaids[TEAM_HORDE]; } @@ -442,8 +442,6 @@ class Battleground void DoorOpen(uint32 type); void DoorClose(uint32 type); - //to be removed - const char* GetTrinityString(int32 entry); virtual bool HandlePlayerUnderMap(Player* /*player*/) { return false; } diff --git a/src/server/game/Chat/Chat.cpp b/src/server/game/Chat/Chat.cpp index a50cf00ad9e..4099b3ac3fd 100644 --- a/src/server/game/Chat/Chat.cpp +++ b/src/server/game/Chat/Chat.cpp @@ -104,7 +104,7 @@ ChatCommand* ChatHandler::getCommandTable() return commandTableCache; } -std::string ChatHandler::PGetParseString(int32 entry, ...) const +std::string ChatHandler::PGetParseString(uint32 entry, ...) const { const char *format = GetTrinityString(entry); char str[1024]; @@ -115,7 +115,7 @@ std::string ChatHandler::PGetParseString(int32 entry, ...) const return std::string(str); } -const char *ChatHandler::GetTrinityString(int32 entry) const +char const* ChatHandler::GetTrinityString(uint32 entry) const { return m_session->GetTrinityString(entry); } @@ -253,12 +253,12 @@ void ChatHandler::SendGlobalGMSysMessage(const char *str) free(buf); } -void ChatHandler::SendSysMessage(int32 entry) +void ChatHandler::SendSysMessage(uint32 entry) { SendSysMessage(GetTrinityString(entry)); } -void ChatHandler::PSendSysMessage(int32 entry, ...) +void ChatHandler::PSendSysMessage(uint32 entry, ...) { const char *format = GetTrinityString(entry); va_list ap; @@ -1250,7 +1250,7 @@ std::string ChatHandler::GetNameLink(Player* chr) const return playerLink(chr->GetName()); } -const char *CliHandler::GetTrinityString(int32 entry) const +char const* CliHandler::GetTrinityString(uint32 entry) const { return sObjectMgr->GetTrinityStringForDBCLocale(entry); } diff --git a/src/server/game/Chat/Chat.h b/src/server/game/Chat/Chat.h index 6ce4e01585f..9e7dcc88c95 100644 --- a/src/server/game/Chat/Chat.h +++ b/src/server/game/Chat/Chat.h @@ -64,13 +64,13 @@ class ChatHandler static char* LineFromMessage(char*& pos) { char* start = strtok(pos, "\n"); pos = NULL; return start; } // function with different implementation for chat/console - virtual const char *GetTrinityString(int32 entry) const; - virtual void SendSysMessage(const char *str); + virtual char const* GetTrinityString(uint32 entry) const; + virtual void SendSysMessage(char const* str); - void SendSysMessage(int32 entry); - void PSendSysMessage(const char *format, ...) ATTR_PRINTF(2, 3); - void PSendSysMessage(int32 entry, ...); - std::string PGetParseString(int32 entry, ...) const; + void SendSysMessage(uint32 entry); + void PSendSysMessage(char const* format, ...) ATTR_PRINTF(2, 3); + void PSendSysMessage(uint32 entry, ...); + std::string PGetParseString(uint32 entry, ...) const; bool ParseCommands(const char* text); @@ -147,7 +147,7 @@ class CliHandler : public ChatHandler explicit CliHandler(void* callbackArg, Print* zprint) : m_callbackArg(callbackArg), m_print(zprint) { } // overwrite functions - const char *GetTrinityString(int32 entry) const override; + char const* GetTrinityString(uint32 entry) const override; bool isAvailable(ChatCommand const& cmd) const override; bool HasPermission(uint32 /*permission*/) const override { return true; } void SendSysMessage(const char *str) override; diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp index 475774831ba..50d8ffec5ae 100644 --- a/src/server/game/Globals/ObjectMgr.cpp +++ b/src/server/game/Globals/ObjectMgr.cpp @@ -7673,112 +7673,48 @@ void ObjectMgr::LoadGameObjectForQuests() TC_LOG_INFO("server.loading", ">> Loaded %u GameObjects for quests in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); } -bool ObjectMgr::LoadTrinityStrings(const char* table, int32 min_value, int32 max_value) +bool ObjectMgr::LoadTrinityStrings() { uint32 oldMSTime = getMSTime(); - int32 start_value = min_value; - int32 end_value = max_value; - // some string can have negative indexes range - if (start_value < 0) - { - if (end_value >= start_value) - { - TC_LOG_ERROR("sql.sql", "Table '%s' attempt loaded with invalid range (%d - %d), strings not loaded.", table, min_value, max_value); - return false; - } - - // real range (max+1, min+1) exaple: (-10, -1000) -> -999...-10+1 - std::swap(start_value, end_value); - ++start_value; - ++end_value; - } - else - { - if (start_value >= end_value) - { - TC_LOG_ERROR("sql.sql", "Table '%s' attempt loaded with invalid range (%d - %d), strings not loaded.", table, min_value, max_value); - return false; - } - } - - // cleanup affected map part for reloading case - for (TrinityStringLocaleContainer::iterator itr = _trinityStringLocaleStore.begin(); itr != _trinityStringLocaleStore.end();) - { - if (itr->first >= start_value && itr->first < end_value) - _trinityStringLocaleStore.erase(itr++); - else - ++itr; - } - - QueryResult result = WorldDatabase.PQuery("SELECT entry, content_default, content_loc1, content_loc2, content_loc3, content_loc4, content_loc5, content_loc6, content_loc7, content_loc8 FROM %s", table); + _trinityStringStore.clear(); // for reload case + QueryResult result = WorldDatabase.Query("SELECT entry, content_default, content_loc1, content_loc2, content_loc3, content_loc4, content_loc5, content_loc6, content_loc7, content_loc8 FROM trinity_string"); if (!result) { - if (min_value == MIN_TRINITY_STRING_ID) // error only in case internal strings - TC_LOG_ERROR("server.loading", ">> Loaded 0 trinity strings. DB table `%s` is empty. Cannot continue.", table); - else - TC_LOG_INFO("server.loading", ">> Loaded 0 string templates. DB table `%s` is empty.", table); - + TC_LOG_ERROR("server.loading", ">> Loaded 0 trinity strings. DB table `trinity_string` is empty."); return false; } - uint32 count = 0; - do { Field* fields = result->Fetch(); - int32 entry = fields[0].GetInt32(); - - if (entry == 0) - { - TC_LOG_ERROR("sql.sql", "Table `%s` contain reserved entry 0, ignored.", table); - continue; - } - else if (entry < start_value || entry >= end_value) - { - TC_LOG_ERROR("sql.sql", "Table `%s` contain entry %i out of allowed range (%d - %d), ignored.", table, entry, min_value, max_value); - continue; - } - - TrinityStringLocale& data = _trinityStringLocaleStore[entry]; + uint32 entry = fields[0].GetUInt32(); - if (!data.Content.empty()) - { - TC_LOG_ERROR("sql.sql", "Table `%s` contain data for already loaded entry %i (from another table?), ignored.", table, entry); - continue; - } + TrinityString& data = _trinityStringStore[entry]; - data.Content.resize(1); - ++count; + data.Content.resize(DEFAULT_LOCALE + 1); for (int8 i = TOTAL_LOCALES - 1; i >= 0; --i) AddLocaleString(fields[i + 1].GetString(), LocaleConstant(i), data.Content); - } while (result->NextRow()); - - if (min_value == MIN_TRINITY_STRING_ID) - TC_LOG_INFO("server.loading", ">> Loaded %u Trinity strings from table %s in %u ms", count, table, GetMSTimeDiffToNow(oldMSTime)); - else - TC_LOG_INFO("server.loading", ">> Loaded %u string templates from %s in %u ms", count, table, GetMSTimeDiffToNow(oldMSTime)); + } + while (result->NextRow()); + TC_LOG_INFO("server.loading", ">> Loaded " SZFMTD " trinity strings in %u ms", _trinityStringStore.size(), GetMSTimeDiffToNow(oldMSTime)); return true; } -const char *ObjectMgr::GetTrinityString(int32 entry, LocaleConstant locale_idx) const +char const* ObjectMgr::GetTrinityString(uint32 entry, LocaleConstant locale) const { - if (TrinityStringLocale const* msl = GetTrinityStringLocale(entry)) + if (TrinityString const* ts = GetTrinityString(entry)) { - if (msl->Content.size() > size_t(locale_idx) && !msl->Content[locale_idx].empty()) - return msl->Content[locale_idx].c_str(); - - return msl->Content[DEFAULT_LOCALE].c_str(); + if (ts->Content.size() > size_t(locale) && !ts->Content[locale].empty()) + return ts->Content[locale].c_str(); + return ts->Content[DEFAULT_LOCALE].c_str(); } - if (entry > 0) - TC_LOG_ERROR("sql.sql", "Entry %i not found in `trinity_string` table.", entry); - else - TC_LOG_ERROR("sql.sql", "Trinity string entry %i not found in DB.", entry); + TC_LOG_ERROR("sql.sql", "Trinity string entry %u not found in DB.", entry); return ""; } diff --git a/src/server/game/Globals/ObjectMgr.h b/src/server/game/Globals/ObjectMgr.h index a26e2959769..f7e555d336a 100644 --- a/src/server/game/Globals/ObjectMgr.h +++ b/src/server/game/Globals/ObjectMgr.h @@ -463,14 +463,10 @@ struct CellObjectGuids typedef std::unordered_map CellObjectGuidsMap; typedef std::unordered_map MapObjectGuids; -// Trinity string ranges -#define MIN_TRINITY_STRING_ID 1 // 'trinity_string' -#define MAX_TRINITY_STRING_ID 2000000000 - // Trinity Trainer Reference start range #define TRINITY_TRAINER_START_REF 200000 -struct TrinityStringLocale +struct TrinityString { StringVector Content; }; @@ -486,10 +482,11 @@ typedef std::unordered_map ItemSetNameLocaleContainer typedef std::unordered_map QuestLocaleContainer; typedef std::unordered_map NpcTextLocaleContainer; typedef std::unordered_map PageTextLocaleContainer; -typedef std::unordered_map TrinityStringLocaleContainer; typedef std::unordered_map GossipMenuItemsLocaleContainer; typedef std::unordered_map PointOfInterestLocaleContainer; +typedef std::unordered_map TrinityStringContainer; + typedef std::multimap QuestRelations; // unit/go -> quest typedef std::multimap QuestRelationsReverse; // quest -> unit/go typedef std::pair QuestRelationBounds; @@ -955,6 +952,8 @@ class ObjectMgr return _creatureQuestInvolvedRelationsReverse.equal_range(questId); } + bool LoadTrinityStrings(); + void LoadEventScripts(); void LoadSpellScripts(); void LoadWaypointScripts(); @@ -964,8 +963,6 @@ class ObjectMgr void LoadBroadcastTexts(); void LoadBroadcastTextLocales(); - bool LoadTrinityStrings(char const* table, int32 min_value, int32 max_value); - bool LoadTrinityStrings() { return LoadTrinityStrings("trinity_string", MIN_TRINITY_STRING_ID, MAX_TRINITY_STRING_ID); } void LoadCreatureClassLevelStats(); void LoadCreatureLocales(); void LoadCreatureTemplates(); @@ -1187,14 +1184,15 @@ class ObjectMgr GameObjectData& NewGOData(uint32 guid) { return _gameObjectDataStore[guid]; } void DeleteGOData(uint32 guid); - TrinityStringLocale const* GetTrinityStringLocale(int32 entry) const + TrinityString const* GetTrinityString(uint32 entry) const { - TrinityStringLocaleContainer::const_iterator itr = _trinityStringLocaleStore.find(entry); - if (itr == _trinityStringLocaleStore.end()) return NULL; + TrinityStringContainer::const_iterator itr = _trinityStringStore.find(entry); + if (itr == _trinityStringStore.end()) + return nullptr; return &itr->second; } - const char *GetTrinityString(int32 entry, LocaleConstant locale_idx) const; - const char *GetTrinityStringForDBCLocale(int32 entry) const { return GetTrinityString(entry, DBCLocaleIndex); } + char const* GetTrinityString(uint32 entry, LocaleConstant locale) const; + char const* GetTrinityStringForDBCLocale(uint32 entry) const { return GetTrinityString(entry, DBCLocaleIndex); } LocaleConstant GetDBCLocaleIndex() const { return DBCLocaleIndex; } void SetDBCLocaleIndex(LocaleConstant locale) { DBCLocaleIndex = locale; } @@ -1438,10 +1436,11 @@ class ObjectMgr QuestLocaleContainer _questLocaleStore; NpcTextLocaleContainer _npcTextLocaleStore; PageTextLocaleContainer _pageTextLocaleStore; - TrinityStringLocaleContainer _trinityStringLocaleStore; GossipMenuItemsLocaleContainer _gossipMenuItemsLocaleStore; PointOfInterestLocaleContainer _pointOfInterestLocaleStore; + TrinityStringContainer _trinityStringStore; + CacheVendorItemContainer _cacheVendorItemStore; CacheTrainerSpellContainer _cacheTrainerSpellStore; diff --git a/src/server/game/Miscellaneous/Language.h b/src/server/game/Miscellaneous/Language.h index 814deba78db..ae8221ef49f 100644 --- a/src/server/game/Miscellaneous/Language.h +++ b/src/server/game/Miscellaneous/Language.h @@ -1192,8 +1192,5 @@ enum TrinityStrings LANG_NPCINFO_INHABIT_TYPE = 11008, LANG_NPCINFO_FLAGS_EXTRA = 11009 - - // NOT RESERVED IDS 12000-1999999999 - // For other tables maybe 2000010000-2147483647 (max index) }; #endif diff --git a/src/server/game/Server/WorldSession.cpp b/src/server/game/Server/WorldSession.cpp index beb6ea54b32..84bb90638f7 100644 --- a/src/server/game/Server/WorldSession.cpp +++ b/src/server/game/Server/WorldSession.cpp @@ -621,7 +621,7 @@ void WorldSession::SendNotification(uint32 string_id, ...) } } -const char *WorldSession::GetTrinityString(int32 entry) const +char const* WorldSession::GetTrinityString(uint32 entry) const { return sObjectMgr->GetTrinityString(entry, GetSessionDbLocaleIndex()); } diff --git a/src/server/game/Server/WorldSession.h b/src/server/game/Server/WorldSession.h index e46a58d5098..789bd5ab04f 100644 --- a/src/server/game/Server/WorldSession.h +++ b/src/server/game/Server/WorldSession.h @@ -366,7 +366,7 @@ class WorldSession // Locales LocaleConstant GetSessionDbcLocale() const { return m_sessionDbcLocale; } LocaleConstant GetSessionDbLocaleIndex() const { return m_sessionDbLocaleIndex; } - const char *GetTrinityString(int32 entry) const; + char const* GetTrinityString(uint32 entry) const; uint32 GetLatency() const { return m_latency; } void SetLatency(uint32 latency) { m_latency = latency; } diff --git a/src/server/game/World/World.cpp b/src/server/game/World/World.cpp index a34362ddacc..0462148129a 100644 --- a/src/server/game/World/World.cpp +++ b/src/server/game/World/World.cpp @@ -2186,7 +2186,7 @@ namespace Trinity { public: typedef std::vector WorldPacketList; - explicit WorldWorldTextBuilder(int32 textId, va_list* args = NULL) : i_textId(textId), i_args(args) { } + explicit WorldWorldTextBuilder(uint32 textId, va_list* args = NULL) : i_textId(textId), i_args(args) { } void operator()(WorldPacketList& data_list, LocaleConstant loc_idx) { char const* text = sObjectMgr->GetTrinityString(i_textId, loc_idx); @@ -2219,13 +2219,13 @@ namespace Trinity } } - int32 i_textId; + uint32 i_textId; va_list* i_args; }; } // namespace Trinity /// Send a System Message to all players (except self if mentioned) -void World::SendWorldText(int32 string_id, ...) +void World::SendWorldText(uint32 string_id, ...) { va_list ap; va_start(ap, string_id); @@ -2244,7 +2244,7 @@ void World::SendWorldText(int32 string_id, ...) } /// Send a System Message to all GMs (except self if mentioned) -void World::SendGMText(int32 string_id, ...) +void World::SendGMText(uint32 string_id, ...) { va_list ap; va_start(ap, string_id); diff --git a/src/server/game/World/World.h b/src/server/game/World/World.h index 6394fa42327..9987b8ab62c 100644 --- a/src/server/game/World/World.h +++ b/src/server/game/World/World.h @@ -628,9 +628,9 @@ class World void SetInitialWorldSettings(); void LoadConfigSettings(bool reload = false); - void SendWorldText(int32 string_id, ...); + void SendWorldText(uint32 string_id, ...); void SendGlobalText(const char* text, WorldSession* self); - void SendGMText(int32 string_id, ...); + void SendGMText(uint32 string_id, ...); void SendServerMessage(ServerMessageType type, const char *text = "", Player* player = NULL); void SendGlobalMessage(WorldPacket* packet, WorldSession* self = nullptr, uint32 team = 0); void SendGlobalGMMessage(WorldPacket* packet, WorldSession* self = nullptr, uint32 team = 0); -- cgit v1.2.3 From cefcde9ba9a4d951500ffb267134eaebaad6b928 Mon Sep 17 00:00:00 2001 From: DDuarte Date: Fri, 19 Sep 2014 03:30:02 +0100 Subject: Core/Misc: Multiple static analysis issues fixed (small optimizations and clear code) --- src/server/collision/Maps/TileAssembler.cpp | 2 +- src/server/game/Battlegrounds/Battleground.cpp | 1 - src/server/game/Battlegrounds/Zones/BattlegroundIC.cpp | 2 +- src/server/game/DungeonFinding/LFGPlayerData.cpp | 2 +- src/server/game/Entities/GameObject/GameObject.cpp | 3 +-- src/server/game/Entities/Pet/Pet.h | 2 +- src/server/game/Entities/Player/Player.cpp | 9 ++------- src/server/game/Entities/Player/Player.h | 2 +- src/server/game/Entities/Unit/Unit.cpp | 2 +- src/server/game/Entities/Unit/Unit.h | 2 +- src/server/game/Handlers/SpellHandler.cpp | 4 ++-- src/server/game/Loot/LootMgr.cpp | 2 +- src/server/game/Maps/Map.cpp | 2 +- src/server/game/Server/Protocol/PacketLog.cpp | 2 +- src/server/game/Server/Protocol/PacketLog.h | 2 +- src/server/game/Server/WorldSocket.cpp | 6 +++--- src/server/game/Spells/Spell.cpp | 3 +-- src/server/game/Spells/SpellMgr.cpp | 4 ++-- src/server/game/Tools/PlayerDump.cpp | 14 ++++++-------- src/server/game/Warden/WardenMac.cpp | 4 ++-- src/server/scripts/Commands/cs_account.cpp | 2 +- src/server/scripts/Commands/cs_debug.cpp | 2 +- src/server/scripts/Commands/cs_guild.cpp | 2 +- src/server/scripts/Commands/cs_instance.cpp | 2 +- src/server/scripts/Commands/cs_misc.cpp | 14 +++++++++----- src/server/scripts/Commands/cs_npc.cpp | 2 +- src/server/scripts/Kalimdor/zone_tanaris.cpp | 2 +- .../TrialOfTheCrusader/boss_anubarak_trial.cpp | 4 ++-- .../scripts/Northrend/Ulduar/Ulduar/instance_ulduar.cpp | 4 ++-- src/server/scripts/Outland/zone_shadowmoon_valley.cpp | 4 ++-- src/server/shared/DataStores/DBCFileLoader.cpp | 6 ++---- src/server/shared/Database/DatabaseWorkerPool.h | 3 +-- src/server/shared/Database/MySQLConnection.cpp | 3 +-- src/server/shared/Debugging/WheatyExceptionReport.cpp | 2 +- src/server/shared/Threading/ProcessPriority.h | 2 +- src/server/shared/Utilities/ServiceWin32.cpp | 3 ++- src/server/shared/Utilities/Util.cpp | 16 ++++++++-------- src/server/shared/Utilities/Util.h | 6 +++--- src/server/worldserver/Main.cpp | 3 +-- src/server/worldserver/RemoteAccess/RASession.cpp | 4 +--- 40 files changed, 72 insertions(+), 84 deletions(-) (limited to 'src/server/game/Server') diff --git a/src/server/collision/Maps/TileAssembler.cpp b/src/server/collision/Maps/TileAssembler.cpp index f8326e0a8ec..0ce71d9c31f 100644 --- a/src/server/collision/Maps/TileAssembler.cpp +++ b/src/server/collision/Maps/TileAssembler.cpp @@ -236,7 +236,7 @@ namespace VMAP MapData::iterator map_iter = mapData.find(mapID); if (map_iter == mapData.end()) { - printf("spawning Map %d\n", mapID); + printf("spawning Map %u\n", mapID); mapData[mapID] = current = new MapSpawns(); } else current = (*map_iter).second; diff --git a/src/server/game/Battlegrounds/Battleground.cpp b/src/server/game/Battlegrounds/Battleground.cpp index 86081c7f074..3fb91ee4a74 100644 --- a/src/server/game/Battlegrounds/Battleground.cpp +++ b/src/server/game/Battlegrounds/Battleground.cpp @@ -133,7 +133,6 @@ Battleground::Battleground() m_IsRated = false; m_BuffChange = false; m_IsRandom = false; - m_Name = ""; m_LevelMin = 0; m_LevelMax = 0; m_InBGFreeSlotQueue = false; diff --git a/src/server/game/Battlegrounds/Zones/BattlegroundIC.cpp b/src/server/game/Battlegrounds/Zones/BattlegroundIC.cpp index 7312b75944d..a0fa73bcabe 100644 --- a/src/server/game/Battlegrounds/Zones/BattlegroundIC.cpp +++ b/src/server/game/Battlegrounds/Zones/BattlegroundIC.cpp @@ -865,7 +865,7 @@ bool BattlegroundIC::IsSpellAllowed(uint32 spellId, Player const* player) const case SPELL_QUARRY: { uint32 team = player->GetTeamId(); - uint8 nodeType = spellId = SPELL_OIL_REFINERY ? NODE_TYPE_REFINERY : NODE_TYPE_QUARRY; + uint8 nodeType = spellId == SPELL_OIL_REFINERY ? NODE_TYPE_REFINERY : NODE_TYPE_QUARRY; uint8 nodeState = team == TEAM_ALLIANCE ? NODE_STATE_CONTROLLED_A : NODE_STATE_CONTROLLED_H; return GetNodeState(nodeType) == nodeState; } diff --git a/src/server/game/DungeonFinding/LFGPlayerData.cpp b/src/server/game/DungeonFinding/LFGPlayerData.cpp index df9909fc4ce..6be50be9b9c 100644 --- a/src/server/game/DungeonFinding/LFGPlayerData.cpp +++ b/src/server/game/DungeonFinding/LFGPlayerData.cpp @@ -34,7 +34,7 @@ void LfgPlayerData::SetState(LfgState state) case LFG_STATE_FINISHED_DUNGEON: m_Roles = 0; m_SelectedDungeons.clear(); - m_Comment = ""; + m_Comment.clear(); // No break on purpose case LFG_STATE_DUNGEON: m_OldState = state; diff --git a/src/server/game/Entities/GameObject/GameObject.cpp b/src/server/game/Entities/GameObject/GameObject.cpp index 3ebe2bfe429..98b49c46f83 100644 --- a/src/server/game/Entities/GameObject/GameObject.cpp +++ b/src/server/game/Entities/GameObject/GameObject.cpp @@ -75,8 +75,7 @@ GameObject::~GameObject() bool GameObject::AIM_Initialize() { - if (m_AI) - delete m_AI; + delete m_AI; m_AI = FactorySelector::SelectGameObjectAI(this); diff --git a/src/server/game/Entities/Pet/Pet.h b/src/server/game/Entities/Pet/Pet.h index 7d4523be9af..f19ff3ffbba 100644 --- a/src/server/game/Entities/Pet/Pet.h +++ b/src/server/game/Entities/Pet/Pet.h @@ -60,7 +60,7 @@ class Pet : public Guardian bool CreateBaseAtCreatureInfo(CreatureTemplate const* cinfo, Unit* owner); bool CreateBaseAtTamed(CreatureTemplate const* cinfo, Map* map, uint32 phaseMask); bool LoadPetFromDB(Player* owner, uint32 petentry = 0, uint32 petnumber = 0, bool current = false); - bool isBeingLoaded() const override { return m_loading;} + bool IsLoading() const override { return m_loading;} void SavePetToDB(PetSaveMode mode); void Remove(PetSaveMode mode, bool returnreagent = false); static void DeleteFromDB(uint32 guidlow); diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index 1df449d50c9..b0c844c82ba 100644 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -14813,7 +14813,7 @@ void Player::SendPreparedQuest(ObjectGuid guid) { qe._Delay = 0; //TEXTEMOTE_MESSAGE; //zyg: player emote qe._Emote = 0; //TEXTEMOTE_HELLO; //zyg: NPC emote - title = ""; + title.clear(); } else { @@ -17131,7 +17131,7 @@ float Player::GetFloatValueFromArray(Tokenizer const& data, uint16 index) return result; } -bool Player::isBeingLoaded() const +bool Player::IsLoading() const { return GetSession()->PlayerLoading(); } @@ -26851,11 +26851,6 @@ Pet* Player::SummonPet(uint32 entry, float x, float y, float z, float ang, PetTy return pet; } -bool Player::IsLoading() const -{ - return GetSession()->PlayerLoading(); -} - void Player::SendSupercededSpell(uint32 oldSpell, uint32 newSpell) { WorldPacket data(SMSG_SUPERCEDED_SPELL, 8); diff --git a/src/server/game/Entities/Player/Player.h b/src/server/game/Entities/Player/Player.h index bb3fccaf35e..f0f189fc8bd 100644 --- a/src/server/game/Entities/Player/Player.h +++ b/src/server/game/Entities/Player/Player.h @@ -1487,7 +1487,7 @@ class Player : public Unit, public GridObject /*********************************************************/ bool LoadFromDB(ObjectGuid guid, SQLQueryHolder *holder); - bool isBeingLoaded() const override; + bool IsLoading() const override; void Initialize(uint32 guid); static uint32 GetUInt32ValueFromArray(Tokenizer const& data, uint16 index); diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index 77a6b655dd9..c4569887abf 100644 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -3286,7 +3286,7 @@ void Unit::_AddAura(UnitAura* aura, Unit* caster) if (aura->IsSingleTarget()) { ASSERT((IsInWorld() && !IsDuringRemoveFromWorld()) || (aura->GetCasterGUID() == GetGUID()) || - (isBeingLoaded() && aura->HasEffectType(SPELL_AURA_CONTROL_VEHICLE))); + (IsLoading() && aura->HasEffectType(SPELL_AURA_CONTROL_VEHICLE))); /* @HACK: Player is not in world during loading auras. * Single target auras are not saved or loaded from database * but may be created as a result of aura links (player mounts with passengers) diff --git a/src/server/game/Entities/Unit/Unit.h b/src/server/game/Entities/Unit/Unit.h index d5ecc219be6..63a984f1247 100644 --- a/src/server/game/Entities/Unit/Unit.h +++ b/src/server/game/Entities/Unit/Unit.h @@ -2135,7 +2135,7 @@ class Unit : public WorldObject virtual float GetFollowAngle() const { return static_cast(M_PI/2); } void OutDebugInfo() const; - virtual bool isBeingLoaded() const { return false;} + virtual bool IsLoading() const { return false; } bool IsDuringRemoveFromWorld() const {return m_duringRemoveFromWorld;} Pet* ToPet() { if (IsPet()) return reinterpret_cast(this); else return NULL; } diff --git a/src/server/game/Handlers/SpellHandler.cpp b/src/server/game/Handlers/SpellHandler.cpp index 61714d6f1e8..d07e13ebc57 100644 --- a/src/server/game/Handlers/SpellHandler.cpp +++ b/src/server/game/Handlers/SpellHandler.cpp @@ -448,11 +448,11 @@ void WorldSession::HandleCancelAuraOpcode(WorldPacket& recvPacket) // over AuraEffectList caused "incompatible iterator" errors on second pass std::list spellIDs; - for (Unit::AuraEffectList::const_iterator auraEffect = auraEffects.begin(); auraEffect != auraEffects.end(); auraEffect++) + for (Unit::AuraEffectList::const_iterator auraEffect = auraEffects.begin(); auraEffect != auraEffects.end(); ++auraEffect) spellIDs.push_back((*auraEffect)->GetId()); // Remove all auras related to resource tracking (only Herbs and Minerals in 3.3.5a) - for (std::list::iterator it = spellIDs.begin(); it != spellIDs.end(); it++) + for (std::list::iterator it = spellIDs.begin(); it != spellIDs.end(); ++it) _player->RemoveOwnedAura(*it, ObjectGuid::Empty, 0, AURA_REMOVE_BY_CANCEL); } } diff --git a/src/server/game/Loot/LootMgr.cpp b/src/server/game/Loot/LootMgr.cpp index 2732c02ae3c..f4f0979d091 100644 --- a/src/server/game/Loot/LootMgr.cpp +++ b/src/server/game/Loot/LootMgr.cpp @@ -161,7 +161,7 @@ uint32 LootStore::LoadLootTable() if (group >= 1 << 7) // it stored in 7 bit field { TC_LOG_ERROR("sql.sql", "Table '%s' entry %d item %d: group (%u) must be less %u - skipped", GetName(), entry, item, group, 1 << 7); - return false; + return 0; } LootStoreItem* storeitem = new LootStoreItem(item, chanceOrQuestChance, lootmode, group, mincountOrRef, maxcount); diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp index 42a103eb944..6b7639ebdd6 100644 --- a/src/server/game/Maps/Map.cpp +++ b/src/server/game/Maps/Map.cpp @@ -3059,7 +3059,7 @@ void InstanceMap::CreateInstanceData(bool load) Field* fields = result->Fetch(); std::string data = fields[0].GetString(); i_data->SetCompletedEncountersMask(fields[1].GetUInt32()); - if (data != "") + if (!data.empty()) { TC_LOG_DEBUG("maps", "Loading instance data for `%s` with id %u", sObjectMgr->GetScriptName(i_script_id), i_InstanceId); i_data->Load(data.c_str()); diff --git a/src/server/game/Server/Protocol/PacketLog.cpp b/src/server/game/Server/Protocol/PacketLog.cpp index 0a085ccc565..513787027b5 100644 --- a/src/server/game/Server/Protocol/PacketLog.cpp +++ b/src/server/game/Server/Protocol/PacketLog.cpp @@ -98,7 +98,7 @@ void PacketLog::Initialize() } } -void PacketLog::LogPacket(WorldPacket const& packet, Direction direction, boost::asio::ip::address addr, uint16 port) +void PacketLog::LogPacket(WorldPacket const& packet, Direction direction, boost::asio::ip::address const& addr, uint16 port) { std::lock_guard lock(_logPacketLock); diff --git a/src/server/game/Server/Protocol/PacketLog.h b/src/server/game/Server/Protocol/PacketLog.h index 36e8c675f63..06674b88b9e 100644 --- a/src/server/game/Server/Protocol/PacketLog.h +++ b/src/server/game/Server/Protocol/PacketLog.h @@ -48,7 +48,7 @@ class PacketLog void Initialize(); bool CanLogPacket() const { return (_file != NULL); } - void LogPacket(WorldPacket const& packet, Direction direction, boost::asio::ip::address addr, uint16 port); + void LogPacket(WorldPacket const& packet, Direction direction, boost::asio::ip::address const& addr, uint16 port); private: FILE* _file; diff --git a/src/server/game/Server/WorldSocket.cpp b/src/server/game/Server/WorldSocket.cpp index cf76812473e..fbba54bdf7a 100644 --- a/src/server/game/Server/WorldSocket.cpp +++ b/src/server/game/Server/WorldSocket.cpp @@ -232,7 +232,7 @@ void WorldSocket::SendPacket(WorldPacket& packet) void WorldSocket::HandleAuthSession(WorldPacket& recvPacket) { - uint8 digest[20]; + uint8 digest[SHA_DIGEST_LENGTH]; uint32 clientSeed; uint8 security; uint32 id; @@ -349,7 +349,7 @@ void WorldSocket::HandleAuthSession(WorldPacket& recvPacket) sha.UpdateBigNumbers(&k, NULL); sha.Finalize(); - if (memcmp(sha.GetDigest(), digest, 20)) + if (memcmp(sha.GetDigest(), digest, SHA_DIGEST_LENGTH) != 0) { SendAuthResponseError(AUTH_FAILED); TC_LOG_ERROR("network", "WorldSocket::HandleAuthSession: Authentication failed for account: %u ('%s') address: %s", id, account.c_str(), address.c_str()); @@ -360,7 +360,7 @@ void WorldSocket::HandleAuthSession(WorldPacket& recvPacket) ///- Re-check ip locking (same check as in auth). if (fields[3].GetUInt8() == 1) // if ip is locked { - if (strcmp(fields[2].GetCString(), address.c_str())) + if (strcmp(fields[2].GetCString(), address.c_str()) != 0) { SendAuthResponseError(AUTH_FAILED); TC_LOG_DEBUG("network", "WorldSocket::HandleAuthSession: Sent Auth Response (Account IP differs. Original IP: %s, new IP: %s).", fields[2].GetCString(), address.c_str()); diff --git a/src/server/game/Spells/Spell.cpp b/src/server/game/Spells/Spell.cpp index 18c066d2164..aedfeb149eb 100644 --- a/src/server/game/Spells/Spell.cpp +++ b/src/server/game/Spells/Spell.cpp @@ -7267,8 +7267,7 @@ WorldObjectSpellTargetCheck::WorldObjectSpellTargetCheck(Unit* caster, Unit* ref WorldObjectSpellTargetCheck::~WorldObjectSpellTargetCheck() { - if (_condSrcInfo) - delete _condSrcInfo; + delete _condSrcInfo; } bool WorldObjectSpellTargetCheck::operator()(WorldObject* target) diff --git a/src/server/game/Spells/SpellMgr.cpp b/src/server/game/Spells/SpellMgr.cpp index a5355c62f2c..c35dc51b873 100644 --- a/src/server/game/Spells/SpellMgr.cpp +++ b/src/server/game/Spells/SpellMgr.cpp @@ -973,10 +973,10 @@ bool SpellMgr::CanSpellTriggerProcOnEvent(SpellProcEntry const& procEntry, ProcE // check spell family name/flags (if set) for spells if (eventInfo.GetTypeMask() & (PERIODIC_PROC_FLAG_MASK | SPELL_PROC_FLAG_MASK | PROC_FLAG_DONE_TRAP_ACTIVATION)) { - if (procEntry.spellFamilyName && (procEntry.spellFamilyName != eventInfo.GetSpellInfo()->SpellFamilyName)) + if (procEntry.spellFamilyName && eventInfo.GetSpellInfo() && (procEntry.spellFamilyName != eventInfo.GetSpellInfo()->SpellFamilyName)) return false; - if (procEntry.spellFamilyMask && !(procEntry.spellFamilyMask & eventInfo.GetSpellInfo()->SpellFamilyFlags)) + if (procEntry.spellFamilyMask && eventInfo.GetSpellInfo() && !(procEntry.spellFamilyMask & eventInfo.GetSpellInfo()->SpellFamilyFlags)) return false; } diff --git a/src/server/game/Tools/PlayerDump.cpp b/src/server/game/Tools/PlayerDump.cpp index 887a79fc9f9..584331ad393 100644 --- a/src/server/game/Tools/PlayerDump.cpp +++ b/src/server/game/Tools/PlayerDump.cpp @@ -342,9 +342,7 @@ bool PlayerDumpWriter::DumpTable(std::string& dump, uint32 guid, char const*tabl bool PlayerDumpWriter::GetDump(uint32 guid, std::string &dump) { - dump = ""; - - dump += "IMPORTANT NOTE: THIS DUMPFILE IS MADE FOR USE WITH THE 'PDUMP' COMMAND ONLY - EITHER THROUGH INGAME CHAT OR ON CONSOLE!\n"; + dump = "IMPORTANT NOTE: THIS DUMPFILE IS MADE FOR USE WITH THE 'PDUMP' COMMAND ONLY - EITHER THROUGH INGAME CHAT OR ON CONSOLE!\n"; dump += "IMPORTANT NOTE: DO NOT apply it directly - it will irreversibly DAMAGE and CORRUPT your database! You have been warned!\n\n"; for (int i = 0; i < DUMP_TABLE_COUNT; ++i) @@ -425,7 +423,7 @@ DumpReturn PlayerDumpReader::LoadDump(std::string const& file, uint32 account, s // normalize the name if specified and check if it exists if (!normalizePlayerName(name)) - name = ""; + name.clear(); if (ObjectMgr::CheckPlayerName(name, true) == CHAR_NAME_SUCCESS) { @@ -434,10 +432,10 @@ DumpReturn PlayerDumpReader::LoadDump(std::string const& file, uint32 account, s PreparedQueryResult result = CharacterDatabase.Query(stmt); if (result) - name = ""; // use the one from the dump + name.clear(); // use the one from the dump } else - name = ""; + name.clear(); // name encoded or empty @@ -533,7 +531,7 @@ DumpReturn PlayerDumpReader::LoadDump(std::string const& file, uint32 account, s playerClass = uint8(atol(getnth(line, 5).c_str())); gender = uint8(atol(getnth(line, 6).c_str())); level = uint8(atol(getnth(line, 7).c_str())); - if (name == "") + if (name.empty()) { // check if the original name already exists name = getnth(line, 3); @@ -629,7 +627,7 @@ DumpReturn PlayerDumpReader::LoadDump(std::string const& file, uint32 account, s snprintf(lastpetid, 20, "%s", currpetid); if (strcmp(lastpetid, currpetid) != 0) { - snprintf(newpetid, 20, "%d", sObjectMgr->GeneratePetNumber()); + snprintf(newpetid, 20, "%u", sObjectMgr->GeneratePetNumber()); snprintf(lastpetid, 20, "%s", currpetid); } diff --git a/src/server/game/Warden/WardenMac.cpp b/src/server/game/Warden/WardenMac.cpp index 092bb19de07..f903e5324ac 100644 --- a/src/server/game/Warden/WardenMac.cpp +++ b/src/server/game/Warden/WardenMac.cpp @@ -244,7 +244,7 @@ void WardenMac::HandleData(ByteBuffer &buff) uint8 sha1Hash[20]; buff.read(sha1Hash, 20); - if (memcmp(sha1Hash, sha1.GetDigest(), 20)) + if (memcmp(sha1Hash, sha1.GetDigest(), 20) != 0) { TC_LOG_DEBUG("warden", "Handle data failed: SHA1 hash is wrong!"); //found = true; @@ -259,7 +259,7 @@ void WardenMac::HandleData(ByteBuffer &buff) uint8 theirsMD5Hash[16]; buff.read(theirsMD5Hash, 16); - if (memcmp(ourMD5Hash, theirsMD5Hash, 16)) + if (memcmp(ourMD5Hash, theirsMD5Hash, 16) != 0) { TC_LOG_DEBUG("warden", "Handle data failed: MD5 hash is wrong!"); //found = true; diff --git a/src/server/scripts/Commands/cs_account.cpp b/src/server/scripts/Commands/cs_account.cpp index 4b7aa8ecad3..91e42fc68f7 100644 --- a/src/server/scripts/Commands/cs_account.cpp +++ b/src/server/scripts/Commands/cs_account.cpp @@ -775,7 +775,7 @@ public: if (handler->HasLowerSecurityAccount(NULL, targetAccountId, true)) return false; - if (strcmp(password, passwordConfirmation)) + if (strcmp(password, passwordConfirmation) != 0) { handler->SendSysMessage(LANG_NEW_PASSWORDS_NOT_MATCH); handler->SetSentErrorMessage(true); diff --git a/src/server/scripts/Commands/cs_debug.cpp b/src/server/scripts/Commands/cs_debug.cpp index a2c71607eaa..6a810070347 100644 --- a/src/server/scripts/Commands/cs_debug.cpp +++ b/src/server/scripts/Commands/cs_debug.cpp @@ -320,7 +320,7 @@ public: std::string type; parsedStream >> type; - if (type == "") + if (type.empty()) break; if (type == "uint8") diff --git a/src/server/scripts/Commands/cs_guild.cpp b/src/server/scripts/Commands/cs_guild.cpp index f03be6e4530..7c025cd4e95 100644 --- a/src/server/scripts/Commands/cs_guild.cpp +++ b/src/server/scripts/Commands/cs_guild.cpp @@ -249,7 +249,7 @@ public: { Guild* guild = nullptr; - if (args && strlen(args) > 0) + if (args && args[0] != '\0') { if (isNumeric(args)) { diff --git a/src/server/scripts/Commands/cs_instance.cpp b/src/server/scripts/Commands/cs_instance.cpp index 464d58ad908..a426c49a5f7 100644 --- a/src/server/scripts/Commands/cs_instance.cpp +++ b/src/server/scripts/Commands/cs_instance.cpp @@ -125,7 +125,7 @@ public: uint16 counter = 0; uint16 MapId = 0; - if (strcmp(map, "all")) + if (strcmp(map, "all") != 0) { MapId = uint16(atoi(map)); if (!MapId) diff --git a/src/server/scripts/Commands/cs_misc.cpp b/src/server/scripts/Commands/cs_misc.cpp index 8e720e9faba..27b6cd562d7 100644 --- a/src/server/scripts/Commands/cs_misc.cpp +++ b/src/server/scripts/Commands/cs_misc.cpp @@ -199,10 +199,12 @@ public: else handler->PSendSysMessage(LANG_GPS_NO_VMAP); + char const* unknown = handler->GetTrinityString(LANG_UNKNOWN); + handler->PSendSysMessage(LANG_MAP_POSITION, - mapId, (mapEntry ? mapEntry->name[handler->GetSessionDbcLocale()] : handler->GetTrinityString(LANG_UNKNOWN)), - zoneId, (zoneEntry ? zoneEntry->area_name[handler->GetSessionDbcLocale()] : handler->GetTrinityString(LANG_UNKNOWN)), - areaId, (areaEntry ? areaEntry->area_name[handler->GetSessionDbcLocale()] : handler->GetTrinityString(LANG_UNKNOWN)), + mapId, (mapEntry ? mapEntry->name[handler->GetSessionDbcLocale()] : unknown), + zoneId, (zoneEntry ? zoneEntry->area_name[handler->GetSessionDbcLocale()] : unknown), + areaId, (areaEntry ? areaEntry->area_name[handler->GetSessionDbcLocale()] : unknown), object->GetPhaseMask(), object->GetPositionX(), object->GetPositionY(), object->GetPositionZ(), object->GetOrientation(), cell.GridX(), cell.GridY(), cell.CellX(), cell.CellY(), object->GetInstanceId(), @@ -1711,7 +1713,9 @@ public: } if (target) - handler->PSendSysMessage(LANG_PINFO_CHR_MAP, map->name[locale], (!zoneName.empty() ? zoneName.c_str() : handler->GetTrinityString(LANG_UNKNOWN)), (!areaName.empty() ? areaName.c_str() : handler->GetTrinityString(LANG_UNKNOWN))); + handler->PSendSysMessage(LANG_PINFO_CHR_MAP, map->name[locale], + (!zoneName.empty() ? zoneName.c_str() : handler->GetTrinityString(LANG_UNKNOWN)), + (!areaName.empty() ? areaName.c_str() : handler->GetTrinityString(LANG_UNKNOWN))); // Output XVII. - XVIX. if they are not empty if (!guildName.empty()) @@ -2187,7 +2191,7 @@ public: { Player* target = NULL; - if (args && strlen(args) > 0) + if (args && args[0] != '\0') { target = sObjectAccessor->FindPlayerByName(args); if (!target) diff --git a/src/server/scripts/Commands/cs_npc.cpp b/src/server/scripts/Commands/cs_npc.cpp index 5f4c8d0dfd4..987c12debb7 100644 --- a/src/server/scripts/Commands/cs_npc.cpp +++ b/src/server/scripts/Commands/cs_npc.cpp @@ -681,7 +681,7 @@ public: } creature->AI()->SetData(data_1, data_2); - std::string AIorScript = creature->GetAIName() != "" ? "AI type: " + creature->GetAIName() : (creature->GetScriptName() != "" ? "Script Name: " + creature->GetScriptName() : "No AI or Script Name Set"); + std::string AIorScript = !creature->GetAIName().empty() ? "AI type: " + creature->GetAIName() : (!creature->GetScriptName().empty() ? "Script Name: " + creature->GetScriptName() : "No AI or Script Name Set"); handler->PSendSysMessage(LANG_NPC_SETDATA, creature->GetGUID().GetCounter(), creature->GetEntry(), creature->GetName().c_str(), data_1, data_2, AIorScript.c_str()); return true; } diff --git a/src/server/scripts/Kalimdor/zone_tanaris.cpp b/src/server/scripts/Kalimdor/zone_tanaris.cpp index ec2fa7b398e..62337487b1c 100644 --- a/src/server/scripts/Kalimdor/zone_tanaris.cpp +++ b/src/server/scripts/Kalimdor/zone_tanaris.cpp @@ -105,7 +105,7 @@ public: ItemPosCountVec dest; uint8 msg = player->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, 11522, 1, NULL); if (msg == EQUIP_ERR_OK) - player->StoreNewItem(dest, 11522, 1, true); + player->StoreNewItem(dest, 11522, true); } } diff --git a/src/server/scripts/Northrend/CrusadersColiseum/TrialOfTheCrusader/boss_anubarak_trial.cpp b/src/server/scripts/Northrend/CrusadersColiseum/TrialOfTheCrusader/boss_anubarak_trial.cpp index cf33e08eeeb..d5bd2bcae7e 100644 --- a/src/server/scripts/Northrend/CrusadersColiseum/TrialOfTheCrusader/boss_anubarak_trial.cpp +++ b/src/server/scripts/Northrend/CrusadersColiseum/TrialOfTheCrusader/boss_anubarak_trial.cpp @@ -196,7 +196,7 @@ class boss_anubarak_trial : public CreatureScript std::list FrostSphereList; me->GetCreatureListWithEntryInGrid(FrostSphereList, NPC_FROST_SPHERE, 150.0f); if (!FrostSphereList.empty()) - for (std::list::iterator itr = FrostSphereList.begin(); itr != FrostSphereList.end(); itr++) + for (std::list::iterator itr = FrostSphereList.begin(); itr != FrostSphereList.end(); ++itr) (*itr)->DespawnOrUnsummon(); _burrowGUID.clear(); @@ -243,7 +243,7 @@ class boss_anubarak_trial : public CreatureScript me->GetCreatureListWithEntryInGrid(AddList, NPC_FROST_SPHERE, 150.0f); me->GetCreatureListWithEntryInGrid(AddList, NPC_BURROWER, 150.0f); if (!AddList.empty()) - for (std::list::iterator itr = AddList.begin(); itr != AddList.end(); itr++) + for (std::list::iterator itr = AddList.begin(); itr != AddList.end(); ++itr) (*itr)->DespawnOrUnsummon(); } diff --git a/src/server/scripts/Northrend/Ulduar/Ulduar/instance_ulduar.cpp b/src/server/scripts/Northrend/Ulduar/Ulduar/instance_ulduar.cpp index d00208b0d6f..016c0bff1e5 100644 --- a/src/server/scripts/Northrend/Ulduar/Ulduar/instance_ulduar.cpp +++ b/src/server/scripts/Northrend/Ulduar/Ulduar/instance_ulduar.cpp @@ -140,8 +140,8 @@ class instance_ulduar : public InstanceMapScript _algalonSummoned = false; _summonAlgalon = false; - memset(_summonObservationRingKeeper, false, sizeof(_summonObservationRingKeeper)); - memset(_summonYSKeeper, false, sizeof(_summonYSKeeper)); + memset(_summonObservationRingKeeper, 0, sizeof(_summonObservationRingKeeper)); + memset(_summonYSKeeper, 0, sizeof(_summonYSKeeper)); } void FillInitialWorldStates(WorldPacket& packet) override diff --git a/src/server/scripts/Outland/zone_shadowmoon_valley.cpp b/src/server/scripts/Outland/zone_shadowmoon_valley.cpp index 358b5d44387..54a7455d3f8 100644 --- a/src/server/scripts/Outland/zone_shadowmoon_valley.cpp +++ b/src/server/scripts/Outland/zone_shadowmoon_valley.cpp @@ -459,7 +459,7 @@ public: uint8 msg = player->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, 30658, 1, NULL); if (msg == EQUIP_ERR_OK) { - player->StoreNewItem(dest, 30658, 1, true); + player->StoreNewItem(dest, 30658, true); player->PlayerTalkClass->ClearMenus(); } } @@ -469,7 +469,7 @@ public: uint8 msg = player->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, 30659, 1, NULL); if (msg == EQUIP_ERR_OK) { - player->StoreNewItem(dest, 30659, 1, true); + player->StoreNewItem(dest, 30659, true); player->PlayerTalkClass->ClearMenus(); } } diff --git a/src/server/shared/DataStores/DBCFileLoader.cpp b/src/server/shared/DataStores/DBCFileLoader.cpp index d027d7539ad..1b7d34464f6 100644 --- a/src/server/shared/DataStores/DBCFileLoader.cpp +++ b/src/server/shared/DataStores/DBCFileLoader.cpp @@ -112,11 +112,9 @@ bool DBCFileLoader::Load(const char* filename, const char* fmt) DBCFileLoader::~DBCFileLoader() { - if (data) - delete [] data; + delete[] data; - if (fieldsOffset) - delete [] fieldsOffset; + delete[] fieldsOffset; } DBCFileLoader::Record DBCFileLoader::getRecord(size_t id) diff --git a/src/server/shared/Database/DatabaseWorkerPool.h b/src/server/shared/Database/DatabaseWorkerPool.h index 5548e44c925..61385d92437 100644 --- a/src/server/shared/Database/DatabaseWorkerPool.h +++ b/src/server/shared/Database/DatabaseWorkerPool.h @@ -76,13 +76,12 @@ class DatabaseWorkerPool bool Open(const std::string& infoString, uint8 async_threads, uint8 synch_threads) { - bool res = true; _connectionInfo = new MySQLConnectionInfo(infoString); TC_LOG_INFO("sql.driver", "Opening DatabasePool '%s'. Asynchronous connections: %u, synchronous connections: %u.", GetDatabaseName(), async_threads, synch_threads); - res = OpenConnections(IDX_ASYNC, async_threads); + bool res = OpenConnections(IDX_ASYNC, async_threads); if (!res) return res; diff --git a/src/server/shared/Database/MySQLConnection.cpp b/src/server/shared/Database/MySQLConnection.cpp index abdf2a2cc3c..24290009625 100644 --- a/src/server/shared/Database/MySQLConnection.cpp +++ b/src/server/shared/Database/MySQLConnection.cpp @@ -57,8 +57,7 @@ m_connectionFlags(CONNECTION_ASYNC) MySQLConnection::~MySQLConnection() { - if (m_worker) - delete m_worker; + delete m_worker; for (size_t i = 0; i < m_stmts.size(); ++i) delete m_stmts[i]; diff --git a/src/server/shared/Debugging/WheatyExceptionReport.cpp b/src/server/shared/Debugging/WheatyExceptionReport.cpp index 2eb456ddd02..66b7929514c 100644 --- a/src/server/shared/Debugging/WheatyExceptionReport.cpp +++ b/src/server/shared/Debugging/WheatyExceptionReport.cpp @@ -1043,7 +1043,7 @@ bool logChildren) offset, bHandled, Name, "", false, false); // Set Value back to an empty string since the Array object itself has no value, only its elements have - symbolDetails.top().Value = ""; + symbolDetails.top().Valu.clear(); DWORD elementsCount; if (SymGetTypeInfo(m_hProcess, modBase, dwTypeIndex, TI_GET_COUNT, &elementsCount)) diff --git a/src/server/shared/Threading/ProcessPriority.h b/src/server/shared/Threading/ProcessPriority.h index 23238c94ace..6446820e32d 100644 --- a/src/server/shared/Threading/ProcessPriority.h +++ b/src/server/shared/Threading/ProcessPriority.h @@ -26,7 +26,7 @@ #define PROCESS_HIGH_PRIORITY -15 // [-20, 19], default is 0 #endif -void SetProcessPriority(const std::string logChannel) +void SetProcessPriority(const std::string& logChannel) { // Suppresses Mac OS X Warning since logChannel isn't used. #if PLATFORM_APPLE diff --git a/src/server/shared/Utilities/ServiceWin32.cpp b/src/server/shared/Utilities/ServiceWin32.cpp index ecf403423f7..6e5309d70d7 100644 --- a/src/server/shared/Utilities/ServiceWin32.cpp +++ b/src/server/shared/Utilities/ServiceWin32.cpp @@ -204,7 +204,8 @@ void WINAPI ServiceMain(DWORD argc, char *argv[]) GetModuleFileName(0, path, sizeof(path)/sizeof(path[0])); - for (i = 0; i < std::strlen(path); i++) + size_t pathLen = std::strlen(path); + for (i = 0; i < pathLen; i++) { if (path[i] == '\\') last_slash = i; } diff --git a/src/server/shared/Utilities/Util.cpp b/src/server/shared/Utilities/Util.cpp index f2c02510ed4..e577797d3e0 100644 --- a/src/server/shared/Utilities/Util.cpp +++ b/src/server/shared/Utilities/Util.cpp @@ -294,7 +294,7 @@ size_t utf8length(std::string& utf8str) } catch(std::exception) { - utf8str = ""; + utf8str.clear(); return 0; } } @@ -316,7 +316,7 @@ void utf8truncate(std::string& utf8str, size_t len) } catch(std::exception) { - utf8str = ""; + utf8str.clear(); } } @@ -360,7 +360,7 @@ bool Utf8toWStr(const std::string& utf8str, std::wstring& wstr) } catch(std::exception) { - wstr = L""; + wstr.clear(); return false; } @@ -383,14 +383,14 @@ bool WStrToUtf8(wchar_t* wstr, size_t size, std::string& utf8str) } catch(std::exception) { - utf8str = ""; + utf8str.clear(); return false; } return true; } -bool WStrToUtf8(std::wstring wstr, std::string& utf8str) +bool WStrToUtf8(std::wstring const& wstr, std::string& utf8str) { try { @@ -406,7 +406,7 @@ bool WStrToUtf8(std::wstring wstr, std::string& utf8str) } catch(std::exception) { - utf8str = ""; + utf8str.clear(); return false; } @@ -415,7 +415,7 @@ bool WStrToUtf8(std::wstring wstr, std::string& utf8str) typedef wchar_t const* const* wstrlist; -std::wstring GetMainPartOfName(std::wstring wname, uint32 declension) +std::wstring GetMainPartOfName(std::wstring const& wname, uint32 declension) { // supported only Cyrillic cases if (wname.size() < 1 || !isCyrillicCharacter(wname[0]) || declension > 5) @@ -492,7 +492,7 @@ bool consoleToUtf8(const std::string& conStr, std::string& utf8str) #endif } -bool Utf8FitTo(const std::string& str, std::wstring search) +bool Utf8FitTo(const std::string& str, std::wstring const& search) { std::wstring temp; diff --git a/src/server/shared/Utilities/Util.h b/src/server/shared/Utilities/Util.h index 6370b9fda09..d88ad3be8e1 100644 --- a/src/server/shared/Utilities/Util.h +++ b/src/server/shared/Utilities/Util.h @@ -147,7 +147,7 @@ inline bool Utf8toWStr(const std::string& utf8str, wchar_t* wstr, size_t& wsize) return Utf8toWStr(utf8str.c_str(), utf8str.size(), wstr, wsize); } -bool WStrToUtf8(std::wstring wstr, std::string& utf8str); +bool WStrToUtf8(std::wstring const& wstr, std::string& utf8str); // size==real string size bool WStrToUtf8(wchar_t* wstr, size_t size, std::string& utf8str); @@ -331,11 +331,11 @@ inline void wstrToLower(std::wstring& str) std::transform( str.begin(), str.end(), str.begin(), wcharToLower ); } -std::wstring GetMainPartOfName(std::wstring wname, uint32 declension); +std::wstring GetMainPartOfName(std::wstring const& wname, uint32 declension); bool utf8ToConsole(const std::string& utf8str, std::string& conStr); bool consoleToUtf8(const std::string& conStr, std::string& utf8str); -bool Utf8FitTo(const std::string& str, std::wstring search); +bool Utf8FitTo(const std::string& str, std::wstring const& search); void utf8printf(FILE* out, const char *str, ...); void vutf8printf(FILE* out, const char *str, va_list* ap); diff --git a/src/server/worldserver/Main.cpp b/src/server/worldserver/Main.cpp index 191e44b3e93..07101e61eb6 100644 --- a/src/server/worldserver/Main.cpp +++ b/src/server/worldserver/Main.cpp @@ -268,8 +268,7 @@ extern int main(int argc, char** argv) delete soapThread; } - if (raAcceptor != nullptr) - delete raAcceptor; + delete raAcceptor; ///- Clean database before leaving ClearOnlineAccounts(); diff --git a/src/server/worldserver/RemoteAccess/RASession.cpp b/src/server/worldserver/RemoteAccess/RASession.cpp index 9892019ae5a..35149fff0b5 100644 --- a/src/server/worldserver/RemoteAccess/RASession.cpp +++ b/src/server/worldserver/RemoteAccess/RASession.cpp @@ -192,9 +192,7 @@ bool RASession::ProcessCommand(std::string& command) } // Obtain a new promise per command - if (_commandExecuting != nullptr) - delete _commandExecuting; - + delete _commandExecuting; _commandExecuting = new std::promise(); CliCommandHolder* cmd = new CliCommandHolder(this, command.c_str(), &RASession::CommandPrint, &RASession::CommandFinished); -- cgit v1.2.3