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
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
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
00343
00344
00345
00351 struct MsgDescr_t {
00352
00353
00354
00355
00356
00357
00358
00359
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