engineplugin.h
1 //------------------------------------------------------------------------------
2 // engineplugin.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) 2011 Braden "Blzut3" Obrzut <admin@maniacsvault.net>
22 //------------------------------------------------------------------------------
23 
24 #ifndef __ENGINEPLUGIN_H__
25 #define __ENGINEPLUGIN_H__
26 
27 #include "global.h"
28 #include "serverapi/serverptr.h"
30 #include "serverapi/textprovider.h"
31 #include <QString>
32 #include <QStringList>
33 #include <QtContainerFwd>
34 #include <QVector>
35 
36 // Bump whenever the ABI changes in order to reject old plugins
37 #define DOOMSEEKER_ABI_VERSION 2
38 
39 #define DECLARE_PLUGIN(XEnginePlugin) \
40  friend PLUGIN_EXPORT EnginePlugin * doomSeekerInit(); \
41 public: \
42  static EnginePlugin *staticInstance() { return __Static_Instance; } \
43 private: \
44  static XEnginePlugin *__Static_Instance;
45 
46 #define INSTALL_PLUGIN(XEnginePlugin) \
47  XEnginePlugin *XEnginePlugin::__Static_Instance; \
48  extern "C" PLUGIN_EXPORT unsigned int doomSeekerABI() { return DOOMSEEKER_ABI_VERSION; } \
49  extern "C" PLUGIN_EXPORT EnginePlugin *doomSeekerInit() \
50  { \
51  XEnginePlugin::__Static_Instance = new XEnginePlugin(); \
52  return XEnginePlugin::staticInstance(); \
53  }
54 
55 class Broadcast;
56 class ConfigPage;
57 class CreateServerDialog;
59 class GameCVarProvider;
60 class GameCVar;
61 class GameExeFactory;
62 class GameHost;
63 class GameMode;
64 class IniSection;
65 class IRCNetworkEntity;
66 class MasterClient;
67 class Server;
68 class QHostAddress;
69 class QPixmap;
70 class QWidget;
71 class TextProvider;
72 
76 class MAIN_EXPORT EnginePlugin
77 {
78 protected:
85  {
87 
90 
106 
117 
256  EP_AllowsLogging
257  };
258 
260  virtual void setupConfig(IniSection &config);
261 
262 public:
267  class Data
268  {
269  public:
270  unsigned int abiVersion;
271  bool allowsConnectPassword;
272  bool allowsEmail;
273  bool allowsJoinPassword;
274  bool allowsMOTD;
275  bool allowsRConPassword;
276  bool allowsURL;
277  QString author;
279  QString defaultMaster;
280  quint16 defaultServerPort;
282  QPixmap *icon;
283  bool inGameFileDownloads;
284  QVector<IRCNetworkEntity> ircChannels;
285  MasterClient *masterClient;
286  QString name;
287  IniSection *pConfig;
288  quint8 refreshThreshold;
289  QString scheme;
290  bool supportsRandomMapRotation;
291  bool valid;
292  unsigned int version;
293  bool demoExtensionAutomatic;
294  QString demoExtension;
295  bool multiplayerDemoExtensionAutomatic;
296  QString multiplayerDemoExtension;
301  QScopedPointer<TextProvider> aboutProvider;
313  bool clientOnly;
324  QSharedPointer<GameExeFactory> gameExeFactory;
325  Broadcast *broadcast;
326 
327  QString clientExeName;
328  QString serverExeName;
329  QStringList gameFileSearchSuffixes;
330 
336  QSharedPointer<GameCVarProvider> difficulty;
337  bool hasMapList;
338  bool hasIwad;
339  bool allowsClientSlots;
340  bool allowsPlayerSlots;
341  bool allowsUpnp;
342  bool allowsUpnpPort;
343  bool allowsLogging;
344  QString canonicalName;
345 
346  Data();
347 
348  bool hasBroadcast() const
349  {
350  return broadcast != nullptr;
351  }
352 
353  bool hasMasterClient() const
354  {
355  return masterClient != nullptr;
356  }
357  };
358 
359  EnginePlugin();
360  virtual ~EnginePlugin();
361 
371  void init(const char *name, const char *const icon[], ...);
372 
376  virtual ConfigPage *configuration(QWidget *parent);
377 
395  virtual QList<CreateServerDialogPage *> createServerDialogPages(CreateServerDialog *pDialog)
396  {
397  Q_UNUSED(pDialog);
398  return QList<CreateServerDialogPage *>();
399  }
400 
401  const Data *data() const
402  {
403  return d;
404  }
405 
409  QString defaultMasterAddress() const;
410 
411  const QPixmap &icon() const
412  {
413  return *d->icon;
414  }
415 
416  void setConfig(IniSection &cfg);
417 
421  virtual QList<DMFlagsSection> dmFlags() const;
422 
423  GameExeFactory *gameExe();
424 
432  virtual GameHost *gameHost();
433 
437  virtual QList<GameMode> gameModes() const;
445  virtual QList<GameCVar> gameModifiers() const;
446 
459  virtual QList<GameCVar> limits(const GameMode &mode) const
460  {
461  Q_UNUSED(mode);
462  return QList<GameCVar>();
463  }
464 
468  void masterHost(QString &host, unsigned short &port) const;
469 
488  QString nameCanonical() const;
489 
497  virtual ServerPtr server(const QHostAddress &address, unsigned short port) const;
498 
515  virtual void start();
516 
517 protected:
522  virtual ServerPtr mkServer(const QHostAddress &address, unsigned short port) const = 0;
523  void initDefaultGameFiles();
524  void setGameExeFactory(QSharedPointer<GameExeFactory> factory);
525 
526 private:
527  Data *d;
528 
529  QStringList collectKnownPaths(const IniSection &ini) const;
530  void findGameFiles(IniSection &ini);
531 };
532 
533 extern "C" PLUGIN_EXPORT EnginePlugin *doomSeekerInit();
534 
535 #endif