Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

Metaserver.h

00001 // TODO: Copyright stuff
00002 
00003 #ifndef ERIS_METASERVER_H
00004 #define ERIS_METASERVER_H
00005 
00006 #ifndef __WIN32__
00007 // pull in uint32_t on POSIX - is this generic?!
00008 #include <stdint.h>
00009 #else
00010 // Apparently not. [MW]
00011 #ifndef _STDINT_H_
00012 #define _STDINT_H_
00013 
00014 typedef unsigned char uint8_t;
00015 typedef unsigned short uint16_t;
00016 typedef unsigned int uint32_t;
00017 
00018 #endif  // _STDINT_H_
00019 
00020 #ifndef vsnprintf
00021 #define vsnprintf _vsnprintf
00022 #endif
00023 #ifndef snprintf
00024 #define snprintf _snprintf
00025 #endif
00026 
00027 #endif // __WIN32__
00028 
00029 
00030 
00031 #include <sigc++/object.h>
00032 #if SIGC_MAJOR_VERSION == 1 && SIGC_MINOR_VERSION == 0
00033 #include <sigc++/basic_signal.h>
00034 #else
00035 #include <sigc++/signal.h>
00036 #endif
00037 
00038 #include <Atlas/Message/DecoderBase.h>
00039 #include <Atlas/Objects/Operation/Info.h>
00040 #include <Atlas/Objects/Entity/RootEntity.h>
00041 
00042 #include <Eris/Types.h>
00043 #include <Eris/ServerInfo.h>
00044 
00045 // Forward decls
00046 class udp_socket_stream;
00047 class basic_socket_stream;
00048         
00049 namespace Eris {
00050         
00051 // Forward Declerations
00052 class MetaQuery;
00053 class BaseConnection;
00054 class Timeout;
00055 class PollData;
00056         
00057 #ifndef uint32_t
00058         /* WIN32 hack ...
00059         this is only true for 32bit machines but WIN64 is far ahead !! */
00060 
00061         #ifdef WINDOWS  
00062         typedef unsigned int uint32_t;
00063         #endif
00064         
00065         #ifdef MACOS
00066         #include <Types.h>
00067         // MacOS defines these anyway
00068         typedef Uint32  uint32_t;
00069         #endif
00070 #endif
00071 
00072 const int DATA_BUFFER_SIZE = 4096;
00073 
00075 typedef std::list<ServerInfo> ServerList;
00076 
00077 typedef enum {
00078         INVALID = 0,    
00079         VALID,          
00080         IN_PROGRESS     
00081 } MetaStatus;
00082 
00084 class Meta : virtual public SigC::Object,
00085                 public Atlas::Message::DecoderBase
00086 {
00087 public:
00088         Meta(const std::string &cnm, 
00089                 const std::string &msv, 
00090                 unsigned int maxQueries);
00091         virtual ~Meta();
00092 
00094         ServerList getGameServerList();
00095         
00097         int getGameServerCount();
00098 
00100         void queryServer(const std::string &host);
00101 
00108         void refresh();
00109 
00113         void cancel();
00114 
00116         const std::string& getClientName() const
00117         { return _clientName; }
00118 
00120         MetaStatus getStatus() const
00121         { return _status; }
00122 
00123         // signals
00124         
00126         SigC::Signal1<void, const ServerInfo&> ReceivedServerInfo;
00127 
00129         SigC::Signal1<void, int> GotServerCount;
00130         
00132         SigC::Signal0<void> CompletedServerList;
00133 
00136         SigC::Signal1<void, const std::string&> Failure;
00137         
00138 protected:
00139         friend class MetaQuery;
00140                 
00141         virtual void ObjectArrived(const Atlas::Message::Object &msg);
00142 
00144         void recv();
00145         
00147         void recvCmd(uint32_t op);
00148 
00150         void processCmd();
00151 
00154         void listReq(int offset = 0);
00155 
00156         void setupRecvCmd();
00157         void setupRecvData(int words, uint32_t got);
00158 
00159         void doFailure(const std::string &msg);
00160         void queryFailure(MetaQuery *q, const std::string& msg);
00161 
00162         void queryTimeout(MetaQuery *q);
00163         void metaTimeout();
00164         
00167         void connect();
00168         
00170         void disconnect();
00171         
00172         std::string _clientName;        
00173         MetaStatus _status;
00174         std::string _metaHost;
00175         
00176         typedef std::list<MetaQuery*> MetaQueryList;
00177         
00178         MetaQueryList _activeQueries,
00179                 _deleteQueries;
00180         StringList _pendingQueries;
00181         unsigned int _maxActiveQueries;
00182 
00183 
00184         typedef std::map<std::string, ServerInfo> ServerInfoMap;
00185         ServerInfoMap _gameServers,
00186                 _lastValidList;
00187 
00188         // storage for the Metaserver protocol
00189         udp_socket_stream* _stream;
00190         char _data[DATA_BUFFER_SIZE];
00191         char* _dataPtr; 
00192 
00193         unsigned int _bytesToRecv, 
00194                 _totalServers,          
00195                 _packed;                
00196                 
00197         bool _recvCmd;          
00198         uint32_t _gotCmd;       
00199         
00200         Timeout* _timeout;      
00201         
00202         void gotData(PollData&);
00203 };
00204         
00205 } // of namespace Eris
00206 
00207 #endif

Generated on Thu May 22 08:01:04 2003 for Eris by doxygen1.3-rc3