Merge Super-Rogue fixes into the MSVC testing branch.
This commit is contained in:
commit
0b952fe136
6 changed files with 46 additions and 100 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;
|
||||||
|
|
@ -64,12 +69,15 @@ char **envp;
|
||||||
scorefile[LINLEN - 1] = '\0';
|
scorefile[LINLEN - 1] = '\0';
|
||||||
#else
|
#else
|
||||||
|
|
||||||
strcpy(scorefile, homedir);
|
strncpy(scorefile, homedir, LINLEN-11);
|
||||||
|
if (scorefile[LINLEN-12] != '\0')
|
||||||
|
scorefile[0] = '\0';
|
||||||
|
|
||||||
if (*scorefile)
|
if (*scorefile)
|
||||||
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)
|
||||||
{
|
{
|
||||||
|
|
@ -115,7 +123,7 @@ char **envp;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!use_savedir)
|
if (!use_savedir)
|
||||||
md_droppriv();
|
md_normaluser();
|
||||||
|
|
||||||
/* get home and options from environment */
|
/* get home and options from environment */
|
||||||
|
|
||||||
|
|
@ -438,24 +446,26 @@ directory_exists(char *dirname)
|
||||||
char *
|
char *
|
||||||
roguehome()
|
roguehome()
|
||||||
{
|
{
|
||||||
static char path[1024];
|
static char path[LINLEN+16];
|
||||||
char *end,*home;
|
char *end,*home;
|
||||||
|
|
||||||
if ( (home = getenv("ROGUEHOME")) != NULL)
|
if ( (home = getenv("ROGUEHOME")) != NULL)
|
||||||
{
|
{
|
||||||
if (*home)
|
if (*home)
|
||||||
{
|
{
|
||||||
strncpy(path, home, PATH_MAX - 20);
|
/* LINLEN - 11 is all that will fit into scorefile */
|
||||||
|
strncpy(path, home, LINLEN - 11);
|
||||||
|
if (path[LINLEN - 12] == '\0')
|
||||||
|
{
|
||||||
end = &path[strlen(path)-1];
|
end = &path[strlen(path)-1];
|
||||||
|
|
||||||
|
|
||||||
while( (end >= path) && ((*end == '/') || (*end == '\\')))
|
while( (end >= path) && ((*end == '/') || (*end == '\\')))
|
||||||
*end-- = '\0';
|
*end-- = '\0';
|
||||||
|
|
||||||
if (directory_exists(path))
|
if (directory_exists(path))
|
||||||
return(path);
|
return(path);
|
||||||
}
|
}
|
||||||
|
/* Otherwise home was truncated and should be ignored */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (directory_exists("/var/games/roguelike"))
|
if (directory_exists("/var/games/roguelike"))
|
||||||
|
|
@ -472,3 +482,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
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1533,41 +1533,6 @@ md_memused(void)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
md_droppriv(void)
|
|
||||||
{
|
|
||||||
#if defined(HAVE_GETUID)
|
|
||||||
uid_t realuid = getuid();
|
|
||||||
|
|
||||||
#if defined(HAVE_SETRESUID)
|
|
||||||
if (setresuid(-1, realuid, realuid) != 0) {
|
|
||||||
#elif defined (HAVE_SETREUID)
|
|
||||||
if (setreuid(realuid, realuid) != 0) {
|
|
||||||
#elif defined (HAVE_SETUID)
|
|
||||||
if (setuid(realuid) != 0) {
|
|
||||||
#else
|
|
||||||
if (0) {
|
|
||||||
#endif
|
|
||||||
printf("Cannot change to effective uid: %d\n", realuid);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
extern uid_t playuid;
|
|
||||||
extern gid_t playgid;
|
|
||||||
|
|
||||||
void
|
|
||||||
md_resetpriv(void)
|
|
||||||
{
|
|
||||||
#if defined (HAVE_SETUID)
|
|
||||||
setuid(playuid);
|
|
||||||
#endif
|
|
||||||
#if defined (HAVE_SETGID)
|
|
||||||
setgid(playgid);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
int
|
||||||
md_random(void)
|
md_random(void)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -69,8 +69,6 @@ void md_onsignal_exit(void);
|
||||||
void md_onsignal_default(void);
|
void md_onsignal_default(void);
|
||||||
int md_issymlink(char *sp);
|
int md_issymlink(char *sp);
|
||||||
long md_memused(void);
|
long md_memused(void);
|
||||||
void md_droppriv(void);
|
|
||||||
void md_resetpriv(void);
|
|
||||||
int md_random(void);
|
int md_random(void);
|
||||||
void md_srandom(unsigned int seed);
|
void md_srandom(unsigned int seed);
|
||||||
char *xcrypt(const char *key, const char *setting);
|
char *xcrypt(const char *key, const char *setting);
|
||||||
|
|
|
||||||
|
|
@ -131,17 +131,13 @@ game_err(int a)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* dosave:
|
* dosave:
|
||||||
* Set UID back to user and save the game
|
* Save the game. UID/GID no longer get reset here.
|
||||||
*/
|
*/
|
||||||
dosave()
|
dosave()
|
||||||
{
|
{
|
||||||
FILE *savef;
|
FILE *savef;
|
||||||
|
|
||||||
ignore();
|
ignore();
|
||||||
if (!use_savedir)
|
|
||||||
{
|
|
||||||
md_resetpriv();
|
|
||||||
}
|
|
||||||
umask(022);
|
umask(022);
|
||||||
|
|
||||||
if (file_name[0] != '\0') {
|
if (file_name[0] != '\0') {
|
||||||
|
|
@ -287,51 +283,13 @@ char *file, **envp;
|
||||||
#endif
|
#endif
|
||||||
if (!wizard)
|
if (!wizard)
|
||||||
{
|
{
|
||||||
#if defined(HAVE_WORKING_FORK)
|
if (unlink(file) < 0)
|
||||||
|
{
|
||||||
endwin();
|
endwin();
|
||||||
if (!use_savedir)
|
|
||||||
{
|
|
||||||
while((pid = fork()) < 0)
|
|
||||||
sleep(1);
|
|
||||||
|
|
||||||
/* set id to unlink file */
|
|
||||||
if(pid == 0)
|
|
||||||
{
|
|
||||||
md_resetpriv();
|
|
||||||
unlink(file);
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
/* wait for unlink to finish */
|
|
||||||
else
|
|
||||||
{
|
|
||||||
while(wait(&ret_status) != pid)
|
|
||||||
continue;
|
|
||||||
if (ret_status < 0)
|
|
||||||
{
|
|
||||||
printf("Cannot unlink file\n");
|
printf("Cannot unlink file\n");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Don't drop privileges, they're needed
|
|
||||||
* for the unlink. */
|
|
||||||
if (unlink(file) < 0)
|
|
||||||
{
|
|
||||||
printf("Cannot unlink file\n");
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
if (unlink(file) < 0)
|
|
||||||
{
|
|
||||||
printf("Cannot unlink file\n");
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (him->s_hpt <= 0) {
|
if (him->s_hpt <= 0) {
|
||||||
endwin();
|
endwin();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue