-/* $NetBSD: scores.c,v 1.15 2008/01/28 05:38:54 dholland Exp $ */
+/* $NetBSD: scores.c,v 1.21 2012/06/19 05:30:44 dholland Exp $ */
/*
* scores.c Larn is copyrighted 1986 by Noah Morgan.
*/
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: scores.c,v 1.15 2008/01/28 05:38:54 dholland 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>
#include "header.h"
#include "extern.h"
+#include <time.h>
+
struct scofmt { /* This is the structure for the scoreboard */
long score; /* the score of the player */
long suid; /* the user id number of the player */
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
"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;
- if (uid != euid)
- seteuid(euid);
+ if (gid != egid)
+ setegid(egid);
i = lopen(scorefile);
- if (uid != euid)
- seteuid(uid);
+ if (gid != egid)
+ setegid(gid);
if (i < 0) {
lprcat("Can't read scoreboard\n");
lflush();
*
* 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();
- if (uid != euid)
- seteuid(euid);
+ if (gid != egid)
+ setegid(egid);
i = lcreat(scorefile);
- if (uid != euid)
- seteuid(uid);
+ if (gid != egid)
+ setegid(gid);
if (i < 0) {
lprcat("Can't write scoreboard\n");
lflush();
* returns -1 if unable to write the scoreboard, returns 0 if all is OK
*/
int
-makeboard()
+makeboard(void)
{
int i;
set_score_output();
}
if (writeboard())
return (-1);
- if (uid != euid)
- seteuid(euid);
+ if (gid != egid)
+ setegid(egid);
chmod(scorefile, 0660);
- if (uid != euid)
- seteuid(uid);
+ if (gid != egid)
+ setegid(gid);
return (0);
}
* the winners scoreboard.
*/
int
-hashewon()
+hashewon(void)
{
int i;
c[HARDGAME] = 0;
* Returns amount actually paid.
*/
long
-paytaxes(x)
- long x;
+paytaxes(long x)
{
int i;
long amt;
*
* Returns the number of players on scoreboard that were shown
*/
-int
-winshou()
+static int
+winshou(void)
{
struct wscofmt *p;
int i, j, count;
* 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;
*/
static char esb[] = "The scoreboard is empty.\n";
void
-showscores()
+showscores(void)
{
int i, j;
lflush();
* Returns nothing of value
*/
void
-showallscores()
+showallscores(void)
{
int i, j;
lflush();
*
* Returns 0 if no sorting done, else returns 1
*/
-int
-sortboard()
+static int
+sortboard(void)
{
int i, j = 0, pos;
long jdat;
* 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;
* 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];
* 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;
static int scorerror;
void
-died(x)
- int x;
+died(int x)
{
int f, win;
char ch;
set_score_output();
if ((wizard == 0) && (c[GOLD] > 0)) { /* wizards can't score */
#ifndef NOLOG
- if (uid != euid)
- 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 */
lflush();
exit(0);
}
- if (uid != euid)
- seteuid(euid);
+ if (gid != egid)
+ setegid(egid);
chmod(logfile, 0660);
- if (uid != euid)
- seteuid(uid);
+ if (gid != egid)
+ setegid(gid);
}
- if (uid != euid)
- seteuid(uid);
+ if (gid != egid)
+ setegid(gid);
strcpy(logg.who, loginname);
logg.score = c[GOLD];
logg.diff = c[HARDGAME];
* diedsub(x) Subroutine to print out the line showing the player when he is killed
* int x;
*/
-void
+static void
diedsub(int x)
{
char ch;
* 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);
}
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;
+ 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)
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 */