]> skyeroc.xyz Git - dgamelaunch/commitdiff
Add "duration" watch-mode column, which shows time since the game was started.
authorPasi Kallinen <paxed@alt.org>
Mon, 10 Oct 2011 17:50:41 +0000 (17:50 +0000)
committerPasi Kallinen <paxed@alt.org>
Mon, 10 Oct 2011 17:50:41 +0000 (17:50 +0000)
git-svn-id: svn://katsu.triplehelix.org/dgamelaunch/trunk@618 db0b04b0-f4d1-0310-9a6d-de3e77497b0e

TODO
dgamelaunch.c
dgamelaunch.h
dgl-common.c
examples/dgamelaunch.conf

diff --git a/TODO b/TODO
index b141ac57494c822b67b5685bc9448875afbee923..da3ab5f7c9170e4f85444fe48a721b42a082f88a 100644 (file)
--- 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
 
 -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
 -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)
 -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,
index 463b958281b7352a9ef5a682cbcabc1d37e40f85..bbbf3ca88f6de0daeaaafe5d5ab8dc82937da231 100644 (file)
@@ -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)
index 00b50662f22b7a18231666f3b35b5597ca656625..034c3f8bafe863ceda9b964c29c0ab3660af7ad7 100644 (file)
@@ -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
index 7f1b796e13e08f5b7d1f12f0c5b789a1ac037f76..084e0ea7c0c55fd55db9dd37009448b69e468c62 100644 (file)
@@ -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:
index 41f860d45eb67ed3b22a6dc695ad544e60adcd24..c89708110d9afa470ae7181d7c79e4d88dd6ea2e 100644 (file)
@@ -29,7 +29,7 @@ maxnicklen = 10
 #   [ "<display title>", "<sortname>", <Screen column>, "<printf format>" ]
 #
 # <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)"],
 #                   ["User", "username", 4, "%-15s"],