2009-03-15 02:47:18 +03:00
|
|
|
/* $NetBSD: sync.c,v 1.33 2009/03/14 23:47:18 dholland Exp $ */
|
1995-04-22 14:36:43 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1995-04-22 14:36:43 +04:00
|
|
|
* Copyright (c) 1983, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2003-08-07 13:36:50 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1993-03-21 12:45:37 +03:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
1997-10-13 23:42:53 +04:00
|
|
|
#include <sys/cdefs.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#ifndef lint
|
1995-04-22 14:36:43 +04:00
|
|
|
#if 0
|
1997-01-07 15:42:14 +03:00
|
|
|
static char sccsid[] = "@(#)sync.c 8.2 (Berkeley) 4/28/95";
|
1995-04-22 14:36:43 +04:00
|
|
|
#else
|
2009-03-15 02:47:18 +03:00
|
|
|
__RCSID("$NetBSD: sync.c,v 1.33 2009/03/14 23:47:18 dholland Exp $");
|
1995-04-22 14:36:43 +04:00
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif /* not lint */
|
|
|
|
|
2004-01-27 23:27:59 +03:00
|
|
|
#include <sys/stat.h>
|
|
|
|
|
1997-10-13 23:42:53 +04:00
|
|
|
#include <fcntl.h>
|
1997-01-07 15:42:14 +03:00
|
|
|
#include <errno.h>
|
2009-03-15 02:47:18 +03:00
|
|
|
#include <limits.h>
|
2001-01-04 06:51:23 +03:00
|
|
|
#include <signal.h>
|
1997-10-13 23:42:53 +04:00
|
|
|
#include <stdarg.h>
|
2001-01-04 06:21:16 +03:00
|
|
|
#include <stdio.h>
|
1997-10-13 23:42:53 +04:00
|
|
|
#include <stdlib.h>
|
2001-01-04 06:51:23 +03:00
|
|
|
#include <string.h>
|
1999-09-09 21:30:17 +04:00
|
|
|
#include <time.h>
|
2001-01-04 06:21:16 +03:00
|
|
|
#include <unistd.h>
|
1997-01-07 15:42:14 +03:00
|
|
|
#include "extern.h"
|
2000-02-10 01:27:55 +03:00
|
|
|
#include "pathnames.h"
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
#define BUFSIZE 4096
|
|
|
|
|
2009-03-15 01:52:52 +03:00
|
|
|
/* Message types */
|
|
|
|
#define W_CAPTAIN 1
|
|
|
|
#define W_CAPTURED 2
|
|
|
|
#define W_CLASS 3
|
|
|
|
#define W_CREW 4
|
|
|
|
#define W_DBP 5
|
|
|
|
#define W_DRIFT 6
|
|
|
|
#define W_EXPLODE 7
|
2009-03-15 01:54:05 +03:00
|
|
|
/* W_FILE 8 not used */
|
2009-03-15 01:52:52 +03:00
|
|
|
#define W_FOUL 9
|
|
|
|
#define W_GUNL 10
|
|
|
|
#define W_GUNR 11
|
|
|
|
#define W_HULL 12
|
|
|
|
#define W_MOVE 13
|
|
|
|
#define W_OBP 14
|
|
|
|
#define W_PCREW 15
|
|
|
|
#define W_UNFOUL 16
|
|
|
|
#define W_POINTS 17
|
|
|
|
#define W_QUAL 18
|
|
|
|
#define W_UNGRAP 19
|
|
|
|
#define W_RIGG 20
|
|
|
|
#define W_COL 21
|
|
|
|
#define W_DIR 22
|
|
|
|
#define W_ROW 23
|
|
|
|
#define W_SIGNAL 24
|
|
|
|
#define W_SINK 25
|
|
|
|
#define W_STRUCK 26
|
|
|
|
#define W_TA 27
|
|
|
|
#define W_ALIVE 28
|
|
|
|
#define W_TURN 29
|
|
|
|
#define W_WIND 30
|
|
|
|
#define W_FS 31
|
|
|
|
#define W_GRAP 32
|
|
|
|
#define W_RIG1 33
|
|
|
|
#define W_RIG2 34
|
|
|
|
#define W_RIG3 35
|
|
|
|
#define W_RIG4 36
|
|
|
|
#define W_BEGIN 37
|
|
|
|
#define W_END 38
|
|
|
|
#define W_DDEAD 39
|
|
|
|
|
|
|
|
|
|
|
|
static void recv_captain(struct ship *ship, const char *astr);
|
|
|
|
static void recv_captured(struct ship *ship, long a);
|
|
|
|
static void recv_class(struct ship *ship, long a);
|
|
|
|
static void recv_crew(struct ship *ship, long a, long b, long c);
|
|
|
|
static void recv_dbp(struct ship *ship, long a, long b, long c, long d);
|
|
|
|
static void recv_drift(struct ship *ship, long a);
|
|
|
|
static void recv_explode(struct ship *ship, long a);
|
|
|
|
static void recv_foul(struct ship *ship, long a);
|
|
|
|
static void recv_gunl(struct ship *ship, long a, long b);
|
|
|
|
static void recv_gunr(struct ship *ship, long a, long b);
|
|
|
|
static void recv_hull(struct ship *ship, long a);
|
|
|
|
static void recv_move(struct ship *ship, const char *astr);
|
|
|
|
static void recv_obp(struct ship *ship, long a, long b, long c, long d);
|
|
|
|
static void recv_pcrew(struct ship *ship, long a);
|
|
|
|
static void recv_unfoul(struct ship *ship, long a, long b);
|
|
|
|
static void recv_points(struct ship *ship, long a);
|
|
|
|
static void recv_qual(struct ship *ship, long a);
|
|
|
|
static void recv_ungrap(struct ship *ship, long a, long b);
|
|
|
|
static void recv_rigg(struct ship *ship, long a, long b, long c, long d);
|
|
|
|
static void recv_col(struct ship *ship, long a);
|
|
|
|
static void recv_dir(struct ship *ship, long a);
|
|
|
|
static void recv_row(struct ship *ship, long a);
|
|
|
|
static void recv_signal(struct ship *ship, const char *astr);
|
|
|
|
static void recv_sink(struct ship *ship, long a);
|
|
|
|
static void recv_struck(struct ship *ship, long a);
|
|
|
|
static void recv_ta(struct ship *ship, long a);
|
|
|
|
static void recv_alive(void);
|
|
|
|
static void recv_turn(long a);
|
|
|
|
static void recv_wind(long a, long b);
|
|
|
|
static void recv_fs(struct ship *ship, long a);
|
|
|
|
static void recv_grap(struct ship *ship, long a);
|
|
|
|
static void recv_rig1(struct ship *ship, long a);
|
|
|
|
static void recv_rig2(struct ship *ship, long a);
|
|
|
|
static void recv_rig3(struct ship *ship, long a);
|
|
|
|
static void recv_rig4(struct ship *ship, long a);
|
|
|
|
static void recv_begin(struct ship *ship);
|
|
|
|
static void recv_end(struct ship *ship);
|
|
|
|
static void recv_ddead(void);
|
|
|
|
|
|
|
|
static void Write(int, struct ship *, long, long, long, long);
|
|
|
|
static void Writestr(int, struct ship *, const char *);
|
|
|
|
|
2009-03-14 22:35:13 +03:00
|
|
|
static int sync_update(int, struct ship *, const char *,
|
|
|
|
long, long, long, long);
|
2001-01-04 05:43:32 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
static char sync_buf[BUFSIZE];
|
|
|
|
static char *sync_bp = sync_buf;
|
|
|
|
static long sync_seek;
|
|
|
|
static FILE *sync_fp;
|
|
|
|
|
2009-03-15 02:47:18 +03:00
|
|
|
static const char *
|
|
|
|
get_sync_file(int scenario_number)
|
|
|
|
{
|
|
|
|
static char sync_file[NAME_MAX];
|
|
|
|
|
|
|
|
snprintf(sync_file, sizeof(sync_file), _FILE_SYNC, scenario_number);
|
|
|
|
return sync_file;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
get_lock_file(int scenario_number)
|
|
|
|
{
|
|
|
|
static char sync_lock[NAME_MAX];
|
|
|
|
|
|
|
|
snprintf(sync_lock, sizeof(sync_lock), _FILE_LOCK, scenario_number);
|
|
|
|
return sync_lock;
|
|
|
|
}
|
|
|
|
|
1997-10-13 23:42:53 +04:00
|
|
|
void
|
2001-01-02 00:57:37 +03:00
|
|
|
fmtship(char *buf, size_t len, const char *fmt, struct ship *ship)
|
1997-10-13 23:42:53 +04:00
|
|
|
{
|
|
|
|
while (*fmt) {
|
|
|
|
if (len-- == 0) {
|
|
|
|
*buf = '\0';
|
|
|
|
return;
|
|
|
|
}
|
1997-10-14 01:02:57 +04:00
|
|
|
if (*fmt == '$' && fmt[1] == '$') {
|
1997-10-13 23:42:53 +04:00
|
|
|
size_t l = snprintf(buf, len, "%s (%c%c)",
|
|
|
|
ship->shipname, colours(ship), sterncolour(ship));
|
|
|
|
buf += l;
|
|
|
|
len -= l - 1;
|
|
|
|
fmt += 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*buf++ = *fmt++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len > 0)
|
|
|
|
*buf = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*VARARGS3*/
|
1997-10-13 23:42:53 +04:00
|
|
|
void
|
|
|
|
makesignal(struct ship *from, const char *fmt, struct ship *ship, ...)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-13 23:42:53 +04:00
|
|
|
char message[BUFSIZ];
|
|
|
|
char format[BUFSIZ];
|
|
|
|
va_list ap;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-13 23:42:53 +04:00
|
|
|
va_start(ap, ship);
|
|
|
|
fmtship(format, sizeof(format), fmt, ship);
|
2009-03-14 21:32:47 +03:00
|
|
|
vsnprintf(message, sizeof(message), format, ap);
|
1997-10-13 23:42:53 +04:00
|
|
|
va_end(ap);
|
2009-03-15 01:52:52 +03:00
|
|
|
send_signal(from, message);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
2001-01-02 00:57:37 +03:00
|
|
|
/*VARARGS2*/
|
1997-10-14 01:02:57 +04:00
|
|
|
void
|
|
|
|
makemsg(struct ship *from, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
char message[BUFSIZ];
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
2009-03-14 21:32:47 +03:00
|
|
|
vsnprintf(message, sizeof(message), fmt, ap);
|
1997-10-14 01:02:57 +04:00
|
|
|
va_end(ap);
|
2009-03-15 01:52:52 +03:00
|
|
|
send_signal(from, message);
|
1997-10-14 01:02:57 +04:00
|
|
|
}
|
1999-02-10 03:45:45 +03:00
|
|
|
|
1997-10-13 23:42:53 +04:00
|
|
|
int
|
2008-01-28 04:58:01 +03:00
|
|
|
sync_exists(int gamenum)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2009-03-15 02:47:18 +03:00
|
|
|
const char *path;
|
1993-03-21 12:45:37 +03:00
|
|
|
struct stat s;
|
|
|
|
time_t t;
|
|
|
|
|
2009-03-15 02:47:18 +03:00
|
|
|
path = get_sync_file(gamenum);
|
2001-01-02 00:57:37 +03:00
|
|
|
time(&t);
|
2000-02-10 01:27:55 +03:00
|
|
|
setegid(egid);
|
2009-03-15 02:47:18 +03:00
|
|
|
if (stat(path, &s) < 0) {
|
2000-02-10 01:27:55 +03:00
|
|
|
setegid(gid);
|
1993-03-21 12:45:37 +03:00
|
|
|
return 0;
|
2000-02-10 01:27:55 +03:00
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
if (s.st_mtime < t - 60*60*2) { /* 2 hours */
|
2009-03-15 02:47:18 +03:00
|
|
|
unlink(path);
|
|
|
|
path = get_lock_file(gamenum);
|
|
|
|
unlink(path);
|
2000-02-10 01:27:55 +03:00
|
|
|
setegid(gid);
|
1993-03-21 12:45:37 +03:00
|
|
|
return 0;
|
2000-02-10 01:27:55 +03:00
|
|
|
} else {
|
|
|
|
setegid(gid);
|
1993-03-21 12:45:37 +03:00
|
|
|
return 1;
|
2000-02-10 01:27:55 +03:00
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-10-13 23:42:53 +04:00
|
|
|
int
|
2001-01-02 00:57:37 +03:00
|
|
|
sync_open(void)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2009-03-15 02:47:18 +03:00
|
|
|
const char *sync_file;
|
|
|
|
const char *sync_lock;
|
2000-02-10 01:27:55 +03:00
|
|
|
struct stat tmp;
|
2009-03-15 02:47:18 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
if (sync_fp != NULL)
|
2001-01-02 00:57:37 +03:00
|
|
|
fclose(sync_fp);
|
2009-03-15 02:47:18 +03:00
|
|
|
sync_file = get_sync_file(game);
|
|
|
|
sync_lock = get_lock_file(game);
|
2000-02-10 01:27:55 +03:00
|
|
|
setegid(egid);
|
|
|
|
if (stat(sync_file, &tmp) < 0) {
|
|
|
|
mode_t omask = umask(002);
|
1993-03-21 12:45:37 +03:00
|
|
|
sync_fp = fopen(sync_file, "w+");
|
2001-01-02 00:57:37 +03:00
|
|
|
umask(omask);
|
1993-03-21 12:45:37 +03:00
|
|
|
} else
|
|
|
|
sync_fp = fopen(sync_file, "r+");
|
2000-02-10 01:27:55 +03:00
|
|
|
setegid(gid);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (sync_fp == NULL)
|
|
|
|
return -1;
|
|
|
|
sync_seek = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1997-10-13 23:42:53 +04:00
|
|
|
void
|
2008-01-28 04:58:01 +03:00
|
|
|
sync_close(int doremove)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2009-03-15 02:47:18 +03:00
|
|
|
const char *sync_file;
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
if (sync_fp != 0)
|
2001-01-02 00:57:37 +03:00
|
|
|
fclose(sync_fp);
|
2008-01-28 04:58:01 +03:00
|
|
|
if (doremove) {
|
2009-03-15 02:47:18 +03:00
|
|
|
sync_file = get_sync_file(game);
|
2000-02-10 01:27:55 +03:00
|
|
|
setegid(egid);
|
2001-01-02 00:57:37 +03:00
|
|
|
unlink(sync_file);
|
2000-02-10 01:27:55 +03:00
|
|
|
setegid(gid);
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
2009-03-15 01:52:52 +03:00
|
|
|
static void
|
2001-01-02 00:57:37 +03:00
|
|
|
Write(int type, struct ship *ship, long a, long b, long c, long d)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2009-03-14 21:32:47 +03:00
|
|
|
size_t max = sizeof(sync_buf) - (sync_bp - sync_buf);
|
2009-03-15 01:52:52 +03:00
|
|
|
int shipindex = (ship == NULL) ? 0 : ship->file->index;
|
1997-10-13 23:42:53 +04:00
|
|
|
|
2009-03-14 21:32:47 +03:00
|
|
|
snprintf(sync_bp, max, "%d %d 0 %ld %ld %ld %ld\n",
|
2009-03-15 01:52:52 +03:00
|
|
|
type, shipindex, a, b, c, d);
|
1999-02-10 03:45:45 +03:00
|
|
|
while (*sync_bp++)
|
|
|
|
;
|
|
|
|
sync_bp--;
|
|
|
|
if (sync_bp >= &sync_buf[sizeof sync_buf])
|
|
|
|
abort();
|
2001-01-02 00:57:37 +03:00
|
|
|
sync_update(type, ship, NULL, a, b, c, d);
|
1999-02-10 03:45:45 +03:00
|
|
|
}
|
|
|
|
|
2009-03-15 01:52:52 +03:00
|
|
|
static void
|
2001-01-02 00:57:37 +03:00
|
|
|
Writestr(int type, struct ship *ship, const char *a)
|
1999-02-10 03:45:45 +03:00
|
|
|
{
|
2009-03-14 21:32:47 +03:00
|
|
|
size_t max = sizeof(sync_buf) - (sync_bp - sync_buf);
|
2009-03-15 01:52:52 +03:00
|
|
|
int shipindex = (ship == NULL) ? 0 : ship->file->index;
|
2009-03-14 21:32:47 +03:00
|
|
|
|
2009-03-15 01:52:52 +03:00
|
|
|
snprintf(sync_bp, max, "%d %d 1 %s\n", type, shipindex, a);
|
1993-03-21 12:45:37 +03:00
|
|
|
while (*sync_bp++)
|
|
|
|
;
|
|
|
|
sync_bp--;
|
|
|
|
if (sync_bp >= &sync_buf[sizeof sync_buf])
|
|
|
|
abort();
|
2001-01-02 00:57:37 +03:00
|
|
|
sync_update(type, ship, a, 0, 0, 0, 0);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-10-13 23:42:53 +04:00
|
|
|
int
|
2001-01-02 00:57:37 +03:00
|
|
|
Sync(void)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
sig_t sighup, sigint;
|
1997-10-13 23:42:53 +04:00
|
|
|
int n;
|
1995-04-24 16:21:37 +04:00
|
|
|
int type, shipnum, isstr;
|
1999-02-10 03:45:45 +03:00
|
|
|
char *astr;
|
1995-04-24 16:21:37 +04:00
|
|
|
long a, b, c, d;
|
1993-03-21 12:45:37 +03:00
|
|
|
char buf[80];
|
|
|
|
char erred = 0;
|
2009-03-15 02:47:18 +03:00
|
|
|
#ifndef LOCK_EX
|
|
|
|
const char *sync_file;
|
|
|
|
const char *sync_lock;
|
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
sighup = signal(SIGHUP, SIG_IGN);
|
|
|
|
sigint = signal(SIGINT, SIG_IGN);
|
|
|
|
for (n = TIMEOUT; --n >= 0;) {
|
|
|
|
#ifdef LOCK_EX
|
|
|
|
if (flock(fileno(sync_fp), LOCK_EX|LOCK_NB) >= 0)
|
|
|
|
break;
|
|
|
|
if (errno != EWOULDBLOCK)
|
|
|
|
return -1;
|
|
|
|
#else
|
2009-03-15 02:47:18 +03:00
|
|
|
sync_file = get_sync_file(game);
|
|
|
|
sync_lock = get_lock_file(game);
|
2000-02-10 01:27:55 +03:00
|
|
|
setegid(egid);
|
|
|
|
if (link(sync_file, sync_lock) >= 0) {
|
|
|
|
setegid(gid);
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
2000-02-10 01:27:55 +03:00
|
|
|
}
|
|
|
|
setegid(gid);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (errno != EEXIST)
|
|
|
|
return -1;
|
|
|
|
#endif
|
|
|
|
sleep(1);
|
|
|
|
}
|
|
|
|
if (n <= 0)
|
|
|
|
return -1;
|
2001-01-02 00:57:37 +03:00
|
|
|
fseek(sync_fp, sync_seek, SEEK_SET);
|
1993-03-21 12:45:37 +03:00
|
|
|
for (;;) {
|
|
|
|
switch (fscanf(sync_fp, "%d%d%d", &type, &shipnum, &isstr)) {
|
|
|
|
case 3:
|
|
|
|
break;
|
|
|
|
case EOF:
|
|
|
|
goto out;
|
|
|
|
default:
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
if (shipnum < 0 || shipnum >= cc->vessels)
|
|
|
|
goto bad;
|
|
|
|
if (isstr != 0 && isstr != 1)
|
|
|
|
goto bad;
|
|
|
|
if (isstr) {
|
2008-01-28 04:58:01 +03:00
|
|
|
int ch;
|
1997-10-13 23:42:53 +04:00
|
|
|
char *p;
|
2006-05-18 22:42:59 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
for (p = buf;;) {
|
2008-01-28 04:58:01 +03:00
|
|
|
ch = getc(sync_fp);
|
2009-03-14 21:41:21 +03:00
|
|
|
*p++ = ch;
|
2008-01-28 04:58:01 +03:00
|
|
|
switch (ch) {
|
1993-03-21 12:45:37 +03:00
|
|
|
case '\n':
|
|
|
|
p--;
|
|
|
|
case EOF:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (p >= buf + sizeof buf)
|
|
|
|
p--;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
*p = 0;
|
|
|
|
for (p = buf; *p == ' '; p++)
|
|
|
|
;
|
1999-02-10 03:45:45 +03:00
|
|
|
astr = p;
|
|
|
|
a = b = c = d = 0;
|
|
|
|
} else {
|
2009-03-14 22:35:13 +03:00
|
|
|
if (fscanf(sync_fp, "%ld%ld%ld%ld", &a, &b, &c, &d)
|
|
|
|
!= 4)
|
1993-03-21 12:45:37 +03:00
|
|
|
goto bad;
|
1999-02-10 03:45:45 +03:00
|
|
|
astr = NULL;
|
|
|
|
}
|
|
|
|
if (sync_update(type, SHIP(shipnum), astr, a, b, c, d) < 0)
|
1993-03-21 12:45:37 +03:00
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
bad:
|
|
|
|
erred++;
|
|
|
|
out:
|
|
|
|
if (!erred && sync_bp != sync_buf) {
|
2001-01-02 00:57:37 +03:00
|
|
|
fseek(sync_fp, 0L, SEEK_END);
|
|
|
|
fwrite(sync_buf, sizeof *sync_buf, sync_bp - sync_buf,
|
1993-03-21 12:45:37 +03:00
|
|
|
sync_fp);
|
2001-01-02 00:57:37 +03:00
|
|
|
fflush(sync_fp);
|
1993-03-21 12:45:37 +03:00
|
|
|
sync_bp = sync_buf;
|
|
|
|
}
|
|
|
|
sync_seek = ftell(sync_fp);
|
|
|
|
#ifdef LOCK_EX
|
2001-01-02 00:57:37 +03:00
|
|
|
flock(fileno(sync_fp), LOCK_UN);
|
1993-03-21 12:45:37 +03:00
|
|
|
#else
|
2000-02-10 01:27:55 +03:00
|
|
|
setegid(egid);
|
2001-01-02 00:57:37 +03:00
|
|
|
unlink(sync_lock);
|
2000-02-10 01:27:55 +03:00
|
|
|
setegid(gid);
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif
|
2001-01-02 00:57:37 +03:00
|
|
|
signal(SIGHUP, sighup);
|
|
|
|
signal(SIGINT, sigint);
|
1993-03-21 12:45:37 +03:00
|
|
|
return erred ? -1 : 0;
|
|
|
|
}
|
|
|
|
|
2001-01-04 05:43:32 +03:00
|
|
|
static int
|
2009-03-14 22:35:13 +03:00
|
|
|
sync_update(int type, struct ship *ship, const char *astr,
|
|
|
|
long a, long b, long c, long d)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
switch (type) {
|
2009-03-15 01:52:52 +03:00
|
|
|
case W_CAPTAIN: recv_captain(ship, astr); break;
|
|
|
|
case W_CAPTURED: recv_captured(ship, a); break;
|
|
|
|
case W_CLASS: recv_class(ship, a); break;
|
|
|
|
case W_CREW: recv_crew(ship, a, b, c); break;
|
|
|
|
case W_DBP: recv_dbp(ship, a, b, c, d); break;
|
|
|
|
case W_DRIFT: recv_drift(ship, a); break;
|
|
|
|
case W_EXPLODE: recv_explode(ship, a); break;
|
|
|
|
case W_FOUL: recv_foul(ship, a); break;
|
|
|
|
case W_GUNL: recv_gunl(ship, a, b); break;
|
|
|
|
case W_GUNR: recv_gunr(ship, a, b); break;
|
|
|
|
case W_HULL: recv_hull(ship, a); break;
|
|
|
|
case W_MOVE: recv_move(ship, astr); break;
|
|
|
|
case W_OBP: recv_obp(ship, a, b, c, d); break;
|
|
|
|
case W_PCREW: recv_pcrew(ship, a); break;
|
|
|
|
case W_UNFOUL: recv_unfoul(ship, a, b); break;
|
|
|
|
case W_POINTS: recv_points(ship, a); break;
|
|
|
|
case W_QUAL: recv_qual(ship, a); break;
|
|
|
|
case W_UNGRAP: recv_ungrap(ship, a, b); break;
|
|
|
|
case W_RIGG: recv_rigg(ship, a, b, c, d); break;
|
|
|
|
case W_COL: recv_col(ship, a); break;
|
|
|
|
case W_DIR: recv_dir(ship, a); break;
|
|
|
|
case W_ROW: recv_row(ship, a); break;
|
|
|
|
case W_SIGNAL: recv_signal(ship, astr); break;
|
|
|
|
case W_SINK: recv_sink(ship, a); break;
|
|
|
|
case W_STRUCK: recv_struck(ship, a); break;
|
|
|
|
case W_TA: recv_ta(ship, a); break;
|
|
|
|
case W_ALIVE: recv_alive(); break;
|
|
|
|
case W_TURN: recv_turn(a); break;
|
|
|
|
case W_WIND: recv_wind(a, b); break;
|
|
|
|
case W_FS: recv_fs(ship, a); break;
|
|
|
|
case W_GRAP: recv_grap(ship, a); break;
|
|
|
|
case W_RIG1: recv_rig1(ship, a); break;
|
|
|
|
case W_RIG2: recv_rig2(ship, a); break;
|
|
|
|
case W_RIG3: recv_rig3(ship, a); break;
|
|
|
|
case W_RIG4: recv_rig4(ship, a); break;
|
|
|
|
case W_BEGIN: recv_begin(ship); break;
|
|
|
|
case W_END: recv_end(ship); break;
|
|
|
|
case W_DDEAD: recv_ddead(); break;
|
1993-03-21 12:45:37 +03:00
|
|
|
default:
|
|
|
|
fprintf(stderr, "sync_update: unknown type %d\r\n", type);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2009-03-15 01:52:52 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Messages to send
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
send_captain(struct ship *ship, const char *astr)
|
|
|
|
{
|
|
|
|
Writestr(W_CAPTAIN, ship, astr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
send_captured(struct ship *ship, long a)
|
|
|
|
{
|
|
|
|
Write(W_CAPTURED, ship, a, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
send_class(struct ship *ship, long a)
|
|
|
|
{
|
|
|
|
Write(W_CLASS, ship, a, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
send_crew(struct ship *ship, long a, long b, long c)
|
|
|
|
{
|
|
|
|
Write(W_CREW, ship, a, b, c, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
send_dbp(struct ship *ship, long a, long b, long c, long d)
|
|
|
|
{
|
|
|
|
Write(W_DBP, ship, a, b, c, d);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
send_drift(struct ship *ship, long a)
|
|
|
|
{
|
|
|
|
Write(W_DRIFT, ship, a, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
send_explode(struct ship *ship, long a)
|
|
|
|
{
|
|
|
|
Write(W_EXPLODE, ship, a, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
send_foul(struct ship *ship, long a)
|
|
|
|
{
|
|
|
|
Write(W_FOUL, ship, a, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
send_gunl(struct ship *ship, long a, long b)
|
|
|
|
{
|
|
|
|
Write(W_GUNL, ship, a, b, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
send_gunr(struct ship *ship, long a, long b)
|
|
|
|
{
|
|
|
|
Write(W_GUNR, ship, a, b, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
send_hull(struct ship *ship, long a)
|
|
|
|
{
|
|
|
|
Write(W_HULL, ship, a, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
send_move(struct ship *ship, const char *astr)
|
|
|
|
{
|
|
|
|
Writestr(W_MOVE, ship, astr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
send_obp(struct ship *ship, long a, long b, long c, long d)
|
|
|
|
{
|
|
|
|
Write(W_OBP, ship, a, b, c, d);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
send_pcrew(struct ship *ship, long a)
|
|
|
|
{
|
|
|
|
Write(W_PCREW, ship, a, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
send_unfoul(struct ship *ship, long a, long b)
|
|
|
|
{
|
|
|
|
Write(W_UNFOUL, ship, a, b, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
send_points(struct ship *ship, long a)
|
|
|
|
{
|
|
|
|
Write(W_POINTS, ship, a, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
send_qual(struct ship *ship, long a)
|
|
|
|
{
|
|
|
|
Write(W_QUAL, ship, a, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
send_ungrap(struct ship *ship, long a, long b)
|
|
|
|
{
|
|
|
|
Write(W_UNGRAP, ship, a, b, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
send_rigg(struct ship *ship, long a, long b, long c, long d)
|
|
|
|
{
|
|
|
|
Write(W_RIGG, ship, a, b, c, d);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
send_col(struct ship *ship, long a)
|
|
|
|
{
|
|
|
|
Write(W_COL, ship, a, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
send_dir(struct ship *ship, long a)
|
|
|
|
{
|
|
|
|
Write(W_DIR, ship, a, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
send_row(struct ship *ship, long a)
|
|
|
|
{
|
|
|
|
Write(W_ROW, ship, a, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
send_signal(struct ship *ship, const char *astr)
|
|
|
|
{
|
|
|
|
Writestr(W_SIGNAL, ship, astr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
send_sink(struct ship *ship, long a)
|
|
|
|
{
|
|
|
|
Write(W_SINK, ship, a, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
send_struck(struct ship *ship, long a)
|
|
|
|
{
|
|
|
|
Write(W_STRUCK, ship, a, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
send_ta(struct ship *ship, long a)
|
|
|
|
{
|
|
|
|
Write(W_TA, ship, a, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
send_alive(void)
|
|
|
|
{
|
|
|
|
Write(W_ALIVE, NULL, 0, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
send_turn(long a)
|
|
|
|
{
|
|
|
|
Write(W_TURN, NULL, a, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
send_wind(long a, long b)
|
|
|
|
{
|
|
|
|
Write(W_WIND, NULL, a, b, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
send_fs(struct ship *ship, long a)
|
|
|
|
{
|
|
|
|
Write(W_FS, ship, a, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
send_grap(struct ship *ship, long a)
|
|
|
|
{
|
|
|
|
Write(W_GRAP, ship, a, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
send_rig1(struct ship *ship, long a)
|
|
|
|
{
|
|
|
|
Write(W_RIG1, ship, a, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
send_rig2(struct ship *ship, long a)
|
|
|
|
{
|
|
|
|
Write(W_RIG2, ship, a, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
send_rig3(struct ship *ship, long a)
|
|
|
|
{
|
|
|
|
Write(W_RIG3, ship, a, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
send_rig4(struct ship *ship, long a)
|
|
|
|
{
|
|
|
|
Write(W_RIG4, ship, a, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
send_begin(struct ship *ship)
|
|
|
|
{
|
|
|
|
Write(W_BEGIN, ship, 0, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
send_end(struct ship *ship)
|
|
|
|
{
|
|
|
|
Write(W_END, ship, 0, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
send_ddead(void)
|
|
|
|
{
|
|
|
|
Write(W_DDEAD, NULL, 0, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Actions upon message receipt
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
|
|
|
recv_captain(struct ship *ship, const char *astr)
|
|
|
|
{
|
|
|
|
strlcpy(ship->file->captain, astr, sizeof ship->file->captain);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
recv_captured(struct ship *ship, long a)
|
|
|
|
{
|
|
|
|
if (a < 0)
|
|
|
|
ship->file->captured = 0;
|
|
|
|
else
|
|
|
|
ship->file->captured = SHIP(a);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
recv_class(struct ship *ship, long a)
|
|
|
|
{
|
|
|
|
ship->specs->class = a;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
recv_crew(struct ship *ship, long a, long b, long c)
|
|
|
|
{
|
|
|
|
struct shipspecs *s = ship->specs;
|
|
|
|
|
|
|
|
s->crew1 = a;
|
|
|
|
s->crew2 = b;
|
|
|
|
s->crew3 = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
recv_dbp(struct ship *ship, long a, long b, long c, long d)
|
|
|
|
{
|
|
|
|
struct BP *p = &ship->file->DBP[a];
|
|
|
|
|
|
|
|
p->turnsent = b;
|
|
|
|
p->toship = SHIP(c);
|
|
|
|
p->mensent = d;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
recv_drift(struct ship *ship, long a)
|
|
|
|
{
|
|
|
|
ship->file->drift = a;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
recv_explode(struct ship *ship, long a)
|
|
|
|
{
|
|
|
|
if ((ship->file->explode = a) == 2)
|
|
|
|
ship->file->dir = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
recv_foul(struct ship *ship, long a)
|
|
|
|
{
|
|
|
|
struct snag *p = &ship->file->foul[a];
|
|
|
|
|
|
|
|
if (SHIP(a)->file->dir == 0)
|
|
|
|
return;
|
|
|
|
if (p->sn_count++ == 0)
|
|
|
|
p->sn_turn = turn;
|
|
|
|
ship->file->nfoul++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
recv_gunl(struct ship *ship, long a, long b)
|
|
|
|
{
|
|
|
|
struct shipspecs *s = ship->specs;
|
|
|
|
|
|
|
|
s->gunL = a;
|
|
|
|
s->carL = b;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
recv_gunr(struct ship *ship, long a, long b)
|
|
|
|
{
|
|
|
|
struct shipspecs *s = ship->specs;
|
|
|
|
|
|
|
|
s->gunR = a;
|
|
|
|
s->carR = b;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
recv_hull(struct ship *ship, long a)
|
|
|
|
{
|
|
|
|
ship->specs->hull = a;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
recv_move(struct ship *ship, const char *astr)
|
|
|
|
{
|
|
|
|
strlcpy(ship->file->movebuf, astr, sizeof ship->file->movebuf);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
recv_obp(struct ship *ship, long a, long b, long c, long d)
|
|
|
|
{
|
|
|
|
struct BP *p = &ship->file->OBP[a];
|
|
|
|
|
|
|
|
p->turnsent = b;
|
|
|
|
p->toship = SHIP(c);
|
|
|
|
p->mensent = d;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
recv_pcrew(struct ship *ship, long a)
|
|
|
|
{
|
|
|
|
ship->file->pcrew = a;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
recv_unfoul(struct ship *ship, long a, long b)
|
|
|
|
{
|
|
|
|
struct snag *p = &ship->file->foul[a];
|
|
|
|
|
|
|
|
if (p->sn_count > 0) {
|
|
|
|
if (b) {
|
|
|
|
ship->file->nfoul -= p->sn_count;
|
|
|
|
p->sn_count = 0;
|
|
|
|
} else {
|
|
|
|
ship->file->nfoul--;
|
|
|
|
p->sn_count--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
recv_points(struct ship *ship, long a)
|
|
|
|
{
|
|
|
|
ship->file->points = a;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
recv_qual(struct ship *ship, long a)
|
|
|
|
{
|
|
|
|
ship->specs->qual = a;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
recv_ungrap(struct ship *ship, long a, long b)
|
|
|
|
{
|
|
|
|
struct snag *p = &ship->file->grap[a];
|
|
|
|
|
|
|
|
if (p->sn_count > 0) {
|
|
|
|
if (b) {
|
|
|
|
ship->file->ngrap -= p->sn_count;
|
|
|
|
p->sn_count = 0;
|
|
|
|
} else {
|
|
|
|
ship->file->ngrap--;
|
|
|
|
p->sn_count--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
recv_rigg(struct ship *ship, long a, long b, long c, long d)
|
|
|
|
{
|
|
|
|
struct shipspecs *s = ship->specs;
|
|
|
|
|
|
|
|
s->rig1 = a;
|
|
|
|
s->rig2 = b;
|
|
|
|
s->rig3 = c;
|
|
|
|
s->rig4 = d;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
recv_col(struct ship *ship, long a)
|
|
|
|
{
|
|
|
|
ship->file->col = a;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
recv_dir(struct ship *ship, long a)
|
|
|
|
{
|
|
|
|
ship->file->dir = a;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
recv_row(struct ship *ship, long a)
|
|
|
|
{
|
|
|
|
ship->file->row = a;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
recv_signal(struct ship *ship, const char *astr)
|
|
|
|
{
|
|
|
|
if (mode == MODE_PLAYER) {
|
|
|
|
if (nobells)
|
|
|
|
Signal("$$: %s", ship, astr);
|
|
|
|
else
|
|
|
|
Signal("\a$$: %s", ship, astr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
recv_sink(struct ship *ship, long a)
|
|
|
|
{
|
|
|
|
if ((ship->file->sink = a) == 2)
|
|
|
|
ship->file->dir = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
recv_struck(struct ship *ship, long a)
|
|
|
|
{
|
|
|
|
ship->file->struck = a;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
recv_ta(struct ship *ship, long a)
|
|
|
|
{
|
|
|
|
ship->specs->ta = a;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
recv_alive(void)
|
|
|
|
{
|
|
|
|
alive = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
recv_turn(long a)
|
|
|
|
{
|
|
|
|
turn = a;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
recv_wind(long a, long b)
|
|
|
|
{
|
|
|
|
winddir = a;
|
|
|
|
windspeed = b;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
recv_fs(struct ship *ship, long a)
|
|
|
|
{
|
|
|
|
ship->file->FS = a;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
recv_grap(struct ship *ship, long a)
|
|
|
|
{
|
|
|
|
struct snag *p = &ship->file->grap[a];
|
|
|
|
|
|
|
|
if (SHIP(a)->file->dir == 0)
|
|
|
|
return;
|
|
|
|
if (p->sn_count++ == 0)
|
|
|
|
p->sn_turn = turn;
|
|
|
|
ship->file->ngrap++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
recv_rig1(struct ship *ship, long a)
|
|
|
|
{
|
|
|
|
ship->specs->rig1 = a;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
recv_rig2(struct ship *ship, long a)
|
|
|
|
{
|
|
|
|
ship->specs->rig2 = a;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
recv_rig3(struct ship *ship, long a)
|
|
|
|
{
|
|
|
|
ship->specs->rig3 = a;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
recv_rig4(struct ship *ship, long a)
|
|
|
|
{
|
|
|
|
ship->specs->rig4 = a;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
recv_begin(struct ship *ship)
|
|
|
|
{
|
|
|
|
strcpy(ship->file->captain, "begin");
|
|
|
|
people++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
recv_end(struct ship *ship)
|
|
|
|
{
|
|
|
|
*ship->file->captain = 0;
|
|
|
|
ship->file->points = 0;
|
|
|
|
people--;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
recv_ddead(void)
|
|
|
|
{
|
|
|
|
hasdriver = 0;
|
|
|
|
}
|