serverstructs.h
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // serverstructs.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) 2010 Braden "Blzut3" Obrzut <admin@maniacsvault.net>
22 //------------------------------------------------------------------------------
23 #ifndef __SERVER_STRUCTS_H_
24 #define __SERVER_STRUCTS_H_
25 
26 #include <climits>
27 #include <QCryptographicHash>
28 #include <QList>
29 #include <QObject>
30 #include <QString>
31 #include <QVariant>
32 
33 #include "dptr.h"
34 #include "global.h"
35 
36 class Checksum;
37 class ModFile;
62 class MAIN_EXPORT DMFlag
63 {
64 public:
65  DMFlag();
66  DMFlag(const QString &internalName, unsigned value);
67  DMFlag(const QString &internalName, unsigned value, const QString &name);
68  DMFlag(const DMFlag &other);
69  virtual ~DMFlag();
70  DMFlag &operator=(const DMFlag &other);
71 
78  const QString &internalName() const;
79 
85  bool isValid() const;
86 
91  const QString &name() const;
92 
96  unsigned value() const;
97 
98 private:
99  DPtr<DMFlag> d;
100 };
101 
142 class MAIN_EXPORT DMFlagsSection
143 {
144 public:
151  static QList<DMFlagsSection> removedBySection(
152  const QList<DMFlagsSection> &original,
153  const QList<DMFlagsSection> &removals);
154 
155  DMFlagsSection();
156 
163  DMFlagsSection(const QString &internalName);
164 
171  DMFlagsSection(const QString &internalName, const QString &name);
172 
173  DMFlagsSection(const DMFlagsSection &other);
174  virtual ~DMFlagsSection();
175  DMFlagsSection &operator=(const DMFlagsSection &other);
176 
184  void add(const DMFlag &flag);
191  unsigned combineValues() const;
192 
197  DMFlagsSection copyEmpty() const;
198 
202  int count() const;
203 
209  const QString &internalName() const;
210 
214  bool isEmpty() const;
215 
220  const QString &name() const;
224  const DMFlag &operator[](int index) const;
225  DMFlag &operator[](int index);
226 
231  DMFlagsSection &operator<<(const DMFlag &flag)
232  {
233  add(flag);
234  return *this;
235  }
236 
245  DMFlagsSection removed(const DMFlagsSection &removals) const;
246 
247 private:
249 };
250 
257 class MAIN_EXPORT GameCVar
258 {
259 public:
260  GameCVar();
261  GameCVar(const QString &name, const QString &command);
262  GameCVar(const QString &name, const QString &command, const QVariant &value);
263  GameCVar(const GameCVar &other);
264  virtual ~GameCVar();
265  GameCVar &operator=(const GameCVar &other);
266 
274  const QString &command() const;
275 
279  bool hasValue() const;
283  bool isValid() const;
284 
289  const QString &name() const;
290 
294  void setValue(const QVariant &value);
295 
299  const QVariant &value() const;
300  QString valueString() const { return value().toString(); }
301  bool valueBool() const { return value().toBool(); }
302  int valueInt() const { return value().toInt(); }
303 
304 private:
305  DPtr<GameCVar> d;
306 };
307 
317 class MAIN_EXPORT GameCVarProvider : public QObject
318 {
319  Q_OBJECT
320 
321 public:
323  virtual ~GameCVarProvider() override;
324 
331  virtual QList<GameCVar> get(const QVariant &context);
332 
333 private:
334  Q_DISABLE_COPY(GameCVarProvider)
335 
337 };
338 
357 using gamemode_id = int;
358 
372 class MAIN_EXPORT GameMode
373 {
374 public:
389  {
390  SGM_Cooperative = 900,
391  SGM_Deathmatch = 901,
392  SGM_TeamDeathmatch = 902,
393  SGM_CTF = 903,
397  SGM_Unknown = 904
398  };
399 
400  // Standard game mode set
401  // These should be used in order to keep the names uniform.
402  // These can't be static members as translations may not work.
403  static GameMode mkCooperative();
404  static GameMode mkDeathmatch();
405  static GameMode mkTeamDeathmatch();
406  static GameMode mkCaptureTheFlag();
407  static GameMode mkUnknown();
408 
423  static GameMode ffaGame(int index, const QString &name);
434  static GameMode teamGame(int index, const QString &name);
435 
439  GameMode();
440  GameMode(const GameMode &other);
441  virtual ~GameMode();
442  GameMode &operator=(const GameMode &other);
443 
447  gamemode_id index() const;
448 
454  const QString &name() const;
455 
459  bool isTeamGame() const;
463  bool isValid() const;
464 
465 private:
466  DPtr<GameMode> d;
467 
468  GameMode(gamemode_id index, const QString &name);
469 
470  void setTeamGame(bool b);
471 };
472 
481 class MAIN_EXPORT PWad
482 {
483 public:
484  PWad(const QString &name, bool optional = false);
485  PWad(const QString &name, bool optional, const QList<Checksum> &checksums);
486  PWad(const ModFile &modFile);
487  PWad(const PWad &other);
488  virtual ~PWad();
489  PWad &operator=(const PWad &other);
490 
491  operator ModFile();
495  bool isOptional() const;
499  const QString &name() const;
503  const QList<Checksum> checksums() const;
510  void addChecksum(const QByteArray &hash, const QCryptographicHash::Algorithm &algorithm);
516  bool validFile(const QString &path) const;
517 private:
518  DPtr<PWad> d;
519 };
520 
525 class Skill
526 {
527 public:
532  static const unsigned char UNDEFINED = CHAR_MAX;
533 };
534 
535 #endif