1 /*
2 * XPilot NG, a multiplayer space war game.
3 *
4 * Copyright (C) 1991-2001 by
5 *
6 * Bj�rn Stabell <bjoern@xpilot.org>
7 * Ken Ronny Schouten <ken@xpilot.org>
8 * Bert Gijsbers <bert@xpilot.org>
9 * Dick Balaska <dick@xpilot.org>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */
25
26 #ifndef XPCOMMON_H
27 #define XPCOMMON_H
28
29 #ifdef HAVE_CONFIG_H
30 # include <config.h>
31 #endif
32
33 #ifdef _WINDOWS
34 # define HAVE_ASSERT_H 1
35 # define HAVE_CTYPE_H 1
36 # define HAVE_ERRNO_H 1
37 # define HAVE_MATH_H 1
38 # define HAVE_SIGNAL_H 1
39 # define HAVE_STDARG_H 1
40 # define HAVE_LIMITS_H 1
41 # define HAVE_SETJMP_H 1
42 # define HAVE_STDLIB_H 1
43 # define HAVE_STRING_H 1
44 # define HAVE_SYS_STAT_H 1
45 # define HAVE_SYS_TYPES_H 1
46 # define HAVE_STRCASECMP 1
47 # define HAVE_STRNCASECMP 1
48 # define HAVE_LIBZ 1
49 #endif
50
51 #include <stdio.h>
52 #ifdef HAVE_STDARG_H
53 # include <stdarg.h>
54 #else
55 # error "ANSI C stdarg.h is needed to compile."
56 #endif
57
58 #ifdef HAVE_SYS_TYPES_H
59 # include <sys/types.h>
60 #endif
61
62 #ifdef HAVE_SYS_STAT_H
63 # include <sys/stat.h>
64 #endif
65
66 #ifdef STDC_HEADERS
67 # include <stdlib.h>
68 # include <stddef.h>
69 #else
70 # ifdef HAVE_STDLIB_H
71 # include <stdlib.h>
72 # endif
73 #endif
74
75 #ifdef HAVE_STRING_H
76 # if ! defined STDC_HEADERS && defined HAVE_MEMORY_H
77 # include <memory.h>
78 # endif
79 # include <string.h>
80 #endif
81
82 #ifdef HAVE_STRINGS_H
83 # include <strings.h>
84 #endif
85
86 #ifdef HAVE_INTTYPES_H
87 # include <inttypes.h>
88 #else
89 # ifdef HAVE_STDINT_H
90 # include <stdint.h>
91 # endif
92 #endif
93
94 #ifdef HAVE_UNISTD_H
95 # include <unistd.h>
96 #endif
97
98 #ifdef HAVE_ASSERT_H
99 # include <assert.h>
100 #endif
101
102 #ifdef HAVE_CTYPE_H
103 # include <ctype.h>
104 #endif
105
106 #ifdef HAVE_ERRNO_H
107 # include <errno.h>
108 #endif
109
110 #ifdef HAVE_MATH_H
111 # include <math.h>
112 #endif
113
114 #ifdef HAVE_SIGNAL_H
115 # include <signal.h>
116 #endif
117
118 #ifdef TIME_WITH_SYS_TIME
119 # include <sys/time.h>
120 # include <time.h>
121 #else
122 # ifdef HAVE_SYS_TIME_H
123 # include <sys/time.h>
124 # else
125 # include <time.h>
126 # endif
127 #endif
128
129 #ifdef HAVE_FCNTL_H
130 # include <fcntl.h>
131 #endif
132
133 #ifdef HAVE_FLOAT_H
134 # include <float.h>
135 #endif
136
137 #ifdef HAVE_LIMITS_H
138 # include <limits.h>
139 #endif
140
141 #ifdef HAVE_PWD_H
142 # include <pwd.h>
143 #endif
144
145 #ifdef HAVE_SETJMP_H
146 # include <setjmp.h>
147 #endif
148
149 #ifdef HAVE_SYS_FILE_H
150 # include <sys/file.h>
151 #endif
152
153 #ifdef HAVE_SYS_IOCTL_H
154 # include <sys/ioctl.h>
155 #endif
156
157 #ifdef HAVE_SYS_PARAM_H
158 # include <sys/param.h>
159 #endif
160
161 #ifdef HAVE_SYS_SELECT_H
162 # include <sys/select.h>
163 #endif
164
165 #ifdef HAVE_SYS_SOCKET_H
166 # include <sys/socket.h>
167 #endif
168
169 #ifdef HAVE_SYS_INTTYPES_H
170 # include <sys/inttypes.h>
171 #endif
172
173 #ifdef HAVE_NETINET_IN_H
174 # include <netinet/in.h>
175 #endif
176
177 #ifdef HAVE_ARPA_INET_H
178 # include <arpa/inet.h>
179 #endif
180
181 #ifdef HAVE_NET_IF_H
182 # include <net/if.h>
183 #endif
184
185 #ifdef HAVE_NETINET_TCP_H
186 # include <netinet/tcp.h>
187 #endif
188
189 #ifdef HAVE_NETDB_H
190 # include <netdb.h>
191 #endif
192
193 /* Platform specific hacks. */
194
195 /* SGI hack. */
196 #ifdef HAVE_BSTRING_H
197 # include <bstring.h>
198 #endif
199
200 /* System V R4 hacks. */
201 #ifdef HAVE_SYS_FILIO_H
202 # include <sys/filio.h>
203 #endif
204
205 #ifdef HAVE_SYS_SOCKIO_H
206 # include <sys/sockio.h>
207 #endif
208
209 /* Sequent hack. */
210 #ifdef HAVE_SYS_FCNTL_H
211 # include <sys/fcntl.h>
212 #endif
213
214 /* Sun hacks. */
215 #ifdef HAVE_ARPA_NAMESER_H
216 # include <arpa/nameser.h>
217 #endif
218
219 #ifdef HAVE_RESOLV_H
220 # include <resolv.h>
221 #endif
222
223 #ifdef HAVE_VALUES_H
224 # include <values.h>
225 #endif
226
227 /* Evil Windows hacks. Yuck. */
228 #ifdef _WINDOWS
229 # include "NT/winNet.h"
230 /* need this for printf wrappers. */
231 # ifdef _XPILOTNTSERVER_
232 # include "../server/NT/winServer.h"
233 # include "../server/NT/winSvrThread.h"
234 extern char *showtime(void);
235 /*# elif !defined(_XPMONNT_)
236 # include "NT/winX.h"
237 # include "../client/NT/winClient.h"*/
238 # endif
239 static void Win_show_error(char *errmsg);
240 # include <io.h>
241 # include <process.h>
242 # include "NT/winNet.h"
243 /* Windows needs specific hacks for sockets: */
244 # undef close
245 # define close(x__) closesocket(x__)
246 # undef ioctl
247 # define ioctl(x__, y__, z__) ioctlsocket(x__, y__, z__)
248 # undef read
249 # define read(x__, y__, z__) recv(x__, y__, z__,0)
250 # undef write
251 # define write(x__, y__, z__) send(x__, y__, z__,0)
252 /* Windows some more hacks: */
253 # define getpid() _getpid()
254 #ifdef _MSC_VER
255 typedef int socklen_t;
256 #define inline __inline
257 #endif
258 #endif
259
260 /* Common XPilot header files. */
261
262 #include "version.h"
263 #include "xpconfig.h"
264 #include "arraylist.h"
265 #include "astershape.h"
266 #include "bit.h"
267 #include "checknames.h"
268 #include "click.h"
269 #include "commonproto.h"
270 #include "const.h"
271 #include "error.h"
272 #include "item.h"
273 #include "list.h"
274 #include "metaserver.h"
275 #include "net.h"
276 #include "pack.h"
277 #include "packet.h"
278 #include "portability.h"
279 #include "rules.h"
280 #include "setup.h"
281 #include "shipshape.h"
282 #include "socklib.h"
283 #include "types.h"
284 #include "wreckshape.h"
285 #include "xpmap.h"
286
287 #ifdef SOUND
288 # include "audio.h"
289 #endif
290
timeval_to_seconds(struct timeval * tvp)291 static inline double timeval_to_seconds(struct timeval *tvp)
292 {
293 return (double)tvp->tv_sec + tvp->tv_usec * 1e-6;
294 }
295
seconds_to_timeval(double t)296 static inline struct timeval seconds_to_timeval(double t)
297 {
298 struct timeval tv;
299
300 tv.tv_sec = (unsigned)t;
301 tv.tv_usec = (unsigned)(((t - (double)tv.tv_sec) * 1e6) + 0.5);
302
303 return tv;
304 }
305
306 /* returns 'tv2 - tv1' */
timeval_sub(struct timeval * tv2,struct timeval * tv1)307 static inline int timeval_sub(struct timeval *tv2,
308 struct timeval *tv1)
309 {
310 int s, us;
311
312 s = tv2->tv_sec - tv1->tv_sec;
313 us = tv2->tv_usec - tv1->tv_usec;
314
315 return 1000000 * s + us;
316 }
317
318 #endif /* XPCOMMON_H */
319