LibNRG  0.0.1
Networking for Real-time Games library
 All Classes Files Functions Variables Friends
nrg::Server Class Reference

The main server-side class of the library.

#include <nrg_server.h>

Inheritance diagram for nrg::Server:
nrg::EntityManager

Public Member Functions

 Server (const std::string &game_name, uint32_t game_version, InputBase &input)
 Construct a server with the given game name, version and a user-created subclass of Input.
 
 Server (const std::string &game_name, uint32_t game_version)
 Construct a server which doesn't accept input, generally not very useful.
 
bool bind (const NetAddress &addr)
 Bind the server to the specified local address.
 
bool isBound () const
 Returns true if the server is bound to a port.
 
bool update ()
 Blocks to accept input from clients until the next snapshot time, then creates the new snapshot and sends updates to clients - returns false on error.
 
bool pollEvent (Event &e)
 Receives Event instances into e, returns false if there are no more events.
 
void pushEvent (const Event &e)
 
size_t playerCount () const
 Returns the number of players connected to this server.
 
void setMaxPlayers (uint16_t val)
 Sets the maximum number of players, doesn't kick anyone if the current count is larger than this.
 
bool isFull () const
 Returns true if the server has reached its maximum player count.
 
void setTickRate (uint8_t rate)
 Sets the number of ticks / master snapshots generated by the server per second, 256 max.
 
uint8_t getTickRate () const
 Gets the number of ticks per second the server is running at, default: 20.
 
void registerEntity (Entity &e)
 Register an Entity with the server to be tracked and replicated to clients.
 
void unregisterEntity (Entity &e)
 
void markEntityUpdated (Entity &e)
 
template<class M , class F >
void addMessageHandler (F &&func)
 Adds a callback function func that will be called on receipt of a message of type M.
 
void broadcastMessage (const MessageBase &m)
 Sends message m to all connected clients.
 
PlayergetPlayerByID (uint16_t) const
 Gets the player with the given id, or nullptr if they don't exist.
 
template<class F >
void setVersionComparison (F &&func)
 Sets a function that should return true if two uint32_t game version parameters are compatible.
 
bool isGameVersionCompatible (uint32_t client_ver) const
 Runs its internal version comparison function against the server version and client_ver, returns true if they're compatible.
 
void setUserPointer (void *p)
 Associate a user-given pointer with this server.
 
void * getUserPointer () const
 Returns the user-given pointer associated with this server, nullptr by default.
 
virtual ~Server ()
 Default destructor.
 
Various Getters
const UDPSocketgetSocket () const
 
const SnapshotgetSnapshot () const
 
const DeltaSnapshotBuffergetDeltaSnapshots () const
 
InputBasegetInput () const
 
const std::string & getGameName ()
 
const uint32_t getGameVersion ()
 
- Public Member Functions inherited from nrg::EntityManager
virtual double getInterpTimer () const
 
virtual bool supportsPrediction () const
 

Member Function Documentation

void nrg::Server::markEntityUpdated ( Entity e)
virtual

Lets the server know an entity has been updated, done automatically

Reimplemented from nrg::EntityManager.

void nrg::Server::pushEvent ( const Event e)

Add an event to the server's internal event queue

void nrg::Server::unregisterEntity ( Entity e)
virtual

Unregister an Entity - automatically called by Entity's destructor

Reimplemented from nrg::EntityManager.


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