xref: /openbsd/games/hunt/huntd/server.h (revision ac1fa6a8)
1 /*	$OpenBSD: server.h,v 1.12 2017/01/21 08:22:57 krw Exp $	*/
2 /*	$NetBSD: hunt.h,v 1.5 1998/09/13 15:27:28 hubertf Exp $	*/
3 /*
4  * Copyright (c) 1983-2003, Regents of the University of California.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are
9  * met:
10  *
11  * + Redistributions of source code must retain the above copyright
12  *   notice, this list of conditions and the following disclaimer.
13  * + Redistributions in binary form must reproduce the above copyright
14  *   notice, this list of conditions and the following disclaimer in the
15  *   documentation and/or other materials provided with the distribution.
16  * + Neither the name of the University of California, San Francisco nor
17  *   the names of its contributors may be used to endorse or promote
18  *   products derived from this software without specific prior written
19  *   permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
24  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #include <sys/socket.h>
35 
36 #include <stdio.h>
37 
38 #ifndef __GNUC__
39 #define __attribute__(x)
40 #endif
41 
42 /*
43  * Choose MAXPL and MAXMON carefully.  The screen is assumed to be
44  * 23 lines high and will only tolerate (MAXPL == 17 && MAXMON == 0)
45  * or (MAXPL + MAXMON <= 16).
46  */
47 #define MAXPL		14
48 #define MAXMON		2
49 #if (MAXPL + MAXMON > 16)
50 #warning "MAXPL + MAXMON is excessive"
51 #endif
52 
53 #define MSGLEN		SCREEN_WIDTH
54 
55 #define UBOUND		1
56 #define DBOUND		(HEIGHT - 1)
57 #define LBOUND		1
58 #define RBOUND		(WIDTH - 1)
59 
60 #define NASCII		128
61 
62 /* Layout of the scoreboard: */
63 #define STAT_LABEL_COL	60
64 #define STAT_VALUE_COL	74
65 #define STAT_NAME_COL	61
66 #define STAT_SCAN_COL	(STAT_NAME_COL + 5)
67 #define STAT_AMMO_ROW	0
68 #define STAT_GUN_ROW	1
69 #define STAT_DAM_ROW	2
70 #define STAT_KILL_ROW	3
71 #define STAT_PLAY_ROW	5
72 #define STAT_MON_ROW	(STAT_PLAY_ROW + MAXPL + 1)
73 #define STAT_NAME_LEN	18
74 
75 /* Number of boots: */
76 #define NBOOTS		2
77 
78 /* Bitmask of directions */
79 #define NORTH		01
80 #define SOUTH		02
81 #define EAST		010
82 #define WEST		020
83 
84 # undef CTRL
85 #define CTRL(x)	((x) & 037)
86 
87 #define BULREQ		1		/* 0 */
88 #define GRENREQ		9		/* 1 */
89 #define SATREQ		25		/* 2 */
90 #define BOMB7REQ	49		/* 3 */
91 #define BOMB9REQ	81		/* 4 */
92 #define BOMB11REQ	121		/* 5 */
93 #define BOMB13REQ	169		/* 6 */
94 #define BOMB15REQ	225		/* 7 */
95 #define BOMB17REQ	289		/* 8 */
96 #define BOMB19REQ	361		/* 9 */
97 #define BOMB21REQ	441		/* 10 */
98 #define MAXBOMB				   11
99 
100 #define SLIMEREQ	5		/* 0 */
101 #define SSLIMEREQ	10		/* 1 */
102 #define SLIME2REQ	15		/* 2 */
103 #define SLIME3REQ	20		/* 3 */
104 #define MAXSLIME			   4
105 
106 #define EXPLEN		16
107 
108 #define _scan_char(pp)	(((pp)->p_scan < 0) ? ' ' : '*')
109 #define _cloak_char(pp)	(((pp)->p_cloak < 0) ? _scan_char(pp) : '+')
110 #define stat_char(pp)	(((pp)->p_flying < 0) ? _cloak_char(pp) : FLYER)
111 
112 typedef struct bullet_def	BULLET;
113 typedef struct expl_def		EXPL;
114 typedef struct player_def	PLAYER;
115 typedef struct ident_def	IDENT;
116 typedef struct regen_def	REGEN;
117 
118 #define	ALL_PLAYERS		((PLAYER *)1)
119 
120 struct ident_def {
121 	char	i_name[NAMELEN];
122 	char	i_team;
123 	long	i_machine;
124 	long	i_uid;
125 	float	i_kills;
126 	int	i_entries;
127 	float	i_score;
128 	int	i_absorbed;
129 	int	i_faced;
130 	int	i_shot;
131 	int	i_robbed;
132 	int	i_slime;
133 	int	i_missed;
134 	int	i_ducked;
135 	int	i_gkills, i_bkills, i_deaths, i_stillb, i_saved;
136 	IDENT	*i_next;
137 };
138 
139 struct player_def {
140 	IDENT	*p_ident;
141 	char	p_over;
142 	int	p_face;
143 	int	p_undershot;
144 	int	p_flying;
145 	int	p_flyx, p_flyy;
146 	int	p_nboots;
147 	FILE	*p_output;
148 	int	p_fd;
149 	int	p_mask;
150 	int	p_damage;
151 	int	p_damcap;
152 	int	p_ammo;
153 	int	p_ncshot;
154 	int	p_scan;
155 	int	p_cloak;
156 	int	p_x, p_y;
157 	int	p_ncount;
158 	int	p_nexec;
159 	long	p_nchar;
160 	char	p_death[MSGLEN];
161 	char	p_maze[HEIGHT][WIDTH2];
162 	int	p_curx, p_cury;
163 	int	p_lastx, p_lasty;
164 	char	p_cbuf[BUFSIZ];
165 };
166 
167 struct bullet_def {
168 	int	b_x, b_y;
169 	int	b_face;
170 	int	b_charge;
171 	char	b_type;
172 	char	b_size;
173 	char	b_over;
174 	PLAYER	*b_owner;
175 	IDENT	*b_score;
176 	FLAG	b_expl;
177 	BULLET	*b_next;
178 };
179 
180 struct expl_def {
181 	int	e_x, e_y;
182 	char	e_char;
183 	EXPL	*e_next;
184 };
185 
186 struct regen_def {
187 	int	r_x, r_y;
188 	REGEN	*r_next;
189 };
190 
191 struct spawn {
192 	int		fd;
193 	int		reading_msg;
194 	struct sockaddr source;
195 	socklen_t	sourcelen;
196 	u_int32_t	uid;
197 	char		name[NAMELEN+1];
198 	u_int8_t	team;
199 	u_int32_t	enter_status;
200 	char		ttyname[NAMELEN];
201 	u_int32_t	mode;
202 	char		msg[BUFSIZ];
203 	int		msglen;
204 	struct spawn *	next;
205 	struct spawn **	prevnext;
206 	int		inlen;
207 	char		inbuf[ sizeof (u_int32_t) + NAMELEN +
208 			       sizeof (u_int8_t) + sizeof (u_int32_t) +
209 			       NAMELEN + sizeof (u_int32_t) ];
210 };
211 
212 extern struct spawn *	Spawn;
213 
214 extern int	Socket;
215 
216 /* answer.c */
217 void	answer_first(void);
218 int	answer_next(struct spawn *);
219 int	rand_dir(void);
220 void	answer_info(FILE *);
221 
222 /* draw.c */
223 void	drawmaze(PLAYER *);
224 void	look(PLAYER *);
225 void	check(PLAYER *, int, int);
226 void	showstat(PLAYER *);
227 void	drawplayer(PLAYER *, FLAG);
228 void	message(PLAYER *, char *);
229 
230 /* driver.c */
231 int	rand_num(int);
232 void	checkdam(PLAYER *, PLAYER *, IDENT *, int, char);
233 __dead void	cleanup(int);
234 
235 /* execute.c */
236 void	mon_execute(PLAYER *);
237 void	execute(PLAYER *);
238 void	add_shot(int, int, int, char, int, PLAYER *, int, char);
239 BULLET *create_shot(int, int, int, char, int, int, PLAYER *, IDENT *,
240 	    int, char);
241 void	ammo_update(PLAYER *);
242 
243 /* expl.c */
244 void	showexpl(int, int, char);
245 void	rollexpl(void);
246 void	makemaze(void);
247 void	clearwalls(void);
248 int	can_rollexpl(void);
249 
250 /* makemaze.c */
251 void	makemaze(void);
252 
253 /* shots.c */
254 int	can_moveshots(void);
255 void	moveshots(void);
256 PLAYER *play_at(int, int);
257 int	opposite(int, char);
258 BULLET *is_bullet(int, int);
259 void	fixshots(int, int, char);
260 
261 /* terminal.c */
262 void	cgoto(PLAYER *, int, int);
263 void	outch(PLAYER *, char);
264 void	outstr(PLAYER *, char *, int);
265 void	outyx(PLAYER *, int, int, const char *, ...)
266 			__attribute__((format (printf, 4, 5)));
267 void	clrscr(PLAYER *);
268 void	ce(PLAYER *);
269 void	sendcom(PLAYER *, int, ...);
270 void	flush(PLAYER *);
271 void	logit(int, const char *, ...)
272 			__attribute__((format (printf, 2, 3)));
273 void	logx(int, const char *, ...)
274 			__attribute__((format (printf, 2, 3)));
275 
276 /* extern.c */
277 extern FLAG	Am_monitor;
278 extern char	Buf[BUFSIZ];
279 extern char	Maze[HEIGHT][WIDTH2];
280 extern char	Orig_maze[HEIGHT][WIDTH2];
281 extern fd_set	Fds_mask;
282 extern fd_set	Have_inp;
283 extern int	Nplayer;
284 extern int	Num_fds;
285 extern int	Socket;
286 extern int	Status;
287 extern int	See_over[NASCII];
288 extern BULLET *	Bullets;
289 extern EXPL *	Expl[EXPLEN];
290 extern EXPL *	Last_expl;
291 extern PLAYER	Player[MAXPL];
292 extern PLAYER *	End_player;
293 extern PLAYER	Boot[NBOOTS];
294 extern IDENT *	Scores;
295 extern PLAYER	Monitor[MAXMON];
296 extern PLAYER *	End_monitor;
297 extern int	volcano;
298 extern int	shot_req[MAXBOMB];
299 extern int	shot_type[MAXBOMB];
300 extern int	slime_req[MAXSLIME];
301