project_files/frontlib/net/netconn.h
changeset 7234 613998625a3c
child 7269 5b0aeef8ba2a
equal deleted inserted replaced
7230:240620f46dd7 7234:613998625a3c
       
     1 #ifndef NETCONN_H_
       
     2 #define NETCONN_H_
       
     3 
       
     4 #include "../model/gamesetup.h"
       
     5 
       
     6 #include <stddef.h>
       
     7 #include <stdint.h>
       
     8 #include <stdbool.h>
       
     9 
       
    10 #define NETCONN_STATE_AWAIT_CONNECTED 0
       
    11 #define NETCONN_STATE_LOBBY 1
       
    12 #define NETCONN_STATE_ROOM 2
       
    13 #define NETCONN_STATE_INGAME 3
       
    14 #define NETCONN_STATE_DISCONNECTED 10
       
    15 
       
    16 #define NETCONN_ERROR_SERVER_TOO_OLD 1
       
    17 #define NETCONN_ERROR_FROM_SERVER 2
       
    18 
       
    19 struct _flib_netconn;
       
    20 typedef struct _flib_netconn flib_netconn;
       
    21 
       
    22 flib_netconn *flib_netconn_create(const char *playerName, const char *host, uint16_t port);
       
    23 void flib_netconn_destroy(flib_netconn *conn);
       
    24 
       
    25 /**
       
    26  * This is called when we can't stay connected due to a problem, e.g. because the
       
    27  * server version is too old, or we are unexpectedly disconnected.
       
    28  *
       
    29  * Once this callback has been called, you should destroy the flib_netconn.
       
    30  */
       
    31 void flib_netconn_onError(flib_netconn *conn, void (*callback)(void *context, int errorCode, const char *errormsg), void* context);
       
    32 
       
    33 /**
       
    34  * This is called when we receive a CONNECTED message from the server, which should be the first
       
    35  * message arriving from the server.
       
    36  */
       
    37 void flib_netconn_onConnected(flib_netconn *conn, void (*callback)(void *context, const char *serverMessage), void* context);
       
    38 
       
    39 /**
       
    40  * Perform I/O operations and call callbacks if something interesting happens.
       
    41  * Should be called regularly.
       
    42  */
       
    43 void flib_netconn_tick(flib_netconn *conn);
       
    44 
       
    45 #endif