5 #include <stdio.h> |
5 #include <stdio.h> |
6 #include <stdbool.h> |
6 #include <stdbool.h> |
7 #include <string.h> |
7 #include <string.h> |
8 #include <inttypes.h> |
8 #include <inttypes.h> |
9 |
9 |
10 int flib_ipc_append_message(flib_vector vec, const char *fmt, ...) { |
10 int flib_ipc_append_message(flib_vector *vec, const char *fmt, ...) { |
11 int result = -1; |
11 int result = -1; |
12 if(!vec || !fmt) { |
12 if(!vec || !fmt) { |
13 flib_log_e("null parameter in flib_ipc_appendmessage"); |
13 flib_log_e("null parameter in flib_ipc_appendmessage"); |
14 } else { |
14 } else { |
15 // 1 byte size prefix, 255 bytes max message length, 1 0-byte for vsnprintf |
15 // 1 byte size prefix, 255 bytes max message length, 1 0-byte for vsnprintf |
36 } |
36 } |
37 } |
37 } |
38 return result; |
38 return result; |
39 } |
39 } |
40 |
40 |
41 int flib_ipc_append_mapconf(flib_vector vec, flib_map *map, bool mappreview) { |
41 int flib_ipc_append_mapconf(flib_vector *vec, flib_map *map, bool mappreview) { |
42 int result = -1; |
42 int result = -1; |
43 flib_vector tempvector = flib_vector_create(); |
43 flib_vector *tempvector = flib_vector_create(); |
44 if(!vec || !map) { |
44 if(!vec || !map) { |
45 flib_log_e("null parameter in flib_ipc_append_mapconf"); |
45 flib_log_e("null parameter in flib_ipc_append_mapconf"); |
46 } else if(tempvector) { |
46 } else if(tempvector) { |
47 bool error = false; |
47 bool error = false; |
48 |
48 |
81 if(flib_vector_append(vec, constbuf.data, constbuf.size) == constbuf.size) { |
81 if(flib_vector_append(vec, constbuf.data, constbuf.size) == constbuf.size) { |
82 result = 0; |
82 result = 0; |
83 } |
83 } |
84 } |
84 } |
85 } |
85 } |
86 flib_vector_destroy(&tempvector); |
86 flib_vector_destroy(tempvector); |
87 return result; |
87 return result; |
88 } |
88 } |
89 |
89 |
90 int flib_ipc_append_seed(flib_vector vec, const char *seed) { |
90 int flib_ipc_append_seed(flib_vector *vec, const char *seed) { |
91 if(!vec || !seed) { |
91 if(!vec || !seed) { |
92 flib_log_e("null parameter in flib_ipc_append_seed"); |
92 flib_log_e("null parameter in flib_ipc_append_seed"); |
93 return -1; |
93 return -1; |
94 } else { |
94 } else { |
95 return flib_ipc_append_message(vec, "eseed %s", seed); |
95 return flib_ipc_append_message(vec, "eseed %s", seed); |
96 } |
96 } |
97 } |
97 } |
98 |
98 |
99 int flib_ipc_append_gamescheme(flib_vector vec, flib_cfg *scheme, flib_cfg_meta *meta) { |
99 int flib_ipc_append_gamescheme(flib_vector *vec, flib_cfg *scheme, flib_cfg_meta *meta) { |
100 int result = -1; |
100 int result = -1; |
101 flib_vector tempvector = flib_vector_create(); |
101 flib_vector *tempvector = flib_vector_create(); |
102 if(!vec || !scheme || !meta) { |
102 if(!vec || !scheme || !meta) { |
103 flib_log_e("null parameter in flib_ipc_append_gamescheme"); |
103 flib_log_e("null parameter in flib_ipc_append_gamescheme"); |
104 } else if(tempvector) { |
104 } else if(tempvector) { |
105 bool error = false; |
105 bool error = false; |
106 uint32_t gamemods = 0; |
106 uint32_t gamemods = 0; |
127 if(flib_vector_append(vec, constbuf.data, constbuf.size) == constbuf.size) { |
127 if(flib_vector_append(vec, constbuf.data, constbuf.size) == constbuf.size) { |
128 result = 0; |
128 result = 0; |
129 } |
129 } |
130 } |
130 } |
131 } |
131 } |
132 flib_vector_destroy(&tempvector); |
132 flib_vector_destroy(tempvector); |
133 return result; |
133 return result; |
134 } |
134 } |
135 |
135 |
136 // FIXME shared ammo will break per-team ammo |
136 // FIXME shared ammo will break per-team ammo |
137 int flib_ipc_append_addteam(flib_vector vec, flib_team *team, bool perHogAmmo, bool sharedAmmo) { |
137 int flib_ipc_append_addteam(flib_vector *vec, flib_team *team, bool perHogAmmo, bool sharedAmmo) { |
138 int result = -1; |
138 int result = -1; |
139 flib_vector tempvector = flib_vector_create(); |
139 flib_vector *tempvector = flib_vector_create(); |
140 if(!vec || !team || !team->weaponset) { |
140 if(!vec || !team || !team->weaponset) { |
141 flib_log_e("invalid parameter in flib_ipc_append_addteam"); |
141 flib_log_e("invalid parameter in flib_ipc_append_addteam"); |
142 } else if(tempvector) { |
142 } else if(tempvector) { |
143 bool error = false; |
143 bool error = false; |
144 error |= flib_ipc_append_message(tempvector, "eammloadt %s", team->weaponset->loadout); |
144 error |= flib_ipc_append_message(tempvector, "eammloadt %s", team->weaponset->loadout); |
159 error |= flib_ipc_append_message(tempvector, "egrave %s", team->grave); |
159 error |= flib_ipc_append_message(tempvector, "egrave %s", team->grave); |
160 error |= flib_ipc_append_message(tempvector, "efort %s", team->fort); |
160 error |= flib_ipc_append_message(tempvector, "efort %s", team->fort); |
161 error |= flib_ipc_append_message(tempvector, "evoicepack %s", team->voicepack); |
161 error |= flib_ipc_append_message(tempvector, "evoicepack %s", team->voicepack); |
162 error |= flib_ipc_append_message(tempvector, "eflag %s", team->flag); |
162 error |= flib_ipc_append_message(tempvector, "eflag %s", team->flag); |
163 |
163 |
164 // TODO bindings |
164 for(int i=0; i<team->bindingCount; i++) { |
|
165 error |= flib_ipc_append_message(tempvector, "ebind %s %s", team->bindings[i].binding, team->bindings[i].action); |
|
166 } |
165 |
167 |
166 for(int i=0; i<team->hogsInGame; i++) { |
168 for(int i=0; i<team->hogsInGame; i++) { |
167 error |= flib_ipc_append_message(tempvector, "eaddhh %i %i %s", team->hogs[i].difficulty, team->hogs[i].initialHealth, team->hogs[i].name); |
169 error |= flib_ipc_append_message(tempvector, "eaddhh %i %i %s", team->hogs[i].difficulty, team->hogs[i].initialHealth, team->hogs[i].name); |
168 error |= flib_ipc_append_message(tempvector, "ehat %s", team->hogs[i].hat); |
170 error |= flib_ipc_append_message(tempvector, "ehat %s", team->hogs[i].hat); |
169 } |
171 } |