#include <netpeermanager.h>
Inheritance diagram for NetPeerManager:
Public Member Functions | |
DECLSPEC | NetPeerManager (const char *name, BasicObject *p, int maxpeers=255) |
DECLSPEC | NetPeerManager (TiXmlElement *el, BasicObject *p) |
virtual const char * | getClassName () |
virtual DECLSPEC bool | init (unsigned int port=NETWORK_PORT, const char *permissionfn=0) |
DECLSPEC void | setNetName (const char *name) |
DECLSPEC const char * | getNetName () const |
DECLSPEC NetPeerSocket * | getSocketByName (const char *name) |
DECLSPEC void | requestPings () |
DECLSPEC Uint32 | getPings (Uint32 *min, Uint32 *max) |
DECLSPEC bool | loadPermissions (TiXmlNode *node) |
DECLSPEC bool | loadPermissions (const char *fn) |
DECLSPEC bool | hasPermission (const char *name, Uint32 host, char *reason=0) |
Static Public Member Functions | |
static NetPeerManager * | getThe () |
Public Attributes | |
bool | bAllowNewConnections |
Protected Member Functions | |
virtual DECLSPEC void | onInit () |
virtual DECLSPEC NetSocket * | createSocket (TCPsocket socket) |
Classes | |
struct | HOST_INFO |
This class contains many functions for peer to peer communication. It uses client and server functions to connect to others and let others connect. As socket class, is used NetPeerSocket.
As a special feature, this class is able to work with XML Nodes.
NetPeerManager::NetPeerManager | ( | const char * | name, | |
BasicObject * | p, | |||
int | maxpeers = 255 | |||
) |
Constructor
maxpeers | limits the maximum number of allowed peers to this value, if it is below MAX_PEERS, otherwise the limit equals MAX_PEERS |
NetPeerManager::NetPeerManager | ( | TiXmlElement * | el, | |
BasicObject * | p | |||
) |
Constructs the manager by using a XML node.
el | The node can contain the attribute "Username". If a subnode "Permissions" exists, this subnode will be parsed with the loadPermissions( XMLNode* ) function, if not and the attribute "PermissionFile" is specified, the file will be parsed and if no permission data is given, every host is allowed to connect to the manager. If the attribte "Port" exists, this port will be opened, otherwise the default NETWORK_PORT will be used. Here an example: <NetPeerManager Name="NetPeerManager" Port="1230" Username="my name" PermissionFile="user/permissions.pml" /> |
virtual const char* NetPeerManager::getClassName | ( | ) | [inline, virtual] |
This function should be overriden in every sub-class of BasicObject!
Reimplemented from BasicObject.
bool NetPeerManager::init | ( | unsigned int | port = NETWORK_PORT , |
|
const char * | permissionfn = 0 | |||
) | [virtual] |
Initializes the manager with the given params. Only call this, if you do not use the constructor with the XML-element.
port | the port to listen for incomming connection requests | |
permissionfn | the filename of a XML file, containing data for permission rules, that say whom to accept and whom to reject. |
void NetPeerManager::setNetName | ( | const char * | name | ) |
Sets the name of the local machine, which is used to connect to other machines in the network.
name | the name as NUL-terminated string |
DECLSPEC const char* NetPeerManager::getNetName | ( | ) | const [inline] |
NetPeerSocket * NetPeerManager::getSocketByName | ( | const char * | name | ) |
name | the name to look for |
void NetPeerManager::requestPings | ( | ) |
Sends a ping request to all hosts. (This does not use ICMP, but TCP)
Uint32 NetPeerManager::getPings | ( | Uint32 * | min, | |
Uint32 * | max | |||
) |
Use this function to get ping times. To get current times, call requestPings() before getPings and wait a bit between these two calls.
min | if not NULL, the time of the fastest response of a host will be assigned here | |
max | if not NULL, the time of the slowest response of a host will be assigned here |
bool NetPeerManager::loadPermissions | ( | TiXmlNode * | node | ) |
Parses the node to store the allowed hosts in a privat struct, which is used by hasPermission to allow or deny an incomming connection. Example:
<Allow> <Player IP="192.168.2.3" /> <Player IP="192.168.2.4" /> <Player IP="192.168.2.5" /> <Player Name="test" /> <Player IP="127.0.0.1" /> </Allow> <Disallow> <Player IP="192.168.2.6" /> <Player /> </Disallow>
bool NetPeerManager::loadPermissions | ( | const char * | fn | ) |
Loads the XML file with the specified filename and parses it's Permissions node with loadPermissions( XMLNode ). The file has to be structured as follows (minimal version):
<PML><Permissions> [<Allow> (allowed Player-tags) </Allow>] [<Disallow> (disallowed Player-tags) </Disallow>] </Permissions></PML>
bool NetPeerManager::hasPermission | ( | const char * | name, | |
Uint32 | host, | |||
char * | reason = 0 | |||
) |
Prooves, whether the specified host has permission to connect, as specified in the permission-tags.
name | the name of the host | |
host | the host's IP address (in OSBO) | |
reason | NULL, or a pointer to reserved space, filled with the reason, why the host has no permission, if a reason is availible |
static NetPeerManager* NetPeerManager::getThe | ( | ) | [inline, static] |
Reimplemented from NetBasicManager.
void NetPeerManager::onInit | ( | ) | [protected, virtual] |
Initializes the object's variables by reading data from the XML element. If there were no XML data used for creation, nothing is done. This function calls onInit() of its children recursively (after it has inited itself). It is highly recommended to call BasicObject::onInit(), usually at the end of the onInit() method, when overwriting it in a derived class.
Reimplemented from NetBasicManager.
NetSocket * NetPeerManager::createSocket | ( | TCPsocket | socket | ) | [protected, virtual] |
Creates a class, derived from NetSocket, that is compatible to the managing class.
socket | the SDL-TCP socket which is used by the new NetSocket |
Implements NetBasicManager.
If - what ever the reason is - no further connections should be accepted then set this to false. It is true, when NetPeerManager is created