Planeshift
Public Member Functions | Static Public Member Functions | Protected Member Functions

NetManager Class Reference

This is the network thread handling packets sending/receiving to/from network other threads can register a message queue and the network thread will sort messages for them and put them in their queue. More...

#include <netmanager.h>

List of all members.

Public Member Functions

virtual void Broadcast (MsgEntry *me, int scope, int guild=-1)
 This broadcasts the same msg out to a bunch of Clients.
void CheckLinkDead (void)
 Checks for and deletes link dead clients.
ClientGetAnyClient (int cnum)
 Gets a client with the specified id.
ClientGetClient (int cnum)
 Gets a client with the specified id.
ClientConnectionSetGetConnections ()
 Gets a list of all connected clients.
bool Initialize (CacheManager *cachemanager, int client_firstmsg, int npcclient_firstmsg, int timeout=15000)
 Initialize the network thread.
virtual void Multicast (MsgEntry *me, const csArray< PublishDestination > &multi, uint32_t except, float range)
 Sends the given message me to all the clients in the list.
 NetManager ()
void Run ()
 This is the main thread function.
virtual bool SendMessage (MsgEntry *me)
 Sends the given message to the client listed in the message.
bool SendMessageDelayed (MsgEntry *me, csTicks delay)
 Queues the message for sending later, so the calling classes don't have to all manage this themselves.
 ~NetManager ()

Static Public Member Functions

static NetManagerCreate (CacheManager *cacheManager, int client_firstmsg, int npcclient_firstmsg, int timeout=15000)
static void Destroy ()

Protected Member Functions

virtual ConnectionGetConnByIP (LPSOCKADDR_IN addr)
 Returns a NetManager::Connection from the given IP address.
virtual ConnectionGetConnByNum (uint32_t clientnum)
 Returns a NetManager::Connection from the given client number.
virtual bool HandleUnknownClient (LPSOCKADDR_IN addr, MsgEntry *msg)
 Handles/connects a new client from an unknown IP address.

Detailed Description

This is the network thread handling packets sending/receiving to/from network other threads can register a message queue and the network thread will sort messages for them and put them in their queue.

Definition at line 49 of file netmanager.h.


Constructor & Destructor Documentation

NetManager::NetManager ( )
NetManager::~NetManager ( )

Member Function Documentation

virtual void NetManager::Broadcast ( MsgEntry me,
int  scope,
int  guild = -1 
) [virtual]

This broadcasts the same msg out to a bunch of Clients.

Which clients recieve this message, depend on the scope.DON'T use this in the client app, it's only here for the MsgHandler class!

Parameters:
meIs the message to be broadcast to other clients.
scopeDetermines which clients will recieve the broadcasted message. Scope can be one of:

guildIs the ID of the guild of the owner of the message. This is only used when scope is set to BC_GUILD. By default is set to -1 and is unused.
See also:
MsgEntry

Implements NetBase.

void NetManager::CheckLinkDead ( void  )

Checks for and deletes link dead clients.

This is called periodicly to detect linkdead clients. If it finds a link dead client then it will delete the client's connection.

static NetManager* NetManager::Create ( CacheManager cacheManager,
int  client_firstmsg,
int  npcclient_firstmsg,
int  timeout = 15000 
) [static]
static void NetManager::Destroy ( ) [static]
Client* NetManager::GetAnyClient ( int  cnum)

Gets a client with the specified id.

Parameters:
cnumThe id of the client to retrive.
Returns:
Returns a pointer to the specified client or NULL if not found.
Client* NetManager::GetClient ( int  cnum)

Gets a client with the specified id.

Parameters:
cnumThe id of the client to retrive.
Returns:
Returns a pointer to the specified client or NULL if not found or client not ready.
virtual Connection* NetManager::GetConnByIP ( LPSOCKADDR_IN  addr) [protected, virtual]

Returns a NetManager::Connection from the given IP address.

Parameters:
addrIs the IP address of client we want to find the connection for.
Returns:
Returns a Connection object that contains the connection for the given IP address.

Implements NetBase.

virtual Connection* NetManager::GetConnByNum ( uint32_t  clientnum) [protected, virtual]

Returns a NetManager::Connection from the given client number.

Parameters:
clientnumIs the client number we wish to get the connection for.
Returns:
Returns a Connection object that contains the connection for the given client number.

Implements NetBase.

ClientConnectionSet* NetManager::GetConnections ( ) [inline]

Gets a list of all connected clients.

Returns:
Returns a pointer to the list of all the clients.

Definition at line 131 of file netmanager.h.

virtual bool NetManager::HandleUnknownClient ( LPSOCKADDR_IN  addr,
MsgEntry msg 
) [protected, virtual]

Handles/connects a new client from an unknown IP address.

This is called when we have recieved a message from a client that we don't know yet. This happens when a new client connects to us. First thing it does is check to make sure the msgtype is equal to firstmsg. If not then we have recieved some random packet. If firstmsg is accepted then it adds this new client to our client list and then changed the client number on the message so an acknowledge can be sent back later.

Parameters:
addrIs the IP address of the client we have not seen before.
msgIs the message recieved from the unknown client.
Returns:
Returns true if the client has been verified and connected or false if it is a bad client or failed to connect properly.

Implements NetBase.

bool NetManager::Initialize ( CacheManager cachemanager,
int  client_firstmsg,
int  npcclient_firstmsg,
int  timeout = 15000 
)

Initialize the network thread.

Initializes firstmsg and timeout is the timout in ms for a connection. If no packets are sent or received in this time then the connection is made linkdead.

Parameters:
cachemanagerPointer to the cachemanager
client_firstmsg,:Is the message type that must be first received from a client to determine if it is a valid client.
npcclient_firstmsg,:Is the message type that must be first received from a npc client to determine if it is a valid npc client.
timeout,:Is the timeout value for a connection given in ms. The default value given is 15000ms.
Returns:
Returns success or faliure for initializing.
virtual void NetManager::Multicast ( MsgEntry me,
const csArray< PublishDestination > &  multi,
uint32_t  except,
float  range 
) [virtual]

Sends the given message me to all the clients in the list.

Sends the given message me to all the clients in the list (clientlist) which is of size count. This will send the message to all the clients except the client which has a client number given in the variable except.

Note:
(Brendon): Why is multi not const & ?
Parameters:
meIs the message to be sent to other clients.
multiIs a vector of all the clients to send this message to.
exceptIs a client number for a client NOT to send this message to. This would usually be the client trying to send the message.
rangeIs the maximum distance the client must be away to be out of "message reception range".

Implements NetBase.

void NetManager::Run ( )

This is the main thread function.

If it hasn't been initialized it waits until the server is ready to go (i.e. is initialized) if so then it sits in a loop where it calls NetBase::ProcessNetwork() and also checks all the dead links. This method also calculates the data transfer rate.

virtual bool NetManager::SendMessage ( MsgEntry me) [virtual]

Sends the given message to the client listed in the message.

MsgEntry has info on who the message is going to.

Parameters:
meIs a message MsgEntry which contains the message and the client number to send the message to.
Returns:
Returns success or faliure.

Reimplemented from NetBase.

bool NetManager::SendMessageDelayed ( MsgEntry me,
csTicks  delay 
)

Queues the message for sending later, so the calling classes don't have to all manage this themselves.


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