project_files/frontlib/net/netconn.h
changeset 7320 e704706008d4
parent 7316 f7b49b2c5d84
child 7324 fb6bfe8e30c8
equal deleted inserted replaced
7318:a446eafcddeb 7320:e704706008d4
    19 
    19 
    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/cfg.h"
    24 #include "../model/scheme.h"
    25 #include "../model/roomlist.h"
    25 #include "../model/roomlist.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>
    61 
    61 
    62 /**
    62 /**
    63  * Create a new netplay connection with these parameters.
    63  * Create a new netplay connection with these parameters.
    64  * The path to the data directory must end with a path delimiter (e.g. C:\Games\Hedgewars\Data\)
    64  * The path to the data directory must end with a path delimiter (e.g. C:\Games\Hedgewars\Data\)
    65  */
    65  */
    66 flib_netconn *flib_netconn_create(const char *playerName, flib_cfg_meta *metacfg, const char *dataDirPath, const char *host, uint16_t port);
    66 flib_netconn *flib_netconn_create(const char *playerName, flib_metascheme *metacfg, const char *dataDirPath, const char *host, int port);
    67 void flib_netconn_destroy(flib_netconn *conn);
    67 void flib_netconn_destroy(flib_netconn *conn);
    68 
    68 
    69 /**
    69 /**
    70  * Perform I/O operations and call callbacks if something interesting happens.
    70  * Perform I/O operations and call callbacks if something interesting happens.
    71  * Should be called regularly.
    71  * Should be called regularly.
   250 
   250 
   251 /**
   251 /**
   252  * Set the scheme. Only makes sense in room state and if you are chief.
   252  * Set the scheme. Only makes sense in room state and if you are chief.
   253  * The server does not send a reply.
   253  * The server does not send a reply.
   254  */
   254  */
   255 int flib_netconn_send_scheme(flib_netconn *conn, const flib_cfg *scheme);
   255 int flib_netconn_send_scheme(flib_netconn *conn, const flib_scheme *scheme);
   256 
   256 
   257 /**
   257 /**
   258  * Inform the server that the round has ended. Call this when the engine
   258  * Inform the server that the round has ended. Call this when the engine
   259  * has disconnected, passing 1 if the round ended normally, 0 otherwise.
   259  * has disconnected, passing 1 if the round ended normally, 0 otherwise.
   260  */
   260  */
   423 
   423 
   424 /**
   424 /**
   425  * A new team was added to the room. The person who adds a team does NOT receive this callback (he gets onTeamAccepted instead).
   425  * A new team was added to the room. The person who adds a team does NOT receive this callback (he gets onTeamAccepted instead).
   426  * The team does not contain bindings, stats, weaponset, color or the number of hogs.
   426  * The team does not contain bindings, stats, weaponset, color or the number of hogs.
   427  */
   427  */
   428 void flib_netconn_onTeamAdd(flib_netconn *conn, void (*callback)(void *context, flib_team *team), void *context);
   428 void flib_netconn_onTeamAdd(flib_netconn *conn, void (*callback)(void *context, const flib_team *team), void *context);
   429 
   429 
   430 /**
   430 /**
   431  * A team was removed from the room.
   431  * A team was removed from the room.
   432  */
   432  */
   433 void flib_netconn_onTeamDelete(flib_netconn *conn, void (*callback)(void *context, const char *teamname), void *context);
   433 void flib_netconn_onTeamDelete(flib_netconn *conn, void (*callback)(void *context, const char *teamname), void *context);
   460  */
   460  */
   461 void flib_netconn_onTeamColorChanged(flib_netconn *conn, void (*callback)(void *context, const char *teamName, int colorIndex), void *context);
   461 void flib_netconn_onTeamColorChanged(flib_netconn *conn, void (*callback)(void *context, const char *teamName, int colorIndex), void *context);
   462 
   462 
   463 void flib_netconn_onEngineMessage(flib_netconn *conn, void (*callback)(void *context, const uint8_t *message, size_t size), void *context);
   463 void flib_netconn_onEngineMessage(flib_netconn *conn, void (*callback)(void *context, const uint8_t *message, size_t size), void *context);
   464 
   464 
   465 void flib_netconn_onCfgScheme(flib_netconn *conn, void (*callback)(void *context, flib_cfg *scheme), void *context);
   465 void flib_netconn_onCfgScheme(flib_netconn *conn, void (*callback)(void *context, const flib_scheme *scheme), void *context);
   466 
   466 
   467 /**
   467 /**
   468  * This is called when the map configuration in a room is changed (or first received). Only non-chiefs receive these messages.
   468  * This is called when the map configuration in a room is changed (or first received). Only non-chiefs receive these messages.
   469  * To reduce the number of callback functions, the netconn keeps track of the current map settings and always passes the entire
   469  * To reduce the number of callback functions, the netconn keeps track of the current map settings and always passes the entire
   470  * current map config, but informs the callee about what has changed (see the NETCONN_MAPCHANGE_ constants).
   470  * current map config, but informs the callee about what has changed (see the NETCONN_MAPCHANGE_ constants).
   484 
   484 
   485 /**
   485 /**
   486  * The weaponset has been changed by the room chief. If you are the chief and change the weaponset yourself,
   486  * The weaponset has been changed by the room chief. If you are the chief and change the weaponset yourself,
   487  * you will not receive this callback!
   487  * you will not receive this callback!
   488  */
   488  */
   489 void flib_netconn_onWeaponsetChanged(flib_netconn *conn, void (*callback)(void *context, flib_weaponset *weaponset), void *context);
   489 void flib_netconn_onWeaponsetChanged(flib_netconn *conn, void (*callback)(void *context, const flib_weaponset *weaponset), void *context);
   490 
   490 
   491 /**
   491 /**
   492  * This callback is called if the server informs us that we have admin rights.
   492  * This callback is called if the server informs us that we have admin rights.
   493  */
   493  */
   494 void flib_netconn_onAdminAccess(flib_netconn *conn, void (*callback)(void *context), void *context);
   494 void flib_netconn_onAdminAccess(flib_netconn *conn, void (*callback)(void *context), void *context);