00001
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
00014 #include <memory>
00015
00016 #ifndef __WIN32__
00017
00018 #include <stdint.h>
00019 #else
00020
00021 #ifndef _STDINT_H_
00022 #define _STDINT_H_
00023
00024 typedef unsigned char uint8_t;
00025 typedef unsigned short uint16_t;
00026 typedef unsigned int uint32_t;
00027
00028 #endif // _STDINT_H_
00029
00030 #endif // __WIN32__
00031
00032
00033 class udp_socket_stream;
00034 class basic_socket_stream;
00035
00036 namespace Eris {
00037
00038
00039 class MetaQuery;
00040 class BaseConnection;
00041 class Timeout;
00042 class PollData;
00043
00044 #ifndef uint32_t
00045
00046
00047
00048 #ifdef WINDOWS
00049 typedef unsigned int uint32_t;
00050 #endif
00051
00052 #ifdef MACOS
00053 #include <Types.h>
00054
00055 typedef Uint32 uint32_t;
00056 #endif
00057 #endif
00058
00059 const int DATA_BUFFER_SIZE = 4096;
00060
00062 typedef std::list<ServerInfo> ServerList;
00063
00065 class Meta : virtual public sigc::trackable,
00066 public Atlas::Objects::ObjectsDecoder
00067 {
00068 public:
00081 Meta(const std::string &msv, unsigned int maxQueries);
00082 virtual ~Meta();
00083
00085 unsigned int getGameServerCount() const;
00086
00090 const ServerInfo& getInfoForServer(unsigned int index) const;
00091
00093 void queryServerByIndex(unsigned int index);
00094
00101 void refresh();
00102
00107 void cancel();
00108
00109
00110
00112 sigc::signal<void, const ServerInfo&> ReceivedServerInfo;
00113
00118 sigc::signal<void, int> CompletedServerList;
00119
00121 sigc::signal<void> AllQueriesDone;
00122
00127 sigc::signal<void, const std::string&> Failure;
00128
00129 protected:
00130 friend class MetaQuery;
00131
00132 virtual void objectArrived(const Atlas::Objects::Root& obj);
00133
00134 void doFailure(const std::string &msg);
00135 void queryFailure(MetaQuery *q, const std::string& msg);
00136
00137 void queryTimeout(MetaQuery *q);
00138 void metaTimeout();
00139
00142 void connect();
00143
00145 void disconnect();
00146
00147 private:
00149 void recv();
00150
00152 void recvCmd(uint32_t op);
00153
00155 void processCmd();
00156
00159 void listReq(int offset = 0);
00160
00161 void setupRecvCmd();
00162 void setupRecvData(int words, uint32_t got);
00163
00164 void deleteQuery(MetaQuery* query);
00165
00166 void internalQuery(unsigned int index);
00167
00168 const std::string m_clientName;
00169
00170 typedef enum
00171 {
00172 INVALID = 0,
00173 VALID,
00174 GETTING_LIST,
00175 QUERYING
00176 } MetaStatus;
00177
00178 MetaStatus m_status;
00180 const std::string m_metaHost;
00181
00182 typedef std::set<MetaQuery*> QuerySet;
00183 QuerySet m_activeQueries;
00184
00186 typedef std::list<int> IntList;
00187 IntList m_pendingQueries;
00188 unsigned int m_maxActiveQueries;
00189
00190 typedef std::vector<ServerInfo> ServerInfoArray;
00191 ServerInfoArray m_gameServers,
00192 m_lastValidList;
00193
00194
00195 udp_socket_stream* m_stream;
00196
00197 char _data[DATA_BUFFER_SIZE];
00198 char* _dataPtr;
00199
00200 unsigned int _bytesToRecv,
00201 _totalServers,
00202 _packed;
00203
00204 bool _recvCmd;
00205 uint32_t _gotCmd;
00206
00207 std::auto_ptr<Timeout> m_timeout;
00208
00209 void gotData(PollData&);
00210 };
00211
00212 }
00213
00214 #endif