message.h

Go to the documentation of this file.
00001 
00025 #ifndef _message_h_
00026 #define _message_h_
00027 
00028 #include "client.h"
00029 
00124 typedef struct MsgDescr_t  MsgDescr;
00125 
00133 enum {
00137     MSG_TYPE_ACK,
00142     MSG_TYPE_CONN_REQ,
00146     MSG_TYPE_CONN_DENY,
00151     MSG_TYPE_CONN_ACCEPT,
00155     MSG_TYPE_CONN_DISCONN,
00159     MSG_TYPE_OPTION,
00163     MSG_TYPE_OBSTACLE,
00167     MSG_TYPE_SPAWN,
00171     MSG_TYPE_GOAL,
00175     MSG_TYPE_GAME_START,
00179     MSG_TYPE_GAME_OVER,
00183     MSG_TYPE_SCORE = MSG_TYPE_GOAL + 1,
00187     MSG_TYPE_PLAYER_UPDATE,
00191     MSG_TYPE_PLAYER_SPWAN,
00192     MSG_TYPE_MAX
00193 };
00194 
00199 #define MSG_MAX_SIZE  510
00200 
00206 struct NetBuffer_t {
00210     Uint8  data[MSG_MAX_SIZE];
00215     Sint16 length;
00216 };
00217 
00218 typedef struct NetBuffer_t  NetBuffer;
00219 
00229 typedef void (*ConstructMsg)(MsgDescr *descr);
00230 
00231 /*
00232  * The simplest message contructor -- writes the message ID to a pre-existing
00233  * pre-filled buffer. Useful for messages that are constructed in buffers
00234  * prior to being added to the message system because the message ID is not
00235  * known until the message is put into the system.
00236  * @deprecated
00237  * @pre  The buffer for the message exists and already has message data prior
00238  *       to calling AddMessage().
00239  * @post The message ID is written to the buffer starting a byte 1, and the
00240  *       MsgDescr::constrFunc is set to NULL.
00241  * @param descr  The message descriptor of the message to modify.
00242  * @author Jeff Jackowski
00243  */
00244 //void MsgSetId(MsgDescr *descr);
00245 
00256 typedef void (*AcknowledgeMsg)(MsgDescr *descr, int cid);
00257 
00265 typedef void (*FailMsg)(MsgDescr *descr, ClientData *client);
00266 
00277 void MsgFailDropConnection(MsgDescr *descr, ClientData *client);
00278 
00289 void MsgFailDisconnect(MsgDescr *descr, ClientData *client);
00290 
00299 typedef Bool (*ApproveSendMsg)(MsgDescr *descr, int cid);
00300 
00304 #define DESTMAPTYPE  Uint16
00305 
00309 #define DESTMAPLEN  bitarraylen(MAX_PLAYERS, DESTMAPTYPE)
00310 
00318 #define GetDestMapIndex(id)  bitindex(id, DESTMAPTYPE)
00319 
00327 #define GetDestMapFlag(id)  bitflag(id, DESTMAPTYPE)
00328 
00334 #define SetDestToAll(msg) \
00335 {                                                                \
00336     int loop;                                                    \
00337     DESTMAPTYPE *map = &((msg)->destMap[0]);                     \
00338     *map = ~0;                                                   \
00339     for (loop = DESTMAPLEN - 1; loop > 0; loop--) *(++map) = ~0; \
00340 }
00341 /*
00342     DESTMAPTYPE *map = &((msg)->destMap[0]);                  \
00343     for (loop = DESTMAPLEN; loop > 0; loop--) *(map++) = ~0;  \
00344 */
00345 
00351 struct MsgDescr_t {
00352     /*
00353      * The function called to construct the message.
00354      * @warning Either this function pointer must not be NULL, or buffer and
00355      *          length must already be set and the buffer must contain the
00356      *          message data. See BufferNew() for the required steps to enter
00357      *          a pre-made message (this pointer NULL) into the system.
00358      */
00359     //ConstructMsg constrFunc;
00364     AcknowledgeMsg ackFunc;
00369     FailMsg failFunc;
00374     ApproveSendMsg approveFunc;
00390     NetBuffer *buffer;
00396     void *data;
00410     DESTMAPTYPE destMap[DESTMAPLEN];
00417     Uint32 nextSend;
00423     Uint16 msgId;
00429     Uint16 interval;
00437     Sint8 triesLeft;
00438     union {
00443         Uint8 flags;
00444         struct {
00450             Bool inflight   : 1;
00455             Bool bcast      : 1;
00461             Bool mcast      : 1;
00468             Bool noResend   : 1;
00473             Bool buffLifeUnmanaged : 1;
00479             Bool doNotAddId : 1;
00480         };
00481     };
00482 };
00483 
00489 Bool MessageInit();
00490 
00495 void MessageUninit();
00496 
00508 MsgDescr *MessageNew();
00509 
00523 void MessageFree(MsgDescr *msg);
00524 
00542 NetBuffer *BufferNew();
00543 
00551 void BufferFree(NetBuffer *buff);
00552 
00565 void BufferVecDestr(void *buff);
00566 
00603 Bool AddMessage(MsgDescr *msg);
00604 
00611 void ServiceMessages();
00612 
00618 Bool ReceiveMessages();
00619 
00627 void CancelAllMessages();
00628 
00634 int  GetNumOutgoingMessages();
00635 
00654 typedef Bool (*HandleMsg)(SocketAddr *origin, NetBuffer *buffer,
00655     Uint8 *clientId, Uint16 messageId);
00656 
00666 Bool SendDisconnectMessage(Uint8 id);
00667 
00678 Bool ValidateClient(SocketAddr *origin, Uint8 clientId);
00679 
00688 Bool ValidateServer(SocketAddr *origin);
00689 
00696 void ProcessNetworkMessages();
00697 
00700 #endif

Generated on Mon May 28 04:41:39 2007 for Retro Tank Super Attack by  doxygen 1.5.2