Horizon Official Technical Documentation
Horizon::Auth::AuthSession Class Reference

#include <AuthSession.hpp>

+ Inheritance diagram for Horizon::Auth::AuthSession:
+ Collaboration diagram for Horizon::Auth::AuthSession:

Public Member Functions

 AuthSession (uint64_t uid)
 
 ~AuthSession ()
 
void initialize () override
 
virtual void update (uint32_t diff) override
 
std::unique_ptr< AuthClientInterface > & clif ()
 
std::unique_ptr< ClientPacketLengthTable > & pkt_tbl ()
 
void transmit_buffer (ByteBuffer _buffer, std::size_t size)
 
- Public Member Functions inherited from Horizon::Networking::Session< AuthSocket, AuthSession >
 Session (uint64_t uid)
 
virtual ~Session ()
 
std::shared_ptr< AuthSocket > get_socket ()
 Get the socket. More...
 
void set_socket (std::weak_ptr< AuthSocket > socket)
 Set the socket. More...
 
virtual void update (uint32_t diff)=0
 
virtual void initialize ()=0
 
bool is_initialized ()
 Called to verify if the session is initialized. More...
 
void set_initialized (bool initialized)
 Set whether the session is initialized or not. More...
 
uint64_t get_session_id ()
 Get the unique id of the session. More...
 
ThreadSafeQueue< ByteBuffer > & get_recv_queue ()
 Receive queue of the buffer received by the socket. More...
 

Private Attributes

std::unique_ptr< AuthClientInterface_clif
 
std::unique_ptr< ClientPacketLengthTable_pkt_tbl
 

Constructor & Destructor Documentation

◆ AuthSession()

AuthSession::AuthSession ( uint64_t  uid)
39: Networking::Session<AuthSocket, AuthSession>(uid)
40{
41}

◆ ~AuthSession()

AuthSession::~AuthSession ( )
44{
45 //
46}

Member Function Documentation

◆ clif()

std::unique_ptr< AuthClientInterface > & Horizon::Auth::AuthSession::clif ( )
inline
65{ return _clif; }
std::unique_ptr< AuthClientInterface > _clif
Definition: AuthSession.hpp:71

References _clif.

◆ initialize()

void AuthSession::initialize ( )
overridevirtual

Called when the session is started. Virtual method that must be implmented by the derived class. Typically used to initialize the session.

Returns
void

Implements Horizon::Networking::Session< AuthSocket, AuthSession >.

49{
50 _pkt_tbl = std::make_unique<ClientPacketLengthTable>(shared_from_this());
51 _clif = std::make_unique<AuthClientInterface>(shared_from_this());
52 set_initialized(true);
53}
std::unique_ptr< ClientPacketLengthTable > _pkt_tbl
Definition: AuthSession.hpp:72
void set_initialized(bool initialized)
Set whether the session is initialized or not.
Definition: Session.hpp:93

References _clif, _pkt_tbl, and Horizon::Networking::Session< AuthSocket, AuthSession >::set_initialized().

+ Here is the call graph for this function:

◆ pkt_tbl()

std::unique_ptr< ClientPacketLengthTable > & Horizon::Auth::AuthSession::pkt_tbl ( )
inline
66{ return _pkt_tbl; }

References _pkt_tbl.

◆ transmit_buffer()

void AuthSession::transmit_buffer ( ByteBuffer  _buffer,
std::size_t  size 
)
56{
57 if (get_socket() == nullptr || !get_socket()->is_open())
58 return;
59
60 if (!_buffer.is_empty()) {
61 uint16_t packet_id = 0x0;
62 int16_t packet_len = 0;
63
64 memcpy(&packet_id, _buffer.get_read_pointer(), sizeof(int16_t));
65
66 std::pair<int16_t, std::shared_ptr<Base::NetworkPacket<AuthSession>>> p;
67 p = _pkt_tbl->get_tpacket_info(packet_id);
68
69 if (p.first == 0) { // Check if packet sending is a handled packet.
70 p = _pkt_tbl->get_hpacket_info(packet_id);
71 if (p.first == 0) {
72 HLog(warning) << "Trying to send packet 0x" << std::hex << packet_id << " which is unknown... ignoring.";
73 return;
74 }
75 }
76
77 if (p.first == -1) {
78 memcpy(&packet_len, _buffer.get_read_pointer() + 2, sizeof(int16_t));
79 } else {
80 packet_len = p.first;
81 }
82
83 if (packet_len != _buffer.active_length()) {
84 HLog(warning) << "Packet 0x" << std::hex << packet_id << " has length len " << std::dec << packet_len << " but buffer has " << _buffer.active_length() << " bytes... ignoring.";
85 return;
86 }
87
88 get_socket()->queue_buffer(std::move(_buffer));
89 }
90}
#define HLog(type)
Definition: Logger.hpp:122
bool is_empty() const
Definition: ByteBuffer.hpp:336
uint8_t * get_read_pointer()
Definition: ByteBuffer.hpp:327
size_t active_length() const
Definition: ByteBuffer.hpp:333
std::shared_ptr< AuthSocket > get_socket()
Get the socket.
Definition: Session.hpp:70

References _pkt_tbl, ByteBuffer::active_length(), ByteBuffer::get_read_pointer(), Horizon::Networking::Session< AuthSocket, AuthSession >::get_socket(), HLog, and ByteBuffer::is_empty().

+ Here is the call graph for this function:

◆ update()

void AuthSession::update ( uint32_t  diff)
overridevirtual

Called when the session is started. Virtual method that must be implmented by the derived class. Typically used to update the session and process packets.

Returns
void

Implements Horizon::Networking::Session< AuthSocket, AuthSession >.

93{
94 std::shared_ptr<ByteBuffer> read_buf;
95 while ((read_buf = get_recv_queue().try_pop())) {
96 uint16_t packet_id = 0x0;
97 memcpy(&packet_id, read_buf->get_read_pointer(), sizeof(uint16_t));
98 HPacketTablePairType p = _pkt_tbl->get_hpacket_info(packet_id);
99 p.second->handle(std::move(*read_buf));
100 }
101}
ThreadSafeQueue< ByteBuffer > & get_recv_queue()
Receive queue of the buffer received by the socket.
Definition: Session.hpp:101
std::pair< int16_t, HPacketStructPtrType > HPacketTablePairType
Definition: PacketLengthTable.hpp:41

References _pkt_tbl, and Horizon::Networking::Session< AuthSocket, AuthSession >::get_recv_queue().

+ Here is the call graph for this function:

Member Data Documentation

◆ _clif

std::unique_ptr<AuthClientInterface> Horizon::Auth::AuthSession::_clif
private

Referenced by clif(), and initialize().

◆ _pkt_tbl

std::unique_ptr<ClientPacketLengthTable> Horizon::Auth::AuthSession::_pkt_tbl
private

The documentation for this class was generated from the following files: