masterclient.h
1 //------------------------------------------------------------------------------
2 // masterclient.h
3 //------------------------------------------------------------------------------
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library 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 GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; 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 Braden "Blzut3" Obrzut <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 
73  void clearServers();
74 
80  QString engineName() const;
81 
86  bool isAddressSame(const QHostAddress &address, unsigned short port) const;
87 
93  bool isEnabled() const;
101  bool isTimeouted() const;
102 
116  QString masterBanHelp() const;
117 
118  void notifyResponse(Response response);
119  int numServers() const;
120  ServerPtr operator[] (int index) const;
121 
129  virtual const EnginePlugin* plugin() const = 0;
130 
131  void pushPacketToCache(const QByteArray &data);
132  void resetPacketCaching();
133 
137  Response readResponse(const QByteArray &data);
138 
142  bool sendRequest(QUdpSocket *socket);
143 
144  const QList<ServerPtr> &servers() const;
145 
146  void updateAddress();
147 
148  public slots:
154  virtual void refreshStarts();
155 
159  void setEnabled(bool b);
160 
166  void timeoutRefresh();
167 
168  signals:
169  void listUpdated();
170 
175  void message(const QString &title, const QString &content, bool isError);
176 
187  void messageImportant(const Message &message);
188 
189  protected:
193  QHostAddress address() const;
194 
202  virtual QByteArray createServerListRequest()=0;
203 
207  void emptyServerList();
208 
209  POLYMORPHIC_SETTER_DECLARE_CONST(QString, MasterClient, masterBanHelp, ());
210  QString masterBanHelp_default() const;
211 
215  unsigned short port() const;
216 
217  bool preparePacketCache(bool write);
218 
223  virtual Response readMasterResponse(const QByteArray &data)=0;
224 
225  void readPacketCache();
229  void registerNewServer(ServerPtr server);
230 
231  void setTimeouted(bool b);
232 
236  virtual void timeoutRefreshEx();
237 
238  private:
240 
241  void emitBannedMessage();
242 };
243 
244 #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