project_files/frontlib/frontlib.c
changeset 7162 fe76d24a25d7
parent 7160 c42949cfdd92
child 7171 906e72caea7b
equal deleted inserted replaced
7160:c42949cfdd92 7162:fe76d24a25d7
    41 		SDL_Quit();
    41 		SDL_Quit();
    42 	}
    42 	}
    43 }
    43 }
    44 
    44 
    45 int main(int argc, char *argv[]) {
    45 int main(int argc, char *argv[]) {
    46 	flib_init(0);
    46 	flib_init(FRONTLIB_SDL_ALREADY_INITIALIZED);
    47 	int port = flib_ipcconn_listen();
    47 	flib_ipcconn_start(true);
    48 	printf("%i\n", port);
       
    49 	fflush(stdout);
       
    50 	char data[256];
    48 	char data[256];
    51 	while(flib_ipcconn_state() != IPC_NOT_CONNECTED) {
    49 	while(flib_ipcconn_state() != IPC_NOT_CONNECTED) {
    52 		flib_ipcconn_tick();
    50 		flib_ipcconn_tick();
    53 		int size = flib_ipcconn_recv_message(data);
    51 		int size = flib_ipcconn_recv_message(data);
    54 		if(size>0) {
    52 		if(size>0) {
    55 			data[size]=0;
    53 			data[size]=0;
    56 			flib_log_i("IPC IN: %s", data);
    54 			flib_log_i("IPC IN: %s", data);
    57 			if(data[0]=='?') {
    55 			switch(data[0]) {
    58 				flib_log_i("IPC OUT: !");
    56 			case 'C':
    59 				flib_ipcconn_send_message("!", 1);
    57 				flib_log_i("Sending config...");
       
    58 				flib_ipcconn_send_messagestr("TL");
       
    59 				flib_ipcconn_send_messagestr("eseed loremipsum");
       
    60 				flib_ipcconn_send_messagestr("escript Missions/Training/Basic_Training_-_Bazooka.lua");
       
    61 				break;
       
    62 			case '?':
       
    63 				flib_log_i("Sending pong...");
       
    64 				flib_ipcconn_send_messagestr("!");
       
    65 				break;
       
    66 			case 'Q':
       
    67 				flib_log_i("Game interrupted.");
       
    68 				break;
       
    69 			case 'q':
       
    70 				flib_log_i("Game finished.");
       
    71 				flib_constbuffer demobuf = flib_ipcconn_getdemo();
       
    72 				flib_log_i("Writing demo (%u bytes)...", demobuf.size);
       
    73 				FILE *file = fopen("testdemo.dem", "w");
       
    74 				fwrite(demobuf.data, 1, demobuf.size, file);
       
    75 				fclose(file);
       
    76 				file = NULL;
       
    77 				break;
       
    78 			case 'H':
       
    79 				flib_log_i("Game halted.");
       
    80 				break;
    60 			}
    81 			}
    61 		}
    82 		}
    62 	}
    83 	}
    63 	flib_log_i("IPC connection lost.");
    84 	flib_log_i("IPC connection lost.");
       
    85 	flib_quit();
    64 	return 0;
    86 	return 0;
    65 }
    87 }