1 /*
2  * file server.h - communication interface for the server
3  *
4  * $Id: server.h,v 1.33 2006/02/10 15:07:35 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 XBLAST_SERVER_H
24 #define XBLAST_SERVER_H
25 
26 /*
27  * global enums
28  */
29 typedef enum
30 {
31 	XBSC_GameTime,				/* future actions received, client is async */
32 	XBSC_IOError,				/* i/o error on stream */
33 	XBSC_WriteError,			/* write error on dgram */
34 	XBSC_ConnFailed,			/* connection failed on dgram */
35 	XBSC_Timeout,				/* timeout on dgram */
36 	XBSC_COTInvalid,			/* invalid cot received */
37 	XBSC_IDInvalid,				/* invalid id received */
38 	XBSC_DataInvalid,			/* invalid data received */
39 	XBSC_MissingData,			/* client has not requested data */
40 	XBSC_UnexpectedEOF,			/* client shut down unexpectedly */
41 	XBSC_ExpectedEOF /* expected eof, possibly due to i/o or parse error */ ,
42 	XBSC_StreamWaiting,			/* all queued data sent on stream */
43 	XBSC_StreamBusy,			/* queued data on stream partially sent */
44 	XBSC_StreamClosed,			/* stream has been removed */
45 	XBSC_DgramClosed,			/* dgram has been removed */
46 } XBServerConstants;
47 /*
48  * global prototypes
49  */
50 
51 /* starting/closing server */
52 extern XBBool Server_StartListen (CFGGameHost *);
53 extern void Server_StopListen (void);
54 extern void Server_ReceiveListenClose (XBBool);
55 
56 /* connecting/disconnecting */
57 extern void Server_Accept (unsigned id, const char *host, unsigned port);
58 extern void Server_StreamDisconnect (unsigned id);
59 extern void Server_DgramDisconnect (unsigned id);
60 extern void Server_SendDisconnect (unsigned id);
61 extern void Server_SendDisconnectAll (void);
62 
63 /* error handling */
64 extern XBBool Server_StreamEvent (unsigned id, XBServerConstants code);
65 extern XBBool Server_DgramEvent (unsigned id, XBServerConstants code);
66 
67 /* receiving data */
68 extern XBBool Server_ReceiveGameConfig (unsigned id, const char *line);
69 extern XBBool Server_ReceivePlayerConfig (unsigned id, int player, const char *line);
70 extern void Server_ReceiveDisconnect (unsigned id);
71 extern void Server_ReceiveDgramPort (unsigned id, unsigned short port);
72 extern void Server_ReceiveHostStateReq (unsigned id, unsigned host, XBHostState state);
73 extern void Server_ReceiveTeamStateReq (unsigned id, unsigned host, unsigned player,
74 										XBTeamState state);
75 extern void Server_ReceiveChat (XBChat *);
76 extern void Server_ReceivePing (unsigned id, int ping);
77 extern void Server_ReceiveSync (unsigned id, XBNetworkEvent);
78 extern void Server_ReceiveLevelCheck (unsigned id, unsigned stat);
79 extern void Server_ReceivePlayerAction (unsigned id, int gameTime,
80 										const PlayerAction * playerAction);
81 extern void Server_ReceiveFinish (unsigned id);
82 extern void Server_ReceiveWinnerTeam (unsigned id, unsigned team);
83 
84 /* retrieving local data */
85 extern XBBool GetIsServer (void);
86 extern void SetIsServer (XBBool value);
87 extern int Server_GetPingTime (unsigned id);
88 extern XBHostState Server_GetHostState (unsigned id);
89 extern XBTeamState Server_GetTeamState (unsigned id, unsigned player);
90 extern XBHostState *Server_GetHostStateReq (unsigned id);
91 extern XBTeamState *Server_GetTeamStateReq (unsigned id, unsigned player);
92 extern XBBool Server_LevelApproved (void);
93 extern void Server_GetPlayerAction (unsigned id, int player, PlayerAction * action);
94 extern XBBool Server_LevelAsync (void);
95 
96 /* setting local data */
97 extern void Server_ClearLevelStatus (void);
98 extern void Server_SetLevelStatus (unsigned id, XBBool val);
99 extern void Server_ResetPlayerAction (void);
100 extern void Server_ClearPlayerAction (void);
101 extern void Server_ClearLevelWinners (void);
102 extern void Server_SetLevelWinners (unsigned id, unsigned team);
103 
104 /* queueing out data */
105 extern void Server_SendAllConfigs (unsigned id);
106 extern void Server_SendDgramPort (unsigned id);
107 extern void Server_QueryGameConfig (unsigned id);
108 extern void Server_SendGameConfig (unsigned id);
109 extern void Server_QueryPlayerConfigs (unsigned id, unsigned cnt);
110 extern void Server_SendPlayerConfig (unsigned id, unsigned player);
111 extern void Server_SendHostState (unsigned id, XBHostState state);
112 extern void Server_SendTeamState (unsigned id, unsigned player, XBTeamState team);
113 extern void Server_SendHostStateReq (unsigned id, unsigned host, XBHostState state);
114 extern void Server_SendTeamStateReq (unsigned id, unsigned host, unsigned player,
115 									 XBTeamState state);
116 extern void Server_SendDisconnectInfo (unsigned clientID);
117 
118 extern void Server_SendChat (XBChat * chat);
119 extern void Server_SysChat (const char *);
120 
121 extern void Server_SendStart (void);
122 extern void Server_SendRandomSeed (void);
123 extern void Server_SendLevel (const DBRoot * level);
124 extern void Server_SendLevelActivate (void);
125 extern void Server_SendLevelReset (void);
126 extern void Server_SendSync (XBNetworkEvent);
127 extern void Server_SendPlayerAction (int gameTime, const PlayerAction * action);
128 extern void Server_FinishPlayerAction (int gameTime);
129 extern XBBool Server_FlushPlayerAction (void);
130 extern void Server_SendLevelSync (void);
131 extern void Server_SendLevelAsync (void);
132 
133 /* connection to central */
134 extern void Server_StartCentralNewGame (const CFGGameHost * cfg, const CFGGameSetup * setup);
135 extern void Server_RestartNewGame (int num, const char *score);
136 extern void Server_CloseNewGame (void);
137 extern void Server_StopNewGame (void);
138 extern void Server_ReceiveNewGameClose (void);
139 
140 #endif
141 /*
142  * end of file server.h
143  */
144