From: Pasi Kallinen Date: Mon, 4 Jun 2012 15:11:56 +0000 (+0300) Subject: Allow printing raw string. X-Git-Tag: v1.6.1-roc-dev~74 X-Git-Url: https://skyeroc.xyz/gitweb/?a=commitdiff_plain;h=24076115185ce6985f83f445880b8b1c3c243caf;p=dgamelaunch Allow printing raw string. Add escape codes to string substitutions. Some mode docs in the example config file. Make chroot creation script fail with message when no sqlite3. --- diff --git a/TODO b/TODO index 443d7f3..d982d5b 100644 --- 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. diff --git a/config.l b/config.l index 3216bd1..9f797ca 100644 --- 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; } diff --git a/dgamelaunch.h b/dgamelaunch.h index b16f609..e7886fe 100644 --- a/dgamelaunch.h +++ b/dgamelaunch.h @@ -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 */ diff --git a/dgl-common.c b/dgl-common.c index 20aff4f..795be39 100644 --- a/dgl-common.c +++ b/dgl-common.c @@ -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; diff --git a/dgl-create-chroot b/dgl-create-chroot index a6814bc..a24a19d 100755 --- a/dgl-create-chroot +++ b/dgl-create-chroot @@ -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 diff --git a/examples/dgamelaunch.conf b/examples/dgamelaunch.conf index a162274..6df268b 100644 --- a/examples/dgamelaunch.conf +++ b/examples/dgamelaunch.conf @@ -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