diff options
author | Shauren <shauren.trinity@gmail.com> | 2014-07-19 17:03:32 +0200 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2014-07-19 17:03:32 +0200 |
commit | 0bcc92d90020d0c4f7d3086189cc94e4990517b1 (patch) | |
tree | 52453e9b1ed9efe2edca7c61ee771cc8d30a29a4 /src | |
parent | 2452cfb98ecdc18bd64a118410d2a6dc9505f0c4 (diff) |
Part 3: Merge branch 'master' of https://github.com/TrinityCore/TrinityCore into 4.3.4
Diffstat (limited to 'src')
16 files changed, 291 insertions, 234 deletions
diff --git a/src/server/authserver/Main.cpp b/src/server/authserver/Main.cpp index 732ed58a19c..9fe6fb276a8 100644 --- a/src/server/authserver/Main.cpp +++ b/src/server/authserver/Main.cpp @@ -33,6 +33,8 @@ #include "AsyncAcceptor.h" #include "AuthSession.h" +#include "BattlenetManager.h" +#include "BattlenetSession.h" #include "Common.h" #include "Configuration/Config.h" #include "Database/DatabaseEnv.h" @@ -117,7 +119,7 @@ int main(int argc, char** argv) std::string bindIp = sConfigMgr->GetStringDefault("BindIP", "0.0.0.0"); AsyncAcceptor<AuthSession> authServer(_ioService, bindIp, port); - AsyncAcceptor<Battlenet::Socket> bnetServer(_ioService, bindIp, 1119); + AsyncAcceptor<Battlenet::Session> bnetServer(_ioService, bindIp, 1119); // Set signal handlers boost::asio::signal_set signals(_ioService, SIGINT, SIGTERM); diff --git a/src/server/authserver/Server/BattlenetBitStream.cpp b/src/server/authserver/Server/BattlenetBitStream.cpp new file mode 100644 index 00000000000..906d7802631 --- /dev/null +++ b/src/server/authserver/Server/BattlenetBitStream.cpp @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/> + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#include "BattlenetBitStream.h" + +template<> +bool Battlenet::BitStream::Read(uint32 /*bitCount*/) +{ + return Read<uint8>(1) != 0; +} diff --git a/src/server/authserver/Server/BattlenetBitStream.h b/src/server/authserver/Server/BattlenetBitStream.h index 3d1d2d5f67d..e108f810e2b 100644 --- a/src/server/authserver/Server/BattlenetBitStream.h +++ b/src/server/authserver/Server/BattlenetBitStream.h @@ -23,36 +23,24 @@ #include <exception> #include <vector> #include <type_traits> -#include <ace/Auto_Ptr.h> -#include <ace/Stack_Trace.h> +#include <memory> namespace Battlenet { class BitStreamPositionException : public std::exception { - static uint32 const MessageSize = ACE_Stack_Trace::SYMBUFSIZ + 128; + static uint32 const MessageSize = 128; public: BitStreamPositionException(bool read, uint32 operationSize, uint32 position, uint32 streamSize) { memset(_message, 0, MessageSize); -#ifndef TRINITY_DEBUG - snprintf(_message, MessageSize, "Attempted to %s more bits (%u) %s stream than %s (%u)\nStack trace:\n", + snprintf(_message, MessageSize, "Attempted to %s more bits (%u) %s stream than %s (%u)\n", (read ? "read" : "write"), operationSize + position, (read ? "from" : "to"), (read ? "exist" : "allowed"), streamSize); -#else - ACE_Stack_Trace st(1); - snprintf(_message, MessageSize, "Attempted to %s more bits (%u) %s stream than %s (%u)\nStack trace:\n%s", - (read ? "read" : "write"), - operationSize + position, - (read ? "from" : "to"), - (read ? "exist" : "allowed"), - streamSize, - st.c_str()); -#endif } char const* what() const throw() @@ -67,7 +55,7 @@ namespace Battlenet class BitStream { public: - static uint32 const MaxSize = 0x1000; + static uint32 const MaxSize = 0x4000; // length : The maximum number of bytes to read BitStream(uint32 length) : _numBits(length * 8), _readPos(0), _writePos(0) @@ -95,13 +83,13 @@ namespace Battlenet return str; } - ACE_Auto_Array_Ptr<uint8> ReadBytes(uint32 count) + std::unique_ptr<uint8[]> ReadBytes(uint32 count) { AlignToNextByte(); if (_readPos + count * 8 > _numBits) throw BitStreamPositionException(true, count * 8, _readPos, _numBits); - ACE_Auto_Array_Ptr<uint8> buf(new uint8[count]); + std::unique_ptr<uint8[]> buf(new uint8[count]); memcpy(buf.get(), &_buffer[_readPos >> 3], count); _readPos += count * 8; return buf; @@ -243,4 +231,7 @@ namespace Battlenet }; } +template<> +bool Battlenet::BitStream::Read<bool>(uint32 bitCount); + #endif // __BATTLENETBITSTREAM_H__ diff --git a/src/server/authserver/Server/BattlenetManager.h b/src/server/authserver/Server/BattlenetManager.h index 3b8a145f4e9..adef3b49d13 100644 --- a/src/server/authserver/Server/BattlenetManager.h +++ b/src/server/authserver/Server/BattlenetManager.h @@ -19,7 +19,6 @@ #define __BATTLENETMANAGER_H__ #include "Define.h" -#include <ace/Singleton.h> #include <string> #include <set> #include <map> @@ -85,17 +84,22 @@ namespace Battlenet class BattlenetMgr { - friend class ACE_Singleton<BattlenetMgr, ACE_Null_Mutex>; BattlenetMgr() { } ~BattlenetMgr(); public: void Load(); bool HasComponent(Battlenet::Component const* component) const; - bool HasProgram(std::string const& program) const { return _programs.count(program); } - bool HasPlatform(std::string const& platform) const { return _platforms.count(platform); } + bool HasProgram(std::string const& program) const { return _programs.count(program) != 0; } + bool HasPlatform(std::string const& platform) const { return _platforms.count(platform) != 0; } Battlenet::ModuleInfo* CreateModule(std::string const& os, std::string const& name) const; + static BattlenetMgr* instance() + { + static BattlenetMgr instance; + return &instance; + } + private: void LoadComponents(); void LoadModules(); @@ -106,6 +110,6 @@ private: std::map<Battlenet::ModuleKey, Battlenet::ModuleInfo*> _modules; }; -#define sBattlenetMgr ACE_Singleton<BattlenetMgr, ACE_Null_Mutex>::instance() +#define sBattlenetMgr BattlenetMgr::instance() #endif // __BATTLENETMANAGER_H__ diff --git a/src/server/authserver/Server/BattlenetPackets.cpp b/src/server/authserver/Server/BattlenetPackets.cpp index 6a8e09090ef..25a2c6cd9a5 100644 --- a/src/server/authserver/Server/BattlenetPackets.cpp +++ b/src/server/authserver/Server/BattlenetPackets.cpp @@ -20,6 +20,8 @@ #include "Util.h" #include <limits> #include <sstream> +#include <boost/lexical_cast.hpp> +#include <boost/asio/ip/address.hpp> std::string Battlenet::PacketHeader::ToString() const { @@ -374,13 +376,13 @@ void Battlenet::RealmUpdate::Write() _stream.WriteString(Version, 5); _stream.Write(Build, 32); - uint32 ip = Address.get_ip_address(); - uint16 port = Address.get_port_number(); + boost::asio::ip::address_v4::bytes_type ip = Address.address().to_v4().to_bytes(); + uint16 port = Address.port(); EndianConvertReverse(ip); EndianConvertReverse(port); - _stream.WriteBytes(&ip, 4); + _stream.WriteBytes(ip.data(), 4); _stream.WriteBytes(&port, 2); } @@ -423,17 +425,27 @@ void Battlenet::RealmJoinResult::Write() _stream.Write(0, 27); _stream.Write(0, 1); // Fail _stream.Write(ServerSeed, 32); - _stream.Write(0, 5); // IPv6 addresses + _stream.Write(IPv6.size(), 5); + for (tcp::endpoint const& addr : IPv6) + { + boost::asio::ip::address_v6::bytes_type ip = addr.address().to_v6().to_bytes(); + uint16 port = addr.port(); + + EndianConvertReverse(port); + + _stream.WriteBytes(ip.data(), 16); + _stream.WriteBytes(&port, 2); + } + _stream.Write(IPv4.size(), 5); - for (ACE_INET_Addr const& addr : IPv4) + for (ip::tcp::endpoint const& addr : IPv4) { - uint32 ip = addr.get_ip_address(); - uint16 port = addr.get_port_number(); + boost::asio::ip::address_v4::bytes_type ip = addr.address().to_v4().to_bytes(); + uint16 port = addr.port(); - EndianConvertReverse(ip); EndianConvertReverse(port); - _stream.WriteBytes(&ip, 4); + _stream.WriteBytes(ip.data(), 4); _stream.WriteBytes(&port, 2); } } @@ -441,9 +453,12 @@ void Battlenet::RealmJoinResult::Write() std::string Battlenet::RealmJoinResult::ToString() const { std::ostringstream stream; - stream << "Battlenet::RealmJoinResult ServerSeed " << ServerSeed << " IPv4 Addresses " << IPv4.size(); - for (ACE_INET_Addr const& addr : IPv4) - stream << std::endl << "Battlenet::RealmJoinResult::Address " << GetAddressString(addr); + stream << "Battlenet::RealmJoinResult ServerSeed " << ServerSeed << " IPv4 Addresses " << IPv4.size() << " IPv6 Addresses " << IPv6.size(); + for (ip::tcp::endpoint const& addr : IPv4) + stream << std::endl << "Battlenet::RealmJoinResult::Address " << boost::lexical_cast<std::string>(addr); + + for (ip::tcp::endpoint const& addr : IPv6) + stream << std::endl << "Battlenet::RealmJoinResult::Address " << boost::lexical_cast<std::string>(addr); return stream.str().c_str(); } diff --git a/src/server/authserver/Server/BattlenetPackets.h b/src/server/authserver/Server/BattlenetPackets.h index d9bfe8a4857..14ec80cdbaa 100644 --- a/src/server/authserver/Server/BattlenetPackets.h +++ b/src/server/authserver/Server/BattlenetPackets.h @@ -23,8 +23,10 @@ #include "BattlenetManager.h" #include "Define.h" #include "Errors.h" -#include <ace/INET_Addr.h> #include <string> +#include <boost/asio/ip/tcp.hpp> + +using boost::asio::ip::tcp; namespace Battlenet { @@ -315,7 +317,7 @@ namespace Battlenet uint32 Type; std::string Name; std::string Version; - ACE_INET_Addr Address; + ip::tcp::endpoint Address; uint8 Flags; uint8 Region; uint8 Battlegroup; @@ -361,7 +363,8 @@ namespace Battlenet std::string ToString() const override; uint32 ServerSeed; - std::vector<ACE_INET_Addr> IPv4; + std::vector<ip::tcp::endpoint> IPv4; + std::vector<ip::tcp::endpoint> IPv6; }; } diff --git a/src/server/authserver/Server/BattlenetSocket.cpp b/src/server/authserver/Server/BattlenetSession.cpp index 1c6951bc608..3725f5dbff8 100644 --- a/src/server/authserver/Server/BattlenetSocket.cpp +++ b/src/server/authserver/Server/BattlenetSession.cpp @@ -17,48 +17,46 @@ #include "AuthCodes.h" #include "BattlenetBitStream.h" -#include "BattlenetSocket.h" +#include "BattlenetSession.h" #include "Database/DatabaseEnv.h" #include "HmacHash.h" #include "Log.h" #include "RealmList.h" #include "SHA256.h" #include <map> +#include <boost/asio/write.hpp> -uint32 const Battlenet::Socket::SRP6_V_Size = 128; -uint32 const Battlenet::Socket::SRP6_S_Size = 32; - -std::map<Battlenet::PacketHeader, Battlenet::Socket::PacketHandler> InitHandlers() +std::map<Battlenet::PacketHeader, Battlenet::Session::PacketHandler> InitHandlers() { - std::map<Battlenet::PacketHeader, Battlenet::Socket::PacketHandler> handlers; + std::map<Battlenet::PacketHeader, Battlenet::Session::PacketHandler> handlers; - handlers[Battlenet::PacketHeader(Battlenet::CMSG_AUTH_CHALLENGE, Battlenet::AUTHENTICATION)] = &Battlenet::Socket::HandleAuthChallenge; - handlers[Battlenet::PacketHeader(Battlenet::CMSG_AUTH_RECONNECT, Battlenet::AUTHENTICATION)] = &Battlenet::Socket::HandleAuthReconnect; - handlers[Battlenet::PacketHeader(Battlenet::CMSG_AUTH_PROOF_RESPONSE, Battlenet::AUTHENTICATION)] = &Battlenet::Socket::HandleAuthProofResponse; + handlers[Battlenet::PacketHeader(Battlenet::CMSG_AUTH_CHALLENGE, Battlenet::AUTHENTICATION)] = &Battlenet::Session::HandleAuthChallenge; + handlers[Battlenet::PacketHeader(Battlenet::CMSG_AUTH_RECONNECT, Battlenet::AUTHENTICATION)] = &Battlenet::Session::HandleAuthReconnect; + handlers[Battlenet::PacketHeader(Battlenet::CMSG_AUTH_PROOF_RESPONSE, Battlenet::AUTHENTICATION)] = &Battlenet::Session::HandleAuthProofResponse; - handlers[Battlenet::PacketHeader(Battlenet::CMSG_PING, Battlenet::CONNECTION)] = &Battlenet::Socket::HandlePing; - handlers[Battlenet::PacketHeader(Battlenet::CMSG_ENABLE_ENCRYPTION, Battlenet::CONNECTION)] = &Battlenet::Socket::HandleEnableEncryption; - handlers[Battlenet::PacketHeader(Battlenet::CMSG_DISCONNECT, Battlenet::CONNECTION)] = &Battlenet::Socket::HandleDisconnect; + handlers[Battlenet::PacketHeader(Battlenet::CMSG_PING, Battlenet::CONNECTION)] = &Battlenet::Session::HandlePing; + handlers[Battlenet::PacketHeader(Battlenet::CMSG_ENABLE_ENCRYPTION, Battlenet::CONNECTION)] = &Battlenet::Session::HandleEnableEncryption; + handlers[Battlenet::PacketHeader(Battlenet::CMSG_DISCONNECT, Battlenet::CONNECTION)] = &Battlenet::Session::HandleDisconnect; - handlers[Battlenet::PacketHeader(Battlenet::CMSG_REALM_UPDATE_SUBSCRIBE, Battlenet::WOW)] = &Battlenet::Socket::HandleRealmUpdateSubscribe; - handlers[Battlenet::PacketHeader(Battlenet::CMSG_JOIN_REQUEST, Battlenet::WOW)] = &Battlenet::Socket::HandleRealmJoinRequest; + handlers[Battlenet::PacketHeader(Battlenet::CMSG_REALM_UPDATE_SUBSCRIBE, Battlenet::WOW)] = &Battlenet::Session::HandleRealmUpdateSubscribe; + handlers[Battlenet::PacketHeader(Battlenet::CMSG_JOIN_REQUEST, Battlenet::WOW)] = &Battlenet::Session::HandleRealmJoinRequest; return handlers; } -std::map<Battlenet::PacketHeader, Battlenet::Socket::PacketHandler> Handlers = InitHandlers(); +std::map<Battlenet::PacketHeader, Battlenet::Session::PacketHandler> Handlers = InitHandlers(); -Battlenet::Socket::ModuleHandler const Battlenet::Socket::ModuleHandlers[MODULE_COUNT] = +Battlenet::Session::ModuleHandler const Battlenet::Session::ModuleHandlers[MODULE_COUNT] = { - &Battlenet::Socket::HandlePasswordModule, - &Battlenet::Socket::UnhandledModule, - &Battlenet::Socket::UnhandledModule, - &Battlenet::Socket::HandleSelectGameAccountModule, - &Battlenet::Socket::HandleRiskFingerprintModule, - &Battlenet::Socket::HandleResumeModule, + &Battlenet::Session::HandlePasswordModule, + &Battlenet::Session::UnhandledModule, + &Battlenet::Session::UnhandledModule, + &Battlenet::Session::HandleSelectGameAccountModule, + &Battlenet::Session::HandleRiskFingerprintModule, + &Battlenet::Session::HandleResumeModule, }; -Battlenet::Socket::Socket(RealmSocket& socket) : _socket(socket), _accountId(0), _accountName(), _locale(), +Battlenet::Session::Session(tcp::socket&& socket) : _socket(std::move(socket)), _accountId(0), _accountName(), _locale(), _os(), _build(0), _gameAccountId(0), _gameAccountIndex(0), _accountSecurityLevel(SEC_PLAYER), I(), s(), v(), b(), B(), K(), _reconnectProof(), _crypt(), _authed(false) { @@ -83,9 +81,14 @@ Battlenet::Socket::Socket(RealmSocket& socket) : _socket(socket), _accountId(0), k.SetBinary(sha.GetDigest(), sha.GetLength()); } -void Battlenet::Socket::_SetVSFields(std::string const& pstr) +Battlenet::Session::~Session() +{ + TC_LOG_TRACE("server.battlenet", "Battlenet::Session::OnClose"); +} + +void Battlenet::Session::_SetVSFields(std::string const& pstr) { - s.SetRand(SRP6_S_Size * 8); + s.SetRand(uint32(BufferSizes::SRP_6_S) * 8); BigNumber p; p.SetHexStr(pstr.c_str()); @@ -105,20 +108,20 @@ void Battlenet::Socket::_SetVSFields(std::string const& pstr) LoginDatabase.Execute(stmt); } -bool Battlenet::Socket::HandleAuthChallenge(PacketHeader& header, BitStream& packet) +bool Battlenet::Session::HandleAuthChallenge(PacketHeader& header, BitStream& packet) { // Verify that this IP is not in the ip_banned table LoginDatabase.Execute(LoginDatabase.GetPreparedStatement(LOGIN_DEL_EXPIRED_IP_BANS)); - std::string const& ip_address = _socket.getRemoteAddress(); + std::string const& ip_address = GetRemoteAddress(); PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_IP_BANNED); stmt->setString(0, ip_address); if (PreparedQueryResult result = LoginDatabase.Query(stmt)) { - AuthComplete complete; - complete.SetAuthResult(LOGIN_BANNED); - Send(complete); - TC_LOG_DEBUG("server.battlenet", "[Battlenet::AuthChallenge] Banned ip '%s:%d' tries to login!", _socket.getRemoteAddress().c_str(), _socket.getRemotePort()); + AuthComplete* complete = new AuthComplete(); + complete->SetAuthResult(LOGIN_BANNED); + AsyncWrite(complete); + TC_LOG_DEBUG("server.battlenet", "[Battlenet::AuthChallenge] Banned ip '%s:%d' tries to login!", ip_address.c_str(), GetRemotePort()); return true; } @@ -127,25 +130,25 @@ bool Battlenet::Socket::HandleAuthChallenge(PacketHeader& header, BitStream& pac if (info.Program != "WoW") { - AuthComplete complete; - complete.SetAuthResult(AUTH_INVALID_PROGRAM); - Send(complete); + AuthComplete* complete = new AuthComplete(); + complete->SetAuthResult(AUTH_INVALID_PROGRAM); + AsyncWrite(complete); return true; } if (!sBattlenetMgr->HasPlatform(info.Platform)) { - AuthComplete complete; - complete.SetAuthResult(AUTH_INVALID_OS); - Send(complete); + AuthComplete* complete = new AuthComplete(); + complete->SetAuthResult(AUTH_INVALID_OS); + AsyncWrite(complete); return true; } if (!sBattlenetMgr->HasPlatform(info.Locale)) { - AuthComplete complete; - complete.SetAuthResult(AUTH_UNSUPPORTED_LANGUAGE); - Send(complete); + AuthComplete* complete = new AuthComplete(); + complete->SetAuthResult(AUTH_UNSUPPORTED_LANGUAGE); + AsyncWrite(complete); return true; } @@ -153,20 +156,20 @@ bool Battlenet::Socket::HandleAuthChallenge(PacketHeader& header, BitStream& pac { if (!sBattlenetMgr->HasComponent(&component)) { - AuthComplete complete; + AuthComplete* complete = new AuthComplete(); if (!sBattlenetMgr->HasProgram(component.Program)) - complete.SetAuthResult(AUTH_INVALID_PROGRAM); + complete->SetAuthResult(AUTH_INVALID_PROGRAM); else if (!sBattlenetMgr->HasPlatform(component.Platform)) - complete.SetAuthResult(AUTH_INVALID_OS); + complete->SetAuthResult(AUTH_INVALID_OS); else { if (component.Program != "WoW" || AuthHelper::IsBuildSupportingBattlenet(component.Build)) - complete.SetAuthResult(AUTH_REGION_BAD_VERSION); + complete->SetAuthResult(AUTH_REGION_BAD_VERSION); else - complete.SetAuthResult(AUTH_USE_GRUNT_LOGON); + complete->SetAuthResult(AUTH_USE_GRUNT_LOGON); } - Send(complete); + AsyncWrite(complete); return true; } @@ -185,9 +188,9 @@ bool Battlenet::Socket::HandleAuthChallenge(PacketHeader& header, BitStream& pac PreparedQueryResult result = LoginDatabase.Query(stmt); if (!result) { - AuthComplete complete; - complete.SetAuthResult(AUTH_UNKNOWN_ACCOUNT); - Send(complete); + AuthComplete* complete = new AuthComplete(); + complete->SetAuthResult(AUTH_UNKNOWN_ACCOUNT); + AsyncWrite(complete); return true; } @@ -202,9 +205,9 @@ bool Battlenet::Socket::HandleAuthChallenge(PacketHeader& header, BitStream& pac if (strcmp(fields[4].GetCString(), ip_address.c_str()) != 0) { - AuthComplete complete; - complete.SetAuthResult(AUTH_ACCOUNT_LOCKED); - Send(complete); + AuthComplete* complete = new AuthComplete(); + complete->SetAuthResult(AUTH_ACCOUNT_LOCKED); + AsyncWrite(complete); return true; } } @@ -227,9 +230,9 @@ bool Battlenet::Socket::HandleAuthChallenge(PacketHeader& header, BitStream& pac TC_LOG_DEBUG("server.battlenet", "[Battlenet::AuthChallenge] Account '%s' is locked to country: '%s' Player country is '%s'", _accountName.c_str(), accountCountry.c_str(), loginCountry.c_str()); if (loginCountry != accountCountry) { - AuthComplete complete; - complete.SetAuthResult(AUTH_ACCOUNT_LOCKED); - Send(complete); + AuthComplete* complete = new AuthComplete(); + complete->SetAuthResult(AUTH_ACCOUNT_LOCKED); + AsyncWrite(complete); return true; } } @@ -248,18 +251,18 @@ bool Battlenet::Socket::HandleAuthChallenge(PacketHeader& header, BitStream& pac Field* fields = banresult->Fetch(); if (fields[0].GetUInt32() == fields[1].GetUInt32()) { - AuthComplete complete; - complete.SetAuthResult(LOGIN_BANNED); - Send(complete); - TC_LOG_DEBUG("server.battlenet", "'%s:%d' [Battlenet::AuthChallenge] Banned account %s tried to login!", _socket.getRemoteAddress().c_str(), _socket.getRemotePort(), _accountName.c_str()); + AuthComplete* complete = new AuthComplete(); + complete->SetAuthResult(LOGIN_BANNED); + AsyncWrite(complete); + TC_LOG_DEBUG("server.battlenet", "'%s:%d' [Battlenet::AuthChallenge] Banned account %s tried to login!", ip_address.c_str(), GetRemotePort(), _accountName.c_str()); return true; } else { - AuthComplete complete; - complete.SetAuthResult(LOGIN_SUSPENDED); - Send(complete); - TC_LOG_DEBUG("server.battlenet", "'%s:%d' [Battlenet::AuthChallenge] Temporarily banned account %s tried to login!", _socket.getRemoteAddress().c_str(), _socket.getRemotePort(), _accountName.c_str()); + AuthComplete* complete = new AuthComplete(); + complete->SetAuthResult(LOGIN_SUSPENDED); + AsyncWrite(complete); + TC_LOG_DEBUG("server.battlenet", "'%s:%d' [Battlenet::AuthChallenge] Temporarily banned account %s tried to login!", ip_address.c_str(), GetRemotePort(), _accountName.c_str()); return true; } } @@ -278,7 +281,7 @@ bool Battlenet::Socket::HandleAuthChallenge(PacketHeader& header, BitStream& pac std::string databaseV = fields[5].GetString(); std::string databaseS = fields[6].GetString(); - if (databaseV.size() != SRP6_V_Size * 2 || databaseS.size() != SRP6_S_Size * 2) + if (databaseV.size() != size_t(BufferSizes::SRP_6_V) * 2 || databaseS.size() != size_t(BufferSizes::SRP_6_S) * 2) _SetVSFields(pStr); else { @@ -305,15 +308,15 @@ bool Battlenet::Socket::HandleAuthChallenge(PacketHeader& header, BitStream& pac _modulesWaitingForData.push(MODULE_PASSWORD); - ProofRequest request; - request.Modules.push_back(password); + ProofRequest* request = new ProofRequest(); + request->Modules.push_back(password); // if has authenticator, send Token module - request.Modules.push_back(thumbprint); - Send(request); + request->Modules.push_back(thumbprint); + AsyncWrite(request); return true; } -bool Battlenet::Socket::HandleAuthReconnect(PacketHeader& header, BitStream& packet) +bool Battlenet::Session::HandleAuthReconnect(PacketHeader& header, BitStream& packet) { AuthResumeInfo reconnect(header, packet); reconnect.Read(); @@ -336,9 +339,9 @@ bool Battlenet::Socket::HandleAuthReconnect(PacketHeader& header, BitStream& pac PreparedQueryResult result = LoginDatabase.Query(stmt); if (!result) { - AuthResume resume; - resume.SetAuthResult(AUTH_UNKNOWN_ACCOUNT); - Send(resume); + AuthResume* resume = new AuthResume(); + resume->SetAuthResult(AUTH_UNKNOWN_ACCOUNT); + AsyncWrite(resume); return false; } @@ -364,23 +367,23 @@ bool Battlenet::Socket::HandleAuthReconnect(PacketHeader& header, BitStream& pac _modulesWaitingForData.push(MODULE_RESUME); - ProofRequest request; - request.Modules.push_back(thumbprint); - request.Modules.push_back(resume); - Send(request); + ProofRequest* request = new ProofRequest(); + request->Modules.push_back(thumbprint); + request->Modules.push_back(resume); + AsyncWrite(request); return true; } -bool Battlenet::Socket::HandleAuthProofResponse(PacketHeader& header, BitStream& packet) +bool Battlenet::Session::HandleAuthProofResponse(PacketHeader& header, BitStream& packet) { ProofResponse proof(header, packet); proof.Read(); if (_modulesWaitingForData.size() < proof.Modules.size()) { - AuthComplete complete; - complete.SetAuthResult(AUTH_CORRUPTED_MODULE); - Send(complete); + AuthComplete* complete = new AuthComplete(); + complete->SetAuthResult(AUTH_CORRUPTED_MODULE); + AsyncWrite(complete); return true; } @@ -399,25 +402,23 @@ bool Battlenet::Socket::HandleAuthProofResponse(PacketHeader& header, BitStream& static_cast<AuthComplete*>(response)->SetAuthResult(AUTH_INTERNAL_ERROR); } - Send(*response); - delete response; + AsyncWrite(response); return true; } -bool Battlenet::Socket::HandlePing(PacketHeader& /*header*/, BitStream& /*packet*/) +bool Battlenet::Session::HandlePing(PacketHeader& /*header*/, BitStream& /*packet*/) { - Pong pong; - Send(pong); + AsyncWrite(new Pong()); return true; } -bool Battlenet::Socket::HandleEnableEncryption(PacketHeader& /*header*/, BitStream& /*packet*/) +bool Battlenet::Session::HandleEnableEncryption(PacketHeader& /*header*/, BitStream& /*packet*/) { _crypt.Init(&K); return true; } -bool Battlenet::Socket::HandleDisconnect(PacketHeader& /*header*/, BitStream& /*packet*/) +bool Battlenet::Session::HandleDisconnect(PacketHeader& /*header*/, BitStream& /*packet*/) { PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_BNET_SESSION_KEY); stmt->setString(0, ""); @@ -427,14 +428,11 @@ bool Battlenet::Socket::HandleDisconnect(PacketHeader& /*header*/, BitStream& /* return true; } -bool Battlenet::Socket::HandleRealmUpdateSubscribe(PacketHeader& /*header*/, BitStream& /*packet*/) +bool Battlenet::Session::HandleRealmUpdateSubscribe(PacketHeader& /*header*/, BitStream& /*packet*/) { - sRealmList->UpdateIfNeed(); - - RealmCharacterCounts counts; + sRealmList.UpdateIfNeed(); - ACE_INET_Addr clientAddr; - _socket.peer().get_remote_addr(clientAddr); + RealmCharacterCounts* counts = new RealmCharacterCounts(); PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_BNET_CHARACTER_COUNTS); stmt->setUInt32(0, _gameAccountId); @@ -445,11 +443,11 @@ bool Battlenet::Socket::HandleRealmUpdateSubscribe(PacketHeader& /*header*/, Bit { Field* fields = countResult->Fetch(); uint32 build = fields[4].GetUInt32(); - counts.CharacterCounts.push_back({ { fields[2].GetUInt8(), fields[3].GetUInt8(), fields[1].GetUInt32(), (_build != build ? build : 0) }, fields[0].GetUInt8() }); + counts->CharacterCounts.push_back({ { fields[2].GetUInt8(), fields[3].GetUInt8(), fields[1].GetUInt32(), (_build != build ? build : 0) }, fields[0].GetUInt8() }); } while (countResult->NextRow()); } - for (RealmList::RealmMap::const_iterator i = sRealmList->begin(); i != sRealmList->end(); ++i) + for (RealmList::RealmMap::const_iterator i = sRealmList.begin(); i != sRealmList.end(); ++i) { Realm const& realm = i->second; @@ -479,7 +477,7 @@ bool Battlenet::Socket::HandleRealmUpdateSubscribe(PacketHeader& /*header*/, Bit version << buildInfo->MajorVersion << '.' << buildInfo->MinorVersion << '.' << buildInfo->BugfixVersion << '.' << buildInfo->Build; update->Version = version.str(); - update->Address = realm.GetAddressForClient(clientAddr); + update->Address = realm.GetAddressForClient(_socket.remote_endpoint().address()); update->Build = buildInfo->Build; } @@ -488,128 +486,140 @@ bool Battlenet::Socket::HandleRealmUpdateSubscribe(PacketHeader& /*header*/, Bit update->Battlegroup = realm.Battlegroup; update->Index = realm.m_ID; - counts.RealmData.push_back(update); + counts->RealmData.push_back(update); } - counts.RealmData.push_back(new RealmUpdateComplete()); + counts->RealmData.push_back(new RealmUpdateComplete()); - Send(counts); + AsyncWrite(counts); return true; } -bool Battlenet::Socket::HandleRealmJoinRequest(PacketHeader& header, BitStream& packet) +bool Battlenet::Session::HandleRealmJoinRequest(PacketHeader& header, BitStream& packet) { RealmJoinRequest join(header, packet); join.Read(); - RealmJoinResult result; - Realm const* realm = sRealmList->GetRealm(join.Realm); + RealmJoinResult* result = new RealmJoinResult(); + Realm const* realm = sRealmList.GetRealm(join.Realm); if (!realm || realm->flag & (REALM_FLAG_INVALID | REALM_FLAG_OFFLINE)) { - Send(result); + AsyncWrite(result); return true; } - result.ServerSeed = uint32(rand32()); + result->ServerSeed = uint32(rand32()); uint8 sessionKey[40]; HmacSha1 hmac(K.GetNumBytes(), K.AsByteArray().get()); hmac.UpdateData((uint8*)"WoW\0", 4); hmac.UpdateData((uint8*)&join.ClientSeed, 4); - hmac.UpdateData((uint8*)&result.ServerSeed, 4); + hmac.UpdateData((uint8*)&result->ServerSeed, 4); hmac.Finalize(); memcpy(sessionKey, hmac.GetDigest(), hmac.GetLength()); HmacSha1 hmac2(K.GetNumBytes(), K.AsByteArray().get()); hmac2.UpdateData((uint8*)"WoW\0", 4); - hmac2.UpdateData((uint8*)&result.ServerSeed, 4); + hmac2.UpdateData((uint8*)&result->ServerSeed, 4); hmac2.UpdateData((uint8*)&join.ClientSeed, 4); hmac2.Finalize(); memcpy(sessionKey + hmac.GetLength(), hmac2.GetDigest(), hmac2.GetLength()); LoginDatabase.DirectPExecute("UPDATE account SET sessionkey = '%s', last_ip = '%s', last_login = NOW(), locale = %u, failed_logins = 0, os = '%s' WHERE id = %u", - ByteArrayToHexStr(sessionKey, 40, true).c_str(), _socket.getRemoteAddress().c_str(), GetLocaleByName(_locale), _os.c_str(), _gameAccountId); + ByteArrayToHexStr(sessionKey, 40, true).c_str(), GetRemoteAddress().c_str(), GetLocaleByName(_locale), _os.c_str(), _gameAccountId); - result.IPv4.push_back(realm->ExternalAddress); + result->IPv4.emplace_back(realm->ExternalAddress, realm->port); if (realm->ExternalAddress != realm->LocalAddress) - result.IPv4.push_back(realm->LocalAddress); + result->IPv4.emplace_back(realm->LocalAddress, realm->port); - Send(result); + AsyncWrite(result); return true; } -void Battlenet::Socket::OnRead() +void Battlenet::Session::AsyncRead() { - size_t length = _socket.recv_len(); - if (!length) - return; - - BitStream packet(length); - if (!_socket.recv((char*)packet.GetBuffer(), length)) - return; + auto self(shared_from_this()); - _crypt.DecryptRecv(packet.GetBuffer(), length); - - while (!packet.IsRead()) + _socket.async_read_some(boost::asio::buffer(_readBuffer, size_t(BufferSizes::Read)), [this, self](boost::system::error_code error, size_t transferedBytes) { - try + if (error) { - PacketHeader header; - header.Opcode = packet.Read<uint32>(6); - if (packet.Read<bool>(1)) - header.Channel = packet.Read<int32>(4); + _socket.close(); + return; + } - if (header.Channel != AUTHENTICATION && !_authed) - { - TC_LOG_DEBUG("server.battlenet", "Battlenet::Socket::OnRead Received not allowed packet %s", header.ToString().c_str()); - _socket.shutdown(); - return; - } + BitStream packet(transferedBytes); + std::memcpy(packet.GetBuffer(), _readBuffer, transferedBytes); + _crypt.DecryptRecv(packet.GetBuffer(), transferedBytes); - TC_LOG_TRACE("server.battlenet", "Battlenet::Socket::OnRead %s", header.ToString().c_str()); - std::map<PacketHeader, PacketHandler>::const_iterator itr = Handlers.find(header); - if (itr != Handlers.end()) + while (!packet.IsRead()) + { + try { - if ((this->*(itr->second))(header, packet)) + PacketHeader header; + header.Opcode = packet.Read<uint32>(6); + if (packet.Read<bool>(1)) + header.Channel = packet.Read<int32>(4); + + if (header.Channel != AUTHENTICATION && !_authed) + { + TC_LOG_DEBUG("server.battlenet", "Battlenet::Session::AsyncRead Received not allowed packet %s", header.ToString().c_str()); + _socket.close(); + return; + } + + TC_LOG_TRACE("server.battlenet", "Battlenet::Session::AsyncRead %s", header.ToString().c_str()); + std::map<PacketHeader, PacketHandler>::const_iterator itr = Handlers.find(header); + if (itr != Handlers.end()) + { + if ((this->*(itr->second))(header, packet)) + break; + } + else + { + TC_LOG_DEBUG("server.battlenet", "Battlenet::Session::AsyncRead Unhandled opcode %s", header.ToString().c_str()); break; + } + + packet.AlignToNextByte(); } - else + catch (BitStreamPositionException const& e) { - TC_LOG_DEBUG("server.battlenet", "Battlenet::Socket::OnRead Unhandled opcode %s", header.ToString().c_str()); + TC_LOG_ERROR("server.battlenet", "Battlenet::Session::AsyncRead Exception: %s", e.what()); + _socket.close(); return; } - - packet.AlignToNextByte(); } - catch (BitStreamPositionException const& e) - { - TC_LOG_ERROR("server.battlenet", "Battlenet::Socket::OnRead Exception: %s", e.what()); - _socket.shutdown(); - return; - } - } -} -void Battlenet::Socket::OnAccept() -{ - TC_LOG_TRACE("server.battlenet", "Battlenet::Socket::OnAccept"); + AsyncRead(); + }); } -void Battlenet::Socket::OnClose() +void Battlenet::Session::Start() { - TC_LOG_TRACE("server.battlenet", "Battlenet::Socket::OnClose"); + TC_LOG_TRACE("server.battlenet", "Battlenet::Session::Start"); + AsyncRead(); } -void Battlenet::Socket::Send(ServerPacket& packet) +void Battlenet::Session::AsyncWrite(ServerPacket* packet) { - TC_LOG_TRACE("server.battlenet", "Battlenet::Socket::Send %s", packet.ToString().c_str()); + TC_LOG_TRACE("server.battlenet", "Battlenet::Session::AsyncWrite %s", packet->ToString().c_str()); + + packet->Write(); - packet.Write(); + _crypt.EncryptSend(const_cast<uint8*>(packet->GetData()), packet->GetSize()); + + auto self(shared_from_this()); + + boost::asio::async_write(_socket, boost::asio::buffer(packet->GetData(), packet->GetSize()), [this, self, packet](boost::system::error_code error, std::size_t /*length*/) + { + if (error) + _socket.close(); - _crypt.EncryptSend(const_cast<uint8*>(packet.GetData()), packet.GetSize()); - _socket.send(reinterpret_cast<char const*>(packet.GetData()), packet.GetSize()); + delete packet; + }); } inline void ReplaceResponse(Battlenet::ServerPacket** oldResponse, Battlenet::ServerPacket* newResponse) @@ -620,7 +630,7 @@ inline void ReplaceResponse(Battlenet::ServerPacket** oldResponse, Battlenet::Se *oldResponse = newResponse; } -bool Battlenet::Socket::HandlePasswordModule(BitStream* dataStream, ServerPacket** response) +bool Battlenet::Session::HandlePasswordModule(BitStream* dataStream, ServerPacket** response) { if (dataStream->GetSize() != 1 + 128 + 32 + 128) { @@ -799,12 +809,12 @@ bool Battlenet::Socket::HandlePasswordModule(BitStream* dataStream, ServerPacket if (fields[2].GetUInt32() == fields[3].GetUInt32()) { complete->SetAuthResult(LOGIN_BANNED); - TC_LOG_DEBUG("server.battlenet", "'%s:%d' [Battlenet::AuthChallenge] Banned account %s tried to login!", _socket.getRemoteAddress().c_str(), _socket.getRemotePort(), _accountName.c_str()); + TC_LOG_DEBUG("server.battlenet", "'%s:%d' [Battlenet::AuthChallenge] Banned account %s tried to login!", GetRemoteAddress().c_str(), GetRemotePort(), _accountName.c_str()); } else { complete->SetAuthResult(LOGIN_SUSPENDED); - TC_LOG_DEBUG("server.battlenet", "'%s:%d' [Battlenet::AuthChallenge] Temporarily banned account %s tried to login!", _socket.getRemoteAddress().c_str(), _socket.getRemotePort(), _accountName.c_str()); + TC_LOG_DEBUG("server.battlenet", "'%s:%d' [Battlenet::AuthChallenge] Temporarily banned account %s tried to login!", GetRemoteAddress().c_str(), GetRemotePort(), _accountName.c_str()); } ReplaceResponse(response, complete); @@ -822,7 +832,7 @@ bool Battlenet::Socket::HandlePasswordModule(BitStream* dataStream, ServerPacket return true; } -bool Battlenet::Socket::HandleSelectGameAccountModule(BitStream* dataStream, ServerPacket** response) +bool Battlenet::Session::HandleSelectGameAccountModule(BitStream* dataStream, ServerPacket** response) { if (dataStream->Read<uint8>(8) != 1) { @@ -863,12 +873,12 @@ bool Battlenet::Socket::HandleSelectGameAccountModule(BitStream* dataStream, Ser if (fields[1].GetUInt32() == fields[2].GetUInt32()) { complete->SetAuthResult(LOGIN_BANNED); - TC_LOG_DEBUG("server.battlenet", "'%s:%d' [Battlenet::SelectGameAccount] Banned account %s tried to login!", _socket.getRemoteAddress().c_str(), _socket.getRemotePort(), _accountName.c_str()); + TC_LOG_DEBUG("server.battlenet", "'%s:%d' [Battlenet::SelectGameAccount] Banned account %s tried to login!", GetRemoteAddress().c_str(), GetRemotePort(), _accountName.c_str()); } else { complete->SetAuthResult(LOGIN_SUSPENDED); - TC_LOG_DEBUG("server.battlenet", "'%s:%d' [Battlenet::SelectGameAccount] Temporarily banned account %s tried to login!", _socket.getRemoteAddress().c_str(), _socket.getRemotePort(), _accountName.c_str()); + TC_LOG_DEBUG("server.battlenet", "'%s:%d' [Battlenet::SelectGameAccount] Temporarily banned account %s tried to login!", GetRemoteAddress().c_str(), GetRemotePort(), _accountName.c_str()); } ReplaceResponse(response, complete); @@ -886,7 +896,7 @@ bool Battlenet::Socket::HandleSelectGameAccountModule(BitStream* dataStream, Ser return true; } -bool Battlenet::Socket::HandleRiskFingerprintModule(BitStream* dataStream, ServerPacket** response) +bool Battlenet::Session::HandleRiskFingerprintModule(BitStream* dataStream, ServerPacket** response) { AuthComplete* complete = new AuthComplete(); if (dataStream->Read<uint8>(8) == 1) @@ -901,7 +911,7 @@ bool Battlenet::Socket::HandleRiskFingerprintModule(BitStream* dataStream, Serve SQLTransaction trans = LoginDatabase.BeginTransaction(); PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_BNET_LAST_LOGIN_INFO); - stmt->setString(0, _socket.getRemoteAddress()); + stmt->setString(0, GetRemoteAddress()); stmt->setUInt8(1, GetLocaleByName(_locale)); stmt->setString(2, _os); stmt->setUInt32(3, _accountId); @@ -924,7 +934,7 @@ bool Battlenet::Socket::HandleRiskFingerprintModule(BitStream* dataStream, Serve return true; } -bool Battlenet::Socket::HandleResumeModule(BitStream* dataStream, ServerPacket** response) +bool Battlenet::Session::HandleResumeModule(BitStream* dataStream, ServerPacket** response) { if (dataStream->Read<uint8>(8) != 1) { @@ -937,10 +947,10 @@ bool Battlenet::Socket::HandleResumeModule(BitStream* dataStream, ServerPacket** static uint8 const ResumeClient = 0; static uint8 const ResumeServer = 1; - ACE_Auto_Array_Ptr<uint8>&& clientChallenge = dataStream->ReadBytes(16); - ACE_Auto_Array_Ptr<uint8>&& clientProof = dataStream->ReadBytes(32); - ACE_Auto_Array_Ptr<uint8>&& serverChallenge = _reconnectProof.AsByteArray(); - ACE_Auto_Array_Ptr<uint8>&& sessionKey = K.AsByteArray(); + std::unique_ptr<uint8[]> clientChallenge = dataStream->ReadBytes(16); + std::unique_ptr<uint8[]> clientProof = dataStream->ReadBytes(32); + std::unique_ptr<uint8[]> serverChallenge = _reconnectProof.AsByteArray(); + std::unique_ptr<uint8[]> sessionKey = K.AsByteArray(); HmacSha256 clientPart(64, sessionKey.get()); clientPart.UpdateData(&ResumeClient, 1); @@ -1005,7 +1015,7 @@ bool Battlenet::Socket::HandleResumeModule(BitStream* dataStream, ServerPacket** return true; } -bool Battlenet::Socket::UnhandledModule(BitStream* /*dataStream*/, ServerPacket** response) +bool Battlenet::Session::UnhandledModule(BitStream* /*dataStream*/, ServerPacket** response) { AuthComplete* complete = new AuthComplete(); complete->SetAuthResult(AUTH_CORRUPTED_MODULE); diff --git a/src/server/authserver/Server/BattlenetSocket.h b/src/server/authserver/Server/BattlenetSession.h index ee399e26b09..ef3e8ae9214 100644 --- a/src/server/authserver/Server/BattlenetSocket.h +++ b/src/server/authserver/Server/BattlenetSession.h @@ -18,12 +18,13 @@ #ifndef _BATTLENETSOCKET_H #define _BATTLENETSOCKET_H -#include "RealmSocket.h" #include "BattlenetPackets.h" #include "BattlenetPacketCrypt.h" #include "BigNumber.h" +#include <memory> +#include <boost/asio/ip/tcp.hpp> -class ACE_INET_Addr; +using boost::asio::ip::tcp; namespace Battlenet { @@ -42,15 +43,21 @@ namespace Battlenet MODULE_COUNT }; - class Socket : public RealmSocket::Session + enum class BufferSizes : uint32 + { + SRP_6_V = 0x80, + SRP_6_S = 0x20, + Read = 0x4000 + }; + + class Session : public std::enable_shared_from_this<Session> { public: - static uint32 const SRP6_V_Size; - static uint32 const SRP6_S_Size; - explicit Socket(RealmSocket& socket); + explicit Session(tcp::socket&& socket); + ~Session(); - typedef bool(Socket::*PacketHandler)(PacketHeader& socket, BitStream& packet); + typedef bool(Session::*PacketHandler)(PacketHeader& socket, BitStream& packet); // Auth bool HandleAuthChallenge(PacketHeader& header, BitStream& packet); @@ -66,16 +73,15 @@ namespace Battlenet bool HandleRealmUpdateSubscribe(PacketHeader& header, BitStream& packet); bool HandleRealmJoinRequest(PacketHeader& header, BitStream& packet); - void OnRead() override; - void OnAccept() override; - void OnClose() override; + void Start(); + void AsyncRead(); - void Send(ServerPacket& packet); + void AsyncWrite(ServerPacket* packet); private: void _SetVSFields(std::string const& rI); - typedef bool(Socket::*ModuleHandler)(BitStream* dataStream, ServerPacket** response); + typedef bool(Session::*ModuleHandler)(BitStream* dataStream, ServerPacket** response); static ModuleHandler const ModuleHandlers[MODULE_COUNT]; bool HandlePasswordModule(BitStream* dataStream, ServerPacket** response); @@ -84,7 +90,11 @@ namespace Battlenet bool HandleResumeModule(BitStream* dataStream, ServerPacket** response); bool UnhandledModule(BitStream* dataStream, ServerPacket** response); - RealmSocket& _socket; + std::string GetRemoteAddress() const { return _socket.remote_endpoint().address().to_string(); } + uint16 GetRemotePort() const { return _socket.remote_endpoint().port(); } + + tcp::socket _socket; + uint8 _readBuffer[BufferSizes::Read]; uint32 _accountId; std::string _accountName; diff --git a/src/server/game/Accounts/BattlenetAccountMgr.cpp b/src/server/game/Accounts/BattlenetAccountMgr.cpp index 5b419535c11..23c1b7cdd61 100644 --- a/src/server/game/Accounts/BattlenetAccountMgr.cpp +++ b/src/server/game/Accounts/BattlenetAccountMgr.cpp @@ -108,9 +108,8 @@ bool Battlenet::AccountMgr::CheckPassword(uint32 accountId, std::string password PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_BNET_CHECK_PASSWORD); stmt->setUInt32(0, accountId); stmt->setString(1, CalculateShaPassHash(username, password)); - PreparedQueryResult result = LoginDatabase.Query(stmt); - return !result.null(); + return LoginDatabase.Query(stmt) != nullptr; } std::string Battlenet::AccountMgr::CalculateShaPassHash(std::string const& name, std::string const& password) diff --git a/src/server/game/Accounts/BattlenetAccountMgr.h b/src/server/game/Accounts/BattlenetAccountMgr.h index 61bfd044b68..c41a54189e5 100644 --- a/src/server/game/Accounts/BattlenetAccountMgr.h +++ b/src/server/game/Accounts/BattlenetAccountMgr.h @@ -20,7 +20,6 @@ #include "Define.h" #include <string> -#include <ace/Singleton.h> enum class AccountOpResult : uint8; diff --git a/src/server/game/Entities/Item/Item.h b/src/server/game/Entities/Item/Item.h index 211b5beaf04..ebd66a64838 100644 --- a/src/server/game/Entities/Item/Item.h +++ b/src/server/game/Entities/Item/Item.h @@ -231,7 +231,7 @@ class Item : public Object void SetBinding(bool val) { ApplyModFlag(ITEM_FIELD_FLAGS, ITEM_FLAG_SOULBOUND, val); } bool IsSoulBound() const { return HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAG_SOULBOUND); } bool IsBoundAccountWide() const { return (GetTemplate()->Flags & ITEM_PROTO_FLAG_BIND_TO_ACCOUNT) != 0; } - bool IsBattlenetAccountBound() const { return GetTemplate()->Flags2 & ITEM_FLAGS_EXTRA_BNET_ACCOUNT_BOUND; } + bool IsBattlenetAccountBound() const { return (GetTemplate()->Flags2 & ITEM_FLAGS_EXTRA_BNET_ACCOUNT_BOUND) != 0; } bool IsBindedNotWith(Player const* player) const; bool IsBoundByEnchant() const; virtual void SaveToDB(SQLTransaction& trans); diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index c4a6e1e473b..14149d7ca84 100644 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -8320,7 +8320,7 @@ void Player::_ApplyWeaponDamage(uint8 slot, ItemTemplate const* proto, ScalingSt if (ssv) { float damageMultiplier = 0.0f; - extraDPS = ssv->GetDPSAndDamageMultiplier(proto->SubClass, proto->Flags2 & ITEM_FLAGS_EXTRA_CASTER_WEAPON, &damageMultiplier); + extraDPS = ssv->GetDPSAndDamageMultiplier(proto->SubClass, (proto->Flags2 & ITEM_FLAGS_EXTRA_CASTER_WEAPON) != 0, &damageMultiplier); if (extraDPS) { float average = extraDPS * proto->Delay / 1000.0f; diff --git a/src/server/game/Entities/Player/Player.h b/src/server/game/Entities/Player/Player.h index 9d1dbcc9215..ef65558e13c 100644 --- a/src/server/game/Entities/Player/Player.h +++ b/src/server/game/Entities/Player/Player.h @@ -1663,8 +1663,8 @@ class Player : public Unit, public GridObject<Player> static bool LoadPositionFromDB(uint32& mapid, float& x, float& y, float& z, float& o, bool& in_flight, uint64 guid); static bool IsValidGender(uint8 Gender) { return Gender <= GENDER_FEMALE; } - static bool IsValidClass(uint8 Class) { return (1 << (Class - 1)) & CLASSMASK_ALL_PLAYABLE; } - static bool IsValidRace(uint8 Race) { return (1 << (Race - 1)) & RACEMASK_ALL_PLAYABLE; } + static bool IsValidClass(uint8 Class) { return ((1 << (Class - 1)) & CLASSMASK_ALL_PLAYABLE) != 0; } + static bool IsValidRace(uint8 Race) { return ((1 << (Race - 1)) & RACEMASK_ALL_PLAYABLE) != 0; } /*********************************************************/ /*** SAVE SYSTEM ***/ diff --git a/src/server/scripts/Spells/spell_dk.cpp b/src/server/scripts/Spells/spell_dk.cpp index 299be87833e..b75f5091ec2 100644 --- a/src/server/scripts/Spells/spell_dk.cpp +++ b/src/server/scripts/Spells/spell_dk.cpp @@ -619,7 +619,7 @@ class spell_dk_death_strike_enabler : public SpellScriptLoader bool CheckProc(ProcEventInfo& eventInfo) { - return eventInfo.GetDamageInfo(); + return eventInfo.GetDamageInfo() != nullptr; } void HandleProc(AuraEffect const* /*aurEff*/, ProcEventInfo& eventInfo) diff --git a/src/server/scripts/Spells/spell_mage.cpp b/src/server/scripts/Spells/spell_mage.cpp index a7a13b48d39..f72f6435b0c 100644 --- a/src/server/scripts/Spells/spell_mage.cpp +++ b/src/server/scripts/Spells/spell_mage.cpp @@ -825,7 +825,7 @@ class spell_mage_ignite : public SpellScriptLoader bool CheckProc(ProcEventInfo& eventInfo) { - return eventInfo.GetProcTarget(); + return eventInfo.GetProcTarget() != nullptr; } void HandleProc(AuraEffect const* aurEff, ProcEventInfo& eventInfo) diff --git a/src/server/scripts/Spells/spell_shaman.cpp b/src/server/scripts/Spells/spell_shaman.cpp index 94c304bf82e..486eec6f4df 100644 --- a/src/server/scripts/Spells/spell_shaman.cpp +++ b/src/server/scripts/Spells/spell_shaman.cpp @@ -648,7 +648,7 @@ class spell_sha_healing_stream_totem : public SpellScriptLoader bool Validate(SpellInfo const* /*spellInfo*/) override { - return sSpellMgr->GetSpellInfo(SPELL_SHAMAN_TOTEM_HEALING_STREAM_HEAL); + return sSpellMgr->GetSpellInfo(SPELL_SHAMAN_TOTEM_HEALING_STREAM_HEAL) != nullptr; } void HandleDummy(SpellEffIndex /* effIndex */) |