Orxonox  0.0.5 Codename: Arcturus
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
orxonox::Server Class Reference

This class is the root class of the network module for a server. More...

#include </home/jenkins/workspace/orxonox_doxygen_trunk/src/libraries/network/Server.h>

Inheritance diagram for orxonox::Server:
orxonox::Host orxonox::ServerConnection orxonox::LANDiscoverable orxonox::WANDiscoverable orxonox::GamestateManager orxonox::Connection orxonox::Configurable orxonox::Configurable orxonox::GamestateHandler orxonox::Listable orxonox::Listable orxonox::Identifiable orxonox::Identifiable

Public Member Functions

 Server ()
 Constructor for default values (bindaddress is set to ENET_HOST_ANY. More...
 
 Server (int port)
 Constructor. More...
 
 Server (int port, const std::string &bindAddress)
 Constructor. More...
 
 ~Server ()
 Destructor. More...
 
void close ()
 This function closes the server. More...
 
int getClientCount ()
 
std::string getServerName ()
 
void open ()
 This function opens the server by creating the listener thread. More...
 
virtual void printRTT () override
 Print ping time to client in milliseconds. More...
 
virtual void queuePacket (ENetPacket *packet, int clientID, uint8_t channelID) override
 
virtual bool sendPacket (packet::Packet *packet) override
 
void update (const Clock &time)
 Run this function once every tick calls processQueue and updateGamestate. More...
 
- Public Member Functions inherited from orxonox::Host
bool isActive ()
 
- Public Member Functions inherited from orxonox::GamestateManager
 GamestateManager ()
 
 ~GamestateManager ()
 
virtual bool ackGamestate (unsigned int gamestateID, unsigned int peerID) override
 Acknowledge a received gamestate. More...
 
virtual bool addGamestate (packet::Gamestate *gs, unsigned int peerID) override
 
void addPeer (uint32_t peerID)
 Add a peer to the game. More...
 
void finishGamestate (unsigned int peerID, packet::Gamestate *&destgamestate, packet::Gamestate *base, packet::Gamestate *gamestate)
 
virtual uint32_t getCurrentGamestateID () override
 
std::vector< packet::Gamestate * > getGamestates ()
 Return a vector with the gamestates of all peers. More...
 
virtual uint32_t getLastReceivedGamestateID (unsigned int peerID) override
 Return the ID of the last received gamestate for a certain peer. More...
 
bool getSnapshot ()
 Update the current gamestate. More...
 
bool hasPeers ()
 
bool processGamestates ()
 Process the queued gamestates. More...
 
void removePeer (uint32_t peerID)
 Remove a peer from the game. More...
 
bool sendAck (unsigned int gamestateID, uint32_t peerID)
 Send Acknowledgement packet. More...
 
void setSynched (uint32_t peerID)
 
bool update ()
 
- Public Member Functions inherited from orxonox::ServerConnection
 ~ServerConnection ()
 Destructor. More...
 
void addPacket (ENetPacket *packet, unsigned int ID, uint8_t channelID)
 Add outgoing packet to queue. More...
 
bool closeListener ()
 Stop listening. More...
 
void disconnectClient (int clientID)
 Terminate connection with a peer. More...
 
bool openListener ()
 
void setBindAddress (const std::string &bindAddress)
 Set address on which to listen. More...
 
void setPort (unsigned int port)
 Set port on which to listen on. More...
 
- Public Member Functions inherited from orxonox::Connection
virtual ~Connection ()
 Destructor. More...
 
- Public Member Functions inherited from orxonox::LANDiscoverable
 LANDiscoverable ()
 
virtual ~LANDiscoverable ()
 
void setActivity (bool bActive)
 
void setConfigValues ()
 Function used for the configuration file parameter update. More...
 
void update ()
 
void updateClientNumber (int clientNumber)
 
- Public Member Functions inherited from orxonox::Configurable
 Configurable ()
 
void setConfigValues ()
 Function to collect the SetConfigValue-macro calls. More...
 
- Public Member Functions inherited from orxonox::Listable
 Listable ()
 Constructor: Allocates space in the element list. More...
 
 Listable (Context *context)
 Constructor: Allocates space in the element list and assigns the context. More...
 
virtual ~Listable ()
 Destructor: Removes the object from the object-lists. More...
 
ContextgetContext () const
 
void setContext (Context *context)
 Changes the context. More...
 
void unregisterObject ()
 Removes this object from the object-lists. More...
 
- Public Member Functions inherited from orxonox::Identifiable
 Identifiable ()
 Constructor: Sets the default values. More...
 
virtual ~Identifiable ()
 
ORX_FORCEINLINE voidgetDerivedPointer (unsigned int classID)
 Returns a valid pointer of any derived type that is registered in the class hierarchy. More...
 
template<class T >
ORX_FORCEINLINE T * getDerivedPointer (unsigned int classID)
 Version of getDerivedPointer with template. More...
 
template<class T >
ORX_FORCEINLINE const T * getDerivedPointer (unsigned int classID) const
 Const version of getDerivedPointer with template. More...
 
IdentifiergetIdentifier () const
 Returns the Identifier of the object. More...
 
bool isA (const Identifier *identifier)
 Returns true if the object's class is of the given type or a derivative. More...
 
template<class B >
bool isA (const SubclassIdentifier< B > *identifier)
 Returns true if the object's class is of the given type or a derivative. More...
 
bool isA (const Identifiable *object)
 Returns true if the object's class is of the given type or a derivative. More...
 
bool isChildOf (const Identifier *identifier)
 Returns true if the object's class is a child of the given type. More...
 
template<class B >
bool isChildOf (const SubclassIdentifier< B > *identifier)
 Returns true if the object's class is a child of the given type. More...
 
bool isChildOf (const Identifiable *object)
 Returns true if the object's class is a child of the given type. More...
 
bool isDirectChildOf (const Identifier *identifier)
 Returns true if the object's class is a direct child of the given type. More...
 
template<class B >
bool isDirectChildOf (const SubclassIdentifier< B > *identifier)
 Returns true if the object's class is a direct child of the given type. More...
 
bool isDirectChildOf (const Identifiable *object)
 Returns true if the object's class is a direct child of the given type. More...
 
bool isDirectParentOf (const Identifier *identifier)
 Returns true if the object's class is a direct parent of the given type. More...
 
template<class B >
bool isDirectParentOf (const SubclassIdentifier< B > *identifier)
 Returns true if the object's class is a direct parent of the given type. More...
 
bool isDirectParentOf (const Identifiable *object)
 Returns true if the object's class is a direct child of the given type. More...
 
bool isExactlyA (const Identifier *identifier)
 Returns true if the object's class is exactly of the given type. More...
 
template<class B >
bool isExactlyA (const SubclassIdentifier< B > *identifier)
 Returns true if the object's class is exactly of the given type. More...
 
bool isExactlyA (const Identifiable *object)
 Returns true if the object's class is exactly of the given type. More...
 
bool isParentOf (const Identifier *identifier)
 Returns true if the object's class is a parent of the given type. More...
 
template<class B >
bool isParentOf (const SubclassIdentifier< B > *identifier)
 Returns true if the object's class is a parent of the given type. More...
 
bool isParentOf (const Identifiable *object)
 Returns true if the object's class is a parent of the given type. More...
 
- Public Member Functions inherited from orxonox::WANDiscoverable
 WANDiscoverable ()
 constructor More...
 
 ~WANDiscoverable ()
 destructor More...
 
std::string getMSAddress ()
 
void setActivity (bool bActive)
 Function used to set the activity/discoverability. More...
 
void setConfigValues ()
 Function used for the configuration file parameter update. More...
 
void updateClientNumber (int clientNumber)
 

Protected Member Functions

void updateGamestate ()
 Take a new snapshot of the gamestate and send it to the clients. More...
 
- Protected Member Functions inherited from orxonox::Host
 Host ()
 Constructor: assures that only one reference will be created and sets the pointer. More...
 
virtual ~Host ()
 Destructor: resets the instance pointer to nullptr. More...
 
void setActive (bool bActive)
 
- Protected Member Functions inherited from orxonox::GamestateHandler
 GamestateHandler ()
 
virtual ~GamestateHandler ()
 
- Protected Member Functions inherited from orxonox::ServerConnection
 ServerConnection ()
 Constructor. More...
 
void disconnectClients ()
 Disconnect all peers. More...
 
- Protected Member Functions inherited from orxonox::Connection
 Connection (uint32_t firstPeerID=NETWORK_PEER_ID_SERVER+1)
 Constructor. More...
 
void addPacket (ENetPacket *packet, uint32_t peerID, uint8_t channelID)
 Send a packet. More...
 
void broadcastPacket (ENetPacket *packet, uint8_t channelID)
 Send a broadcast packet. More...
 
void disconnectPeer (uint32_t peerID)
 Send an outgoing event of type 'disconnectPeer'. More...
 
void disconnectPeers ()
 Send an outgoing event of type 'disconnectPeers'. More...
 
void disconnectPeersInternal ()
 
void enableCompression ()
 
incomingEvent preprocessConnectEvent (ENetEvent &event)
 
incomingEvent preprocessDisconnectEvent (ENetEvent &event)
 
incomingEvent preprocessReceiveEvent (ENetEvent &event)
 
void processIncomingEvent (ENetEvent &event)
 Handle an incoming event. More...
 
void processOutgoingEvent (outgoingEvent &event)
 Send an event. More...
 
void processQueue ()
 
void startCommunicationThread ()
 Start the main communication thread. More...
 
void stopCommunicationThread ()
 Stop the main communication thread. More...
 
void waitOutgoingQueue ()
 

Private Member Functions

virtual void addPeer (uint32_t peerID) override
 Add a new peer to the server. More...
 
bool createClient (int clientID)
 Create a client. More...
 
void disconnectClient (uint32_t clientID)
 Disconnect a client. More...
 
virtual void doReceiveChat (const std::string &message, unsigned int sourceID, unsigned int targetID) override
 Gets called if a packet::Chat packet is received. More...
 
virtual void doSendChat (const std::string &message, unsigned int sourceID, unsigned int targetID) override
 Sends a chat message to the given target ID. More...
 
virtual bool isServer_ () override
 
bool isValidTarget (unsigned int targetID)
 Returns true if the target ID is in the list of clients (or if it corresponds to the broadcast or the server ID). More...
 
unsigned int playerID ()
 
virtual void processPacket (packet::Packet *packet) override
 Process an incoming packet. More...
 
virtual void removePeer (uint32_t peerID) override
 Remove a peer from the server. More...
 
bool sendGameStates ()
 Send the current gamestate to all peers. More...
 
bool sendObjectDeletes ()
 Send 'DeleteObjects' packet. More...
 
void syncClassid (unsigned int clientID)
 

Private Attributes

std::vector< uint32_t > clientIDs_
 
std::deque< packet::Packet * > packetQueue_
 
std::string serverName_
 
float timeSinceLastUpdate_
 

Additional Inherited Members

- Static Public Member Functions inherited from orxonox::Host
static void addPacket (ENetPacket *packet, int clientID=NETWORK_PEER_ID_SERVER, uint8_t channelID=0)
 This function is used to add an enetpacket to be sent to another peer. More...
 
static HostgetActiveInstance ()
 Singleton implementation. More...
 
static unsigned int getPlayerID ()
 
static bool isServer ()
 
static bool running ()
 
static void sendChat (const std::string &message, unsigned int sourceID, unsigned int targetID)
 Sends a chat message through the network. More...
 
static void setClientID (unsigned int id)
 
- Public Attributes inherited from orxonox::WANDiscoverable
MasterServerComm msc
 Master server communications object. More...
 
- Protected Attributes inherited from orxonox::Connection
ENetHosthost_
 

Detailed Description

This class is the root class of the network module for a server.

It implements all functions necessary for a Server

Constructor & Destructor Documentation

orxonox::Server::Server ( )

Constructor for default values (bindaddress is set to ENET_HOST_ANY.

orxonox::Server::Server ( int  port)

Constructor.

Parameters
portPort to listen on
orxonox::Server::Server ( int  port,
const std::string &  bindAddress 
)

Constructor.

Parameters
portPort to listen on
bindAddressAddress to listen on
orxonox::Server::~Server ( )

Destructor.

Member Function Documentation

void orxonox::Server::addPeer ( uint32_t  peerID)
overrideprivatevirtual

Add a new peer to the server.

Implements orxonox::Connection.

void orxonox::Server::close ( )

This function closes the server.

bool orxonox::Server::createClient ( int  clientID)
private

Create a client.

void orxonox::Server::disconnectClient ( uint32_t  clientID)
private

Disconnect a client.

void orxonox::Server::doReceiveChat ( const std::string &  message,
unsigned int  sourceID,
unsigned int  targetID 
)
overrideprivatevirtual

Gets called if a packet::Chat packet is received.

Forwards the packet to the target and calls the parent function if necessary.

Implements orxonox::Host.

void orxonox::Server::doSendChat ( const std::string &  message,
unsigned int  sourceID,
unsigned int  targetID 
)
overrideprivatevirtual

Sends a chat message to the given target ID.

Parameters
messagemessage to be sent
sourceIDthe ID of the sender
targetIDthe ID of the receiver

Implements orxonox::Host.

int orxonox::Server::getClientCount ( )
inline
std::string orxonox::Server::getServerName ( )
inline
virtual bool orxonox::Server::isServer_ ( )
inlineoverrideprivatevirtual

Implements orxonox::Host.

bool orxonox::Server::isValidTarget ( unsigned int  targetID)
private

Returns true if the target ID is in the list of clients (or if it corresponds to the broadcast or the server ID).

void orxonox::Server::open ( )

This function opens the server by creating the listener thread.

unsigned int orxonox::Server::playerID ( )
inlineprivate
void orxonox::Server::printRTT ( )
overridevirtual

Print ping time to client in milliseconds.

Implements orxonox::Host.

void orxonox::Server::processPacket ( packet::Packet packet)
overrideprivatevirtual

Process an incoming packet.

Implements orxonox::Connection.

void orxonox::Server::queuePacket ( ENetPacket packet,
int  clientID,
uint8_t  channelID 
)
overridevirtual

Implements orxonox::Host.

void orxonox::Server::removePeer ( uint32_t  peerID)
overrideprivatevirtual

Remove a peer from the server.

Implements orxonox::Connection.

bool orxonox::Server::sendGameStates ( )
private

Send the current gamestate to all peers.

bool orxonox::Server::sendObjectDeletes ( )
private

Send 'DeleteObjects' packet.

virtual bool orxonox::Server::sendPacket ( packet::Packet packet)
inlineoverridevirtual
void orxonox::Server::syncClassid ( unsigned int  clientID)
private
void orxonox::Server::update ( const Clock time)

Run this function once every tick calls processQueue and updateGamestate.

Parameters
timetime since last tick
void orxonox::Server::updateGamestate ( )
protected

Take a new snapshot of the gamestate and send it to the clients.

Member Data Documentation

std::vector<uint32_t> orxonox::Server::clientIDs_
private
std::deque<packet::Packet*> orxonox::Server::packetQueue_
private
std::string orxonox::Server::serverName_
private
float orxonox::Server::timeSinceLastUpdate_
private

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