Eris  1.3.21
Metaserver.h
1 // TODO: Copyright stuff
2 
3 #ifndef ERIS_METASERVER_H
4 #define ERIS_METASERVER_H
5 
6 #include <Eris/Types.h>
7 #include <Eris/ServerInfo.h>
8 
9 #include <Atlas/Objects/Decoder.h>
10 
11 #include <sigc++/trackable.h>
12 #include <sigc++/signal.h>
13 #include <memory>
14 
15 #ifndef __WIN32__
16 // pull in uint32_t on POSIX - is this generic?!
17 #include <stdint.h>
18 #else
19 // Apparently not. [MW]
20 #ifndef _STDINT_H_
21 #define _STDINT_H_
22 
23 typedef unsigned char uint8_t;
24 typedef unsigned short uint16_t;
25 typedef unsigned int uint32_t;
26 
27 #endif // _STDINT_H_
28 
29 #endif // __WIN32__
30 
31 // Forward decls
32 class udp_socket_stream;
33 class basic_socket_stream;
34 
35 namespace Eris {
36 
37 // Forward Declerations
38 class MetaQuery;
39 class BaseConnection;
40 class Timeout;
41 class PollData;
42 
43 #ifndef uint32_t
44  /* WIN32 hack ...
45  this is only true for 32bit machines but WIN64 is far ahead !! */
46 
47  #ifdef WINDOWS
48  typedef unsigned int uint32_t;
49  #endif
50 
51  #ifdef MACOS
52  #include <Types.h>
53  // MacOS defines these anyway
54  typedef Uint32 uint32_t;
55  #endif
56 #endif
57 
58 const int DATA_BUFFER_SIZE = 4096;
59 
61 typedef std::list<ServerInfo> ServerList;
62 
64 class Meta : virtual public sigc::trackable,
65  public Atlas::Objects::ObjectsDecoder
66 {
67 public:
68  typedef enum
69  {
70  INVALID = 0,
74  } MetaStatus;
75 
88  Meta(const std::string &msv, unsigned int maxQueries);
89  virtual ~Meta();
90 
92  unsigned int getGameServerCount() const;
93 
97  const ServerInfo& getInfoForServer(unsigned int index) const;
98 
100  void queryServerByIndex(unsigned int index);
101 
108  void refresh();
109 
114  void cancel();
115 
116 // accessors
117  MetaStatus getStatus() const {
118  return m_status;
119  }
120 // signals
121 
123  sigc::signal<void, const ServerInfo&> ReceivedServerInfo;
124 
129  sigc::signal<void, int> CompletedServerList;
130 
132  sigc::signal<void> AllQueriesDone;
133 
138  sigc::signal<void, const std::string&> Failure;
139 
140 protected:
141  friend class MetaQuery;
142 
143  virtual void objectArrived(const Atlas::Objects::Root& obj);
144 
145  void doFailure(const std::string &msg);
146  void queryFailure(MetaQuery *q, const std::string& msg);
147 
148  void query();
149  void queryTimeout(MetaQuery *q);
150  void metaTimeout();
151 
154  void connect();
155 
157  void disconnect();
158 
159 private:
161  void recv();
162 
164  void recvCmd(uint32_t op);
165 
167  void processCmd();
168 
171  void listReq(int offset = 0);
172 
173  void setupRecvCmd();
174  void setupRecvData(int words, uint32_t got);
175 
176  void deleteQuery(MetaQuery* query);
177 
178  void internalQuery(unsigned int index);
179 
180  const std::string m_clientName;
181 
182  MetaStatus m_status;
184  const std::string m_metaHost;
185 
186  typedef std::set<MetaQuery*> QuerySet;
187  QuerySet m_activeQueries;
188 
189  unsigned int m_maxActiveQueries;
190  unsigned int m_nextQuery;
191 
192  typedef std::vector<ServerInfo> ServerInfoArray;
193  ServerInfoArray m_gameServers,
194  m_lastValidList;
195 
196  // storage for the Metaserver protocol
197  udp_socket_stream* m_stream;
198 
199  char _data[DATA_BUFFER_SIZE];
200  char* _dataPtr;
201 
202  std::streamsize _bytesToRecv;
203  unsigned int _totalServers,
204  _packed;
205 
206  bool _recvCmd;
207  uint32_t _gotCmd;
208 
209  std::auto_ptr<Timeout> m_timeout;
210 
211  void gotData(PollData&);
212 };
213 
214 } // of namespace Eris
215 
216 #endif
sigc::signal< void > AllQueriesDone
Emitted when the entire server list has been refreshed.
Definition: Metaserver.h:132
const ServerInfo & getInfoForServer(unsigned int index) const
Retrive one of the servers.
Definition: Metaserver.cpp:164
Information about a specific game server, retrieved via the Meta-server and anonymous GETs...
Definition: ServerInfo.h:21
void connect()
initiate a connection to the meta-server : this will issue a keep-alive followed by a list request...
Definition: Metaserver.cpp:182
MetaQuery is a temporary connection used to retrieve information about a game server.
Definition: MetaQuery.h:23
Querying game servers for information.
Definition: Metaserver.h:73
void disconnect()
tear down an existing connection to the server
Definition: Metaserver.cpp:217
The server list is not valid.
Definition: Metaserver.h:70
Definition: Account.cpp:35
MetaStatus
Definition: Metaserver.h:68
Definition: Poll.h:11
Retrieving the list of game servers from the metaserver.
Definition: Metaserver.h:72
The list is valid and completed.
Definition: Metaserver.h:71
Meta(const std::string &msv, unsigned int maxQueries)
Create a Metaserver object, which manages all interaction with the metaserver itself, and querying active game servers.
Definition: Metaserver.cpp:62
void cancel()
Cancel outstanding refresh / queries.
Definition: Metaserver.cpp:144
void refresh()
Refresh the entire server list.
Definition: Metaserver.cpp:126
sigc::signal< void, const std::string & > Failure
Indicates a failure (usually network related) has occurred.
Definition: Metaserver.h:138
Meta encapsulates the meta-game system, including the meta-server protocol and queries.
Definition: Metaserver.h:64
void queryServerByIndex(unsigned int index)
Query a specific game server; emits a signal when complete.
Definition: Metaserver.cpp:106
unsigned int getGameServerCount() const
Return the total number of game servers the meta server knows about.
Definition: Metaserver.cpp:175
sigc::signal< void, const ServerInfo & > ReceivedServerInfo
Emitted when information about a server is received.
Definition: Metaserver.h:123
sigc::signal< void, int > CompletedServerList
Emitted once the complete list of servers has been retrived from the metaserver.
Definition: Metaserver.h:129