project_files/frontlib/net/netconn.h
changeset 7338 1ed603a54ebd
parent 7324 fb6bfe8e30c8
child 7482 d70a5b0d1190
equal deleted inserted replaced
7336:f821f7d727b7 7338:1ed603a54ebd
    20 #ifndef NETCONN_H_
    20 #ifndef NETCONN_H_
    21 #define NETCONN_H_
    21 #define NETCONN_H_
    22 
    22 
    23 #include "../model/gamesetup.h"
    23 #include "../model/gamesetup.h"
    24 #include "../model/scheme.h"
    24 #include "../model/scheme.h"
    25 #include "../model/roomlist.h"
    25 #include "../model/room.h"
    26 
    26 
    27 #include <stddef.h>
    27 #include <stddef.h>
    28 #include <stdint.h>
    28 #include <stdint.h>
    29 #include <stdbool.h>
    29 #include <stdbool.h>
    30 
    30 
    71  * Perform I/O operations and call callbacks if something interesting happens.
    71  * Perform I/O operations and call callbacks if something interesting happens.
    72  * Should be called regularly.
    72  * Should be called regularly.
    73  */
    73  */
    74 void flib_netconn_tick(flib_netconn *conn);
    74 void flib_netconn_tick(flib_netconn *conn);
    75 
    75 
    76 
       
    77 /**
       
    78  * Return the current roomlist. Don't free or modify.
       
    79  */
       
    80 const flib_roomlist *flib_netconn_get_roomlist(flib_netconn *conn);
       
    81 
       
    82 /**
    76 /**
    83  * Are you currently the owner of this room? The return value only makes sense in
    77  * Are you currently the owner of this room? The return value only makes sense in
    84  * NETCONN_STATE_ROOM and NETCONN_STATE_INGAME states.
    78  * NETCONN_STATE_ROOM and NETCONN_STATE_INGAME states.
    85  */
    79  */
    86 bool flib_netconn_is_chief(flib_netconn *conn);
    80 bool flib_netconn_is_chief(flib_netconn *conn);
    87 
    81 
    88 /**
    82 /**
    89  * Are you in the context of a room, i.e. either in room or ingame state?
    83  * Are you in the context of a room, i.e. either in room or ingame state?
    90  */
    84  */
    91 bool flib_netconn_is_in_room_context(flib_netconn *conn);
    85 bool flib_netconn_is_in_room_context(flib_netconn *conn);
       
    86 
       
    87 /**
       
    88  * Returns the playername. This is *probably* the one provided on creation, but
       
    89  * if that name was already taken, a different one could have been set by the
       
    90  * onNickTaken callback or its default implementation.
       
    91  */
       
    92 const char *flib_netconn_get_playername(flib_netconn *conn);
    92 
    93 
    93 /**
    94 /**
    94  * Generate a game setup from the current room state.
    95  * Generate a game setup from the current room state.
    95  * Returns NULL if the room state does not contain enough information
    96  * Returns NULL if the room state does not contain enough information
    96  * for a complete game setup, or if an error occurs.
    97  * for a complete game setup, or if an error occurs.
   125  * be changed.
   126  * be changed.
   126  */
   127  */
   127 int flib_netconn_send_nick(flib_netconn *conn, const char *nick);
   128 int flib_netconn_send_nick(flib_netconn *conn, const char *nick);
   128 
   129 
   129 /**
   130 /**
       
   131  * Request an update of the room list. Only makes sense when in lobby state.
       
   132  * If the action succeeds, you will receive an onRoomlist callback containing the current room data.
       
   133  */
       
   134 int flib_netconn_send_request_roomlist(flib_netconn *conn);
       
   135 
       
   136 /**
   130  * Join a room as guest (not chief). Only makes sense when in lobby state. If the action succeeds, you will
   137  * Join a room as guest (not chief). Only makes sense when in lobby state. If the action succeeds, you will
   131  * receive an onEnterRoom callback with chief=false.
   138  * receive an onEnterRoom callback with chief=false.
   132  */
   139  */
   133 int flib_netconn_send_joinRoom(flib_netconn *conn, const char *room);
   140 int flib_netconn_send_joinRoom(flib_netconn *conn, const char *room);
   134 
   141 
   354  * also be NULL.
   361  * also be NULL.
   355  */
   362  */
   356 void flib_netconn_onDisconnected(flib_netconn *conn, void (*callback)(void *context, int reason, const char *message), void* context);
   363 void flib_netconn_onDisconnected(flib_netconn *conn, void (*callback)(void *context, int reason, const char *message), void* context);
   357 
   364 
   358 /**
   365 /**
   359  * Callbacks for room list updates. The room list is managed automatically and can be queried with
   366  * Callbacks for room list updates. The roomlist can be queried with flib_netconn_send_request_roomlist(), which will
   360  * flib_netconn_get_roomlist() as soon as the onConnected callback is fired. These callbacks
   367  * trigger flib_netconn_onRoomlist once the server replies. Additionally, the roomAdd/delete/update callbacks will fire
   361  * provide notification about changes.
   368  * whenever the server informs about these events, which can happen *before* the roomlist is first received - so be sure
   362  */
   369  * not to blindly reference your room list in these callbacks. The server currently only sends updates when a room changes
       
   370  * its name, so in order to update other room information you need to query the roomlist again.
       
   371  */
       
   372 void flib_netconn_onRoomlist(flib_netconn *conn, void (*callback)(void *context, const flib_room **rooms, int roomCount), void* context);
   363 void flib_netconn_onRoomAdd(flib_netconn *conn, void (*callback)(void *context, const flib_room *room), void* context);
   373 void flib_netconn_onRoomAdd(flib_netconn *conn, void (*callback)(void *context, const flib_room *room), void* context);
   364 void flib_netconn_onRoomDelete(flib_netconn *conn, void (*callback)(void *context, const char *name), void* context);
   374 void flib_netconn_onRoomDelete(flib_netconn *conn, void (*callback)(void *context, const char *name), void* context);
   365 void flib_netconn_onRoomUpdate(flib_netconn *conn, void (*callback)(void *context, const char *oldName, const flib_room *room), void* context);
   375 void flib_netconn_onRoomUpdate(flib_netconn *conn, void (*callback)(void *context, const char *oldName, const flib_room *room), void* context);
   366 
   376 
   367 /**
   377 /**