Planeshift
|
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>
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. | |
Client * | GetAnyClient (int cnum) |
Gets a client with the specified id. | |
Client * | GetClient (int cnum) |
Gets a client with the specified id. | |
ClientConnectionSet * | GetConnections () |
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 NetManager * | Create (CacheManager *cacheManager, int client_firstmsg, int npcclient_firstmsg, int timeout=15000) |
static void | Destroy () |
Protected Member Functions | |
virtual Connection * | GetConnByIP (LPSOCKADDR_IN addr) |
Returns a NetManager::Connection from the given IP address. | |
virtual Connection * | GetConnByNum (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. |
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.
NetManager::NetManager | ( | ) |
NetManager::~NetManager | ( | ) |
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!
me | Is the message to be broadcast to other clients. |
scope | Determines which clients will recieve the broadcasted message. Scope can be one of: |
guild | Is 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. |
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] |
Gets a client with the specified id.
cnum | The id of the client to retrive. |
Gets a client with the specified id.
cnum | The id of the client to retrive. |
virtual Connection* NetManager::GetConnByIP | ( | LPSOCKADDR_IN | addr | ) | [protected, virtual] |
Returns a NetManager::Connection from the given IP address.
addr | Is the IP address of client we want to find the connection for. |
Implements NetBase.
virtual Connection* NetManager::GetConnByNum | ( | uint32_t | clientnum | ) | [protected, virtual] |
Returns a NetManager::Connection from the given client number.
clientnum | Is the client number we wish to get the connection for. |
Implements NetBase.
ClientConnectionSet* NetManager::GetConnections | ( | ) | [inline] |
Gets a list of all connected 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.
addr | Is the IP address of the client we have not seen before. |
msg | Is the message recieved from the unknown client. |
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.
cachemanager | Pointer 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. |
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.
me | Is the message to be sent to other clients. |
multi | Is a vector of all the clients to send this message to. |
except | Is a client number for a client NOT to send this message to. This would usually be the client trying to send the message. |
range | Is 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] |
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.