diff options
author | 2001-02-04 02:51:23 +0000 | |
---|---|---|
committer | 2001-02-04 02:51:23 +0000 | |
commit | 921320ab53c9f345bb84a9d4574e555414b5042c (patch) | |
tree | a8a4eab99f8bdddc9d69f1c1ae524a97ae7b6596 | |
parent | Format for long usernames (diff) | |
download | wireguard-openbsd-921320ab53c9f345bb84a9d4574e555414b5042c.tar.xz wireguard-openbsd-921320ab53c9f345bb84a9d4574e555414b5042c.zip |
Tidy, avoid segfaults on unknown users, and deal with long usernames
-rw-r--r-- | games/phantasia/include.h | 5 | ||||
-rw-r--r-- | games/phantasia/main.c | 21 | ||||
-rw-r--r-- | games/phantasia/misc.c | 4 | ||||
-rw-r--r-- | games/phantasia/phantdefs.h | 145 | ||||
-rw-r--r-- | games/phantasia/phantstruct.h | 6 |
5 files changed, 94 insertions, 87 deletions
diff --git a/games/phantasia/include.h b/games/phantasia/include.h index 447856657ad..b8b874093ef 100644 --- a/games/phantasia/include.h +++ b/games/phantasia/include.h @@ -1,12 +1,15 @@ -/* $OpenBSD: include.h,v 1.2 1998/11/29 19:56:56 pjanzen Exp $ */ +/* $OpenBSD: include.h,v 1.3 2001/02/04 02:51:23 pjanzen Exp $ */ /* $NetBSD: include.h,v 1.3 1995/04/24 12:24:31 cgd Exp $ */ /* * include.h - includes all important files for Phantasia */ +#include <sys/param.h> + #include <ctype.h> #include <curses.h> +#include <err.h> #include <errno.h> #include <math.h> #include <setjmp.h> diff --git a/games/phantasia/main.c b/games/phantasia/main.c index 67372748eaa..4549f0fe5cf 100644 --- a/games/phantasia/main.c +++ b/games/phantasia/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.7 2000/06/29 07:39:45 pjanzen Exp $ */ +/* $OpenBSD: main.c,v 1.8 2001/02/04 02:51:24 pjanzen Exp $ */ /* $NetBSD: main.c,v 1.3 1995/04/24 12:24:37 cgd Exp $ */ /* @@ -54,8 +54,6 @@ * to be updated. */ -/**/ - /* * main.c Main routines for Phantasia */ @@ -196,7 +194,7 @@ main(argc, argv) Timeout = TRUE; /* update some important player statistics */ - strcpy(Player.p_login, Login); + strlcpy(Player.p_login, Login, MAXLOGNAME); time(&seconds); Player.p_lastused = localtime(&seconds)->tm_yday; Player.p_status = S_PLAYING; @@ -345,6 +343,17 @@ initialstate() Windows = FALSE; Echo = TRUE; + /* setup login name */ + if ((Login = getlogin()) == NULL) { + struct passwd *gpwd; + + gpwd = getpwuid(getuid()); + if (gpwd != NULL) + Login = gpwd->pw_name; + else + errx(1, "Who are you?"); + } + #ifdef TERMIOS /* setup terminal keys */ if (tcgetattr(0, &tty) == 0) { @@ -359,10 +368,6 @@ initialstate() Ch_Kill = CH_KILL; #endif - /* setup login name */ - if ((Login = getlogin()) == NULL) - Login = getpwuid(getuid())->pw_name; - /* open some files */ if ((Playersfp = fopen(_PATH_PEOPLE, "r+")) == NULL) error(_PATH_PEOPLE); diff --git a/games/phantasia/misc.c b/games/phantasia/misc.c index e4297236337..b943effdfb9 100644 --- a/games/phantasia/misc.c +++ b/games/phantasia/misc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: misc.c,v 1.6 2000/06/29 07:39:45 pjanzen Exp $ */ +/* $OpenBSD: misc.c,v 1.7 2001/02/04 02:51:25 pjanzen Exp $ */ /* $NetBSD: misc.c,v 1.2 1995/03/24 03:59:03 cgd Exp $ */ /* @@ -1392,7 +1392,7 @@ readmessage() / / FUNCTION NAME: error() / -/ FUNCTION: process evironment error +/ FUNCTION: process environment error / / AUTHOR: E. A. Estes, 12/4/85 / diff --git a/games/phantasia/phantdefs.h b/games/phantasia/phantdefs.h index ef571b7f7a7..6e06cff9ffe 100644 --- a/games/phantasia/phantdefs.h +++ b/games/phantasia/phantdefs.h @@ -1,4 +1,4 @@ -/* $OpenBSD: phantdefs.h,v 1.3 1998/11/29 19:57:01 pjanzen Exp $ */ +/* $OpenBSD: phantdefs.h,v 1.4 2001/02/04 02:51:25 pjanzen Exp $ */ /* $NetBSD: phantdefs.h,v 1.2 1995/03/24 03:59:28 cgd Exp $ */ /* @@ -13,14 +13,14 @@ #define R_SPOILED 4 /* ring which has gone bad */ /* status constants */ -#define S_NOTUSED 0 /* record not in use */ +#define S_NOTUSED 0 /* record not in use */ #define S_OFF 1 /* not playing */ #define S_PLAYING 2 /* playing - nothing else */ #define S_CLOAKED 3 /* playing - cloaked */ #define S_INBATTLE 4 /* playing - in battle */ #define S_MONSTER 5 /* playing - fighting monster */ -#define S_TRADING 6 /* playing - at a trading post */ -#define S_HUNGUP 7 /* error occured with character */ +#define S_TRADING 6 /* playing - at a trading post */ +#define S_HUNGUP 7 /* error occured with character */ /* tampered constants */ #define T_OFF 0 /* nothing */ @@ -37,15 +37,15 @@ #define T_EXVALAR 11 /* no longer valar */ /* inter-terminal battle status constants */ -#define I_OFF 0 /* nothing */ -#define I_RAN 1 /* ran away */ -#define I_STUCK 2 /* tried to run unsuccessfully */ -#define I_BLEWIT 3 /* tried to luckout unsuccessfully */ -#define I_KILLED 4 /* killed foe */ +#define I_OFF 0 /* nothing */ +#define I_RAN 1 /* ran away */ +#define I_STUCK 2 /* tried to run unsuccessfully */ +#define I_BLEWIT 3 /* tried to luckout unsuccessfully */ +#define I_KILLED 4 /* killed foe */ /* constants for altering coordinates */ -#define A_SPECIFIC 0 /* coordinates specified */ -#define A_FORCED 1 /* coordinates specified, ignore Beyond */ +#define A_SPECIFIC 0 /* coordinates specified */ +#define A_FORCED 1 /* coordinates specified, ignore Beyond */ #define A_NEAR 2 /* coordinates not specified, move near */ #define A_FAR 3 /* coordinates not specified, move far */ @@ -60,84 +60,83 @@ /* constants for special character types */ #define SC_NONE 0 /* not a special character */ -#define SC_KING 1 /* king */ +#define SC_KING 1 /* king */ #define SC_COUNCIL 2 /* council of the wise */ #define SC_VALAR 3 /* valar */ #define SC_EXVALAR 4 /* ex-valar */ /* special monster constants */ -#define SM_NONE 0 /* nothing special */ -#define SM_UNICORN 1 /* unicorn */ -#define SM_MODNAR 2 /* Modnar */ -#define SM_MIMIC 3 /* mimic */ -#define SM_DARKLORD 4 /* Dark Lord */ -#define SM_LEANAN 5 /* Leanan-Sidhe */ -#define SM_SARUMAN 6 /* Saruman */ -#define SM_THAUMATURG 7 /* thaumaturgist */ -#define SM_BALROG 8 /* balrog */ -#define SM_VORTEX 9 /* vortex */ +#define SM_NONE 0 /* nothing special */ +#define SM_UNICORN 1 /* unicorn */ +#define SM_MODNAR 2 /* Modnar */ +#define SM_MIMIC 3 /* mimic */ +#define SM_DARKLORD 4 /* Dark Lord */ +#define SM_LEANAN 5 /* Leanan-Sidhe */ +#define SM_SARUMAN 6 /* Saruman */ +#define SM_THAUMATURG 7 /* thaumaturgist */ +#define SM_BALROG 8 /* balrog */ +#define SM_VORTEX 9 /* vortex */ #define SM_NAZGUL 10 /* nazgul */ -#define SM_TIAMAT 11 /* Tiamat */ -#define SM_KOBOLD 12 /* kobold */ -#define SM_SHELOB 13 /* Shelob */ -#define SM_FAERIES 14 /* assorted faeries */ -#define SM_LAMPREY 15 /* lamprey */ -#define SM_SHRIEKER 16 /* shrieker */ -#define SM_BONNACON 17 /* bonnacon */ -#define SM_SMEAGOL 18 /* Smeagol */ -#define SM_SUCCUBUS 19 /* succubus */ -#define SM_CERBERUS 20 /* Cerberus */ -#define SM_UNGOLIANT 21 /* Ungoliant */ -#define SM_JABBERWOCK 22 /* jabberwock */ -#define SM_MORGOTH 23 /* Morgoth */ -#define SM_TROLL 24 /* troll */ -#define SM_WRAITH 25 /* wraith */ +#define SM_TIAMAT 11 /* Tiamat */ +#define SM_KOBOLD 12 /* kobold */ +#define SM_SHELOB 13 /* Shelob */ +#define SM_FAERIES 14 /* assorted faeries */ +#define SM_LAMPREY 15 /* lamprey */ +#define SM_SHRIEKER 16 /* shrieker */ +#define SM_BONNACON 17 /* bonnacon */ +#define SM_SMEAGOL 18 /* Smeagol */ +#define SM_SUCCUBUS 19 /* succubus */ +#define SM_CERBERUS 20 /* Cerberus */ +#define SM_UNGOLIANT 21 /* Ungoliant */ +#define SM_JABBERWOCK 22 /* jabberwock */ +#define SM_MORGOTH 23 /* Morgoth */ +#define SM_TROLL 24 /* troll */ +#define SM_WRAITH 25 /* wraith */ /* constants for spells */ -#define ML_ALLORNOTHING 0.0 /* magic level for 'all or nothing' */ +#define ML_ALLORNOTHING 0.0 /* magic level for 'all or nothing' */ #define MM_ALLORNOTHING 1.0 /* mana used for 'all or nothing' */ -#define ML_MAGICBOLT 5.0 /* magic level for 'magic bolt' */ -#define ML_FORCEFIELD 15.0 /* magic level for 'force field' */ -#define MM_FORCEFIELD 30.0 /* mana used for 'force field' */ -#define ML_XFORM 25.0 /* magic level for 'transform' */ -#define MM_XFORM 50.0 /* mana used for 'transform' */ -#define ML_INCRMIGHT 35.0 /* magic level for 'increase might' */ -#define MM_INCRMIGHT 75.0 /* mana used for 'increase might' */ -#define ML_INVISIBLE 45.0 /* magic level for 'invisibility' */ -#define MM_INVISIBLE 90.0 /* mana used for 'invisibility' */ -#define ML_XPORT 60.0 /* magic level for 'transport' */ -#define MM_XPORT 125.0 /* mana used for 'transport' */ -#define ML_PARALYZE 75.0 /* magic level for 'paralyze' */ -#define MM_PARALYZE 150.0 /* mana used for 'paralyze' */ -#define MM_SPECIFY 1000.0 /* mana used for 'specify' */ +#define ML_MAGICBOLT 5.0 /* magic level for 'magic bolt' */ +#define ML_FORCEFIELD 15.0 /* magic level for 'force field' */ +#define MM_FORCEFIELD 30.0 /* mana used for 'force field' */ +#define ML_XFORM 25.0 /* magic level for 'transform' */ +#define MM_XFORM 50.0 /* mana used for 'transform' */ +#define ML_INCRMIGHT 35.0 /* magic level for 'increase might' */ +#define MM_INCRMIGHT 75.0 /* mana used for 'increase might' */ +#define ML_INVISIBLE 45.0 /* magic level for 'invisibility' */ +#define MM_INVISIBLE 90.0 /* mana used for 'invisibility' */ +#define ML_XPORT 60.0 /* magic level for 'transport' */ +#define MM_XPORT 125.0 /* mana used for 'transport' */ +#define ML_PARALYZE 75.0 /* magic level for 'paralyze' */ +#define MM_PARALYZE 150.0 /* mana used for 'paralyze' */ +#define MM_SPECIFY 1000.0 /* mana used for 'specify' */ #define ML_CLOAK 20.0 /* magic level for 'cloak' */ -#define MEL_CLOAK 7.0 /* experience level for 'cloak' */ -#define MM_CLOAK 35.0 /* mana used for 'cloak' */ -#define ML_TELEPORT 40.0 /* magic level for 'teleport' */ -#define MEL_TELEPORT 12.0 /* experience level for 'teleport' */ -#define MM_INTERVENE 1000.0 /* mana used to 'intervene' */ +#define MEL_CLOAK 7.0 /* experience level for 'cloak' */ +#define MM_CLOAK 35.0 /* mana used for 'cloak' */ +#define ML_TELEPORT 40.0 /* magic level for 'teleport' */ +#define MEL_TELEPORT 12.0 /* experience level for 'teleport' */ +#define MM_INTERVENE 1000.0 /* mana used to 'intervene' */ /* some miscellaneous constants */ #define SZ_DATABUF 100 /* size of input buffer */ -#define SZ_PLAYERSTRUCT sizeof(struct player) /* size of player structure */ -#define SZ_VOIDSTRUCT sizeof(struct energyvoid) /* size of energy void struct */ -#define SZ_SCORESTRUCT sizeof(struct scoreboard) /* size of score board entry */ -#define SZ_MONSTERSTRUCT sizeof(struct monster) /* size of monster structure */ -#define SZ_NAME 21 /* size of player name (incl. trailing nul) */ -#define SZ_PASSWORD 9 /* size of password (incl. trailing nul) */ -#define SZ_LOGIN 9 /* size of login (incl. trailing nul) */ +#define SZ_PLAYERSTRUCT sizeof(struct player) /* size of player structure */ +#define SZ_VOIDSTRUCT sizeof(struct energyvoid) /* size of energy void struct */ +#define SZ_SCORESTRUCT sizeof(struct scoreboard) /* size of score board entry */ +#define SZ_MONSTERSTRUCT sizeof(struct monster) /* size of monster structure */ +#define SZ_NAME 21 /* size of player name (incl. trailing nul) */ +#define SZ_PASSWORD 9 /* size of password (incl. trailing nul) */ #define N_DAYSOLD 21 /* number of days old for purge */ #define N_AGE 500 /* age to degenerate ratio */ -#define N_GEMVALUE (1000.0) /* number of gold pieces to gem ratio */ -#define N_TAXAMOUNT (7.0) /* tax percent */ +#define N_GEMVALUE (1000.0) /* number of gold pieces to gem ratio */ +#define N_TAXAMOUNT (7.0) /* tax percent */ -#define D_BEYOND (1.1e6) /* distance to beyond point of no return */ +#define D_BEYOND (1.1e6) /* distance to beyond point of no return */ #define D_EXPER (2000.0) /* distance experimentos are allowed */ -#define CH_MARKDELETE '\001' /* used to alter name of deleted players */ -#define CH_KILL '\030' /* kill character (ctrl-X) */ -#define CH_ERASE '\010' /* erase character (ctrl-H) */ -#define CH_NEWLINE '\n' /* newline */ -#define CH_RETURN '\r' /* carriage return */ -#define CH_REDRAW '\014' /* redraw screen character (ctrl-L) */ +#define CH_MARKDELETE '\001' /* used to alter name of deleted players */ +#define CH_KILL '\030' /* kill character (ctrl-X) */ +#define CH_ERASE '\010' /* erase character (ctrl-H) */ +#define CH_NEWLINE '\n' /* newline */ +#define CH_RETURN '\r' /* carriage return */ +#define CH_REDRAW '\014' /* redraw screen character (ctrl-L) */ diff --git a/games/phantasia/phantstruct.h b/games/phantasia/phantstruct.h index 599d9faf8aa..5ebf05274c1 100644 --- a/games/phantasia/phantstruct.h +++ b/games/phantasia/phantstruct.h @@ -1,4 +1,4 @@ -/* $OpenBSD: phantstruct.h,v 1.2 1998/11/29 19:57:02 pjanzen Exp $ */ +/* $OpenBSD: phantstruct.h,v 1.3 2001/02/04 02:51:25 pjanzen Exp $ */ /* $NetBSD: phantstruct.h,v 1.2 1995/03/24 04:00:11 cgd Exp $ */ /* @@ -60,7 +60,7 @@ struct player /* player statistics */ char p_name[SZ_NAME]; /* name */ char p_password[SZ_PASSWORD];/* password */ - char p_login[SZ_LOGIN]; /* login */ + char p_login[MAXLOGNAME]; /* login */ }; struct monster /* monster stats */ @@ -97,7 +97,7 @@ struct scoreboard /* scoreboard entry */ double sb_level; /* level of player */ char sb_type[4]; /* character type of player */ char sb_name[SZ_NAME]; /* name of player */ - char sb_login[SZ_LOGIN]; /* login of player */ + char sb_login[MAXLOGNAME]; /* login of player */ }; struct charstats /* character type statistics */ |