project_files/frontlib/ipc/gameconn.c
changeset 7482 d70a5b0d1190
parent 7320 e704706008d4
child 7576 65d29988fd3d
equal deleted inserted replaced
7479:c8c552ee3acb 7482:d70a5b0d1190
   115 	}
   115 	}
   116 	flib_gameconn_destroy(tempConn);
   116 	flib_gameconn_destroy(tempConn);
   117 	return result;
   117 	return result;
   118 }
   118 }
   119 
   119 
   120 flib_gameconn *flib_gameconn_create_playdemo(const uint8_t *demo, size_t size) {
   120 flib_gameconn *flib_gameconn_create_playdemo(const uint8_t *demoFileContent, size_t size) {
   121 	if(log_badargs_if(demo==NULL && size>0)) {
   121 	if(log_badargs_if(demoFileContent==NULL && size>0)) {
   122 		return NULL;
   122 		return NULL;
   123 	}
   123 	}
   124 	flib_gameconn *result = NULL;
   124 	flib_gameconn *result = NULL;
   125 	flib_gameconn *tempConn = flib_gameconn_create_partial(false, "Player", false);
   125 	flib_gameconn *tempConn = flib_gameconn_create_partial(false, "Player", false);
   126 	if(tempConn) {
   126 	if(tempConn) {
   127 		if(!flib_vector_append(tempConn->configBuffer, demo, size)) {
   127 		if(!flib_vector_append(tempConn->configBuffer, demoFileContent, size)) {
   128 			result = tempConn;
   128 			result = tempConn;
   129 			tempConn = NULL;
   129 			tempConn = NULL;
   130 		}
   130 		}
   131 	}
   131 	}
   132 	flib_gameconn_destroy(tempConn);
   132 	flib_gameconn_destroy(tempConn);
   133 	return result;
   133 	return result;
   134 }
   134 }
   135 
   135 
   136 flib_gameconn *flib_gameconn_create_loadgame(const char *playerName, const uint8_t *save, size_t size) {
   136 flib_gameconn *flib_gameconn_create_loadgame(const char *playerName, const uint8_t *saveFileContent, size_t size) {
   137 	if(log_badargs_if(save==NULL && size>0)) {
   137 	if(log_badargs_if(saveFileContent==NULL && size>0)) {
   138 		return NULL;
   138 		return NULL;
   139 	}
   139 	}
   140 	flib_gameconn *result = NULL;
   140 	flib_gameconn *result = NULL;
   141 	flib_gameconn *tempConn = flib_gameconn_create_partial(true, playerName, false);
   141 	flib_gameconn *tempConn = flib_gameconn_create_partial(true, playerName, false);
   142 	if(tempConn) {
   142 	if(tempConn) {
   143 		if(!flib_vector_append(tempConn->configBuffer, save, size)) {
   143 		if(!flib_vector_append(tempConn->configBuffer, saveFileContent, size)) {
   144 			result = tempConn;
   144 			result = tempConn;
   145 			tempConn = NULL;
   145 			tempConn = NULL;
   146 		}
   146 		}
   147 	}
   147 	}
   148 	flib_gameconn_destroy(tempConn);
   148 	flib_gameconn_destroy(tempConn);
   273 	}
   273 	}
   274 	uint8_t converted[257];
   274 	uint8_t converted[257];
   275 	if(!format_chatmessage(converted, playername, msg)
   275 	if(!format_chatmessage(converted, playername, msg)
   276 			&& !flib_ipcbase_send_raw(conn->ipcBase, converted, converted[0]+1)) {
   276 			&& !flib_ipcbase_send_raw(conn->ipcBase, converted, converted[0]+1)) {
   277 		demo_append(conn, converted, converted[0]+1);
   277 		demo_append(conn, converted, converted[0]+1);
       
   278 		return 0;
       
   279 	}
       
   280 	return -1;
       
   281 }
       
   282 
       
   283 int flib_gameconn_send_quit(flib_gameconn *conn) {
       
   284 	if(log_badargs_if(conn==NULL)) {
       
   285 		return -1;
       
   286 	}
       
   287 	const char *msg = "\x07""efinish";
       
   288 	if(!flib_ipcbase_send_raw(conn->ipcBase, msg, msg[0]+1)) {
       
   289 		demo_append(conn, msg, msg[0]+1);
   278 		return 0;
   290 		return 0;
   279 	}
   291 	}
   280 	return -1;
   292 	return -1;
   281 }
   293 }
   282 
   294