Eris 1.3.16
|
00001 // TODO: Copyright stuff 00002 00003 #ifndef ERIS_METASERVER_H 00004 #define ERIS_METASERVER_H 00005 00006 #include <Eris/Types.h> 00007 #include <Eris/ServerInfo.h> 00008 00009 #include <Atlas/Objects/Decoder.h> 00010 00011 #include <sigc++/trackable.h> 00012 #include <sigc++/signal.h> 00013 #include <memory> 00014 00015 #ifndef __WIN32__ 00016 // pull in uint32_t on POSIX - is this generic?! 00017 #include <stdint.h> 00018 #else 00019 // Apparently not. [MW] 00020 #ifndef _STDINT_H_ 00021 #define _STDINT_H_ 00022 00023 typedef unsigned char uint8_t; 00024 typedef unsigned short uint16_t; 00025 typedef unsigned int uint32_t; 00026 00027 #endif // _STDINT_H_ 00028 00029 #endif // __WIN32__ 00030 00031 // Forward decls 00032 class udp_socket_stream; 00033 class basic_socket_stream; 00034 00035 namespace Eris { 00036 00037 // Forward Declerations 00038 class MetaQuery; 00039 class BaseConnection; 00040 class Timeout; 00041 class PollData; 00042 00043 #ifndef uint32_t 00044 /* WIN32 hack ... 00045 this is only true for 32bit machines but WIN64 is far ahead !! */ 00046 00047 #ifdef WINDOWS 00048 typedef unsigned int uint32_t; 00049 #endif 00050 00051 #ifdef MACOS 00052 #include <Types.h> 00053 // MacOS defines these anyway 00054 typedef Uint32 uint32_t; 00055 #endif 00056 #endif 00057 00058 const int DATA_BUFFER_SIZE = 4096; 00059 00061 typedef std::list<ServerInfo> ServerList; 00062 00064 class Meta : virtual public sigc::trackable, 00065 public Atlas::Objects::ObjectsDecoder 00066 { 00067 public: 00080 Meta(const std::string &msv, unsigned int maxQueries); 00081 virtual ~Meta(); 00082 00084 unsigned int getGameServerCount() const; 00085 00089 const ServerInfo& getInfoForServer(unsigned int index) const; 00090 00092 void queryServerByIndex(unsigned int index); 00093 00100 void refresh(); 00101 00106 void cancel(); 00107 00108 // signals 00109 00111 sigc::signal<void, const ServerInfo&> ReceivedServerInfo; 00112 00117 sigc::signal<void, int> CompletedServerList; 00118 00120 sigc::signal<void> AllQueriesDone; 00121 00126 sigc::signal<void, const std::string&> Failure; 00127 00128 protected: 00129 friend class MetaQuery; 00130 00131 virtual void objectArrived(const Atlas::Objects::Root& obj); 00132 00133 void doFailure(const std::string &msg); 00134 void queryFailure(MetaQuery *q, const std::string& msg); 00135 00136 void queryTimeout(MetaQuery *q); 00137 void metaTimeout(); 00138 00141 void connect(); 00142 00144 void disconnect(); 00145 00146 private: 00148 void recv(); 00149 00151 void recvCmd(uint32_t op); 00152 00154 void processCmd(); 00155 00158 void listReq(int offset = 0); 00159 00160 void setupRecvCmd(); 00161 void setupRecvData(int words, uint32_t got); 00162 00163 void deleteQuery(MetaQuery* query); 00164 00165 void internalQuery(unsigned int index); 00166 00167 const std::string m_clientName; 00168 00169 typedef enum 00170 { 00171 INVALID = 0, 00172 VALID, 00173 GETTING_LIST, 00174 QUERYING 00175 } MetaStatus; 00176 00177 MetaStatus m_status; 00179 const std::string m_metaHost; 00180 00181 typedef std::set<MetaQuery*> QuerySet; 00182 QuerySet m_activeQueries; 00183 00185 typedef std::list<int> IntList; 00186 IntList m_pendingQueries; 00187 unsigned int m_maxActiveQueries; 00188 00189 typedef std::vector<ServerInfo> ServerInfoArray; 00190 ServerInfoArray m_gameServers, 00191 m_lastValidList; 00192 00193 // storage for the Metaserver protocol 00194 udp_socket_stream* m_stream; 00195 00196 char _data[DATA_BUFFER_SIZE]; 00197 char* _dataPtr; 00198 00199 std::streamsize _bytesToRecv; 00200 unsigned int _totalServers, 00201 _packed; 00202 00203 bool _recvCmd; 00204 uint32_t _gotCmd; 00205 00206 std::auto_ptr<Timeout> m_timeout; 00207 00208 void gotData(PollData&); 00209 }; 00210 00211 } // of namespace Eris 00212 00213 #endif