High-performance UDP server implementation using ASIO library. More...
#include <AsioServer.hpp>
Inheritance diagram for srv::AsioServer:
Collaboration diagram for srv::AsioServer:Public Member Functions | |
| AsioServer () | |
| Constructor. | |
| ~AsioServer () override | |
| Destructor. | |
| const std::string | getName () const override |
| utl::PluginType | getType () const override |
| void | init (const std::string &host, std::uint16_t port) override |
| void | start () override |
| void | stop () override |
| void | update () override |
| void | sendToClient (std::uint32_t sessionId, const std::vector< std::uint8_t > &data, bool reliable=false) override |
| void | sendToAllClients (const std::vector< std::uint8_t > &data, bool reliable=false) override |
| void | disconnectClient (std::uint32_t sessionId) override |
| std::size_t | getClientCount () const override |
| std::vector< std::uint32_t > | getConnectedSessions () const override |
| bool | isRunning () const override |
| void | setTickRate (std::uint16_t tickRate) override |
| void | setServerCapabilities (std::uint32_t caps) override |
Public Member Functions inherited from srv::INetworkServer | |
| virtual | ~INetworkServer ()=default |
| virtual void | init (const std::string &host, uint16_t port)=0 |
Public Member Functions inherited from utl::IPlugin | |
| virtual | ~IPlugin ()=default |
Private Member Functions | |
| void | setupPacketHandlers () |
| Initialize packet handlers. | |
| void | startReceive () |
| Start receiving packets asynchronously. | |
| void | handleReceive (std::size_t bytesReceived) |
| Handle received packet. | |
| void | networkThreadLoop () const |
| Network thread main loop. | |
| std::uint32_t | generateSessionId () const |
| Generate unique session ID. | |
| std::string | endpointToString (const asio::ip::udp::endpoint &endpoint) |
| Get endpoint string representation. | |
| void | sendPacketImmediate (const std::vector< std::uint8_t > &data, const asio::ip::udp::endpoint &destination) |
| Send packet immediately. | |
| rnp::HandlerResult | handleConnect (const rnp::PacketConnect &packet, const rnp::PacketContext &context) |
| Handle CONNECT packet. | |
| rnp::HandlerResult | handleDisconnect (const rnp::PacketDisconnect &packet, const rnp::PacketContext &context) |
| Handle DISCONNECT packet. | |
| rnp::HandlerResult | handlePing (const rnp::PacketPingPong &packet, const rnp::PacketContext &context) |
| Handle PING packet. | |
| rnp::HandlerResult | handlePong (const rnp::PacketPingPong &packet, const rnp::PacketContext &context) |
| Handle PONG packet. | |
| void | sendPong (std::uint32_t nonce, const asio::ip::udp::endpoint &destination, std::uint32_t sessionId) |
| Send PONG response. | |
| void | sendConnectAccept (std::uint32_t sessionId, const asio::ip::udp::endpoint &destination) |
| Send CONNECT_ACCEPT response. | |
| void | sendError (rnp::ErrorCode errorCode, const std::string &description, const asio::ip::udp::endpoint &destination, std::uint32_t sessionId) |
| Send ERROR packet. | |
| void | updateClientManagement () |
| Update client timeouts and send pings. | |
| void | processSendQueue () |
| Process send queue. | |
| void | processEventBusEvents () |
| Process EventBus events for network operations. | |
| void | handleSendToClientEvent (const utl::Event &event) |
| Handle send to client event from EventBus. | |
| void | handleBroadcastEvent (const utl::Event &event) |
| Handle broadcast event from EventBus. | |
| void | handleSendEntityEventToClients (const utl::Event &event) |
| Handle send entity event to clients from EventBus. | |
| rnp::HandlerResult | handleEntityEvent (const std::vector< rnp::EventRecord > &events, const rnp::PacketContext &context) const |
| Handle entity event packet (including player inputs) | |
| rnp::HandlerResult | handleLobbyListRequest (const rnp::PacketContext &context) |
| Handle LOBBY_LIST_REQUEST packet. | |
| rnp::HandlerResult | handleLobbyCreate (const rnp::PacketLobbyCreate &packet, const rnp::PacketContext &context) |
| Handle LOBBY_CREATE packet. | |
| rnp::HandlerResult | handleLobbyJoin (const rnp::PacketLobbyJoin &packet, const rnp::PacketContext &context) |
| Handle LOBBY_JOIN packet. | |
| rnp::HandlerResult | handleLobbyLeave (const rnp::PacketContext &context) |
| Handle LOBBY_LEAVE packet. | |
| void | sendLobbyList (std::uint32_t sessionId) |
| Send lobby list to client. | |
| std::uint32_t | createLobby (const std::string &lobbyName, std::uint32_t hostSessionId, std::uint8_t maxPlayers, std::uint8_t gameMode) |
| Create new lobby. | |
| LobbyStatus | joinLobby (std::uint32_t lobbyId, std::uint32_t sessionId) |
| Join player to lobby. | |
| void | leaveLobby (std::uint32_t sessionId) |
| Remove player from lobby. | |
| void | broadcastLobbyUpdate (std::uint32_t lobbyId) |
| Broadcast lobby update to all lobby members. | |
| rnp::HandlerResult | handleStartGameRequest (const rnp::PacketStartGameRequest &packet, const rnp::PacketContext &context) |
| Handle START_GAME_REQUEST packet. | |
| void | broadcastGameOverToLobby (std::uint32_t lobbyId) |
| Broadcast game start to all players in lobby. | |
| void | broadcastGameStart (std::uint32_t lobbyId) |
| Broadcast game start notification to all lobby members. | |
| rnp::LobbyInfo | lobbyToLobbyInfo (const Lobby &lobby) |
| Convert Lobby to LobbyInfo for network transmission. | |
| void | sendLobbyCreateResponse (std::uint32_t sessionId, std::uint32_t lobbyId, bool success, rnp::ErrorCode errorCode=rnp::ErrorCode::INTERNAL_ERROR) |
| Send lobby create response. | |
| void | sendLobbyJoinResponse (std::uint32_t sessionId, std::uint32_t lobbyId, bool success, rnp::ErrorCode errorCode, const rnp::LobbyInfo *lobbyInfo=nullptr) |
| Send lobby join response. | |
| void | handleGameOverEvent (const utl::Event &event) |
| Handle GAME_OVER event from game server. | |
| void | broadcastGameOverToLobby (std::uint32_t lobbyId, const std::vector< std::uint8_t > &gameOverData) |
| Broadcast GAME_OVER packet to all players in a lobby. | |
| void | cleanupEmptyLobbies () |
| Clean up empty lobbies. | |
Private Attributes | |
| std::unique_ptr< asio::io_context > | m_ioContext |
| ASIO I/O context for async operations. | |
| std::unique_ptr< asio::ip::udp::socket > | m_socket |
| UDP socket for network communication. | |
| std::unique_ptr< std::thread > | m_networkThread |
| Dedicated network thread. | |
| std::string | m_host |
| Server bind address (e.g., "0.0.0.0") | |
| std::uint16_t | m_port |
| Server listening port (default: 4567) | |
| std::uint16_t | m_tickRate |
| Server tick rate in Hz. | |
| std::uint32_t | m_serverCaps |
| Server capability flags. | |
| std::atomic< bool > | m_running |
| Server running state (atomic for thread safety) | |
| std::atomic< bool > | m_started |
| Server started state. | |
| std::unordered_map< std::uint32_t, ClientSession > | m_clients |
| Map of session ID to client session. | |
| std::unordered_map< std::string, std::uint32_t > | m_endpointToSession |
| Map of endpoint string to session ID. | |
| std::uint32_t | m_nextSessionId |
| Next available session ID. | |
| std::mutex | m_clientsMutex |
| Mutex for thread-safe client access. | |
| std::unordered_map< std::uint32_t, Lobby > | m_lobbies |
| Map of lobby ID to lobby data. | |
| std::uint32_t | m_nextLobbyId |
| Next available lobby ID. | |
| std::mutex | m_lobbiesMutex |
| Mutex for thread-safe lobby access. | |
| std::unique_ptr< rnp::HandlerPacket > | m_packetHandler |
| RNP packet handler instance. | |
| std::queue< QueuedPacket > | m_sendQueue |
| Queue of packets waiting to be sent. | |
| std::mutex | m_sendQueueMutex |
| Mutex for send queue access. | |
| std::mutex | m_socketMutex |
| Mutex for socket operations. | |
| std::array< std::uint8_t, MAX_LEN_RECV_BUFFER > | m_recvBuffer |
| Buffer for receiving UDP packets. | |
| asio::ip::udp::endpoint | m_senderEndpoint |
| Endpoint of last packet sender. | |
| std::chrono::steady_clock::time_point | m_lastPingTime |
| Timestamp of last ping sweep. | |
| std::chrono::milliseconds | m_pingInterval |
| Interval between ping sweeps (5000ms) | |
| std::chrono::milliseconds | m_clientTimeout |
| Client timeout duration (15000ms) | |
| std::uint32_t | m_componentId |
| Component ID for event bus registration. | |
| utl::EventBus & | m_eventBus |
High-performance UDP server implementation using ASIO library.
This class provides a complete multiplayer game server implementation with:
The server runs its network operations on a separate thread and communicates with the game engine via an event bus system.
Definition at line 157 of file AsioServer.hpp.
| srv::AsioServer::AsioServer | ( | ) |
Constructor.
Definition at line 21 of file asioServer.cpp.
References utl::BROADCAST_WORLD_STATE, utl::GAME_OVER, m_componentId, m_eventBus, utl::EventBus::registerComponent(), utl::SEND_ENTITY_EVENTS, utl::SEND_TO_CLIENT, setupPacketHandlers(), and utl::EventBus::subscribe().
Here is the call graph for this function:
|
override |
Destructor.
Definition at line 44 of file asioServer.cpp.
References stop().
Here is the call graph for this function:
|
private |
Broadcast game start to all players in lobby.
| lobbyId | Target lobby ID |
Broadcast game start notification to all lobby members
| lobbyId | Lobby ID that is starting |
Broadcast game over notification to lobby members
| lobbyId | Lobby ID that finished |
Referenced by handleGameOverEvent().
Here is the caller graph for this function:
|
private |
Broadcast GAME_OVER packet to all players in a lobby.
| lobbyId | Target lobby ID |
| gameOverData | Game over packet data |
Definition at line 1370 of file asioServer.cpp.
References rnp::GAME_OVER, rnp::Serializer::getData(), utl::INFO, rnp::PacketHeader::length, utl::Logger::log(), m_clients, m_clientsMutex, m_lobbies, m_lobbiesMutex, sendPacketImmediate(), rnp::Serializer::serializeHeader(), rnp::PacketHeader::sessionId, and rnp::PacketHeader::type.
Here is the call graph for this function:
|
private |
Broadcast game start notification to all lobby members.
| lobbyId | Lobby ID that is starting |
Definition at line 1641 of file asioServer.cpp.
References utl::GAME_LOGIC, rnp::GAME_START, utl::GAME_START, rnp::Serializer::getData(), utl::INFO, rnp::PacketHeader::length, rnp::PacketGameStart::lobbyId, utl::Logger::log(), m_clients, m_clientsMutex, m_eventBus, m_lobbies, m_lobbiesMutex, utl::NETWORK_SERVER, utl::EventBus::publish(), sendPacketImmediate(), rnp::Serializer::serializeGameStart(), rnp::Serializer::serializeHeader(), rnp::PacketHeader::sessionId, and rnp::PacketHeader::type.
Referenced by handleStartGameRequest().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Broadcast lobby update to all lobby members.
| lobbyId | Target lobby ID |
Broadcast lobby update to all lobby members
| lobbyId | Lobby ID to broadcast update for |
Definition at line 1409 of file asioServer.cpp.
References rnp::Serializer::getData(), utl::INFO, rnp::PacketHeader::length, rnp::LOBBY_UPDATE, rnp::PacketLobbyUpdate::lobbyInfo, lobbyToLobbyInfo(), utl::Logger::log(), m_clients, m_clientsMutex, m_lobbies, m_lobbiesMutex, sendPacketImmediate(), rnp::Serializer::serializeHeader(), rnp::Serializer::serializeLobbyUpdate(), rnp::PacketHeader::sessionId, rnp::PacketHeader::type, and update().
Referenced by disconnectClient(), handleLobbyCreate(), handleLobbyJoin(), and handleLobbyLeave().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Clean up empty lobbies.
Remove empty lobbies from server
Called periodically to clean up abandoned lobbies
Definition at line 1540 of file asioServer.cpp.
References utl::INFO, utl::Logger::log(), and m_lobbies.
Referenced by leaveLobby().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Create new lobby.
Create a new lobby
| lobbyName | Display name for the lobby |
| hostSessionId | Session ID of the lobby host |
| maxPlayers | Maximum number of players (1-8) |
| gameMode | Game mode identifier |
Definition at line 1213 of file asioServer.cpp.
References utl::INFO, utl::Logger::log(), m_lobbies, m_lobbiesMutex, m_nextLobbyId, and srv::Lobby::playerSessions.
Referenced by handleLobbyCreate().
Here is the call graph for this function:
Here is the caller graph for this function:
|
overridevirtual |
Implements srv::INetworkServer.
Definition at line 251 of file asioServer.cpp.
References broadcastLobbyUpdate(), rnp::HandlerPacket::clearSession(), rnp::CLIENT_REQUEST, rnp::DISCONNECT, endpointToString(), rnp::Serializer::getData(), utl::INFO, leaveLobby(), rnp::PacketHeader::length, utl::Logger::log(), m_clients, m_clientsMutex, m_endpointToSession, m_packetHandler, rnp::PacketDisconnect::reasonCode, sendPacketImmediate(), rnp::Serializer::serializeDisconnect(), rnp::Serializer::serializeHeader(), rnp::PacketHeader::sessionId, and rnp::PacketHeader::type.
Referenced by updateClientManagement().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Get endpoint string representation.
| endpoint | UDP endpoint |
Convert endpoint to string representation
| endpoint | UDP endpoint |
Definition at line 526 of file asioServer.cpp.
Referenced by disconnectClient(), handleConnect(), and handleDisconnect().
Here is the caller graph for this function:
|
private |
Generate unique session ID.
Generate a unique session ID
Definition at line 511 of file asioServer.cpp.
References m_clients.
Referenced by handleConnect().
Here is the caller graph for this function:
|
nodiscardoverridevirtual |
Implements srv::INetworkServer.
Definition at line 308 of file asioServer.cpp.
References m_clients, and m_clientsMutex.
|
nodiscardoverridevirtual |
Implements srv::INetworkServer.
Definition at line 314 of file asioServer.cpp.
References m_clients, and m_clientsMutex.
|
inlinenodiscardoverridevirtual |
Implements utl::IPlugin.
Definition at line 171 of file AsioServer.hpp.
|
inlinenodiscardoverridevirtual |
Implements utl::IPlugin.
Definition at line 172 of file AsioServer.hpp.
References utl::NETWORK_CLIENT.
|
private |
Handle broadcast event from EventBus.
| event | Broadcast event |
Handle broadcast event from event bus
| event | Event containing packet data to broadcast |
Definition at line 903 of file asioServer.cpp.
References utl::Event::data, and sendToAllClients().
Referenced by processEventBusEvents().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Handle CONNECT packet.
| packet | Connect packet |
| context | Packet context |
Definition at line 563 of file asioServer.cpp.
References rnp::PacketConnect::clientCaps, srv::ClientSession::clientCaps, srv::ClientSession::endpoint, endpointToString(), utl::GAME_LOGIC, generateSessionId(), srv::ClientSession::isConnected, srv::ClientSession::lastSeen, m_clients, m_clientsMutex, m_componentId, m_endpointToSession, m_eventBus, m_senderEndpoint, srv::MAX_CLIENTS, rnp::PacketConnect::nameLen, utl::PLAYER_CONNECTED, rnp::PacketConnect::playerName, srv::ClientSession::playerName, utl::EventBus::publish(), rnp::RATE_LIMITED, rnp::PacketContext::receiveTime, sendConnectAccept(), sendError(), srv::ClientSession::sessionId, and rnp::SUCCESS.
Referenced by setupPacketHandlers().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Handle DISCONNECT packet.
| packet | Disconnect packet |
| context | Packet context |
Definition at line 637 of file asioServer.cpp.
References endpointToString(), utl::GAME_LOGIC, m_clients, m_clientsMutex, m_componentId, m_endpointToSession, m_eventBus, utl::PLAYER_DISCONNECTED, utl::EventBus::publish(), rnp::PacketContext::sessionId, and rnp::SUCCESS.
Referenced by setupPacketHandlers().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Handle entity event packet (including player inputs)
| events | Entity event records |
| context | Packet context |
Definition at line 923 of file asioServer.cpp.
References utl::ENTITY_EVENT_RECEIVED, utl::GAME_LOGIC, utl::INFO, rnp::INPUT, utl::Logger::log(), m_componentId, m_eventBus, utl::PLAYER_INPUT_RECEIVED, utl::EventBus::publish(), rnp::PacketContext::sessionId, and rnp::SUCCESS.
Referenced by setupPacketHandlers().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Handle GAME_OVER event from game server.
| event | Game over event |
Handle game over event from game engine
| event | Event containing game over data |
Definition at line 1329 of file asioServer.cpp.
References broadcastGameOverToLobby(), utl::Event::data, utl::INFO, utl::Logger::log(), m_clients, m_clientsMutex, m_lobbies, and m_lobbiesMutex.
Referenced by processEventBusEvents().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Handle LOBBY_CREATE packet.
| packet | Lobby create packet |
| context | Packet context |
Definition at line 984 of file asioServer.cpp.
References rnp::ALREADY_IN_LOBBY, broadcastLobbyUpdate(), createLobby(), rnp::PacketLobbyCreate::gameMode, utl::INFO, rnp::INTERNAL_ERROR, rnp::PacketLobbyCreate::lobbyName, utl::Logger::log(), m_clients, m_clientsMutex, m_nextLobbyId, rnp::PacketLobbyCreate::maxPlayers, rnp::PacketLobbyCreate::nameLen, rnp::PROCESSING_ERROR, sendLobbyCreateResponse(), rnp::PacketContext::sessionId, rnp::SUCCESS, and rnp::UNAUTHORIZED_SESSION.
Referenced by setupPacketHandlers().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Handle LOBBY_JOIN packet.
| packet | Lobby join packet |
| context | Packet context |
Definition at line 1047 of file asioServer.cpp.
References rnp::ALREADY_IN_LOBBY, broadcastLobbyUpdate(), rnp::LobbyInfo::currentPlayers, utl::INFO, joinLobby(), rnp::LOBBY_NOT_FOUND, rnp::PacketLobbyJoin::lobbyId, lobbyToLobbyInfo(), utl::Logger::log(), m_clients, m_clientsMutex, m_lobbies, m_lobbiesMutex, rnp::LobbyInfo::maxPlayers, rnp::NONE, rnp::PROCESSING_ERROR, sendLobbyJoinResponse(), rnp::PacketContext::sessionId, rnp::SUCCESS, srv::SUCCESS, rnp::UNAUTHORIZED_SESSION, and utl::WARNING.
Referenced by setupPacketHandlers().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Handle LOBBY_LEAVE packet.
| context | Packet context |
Definition at line 1133 of file asioServer.cpp.
References broadcastLobbyUpdate(), utl::INFO, leaveLobby(), utl::Logger::log(), m_clients, m_clientsMutex, m_senderEndpoint, rnp::NOT_IN_LOBBY, rnp::PROCESSING_ERROR, sendError(), rnp::PacketContext::sessionId, rnp::SUCCESS, and rnp::UNAUTHORIZED_SESSION.
Referenced by setupPacketHandlers().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Handle LOBBY_LIST_REQUEST packet.
| context | Packet context |
Definition at line 964 of file asioServer.cpp.
References utl::INFO, utl::Logger::log(), m_clients, m_clientsMutex, m_senderEndpoint, rnp::PROCESSING_ERROR, sendError(), sendLobbyList(), rnp::PacketContext::sessionId, rnp::SUCCESS, and rnp::UNAUTHORIZED_SESSION.
Referenced by setupPacketHandlers().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Handle PING packet.
| packet | Ping packet |
| context | Packet context |
Definition at line 680 of file asioServer.cpp.
References m_clients, m_clientsMutex, m_senderEndpoint, rnp::PacketPingPong::nonce, rnp::PacketContext::receiveTime, sendPong(), rnp::PacketContext::sessionId, and rnp::SUCCESS.
Referenced by setupPacketHandlers().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Handle PONG packet.
| packet | Pong packet |
| context | Packet context |
Definition at line 697 of file asioServer.cpp.
References m_clients, m_clientsMutex, rnp::PacketContext::receiveTime, rnp::PacketPingPong::sendTimeMs, rnp::PacketContext::sessionId, and rnp::SUCCESS.
Referenced by setupPacketHandlers().
Here is the caller graph for this function:
|
private |
Handle received packet.
| bytesReceived | Number of bytes received |
Definition at line 425 of file asioServer.cpp.
References rnp::Serializer::deserializeHeader(), utl::INFO, utl::Logger::log(), m_packetHandler, m_recvBuffer, m_senderEndpoint, rnp::HandlerPacket::processPacket(), rnp::PacketContext::receiveTime, rnp::PacketContext::senderAddress, rnp::PacketContext::senderPort, rnp::PacketContext::sessionId, rnp::PacketHeader::sessionId, rnp::SUCCESS, rnp::PacketHeader::type, and utl::WARNING.
Here is the call graph for this function:
|
private |
Handle send entity event to clients from EventBus.
| event | Entity event to send to clients |
Handle entity event broadcast to clients
| event | Event containing entity event data |
Definition at line 913 of file asioServer.cpp.
References utl::Event::data, and sendToAllClients().
Referenced by processEventBusEvents().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Handle send to client event from EventBus.
| event | Send to client event |
Handle "send to client" event from event bus
| event | Event containing target session and packet data |
Definition at line 884 of file asioServer.cpp.
References utl::Event::data, and sendToClient().
Referenced by processEventBusEvents().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Handle START_GAME_REQUEST packet.
| packet | Start game request packet |
| context | Packet context |
Definition at line 1559 of file asioServer.cpp.
References broadcastGameStart(), utl::Event::data, utl::GAME_LOGIC, rnp::IN_GAME, utl::INFO, rnp::LOBBY_NOT_FOUND, rnp::PacketStartGameRequest::lobbyId, utl::Logger::log(), m_clients, m_clientsMutex, m_componentId, m_eventBus, m_lobbies, m_lobbiesMutex, m_senderEndpoint, rnp::NOT_IN_LOBBY, rnp::PROCESSING_ERROR, utl::EventBus::publish(), sendError(), utl::SERVER_START, rnp::PacketContext::sessionId, rnp::SUCCESS, and rnp::UNAUTHORIZED_SESSION.
Referenced by setupPacketHandlers().
Here is the call graph for this function:
Here is the caller graph for this function:
|
override |
Definition at line 51 of file asioServer.cpp.
|
nodiscardoverridevirtual |
Implements srv::INetworkServer.
Definition at line 328 of file asioServer.cpp.
References m_running.
|
private |
Join player to lobby.
| lobbyId | Target lobby ID |
| sessionId | Player session ID |
Join an existing lobby
| lobbyId | Target lobby ID |
| sessionId | Joining client's session ID |
Definition at line 1231 of file asioServer.cpp.
References srv::ALREADY_IN_LOBBY, srv::FULL, srv::IN_GAME, utl::INFO, utl::Logger::log(), m_lobbies, m_lobbiesMutex, srv::Lobby::maxPlayers, srv::NOT_FOUND, srv::Lobby::playerSessions, srv::Lobby::status, srv::SUCCESS, rnp::WAITING, and utl::WARNING.
Referenced by handleLobbyJoin().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Remove player from lobby.
| sessionId | Player session ID |
Remove a client from their current lobby
| sessionId | Client's session ID |
Definition at line 1277 of file asioServer.cpp.
References cleanupEmptyLobbies(), utl::INFO, utl::Logger::log(), m_clients, m_clientsMutex, m_lobbies, and m_lobbiesMutex.
Referenced by disconnectClient(), and handleLobbyLeave().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Convert Lobby to LobbyInfo for network transmission.
| lobby | Lobby structure |
Convert internal Lobby struct to RNP LobbyInfo
| lobby | Internal lobby structure |
Definition at line 1455 of file asioServer.cpp.
References rnp::LobbyInfo::currentPlayers, rnp::LobbyInfo::gameMode, srv::Lobby::gameMode, rnp::LobbyInfo::hostSessionId, srv::Lobby::hostSessionId, rnp::LobbyInfo::lobbyId, srv::Lobby::lobbyId, rnp::LobbyInfo::lobbyName, srv::Lobby::lobbyName, m_clients, m_clientsMutex, rnp::LobbyInfo::maxPlayers, srv::Lobby::maxPlayers, rnp::LobbyInfo::playerNames, srv::Lobby::playerSessions, rnp::LobbyInfo::status, and srv::Lobby::status.
Referenced by broadcastLobbyUpdate(), handleLobbyJoin(), and sendLobbyList().
Here is the caller graph for this function:
|
private |
Network thread main loop.
Main network thread loop
Runs the ASIO io_context and handles network events
Definition at line 476 of file asioServer.cpp.
References m_ioContext, and m_running.
Referenced by start().
Here is the caller graph for this function:
|
private |
Process EventBus events for network operations.
Process events from the event bus
Handles events from game engine (sends, broadcasts, etc.)
Definition at line 851 of file asioServer.cpp.
References utl::BROADCAST_WORLD_STATE, utl::EventBus::consumeForTarget(), utl::GAME_OVER, handleBroadcastEvent(), handleGameOverEvent(), handleSendEntityEventToClients(), handleSendToClientEvent(), m_componentId, m_eventBus, utl::SEND_ENTITY_EVENTS, and utl::SEND_TO_CLIENT.
Referenced by update().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Process send queue.
Process outgoing packet queue
Sends all queued packets via UDP socket
Definition at line 840 of file asioServer.cpp.
References srv::QueuedPacket::data, srv::QueuedPacket::destination, m_sendQueue, m_sendQueueMutex, and sendPacketImmediate().
Referenced by update().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Send CONNECT_ACCEPT response.
| sessionId | New session ID |
| destination | Target endpoint |
Definition at line 737 of file asioServer.cpp.
References rnp::CONNECT_ACCEPT, rnp::Serializer::getData(), m_serverCaps, m_tickRate, rnp::MAX_PAYLOAD, sendPacketImmediate(), rnp::Serializer::serializeConnectAccept(), rnp::Serializer::serializeHeader(), rnp::PacketConnectAccept::sessionId, and rnp::PacketHeader::type.
Referenced by handleConnect().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Send ERROR packet.
| errorCode | Error code |
| description | Error description |
| destination | Target endpoint |
| sessionId | Session ID |
Definition at line 765 of file asioServer.cpp.
References rnp::PacketError::errorCode, rnp::Serializer::getData(), rnp::PACKET_ERROR, sendPacketImmediate(), rnp::Serializer::serializeError(), rnp::Serializer::serializeHeader(), and rnp::PacketHeader::type.
Referenced by handleConnect(), handleLobbyLeave(), handleLobbyListRequest(), and handleStartGameRequest().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Send lobby create response.
| sessionId | Target client session ID |
| lobbyId | Created lobby ID (0 if failed) |
| success | Success status |
| errorCode | Error code if failed |
Definition at line 1486 of file asioServer.cpp.
References rnp::PacketLobbyCreateResponse::errorCode, rnp::Serializer::getData(), utl::INFO, rnp::PacketHeader::length, rnp::LOBBY_CREATE_RESPONSE, rnp::PacketLobbyCreateResponse::lobbyId, utl::Logger::log(), m_senderEndpoint, sendPacketImmediate(), rnp::Serializer::serializeHeader(), rnp::Serializer::serializeLobbyCreateResponse(), rnp::PacketHeader::sessionId, rnp::PacketLobbyCreateResponse::success, and rnp::PacketHeader::type.
Referenced by handleLobbyCreate().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Send lobby join response.
| sessionId | Target client session ID |
| lobbyId | Target lobby ID |
| success | Success status |
| errorCode | Error code if failed |
| lobbyInfo | Lobby information if successful |
Send lobby join response to client
| sessionId | Requesting client's session ID |
| lobbyId | Target lobby ID |
| success | Whether join succeeded |
| errorCode | Error code if failed |
| lobbyInfo | Current lobby info (if success) |
Definition at line 1511 of file asioServer.cpp.
References rnp::PacketLobbyJoinResponse::errorCode, rnp::Serializer::getData(), utl::INFO, rnp::PacketHeader::length, rnp::LOBBY_JOIN_RESPONSE, rnp::PacketLobbyJoinResponse::lobbyId, rnp::PacketLobbyJoinResponse::lobbyInfo, utl::Logger::log(), m_senderEndpoint, sendPacketImmediate(), rnp::Serializer::serializeHeader(), rnp::Serializer::serializeLobbyJoinResponse(), rnp::PacketHeader::sessionId, rnp::PacketLobbyJoinResponse::success, and rnp::PacketHeader::type.
Referenced by handleLobbyJoin().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Send lobby list to client.
| sessionId | Target client session ID |
Send lobby list to requesting client
| sessionId | Requesting client's session ID |
Definition at line 1173 of file asioServer.cpp.
References rnp::LobbyInfo::currentPlayers, rnp::Serializer::getData(), utl::INFO, rnp::PacketHeader::length, rnp::PacketLobbyListResponse::lobbies, rnp::LOBBY_LIST_RESPONSE, rnp::PacketLobbyListResponse::lobbyCount, rnp::LobbyInfo::lobbyId, lobbyToLobbyInfo(), utl::Logger::log(), m_lobbies, m_lobbiesMutex, m_senderEndpoint, rnp::LobbyInfo::maxPlayers, sendPacketImmediate(), rnp::Serializer::serializeHeader(), rnp::Serializer::serializeLobbyListResponse(), rnp::PacketHeader::sessionId, and rnp::PacketHeader::type.
Referenced by handleLobbyListRequest().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Send packet immediately.
| data | Packet data |
| destination | Target endpoint |
Definition at line 531 of file asioServer.cpp.
References utl::INFO, utl::Logger::log(), m_running, m_socket, m_socketMutex, and utl::WARNING.
Referenced by broadcastGameOverToLobby(), broadcastGameStart(), broadcastLobbyUpdate(), disconnectClient(), processSendQueue(), sendConnectAccept(), sendError(), sendLobbyCreateResponse(), sendLobbyJoinResponse(), sendLobbyList(), sendPong(), and stop().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Send PONG response.
| nonce | Ping nonce |
| destination | Target endpoint |
| sessionId | Client session ID |
Definition at line 717 of file asioServer.cpp.
References rnp::Serializer::getData(), rnp::PacketPingPong::nonce, rnp::PONG, sendPacketImmediate(), rnp::Serializer::serializeHeader(), rnp::Serializer::serializePingPong(), and rnp::PacketHeader::type.
Referenced by handlePing().
Here is the call graph for this function:
Here is the caller graph for this function:
|
overridevirtual |
Implements srv::INetworkServer.
Definition at line 237 of file asioServer.cpp.
References m_clients, m_clientsMutex, m_sendQueue, and m_sendQueueMutex.
Referenced by handleBroadcastEvent(), and handleSendEntityEventToClients().
Here is the caller graph for this function:
|
overridevirtual |
Implements srv::INetworkServer.
Definition at line 222 of file asioServer.cpp.
References m_clients, m_clientsMutex, m_sendQueue, and m_sendQueueMutex.
Referenced by handleSendToClientEvent().
Here is the caller graph for this function:
|
overridevirtual |
Implements srv::INetworkServer.
Definition at line 336 of file asioServer.cpp.
References m_serverCaps.
|
overridevirtual |
Implements srv::INetworkServer.
Definition at line 330 of file asioServer.cpp.
References m_tickRate.
|
private |
Initialize packet handlers.
Setup packet handlers for all RNP packet types
Registers callback functions for each packet type with the packet handler
Definition at line 342 of file asioServer.cpp.
References handleConnect(), handleDisconnect(), handleEntityEvent(), handleLobbyCreate(), handleLobbyJoin(), handleLobbyLeave(), handleLobbyListRequest(), handlePing(), handlePong(), handleStartGameRequest(), m_packetHandler, rnp::HandlerPacket::onConnect(), rnp::HandlerPacket::onDisconnect(), rnp::HandlerPacket::onEntityEvent(), rnp::HandlerPacket::onLobbyCreate(), rnp::HandlerPacket::onLobbyJoin(), rnp::HandlerPacket::onLobbyLeave(), rnp::HandlerPacket::onLobbyListRequest(), rnp::HandlerPacket::onPing(), rnp::HandlerPacket::onPong(), and rnp::HandlerPacket::onStartGameRequest().
Referenced by AsioServer().
Here is the call graph for this function:
Here is the caller graph for this function:
|
overridevirtual |
Implements srv::INetworkServer.
Definition at line 60 of file asioServer.cpp.
References m_host, m_networkThread, m_port, m_running, m_socket, m_started, networkThreadLoop(), and startReceive().
Here is the call graph for this function:
|
private |
Start receiving packets asynchronously.
Start asynchronous receive operation
Initiates async_receive_from on the UDP socket
Definition at line 388 of file asioServer.cpp.
References utl::Logger::log(), m_recvBuffer, m_running, m_senderEndpoint, m_socket, and utl::WARNING.
Referenced by start().
Here is the call graph for this function:
Here is the caller graph for this function:
|
overridevirtual |
Implements srv::INetworkServer.
Definition at line 110 of file asioServer.cpp.
References rnp::DISCONNECT, rnp::Serializer::getData(), m_clients, m_clientsMutex, m_endpointToSession, m_ioContext, m_networkThread, m_running, m_socket, m_socketMutex, m_started, rnp::PacketDisconnect::reasonCode, sendPacketImmediate(), rnp::Serializer::serializeDisconnect(), rnp::Serializer::serializeHeader(), rnp::SERVER_SHUTDOWN, and rnp::PacketHeader::type.
Referenced by ~AsioServer().
Here is the call graph for this function:
Here is the caller graph for this function:
|
overridevirtual |
Implements srv::INetworkServer.
Definition at line 206 of file asioServer.cpp.
References m_running, processEventBusEvents(), processSendQueue(), and updateClientManagement().
Referenced by broadcastLobbyUpdate().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Update client timeouts and send pings.
Update client management (timeouts, pings)
Checks for timed-out clients and sends periodic ping packets
Definition at line 785 of file asioServer.cpp.
References disconnectClient(), rnp::Serializer::getData(), m_clients, m_clientsMutex, m_clientTimeout, m_lastPingTime, m_pingInterval, m_sendQueue, m_sendQueueMutex, rnp::PacketPingPong::nonce, rnp::PING, rnp::Serializer::serializeHeader(), rnp::Serializer::serializePingPong(), and rnp::PacketHeader::type.
Referenced by update().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Map of session ID to client session.
Definition at line 208 of file AsioServer.hpp.
Referenced by broadcastGameOverToLobby(), broadcastGameStart(), broadcastLobbyUpdate(), disconnectClient(), generateSessionId(), getClientCount(), getConnectedSessions(), handleConnect(), handleDisconnect(), handleGameOverEvent(), handleLobbyCreate(), handleLobbyJoin(), handleLobbyLeave(), handleLobbyListRequest(), handlePing(), handlePong(), handleStartGameRequest(), leaveLobby(), lobbyToLobbyInfo(), sendToAllClients(), sendToClient(), stop(), and updateClientManagement().
|
mutableprivate |
Mutex for thread-safe client access.
Definition at line 212 of file AsioServer.hpp.
Referenced by broadcastGameOverToLobby(), broadcastGameStart(), broadcastLobbyUpdate(), disconnectClient(), getClientCount(), getConnectedSessions(), handleConnect(), handleDisconnect(), handleGameOverEvent(), handleLobbyCreate(), handleLobbyJoin(), handleLobbyLeave(), handleLobbyListRequest(), handlePing(), handlePong(), handleStartGameRequest(), leaveLobby(), lobbyToLobbyInfo(), sendToAllClients(), sendToClient(), stop(), and updateClientManagement().
|
private |
Client timeout duration (15000ms)
Definition at line 232 of file AsioServer.hpp.
Referenced by updateClientManagement().
|
private |
Component ID for event bus registration.
Definition at line 235 of file AsioServer.hpp.
Referenced by AsioServer(), handleConnect(), handleDisconnect(), handleEntityEvent(), handleStartGameRequest(), and processEventBusEvents().
|
private |
Map of endpoint string to session ID.
Definition at line 210 of file AsioServer.hpp.
Referenced by disconnectClient(), handleConnect(), handleDisconnect(), and stop().
|
private |
Definition at line 236 of file AsioServer.hpp.
Referenced by AsioServer(), broadcastGameStart(), handleConnect(), handleDisconnect(), handleEntityEvent(), handleStartGameRequest(), and processEventBusEvents().
|
private |
Server bind address (e.g., "0.0.0.0")
Definition at line 198 of file AsioServer.hpp.
|
private |
ASIO I/O context for async operations.
Definition at line 193 of file AsioServer.hpp.
Referenced by networkThreadLoop(), and stop().
|
private |
Timestamp of last ping sweep.
Definition at line 230 of file AsioServer.hpp.
Referenced by updateClientManagement().
|
private |
Map of lobby ID to lobby data.
Definition at line 215 of file AsioServer.hpp.
Referenced by broadcastGameOverToLobby(), broadcastGameStart(), broadcastLobbyUpdate(), cleanupEmptyLobbies(), createLobby(), handleGameOverEvent(), handleLobbyJoin(), handleStartGameRequest(), joinLobby(), leaveLobby(), and sendLobbyList().
|
mutableprivate |
Mutex for thread-safe lobby access.
Definition at line 217 of file AsioServer.hpp.
Referenced by broadcastGameOverToLobby(), broadcastGameStart(), broadcastLobbyUpdate(), createLobby(), handleGameOverEvent(), handleLobbyJoin(), handleStartGameRequest(), joinLobby(), leaveLobby(), and sendLobbyList().
|
private |
Dedicated network thread.
Definition at line 195 of file AsioServer.hpp.
|
private |
Next available lobby ID.
Definition at line 216 of file AsioServer.hpp.
Referenced by createLobby(), and handleLobbyCreate().
|
private |
Next available session ID.
Definition at line 211 of file AsioServer.hpp.
|
private |
RNP packet handler instance.
Definition at line 220 of file AsioServer.hpp.
Referenced by disconnectClient(), handleReceive(), and setupPacketHandlers().
|
private |
Interval between ping sweeps (5000ms)
Definition at line 231 of file AsioServer.hpp.
Referenced by updateClientManagement().
|
private |
Server listening port (default: 4567)
Definition at line 199 of file AsioServer.hpp.
|
private |
Buffer for receiving UDP packets.
Definition at line 226 of file AsioServer.hpp.
Referenced by handleReceive(), and startReceive().
|
private |
Server running state (atomic for thread safety)
Definition at line 204 of file AsioServer.hpp.
Referenced by isRunning(), networkThreadLoop(), sendPacketImmediate(), start(), startReceive(), stop(), and update().
|
private |
Endpoint of last packet sender.
Definition at line 227 of file AsioServer.hpp.
Referenced by handleConnect(), handleLobbyLeave(), handleLobbyListRequest(), handlePing(), handleReceive(), handleStartGameRequest(), sendLobbyCreateResponse(), sendLobbyJoinResponse(), sendLobbyList(), and startReceive().
|
private |
Queue of packets waiting to be sent.
Definition at line 221 of file AsioServer.hpp.
Referenced by processSendQueue(), sendToAllClients(), sendToClient(), and updateClientManagement().
|
private |
Mutex for send queue access.
Definition at line 222 of file AsioServer.hpp.
Referenced by processSendQueue(), sendToAllClients(), sendToClient(), and updateClientManagement().
|
private |
Server capability flags.
Definition at line 201 of file AsioServer.hpp.
Referenced by sendConnectAccept(), and setServerCapabilities().
|
private |
UDP socket for network communication.
Definition at line 194 of file AsioServer.hpp.
Referenced by sendPacketImmediate(), start(), startReceive(), and stop().
|
private |
Mutex for socket operations.
Definition at line 223 of file AsioServer.hpp.
Referenced by sendPacketImmediate(), and stop().
|
private |
Server started state.
Definition at line 205 of file AsioServer.hpp.
|
private |
Server tick rate in Hz.
Definition at line 200 of file AsioServer.hpp.
Referenced by sendConnectAccept(), and setTickRate().