server.h
1 //------------------------------------------------------------------------------
2 // server.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 __SERVER_H__
25 #define __SERVER_H__
26 
27 #include "serverapi/polymorphism.h"
28 #include "serverapi/serverptr.h"
29 #include "dptr.h"
30 #include "global.h"
31 
32 #include <QColor>
33 #include <QList>
34 #include <QObject>
35 #include <QHostAddress>
36 #include <QHostInfo>
37 #include <QString>
38 #include <QMetaType>
39 #include <QPixmap>
40 #include <QTime>
41 #include <QUdpSocket>
42 
43 class DMFlagsSection;
44 class EnginePlugin;
45 class ExeFile;
46 class GameCVar;
47 class GameHost;
48 class GameMode;
49 class GameClientRunner;
50 class PathFinder;
51 class Player;
52 class PlayersList;
53 class PWad;
54 class RConProtocol;
55 class TooltipGenerator;
56 
93 class MAIN_EXPORT Server : public QObject
94 {
95  Q_OBJECT
96 
97  friend class ServerPointer;
98 
99  public:
107  enum Response
108  {
153  };
154 
158  Server(const QHostAddress &address, unsigned short port);
159  virtual ~Server();
160 
161  // VIRTUALS
169  virtual ExeFile* clientExe();
177  virtual GameClientRunner* gameRunner();
183  virtual bool hasRcon() const { return false; }
187  virtual QList<GameCVar> modifiers() const;
195  virtual RConProtocol *rcon() { return NULL; }
201  virtual QRgb teamColor(int team) const;
207  virtual QString teamName(int team) const;
214  virtual EnginePlugin* plugin() const = 0;
215 
225  virtual TooltipGenerator* tooltipGenerator() const;
226 
244  virtual PathFinder wadPathFinder();
245  // END OF VIRTUALS
246 
255  void addPlayer(const Player& player);
259  const QHostAddress &address() const;
263  QString addressWithPort() const;
264 
268  QStringList allWadNames() const;
269 
273  bool anyWadnameContains(const QString& text,
274  Qt::CaseSensitivity cs = Qt::CaseInsensitive) const;
275 
281  void clearPlayersList();
282 
286  QString customDetails();
287 
291  const QList<DMFlagsSection>& dmFlags() const;
295  const QString& email() const;
296 
304  QString engineName() const;
305 
309  const GameMode& gameMode() const;
313  const QString& gameVersion() const;
314 
327  QString hostName(bool forceAddress=false) const;
331  const QPixmap &icon() const;
332 
338  bool isCustom() const;
342  bool isEmpty() const;
346  bool isFull() const;
353  bool isKnown() const;
354 
358  bool isLockedAnywhere() const;
362  bool isLocked() const;
366  bool isLockedInGame() const;
367 
371  bool isRandomMapRotation() const;
375  bool isRefreshing() const;
376 
385  bool isSecure() const;
386 
390  bool isSpecial() const;
391 
395  bool isTestingServer() const;
396 
400  const QString& iwad() const;
401 
406  Response lastResponse() const;
414  void lookupHost();
415 
419  const QString& map() const;
423  const QStringList& mapList() const;
430  unsigned short maxClients() const;
434  unsigned short maxPlayers() const;
438  const QString& motd() const;
442  const QString& name() const;
446  int numFreeClientSlots() const;
450  int numFreeJoinSlots() const;
456  int numFreeSpectatorSlots() const;
461  int numTotalSlots() const { return maxPlayers() > maxClients() ? maxPlayers() : maxClients(); }
465  int numWads() const { return wads().size(); }
469  unsigned int ping() const;
473  const Player& player(int index) const;
477  const PlayersList &players() const;
481  unsigned short port() const;
482 
487  Response readRefreshQueryResponse(const QByteArray& data);
488 
492  void refreshStarts();
493 
497  void refreshStops(Response response);
498 
502  unsigned int score(int team=0) const;
506  const QList<int>& scores() const;
512  unsigned int scoreLimit() const;
513 
523  QWeakPointer<Server> self() const;
524 
531  bool sendRefreshQuery(QUdpSocket* socket);
532 
537  void setCustom(bool custom);
541  void setEmail(const QString& mail);
545  void setGameMode(const GameMode& gameMode);
549  void setMap(const QString& name);
553  void setMapList(const QStringList& mapList);
557  void setMaxClients(unsigned short i);
561  void setMaxPlayers(unsigned short i);
565  void setMotd(const QString& message);
569  void setName(const QString& name);
573  void setPort(unsigned short i);
577  void setRandomMapRotation(bool b);
583  void setSelf(const QWeakPointer<Server> &self);
587  void setSkill(unsigned char newSkill);
591  void setWebSite(const QString& site);
592 
596  unsigned short timeLeft() const;
600  unsigned short timeLimit() const;
601 
614  qint64 timeMsSinceLastRefresh() const;
615 
623  unsigned char skill() const;
627  const PWad &wad(int index) const;
631  const QList<PWad>& wads() const;
635  const QString& webSite() const;
636 
640  bool isLan() const;
641  void setLan(bool b);
642 
643  signals:
650  void begunRefreshing(ServerPtr server);
662  void updated(ServerPtr server, int response);
663 
664  protected:
665  POLYMORPHIC_SETTER_DECLARE(QString, Server, customDetails, ());
666  QString customDetails_default();
667 
675  Response readRequest(const QByteArray &data);
676  POLYMORPHIC_SETTER_DECLARE(Response, Server, readRequest, (const QByteArray &data));
677 
683  QByteArray createSendRequest();
684  POLYMORPHIC_SETTER_DECLARE(QByteArray, Server, createSendRequest, ());
685 
689  void addWad(const PWad& wad);
693  void clearWads();
698  QList<int>& scoresMutable();
702  void setDmFlags(const QList<DMFlagsSection>& dmFlags);
706  void setGameVersion(const QString& version);
710  void setIwad(const QString& iwad);
714  void setLocked(bool locked);
718  void setLockedInGame(bool locked);
725  void setPing(unsigned int currentPing);
726 
733  void setPingIsSet(bool b);
734 
735  void setTestingServer(bool b);
739  void setTimeLeft(unsigned short timeLeft);
743  void setTimeLimit(unsigned short timeLimit);
747  void setScoreLimit(unsigned int scoreLimit);
751  void setSecure(bool bSecureServer);
752 
753  private:
754  Q_DISABLE_COPY(Server)
755 
756  static QString teamNames[];
757 
758  DPtr<Server> d;
759 
760  void clearDMFlags();
761 
762  QByteArray createSendRequest_default();
763  Response readRequest_default(const QByteArray &data);
764 
765  void setResponse(Response response);
766  void setScores(const QList<int>& scores);
767  void setWads(const QList<PWad>& wads);
768 
769  private slots:
770  void setHostName(QHostInfo host);
771 };
772 
773 Q_DECLARE_METATYPE(ServerPtr);
774 Q_DECLARE_METATYPE(ServerCPtr);
775 
776 #endif /* __SERVER_H__ */
Waiting for additional packets.
Definition: server.h:143
Performs a case-insensitive (OS independent) file searches.
Definition: pathfinder.h:81
PWAD hosted on a server.
Player is banned from that server.
Definition: server.h:132
virtual bool hasRcon() const
Does this server support remote console connection?
Definition: server.h:183
int numTotalSlots() const
Actual number of free connection slots deduced from maxPlayers() and maxClients().
Definition: server.h:461
A group of DMFlag objects that can be safely OR&#39;ed together to form a meaningful value.
A representation of a server for a given game.
Definition: server.h:93
"Dummy" response for servers that weren&#39;t refreshed yet.
Definition: server.h:136
Doomseeker needs to send some more challenge data to the server.
Definition: server.h:152
Response from the server was erroreneous.
Definition: server.h:128
Remote console protocol interface.
Definition: rconprotocol.h:79
Data structure that holds information about players in a server.
Definition: player.h:37
virtual RConProtocol * rcon()
Spawns RConProtocol instance.
Definition: server.h:195
Game mode representation.
Response was parsed properly and Server information is available.
Definition: server.h:113
Creates game servers, offline games or demo playbacks.
Definition: gamehost.h:69
Server didn&#39;t respond at all.
Definition: server.h:117
Creates command line that launches the client executable of the game and connects it to a server...
Response
Type of response that is extracted by parsing the packet that came from the Server.
Definition: server.h:107
int numWads() const
Number of PWADs loaded on this server.
Definition: server.h:465
Access to external program executables (game clients, servers, and so on).
Definition: exefile.h:48
A general game setting or variable (like fraglimit).
Server responded with "wait", may happen when we refresh too quickly.
Definition: server.h:122