Orxonox: orxonox::Server Class Reference

# orxonox::Server Class Reference

`#include <src/network/Server.h>`

Inheritance diagram for orxonox::Server:

List of all members.

## Public Member Functions

void | close ()
double | getPacketLoss (unsigned int clientID)
| : return packet loss ratio to client (scales from 0 to 1)
unsigned int | getPing (unsigned int clientID)
| : returns ping time to client in milliseconds
void | open ()
bool | processChat (const std::string &message, unsigned int playerID)
bool | queuePacket (ENetPacket *packet, int clientID)
| Server (int port, const std::string &bindAddress)
| Server (int port)
| Server ()
void | update (const Clock &time)
| ~Server ()
| Destructor.

## Protected Member Functions

void | updateGamestate ()

## Private Member Functions

void | addClient (ENetEvent *event)
virtual bool | broadcast (const std::string &message)
virtual bool | chat (const std::string &message)
bool | createClient (int clientID)
void | disconnectClient (ClientInformation *client)
virtual bool | isServer_ ()
unsigned int | playerID ()
bool | processPacket (ENetPacket *packet, ENetPeer *peer)
bool | sendChat (const std::string &message, unsigned int clientID)
bool | sendGameState ()
bool | sendObjectDeletes ()
unsigned int | shipID ()
void | syncClassid (unsigned int clientID)

## Private Attributes

float | timeSinceLastUpdate_

## 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

References timeSinceLastUpdate_.

orxonox::Server::Server | ( | int | port | ) |

References orxonox::ServerConnection::setPort(), and timeSinceLastUpdate_.

orxonox::Server::Server | ( | int | port,
|  | const std::string & | bindAddress |
| ) |  |  |

Constructor

Parameters:

  | port | Port to listen on
  | bindAddress | Address to listen on

References orxonox::ServerConnection::setBindAddress(), orxonox::ServerConnection::setPort(), and timeSinceLastUpdate_.

orxonox::Server::~Server | ( |  | ) |

Destructor.

## Member Function Documentation

void orxonox::Server::addClient | ( | ENetEvent * | event | ) | `[private, virtual]`

Implements orxonox::Connection.

References COUT, createClient(), orxonox::ClientInformation::getID(), orxonox::ClientInformation::insertBack(), orxonox::ClientInformation::setID(), and orxonox::ClientInformation::setPeer().

bool orxonox::Server::broadcast | ( | const std::string & | message | ) | `[private, virtual]`

Implements orxonox::Host.

References orxonox::CLIENTID_UNKNOWN, and sendChat().

bool orxonox::Server::chat | ( | const std::string & | message | ) | `[private, virtual]`

Implements orxonox::Host.

References orxonox::Host::getPlayerID(), and sendChat().

Referenced by processChat(), and sendChat().

void orxonox::Server::close | ( |  | ) |

This function closes the server

References orxonox::ServerConnection::closeListener(), COUT, and orxonox::ServerConnection::disconnectClients().

Referenced by orxonox::GSDedicated::deactivate().

bool orxonox::Server::createClient | ( | int | clientID | ) | `[private]`

References orxonox::packet::Gamestate::collectData(), orxonox::packet::Gamestate::compressData(), COUT, orxonox::ClientInformation::findClient(), orxonox::packet::Type::FunctionIDs, orxonox::packet::Type::Gamestate, orxonox::ClientInformation::getID(), orxonox::ClientInformation::getShipID(), orxonox::packet::Packet::send(), orxonox::packet::Packet::setClientID(), orxonox::ClientInformation::setSynched(), syncClassid(), and orxonox::packet::Type::Welcome.

Referenced by addClient().

void orxonox::Server::disconnectClient | ( | ClientInformation * | client | ) | `[private, virtual]`

Reimplemented from orxonox::ServerConnection.

References orxonox::ServerConnection::disconnectClient(), orxonox::ClientInformation::getID(), and orxonox::GamestateManager::removeClient().

double orxonox::Server::getPacketLoss | ( | unsigned int | clientID | ) |

: return packet loss ratio to client (scales from 0 to 1)

References orxonox::ClientInformation::findClient(), and orxonox::ClientInformation::getPacketLoss().

