Skip to content

Commit

Permalink
Allow printing raw string.
Browse files Browse the repository at this point in the history
Add escape codes to string substitutions.
Some mode docs in the example config file.
Make chroot creation script fail with message when no sqlite3.
  • Loading branch information
paxed committed Jun 4, 2012
1 parent f29618c commit 2407611
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 12 deletions.
2 changes: 0 additions & 2 deletions TODO
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
1 change: 1 addition & 0 deletions config.l
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
1 change: 1 addition & 0 deletions dgamelaunch.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
25 changes: 23 additions & 2 deletions dgl-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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++;
Expand Down Expand Up @@ -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;
Expand Down
18 changes: 11 additions & 7 deletions dgl-create-chroot
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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


Expand Down
28 changes: 27 additions & 1 deletion examples/dgamelaunch.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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")
]

Expand Down Expand Up @@ -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
Expand All @@ -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",
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2407611

Please sign in to comment.