00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef __MASTERSERVER_H__
00025 #define __MASTERSERVER_H__
00026
00027 #include <QObject>
00028 #include <QHostAddress>
00029 #include <QList>
00030
00031 #include "global.h"
00032
00033 class Message;
00034 class EnginePlugin;
00035 class Server;
00036 class QFile;
00037 class QUdpSocket;
00038
00043 class MAIN_EXPORT MasterClient : public QObject
00044 {
00045 Q_OBJECT
00046
00047 public:
00061 static QUdpSocket* pGlobalUdpSocket;
00062
00063 MasterClient();
00064 virtual ~MasterClient();
00065
00066 bool hasServer(const Server*);
00067
00072 bool isAddressDataCorrect(const QHostAddress& address, unsigned short port)
00073 {
00074 return (this->address == address && this->port == port);
00075 }
00076
00082 bool isEnabled() const { return enabled; }
00083 bool isTimeouted() const { return bTimeouted; }
00084 int numPlayers() const;
00085 int numServers() const { return servers.size(); }
00086 Server *operator[] (int index) const { return servers[index]; }
00087
00095 virtual const EnginePlugin* plugin() const = 0;
00096
00097 void pushPacketToCache(QByteArray &data);
00098 void resetPacketCaching();
00099
00107 virtual bool readMasterResponse(QByteArray &data)=0;
00108
00115 virtual bool readMasterResponse(QHostAddress& address, unsigned short port, QByteArray &data);
00116
00117 QList<Server*> &serverList() { return servers; }
00118 const QList<Server*> &serverList() const { return servers; }
00119
00120 void updateAddress();
00121
00122 public slots:
00128 virtual void refresh();
00129
00133 void setEnabled(bool b) { enabled = b; }
00134
00140 void timeoutRefresh();
00141
00142 signals:
00143 void listUpdated();
00144
00149 void message(const QString& title, const QString& content, bool isError);
00150
00161 void messageImportant(const Message& message);
00162
00172 void newServerBatchReceived(const QList<Server* >& servers);
00173
00174 protected:
00175 QHostAddress address;
00176
00184 bool bTimeouted;
00185 bool enabled;
00186 unsigned short port;
00187 QList<Server *> servers;
00188
00189 QFile *cache;
00190
00194 void emptyServerList();
00195
00201 QString engineName() const;
00202
00210 virtual bool getServerListRequest(QByteArray &data)=0;
00211
00216 void notifyBanned();
00221 void notifyDelay();
00222
00227 void notifyError();
00228
00233 void notifyUpdate();
00234
00235 bool preparePacketCache(bool write);
00236 void readPacketCache();
00237
00241 virtual void timeoutRefreshEx() {}
00242 };
00243
00244 #endif