Eris  1.4.0
Metaserver.h
1 // TODO: Copyright stuff
2 
3 #ifndef ERIS_METASERVER_H
4 #define ERIS_METASERVER_H
5 
6 #include "Types.h"
7 #include "ServerInfo.h"
8 
9 #include <Atlas/Objects/Decoder.h>
10 
11 #include <sigc++/trackable.h>
12 #include <sigc++/signal.h>
13 
14 #include <boost/asio.hpp>
15 
16 #include <memory>
17 
18 #include <stdint.h>
19 #include <ios>
20 
21 // Forward decls
22 namespace Eris {
23 
24 // Forward Declerations
25 class MetaQuery;
26 class BaseConnection;
27 class Timeout;
28 class EventService;
29 
30 const int DATA_BUFFER_SIZE = 4096;
31 
33 typedef std::list<ServerInfo> ServerList;
34 
36 class Meta : virtual public sigc::trackable,
37  public Atlas::Objects::ObjectsDecoder
38 {
39 public:
40  typedef enum
41  {
42  INVALID = 0,
46  } MetaStatus;
47 
60  Meta(boost::asio::io_service& io_service, EventService& eventService, const std::string &msv, unsigned int maxQueries);
61  virtual ~Meta();
62 
64  size_t getGameServerCount() const;
65 
69  const ServerInfo& getInfoForServer(size_t index) const;
70 
72  void queryServerByIndex(size_t index);
73 
80  void refresh();
81 
86  void cancel();
87 
88  void dispatch();
89 
90 // accessors
91  MetaStatus getStatus() const {
92  return m_status;
93  }
94 // signals
95 
97  sigc::signal<void, const ServerInfo&> ReceivedServerInfo;
98 
103  sigc::signal<void, int> CompletedServerList;
104 
106  sigc::signal<void> AllQueriesDone;
107 
112  sigc::signal<void, const std::string&> Failure;
113 
114 protected:
115  friend class MetaQuery;
116 
117  virtual void objectArrived(const Atlas::Objects::Root& obj);
118 
119  void doFailure(const std::string &msg);
120  void queryFailure(MetaQuery *q, const std::string& msg);
121 
122  void query();
123  void queryTimeout(MetaQuery *q);
124  void metaTimeout();
125 
128  void connect();
129 
131  void disconnect();
132 
133 private:
134 
135  void connect(boost::asio::ip::udp::endpoint endpoint);
136 
137  void write();
138  void do_read();
139 
141  void recv();
142 
144  void recvCmd(uint32_t op);
145 
147  void processCmd();
148 
151  void listReq(unsigned int offset = 0);
152 
153  void setupRecvCmd();
154  void setupRecvData(int words, uint32_t got);
155 
156  void deleteQuery(MetaQuery* query);
157 
158  void internalQuery(size_t index);
159 
160  void startTimeout();
161 
162  boost::asio::io_service& m_io_service;
163 
164  EventService& m_event_service;
165 
166  const std::string m_clientName;
167 
168  MetaStatus m_status;
170  const std::string m_metaHost;
171 
172  typedef std::set<MetaQuery*> QuerySet;
173  QuerySet m_activeQueries;
174 
175  size_t m_maxActiveQueries;
176  size_t m_nextQuery;
177 
178  typedef std::vector<ServerInfo> ServerInfoArray;
179  ServerInfoArray m_gameServers,
180  m_lastValidList;
181 
182  boost::asio::ip::udp::resolver m_resolver;
183 
184  // storage for the Metaserver protocol
185  boost::asio::ip::udp::socket m_socket;
186 
187  boost::asio::deadline_timer m_metaTimer;
188 
189  boost::asio::streambuf m_receive_buffer;
190  std::iostream m_receive_stream;
191 
192  boost::asio::streambuf* m_send_buffer;
193  std::iostream m_send_stream;
194 
195  char _data[DATA_BUFFER_SIZE];
196  char* _dataPtr;
197 
198  std::streamsize _bytesToRecv;
199  unsigned int _totalServers,
200  _packed;
201 
202  bool _recvCmd;
203  uint32_t _gotCmd;
204 
205  void gotData();
206 };
207 
208 } // of namespace Eris
209 
210 #endif
sigc::signal< void > AllQueriesDone
Emitted when the entire server list has been refreshed.
Definition: Metaserver.h:106
Information about a specific game server, retrieved via the Meta-server and anonymous GETs...
Definition: ServerInfo.h:22
void connect()
initiate a connection to the meta-server : this will issue a keep-alive followed by a list request...
Definition: Metaserver.cpp:187
MetaQuery is a temporary connection used to retrieve information about a game server.
Definition: MetaQuery.h:20
Querying game servers for information.
Definition: Metaserver.h:45
const ServerInfo & getInfoForServer(size_t index) const
Retrive one of the servers.
Definition: Metaserver.cpp:171
void disconnect()
tear down an existing connection to the server
Definition: Metaserver.cpp:222
The server list is not valid.
Definition: Metaserver.h:42
void queryServerByIndex(size_t index)
Query a specific game server; emits a signal when complete.
Definition: Metaserver.cpp:112
Every Eris class and type lives inside the Eris namespace; certain utility functions live in the Util...
Definition: Account.cpp:34
MetaStatus
Definition: Metaserver.h:40
Handles polling of the IO system as well as making sure that registered handlers are run on the main ...
Definition: EventService.h:43
std::list< ServerInfo > ServerList
Storage of server information.
Definition: Metaserver.h:33
size_t getGameServerCount() const
Return the total number of game servers the meta server knows about.
Definition: Metaserver.cpp:182
Retrieving the list of game servers from the metaserver.
Definition: Metaserver.h:44
The list is valid and completed.
Definition: Metaserver.h:43
void cancel()
Cancel outstanding refresh / queries.
Definition: Metaserver.cpp:151
void refresh()
Refresh the entire server list.
Definition: Metaserver.cpp:132
sigc::signal< void, const std::string & > Failure
Indicates a failure (usually network related) has occurred.
Definition: Metaserver.h:112
Meta(boost::asio::io_service &io_service, EventService &eventService, 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:57
Meta encapsulates the meta-game system, including the meta-server protocol and queries.
Definition: Metaserver.h:36
sigc::signal< void, const ServerInfo & > ReceivedServerInfo
Emitted when information about a server is received.
Definition: Metaserver.h:97
sigc::signal< void, int > CompletedServerList
Emitted once the complete list of servers has been retrived from the metaserver.
Definition: Metaserver.h:103