author | Medo <smaxein@googlemail.com> |
Thu, 05 Jul 2012 00:33:24 +0200 | |
changeset 7316 | f7b49b2c5d84 |
parent 7314 | 6171f0bad318 |
child 7320 | e704706008d4 |
permissions | -rw-r--r-- |
7314
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
1 |
/* |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
2 |
* Hedgewars, a free turn based strategy game |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
3 |
* Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com> |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
4 |
* |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
5 |
* This program is free software; you can redistribute it and/or |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
6 |
* modify it under the terms of the GNU General Public License |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
7 |
* as published by the Free Software Foundation; either version 2 |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
8 |
* of the License, or (at your option) any later version. |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
9 |
* |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
10 |
* This program is distributed in the hope that it will be useful, |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
13 |
* GNU General Public License for more details. |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
14 |
* |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
16 |
* along with this program; if not, write to the Free Software |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
17 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
18 |
*/ |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
19 |
|
7177
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
20 |
#include "ipcprotocol.h" |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
7177
diff
changeset
|
21 |
#include "../util/util.h" |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
7177
diff
changeset
|
22 |
#include "../util/logging.h" |
7314
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
23 |
#include "../md5/md5.h" |
7177
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
24 |
|
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
25 |
#include <stdio.h> |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
26 |
#include <stdbool.h> |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
27 |
#include <string.h> |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
7177
diff
changeset
|
28 |
#include <inttypes.h> |
7230
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
29 |
#include <stdlib.h> |
7177
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
30 |
|
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
31 |
int flib_ipc_append_message(flib_vector *vec, const char *fmt, ...) { |
7177
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
32 |
int result = -1; |
7316
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
33 |
if(!log_badargs_if2(vec==NULL, fmt==NULL)) { |
7177
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
34 |
// 1 byte size prefix, 255 bytes max message length, 1 0-byte for vsnprintf |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
35 |
char msgbuffer[257]; |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
36 |
|
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
37 |
// Format the message, leaving one byte at the start for the length |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
38 |
va_list argp; |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
39 |
va_start(argp, fmt); |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
40 |
int msgSize = vsnprintf(msgbuffer+1, 256, fmt, argp); |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
41 |
va_end(argp); |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
42 |
|
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
43 |
if(!log_e_if(msgSize > 255, "Message too long (%u bytes)", (unsigned)msgSize) |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
44 |
&& !log_e_if(msgSize < 0, "printf error")) { |
7177
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
45 |
// Add the length prefix |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
46 |
((uint8_t*)msgbuffer)[0] = msgSize; |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
47 |
|
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
48 |
// Append it to the vector |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
49 |
result = flib_vector_append(vec, msgbuffer, msgSize+1); |
7177
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
50 |
} |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
51 |
} |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
52 |
return result; |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
53 |
} |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
54 |
|
7230
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
55 |
int flib_ipc_append_mapconf(flib_vector *vec, const flib_map *map, bool mappreview) { |
7177
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
56 |
int result = -1; |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
57 |
flib_vector *tempvector = flib_vector_create(); |
7316
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
58 |
if(!log_badargs_if2(vec==NULL, map==NULL)) { |
7177
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
59 |
bool error = false; |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
60 |
|
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
61 |
if(map->mapgen == MAPGEN_NAMED) { |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
62 |
error |= log_e_if(!map->name, "Missing map name") |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
63 |
|| flib_ipc_append_message(tempvector, "emap %s", map->name); |
7177
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
64 |
} |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
65 |
if(!mappreview) { |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
66 |
error |= log_e_if(!map->theme, "Missing map theme") |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
67 |
|| flib_ipc_append_message(tempvector, "etheme %s", map->theme); |
7177
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
68 |
} |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
69 |
error |= flib_ipc_append_seed(tempvector, map->seed); |
7177
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
70 |
error |= flib_ipc_append_message(tempvector, "e$template_filter %i", map->templateFilter); |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
71 |
error |= flib_ipc_append_message(tempvector, "e$mapgen %i", map->mapgen); |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
72 |
|
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
73 |
if(map->mapgen == MAPGEN_MAZE) { |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
74 |
error |= flib_ipc_append_message(tempvector, "e$maze_size %i", map->mazeSize); |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
75 |
} |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
76 |
if(map->mapgen == MAPGEN_DRAWN) { |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
77 |
/* |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
78 |
* We have to split the drawn map data into several edraw messages here because |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
79 |
* it can be longer than the maximum message size. |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
80 |
*/ |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
81 |
const char *edraw = "edraw "; |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
82 |
int edrawlen = strlen(edraw); |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
83 |
for(int offset=0; offset<map->drawDataSize; offset+=200) { |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
84 |
int bytesRemaining = map->drawDataSize-offset; |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
85 |
int fragmentsize = bytesRemaining < 200 ? bytesRemaining : 200; |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
86 |
uint8_t messagesize = edrawlen + fragmentsize; |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
87 |
error |= flib_vector_append(tempvector, &messagesize, 1); |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
88 |
error |= flib_vector_append(tempvector, edraw, edrawlen); |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
89 |
error |= flib_vector_append(tempvector, map->drawData+offset, fragmentsize); |
7177
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
90 |
} |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
91 |
} |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
92 |
|
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
93 |
if(!log_e_if(error, "Error generating map config")) { |
7177
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
94 |
// Message created, now we can copy everything. |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
95 |
flib_constbuffer constbuf = flib_vector_as_constbuffer(tempvector); |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
96 |
if(!flib_vector_append(vec, constbuf.data, constbuf.size)) { |
7177
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
97 |
result = 0; |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
98 |
} |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
99 |
} |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
100 |
} |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
101 |
flib_vector_destroy(tempvector); |
7177
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
102 |
return result; |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
103 |
} |
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
104 |
|
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
105 |
int flib_ipc_append_seed(flib_vector *vec, const char *seed) { |
7316
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
106 |
if(log_badargs_if2(vec==NULL, seed==NULL)) { |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
107 |
return -1; |
7177
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
108 |
} |
7316
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
109 |
return flib_ipc_append_message(vec, "eseed %s", seed); |
7177
bf6cf4dd847a
Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
110 |
} |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
7177
diff
changeset
|
111 |
|
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
112 |
int flib_ipc_append_script(flib_vector *vec, const char *script) { |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
113 |
int result = -1; |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
114 |
char *copy = flib_strdupnull(script); |
7316
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
115 |
if(!log_badargs_if(vec==NULL) && copy) { |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
116 |
if(!strcmp("Normal", copy)) { |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
117 |
// "Normal" means no gametype script |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
118 |
result = 0; |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
119 |
} else { |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
120 |
size_t len = strlen(copy); |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
121 |
for(size_t i=0; i<len; i++) { |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
122 |
if(copy[i] == ' ') { |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
123 |
copy[i] = '_'; |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
124 |
} |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
125 |
} |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
126 |
|
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
127 |
result = flib_ipc_append_message(vec, "escript %s%s.lua", MULTIPLAYER_SCRIPT_PATH, copy); |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
128 |
} |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
129 |
} |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
130 |
free(copy); |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
131 |
return result; |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
132 |
} |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
133 |
|
7316
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
134 |
static uint32_t buildModFlags(const flib_cfg *scheme) { |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
135 |
uint32_t result = 0; |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
136 |
for(int i=0; i<scheme->meta->modCount; i++) { |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
137 |
if(scheme->mods[i]) { |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
138 |
int bitmaskIndex = scheme->meta->mods[i].bitmaskIndex; |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
139 |
result |= (UINT32_C(1) << bitmaskIndex); |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
140 |
} |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
141 |
} |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
142 |
return result; |
7271
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
143 |
} |
5608ac657362
frontlib: Intermittent commit. Things are still in flux but we're getting there :)
Medo <smaxein@googlemail.com>
parents:
7230
diff
changeset
|
144 |
|
7230
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
145 |
int flib_ipc_append_gamescheme(flib_vector *vec, const flib_cfg *scheme) { |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
7177
diff
changeset
|
146 |
int result = -1; |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
147 |
flib_vector *tempvector = flib_vector_create(); |
7316
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
148 |
if(!log_badargs_if2(vec==NULL, scheme==NULL) && tempvector) { |
7230
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
149 |
const flib_cfg_meta *meta = scheme->meta; |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
7177
diff
changeset
|
150 |
bool error = false; |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
151 |
error |= flib_ipc_append_message(tempvector, "e$gmflags %"PRIu32, buildModFlags(scheme)); |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
7177
diff
changeset
|
152 |
for(int i=0; i<meta->settingCount; i++) { |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
153 |
if(meta->settings[i].engineCommand) { |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
154 |
int value = scheme->settings[i]; |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
155 |
if(meta->settings[i].maxMeansInfinity) { |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
156 |
value = value>=meta->settings[i].max ? 9999 : value; |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
157 |
} |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
158 |
if(meta->settings[i].times1000) { |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
159 |
value *= 1000; |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
160 |
} |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
161 |
error |= flib_ipc_append_message(tempvector, "%s %i", meta->settings[i].engineCommand, value); |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
7177
diff
changeset
|
162 |
} |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
7177
diff
changeset
|
163 |
} |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
7177
diff
changeset
|
164 |
|
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
7177
diff
changeset
|
165 |
if(!error) { |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
7177
diff
changeset
|
166 |
// Message created, now we can copy everything. |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
7177
diff
changeset
|
167 |
flib_constbuffer constbuf = flib_vector_as_constbuffer(tempvector); |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
168 |
if(!flib_vector_append(vec, constbuf.data, constbuf.size)) { |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
7177
diff
changeset
|
169 |
result = 0; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
7177
diff
changeset
|
170 |
} |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
7177
diff
changeset
|
171 |
} |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
7177
diff
changeset
|
172 |
} |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
173 |
flib_vector_destroy(tempvector); |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
7177
diff
changeset
|
174 |
return result; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
7177
diff
changeset
|
175 |
} |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
7177
diff
changeset
|
176 |
|
7230
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
177 |
static int appendWeaponSet(flib_vector *vec, flib_weaponset *set) { |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
178 |
return flib_ipc_append_message(vec, "eammloadt %s", set->loadout) |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
179 |
|| flib_ipc_append_message(vec, "eammprob %s", set->crateprob) |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
180 |
|| flib_ipc_append_message(vec, "eammdelay %s", set->delay) |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
181 |
|| flib_ipc_append_message(vec, "eammreinf %s", set->crateammo); |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
182 |
} |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
183 |
|
7314
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
184 |
static void calculateMd5Hex(const char *in, char out[33]) { |
7316
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
185 |
md5_state_t md5state; |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
186 |
uint8_t md5bytes[16]; |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
187 |
md5_init(&md5state); |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
188 |
md5_append(&md5state, (unsigned char*)in, strlen(in)); |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
189 |
md5_finish(&md5state, md5bytes); |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
190 |
for(int i=0;i<sizeof(md5bytes); i++) { |
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
191 |
snprintf(out+i*2, 3, "%02x", (unsigned)md5bytes[i]); |
7314
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
192 |
} |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
193 |
} |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
194 |
|
7230
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
195 |
int flib_ipc_append_addteam(flib_vector *vec, const flib_team *team, bool perHogAmmo, bool noAmmoStore) { |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
7177
diff
changeset
|
196 |
int result = -1; |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
197 |
flib_vector *tempvector = flib_vector_create(); |
7316
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
198 |
if(!log_badargs_if2(vec==NULL, team==NULL) && tempvector) { |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
7177
diff
changeset
|
199 |
bool error = false; |
7230
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
200 |
|
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
201 |
if(!perHogAmmo && !noAmmoStore) { |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
202 |
error = error |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
203 |
|| appendWeaponSet(tempvector, team->hogs[0].weaponset) |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
204 |
|| flib_ipc_append_message(tempvector, "eammstore"); |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
7177
diff
changeset
|
205 |
} |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
7177
diff
changeset
|
206 |
|
7314
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
207 |
char md5Hex[33]; |
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
208 |
calculateMd5Hex(team->ownerName ? team->ownerName : "", md5Hex); |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
209 |
if(team->colorIndex<0 || team->colorIndex>=flib_teamcolor_defaults_len) { |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
210 |
flib_log_e("Color index out of bounds for team %s: %i", team->name, team->colorIndex); |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
211 |
error = true; |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
212 |
} else { |
7314
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
213 |
error |= flib_ipc_append_message(tempvector, "eaddteam %s %"PRIu32" %s", md5Hex, flib_teamcolor_defaults[team->colorIndex], team->name); |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
214 |
} |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
7177
diff
changeset
|
215 |
|
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
7177
diff
changeset
|
216 |
if(team->remoteDriven) { |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
7177
diff
changeset
|
217 |
error |= flib_ipc_append_message(tempvector, "erdriven"); |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
7177
diff
changeset
|
218 |
} |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
7177
diff
changeset
|
219 |
|
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
7177
diff
changeset
|
220 |
error |= flib_ipc_append_message(tempvector, "egrave %s", team->grave); |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
7177
diff
changeset
|
221 |
error |= flib_ipc_append_message(tempvector, "efort %s", team->fort); |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
7177
diff
changeset
|
222 |
error |= flib_ipc_append_message(tempvector, "evoicepack %s", team->voicepack); |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
7177
diff
changeset
|
223 |
error |= flib_ipc_append_message(tempvector, "eflag %s", team->flag); |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
7177
diff
changeset
|
224 |
|
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
225 |
for(int i=0; i<team->bindingCount; i++) { |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
226 |
error |= flib_ipc_append_message(tempvector, "ebind %s %s", team->bindings[i].binding, team->bindings[i].action); |
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
227 |
} |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
7177
diff
changeset
|
228 |
|
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
7177
diff
changeset
|
229 |
for(int i=0; i<team->hogsInGame; i++) { |
7230
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
230 |
if(perHogAmmo && !noAmmoStore) { |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
231 |
error |= appendWeaponSet(tempvector, team->hogs[i].weaponset); |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
232 |
} |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
7177
diff
changeset
|
233 |
error |= flib_ipc_append_message(tempvector, "eaddhh %i %i %s", team->hogs[i].difficulty, team->hogs[i].initialHealth, team->hogs[i].name); |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
7177
diff
changeset
|
234 |
error |= flib_ipc_append_message(tempvector, "ehat %s", team->hogs[i].hat); |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
7177
diff
changeset
|
235 |
} |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
7177
diff
changeset
|
236 |
|
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
7177
diff
changeset
|
237 |
if(!error) { |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
7177
diff
changeset
|
238 |
// Message created, now we can copy everything. |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
7177
diff
changeset
|
239 |
flib_constbuffer constbuf = flib_vector_as_constbuffer(tempvector); |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
240 |
if(!flib_vector_append(vec, constbuf.data, constbuf.size)) { |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
7177
diff
changeset
|
241 |
result = 0; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
7177
diff
changeset
|
242 |
} |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
7177
diff
changeset
|
243 |
} |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
7177
diff
changeset
|
244 |
} |
7224
5143861c83bd
Cleanup, refactoring and generally more development in the frontlib
Medo <smaxein@googlemail.com>
parents:
7179
diff
changeset
|
245 |
flib_vector_destroy(tempvector); |
7179
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
7177
diff
changeset
|
246 |
return result; |
f84805e6df03
Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents:
7177
diff
changeset
|
247 |
} |
7230
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
248 |
|
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
249 |
int flib_ipc_append_fullconfig(flib_vector *vec, const flib_gamesetup *setup, bool netgame) { |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
250 |
int result = -1; |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
251 |
flib_vector *tempvector = flib_vector_create(); |
7316
f7b49b2c5d84
frontlib: Improved and unified parameter checking, moved the cmdlineClient out
Medo <smaxein@googlemail.com>
parents:
7314
diff
changeset
|
252 |
if(!log_badargs_if2(vec==NULL, setup==NULL) && tempvector) { |
7230
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
253 |
bool error = false; |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
254 |
bool perHogAmmo = false; |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
255 |
bool sharedAmmo = false; |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
256 |
|
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
257 |
error |= flib_ipc_append_message(vec, netgame ? "TN" : "TL"); |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
258 |
if(setup->map) { |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
259 |
error |= flib_ipc_append_mapconf(tempvector, setup->map, false); |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
260 |
} |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
261 |
if(setup->script) { |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
262 |
error |= flib_ipc_append_script(tempvector, setup->script); |
7230
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
263 |
} |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
264 |
if(setup->gamescheme) { |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
265 |
error |= flib_ipc_append_gamescheme(tempvector, setup->gamescheme); |
7314
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
266 |
sharedAmmo = flib_cfg_get_mod(setup->gamescheme, "sharedammo"); |
7230
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
267 |
// Shared ammo has priority over per-hog ammo |
7314
6171f0bad318
frontlib: Fixes and improvements. Added a GPLv2+ license header to all frontlib
Medo <smaxein@googlemail.com>
parents:
7275
diff
changeset
|
268 |
perHogAmmo = !sharedAmmo && flib_cfg_get_mod(setup->gamescheme, "perhogammo"); |
7230
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
269 |
} |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
270 |
if(setup->teamlist->teams && setup->teamlist->teamCount>0) { |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
271 |
int *clanColors = flib_calloc(setup->teamlist->teamCount, sizeof(int)); |
7230
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
272 |
if(!clanColors) { |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
273 |
error = true; |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
274 |
} else { |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
275 |
int clanCount = 0; |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
276 |
for(int i=0; !error && i<setup->teamlist->teamCount; i++) { |
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
277 |
flib_team *team = setup->teamlist->teams[i]; |
7230
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
278 |
// Find the clan index of this team (clans are identified by color). |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
279 |
bool newClan = false; |
7230
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
280 |
int clan = 0; |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
281 |
while(clan<clanCount && clanColors[clan] != team->colorIndex) { |
7230
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
282 |
clan++; |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
283 |
} |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
284 |
if(clan==clanCount) { |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
285 |
newClan = true; |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
286 |
clanCount++; |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
287 |
clanColors[clan] = team->colorIndex; |
7230
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
288 |
} |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
289 |
|
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
290 |
// If shared ammo is active, only add an ammo store for the first team in each clan. |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
291 |
bool noAmmoStore = sharedAmmo&&!newClan; |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
292 |
error |= flib_ipc_append_addteam(tempvector, setup->teamlist->teams[i], perHogAmmo, noAmmoStore); |
7230
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
293 |
} |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
294 |
} |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
295 |
free(clanColors); |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
296 |
} |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
297 |
error |= flib_ipc_append_message(tempvector, "!"); |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
298 |
|
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
299 |
if(!error) { |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
300 |
// Message created, now we can copy everything. |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
301 |
flib_constbuffer constbuf = flib_vector_as_constbuffer(tempvector); |
7275
15f722e0b96f
frontlib: Getting there :) Added commandline client for testing
Medo <smaxein@googlemail.com>
parents:
7271
diff
changeset
|
302 |
if(!flib_vector_append(vec, constbuf.data, constbuf.size)) { |
7230
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
303 |
result = 0; |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
304 |
} |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
305 |
} |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
306 |
} |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
307 |
return result; |
240620f46dd7
Changed frontlib to use the existing ini file formats of the QtFrontend
Medo <smaxein@googlemail.com>
parents:
7224
diff
changeset
|
308 |
} |