00001 /********************************************************************************/ 00002 /* */ 00003 /* Netrinjo-Engine - a library for game-development */ 00004 /* Copyright (C) 2005-2006 by Tobias Nadler */ 00005 /* */ 00006 /* This library is free software; you can redistribute it and/or */ 00007 /* modify it under the terms of the GNU Lesser General Public */ 00008 /* License as published by the Free Software Foundation; either */ 00009 /* version 2.1 of the License, or (at your option) any later version. */ 00010 /* */ 00011 /* This library is distributed in the hope that it will be useful, */ 00012 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ 00013 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */ 00014 /* Lesser General Public License for more details. */ 00015 /* */ 00016 /* You should have received a copy of the GNU Lesser General Public */ 00017 /* License along with this library; if not, write to the Free Software */ 00018 /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 00019 /* */ 00020 /********************************************************************************/ 00021 00022 #ifndef NETPEERSOCKET_H 00023 #define NETPEERSOCKET_H 00024 00025 #include "netsocket.h" 00026 #include <list> 00027 #include "netpeermanager.h" 00028 00037 #define MAX_PING 5000 00038 00039 using namespace std; 00040 struct NetBasicData; 00041 class NetPeerManager; 00042 00054 class DECLSPEC NetPeerSocket : public NetStandardSocket 00055 { 00056 public: 00063 DECLSPEC NetPeerSocket( const char *name, NetPeerManager *parent, TCPsocket connection = NULL ); 00070 DECLSPEC NetPeerSocket( const char *name, NetPeerManager *parent, IPaddress ip ); 00075 DECLSPEC NetPeerSocket( TiXmlElement *el, NetPeerManager *parent ); 00076 virtual DECLSPEC ~NetPeerSocket(); 00077 00078 virtual const char *getClassName() { return "NetPeerSocket"; } 00079 00081 const char *getNetName() { return chName; } 00082 00092 DECLSPEC Uint32 fastPing(); 00099 DECLSPEC void requestPing(); 00104 Uint32 lastPing() const { return tPing; } 00105 00107 int getListenPort() { return nListenPort; } 00108 00109 // virtual DECLSPEC int readData( char *data, int *err = NULL ); 00110 // virtual DECLSPEC char *readData( int *size ); 00111 00112 // just for usage via BasicSlot 00113 static void newsocket(void *presult, BasicObject *o, void *xmldata) 00114 { 00115 NetSocket *r = new NetPeerSocket((TiXmlElement*)xmldata, (NetPeerManager*)o); 00116 *(NetSocket**)presult = r; 00117 } 00118 00119 protected: 00121 char chName[PEER_MAX_NAME+1]; 00123 int nListenPort; 00124 00130 virtual DECLSPEC void handleData( NetBasicData *d ); 00131 virtual DECLSPEC bool onReceive(); 00132 00133 virtual DECLSPEC void onConnect(); 00134 00138 virtual DECLSPEC void onPing() {} 00139 private: 00140 void init(); 00141 Uint32 tPing, tPingSent; 00142 // ob Verbindung aktiv aufgebaut wurde, oder passiv 00143 bool bActiveConnect; 00144 }; 00145 00146 #endif