From 146947b386325d889ecc7df5d0c254d52002c3c6 Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Sun, 6 Apr 2008 09:13:50 +0000 Subject: [PATCH] Make watching-screen default sortmode configurable git-svn-id: svn://katsu.triplehelix.org/dgamelaunch/trunk@441 db0b04b0-f4d1-0310-9a6d-de3e77497b0e --- TODO | 5 ----- config.l | 1 + config.y | 17 ++++++++++++++++- dgamelaunch.c | 5 ++++- dgamelaunch.h | 6 +++--- dgl-common.c | 2 ++ examples/dgamelaunch.conf | 4 ++++ 7 files changed, 30 insertions(+), 10 deletions(-) diff --git a/TODO b/TODO index 83bf3d8..8366a93 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,3 @@ --Update dgl-wall.c or fold the functionality into dgl itself. - (see below) -BUG: cannot quit watching until caught up with the stream. -make default_fmode configurable, and add config file command "chmod file mode" @@ -8,9 +6,6 @@ -maybe allow changing the watching-screen &c layouts too? -add commandline parameters to dgamelaunch: dgamelaunch --chpasswd "nick" "newpass" - dgamelaunch --wall "message to mail everyone" - these are obviously only for the server admin... --allow setting the default watch-screen sortmode in config file. -some games (robotfindskitten?) are not worth saving into ttyrecs, make it configurable. -allow configuring ttyplay.c; some games may use different clear-screen commands. (see for example crawl) diff --git a/config.l b/config.l index d688637..f632c52 100644 --- a/config.l +++ b/config.l @@ -83,6 +83,7 @@ cursor { return TYPE_CURSOR; } "inprogressdir" { return TYPE_PATH_INPROGRESS; } "game_args" { return TYPE_GAME_ARGS; } "rc_fmt" { return TYPE_RC_FMT; } +sortmode { return TYPE_WATCH_SORTMODE; } commands { return TYPE_CMDQUEUE; } yes { yylval.i = 1; return TYPE_BOOL; } no { yylval.i = 0; return TYPE_BOOL; } diff --git a/config.y b/config.y index dd3a62d..973b933 100644 --- a/config.y +++ b/config.y @@ -34,7 +34,7 @@ static const char* lookup_token (int t); } %token TYPE_SUSER TYPE_SGROUP TYPE_SGID TYPE_SUID TYPE_MAX TYPE_MAXNICKLEN -%token TYPE_GAME_SHORT_NAME +%token TYPE_GAME_SHORT_NAME TYPE_WATCH_SORTMODE %token TYPE_ALLOW_REGISTRATION %token TYPE_PATH_GAME TYPE_NAME_GAME TYPE_PATH_DGLDIR TYPE_PATH_SPOOL %token TYPE_PATH_BANNER TYPE_PATH_CANNED TYPE_PATH_CHROOT @@ -155,7 +155,20 @@ KeyPair: TYPE_CMDQUEUE '[' TYPE_CMDQUEUENAME ']' globalconfig.chroot = strdup ($3); break; + case TYPE_WATCH_SORTMODE: + { + int tmpi, okay = 0; + for (tmpi = 0; tmpi < NUM_SORTMODES; tmpi++) + if (!strcasecmp(SORTMODE_NAME[tmpi], $3 )) { + globalconfig.sortmode = tmpi; + okay = 1; + break; + } + if (!okay) + fprintf(stderr, "%s:%d: unknown sortmode '%s'\n", config, line, $3); + } + break; case TYPE_PATH_DGLDIR: if (globalconfig.dglroot) free(globalconfig.dglroot); @@ -512,6 +525,7 @@ KeyType : TYPE_SUSER { $$ = TYPE_SUSER; } | TYPE_PATH_LOCKFILE { $$ = TYPE_PATH_LOCKFILE; } | TYPE_PATH_INPROGRESS { $$ = TYPE_PATH_INPROGRESS; } | TYPE_RC_FMT { $$ = TYPE_RC_FMT; } + | TYPE_WATCH_SORTMODE { $$ = TYPE_WATCH_SORTMODE; } ; %% @@ -538,6 +552,7 @@ const char* lookup_token (int t) case TYPE_PATH_INPROGRESS: return "inprogressdir"; case TYPE_GAME_ARGS: return "game_args"; case TYPE_RC_FMT: return "rc_fmt"; + case TYPE_WATCH_SORTMODE: return "sortmode"; default: abort(); } } diff --git a/dgamelaunch.c b/dgamelaunch.c index 57ddc73..20ca6e4 100644 --- a/dgamelaunch.c +++ b/dgamelaunch.c @@ -355,13 +355,16 @@ void inprogressmenu (int gameid) { int i, menuchoice, len = 20, offset = 0, doresizewin = 0; - static dg_sortmode sortmode = SORTMODE_NONE; + static dg_sortmode sortmode = NUM_SORTMODES; time_t ctime; struct dg_game **games; char ttyrecname[130], *replacestr = NULL, gametype[10]; int is_nhext[14]; sigset_t oldmask, toblock; + if (sortmode == NUM_SORTMODES) + sortmode = globalconfig.sortmode; + games = populate_games (gameid, &len); games = sort_games (games, len, sortmode); diff --git a/dgamelaunch.h b/dgamelaunch.h index 351ebcb..8970919 100644 --- a/dgamelaunch.h +++ b/dgamelaunch.h @@ -110,6 +110,7 @@ struct dg_globalconfig char* passwd; char* lockfile; int allow_registration; /* allow registering new nicks */ + int sortmode; /* default watching-screen sortmode */ struct dg_cmdpart *cmdqueue[NUM_DGLTIMES]; @@ -146,11 +147,10 @@ typedef enum NUM_SORTMODES } dg_sortmode; -static const char *SORTMODE_NAME[] = { +static const char *SORTMODE_NAME[NUM_SORTMODES] = { "Unsorted", "Username", - "Idletime", - "", + "Idletime" }; diff --git a/dgl-common.c b/dgl-common.c index be04fc2..efd648d 100644 --- a/dgl-common.c +++ b/dgl-common.c @@ -528,6 +528,8 @@ create_config () if (!globalconfig.allow_registration) globalconfig.allow_registration = 1; globalconfig.menulist = NULL; + globalconfig.sortmode = SORTMODE_NONE; + if (config) { if ((config_file = fopen(config, "r")) != NULL) diff --git a/examples/dgamelaunch.conf b/examples/dgamelaunch.conf index 62fa1df..d89a198 100644 --- a/examples/dgamelaunch.conf +++ b/examples/dgamelaunch.conf @@ -19,6 +19,10 @@ allow_new_nicks = yes # the record/logfile. maxnicklen = 10 +# Set the default watching-screen sorting mode. Can be one of +# "unsorted", "username" or "idletime". Unsorted is the default. +#sortmode = "username" + # Path to a prepared chroot jail. chroot_path = "/var/lib/dgamelaunch/"