13 FINISHED |
14 FINISHED |
14 } mapconn_state; |
15 } mapconn_state; |
15 |
16 |
16 struct _flib_mapconn { |
17 struct _flib_mapconn { |
17 uint8_t mapBuffer[IPCCONN_MAPMSG_BYTES]; |
18 uint8_t mapBuffer[IPCCONN_MAPMSG_BYTES]; |
18 flib_ipcconn connection; |
19 flib_ipcconn *connection; |
19 flib_vector configBuffer; |
20 flib_vector *configBuffer; |
20 |
21 |
21 mapconn_state progress; |
22 mapconn_state progress; |
22 |
23 |
23 void (*onSuccessCb)(void*, const uint8_t*, int); |
24 void (*onSuccessCb)(void*, const uint8_t*, int); |
24 void *onSuccessCtx; |
25 void *onSuccessCtx; |
36 static void clearCallbacks(flib_mapconn *conn) { |
37 static void clearCallbacks(flib_mapconn *conn) { |
37 conn->onSuccessCb = &noop_handleSuccess; |
38 conn->onSuccessCb = &noop_handleSuccess; |
38 conn->onFailureCb = &noop_handleFailure; |
39 conn->onFailureCb = &noop_handleFailure; |
39 } |
40 } |
40 |
41 |
41 static flib_vector createConfigBuffer(char *seed, flib_map *mapdesc) { |
42 static flib_vector *createConfigBuffer(char *seed, flib_map *mapdesc) { |
42 flib_vector result = NULL; |
43 flib_vector *result = NULL; |
43 flib_vector tempbuffer = flib_vector_create(); |
44 flib_vector *tempbuffer = flib_vector_create(); |
44 if(tempbuffer) { |
45 if(tempbuffer) { |
45 bool error = false; |
46 bool error = false; |
46 error |= flib_ipc_append_seed(tempbuffer, seed); |
47 error |= flib_ipc_append_seed(tempbuffer, seed); |
47 error |= flib_ipc_append_mapconf(tempbuffer, mapdesc, true); |
48 error |= flib_ipc_append_mapconf(tempbuffer, mapdesc, true); |
48 error |= flib_ipc_append_message(tempbuffer, "!"); |
49 error |= flib_ipc_append_message(tempbuffer, "!"); |
49 if(!error) { |
50 if(!error) { |
50 result = tempbuffer; |
51 result = tempbuffer; |
51 tempbuffer = NULL; |
52 tempbuffer = NULL; |
52 } |
53 } |
53 } |
54 } |
54 flib_vector_destroy(&tempbuffer); |
55 flib_vector_destroy(tempbuffer); |
55 return result; |
56 return result; |
56 } |
57 } |
57 |
58 |
58 flib_mapconn *flib_mapconn_create(char *seed, flib_map *mapdesc) { |
59 flib_mapconn *flib_mapconn_create(char *seed, flib_map *mapdesc) { |
59 flib_mapconn *result = NULL; |
60 flib_mapconn *result = NULL; |
60 flib_mapconn *tempConn = calloc(1, sizeof(flib_mapconn)); |
61 flib_mapconn *tempConn = flib_calloc(1, sizeof(flib_mapconn)); |
61 if(tempConn) { |
62 if(tempConn) { |
62 tempConn->connection = flib_ipcconn_create(false, "Player"); |
63 tempConn->connection = flib_ipcconn_create(); |
63 tempConn->configBuffer = createConfigBuffer(seed, mapdesc); |
64 tempConn->configBuffer = createConfigBuffer(seed, mapdesc); |
64 if(tempConn->connection && tempConn->configBuffer) { |
65 if(tempConn->connection && tempConn->configBuffer) { |
65 tempConn->progress = AWAIT_CONNECTION; |
66 tempConn->progress = AWAIT_CONNECTION; |
66 clearCallbacks(tempConn); |
67 clearCallbacks(tempConn); |
67 result = tempConn; |
68 result = tempConn; |