masterclient.h
1 //------------------------------------------------------------------------------
2 // masterclient.h
3 //------------------------------------------------------------------------------
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301, USA.
19 //
20 //------------------------------------------------------------------------------
21 // Copyright (C) 2009 "Blzut3" <admin@maniacsvault.net>
22 //------------------------------------------------------------------------------
23 
24 #ifndef __MASTERSERVER_H__
25 #define __MASTERSERVER_H__
26 
27 #include <QObject>
28 #include <QHostAddress>
29 #include <QList>
30 
31 #include "dptr.h"
32 #include "global.h"
33 #include "polymorphism.h"
34 #include "serverapi/serverptr.h"
35 
36 class Message;
37 class EnginePlugin;
38 class Server;
39 class QFile;
40 class QUdpSocket;
41 
49 class MAIN_EXPORT MasterClient : public QObject
50 {
51  Q_OBJECT
52 
53  public:
54  enum Response
55  {
56  RESPONSE_GOOD, // Data is available
57  RESPONSE_TIMEOUT, // Server didn't respond at all
58  RESPONSE_WAIT, // Server responded with "wait"
59  RESPONSE_BAD, // Probably refreshing too quickly
60  RESPONSE_BANNED, // Won't recieve data from this server ever.
61  RESPONSE_NO_RESPONSE_YET, // "Dummy" response for servers that weren't refreshed yet
62  RESPONSE_PENDING, // Waiting for additional packets
63  RESPONSE_REPLY, // Ask the refresher to call createSendRequest again
64  RESPONSE_OLD, // Client too old.
65  };
66 
67  MasterClient();
68  virtual ~MasterClient();
69 
70  void clearServers();
71 
77  QString engineName() const;
78 
83  bool isAddressSame(const QHostAddress &address, unsigned short port) const;
84 
90  bool isEnabled() const;
98  bool isTimeouted() const;
99 
113  QString masterBanHelp() const;
114 
115  void notifyResponse(Response response);
116  int numServers() const;
117  ServerPtr operator[] (int index) const;
118 
126  virtual const EnginePlugin* plugin() const = 0;
127 
128  void pushPacketToCache(const QByteArray &data);
129  void resetPacketCaching();
130 
134  Response readResponse(const QByteArray &data);
135 
139  bool sendRequest(QUdpSocket *socket);
140 
141  const QList<ServerPtr> &servers() const;
142 
143  void updateAddress();
144 
145  public slots:
151  virtual void refreshStarts();
152 
156  void setEnabled(bool b);
157 
163  void timeoutRefresh();
164 
165  signals:
166  void listUpdated();
167 
172  void message(const QString &title, const QString &content, bool isError);
173 
184  void messageImportant(const Message &message);
185 
186  protected:
190  QHostAddress address() const;
191 
199  virtual QByteArray createServerListRequest()=0;
200 
204  void emptyServerList();
205 
206  POLYMORPHIC_SETTER_DECLARE_CONST(QString, MasterClient, masterBanHelp, ());
207  QString masterBanHelp_default() const;
208 
212  unsigned short port() const;
213 
214  bool preparePacketCache(bool write);
215 
220  virtual Response readMasterResponse(const QByteArray &data)=0;
221 
222  void readPacketCache();
226  void registerNewServer(ServerPtr server);
227 
228  void setTimeouted(bool b);
229 
233  virtual void timeoutRefreshEx();
234 
235  private:
237 
238  void emitBannedMessage();
239 };
240 
241 #endif /* __MASTERSERVER_H__ */
Message object used to pass messages throughout the Doomseeker&#39;s system.
Definition: message.h:63
A representation of a server for a given game.
Definition: server.h:93
Abstract base for all MasterClients.
Definition: masterclient.h:49