more cleanup; sail, driver, sail.log merged into single program
authorEdward Wang <edward@ucbvax.Berkeley.EDU>
Tue, 5 Mar 1985 10:07:10 +0000 (02:07 -0800)
committerEdward Wang <edward@ucbvax.Berkeley.EDU>
Tue, 5 Mar 1985 10:07:10 +0000 (02:07 -0800)
SCCS-vsn: games/sail/sync.c 2.7
SCCS-vsn: games/sail/lo_main.c 2.2
SCCS-vsn: games/sail/pl_1.c 2.9
SCCS-vsn: games/sail/machdep.h 2.6
SCCS-vsn: games/sail/extern.h 2.5
SCCS-vsn: games/sail/dr_1.c 2.11
SCCS-vsn: games/sail/Makefile 2.7

usr/src/games/sail/Makefile
usr/src/games/sail/dr_1.c
usr/src/games/sail/extern.h
usr/src/games/sail/lo_main.c
usr/src/games/sail/machdep.h
usr/src/games/sail/pl_1.c
usr/src/games/sail/sync.c

index fdb379a..e5e28e6 100644 (file)
@@ -1,66 +1,51 @@
 #
 # Sail - Wooden Ships And Iron Men
 #
 #
 # Sail - Wooden Ships And Iron Men
 #
-# Makefile     @(#)Makefile    2.6 84/12/03
+# Makefile     @(#)Makefile    2.7 85/03/04
 #
 CC=    cc
 CTAGS= ctags -w
 CFLAGS=        -O
 
 #
 CC=    cc
 CTAGS= ctags -w
 CFLAGS=        -O
 
-DFILES=                driver1.c driver2.c driver3.c grap.c boarders.c
-DOBJS=         driver1.o driver2.o driver3.o grap.o boarders.o
-PFILES=                player1.c player2.c player3.c player4.c player5.c \
-               player6.c player7.c version.c
-POBJS=         player1.o player2.o player3.o player4.o player5.o \
-               player6.o player7.o version.o
-COMMONFILES=   assorted.c game.c globals.c misc.c parties.c sync.c
-COMMONOBJS=    assorted.o game.o globals.o misc.o parties.o sync.o
-LFILES=                sail.log.c
-LOBJS=         sail.log.o
-HDRS=          externs.h player.h driver.h machdep.h
+CFILES=                main.c pl_main.c player1.c player2.c player3.c player4.c \
+               player5.c player6.c player7.c dr_main.c driver1.c driver2.c \
+               driver3.c driver4.c driver5.c lo_main.c assorted.c game.c \
+               globals.c misc.c parties.c sync.c version.c
+OBJS=          main.o pl_main.o player1.o player2.o player3.o player4.o \
+               player5.o player6.o player7.o dr_main.o driver1.o driver2.o \
+               driver3.o driver4.o driver5.o lo_main.o assorted.o game.o \
+               globals.o misc.o parties.o sync.o version.o
+HFILES=                externs.h player.h driver.h machdep.h
 OTHERFILES=    Makefile sail.6
 OTHERFILES=    Makefile sail.6
-CTAGFILES=     ${DFILES} ${PFILES} ${LFILES} ${COMMONFILES}
 JUNKFILES=     make.out
 JUNKFILES=     make.out
-PLIBS=         -lcurses -ltermlib
-DLIBS=
-LLIBS=
+LIBS=          -lcurses -ltermlib
 
 SAILMASTER=    daemon
 
 SAILMASTER=    daemon
-DRIVER=                lib/saildriver
 LOGFILE=       lib/saillog
 TARGET=                $(DESTDIR)/usr/games
 
 LOGFILE=       lib/saillog
 TARGET=                $(DESTDIR)/usr/games
 
