From fea9d275fa0ed8f5b43dc54979cdd5a58afc993b Mon Sep 17 00:00:00 2001 From: Shauren Date: Wed, 30 Apr 2014 23:02:01 +0200 Subject: Verify received components --- src/server/authserver/Server/BattlenetManager.cpp | 61 +++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/server/authserver/Server/BattlenetManager.cpp (limited to 'src/server/authserver/Server/BattlenetManager.cpp') diff --git a/src/server/authserver/Server/BattlenetManager.cpp b/src/server/authserver/Server/BattlenetManager.cpp new file mode 100644 index 00000000000..b7df889809e --- /dev/null +++ b/src/server/authserver/Server/BattlenetManager.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2008-2014 TrinityCore + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#include "BattlenetManager.h" +#include "DatabaseEnv.h" + +void BattlenetMgr::Load() +{ + LoadComponents(); + LoadModules(); +} + +void BattlenetMgr::LoadComponents() +{ + QueryResult result = LoginDatabase.Query("SELECT Program, Platform, Build FROM battlenet_components"); + if (result) + { + do + { + Field* fields = result->Fetch(); + Battlenet::Component* component = new Battlenet::Component(); + component->Program = fields[0].GetString(); + component->Platform = fields[1].GetString(); + component->Build = fields[2].GetUInt32(); + + _components.insert(component); + _programs.insert(component->Program); + _platforms.insert(component->Platform); + _builds.insert(component->Build); + + } while (result->NextRow()); + } +} + +void BattlenetMgr::LoadModules() +{ + +} + +bool BattlenetMgr::HasComponent(Battlenet::Component const* component) const +{ + for (Battlenet::Component const* c : _components) + if (component->Program == c->Program && component->Platform == c->Platform && component->Build == c->Build) + return true; + + return false; +} -- cgit v1.2.3 From 6955d7c9ad0e55480aa97d9cafd878c6bc3dc426 Mon Sep 17 00:00:00 2001 From: Shauren Date: Fri, 2 May 2014 02:55:10 +0200 Subject: Core/Battle.net * Fixed AuthResult codes * Fixed BitStream::WriteBytes size check * Fixed comparison operator for packet header * Fixed channel for client packets without channel * Implemented loading modules from database --- src/server/authserver/Authentication/AuthCodes.h | 9 +++-- src/server/authserver/Server/BattlenetBitStream.h | 12 +++++- src/server/authserver/Server/BattlenetManager.cpp | 38 +++++++++++++++++- src/server/authserver/Server/BattlenetManager.h | 47 +++++++++++++++++++++-- src/server/authserver/Server/BattlenetPackets.cpp | 33 ++++++++-------- src/server/authserver/Server/BattlenetPackets.h | 18 ++++----- src/server/authserver/Server/BattlenetSocket.cpp | 34 ++++++++++++++-- src/server/authserver/Server/BattlenetSocket.h | 2 + src/server/shared/Utilities/Util.cpp | 25 ++++++++++++ src/server/shared/Utilities/Util.h | 1 + 10 files changed, 179 insertions(+), 40 deletions(-) (limited to 'src/server/authserver/Server/BattlenetManager.cpp') diff --git a/src/server/authserver/Authentication/AuthCodes.h b/src/server/authserver/Authentication/AuthCodes.h index e844863e4b1..12c2a810abb 100644 --- a/src/server/authserver/Authentication/AuthCodes.h +++ b/src/server/authserver/Authentication/AuthCodes.h @@ -97,7 +97,10 @@ namespace Battlenet AUTH_BATTLENET_MAINTENANCE = 122, AUTH_LOGON_TOO_FAST = 123, AUTH_USE_GRUNT_LOGON = 124, + AUTH_NO_GAME_ACCOUNTS_IN_REGION = 140, + AUTH_ACCOUNT_LOCKED = 141, + LOGIN_SERVER_BUSY = 200, LOGIN_NO_GAME_ACCOUNT = 201, LOGIN_BANNED = 202, LOGIN_SUSPENDED = 203, @@ -110,9 +113,9 @@ namespace Battlenet LOGIN_TRIAL_EXPIRED = 210, LOGIN_ANTI_INDULGENCE = 211, LOGIN_INCORRECT_REGION = 212, - LOGIN_CHARGEBACK = 213, - LOGIN_IGR_WITHOUT_BNET = 214, - LOGIN_LOCKED_ENFORCED = 215, + LOGIN_LOCKED_ENFORCED = 213, + LOGIN_CHARGEBACK = 214, + LOGIN_IGR_WITHOUT_BNET = 215, LOGIN_UNLOCKABLE_LOCK = 216, LOGIN_IGR_REQUIRED = 217, LOGIN_PAYMENT_CHANGED = 218, diff --git a/src/server/authserver/Server/BattlenetBitStream.h b/src/server/authserver/Server/BattlenetBitStream.h index 4b6c7f882d4..d372e0933c2 100644 --- a/src/server/authserver/Server/BattlenetBitStream.h +++ b/src/server/authserver/Server/BattlenetBitStream.h @@ -22,16 +22,21 @@ #include #include #include +#include namespace Battlenet { class BitStreamPositionException : public std::exception { public: + BitStreamPositionException() : st(1) { } + char const* what() const { - return ""; + return st.c_str(); } + + ACE_Stack_Trace st; }; class BitStream @@ -121,7 +126,10 @@ namespace Battlenet void WriteBytes(T* data, uint32 count) { AlignToNextByte(); - if (_writePos + 8 * count > MaxSize) + if (!count || !data) + return; + + if (_writePos + count > MaxSize) throw BitStreamPositionException(); _buffer.resize(_buffer.size() + count); diff --git a/src/server/authserver/Server/BattlenetManager.cpp b/src/server/authserver/Server/BattlenetManager.cpp index b7df889809e..a43512e612e 100644 --- a/src/server/authserver/Server/BattlenetManager.cpp +++ b/src/server/authserver/Server/BattlenetManager.cpp @@ -18,6 +18,15 @@ #include "BattlenetManager.h" #include "DatabaseEnv.h" +BattlenetMgr::~BattlenetMgr() +{ + for (Battlenet::Component* component : _components) + delete component; + + for (auto const& m : _modules) + delete m.second; +} + void BattlenetMgr::Load() { LoadComponents(); @@ -40,7 +49,6 @@ void BattlenetMgr::LoadComponents() _components.insert(component); _programs.insert(component->Program); _platforms.insert(component->Platform); - _builds.insert(component->Build); } while (result->NextRow()); } @@ -48,7 +56,27 @@ void BattlenetMgr::LoadComponents() void BattlenetMgr::LoadModules() { + QueryResult result = LoginDatabase.Query("SELECT `Hash`, `Name`, `Type`, `System`, `Data` FROM battlenet_modules"); + if (result) + { + do + { + Field* fields = result->Fetch(); + Battlenet::ModuleInfo* module = new Battlenet::ModuleInfo(); + module->Type = fields[2].GetString(); + module->Region.assign("\0\0EU", 4); + HexStrToByteArray(fields[0].GetString(), module->ModuleId); + std::string data = fields[4].GetString(); + module->DataSize = data.length() / 2; + if (module->DataSize) + { + module->Data = new uint8[data.length() / 2]; + HexStrToByteArray(data, module->Data); + } + _modules[{ fields[3].GetString(), fields[1].GetString() }] = module; + } while (result->NextRow()); + } } bool BattlenetMgr::HasComponent(Battlenet::Component const* component) const @@ -59,3 +87,11 @@ bool BattlenetMgr::HasComponent(Battlenet::Component const* component) const return false; } + +Battlenet::ModuleInfo const* BattlenetMgr::GetModule(Battlenet::ModuleKey const& key) const +{ + if (_modules.count(key)) + return _modules.at(key); + + return NULL; +} diff --git a/src/server/authserver/Server/BattlenetManager.h b/src/server/authserver/Server/BattlenetManager.h index d3962a32c0d..9fceb973770 100644 --- a/src/server/authserver/Server/BattlenetManager.h +++ b/src/server/authserver/Server/BattlenetManager.h @@ -32,20 +32,61 @@ namespace Battlenet std::string Platform; uint32 Build; }; + + struct ModuleKey + { + std::string Platform; + std::string Name; + + bool operator<(ModuleKey const& right) const + { + int32 res = Platform.compare(right.Platform); + if (res < 0) + return true; + else if (res > 0) + return false; + + return Name < right.Name; + } + }; + + struct ModuleInfo + { + ModuleInfo() : DataSize(0), Data(nullptr) { } + ModuleInfo(ModuleInfo const& right) : Type(right.Type), Region(right.Region), DataSize(right.DataSize), Data(nullptr) + { + memcpy(ModuleId, right.ModuleId, 32); + if (DataSize) + { + Data = new uint8[DataSize]; + memcpy(Data, right.Data, DataSize); + } + } + ~ModuleInfo() + { + delete Data; + } + + std::string Type; + std::string Region; + uint8 ModuleId[32]; + uint32 DataSize; + uint8* Data; + }; } class BattlenetMgr { friend class ACE_Singleton; BattlenetMgr() { } - ~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 HasBuild(uint32 build) const { return _builds.count(build); } + Battlenet::ModuleInfo const* GetModule(Battlenet::ModuleKey const& key) const; private: void LoadComponents(); @@ -54,7 +95,7 @@ private: std::set _components; std::set _programs; std::set _platforms; - std::set _builds; + std::map _modules; }; #define sBattlenetMgr ACE_Singleton::instance() diff --git a/src/server/authserver/Server/BattlenetPackets.cpp b/src/server/authserver/Server/BattlenetPackets.cpp index 80213a0ba33..68a602d8598 100644 --- a/src/server/authserver/Server/BattlenetPackets.cpp +++ b/src/server/authserver/Server/BattlenetPackets.cpp @@ -78,14 +78,13 @@ std::string Battlenet::AuthChallenge::ToString() const void Battlenet::ProofRequest::Write() { _stream.Write(Modules.size(), 3); - for (size_t i = 0; i < Modules.size(); ++i) + for (ModuleInfo const* info : Modules) { - ModuleInfo& info = Modules[i]; - _stream.WriteBytes(info.AuthString.c_str(), 4); - _stream.WriteFourCC(info.Locale.c_str()); - _stream.WriteBytes(info.ModuleId, 32); - _stream.Write(info.BlobSize, 10); - _stream.WriteBytes(info.Blob, info.BlobSize); + _stream.WriteBytes(info->Type.c_str(), 4); + _stream.WriteFourCC(info->Region.c_str()); + _stream.WriteBytes(info->ModuleId, 32); + _stream.Write(info->DataSize, 10); + _stream.WriteBytes(info->Data, info->DataSize); } } @@ -93,8 +92,8 @@ std::string Battlenet::ProofRequest::ToString() const { std::ostringstream stream; stream << "Battlenet::ProofRequest modules " << Modules.size(); - for (ModuleInfo const& module : Modules) - stream << std::endl << "Locale " << module.Locale << "ModuleId " << ByteArrayToHexStr(module.ModuleId, 32) << "BlobSize " << module.BlobSize; + for (ModuleInfo const* module : Modules) + stream << std::endl << "Locale " << module->Region << "ModuleId " << ByteArrayToHexStr(module->ModuleId, 32) << "BlobSize " << module->DataSize; return stream.str(); } @@ -138,11 +137,11 @@ void Battlenet::AuthComplete::Write() for (size_t i = 0; i < Modules.size(); ++i) { ModuleInfo& info = Modules[i]; - _stream.WriteBytes(info.AuthString.c_str(), 4); - _stream.WriteFourCC(info.Locale.c_str()); + _stream.WriteBytes(info.Type.c_str(), 4); + _stream.WriteFourCC(info.Region.c_str()); _stream.WriteBytes(info.ModuleId, 32); - _stream.Write(info.BlobSize, 10); - _stream.WriteBytes(info.Blob, info.BlobSize); + _stream.Write(info.DataSize, 10); + _stream.WriteBytes(info.Data, info.DataSize); } _stream.Write(PingTimeout + std::numeric_limits::min(), 32); @@ -165,11 +164,11 @@ void Battlenet::AuthComplete::Write() if (!Modules.empty()) { ModuleInfo& info = Modules[0]; - _stream.WriteBytes(info.AuthString.c_str(), 4); - _stream.WriteFourCC(info.Locale.c_str()); + _stream.WriteBytes(info.Type.c_str(), 4); + _stream.WriteFourCC(info.Region.c_str()); _stream.WriteBytes(info.ModuleId, 32); - _stream.Write(info.BlobSize, 10); - _stream.WriteBytes(info.Blob, info.BlobSize); + _stream.Write(info.DataSize, 10); + _stream.WriteBytes(info.Data, info.DataSize); } _stream.Write(ErrorType, 2); diff --git a/src/server/authserver/Server/BattlenetPackets.h b/src/server/authserver/Server/BattlenetPackets.h index 86dcb99a4da..3b02c0c602a 100644 --- a/src/server/authserver/Server/BattlenetPackets.h +++ b/src/server/authserver/Server/BattlenetPackets.h @@ -58,7 +58,12 @@ namespace Battlenet bool operator<(PacketHeader const& right) const { - return Opcode < right.Opcode || Channel < right.Channel; + if (Opcode < right.Opcode) + return true; + if (Opcode > right.Opcode) + return false; + + return Channel < right.Channel; } bool operator==(PacketHeader const& right) const @@ -133,15 +138,6 @@ namespace Battlenet std::string Login; }; - struct ModuleInfo - { - std::string AuthString; - std::string Locale; - uint8 ModuleId[32]; - uint32 BlobSize; - uint8* Blob; - }; - class ProofRequest final : public ServerPacket { public: @@ -150,7 +146,7 @@ namespace Battlenet void Write() override; std::string ToString() const override; - std::vector Modules; + std::vector Modules; }; class ProofResponse final : public ClientPacket diff --git a/src/server/authserver/Server/BattlenetSocket.cpp b/src/server/authserver/Server/BattlenetSocket.cpp index 04005e30878..edd73080270 100644 --- a/src/server/authserver/Server/BattlenetSocket.cpp +++ b/src/server/authserver/Server/BattlenetSocket.cpp @@ -25,6 +25,32 @@ bool Battlenet::Socket::HandleAuthChallenge(PacketHeader& header, BitStream& pac AuthChallenge info(header, packet); info.Read(); + printf("%s\n", info.ToString().c_str()); + + if (info.Program != "WoW") + { + AuthComplete complete; + complete.SetAuthResult(AUTH_INVALID_PROGRAM); + Send(complete); + return true; + } + + if (!sBattlenetMgr->HasPlatform(info.Platform)) + { + AuthComplete complete; + complete.SetAuthResult(AUTH_INVALID_OS); + Send(complete); + return true; + } + + if (!sBattlenetMgr->HasPlatform(info.Locale)) + { + AuthComplete complete; + complete.SetAuthResult(AUTH_UNSUPPORTED_LANGUAGE); + Send(complete); + return true; + } + for (Component const& component : info.Components) { if (!sBattlenetMgr->HasComponent(&component)) @@ -34,7 +60,7 @@ bool Battlenet::Socket::HandleAuthChallenge(PacketHeader& header, BitStream& pac complete.SetAuthResult(AUTH_INVALID_PROGRAM); else if (!sBattlenetMgr->HasPlatform(component.Platform)) complete.SetAuthResult(AUTH_INVALID_OS); - else if (!sBattlenetMgr->HasBuild(component.Build)) + else complete.SetAuthResult(AUTH_REGION_BAD_VERSION); Send(complete); @@ -42,9 +68,9 @@ bool Battlenet::Socket::HandleAuthChallenge(PacketHeader& header, BitStream& pac } } - printf("%s\n", info.ToString().c_str()); - _accountName = info.Login; + _locale = info.Locale; + _os = info.Platform; ProofRequest request; Send(request); @@ -101,6 +127,8 @@ void Battlenet::Socket::OnRead() header.Opcode = packet.Read(6); if (packet.Read(1)) _currentChannel = header.Channel = packet.Read(4); + else + header.Channel = _currentChannel; printf("Battlenet::Socket::OnRead %s\n", header.ToString().c_str()); std::map::const_iterator itr = Handlers.find(header); diff --git a/src/server/authserver/Server/BattlenetSocket.h b/src/server/authserver/Server/BattlenetSocket.h index 7507f090a7f..b4db6c46251 100644 --- a/src/server/authserver/Server/BattlenetSocket.h +++ b/src/server/authserver/Server/BattlenetSocket.h @@ -48,6 +48,8 @@ namespace Battlenet uint32 _currentChannel; std::string _accountName; + std::string _locale; + std::string _os; PacketCrypt _crypt; }; diff --git a/src/server/shared/Utilities/Util.cpp b/src/server/shared/Utilities/Util.cpp index f2a6f1b7622..004335422c0 100644 --- a/src/server/shared/Utilities/Util.cpp +++ b/src/server/shared/Utilities/Util.cpp @@ -547,3 +547,28 @@ std::string ByteArrayToHexStr(uint8 const* bytes, uint32 arrayLen, bool reverse return ss.str(); } + +void HexStrToByteArray(std::string const& str, uint8* out, bool reverse /*= false*/) +{ + // string must have even number of characters + if (str.length() & 1) + return; + + int32 init = 0; + int32 end = str.length(); + int8 op = 1; + + if (reverse) + { + init = str.length() - 2; + end = -1; + op = -1; + } + + uint32 j = 0; + for (int32 i = init; i != end; i += 2 * op) + { + char buffer[3] = { str[i], str[i + 1], '\0' }; + out[j++] = strtoul(buffer, NULL, 16); + } +} diff --git a/src/server/shared/Utilities/Util.h b/src/server/shared/Utilities/Util.h index 236670e5cf1..d1cfeadff64 100644 --- a/src/server/shared/Utilities/Util.h +++ b/src/server/shared/Utilities/Util.h @@ -355,6 +355,7 @@ std::string GetAddressString(ACE_INET_Addr const& addr); uint32 CreatePIDFile(const std::string& filename); std::string ByteArrayToHexStr(uint8 const* bytes, uint32 length, bool reverse = false); +void HexStrToByteArray(std::string const& str, uint8* out, bool reverse = false); #endif //handler for operations on large flags -- cgit v1.2.3 From 2654fd67f32ef8b10cb0f9fcdc5033de62ca9a78 Mon Sep 17 00:00:00 2001 From: Shauren Date: Fri, 2 May 2014 13:30:41 +0200 Subject: Core/Battle.net: Refactored FCC writing --- src/server/authserver/Server/BattlenetBitStream.h | 9 +++++++-- src/server/authserver/Server/BattlenetManager.cpp | 1 - src/server/authserver/Server/BattlenetManager.h | 2 +- src/server/authserver/Server/BattlenetPackets.cpp | 10 +++++----- 4 files changed, 13 insertions(+), 9 deletions(-) (limited to 'src/server/authserver/Server/BattlenetManager.cpp') diff --git a/src/server/authserver/Server/BattlenetBitStream.h b/src/server/authserver/Server/BattlenetBitStream.h index d372e0933c2..9d5f4c85f0d 100644 --- a/src/server/authserver/Server/BattlenetBitStream.h +++ b/src/server/authserver/Server/BattlenetBitStream.h @@ -138,10 +138,15 @@ namespace Battlenet } //WriteFloat - void WriteFourCC(char const* fcc) + void WriteFourCC(std::string const& fcc) { - uint32 intVal = *(uint32*)fcc; + uint32 intVal = *(uint32*)fcc.c_str(); + size_t len = fcc.length(); EndianConvertReverse(intVal); + // Add padding + while (len++ < 4) + intVal >>= 8; + Write(intVal, 32); } diff --git a/src/server/authserver/Server/BattlenetManager.cpp b/src/server/authserver/Server/BattlenetManager.cpp index a43512e612e..f8ff5d8989e 100644 --- a/src/server/authserver/Server/BattlenetManager.cpp +++ b/src/server/authserver/Server/BattlenetManager.cpp @@ -64,7 +64,6 @@ void BattlenetMgr::LoadModules() Field* fields = result->Fetch(); Battlenet::ModuleInfo* module = new Battlenet::ModuleInfo(); module->Type = fields[2].GetString(); - module->Region.assign("\0\0EU", 4); HexStrToByteArray(fields[0].GetString(), module->ModuleId); std::string data = fields[4].GetString(); module->DataSize = data.length() / 2; diff --git a/src/server/authserver/Server/BattlenetManager.h b/src/server/authserver/Server/BattlenetManager.h index 9fceb973770..08c98645ebd 100644 --- a/src/server/authserver/Server/BattlenetManager.h +++ b/src/server/authserver/Server/BattlenetManager.h @@ -52,7 +52,7 @@ namespace Battlenet struct ModuleInfo { - ModuleInfo() : DataSize(0), Data(nullptr) { } + ModuleInfo() : Region("EU"), DataSize(0), Data(nullptr) { } ModuleInfo(ModuleInfo const& right) : Type(right.Type), Region(right.Region), DataSize(right.DataSize), Data(nullptr) { memcpy(ModuleId, right.ModuleId, 32); diff --git a/src/server/authserver/Server/BattlenetPackets.cpp b/src/server/authserver/Server/BattlenetPackets.cpp index 68a602d8598..bcb4f4e4898 100644 --- a/src/server/authserver/Server/BattlenetPackets.cpp +++ b/src/server/authserver/Server/BattlenetPackets.cpp @@ -67,7 +67,7 @@ std::string Battlenet::AuthChallenge::ToString() const std::ostringstream stream; stream << "Battlenet::AuthChallenge Program: " << Program << ", Platform: " << Platform << ", Locale: " << Locale; for (Component const& component : Components) - stream << std::endl << "Battlenet::AuthChallenge::Component Program: " << component.Program << ", Platform: " << component.Platform << ", Build: " << component.Build; + stream << std::endl << "Battlenet::Component Program: " << component.Program << ", Platform: " << component.Platform << ", Build: " << component.Build; if (!Login.empty()) stream << std::endl << "Battlenet::AuthChallenge Login: " << Login; @@ -81,7 +81,7 @@ void Battlenet::ProofRequest::Write() for (ModuleInfo const* info : Modules) { _stream.WriteBytes(info->Type.c_str(), 4); - _stream.WriteFourCC(info->Region.c_str()); + _stream.WriteFourCC(info->Region); _stream.WriteBytes(info->ModuleId, 32); _stream.Write(info->DataSize, 10); _stream.WriteBytes(info->Data, info->DataSize); @@ -93,7 +93,7 @@ std::string Battlenet::ProofRequest::ToString() const std::ostringstream stream; stream << "Battlenet::ProofRequest modules " << Modules.size(); for (ModuleInfo const* module : Modules) - stream << std::endl << "Locale " << module->Region << "ModuleId " << ByteArrayToHexStr(module->ModuleId, 32) << "BlobSize " << module->DataSize; + stream << std::endl << "Battlenet::ModuleInfo Locale " << module->Region.c_str() << ", ModuleId " << ByteArrayToHexStr(module->ModuleId, 32) << ", BlobSize " << module->DataSize; return stream.str(); } @@ -138,7 +138,7 @@ void Battlenet::AuthComplete::Write() { ModuleInfo& info = Modules[i]; _stream.WriteBytes(info.Type.c_str(), 4); - _stream.WriteFourCC(info.Region.c_str()); + _stream.WriteFourCC(info.Region); _stream.WriteBytes(info.ModuleId, 32); _stream.Write(info.DataSize, 10); _stream.WriteBytes(info.Data, info.DataSize); @@ -165,7 +165,7 @@ void Battlenet::AuthComplete::Write() { ModuleInfo& info = Modules[0]; _stream.WriteBytes(info.Type.c_str(), 4); - _stream.WriteFourCC(info.Region.c_str()); + _stream.WriteFourCC(info.Region); _stream.WriteBytes(info.ModuleId, 32); _stream.Write(info.DataSize, 10); _stream.WriteBytes(info.Data, info.DataSize); -- cgit v1.2.3 From db2cb70120dde10ffa210ad5af8a973cc1644355 Mon Sep 17 00:00:00 2001 From: Shauren Date: Sun, 1 Jun 2014 02:39:55 +0200 Subject: Core/Battle.net: Refactored ModuleInfo creation --- src/server/authserver/Server/BattlenetManager.cpp | 8 +++---- src/server/authserver/Server/BattlenetManager.h | 2 +- src/server/authserver/Server/BattlenetSocket.cpp | 26 +++++++++++------------ 3 files changed, 17 insertions(+), 19 deletions(-) (limited to 'src/server/authserver/Server/BattlenetManager.cpp') diff --git a/src/server/authserver/Server/BattlenetManager.cpp b/src/server/authserver/Server/BattlenetManager.cpp index f8ff5d8989e..f470c365b56 100644 --- a/src/server/authserver/Server/BattlenetManager.cpp +++ b/src/server/authserver/Server/BattlenetManager.cpp @@ -87,10 +87,10 @@ bool BattlenetMgr::HasComponent(Battlenet::Component const* component) const return false; } -Battlenet::ModuleInfo const* BattlenetMgr::GetModule(Battlenet::ModuleKey const& key) const +Battlenet::ModuleInfo* BattlenetMgr::CreateModule(std::string const& os, std::string const& name) const { - if (_modules.count(key)) - return _modules.at(key); + Battlenet::ModuleKey key { os, name }; + ASSERT(_modules.count(key)); - return NULL; + return new Battlenet::ModuleInfo(*_modules.at(key)); } diff --git a/src/server/authserver/Server/BattlenetManager.h b/src/server/authserver/Server/BattlenetManager.h index 7bc12f94c62..3b8a145f4e9 100644 --- a/src/server/authserver/Server/BattlenetManager.h +++ b/src/server/authserver/Server/BattlenetManager.h @@ -94,7 +94,7 @@ public: 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); } - Battlenet::ModuleInfo const* GetModule(Battlenet::ModuleKey const& key) const; + Battlenet::ModuleInfo* CreateModule(std::string const& os, std::string const& name) const; private: void LoadComponents(); diff --git a/src/server/authserver/Server/BattlenetSocket.cpp b/src/server/authserver/Server/BattlenetSocket.cpp index ad589507a14..12b02b5963e 100644 --- a/src/server/authserver/Server/BattlenetSocket.cpp +++ b/src/server/authserver/Server/BattlenetSocket.cpp @@ -286,8 +286,8 @@ bool Battlenet::Socket::HandleAuthChallenge(PacketHeader& header, BitStream& pac I.SetBinary(sha.GetDigest(), sha.GetLength()); - ModuleInfo* password = new ModuleInfo(*sBattlenetMgr->GetModule({ _os, "Password" })); - ModuleInfo* thumbprint = new ModuleInfo(*sBattlenetMgr->GetModule({ _os, "Thumbprint" })); + ModuleInfo* password = sBattlenetMgr->CreateModule(_os, "Password"); + ModuleInfo* thumbprint = sBattlenetMgr->CreateModule(_os, "Thumbprint"); std::string pStr = fields[0].GetString(); @@ -367,11 +367,10 @@ bool Battlenet::Socket::HandlePing(PacketHeader& /*header*/, BitStream& /*packet return true; } -bool Battlenet::Socket::HandleEnableEncryption(PacketHeader& /*header*/, BitStream& packet) +bool Battlenet::Socket::HandleEnableEncryption(PacketHeader& /*header*/, BitStream& /*packet*/) { _crypt.Init(&K); - _crypt.DecryptRecv(packet.GetBuffer() + 2, packet.GetSize() - 2); - return false; + return true; } bool Battlenet::Socket::HandleRealmUpdateSubscribe(PacketHeader& /*header*/, BitStream& /*packet*/) @@ -691,7 +690,7 @@ bool Battlenet::Socket::HandlePasswordModule(BitStream* dataStream, ServerPacket M.SetBinary(sha.GetDigest(), sha.GetLength()); BitStream stream; - ModuleInfo* password = new ModuleInfo(*sBattlenetMgr->GetModule({ _os, "Password" })); + ModuleInfo* password = sBattlenetMgr->CreateModule(_os, "Password"); uint8 state = 3; stream.WriteBytes(&state, 1); @@ -717,7 +716,7 @@ bool Battlenet::Socket::HandlePasswordModule(BitStream* dataStream, ServerPacket accounts.WriteString(fields[0].GetString(), 8); } while (result->NextRow()); - ModuleInfo* selectGameAccount = new ModuleInfo(*sBattlenetMgr->GetModule({ _os, "SelectGameAccount" })); + ModuleInfo* selectGameAccount = sBattlenetMgr->CreateModule(_os, "SelectGameAccount"); selectGameAccount->DataSize = accounts.GetSize(); selectGameAccount->Data = new uint8[selectGameAccount->DataSize]; memcpy(selectGameAccount->Data, accounts.GetBuffer(), selectGameAccount->DataSize); @@ -743,17 +742,16 @@ bool Battlenet::Socket::HandlePasswordModule(BitStream* dataStream, ServerPacket } ReplaceResponse(response, complete); - return true; + return false; } _gameAccountId = (*result)[1].GetUInt32(); - request->Modules.push_back(new ModuleInfo(*sBattlenetMgr->GetModule({ _os, "RiskFingerprint" }))); + request->Modules.push_back(sBattlenetMgr->CreateModule(_os, "RiskFingerprint")); _modulesWaitingForData.push(MODULE_RISK_FINGERPRINT); } ReplaceResponse(response, request); - return true; } @@ -789,22 +787,22 @@ 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::AuthChallenge] 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!", _socket.getRemoteAddress().c_str(), _socket.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::SelectGameAccount] Temporarily banned account %s tried to login!", _socket.getRemoteAddress().c_str(), _socket.getRemotePort(), _accountName.c_str()); } ReplaceResponse(response, complete); - return true; + return false; } _gameAccountId = fields[0].GetUInt32(); ProofRequest* request = new ProofRequest(); - request->Modules.push_back(new ModuleInfo(*sBattlenetMgr->GetModule({ _os, "RiskFingerprint" }))); + request->Modules.push_back(sBattlenetMgr->CreateModule(_os, "RiskFingerprint")); ReplaceResponse(response, request); _modulesWaitingForData.push(MODULE_RISK_FINGERPRINT); -- cgit v1.2.3