27 SDL_Quit(); |
27 SDL_Quit(); |
28 } |
28 } |
29 return -1; |
29 return -1; |
30 } |
30 } |
31 |
31 |
32 flib_ipcconn_init(); |
|
33 return 0; |
32 return 0; |
34 } |
33 } |
35 |
34 |
36 void flib_quit() { |
35 void flib_quit() { |
37 flib_ipcconn_quit(); |
|
38 |
|
39 SDLNet_Quit(); |
36 SDLNet_Quit(); |
40 if(!(flib_initflags | FRONTLIB_SDL_ALREADY_INITIALIZED)) { |
37 if(!(flib_initflags | FRONTLIB_SDL_ALREADY_INITIALIZED)) { |
41 SDL_Quit(); |
38 SDL_Quit(); |
42 } |
39 } |
43 } |
40 } |
44 |
41 |
45 int main(int argc, char *argv[]) { |
42 int main(int argc, char *argv[]) { |
46 flib_init(FRONTLIB_SDL_ALREADY_INITIALIZED); |
43 flib_init(0); |
47 flib_ipcconn_start(true); |
44 |
|
45 flib_ipcconn ipc = flib_ipcconn_create(true, "Medo42"); |
48 char data[256]; |
46 char data[256]; |
49 while(flib_ipcconn_state() != IPC_NOT_CONNECTED) { |
47 while(flib_ipcconn_state(ipc) != IPC_NOT_CONNECTED) { |
50 flib_ipcconn_tick(); |
48 flib_ipcconn_tick(ipc); |
51 int size = flib_ipcconn_recv_message(data); |
49 int size = flib_ipcconn_recv_message(ipc, data); |
52 if(size>0) { |
50 if(size>0) { |
53 data[size]=0; |
51 data[size]=0; |
54 flib_log_i("IPC IN: %s", data); |
|
55 switch(data[0]) { |
52 switch(data[0]) { |
56 case 'C': |
53 case 'C': |
57 flib_log_i("Sending config..."); |
54 flib_log_i("Sending config..."); |
58 flib_ipcconn_send_messagestr("TL"); |
55 flib_ipcconn_send_messagestr(ipc, "TL"); |
59 flib_ipcconn_send_messagestr("eseed loremipsum"); |
56 flib_ipcconn_send_messagestr(ipc, "eseed loremipsum"); |
60 flib_ipcconn_send_messagestr("escript Missions/Training/Basic_Training_-_Bazooka.lua"); |
57 flib_ipcconn_send_messagestr(ipc, "escript Missions/Training/Basic_Training_-_Bazooka.lua"); |
61 break; |
58 break; |
62 case '?': |
59 case '?': |
63 flib_log_i("Sending pong..."); |
60 flib_log_i("Sending pong..."); |
64 flib_ipcconn_send_messagestr("!"); |
61 flib_ipcconn_send_messagestr(ipc, "!"); |
65 break; |
62 break; |
66 case 'Q': |
63 case 'Q': |
67 flib_log_i("Game interrupted."); |
64 flib_log_i("Game interrupted."); |
68 break; |
65 break; |
69 case 'q': |
66 case 'q': |
70 flib_log_i("Game finished."); |
67 flib_log_i("Game finished."); |
71 flib_constbuffer demobuf = flib_ipcconn_getdemo(); |
68 flib_constbuffer demobuf = flib_ipcconn_getdemo(ipc); |
72 flib_log_i("Writing demo (%u bytes)...", demobuf.size); |
69 flib_log_i("Writing demo (%u bytes)...", demobuf.size); |
73 FILE *file = fopen("testdemo.dem", "w"); |
70 FILE *file = fopen("testdemo.dem", "wb"); |
74 fwrite(demobuf.data, 1, demobuf.size, file); |
71 fwrite(demobuf.data, 1, demobuf.size, file); |
75 fclose(file); |
72 fclose(file); |
76 file = NULL; |
73 file = NULL; |
77 break; |
74 break; |
78 case 'H': |
75 case 'H': |