Home | History | Annotate | Line # | Download | only in sail
sync.c revision 1.25.12.1
      1  1.25.12.1       jym /*	$NetBSD: sync.c,v 1.25.12.1 2009/05/13 19:18:06 jym Exp $	*/
      2        1.3       cgd 
      3        1.1       cgd /*
      4        1.3       cgd  * Copyright (c) 1983, 1993
      5        1.3       cgd  *	The Regents of the University of California.  All rights reserved.
      6        1.1       cgd  *
      7        1.1       cgd  * Redistribution and use in source and binary forms, with or without
      8        1.1       cgd  * modification, are permitted provided that the following conditions
      9        1.1       cgd  * are met:
     10        1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     11        1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     12        1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     13        1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     14        1.1       cgd  *    documentation and/or other materials provided with the distribution.
     15       1.21       agc  * 3. Neither the name of the University nor the names of its contributors
     16        1.1       cgd  *    may be used to endorse or promote products derived from this software
     17        1.1       cgd  *    without specific prior written permission.
     18        1.1       cgd  *
     19        1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     20        1.1       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21        1.1       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22        1.1       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     23        1.1       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24        1.1       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25        1.1       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26        1.1       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27        1.1       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28        1.1       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29        1.1       cgd  * SUCH DAMAGE.
     30        1.1       cgd  */
     31        1.1       cgd 
     32        1.6  christos #include <sys/cdefs.h>
     33        1.1       cgd #ifndef lint
     34        1.3       cgd #if 0
     35        1.5       tls static char sccsid[] = "@(#)sync.c	8.2 (Berkeley) 4/28/95";
     36        1.3       cgd #else
     37  1.25.12.1       jym __RCSID("$NetBSD: sync.c,v 1.25.12.1 2009/05/13 19:18:06 jym Exp $");
     38        1.3       cgd #endif
     39        1.1       cgd #endif /* not lint */
     40        1.1       cgd 
     41       1.22       jsm #include <sys/stat.h>
     42       1.22       jsm 
     43        1.6  christos #include <fcntl.h>
     44        1.5       tls #include <errno.h>
     45  1.25.12.1       jym #include <limits.h>
     46       1.18     jwise #include <signal.h>
     47        1.6  christos #include <stdarg.h>
     48       1.17     jwise #include <stdio.h>
     49        1.6  christos #include <stdlib.h>
     50       1.18     jwise #include <string.h>
     51       1.17     jwise #include <time.h>
     52        1.6  christos #include <unistd.h>
     53        1.5       tls #include "extern.h"
     54       1.14       jsm #include "pathnames.h"
     55        1.1       cgd 
     56        1.1       cgd #define BUFSIZE 4096
     57        1.1       cgd 
     58  1.25.12.1       jym /* Message types */
     59  1.25.12.1       jym #define W_CAPTAIN	1
     60  1.25.12.1       jym #define W_CAPTURED	2
     61  1.25.12.1       jym #define W_CLASS		3
     62  1.25.12.1       jym #define W_CREW		4
     63  1.25.12.1       jym #define W_DBP		5
     64  1.25.12.1       jym #define W_DRIFT		6
     65  1.25.12.1       jym #define W_EXPLODE	7
     66  1.25.12.1       jym /*      W_FILE		8   not used */
     67  1.25.12.1       jym #define W_FOUL		9
     68  1.25.12.1       jym #define W_GUNL		10
     69  1.25.12.1       jym #define W_GUNR		11
     70  1.25.12.1       jym #define W_HULL		12
     71  1.25.12.1       jym #define W_MOVE		13
     72  1.25.12.1       jym #define W_OBP		14
     73  1.25.12.1       jym #define W_PCREW		15
     74  1.25.12.1       jym #define W_UNFOUL	16
     75  1.25.12.1       jym #define W_POINTS	17
     76  1.25.12.1       jym #define W_QUAL		18
     77  1.25.12.1       jym #define W_UNGRAP	19
     78  1.25.12.1       jym #define W_RIGG		20
     79  1.25.12.1       jym #define W_COL		21
     80  1.25.12.1       jym #define W_DIR		22
     81  1.25.12.1       jym #define W_ROW		23
     82  1.25.12.1       jym #define W_SIGNAL	24
     83  1.25.12.1       jym #define W_SINK		25
     84  1.25.12.1       jym #define W_STRUCK	26
     85  1.25.12.1       jym #define W_TA		27
     86  1.25.12.1       jym #define W_ALIVE		28
     87  1.25.12.1       jym #define W_TURN		29
     88  1.25.12.1       jym #define W_WIND		30
     89  1.25.12.1       jym #define W_FS		31
     90  1.25.12.1       jym #define W_GRAP		32
     91  1.25.12.1       jym #define W_RIG1		33
     92  1.25.12.1       jym #define W_RIG2		34
     93  1.25.12.1       jym #define W_RIG3		35
     94  1.25.12.1       jym #define W_RIG4		36
     95  1.25.12.1       jym #define W_BEGIN		37
     96  1.25.12.1       jym #define W_END		38
     97  1.25.12.1       jym #define W_DDEAD		39
     98  1.25.12.1       jym 
     99  1.25.12.1       jym 
    100  1.25.12.1       jym static void recv_captain(struct ship *ship, const char *astr);
    101  1.25.12.1       jym static void recv_captured(struct ship *ship, long a);
    102  1.25.12.1       jym static void recv_class(struct ship *ship, long a);
    103  1.25.12.1       jym static void recv_crew(struct ship *ship, long a, long b, long c);
    104  1.25.12.1       jym static void recv_dbp(struct ship *ship, long a, long b, long c, long d);
    105  1.25.12.1       jym static void recv_drift(struct ship *ship, long a);
    106  1.25.12.1       jym static void recv_explode(struct ship *ship, long a);
    107  1.25.12.1       jym static void recv_foul(struct ship *ship, long a);
    108  1.25.12.1       jym static void recv_gunl(struct ship *ship, long a, long b);
    109  1.25.12.1       jym static void recv_gunr(struct ship *ship, long a, long b);
    110  1.25.12.1       jym static void recv_hull(struct ship *ship, long a);
    111  1.25.12.1       jym static void recv_move(struct ship *ship, const char *astr);
    112  1.25.12.1       jym static void recv_obp(struct ship *ship, long a, long b, long c, long d);
    113  1.25.12.1       jym static void recv_pcrew(struct ship *ship, long a);
    114  1.25.12.1       jym static void recv_unfoul(struct ship *ship, long a, long b);
    115  1.25.12.1       jym static void recv_points(struct ship *ship, long a);
    116  1.25.12.1       jym static void recv_qual(struct ship *ship, long a);
    117  1.25.12.1       jym static void recv_ungrap(struct ship *ship, long a, long b);
    118  1.25.12.1       jym static void recv_rigg(struct ship *ship, long a, long b, long c, long d);
    119  1.25.12.1       jym static void recv_col(struct ship *ship, long a);
    120  1.25.12.1       jym static void recv_dir(struct ship *ship, long a);
    121  1.25.12.1       jym static void recv_row(struct ship *ship, long a);
    122  1.25.12.1       jym static void recv_signal(struct ship *ship, const char *astr);
    123  1.25.12.1       jym static void recv_sink(struct ship *ship, long a);
    124  1.25.12.1       jym static void recv_struck(struct ship *ship, long a);
    125  1.25.12.1       jym static void recv_ta(struct ship *ship, long a);
    126  1.25.12.1       jym static void recv_alive(void);
    127  1.25.12.1       jym static void recv_turn(long a);
    128  1.25.12.1       jym static void recv_wind(long a, long b);
    129  1.25.12.1       jym static void recv_fs(struct ship *ship, long a);
    130  1.25.12.1       jym static void recv_grap(struct ship *ship, long a);
    131  1.25.12.1       jym static void recv_rig1(struct ship *ship, long a);
    132  1.25.12.1       jym static void recv_rig2(struct ship *ship, long a);
    133  1.25.12.1       jym static void recv_rig3(struct ship *ship, long a);
    134  1.25.12.1       jym static void recv_rig4(struct ship *ship, long a);
    135  1.25.12.1       jym static void recv_begin(struct ship *ship);
    136  1.25.12.1       jym static void recv_end(struct ship *ship);
    137  1.25.12.1       jym static void recv_ddead(void);
    138  1.25.12.1       jym 
    139  1.25.12.1       jym static void Write(int, struct ship *, long, long, long, long);
    140  1.25.12.1       jym static void Writestr(int, struct ship *, const char *);
    141  1.25.12.1       jym 
    142  1.25.12.1       jym static int sync_update(int, struct ship *, const char *,
    143  1.25.12.1       jym 		       long, long, long, long);
    144       1.16     jwise 
    145        1.1       cgd static char sync_buf[BUFSIZE];
    146        1.1       cgd static char *sync_bp = sync_buf;
    147        1.1       cgd static long sync_seek;
    148        1.1       cgd static FILE *sync_fp;
    149        1.1       cgd 
    150  1.25.12.1       jym static const char *
    151  1.25.12.1       jym get_sync_file(int scenario_number)
    152  1.25.12.1       jym {
    153  1.25.12.1       jym 	static char sync_file[NAME_MAX];
    154  1.25.12.1       jym 
    155  1.25.12.1       jym 	snprintf(sync_file, sizeof(sync_file), _FILE_SYNC, scenario_number);
    156  1.25.12.1       jym 	return sync_file;
    157  1.25.12.1       jym }
    158  1.25.12.1       jym 
    159  1.25.12.1       jym static const char *
    160  1.25.12.1       jym get_lock_file(int scenario_number)
    161  1.25.12.1       jym {
    162  1.25.12.1       jym 	static char sync_lock[NAME_MAX];
    163  1.25.12.1       jym 
    164  1.25.12.1       jym 	snprintf(sync_lock, sizeof(sync_lock), _FILE_LOCK, scenario_number);
    165  1.25.12.1       jym 	return sync_lock;
    166  1.25.12.1       jym }
    167  1.25.12.1       jym 
    168        1.6  christos void
    169       1.15     jwise fmtship(char *buf, size_t len, const char *fmt, struct ship *ship)
    170        1.6  christos {
    171        1.6  christos 	while (*fmt) {
    172        1.6  christos 		if (len-- == 0) {
    173        1.6  christos 			*buf = '\0';
    174        1.6  christos 			return;
    175        1.6  christos 		}
    176        1.7  christos 		if (*fmt == '$' && fmt[1] == '$') {
    177        1.6  christos 			size_t l = snprintf(buf, len, "%s (%c%c)",
    178        1.6  christos 			    ship->shipname, colours(ship), sterncolour(ship));
    179        1.6  christos 			buf += l;
    180        1.6  christos 			len -= l - 1;
    181        1.6  christos 			fmt += 2;
    182        1.6  christos 		}
    183        1.6  christos 		else
    184        1.6  christos 			*buf++ = *fmt++;
    185        1.6  christos 	}
    186        1.6  christos 
    187        1.6  christos 	if (len > 0)
    188        1.6  christos 		*buf = '\0';
    189        1.6  christos }
    190        1.6  christos 
    191        1.6  christos 
    192        1.1       cgd /*VARARGS3*/
    193        1.6  christos void
    194        1.6  christos makesignal(struct ship *from, const char *fmt, struct ship *ship, ...)
    195        1.6  christos {
    196        1.6  christos 	char message[BUFSIZ];
    197        1.6  christos 	char format[BUFSIZ];
    198        1.6  christos 	va_list ap;
    199       1.15     jwise 
    200        1.6  christos 	va_start(ap, ship);
    201        1.6  christos 	fmtship(format, sizeof(format), fmt, ship);
    202  1.25.12.1       jym 	vsnprintf(message, sizeof(message), format, ap);
    203        1.6  christos 	va_end(ap);
    204  1.25.12.1       jym 	send_signal(from, message);
    205        1.1       cgd }
    206        1.1       cgd 
    207       1.15     jwise /*VARARGS2*/
    208        1.7  christos void
    209        1.7  christos makemsg(struct ship *from, const char *fmt, ...)
    210        1.7  christos {
    211        1.7  christos 	char message[BUFSIZ];
    212        1.7  christos 	va_list ap;
    213       1.15     jwise 
    214        1.7  christos 	va_start(ap, fmt);
    215  1.25.12.1       jym 	vsnprintf(message, sizeof(message), fmt, ap);
    216        1.7  christos 	va_end(ap);
    217  1.25.12.1       jym 	send_signal(from, message);
    218        1.7  christos }
    219       1.11   hubertf 
    220        1.6  christos int
    221       1.25  dholland sync_exists(int gamenum)
    222        1.1       cgd {
    223  1.25.12.1       jym 	const char *path;
    224        1.1       cgd 	struct stat s;
    225        1.1       cgd 	time_t t;
    226        1.1       cgd 
    227  1.25.12.1       jym 	path = get_sync_file(gamenum);
    228       1.15     jwise 	time(&t);
    229       1.14       jsm 	setegid(egid);
    230  1.25.12.1       jym 	if (stat(path, &s) < 0) {
    231       1.14       jsm 		setegid(gid);
    232        1.1       cgd 		return 0;
    233       1.14       jsm 	}
    234        1.1       cgd 	if (s.st_mtime < t - 60*60*2) {		/* 2 hours */
    235  1.25.12.1       jym 		unlink(path);
    236  1.25.12.1       jym 		path = get_lock_file(gamenum);
    237  1.25.12.1       jym 		unlink(path);
    238       1.14       jsm 		setegid(gid);
    239        1.1       cgd 		return 0;
    240       1.14       jsm 	} else {
    241       1.14       jsm 		setegid(gid);
    242        1.1       cgd 		return 1;
    243       1.14       jsm 	}
    244        1.1       cgd }
    245        1.1       cgd 
    246        1.6  christos int
    247       1.15     jwise sync_open(void)
    248        1.1       cgd {
    249  1.25.12.1       jym 	const char *sync_file;
    250  1.25.12.1       jym 	const char *sync_lock;
    251       1.14       jsm 	struct stat tmp;
    252  1.25.12.1       jym 
    253        1.1       cgd 	if (sync_fp != NULL)
    254       1.15     jwise 		fclose(sync_fp);
    255  1.25.12.1       jym 	sync_file = get_sync_file(game);
    256  1.25.12.1       jym 	sync_lock = get_lock_file(game);
    257       1.14       jsm 	setegid(egid);
    258       1.14       jsm 	if (stat(sync_file, &tmp) < 0) {
    259       1.14       jsm 		mode_t omask = umask(002);
    260        1.1       cgd 		sync_fp = fopen(sync_file, "w+");
    261       1.15     jwise 		umask(omask);
    262        1.1       cgd 	} else
    263        1.1       cgd 		sync_fp = fopen(sync_file, "r+");
    264       1.14       jsm 	setegid(gid);
    265        1.1       cgd 	if (sync_fp == NULL)
    266        1.1       cgd 		return -1;
    267        1.1       cgd 	sync_seek = 0;
    268        1.1       cgd 	return 0;
    269        1.1       cgd }
    270        1.1       cgd 
    271        1.6  christos void
    272       1.25  dholland sync_close(int doremove)
    273        1.1       cgd {
    274  1.25.12.1       jym 	const char *sync_file;
    275  1.25.12.1       jym 
    276        1.1       cgd 	if (sync_fp != 0)
    277       1.15     jwise 		fclose(sync_fp);
    278       1.25  dholland 	if (doremove) {
    279  1.25.12.1       jym 		sync_file = get_sync_file(game);
    280       1.14       jsm 		setegid(egid);
    281       1.15     jwise 		unlink(sync_file);
    282       1.14       jsm 		setegid(gid);
    283       1.14       jsm 	}
    284        1.1       cgd }
    285        1.1       cgd 
    286  1.25.12.1       jym static void
    287       1.15     jwise Write(int type, struct ship *ship, long a, long b, long c, long d)
    288        1.1       cgd {
    289  1.25.12.1       jym 	size_t max = sizeof(sync_buf) - (sync_bp - sync_buf);
    290  1.25.12.1       jym 	int shipindex = (ship == NULL) ? 0 : ship->file->index;
    291        1.6  christos 
    292  1.25.12.1       jym 	snprintf(sync_bp, max, "%d %d 0 %ld %ld %ld %ld\n",
    293  1.25.12.1       jym 		       type, shipindex, a, b, c, d);
    294       1.11   hubertf 	while (*sync_bp++)
    295       1.11   hubertf 		;
    296       1.11   hubertf 	sync_bp--;
    297       1.11   hubertf 	if (sync_bp >= &sync_buf[sizeof sync_buf])
    298       1.11   hubertf 		abort();
    299       1.15     jwise 	sync_update(type, ship, NULL, a, b, c, d);
    300       1.11   hubertf }
    301       1.11   hubertf 
    302  1.25.12.1       jym static void
    303       1.15     jwise Writestr(int type, struct ship *ship, const char *a)
    304       1.11   hubertf {
    305  1.25.12.1       jym 	size_t max = sizeof(sync_buf) - (sync_bp - sync_buf);
    306  1.25.12.1       jym 	int shipindex = (ship == NULL) ? 0 : ship->file->index;
    307  1.25.12.1       jym 
    308  1.25.12.1       jym 	snprintf(sync_bp, max, "%d %d 1 %s\n", type, shipindex, a);
    309        1.1       cgd 	while (*sync_bp++)
    310        1.1       cgd 		;
    311        1.1       cgd 	sync_bp--;
    312        1.1       cgd 	if (sync_bp >= &sync_buf[sizeof sync_buf])
    313        1.1       cgd 		abort();
    314       1.15     jwise 	sync_update(type, ship, a, 0, 0, 0, 0);
    315        1.1       cgd }
    316        1.1       cgd 
    317        1.6  christos int
    318       1.15     jwise Sync(void)
    319        1.1       cgd {
    320        1.1       cgd 	sig_t sighup, sigint;
    321        1.6  christos 	int n;
    322        1.4       cgd 	int type, shipnum, isstr;
    323       1.11   hubertf 	char *astr;
    324        1.4       cgd 	long a, b, c, d;
    325        1.1       cgd 	char buf[80];
    326        1.1       cgd 	char erred = 0;
    327  1.25.12.1       jym #ifndef LOCK_EX
    328  1.25.12.1       jym 	const char *sync_file;
    329  1.25.12.1       jym 	const char *sync_lock;
    330  1.25.12.1       jym #endif
    331        1.1       cgd 
    332        1.1       cgd 	sighup = signal(SIGHUP, SIG_IGN);
    333        1.1       cgd 	sigint = signal(SIGINT, SIG_IGN);
    334        1.1       cgd 	for (n = TIMEOUT; --n >= 0;) {
    335        1.1       cgd #ifdef LOCK_EX
    336        1.1       cgd 		if (flock(fileno(sync_fp), LOCK_EX|LOCK_NB) >= 0)
    337        1.1       cgd 			break;
    338        1.1       cgd 		if (errno != EWOULDBLOCK)
    339        1.1       cgd 			return -1;
    340        1.1       cgd #else
    341  1.25.12.1       jym 		sync_file = get_sync_file(game);
    342  1.25.12.1       jym 		sync_lock = get_lock_file(game);
    343       1.14       jsm 		setegid(egid);
    344       1.14       jsm 		if (link(sync_file, sync_lock) >= 0) {
    345       1.14       jsm 			setegid(gid);
    346        1.1       cgd 			break;
    347       1.14       jsm 		}
    348       1.14       jsm 		setegid(gid);
    349        1.1       cgd 		if (errno != EEXIST)
    350        1.1       cgd 			return -1;
    351        1.1       cgd #endif
    352        1.1       cgd 		sleep(1);
    353        1.1       cgd 	}
    354        1.1       cgd 	if (n <= 0)
    355        1.1       cgd 		return -1;
    356       1.15     jwise 	fseek(sync_fp, sync_seek, SEEK_SET);
    357        1.1       cgd 	for (;;) {
    358        1.1       cgd 		switch (fscanf(sync_fp, "%d%d%d", &type, &shipnum, &isstr)) {
    359        1.1       cgd 		case 3:
    360        1.1       cgd 			break;
    361        1.1       cgd 		case EOF:
    362        1.1       cgd 			goto out;
    363        1.1       cgd 		default:
    364        1.1       cgd 			goto bad;
    365        1.1       cgd 		}
    366        1.1       cgd 		if (shipnum < 0 || shipnum >= cc->vessels)
    367        1.1       cgd 			goto bad;
    368        1.1       cgd 		if (isstr != 0 && isstr != 1)
    369        1.1       cgd 			goto bad;
    370        1.1       cgd 		if (isstr) {
    371       1.25  dholland 			int ch;
    372        1.6  christos 			char *p;
    373       1.24       mrg 
    374        1.1       cgd 			for (p = buf;;) {
    375       1.25  dholland 				ch = getc(sync_fp);
    376  1.25.12.1       jym 				*p++ = ch;
    377       1.25  dholland 				switch (ch) {
    378        1.1       cgd 				case '\n':
    379        1.1       cgd 					p--;
    380        1.1       cgd 				case EOF:
    381        1.1       cgd 					break;
    382        1.1       cgd 				default:
    383        1.1       cgd 					if (p >= buf + sizeof buf)
    384        1.1       cgd 						p--;
    385        1.1       cgd 					continue;
    386        1.1       cgd 				}
    387        1.1       cgd 				break;
    388        1.1       cgd 			}
    389        1.1       cgd 			*p = 0;
    390        1.1       cgd 			for (p = buf; *p == ' '; p++)
    391        1.1       cgd 				;
    392       1.11   hubertf 			astr = p;
    393       1.11   hubertf 			a = b = c = d = 0;
    394       1.11   hubertf 		} else {
    395  1.25.12.1       jym 			if (fscanf(sync_fp, "%ld%ld%ld%ld", &a, &b, &c, &d)
    396  1.25.12.1       jym 			    != 4)
    397        1.1       cgd 				goto bad;
    398       1.11   hubertf 			astr = NULL;
    399       1.11   hubertf 		}
    400       1.11   hubertf 		if (sync_update(type, SHIP(shipnum), astr, a, b, c, d) < 0)
    401        1.1       cgd 			goto bad;
    402        1.1       cgd 	}
    403        1.1       cgd bad:
    404        1.1       cgd 	erred++;
    405        1.1       cgd out:
    406        1.1       cgd 	if (!erred && sync_bp != sync_buf) {
    407       1.15     jwise 		fseek(sync_fp, 0L, SEEK_END);
    408       1.15     jwise 		fwrite(sync_buf, sizeof *sync_buf, sync_bp - sync_buf,
    409        1.1       cgd 			sync_fp);
    410       1.15     jwise 		fflush(sync_fp);
    411        1.1       cgd 		sync_bp = sync_buf;
    412        1.1       cgd 	}
    413        1.1       cgd 	sync_seek = ftell(sync_fp);
    414        1.1       cgd #ifdef LOCK_EX
    415       1.15     jwise 	flock(fileno(sync_fp), LOCK_UN);
    416        1.1       cgd #else
    417       1.14       jsm 	setegid(egid);
    418       1.15     jwise 	unlink(sync_lock);
    419       1.14       jsm 	setegid(gid);
    420        1.1       cgd #endif
    421       1.15     jwise 	signal(SIGHUP, sighup);
    422       1.15     jwise 	signal(SIGINT, sigint);
    423        1.1       cgd 	return erred ? -1 : 0;
    424        1.1       cgd }
    425        1.1       cgd 
    426       1.16     jwise static int
    427  1.25.12.1       jym sync_update(int type, struct ship *ship, const char *astr,
    428  1.25.12.1       jym 	    long a, long b, long c, long d)
    429        1.1       cgd {
    430        1.1       cgd 	switch (type) {
    431  1.25.12.1       jym 	case W_CAPTAIN:  recv_captain(ship, astr);    break;
    432  1.25.12.1       jym 	case W_CAPTURED: recv_captured(ship, a);      break;
    433  1.25.12.1       jym 	case W_CLASS:    recv_class(ship, a);         break;
    434  1.25.12.1       jym 	case W_CREW:     recv_crew(ship, a, b, c);    break;
    435  1.25.12.1       jym 	case W_DBP:      recv_dbp(ship, a, b, c, d);  break;
    436  1.25.12.1       jym 	case W_DRIFT:    recv_drift(ship, a);         break;
    437  1.25.12.1       jym 	case W_EXPLODE:  recv_explode(ship, a);       break;
    438  1.25.12.1       jym 	case W_FOUL:     recv_foul(ship, a);          break;
    439  1.25.12.1       jym 	case W_GUNL:     recv_gunl(ship, a, b);       break;
    440  1.25.12.1       jym 	case W_GUNR:     recv_gunr(ship, a, b);       break;
    441  1.25.12.1       jym 	case W_HULL:     recv_hull(ship, a);          break;
    442  1.25.12.1       jym 	case W_MOVE:     recv_move(ship, astr);       break;
    443  1.25.12.1       jym 	case W_OBP:      recv_obp(ship, a, b, c, d);  break;
    444  1.25.12.1       jym 	case W_PCREW:    recv_pcrew(ship, a);         break;
    445  1.25.12.1       jym 	case W_UNFOUL:   recv_unfoul(ship, a, b);     break;
    446  1.25.12.1       jym 	case W_POINTS:   recv_points(ship, a);        break;
    447  1.25.12.1       jym 	case W_QUAL:     recv_qual(ship, a);          break;
    448  1.25.12.1       jym 	case W_UNGRAP:   recv_ungrap(ship, a, b);     break;
    449  1.25.12.1       jym 	case W_RIGG:     recv_rigg(ship, a, b, c, d); break;
    450  1.25.12.1       jym 	case W_COL:      recv_col(ship, a);           break;
    451  1.25.12.1       jym 	case W_DIR:      recv_dir(ship, a);           break;
    452  1.25.12.1       jym 	case W_ROW:      recv_row(ship, a);           break;
    453  1.25.12.1       jym 	case W_SIGNAL:   recv_signal(ship, astr);     break;
    454  1.25.12.1       jym 	case W_SINK:     recv_sink(ship, a);          break;
    455  1.25.12.1       jym 	case W_STRUCK:   recv_struck(ship, a);        break;
    456  1.25.12.1       jym 	case W_TA:       recv_ta(ship, a);            break;
    457  1.25.12.1       jym 	case W_ALIVE:    recv_alive();                break;
    458  1.25.12.1       jym 	case W_TURN:     recv_turn(a);                break;
    459  1.25.12.1       jym 	case W_WIND:     recv_wind(a, b);             break;
    460  1.25.12.1       jym 	case W_FS:       recv_fs(ship, a);            break;
    461  1.25.12.1       jym 	case W_GRAP:     recv_grap(ship, a);          break;
    462  1.25.12.1       jym 	case W_RIG1:     recv_rig1(ship, a);          break;
    463  1.25.12.1       jym 	case W_RIG2:     recv_rig2(ship, a);          break;
    464  1.25.12.1       jym 	case W_RIG3:     recv_rig3(ship, a);          break;
    465  1.25.12.1       jym 	case W_RIG4:     recv_rig4(ship, a);          break;
    466  1.25.12.1       jym 	case W_BEGIN:    recv_begin(ship);            break;
    467  1.25.12.1       jym 	case W_END:      recv_end(ship);              break;
    468  1.25.12.1       jym 	case W_DDEAD:    recv_ddead();                break;
    469        1.1       cgd 	default:
    470        1.1       cgd 		fprintf(stderr, "sync_update: unknown type %d\r\n", type);
    471        1.1       cgd 		return -1;
    472        1.1       cgd 	}
    473        1.1       cgd 	return 0;
    474        1.1       cgd }
    475  1.25.12.1       jym 
    476  1.25.12.1       jym /*
    477  1.25.12.1       jym  * Messages to send
    478  1.25.12.1       jym  */
    479  1.25.12.1       jym 
    480  1.25.12.1       jym void
    481  1.25.12.1       jym send_captain(struct ship *ship, const char *astr)
    482  1.25.12.1       jym {
    483  1.25.12.1       jym 	Writestr(W_CAPTAIN, ship, astr);
    484  1.25.12.1       jym }
    485  1.25.12.1       jym 
    486  1.25.12.1       jym void
    487  1.25.12.1       jym send_captured(struct ship *ship, long a)
    488  1.25.12.1       jym {
    489  1.25.12.1       jym 	Write(W_CAPTURED, ship, a, 0, 0, 0);
    490  1.25.12.1       jym }
    491  1.25.12.1       jym 
    492  1.25.12.1       jym void
    493  1.25.12.1       jym send_class(struct ship *ship, long a)
    494  1.25.12.1       jym {
    495  1.25.12.1       jym 	Write(W_CLASS, ship, a, 0, 0, 0);
    496  1.25.12.1       jym }
    497  1.25.12.1       jym 
    498  1.25.12.1       jym void
    499  1.25.12.1       jym send_crew(struct ship *ship, long a, long b, long c)
    500  1.25.12.1       jym {
    501  1.25.12.1       jym 	Write(W_CREW, ship, a, b, c, 0);
    502  1.25.12.1       jym }
    503  1.25.12.1       jym 
    504  1.25.12.1       jym void
    505  1.25.12.1       jym send_dbp(struct ship *ship, long a, long b, long c, long d)
    506  1.25.12.1       jym {
    507  1.25.12.1       jym 	Write(W_DBP, ship, a, b, c, d);
    508  1.25.12.1       jym }
    509  1.25.12.1       jym 
    510  1.25.12.1       jym void
    511  1.25.12.1       jym send_drift(struct ship *ship, long a)
    512  1.25.12.1       jym {
    513  1.25.12.1       jym 	Write(W_DRIFT, ship, a, 0, 0, 0);
    514  1.25.12.1       jym }
    515  1.25.12.1       jym 
    516  1.25.12.1       jym void
    517  1.25.12.1       jym send_explode(struct ship *ship, long a)
    518  1.25.12.1       jym {
    519  1.25.12.1       jym 	Write(W_EXPLODE, ship, a, 0, 0, 0);
    520  1.25.12.1       jym }
    521  1.25.12.1       jym 
    522  1.25.12.1       jym void
    523  1.25.12.1       jym send_foul(struct ship *ship, long a)
    524  1.25.12.1       jym {
    525  1.25.12.1       jym 	Write(W_FOUL, ship, a, 0, 0, 0);
    526  1.25.12.1       jym }
    527  1.25.12.1       jym 
    528  1.25.12.1       jym void
    529  1.25.12.1       jym send_gunl(struct ship *ship, long a, long b)
    530  1.25.12.1       jym {
    531  1.25.12.1       jym 	Write(W_GUNL, ship, a, b, 0, 0);
    532  1.25.12.1       jym }
    533  1.25.12.1       jym 
    534  1.25.12.1       jym void
    535  1.25.12.1       jym send_gunr(struct ship *ship, long a, long b)
    536  1.25.12.1       jym {
    537  1.25.12.1       jym 	Write(W_GUNR, ship, a, b, 0, 0);
    538  1.25.12.1       jym }
    539  1.25.12.1       jym 
    540  1.25.12.1       jym void
    541  1.25.12.1       jym send_hull(struct ship *ship, long a)
    542  1.25.12.1       jym {
    543  1.25.12.1       jym 	Write(W_HULL, ship, a, 0, 0, 0);
    544  1.25.12.1       jym }
    545  1.25.12.1       jym 
    546  1.25.12.1       jym void
    547  1.25.12.1       jym send_move(struct ship *ship, const char *astr)
    548  1.25.12.1       jym {
    549  1.25.12.1       jym 	Writestr(W_MOVE, ship, astr);
    550  1.25.12.1       jym }
    551  1.25.12.1       jym 
    552  1.25.12.1       jym void
    553  1.25.12.1       jym send_obp(struct ship *ship, long a, long b, long c, long d)
    554  1.25.12.1       jym {
    555  1.25.12.1       jym 	Write(W_OBP, ship, a, b, c, d);
    556  1.25.12.1       jym }
    557  1.25.12.1       jym 
    558  1.25.12.1       jym void
    559  1.25.12.1       jym send_pcrew(struct ship *ship, long a)
    560  1.25.12.1       jym {
    561  1.25.12.1       jym 	Write(W_PCREW, ship, a, 0, 0, 0);
    562  1.25.12.1       jym }
    563  1.25.12.1       jym 
    564  1.25.12.1       jym void
    565  1.25.12.1       jym send_unfoul(struct ship *ship, long a, long b)
    566  1.25.12.1       jym {
    567  1.25.12.1       jym 	Write(W_UNFOUL, ship, a, b, 0, 0);
    568  1.25.12.1       jym }
    569  1.25.12.1       jym 
    570  1.25.12.1       jym void
    571  1.25.12.1       jym send_points(struct ship *ship, long a)
    572  1.25.12.1       jym {
    573  1.25.12.1       jym 	Write(W_POINTS, ship, a, 0, 0, 0);
    574  1.25.12.1       jym }
    575  1.25.12.1       jym 
    576  1.25.12.1       jym void
    577  1.25.12.1       jym send_qual(struct ship *ship, long a)
    578  1.25.12.1       jym {
    579  1.25.12.1       jym 	Write(W_QUAL, ship, a, 0, 0, 0);
    580  1.25.12.1       jym }
    581  1.25.12.1       jym 
    582  1.25.12.1       jym void
    583  1.25.12.1       jym send_ungrap(struct ship *ship, long a, long b)
    584  1.25.12.1       jym {
    585  1.25.12.1       jym 	Write(W_UNGRAP, ship, a, b, 0, 0);
    586  1.25.12.1       jym }
    587  1.25.12.1       jym 
    588  1.25.12.1       jym void
    589  1.25.12.1       jym send_rigg(struct ship *ship, long a, long b, long c, long d)
    590  1.25.12.1       jym {
    591  1.25.12.1       jym 	Write(W_RIGG, ship, a, b, c, d);
    592  1.25.12.1       jym }
    593  1.25.12.1       jym 
    594  1.25.12.1       jym void
    595  1.25.12.1       jym send_col(struct ship *ship, long a)
    596  1.25.12.1       jym {
    597  1.25.12.1       jym 	Write(W_COL, ship, a, 0, 0, 0);
    598  1.25.12.1       jym }
    599  1.25.12.1       jym 
    600  1.25.12.1       jym void
    601  1.25.12.1       jym send_dir(struct ship *ship, long a)
    602  1.25.12.1       jym {
    603  1.25.12.1       jym 	Write(W_DIR, ship, a, 0, 0, 0);
    604  1.25.12.1       jym }
    605  1.25.12.1       jym 
    606  1.25.12.1       jym void
    607  1.25.12.1       jym send_row(struct ship *ship, long a)
    608  1.25.12.1       jym {
    609  1.25.12.1       jym 	Write(W_ROW, ship, a, 0, 0, 0);
    610  1.25.12.1       jym }
    611  1.25.12.1       jym 
    612  1.25.12.1       jym void
    613  1.25.12.1       jym send_signal(struct ship *ship, const char *astr)
    614  1.25.12.1       jym {
    615  1.25.12.1       jym 	Writestr(W_SIGNAL, ship, astr);
    616  1.25.12.1       jym }
    617  1.25.12.1       jym 
    618  1.25.12.1       jym void
    619  1.25.12.1       jym send_sink(struct ship *ship, long a)
    620  1.25.12.1       jym {
    621  1.25.12.1       jym 	Write(W_SINK, ship, a, 0, 0, 0);
    622  1.25.12.1       jym }
    623  1.25.12.1       jym 
    624  1.25.12.1       jym void
    625  1.25.12.1       jym send_struck(struct ship *ship, long a)
    626  1.25.12.1       jym {
    627  1.25.12.1       jym 	Write(W_STRUCK, ship, a, 0, 0, 0);
    628  1.25.12.1       jym }
    629  1.25.12.1       jym 
    630  1.25.12.1       jym void
    631  1.25.12.1       jym send_ta(struct ship *ship, long a)
    632  1.25.12.1       jym {
    633  1.25.12.1       jym 	Write(W_TA, ship, a, 0, 0, 0);
    634  1.25.12.1       jym }
    635  1.25.12.1       jym 
    636  1.25.12.1       jym void
    637  1.25.12.1       jym send_alive(void)
    638  1.25.12.1       jym {
    639  1.25.12.1       jym 	Write(W_ALIVE, NULL, 0, 0, 0, 0);
    640  1.25.12.1       jym }
    641  1.25.12.1       jym 
    642  1.25.12.1       jym void
    643  1.25.12.1       jym send_turn(long a)
    644  1.25.12.1       jym {
    645  1.25.12.1       jym 	Write(W_TURN, NULL, a, 0, 0, 0);
    646  1.25.12.1       jym }
    647  1.25.12.1       jym 
    648  1.25.12.1       jym void
    649  1.25.12.1       jym send_wind(long a, long b)
    650  1.25.12.1       jym {
    651  1.25.12.1       jym 	Write(W_WIND, NULL, a, b, 0, 0);
    652  1.25.12.1       jym }
    653  1.25.12.1       jym 
    654  1.25.12.1       jym void
    655  1.25.12.1       jym send_fs(struct ship *ship, long a)
    656  1.25.12.1       jym {
    657  1.25.12.1       jym 	Write(W_FS, ship, a, 0, 0, 0);
    658  1.25.12.1       jym }
    659  1.25.12.1       jym 
    660  1.25.12.1       jym void
    661  1.25.12.1       jym send_grap(struct ship *ship, long a)
    662  1.25.12.1       jym {
    663  1.25.12.1       jym 	Write(W_GRAP, ship, a, 0, 0, 0);
    664  1.25.12.1       jym }
    665  1.25.12.1       jym 
    666  1.25.12.1       jym void
    667  1.25.12.1       jym send_rig1(struct ship *ship, long a)
    668  1.25.12.1       jym {
    669  1.25.12.1       jym 	Write(W_RIG1, ship, a, 0, 0, 0);
    670  1.25.12.1       jym }
    671  1.25.12.1       jym 
    672  1.25.12.1       jym void
    673  1.25.12.1       jym send_rig2(struct ship *ship, long a)
    674  1.25.12.1       jym {
    675  1.25.12.1       jym 	Write(W_RIG2, ship, a, 0, 0, 0);
    676  1.25.12.1       jym }
    677  1.25.12.1       jym 
    678  1.25.12.1       jym void
    679  1.25.12.1       jym send_rig3(struct ship *ship, long a)
    680  1.25.12.1       jym {
    681  1.25.12.1       jym 	Write(W_RIG3, ship, a, 0, 0, 0);
    682  1.25.12.1       jym }
    683  1.25.12.1       jym 
    684  1.25.12.1       jym void
    685  1.25.12.1       jym send_rig4(struct ship *ship, long a)
    686  1.25.12.1       jym {
    687  1.25.12.1       jym 	Write(W_RIG4, ship, a, 0, 0, 0);
    688  1.25.12.1       jym }
    689  1.25.12.1       jym 
    690  1.25.12.1       jym void
    691  1.25.12.1       jym send_begin(struct ship *ship)
    692  1.25.12.1       jym {
    693  1.25.12.1       jym 	Write(W_BEGIN, ship, 0, 0, 0, 0);
    694  1.25.12.1       jym }
    695  1.25.12.1       jym 
    696  1.25.12.1       jym void
    697  1.25.12.1       jym send_end(struct ship *ship)
    698  1.25.12.1       jym {
    699  1.25.12.1       jym 	Write(W_END, ship, 0, 0, 0, 0);
    700  1.25.12.1       jym }
    701  1.25.12.1       jym 
    702  1.25.12.1       jym void
    703  1.25.12.1       jym send_ddead(void)
    704  1.25.12.1       jym {
    705  1.25.12.1       jym 	Write(W_DDEAD, NULL, 0, 0, 0, 0);
    706  1.25.12.1       jym }
    707  1.25.12.1       jym 
    708  1.25.12.1       jym 
    709  1.25.12.1       jym /*
    710  1.25.12.1       jym  * Actions upon message receipt
    711  1.25.12.1       jym  */
    712  1.25.12.1       jym 
    713  1.25.12.1       jym static void
    714  1.25.12.1       jym recv_captain(struct ship *ship, const char *astr)
    715  1.25.12.1       jym {
    716  1.25.12.1       jym 	strlcpy(ship->file->captain, astr, sizeof ship->file->captain);
    717  1.25.12.1       jym }
    718  1.25.12.1       jym 
    719  1.25.12.1       jym static void
    720  1.25.12.1       jym recv_captured(struct ship *ship, long a)
    721  1.25.12.1       jym {
    722  1.25.12.1       jym 	if (a < 0)
    723  1.25.12.1       jym 		ship->file->captured = 0;
    724  1.25.12.1       jym 	else
    725  1.25.12.1       jym 		ship->file->captured = SHIP(a);
    726  1.25.12.1       jym }
    727  1.25.12.1       jym 
    728  1.25.12.1       jym static void
    729  1.25.12.1       jym recv_class(struct ship *ship, long a)
    730  1.25.12.1       jym {
    731  1.25.12.1       jym 	ship->specs->class = a;
    732  1.25.12.1       jym }
    733  1.25.12.1       jym 
    734  1.25.12.1       jym static void
    735  1.25.12.1       jym recv_crew(struct ship *ship, long a, long b, long c)
    736  1.25.12.1       jym {
    737  1.25.12.1       jym 	struct shipspecs *s = ship->specs;
    738  1.25.12.1       jym 
    739  1.25.12.1       jym 	s->crew1 = a;
    740  1.25.12.1       jym 	s->crew2 = b;
    741  1.25.12.1       jym 	s->crew3 = c;
    742  1.25.12.1       jym }
    743  1.25.12.1       jym 
    744  1.25.12.1       jym static void
    745  1.25.12.1       jym recv_dbp(struct ship *ship, long a, long b, long c, long d)
    746  1.25.12.1       jym {
    747  1.25.12.1       jym 	struct BP *p = &ship->file->DBP[a];
    748  1.25.12.1       jym 
    749  1.25.12.1       jym 	p->turnsent = b;
    750  1.25.12.1       jym 	p->toship = SHIP(c);
    751  1.25.12.1       jym 	p->mensent = d;
    752  1.25.12.1       jym }
    753  1.25.12.1       jym 
    754  1.25.12.1       jym static void
    755  1.25.12.1       jym recv_drift(struct ship *ship, long a)
    756  1.25.12.1       jym {
    757  1.25.12.1       jym 	ship->file->drift = a;
    758  1.25.12.1       jym }
    759  1.25.12.1       jym 
    760  1.25.12.1       jym static void
    761  1.25.12.1       jym recv_explode(struct ship *ship, long a)
    762  1.25.12.1       jym {
    763  1.25.12.1       jym 	if ((ship->file->explode = a) == 2)
    764  1.25.12.1       jym 		ship->file->dir = 0;
    765  1.25.12.1       jym }
    766  1.25.12.1       jym 
    767  1.25.12.1       jym static void
    768  1.25.12.1       jym recv_foul(struct ship *ship, long a)
    769  1.25.12.1       jym {
    770  1.25.12.1       jym 	struct snag *p = &ship->file->foul[a];
    771  1.25.12.1       jym 
    772  1.25.12.1       jym 	if (SHIP(a)->file->dir == 0)
    773  1.25.12.1       jym 		return;
    774  1.25.12.1       jym 	if (p->sn_count++ == 0)
    775  1.25.12.1       jym 		p->sn_turn = turn;
    776  1.25.12.1       jym 	ship->file->nfoul++;
    777  1.25.12.1       jym }
    778  1.25.12.1       jym 
    779  1.25.12.1       jym static void
    780  1.25.12.1       jym recv_gunl(struct ship *ship, long a, long b)
    781  1.25.12.1       jym {
    782  1.25.12.1       jym 	struct shipspecs *s = ship->specs;
    783  1.25.12.1       jym 
    784  1.25.12.1       jym 	s->gunL = a;
    785  1.25.12.1       jym 	s->carL = b;
    786  1.25.12.1       jym }
    787  1.25.12.1       jym 
    788  1.25.12.1       jym static void
    789  1.25.12.1       jym recv_gunr(struct ship *ship, long a, long b)
    790  1.25.12.1       jym {
    791  1.25.12.1       jym 	struct shipspecs *s = ship->specs;
    792  1.25.12.1       jym 
    793  1.25.12.1       jym 	s->gunR = a;
    794  1.25.12.1       jym 	s->carR = b;
    795  1.25.12.1       jym }
    796  1.25.12.1       jym 
    797  1.25.12.1       jym static void
    798  1.25.12.1       jym recv_hull(struct ship *ship, long a)
    799  1.25.12.1       jym {
    800  1.25.12.1       jym 	ship->specs->hull = a;
    801  1.25.12.1       jym }
    802  1.25.12.1       jym 
    803  1.25.12.1       jym static void
    804  1.25.12.1       jym recv_move(struct ship *ship, const char *astr)
    805  1.25.12.1       jym {
    806  1.25.12.1       jym 	strlcpy(ship->file->movebuf, astr, sizeof ship->file->movebuf);
    807  1.25.12.1       jym }
    808  1.25.12.1       jym 
    809  1.25.12.1       jym static void
    810  1.25.12.1       jym recv_obp(struct ship *ship, long a, long b, long c, long d)
    811  1.25.12.1       jym {
    812  1.25.12.1       jym 	struct BP *p = &ship->file->OBP[a];
    813  1.25.12.1       jym 
    814  1.25.12.1       jym 	p->turnsent = b;
    815  1.25.12.1       jym 	p->toship = SHIP(c);
    816  1.25.12.1       jym 	p->mensent = d;
    817  1.25.12.1       jym }
    818  1.25.12.1       jym 
    819  1.25.12.1       jym static void
    820  1.25.12.1       jym recv_pcrew(struct ship *ship, long a)
    821  1.25.12.1       jym {
    822  1.25.12.1       jym 	ship->file->pcrew = a;
    823  1.25.12.1       jym }
    824  1.25.12.1       jym 
    825  1.25.12.1       jym static void
    826  1.25.12.1       jym recv_unfoul(struct ship *ship, long a, long b)
    827  1.25.12.1       jym {
    828  1.25.12.1       jym 	struct snag *p = &ship->file->foul[a];
    829  1.25.12.1       jym 
    830  1.25.12.1       jym 	if (p->sn_count > 0) {
    831  1.25.12.1       jym 		if (b) {
    832  1.25.12.1       jym 			ship->file->nfoul -= p->sn_count;
    833  1.25.12.1       jym 			p->sn_count = 0;
    834  1.25.12.1       jym 		} else {
    835  1.25.12.1       jym 			ship->file->nfoul--;
    836  1.25.12.1       jym 			p->sn_count--;
    837  1.25.12.1       jym 		}
    838  1.25.12.1       jym 	}
    839  1.25.12.1       jym }
    840  1.25.12.1       jym 
    841  1.25.12.1       jym static void
    842  1.25.12.1       jym recv_points(struct ship *ship, long a)
    843  1.25.12.1       jym {
    844  1.25.12.1       jym 	ship->file->points = a;
    845  1.25.12.1       jym }
    846  1.25.12.1       jym 
    847  1.25.12.1       jym static void
    848  1.25.12.1       jym recv_qual(struct ship *ship, long a)
    849  1.25.12.1       jym {
    850  1.25.12.1       jym 	ship->specs->qual = a;
    851  1.25.12.1       jym }
    852  1.25.12.1       jym 
    853  1.25.12.1       jym static void
    854  1.25.12.1       jym recv_ungrap(struct ship *ship, long a, long b)
    855  1.25.12.1       jym {
    856  1.25.12.1       jym 	struct snag *p = &ship->file->grap[a];
    857  1.25.12.1       jym 
    858  1.25.12.1       jym 	if (p->sn_count > 0) {
    859  1.25.12.1       jym 		if (b) {
    860  1.25.12.1       jym 			ship->file->ngrap -= p->sn_count;
    861  1.25.12.1       jym 			p->sn_count = 0;
    862  1.25.12.1       jym 		} else {
    863  1.25.12.1       jym 			ship->file->ngrap--;
    864  1.25.12.1       jym 			p->sn_count--;
    865  1.25.12.1       jym 		}
    866  1.25.12.1       jym 	}
    867  1.25.12.1       jym }
    868  1.25.12.1       jym 
    869  1.25.12.1       jym static void
    870  1.25.12.1       jym recv_rigg(struct ship *ship, long a, long b, long c, long d)
    871  1.25.12.1       jym {
    872  1.25.12.1       jym 	struct shipspecs *s = ship->specs;
    873  1.25.12.1       jym 
    874  1.25.12.1       jym 	s->rig1 = a;
    875  1.25.12.1       jym 	s->rig2 = b;
    876  1.25.12.1       jym 	s->rig3 = c;
    877  1.25.12.1       jym 	s->rig4 = d;
    878  1.25.12.1       jym }
    879  1.25.12.1       jym 
    880  1.25.12.1       jym static void
    881  1.25.12.1       jym recv_col(struct ship *ship, long a)
    882  1.25.12.1       jym {
    883  1.25.12.1       jym 	ship->file->col = a;
    884  1.25.12.1       jym }
    885  1.25.12.1       jym 
    886  1.25.12.1       jym static void
    887  1.25.12.1       jym recv_dir(struct ship *ship, long a)
    888  1.25.12.1       jym {
    889  1.25.12.1       jym 	ship->file->dir = a;
    890  1.25.12.1       jym }
    891  1.25.12.1       jym 
    892  1.25.12.1       jym static void
    893  1.25.12.1       jym recv_row(struct ship *ship, long a)
    894  1.25.12.1       jym {
    895  1.25.12.1       jym 	ship->file->row = a;
    896  1.25.12.1       jym }
    897  1.25.12.1       jym 
    898  1.25.12.1       jym static void
    899  1.25.12.1       jym recv_signal(struct ship *ship, const char *astr)
    900  1.25.12.1       jym {
    901  1.25.12.1       jym 	if (mode == MODE_PLAYER) {
    902  1.25.12.1       jym 		if (nobells)
    903  1.25.12.1       jym 			Signal("$$: %s", ship, astr);
    904  1.25.12.1       jym 		else
    905  1.25.12.1       jym 			Signal("\a$$: %s", ship, astr);
    906  1.25.12.1       jym 	}
    907  1.25.12.1       jym }
    908  1.25.12.1       jym 
    909  1.25.12.1       jym static void
    910  1.25.12.1       jym recv_sink(struct ship *ship, long a)
    911  1.25.12.1       jym {
    912  1.25.12.1       jym 	if ((ship->file->sink = a) == 2)
    913  1.25.12.1       jym 		ship->file->dir = 0;
    914  1.25.12.1       jym }
    915  1.25.12.1       jym 
    916  1.25.12.1       jym static void
    917  1.25.12.1       jym recv_struck(struct ship *ship, long a)
    918  1.25.12.1       jym {
    919  1.25.12.1       jym 	ship->file->struck = a;
    920  1.25.12.1       jym }
    921  1.25.12.1       jym 
    922  1.25.12.1       jym static void
    923  1.25.12.1       jym recv_ta(struct ship *ship, long a)
    924  1.25.12.1       jym {
    925  1.25.12.1       jym 	ship->specs->ta = a;
    926  1.25.12.1       jym }
    927  1.25.12.1       jym 
    928  1.25.12.1       jym static void
    929  1.25.12.1       jym recv_alive(void)
    930  1.25.12.1       jym {
    931  1.25.12.1       jym 	alive = 1;
    932  1.25.12.1       jym }
    933  1.25.12.1       jym 
    934  1.25.12.1       jym static void
    935  1.25.12.1       jym recv_turn(long a)
    936  1.25.12.1       jym {
    937  1.25.12.1       jym 	turn = a;
    938  1.25.12.1       jym }
    939  1.25.12.1       jym 
    940  1.25.12.1       jym static void
    941  1.25.12.1       jym recv_wind(long a, long b)
    942  1.25.12.1       jym {
    943  1.25.12.1       jym 	winddir = a;
    944  1.25.12.1       jym 	windspeed = b;
    945  1.25.12.1       jym }
    946  1.25.12.1       jym 
    947  1.25.12.1       jym static void
    948  1.25.12.1       jym recv_fs(struct ship *ship, long a)
    949  1.25.12.1       jym {
    950  1.25.12.1       jym 	ship->file->FS = a;
    951  1.25.12.1       jym }
    952  1.25.12.1       jym 
    953  1.25.12.1       jym static void
    954  1.25.12.1       jym recv_grap(struct ship *ship, long a)
    955  1.25.12.1       jym {
    956  1.25.12.1       jym 	struct snag *p = &ship->file->grap[a];
    957  1.25.12.1       jym 
    958  1.25.12.1       jym 	if (SHIP(a)->file->dir == 0)
    959  1.25.12.1       jym 		return;
    960  1.25.12.1       jym 	if (p->sn_count++ == 0)
    961  1.25.12.1       jym 		p->sn_turn = turn;
    962  1.25.12.1       jym 	ship->file->ngrap++;
    963  1.25.12.1       jym }
    964  1.25.12.1       jym 
    965  1.25.12.1       jym static void
    966  1.25.12.1       jym recv_rig1(struct ship *ship, long a)
    967  1.25.12.1       jym {
    968  1.25.12.1       jym 	ship->specs->rig1 = a;
    969  1.25.12.1       jym }
    970  1.25.12.1       jym 
    971  1.25.12.1       jym static void
    972  1.25.12.1       jym recv_rig2(struct ship *ship, long a)
    973  1.25.12.1       jym {
    974  1.25.12.1       jym 	ship->specs->rig2 = a;
    975  1.25.12.1       jym }
    976  1.25.12.1       jym 
    977  1.25.12.1       jym static void
    978  1.25.12.1       jym recv_rig3(struct ship *ship, long a)
    979  1.25.12.1       jym {
    980  1.25.12.1       jym 	ship->specs->rig3 = a;
    981  1.25.12.1       jym }
    982  1.25.12.1       jym 
    983  1.25.12.1       jym static void
    984  1.25.12.1       jym recv_rig4(struct ship *ship, long a)
    985  1.25.12.1       jym {
    986  1.25.12.1       jym 	ship->specs->rig4 = a;
    987  1.25.12.1       jym }
    988  1.25.12.1       jym 
    989  1.25.12.1       jym static void
    990  1.25.12.1       jym recv_begin(struct ship *ship)
    991  1.25.12.1       jym {
    992  1.25.12.1       jym 	strcpy(ship->file->captain, "begin");
    993  1.25.12.1       jym 	people++;
    994  1.25.12.1       jym }
    995  1.25.12.1       jym 
    996  1.25.12.1       jym static void
    997  1.25.12.1       jym recv_end(struct ship *ship)
    998  1.25.12.1       jym {
    999  1.25.12.1       jym 	*ship->file->captain = 0;
   1000  1.25.12.1       jym 	ship->file->points = 0;
   1001  1.25.12.1       jym 	people--;
   1002  1.25.12.1       jym }
   1003  1.25.12.1       jym 
   1004  1.25.12.1       jym static void
   1005  1.25.12.1       jym recv_ddead(void)
   1006  1.25.12.1       jym {
   1007  1.25.12.1       jym 	hasdriver = 0;
   1008  1.25.12.1       jym }
   1009