Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members

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/Message/DecoderBase.h>
00010 
00011 #include <sigc++/object.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 
00062 typedef enum {
00063         INVALID = 0,    
00064         VALID,          
00065         IN_PROGRESS     
00066 } MetaStatus;
00067 
00069 class Meta : virtual public SigC::Object,
00070                 public Atlas::Message::DecoderBase
00071 {
00072 public:
00073         Meta(const std::string &cnm, 
00074                 const std::string &msv, 
00075                 unsigned int maxQueries);
00076         virtual ~Meta();
00077 
00079         ServerList getGameServerList();
00080         
00082         int getGameServerCount() const;
00083         
00085         const ServerInfo& getInfoForServer(unsigned int index) const;
00086 
00088         void queryServer(const std::string &host);
00089 
00096         void refresh();
00097 
00101         void cancel();
00102 
00104         const std::string& getClientName() const
00105         { return _clientName; }
00106 
00108         MetaStatus getStatus() const
00109         { return _status; }
00110 
00112         unsigned int numServers() const
00113         { return getGameServerCount(); }
00114 
00115         // signals
00116         
00118         SigC::Signal1<void, const ServerInfo&> ReceivedServerInfo;
00119 
00121         SigC::Signal1<void, int> GotServerCount;
00122         
00124         SigC::Signal0<void> CompletedServerList;
00125 
00128         SigC::Signal1<void, const std::string&> Failure;
00129         
00130 protected:
00131         friend class MetaQuery;
00132                 
00133         virtual void objectArrived(const Atlas::Message::Element &msg);
00134 
00136         void recv();
00137         
00139         void recvCmd(uint32_t op);
00140 
00142         void processCmd();
00143 
00146         void listReq(int offset = 0);
00147 
00148         void setupRecvCmd();
00149         void setupRecvData(int words, uint32_t got);
00150 
00151         void doFailure(const std::string &msg);
00152         void queryFailure(MetaQuery *q, const std::string& msg);
00153 
00154         void queryTimeout(MetaQuery *q);
00155         void metaTimeout();
00156         
00159         void connect();
00160         
00162         void disconnect();
00163         
00164         std::string _clientName;        
00165         MetaStatus _status;
00166         std::string _metaHost;
00167         
00168         typedef std::list<MetaQuery*> MetaQueryList;
00169         
00170         MetaQueryList _activeQueries,
00171                 _deleteQueries;
00172         StringList _pendingQueries;
00173         unsigned int _maxActiveQueries;
00174 
00175 
00176         typedef std::map<std::string, ServerInfo> ServerInfoMap;
00177         ServerInfoMap _gameServers,
00178                 _lastValidList;
00179 
00180         // storage for the Metaserver protocol
00181         udp_socket_stream* _stream;
00182         char _data[DATA_BUFFER_SIZE];
00183         char* _dataPtr; 
00184 
00185         unsigned int _bytesToRecv, 
00186                 _totalServers,          
00187                 _packed;                
00188                 
00189         bool _recvCmd;          
00190         uint32_t _gotCmd;       
00191         
00192         Timeout* _timeout;      
00193         
00194         void gotData(PollData&);
00195 };
00196         
00197 } // of namespace Eris
00198 
00199 #endif

Generated on Wed Nov 10 20:56:36 2004 for Eris by  doxygen 1.3.9.1