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/Message/DecoderBase.h>
00010
00011
#include <sigc++/object.h>
00012
#include <sigc++/signal.h>
00013
00014
#ifndef __WIN32__
00015
00016
#include <stdint.h>
00017
#else
00018
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
00031
class udp_socket_stream;
00032
class basic_socket_stream;
00033
00034
namespace Eris {
00035
00036
00037
class MetaQuery;
00038
class BaseConnection;
00039
class Timeout;
00040
class PollData;
00041
00042
#ifndef uint32_t
00043
00044
00045
00046
#ifdef WINDOWS
00047
typedef unsigned int uint32_t;
00048
#endif
00049
00050
#ifdef MACOS
00051
#include <Types.h>
00052
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();
00083
00085
void queryServer(
const std::string &host);
00086
00093
void refresh();
00094
00098
void cancel();
00099
00101 const std::string&
getClientName()
const
00102
{
return _clientName; }
00103
00105 MetaStatus
getStatus()
const
00106
{
return _status; }
00107
00108
00109
00111 SigC::Signal1<void, const ServerInfo&>
ReceivedServerInfo;
00112
00114 SigC::Signal1<void, int>
GotServerCount;
00115
00117 SigC::Signal0<void>
CompletedServerList;
00118
00121 SigC::Signal1<void, const std::string&>
Failure;
00122
00123
protected:
00124
friend class MetaQuery;
00125
00126
virtual void objectArrived(
const Atlas::Message::Element &msg);
00127
00129
void recv();
00130
00132
void recvCmd(uint32_t op);
00133
00135
void processCmd();
00136
00139
void listReq(
int offset = 0);
00140
00141
void setupRecvCmd();
00142
void setupRecvData(
int words, uint32_t got);
00143
00144
void doFailure(
const std::string &msg);
00145
void queryFailure(
MetaQuery *q,
const std::string& msg);
00146
00147
void queryTimeout(
MetaQuery *q);
00148
void metaTimeout();
00149
00152
void connect();
00153
00155
void disconnect();
00156
00157 std::string
_clientName;
00158 MetaStatus _status;
00159 std::string _metaHost;
00160
00161
typedef std::list<MetaQuery*> MetaQueryList;
00162
00163 MetaQueryList _activeQueries,
00164 _deleteQueries;
00165 StringList _pendingQueries;
00166
unsigned int _maxActiveQueries;
00167
00168
00169
typedef std::map<std::string, ServerInfo> ServerInfoMap;
00170 ServerInfoMap _gameServers,
00171 _lastValidList;
00172
00173
00174 udp_socket_stream* _stream;
00175
char _data[DATA_BUFFER_SIZE];
00176 char*
_dataPtr;
00177
00178
unsigned int _bytesToRecv,
00179 _totalServers,
00180
_packed;
00181
00182 bool _recvCmd;
00183 uint32_t
_gotCmd;
00184
00185 Timeout*
_timeout;
00186
00187
void gotData(PollData&);
00188 };
00189
00190 }
00191
00192
#endif