gamecreateparams.cpp
1 //------------------------------------------------------------------------------
2 // gamecreateparams.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) 2014 "Zalewa" <zalewapl@gmail.com>
22 //------------------------------------------------------------------------------
23 #include "gamecreateparams.h"
24 
26 #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 map;
47  QStringList mapList;
48  int maxClients;
49  int maxPlayers;
50  QString motd;
51  QString name;
52  QMap<QString, QVariant> options;
53  unsigned short port;
54  QList<bool> pwadsOptional;
55  QStringList pwadsPaths;
56  bool randomMapRotation;
57  QString rconPassword;
58  int skill;
59  bool upnp;
60  quint16 upnpPort;
61  QString url;
62 };
63 
64 DPointered(GameCreateParams)
65 
67 {
68  d->broadcastToLan = true;
69  d->broadcastToMaster = true;
70  d->randomMapRotation = false;
71  d->maxClients = 0;
72  d->maxPlayers = 0;
73  d->port = 0;
74  d->skill = 0;
75  d->upnp = true;
76  d->upnpPort = 0;
77 }
78 
79 GameCreateParams::~GameCreateParams()
80 {
81 }
82 
83 const QString& GameCreateParams::connectPassword() const
84 {
85  return d->connectPassword;
86 }
87 
88 QStringList& GameCreateParams::customParameters()
89 {
90  return d->customParameters;
91 }
92 
93 const QStringList& GameCreateParams::customParameters() const
94 {
95  return d->customParameters;
96 }
97 
98 QList<GameCVar>& GameCreateParams::cvars()
99 {
100  return d->cvars;
101 }
102 
103 const QList<GameCVar>& GameCreateParams::cvars() const
104 {
105  return d->cvars;
106 }
107 
108 const QString& GameCreateParams::demoPath() const
109 {
110  return d->demoPath;
111 }
112 
114 {
115  return d->demoRecord;
116 }
117 
118 void GameCreateParams::setDemoRecord(const GameDemo &demo)
119 {
120  d->demoRecord = demo;
121 }
122 
123 QList<DMFlagsSection>& GameCreateParams::dmFlags()
124 {
125  return d->dmFlags;
126 }
127 
128 const QList<DMFlagsSection>& GameCreateParams::dmFlags() const
129 {
130  return d->dmFlags;
131 }
132 
133 const QString& GameCreateParams::email() const
134 {
135  return d->email;
136 }
137 
138 const QString& GameCreateParams::executablePath() const
139 {
140  return d->executablePath;
141 }
142 
143 const GameMode& GameCreateParams::gameMode() const
144 {
145  return d->gameMode;
146 }
147 
148 GameCreateParams::HostMode GameCreateParams::hostMode() const
149 {
150  return d->hostMode;
151 }
152 
153 bool GameCreateParams::isBroadcastToLan() const
154 {
155  return d->broadcastToLan;
156 }
157 
158 bool GameCreateParams::isBroadcastToMaster() const
159 {
160  return d->broadcastToMaster;
161 }
162 
163 bool GameCreateParams::isRandomMapRotation() const
164 {
165  return d->randomMapRotation;
166 }
167 
168 const QString& GameCreateParams::ingamePassword() const
169 {
170  return d->ingamePassword;
171 }
172 
173 const QString& GameCreateParams::iwadPath() const
174 {
175  return d->iwadPath;
176 }
177 
179 {
180  QFileInfo fi(iwadPath());
181  return fi.fileName();
182 }
183 
184 const QString& GameCreateParams::map() const
185 {
186  return d->map;
187 }
188 
189 const QStringList& GameCreateParams::mapList() const
190 {
191  return d->mapList;
192 }
193 
194 int GameCreateParams::maxClients() const
195 {
196  return d->maxClients;
197 }
198 
199 int GameCreateParams::maxPlayers() const
200 {
201  return d->maxPlayers;
202 }
203 
205 {
206  return qMax(maxClients(), maxPlayers());
207 }
208 
209 const QString& GameCreateParams::motd() const
210 {
211  return d->motd;
212 }
213 
214 const QString& GameCreateParams::name() const
215 {
216  return d->name;
217 }
218 
219 QVariant GameCreateParams::option(const QString &name) const
220 {
221  return d->options[name];
222 }
223 
224 void GameCreateParams::setOption(const QString &name, const QVariant &value)
225 {
226  d->options[name] = value;
227 }
228 
229 unsigned short GameCreateParams::port() const
230 {
231  return d->port;
232 }
233 
234 QList<bool>& GameCreateParams::pwadsOptional()
235 {
236  return d->pwadsOptional;
237 }
238 
239 const QList<bool>& GameCreateParams::pwadsOptional() const
240 {
241  return d->pwadsOptional;
242 }
243 
244 QStringList& GameCreateParams::pwadsPaths()
245 {
246  return d->pwadsPaths;
247 }
248 
249 const QStringList& GameCreateParams::pwadsPaths() const
250 {
251  return d->pwadsPaths;
252 }
253 
254 QStringList GameCreateParams::pwadsNames() const
255 {
256  QStringList result;
257  foreach (const QString &path, pwadsPaths())
258  {
259  QFileInfo fi(path);
260  result << fi.fileName();
261  }
262  return result;
263 }
264 
265 QList<PWad> GameCreateParams::pwads() const
266 {
267  QList<PWad> result;
268  QStringList names = pwadsNames();
269  for (int i = 0; i < names.size(); ++i)
270  {
271  result << PWad(names[i], pwadsOptional()[i]);
272  }
273  return result;
274 }
275 
276 const QString& GameCreateParams::rconPassword() const
277 {
278  return d->rconPassword;
279 }
280 
281 void GameCreateParams::setBroadcastToLan(bool b)
282 {
283  d->broadcastToLan = b;
284 }
285 
286 void GameCreateParams::setBroadcastToMaster(bool b)
287 {
288  d->broadcastToMaster = b;
289 }
290 
291 void GameCreateParams::setConnectPassword(const QString& pass)
292 {
293  d->connectPassword = pass;
294 }
295 
296 void GameCreateParams::setCustomParameters(const QStringList& customParameters)
297 {
298  d->customParameters = customParameters;
299 }
300 
301 void GameCreateParams::setCvars(const QList<GameCVar>& cvars)
302 {
303  d->cvars = cvars;
304 }
305 
306 void GameCreateParams::setDemoPath(const QString& demoPath)
307 {
308  d->demoPath = demoPath;
309 }
310 
311 void GameCreateParams::setEmail(const QString& email)
312 {
313  d->email = email;
314 }
315 
316 void GameCreateParams::setExecutablePath(const QString& executablePath)
317 {
318  d->executablePath = executablePath;
319 }
320 
321 void GameCreateParams::setGameMode(const GameMode& mode)
322 {
323  d->gameMode = mode;
324 }
325 
326 void GameCreateParams::setHostMode(HostMode mode)
327 {
328  d->hostMode = mode;
329 }
330 
331 void GameCreateParams::setIngamePassword(const QString& pass)
332 {
333  d->ingamePassword = pass;
334 }
335 
336 void GameCreateParams::setIwadPath(const QString& iwadPath)
337 {
338  d->iwadPath = iwadPath;
339 }
340 
341 void GameCreateParams::setMap(const QString& map)
342 {
343  d->map = map;
344 }
345 
346 void GameCreateParams::setMapList(const QStringList& mapList)
347 {
348  d->mapList = mapList;
349 }
350 
351 void GameCreateParams::setMaxClients(int num)
352 {
353  d->maxClients = num;
354 }
355 
356 void GameCreateParams::setMaxPlayers(int num)
357 {
358  d->maxPlayers = num;
359 }
360 
361 void GameCreateParams::setMotd(const QString& motd)
362 {
363  d->motd = motd;
364 }
365 
366 void GameCreateParams::setName(const QString& name)
367 {
368  d->name = name;
369 }
370 
371 void GameCreateParams::setPort(unsigned short port)
372 {
373  d->port = port;
374 }
375 
376 void GameCreateParams::setPwadsOptional(const QList<bool>& pwadsOptional)
377 {
378  d->pwadsOptional = pwadsOptional;
379 }
380 
381 void GameCreateParams::setPwadsPaths(const QStringList& pwadsPaths)
382 {
383  d->pwadsPaths = pwadsPaths;
384 }
385 
386 void GameCreateParams::setRandomMapRotation(bool b)
387 {
388  d->randomMapRotation = b;
389 }
390 
391 void GameCreateParams::setRconPassword(const QString& pass)
392 {
393  d->rconPassword = pass;
394 }
395 
396 void GameCreateParams::setSkill(int skill)
397 {
398  d->skill = skill;
399 }
400 
401 void GameCreateParams::setUrl(const QString& url)
402 {
403  d->url = url;
404 }
405 
407 {
408  return d->skill;
409 }
410 
412 {
413  return d->upnp;
414 }
415 
416 void GameCreateParams::setUpnp(bool upnp)
417 {
418  d->upnp = upnp;
419 }
420 
422 {
423  return d->upnpPort;
424 }
425 
426 void GameCreateParams::setUpnpPort(quint16 port)
427 {
428  d->upnpPort = port;
429 }
430 
431 const QString& GameCreateParams::url() const
432 {
433  return d->url;
434 }
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 & 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.