Horizon Official Technical Documentation
CharSession.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) 2020- Horizon Dev Team.
11 *
12 * Base Author - Sagun Khosla. (sagunxp@gmail.com)
13 *
14 * This library is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this library. If not, see <http://www.gnu.org/licenses/>.
26 **************************************************/
27#ifndef HORIZON_SESSION_CHARSESSION_HPP
28#define HORIZON_SESSION_CHARSESSION_HPP
29
34
35#include <memory>
36#include <chrono>
37#include <mutex>
38
39#if CLIENT_TYPE == 'S'
41#elif CLIENT_TYPE == 'R'
43#elif CLIENT_TYPE == 'Z'
45#elif CLIENT_TYPE == 'M'
47#elif CLIENT_TYPE == 'A'
49#endif
50
51namespace Horizon
52{
53namespace Char
54{
56{
57 uint32_t _account_id{0};
58 uint32_t _auth_id{0};
59 uint32_t _group_id{0};
60 std::chrono::system_clock::time_point _connect_time;
61 uint8_t _character_slots{0};
62 uint32_t _pincode_seed{0};
63 uint8_t _pincode_tries{0};
64};
65class CharSocket;
66class CharSession : public Horizon::Networking::Session<CharSocket, CharSession>
67{
68public:
69 CharSession(uint64_t uid);
71
72 void initialize();
73 void update(uint32_t diff);
74
76
77 std::unique_ptr<CharClientInterface> &clif() { return _clif; }
78 std::unique_ptr<ClientPacketLengthTable> &pkt_tbl() { return _pkt_tbl; }
79
80 s_session_data &get_session_data() { std::lock_guard<std::mutex> lock(_sd_mutex); return _session_data; }
81 void set_session_data(s_session_data &data) { std::lock_guard<std::mutex> lock(_sd_mutex); _session_data = data; }
82
83 void transmit_buffer(ByteBuffer _buffer, std::size_t size);
84
85
86protected:
87 std::unique_ptr<CharClientInterface> _clif;
88 std::unique_ptr<ClientPacketLengthTable> _pkt_tbl;
90 std::mutex _sd_mutex;
91 bool _first_packet_sent{false};
92};
93}
94}
95#endif /* HORIZON_CHAR_SESSION_CHARSESSION_HPP */
Definition: ByteBuffer.hpp:78
Definition: CharSession.hpp:67
std::unique_ptr< ClientPacketLengthTable > & pkt_tbl()
Definition: CharSession.hpp:78
void initialize()
Definition: CharSession.cpp:47
void set_session_data(s_session_data &data)
Definition: CharSession.hpp:81
std::unique_ptr< CharClientInterface > _clif
Definition: CharSession.hpp:87
std::mutex _sd_mutex
Definition: CharSession.hpp:90
std::unique_ptr< ClientPacketLengthTable > _pkt_tbl
Definition: CharSession.hpp:88
CharSession(uint64_t uid)
Definition: CharSession.cpp:37
s_session_data & get_session_data()
Definition: CharSession.hpp:80
s_session_data _session_data
Definition: CharSession.hpp:89
std::unique_ptr< CharClientInterface > & clif()
Definition: CharSession.hpp:77
void transmit_buffer(ByteBuffer _buffer, std::size_t size)
Definition: CharSession.cpp:54
~CharSession()
Definition: CharSession.cpp:42
void update(uint32_t diff)
Definition: CharSession.cpp:93
bool _first_packet_sent
Definition: CharSession.hpp:91
A Session object that handles a single socket. Sockets are moved into the thread by SocketMgr,...
Definition: Session.hpp:55
Definition: Element.hpp:7
Definition: CharSession.hpp:56
uint32_t _account_id
Definition: CharSession.hpp:57
uint32_t _group_id
Definition: CharSession.hpp:59
uint8_t _character_slots
Definition: CharSession.hpp:61
uint32_t _auth_id
Definition: CharSession.hpp:58
uint32_t _pincode_seed
Definition: CharSession.hpp:62
std::chrono::system_clock::time_point _connect_time
Definition: CharSession.hpp:60
uint8_t _pincode_tries
Definition: CharSession.hpp:63