gamecreateparams.cpp
1 //------------------------------------------------------------------------------
2 // gamecreateparams.cpp
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) 2014 "Zalewa" <zalewapl@gmail.com>
22 //------------------------------------------------------------------------------
23 #include "gamecreateparams.h"
24 
25 #include "gamedemo.h"
27 #include <QFileInfo>
28 
29 DClass<GameCreateParams>
30 {
31 public:
32  bool broadcastToLan;
33  bool broadcastToMaster;
34  QString connectPassword;
35  QStringList customParameters;
36  QList<GameCVar> cvars;
37  QString executablePath;
38  QString demoPath;
39  GameDemo demoRecord;
40  QList<DMFlagsSection> dmFlags;
41  QString email;
42  GameMode gameMode;
43  GameCreateParams::HostMode hostMode;
44  QString ingamePassword;
45  QString iwadPath;
46  QString loggingPath;
47  QString map;
48  QStringList mapList;
49  int maxClients;
50  int maxPlayers;
51  QString motd;
52  QString name;
53  QMap<QString, QVariant> options;
54  unsigned short port;
55  QList<bool> pwadsOptional;
56  QStringList pwadsPaths;
57  bool randomMapRotation;
58  QString rconPassword;
59  int skill;
60  bool upnp;
61  quint16 upnpPort;
62  QString url;
63 };
64 
65 DPointered(GameCreateParams)
66 
68 {
69  d->broadcastToLan = true;
70  d->broadcastToMaster = true;
71  d->randomMapRotation = false;
72  d->maxClients = 0;
73  d->maxPlayers = 0;
74  d->port = 0;
75  d->skill = 0;
76  d->upnp = true;
77  d->upnpPort = 0;
78 }
79 
80 GameCreateParams::~GameCreateParams()
81 {
82 }
83 
84 const QString &GameCreateParams::connectPassword() const
85 {
86  return d->connectPassword;
87 }
88 
89 QStringList &GameCreateParams::customParameters()
90 {
91  return d->customParameters;
92 }
93 
94 const QStringList &GameCreateParams::customParameters() const
95 {
96  return d->customParameters;
97 }
98 
99 QList<GameCVar> &GameCreateParams::cvars()
100 {
101  return d->cvars;
102 }
103 
104 const QList<GameCVar> &GameCreateParams::cvars() const
105 {
106  return d->cvars;
107 }
108 
109 const QString &GameCreateParams::demoPath() const
110 {
111  return d->demoPath;
112 }
113 
115 {
116  return d->demoRecord;
117 }
118 
119 void GameCreateParams::setDemoRecord(const GameDemo &demo)
120 {
121  d->demoRecord = demo;
122 }
123 
124 QList<DMFlagsSection> &GameCreateParams::dmFlags()
125 {
126  return d->dmFlags;
127 }
128 
129 const QList<DMFlagsSection> &GameCreateParams::dmFlags() const
130 {
131  return d->dmFlags;
132 }
133 
134 const QString &GameCreateParams::email() const
135 {
136  return d->email;
137 }
138 
139 const QString &GameCreateParams::executablePath() const
140 {
141  return d->executablePath;
142 }
143 
144 const GameMode &GameCreateParams::gameMode() const
145 {
146  return d->gameMode;
147 }
148 
149 GameCreateParams::HostMode GameCreateParams::hostMode() const
150 {
151  return d->hostMode;
152 }
153 
154 bool GameCreateParams::isBroadcastToLan() const
155 {
156  return d->broadcastToLan;
157 }
158 
159 bool GameCreateParams::isBroadcastToMaster() const
160 {
161  return d->broadcastToMaster;
162 }
163 
164 bool GameCreateParams::isRandomMapRotation() const
165 {
166  return d->randomMapRotation;
167 }
168 
169 const QString &GameCreateParams::ingamePassword() const
170 {
171  return d->ingamePassword;
172 }
173 
174 const QString &GameCreateParams::iwadPath() const
175 {
176  return d->iwadPath;
177 }
178 
180 {
181  QFileInfo fi(iwadPath());
182  return fi.fileName();
183 }
184 
185 const QString &GameCreateParams::loggingPath() const
186 {
187  return d->loggingPath;
188 }
189 
190 const QString &GameCreateParams::map() const
191 {
192  return d->map;
193 }
194 
195 const QStringList &GameCreateParams::mapList() const
196 {
197  return d->mapList;
198 }
199 
200 int GameCreateParams::maxClients() const
201 {
202  return d->maxClients;
203 }
204 
205 int GameCreateParams::maxPlayers() const
206 {
207  return d->maxPlayers;
208 }
209 
211 {
212  return qMax(maxClients(), maxPlayers());
213 }
214 
215 const QString &GameCreateParams::motd() const
216 {
217  return d->motd;
218 }
219 
220 const QString &GameCreateParams::name() const
221 {
222  return d->name;
223 }
224 
225 QVariant GameCreateParams::option(const QString &name) const
226 {
227  return d->options[name];
228 }
229 
230 void GameCreateParams::setOption(const QString &name, const QVariant &value)
231 {
232  d->options[name] = value;
233 }
234 
235 unsigned short GameCreateParams::port() const
236 {
237  return d->port;
238 }
239 
240 QList<bool> &GameCreateParams::pwadsOptional()
241 {
242  return d->pwadsOptional;
243 }
244 
245 const QList<bool> &GameCreateParams::pwadsOptional() const
246 {
247  return d->pwadsOptional;
248 }
249 
250 QStringList &GameCreateParams::pwadsPaths()
251 {
252  return d->pwadsPaths;
253 }
254 
255 const QStringList &GameCreateParams::pwadsPaths() const
256 {
257  return d->pwadsPaths;
258 }
259 
260 QStringList GameCreateParams::pwadsNames() const
261 {
262  QStringList result;
263  for (const QString &path : pwadsPaths())
264  {
265  QFileInfo fi(path);
266  result << fi.fileName();
267  }
268  return result;
269 }
270 
271 QList<PWad> GameCreateParams::pwads() const
272 {
273  QList<PWad> result;
274  QStringList names = pwadsNames();
275  for (int i = 0; i < names.size(); ++i)
276  {
277  result << PWad(names[i], pwadsOptional()[i]);
278  }
279  return result;
280 }
281 
282 const QString &GameCreateParams::rconPassword() const
283 {
284  return d->rconPassword;
285 }
286 
287 void GameCreateParams::setBroadcastToLan(bool b)
288 {
289  d->broadcastToLan = b;
290 }
291 
292 void GameCreateParams::setBroadcastToMaster(bool b)
293 {
294  d->broadcastToMaster = b;
295 }
296 
297 void GameCreateParams::setConnectPassword(const QString &pass)
298 {
299  d->connectPassword = pass;
300 }
301 
302 void GameCreateParams::setCustomParameters(const QStringList &customParameters)
303 {
304  d->customParameters = customParameters;
305 }
306 
307 void GameCreateParams::setCvars(const QList<GameCVar> &cvars)
308 {
309  d->cvars = cvars;
310 }
311 
312 void GameCreateParams::setDemoPath(const QString &demoPath)
313 {
314  d->demoPath = demoPath;
315 }
316 
317 void GameCreateParams::setEmail(const QString &email)
318 {
319  d->email = email;
320 }
321 
322 void GameCreateParams::setExecutablePath(const QString &executablePath)
323 {
324  d->executablePath = executablePath;
325 }
326 
327 void GameCreateParams::setGameMode(const GameMode &mode)
328 {
329  d->gameMode = mode;
330 }
331 
332 void GameCreateParams::setHostMode(HostMode mode)
333 {
334  d->hostMode = mode;
335 }
336 
337 void GameCreateParams::setIngamePassword(const QString &pass)
338 {
339  d->ingamePassword = pass;
340 }
341 
342 void GameCreateParams::setIwadPath(const QString &iwadPath)
343 {
344  d->iwadPath = iwadPath;
345 }
346 
347 void GameCreateParams::setLoggingPath(const QString &loggingPath)
348 {
349  d->loggingPath = loggingPath;
350 }
351 
352 void GameCreateParams::setMap(const QString &map)
353 {
354  d->map = map;
355 }
356 
357 void GameCreateParams::setMapList(const QStringList &mapList)
358 {
359  d->mapList = mapList;
360 }
361 
362 void GameCreateParams::setMaxClients(int num)
363 {
364  d->maxClients = num;
365 }
366 
367 void GameCreateParams::setMaxPlayers(int num)
368 {
369  d->maxPlayers = num;
370 }
371 
372 void GameCreateParams::setMotd(const QString &motd)
373 {
374  d->motd = motd;
375 }
376 
377 void GameCreateParams::setName(const QString &name)
378 {
379  d->name = name;
380 }
381 
382 void GameCreateParams::setPort(unsigned short port)
383 {
384  d->port = port;
385 }
386 
387 void GameCreateParams::setPwadsOptional(const QList<bool> &pwadsOptional)
388 {
389  d->pwadsOptional = pwadsOptional;
390 }
391 
392 void GameCreateParams::setPwadsPaths(const QStringList &pwadsPaths)
393 {
394  d->pwadsPaths = pwadsPaths;
395 }
396 
397 void GameCreateParams::setRandomMapRotation(bool b)
398 {
399  d->randomMapRotation = b;
400 }
401 
402 void GameCreateParams::setRconPassword(const QString &pass)
403 {
404  d->rconPassword = pass;
405 }
406 
407 void GameCreateParams::setSkill(int skill)
408 {
409  d->skill = skill;
410 }
411 
412 void GameCreateParams::setUrl(const QString &url)
413 {
414  d->url = url;
415 }
416 
418 {
419  return d->skill;
420 }
421 
423 {
424  return d->upnp;
425 }
426 
427 void GameCreateParams::setUpnp(bool upnp)
428 {
429  d->upnp = upnp;
430 }
431 
433 {
434  return d->upnpPort;
435 }
436 
437 void GameCreateParams::setUpnpPort(quint16 port)
438 {
439  d->upnpPort = port;
440 }
441 
442 const QString &GameCreateParams::url() const
443 {
444  return d->url;
445 }
QStringList pwadsNames() const
Names of PWADs, derived from pwadsPaths().
const QString & connectPassword() const
Password that allows clients to connect to the server.
QList< PWad > pwads() const
PWad objects with just the file names and optional statuses.
const QString & ingamePassword() const
Internal game password.
Game parametrization data used when creating new games.
quint16 upnpPort() const
Game or plugin can use this network port as it sees fit within the UPnP context.
PWAD hosted on a server.
QString iwadName() const
Name of IWAD, derived from iwadPath().
const QString & motd() const
Message of the Day.
int maxTotalClientSlots() const
Derived basing on maxClients() and maxPlayers() value; higher value wins.
const QString & executablePath() const
Path to the game executable.
bool upnp() const
If set, the game should try to enable UPnP.
const QString & demoPath() const
Use if running in HostMode::Demo mode or recording a demo.
const QString & url() const
URL for server&#39;s website or for WADs download.
Game mode representation.
QVariant option(const QString &name) const
Option is a means for game plugin to set plugin specific settings.
const QString & loggingPath() const
Path to the directory where logs should be saved.
const QString & map() const
Level name as in E1M1 or MAP01.
QList< GameCVar > & cvars()
Contents of this list will be passed as "+consoleCommand value" to the command line.
const QString & rconPassword() const
Password required to connect to remote admin console.
int skill() const
Difficulty level.
const GameDemo & demoRecord() const
Type of demo to record; applicable only in Offline game.
const QStringList & mapList() const
List of maps in cycle, as in MAP01, MAP02, MAP03, and so on.