TrinityCore
BattlenetHandler.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "WorldSession.h"
19#include "BattlenetPackets.h"
21#include "ObjectDefines.h"
22
24{
25 SetRealmListSecret(changeRealmTicket.Secret);
26
28 realmListTicket.Token = changeRealmTicket.Token;
29 realmListTicket.Allow = true;
30 realmListTicket.Ticket << "WorldserverRealmListTicket";
31
32 SendPacket(realmListTicket.Write());
33}
34
36{
37 sServiceDispatcher.Dispatch(this, request.Method.GetServiceHash(), request.Method.Token, request.Method.GetMethodId(), std::move(request.Data));
38}
39
40void WorldSession::SendBattlenetResponse(uint32 serviceHash, uint32 methodId, uint32 token, pb::Message const* response)
41{
43 bnetResponse.BnetStatus = ERROR_OK;
44 bnetResponse.Method.Type = MAKE_PAIR64(methodId, serviceHash);
45 bnetResponse.Method.ObjectId = 1;
46 bnetResponse.Method.Token = token;
47
48 if (response->ByteSize())
49 {
50 bnetResponse.Data.resize(response->ByteSize());
51 response->SerializePartialToArray(bnetResponse.Data.contents(), response->ByteSize());
52 }
53
54 SendPacket(bnetResponse.Write());
55}
56
57void WorldSession::SendBattlenetResponse(uint32 serviceHash, uint32 methodId, uint32 token, uint32 status)
58{
60 bnetResponse.BnetStatus = BattlenetRpcErrorCode(status);
61 bnetResponse.Method.Type = MAKE_PAIR64(methodId, serviceHash);
62 bnetResponse.Method.ObjectId = 1;
63 bnetResponse.Method.Token = token;
64
65 SendPacket(bnetResponse.Write());
66}
67
68void WorldSession::SendBattlenetRequest(uint32 serviceHash, uint32 methodId, pb::Message const* request, std::function<void(MessageBuffer)> callback)
69{
71 SendBattlenetRequest(serviceHash, methodId, request);
72}
73
74void WorldSession::SendBattlenetRequest(uint32 serviceHash, uint32 methodId, pb::Message const* request)
75{
77 notification.Method.Type = MAKE_PAIR64(methodId, serviceHash);
78 notification.Method.ObjectId = 1;
79 notification.Method.Token = _battlenetRequestToken++;
80
81 if (request->ByteSize())
82 {
83 notification.Data.resize(request->ByteSize());
84 request->SerializePartialToArray(notification.Data.contents(), request->ByteSize());
85 }
86
87 SendPacket(notification.Write());
88}
BattlenetRpcErrorCode
uint32_t uint32
Definition: Define.h:142
uint64 MAKE_PAIR64(uint32 l, uint32 h)
Definition: ObjectDefines.h:87
#define sServiceDispatcher
void resize(size_t newsize)
Definition: ByteBuffer.h:539
uint8 * contents()
Definition: ByteBuffer.h:522
WorldPacket const * Write() override
BattlenetRpcErrorCode BnetStatus
WorldPacket const * Write() override
void HandleBattlenetRequest(WorldPackets::Battlenet::Request &request)
void SetRealmListSecret(std::array< uint8, 32 > const &secret)
void HandleBattlenetChangeRealmTicket(WorldPackets::Battlenet::ChangeRealmTicket &changeRealmTicket)
void SendPacket(WorldPacket const *packet, bool forced=false)
Send a packet to the client.
void SendBattlenetResponse(uint32 serviceHash, uint32 methodId, uint32 token, pb::Message const *response)
void SendBattlenetRequest(uint32 serviceHash, uint32 methodId, pb::Message const *request, std::function< void(MessageBuffer)> callback)
uint32 _battlenetRequestToken
std::unordered_map< uint32, std::function< void(MessageBuffer)> > _battlenetResponseCallbacks