TrinityCore
Loading...
Searching...
No Matches
ConnectionService.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 "ConnectionService.h"
20#include "Session.h"
21#include "Timer.h"
22#include "Util.h"
23
24namespace Battlenet::Services
25{
26namespace V1
27{
31
32uint32 Connection::HandleConnect(connection::v1::ConnectRequest const* request, connection::v1::ConnectResponse* response, std::function<void(ServiceBase*, uint32, ::google::protobuf::Message const*)>& /*continuation*/)
33{
34 std::chrono::system_clock::duration now = std::chrono::system_clock::now().time_since_epoch();
35
36 response->mutable_server_id()->set_label(GetPID());
37 response->mutable_server_id()->set_epoch(std::chrono::duration_cast<Seconds>(now - Milliseconds(getMSTime())).count());
38 if (!request->has_client_id())
39 {
40 response->mutable_client_id()->set_label(_session->GetSessionId());
41 response->mutable_client_id()->set_epoch(std::chrono::duration_cast<Seconds>(_session->GetCreationTime().time_since_epoch()).count());
42 }
43 else
44 response->mutable_client_id()->CopyFrom(request->client_id());
45
46 response->set_server_time(std::chrono::duration_cast<Milliseconds>(now).count());
47
48 response->set_use_bindless_rpc(request->use_bindless_rpc());
49
50 response->set_ciid(Trinity::StringFormat("{:08X}{:08X}-{:08X}{:08X}",
51 response->server_id().label(), response->server_id().epoch(),
52 response->client_id().label(), response->client_id().epoch()));
53
54 _session->SetClientInstanceId(response->ciid());
55
56 return ERROR_OK;
57}
58
59uint32 Connection::HandleKeepAlive(NoData const* /*request*/)
60{
61 return ERROR_OK;
62}
63
64uint32 Connection::HandleRequestDisconnect(connection::v1::DisconnectRequest const* request)
65{
66 connection::v1::DisconnectNotification disconnectNotification;
67 disconnectNotification.set_error_code(request->error_code());
68 ForceDisconnect(&disconnectNotification);
69
71 return ERROR_OK;
72}
73}
74}
uint32_t uint32
Definition Define.h:154
std::chrono::milliseconds Milliseconds
Milliseconds shorthand typedef.
Definition Duration.h:24
uint32 getMSTime()
Definition Timer.h:33
uint32 GetPID()
Definition Util.cpp:291
uint32 HandleRequestDisconnect(connection::v1::DisconnectRequest const *request) override
uint32 HandleConnect(connection::v1::ConnectRequest const *request, connection::v1::ConnectResponse *response, std::function< void(ServiceBase *, uint32, ::google::protobuf::Message const *)> &continuation) override
uint32 HandleKeepAlive(NoData const *request) override
void DelayedCloseSocket()
Definition Session.h:92
SystemTimePoint GetCreationTime() const
Definition Session.h:97
uint32 GetSessionId() const
Definition Session.h:96
void SetClientInstanceId(std::string const &ciid)
Definition Session.h:98
std::string StringFormat(FormatString< Args... > fmt, Args &&... args) noexcept
Default TC string format function.