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 numPlayers() const;
117  int numServers() const;
118  ServerPtr operator[] (int index) const;
119 
127  virtual const EnginePlugin* plugin() const = 0;
128 
129  void pushPacketToCache(const QByteArray &data);
130  void resetPacketCaching();
131 
135  Response readResponse(const QByteArray &data);
136 
140  bool sendRequest(QUdpSocket *socket);
141 
142  const QList<ServerPtr> &servers() const;
143 
144  void updateAddress();
145 
146  public slots:
152  virtual void refreshStarts();
153 
157  void setEnabled(bool b);
158 
164  void timeoutRefresh();
165 
166  signals:
167  void listUpdated();
168 
173  void message(const QString &title, const QString &content, bool isError);
174 
185  void messageImportant(const Message &message);
186 
187  protected:
195  virtual QByteArray createServerListRequest()=0;
196 
200  void emptyServerList();
201 
202  POLYMORPHIC_SETTER_DECLARE_CONST(QString, MasterClient, masterBanHelp, ());
203  QString masterBanHelp_default() const;
204 
205  bool preparePacketCache(bool write);
206 
211  virtual Response readMasterResponse(const QByteArray &data)=0;
212 
213  void readPacketCache();
217  void registerNewServer(ServerPtr server);
218 
219  void setTimeouted(bool b);
220 
224  virtual void timeoutRefreshEx();
225 
226  private:
228 
229  void emitBannedMessage();
230 };
231 
232 #endif /* __MASTERSERVER_H__ */
Message object used to pass messages throughout the Doomseeker's system.
Definition: message.h:62
A representation of a server for a given game.
Definition: server.h:93
Abstract base for all MasterClients.
Definition: masterclient.h:49