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  const QString& iwad() const;
391 
396  Response lastResponse() const;
404  void lookupHost();
405 
409  const QString& map() const;
413  const QStringList& mapList() const;
420  unsigned short maxClients() const;
424  unsigned short maxPlayers() const;
428  const QString& motd() const;
432  const QString& name() const;
436  int numFreeClientSlots() const;
440  int numFreeJoinSlots() const;
446  int numFreeSpectatorSlots() const;
451  int numTotalSlots() const { return maxPlayers() > maxClients() ? maxPlayers() : maxClients(); }
455  int numWads() const { return wads().size(); }
459  unsigned int ping() const;
463  const Player& player(int index) const;
467  const PlayersList &players() const;
471  unsigned short port() const;
472 
477  Response readRefreshQueryResponse(const QByteArray& data);
478 
482  void refreshStarts();
483 
487  void refreshStops(Response response);
488 
492  unsigned int score(int team=0) const;
496  const QList<int>& scores() const;
502  unsigned int scoreLimit() const;
503 
513  QWeakPointer<Server> self() const;
514 
521  bool sendRefreshQuery(QUdpSocket* socket);
522 
527  void setCustom(bool custom);
531  void setEmail(const QString& mail);
535  void setGameMode(const GameMode& gameMode);
539  void setMap(const QString& name);
543  void setMapList(const QStringList& mapList);
547  void setMaxClients(unsigned short i);
551  void setMaxPlayers(unsigned short i);
555  void setMotd(const QString& message);
559  void setName(const QString& name);
563  void setPort(unsigned short i);
567  void setRandomMapRotation(bool b);
573  void setSelf(const QWeakPointer<Server> &self);
577  void setSkill(unsigned char newSkill);
581  void setWebSite(const QString& site);
582 
586  unsigned short timeLeft() const;
590  unsigned short timeLimit() const;
591 
604  qint64 timeMsSinceLastRefresh() const;
605 
613  unsigned char skill() const;
617  const PWad &wad(int index) const;
621  const QList<PWad>& wads() const;
625  const QString& webSite() const;
626 
627  signals:
634  void begunRefreshing(ServerPtr server);
646  void updated(ServerPtr server, int response);
647 
648  protected:
649  POLYMORPHIC_SETTER_DECLARE(QString, Server, customDetails, ());
650  QString customDetails_default();
651 
659  Response readRequest(const QByteArray &data);
660  POLYMORPHIC_SETTER_DECLARE(Response, Server, readRequest, (const QByteArray &data));
661 
667  QByteArray createSendRequest();
668  POLYMORPHIC_SETTER_DECLARE(QByteArray, Server, createSendRequest, ());
669 
673  void addWad(const PWad& wad);
677  void clearWads();
682  QList<int>& scoresMutable();
686  void setDmFlags(const QList<DMFlagsSection>& dmFlags);
690  void setGameVersion(const QString& version);
694  void setIwad(const QString& iwad);
698  void setLocked(bool locked);
702  void setLockedInGame(bool locked);
709  void setPing(unsigned int currentPing);
710 
717  void setPingIsSet(bool b);
718 
722  void setTimeLeft(unsigned short timeLeft);
726  void setTimeLimit(unsigned short timeLimit);
730  void setScoreLimit(unsigned int scoreLimit);
734  void setSecure(bool bSecureServer);
735 
736  private:
737  Q_DISABLE_COPY(Server)
738 
739  static QString teamNames[];
740 
741  DPtr<Server> d;
742 
743  void clearDMFlags();
744 
748  void emitUpdated(int response);
749 
750  QByteArray createSendRequest_default();
751  Response readRequest_default(const QByteArray &data);
752 
753  void setResponse(Response response);
754  void setScores(const QList<int>& scores);
755  void setWads(const QList<PWad>& wads);
756 
757  private slots:
758  void setHostName(QHostInfo host);
759 };
760 
761 Q_DECLARE_METATYPE(ServerPtr);
762 Q_DECLARE_METATYPE(ServerCPtr);
763 
764 #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:451
A group of DMFlag objects that can be safely OR'ed together to form a meaningful value.
Definition: serverstructs.h:86
A representation of a server for a given game.
Definition: server.h:93
"Dummy" response for servers that weren'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't respond at all.
Definition: server.h:117
Definition: dptr.h:54
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:455
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