Eris  1.3.23
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 #include <stdint.h>
16 
17 // Forward decls
18 class udp_socket_stream;
19 class basic_socket_stream;
20 
21 namespace Eris {
22 
23 // Forward Declerations
24 class MetaQuery;
25 class BaseConnection;
26 class Timeout;
27 class PollData;
28 
29 const int DATA_BUFFER_SIZE = 4096;
30 
32 typedef std::list<ServerInfo> ServerList;
33 
35 class Meta : virtual public sigc::trackable,
36  public Atlas::Objects::ObjectsDecoder
37 {
38 public:
39  typedef enum
40  {
41  INVALID = 0,
45  } MetaStatus;
46 
59  Meta(const std::string &msv, unsigned int maxQueries);
60  virtual ~Meta();
61 
63  unsigned int getGameServerCount() const;
64 
68  const ServerInfo& getInfoForServer(unsigned int index) const;
69 
71  void queryServerByIndex(unsigned int index);
72 
79  void refresh();
80 
85  void cancel();
86 
87 // accessors
88  MetaStatus getStatus() const {
89  return m_status;
90  }
91 // signals
92 
94  sigc::signal<void, const ServerInfo&> ReceivedServerInfo;
95 
100  sigc::signal<void, int> CompletedServerList;
101 
103  sigc::signal<void> AllQueriesDone;
104 
109  sigc::signal<void, const std::string&> Failure;
110 
111 protected:
112  friend class MetaQuery;
113 
114  virtual void objectArrived(const Atlas::Objects::Root& obj);
115 
116  void doFailure(const std::string &msg);
117  void queryFailure(MetaQuery *q, const std::string& msg);
118 
119  void query();
120  void queryTimeout(MetaQuery *q);
121  void metaTimeout();
122 
125  void connect();
126 
128  void disconnect();
129 
130 private:
132  void recv();
133 
135  void recvCmd(uint32_t op);
136 
138  void processCmd();
139 
142  void listReq(int offset = 0);
143 
144  void setupRecvCmd();
145  void setupRecvData(int words, uint32_t got);
146 
147  void deleteQuery(MetaQuery* query);
148 
149  void internalQuery(unsigned int index);
150 
151  const std::string m_clientName;
152 
153  MetaStatus m_status;
155  const std::string m_metaHost;
156 
157  typedef std::set<MetaQuery*> QuerySet;
158  QuerySet m_activeQueries;
159 
160  unsigned int m_maxActiveQueries;
161  unsigned int m_nextQuery;
162 
163  typedef std::vector<ServerInfo> ServerInfoArray;
164  ServerInfoArray m_gameServers,
165  m_lastValidList;
166 
167  // storage for the Metaserver protocol
168  udp_socket_stream* m_stream;
169 
170  char _data[DATA_BUFFER_SIZE];
171  char* _dataPtr;
172 
173  std::streamsize _bytesToRecv;
174  unsigned int _totalServers,
175  _packed;
176 
177  bool _recvCmd;
178  uint32_t _gotCmd;
179 
180  std::unique_ptr<Timeout> m_timeout;
181 
182  void gotData(PollData&);
183 };
184 
185 } // of namespace Eris
186 
187 #endif
Eris::Timeout
Timeout
Definition: Timeout.h:12
Eris::Meta
Meta encapsulates the meta-game system, including the meta-server protocol and queries.
Definition: Metaserver.h:35
Eris::Meta::AllQueriesDone
sigc::signal< void > AllQueriesDone
Emitted when the entire server list has been refreshed.
Definition: Metaserver.h:103
Eris::Meta::INVALID
@ INVALID
The server list is not valid.
Definition: Metaserver.h:41
Eris::Meta::Failure
sigc::signal< void, const std::string & > Failure
Indicates a failure (usually network related) has occurred.
Definition: Metaserver.h:109
Eris::Meta::VALID
@ VALID
The list is valid and completed.
Definition: Metaserver.h:42
Eris::PollData
Definition: Poll.h:11
Eris::BaseException
This is the Eris base for all exceptions; note it inherits from std::except, which isn't ideal.
Definition: Exceptions.h:19
Eris::Meta::queryServerByIndex
void queryServerByIndex(unsigned int index)
Query a specific game server; emits a signal when complete.
Definition: Metaserver.cpp:104
Eris::MetaQuery
MetaQuery is a temporary connection used to retrieve information about a game server.
Definition: MetaQuery.h:23
Eris::Meta::MetaStatus
MetaStatus
Definition: Metaserver.h:39
Eris::BaseConnection::CONNECTING
@ CONNECTING
stream / socket connection in progress
Definition: BaseConnection.h:51
Eris::error
Definition: LogStream.h:55
Eris::BaseConnection::NEGOTIATE
@ NEGOTIATE
Atlas negotiation in progress.
Definition: BaseConnection.h:50
Eris::Meta::cancel
void cancel()
Cancel outstanding refresh / queries.
Definition: Metaserver.cpp:142
Eris::Meta::QUERYING
@ QUERYING
Querying game servers for information.
Definition: Metaserver.h:44
Eris::ServerInfo::TIMEOUT
@ TIMEOUT
server query timed out
Definition: ServerInfo.h:30
Eris::Meta::Meta
Meta(const std::string &msv, unsigned int maxQueries)
Create a Metaserver object, which manages all interaction with the metaserver itself,...
Definition: Metaserver.cpp:60
Eris::Meta::getInfoForServer
const ServerInfo & getInfoForServer(unsigned int index) const
Retrive one of the servers.
Definition: Metaserver.cpp:162
Eris::Meta::connect
void connect()
initiate a connection to the meta-server : this will issue a keep-alive followed by a list request.
Definition: Metaserver.cpp:180
Eris::Meta::getGameServerCount
unsigned int getGameServerCount() const
Return the total number of game servers the meta server knows about.
Definition: Metaserver.cpp:173
Eris::Meta::ReceivedServerInfo
sigc::signal< void, const ServerInfo & > ReceivedServerInfo
Emitted when information about a server is received.
Definition: Metaserver.h:94
Eris::ServerInfo
Information about a specific game server, retrieved via the Meta-server and anonymous GETs.
Definition: ServerInfo.h:21
Eris::Meta::CompletedServerList
sigc::signal< void, int > CompletedServerList
Emitted once the complete list of servers has been retrived from the metaserver.
Definition: Metaserver.h:100
Eris::Meta::refresh
void refresh()
Refresh the entire server list.
Definition: Metaserver.cpp:124
Eris::Meta::disconnect
void disconnect()
tear down an existing connection to the server
Definition: Metaserver.cpp:215
Eris::warning
Definition: LogStream.h:45
Eris::Meta::GETTING_LIST
@ GETTING_LIST
Retrieving the list of game servers from the metaserver.
Definition: Metaserver.h:43