-all: sail driver sail.log
+all: sail
 
 
-sail: ${POBJS} ${COMMONOBJS}
-       cc -O ${COMMONOBJS} ${POBJS} ${PLIBS} -o sail
-
-driver: ${DOBJS} ${COMMONOBJS}
-       cc -O ${COMMONOBJS} ${DOBJS} ${DLIBS} -o driver
-
-sail.log: ${LOBJS} globals.o
-       cc -O ${LOBJS} globals.o -o sail.log
+sail: $(OBJS)
+       $(CC) -o sail $(OBJS) $(LIBS)
 
 lint:
 
 lint:
-       lint -z $(PFILES) $(COMMONFILES) -lcurses
-       lint -z $(DFILES) $(COMMONFILES)
+       lint -z $(CFILES) -lcurses
 
 
-tags: ${CTAGFILES}
-       ${CTAGS} ${CTAGFILES}
+tags: $(CFILES) $(HFILES)
+       $(CTAGS) $(CFILES) $(HFILES)
 
 
-${HDRS} ${CTAGFILES}:
+$(CFILES) $(HFILES) $(OTHERFILES):
        sccs get $@;
 
 clean: 
        sccs get $@;
 
 clean: 
-       rm -f ${DOBJS} ${POBJS} ${LOBJS} ${COMMONOBJS} ${JUNKFILES}
+       rm -f $(OBJS) $(JUNKFILES)
 
 
-install: sail driver sail.log $(TARGET)/$(LOGFILE)
-       install -c -s -m 4755 -o ${SAILMASTER} sail ${TARGET}/sail
-       install -c -s -m 4755 -o ${SAILMASTER} driver ${TARGET}/${DRIVER}
-       install -c -s -m 755 sail.log ${TARGET}/sail.log
+install: sail sail.6 $(TARGET)/$(LOGFILE)
+       install -c -s -m 4755 -o $(SAILMASTER) sail $(TARGET)/sail
        install -c sail.6 $(DESTDIR)/usr/man/man6
 
 logfile $(TARGET)/$(LOGFILE):
        install -c sail.6 $(DESTDIR)/usr/man/man6
 
 logfile $(TARGET)/$(LOGFILE):
-       cp /dev/null ${TARGET}/${LOGFILE}
-       chown ${SAILMASTER} ${TARGET}/${LOGFILE}
-       chmod 644 ${TARGET}/${LOGFILE}
+       cp /dev/null $(TARGET)/$(LOGFILE)
+       chown $(SAILMASTER) $(TARGET)/$(LOGFILE)
+       chmod 644 $(TARGET)/$(LOGFILE)
index d7ad96c..6b06855 100644 (file)
@@ -1,76 +1,9 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)dr_1.c      2.10 84/03/08";
+static char *sccsid = "@(#)dr_1.c      2.11 85/03/04";
 #endif
 
 #include "driver.h"
 
 #endif
 
 #include "driver.h"
 
