static char *sccsid
= "@(#)sync.c 1.7 83/10/28";
static char sync_buf
[BUFSIZE
];
static char *sync_bufp
= sync_buf
;
static char sync_lock
[25];
static char sync_file
[25];
#define SF "/tmp/#sailsink.%d"
#define LF "/tmp/#saillock.%d"
makesignal(from
, fmt
, ship
, a
, b
, c
)
register struct ship
*ship
;
(void) sprintf(message
, fmt
, a
, b
, c
);
(void) sprintf(message
, fmt
,
ship
->shipname
, colours(ship
),
sterncolour(ship
), a
, b
, c
);
Write(W_SIGNAL
, from
, 1, (int)message
, 0, 0, 0);
char buf
[sizeof sync_file
];
(void) sprintf(buf
, SF
, game
);
if (s
.st_mtime
< t
- 60*60*2) { /* 2 hours */
(void) sprintf(sync_lock
, LF
, game
);
(void) sprintf(sync_file
, SF
, game
);
if (access(sync_file
, 0) < 0) {
sync_fp
= fopen(sync_file
, "w+");
sync_fp
= fopen(sync_file
, "r+");
(void) unlink(sync_file
);
Write(type
, ship
, isstr
, a
, b
, c
, d
)
(void) sprintf(sync_bufp
, "%d %d %d %s\n",
type
, ship
-SHIP(0), isstr
, a
);
(void) sprintf(sync_bufp
, "%d %d %d %d %d %d %d\n",
type
, ship
-SHIP(0), isstr
, a
, b
, c
, d
);
if (sync_bufp
>= &sync_buf
[sizeof sync_buf
])
sync_update(type
, ship
, a
, b
, c
, d
);
int (*sig1
)(), (*sig2
)();
int type
, shipnum
, isstr
, a
, b
, c
, d
;
sig1
= signal(SIGHUP
, SIG_IGN
);
sig2
= signal(SIGINT
, SIG_IGN
);
for (n
= 0; link(sync_file
, sync_lock
) < 0 && n
< 30; n
++)
(void) fseek(sync_fp
, sync_seek
, 0);
while (fscanf(sync_fp
, "%d%d%d", &type
, &shipnum
, &isstr
) != EOF
) {
switch (*p
++ = getc(sync_fp
)) {
for (p
= buf
; *p
== ' '; p
++)
(void) fscanf(sync_fp
, "%d%d%d%d", &a
, &b
, &c
, &d
);
sync_update(type
, SHIP(shipnum
), a
, b
, c
, d
);
if (sync_bufp
!= sync_buf
) {
(void) fseek(sync_fp
, 0L, 2);
(void) fputs(sync_buf
, sync_fp
);
sync_seek
= ftell(sync_fp
);
(void) unlink(sync_lock
);
(void) signal(SIGHUP
, sig1
);
(void) signal(SIGINT
, sig2
);
sync_update(type
, ship
, a
, b
, c
, d
)
register struct ship
*ship
;
register struct BP
*p
= &ship
->file
->DBP
[a
];
register struct BP
*p
= &ship
->file
->OBP
[a
];
register struct snag
*p
= &ship
->file
->fouls
[a
];
register struct snag
*p
= &ship
->file
->grapples
[a
];
Signal("\7%s (%c%c): %s", ship
, a
);
register struct shipspecs
*s
= ship
->specs
;
(void) strncpy(ship
->file
->captain
, (char *)a
,
sizeof ship
->file
->captain
- 1);
ship
->file
->captain
[sizeof ship
->file
->captain
- 1] = 0;
ship
->file
->captured
= 0;
ship
->file
->captured
= SHIP(a
);
if ((ship
->file
->explode
= a
) == 2)
register struct shipspecs
*s
= ship
->specs
;
register struct shipspecs
*s
= ship
->specs
;
(void) strncpy(ship
->file
->last
, (char *)a
,
sizeof ship
->file
->last
- 1);
ship
->file
->last
[sizeof ship
->file
->last
- 1] = 0;
register struct shipspecs
*s
= ship
->specs
;
if ((ship
->file
->sink
= a
) == 2)
(void) strcpy(ship
->file
->captain
, "begin");
(void) strcpy(ship
->file
->captain
, "");
fprintf(stderr
, "sync_update: unknown type %d\n", type
);