unsigned int orxonox::Server::getPing | ( | unsigned int | clientID | ) |

: returns ping time to client in milliseconds

References orxonox::ClientInformation::findClient(), and orxonox::ClientInformation::getRTT().

virtual bool orxonox::Server::isServer_ | ( |  | ) | `[inline, private, virtual]`

Implements orxonox::Host.

void orxonox::Server::open | ( |  | ) |

This function opens the server by creating the listener thread

References COUT, and orxonox::ServerConnection::openListener().

Referenced by orxonox::GSDedicated::activate().

unsigned int orxonox::Server::playerID | ( |  | ) | `[inline, private]`

bool orxonox::Server::processChat | ( | const std::string & | message,
|  | unsigned int | playerID |
| ) |  |  | `[virtual]`

Implements orxonox::Host.

References orxonox::packet::Type::Chat, chat(), COUT, orxonox::ClientInformation::getBegin(), orxonox::ClientInformation::getID(), orxonox::ClientInformation::next(), orxonox::packet::Packet::send(), and orxonox::packet::Packet::setClientID().

bool orxonox::Server::processPacket | ( | ENetPacket * | packet,
|  | ENetPeer * | peer |
| ) |  |  | `[private]`

References orxonox::packet::Packet::createPacket(), and orxonox::packet::Packet::process().

bool orxonox::Server::queuePacket | ( | ENetPacket * | packet,
|  | int | clientID |
| ) |  |  | `[virtual]`

Implements orxonox::Host.

References orxonox::ServerConnection::addPacket().

bool orxonox::Server::sendChat | ( | const std::string & | message,
|  | unsigned int | clientID |
| ) |  |  | `[private]`

References orxonox::packet::Type::Chat, chat(), COUT, orxonox::ClientInformation::getBegin(), orxonox::ClientInformation::getID(), orxonox::ClientInformation::next(), orxonox::packet::Packet::send(), and orxonox::packet::Packet::setClientID().

Referenced by broadcast(), and chat().

bool orxonox::Server::sendGameState | ( |  | ) | `[private]`

sends the gamestate

References orxonox::GamestateManager::sendGamestates().

Referenced by updateGamestate().

bool orxonox::Server::sendObjectDeletes | ( |  | ) | `[private]`

References COUT, orxonox::packet::Type::DeleteObjects, orxonox::packet::DeleteObjects::fetchIDs(), orxonox::ClientInformation::getBegin(), orxonox::ClientInformation::getFailures(), orxonox::ClientInformation::getID(), orxonox::ClientInformation::getSynched(), orxonox::ClientInformation::next(), orxonox::packet::Packet::send(), and orxonox::packet::Packet::setClientID().

Referenced by updateGamestate().

unsigned int orxonox::Server::shipID | ( |  | ) | `[inline, private]`

void orxonox::Server::syncClassid | ( | unsigned int | clientID | ) | `[private]`

References orxonox::packet::Type::ClassID, COUT, orxonox::packet::Packet::send(), and orxonox::packet::Packet::setClientID().

Referenced by createClient().

void orxonox::Server::update | ( | const Clock & | time | ) |

Run this function once every tick calls processQueue and updateGamestate

Parameters:

  | time | time since last tick

References orxonox::Clock::getDeltaTime(), orxonox::ClientInformation::hasClients(), orxonox::NETWORK_PERIOD, orxonox::GamestateManager::processGamestates(), orxonox::Connection::processQueue(), orxonox::FunctionCallManager::sendCalls(), orxonox::Connection::sendPackets(), timeSinceLastUpdate_, and updateGamestate().

Referenced by orxonox::GSDedicated::update().

void orxonox::Server::updateGamestate | ( |  | ) | `[protected]`

takes a new snapshot of the gamestate and sends it to the clients

References COUT, orxonox::ClientInformation::getBegin(), sendGameState(), sendObjectDeletes(), and orxonox::GamestateManager::update().

Referenced by update().

## Member Data Documentation

float orxonox::Server::timeSinceLastUpdate_`[private]`

Referenced by Server(), and update().

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

- src/network/Server.h
- src/network/Server.cc