R-Type 0.1
Loading...
Searching...
No Matches
rtype::server::Server Class Reference

Game level layer over NetworkServer that decodes client messages and encodes server messages. More...

#include <Server.hpp>

Classes

struct  ConnectionEvent
 Client connection or disconnection. More...
 
struct  InputEvent
 Input message received from a client. More...
 
struct  QueryEntityEvent
 QueryEntity message received from a client. More...
 

Public Member Functions

 Server (std::uint16_t port)
 Creates the server on a UDP port, without starting it.
 
 ~Server ()
 Stops the network thread.
 
void start ()
 Starts the network thread.
 
void stop ()
 Stops the network thread.
 
void send (std::uint32_t connectionId, const std::vector< std::uint8_t > &payload)
 Sends already encoded messages to a client.
 
bool pollInput (InputEvent &event)
 Pops the oldest Input message.
 
bool pollConnectionEvent (ConnectionEvent &event)
 Pops the oldest connection change.
 
bool pollQueryEntity (QueryEntityEvent &event)
 Pops the oldest QueryEntity message.
 
bool sendCreateEntity (std::uint32_t connectionId, const protocol::CreateEntityPayload &payload)
 Sends a CreateEntity message.
 
bool sendDestroyEntity (std::uint32_t connectionId, const protocol::DestroyEntityPayload &payload)
 Sends a DestroyEntity message.
 
bool sendSnapshot (std::uint32_t connectionId, const protocol::SnapshotPayload &payload)
 Sends a Snapshot message.
 

Detailed Description

Game level layer over NetworkServer that decodes client messages and encodes server messages.

Decoded messages are pushed by the network thread into mutex protected queues that the game loop drains with the poll methods.

Constructor & Destructor Documentation

◆ Server()

rtype::server::Server::Server ( std::uint16_t port)
explicit

Creates the server on a UDP port, without starting it.

Parameters
portLocal port to listen on.

Member Function Documentation

◆ send()

void rtype::server::Server::send ( std::uint32_t connectionId,
const std::vector< std::uint8_t > & payload )

Sends already encoded messages to a client.

Parameters
connectionIdDestination connection.
payloadMessages, headers included.

◆ pollInput()

bool rtype::server::Server::pollInput ( InputEvent & event)

Pops the oldest Input message.

Parameters
eventReceives the message.
Returns
True if a message was popped.

◆ pollConnectionEvent()

bool rtype::server::Server::pollConnectionEvent ( ConnectionEvent & event)

Pops the oldest connection change.

Parameters
eventReceives the change.
Returns
True if a change was popped.

◆ pollQueryEntity()

bool rtype::server::Server::pollQueryEntity ( QueryEntityEvent & event)

Pops the oldest QueryEntity message.

Parameters
eventReceives the message.
Returns
True if a message was popped.

◆ sendCreateEntity()

bool rtype::server::Server::sendCreateEntity ( std::uint32_t connectionId,
const protocol::CreateEntityPayload & payload )

Sends a CreateEntity message.

Parameters
connectionIdDestination connection.
payloadMessage payload.
Returns
False if the payload is invalid or cannot be encoded.

◆ sendDestroyEntity()

bool rtype::server::Server::sendDestroyEntity ( std::uint32_t connectionId,
const protocol::DestroyEntityPayload & payload )

Sends a DestroyEntity message.

Parameters
connectionIdDestination connection.
payloadMessage payload.
Returns
False if the payload is invalid or cannot be encoded.

◆ sendSnapshot()

bool rtype::server::Server::sendSnapshot ( std::uint32_t connectionId,
const protocol::SnapshotPayload & payload )

Sends a Snapshot message.

Parameters
connectionIdDestination connection.
payloadMessage payload.
Returns
False if the snapshot has too many states or cannot be encoded.