-main(argc, argv)
-int argc;
-char **argv;
-{
-       register int n;
-       register struct ship *sp;
-       int nat[NNATION];
-
-       if (argc != 2)
-               exit(1);
-       (void) signal(SIGINT, SIG_IGN);
-       (void) signal(SIGQUIT, SIG_IGN);
-       (void) signal(SIGTSTP, SIG_IGN);
-       (void) srand(getpid());
-       (void) setruid(geteuid());
-       /* ;;; add code here to check the game number. */
-       game = atoi(argv[1]);
-       cc = &scene[game];
-       ls = SHIP(cc->vessels);
-       if (sync_open() < 0) {
-               perror("driver: syncfile");
-               exit(1);
-       }
-       for (n = 0; n < NNATION; n++)
-               nat[n] = 0;
-       foreachship(sp) {
-               sp->file = (struct File *) calloc(1, sizeof (struct File));
-               if (sp == NULL) {
-                       (void) printf("driver: OUT OF MEMORY\n");
-                       exit(1);
-               }
-               sp->file->index = sp - SHIP(0);
-               sp->file->loadL = L_ROUND;
-               sp->file->loadR = L_ROUND;
-               sp->file->readyR = R_LOADED|R_INITIAL;
-               sp->file->readyL = R_LOADED|R_INITIAL;
-               sp->file->stern = nat[sp->nationality]++;
-               sp->file->dir = sp->shipdir;
-               sp->file->row = sp->shiprow;
-               sp->file->col = sp->shipcol;
-       }
-       windspeed = cc->windspeed;
-       winddir = cc->winddir;
-       for (;;) {
-               sleep(7);
-               if (Sync() < 0) {
-                       sync_close(1);
-                       exit(1);
-               }
-               next();
-               unfoul();
-               checkup();
-               prizecheck();
-               moveall();
-               thinkofgrapples();
-               boardcomp();
-               compcombat();
-               resolve();
-               reload();
-               checksails();
-               if (Sync() < 0) {
-                       sync_close(1);
-                       exit(1);
-               }
-       }
-}
-
 unfoul()
 {
        register struct ship *sp;
 unfoul()
 {
        register struct ship *sp;
@@ -83,8 +16,8 @@ unfoul()
                        continue;
                nat = capship(sp)->nationality;
                foreachship(to) {
                        continue;
                nat = capship(sp)->nationality;
                foreachship(to) {
-                       if (nat != capship(to)->nationality
-                           && !toughmelee(sp, to, 0, 0))
+                       if (nat != capship(to)->nationality &&
+                           !toughmelee(sp, to, 0, 0))
                                continue;
                        for (i = fouled2(sp, to); --i >= 0;)
                                if (die() <= 2)
                                continue;
                        for (i = fouled2(sp, to); --i >= 0;)
                                if (die() <= 2)
@@ -495,11 +428,3 @@ next()
                }
        }
 }
                }
        }
 }
-
-/*ARGSUSED*/
-/*VARARGS2*/
-Signal(fmt, ship, a, b, c)
-char *fmt;
-struct ship *ship;
-{
-}
index 5518aef..cdd885f 100644 (file)
@@ -1,11 +1,27 @@
 /*
 /*
- * @(#)extern.h        2.4 84/02/23
+ * @(#)extern.h        2.5 85/03/04
  */
 #include <stdio.h>
 #include <signal.h>
 #include <ctype.h>
  */
 #include <stdio.h>
 #include <signal.h>
 #include <ctype.h>
+#include <setjmp.h>
 #include "machdep.h"
 
 #include "machdep.h"
 
+       /* program mode */
+int mode;
+jmp_buf restart;
+#define MODE_PLAYER    1
+#define MODE_DRIVER    2
+#define MODE_LOGGER    3
+
+       /* command line flags */
+char debug;                            /* -D */
+char randomize;                                /* -x */
+char longfmt;                          /* -l */
+
+       /* other initial modes */
+char issetuid;                         /* running setuid */
+
 #define die()          ((rand() >> 3) % 6 + 1)
 #define sqr(a)         ((a) * (a))
 #define abs(a)         ((a) > 0 ? (a) : -(a))
 #define die()          ((rand() >> 3) % 6 + 1)
 #define sqr(a)         ((a) * (a))
 #define abs(a)         ((a) > 0 ? (a) : -(a))
@@ -244,7 +260,6 @@ int turn;
 int game;
 int alive;
 int people;
 int game;
 int alive;
 int people;
-char isplayer;
 char hasdriver;
 
 char *info();
 char hasdriver;
 
 char *info();
@@ -254,6 +269,7 @@ char *saywhat();
 struct ship *closestenemy();
 
 char *calloc();
 struct ship *closestenemy();
 
 char *calloc();
+char *rindex();
 char *strcpy();
 char *strcat();
 char *strncpy();
 char *strcpy();
 char *strcat();
 char *strncpy();
index 48929d3..66dc35c 100644 (file)
@@ -1,14 +1,11 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)lo_main.c   2.1 83/10/31";
+static char *sccsid = "@(#)lo_main.c   2.2 85/03/04";
 #endif
 
 /*
  * Print out the top ten SAILors
  *
 #endif
 
 /*
  * Print out the top ten SAILors
  *
- * sail.log [-s/l]
- *
- *  -s force a short listing (without real usernames)
- *  -l force a long listing (print out real usernames)
+ * -l force a long listing (print out real usernames)
  */
 #include <pwd.h>
 #include "externs.h"
  */
 #include <pwd.h>
 #include "externs.h"
