Change maximum banner line length to 256.
Add color and attribute changing commands to banners: $ATTR() Fix chroot creation script failing if no nethack binary exists.
This commit is contained in:
parent
820cecae54
commit
f29618c783
132
dgamelaunch.c
132
dgamelaunch.c
|
@ -123,6 +123,25 @@ static struct dg_watchcols default_watchcols[] = {
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
int color_remap[16] = {
|
||||||
|
COLOR_PAIR(9) | A_NORMAL,
|
||||||
|
COLOR_PAIR(COLOR_BLUE) | A_NORMAL,
|
||||||
|
COLOR_PAIR(COLOR_GREEN) | A_NORMAL,
|
||||||
|
COLOR_PAIR(COLOR_CYAN) | A_NORMAL,
|
||||||
|
COLOR_PAIR(COLOR_RED) | A_NORMAL,
|
||||||
|
COLOR_PAIR(COLOR_MAGENTA) | A_NORMAL,
|
||||||
|
COLOR_PAIR(COLOR_YELLOW) | A_NORMAL,
|
||||||
|
COLOR_PAIR(COLOR_BLACK) | A_NORMAL,
|
||||||
|
COLOR_PAIR(10) | A_BOLD,
|
||||||
|
COLOR_PAIR(COLOR_BLUE) | A_BOLD,
|
||||||
|
COLOR_PAIR(COLOR_GREEN) | A_BOLD,
|
||||||
|
COLOR_PAIR(COLOR_CYAN) | A_BOLD,
|
||||||
|
COLOR_PAIR(COLOR_RED) | A_BOLD,
|
||||||
|
COLOR_PAIR(COLOR_MAGENTA) | A_BOLD,
|
||||||
|
COLOR_PAIR(COLOR_YELLOW) | A_BOLD,
|
||||||
|
COLOR_PAIR(COLOR_WHITE) | A_BOLD,
|
||||||
|
};
|
||||||
|
|
||||||
static struct dg_watchcols *default_watchcols_list[DGL_MAXWATCHCOLS + 1];
|
static struct dg_watchcols *default_watchcols_list[DGL_MAXWATCHCOLS + 1];
|
||||||
|
|
||||||
struct dg_user *
|
struct dg_user *
|
||||||
|
@ -434,14 +453,14 @@ banner_var_free()
|
||||||
char *
|
char *
|
||||||
banner_var_resolve(struct dg_banner_var *bv)
|
banner_var_resolve(struct dg_banner_var *bv)
|
||||||
{
|
{
|
||||||
static char tmpbuf[81];
|
static char tmpbuf[DGL_BANNER_LINELEN+1];
|
||||||
time_t tstamp;
|
time_t tstamp;
|
||||||
struct tm *ptm;
|
struct tm *ptm;
|
||||||
if (!bv) return NULL;
|
if (!bv) return NULL;
|
||||||
if (!bv->special) return bv->value;
|
if (!bv->special) return bv->value;
|
||||||
time(&tstamp);
|
time(&tstamp);
|
||||||
ptm = gmtime(&tstamp);
|
ptm = gmtime(&tstamp);
|
||||||
strftime(tmpbuf, 80, bv->value, ptm);
|
strftime(tmpbuf, DGL_BANNER_LINELEN, bv->value, ptm);
|
||||||
return tmpbuf;
|
return tmpbuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -479,8 +498,8 @@ banner_addline(struct dg_banner *ban, char *line)
|
||||||
if (!ban) return;
|
if (!ban) return;
|
||||||
ban->len++;
|
ban->len++;
|
||||||
ban->lines = realloc (ban->lines, sizeof (char *) * ban->len);
|
ban->lines = realloc (ban->lines, sizeof (char *) * ban->len);
|
||||||
if (len >= 80) {
|
if (len >= DGL_BANNER_LINELEN) {
|
||||||
len = 80;
|
len = DGL_BANNER_LINELEN;
|
||||||
ban->lines[ban->len - 1] = malloc(len);
|
ban->lines[ban->len - 1] = malloc(len);
|
||||||
strncpy(ban->lines[ban->len - 1], line, len);
|
strncpy(ban->lines[ban->len - 1], line, len);
|
||||||
ban->lines[ban->len - 1][len-1] = '\0';
|
ban->lines[ban->len - 1][len-1] = '\0';
|
||||||
|
@ -492,10 +511,10 @@ void
|
||||||
loadbanner (char *fname, struct dg_banner *ban)
|
loadbanner (char *fname, struct dg_banner *ban)
|
||||||
{
|
{
|
||||||
FILE *bannerfile;
|
FILE *bannerfile;
|
||||||
char buf[80];
|
char buf[DGL_BANNER_LINELEN+1];
|
||||||
if (ban->len > 23) return;
|
if (ban->len > 23) return;
|
||||||
|
|
||||||
memset (buf, 0, 80);
|
memset (buf, 0, DGL_BANNER_LINELEN);
|
||||||
|
|
||||||
bannerfile = fopen (fname, "r");
|
bannerfile = fopen (fname, "r");
|
||||||
|
|
||||||
|
@ -503,22 +522,22 @@ loadbanner (char *fname, struct dg_banner *ban)
|
||||||
{
|
{
|
||||||
if (ban->len == 0)
|
if (ban->len == 0)
|
||||||
banner_addline(ban, "### dgamelaunch " PACKAGE_VERSION " - network console game launcher");
|
banner_addline(ban, "### dgamelaunch " PACKAGE_VERSION " - network console game launcher");
|
||||||
snprintf(buf, 80, "### NOTE: administrator has not installed a %s file", fname);
|
snprintf(buf, DGL_BANNER_LINELEN, "### NOTE: administrator has not installed a %s file", fname);
|
||||||
banner_addline(ban, buf);
|
banner_addline(ban, buf);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (fgets (buf, 80, bannerfile) != NULL)
|
while (fgets (buf, DGL_BANNER_LINELEN, bannerfile) != NULL)
|
||||||
{
|
{
|
||||||
char bufnew[80];
|
char bufnew[DGL_BANNER_LINELEN+1];
|
||||||
int slen;
|
int slen;
|
||||||
|
|
||||||
memset (bufnew, 0, 80);
|
memset (bufnew, 0, DGL_BANNER_LINELEN);
|
||||||
|
|
||||||
slen = strlen(buf);
|
slen = strlen(buf);
|
||||||
if ((slen > 0) && (buf[slen-1] == '\n')) buf[slen-1] = '\0';
|
if ((slen > 0) && (buf[slen-1] == '\n')) buf[slen-1] = '\0';
|
||||||
|
|
||||||
strncpy(bufnew, buf, 80);
|
strncpy(bufnew, buf, DGL_BANNER_LINELEN);
|
||||||
if (strstr(bufnew, "$INCLUDE(")) {
|
if (strstr(bufnew, "$INCLUDE(")) {
|
||||||
char *fn = bufnew + 9;
|
char *fn = bufnew + 9;
|
||||||
char *fn_end = strchr(fn, ')');
|
char *fn_end = strchr(fn, ')');
|
||||||
|
@ -529,22 +548,22 @@ loadbanner (char *fname, struct dg_banner *ban)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
char tmpbufnew[80];
|
char tmpbufnew[DGL_BANNER_LINELEN+1];
|
||||||
struct dg_banner_var *bv = globalconfig.banner_var_list;
|
struct dg_banner_var *bv = globalconfig.banner_var_list;
|
||||||
while (bv) {
|
while (bv) {
|
||||||
strncpy(bufnew, bannerstrmangle(bufnew, tmpbufnew, 80, bv->name, banner_var_resolve(bv)), 80);
|
strncpy(bufnew, bannerstrmangle(bufnew, tmpbufnew, DGL_BANNER_LINELEN, bv->name, banner_var_resolve(bv)), DGL_BANNER_LINELEN);
|
||||||
bv = bv->next;
|
bv = bv->next;
|
||||||
}
|
}
|
||||||
strncpy(bufnew, bannerstrmangle(bufnew, tmpbufnew, 80, "$VERSION", PACKAGE_STRING), 80);
|
strncpy(bufnew, bannerstrmangle(bufnew, tmpbufnew, DGL_BANNER_LINELEN, "$VERSION", PACKAGE_STRING), DGL_BANNER_LINELEN);
|
||||||
if (me && loggedin) {
|
if (me && loggedin) {
|
||||||
strncpy(bufnew, bannerstrmangle(bufnew, tmpbufnew, 80, "$USERNAME", me->username), 80);
|
strncpy(bufnew, bannerstrmangle(bufnew, tmpbufnew, DGL_BANNER_LINELEN, "$USERNAME", me->username), DGL_BANNER_LINELEN);
|
||||||
} else {
|
} else {
|
||||||
strncpy(bufnew, bannerstrmangle(bufnew, tmpbufnew, 80, "$USERNAME", "[Anonymous]"), 80);
|
strncpy(bufnew, bannerstrmangle(bufnew, tmpbufnew, DGL_BANNER_LINELEN, "$USERNAME", "[Anonymous]"), DGL_BANNER_LINELEN);
|
||||||
}
|
}
|
||||||
banner_addline(ban, bufnew);
|
banner_addline(ban, bufnew);
|
||||||
}
|
}
|
||||||
|
|
||||||
memset (buf, 0, 80);
|
memset (buf, 0, DGL_BANNER_LINELEN);
|
||||||
|
|
||||||
if (ban->len >= 24)
|
if (ban->len >= 24)
|
||||||
break;
|
break;
|
||||||
|
@ -557,11 +576,71 @@ void
|
||||||
drawbanner (struct dg_banner *ban)
|
drawbanner (struct dg_banner *ban)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
char *tmpch, *tmpch2, *splch;
|
||||||
|
int attr = 0, oattr = 0;
|
||||||
|
|
||||||
if (!ban) return;
|
if (!ban) return;
|
||||||
|
|
||||||
for (i = 0; i < ban->len; i++)
|
for (i = 0; i < ban->len; i++) {
|
||||||
mvaddstr (1 + i, 1, ban->lines[i]);
|
char *tmpbuf = strdup(ban->lines[i]);
|
||||||
|
char *tmpbuf2 = tmpbuf;
|
||||||
|
int ok = 0;
|
||||||
|
int x = 1;
|
||||||
|
do {
|
||||||
|
ok = 0;
|
||||||
|
if ((tmpch = strstr(tmpbuf2, "$ATTR("))) {
|
||||||
|
if ((tmpch2 = strstr(tmpch, ")"))) {
|
||||||
|
int spl = 0;
|
||||||
|
char *nxttmpch;
|
||||||
|
ok = 1;
|
||||||
|
oattr = attr;
|
||||||
|
attr = A_NORMAL;
|
||||||
|
*tmpch = *tmpch2 = '\0';
|
||||||
|
tmpch += 6;
|
||||||
|
nxttmpch = tmpch;
|
||||||
|
do {
|
||||||
|
spl = 0;
|
||||||
|
splch = strchr(tmpch, ';');
|
||||||
|
if (splch && *splch) {
|
||||||
|
spl = 1;
|
||||||
|
nxttmpch = splch;
|
||||||
|
*nxttmpch = '\0';
|
||||||
|
nxttmpch++;
|
||||||
|
}
|
||||||
|
if (tmpch && *tmpch) {
|
||||||
|
switch (*tmpch) {
|
||||||
|
default: break;
|
||||||
|
case '0': case '1': case '2': case '3': case '4':
|
||||||
|
case '5': case '6': case '7': case '8': case '9':
|
||||||
|
{
|
||||||
|
int num = atoi(tmpch);
|
||||||
|
if (num >= 0 && num <= 15)
|
||||||
|
attr |= color_remap[num];
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'b': attr |= A_BOLD; break;
|
||||||
|
case 's': attr |= A_STANDOUT; break;
|
||||||
|
case 'u': attr |= A_UNDERLINE; break;
|
||||||
|
case 'r': attr |= A_REVERSE; break;
|
||||||
|
case 'd': attr |= A_DIM; break;
|
||||||
|
}
|
||||||
|
} else attr = A_NORMAL;
|
||||||
|
tmpch = nxttmpch;
|
||||||
|
} while (spl);
|
||||||
|
|
||||||
|
mvaddstr(1 + i, x, tmpbuf2);
|
||||||
|
if (oattr) attroff(oattr);
|
||||||
|
if (attr) attron(attr);
|
||||||
|
x += strlen(tmpbuf2);
|
||||||
|
tmpch2++;
|
||||||
|
tmpbuf2 = tmpch2;
|
||||||
|
} else
|
||||||
|
mvaddstr (1 + i, x, tmpbuf2);
|
||||||
|
} else
|
||||||
|
mvaddstr (1 + i, x, tmpbuf2);
|
||||||
|
} while (ok);
|
||||||
|
free(tmpbuf);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -1678,8 +1757,19 @@ initcurses ()
|
||||||
#ifdef USE_NCURSES_COLOR
|
#ifdef USE_NCURSES_COLOR
|
||||||
start_color();
|
start_color();
|
||||||
use_default_colors();
|
use_default_colors();
|
||||||
init_pair(1, -1, -1);
|
|
||||||
init_pair(2, COLOR_RED, -1);
|
init_pair(COLOR_BLACK, COLOR_WHITE, COLOR_BLACK);
|
||||||
|
init_pair(COLOR_RED, COLOR_RED, COLOR_BLACK);
|
||||||
|
init_pair(COLOR_GREEN, COLOR_GREEN, COLOR_BLACK);
|
||||||
|
init_pair(COLOR_YELLOW, COLOR_YELLOW, COLOR_BLACK);
|
||||||
|
init_pair(COLOR_BLUE, COLOR_BLUE, COLOR_BLACK);
|
||||||
|
init_pair(COLOR_MAGENTA, COLOR_MAGENTA, COLOR_BLACK);
|
||||||
|
init_pair(COLOR_CYAN, COLOR_CYAN, COLOR_BLACK);
|
||||||
|
init_pair(COLOR_WHITE, COLOR_WHITE, COLOR_BLACK);
|
||||||
|
init_pair(9, 0, COLOR_BLACK);
|
||||||
|
init_pair(10, COLOR_BLACK, COLOR_BLACK);
|
||||||
|
init_pair(11, -1, -1);
|
||||||
|
|
||||||
if (globalconfig.utf8esc) write(1, "\033%G", 3);
|
if (globalconfig.utf8esc) write(1, "\033%G", 3);
|
||||||
#endif
|
#endif
|
||||||
clear();
|
clear();
|
||||||
|
|
|
@ -25,14 +25,16 @@
|
||||||
|
|
||||||
#define DGL_MAXWATCHCOLS 10
|
#define DGL_MAXWATCHCOLS 10
|
||||||
|
|
||||||
|
#define DGL_BANNER_LINELEN 256 /* max. length of banner lines*/
|
||||||
|
|
||||||
#ifdef USE_NCURSES_COLOR
|
#ifdef USE_NCURSES_COLOR
|
||||||
# define CLR_NORMAL COLOR_PAIR(1) | A_NORMAL
|
# define CLR_NORMAL COLOR_PAIR(11) | A_NORMAL
|
||||||
# define CLR_RED COLOR_PAIR(2) | A_NORMAL
|
# define CLR_RED COLOR_PAIR(COLOR_RED) | A_NORMAL
|
||||||
#else
|
#else
|
||||||
# define CLR_NORMAL 0
|
# define CLR_NORMAL 0
|
||||||
# define CLR_RED 0
|
# define CLR_RED 0
|
||||||
#endif
|
#endif
|
||||||
|
extern int color_remap[];
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
|
|
|
@ -15,7 +15,7 @@ CHROOT="/opt/nethack/nethack.alt.org/"
|
||||||
USRGRP="games:games"
|
USRGRP="games:games"
|
||||||
# COMPRESS from include/config.h; the compression binary to copy. leave blank to skip.
|
# COMPRESS from include/config.h; the compression binary to copy. leave blank to skip.
|
||||||
COMPRESSBIN="/bin/gzip"
|
COMPRESSBIN="/bin/gzip"
|
||||||
# nethack binary to copy into chroot
|
# 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)
|
# 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/"
|
||||||
|
@ -149,7 +149,7 @@ NHSUBDIR="`echo ${NHSUBDIR#/}`"
|
||||||
|
|
||||||
mkdir "$CHROOT/$NHSUBDIR"
|
mkdir "$CHROOT/$NHSUBDIR"
|
||||||
|
|
||||||
if [ ! -e "$NETHACKBIN" ]; then
|
if [ -n "$NETHACKBIN" -a ! -e "$NETHACKBIN" ]; then
|
||||||
errorexit "Cannot find NetHack binary $NETHACKBIN"
|
errorexit "Cannot find NetHack binary $NETHACKBIN"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue