From: Joshua Kwan Date: Sat, 3 Apr 2004 19:27:42 +0000 (+0000) Subject: move junk around, genericize things X-Git-Tag: v1.6.1-roc-dev~416 X-Git-Url: https://skyeroc.xyz/gitweb/?a=commitdiff_plain;h=4d45d4d2634a13e70f389b07adbf2d5708f30a9c;p=dgamelaunch move junk around, genericize things git-svn-id: svn://katsu.triplehelix.org/dgamelaunch/trunk@287 db0b04b0-f4d1-0310-9a6d-de3e77497b0e --- 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.conf b/dgamelaunch.conf deleted file mode 100644 index 4130f87..0000000 --- a/dgamelaunch.conf +++ /dev/null @@ -1,57 +0,0 @@ -# This is a sample dgamelaunch configuration file. Only bash-style comments -# are allowed, such as this. Each configuration option will be explained -# along with its default value. - -# The following two options are fairly insecure. They will force us to -# load the password/group database into memory while still having root -# privileges. Replace them with shed_uid/shed_gid entries as soon as -# possible if you decide to use them. dgamelaunch will inform you of -# the uids/gids corresponding to your choices when it loads. -# -# Note that shed_uid and shed_gid will always take precedence over -# shed_user and shed_group if they are specified. - -# shed_user: username to shed privileges to -shed_user = "games" -# shed_group: group name to shed privileges to -shed_group = "games" - -# Preferably, you may use the respective gids/uids. This is for Debian: -shed_uid = 5 -shed_gid = 60 - -# Max amount of registered users to allow. -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, dgamelaunch's working directory for rcfiles/ttyrec/etc -dglroot = "/dgldir/" - -# From inside the jail, where dgamelaunch should put mail - should match up with -# NetHack settings. -spooldir = "/var/mail/" - -# From inside the jail, location of a banner file that contains no more than -# 14 lines of 80-column width text. Any more will be truncated. -banner = "/dgl-banner" - -# From inside the jail, the default .nethackrc that is copied for new users. -rc_template = "/dgl-default-rcfile" - -# The defaults are usually just fine for this. passwd refers to the file -# that stores the user database, and lockfile is only used internally by -# dgamelaunch. - -passwd = "/dgl-login" -lockfile = "/dgl-lock" - -# From inside the jail, the path to the savefile. %u is replaced by the -# decimal representation of shed_uid, %n is replaced by the player's -# user name. Before starting the game, this file is copied to its name -# with ".bak" appended. Set to an empty string to disable this copying. -savefilefmt = "/var/games/nethack/save/%u%n.gz" 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/dgl-create-chroot.conf.example.freebsd b/dgl-create-chroot.conf.example.freebsd deleted file mode 100644 index d0b6e4d..0000000 --- a/dgl-create-chroot.conf.example.freebsd +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh -# Example configuration, for my FreeBSD 4 machine, using nethack from ports. -# This file created by Jilles Tjoelker . - -chroot_path="/home/jilles/src/3rdparty/dgamelaunch-chroot-2" -shed_uid=1031 -shed_gid=1031 -libs="/usr/libexec/ld-elf.so.1" # /libexec/ld-elf.so.1 for FreeBSD 5 -playground_fixed="/usr/local/lib/nethack" -playground_var="/usr/local/lib/nethack" -nethack_bin="$playground_fixed/nethack" -termdata="/usr/share/misc/termcap" diff --git a/dgl-create-chroot.conf.example.macosx b/dgl-create-chroot.conf.example.macosx deleted file mode 100644 index a35e0e8..0000000 --- a/dgl-create-chroot.conf.example.macosx +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/sh -# Brett Carrington - -# NOTE: This copied from the dgl-create-chroot changes by Jilles, likely -# incomplete. - -chroot_path="/var/lib/dgamelaunch" -shed_uid=5 -shed_gid=60 -libs="" -playground_fixed="/opt/local/share/nethackdir/" -playground_var="" -nethack_bin="/opt/local/bin/nethack" -termdata="/usr/share/terminfo" diff --git a/dgl-create-chroot.conf.example.solaris b/dgl-create-chroot.conf.example.solaris deleted file mode 100644 index fc852ef..0000000 --- a/dgl-create-chroot.conf.example.solaris +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/sh -# hack it for crab test -# This file created by Jilles Tjoelker . - -chroot_path="/tmp/jilles/dgl-chroot" -shed_uid=1677 -shed_gid=104 -# This allows both 32-bit and 64-bit dynamically linked binaries in the chroot: -libs="/usr/lib/ld.so.1 /usr/lib/sparcv9/ld.so.1" -playground_fixed="" -playground_var="" -nethack_bin="nethackstub" -# For standard curses: -termdata="/usr/share/lib/terminfo" -#termdata="/usr/local/share/lib/terminfo" diff --git a/examples/dgamelaunch.conf b/examples/dgamelaunch.conf new file mode 100644 index 0000000..431f329 --- /dev/null +++ b/examples/dgamelaunch.conf @@ -0,0 +1,58 @@ +# This is a sample dgamelaunch configuration file. Only bash-style comments +# are allowed, such as this. Each configuration option will be explained +# along with its default value. + +# The following two options are fairly insecure. They will force us to +# load the password/group database into memory while still having root +# privileges. Replace them with shed_uid/shed_gid entries as soon as +# possible if you decide to use them. dgamelaunch will inform you of +# the uids/gids corresponding to your choices when it loads. +# +# Note that shed_uid and shed_gid will always take precedence over +# shed_user and shed_group if they are specified. + +# shed_user: username to shed privileges to +shed_user = "games" +# shed_group: group name to shed privileges to +shed_group = "games" + +# Preferably, you may use the respective gids/uids. This is for Debian: +shed_uid = 5 +shed_gid = 60 + +# Max amount of registered users to allow. +maxusers = 64000 + +# Path to a prepared chroot jail. +chroot_path = "/var/lib/dgamelaunch/" + +# 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/" + +# From inside the jail, where dgamelaunch should put mail - should match up with +# NetHack settings. +spooldir = "/var/mail/" + +# From inside the jail, location of a banner file that contains no more than +# 14 lines of 80-column width text. Any more will be truncated. +banner = "/dgl-banner" + +# From inside the jail, the default .nethackrc that is copied for new users. +rc_template = "/dgl-default-rcfile" + +# The defaults are usually just fine for this. passwd refers to the file +# that stores the user database, and lockfile is only used internally by +# dgamelaunch. + +passwd = "/dgl-login" +lockfile = "/dgl-lock" + +# From inside the jail, the path to the savefile. %u is replaced by the +# decimal representation of shed_uid, %n is replaced by the player's +# user name. Before starting the game, this file is copied to its name +# with ".bak" appended. Set to an empty string to disable this copying. +savefilefmt = "/var/games/nethack/save/%u%n.gz" diff --git a/examples/dgl-create-chroot.conf.example.freebsd b/examples/dgl-create-chroot.conf.example.freebsd new file mode 100644 index 0000000..d0b6e4d --- /dev/null +++ b/examples/dgl-create-chroot.conf.example.freebsd @@ -0,0 +1,12 @@ +#!/bin/sh +# Example configuration, for my FreeBSD 4 machine, using nethack from ports. +# This file created by Jilles Tjoelker . + +chroot_path="/home/jilles/src/3rdparty/dgamelaunch-chroot-2" +shed_uid=1031 +shed_gid=1031 +libs="/usr/libexec/ld-elf.so.1" # /libexec/ld-elf.so.1 for FreeBSD 5 +playground_fixed="/usr/local/lib/nethack" +playground_var="/usr/local/lib/nethack" +nethack_bin="$playground_fixed/nethack" +termdata="/usr/share/misc/termcap" diff --git a/examples/dgl-create-chroot.conf.example.macosx b/examples/dgl-create-chroot.conf.example.macosx new file mode 100644 index 0000000..a35e0e8 --- /dev/null +++ b/examples/dgl-create-chroot.conf.example.macosx @@ -0,0 +1,14 @@ +#!/bin/sh +# Brett Carrington + +# NOTE: This copied from the dgl-create-chroot changes by Jilles, likely +# incomplete. + +chroot_path="/var/lib/dgamelaunch" +shed_uid=5 +shed_gid=60 +libs="" +playground_fixed="/opt/local/share/nethackdir/" +playground_var="" +nethack_bin="/opt/local/bin/nethack" +termdata="/usr/share/terminfo" diff --git a/examples/dgl-create-chroot.conf.example.solaris b/examples/dgl-create-chroot.conf.example.solaris new file mode 100644 index 0000000..fc852ef --- /dev/null +++ b/examples/dgl-create-chroot.conf.example.solaris @@ -0,0 +1,15 @@ +#!/bin/sh +# hack it for crab test +# This file created by Jilles Tjoelker . + +chroot_path="/tmp/jilles/dgl-chroot" +shed_uid=1677 +shed_gid=104 +# This allows both 32-bit and 64-bit dynamically linked binaries in the chroot: +libs="/usr/lib/ld.so.1 /usr/lib/sparcv9/ld.so.1" +playground_fixed="" +playground_var="" +nethack_bin="nethackstub" +# For standard curses: +termdata="/usr/share/lib/terminfo" +#termdata="/usr/local/share/lib/terminfo" 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 (); }