aboutsummaryrefslogtreecommitdiff
path: root/src/server/bnetserver/Services/ConnectionService.cpp
blob: b6988e7a2658a8354a82286205e2550f83d2307d (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
/*
 * Copyright (C) 2008-2017 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 "ConnectionService.h"
#include "Duration.h"
#include "Log.h"
#include "Session.h"
#include "Util.h"
#include "BattlenetRpcErrorCodes.h"

Battlenet::Services::Connection::Connection(Session* session) : ConnectionService(session)
{
}

uint32 Battlenet::Services::Connection::HandleConnect(connection::v1::ConnectRequest const* request, connection::v1::ConnectResponse* response, std::function<void(ServiceBase*, uint32, ::google::protobuf::Message const*)>& /*continuation*/)
{
    if (request->has_client_id())
        response->mutable_client_id()->CopyFrom(request->client_id());

    std::chrono::system_clock::duration now = std::chrono::system_clock::now().time_since_epoch();

    response->mutable_server_id()->set_label(GetPID());
    response->mutable_server_id()->set_epoch(std::chrono::duration_cast<Seconds>(now).count());
    response->set_server_time(std::chrono::duration_cast<Milliseconds>(now).count());

    response->set_use_bindless_rpc(request->use_bindless_rpc());
    return ERROR_OK;
}

uint32 Battlenet::Services::Connection::HandleKeepAlive(NoData const* /*request*/)
{
    return ERROR_OK;
}

uint32 Battlenet::Services::Connection::HandleRequestDisconnect(connection::v1::DisconnectRequest const* request)
{
    connection::v1::DisconnectNotification disconnectNotification;
    disconnectNotification.set_error_code(request->error_code());
    ForceDisconnect(&disconnectNotification);

    _session->DelayedCloseSocket();
    return ERROR_OK;
}