Horizon Official Technical Documentation
InterServerAPI.hpp
Go to the documentation of this file.
1/***************************************************
2 * _ _ _ *
3 * | | | | (_) *
4 * | |_| | ___ _ __ _ _______ _ __ *
5 * | _ |/ _ \| '__| |_ / _ \| '_ \ *
6 * | | | | (_) | | | |/ / (_) | | | | *
7 * \_| |_/\___/|_| |_/___\___/|_| |_| *
8 ***************************************************
9 * This file is part of Horizon (c).
10 * Copyright (c) 2019 Sagun K. (sagunxp@gmail.com).
11 * Copyright (c) 2019 Horizon Dev Team.
12 *
13 * Base Author - Sagun K. (sagunxp@gmail.com)
14 *
15 * This library is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation, either version 3 of the License, or
18 * (at your option) any later version.
19 *
20 * This library is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this library. If not, see <http://www.gnu.org/licenses/>.
27 **************************************************/
28
29#ifndef HORIZON_INTERFACES_INTERSERVERAPI_HPP
30#define HORIZON_INTERFACES_INTERSERVERAPI_HPP
31
32#include "Server/Common/Models/GameAccount.hpp"
33#include "Server/Common/Models/SessionData.hpp"
34
35#include <stdio.h>
36#include <memory>
37
38namespace Horizon
39{
40namespace Interface
41{
42template <class SessionType>
44{
45public:
47 {
48 //
49 }
50
52 {
53 //
54 }
55
63 std::shared_ptr<Horizon::Models::SessionData> get_session_data(uint32_t auth_code)
64 {
65 std::shared_ptr<SessionData> session_data = std::make_shared<Horizon::Models::SessionData>();
66 PACKET_CI_SESSION_REQ send_pkt;
67 PACKET_IC_SESSION_REQ_ACK recv_pkt;
68
69 send_pkt.auth_code = auth_code;
70
71 if (_inter_socket != nullptr
72 && _inter_socket->get_session()->get_packet_handler()->send_and_receive_packet(send_pkt, &recv_pkt) == Horizon::Base::inter_packets::IC_SESSION_REQ_ACK) {
73 *session_data << recv_pkt.s;
74 return session_data;
75 }
76
77 return nullptr;
78 }
79
81 {
82 if (_inter_socket != nullptr)
83 _inter_socket->get_session()->get_packet_handler()->Send_CI_CONNECT_AUTH();
84 }
85
91 void delete_session(uint32_t auth_code)
92 {
93 if (_inter_socket != nullptr)
94 _inter_socket->get_session()->get_packet_handler()->Send_CI_SESSION_DEL(auth_code);
95 }
96
101 void store_session_data(std::shared_ptr<Horizon::Models::SessionData> const &session_data)
102 {
103 if (_inter_socket != nullptr)
104 _inter_socket->get_session()->get_packet_handler()->Send_CI_SESSION_SET(*session_data);
105 }
106
114 std::shared_ptr<Horizon::Models::GameAccount> get_game_account(uint32_t account_id)
115 {
116 std::shared_ptr<Horizon::Models::GameAccount> game_account = std::make_shared<Horizon::Models::GameAccount>();
117 PACKET_CI_GAME_ACCOUNT_REQ send_pkt;
118 PACKET_IC_GAME_ACCOUNT_REQ_ACK recv_pkt;
119
120 send_pkt.account_id = account_id;
121
122 if (_inter_socket != nullptr
123 && _inter_socket->get_session()->get_packet_handler()->send_and_receive_packet(send_pkt, &recv_pkt) == Horizon::Base::inter_packets::IC_GAME_ACCOUNT_REQ_ACK) {
124 *game_account << recv_pkt.s;
125 return game_account;
126 }
127
128 return nullptr;
129 }
130
136 void delete_game_account(uint32_t account_id)
137 {
138 if (_inter_socket != nullptr)
139 _inter_socket->get_session()->get_packet_handler()->Send_CI_GAME_ACCOUNT_DEL(account_id);
140 }
141
146 void store_game_account(std::shared_ptr<Horizon::Models::GameAccount> game_account)
147 {
148 if (_inter_socket != nullptr)
149 _inter_socket->get_session()->get_packet_handler()->Send_CI_GAME_ACCOUNT_SET(*game_account);
150 }
151
153 {
154 PACKET_CI_PING send_pkt;
155 PACKET_IC_PONG recv_pkt;
156
157 if (_inter_socket != nullptr && _inter_socket->get_session() && _inter_socket->get_session()->get_packet_handler()
158 &&_inter_socket->get_session()->get_packet_handler()->send_and_receive_packet(send_pkt, &recv_pkt) == Horizon::Base::inter_packets::IC_PONG)
159 return true;
160
161 return false;
162 }
163
164 std::shared_ptr<SessionType> get_inter_socket() { return std::atomic_load(&_inter_socket); }
165 void set_inter_socket(std::shared_ptr<SessionType> socket) { std::atomic_store(&_inter_socket, socket); }
166
167private:
168 std::shared_ptr<SessionType> _inter_socket;
169};
170}
171}
172
173#endif /* HORIZON_INTERFACES_INTER_SERVER_HPP */
Definition: InterServerAPI.hpp:44
std::shared_ptr< Horizon::Models::SessionData > get_session_data(uint32_t auth_code)
Obtain session data from the inter-server.
Definition: InterServerAPI.hpp:63
virtual ~InterServerAPI()
Definition: InterServerAPI.hpp:51
void request_authorisation()
Definition: InterServerAPI.hpp:80
std::shared_ptr< SessionType > _inter_socket
Definition: InterServerAPI.hpp:168
bool ping_inter_server()
Definition: InterServerAPI.hpp:152
void delete_game_account(uint32_t account_id)
Request inter to delete a game account from the server's storage.
Definition: InterServerAPI.hpp:136
void set_inter_socket(std::shared_ptr< SessionType > socket)
Definition: InterServerAPI.hpp:165
void delete_session(uint32_t auth_code)
Request inter to delete a session from the server's storage.
Definition: InterServerAPI.hpp:91
std::shared_ptr< Horizon::Models::GameAccount > get_game_account(uint32_t account_id)
Obtain game account data from the inter-server.
Definition: InterServerAPI.hpp:114
void store_session_data(std::shared_ptr< Horizon::Models::SessionData > const &session_data)
Insert or Update session data into the inter server storage.
Definition: InterServerAPI.hpp:101
void store_game_account(std::shared_ptr< Horizon::Models::GameAccount > game_account)
Insert or Update game account data into the inter server storage.
Definition: InterServerAPI.hpp:146
InterServerAPI()
Definition: InterServerAPI.hpp:46
std::shared_ptr< SessionType > get_inter_socket()
Definition: InterServerAPI.hpp:164
Definition: Element.hpp:7