From d770f8ed96737fded90a2d6e7aab822390cdaf2e Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Mon, 10 Oct 2011 17:50:41 +0000 Subject: [PATCH] Add "duration" watch-mode column, which shows time since the game was started. git-svn-id: svn://katsu.triplehelix.org/dgamelaunch/trunk@618 db0b04b0-f4d1-0310-9a6d-de3e77497b0e --- TODO | 23 ++------------- dgamelaunch.c | 62 +++++++++++++++++++++++++-------------- dgamelaunch.h | 2 ++ dgl-common.c | 1 + examples/dgamelaunch.conf | 2 +- 5 files changed, 46 insertions(+), 44 deletions(-) diff --git a/TODO b/TODO index b141ac5..da3ab5f 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,3 @@ -%t format variable: path+filename of the finished ttyrec, in postcommands - < kerio> paxed: it would also be cool to have %g and %s work within a game definition too @@ -39,13 +37,8 @@ -watching menu will hilight the first matching username... what if we have more than one game installed, and someone's playing more than one at the same time? Should also save game#, not just the username. --allow admin to disabling the 'm' mail key in ttyplay. +-allow admin to disable the 'm' mail key in ttyplay. -update README --maybe allow something like changed_menu="[Updated %d]" config option and - $CHANGED in the menu banner. - the $CHANGED will be replaced with the changed_menu value. - the %d in changed_menu will be replaced with the banner file - change time. -whenever config file has a dir, check that it ends with "/" -in domailuser(), we need find_curr_player_game(username) -for menu definitions, allow "default" commands (when user presses a @@ -57,14 +50,6 @@ -allow the admin to config the watching menu: -top banner -bottom banner - -remove and reorder the columns: - watch_title = " Name Game Size Start date & time Idle" - this doesn't allow hiliting the sorted title, though... - watch_columns = "0) 1 2 3 4 5 6" - where the numbers correspond to the columns, everything else - is passed through. the columns have default widths. - col 0=selectletter, 1=playername, 2=gamenum, 3=termsize, 4=startdate, - 5=starttime, 6=idletime -set default sort method -selectorchars: watch_selectorchars = "abcdefghijklmn" (a-zA-Z, minus qQ) @@ -92,18 +77,14 @@ -BUG: cannot quit watching until caught up with the stream. -allow configuring the watching, new user registration, email/passwd change, etc. screens. --make default_fmode configurable, and add config - file command "chmod file mode" --allow setting the new rcfile access rights. +-add config file command "chmod file mode" -allow configuring the ttyrec dir location & file format. --maybe allow changing the watching-screen &c layouts too? -add commandline parameters to dgamelaunch: dgamelaunch --chpasswd "nick" "newpass" -some games (robotfindskitten?) are not worth saving into ttyrecs, make it configurable. if no ttyrecs, then can't watch the game, which is a pity. maybe rather just save the latest ttyrec, which ties into having configurable ttyrec filenames... --save the game name into ttyrec filename, so we can find what game it was. -allow configuring ttyplay.c; some games may use different clear-screen commands. (see for example crawl) -allow configuring the gfx stripping. (number of chars, types of stripping, diff --git a/dgamelaunch.c b/dgamelaunch.c index 463b958..bbbf3ca 100644 --- a/dgamelaunch.c +++ b/dgamelaunch.c @@ -803,6 +803,34 @@ sortmode_increment(struct dg_watchcols **watchcols, *sortmode = old_sortmode; } +char * +get_timediff(time_t ctime, long seconds) +{ + static char data[32]; + long secs, mins, hours; + + secs = (ctime - seconds); + + if (showplayers) { + snprintf(data, 10, "%ld", secs); + return data; + } + + hours = (secs / 3600); + secs -= (hours * 3600); + mins = (secs / 60) % 60; + secs -= (mins*60); + if (hours) + snprintf(data, 10, "%ldh %ldm", hours, mins); + else if (mins) + snprintf(data, 10, "%ldm %lds", mins, secs); + else if (secs > 4) + snprintf(data, 10, "%lds", secs); + else + snprintf(data, 10, " "); + return data; +} + static void game_get_column_data(struct dg_game *game, @@ -843,31 +871,21 @@ game_get_column_data(struct dg_game *game, game->time); break; - case SORTMODE_IDLETIME: - { - long secs, mins, hours; - - secs = (ctime - game->idle_time); - - if (showplayers) { - snprintf(data, 10, "%ld", secs); - break; + case SORTMODE_DURATION: + { + /* TODO: populate_games() should put st_ctime into game struct */ + struct tm timetm; + char tmptimebuf[32]; + snprintf(tmptimebuf, 30, "%s %s", game->date, game->time); + tmptimebuf[31] = '\0'; + strptime(tmptimebuf, "%Y-%m-%d %H:%M:%S", &timetm); + snprintf(data, 10, get_timediff(ctime, mktime(&timetm))); } + break; - hours = (secs / 3600); - secs -= (hours * 3600); - mins = (secs / 60) % 60; - secs -= (mins*60); - if (hours) - snprintf(data, 10, "%ldh %ldm", hours, mins); - else if (mins) - snprintf(data, 10, "%ldm %lds", mins, secs); - else if (secs > 4) - snprintf(data, 10, "%lds", secs); - else - snprintf(data, 10, " "); + case SORTMODE_IDLETIME: + snprintf(data, 10, get_timediff(ctime, game->idle_time)); break; - } case SORTMODE_EXTRA_INFO: if (game->extra_info) diff --git a/dgamelaunch.h b/dgamelaunch.h index 00b5066..034c3f8 100644 --- a/dgamelaunch.h +++ b/dgamelaunch.h @@ -80,6 +80,7 @@ typedef enum SORTMODE_GAMENUM, SORTMODE_WINDOWSIZE, SORTMODE_STARTTIME, + SORTMODE_DURATION, SORTMODE_IDLETIME, SORTMODE_EXTRA_INFO, #ifdef USE_SHMEM @@ -94,6 +95,7 @@ static const char *SORTMODE_NAME[NUM_SORTMODES] = { "Game", "Windowsize", "Starttime", + "Duration", "Idletime", "Extrainfo", #ifdef USE_SHMEM diff --git a/dgl-common.c b/dgl-common.c index 7f1b796..084e0ea 100644 --- a/dgl-common.c +++ b/dgl-common.c @@ -482,6 +482,7 @@ sort_games (struct dg_game **games, int len, dg_sortmode sortmode) (void) time(&sort_ctime); qsort(games, len, sizeof(struct dg_game *), sort_game_idletime); break; + case SORTMODE_DURATION: case SORTMODE_STARTTIME: qsort(games, len, sizeof(struct dg_game *), sort_game_starttime); break; case SORTMODE_EXTRA_INFO: diff --git a/examples/dgamelaunch.conf b/examples/dgamelaunch.conf index 41f860d..c897081 100644 --- a/examples/dgamelaunch.conf +++ b/examples/dgamelaunch.conf @@ -29,7 +29,7 @@ maxnicklen = 10 # [ "", "", , "" ] # # may be "unsorted", "username", "game", "windowsize", "starttime", -# "idletime", or (if shmem is enabled) "watchers". +# "duration", "idletime", or (if shmem is enabled) "watchers". # # watch_columns = [ ["", "", 1, "%s)"], # ["User", "username", 4, "%-15s"],