server.h
1 //------------------------------------------------------------------------------
2 // server.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 __SERVER_H__
25 #define __SERVER_H__
26 
27 #include "dptr.h"
28 #include "global.h"
29 #include "serverapi/polymorphism.h"
30 #include "serverapi/serverptr.h"
31 
32 #include <QColor>
33 #include <QHostAddress>
34 #include <QHostInfo>
35 #include <QList>
36 #include <QMetaType>
37 #include <QObject>
38 #include <QPixmap>
39 #include <QString>
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() override;
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 nullptr; }
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 
252  virtual PathFinder wadPathFinder();
253  // END OF VIRTUALS
254 
263  void addPlayer(const Player &player);
267  const QHostAddress &address() const;
271  QString addressWithPort() const;
272 
276  QStringList allWadNames() const;
277 
281  bool anyWadnameContains(const QString &text,
282  Qt::CaseSensitivity cs = Qt::CaseInsensitive) const;
283 
289  void clearPlayersList();
290 
294  QString customDetails();
295 
299  const QList<DMFlagsSection> &dmFlags() const;
303  const QString &email() const;
304 
312  QString engineName() const;
313 
317  const GameMode &gameMode() const;
321  const QString &gameVersion() const;
322 
335  QString hostName(bool forceAddress = false) const;
339  const QPixmap &icon() const;
340 
346  bool isCustom() const;
350  bool isEmpty() const;
354  bool isFull() const;
361  bool isKnown() const;
362 
366  bool isLockedAnywhere() const;
370  bool isLocked() const;
374  bool isLockedInGame() const;
375 
379  bool isRandomMapRotation() const;
383  bool isRefreshing() const;
384 
393  bool isSecure() const;
394 
398  bool isSpecial() const;
399 
403  bool isTestingServer() const;
404 
408  const QString &iwad() const;
409 
414  Response lastResponse() const;
422  void lookupHost();
423 
427  const QString &map() const;
431  const QStringList &mapList() const;
438  unsigned short maxClients() const;
442  unsigned short maxPlayers() const;
446  const QString &motd() const;
450  const QString &name() const;
454  int numFreeClientSlots() const;
458  int numFreeJoinSlots() const;
464  int numFreeSpectatorSlots() const;
469  int numTotalSlots() const
470  {
471  return maxPlayers() > maxClients() ? maxPlayers() : maxClients();
472  }
476  int numWads() const { return wads().size(); }
480  unsigned int ping() const;
484  const Player &player(int index) const;
488  const PlayersList &players() const;
492  unsigned short port() const;
493 
498  Response readRefreshQueryResponse(const QByteArray &data);
499 
503  void refreshStarts();
504 
508  void refreshStops(Response response);
509 
513  unsigned int score(int team = 0) const;
517  const QList<int> &scores() const;
523  unsigned int scoreLimit() const;
524 
534  QWeakPointer<Server> self() const;
535 
542  bool sendRefreshQuery(QUdpSocket *socket);
543 
548  void setCustom(bool custom);
552  void setEmail(const QString &mail);
556  void setGameMode(const GameMode &gameMode);
560  void setMap(const QString &name);
564  void setMapList(const QStringList &mapList);
568  void setMaxClients(unsigned short i);
572  void setMaxPlayers(unsigned short i);
576  void setMotd(const QString &message);
580  void setName(const QString &name);
584  void setPort(unsigned short i);
588  void setRandomMapRotation(bool b);
594  void setSelf(const QWeakPointer<Server> &self);
598  void setSkill(unsigned char newSkill);
602  void setWebSite(const QString &site);
603 
607  unsigned short timeLeft() const;
611  unsigned short timeLimit() const;
612 
625  qint64 timeMsSinceLastRefresh() const;
626 
634  unsigned char skill() const;
638  const PWad &wad(int index) const;
642  const QList<PWad> &wads() const;
646  const QString &webSite() const;
647 
651  bool isLan() const;
652  void setLan(bool b);
653 
654 signals:
661  void begunRefreshing(ServerPtr server);
673  void updated(ServerPtr server, int response);
674 
675 protected:
676  POLYMORPHIC_SETTER_DECLARE(QString, Server, customDetails, ())
677  QString customDetails_default();
678 
686  Response readRequest(const QByteArray &data);
687  POLYMORPHIC_SETTER_DECLARE(Response, Server, readRequest, (const QByteArray &data))
688 
689 
694  QByteArray createSendRequest();
695  POLYMORPHIC_SETTER_DECLARE(QByteArray, Server, createSendRequest, ())
696 
697 
700  void addWad(const PWad &wad);
704  void clearWads();
709  QList<int> &scoresMutable();
713  void setDmFlags(const QList<DMFlagsSection> &dmFlags);
717  void setGameVersion(const QString &version);
721  void setIwad(const QString &iwad);
725  void setLocked(bool locked);
729  void setLockedInGame(bool locked);
736  void setPing(unsigned int currentPing);
737 
744  void setPingIsSet(bool b);
745 
746  void setTestingServer(bool b);
750  void setTimeLeft(unsigned short timeLeft);
754  void setTimeLimit(unsigned short timeLimit);
758  void setScoreLimit(unsigned int scoreLimit);
762  void setSecure(bool bSecureServer);
763 
764 private:
765  Q_DISABLE_COPY(Server)
766 
767  static QString teamNames[];
768 
769  DPtr<Server> d;
770 
771  void clearDMFlags();
772 
773  QByteArray createSendRequest_default();
774  Response readRequest_default(const QByteArray &data);
775 
776  void setResponse(Response response);
777  void setScores(const QList<int> &scores);
778  void setWads(const QList<PWad> &wads);
779 
780 private slots:
781  void setHostName(QHostInfo host);
782 };
783 
784 Q_DECLARE_METATYPE(ServerPtr)
785 Q_DECLARE_METATYPE(ServerCPtr)
786 
787 #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:469
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 erroneous.
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:476
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