/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* hack.main.c - version 1.0.3 */
extern char *getlogin(), *getenv();
extern char plname
[PL_NSIZ
], pl_character
[PL_CSIZ
];
extern struct permonst mons
[CMNUM
+2];
extern char genocided
[], fut_geno
[];
char *occtxt
; /* defined when occupation != NULL */
int hackpid
; /* current pid */
int locknum
; /* max num of players */
char *catmore
; /* default pager */
char SAVEF
[PL_NSIZ
+ 11] = "save/"; /* save/99999player */
char *hname
; /* name of the game (argv[0] of call) */
char obuf
[BUFSIZ
]; /* BUFSIZ is defined in stdio.h */
#ifdef CHDIR /* otherwise no chdir() */
* See if we must change directory to the playground.
* (Perhaps hack runs suid and playground is inaccessible
* The environment variable HACKDIR is overridden by a
* -d command line option (must be the first option given)
if(argc
> 1 && !strncmp(argv
[1], "-d", 2)) {
if(*dir
== '=' || *dir
== ':') dir
++;
error("Flag -d must be followed by a directory name.");
* Who am i? Algorithm: 1. Use name as specified in HACKOPTIONS
* 2. Use $USER or $LOGNAME (if 1. fails)
* 3. Use getlogin() (if 2. fails)
* The resulting name is overridden by command line options.
* If everything fails, or if the resulting name is some generic
* account like "games", "play", "player", "hack" then eventually
* Note that we trust him here; it is possible to play under
if(!*plname
&& (s
= getenv("USER")))
(void) strncpy(plname
, s
, sizeof(plname
)-1);
if(!*plname
&& (s
= getenv("LOGNAME")))
(void) strncpy(plname
, s
, sizeof(plname
)-1);
if(!*plname
&& (s
= getlogin()))
(void) strncpy(plname
, s
, sizeof(plname
)-1);
* Now we know the directory containing 'record' and
if(argc
> 1 && !strncmp(argv
[1], "-s", 2)) {
* It seems he really wants to play.
* Remember tty modes, to be restored on exit.
u
.uhp
= 1; /* prevent RIP on early quits */
u
.ux
= FAR
; /* prevent nscr() */
(void) signal(SIGHUP
, hangup
);
* Find the creation date of this game,
* so as to avoid restoring outdated savefiles.
* We cannot do chdir earlier, otherwise gethdate will fail.
while(argc
> 1 && argv
[1][0] == '-'){
/* if(!strcmp(getlogin(), WIZARD)) */
(void) strncpy(plname
, argv
[0]+2, sizeof(plname
)-1);
(void) strncpy(plname
, argv
[0], sizeof(plname
)-1);
printf("Player name expected after -u\n");
/* allow -T for Tourist, etc. */
(void) strncpy(pl_character
, argv
[0]+1,
/* printf("Unknown option: %s\n", *argv); */
if(!locknum
|| locknum
> MAX_NR_OF_PLAYERS
)
locknum
= MAX_NR_OF_PLAYERS
;
if(!(catmore
= getenv("HACKPAGER")) && !(catmore
= getenv("PAGER")))
if(wizard
) (void) strcpy(plname
, "wizard"); else
if(!*plname
|| !strncmp(plname
, "player", 4)
|| !strncmp(plname
, "games", 4))
plnamesuffix(); /* strip suffix from name; calls askname() */
/* again if suffix was whole name */
* check for multiple games under the same name
* (if !locknum) or check max nr of players (otherwise)
(void) signal(SIGQUIT
,SIG_IGN
);
(void) signal(SIGINT
,SIG_IGN
);
(void) strcpy(lock
,plname
);
getlock(); /* sets lock if locknum != 0 */
(void) strcpy(lock
,plname
);
if(sfoo
= getenv("MAGIC"))
case 'n': (void) srandom(*sfoo
++);
if(sfoo
= getenv("GENOCIDED")){
register struct permonst
*pm
= mons
;
register char *gp
= genocided
;
while(pm
< mons
+CMNUM
+2){
if(!index(sfoo
, pm
->mlet
))
(void) strcpy(genocided
, sfoo
);
(void) strcpy(fut_geno
, genocided
);
(void) sprintf(SAVEF
, "save/%d%s", getuid(), plname
);
regularize(SAVEF
+5); /* avoid . or / in name */
if((fd
= open(SAVEF
,0)) >= 0 &&
(uptodate(fd
) || unlink(SAVEF
) == 666)) {
(void) signal(SIGINT
,done1
);
pline("Restoring old save file...");
pline("Hello %s, welcome to %s!", plname
, gamename
);
fobj
= fcobj
= invent
= 0;
(void) signal(SIGINT
,done1
);
{ register struct monst
*mtmp
;
if(mtmp
= m_at(u
.ux
, u
.uy
)) mnexto(mtmp
); /* riv05!a3 */
if(flags
.nonews
|| !readnews())
/* after reading news we did docrt() already */
/* give welcome message before pickup messages */
pline("Hello %s, welcome to %s!", plname
, gamename
);
flags
.moonphase
= phase_of_the_moon();
if(flags
.moonphase
== FULL_MOON
) {
pline("You are lucky! Full moon tonight.");
} else if(flags
.moonphase
== NEW_MOON
) {
pline("Be careful! New moon tonight.");
if(flags
.move
) { /* actual time passed */
(!(Fast
& ~INTRINSIC
) && (!Fast
|| rn2(3)))) {
extern struct monst
*makemon();
(void) makemon((struct permonst
*)0, 0, 0);
if(flags
.time
) flags
.botl
= 1;
if(u
.uhp
*10 < u
.uhpmax
&& moves
-wailmsg
> 50){
pline("You hear the wailing of the Banshee...");
pline("You hear the howling of the CwnAnnwn...");
if(Regeneration
|| !(moves
%3)) {
u
.uhp
+= rnd((int) u
.ulevel
-9);
} else if(Regeneration
||
(!(moves
%(22-u
.ulevel
*2)))) {
if(Teleportation
&& !rn2(85)) tele();
if(Searching
&& multi
>= 0) (void) dosearch();
pline(nomovemsg
? nomovemsg
:
if(afternmv
) (*afternmv
)();
if(flags
.botl
|| flags
.botlx
) bot();
if(multi
>= 0 && occupation
) {
else if ((*occupation
)() == 0)
if(flags
.run
>= 4) finddir();
if(!multi
) { /* lookaround may clear multi */
if(multi
< COLNO
&& !--multi
)
flags
.mv
= flags
.run
= 0;
if(multi
&& multi
%7 == 0)
/* construct the string xlock.n */
while(*tf
&& *tf
!= '.') tf
++;
(void) sprintf(tf
, ".%d", foo
);
* plname is filled either by an option (-u Player or -uPlayer) or
* explicitly (-w implies wizard) or by askname.
* It may still contain a suffix denoting pl_character.
printf("\nWho are you? ");
while((c
= getchar()) != '\n'){
if(c
== EOF
) error("End of input\n");
/* some people get confused when their erase char is not ^H */
if(c
< 'A' || (c
> 'Z' && c
< 'a') || c
> 'z') c
= '_';
if(ct
< sizeof(plname
)-1) plname
[ct
++] = c
;
pline("Program in disorder - perhaps you'd better Quit.");
if(dir
/* User specified directory? */
&& strcmp(dir
, HACKDIR
) /* and not the default? */
(void) setuid(getuid()); /* Ron Wessels */
if(dir
&& chdir(dir
) < 0) {
error("Cannot chdir to %s.", dir
);
/* warn the player if he cannot write the record file */
/* perhaps we should also test whether . is writable */
/* unfortunately the access systemcall is worthless */
if((fd
= open(RECORD
, 2)) < 0) {
printf("Warning: cannot write %s/%s", dir
, RECORD
);
pline("You stop %s.", occtxt
);