project_files/frontlib/frontlib.c
changeset 7162 fe76d24a25d7
parent 7160 c42949cfdd92
child 7171 906e72caea7b
--- a/project_files/frontlib/frontlib.c	Thu May 31 18:54:40 2012 +0200
+++ b/project_files/frontlib/frontlib.c	Sat Jun 02 14:26:52 2012 +0200
@@ -43,10 +43,8 @@
 }
 
 int main(int argc, char *argv[]) {
-	flib_init(0);
-	int port = flib_ipcconn_listen();
-	printf("%i\n", port);
-	fflush(stdout);
+	flib_init(FRONTLIB_SDL_ALREADY_INITIALIZED);
+	flib_ipcconn_start(true);
 	char data[256];
 	while(flib_ipcconn_state() != IPC_NOT_CONNECTED) {
 		flib_ipcconn_tick();
@@ -54,12 +52,36 @@
 		if(size>0) {
 			data[size]=0;
 			flib_log_i("IPC IN: %s", data);
-			if(data[0]=='?') {
-				flib_log_i("IPC OUT: !");
-				flib_ipcconn_send_message("!", 1);
+			switch(data[0]) {
+			case 'C':
+				flib_log_i("Sending config...");
+				flib_ipcconn_send_messagestr("TL");
+				flib_ipcconn_send_messagestr("eseed loremipsum");
+				flib_ipcconn_send_messagestr("escript Missions/Training/Basic_Training_-_Bazooka.lua");
+				break;
+			case '?':
+				flib_log_i("Sending pong...");
+				flib_ipcconn_send_messagestr("!");
+				break;
+			case 'Q':
+				flib_log_i("Game interrupted.");
+				break;
+			case 'q':
+				flib_log_i("Game finished.");
+				flib_constbuffer demobuf = flib_ipcconn_getdemo();
+				flib_log_i("Writing demo (%u bytes)...", demobuf.size);
+				FILE *file = fopen("testdemo.dem", "w");
+				fwrite(demobuf.data, 1, demobuf.size, file);
+				fclose(file);
+				file = NULL;
+				break;
+			case 'H':
+				flib_log_i("Game halted.");
+				break;
 			}
 		}
 	}
 	flib_log_i("IPC connection lost.");
+	flib_quit();
 	return 0;
 }