project_files/frontlib/ipc/ipcprotocol.c
author Medo <smaxein@googlemail.com>
Sat, 09 Jun 2012 03:28:38 +0200
changeset 7179 f84805e6df03
parent 7177 bf6cf4dd847a
child 7224 5143861c83bd
permissions -rw-r--r--
Implemented game launching API for the frontlib. It is still buggy though, and not all game settings can be conveniently created/modified yet.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7177
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
     1
#include "ipcprotocol.h"
7179
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
     2
#include "../util/util.h"
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
     3
#include "../util/logging.h"
7177
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
     4
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
     5
#include <stdio.h>
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
     6
#include <stdbool.h>
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
     7
#include <string.h>
7179
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
     8
#include <inttypes.h>
7177
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
     9
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    10
int flib_ipc_append_message(flib_vector vec, const char *fmt, ...) {
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    11
	int result = -1;
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    12
	if(!vec || !fmt) {
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    13
		flib_log_e("null parameter in flib_ipc_appendmessage");
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    14
	} else {
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    15
		// 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
    16
		char msgbuffer[257];
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    17
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    18
		// 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
    19
		va_list argp;
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    20
		va_start(argp, fmt);
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    21
		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
    22
		va_end(argp);
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    23
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    24
		if(msgSize > 255) {
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    25
			flib_log_e("Message too long (%u bytes) in flib_ipc_appendmessage", (unsigned)msgSize);
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    26
		} else if(msgSize<0) {
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    27
			flib_log_e("printf error in flib_ipc_appendmessage");
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    28
		} else {
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    29
			// Add the length prefix
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    30
			((uint8_t*)msgbuffer)[0] = msgSize;
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    31
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    32
			// Append it to the vector
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    33
			if(flib_vector_append(vec, msgbuffer, msgSize+1) == msgSize+1) {
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    34
				result = 0;
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    35
			}
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
	}
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    38
	return result;
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    39
}
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    40
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    41
int flib_ipc_append_mapconf(flib_vector vec, flib_map *map, bool mappreview) {
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    42
	int result = -1;
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    43
	flib_vector tempvector = flib_vector_create();
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    44
	if(!vec || !map) {
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    45
		flib_log_e("null parameter in flib_ipc_append_mapconf");
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    46
	} else if(tempvector) {
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    47
		bool error = false;
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    48
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    49
		if(map->mapgen == MAPGEN_NAMED) {
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    50
			error |= flib_ipc_append_message(tempvector, "emap %s", map->name);
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
		if(map->theme && !mappreview) {
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    53
			error |= flib_ipc_append_message(tempvector, "etheme %s", map->theme);
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    54
		}
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    55
		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
    56
		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
    57
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    58
		if(map->mapgen == MAPGEN_MAZE) {
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    59
			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
    60
		}
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    61
		if(map->mapgen == MAPGEN_DRAWN) {
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    62
			/*
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    63
			 * 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
    64
			 * 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
    65
			 */
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    66
			const char *edraw = "edraw ";
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    67
			int edrawlen = strlen(edraw);
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    68
			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
    69
				int bytesRemaining = map->drawDataSize-offset;
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    70
				int fragmentsize = bytesRemaining < 200 ? bytesRemaining : 200;
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    71
				uint8_t messagesize = edrawlen + fragmentsize;
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    72
				error |= (flib_vector_append(tempvector, &messagesize, 1) != 1);
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    73
				error |= (flib_vector_append(tempvector, edraw, edrawlen) != edrawlen);
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    74
				error |= (flib_vector_append(tempvector, map->drawData+offset, fragmentsize) != fragmentsize);
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
		}
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
		if(!error) {
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    79
			// Message created, now we can copy everything.
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    80
			flib_constbuffer constbuf = flib_vector_as_constbuffer(tempvector);
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    81
			if(flib_vector_append(vec, constbuf.data, constbuf.size) == constbuf.size) {
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    82
				result = 0;
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    83
			}
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    84
		}
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    85
	}
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    86
	flib_vector_destroy(&tempvector);
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    87
	return result;
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    88
}
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    89
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    90
int flib_ipc_append_seed(flib_vector vec, const char *seed) {
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    91
	if(!vec || !seed) {
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    92
		flib_log_e("null parameter in flib_ipc_append_seed");
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    93
		return -1;
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    94
	} else {
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    95
		return flib_ipc_append_message(vec, "eseed %s", seed);
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    96
	}
bf6cf4dd847a Implemented public API for letting the engine render maps
Medo <smaxein@googlemail.com>
parents:
diff changeset
    97
}
7179
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
    98
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
    99
int flib_ipc_append_gamescheme(flib_vector vec, flib_cfg *scheme, flib_cfg_meta *meta) {
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   100
	int result = -1;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   101
	flib_vector tempvector = flib_vector_create();
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   102
	if(!vec || !scheme || !meta) {
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   103
		flib_log_e("null parameter in flib_ipc_append_gamescheme");
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   104
	} else if(tempvector) {
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   105
		bool error = false;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   106
		uint32_t gamemods = 0;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   107
		for(int i=0; i<meta->modCount; i++) {
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   108
			if(scheme->mods[i]) {
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   109
				gamemods |= (1<<meta->mods[i].bitmaskIndex);
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   110
			}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   111
		}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   112
		error |= flib_ipc_append_message(tempvector, "e$gmflags %"PRIu32, gamemods);
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   113
		for(int i=0; i<meta->settingCount; i++) {
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   114
			int value = scheme->settings[i];
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   115
			if(meta->settings[i].checkOverMax) {
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   116
				value = value>meta->settings[i].max ? meta->settings[i].max : value;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   117
			}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   118
			if(meta->settings[i].times1000) {
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   119
				value *= 1000;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   120
			}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   121
			error |= flib_ipc_append_message(tempvector, "%s %i", meta->settings[i].engineCommand, value);
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   122
		}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   123
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   124
		if(!error) {
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   125
			// Message created, now we can copy everything.
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   126
			flib_constbuffer constbuf = flib_vector_as_constbuffer(tempvector);
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   127
			if(flib_vector_append(vec, constbuf.data, constbuf.size) == constbuf.size) {
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   128
				result = 0;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   129
			}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   130
		}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   131
	}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   132
	flib_vector_destroy(&tempvector);
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   133
	return result;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   134
}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   135
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   136
// FIXME shared ammo will break per-team ammo
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   137
int flib_ipc_append_addteam(flib_vector vec, flib_team *team, bool perHogAmmo, bool sharedAmmo) {
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   138
	int result = -1;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   139
	flib_vector tempvector = flib_vector_create();
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   140
	if(!vec || !team || !team->weaponset) {
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   141
		flib_log_e("invalid parameter in flib_ipc_append_addteam");
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   142
	} else if(tempvector) {
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   143
		bool error = false;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   144
		error |= flib_ipc_append_message(tempvector, "eammloadt %s", team->weaponset->loadout);
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   145
		error |= flib_ipc_append_message(tempvector, "eammprob %s", team->weaponset->crateprob);
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   146
		error |= flib_ipc_append_message(tempvector, "eammdelay %s", team->weaponset->delay);
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   147
		error |= flib_ipc_append_message(tempvector, "eammreinf %s", team->weaponset->crateammo);
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   148
		if(!perHogAmmo) {
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   149
			error |= flib_ipc_append_message(tempvector, "eammstore");
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   150
		}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   151
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   152
		char *hash = team->hash ? team->hash : "00000000000000000000000000000000";
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   153
		error |= flib_ipc_append_message(tempvector, "eaddteam %s %"PRIu32" %s", hash, team->color, team->name);
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   154
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   155
		if(team->remoteDriven) {
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   156
			error |= flib_ipc_append_message(tempvector, "erdriven");
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   157
		}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   158
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   159
		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
   160
		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
   161
		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
   162
		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
   163
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   164
		// TODO bindings
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   165
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   166
		for(int i=0; i<team->hogsInGame; i++) {
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   167
			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
   168
			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
   169
		}
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
		if(!error) {
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   172
			// Message created, now we can copy everything.
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   173
			flib_constbuffer constbuf = flib_vector_as_constbuffer(tempvector);
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   174
			if(flib_vector_append(vec, constbuf.data, constbuf.size) == constbuf.size) {
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   175
				result = 0;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   176
			}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   177
		}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   178
	}
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   179
	flib_vector_destroy(&tempvector);
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   180
	return result;
f84805e6df03 Implemented game launching API for the frontlib.
Medo <smaxein@googlemail.com>
parents: 7177
diff changeset
   181
}