@@ -19,27 +16,15 @@ char *title[] = {
        "Commander", "Lieutenant"
 };
 
        "Commander", "Lieutenant"
 };
 
-main(argc, argv)
-int argc;
-char **argv;
+lo_main()
 {
        FILE *fp;
        char sbuf[32];
        int n = 0, people;
 {
        FILE *fp;
        char sbuf[32];
        int n = 0, people;
-       int usrnam = 0;
        struct passwd *getpwuid(), *pass;
        struct logs log;
        struct ship *ship;
 
        struct passwd *getpwuid(), *pass;
        struct logs log;
        struct ship *ship;
 
-       if (argc > 1 && argc == 2)
-               if (strcmp(argv[1], "-s") == 0)
-                       usrnam = 0;
-               else if (strcmp(argv[1], "-l") == 0)
-                       usrnam = 1;
-               else {
-                       fprintf(stderr, "usage: %s: [-s/l]\n", argv[0]);
-                       exit(1);
-               }
        if ((fp = fopen(LOGFILE, "r")) == 0) {
                perror(LOGFILE);
                exit(1);
        if ((fp = fopen(LOGFILE, "r")) == 0) {
                perror(LOGFILE);
                exit(1);
@@ -54,9 +39,9 @@ char **argv;
                perror(LOGFILE);
                exit(1);
        }
                perror(LOGFILE);
                exit(1);
        }
-       while (fread((char *)&log, sizeof log, 1, fp) == 1
-              && log.l_name[0] != '\0') {
-               if (usrnam && (pass = getpwuid(log.l_uid)) != NULL)
+       while (fread((char *)&log, sizeof log, 1, fp) == 1 &&
+              log.l_name[0] != '\0') {
+               if (longfmt && (pass = getpwuid(log.l_uid)) != NULL)
                        (void) sprintf(sbuf, "%10.10s (%s)",
                                log.l_name, pass->pw_name);
                else
                        (void) sprintf(sbuf, "%10.10s (%s)",
                                log.l_name, pass->pw_name);
                else
@@ -67,4 +52,5 @@ char **argv;
                        (float) log.l_netpoints / ship->specs->pts);
        }
        printf("\n%d people have played.\n", people);
                        (float) log.l_netpoints / ship->specs->pts);
        }
        printf("\n%d people have played.\n", people);
+       return 0;
 }
 }
index 3b98a90..ff25ab3 100644 (file)
@@ -1,16 +1,10 @@
 /*
 /*
- * sccsid = "@(#)machdep.h     2.5 %G%";
+ * sccsid = "@(#)machdep.h     2.6 %G%";
  */
  */
-#define LOGFILE "/usr/games/lib/saillog"
-#define DRIVER1 "driver"
-#define DRIVER2 "/usr/games/lib/saildriver"
-#define DRIVER3 "/usr/public/.driver"
-#define DRIVERNAME "driver"
-#define SETUID                 /* player and driver run setuid */
 
 
-#define TIMEOUT 300            /* Sync() time out */
+#define LOGFILE "/usr/games/lib/saillog"       /* has to match the makefile */
 
 
-#define BUFSIZE 4096
+#define TIMEOUT 300                            /* Sync() timeout in seconds */
 
 /* for 4.2bsd machines */
 #define blockalarm()   ((void) sigblock(1 << SIGALRM-1))
 
 /* for 4.2bsd machines */
 #define blockalarm()   ((void) sigblock(1 << SIGALRM-1))
index 1173872..6682709 100644 (file)
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)pl_1.c      2.8 84/12/12";
+static char *sccsid = "@(#)pl_1.c      2.9 85/03/04";
 #endif
 
 #include "player.h"
 #include <sys/types.h>
 #include <sys/wait.h>
 
 #endif
 
 #include "player.h"
 #include <sys/types.h>
 #include <sys/wait.h>
 
