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 
105 
116 
255  EP_AllowsLogging
256  };
257 
259  virtual void setupConfig(IniSection &config);
260 
261 public:
266  class Data
267  {
268  public:
269  unsigned int abiVersion;
270  bool allowsConnectPassword;
271  bool allowsEmail;
272  bool allowsJoinPassword;
273  bool allowsMOTD;
274  bool allowsRConPassword;
275  bool allowsURL;
276  QString author;
278  QString defaultMaster;
279  quint16 defaultServerPort;
281  QPixmap *icon;
282  bool inGameFileDownloads;
283  QVector<IRCNetworkEntity> ircChannels;
284  MasterClient *masterClient;
285  QString name;
286  IniSection *pConfig;
287  quint8 refreshThreshold;
288  QString scheme;
289  bool supportsRandomMapRotation;
290  bool valid;
291  unsigned int version;
292  bool demoExtensionAutomatic;
293  QString demoExtension;
298  QScopedPointer<TextProvider> aboutProvider;
310  bool clientOnly;
321  QSharedPointer<GameExeFactory> gameExeFactory;
322  Broadcast *broadcast;
323 
324  QString clientExeName;
325  QString serverExeName;
326  QStringList gameFileSearchSuffixes;
327 
333  QSharedPointer<GameCVarProvider> difficulty;
334  bool hasMapList;
335  bool hasIwad;
336  bool allowsClientSlots;
337  bool allowsPlayerSlots;
338  bool allowsUpnp;
339  bool allowsUpnpPort;
340  bool allowsLogging;
341  QString canonicalName;
342 
343  Data();
344 
345  bool hasBroadcast() const
346  {
347  return broadcast != nullptr;
348  }
349 
350  bool hasMasterClient() const
351  {
352  return masterClient != nullptr;
353  }
354  };
355 
356  EnginePlugin();
357  virtual ~EnginePlugin();
358 
368  void init(const char *name, const char *const icon[], ...);
369 
373  virtual ConfigPage *configuration(QWidget *parent);
374 
392  virtual QList<CreateServerDialogPage *> createServerDialogPages(CreateServerDialog *pDialog)
393  {
394  Q_UNUSED(pDialog);
395  return QList<CreateServerDialogPage *>();
396  }
397 
398  const Data *data() const
399  {
400  return d;
401  }
402  const QPixmap &icon() const
403  {
404  return *d->icon;
405  }
406  void setConfig(IniSection &cfg);
407 
411  virtual QList<DMFlagsSection> dmFlags() const;
412 
413  GameExeFactory *gameExe();
414 
422  virtual GameHost *gameHost();
423 
431  virtual QList<GameMode> gameModes() const;
435  virtual QList<GameCVar> gameModifiers() const;
436 
441  virtual QList<GameCVar> limits(const GameMode &mode) const
442  {
443  Q_UNUSED(mode);
444  return QList<GameCVar>();
445  }
446 
450  void masterHost(QString &host, unsigned short &port) const;
451 
465  QString nameCanonical() const;
466 
474  virtual ServerPtr server(const QHostAddress &address, unsigned short port) const;
475 
492  virtual void start();
493 
494 protected:
499  virtual ServerPtr mkServer(const QHostAddress &address, unsigned short port) const = 0;
500  void initDefaultGameFiles();
501  void setGameExeFactory(QSharedPointer<GameExeFactory> factory);
502 
503 private:
504  Data *d;
505 
506  QStringList collectKnownPaths(const IniSection &ini) const;
507  void findGameFiles(IniSection &ini);
508 };
509 
510 extern "C" PLUGIN_EXPORT EnginePlugin *doomSeekerInit();
511 
512 #endif