25#include "RealmList.pb.h"
35 if (command.starts_with(
"Command_"sv))
37 size_t pos = command.rfind(
'_');
38 if (pos != std::string_view::npos)
39 command.remove_suffix(command.length() - pos);
48 return itr !=
params.end() ? &itr->second :
nullptr;
52 std::vector<std::pair<std::string_view, Variant>>&
params,
53 std::vector<std::pair<std::string_view, Variant>>& responseValues)
55 auto command = std::ranges::find_if(
params,
56 [](std::string_view paramName) {
return paramName.starts_with(
"Command_"sv); },
59 if (command ==
params.end())
84 for (std::string& subRegion :
sRealmList->GetSubRegions())
85 responseValues.emplace_back(std::move(subRegion));
91 TC_LOG_ERROR(
"session.rpc",
"{} sent GetAllValuesForAttributeRequest with unknown command {}.", session->
GetPlayerInfo(), command);
96 std::vector<std::pair<std::string_view, Variant>>&
params,
97 std::vector<std::pair<std::string_view, Variant>>& responseValues)
99 std::string subRegionId;
100 if (
Variant const* subRegion =
FindParamValue(
params,
"Command_RealmListRequest_v1"); subRegion && std::holds_alternative<std::string>(*subRegion))
101 subRegionId = std::get<std::string>(*subRegion);
105 if (realmListJson.empty())
108 ::JSON::RealmList::RealmCharacterCountList realmCharacterCounts;
111 ::JSON::RealmList::RealmCharacterCountEntry* countEntry = realmCharacterCounts.add_counts();
112 countEntry->set_wowrealmaddress(realmAddress);
113 countEntry->set_count(count);
116 std::string json =
"JSONRealmCharacterCountList:" +
::JSON::Serialize(realmCharacterCounts);
118 uLongf compressedLength = compressBound(json.length());
119 std::vector<uint8> characterCountsJson(4 + compressedLength);
120 *
reinterpret_cast<uint32*
>(characterCountsJson.data()) = json.length() + 1;
122 if (compress(characterCountsJson.data() + 4, &compressedLength,
reinterpret_cast<uint8 const*
>(json.c_str()), json.length() + 1) != Z_OK)
125 responseValues.emplace_back(
"Param_RealmList"sv, std::move(realmListJson));
126 responseValues.emplace_back(
"Param_CharacterCountList"sv, std::move(characterCountsJson));
132 std::vector<std::pair<std::string_view, Variant>>&
params,
133 std::vector<std::pair<std::string_view, Variant>>& responseValues)
136 if (!realmAddress || !std::holds_alternative<uint64>(*realmAddress))
145 responseValues.emplace_back(
"Param_RealmJoinTicket"sv, std::move(result.
JoinTicket));
146 responseValues.emplace_back(
"Param_ServerAddresses"sv, std::move(result.
ServerAddresses));
147 responseValues.emplace_back(
"Param_JoinSecret"sv, std::move(result.
JoinSecret));
158 switch (from.type_case())
160 case v2::Variant::kBoolValue:
161 return from.bool_value();
162 case v2::Variant::kIntValue:
163 return from.int_value();
164 case v2::Variant::kFloatValue:
165 return from.float_value();
166 case v2::Variant::kStringValue:
167 return from.string_value();
168 case v2::Variant::kBlobValue:
169 return Variant{ std::in_place_type<std::vector<uint8>>,
170 reinterpret_cast<uint8 const*
>(from.blob_value().data()),
171 reinterpret_cast<uint8 const*
>(from.blob_value().data()) + from.blob_value().size() };
172 case v2::Variant::kUintValue:
173 return from.uint_value();
183 std::visit([to]<
typename T>(T
const& value)
185 if constexpr (std::is_same_v<T, bool>)
186 to->set_bool_value(value);
187 else if constexpr (std::is_same_v<T, int64>)
188 to->set_int_value(value);
189 else if constexpr (std::is_same_v<T, double>)
190 to->set_float_value(value);
191 else if constexpr (std::is_same_v<T, std::string>)
192 to->set_string_value(value);
193 else if constexpr (std::is_same_v<T, std::vector<uint8>>)
194 to->set_blob_value(value.data(), value.size());
195 else if constexpr (std::is_same_v<T, uint64>)
196 to->set_uint_value(value);
198 static_assert(Trinity::dependant_false_v<T>);
208 std::vector<std::pair<std::string_view, Variant>>
params;
209 std::vector<std::pair<std::string_view, Variant>> responseValues;
211 for (v2::Attribute
const& attribute : request->attribute())
213 if (!attribute.has_name() || !attribute.has_value())
221 for (
auto&& [name, value] : responseValues)
223 v2::Attribute* attr = response->add_result();
224 attr->set_name(name.data(), name.length());
225 ToProto(value, attr->mutable_value());
233 std::vector<Variant> responseValues;
237 for (
Variant& value : responseValues)
238 ToProto(value, response->add_attribute_value());
@ ERROR_RPC_NOT_IMPLEMENTED
@ ERROR_RPC_MALFORMED_REQUEST
@ ERROR_UTIL_SERVER_FAILED_TO_SERIALIZE_RESPONSE
@ ERROR_UTIL_SERVER_UNKNOWN_REALM
std::unordered_set< uint32 > params[2]
#define TC_LOG_ERROR(filterType__, message__,...)
static Variant * FindParamValue(std::vector< std::pair< std::string_view, Variant > > ¶ms, std::string_view paramName)
static uint32 HandleClientRequest(Session *session, std::vector< std::pair< std::string_view, Variant > > ¶ms, std::vector< std::pair< std::string_view, Variant > > &responseValues)
static std::string_view ParseParamName(std::string_view command)
static uint32 JoinRealm(Session const *session, std::vector< std::pair< std::string_view, Variant > > ¶ms, std::vector< std::pair< std::string_view, Variant > > &responseValues)
static uint32 GetRealmList(Session const *session, std::vector< std::pair< std::string_view, Variant > > ¶ms, std::vector< std::pair< std::string_view, Variant > > &responseValues)
static uint32 HandleGetAllValuesForAttribute(Session const *session, std::string_view command, std::vector< Variant > &responseValues)
uint32 HandleGetAllValuesForAttribute(game_utilities::v2::client::GetAllValuesForAttributeRequest const *request, game_utilities::v2::client::GetAllValuesForAttributeResponse *response, std::function< void(ServiceBase *, uint32, ::google::protobuf::Message const *)> &continuation) override
GameUtilitiesService(WorldSession *session)
uint32 HandleProcessTask(game_utilities::v2::client::ProcessTaskRequest const *request, game_utilities::v2::client::ProcessTaskResponse *response, std::function< void(ServiceBase *, uint32, ::google::protobuf::Message const *)> &continuation) override
Player session in the World.
AccountTypes GetSecurity() const
std::array< uint8, 32 > const & GetRealmListSecret() const
Minutes GetTimezoneOffset() const
LocaleConstant GetSessionDbcLocale() const
std::string GetPlayerInfo() const
std::string const & GetOS() const
std::string const & GetAccountName() const
ClientBuild::VariantId const & GetClientBuildVariant() const
std::string const & GetRemoteAddress() const
uint32 GetClientBuild() const
std::unordered_map< uint32, uint8 > const & GetRealmCharacterCounts() const
Battlenet::Services::Variant FromProto(bgs::protocol::v2::Variant const &from)
void ToProto(Battlenet::Services::Variant const &from, bgs::protocol::v2::Variant *to)
std::variant< bool, int64, double, std::string, std::vector< uint8 >, uint64 > Variant
TC_SHARED_API std::string Serialize(google::protobuf::Message const &message)
std::vector< uint8 > JoinSecret
std::vector< uint8 > JoinTicket
std::vector< uint8 > ServerAddresses
static constexpr T GetHash(std::span< V, Extent > data) noexcept