srogue: open the score and log files when the program starts.
Super-Rogue can now use the same privilege-dropping scheme as the other games.
This commit is contained in:
parent
2d3d25c5e9
commit
bc5b26fece
3 changed files with 28 additions and 7 deletions
|
|
@ -54,6 +54,7 @@ int group = NEWGROUP; /* Current group number */
|
||||||
int hungry_state = F_OKAY; /* How hungry is he */
|
int hungry_state = F_OKAY; /* How hungry is he */
|
||||||
int foodlev = 1; /* how fast he eats food */
|
int foodlev = 1; /* how fast he eats food */
|
||||||
int ringfood = 0; /* rings affect on food consumption */
|
int ringfood = 0; /* rings affect on food consumption */
|
||||||
|
int scorefd = -1; /* Scoreboard file descriptor */
|
||||||
char take; /* Thing the rogue is taking */
|
char take; /* Thing the rogue is taking */
|
||||||
char runch; /* Direction player is running */
|
char runch; /* Direction player is running */
|
||||||
char curpurch[15]; /* name of item ready to buy */
|
char curpurch[15]; /* name of item ready to buy */
|
||||||
|
|
@ -101,6 +102,8 @@ char illegal[] = { "Illegal command '%s'." };
|
||||||
char callit[] = { "Call it: " };
|
char callit[] = { "Call it: " };
|
||||||
char starlist[] = { " (* for a list)" };
|
char starlist[] = { " (* for a list)" };
|
||||||
|
|
||||||
|
FILE *logfile = NULL;
|
||||||
|
|
||||||
struct coord oldpos; /* Pos before last look() call */
|
struct coord oldpos; /* Pos before last look() call */
|
||||||
struct coord delta; /* Change indicated to get_dir() */
|
struct coord delta; /* Change indicated to get_dir() */
|
||||||
struct coord stairs; /* where the stairs are put */
|
struct coord stairs; /* where the stairs are put */
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,11 @@
|
||||||
|
|
||||||
#include "rogue.ext"
|
#include "rogue.ext"
|
||||||
|
|
||||||
|
void open_records(void);
|
||||||
|
|
||||||
|
extern int scorefd;
|
||||||
|
extern FILE *logfile;
|
||||||
|
|
||||||
main(argc, argv, envp)
|
main(argc, argv, envp)
|
||||||
char **argv;
|
char **argv;
|
||||||
char **envp;
|
char **envp;
|
||||||
|
|
@ -70,6 +75,7 @@ char **envp;
|
||||||
strcat(scorefile,"/");
|
strcat(scorefile,"/");
|
||||||
strcat(scorefile, "srogue.scr");
|
strcat(scorefile, "srogue.scr");
|
||||||
#endif
|
#endif
|
||||||
|
open_records();
|
||||||
|
|
||||||
if(argc >= 2 && strcmp(argv[1], "-s") == 0)
|
if(argc >= 2 && strcmp(argv[1], "-s") == 0)
|
||||||
{
|
{
|
||||||
|
|
@ -472,3 +478,14 @@ roguehome()
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
open_records(void)
|
||||||
|
{
|
||||||
|
if (scorefd < 0)
|
||||||
|
scorefd = open(scorefile, O_RDWR | O_CREAT, 0666);
|
||||||
|
#ifdef LOGFILE
|
||||||
|
if (logfile == NULL)
|
||||||
|
logfile = fopen(LOGFILE, "a");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
15
srogue/rip.c
15
srogue/rip.c
|
|
@ -47,6 +47,9 @@ static char *rip[] = {
|
||||||
|
|
||||||
#define RIP_LINES (sizeof rip / (sizeof (char *)))
|
#define RIP_LINES (sizeof rip / (sizeof (char *)))
|
||||||
|
|
||||||
|
extern int scorefd;
|
||||||
|
extern FILE *logfile;
|
||||||
|
|
||||||
char *killname();
|
char *killname();
|
||||||
void writelog(int amount, int aflag, char monst);
|
void writelog(int amount, int aflag, char monst);
|
||||||
|
|
||||||
|
|
@ -140,7 +143,7 @@ int amount, aflag;
|
||||||
/*
|
/*
|
||||||
* Open file and read list
|
* Open file and read list
|
||||||
*/
|
*/
|
||||||
if ((fd = open(scorefile, O_RDWR | O_CREAT, 0666)) < 0)
|
if ((fd = scorefd) < 0)
|
||||||
return;
|
return;
|
||||||
outf = (FILE *) fdopen(fd, "w");
|
outf = (FILE *) fdopen(fd, "w");
|
||||||
for (scp = top_ten; scp <= &top_ten[9]; scp++) {
|
for (scp = top_ten; scp <= &top_ten[9]; scp++) {
|
||||||
|
|
@ -221,11 +224,12 @@ void writelog(int amount, int aflag, char monst)
|
||||||
{
|
{
|
||||||
char logmessage[220], ltemp[80], mlev[40];
|
char logmessage[220], ltemp[80], mlev[40];
|
||||||
char *killer;
|
char *killer;
|
||||||
FILE *logfi;
|
|
||||||
|
|
||||||
if (waswizard)
|
if (waswizard)
|
||||||
return;
|
return;
|
||||||
#ifdef LOGFILE
|
#ifdef LOGFILE
|
||||||
|
if (logfile == NULL)
|
||||||
|
return;
|
||||||
sprintf(logmessage, "%d %d %s %d ", time(NULL), amount, whoami,
|
sprintf(logmessage, "%d %d %s %d ", time(NULL), amount, whoami,
|
||||||
him->s_lvl);
|
him->s_lvl);
|
||||||
if (amulet)
|
if (amulet)
|
||||||
|
|
@ -247,11 +251,8 @@ void writelog(int amount, int aflag, char monst)
|
||||||
else
|
else
|
||||||
return;
|
return;
|
||||||
strcat(logmessage, ltemp);
|
strcat(logmessage, ltemp);
|
||||||
logfi = fopen(LOGFILE, "a");
|
fprintf(logfile, "%s", logmessage);
|
||||||
if (logfi == NULL)
|
fclose(logfile);
|
||||||
return;
|
|
||||||
fprintf(logfi, "%s", logmessage);
|
|
||||||
fclose(logfi);
|
|
||||||
#endif
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue