Main Page   Class Hierarchy   Compound List   File List   Compound Members  

NetManagerServer Class Reference

Server network manager class for Perihelion. More...

#include <netmanagerserver.h>

Inheritance diagram for NetManagerServer:

Inheritance graph
[legend]
Collaboration diagram for NetManagerServer:

Collaboration graph
[legend]
List of all members.

Public Methods

 NetManagerServer ()
 Creates a server NetManager. More...

 ~NetManagerServer ()
 Flushes the remaining data, closes the socket and destroys all the data structures.

void send (MessagePacket &msg, unsigned socketIndex, bool immediate=true)
 Sends a message packet through the indicated socket. More...

void send (const string &msg, unsigned socketIndex, bool immediate=true)
 Sends a single message through the indicated socket. More...

void flush (unsigned socketIndex)
 Flushes an output socket. More...

MessagePacket next ()
 Returns the next received MessagePacket. More...

vector< int > getNewClients ()
 Returns the list of newly connected clients. More...

vector< int > getTimedOutClients ()
 Returns the list of timed out clients. More...

bool thereAreNewClients () const
 Determines whether there are newly connected clients. More...

bool thereAreTimedOutClients () const
 Determines whether there are some just timed out clients. More...

void dismissClient (int client)
 Stops keeping control of a certain client. More...

void flush ()
 Flushes all the output sockets. More...

bool isTimedOut (unsigned client) const
 Tells if one client is or not timed out. More...


Static Public Attributes

const Uint32 TIMEOUT = 60*1000
 Number of milliseconds after which a client will be considered timed out. More...


Private Methods

virtual void onReception (unsigned client)
 Method called after reception of a packet from a certain client. More...

virtual bool forwardMessage (const MessagePacket &msg, IPaddress *ip)
 Determines whether the message should or not be forwarded to the user. More...

int findClient (const IPaddress *ip) const
 Finds a client by checking its IP. More...

int registerClient (IPaddress *ip)
 Registers a new client. More...

void acknowledgeClient (int client)
 Sends an empty acknowledge MessagePacket to the 'client'. More...


Private Attributes

vector< UDPsocket > senderSockets
 Vector of sockets used to send data. More...

vector< MessagePacketoutputBuffer
 Contains the unsent message packets for each destination socket. More...

vector< bool > validClients
 Keeps the state of the controlled clients. More...

int msgCount
 Counts the number of available messages to be read.

vector< int > newClients
 Maintains a list of the newly connected clients.

vector< int > timedOutClients
 Maintains a list of the just timed out clients.

vector< Uint32 > lastMsgTime
 Vector containing the SDL time in which we received the last message from each client.


Detailed Description

Server network manager class for Perihelion.

Server network manager class for Perihelion, with capabilities to send and receive MessagePacket objects, and return them to the class' users, which will be the game server.

Please be aware of methods that can throw exceptions when indicated.

Note: Unless we find an use for them, channels in UCP sockets will be ignored, and 0 will be used by default.


Constructor & Destructor Documentation

NetManagerServer::NetManagerServer  
 

Creates a server NetManager.

Creates a server NetManager object, ready to listen for requests Closes the socket and destroys all the data structures


Member Function Documentation

void NetManagerServer::acknowledgeClient int    client [private]
 

Sends an empty acknowledge MessagePacket to the 'client'.

Parameters:
client  the newly assignated client index.

void NetManagerServer::dismissClient int    client
 

Stops keeping control of a certain client.

Stops keeping control of a certain client, which now will have to make a new service request in order to get in the game.

Parameters:
client  indicates the

int NetManagerServer::findClient const IPaddress *    ip const [private]
 

Finds a client by checking its IP.

Finds a client by checking its IP, and comparing it with all the available clients.

Parameters:
ip  identifies the client to be found.
Returns:
the client index if it already exists, or -1 otherwise.

void NetManagerServer::flush  
 

Flushes all the output sockets.

Flushes all the output sockets in the NetManager. This method can raise exceptions if something goes wrong, so please catch the 'string'.

void NetManagerServer::flush unsigned    socketIndex
 

Flushes an output socket.

Flushes the indicated output socket. It can flush just one single socket. This method can raise exceptions if something goes wrong, so please catch the 'string'.

Parameters:
socketIndex  indicates the buffer to be flushed.

bool NetManagerServer::forwardMessage const MessagePacket   msg,
IPaddress *    ip
[private, virtual]
 

Determines whether the message should or not be forwarded to the user.

Returns:
a boolean telling whether the message must pass or not.

Implements NetManager.

vector< int > NetManagerServer::getNewClients  
 

Returns the list of newly connected clients.

Returns the list of newly connected clients, in the form of a vector<int>. Each element in that vector represents the desired index for the new player, which should be used as-is along the whole system.

Returns:
a vector<int> with a list of the new clients just connected.

vector<int> NetManagerServer::getTimedOutClients  
 

Returns the list of timed out clients.

Returns the list of timed out clients, in the form of a vector<int>. Each element in that vector represents the index of the player to dismiss, which should be used as-is along the whole system. The next time this method is called, these clients won't appear again.

Returns:
a vector with a list of the clients just timed out.

bool NetManagerServer::isTimedOut unsigned    client const
 

Tells if one client is or not timed out.

After a certain amount of time specified in NetManagerServer::TIMEOUT, every client that hasn't sent any message will be considered timed out, and then no one of its messages will be attended.

Parameters:
client  is an index to the client we want to query.
Returns:
a boolean value being true if the client is timed out, and false otherwise.

MessagePacket NetManagerServer::next  
 

Returns the next received MessagePacket.

Returns the next MessagePacket received from the receiverSocket, if there is one ready. This method can raise exceptions if something goes wrong, so please catch the 'string'.

Returns:
the next MessagePacket in the queue for socketIndex

void NetManagerServer::onReception unsigned    client [private, virtual]
 

Method called after reception of a packet from a certain client.

Updates the timeout counter for the indicated client

Parameters:
client  indicates the index of the client that sent the message.

Reimplemented from NetManager.

int NetManagerServer::registerClient IPaddress *    ip [private]
 

Registers a new client.

Registers a new client and sets up the data structures needed to manage it.

Parameters:
ip  indicates the IP address of the new client.
Returns:
the index number associated to this new client.

void NetManagerServer::send const string &    msg,
unsigned    socketIndex,
bool    immediate = true
 

Sends a single message through the indicated socket.

Sends a single message through a socket determined by the socketIndex. Actually, depending on the 'immediate' parameter, this method can send the message or schedule it for later delivery, when 'flush' is called. This method could raise exceptions when something fails, so please enclose its calls within a try-catch block.

Parameters:
msg  the actual message to be sent.
socketIndex  determines the destination of the message.
immediate  indicates whether the message should be sent immediately or it can be scheduled for later delivery.

void NetManagerServer::send MessagePacket   msg,
unsigned    socketIndex,
bool    immediate = true
 

Sends a message packet through the indicated socket.

Sends a message packet through a socket determined by the socketIndex. There is no need to set the client index number in the packet, since this is done inside the method. Actually, depending on the 'immediate' parameter, this method can send the message or schedule it for later delivery, when 'flush' is called. This method could raise exceptions when something fails, so please enclose its calls within a try-catch block.

Parameters:
msg  the actual message to be sent.
socketIndex  determines the destination of the message.
immediate  indicates whether the message should be sent immediately or it can be scheduled for later delivery.

bool NetManagerServer::thereAreNewClients   const [inline]
 

Determines whether there are newly connected clients.

Determines whether there are newly connected clients as returned by 'getNewClients'.

Returns:
a boolean value, true if there are new clients, false otherwise.

bool NetManagerServer::thereAreTimedOutClients   const [inline]
 

Determines whether there are some just timed out clients.

Determines whether there are some just timed out clients as returned by 'getTimedOutClients'.

Returns:
a boolean value, true if there are timed out clients, false otherwise.


Member Data Documentation

vector<MessagePacket> NetManagerServer::outputBuffer [private]
 

Contains the unsent message packets for each destination socket.

Contains the unsent message packets for each destination socket. Messages are appended to each other, so that only one packet is sent afterwards to each destination.

vector<UDPsocket> NetManagerServer::senderSockets [private]
 

Vector of sockets used to send data.

Vector of sockets used to send data from the server to the clients

const Uint32 NetManagerServer::TIMEOUT = 60*1000 [static]
 

Number of milliseconds after which a client will be considered timed out.

Number of milliseconds that a client can remain innactive in a game, before the server considers him timed out and then disregards him.

vector<bool> NetManagerServer::validClients [private]
 

Keeps the state of the controlled clients.

Keeps the state (valid/not valid) of the controlled clients. True means 'valid', and false means 'not valid' (duh!)


The documentation for this class was generated from the following files:
Generated on Thu Jun 6 17:22:23 2002 for Perihelion by doxygen1.2.15