]> git.cameronkatri.com Git - bsdgames-darwin.git/blobdiff - larn/scores.c
typo
[bsdgames-darwin.git] / larn / scores.c
index 71d399e198135cb1a2b71a155ab17aaa89b2288b..49a6f873e1cc5348bc2441b98d2ed3ebd774eb0e 100644 (file)
@@ -1,4 +1,4 @@
-/*     $NetBSD: scores.c,v 1.12 2004/02/13 11:36:08 wiz Exp $  */
+/*     $NetBSD: scores.c,v 1.21 2012/06/19 05:30:44 dholland Exp $     */
 
 /*
  * scores.c                     Larn is copyrighted 1986 by Noah Morgan.
@@ -26,7 +26,7 @@
  */
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: scores.c,v 1.12 2004/02/13 11:36:08 wiz Exp $");
+__RCSID("$NetBSD: scores.c,v 1.21 2012/06/19 05:30:44 dholland Exp $");
 #endif                         /* not lint */
 #include <sys/types.h>
 #include <sys/times.h>
@@ -64,7 +64,7 @@ struct wscofmt {              /* This is the structure for the winning
 
 struct log_fmt {               /* 102 bytes struct for the log file                             */
        long            score;  /* the players score                                                             */
-       time_t          diedtime;       /* time when game was over                                                       */
+       int32_t          diedtime;      /* time when game was over                                                       */
        short           cavelev;/* level in caves                                                                        */
        short           diff;   /* difficulty player played at                                           */
 #ifdef EXTRA
@@ -86,7 +86,7 @@ struct log_fmt {              /* 102 bytes struct for the log file                             */
 static struct scofmt sco[SCORESIZE];   /* the structure for the scoreboard  */
 static struct wscofmt winr[SCORESIZE]; /* struct for the winning scoreboard */
 static struct log_fmt logg;    /* structure for the log file            */
-static char    *whydead[] = {
+static const char *whydead[] = {
        "quit", "suspended", "self - annihilated", "shot by an arrow",
        "hit by a dart", "fell into a pit", "fell into a bottomless pit",
        "a winner", "trapped in solid rock", "killed by a missing save file",
@@ -102,19 +102,31 @@ static char    *whydead[] = {
        "died a post mortem death", "wasted by a malloc() failure"
 };
 
+static int readboard(void);
+static int writeboard(void);
+static int winshou(void);
+static int shou(int);
+static int sortboard(void);
+static void newscore(long, char *, int, int);
+static void new1sub(long, int, char *, long);
+static void new2sub(long, int, char *, int);
+static void diedsub(int);
+
 /*
  * readboard()         Function to read in the scoreboard into a static buffer
  *
  * returns -1 if unable to read in the scoreboard, returns 0 if all is OK
  */
-int
-readboard()
+static int
+readboard(void)
 {
        int             i;
 
-       seteuid(euid);
+       if (gid != egid)
+               setegid(egid);
        i = lopen(scorefile);
-       seteuid(uid);
+       if (gid != egid)
+               setegid(gid);
        if (i < 0) {
                lprcat("Can't read scoreboard\n");
                lflush();
@@ -132,15 +144,17 @@ readboard()
  *
  * returns -1 if unable to write the scoreboard, returns 0 if all is OK
  */
-int
-writeboard()
+static int
+writeboard(void)
 {
        int             i;
 
        set_score_output();
-       seteuid(euid);
+       if (gid != egid)
+               setegid(egid);
        i = lcreat(scorefile);
-       seteuid(uid);
+       if (gid != egid)
+               setegid(gid);
        if (i < 0) {
                lprcat("Can't write scoreboard\n");
                lflush();
@@ -159,18 +173,21 @@ writeboard()
  * returns -1 if unable to write the scoreboard, returns 0 if all is OK
  */
 int
-makeboard()
+makeboard(void)
 {
        int    i;
+       set_score_output();
        for (i = 0; i < SCORESIZE; i++) {
                winr[i].taxes = winr[i].score = sco[i].score = 0;
                winr[i].order = sco[i].order = i;
        }
        if (writeboard())
                return (-1);
-       seteuid(euid);
+       if (gid != egid)
+               setegid(egid);
        chmod(scorefile, 0660);
-       seteuid(uid);
+       if (gid != egid)
+               setegid(gid);
        return (0);
 }
 
@@ -183,7 +200,7 @@ makeboard()
  * the winners scoreboard.
  */
 int
-hashewon()
+hashewon(void)
 {
        int    i;
        c[HARDGAME] = 0;
@@ -206,8 +223,7 @@ hashewon()
  * Returns amount actually paid.
  */
 long 
-paytaxes(x)
-       long            x;
+paytaxes(long x)
 {
        int    i;
        long   amt;
@@ -226,6 +242,7 @@ paytaxes(x)
                                                         * (Ughhhhh) */
                                winr[i].taxes -= amt;
                                outstanding_taxes -= amt;
+                               set_score_output();
                                if (writeboard() < 0)
                                        return (0);
                                return (amt);
@@ -238,8 +255,8 @@ paytaxes(x)
  *
  * Returns the number of players on scoreboard that were shown
  */
-int
-winshou()
+static int
+winshou(void)
 {
        struct wscofmt *p;
        int    i, j, count;
@@ -260,7 +277,7 @@ winshou()
                                if (p->order == i) {
                                        if (p->score) {
                                                count++;
-                                               lprintf("%10d     %2d      %5d Mobuls   %s \n",
+                                               lprintf("%10ld     %2ld      %5ld Mobuls   %s \n",
                                                        (long) p->score, (long) p->hardlev, (long) p->timeused, p->who);
                                        }
                                        break;
@@ -277,9 +294,8 @@ winshou()
  * Enter with 0 to list the scores, enter with 1 to list inventories too
  * Returns the number of players on scoreboard that were shown
  */
-int
-shou(x)
-       int             x;
+static int
+shou(int x)
 {
        int    i, j, n, k;
        int             count;
@@ -297,7 +313,7 @@ shou(x)
                                if (sco[j].order == i) {
                                        if (sco[j].score) {
                                                count++;
-                                               lprintf("%10d     %2d       %s ",
+                                               lprintf("%10ld     %2ld       %s ",
                                                        (long) sco[j].score, (long) sco[j].hardlev, sco[j].who);
                                                if (sco[j].what < 256)
                                                        lprintf("killed by a %s", monster[sco[j].what].name);
@@ -333,7 +349,7 @@ shou(x)
  */
 static char     esb[] = "The scoreboard is empty.\n";
 void
-showscores()
+showscores(void)
 {
        int    i, j;
        lflush();
@@ -355,7 +371,7 @@ showscores()
  * Returns nothing of value
  */
 void
-showallscores()
+showallscores(void)
 {
        int    i, j;
        lflush();
@@ -382,8 +398,8 @@ showallscores()
  *
  * Returns 0 if no sorting done, else returns 1
  */
-int
-sortboard()
+static int
+sortboard(void)
 {
        int    i, j = 0, pos;
        long            jdat;
@@ -421,11 +437,8 @@ sortboard()
  *     died() reason # in whyded, and TRUE/FALSE in winner if a winner
  * ex.         newscore(1000, "player 1", 32, 0);
  */
-void
-newscore(score, whoo, whyded, winner)
-       long            score;
-       int             winner, whyded;
-       char           *whoo;
+static void
+newscore(long score, char *whoo, int whyded, int winner)
 {
        int    i;
        long            taxes;
@@ -490,11 +503,8 @@ newscore(score, whoo, whyded, winner)
  *     slot in scoreboard in i, and the tax bill in taxes.
  * Returns nothing of value
  */
-void
-new1sub(score, i, whoo, taxes)
-       long            score, taxes;
-       int             i;
-       char           *whoo;
+static void
+new1sub(long score, int i, char *whoo, long taxes)
 {
        struct wscofmt *p;
        p = &winr[i];
@@ -517,11 +527,8 @@ new1sub(score, i, whoo, taxes)
  *     died() reason # in whyded, and slot in scoreboard in i.
  * Returns nothing of value
  */
-void
-new2sub(score, i, whoo, whyded)
-       long            score;
-       int             i, whyded;
-       char           *whoo;
+static void
+new2sub(long score, int i, char *whoo, int whyded)
 {
        int    j;
        struct scofmt *p;
@@ -583,11 +590,11 @@ new2sub(score, i, whoo, whyded)
 
 static int      scorerror;
 void
-died(x)
-       int             x;
+died(int x)
 {
        int    f, win;
-       char            ch, *mod;
+       char            ch;
+       const char     *mod;
        time_t          zzz;
        if (c[LIFEPROT] > 0) {  /* if life protection */
                switch ((x > 0) ? x : -x) {
@@ -643,7 +650,8 @@ invalid:
        set_score_output();
        if ((wizard == 0) && (c[GOLD] > 0)) {   /* wizards can't score           */
 #ifndef NOLOG
-               seteuid(euid);
+               if (gid != egid)
+                       setegid(egid);
                if (lappend(logfile) < 0) {     /* append to file */
                        if (lcreat(logfile) < 0) {      /* and can't create new
                                                         * log file */
@@ -654,11 +662,14 @@ invalid:
                                lflush();
                                exit(0);
                        }
-                       seteuid(euid);
+                       if (gid != egid)
+                               setegid(egid);
                        chmod(logfile, 0660);
-                       seteuid(uid);
+                       if (gid != egid)
+                               setegid(gid);
                }
-               seteuid(uid);
+               if (gid != egid)
+                       setegid(gid);
                strcpy(logg.who, loginname);
                logg.score = c[GOLD];
                logg.diff = c[HARDGAME];
@@ -700,8 +711,10 @@ invalid:
                 * game
                 */
                if (x != 257) {
-                       if (sortboard())
+                       if (sortboard()) {
+                               set_score_output();
                                scorerror = writeboard();
+                       }
                }
        }
        if ((x == 256) || (x == 257) || (f != 0))
@@ -717,12 +730,13 @@ invalid:
  * diedsub(x) Subroutine to print out the line showing the player when he is killed
  *     int x;
  */
-void
-diedsub(x)
-       int             x;
+static void
+diedsub(int x)
 {
-       char   ch, *mod;
-       lprintf("Score: %d, Diff: %d,  %s ", (long) c[GOLD], (long) c[HARDGAME], logname);
+       char   ch;
+       const char *mod;
+
+       lprintf("Score: %ld, Diff: %ld,  %s ", (long) c[GOLD], (long) c[HARDGAME], logname);
        if (x < 256) {
                ch = *monster[x].name;
                if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')
@@ -742,33 +756,40 @@ diedsub(x)
  * diedlog()   Subroutine to read a log file and print it out in ascii format
  */
 void
-diedlog()
+diedlog(void)
 {
        int    n;
        char  *p;
+       static char  q[] = "?";
        struct stat     stbuf;
+       time_t t;
+
        lcreat((char *) 0);
        if (lopen(logfile) < 0) {
                lprintf("Can't locate log file <%s>\n", logfile);
                return;
        }
-       if (fstat(fd, &stbuf) < 0) {
+       if (fstat(io_infd, &stbuf) < 0) {
                lprintf("Can't  stat log file <%s>\n", logfile);
                return;
        }
        for (n = stbuf.st_size / sizeof(struct log_fmt); n > 0; --n) {
                lrfill((char *) &logg, sizeof(struct log_fmt));
-               p = ctime(&logg.diedtime);
-               p[16] = '\n';
-               p[17] = 0;
-               lprintf("Score: %d, Diff: %d,  %s %s on %d at %s", (long) (logg.score), (long) (logg.diff), logg.who, logg.what, (long) (logg.cavelev), p + 4);
+               t = logg.diedtime;
+               if ((p = ctime(&t)) == NULL)
+                       p = q;
+               else {
+                       p[16] = '\n';
+                       p[17] = 0;
+               }
+               lprintf("Score: %ld, Diff: %ld,  %s %s on %ld at %s", (long) (logg.score), (long) (logg.diff), logg.who, logg.what, (long) (logg.cavelev), p + 4);
 #ifdef EXTRA
                if (logg.moves <= 0)
                        logg.moves = 1;
-               lprintf("  Experience Level: %d,  AC: %d,  HP: %d/%d,  Elapsed Time: %d minutes\n", (long) (logg.lev), (long) (logg.ac), (long) (logg.hp), (long) (logg.hpmax), (long) (logg.elapsedtime));
-               lprintf("  CPU time used: %d seconds,  Machine usage: %d.%02d%%\n", (long) (logg.cputime), (long) (logg.usage / 100), (long) (logg.usage % 100));
-               lprintf("  BYTES in: %d, out: %d, moves: %d, deaths: %d, spells cast: %d\n", (long) (logg.bytin), (long) (logg.bytout), (long) (logg.moves), (long) (logg.killed), (long) (logg.spused));
-               lprintf("  out bytes per move: %d,  time per move: %d ms\n", (long) (logg.bytout / logg.moves), (long) ((logg.cputime * 1000) / logg.moves));
+               lprintf("  Experience Level: %ld,  AC: %ld,  HP: %ld/%ld,  Elapsed Time: %ld minutes\n", (long) (logg.lev), (long) (logg.ac), (long) (logg.hp), (long) (logg.hpmax), (long) (logg.elapsedtime));
+               lprintf("  CPU time used: %ld seconds,  Machine usage: %ld.%02ld%%\n", (long) (logg.cputime), (long) (logg.usage / 100), (long) (logg.usage % 100));
+               lprintf("  BYTES in: %ld, out: %ld, moves: %ld, deaths: %ld, spells cast: %ld\n", (long) (logg.bytin), (long) (logg.bytout), (long) (logg.moves), (long) (logg.killed), (long) (logg.spused));
+               lprintf("  out bytes per move: %ld,  time per move: %ld ms\n", (long) (logg.bytout / logg.moves), (long) ((logg.cputime * 1000) / logg.moves));
 #endif
        }
        lflush();
@@ -801,7 +822,7 @@ getplid(nam)
        lflush();               /* flush any pending I/O */
        snprintf(name, sizeof(name), "%s\n", nam);/* append a \n to name */
        if (lopen(playerids) < 0) {     /* no file, make it */
-               if ((fd7 = creat(playerids, 0666)) < 0)
+               if ((fd7 = creat(playerids, 0664)) < 0)
                        return (-1);    /* can't make it */
                close(fd7);
                goto addone;    /* now append new playerid record to file */
@@ -826,7 +847,7 @@ getplid(nam)
 addone:
        if (lappend(playerids) < 0)
                return (-1);    /* can't open file for append */
-       lprintf("%d\n%s", (long) ++high, name); /* new id # and name */
+       lprintf("%ld\n%s", (long) ++high, name);        /* new id # and name */
        lwclose();
        lcreat((char *) 0);     /* re-open terminal channel */
        return (high);