LibNRG  0.0.1
Networking for Real-time Games library
 All Classes Files Functions Variables Friends
nrg_server_state.h
Go to the documentation of this file.
1 /*
2  LibNRG - Networking for Real-time Games
3 
4  Copyright (C) 2012-2014 Alex Baines <alex@abaines.me.uk>
5 
6  This software is provided 'as-is', without any express or implied
7  warranty. In no event will the authors be held liable for any damages
8  arising from the use of this software.
9 
10  Permission is granted to anyone to use this software for any purpose,
11  including commercial applications, and to alter it and redistribute it
12  freely, subject to the following restrictions:
13 
14  1. The origin of this software must not be misrepresented; you must not
15  claim that you wrote the original software. If you use this software
16  in a product, an acknowledgment in the product documentation would be
17  appreciated but is not required.
18  2. Altered source versions must be plainly marked as such, and must not be
19  misrepresented as being the original software.
20  3. This notice may not be removed or altered from any source distribution.
21 */
25 #ifndef NRG_SERVER_STATE_H
26 #define NRG_SERVER_STATE_H
27 #include "nrg_core.h"
28 #include "nrg_state.h"
29 #include "nrg_snapshot.h"
30 #include "nrg_message.h"
31 #include "nrg_message_manager.h"
32 
33 namespace nrg {
34 
36 struct ServerHandshakeState : public State {
38  bool init(Client*, Server*, Player*);
39  bool onRecvPacket(Packet& p, PacketFlags f);
40  bool needsUpdate() const { return true; }
41  StateResult update(StateConnectionOut& out, StateFlags f);
42 private:
43  Server* server;
44  Player* player;
45  int8_t response;
46  Packet packet;
47 };
48 
50 class ServerPlayerGameState : public State {
51 public:
53  bool init(Client*, Server*, Player*);
54  bool onRecvPacket(Packet& p, PacketFlags f);
55  bool needsUpdate() const;
56  StateResult update(StateConnectionOut& out, StateFlags f);
57  void registerMessageHandler(MessageBase&& m);
58  void registerMessageHandler(const MessageBase& m);
59  void sendMessage(const MessageBase& m);
60 private:
61  DeltaSnapshot snapshot;
62  bool no_ack;
63  int unackd_updates;
64  uint8_t seq;
65  uint16_t last_sent_id;
66  uint16_t ack_time;
67  uint16_t c_time;
68  Packet buffer;
69  MessageManager msg_manager;
70  Server* server;
71  Player* player;
72 };
73 
74 }
75 
76 #endif
bool onRecvPacket(Packet &p, PacketFlags f)
Called when a Packet is recieved and this is the active State, f shows if the packet was out-of-order...
Abstract base class for Message.
Definition: nrg_message.h:36
Contains Message classes and functionality for two-way RPC between Server and Client.
bool init(Client *, Server *, Player *)
Called to (re)initialise this State instance, for Client-side c won't be null, but s and p will...
Interface for wrapping ConnectionOut with rate-limiting functionality.
Definition: nrg_state.h:61
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
bool needsUpdate() const
Called to see if the State would like to be updated.
Definition: nrg_server_state.h:40
Contains functionality for managing the storage and reliable transmission or Messages.
Class that stores Messages to be sent, and parses received messages from packets, running their callb...
Definition: nrg_message_manager.h:37
The main server-side class of the library.
Definition: nrg_server.h:44
State for default game protocol, server-side.
Definition: nrg_server_state.h:50
Abstract class that represents a protocol followed by the Server and Client.
Definition: nrg_state.h:73
StateResult update(StateConnectionOut &out, StateFlags f)
Called to update the state (or on a timeout) allowing it to optionally send some Packets using out...
Definition: nrg_snapshot.h:62
bool needsUpdate() const
Called to see if the State would like to be updated.
StateResult update(StateConnectionOut &out, StateFlags f)
Called to update the state (or on a timeout) allowing it to optionally send some Packets using out...
bool init(Client *, Server *, Player *)
Called to (re)initialise this State instance, for Client-side c won't be null, but s and p will...
bool onRecvPacket(Packet &p, PacketFlags f)
Called when a Packet is recieved and this is the active State, f shows if the packet was out-of-order...
State for default handshake protocol, server-side.
Definition: nrg_server_state.h:36
The main client-side nrg class.
Definition: nrg_client.h:42
Common defines and includes used by all the other nrg header files.
Functionality related to the State abstract class.
Classes to hold a specific snapshot in time of Entity Field values.