project_files/frontlib/ipc/gameconn.c
changeset 7320 e704706008d4
parent 7316 f7b49b2c5d84
child 7482 d70a5b0d1190
equal deleted inserted replaced
7318:a446eafcddeb 7320:e704706008d4
    52 	void *onErrorMessageCtx;
    52 	void *onErrorMessageCtx;
    53 
    53 
    54 	void (*onChatCb)(void* context, const char *msg, bool teamchat);
    54 	void (*onChatCb)(void* context, const char *msg, bool teamchat);
    55 	void *onChatCtx;
    55 	void *onChatCtx;
    56 
    56 
    57 	void (*onGameRecordedCb)(void *context, const uint8_t *record, int size, bool isSavegame);
    57 	void (*onGameRecordedCb)(void *context, const uint8_t *record, size_t size, bool isSavegame);
    58 	void *onGameRecordedCtx;
    58 	void *onGameRecordedCtx;
    59 
    59 
    60 	void (*onEngineMessageCb)(void *context, const uint8_t *em, size_t size);
    60 	void (*onEngineMessageCb)(void *context, const uint8_t *em, size_t size);
    61 	void *onEngineMessageCtx;
    61 	void *onEngineMessageCtx;
    62 
    62 
    63 	bool running;
    63 	bool running;
    64 	bool destroyRequested;
    64 	bool destroyRequested;
    65 };
    65 };
    66 
    66 
    67 static void defaultCallback_onConnect(void* context) {}
       
    68 static void defaultCallback_onDisconnect(void* context, int reason) {}
       
    69 static void defaultCallback_onErrorMessage(void* context, const char *msg) {
    67 static void defaultCallback_onErrorMessage(void* context, const char *msg) {
    70 	flib_log_w("Error from engine (no callback set): %s", msg);
    68 	flib_log_w("Error from engine (no callback set): %s", msg);
    71 }
    69 }
    72 static void defaultCallback_onChat(void* context, const char *msg, bool teamchat) {}
       
    73 static void defaultCallback_onGameRecorded(void *context, const uint8_t *record, int size, bool isSavegame) {}
       
    74 static void defaultCallback_onEngineMessage(void *context, const uint8_t *em, size_t size) {}
       
    75 
    70 
    76 static void clearCallbacks(flib_gameconn *conn) {
    71 static void clearCallbacks(flib_gameconn *conn) {
    77 	conn->onConnectCb = &defaultCallback_onConnect;
    72 	flib_gameconn_onConnect(conn, NULL, NULL);
    78 	conn->onDisconnectCb = &defaultCallback_onDisconnect;
    73 	flib_gameconn_onDisconnect(conn, NULL, NULL);
    79 	conn->onErrorMessageCb = &defaultCallback_onErrorMessage;
    74 	flib_gameconn_onErrorMessage(conn, NULL, NULL);
    80 	conn->onChatCb = &defaultCallback_onChat;
    75 	flib_gameconn_onChat(conn, NULL, NULL);
    81 	conn->onGameRecordedCb = &defaultCallback_onGameRecorded;
    76 	flib_gameconn_onGameRecorded(conn, NULL, NULL);
    82 	conn->onEngineMessageCb = &defaultCallback_onEngineMessage;
    77 	flib_gameconn_onEngineMessage(conn, NULL, NULL);
    83 }
    78 }
    84 
    79 
    85 static flib_gameconn *flib_gameconn_create_partial(bool record, const char *playerName, bool netGame) {
    80 static flib_gameconn *flib_gameconn_create_partial(bool record, const char *playerName, bool netGame) {
    86 	flib_gameconn *result = NULL;
    81 	flib_gameconn *result = NULL;
    87 	flib_gameconn *tempConn = flib_calloc(1, sizeof(flib_gameconn));
    82 	flib_gameconn *tempConn = flib_calloc(1, sizeof(flib_gameconn));
   310 
   305 
   311 GENERATE_CB_SETTER_AND_DEFAULT(onConnect, (void *context));
   306 GENERATE_CB_SETTER_AND_DEFAULT(onConnect, (void *context));
   312 GENERATE_CB_SETTER_AND_DEFAULT(onDisconnect, (void* context, int reason));
   307 GENERATE_CB_SETTER_AND_DEFAULT(onDisconnect, (void* context, int reason));
   313 GENERATE_CB_SETTER(onErrorMessage, (void* context, const char *msg), defaultCallback_onErrorMessage);
   308 GENERATE_CB_SETTER(onErrorMessage, (void* context, const char *msg), defaultCallback_onErrorMessage);
   314 GENERATE_CB_SETTER_AND_DEFAULT(onChat, (void* context, const char *msg, bool teamchat));
   309 GENERATE_CB_SETTER_AND_DEFAULT(onChat, (void* context, const char *msg, bool teamchat));
   315 GENERATE_CB_SETTER_AND_DEFAULT(onGameRecorded, (void *context, const uint8_t *record, int size, bool isSavegame));
   310 GENERATE_CB_SETTER_AND_DEFAULT(onGameRecorded, (void *context, const uint8_t *record, size_t size, bool isSavegame));
   316 GENERATE_CB_SETTER_AND_DEFAULT(onEngineMessage, (void *context, const uint8_t *em, size_t size));
   311 GENERATE_CB_SETTER_AND_DEFAULT(onEngineMessage, (void *context, const uint8_t *em, size_t size));
   317 
   312 
   318 #undef GENERATE_CB_SETTER_AND_DEFAULT
   313 #undef GENERATE_CB_SETTER_AND_DEFAULT
   319 #undef GENERATE_CB_SETTER
   314 #undef GENERATE_CB_SETTER
   320 
   315