project_files/frontlib/ipc/gameconn.h
changeset 7179 f84805e6df03
child 7224 5143861c83bd
equal deleted inserted replaced
7177:bf6cf4dd847a 7179:f84805e6df03
       
     1 #ifndef GAMECONN_H_
       
     2 #define GAMECONN_H_
       
     3 
       
     4 #include "../util/buffer.h"
       
     5 #include "../model/gamesetup.h"
       
     6 
       
     7 #include <stddef.h>
       
     8 #include <stdint.h>
       
     9 #include <stdbool.h>
       
    10 
       
    11 #define GAME_END_FINISHED 0
       
    12 #define GAME_END_INTERRUPTED 1
       
    13 #define GAME_END_HALTED 2
       
    14 #define GAME_END_ERROR 3
       
    15 
       
    16 struct _flib_gameconn;
       
    17 typedef struct _flib_gameconn flib_gameconn;
       
    18 
       
    19 flib_gameconn *flib_gameconn_create(const char *playerName, flib_cfg_meta *metaconf, flib_gamesetup *setup, bool netgame);
       
    20 flib_gameconn *flib_gameconn_create_playdemo(const uint8_t *demo, int size);
       
    21 flib_gameconn *flib_gameconn_create_loadgame(const char *playerName, const uint8_t *save, int size);
       
    22 void flib_gameconn_destroy(flib_gameconn *conn);
       
    23 
       
    24 /**
       
    25  * Returns the port on which the gameconn is listening. Only fails if you
       
    26  * pass NULL (not allowed), in that case 0 is returned.
       
    27  */
       
    28 int flib_gameconn_getport(flib_gameconn *conn);
       
    29 
       
    30 /**
       
    31  * Perform I/O operations and call callbacks if something interesting happens.
       
    32  * Should be called regularly.
       
    33  */
       
    34 void flib_gameconn_tick(flib_gameconn *conn);
       
    35 
       
    36 // TODO: Not needed yet, only for netgames
       
    37 /*
       
    38 flib_gameconn_send_enginemsg(flib_gameconn conn, uint8_t *data, int len);
       
    39 flib_gameconn_send_textmsg(flib_gameconn conn, int msgtype, const char *msg);
       
    40 flib_gameconn_send_chatmsg(flib_gameconn conn, const char *playername, const char *msg);
       
    41 */
       
    42 
       
    43 /**
       
    44  * handleConnect(void *context)
       
    45  */
       
    46 void flib_gameconn_onConnect(flib_gameconn *conn, void (*callback)(void* context), void* context);
       
    47 
       
    48 /**
       
    49  * handleDisconnect(void *context, int reason)
       
    50  */
       
    51 void flib_gameconn_onDisconnect(flib_gameconn *conn, void (*callback)(void* context, int reason), void* context);
       
    52 
       
    53 /**
       
    54  * Receives error messages sent by the engine
       
    55  * handleErrorMessage(void* context, const char *msg)
       
    56  */
       
    57 void flib_gameconn_onErrorMessage(flib_gameconn *conn, void (*callback)(void* context, const char *msg), void* context);
       
    58 
       
    59 /**
       
    60  * handleChat(void* context, const char *msg, bool teamchat)
       
    61  */
       
    62 void flib_gameconn_onChat(flib_gameconn *conn, void (*callback)(void* context, const char *msg, bool teamchat), void* context);
       
    63 
       
    64 /**
       
    65  * Called when the game ends
       
    66  * handleGameRecorded(void *context, const uint8_t *record, int size, bool isSavegame)
       
    67  */
       
    68 void flib_gameconn_onGameRecorded(flib_gameconn *conn, void (*callback)(void *context, const uint8_t *record, int size, bool isSavegame), void* context);
       
    69 
       
    70 /**
       
    71  * Called when the game ends
       
    72  * TODO handleStats(???)
       
    73  */
       
    74 
       
    75 /**
       
    76  * ...needs to be passed on to the server in a net game
       
    77  * handleEngineMessage(void *context, const uint8_t *em, int size)
       
    78  */
       
    79 void flib_gameconn_onNetMessage(flib_gameconn *conn, void (*callback)(void *context, const uint8_t *em, int size), void* context);
       
    80 
       
    81 #endif