-int choke(), child();
-
-/*ARGSUSED*/
-main(argc, argv)
-int argc;
-char **argv;
-{
-       char nodrive = 0, randomize = 0, debug = 0;
-       extern char _sobuf[];
-
-       setbuf(stdout, _sobuf);
-       isplayer = 1;
-
-       while (*++argv && **argv == '-')
-               switch (*++*argv) {
-               case 'd':
-                       nodrive = 1;
-                       break;
-               case 'D':
-                       debug++;
-                       break;
-               case 'x':
-                       randomize = 1;
-                       break;
-               default:
-                       printf("Unknown flag '%s'\n",*argv);
-                       break;
-               }
-       if (*argv)
-               game = atoi(*argv);
-       else
-               game = -1;
-       initialize(nodrive, randomize, debug);
-       Signal("Aye aye, Sir", (struct ship *)0);
-       play();
-}
-
-initialize(nodriver, randomize, debug)
-char randomize, nodriver, debug;
-{
-       register struct File *fp;
-       register struct ship *sp;
-       char captain[80];
-       char message[60];
-       int load;
-       register int n;
-       char *nameptr;
-       int nat[NNATION];
-
-       if (!SCREENTEST()) {
-               printf("Can't sail on this terminal.\n");
-               exit(1);
-       }
-
-       (void) srand(getpid());
-
-       if (game < 0) {
-               (void) puts("Choose a scenario:\n");
-               (void) puts("\n\tNUMBER\tSHIPS\tIN PLAY\tTITLE");
-               for (n = 0; n < NSCENE; n++) {
-                       /* ( */
-                       printf("\t%d):\t%d\t%s\t%s\n", n, scene[n].vessels,
-                               sync_exists(n) ? "YES" : "no",
-                               scene[n].name);
-               }
-reprint:
-               printf("\nScenario number? ");
-               (void) fflush(stdout);
-               (void) scanf("%d", &game);
-               while (getchar() != '\n')
-                       ;
-       }
-       if (game < 0 || game >= NSCENE) {
-               (void) puts("Very funny.");
-               exit(1);
-       }
-       cc = &scene[game];
-       ls = SHIP(cc->vessels);
-
-       for (n = 0; n < NNATION; n++)
-               nat[n] = 0;
-       foreachship(sp) {
-               sp->file = (struct File *) calloc(1, sizeof (struct File));
-               if (sp->file == NULL) {
-                       (void) puts("OUT OF MEMORY");
-                       exit(0);
-               }
-               sp->file->index = sp - SHIP(0);
-               sp->file->stern = nat[sp->nationality]++;
-               sp->file->dir = sp->shipdir;
-               sp->file->row = sp->shiprow;
-               sp->file->col = sp->shipcol;
-       }
-       windspeed = cc->windspeed;
-       winddir = cc->winddir;
-
-       (void) signal(SIGHUP, choke);
-       (void) signal(SIGINT, choke);
-
-       hasdriver = sync_exists(game);
-       if (sync_open() < 0) {
-               perror("sail: syncfile");
-               exit(1);
-       }
-
-       if (hasdriver) {
-               (void) puts("Synchronizing with the other players...");
-               (void) fflush(stdout);
-               if (Sync() < 0)
-                       leave(LEAVE_SYNC);
-       }
-       for (;;) {
-               foreachship(sp)
-                       if (sp->file->captain[0] == 0 && !sp->file->struck
-                           && sp->file->captured == 0)
-                               break;
-               if (sp >= ls) {
-                       (void) puts("All ships taken in that scenario.");
-                       foreachship(sp)
-                               free((char *)sp->file);
-                       sync_close(0);
-                       people = 0;
-                       goto reprint;
-               }
-               if (randomize) {
-                       player = sp - SHIP(0);
-               } else {
-                       printf("%s\n\n", cc->name);
-                       foreachship(sp)
-                               printf("  %2d:  %-10s %-15s  (%-2d pts)   %s\n",
-                                       sp->file->index,
-                                       countryname[sp->nationality],
-                                       sp->shipname,
-                                       sp->specs->pts,
-                                       saywhat(sp, 1));
-                       printf("\nWhich ship (0-%d)? ", cc->vessels-1);
-                       (void) fflush(stdout);
-                       if (scanf("%d", &player) != 1 || player < 0
-                           || player >= cc->vessels) {
-                               while (getchar() != '\n')
-                                       ;
-                               (void) puts("Say what?");
-                               player = -1;
-                       } else
-                               while (getchar() != '\n')
-                                       ;
-               }
-               if (player < 0)
-                       continue;
-               if (Sync() < 0)
-                       leave(LEAVE_SYNC);
-               fp = SHIP(player)->file;
-               if (fp->captain[0] || fp->struck || fp->captured != 0)
-                       (void) puts("That ship is taken.");
-               else
-                       break;
-       }
-
-       ms = SHIP(player);
-       mf = ms->file;
-       mc = ms->specs;
-
-       Write(W_BEGIN, ms, 0, 0, 0, 0, 0);
-       if (Sync() < 0)
-               leave(LEAVE_SYNC);
-
-       (void) signal(SIGCHLD, child);
-       if (!hasdriver && !nodriver) {
-               char num[10];
-               (void) sprintf(num, "%d", game);
-               switch (fork()) {
-               case 0:
-                       execl(DRIVER1, DRIVERNAME, num, 0);
-                       execl(DRIVER2, DRIVERNAME, num, 0);
-                       execl(DRIVER3, DRIVERNAME, num, 0);
-                       perror(DRIVERNAME);
-                       exit(1);
-                       break;
-               case -1:
-                       perror("fork");
-                       leave(LEAVE_FORK);
-                       break;
-               default:
-                       hasdriver++;
-               }
-       }
-
-       printf("Your ship is the %s, a %d gun %s (%s crew).\n",
-               ms->shipname, mc->guns, classname[mc->class],
-               qualname[mc->qual]);
-       if ((nameptr = (char *) getenv("SAILNAME")) && *nameptr)
-               (void) strncpy(captain, nameptr, sizeof captain);
-       else {
-               (void) printf("Your name, Captain? ");
-               (void) fflush(stdout);
-               (void) gets(captain);
-               if (!*captain)
-                       (void) strcpy(captain, "no name");
-       }
-       captain[sizeof captain - 1] = '\0';
-       Write(W_CAPTAIN, ms, 1, (int)captain, 0, 0, 0);
-       for (n = 0; n < 2; n++) {
-               char buf[10];
-
-               printf("\nInitial broadside %s (grape, chain, round, double): ",
-                       n ? "right" : "left");
-               (void) fflush(stdout);
-               (void) scanf("%s", buf);
-               switch (*buf) {
-               case 'g':
-                       load = L_GRAPE;
-                       break;
-               case 'c':
-                       load = L_CHAIN;
-                       break;
-               case 'r':
-                       load = L_ROUND;
-                       break;
-               case 'd':
-                       load = L_DOUBLE;
-                       break;
-               default:
-                       load = L_ROUND;
-               }
-               if (n) {
-                       mf->loadR = load;
-                       mf->readyR = R_LOADED|R_INITIAL;
-               } else {
-                       mf->loadL = load;
-                       mf->readyL = R_LOADED|R_INITIAL;
-               }
-       }
-
-       initscreen();
-       draw_board();
-       (void) sprintf(message, "Captain %s assuming command", captain);
-       Write(W_SIGNAL, ms, 1, (int)message, 0, 0, 0);
-       newturn();
-}
-
 /*
  * If we get here before a ship is chosen, then ms == 0 and
  * we don't want to update the score file, or do any Write's either.
 /*
  * If we get here before a ship is chosen, then ms == 0 and
  * we don't want to update the score file, or do any Write's either.
index 461182a..eabbfaa 100644 (file)
@@ -1,11 +1,13 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)sync.c      2.6 84/04/28";
+static char *sccsid = "@(#)sync.c      2.7 85/03/04";
 #endif
 
 #include "externs.h"
 #include <sys/file.h>
 #include <sys/errno.h>
 
 #endif
 
 #include "externs.h"
 #include <sys/file.h>
 #include <sys/errno.h>
 
+#define BUFSIZE 4096
+
 static char sync_buf[BUFSIZE];
 static char *sync_bp = sync_buf;
 static char sync_lock[25];
 static char sync_buf[BUFSIZE];
 static char *sync_bp = sync_buf;
 static char sync_lock[25];
@@ -17,9 +19,9 @@ static FILE *sync_fp;
 
 /*VARARGS3*/
 makesignal(from, fmt, ship, a, b, c)
 
 /*VARARGS3*/
 makesignal(from, fmt, ship, a, b, c)
