1 #include "frontlib.h" |
1 #include "frontlib.h" |
2 #include "util/logging.h" |
2 #include "util/logging.h" |
|
3 #include "util/buffer.h" |
3 #include "model/map.h" |
4 #include "model/map.h" |
4 #include "model/weapon.h" |
5 #include "model/weapon.h" |
5 #include "model/schemelist.h" |
6 #include "model/schemelist.h" |
6 #include "ipc/mapconn.h" |
7 #include "ipc/mapconn.h" |
7 #include "ipc/gameconn.h" |
8 #include "ipc/gameconn.h" |
|
9 #include "net/netbase.h" |
8 |
10 |
9 #include <stdlib.h> |
11 #include <stdlib.h> |
10 #include <stdbool.h> |
12 #include <stdbool.h> |
11 #include <assert.h> |
13 #include <assert.h> |
|
14 #include <string.h> |
12 |
15 |
13 // Callback function that will be called when the map is rendered |
16 // Callback function that will be called when the map is rendered |
14 static void handleMapSuccess(void *context, const uint8_t *bitmap, int numHedgehogs) { |
17 static void handleMapSuccess(void *context, const uint8_t *bitmap, int numHedgehogs) { |
15 printf("Drawing map for %i brave little hogs...", numHedgehogs); |
18 printf("Drawing map for %i brave little hogs...", numHedgehogs); |
16 |
19 |
202 //testMapPreview(); |
205 //testMapPreview(); |
203 //testDemo(); |
206 //testDemo(); |
204 //testSave(); |
207 //testSave(); |
205 //testGame(); |
208 //testGame(); |
206 |
209 |
207 flib_cfg_meta *meta = flib_cfg_meta_from_ini("metasettings.ini"); |
210 flib_netbase *conn = flib_netbase_create("140.247.62.101", 46631); |
208 assert(meta); |
211 |
209 flib_schemelist *schemelist = flib_schemelist_from_ini(meta, "schemes.ini"); |
212 while(flib_netbase_connected(conn)) { |
210 assert(schemelist); |
213 flib_netmsg *msg = flib_netbase_recv_message(conn); |
211 |
214 if(msg && msg->partCount>0) { |
212 flib_schemelist_to_ini("Copy of Schemelist.ini", schemelist); |
215 flib_log_i("[NET IN] %s", msg->parts[0]); |
213 flib_schemelist_release(schemelist); |
216 for(int i=1; i<msg->partCount; i++) { |
214 flib_cfg_meta_release(meta); |
217 flib_log_i("[NET IN][-] %s", msg->parts[i]); |
215 |
218 } |
216 flib_weaponsetlist *weaponsets = flib_weaponsetlist_from_ini("weapons.ini"); |
219 if(!strcmp(msg->parts[0], "CONNECTED")) { |
217 assert(!flib_weaponsetlist_to_ini("copy of weapons.ini", weaponsets)); |
220 flib_netmsg *nickmsg = flib_netmsg_create(); |
218 flib_weaponsetlist_release(weaponsets); |
221 flib_netmsg_append_part(nickmsg, "NICK", 4); |
|
222 flib_netmsg_append_part(nickmsg, "Medo42_frontlib", 15); |
|
223 flib_netmsg *protomsg = flib_netmsg_create(); |
|
224 flib_netmsg_append_part(protomsg, "PROTO", 5); |
|
225 flib_netmsg_append_part(protomsg, "42", 2); |
|
226 flib_netbase_send_message(conn, nickmsg); |
|
227 flib_netbase_send_message(conn, protomsg); |
|
228 flib_netmsg_destroy(nickmsg); |
|
229 flib_netmsg_destroy(protomsg); |
|
230 } |
|
231 if(!strcmp(msg->parts[0], "SERVER_MESSAGE")) { |
|
232 flib_netmsg *quitmsg = flib_netmsg_create(); |
|
233 flib_netmsg_append_part(quitmsg, "QUIT", 4); |
|
234 flib_netmsg_append_part(quitmsg, "Just testing", 12); |
|
235 flib_netbase_send_message(conn, quitmsg); |
|
236 flib_netmsg_destroy(quitmsg); |
|
237 } |
|
238 } |
|
239 flib_netmsg_destroy(msg); |
|
240 } |
219 |
241 |
220 flib_quit(); |
242 flib_quit(); |
221 return 0; |
243 return 0; |
222 } |
244 } |