]> skyeroc.xyz Git - dgamelaunch/commitdiff
Allow printing raw string.
authorPasi Kallinen <paxed@alt.org>
Mon, 4 Jun 2012 15:11:56 +0000 (18:11 +0300)
committerPasi Kallinen <paxed@alt.org>
Mon, 4 Jun 2012 15:11:56 +0000 (18:11 +0300)
Add escape codes to string substitutions.
Some mode docs in the example config file.
Make chroot creation script fail with message when no sqlite3.

TODO
config.l
dgamelaunch.h
dgl-common.c
dgl-create-chroot
examples/dgamelaunch.conf

diff --git a/TODO b/TODO
index 443d7f3c153cb52724291465a2fe3c3aed4c5b6a..d982d5b3c493f709d3a87e01f34169f3c8b8971e 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,6 +1,4 @@
 
--xterm title escape codes. Title strings defineable in config file?
-
 -allow setting banners for the internal menus, with the same method
  as normal user-defined menus, but only the banner is used from them.
  if no such menu is defined, then uses the default banner file.
index 3216bd1c14df5fec2fdad7fc2a090515bef51bf7..9f797ca5b15504069ca83a925f0c65fb423d0d8c 100644 (file)
--- a/config.l
+++ b/config.l
@@ -120,6 +120,7 @@ quit                { yylval.i = DGLCMD_QUIT;       return TYPE_DGLCMD0; }
 play_game      { yylval.i = DGLCMD_PLAYGAME;    return TYPE_DGLCMD1; }
 submenu                { yylval.i = DGLCMD_SUBMENU;     return TYPE_DGLCMD1; }
 return         { yylval.i = DGLCMD_RETURN;      return TYPE_DGLCMD0; }
+rawprint       { yylval.i = DGLCMD_RAWPRINT;    return TYPE_DGLCMD1; }
 DEFINE         { return TYPE_DEFINE_GAME; }
 
 
index b16f6092539ef66064e9a4ddda6f17e6acc42e3c..e7886fe6fecfe5dba3ffd6ca439de97010806fc1 100644 (file)
@@ -57,6 +57,7 @@ typedef enum
 typedef enum
 {
     DGLCMD_NONE = 0,
+    DGLCMD_RAWPRINT,   /* rawprint "foo" */
     DGLCMD_MKDIR,      /* mkdir foo */
     DGLCMD_CHDIR,      /* chdir foo */
     DGLCMD_IF_NX_CP,   /* ifnxcp foo bar */
index 20aff4f35dcd30d98901a4e5102c673da4d22484..795be39f8c9e644de80ad17c2a0f1889eba1f8e2 100644 (file)
@@ -115,6 +115,7 @@ dgl_format_str(int game, struct dg_user *me, char *str, char *plrname)
     static char buf[1024];
     char *f, *p, *end;
     int ispercent = 0;
+    int isbackslash = 0;
 
     if (!str) return NULL;
 
@@ -172,10 +173,27 @@ dgl_format_str(int game, struct dg_user *me, char *str, char *plrname)
                    p++;
            }
            ispercent = 0;