-struct ship *from;
-char *fmt;
-register struct ship *ship;
+       struct ship *from;
+       char *fmt;
+       register struct ship *ship;
 {
        char message[80];
 
 {
        char message[80];
 
@@ -55,27 +57,24 @@ sync_exists(game)
 
 sync_open()
 {
 
 sync_open()
 {
-       (void) sprintf(sync_lock, LF, game);
-       (void) sprintf(sync_file, SF, game);
-       if (access(sync_file, 0) < 0) {
-               int omask;
-#ifdef SETUID
-               omask = umask(077);
-#else
-               omask = umask(011);
-#endif
-               sync_fp = fopen(sync_file, "w+");
-               (void) umask(omask);
-       } else
-               sync_fp = fopen(sync_file, "r+");
-       if (sync_fp == 0)
-               return -1;
+       if (sync_fp == NULL) {
+               (void) sprintf(sync_lock, LF, game);
+               (void) sprintf(sync_file, SF, game);
+               if (access(sync_file, 0) < 0) {
+                       int omask = umask(issetuid ? 077 : 011);
+                       sync_fp = fopen(sync_file, "w+");
+                       (void) umask(omask);
+               } else
+                       sync_fp = fopen(sync_file, "r+");
+               if (sync_fp == NULL)
+                       return -1;
+       }
        sync_seek == 0;
        return 0;
 }
 
 sync_close(remove)
        sync_seek == 0;
        return 0;
 }
 
 sync_close(remove)
-char remove;
+       char remove;
 {
        if (sync_fp != 0)
                (void) fclose(sync_fp);
 {
        if (sync_fp != 0)
                (void) fclose(sync_fp);
@@ -84,10 +83,10 @@ char remove;
 }
 
 Write(type, ship, isstr, a, b, c, d)
 }
 
 Write(type, ship, isstr, a, b, c, d)
-int type;
-struct ship *ship;
-char isstr;
-int a, b, c, d;
+       int type;
+       struct ship *ship;
+       char isstr;
+       int a, b, c, d;
 {
        if (isstr)
                (void) sprintf(sync_bp, "%d %d %d %s\n",
 {
        if (isstr)
                (void) sprintf(sync_bp, "%d %d %d %s\n",
@@ -191,9 +190,9 @@ out:
 }
 
 sync_update(type, ship, a, b, c, d)
 }
 
 sync_update(type, ship, a, b, c, d)
-int type;
-register struct ship *ship;
-int a, b, c, d;
+       int type;
+       register struct ship *ship;
+       int a, b, c, d;
 {
        switch (type) {
        case W_DBP: {
 {
        switch (type) {
        case W_DBP: {
@@ -253,7 +252,7 @@ int a, b, c, d;
                break;
                }
        case W_SIGNAL:
                break;
                }
        case W_SIGNAL:
-               if (isplayer)
+               if (mode == MODE_PLAYER)
                        Signal("\7%s (%c%c): %s", ship, a);
                break;
        case W_CREW: {
                        Signal("\7%s (%c%c): %s", ship, a);
                break;
        case W_CREW: {