|
Air-Trap 1.0.0
A multiplayer R-Type clone game engine built with C++23 and ECS architecture
|
#include <Session.hpp>
Public Member Functions | |
| Session (uint32_t id, asio::ip::tcp::socket socket, asio::ip::udp::socket &serverUdpSocket, IEventPublisher &publisher) | |
| Constructor for Session. | |
| ~Session () | |
| Destructor for Session. | |
| void | start (void) |
| Start the session's read and write operations. | |
| void | stop (void) |
| Stop the session's operations. | |
| void | send (const Packet &packet, NetworkMode mode) |
| Send a packet to the client. | |
| void | setId (uint32_t id) |
| Set the unique identifier for the session. | |
| uint32_t | getId () const |
| Get the unique identifier for the session. | |
| asio::ip::tcp::endpoint | getTcpEndpoint () const |
| Set the TCP endpoint for the session. | |
| void | setUdpEndpoint (const asio::ip::udp::endpoint &endpoint) |
| Set the UDP endpoint for the session. | |
| asio::ip::udp::endpoint | getUdpEndpoint () const |
| Get the UDP endpoint for the session. | |
Private Member Functions | |
| asio::awaitable< void > | reader (void) |
| Asynchronous reader coroutine for the session. | |
| asio::awaitable< void > | writer (void) |
| Asynchronous writer coroutine for the session. | |
Private Attributes | |
| uint32_t | _id |
| Unique identifier for the session. | |
| bool | _stopped = false |
| Flag indicating if the session is stopped. | |
| asio::ip::tcp::socket | _socket |
| TCP socket associated with the session. | |
| asio::ip::udp::socket & | _serverUdpSocket |
| Reference to the server's UDP socket. | |
| IEventPublisher & | _publisher |
| Reference to the event publisher for network events. | |
| asio::ip::udp::endpoint | _udpEndpoint {} |
| UDP endpoint associated with the session. | |
| bool | _hasUdp = false |
| Flag indicating if UDP endpoint is set. | |
| std::mutex | _writeMutex |
| Mutex for synchronizing write operations. | |
| asio::steady_timer | _timer |
| Timer for managing write operations. | |
| std::deque< Packet > | _writeQueue {} |
| Queue of packets to be written to the TCP socket. | |
Definition at line 22 of file Session.hpp.
| rtp::net::Session::Session | ( | uint32_t | id, |
| asio::ip::tcp::socket | socket, | ||
| asio::ip::udp::socket & | serverUdpSocket, | ||
| IEventPublisher & | publisher | ||
| ) |
Constructor for Session.
| id | Unique identifier for the session |
| socket | TCP socket associated with the session |
| serverUdpSocket | Reference to the server's UDP socket |
| publisher | Reference to the event publisher for network events |
Definition at line 17 of file Session.cpp.
| rtp::net::Session::~Session | ( | ) |
| uint32_t rtp::net::Session::getId | ( | ) | const |
Get the unique identifier for the session.
Definition at line 69 of file Session.cpp.
References _id.
| asio::ip::tcp::endpoint rtp::net::Session::getTcpEndpoint | ( | ) | const |
Set the TCP endpoint for the session.
| endpoint | New TCP endpoint for the session |
Definition at line 73 of file Session.cpp.
References _socket.
|
inline |
Get the UDP endpoint for the session.
Definition at line 88 of file Session.hpp.
References _udpEndpoint.
|
private |
Asynchronous reader coroutine for the session.
Definition at line 86 of file Session.cpp.
References _id, _publisher, _socket, _stopped, rtp::net::Header::ackId, rtp::net::Packet::body, rtp::net::Header::bodySize, rtp::net::Disconnect, rtp::net::Packet::from_network(), rtp::net::Packet::header, rtp::net::Header::magic, rtp::net::MAGIC_NUMBER, rtp::net::IEventPublisher::publishEvent(), rtp::net::Header::sequenceId, rtp::net::Header::sessionId, and stop().
| void rtp::net::Session::send | ( | const Packet & | packet, |
| NetworkMode | mode | ||
| ) |
Send a packet to the client.
Definition at line 51 of file Session.cpp.
References _hasUdp, _serverUdpSocket, _timer, _udpEndpoint, _writeMutex, _writeQueue, rtp::net::TCP, and rtp::net::UDP.
| void rtp::net::Session::setId | ( | uint32_t | id | ) |
Set the unique identifier for the session.
| id | New identifier for the session |
Definition at line 65 of file Session.cpp.
References _id.
| void rtp::net::Session::setUdpEndpoint | ( | const asio::ip::udp::endpoint & | endpoint | ) |
Set the UDP endpoint for the session.
| endpoint | New UDP endpoint for the session |
Definition at line 77 of file Session.cpp.
References _hasUdp, and _udpEndpoint.
| void rtp::net::Session::start | ( | void | ) |
Start the session's read and write operations.
Definition at line 33 of file Session.cpp.
References _socket.
| void rtp::net::Session::stop | ( | void | ) |
Stop the session's operations.
Definition at line 43 of file Session.cpp.
References _socket, _stopped, and _timer.
Referenced by ~Session(), reader(), and writer().
|
private |
Asynchronous writer coroutine for the session.
Definition at line 116 of file Session.cpp.
References _socket, _stopped, _timer, _writeMutex, _writeQueue, rtp::net::Packet::getBufferSequence(), and stop().
|
private |
Flag indicating if UDP endpoint is set.
Definition at line 112 of file Session.hpp.
Referenced by send(), and setUdpEndpoint().
|
private |
Unique identifier for the session.
Definition at line 104 of file Session.hpp.
|
private |
Reference to the event publisher for network events.
Definition at line 109 of file Session.hpp.
Referenced by reader().
|
private |
Reference to the server's UDP socket.
Definition at line 108 of file Session.hpp.
Referenced by send().
|
private |
TCP socket associated with the session.
Definition at line 107 of file Session.hpp.
Referenced by getTcpEndpoint(), reader(), start(), stop(), and writer().
|
private |
Flag indicating if the session is stopped.
Definition at line 105 of file Session.hpp.
|
private |
Timer for managing write operations.
Definition at line 115 of file Session.hpp.
|
private |
UDP endpoint associated with the session.
Definition at line 111 of file Session.hpp.
Referenced by getUdpEndpoint(), send(), and setUdpEndpoint().
|
private |
Mutex for synchronizing write operations.
Definition at line 114 of file Session.hpp.
|
private |
Queue of packets to be written to the TCP socket.
Definition at line 116 of file Session.hpp.