+       } else if (isbackslash) {
+           switch (*f) {
+           case 'a': *p = '\007'; break;
+           case 'b': *p = '\010'; break;
+           case 't': *p = '\011'; break;
+           case 'n': *p = '\012'; break;
+           case 'v': *p = '\013'; break;
+           case 'f': *p = '\014'; break;
+           case 'r': *p = '\015'; break;
+           case 'e': *p = '\033'; break;
+           default:  *p = *f;
+           }
+           if (p < end)
+               p++;
+           isbackslash = 0;
        } else {
-           if (*f == '%')
+           if (*f == '%') {
                ispercent = 1;
-           else {
+           } else if (*f == '\\') {
+               isbackslash = 1;
+           } else {
                *p = *f;
                if (p < end)
                    p++;
@@ -211,6 +229,9 @@ dgl_exec_cmdqueue(struct dg_cmdpart *queue, int game, struct dg_user *me)
 
        switch (tmp->cmd) {
        default: break;
+       case DGLCMD_RAWPRINT:
+           if (p1) fprintf(stdout, "%s", p1);
+           break;
        case DGLCMD_MKDIR:
            if (p1 && (access(p1, F_OK) != 0)) mkdir(p1, 0755);
            break;
index a6814bc31658c2f7082a6fbd30b4ab3c03ce802c..a24a19dc0c01ae9f481bb951e8a21f923e7b53f3 100755 (executable)
@@ -16,9 +16,9 @@ USRGRP="games:games"
 # COMPRESS from include/config.h; the compression binary to copy. leave blank to skip.
 COMPRESSBIN="/bin/gzip"
 # nethack binary to copy into chroot (leave blank to skip)
-NETHACKBIN="/home/paxed/hacking/coding/nethacksource/nethack-3.4.3-nao/nh343/nethack.343-nao"
+#NETHACKBIN="/home/paxed/hacking/coding/nethacksource/nethack-3.4.3-nao/nh343/nethack.343-nao"
 # fixed data to copy (leave blank to skip)
-NH_PLAYGROUND_FIXED="/home/paxed/hacking/coding/nethacksource/nethack-3.4.3-nao/nh343/"
+#NH_PLAYGROUND_FIXED="/home/paxed/hacking/coding/nethacksource/nethack-3.4.3-nao/nh343/"
 # HACKDIR from include/config.h; aka nethack subdir inside chroot
 NHSUBDIR="/nh343/"
 # VAR_PLAYGROUND from include/unixconf.h
@@ -98,11 +98,15 @@ chown "$USRGRP" "$CHROOT/dgldir/userdata"
 
 
 if [ -n "$SQLITE_DBFILE" ]; then
-  echo "Creating SQLite database at $SQLITE_DBFILE"
-  SQLITE_DBFILE="`echo ${SQLITE_DBFILE%/}`"
-  SQLITE_DBFILE="`echo ${SQLITE_DBFILE#/}`"
-  sqlite3 "$CHROOT/$SQLITE_DBFILE" "create table dglusers (id integer primary key, username text, email text, env text, password text, flags integer);"
-  chown "$USRGRP" "$CHROOT/$SQLITE_DBFILE"
+  if [ "x`which sqlite3`" = "x" ]; then
+      errorexit "No sqlite3 found."
+  else
+      echo "Creating SQLite database at $SQLITE_DBFILE"
+      SQLITE_DBFILE="`echo ${SQLITE_DBFILE%/}`"
+      SQLITE_DBFILE="`echo ${SQLITE_DBFILE#/}`"
+      sqlite3 "$CHROOT/$SQLITE_DBFILE" "create table dglusers (id integer primary key, username text, email text, env text, password text, flags integer);"
+      chown "$USRGRP" "$CHROOT/$SQLITE_DBFILE"
+  fi
 fi
 
 
index a162274a9973211a26644dc36681a7166b6c5da7..6df268b287afac222e59a85189dd01c0ea8e81ad 100644 (file)
@@ -52,7 +52,7 @@ dglroot = "/dgldir/"
 # "$FOO" = timeformat("%F %T")
 # for the timeformat parameter string format, see man strftime
 bannervars = [ "$MOTDTIME" = "2011.10.08",
-              "$SERVERID" = "nethack.alt.org - http://nethack.alt.org/",
+              "$SERVERID" = "$ATTR(14)nethack.alt.org - http://nethack.alt.org/$ATTR()",
               "$DATETIME" = timeformat("%F %T")
             ]
 
@@ -123,6 +123,7 @@ locale = "en_US.UTF-8"
 #   unlink "foo"       = delete file "foo"
 #   setenv "foo" "bar" = set environment variable "foo" to "bar"
 #   exec "foo" "bar"   = execute "foo" with "bar" as it's param
+#   rawprint "foo"     = output string "foo"
 #   chpasswd           = do the change password prompting, if logged in
 #   chmail             = do the change email prompting, if logged in
 #   watch_menu         = go to the watching menu
@@ -148,9 +149,23 @@ locale = "en_US.UTF-8"
 #   %s = short game name, if user has selected a game.
 #   %t = ttyrec path & filename of the last game played.
 #
+# Also some escape codes:
+#   \\ = backslash
+#   \a = bell
+#   \b = backspace
+#   \e = escape character
+#   \f = form feed
+#   \n = newline
+#   \r = carriage return
+#   \t = tab
+#   \v = vertical tab
+#
 # eg. commands[login] = mkdir "foo", unlink "bar", setenv "Z" "foo"
 #
 
+# Change the terminal title: (assuming terminals support the escape code)
+#commands[dglstart] = rawprint "\e]2;nethack.alt.org\a"
+
 # create the user's dirs when they register
 commands[register] = mkdir "%ruserdata/%n",
                      mkdir "%ruserdata/%n/dumplog",
@@ -186,6 +201,17 @@ menu["mainmenu_anon"] {
 menu["mainmenu_user"] {
 # contents of this file are written to screen.
 # the file must be inside the chroot.
+# Some string subsitutions can be done in the file:
+# $INCLUDE(filename) =  includes the file to this file.
+# String substitutions defined in bannervars-section above.
+# $VERSION           =  dgamelaunch version
+# $USERNAME          =  user name (or [Anonymous] if not logged in)
+# $ATTR(params)      =  change text color and attributes.
+#        params can be either number (to set the text color),
+#       one, or any of "b" (bold), "s" (standout), "u" (underline),
+#       "r" (reverse) or "d" (dim),
+#       or both color number and attribute characters, separated by colon.
+#       Empty param resets color and attributes to default.
         bannerfile = "dgl_menu_main_user.txt"
 # after which cursor is moved to this location
 # if cursor-definition is missing, the cursor is put