30 #include "nrg_packet.h"
47 Server(
const std::string& game_name, uint32_t game_version,
InputBase& input);
49 Server(
const std::string& game_name, uint32_t game_version);
91 template<
class M,
class F>
94 using namespace std::placeholders;
96 global_msg_handlers.insert(
97 make_unique<M>(std::bind(forward<F>(func), _1, _2, ref(current_player)))
109 const UDPSocket& getSocket()
const {
return sock; }
110 const Snapshot& getSnapshot()
const {
return master_snapshot; }
111 const DeltaSnapshotBuffer& getDeltaSnapshots()
const {
return snaps; }
112 InputBase* getInput()
const {
return input; }
113 const std::string& getGameName() {
return game_name; }
114 const uint32_t getGameVersion() {
return game_version; }
120 version_func = std::forward<F>(func);
139 std::map<NetAddress, Player*> clients;
140 std::set<std::unique_ptr<MessageBase>> global_msg_handlers;
143 std::vector<Entity*> entities;
144 std::vector<uint16_t> updated_entities;
148 std::string game_name;
149 uint32_t game_version;
150 uint16_t max_players;
151 std::function<bool(uint32_t, uint32_t)> version_func;
152 std::function<bool(Server& s, Packet& p)> connect_check;
void registerEntity(Entity &e)
Register an Entity with the server to be tracked and replicated to clients.
Abstract base class for Message.
Definition: nrg_message.h:36
Definition: nrg_snapshot.h:38
Contains Message classes and functionality for two-way RPC between Server and Client.
void pushEvent(const Event &e)
void addMessageHandler(F &&func)
Adds a callback function func that will be called on receipt of a message of type M...
Definition: nrg_server.h:92
Socket derivative specifically for the User-Datagram Protocol.
Definition: nrg_socket.h:112
Class for storing data to be sent / received across the network.
Definition: nrg_packet.h:58
Represents a connected client on the server.
Definition: nrg_player.h:34
void setVersionComparison(F &&func)
Sets a function that should return true if two uint32_t game version parameters are compatible...
Definition: nrg_server.h:119
Union to contain all the event types.
Definition: nrg_event.h:72
Contains the NetAddress class for wrapping POSIX sockaddr structures and resolving hostnames to IP ad...
Functionality to notify users of Client and Server occurances.
Abstract class to be inherited by users of the library which acts as a container of one or more Field...
Definition: nrg_entity.h:37
Holds a queue of Event objects.
Definition: nrg_event.h:92
void setTickRate(uint8_t rate)
Sets the number of ticks / master snapshots generated by the server per second, 256 max...
Abstract class that contains functionality required by Entity objects.
Definition: nrg_entity.h:84
Library versioning stuff.
virtual ~Server()
Default destructor.
The main server-side class of the library.
Definition: nrg_server.h:44
uint8_t getTickRate() const
Gets the number of ticks per second the server is running at, default: 20.
Contains the Player Interface used server-side.
bool bind(const NetAddress &addr)
Bind the server to the specified local address.
void markEntityUpdated(Entity &e)
void setUserPointer(void *p)
Associate a user-given pointer with this server.
Definition: nrg_server.h:127
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...
Classes to wrap POSIX sockets.
bool isBound() const
Returns true if the server is bound to a port.
void setMaxPlayers(uint16_t val)
Sets the maximum number of players, doesn't kick anyone if the current count is larger than this...
Definition: nrg_server.h:70
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 broadcastMessage(const MessageBase &m)
Sends message m to all connected clients.
bool pollEvent(Event &e)
Receives Event instances into e, returns false if there are no more events.
bool update()
Blocks to accept input from clients until the next snapshot time, then creates the new snapshot and s...
bool isFull() const
Returns true if the server has reached its maximum player count.
Definition: nrg_server.h:73
size_t playerCount() const
Returns the number of players connected to this server.
Player * getPlayerByID(uint16_t) const
Gets the player with the given id, or nullptr if they don't exist.
void unregisterEntity(Entity &e)
Common defines and includes used by all the other nrg header files.
Classes to hold a specific snapshot in time of Entity Field values.
void * getUserPointer() const
Returns the user-given pointer associated with this server, nullptr by default.
Definition: nrg_server.h:130
Class to wrap the various POSIX sockaddrs and resolve hostnames.
Definition: nrg_netaddress.h:32