1 /*
2  * net_tele.h - telegrams for cleint/server communication
3  *
4  * $Id: net_tele.h,v 1.12 2006/02/09 21:21:24 fzago Exp $
5  *
6  * Program XBLAST
7  * (C) by Oliver Vogel (e-mail: m.vogel@ndh.net)
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published
11  * by the Free Software Foundation; either version 2; or (at your option)
12  * any later version
13  *
14  * This program is distributed in the hope that it will be entertaining,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILTY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
17  * Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with this program; if not, write to the Free Software Foundation, Inc.
21  * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  */
23 #ifndef _NET_TELE_H
24 #define _NET_TELE_H
25 
26 /*
27  * type declarations
28  */
29 typedef struct _xb_telegram XBTelegram;
30 typedef struct _xb_snd_queue XBSndQueue;
31 typedef struct _xb_rcv_queue XBRcvQueue;
32 
33 /*
34  * type definitions
35  */
36 
37 /* cause of transmission */
38 typedef enum
39 {
40 	XBT_COT_Activate,			/* server demands activation */
41 	XBT_COT_Spontaneous,		/* client message */
42 	XBT_COT_SendData,			/* send data to client */
43 	XBT_COT_RequestData,		/* request data from client */
44 	XBT_COT_DataNotAvailable,	/* client does not have data */
45 	XBT_COT_DataAvailable,		/* client has data */
46 	/* --- */
47 	NUM_XBT_COT
48 } XBTeleCOT;
49 
50 /* telegram object id */
51 typedef enum
52 {
53 	XBT_ID_GameConfig,			/* game data */
54 	XBT_ID_PlayerConfig,		/* player data */
55 	XBT_ID_RequestDisconnect,	/* host wants disconnect */
56 	XBT_ID_HostDisconnected,	/* message host has disconnected */
57 	XBT_ID_StartGame,			/* server starts the game */
58 	XBT_ID_RandomSeed,			/* seed for random numer generator */
59 	XBT_ID_LevelConfig,			/* level data */
60 	XBT_ID_DgramPort,			/* port for datagram connection */
61 	XBT_ID_Sync,				/* synchronisation between client and server */
62 	XBT_ID_HostIsIn,			/* host is in game */
63 	XBT_ID_HostIsOut,			/* host is out of game */
64 	XBT_ID_TeamChange,			/* Team Change */
65 	XBT_ID_GameStat,			/* Host sends game statistics */
66 	XBT_ID_PID,					/* Central sends PID */
67 	XBT_ID_WinnerTeam,			/* Client sends winner team for level */
68 	XBT_ID_Async,				/* client and server asynced */
69 	XBT_ID_Chat,				/* Server/Client sends chat line */
70 	XBT_ID_HostChange,			/* host state change by server */
71 	XBT_ID_HostChangeReq,		/* host change request */
72 	XBT_ID_TeamChangeReq,		/* team change request */
73 	/* --- */
74 	NUM_XBT_ID
75 } XBTeleID;
76 
77 /* result of i/o operations */
78 typedef enum
79 {
80 	XBT_R_IOError,				/* an error has occured during i/o operation */
81 	XBT_R_TeleError,			/* an error has occured during parsing */
82 	XBT_R_Continue,				/* telegram has been partially send/received */
83 	XBT_R_Complete,				/* telegram has been completely send/received */
84 	XBT_R_EndOfFile				/* stream was closed */
85 } XBTeleResult;
86 
87 /* information object adress */
88 typedef unsigned char XBTeleIOB;
89 
90 /*
91  * global prototypes
92  */
93 extern XBTelegram *Net_CreateTelegram (XBTeleCOT cot, XBTeleID id, XBTeleIOB iob, const void *data,
94 									   size_t len);
95 extern void Net_DeleteTelegram (XBTelegram * tele);
96 
97 extern XBSndQueue *Net_CreateSndQueue (XBBool server);
98 extern void Net_DeleteSndQueue (XBSndQueue * list);
99 extern XBTeleResult Net_Send (XBSndQueue * list, const XBSocket * pSocket);
100 extern void Net_SendTelegram (XBSndQueue * list, XBTelegram * tele);
101 
102 extern XBRcvQueue *Net_CreateRcvQueue (XBBool server);
103 extern void Net_DeleteRcvQueue (XBRcvQueue * list);
104 extern XBTeleResult Net_Receive (XBRcvQueue * list, const XBSocket * pSocket);
105 extern XBTelegram *Net_ReceiveTelegram (XBRcvQueue * list);
106 
107 extern XBTeleCOT Net_TeleCOT (const XBTelegram *);
108 extern XBTeleID Net_TeleID (const XBTelegram *);
109 extern XBTeleIOB Net_TeleIOB (const XBTelegram *);
110 extern const void *Net_TeleData (const XBTelegram *, size_t * len);
111 
112 #endif
113 /*
114  * end of file net_tele.h
115  */
116