From 4d45d4d2634a13e70f389b07adbf2d5708f30a9c Mon Sep 17 00:00:00 2001 From: Joshua Kwan Date: Sat, 3 Apr 2004 19:27:42 +0000 Subject: [PATCH] move junk around, genericize things git-svn-id: svn://katsu.triplehelix.org/dgamelaunch/trunk@287 db0b04b0-f4d1-0310-9a6d-de3e77497b0e --- Changelog | 4 +++- config.l | 3 ++- config.y | 20 +++++++++++++------ dgamelaunch.c | 15 +++++++------- dgamelaunch.h | 3 ++- dgl-common.c | 6 ++++-- dgamelaunch.conf => examples/dgamelaunch.conf | 5 +++-- .../dgl-create-chroot.conf.example.freebsd | 0 .../dgl-create-chroot.conf.example.macosx | 0 .../dgl-create-chroot.conf.example.solaris | 0 ttyrec.c | 4 ++-- 11 files changed, 37 insertions(+), 23 deletions(-) rename dgamelaunch.conf => examples/dgamelaunch.conf (94%) rename dgl-create-chroot.conf.example.freebsd => examples/dgl-create-chroot.conf.example.freebsd (100%) rename dgl-create-chroot.conf.example.macosx => examples/dgl-create-chroot.conf.example.macosx (100%) rename dgl-create-chroot.conf.example.solaris => examples/dgl-create-chroot.conf.example.solaris (100%) diff --git a/Changelog b/Changelog index d691987..ada11de 100644 --- a/Changelog +++ b/Changelog @@ -1,11 +1,13 @@ 1.4.5 (????/??/??) - * Reset offset if necessary to show at least one game to avoid things + * Reset offset if necessary to show at least one game to avoid things like "(15-14 of 14)". * Provide several examples for dgl-create-chroot.conf. * Backup the savefile before starting nethack to help prevent more lost games. Note this must be explicitly configured in the configuration file. * Added ^W for delete word in mygetnstr(). + * Begun generalization of code so that someone can get it to work + with stuff like Slash'EM etc. easier. 1.4.4 (2004/03/07) * Show total number of games in progress below the list, useful if diff --git a/config.l b/config.l index 241a34f..3a73e85 100644 --- a/config.l +++ b/config.l @@ -58,7 +58,8 @@ COMMENT ^#.* "maxusers" { return TYPE_MAX; } "chroot_path" { return TYPE_PATH_CHROOT; } -"nethack" { return TYPE_PATH_NETHACK; } +"game_name" { return TYPE_NAME_GAME; } +"game_path" { return TYPE_PATH_GAME; } "dglroot" { return TYPE_PATH_DGLDIR; } "spooldir" { return TYPE_PATH_SPOOL; } "banner" { return TYPE_PATH_BANNER; } diff --git a/config.y b/config.y index 250ec74..eb4c308 100644 --- a/config.y +++ b/config.y @@ -26,7 +26,7 @@ static const char* lookup_token (int t); } %token TYPE_SUSER TYPE_SGROUP TYPE_SGID TYPE_SUID TYPE_MAX -%token TYPE_PATH_NETHACK TYPE_PATH_DGLDIR TYPE_PATH_SPOOL +%token TYPE_PATH_GAME TYPE_NAME_GAME TYPE_PATH_DGLDIR TYPE_PATH_SPOOL %token TYPE_PATH_BANNER TYPE_PATH_CANNED TYPE_PATH_CHROOT %token TYPE_PATH_PASSWD TYPE_PATH_LOCKFILE TYPE_PATH_SAVEFILEFMT %token TYPE_MALSTRING @@ -113,9 +113,14 @@ KeyPair: KeyType '=' TYPE_VALUE { myconfig->chroot = strdup ($3); break; - case TYPE_PATH_NETHACK: - if (myconfig->nethack) free(myconfig->nethack); - myconfig->nethack = strdup ($3); + case TYPE_PATH_GAME: + if (myconfig->game_path) free(myconfig->game_path); + myconfig->game_path = strdup ($3); + break; + + case TYPE_NAME_GAME: + if (myconfig->game_name) free (myconfig->game_name); + myconfig->game_name = strdup($3); break; case TYPE_PATH_DGLDIR: @@ -214,7 +219,8 @@ KeyType : TYPE_SUSER { $$ = TYPE_SUSER; } | TYPE_SGID { $$ = TYPE_SGID; } | TYPE_MAX { $$ = TYPE_MAX; } | TYPE_PATH_CHROOT { $$ = TYPE_PATH_CHROOT; } - | TYPE_PATH_NETHACK { $$ = TYPE_PATH_NETHACK; } + | TYPE_PATH_GAME { $$ = TYPE_PATH_GAME; } + | TYPE_NAME_GAME { $$ = TYPE_NAME_GAME; } | TYPE_PATH_DGLDIR { $$ = TYPE_PATH_DGLDIR; } | TYPE_PATH_SPOOL { $$ = TYPE_PATH_SPOOL; } | TYPE_PATH_BANNER { $$ = TYPE_PATH_BANNER; } @@ -236,11 +242,13 @@ const char* lookup_token (int t) case TYPE_SGID: return "shed_gid"; case TYPE_MAX: return "maxusers"; case TYPE_PATH_CHROOT: return "chroot_path"; - case TYPE_PATH_NETHACK: return "nethack"; + case TYPE_PATH_GAME: return "game_path"; + case TYPE_NAME_GAME: return "game_name"; case TYPE_PATH_DGLDIR: return "dglroot"; case TYPE_PATH_SPOOL: return "spooldir"; case TYPE_PATH_BANNER: return "banner"; case TYPE_PATH_CANNED: return "rc_template"; + case TYPE_PATH_SAVEFILEFMT: return "savefilefmt"; default: abort(); } } diff --git a/dgamelaunch.c b/dgamelaunch.c index 6ccd538..e617aef 100644 --- a/dgamelaunch.c +++ b/dgamelaunch.c @@ -689,7 +689,7 @@ drawmenu () mvaddstr (banner.len + 5, 1, "e) Change email address"); mvaddstr (banner.len + 6, 1, "o) Edit option file"); mvaddstr (banner.len + 7, 1, "w) Watch games in progress"); - mvaddstr (banner.len + 8, 1, "p) Play nethack!"); + mvprintw (banner.len + 8, 1, "p) Play %s!", myconfig->game_name); mvaddstr (banner.len + 9, 1, "q) Quit"); mvaddstr (banner.len + 11, 1, "=> "); } @@ -1391,8 +1391,6 @@ backup_savefile (void) return n >= 0; } -/* TODO: Some of the messages here (sorry no nethack for you!) are nethack specific - * as may be some code... don't think so though. Globalize it. */ int purge_stale_locks (void) { @@ -1453,7 +1451,8 @@ purge_stale_locks (void) #define HUP_WAIT 10 /* seconds before HUPPING */ mvprintw (3, 1, - "There are some stale Nethack processes, will recover in %d seconds.", HUP_WAIT); + "There are some stale %s processes, will recover in %d seconds.", + myconfig->game_name, HUP_WAIT); mvaddstr (4, 1, "Press a key NOW if you don't want this to happen!"); @@ -1494,8 +1493,8 @@ purge_stale_locks (void) sleep (1); if (seconds == 10) { - mvaddstr (3, 1, - "Couldn't terminate one of your stale Nethack processes gracefully."); + mvprintw (3, 1, + "Couldn't terminate one of your stale %s processes gracefully.", myconfig->game_name); mvaddstr (4, 1, "Force its termination? [yn] "); if (tolower (getch ()) == 'y') { @@ -1505,8 +1504,8 @@ purge_stale_locks (void) else { endwin (); - fprintf (stderr, "Sorry, no nethack for you now, please " - "contact the admin.\n"); + fprintf (stderr, "Sorry, no %s for you now, please " + "contact the admin.\n", myconfig->game_name); graceful_exit (1); } } diff --git a/dgamelaunch.h b/dgamelaunch.h index 1c6b282..a5e5c32 100644 --- a/dgamelaunch.h +++ b/dgamelaunch.h @@ -45,7 +45,8 @@ struct dg_game struct dg_config { char* chroot; - char* nethack; + char* game_path; + char* game_name; char* dglroot; char* lockfile; char* passwd; diff --git a/dgl-common.c b/dgl-common.c index 185a34e..d49c039 100644 --- a/dgl-common.c +++ b/dgl-common.c @@ -18,7 +18,8 @@ extern int yyparse (); struct dg_config *myconfig = NULL; struct dg_config defconfig = { /* chroot = */ "/var/lib/dgamelaunch/", - /* nethack = */ "/bin/nethack", + /* game_path = */ "/bin/nethack", + /* game_name = */ "NetHack", /* dglroot = */ "/dgldir/", /* lockfile = */ "/dgl-lock", /* passwd = */ "/dgl-login", @@ -232,7 +233,8 @@ create_config () if (myconfig->max == 0 && !set_max) myconfig->max = defconfig.max; if (!myconfig->banner) myconfig->banner = defconfig.banner; if (!myconfig->chroot) myconfig->chroot = defconfig.chroot; - if (!myconfig->nethack) myconfig->nethack = defconfig.nethack; + if (!myconfig->game_path) myconfig->game_path = defconfig.game_path; + if (!myconfig->game_name) myconfig->game_name = defconfig.game_name; if (!myconfig->dglroot) myconfig->dglroot = defconfig.dglroot; if (!myconfig->rcfile) myconfig->rcfile = defconfig.rcfile; if (!myconfig->spool) myconfig->spool = defconfig.spool; diff --git a/dgamelaunch.conf b/examples/dgamelaunch.conf similarity index 94% rename from dgamelaunch.conf rename to examples/dgamelaunch.conf index 4130f87..431f329 100644 --- a/dgamelaunch.conf +++ b/examples/dgamelaunch.conf @@ -26,8 +26,9 @@ maxusers = 64000 # Path to a prepared chroot jail. chroot_path = "/var/lib/dgamelaunch/" -# From inside the jail, the location of the nethack binary. -nethack = "/bin/nethack" +# From inside the jail, the location of the binary to be launched. +game_path = "/bin/nethack" +game_name = "NetHack" # From inside the jail, dgamelaunch's working directory for rcfiles/ttyrec/etc dglroot = "/dgldir/" diff --git a/dgl-create-chroot.conf.example.freebsd b/examples/dgl-create-chroot.conf.example.freebsd similarity index 100% rename from dgl-create-chroot.conf.example.freebsd rename to examples/dgl-create-chroot.conf.example.freebsd diff --git a/dgl-create-chroot.conf.example.macosx b/examples/dgl-create-chroot.conf.example.macosx similarity index 100% rename from dgl-create-chroot.conf.example.macosx rename to examples/dgl-create-chroot.conf.example.macosx diff --git a/dgl-create-chroot.conf.example.solaris b/examples/dgl-create-chroot.conf.example.solaris similarity index 100% rename from dgl-create-chroot.conf.example.solaris rename to examples/dgl-create-chroot.conf.example.solaris diff --git a/ttyrec.c b/ttyrec.c index b212358..f62f903 100644 --- a/ttyrec.c +++ b/ttyrec.c @@ -262,7 +262,7 @@ dooutput () void doshell (char *username) { - char *argv1 = myconfig->nethack; + char *argv1 = myconfig->game_path; char *argv2 = "-u"; char *myargv[10]; @@ -279,7 +279,7 @@ doshell (char *username) myargv[2] = username; myargv[3] = 0; - execvp (myconfig->nethack, myargv); + execvp (myconfig->game_path, myargv); fail (); } -- 2.47.3