aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Server/BattlenetServerManager.cpp
blob: 7f6c1676c1f913dc8a1a81f0c7a8c17b0292578c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
 * 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 "Config.h"
#include "World.h"
#include "ZmqContext.h"
#include "BattlenetServerManager.h"

void Battlenet::ServerManager::InitializeConnection()
{
    std::string bnetserverAddress = sConfigMgr->GetStringDefault("BnetServer.Address", "127.0.0.1");
    int32 bnetserverPort = sConfigMgr->GetIntDefault("BnetServer.Port", 1118);
    _socket = new ZmqMux("inproc://bnetmgr", "tcp://" + bnetserverAddress + ":" + std::to_string(bnetserverPort));
    _socket->Start();
}

void Battlenet::ServerManager::CloseConnection()
{
    _socket->End();
    delete _socket;
    _socket = nullptr;
}

Battlenet::Header Battlenet::ServerManager::CreateHeader(BnetCommands command)
{
    Header header;
    header.Ipc.Channel = IPC_CHANNEL_BNET;
    header.Ipc.Command = command;
    header.Realm = realmHandle;
    return header;
}

void Battlenet::ServerManager::SendChangeToonOnlineState(uint32 battlenetAccountId, uint32 gameAccountId, ObjectGuid guid, std::string const& name, bool online)
{
    // Do nothing for Grunt login
    if (!battlenetAccountId)
        return;

    Header header = CreateHeader(BNET_CHANGE_TOON_ONLINE_STATE);
    ToonHandle toon;
    toon.AccountId = battlenetAccountId;
    toon.GameAccountId = gameAccountId;
    toon.Guid = guid.GetCounter();
    toon.Name = name;

    zmqpp::message msg;
    msg << header;
    msg << toon;
    msg << online;

    _socket->Send(&msg);
}