26#include "utils/no_copy.hpp"
78 virtual void callback(
Protocol *protocol) = 0;
90class Protocol :
public std::enable_shared_from_this<Protocol>,
124 bool reliable =
true);
Class that must be inherited to pass objects to protocols.
Definition: protocol.hpp:73
Class representing an event that need to pass trough the system. This is used to remove ENet dependen...
Definition: event.hpp:73
A new implementation of NetworkString, which has a fixed format: Byte 0: The type of the message,...
Definition: network_string.hpp:422
Utility class, you can inherit from this class to disallow the assignment operator and copy construct...
Definition: no_copy.hpp:26
Abstract class used to define the global protocol functions.
Definition: protocol.hpp:92
ProtocolType m_type
The type of the protocol.
Definition: protocol.hpp:95
virtual void asynchronousUpdate()=0
Called by the protocol listener as often as possible.
bool checkDataSize(Event *event, unsigned int minimum_size)
Checks if the message has at least the specified size, and if not prints a warning message including ...
Definition: protocol.cpp:63
virtual bool notifyEventAsynchronous(Event *event)
Notify a protocol matching the Event type of that event.
Definition: protocol.hpp:138
void setHandleConnections(bool b)
Sets if this protocol should receive connection events.
Definition: protocol.hpp:145
bool m_handle_disconnections
TRue if this protocol should recceiver disconnection events.
Definition: protocol.hpp:101
virtual void requestTerminate()
Submits a request to the ProtocolManager to terminate this protocol.
Definition: protocol.cpp:87
void sendMessageToPeers(NetworkString *message, bool reliable=true)
Sends a message to all validated peers in game, encrypt the message if needed.
Definition: protocol.cpp:99
bool m_handle_connections
True if this protocol should receive connection events.
Definition: protocol.hpp:98
void setHandleDisconnections(bool b)
Sets if this protocol should receive disconnection events.
Definition: protocol.hpp:148
virtual void setup()=0
Called when the protocol is going to start.
virtual bool notifyEvent(Event *event)
Notify a protocol matching the Event type of that event.
Definition: protocol.hpp:132
virtual bool handleConnects() const
Return true if this protocol should be informed about connects.
Definition: protocol.hpp:151
void sendMessageToPeersInServer(NetworkString *message, bool reliable=true)
Sends a message to all validated peers in server, encrypt the message if needed.
Definition: protocol.cpp:110
ProtocolType getProtocolType() const
Method to get a protocol's type.
Definition: protocol.hpp:142
virtual void update(int ticks)=0
Called by the protocol listener, synchronously with the main loop.
virtual bool handleDisconnects() const
Return true if this protocol should be informed about disconnects.
Definition: protocol.hpp:154
virtual ~Protocol()
Destructor.
Definition: protocol.cpp:45
NetworkString * getNetworkString(size_t capacity=16) const
functions to check incoming data easily
Definition: protocol.cpp:53
void sendToServer(NetworkString *message, bool reliable=true)
Sends a message from a client to the server.
Definition: protocol.cpp:119
virtual void requestStart()
Starts a request in the protocol manager to start this protocol.
Definition: protocol.cpp:78
Represents a peer. This class is used to interface the ENetPeer structure.
Definition: stk_peer.hpp:76
ProtocolType
The types that protocols can have.
Definition: protocol.hpp:43
@ PROTOCOL_CONNECTION
Protocol that deals with client-server connection.
Definition: protocol.hpp:45
@ PROTOCOL_CONTROLLER_EVENTS
Protocol to transfer controller modifications.
Definition: protocol.hpp:48
@ PROTOCOL_MAX
Maximum number of different protocol types.
Definition: protocol.hpp:50
@ PROTOCOL_LOBBY_ROOM
Protocol that is used during the lobby room phase.
Definition: protocol.hpp:46
@ PROTOCOL_SYNCHRONOUS
Flag, indicates synchronous delivery.
Definition: protocol.hpp:51
@ PROTOCOL_GAME_EVENTS
Protocol to communicate the game events.
Definition: protocol.hpp:47
@ PROTOCOL_NONE
No protocol type assigned.
Definition: protocol.hpp:44
@ PROTOCOL_SILENT
Used for protocols that do not subscribe to any network event.
Definition: protocol.hpp:49
ProtocolState
Defines the three states that a protocol can have.
Definition: protocol.hpp:59
@ PROTOCOL_STATE_RUNNING
The protocol is being updated everytime.
Definition: protocol.hpp:61
@ PROTOCOL_STATE_TERMINATED
The protocol is terminated/does not exist.
Definition: protocol.hpp:63
@ PROTOCOL_STATE_INITIALISING
The protocol is waiting to be started.
Definition: protocol.hpp:60
@ PROTOCOL_STATE_PAUSED
The protocol is paused.
Definition: protocol.hpp:62
Declares the general types that are used by the network.