00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef NETPEERMANAGER_H
00023 #define NETPEERMANAGER_H
00024
00025 #include "netmanager.h"
00026
00035 #define PEER_MAX_NAME 63
00036
00040 #define PEER_MAX_REASON 255
00041
00042 class NetPeerSocket;
00043 class TiXmlNode;
00044
00062 class DECLSPEC NetPeerManager : public NetBasicManager
00063 {
00064 public:
00070 DECLSPEC NetPeerManager(const char *name, BasicObject *p, int maxpeers = 255 );
00090 DECLSPEC NetPeerManager(TiXmlElement *el, BasicObject *p );
00091 virtual DECLSPEC ~NetPeerManager();
00092 virtual const char *getClassName() { return "NetPeerManager"; }
00093
00103 virtual DECLSPEC bool init( unsigned int port = NETWORK_PORT, const char *permissionfn = 0 );
00104
00111 DECLSPEC void setNetName( const char *name );
00115 DECLSPEC const char *getNetName() const {return chName;}
00116
00122 DECLSPEC NetPeerSocket *getSocketByName( const char *name );
00123
00127 DECLSPEC void requestPings();
00135 DECLSPEC Uint32 getPings( Uint32 *min, Uint32 *max );
00158 DECLSPEC bool loadPermissions( TiXmlNode *node );
00171 DECLSPEC bool loadPermissions( const char *fn );
00181 DECLSPEC bool hasPermission( const char *name, Uint32 host, char *reason = 0 );
00186 bool bAllowNewConnections;
00187
00195 static NetPeerManager *getThe() { return (NetPeerManager*)NetBasicManager::getThe(); }
00196 protected:
00197 virtual DECLSPEC void onInit();
00198 virtual DECLSPEC NetSocket *createSocket( TCPsocket socket );
00199
00200 private:
00201 struct HOST_INFO
00202 {
00203 char chName[PEER_MAX_NAME+1];
00204 Uint32 ip;
00205 bool bAllowed;
00206 };
00207 typedef list<HOST_INFO>::iterator PermissionIter;
00208 list<HOST_INFO> lPermissionInfos;
00209
00210 int nMaxPeers;
00211 char chName[PEER_MAX_NAME+1];
00212 };
00213
00214 #endif