engineplugin.cpp
1 //------------------------------------------------------------------------------
2 // engineplugin.cpp
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) 2011 "Blzut3" <admin@maniacsvault.net>
22 //------------------------------------------------------------------------------
23 
24 #include "gui/configuration/engineconfigurationbasebox.h"
25 #include "ini/ini.h"
26 #include "irc/entities/ircnetworkentity.h"
27 #include "plugins/engineplugin.h"
28 #include "serverapi/gameexefactory.h"
29 #include "serverapi/gamehost.h"
30 #include "serverapi/server.h"
31 #include "log.h"
32 #include "strings.h"
33 
34 #include <cstdarg>
35 #include <QPixmap>
36 
37 EnginePlugin::Data::Data()
38 {
39  // Init the defaults.
40  allowsConnectPassword = false;
41  allowsEmail = false;
42  allowsJoinPassword = false;
43  allowsMOTD = false;
44  allowsRConPassword = false;
45  allowsURL = false;
46  clientOnly = false;
48  defaultServerPort = 10666;
49  demoExtensionAutomatic = true;
50  demoExtension = "lmp";
51  hasMasterServer = false;
52  icon = NULL;
53  inGameFileDownloads = false;
54  pConfig = NULL;
55  refreshThreshold = 2;
56  supportsRandomMapRotation = false;
57  valid = true;
58  version = 0;
59 }
60 
62 
63 EnginePlugin::EnginePlugin()
64 {
65  d = new Data;
66 
67  d->gameExeFactory = new GameExeFactory(this);
68 
69  // At the moment I can't think of how we would support any ABI other than
70  // the current, but I suppose we might as well keep track of it?
71  d->abiVersion = DOOMSEEKER_ABI_VERSION;
72 }
73 
74 EnginePlugin::~EnginePlugin()
75 {
76  delete d->icon;
77  delete d->pConfig;
78  delete d->gameExeFactory;
79  delete d;
80 }
81 
83 {
84  return new EngineConfigurationBaseBox(this, *d->pConfig, parent);
85 }
86 
88 {
89  return new GameHost(this);
90 }
91 
92 void EnginePlugin::init(const char* name, const char* const icon[], ...)
93 {
94  d->name = name;
95  d->icon = new QPixmap(icon);
96  d->scheme = QString(d->name).replace(' ', "");
97 
98  va_list va;
99  va_start(va, icon);
100 
101  int feature;
102  while((feature = va_arg(va, int)) != EP_Done)
103  {
104  switch(feature)
105  {
106  default:
107  // Since we don't know if the feature has arguments we must abort.
108  gLog << QString("%1 plugin attempted to use unknown feature.").arg(name);
109  d->valid = false;
110  return;
111 
112  case EP_Author:
113  d->author = va_arg(va, const char*);
114  break;
115  case EP_Version:
116  d->version = va_arg(va, unsigned int);
117  break;
118 
120  d->allowsConnectPassword = true;
121  break;
122  case EP_AllowsEmail:
123  d->allowsEmail = true;
124  break;
125  case EP_AllowsURL:
126  d->allowsURL = true;
127  break;
129  d->allowsJoinPassword = true;
130  break;
132  d->allowsRConPassword = true;
133  break;
134  case EP_AllowsMOTD:
135  d->allowsMOTD = true;
136  break;
137  case EP_ClientOnly:
138  d->clientOnly = true;
139  break;
140  case EP_DefaultMaster:
141  d->defaultMaster = va_arg(va, const char*);
142  break;
144  d->defaultServerPort = va_arg(va, unsigned int);
145  break;
146  case EP_DemoExtension:
147  d->demoExtensionAutomatic = va_arg(va, unsigned int);
148  d->demoExtension = va_arg(va, const char*);
149  break;
151  d->createDMFlagsPagesAutomatic = false;
152  break;
153  case EP_HasMasterServer:
154  d->hasMasterServer = true;
155  break;
157  d->inGameFileDownloads = true;
158  break;
159  case EP_IRCChannel:
160  {
161  // Either create an entity or put the channel in an existing one.
162  IRCNetworkEntity entity;
163  entity.setDescription(va_arg(va, const char*));
164  entity.setAddress(va_arg(va, const char*));
165  entity.autojoinChannels() << va_arg(va, const char*);
166 
167  if(d->ircChannels.contains(entity))
168  {
169  IRCNetworkEntity &existingEntity = d->ircChannels[d->ircChannels.indexOf(entity)];
170  existingEntity.autojoinChannels() << entity.autojoinChannels()[0];
171  }
172  else
173  d->ircChannels << entity;
174  break;
175  }
177  d->supportsRandomMapRotation = true;
178  break;
179  case EP_URLScheme:
180  d->scheme = va_arg(va, const char*);
181  break;
182  case EP_RefreshThreshold:
183  d->refreshThreshold = va_arg(va, unsigned int);
184  break;
185  }
186  }
187 
188  va_end(va);
189 }
190 
191 void EnginePlugin::masterHost(QString &host, unsigned short &port) const
192 {
193  QString str = d->pConfig->setting("Masterserver");
194  Strings::translateServerAddress(str, host, port, d->defaultMaster);
195 }
196 
198 {
199  QString name = data()->name;
200  name = name.toLower();
201  name = name.replace(QRegExp("\\s"), "_");
202  return name;
203 }
204 
205 ServerPtr EnginePlugin::server(const QHostAddress &address, unsigned short port) const
206 {
207  ServerPtr server = mkServer(address, port);
208  server->setSelf(server.toWeakRef());
209  return server;
210 }
211 
212 void EnginePlugin::setConfig(IniSection &ini) const
213 {
214  d->pConfig = new IniSection(ini);
215 
216  ini.createSetting("Masterserver", data()->defaultMaster);
217 
218  setupConfig(ini);
219 }
220 
221 void EnginePlugin::setDMFlags(const QList<DMFlagsSection> &dmFlags)
222 {
223  d->allDMFlags = dmFlags;
224 }
225 
226 void EnginePlugin::setGameModes(const QList<GameMode> &gameModes)
227 {
228  d->gameModes = gameModes;
229 }
230 
231 void EnginePlugin::setGameModifiers(const QList<GameCVar> &gameModifiers)
232 {
233  d->gameModifiers = gameModifiers;
234 }
GameExeFactory * gameExeFactory
Factory of executable retrievers objects.
Definition: engineplugin.h:181
IniVariable createSetting(const QString &name, const QVariant &data)
Inits specified variable with specified data.
Definition: inisection.cpp:57
bool createDMFlagsPagesAutomatic
Controls behavior of "Create Game" dialog.
Definition: engineplugin.h:170
QPixmap * icon
icon of the engine
Definition: engineplugin.h:148
(const char*) Author of the plugin.
Definition: engineplugin.h:81
static void translateServerAddress(const QString &addressString, QString &hostname, unsigned short &port, const QString &defaultAddress)
Translates string in format "hostname:port" to atomic values.
Definition: strings.cpp:404
Allows the player to join a server without downloading files through Wadseeker.
Definition: engineplugin.h:93
virtual ServerPtr mkServer(const QHostAddress &address, unsigned short port) const =0
Create an instance of local Server subclass and return a ServerPtr.
Signifies that servers can be created with a join password.
Definition: engineplugin.h:87
void init(const char *name, const char *const icon[],...)
virtual GameHost * gameHost()
Creates an instance of GameHost derivative class.
Signifies that a server can be created with a random map rotation.
Definition: engineplugin.h:95
const QStringList & autojoinChannels() const
List of channels to which a /join command will be issued automatically when a connection with this ne...
QList< GameMode > gameModes
All available game modes for the engine or NULL if none.
Definition: engineplugin.h:137
void masterHost(QString &host, unsigned short &port) const
Returns executable file retrievers from plugins to Doomseeker.
QList< GameCVar > gameModifiers
Returns a list of modifiers.
Definition: engineplugin.h:145
(const char*) Default ip address and port ("address:port") for master server. Requires EP_HasMasterSe...
Definition: engineplugin.h:90
(bool)auto, (const char*)extension Sets the extension taht will be used for demos (default is true an...
Definition: engineplugin.h:98
Signifies that servers can be created for remote console access.
Definition: engineplugin.h:88
virtual ServerPtr server(const QHostAddress &address, unsigned short port) const
Creates an instance of server object from this plugin.
virtual ConfigurationBaseBox * configuration(QWidget *parent) const
Engine's configuration widget.
Signifies that servers can have a message of the day.
Definition: engineplugin.h:89
Signifies that servers can provide a URL for potential wad downloads.
Definition: engineplugin.h:86
virtual void setupConfig(IniSection &config) const
Reimplement if you want to perform some ini initialization manually.
Definition: engineplugin.h:113
Signals the end of init parameters.
Definition: engineplugin.h:79
IniVariable setting(const QString &name)
Gets a variable. Creates it first if it doesn't exist yet.
Definition: inisection.cpp:137
(quint8) The amount of time (in seconds) that must pass before a server can be requeried.
Definition: engineplugin.h:96
Signifies that servers can be created with a connection password.
Definition: engineplugin.h:84
Base for configuration pages for plugins; provides some default behavior.
Signifies that servers can have an administrative contact email attached.
Definition: engineplugin.h:85
Data structure that describes and defines a connection to an IRC network or server.
INI section representation.
Definition: inisection.h:40
Indicates that client binary serves the purpose of the client and server.
Definition: engineplugin.h:109
Creates game servers, offline games or demo playbacks.
Definition: gamehost.h:69
(unsigned int) Single version number for plugin.
Definition: engineplugin.h:82
Signifies that the plugin implements a master server protocol.
Definition: engineplugin.h:92
(quint16) Default port for custom server creation.
Definition: engineplugin.h:91
QString nameCanonical() const
Derived from actual plugin name.
Base class for configuration pages.
(const char*)server, (const char*)channel - Can be repeated. Default IRC channels.
Definition: engineplugin.h:94
(const char*) Overrides the URL scheme which Doomseeker sets for this plugin. By default it is the po...
Definition: engineplugin.h:97
QString defaultMaster
Default port on which servers for given engine are hosted.
Definition: engineplugin.h:134
QList< DMFlagsSection > allDMFlags
List of all engine's DM flags or NULL if none.
Definition: engineplugin.h:125