diff options
| -rw-r--r-- | src/server/authserver/Main.cpp | 2 | ||||
| -rw-r--r-- | src/server/authserver/Server/BattlenetBitStream.h | 2 | ||||
| -rw-r--r-- | src/server/authserver/Server/BattlenetManager.cpp | 61 | ||||
| -rw-r--r-- | src/server/authserver/Server/BattlenetManager.h | 62 | ||||
| -rw-r--r-- | src/server/authserver/Server/BattlenetPackets.cpp | 43 | ||||
| -rw-r--r-- | src/server/authserver/Server/BattlenetPackets.h | 20 | ||||
| -rw-r--r-- | src/server/authserver/Server/BattlenetSocket.cpp | 36 | ||||
| -rw-r--r-- | src/server/authserver/Server/BattlenetSocket.h | 3 | 
8 files changed, 202 insertions, 27 deletions
diff --git a/src/server/authserver/Main.cpp b/src/server/authserver/Main.cpp index 0e23dd99ba8..be2e6a11d4f 100644 --- a/src/server/authserver/Main.cpp +++ b/src/server/authserver/Main.cpp @@ -254,6 +254,8 @@ extern int main(int argc, char** argv)  #endif  #endif +    sBattlenetMgr->Load(); +      // maximum counter for next ping      uint32 numLoops = (sConfigMgr->GetIntDefault("MaxPingTime", 30) * (MINUTE * 1000000 / 100000));      uint32 loopCounter = 0; diff --git a/src/server/authserver/Server/BattlenetBitStream.h b/src/server/authserver/Server/BattlenetBitStream.h index fa09b24b204..4b6c7f882d4 100644 --- a/src/server/authserver/Server/BattlenetBitStream.h +++ b/src/server/authserver/Server/BattlenetBitStream.h @@ -178,6 +178,8 @@ namespace Battlenet          size_t GetSize() const { return _buffer.size(); } +        void FinishReading() { _readPos = _numBits; } +      private:          std::vector<uint8> _buffer;          uint32 _numBits; 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 <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 "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; +} diff --git a/src/server/authserver/Server/BattlenetManager.h b/src/server/authserver/Server/BattlenetManager.h new file mode 100644 index 00000000000..d3962a32c0d --- /dev/null +++ b/src/server/authserver/Server/BattlenetManager.h @@ -0,0 +1,62 @@ +/* + * 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/>. + */ + +#ifndef __BATTLENETMANAGER_H__ +#define __BATTLENETMANAGER_H__ + +#include "Define.h" +#include <ace/Singleton.h> +#include <string> +#include <set> +#include <map> + +namespace Battlenet +{ +    struct Component +    { +        std::string Program; +        std::string Platform; +        uint32 Build; +    }; +} + +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 HasBuild(uint32 build) const { return _builds.count(build); } + +private: +    void LoadComponents(); +    void LoadModules(); + +    std::set<Battlenet::Component*> _components; +    std::set<std::string> _programs; +    std::set<std::string> _platforms; +    std::set<uint32> _builds; +}; + +#define sBattlenetMgr ACE_Singleton<BattlenetMgr, ACE_Null_Mutex>::instance() + +#endif // __BATTLENETMANAGER_H__ diff --git a/src/server/authserver/Server/BattlenetPackets.cpp b/src/server/authserver/Server/BattlenetPackets.cpp index 37040fa6d6e..80213a0ba33 100644 --- a/src/server/authserver/Server/BattlenetPackets.cpp +++ b/src/server/authserver/Server/BattlenetPackets.cpp @@ -15,9 +15,8 @@   * with this program. If not, see <http://www.gnu.org/licenses/>.   */ -#include "Common.h" -#include "BattlenetBitStream.h"  #include "BattlenetPackets.h" +#include "Common.h"  #include "Util.h"  #include <limits>  #include <sstream> @@ -58,14 +57,17 @@ void Battlenet::AuthChallenge::Read()      if (_stream.Read<uint32>(1))          Login = _stream.ReadString(9, 3); + +    if (GetHeader().Opcode == CMSG_AUTH_CHALLENGE_NEW) +        _stream.FinishReading();  }  std::string Battlenet::AuthChallenge::ToString() const  {      std::ostringstream stream;      stream << "Battlenet::AuthChallenge Program: " << Program << ", Platform: " << Platform << ", Locale: " << Locale; -    for (uint32 i = 0; i < Components.size(); ++i) -        stream << std::endl << "Battlenet::AuthChallenge::Component Program: " << Components[i].Program << ", Platform: " << Components[i].Platform << ", Build: " << Components[i].Build; +    for (Component const& component : Components) +        stream << std::endl << "Battlenet::AuthChallenge::Component Program: " << component.Program << ", Platform: " << component.Platform << ", Build: " << component.Build;      if (!Login.empty())          stream << std::endl << "Battlenet::AuthChallenge Login: " << Login; @@ -87,6 +89,16 @@ void Battlenet::ProofRequest::Write()      }  } +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; + +    return stream.str(); +} +  Battlenet::ProofResponse::~ProofResponse()  {      for (size_t i = 0; i < Modules.size(); ++i) @@ -108,10 +120,10 @@ std::string Battlenet::ProofResponse::ToString() const  {      std::ostringstream stream;      stream << "Battlenet::ProofResponse Modules " << Modules.size(); -    for (size_t i = 0; i < Modules.size(); ++i) +    for (ModuleData const& module : Modules)      { -        std::string hexStr = ByteArrayToHexStr(Modules[i].Data, Modules[i].Size); -        stream << std::endl << "Battlenet::ProofResponse::ModuleData Size: " << Modules[i].Size << ", Data: " << hexStr; +        std::string hexStr = ByteArrayToHexStr(module.Data, module.Size); +        stream << std::endl << "Battlenet::ProofResponse::ModuleData Size: " << module.Size << ", Data: " << hexStr;      }      return stream.str(); @@ -119,8 +131,8 @@ std::string Battlenet::ProofResponse::ToString() const  void Battlenet::AuthComplete::Write()  { -    _stream.Write(AuthResult != 0, 1); -    if (AuthResult == 0) +    _stream.Write(Result != 0, 1); +    if (Result == 0)      {          _stream.Write(Modules.size(), 3);          for (size_t i = 0; i < Modules.size(); ++i) @@ -163,8 +175,19 @@ void Battlenet::AuthComplete::Write()          _stream.Write(ErrorType, 2);          if (ErrorType == 1)          { -            _stream.Write(AuthResult, 16); +            _stream.Write<uint16>(Result, 16);              _stream.Write(0, 32);          }      }  } + +std::string Battlenet::AuthComplete::ToString() const +{ +    return "Battlenet::AuthComplete"; +} + +void Battlenet::AuthComplete::SetAuthResult(AuthResult result) +{ +    ErrorType = result != AUTH_OK ? 1 : 0; +    Result = result; +} diff --git a/src/server/authserver/Server/BattlenetPackets.h b/src/server/authserver/Server/BattlenetPackets.h index 23625e30d2b..86dcb99a4da 100644 --- a/src/server/authserver/Server/BattlenetPackets.h +++ b/src/server/authserver/Server/BattlenetPackets.h @@ -18,6 +18,9 @@  #ifndef __BATTLENETPACKETS_H__  #define __BATTLENETPACKETS_H__ +#include "AuthCodes.h" +#include "BattlenetBitStream.h" +#include "BattlenetManager.h"  #include "Define.h"  #include "Errors.h"  #include <string> @@ -39,6 +42,7 @@ namespace Battlenet      {          CMSG_AUTH_CHALLENGE         = 0x0,          CMSG_AUTH_PROOF_RESPONSE    = 0x2, +        CMSG_AUTH_CHALLENGE_NEW     = 0x9,  // MoP          SMSG_AUTH_COMPLETE          = 0x0,          SMSG_AUTH_PROOF_REQUEST     = 0x2, @@ -116,16 +120,9 @@ namespace Battlenet      public:          AuthChallenge(PacketHeader const& header, BitStream& stream) : ClientPacket(header, stream)          { -            ASSERT(header == PacketHeader(CMSG_AUTH_CHALLENGE, AUTHENTICATION) && "Invalid packet header for AuthChallenge"); +            ASSERT(header.Channel == AUTHENTICATION && (header.Opcode == CMSG_AUTH_CHALLENGE || header.Opcode == CMSG_AUTH_CHALLENGE_NEW) && "Invalid packet header for AuthChallenge");          } -        struct Component -        { -            std::string Program; -            std::string Platform; -            uint32 Build; -        }; -          void Read() override;          std::string ToString() const override; @@ -151,6 +148,7 @@ namespace Battlenet          ProofRequest() : ServerPacket(PacketHeader(SMSG_AUTH_PROOF_REQUEST, AUTHENTICATION)) { }          void Write() override; +        std::string ToString() const override;          std::vector<ModuleInfo> Modules;      }; @@ -181,14 +179,16 @@ namespace Battlenet      {      public:          AuthComplete() : ServerPacket(PacketHeader(SMSG_AUTH_COMPLETE, AUTHENTICATION)), -            AuthResult(0), ErrorType(0), PingTimeout(120000), Threshold(1000000), Rate(1000) +            Result(AUTH_OK), ErrorType(0), PingTimeout(120000), Threshold(1000000), Rate(1000)          {          }          void Write() override; +        std::string ToString() const override; -        uint32 AuthResult;          std::vector<ModuleInfo> Modules; +        void SetAuthResult(AuthResult result); +        AuthResult Result;          uint32 ErrorType;          int32 PingTimeout; diff --git a/src/server/authserver/Server/BattlenetSocket.cpp b/src/server/authserver/Server/BattlenetSocket.cpp index fb9ca008e8b..04005e30878 100644 --- a/src/server/authserver/Server/BattlenetSocket.cpp +++ b/src/server/authserver/Server/BattlenetSocket.cpp @@ -17,7 +17,6 @@  #include "AuthCodes.h"  #include "BattlenetBitStream.h" -#include "BattlenetPackets.h"  #include "BattlenetSocket.h"  #include <map> @@ -26,13 +25,29 @@ bool Battlenet::Socket::HandleAuthChallenge(PacketHeader& header, BitStream& pac      AuthChallenge info(header, packet);      info.Read(); +    for (Component const& component : info.Components) +    { +        if (!sBattlenetMgr->HasComponent(&component)) +        { +            AuthComplete complete; +            if (!sBattlenetMgr->HasProgram(component.Program)) +                complete.SetAuthResult(AUTH_INVALID_PROGRAM); +            else if (!sBattlenetMgr->HasPlatform(component.Platform)) +                complete.SetAuthResult(AUTH_INVALID_OS); +            else if (!sBattlenetMgr->HasBuild(component.Build)) +                complete.SetAuthResult(AUTH_REGION_BAD_VERSION); + +            Send(complete); +            return true; +        } +    } +      printf("%s\n", info.ToString().c_str());      _accountName = info.Login;      ProofRequest request; -    request.Write(); -    _socket.send((char const*)request.GetData(), request.GetSize()); +    Send(request);      return true;  } @@ -44,10 +59,8 @@ bool Battlenet::Socket::HandleAuthProofResponse(PacketHeader& header, BitStream&      printf("%s\n", response.ToString().c_str());      AuthComplete complete; -    complete.ErrorType = 1; -    complete.AuthResult = AUTH_USE_GRUNT_LOGON; -    complete.Write(); -    _socket.send((char const*)complete.GetData(), complete.GetSize()); +    complete.SetAuthResult(AUTH_USE_GRUNT_LOGON); +    Send(complete);      return true;  } @@ -56,6 +69,7 @@ std::map<Battlenet::PacketHeader, Battlenet::Socket::PacketHandler> InitHandlers      std::map<Battlenet::PacketHeader, Battlenet::Socket::PacketHandler> handlers;      handlers[Battlenet::PacketHeader(Battlenet::CMSG_AUTH_CHALLENGE, Battlenet::AUTHENTICATION)] = &Battlenet::Socket::HandleAuthChallenge; +    handlers[Battlenet::PacketHeader(Battlenet::CMSG_AUTH_CHALLENGE_NEW, Battlenet::AUTHENTICATION)] = &Battlenet::Socket::HandleAuthChallenge;      handlers[Battlenet::PacketHeader(Battlenet::CMSG_AUTH_PROOF_RESPONSE, Battlenet::AUTHENTICATION)] = &Battlenet::Socket::HandleAuthProofResponse;      return handlers; @@ -122,3 +136,11 @@ void Battlenet::Socket::OnClose()  {      printf("Battlenet::Socket::OnClose\n");  } + +void Battlenet::Socket::Send(ServerPacket& packet) +{ +    printf("Battlenet::Socket::Send %s\n", packet.ToString().c_str()); + +    packet.Write(); +    _socket.send(reinterpret_cast<char const*>(packet.GetData()), packet.GetSize()); +} diff --git a/src/server/authserver/Server/BattlenetSocket.h b/src/server/authserver/Server/BattlenetSocket.h index f7cc59d7e97..7507f090a7f 100644 --- a/src/server/authserver/Server/BattlenetSocket.h +++ b/src/server/authserver/Server/BattlenetSocket.h @@ -19,6 +19,7 @@  #define _BATTLENETSOCKET_H  #include "RealmSocket.h" +#include "BattlenetPackets.h"  #include "BattlenetPacketCrypt.h"  namespace Battlenet @@ -40,6 +41,8 @@ namespace Battlenet          void OnAccept() override;          void OnClose() override; +        void Send(ServerPacket& packet); +      private:          RealmSocket& _socket;          uint32 _currentChannel;  | 
