From 6be53574f81bc2f6705ef2b57487addd2127cea5 Mon Sep 17 00:00:00 2001 From: Meji Date: Tue, 16 Jan 2024 20:04:54 +0100 Subject: Core/Worldserver: Split Worldserver services into separate files (#29555) (cherry picked from commit 39621fa41c96f66698055447c7a9134865e0f00b) --- src/server/bnetserver/Services/AccountService.cpp | 1 - .../bnetserver/Services/AuthenticationService.cpp | 1 - .../bnetserver/Services/ConnectionService.cpp | 1 - src/server/bnetserver/Services/ConnectionService.h | 1 - .../bnetserver/Services/GameUtilitiesService.cpp | 1 - .../bnetserver/Services/GameUtilitiesService.h | 6 +- .../Services/WorldserverGameUtilitiesService.cpp | 143 +++++++++++++++++++++ .../Services/WorldserverGameUtilitiesService.h | 50 +++++++ src/server/game/Services/WorldserverService.cpp | 143 --------------------- src/server/game/Services/WorldserverService.h | 34 ----- .../game/Services/WorldserverServiceDispatcher.cpp | 3 +- .../game/Services/WorldserverServiceDispatcher.h | 3 +- 12 files changed, 198 insertions(+), 189 deletions(-) create mode 100644 src/server/game/Services/WorldserverGameUtilitiesService.cpp create mode 100644 src/server/game/Services/WorldserverGameUtilitiesService.h delete mode 100644 src/server/game/Services/WorldserverService.cpp (limited to 'src/server') diff --git a/src/server/bnetserver/Services/AccountService.cpp b/src/server/bnetserver/Services/AccountService.cpp index 0e75de80a24..60eb5ffec24 100644 --- a/src/server/bnetserver/Services/AccountService.cpp +++ b/src/server/bnetserver/Services/AccountService.cpp @@ -16,7 +16,6 @@ */ #include "AccountService.h" -#include "Session.h" Battlenet::Services::Account::Account(Session* session) : AccountService(session) { diff --git a/src/server/bnetserver/Services/AuthenticationService.cpp b/src/server/bnetserver/Services/AuthenticationService.cpp index d157f42ca32..7dda9db6902 100644 --- a/src/server/bnetserver/Services/AuthenticationService.cpp +++ b/src/server/bnetserver/Services/AuthenticationService.cpp @@ -16,7 +16,6 @@ */ #include "AuthenticationService.h" -#include "Session.h" Battlenet::Services::Authentication::Authentication(Session* session) : AuthenticationService(session) { diff --git a/src/server/bnetserver/Services/ConnectionService.cpp b/src/server/bnetserver/Services/ConnectionService.cpp index ab8d6b838ed..fbb34a51985 100644 --- a/src/server/bnetserver/Services/ConnectionService.cpp +++ b/src/server/bnetserver/Services/ConnectionService.cpp @@ -17,7 +17,6 @@ #include "ConnectionService.h" #include "Duration.h" -#include "Session.h" #include "Util.h" #include "BattlenetRpcErrorCodes.h" diff --git a/src/server/bnetserver/Services/ConnectionService.h b/src/server/bnetserver/Services/ConnectionService.h index 028c1ec4205..f3aa3253e94 100644 --- a/src/server/bnetserver/Services/ConnectionService.h +++ b/src/server/bnetserver/Services/ConnectionService.h @@ -37,7 +37,6 @@ namespace Battlenet uint32 HandleConnect(connection::v1::ConnectRequest const* request, connection::v1::ConnectResponse* response, std::function& continuation) override; uint32 HandleKeepAlive(NoData const* request) override; uint32 HandleRequestDisconnect(connection::v1::DisconnectRequest const* request) override; - }; } } diff --git a/src/server/bnetserver/Services/GameUtilitiesService.cpp b/src/server/bnetserver/Services/GameUtilitiesService.cpp index 225b7e47cc0..ee76e8b76a0 100644 --- a/src/server/bnetserver/Services/GameUtilitiesService.cpp +++ b/src/server/bnetserver/Services/GameUtilitiesService.cpp @@ -16,7 +16,6 @@ */ #include "GameUtilitiesService.h" -#include "Session.h" Battlenet::Services::GameUtilities::GameUtilities(Session* session) : GameUtilitiesService(session) { diff --git a/src/server/bnetserver/Services/GameUtilitiesService.h b/src/server/bnetserver/Services/GameUtilitiesService.h index ccd69dcd53d..bbc27baa933 100644 --- a/src/server/bnetserver/Services/GameUtilitiesService.h +++ b/src/server/bnetserver/Services/GameUtilitiesService.h @@ -15,8 +15,8 @@ * with this program. If not, see . */ -#ifndef GameUtilitiesServiceService_h__ -#define GameUtilitiesServiceService_h__ +#ifndef GameUtilitiesService_h__ +#define GameUtilitiesService_h__ #include "Service.h" #include "game_utilities_service.pb.h" @@ -40,4 +40,4 @@ namespace Battlenet } } -#endif // GameUtilitiesServiceService_h__ +#endif // GameUtilitiesService_h__ diff --git a/src/server/game/Services/WorldserverGameUtilitiesService.cpp b/src/server/game/Services/WorldserverGameUtilitiesService.cpp new file mode 100644 index 00000000000..63c8223c72f --- /dev/null +++ b/src/server/game/Services/WorldserverGameUtilitiesService.cpp @@ -0,0 +1,143 @@ +/* + * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information + * + * 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 "WorldserverGameUtilitiesService.h" +#include "BattlenetRpcErrorCodes.h" +#include "IpAddress.h" +#include "Log.h" +#include "ProtobufJSON.h" +#include "Realm.h" +#include "RealmList.h" +#include "RealmList.pb.h" +#include "World.h" +#include + +std::unordered_map const Battlenet::Services::GameUtilitiesService::ClientRequestHandlers = +{ + { "Command_RealmListRequest_v1", &GameUtilitiesService::HandleRealmListRequest }, + { "Command_RealmJoinRequest_v1", &GameUtilitiesService::HandleRealmJoinRequest } +}; + +Battlenet::Services::GameUtilitiesService::GameUtilitiesService(WorldSession* session) : BaseService(session) +{ +} + +uint32 Battlenet::Services::GameUtilitiesService::HandleProcessClientRequest(game_utilities::v1::ClientRequest const* request, game_utilities::v1::ClientResponse* response, std::function& /*continuation*/) +{ + Attribute const* command = nullptr; + std::unordered_map params; + auto removeSuffix = [](std::string const& string) -> std::string + { + size_t pos = string.rfind('_'); + if (pos != std::string::npos) + return string.substr(0, pos); + + return string; + }; + + for (int32 i = 0; i < request->attribute_size(); ++i) + { + Attribute const& attr = request->attribute(i); + if (strstr(attr.name().c_str(), "Command_") == attr.name().c_str()) + { + command = &attr; + params[removeSuffix(attr.name())] = &attr.value(); + } + else + params[attr.name()] = &attr.value(); + } + + if (!command) + { + TC_LOG_ERROR("session.rpc", "{} sent ClientRequest with no command.", GetCallerInfo()); + return ERROR_RPC_MALFORMED_REQUEST; + } + + auto itr = ClientRequestHandlers.find(removeSuffix(command->name())); + if (itr == ClientRequestHandlers.end()) + { + TC_LOG_ERROR("session.rpc", "{} sent ClientRequest with unknown command {}.", GetCallerInfo(), removeSuffix(command->name())); + return ERROR_RPC_NOT_IMPLEMENTED; + } + + return (this->*itr->second)(params, response); +} + +static Variant const* GetParam(std::unordered_map const& params, char const* paramName) +{ + auto itr = params.find(paramName); + return itr != params.end() ? itr->second : nullptr; +} + +uint32 Battlenet::Services::GameUtilitiesService::HandleRealmListRequest(std::unordered_map const& params, game_utilities::v1::ClientResponse* response) +{ + std::string subRegionId; + if (Variant const* subRegion = GetParam(params, "Command_RealmListRequest_v1")) + subRegionId = subRegion->string_value(); + + std::vector compressed = sRealmList->GetRealmList(realm.Build, subRegionId); + + if (compressed.empty()) + return ERROR_UTIL_SERVER_FAILED_TO_SERIALIZE_RESPONSE; + + Attribute* attribute = response->add_attribute(); + attribute->set_name("Param_RealmList"); + attribute->mutable_value()->set_blob_value(compressed.data(), compressed.size()); + + JSON::RealmList::RealmCharacterCountList realmCharacterCounts; + for (auto const& characterCount : _session->GetRealmCharacterCounts()) + { + ::JSON::RealmList::RealmCharacterCountEntry* countEntry = realmCharacterCounts.add_counts(); + countEntry->set_wowrealmaddress(characterCount.first); + countEntry->set_count(characterCount.second); + } + + std::string json = "JSONRealmCharacterCountList:" + JSON::Serialize(realmCharacterCounts); + + uLongf compressedLength = compressBound(json.length()); + compressed.resize(4 + compressedLength); + *reinterpret_cast(compressed.data()) = json.length() + 1; + + if (compress(compressed.data() + 4, &compressedLength, reinterpret_cast(json.c_str()), json.length() + 1) != Z_OK) + return ERROR_UTIL_SERVER_FAILED_TO_SERIALIZE_RESPONSE; + + attribute = response->add_attribute(); + attribute->set_name("Param_CharacterCountList"); + attribute->mutable_value()->set_blob_value(compressed.data(), compressedLength + 4); + + return ERROR_OK; +} + +uint32 Battlenet::Services::GameUtilitiesService::HandleRealmJoinRequest(std::unordered_map const& params, game_utilities::v1::ClientResponse* response) +{ + if (Variant const* realmAddress = GetParam(params, "Param_RealmAddress")) + return sRealmList->JoinRealm(uint32(realmAddress->uint_value()), realm.Build, Trinity::Net::make_address(_session->GetRemoteAddress()), _session->GetRealmListSecret(), + _session->GetSessionDbcLocale(), _session->GetOS(), _session->GetTimezoneOffset(), _session->GetAccountName(), response); + + return ERROR_WOW_SERVICES_INVALID_JOIN_TICKET; +} + +uint32 Battlenet::Services::GameUtilitiesService::HandleGetAllValuesForAttribute(game_utilities::v1::GetAllValuesForAttributeRequest const* request, game_utilities::v1::GetAllValuesForAttributeResponse* response, std::function& /*continuation*/) +{ + if (request->attribute_key().find("Command_RealmListRequest_v1") == 0) + { + sRealmList->WriteSubRegions(response); + return ERROR_OK; + } + + return ERROR_RPC_NOT_IMPLEMENTED; +} diff --git a/src/server/game/Services/WorldserverGameUtilitiesService.h b/src/server/game/Services/WorldserverGameUtilitiesService.h new file mode 100644 index 00000000000..46e729eae22 --- /dev/null +++ b/src/server/game/Services/WorldserverGameUtilitiesService.h @@ -0,0 +1,50 @@ +/* + * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information + * + * 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 . + */ + +#ifndef WorldserverGameUtilitiesService_h__ +#define WorldserverGameUtilitiesService_h__ + +#include "WorldserverService.h" +#include "game_utilities_service.pb.h" + +namespace Battlenet +{ + class Session; + + namespace Services + { + class GameUtilitiesService : public WorldserverService + { + typedef WorldserverService BaseService; + + public: + GameUtilitiesService(WorldSession* session); + + uint32 HandleProcessClientRequest(game_utilities::v1::ClientRequest const* request, game_utilities::v1::ClientResponse* response, std::function& continuation) override; + uint32 HandleGetAllValuesForAttribute(game_utilities::v1::GetAllValuesForAttributeRequest const* request, game_utilities::v1::GetAllValuesForAttributeResponse* response, std::function& continuation) override; + + private: + using ClientRequestHandler = uint32(GameUtilitiesService::*)(std::unordered_map const&, game_utilities::v1::ClientResponse*); + static std::unordered_map const ClientRequestHandlers; + + uint32 HandleRealmListRequest(std::unordered_map const& params, game_utilities::v1::ClientResponse* response); + uint32 HandleRealmJoinRequest(std::unordered_map const& params, game_utilities::v1::ClientResponse* response); + }; + } +} + +#endif // WorldserverGameUtilitiesService_h__ diff --git a/src/server/game/Services/WorldserverService.cpp b/src/server/game/Services/WorldserverService.cpp deleted file mode 100644 index 213ffbbad8f..00000000000 --- a/src/server/game/Services/WorldserverService.cpp +++ /dev/null @@ -1,143 +0,0 @@ -/* - * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information - * - * 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 "WorldserverService.h" -#include "BattlenetRpcErrorCodes.h" -#include "IpAddress.h" -#include "Log.h" -#include "ProtobufJSON.h" -#include "Realm.h" -#include "RealmList.h" -#include "RealmList.pb.h" -#include "World.h" -#include - -std::unordered_map const Battlenet::GameUtilitiesService::ClientRequestHandlers = -{ - { "Command_RealmListRequest_v1", &GameUtilitiesService::HandleRealmListRequest }, - { "Command_RealmJoinRequest_v1", &GameUtilitiesService::HandleRealmJoinRequest } -}; - -Battlenet::GameUtilitiesService::GameUtilitiesService(WorldSession* session) : BaseService(session) -{ -} - -uint32 Battlenet::GameUtilitiesService::HandleProcessClientRequest(game_utilities::v1::ClientRequest const* request, game_utilities::v1::ClientResponse* response, std::function& /*continuation*/) -{ - Attribute const* command = nullptr; - std::unordered_map params; - auto removeSuffix = [](std::string const& string) -> std::string - { - size_t pos = string.rfind('_'); - if (pos != std::string::npos) - return string.substr(0, pos); - - return string; - }; - - for (int32 i = 0; i < request->attribute_size(); ++i) - { - Attribute const& attr = request->attribute(i); - if (strstr(attr.name().c_str(), "Command_") == attr.name().c_str()) - { - command = &attr; - params[removeSuffix(attr.name())] = &attr.value(); - } - else - params[attr.name()] = &attr.value(); - } - - if (!command) - { - TC_LOG_ERROR("session.rpc", "{} sent ClientRequest with no command.", GetCallerInfo()); - return ERROR_RPC_MALFORMED_REQUEST; - } - - auto itr = ClientRequestHandlers.find(removeSuffix(command->name())); - if (itr == ClientRequestHandlers.end()) - { - TC_LOG_ERROR("session.rpc", "{} sent ClientRequest with unknown command {}.", GetCallerInfo(), removeSuffix(command->name())); - return ERROR_RPC_NOT_IMPLEMENTED; - } - - return (this->*itr->second)(params, response); -} - -static Variant const* GetParam(std::unordered_map const& params, char const* paramName) -{ - auto itr = params.find(paramName); - return itr != params.end() ? itr->second : nullptr; -} - -uint32 Battlenet::GameUtilitiesService::HandleRealmListRequest(std::unordered_map const& params, game_utilities::v1::ClientResponse* response) -{ - std::string subRegionId; - if (Variant const* subRegion = GetParam(params, "Command_RealmListRequest_v1")) - subRegionId = subRegion->string_value(); - - std::vector compressed = sRealmList->GetRealmList(realm.Build, subRegionId); - - if (compressed.empty()) - return ERROR_UTIL_SERVER_FAILED_TO_SERIALIZE_RESPONSE; - - Attribute* attribute = response->add_attribute(); - attribute->set_name("Param_RealmList"); - attribute->mutable_value()->set_blob_value(compressed.data(), compressed.size()); - - JSON::RealmList::RealmCharacterCountList realmCharacterCounts; - for (auto const& characterCount : _session->GetRealmCharacterCounts()) - { - ::JSON::RealmList::RealmCharacterCountEntry* countEntry = realmCharacterCounts.add_counts(); - countEntry->set_wowrealmaddress(characterCount.first); - countEntry->set_count(characterCount.second); - } - - std::string json = "JSONRealmCharacterCountList:" + JSON::Serialize(realmCharacterCounts); - - uLongf compressedLength = compressBound(json.length()); - compressed.resize(4 + compressedLength); - *reinterpret_cast(compressed.data()) = json.length() + 1; - - if (compress(compressed.data() + 4, &compressedLength, reinterpret_cast(json.c_str()), json.length() + 1) != Z_OK) - return ERROR_UTIL_SERVER_FAILED_TO_SERIALIZE_RESPONSE; - - attribute = response->add_attribute(); - attribute->set_name("Param_CharacterCountList"); - attribute->mutable_value()->set_blob_value(compressed.data(), compressedLength + 4); - - return ERROR_OK; -} - -uint32 Battlenet::GameUtilitiesService::HandleRealmJoinRequest(std::unordered_map const& params, game_utilities::v1::ClientResponse* response) -{ - if (Variant const* realmAddress = GetParam(params, "Param_RealmAddress")) - return sRealmList->JoinRealm(uint32(realmAddress->uint_value()), realm.Build, Trinity::Net::make_address(_session->GetRemoteAddress()), _session->GetRealmListSecret(), - _session->GetSessionDbcLocale(), _session->GetOS(), _session->GetTimezoneOffset(), _session->GetAccountName(), response); - - return ERROR_WOW_SERVICES_INVALID_JOIN_TICKET; -} - -uint32 Battlenet::GameUtilitiesService::HandleGetAllValuesForAttribute(game_utilities::v1::GetAllValuesForAttributeRequest const* request, game_utilities::v1::GetAllValuesForAttributeResponse* response, std::function& /*continuation*/) -{ - if (request->attribute_key().find("Command_RealmListRequest_v1") == 0) - { - sRealmList->WriteSubRegions(response); - return ERROR_OK; - } - - return ERROR_RPC_NOT_IMPLEMENTED; -} diff --git a/src/server/game/Services/WorldserverService.h b/src/server/game/Services/WorldserverService.h index 52f5945b9a8..80b89621cd1 100644 --- a/src/server/game/Services/WorldserverService.h +++ b/src/server/game/Services/WorldserverService.h @@ -19,22 +19,6 @@ #define WorldserverService_h__ #include "WorldSession.h" -#include "account_service.pb.h" -#include "authentication_service.pb.h" -#include "challenge_service.pb.h" -#include "club_listener.pb.h" -#include "club_membership_listener.pb.h" -#include "club_membership_service.pb.h" -#include "club_service.pb.h" -#include "connection_service.pb.h" -#include "friends_service.pb.h" -#include "game_utilities_service.pb.h" -#include "presence_listener.pb.h" -#include "presence_service.pb.h" -#include "report_service.pb.h" -#include "api/client/v2/report_service.pb.h" -#include "resource_service.pb.h" -#include "user_manager_service.pb.h" namespace bgs { namespace protocol { } } using namespace bgs::protocol; @@ -56,24 +40,6 @@ namespace Battlenet WorldSession* _session; }; - - class GameUtilitiesService : public WorldserverService - { - typedef WorldserverService BaseService; - - public: - GameUtilitiesService(WorldSession* session); - - uint32 HandleProcessClientRequest(game_utilities::v1::ClientRequest const* request, game_utilities::v1::ClientResponse* response, std::function& continuation) override; - uint32 HandleGetAllValuesForAttribute(game_utilities::v1::GetAllValuesForAttributeRequest const* request, game_utilities::v1::GetAllValuesForAttributeResponse* response, std::function& continuation) override; - - private: - using ClientRequestHandler = uint32(GameUtilitiesService::*)(std::unordered_map const&, game_utilities::v1::ClientResponse*); - static std::unordered_map const ClientRequestHandlers; - - uint32 HandleRealmListRequest(std::unordered_map const& params, game_utilities::v1::ClientResponse* response); - uint32 HandleRealmJoinRequest(std::unordered_map const& params, game_utilities::v1::ClientResponse* response); - }; } #endif // WorldserverService_h__ diff --git a/src/server/game/Services/WorldserverServiceDispatcher.cpp b/src/server/game/Services/WorldserverServiceDispatcher.cpp index 881c788574f..77177139790 100644 --- a/src/server/game/Services/WorldserverServiceDispatcher.cpp +++ b/src/server/game/Services/WorldserverServiceDispatcher.cpp @@ -16,7 +16,6 @@ */ #include "WorldserverServiceDispatcher.h" -#include "WorldserverService.h" Battlenet::WorldserverServiceDispatcher::WorldserverServiceDispatcher() { @@ -26,7 +25,7 @@ Battlenet::WorldserverServiceDispatcher::WorldserverServiceDispatcher() AddService>(); AddService>(); AddService>(); - AddService(); + AddService(); AddService>(); AddService>(); AddService>(); diff --git a/src/server/game/Services/WorldserverServiceDispatcher.h b/src/server/game/Services/WorldserverServiceDispatcher.h index 038d8c873d7..c40d2c883ab 100644 --- a/src/server/game/Services/WorldserverServiceDispatcher.h +++ b/src/server/game/Services/WorldserverServiceDispatcher.h @@ -21,7 +21,6 @@ #include "WorldSession.h" #include "MessageBuffer.h" #include "Log.h" -#include "Common.h" #include "account_service.pb.h" #include "authentication_service.pb.h" #include "challenge_service.pb.h" @@ -31,7 +30,7 @@ #include "club_service.pb.h" #include "connection_service.pb.h" #include "friends_service.pb.h" -#include "game_utilities_service.pb.h" +#include "WorldserverGameUtilitiesService.h" #include "presence_listener.pb.h" #include "presence_service.pb.h" #include "report_service.pb.h" -- cgit v1.2.3