diff options
-rw-r--r-- | src/server/bnetserver/Server/Session.cpp | 34 | ||||
-rw-r--r-- | src/server/game/Services/WorldserverService.cpp | 54 | ||||
-rw-r--r-- | src/server/game/Services/WorldserverService.h | 7 |
3 files changed, 67 insertions, 28 deletions
diff --git a/src/server/bnetserver/Server/Session.cpp b/src/server/bnetserver/Server/Session.cpp index 759ec3ef6dc..acfd958b2cd 100644 --- a/src/server/bnetserver/Server/Session.cpp +++ b/src/server/bnetserver/Server/Session.cpp @@ -452,10 +452,10 @@ uint32 Battlenet::Session::HandleGetGameAccountState(account::v1::GetGameAccount std::unordered_map<std::string, Battlenet::Session::ClientRequestHandler> const Battlenet::Session::ClientRequestHandlers = { - { "Command_RealmListTicketRequest_v1_b9", &Battlenet::Session::GetRealmListTicket }, - { "Command_LastCharPlayedRequest_v1_b9", &Battlenet::Session::GetLastCharPlayed }, - { "Command_RealmListRequest_v1_b9", &Battlenet::Session::GetRealmList }, - { "Command_RealmJoinRequest_v1_b9", &Battlenet::Session::JoinRealm }, + { "Command_RealmListTicketRequest_v1", &Battlenet::Session::GetRealmListTicket }, + { "Command_LastCharPlayedRequest_v1", &Battlenet::Session::GetLastCharPlayed }, + { "Command_RealmListRequest_v1", &Battlenet::Session::GetRealmList }, + { "Command_RealmJoinRequest_v1", &Battlenet::Session::JoinRealm }, }; uint32 Battlenet::Session::HandleProcessClientRequest(game_utilities::v1::ClientRequest const* request, game_utilities::v1::ClientResponse* response) @@ -465,13 +465,25 @@ uint32 Battlenet::Session::HandleProcessClientRequest(game_utilities::v1::Client Attribute const* command = nullptr; std::unordered_map<std::string, Variant const*> 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); - params[attr.name()] = &attr.value(); 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) @@ -480,17 +492,17 @@ uint32 Battlenet::Session::HandleProcessClientRequest(game_utilities::v1::Client return ERROR_RPC_MALFORMED_REQUEST; } - auto itr = ClientRequestHandlers.find(command->name()); + auto itr = ClientRequestHandlers.find(removeSuffix(command->name())); if (itr == ClientRequestHandlers.end()) { - TC_LOG_ERROR("session.rpc", "%s sent ClientRequest with unknown command %s.", GetClientInfo().c_str(), command->name().c_str()); + TC_LOG_ERROR("session.rpc", "%s sent ClientRequest with unknown command %s.", GetClientInfo().c_str(), removeSuffix(command->name()).c_str()); return ERROR_RPC_NOT_IMPLEMENTED; } return (this->*itr->second)(params, response); } -inline Variant const* GetParam(std::unordered_map<std::string, Variant const*> const& params, char const* paramName) +static Variant const* GetParam(std::unordered_map<std::string, Variant const*> const& params, char const* paramName) { auto itr = params.find(paramName); return itr != params.end() ? itr->second : nullptr; @@ -553,7 +565,7 @@ uint32 Battlenet::Session::GetRealmListTicket(std::unordered_map<std::string, Va uint32 Battlenet::Session::GetLastCharPlayed(std::unordered_map<std::string, Variant const*> const& params, game_utilities::v1::ClientResponse* response) { - if (Variant const* subRegion = GetParam(params, "Command_LastCharPlayedRequest_v1_b9")) + if (Variant const* subRegion = GetParam(params, "Command_LastCharPlayedRequest_v1")) { auto lastPlayerChar = _gameAccountInfo->LastPlayedCharacters.find(subRegion->string_value()); if (lastPlayerChar != _gameAccountInfo->LastPlayedCharacters.end()) @@ -592,7 +604,7 @@ uint32 Battlenet::Session::GetRealmList(std::unordered_map<std::string, Variant return ERROR_USER_SERVER_BAD_WOW_ACCOUNT; std::string subRegionId; - if (Variant const* subRegion = GetParam(params, "Command_RealmListRequest_v1_b9")) + if (Variant const* subRegion = GetParam(params, "Command_RealmListRequest_v1")) subRegionId = subRegion->string_value(); std::vector<uint8> compressed = sRealmList->GetRealmList(_build, subRegionId); @@ -640,7 +652,7 @@ uint32 Battlenet::Session::HandleGetAllValuesForAttribute(game_utilities::v1::Ge if (!_authed) return ERROR_DENIED; - if (request->attribute_key() == "Command_RealmListRequest_v1_b9") + if (request->attribute_key().find("Command_RealmListRequest_v1") == 0) { sRealmList->WriteSubRegions(response); return ERROR_OK; diff --git a/src/server/game/Services/WorldserverService.cpp b/src/server/game/Services/WorldserverService.cpp index ebf3c3b4227..5c116b597bd 100644 --- a/src/server/game/Services/WorldserverService.cpp +++ b/src/server/game/Services/WorldserverService.cpp @@ -26,6 +26,12 @@ #include "World.h" #include <zlib.h> +std::unordered_map<std::string, Battlenet::GameUtilitiesService::ClientRequestHandler> const Battlenet::GameUtilitiesService::ClientRequestHandlers = +{ + { "Command_RealmListRequest_v1", &GameUtilitiesService::HandleRealmListRequest }, + { "Command_RealmJoinRequest_v1", &GameUtilitiesService::HandleRealmJoinRequest } +}; + Battlenet::GameUtilitiesService::GameUtilitiesService(WorldSession* session) : BaseService(session) { } @@ -34,13 +40,25 @@ uint32 Battlenet::GameUtilitiesService::HandleProcessClientRequest(game_utilitie { Attribute const* command = nullptr; std::unordered_map<std::string, Variant const*> 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); - params[attr.name()] = &attr.value(); 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) @@ -49,20 +67,27 @@ uint32 Battlenet::GameUtilitiesService::HandleProcessClientRequest(game_utilitie return ERROR_RPC_MALFORMED_REQUEST; } - if (command->name() == "Command_RealmListRequest_v1_b9") - return HandleRealmListRequest(params, response); - else if (command->name() == "Command_RealmJoinRequest_v1_b9") - return HandleRealmJoinRequest(params, response); + auto itr = ClientRequestHandlers.find(removeSuffix(command->name())); + if (itr == ClientRequestHandlers.end()) + { + TC_LOG_ERROR("session.rpc", "%s sent ClientRequest with unknown command %s.", GetCallerInfo().c_str(), removeSuffix(command->name()).c_str()); + return ERROR_RPC_NOT_IMPLEMENTED; + } + + return (this->*itr->second)(params, response); +} - return ERROR_RPC_NOT_IMPLEMENTED; +static Variant const* GetParam(std::unordered_map<std::string, Variant const*> const& params, char const* paramName) +{ + auto itr = params.find(paramName); + return itr != params.end() ? itr->second : nullptr; } -uint32 Battlenet::GameUtilitiesService::HandleRealmListRequest(std::unordered_map<std::string, Variant const*> params, game_utilities::v1::ClientResponse* response) +uint32 Battlenet::GameUtilitiesService::HandleRealmListRequest(std::unordered_map<std::string, Variant const*> const& params, game_utilities::v1::ClientResponse* response) { std::string subRegionId; - auto subRegion = params.find("Command_RealmListRequest_v1_b9"); - if (subRegion != params.end()) - subRegionId = subRegion->second->string_value(); + if (Variant const* subRegion = GetParam(params, "Command_RealmListRequest_v1")) + subRegionId = subRegion->string_value(); std::vector<uint8> compressed = sRealmList->GetRealmList(realm.Build, subRegionId); @@ -97,11 +122,10 @@ uint32 Battlenet::GameUtilitiesService::HandleRealmListRequest(std::unordered_ma return ERROR_OK; } -uint32 Battlenet::GameUtilitiesService::HandleRealmJoinRequest(std::unordered_map<std::string, Variant const*> params, game_utilities::v1::ClientResponse* response) +uint32 Battlenet::GameUtilitiesService::HandleRealmJoinRequest(std::unordered_map<std::string, Variant const*> const& params, game_utilities::v1::ClientResponse* response) { - auto realmAddress = params.find("Param_RealmAddress"); - if (realmAddress != params.end()) - return sRealmList->JoinRealm(uint32(realmAddress->second->uint_value()), realm.Build, Trinity::Net::make_address(_session->GetRemoteAddress()), _session->GetRealmListSecret(), + 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->GetAccountName(), response); return ERROR_WOW_SERVICES_INVALID_JOIN_TICKET; @@ -109,7 +133,7 @@ uint32 Battlenet::GameUtilitiesService::HandleRealmJoinRequest(std::unordered_ma uint32 Battlenet::GameUtilitiesService::HandleGetAllValuesForAttribute(game_utilities::v1::GetAllValuesForAttributeRequest const* request, game_utilities::v1::GetAllValuesForAttributeResponse* response, std::function<void(ServiceBase*, uint32, ::google::protobuf::Message const*)>& /*continuation*/) { - if (request->attribute_key() == "Command_RealmListRequest_v1_b9") + if (request->attribute_key() == "Command_RealmListRequest_v1") { sRealmList->WriteSubRegions(response); return ERROR_OK; diff --git a/src/server/game/Services/WorldserverService.h b/src/server/game/Services/WorldserverService.h index 6fae99a95b9..52f5945b9a8 100644 --- a/src/server/game/Services/WorldserverService.h +++ b/src/server/game/Services/WorldserverService.h @@ -68,8 +68,11 @@ namespace Battlenet uint32 HandleGetAllValuesForAttribute(game_utilities::v1::GetAllValuesForAttributeRequest const* request, game_utilities::v1::GetAllValuesForAttributeResponse* response, std::function<void(ServiceBase*, uint32, ::google::protobuf::Message const*)>& continuation) override; private: - uint32 HandleRealmListRequest(std::unordered_map<std::string, Variant const*> params, game_utilities::v1::ClientResponse* response); - uint32 HandleRealmJoinRequest(std::unordered_map<std::string, Variant const*> params, game_utilities::v1::ClientResponse* response); + using ClientRequestHandler = uint32(GameUtilitiesService::*)(std::unordered_map<std::string, Variant const*> const&, game_utilities::v1::ClientResponse*); + static std::unordered_map<std::string, ClientRequestHandler> const ClientRequestHandlers; + + uint32 HandleRealmListRequest(std::unordered_map<std::string, Variant const*> const& params, game_utilities::v1::ClientResponse* response); + uint32 HandleRealmJoinRequest(std::unordered_map<std::string, Variant const*> const& params, game_utilities::v1::ClientResponse* response); }; } |