240 char ammostring[WEAPONS_COUNT*4+1]; |
240 char ammostring[WEAPONS_COUNT*4+1]; |
241 strcpy(ammostring, weaponset->loadout); |
241 strcpy(ammostring, weaponset->loadout); |
242 strcat(ammostring, weaponset->crateprob); |
242 strcat(ammostring, weaponset->crateprob); |
243 strcat(ammostring, weaponset->delay); |
243 strcat(ammostring, weaponset->delay); |
244 strcat(ammostring, weaponset->crateammo); |
244 strcat(ammostring, weaponset->crateammo); |
245 if(!flib_netbase_sendf(conn->netBase, "CFG\nAMMO\n%s\n%s\n\n", weaponset->name, ammostring)) { |
245 if(conn->isChief) { |
246 if(conn->isChief) { |
246 if(!flib_netbase_sendf(conn->netBase, "CFG\nAMMO\n%s\n%s\n\n", weaponset->name, ammostring)) { |
247 netconn_setWeaponset(conn, weaponset); |
247 netconn_setWeaponset(conn, weaponset); |
248 } |
248 return 0; |
249 return 0; |
249 } |
250 } |
250 } |
251 } |
251 } |
252 return -1; |
252 return -1; |
253 } |
253 } |
254 |
254 |
275 } |
275 } |
276 return error; |
276 return error; |
277 } |
277 } |
278 |
278 |
279 int flib_netconn_send_mapName(flib_netconn *conn, const char *mapName) { |
279 int flib_netconn_send_mapName(flib_netconn *conn, const char *mapName) { |
280 if(!sendStr(conn, "CFG\nMAP", mapName)) { |
280 if(log_badargs_if2(conn==NULL, mapName==NULL)) { |
281 if(conn->isChief) { |
281 return -1; |
|
282 } |
|
283 if(conn->isChief) { |
|
284 if(!sendStr(conn, "CFG\nMAP", mapName)) { |
282 char *copy = flib_strdupnull(mapName); |
285 char *copy = flib_strdupnull(mapName); |
283 if(copy) { |
286 if(copy) { |
284 free(conn->map->name); |
287 free(conn->map->name); |
285 conn->map->name = copy; |
288 conn->map->name = copy; |
286 } |
289 return 0; |
287 } |
290 } |
288 return 0; |
291 } |
289 } |
292 } |
290 return -1; |
293 return -1; |
291 } |
294 } |
292 |
295 |
293 int flib_netconn_send_mapGen(flib_netconn *conn, int mapGen) { |
296 int flib_netconn_send_mapGen(flib_netconn *conn, int mapGen) { |
294 if(!sendInt(conn, "CFG\nMAPGEN", mapGen)) { |
297 if(log_badargs_if(conn==NULL)) { |
295 if(conn->isChief) { |
298 return -1; |
|
299 } |
|
300 if(conn->isChief) { |
|
301 if(!sendInt(conn, "CFG\nMAPGEN", mapGen)) { |
296 conn->map->mapgen = mapGen; |
302 conn->map->mapgen = mapGen; |
297 } |
303 return 0; |
298 return 0; |
304 } |
299 } |
305 } |
300 return -1; |
306 return -1; |
301 } |
307 } |
302 |
308 |
303 int flib_netconn_send_mapTemplate(flib_netconn *conn, int templateFilter) { |
309 int flib_netconn_send_mapTemplate(flib_netconn *conn, int templateFilter) { |
304 if(!sendInt(conn, "CFG\nTEMPLATE", templateFilter)) { |
310 if(log_badargs_if(conn==NULL)) { |
305 if(conn->isChief) { |
311 return -1; |
|
312 } |
|
313 if(conn->isChief) { |
|
314 if(!sendInt(conn, "CFG\nTEMPLATE", templateFilter)) { |
306 conn->map->templateFilter = templateFilter; |
315 conn->map->templateFilter = templateFilter; |
307 } |
316 return 0; |
308 return 0; |
317 } |
309 } |
318 } |
310 return -1; |
319 return -1; |
311 } |
320 } |
312 |
321 |
313 int flib_netconn_send_mapMazeSize(flib_netconn *conn, int mazeSize) { |
322 int flib_netconn_send_mapMazeSize(flib_netconn *conn, int mazeSize) { |
314 if(!sendInt(conn, "CFG\nMAZE_SIZE", mazeSize)) { |
323 if(log_badargs_if(conn==NULL)) { |
315 if(conn->isChief) { |
324 return -1; |
|
325 } |
|
326 if(conn->isChief) { |
|
327 if(!sendInt(conn, "CFG\nMAZE_SIZE", mazeSize)) { |
316 conn->map->mazeSize = mazeSize; |
328 conn->map->mazeSize = mazeSize; |
317 } |
329 return 0; |
318 return 0; |
330 } |
319 } |
331 } |
320 return -1; |
332 return -1; |
321 } |
333 } |
322 |
334 |
323 int flib_netconn_send_mapSeed(flib_netconn *conn, const char *seed) { |
335 int flib_netconn_send_mapSeed(flib_netconn *conn, const char *seed) { |
324 if(!sendStr(conn, "CFG\nSEED", seed)) { |
336 if(log_badargs_if2(conn==NULL, seed==NULL)) { |
325 if(conn->isChief) { |
337 return -1; |
|
338 } |
|
339 if(conn->isChief) { |
|
340 if(!sendStr(conn, "CFG\nSEED", seed)) { |
326 char *copy = flib_strdupnull(seed); |
341 char *copy = flib_strdupnull(seed); |
327 if(copy) { |
342 if(copy) { |
328 free(conn->map->seed); |
343 free(conn->map->seed); |
329 conn->map->seed = copy; |
344 conn->map->seed = copy; |
330 } |
345 return 0; |
331 } |
346 } |
332 return 0; |
347 } |
333 } |
348 } |
334 return -1; |
349 return -1; |
335 } |
350 } |
336 |
351 |
337 int flib_netconn_send_mapTheme(flib_netconn *conn, const char *theme) { |
352 int flib_netconn_send_mapTheme(flib_netconn *conn, const char *theme) { |
338 if(!sendStr(conn, "CFG\nTHEME", theme)) { |
353 if(log_badargs_if2(conn==NULL, theme==NULL)) { |
339 if(conn->isChief) { |
354 return -1; |
|
355 } |
|
356 if(conn->isChief) { |
|
357 if(!sendStr(conn, "CFG\nTHEME", theme)) { |
340 char *copy = flib_strdupnull(theme); |
358 char *copy = flib_strdupnull(theme); |
341 if(copy) { |
359 if(copy) { |
342 free(conn->map->theme); |
360 free(conn->map->theme); |
343 conn->map->theme = copy; |
361 conn->map->theme = copy; |
344 } |
362 return 0; |
345 } |
363 } |
346 return 0; |
364 } |
347 } |
365 } |
348 return -1; |
366 return -1; |
349 } |
367 } |
350 |
368 |
351 int flib_netconn_send_mapDrawdata(flib_netconn *conn, const uint8_t *drawData, size_t size) { |
369 int flib_netconn_send_mapDrawdata(flib_netconn *conn, const uint8_t *drawData, size_t size) { |
352 int result = -1; |
370 int result = -1; |
353 if(!log_badargs_if3(conn==NULL, drawData==NULL && size>0, size>SIZE_MAX/2)) { |
371 if(!log_badargs_if3(conn==NULL, drawData==NULL && size>0, size>SIZE_MAX/2) && conn->isChief) { |
354 uLongf zippedSize = compressBound(size); |
372 uLongf zippedSize = compressBound(size); |
355 uint8_t *zipped = flib_malloc(zippedSize+4); // 4 extra bytes for header |
373 uint8_t *zipped = flib_malloc(zippedSize+4); // 4 extra bytes for header |
356 if(zipped) { |
374 if(zipped) { |
357 // Create the QCompress size header (uint32 big endian) |
375 // Create the QCompress size header (uint32 big endian) |
358 zipped[0] = (size>>24) & 0xff; |
376 zipped[0] = (size>>24) & 0xff; |
386 } |
404 } |
387 return result; |
405 return result; |
388 } |
406 } |
389 |
407 |
390 int flib_netconn_send_script(flib_netconn *conn, const char *scriptName) { |
408 int flib_netconn_send_script(flib_netconn *conn, const char *scriptName) { |
391 if(!sendStr(conn, "CFG\nSCRIPT", scriptName)) { |
409 if(log_badargs_if2(conn==NULL, scriptName==NULL)) { |
392 if(conn->isChief) { |
410 return -1; |
|
411 } |
|
412 if(conn->isChief) { |
|
413 if(!sendStr(conn, "CFG\nSCRIPT", scriptName)) { |
393 netconn_setScript(conn, scriptName); |
414 netconn_setScript(conn, scriptName); |
394 } |
415 return 0; |
395 return 0; |
416 } |
396 } |
417 } |
397 return -1; |
418 return -1; |
398 } |
419 } |
399 |
420 |
400 int flib_netconn_send_scheme(flib_netconn *conn, const flib_scheme *scheme) { |
421 int flib_netconn_send_scheme(flib_netconn *conn, const flib_scheme *scheme) { |
401 int result = -1; |
422 int result = -1; |
402 if(!log_badargs_if3(conn==NULL, scheme==NULL, flib_strempty(scheme->name))) { |
423 if(!log_badargs_if3(conn==NULL, scheme==NULL, flib_strempty(scheme->name)) && conn->isChief) { |
403 flib_vector *vec = flib_vector_create(); |
424 flib_vector *vec = flib_vector_create(); |
404 if(vec) { |
425 if(vec) { |
405 bool error = false; |
426 bool error = false; |
406 error |= flib_vector_appendf(vec, "CFG\nSCHEME\n%s\n", scheme->name); |
427 error |= flib_vector_appendf(vec, "CFG\nSCHEME\n%s\n", scheme->name); |
407 for(int i=0; i<scheme->meta->modCount; i++) { |
428 for(int i=0; i<flib_meta.modCount; i++) { |
408 error |= flib_vector_appendf(vec, "%s\n", scheme->mods[i] ? "true" : "false"); |
429 error |= flib_vector_appendf(vec, "%s\n", scheme->mods[i] ? "true" : "false"); |
409 } |
430 } |
410 for(int i=0; i<scheme->meta->settingCount; i++) { |
431 for(int i=0; i<flib_meta.settingCount; i++) { |
411 error |= flib_vector_appendf(vec, "%i\n", scheme->settings[i]); |
432 error |= flib_vector_appendf(vec, "%i\n", scheme->settings[i]); |
412 } |
433 } |
413 error |= flib_vector_appendf(vec, "\n"); |
434 error |= flib_vector_appendf(vec, "\n"); |
414 if(!error) { |
435 if(!error) { |
415 result = flib_netbase_send_raw(conn->netBase, flib_vector_data(vec), flib_vector_size(vec)); |
436 result = flib_netbase_send_raw(conn->netBase, flib_vector_data(vec), flib_vector_size(vec)); |
416 } |
437 } |
417 } |
438 } |
418 flib_vector_destroy(vec); |
439 flib_vector_destroy(vec); |
419 } |
440 } |
420 |
441 |
421 if(!result && conn->isChief) { |
442 if(!result) { |
422 netconn_setScheme(conn, scheme); |
443 netconn_setScheme(conn, scheme); |
423 } |
444 } |
424 return result; |
445 return result; |
425 } |
446 } |
426 |
447 |