Metaserver.h

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

Generated on Tue Mar 18 00:36:53 2008 for Eris by  doxygen 1.5.4