8#ifndef RTYPE_SERVER_NETWORK_HPP_
9 #define RTYPE_SERVER_NETWORK_HPP_
19 #include <unordered_map>
52 void start(
void)
override;
58 void stop(
void)
override;
79 std::optional<net::NetworkEvent>
pollEvent(
void)
override;
106 std::unordered_map<uint32_t,
115 std::unordered_map<asio::ip::udp::endpoint,
Logger declaration with support for multiple log levels.
Network packet implementation for R-Type protocol.
Interface for network event handling.
Interface for network operations.
Network packet with header and serializable body.
Implementation ASIO du serveur réseau (TCP + UDP)
void start(void) override
Start the network server.
void sendPacket(uint32_t sessionId, const net::Packet &packet, net::NetworkMode mode)
Send a packet to a specific session.
std::optional< net::NetworkEvent > pollEvent(void) override
Poll for a network event.
std::mutex _sessionsMutex
Mutex for protecting access to the sessions map.
uint32_t _nextSessionId
Next session ID to assign to a new connection.
std::unordered_map< asio::ip::udp::endpoint, uint32_t > _udpEndpointToSessionId
Map of UDP endpoints to session IDs.
std::mutex _udpMapMutex
Mutex for protecting access to the UDP endpoint map.
void broadcastPacket(const net::Packet &packet, net::NetworkMode mode)
Broadcast a packet to all connected sessions.
asio::ip::tcp::acceptor _acceptor
TCP acceptor for incoming connections.
std::queue< net::NetworkEvent > _eventQueue
Queue of network events to be processed.
std::unordered_map< uint32_t, std::shared_ptr< net::Session > > _sessions
Map of active sessions indexed by session ID.
void publishEvent(net::NetworkEvent event) override
Publish a network event to be processed.
std::array< char, 4096 > _udpBuffer
Buffer for receiving UDP packets.
std::mutex _eventQueueMutex
Mutex for protecting access to the event queue.
asio::ip::udp::endpoint _udpRemoteEndpoint
Remote endpoint for the last received UDP packet.
~ServerNetwork() override
Destructor for ServerNetwork.
asio::ip::udp::socket _udpSocket
UDP socket for receiving and sending datagrams.
void acceptConnection()
Accept incoming TCP connections.
std::thread _ioThread
Thread running the ASIO I/O context.
void receiveUdpPacket()
Receive incoming UDP packets.
asio::io_context _ioContext
ASIO I/O context for managing asynchronous operations.
void stop(void) override
Stop the network server.
NetworkMode
Enum representing network transmission modes.
File : GameManager.hpp License: MIT Author : Elias Josué HAJJAR LLAUQUEN elias-josue....
Represents a network event containing session ID and packet data.