project_files/frontlib/net/netconn.h
changeset 7691 55c0a856ecd0
parent 7689 855eeee4166f
child 8260 83d85e32c713
equal deleted inserted replaced
7689:855eeee4166f 7691:55c0a856ecd0
   186 	 */
   186 	 */
   187 	int flib_netconn_send_request_roomlist(flib_netconn *conn);
   187 	int flib_netconn_send_request_roomlist(flib_netconn *conn);
   188 
   188 
   189 	/**
   189 	/**
   190 	 * Join a room as guest (not chief). Only makes sense when in lobby state. If the action
   190 	 * Join a room as guest (not chief). Only makes sense when in lobby state. If the action
   191 	 * succeeds, you will receive an onEnterRoom callback with chief=false.
   191 	 * succeeds, you will receive an onEnterRoom callback with chief=false followed by other
       
   192 	 * callbacks with current room information.
   192 	 */
   193 	 */
   193 	int flib_netconn_send_joinRoom(flib_netconn *conn, const char *room);
   194 	int flib_netconn_send_joinRoom(flib_netconn *conn, const char *room);
   194 
   195 
   195 	/**
   196 	/**
   196 	 * Follow a player. Only valid in the lobby. If the player is in a room (or in a game), this
   197 	 * Follow a player. Only valid in the lobby. If the player is in a room (or in a game), this
   234 
   235 
   235 // Send functions that only make sense in a room
   236 // Send functions that only make sense in a room
   236 
   237 
   237 	/**
   238 	/**
   238 	 * Leave the room for the lobby. Only makes sense in room state. msg can be NULL if you don't
   239 	 * Leave the room for the lobby. Only makes sense in room state. msg can be NULL if you don't
   239 	 * want to send a message. The server always accepts a part message, so once you send it off,
   240 	 * want to send a message. The server always accepts a part command, so once you send it off,
   240 	 * you can just assume that you are back in the lobby.
   241 	 * you can just assume that you are back in the lobby.
   241 	 */
   242 	 */
   242 	int flib_netconn_send_leaveRoom(flib_netconn *conn, const char *msg);
   243 	int flib_netconn_send_leaveRoom(flib_netconn *conn, const char *msg);
   243 
   244 
   244 	/**
   245 	/**
   245 	 * Change your "ready" status in the room. Only makes sense when in room state. If the action
   246 	 * Change your "ready" status in the room. Only makes sense when in room state. If the action
   246 	 * succeeds, you will receive an onReadyState callback containing the change.
   247 	 * succeeds, you will receive an onClientFlags callback containing the change.
   247 	 */
   248 	 */
   248 	int flib_netconn_send_toggleReady(flib_netconn *conn);
   249 	int flib_netconn_send_toggleReady(flib_netconn *conn);
   249 
   250 
   250 	/**
   251 	/**
   251 	 * Add a team to the current room. Apart from the "fixed" team information, this also includes
   252 	 * Add a team to the current room. Apart from the "fixed" team information, this also includes
   477 	 * NOTE: partMessage may be NULL.
   478 	 * NOTE: partMessage may be NULL.
   478 	 */
   479 	 */
   479 	void flib_netconn_onLobbyJoin(flib_netconn *conn, void (*callback)(void *context, const char *nick), void* context);
   480 	void flib_netconn_onLobbyJoin(flib_netconn *conn, void (*callback)(void *context, const char *nick), void* context);
   480 	void flib_netconn_onLobbyLeave(flib_netconn *conn, void (*callback)(void *context, const char *nick, const char *partMessage), void* context);
   481 	void flib_netconn_onLobbyLeave(flib_netconn *conn, void (*callback)(void *context, const char *nick, const char *partMessage), void* context);
   481 
   482 
       
   483 	/**
       
   484 	 * This is called when the server informs us that one or more flags associated with a
       
   485 	 * player/client have changed.
       
   486 	 *
       
   487 	 * nick is the name of the player, flags is a string containing one character for each modified
       
   488 	 * flag (see below), and newFlagState signals whether the flags should be set to true or false.
       
   489 	 *
       
   490 	 * Some of these flags are important for protocol purposes (especially if they are set for you)
       
   491 	 * while others are just informational. Also, some flags are only relevant for players who are
       
   492 	 * in the same room as you, and the server will not inform you if they change for others.
       
   493 	 *
       
   494 	 * These are the currently known/used flags:
       
   495 	 * a: Server admin. Always updated.
       
   496 	 * h: Room chief. Updated when in the same room.
       
   497 	 * r: Ready to play. Updated when in the same room.
       
   498 	 * u: Registered user. Always updated.
       
   499 	 *
       
   500 	 * The server tells us the 'a' and 'u' flags for all players when we first join the lobby, and
       
   501 	 * also tells us the 'r' and 'h' flags when we join or create a room. It assumes that all flags
       
   502 	 * are initially false, so it will typically only tell you to set certain flags to true when
       
   503 	 * transmitting the initial states. Reset the 'h' and 'r' flags to false when leaving a room,
       
   504 	 * or when entering room state, to arrive at the right state for each player.
       
   505 	 *
       
   506 	 * The room chief state of yourself is particularly important because it determines whether you
       
   507 	 * can modify settings of the current room. Generally, when you create a room you start out
       
   508 	 * being room chief, and when you join an existing room you are not. However, if the original
       
   509 	 * chief leaves a room, the server can choose a new chief, and if that happens the chief flag
       
   510 	 * will be transferred to someone else.
       
   511 	 */
       
   512 	void flib_netconn_onClientFlags(flib_netconn *conn, void (*callback)(void *context, const char *nick, const char *flags, bool newFlagState), void *context);
   482 
   513 
   483 // Callbacks that happen only in response to specific requests
   514 // Callbacks that happen only in response to specific requests
   484 
   515 
   485 	/**
   516 	/**
   486 	 * Response to flib_netconn_send_request_roomlist().
   517 	 * Response to flib_netconn_send_request_roomlist().
   518 
   549 
   519 
   550 
   520 // Callbacks that are only relevant in a room
   551 // Callbacks that are only relevant in a room
   521 
   552 
   522 	/**
   553 	/**
   523 	 * This callback informs about changes to your room chief status, i.e. whether you are allowed
       
   524 	 * to modify the current room. Generally when you create a room you start out being room chief,
       
   525 	 * and when you join an existing room you are not. However, if the original chief leaves a room,
       
   526 	 * the server can choose a new chief, and if that happens this callback is called with the new
       
   527 	 * status.
       
   528 	 *
       
   529 	 * Note: This callback does not automatically fire when joining a room. You can always query the
       
   530 	 * current chief status using flib_netconn_is_chief().
       
   531 	 */
       
   532 	void flib_netconn_onRoomChiefStatus(flib_netconn *conn, void (*callback)(void *context, bool chief), void* context);
       
   533 
       
   534 	/**
       
   535 	 * One of the players in the room (possibly you) changed their ready state.
       
   536 	 */
       
   537 	void flib_netconn_onReadyState(flib_netconn *conn, void (*callback)(void *context, const char *nick, bool ready), void* context);
       
   538 
       
   539 	/**
       
   540 	 * You just left a room and entered the lobby again.
   554 	 * You just left a room and entered the lobby again.
   541 	 * reason is one of the NETCONN_ROOMLEAVE_ constants (usually a kick).
   555 	 * reason is one of the NETCONN_ROOMLEAVE_ constants (usually a kick).
   542 	 * This will not be called when you actively leave a room using PART.
   556 	 * This will not be called when you actively leave a room using PART.
   543 	 * Don't confuse with onRoomLeave, which indicates that *someone else* left the room.
   557 	 * Don't confuse with onRoomLeave, which indicates that *someone else* left the room.
   544 	 */
   558 	 */
   635 	 * engine to keep up to date with the current happenings. Pass it on to the engine using
   649 	 * engine to keep up to date with the current happenings. Pass it on to the engine using
   636 	 * flib_gameconn_send_enginemsg.
   650 	 * flib_gameconn_send_enginemsg.
   637 	 */
   651 	 */
   638 	void flib_netconn_onEngineMessage(flib_netconn *conn, void (*callback)(void *context, const uint8_t *message, size_t size), void *context);
   652 	void flib_netconn_onEngineMessage(flib_netconn *conn, void (*callback)(void *context, const uint8_t *message, size_t size), void *context);
   639 
   653 
   640 
       
   641 // Callbacks only needed for admin stuffs
       
   642 
       
   643 	/**
       
   644 	 * This callback is called if the server informs us that we have admin rights.
       
   645 	 */
       
   646 	void flib_netconn_onAdminAccess(flib_netconn *conn, void (*callback)(void *context), void *context);
       
   647 
       
   648 #endif
   654 #endif