Doomseeker
   
  • Doomseeker
  • Wadseeker
  • Download
  • Tracker
  • Git
  • Docs
  • Main Page
  • Classes
  • Files
  • File List
  • File Members

src/core/serverapi/server.h

00001 //------------------------------------------------------------------------------
00002 // server.h
00003 //------------------------------------------------------------------------------
00004 //
00005 // This program is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU General Public License
00007 // as published by the Free Software Foundation; either version 2
00008 // of the License, or (at your option) any later version.
00009 //
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00018 // 02110-1301, USA.
00019 //
00020 //------------------------------------------------------------------------------
00021 // Copyright (C) 2009 "Blzut3" <admin@maniacsvault.net>
00022 //------------------------------------------------------------------------------
00023 
00024 #ifndef __SERVER_H__
00025 #define __SERVER_H__
00026 
00027 #include <QColor>
00028 #include <QDir>
00029 #include <QFileInfo>
00030 #include <QList>
00031 #include <QProcess>
00032 #include <QObject>
00033 #include <QHostAddress>
00034 #include <QHostInfo>
00035 #include <QString>
00036 #include <QMetaType>
00037 #include <QThread>
00038 #include <QTime>
00039 #include <QUdpSocket>
00040 
00041 #include "serverapi/rconprotocol.h"
00042 #include "serverapi/player.h"
00043 #include "serverapi/serverstructs.h"
00044 #include "global.h"
00045 
00046 class Binaries;
00047 class GameRunner;
00048 class PlayersList;
00049 class EnginePlugin;
00050 class TooltipGenerator;
00051 class QPixmap;
00052 
00053 // Some ports support optional wads.
00054 class MAIN_EXPORT PWad
00055 {
00056         public:
00057                 PWad(const QString &name, bool optional=false) : name(name), optional(optional) {}
00058 
00059                 QString name;
00060                 bool    optional;
00061 };
00062 
00063 class MAIN_EXPORT Server : public QObject
00064 {
00065         Q_OBJECT
00066 
00067         public:
00068                 enum Response
00069                 {
00070                         RESPONSE_GOOD,          // Data is available
00071                         RESPONSE_TIMEOUT,       // Server didn't respond at all
00072                         RESPONSE_WAIT,          // Server responded with "wait"
00073                         RESPONSE_BAD,           // Probably refreshing too quickly
00074                         RESPONSE_BANNED,        // Won't recieve data from this server ever.
00075                         RESPONSE_NO_RESPONSE_YET        // "Dummy" response for servers that weren't refreshed yet
00076                 };
00077 
00078                 Server(const QHostAddress &address, unsigned short port);
00079                 virtual ~Server();
00080 
00088                 virtual Binaries*                                               binaries() const;
00089 
00095                 virtual QString         engineName() const;
00096 
00104                 void lookupHost();
00105 
00106                 const QHostAddress      &address() const { return serverAddress; }
00107                 QString                         addressWithPort() const { return QString("%1:%2").arg(address().toString()).arg(port()); }
00108                 const QString&          connectPassword() const { return passwordConnect; }
00109                 const QString&          eMail() const { return email; }
00110                 const DMFlags           &gameFlags() const { return dmFlags; }
00111                 const GameMode          &gameMode() const { return currentGameMode; }
00112                 unsigned char           gameSkill() const { return skill; }
00113                 virtual bool            hasRcon() const { return false; }
00119                 QString                         hostName(bool forceAddress=false) const;
00120                 const QPixmap           &icon() const;
00121                 bool                            isBroadcastingToLAN() const { return broadcastToLAN; }
00122                 bool                            isBroadcastingToMaster() const { return broadcastToMaster; }
00123                 bool                            isCustom() const { return custom; }
00124                 bool                            isEmpty() const;
00125                 bool                            isFull() const;
00126                 bool                            isKnown() const { return bKnown; }
00127                 bool                            isLocked() const { return locked; }
00128                 bool                            isRefreshable() const;
00129                 bool                            isSecured() const { return bSecureServer; }
00130                 bool                            isSetToDelete() const { return bDelete; }
00131                 const QString           &iwadName() const { return iwad; }
00132                 const QString&          joinPassword() const { return passwordJoin; }
00133                 int                                     lastResponse() const { return response; }
00134                 const QString           &map() const { return mapName; }
00135                 const QStringList&      mapsList() const { return mapList; }
00136                 unsigned short          maximumClients() const { return maxPlayers > maxClients ? maxPlayers : maxClients; }
00137                 unsigned short          maximumPlayers() const { return maxPlayers; }
00138                 const QString&          messageOfTheDay() const { return motd; }
00139                 virtual const GameCVar  *modifier() const { return NULL; }
00140                 const QString           &name() const { return serverName; }
00141                 int                                     numFreeClientSlots() const;
00142                 int                                     numFreeJoinSlots() const;
00143                 int                                     numFreeSpectatorSlots() const;
00144                 int                                     numWads() const { return wads.size(); }
00145                 unsigned int            ping() const { return currentPing; }
00146                 const Player&           player(int index) const;
00147                 const PlayersList*      playersList() const { return players; }
00148                 unsigned short          port() const { return serverPort; }
00149                 const QList<PWad>&      pwads() const { return wads; }
00150                 bool                            randomMapRotation() const { return mapRandomRotation; }
00151                 virtual RConProtocol    *rcon() { return NULL; }
00152                 const QString&          rconPassword() const { return passwordRCon; }
00153                 unsigned int            score(int team=0) const { return scores[team]; }
00154                 unsigned int            scoreLimit() const { return serverScoreLimit; }
00155                 virtual QRgb            teamColor(int team) const;
00156                 virtual QString         teamName(int team) const { return team < MAX_TEAMS && team >= 0 ? teamNames[team] : ""; }
00157                 unsigned short          timeLeft() const { return serverTimeLeft; }
00158                 unsigned short          timeLimit() const { return serverTimeLimit; }
00159                 const QString           version() const { return serverVersion; }
00160                 const PWad                      &wad(int index) const { return wads[index]; }
00161                 const QString           &website() const { return webSite; }
00162 
00163                 void                            setBroadcastToLAN(bool b) { broadcastToLAN = b; }
00164                 void                            setBroadcastToMaster(bool b) { broadcastToMaster = b; }
00165                 void                            setHostEmail(const QString& mail) { email = mail; }
00166                 void                            setGameMode(const GameMode& gameMode) { currentGameMode = gameMode; }
00167                 void                            setMap(const QString& name) { mapName = name; }
00168                 void                            setMapList(const QStringList& maplist) { mapList = maplist; }
00169                 void                            setMaximumClients(unsigned short i) { maxClients = i; }
00170                 void                            setMaximumPlayers(unsigned short i) { maxPlayers = i; }
00171                 void                            setMOTD(const QString& message) { motd = message; }
00172                 void                            setName(const QString& name) { serverName = name; }
00173                 void                            setPasswordConnect(const QString& str) { passwordConnect = str; }
00174                 void                            setPasswordJoin(const QString& str) { passwordJoin = str; }
00175                 void                            setPasswordRCon(const QString& str) { passwordRCon = str; }
00176                 void                            setPort(unsigned short i) { serverPort = i; }
00177                 void                            setRandomMapRotation(bool b) { mapRandomRotation = b; }
00178                 void                            setSkill(unsigned char newSkill) { skill = newSkill; }
00179                 void                            setWebsite(const QString& site) { webSite = site; }
00180 
00181                 void                            setCustom(bool b) { custom = b; }
00182                 void                            setToDelete(bool b);
00183 
00191                 virtual GameRunner*     gameRunner() const;
00192 
00196                 void                            refreshStarts();
00197 
00201                 void                            refreshStops(Response response);
00202 
00203                 Response readRefreshQueryResponse(QByteArray& data);
00204 
00210                 bool                            sendRefreshQuery(QUdpSocket* socket);
00211 
00212                 bool                            isRefreshing() const { return bIsRefreshing; }
00213 
00220                 virtual const EnginePlugin*             plugin() const = 0;
00221 
00230                 virtual TooltipGenerator*       tooltipGenerator() const;
00231 
00232                 friend class ServerPointer;
00233 
00234         public slots:
00238                 bool                    refresh();
00239 
00240         signals:
00241                 void                            begunRefreshing(Server* server);
00247                 void                            updated(Server *server, int response);
00248 
00249         protected:
00250                 void                            clearDMFlags();
00251 
00255                 void                            emitUpdated(int response) { emit updated(this, response); }
00256 
00263                 virtual Response                readRequest(QByteArray &data)=0;
00264 
00270                 virtual bool            sendRequest(QByteArray &data)=0;
00271 
00278                 bool                            bDelete;
00285                 bool                            bKnown;
00286 
00295                 bool                            bPingIsSet;
00296 
00297                 bool                            bSecureServer;
00298                 bool                            broadcastToLAN;
00299                 bool                            broadcastToMaster;
00300                 GameMode                        currentGameMode;
00301                 unsigned int            currentPing;
00302                 bool                            custom;
00303                 DMFlags                         dmFlags;
00304                 QString                         email;
00305                 QString                         iwad;
00306                 bool                            locked;
00307                 QStringList                     mapList;
00308                 QString                         mapName;
00309                 bool                            mapRandomRotation;
00310                 unsigned short          maxClients;
00311                 unsigned short          maxPlayers;
00312                 QString                         motd;
00313                 QString                         passwordConnect;
00314                 QString                         passwordJoin;
00315                 QString                         passwordRCon;
00316                 PlayersList*            players;
00317                 Response                        response;
00318                 unsigned int            scores[MAX_TEAMS];
00319                 QString                         serverName;
00320                 unsigned int            serverScoreLimit;
00321                 unsigned short          serverTimeLeft;
00322                 unsigned short          serverTimeLimit;
00323                 QString                         serverVersion;
00324                 unsigned char           skill;
00325                 QList<PWad>                     wads;
00326                 QString                         webSite;
00327 
00328                 static QString          teamNames[];
00329 
00330                 QTime                           time;
00331 
00332         protected slots:
00333                 void                            setHostName(QHostInfo host);
00334 
00335         private:
00336                 Q_DISABLE_COPY(Server)
00337 
00338                 
00343                 bool                            bIsRefreshing;
00344                 QHostAddress            serverAddress;
00345                 QHostInfo                       serverHost;
00346                 unsigned short          serverPort;
00347 
00348                 int                                     triesLeft; 
00349 
00350                 void                            setResponse(Response response);
00351 };
00352 
00353 class MAIN_EXPORT ServerPointer
00354 {
00355         private:
00356                 void copy(const ServerPointer& copyin)
00357                 {
00358                         ptr = copyin.ptr;
00359                 }
00360 
00361         public:
00362                 Server* ptr;
00363 
00364                 ServerPointer() {}
00365                 ServerPointer(Server* s)
00366                 {
00367                         ptr = s;
00368                 }
00369 
00370                 ServerPointer(const ServerPointer& copyin)
00371                 {
00372                         copy(copyin);
00373                 }
00374 
00375                 ServerPointer& operator=(const ServerPointer& rhs)
00376                 {
00377                         if (this != &rhs)
00378                         {
00379                                 copy(rhs);
00380                         }
00381 
00382                         return *this;
00383                 }
00384                 ~ServerPointer() {}
00385 
00386                 bool operator==(const Server* fPtr) const
00387                 {
00388                         return (ptr == fPtr);
00389                 }
00390 
00391                 friend bool operator==(const Server* fPtr, const ServerPointer& ref)
00392                 {
00393                         return (fPtr == ref.ptr);
00394                 }
00395 
00396                 Server* operator->()
00397                 {
00398                         return ptr;
00399                 }
00400 };
00401 
00402 Q_DECLARE_METATYPE(ServerPointer)
00403 
00404 #endif /* __SERVER_H__ */
   
Doomseeker © 2009-2024 The Doomseeker Team