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
This commit is contained in:
Pasi Kallinen 2011-10-10 17:50:41 +00:00
parent b42d170041
commit d770f8ed96
5 changed files with 46 additions and 44 deletions

23
TODO
View File

@ -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 < 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 -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 more than one game installed, and someone's playing more than one at the
same time? Should also save game#, not just the username. 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 -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 "/" -whenever config file has a dir, check that it ends with "/"
-in domailuser(), we need find_curr_player_game(username) -in domailuser(), we need find_curr_player_game(username)
-for menu definitions, allow "default" commands (when user presses a -for menu definitions, allow "default" commands (when user presses a
@ -57,14 +50,6 @@
-allow the admin to config the watching menu: -allow the admin to config the watching menu:
-top banner -top banner
-bottom 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 -set default sort method
-selectorchars: -selectorchars:
watch_selectorchars = "abcdefghijklmn" (a-zA-Z, minus qQ) watch_selectorchars = "abcdefghijklmn" (a-zA-Z, minus qQ)
@ -92,18 +77,14 @@
-BUG: cannot quit watching until caught up with the stream. -BUG: cannot quit watching until caught up with the stream.
-allow configuring the watching, new user registration, -allow configuring the watching, new user registration,
email/passwd change, etc. screens. email/passwd change, etc. screens.
-make default_fmode configurable, and add config -add config file command "chmod file mode"
file command "chmod file mode"
-allow setting the new rcfile access rights.
-allow configuring the ttyrec dir location & file format. -allow configuring the ttyrec dir location & file format.
-maybe allow changing the watching-screen &c layouts too?
-add commandline parameters to dgamelaunch: -add commandline parameters to dgamelaunch:
dgamelaunch --chpasswd "nick" "newpass" dgamelaunch --chpasswd "nick" "newpass"
-some games (robotfindskitten?) are not worth saving into ttyrecs, -some games (robotfindskitten?) are not worth saving into ttyrecs,
make it configurable. if no ttyrecs, then can't watch the game, which is 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 a pity. maybe rather just save the latest ttyrec, which ties into
having configurable ttyrec filenames... 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 -allow configuring ttyplay.c; some games may use different clear-screen
commands. (see for example crawl) commands. (see for example crawl)
-allow configuring the gfx stripping. (number of chars, types of stripping, -allow configuring the gfx stripping. (number of chars, types of stripping,

View File

@ -803,6 +803,34 @@ sortmode_increment(struct dg_watchcols **watchcols,
*sortmode = old_sortmode; *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 static
void void
game_get_column_data(struct dg_game *game, game_get_column_data(struct dg_game *game,
@ -843,31 +871,21 @@ game_get_column_data(struct dg_game *game,
game->time); game->time);
break; break;
case SORTMODE_IDLETIME: case SORTMODE_DURATION:
{ {
long secs, mins, hours; /* TODO: populate_games() should put st_ctime into game struct */
struct tm timetm;
secs = (ctime - game->idle_time); char tmptimebuf[32];
snprintf(tmptimebuf, 30, "%s %s", game->date, game->time);
if (showplayers) { tmptimebuf[31] = '\0';
snprintf(data, 10, "%ld", secs); strptime(tmptimebuf, "%Y-%m-%d %H:%M:%S", &timetm);
break; snprintf(data, 10, get_timediff(ctime, mktime(&timetm)));
} }
break;
hours = (secs / 3600); case SORTMODE_IDLETIME:
secs -= (hours * 3600); snprintf(data, 10, get_timediff(ctime, game->idle_time));
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, " ");
break; break;
}
case SORTMODE_EXTRA_INFO: case SORTMODE_EXTRA_INFO:
if (game->extra_info) if (game->extra_info)

View File

@ -80,6 +80,7 @@ typedef enum
SORTMODE_GAMENUM, SORTMODE_GAMENUM,
SORTMODE_WINDOWSIZE, SORTMODE_WINDOWSIZE,
SORTMODE_STARTTIME, SORTMODE_STARTTIME,
SORTMODE_DURATION,
SORTMODE_IDLETIME, SORTMODE_IDLETIME,
SORTMODE_EXTRA_INFO, SORTMODE_EXTRA_INFO,
#ifdef USE_SHMEM #ifdef USE_SHMEM
@ -94,6 +95,7 @@ static const char *SORTMODE_NAME[NUM_SORTMODES] = {
"Game", "Game",
"Windowsize", "Windowsize",
"Starttime", "Starttime",
"Duration",
"Idletime", "Idletime",
"Extrainfo", "Extrainfo",
#ifdef USE_SHMEM #ifdef USE_SHMEM

View File

@ -482,6 +482,7 @@ sort_games (struct dg_game **games, int len, dg_sortmode sortmode)
(void) time(&sort_ctime); (void) time(&sort_ctime);
qsort(games, len, sizeof(struct dg_game *), sort_game_idletime); qsort(games, len, sizeof(struct dg_game *), sort_game_idletime);
break; break;
case SORTMODE_DURATION:
case SORTMODE_STARTTIME: qsort(games, len, sizeof(struct dg_game *), sort_game_starttime); break; case SORTMODE_STARTTIME: qsort(games, len, sizeof(struct dg_game *), sort_game_starttime); break;
case SORTMODE_EXTRA_INFO: case SORTMODE_EXTRA_INFO:

View File

@ -29,7 +29,7 @@ maxnicklen = 10
# [ "<display title>", "<sortname>", <Screen column>, "<printf format>" ] # [ "<display title>", "<sortname>", <Screen column>, "<printf format>" ]
# #
# <sortname> may be "unsorted", "username", "game", "windowsize", "starttime", # <sortname> 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)"], # watch_columns = [ ["", "", 1, "%s)"],
# ["User", "username", 4, "%-15s"], # ["User", "username", 4, "%-15s"],