Add $INCLUDE(filename) menu banner command.
That text in any line of a menu banner file will cause the file 'filename' to be included in that place. git-svn-id: svn://katsu.triplehelix.org/dgamelaunch/trunk@548 db0b04b0-f4d1-0310-9a6d-de3e77497b0e
This commit is contained in:
parent
431ef1e791
commit
082c777fe8
|
@ -338,36 +338,58 @@ bannerstrmangle(char *buf, char *fromstr, char *tostr)
|
||||||
return bufnew;
|
return bufnew;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
freebanner(struct dg_banner *ban)
|
||||||
|
{
|
||||||
|
unsigned int l;
|
||||||
|
if (!ban) return;
|
||||||
|
l = ban->len;
|
||||||
|
|
||||||
|
while (l > 0) {
|
||||||
|
l--;
|
||||||
|
free(ban->lines[l]);
|
||||||
|
}
|
||||||
|
free(ban->lines);
|
||||||
|
ban->len = 0;
|
||||||
|
ban->lines = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
banner_addline(struct dg_banner *ban, char *line)
|
||||||
|
{
|
||||||
|
size_t len = strlen(line);
|
||||||
|
if (!ban) return;
|
||||||
|
ban->len++;
|
||||||
|
ban->lines = realloc (ban->lines, sizeof (char *) * ban->len);
|
||||||
|
if (len >= 80) {
|
||||||
|
len = 80;
|
||||||
|
ban->lines[ban->len - 1] = malloc(len);
|
||||||
|
strncpy(ban->lines[ban->len - 1], line, len);
|
||||||
|
ban->lines[ban->len - 1][len-1] = '\0';
|
||||||
|
} else
|
||||||
|
ban->lines[ban->len - 1] = strdup(line);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
loadbanner (char *fname, struct dg_banner *ban)
|
loadbanner (char *fname, struct dg_banner *ban)
|
||||||
{
|
{
|
||||||
FILE *bannerfile;
|
FILE *bannerfile;
|
||||||
char buf[80];
|
char buf[80];
|
||||||
|
if (ban->len > 23) return;
|
||||||
|
|
||||||
memset (buf, 0, 80);
|
memset (buf, 0, 80);
|
||||||
|
|
||||||
if (ban->lines) return;
|
|
||||||
|
|
||||||
bannerfile = fopen (fname, "r");
|
bannerfile = fopen (fname, "r");
|
||||||
|
|
||||||
if (!bannerfile)
|
if (!bannerfile)
|
||||||
{
|
{
|
||||||
#define NOTE_NO_DGL_BANNER "### NOTE: administrator has not installed a %s file"
|
if (ban->len == 0)
|
||||||
size_t len;
|
banner_addline(ban, "### dgamelaunch " PACKAGE_VERSION " - network console game launcher");
|
||||||
ban->len = 2;
|
snprintf(buf, 80, "### NOTE: administrator has not installed a %s file", fname);
|
||||||
ban->lines = malloc (sizeof (char *));
|
banner_addline(ban, buf);
|
||||||
ban->lines[0] =
|
|
||||||
strdup ("### dgamelaunch " PACKAGE_VERSION
|
|
||||||
" - network console game launcher");
|
|
||||||
len = strlen(fname) + ARRAY_SIZE(NOTE_NO_DGL_BANNER);
|
|
||||||
ban->lines[1] = malloc(len);
|
|
||||||
snprintf(ban->lines[1], len, NOTE_NO_DGL_BANNER, fname);
|
|
||||||
#undef NOTE_NO_DGL_BANNER
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ban->len = 0;
|
|
||||||
|
|
||||||
while (fgets (buf, 80, bannerfile) != NULL)
|
while (fgets (buf, 80, bannerfile) != NULL)
|
||||||
{
|
{
|
||||||
char bufnew[80];
|
char bufnew[80];
|
||||||
|
@ -378,10 +400,18 @@ loadbanner (char *fname, struct dg_banner *ban)
|
||||||
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';
|
||||||
|
|
||||||
ban->len++;
|
|
||||||
ban->lines = realloc (ban->lines, sizeof (char *) * ban->len);
|
|
||||||
|
|
||||||
strncpy(bufnew, buf, 80);
|
strncpy(bufnew, buf, 80);
|
||||||
|
if (strstr(bufnew, "$INCLUDE(")) {
|
||||||
|
char *fn = bufnew + 9;
|
||||||
|
char *fn_end = strchr(fn, ')');
|
||||||
|
if (fn_end) {
|
||||||
|
*fn_end = '\0';
|
||||||
|
if (strcmp(fname, fn)) {
|
||||||
|
banner_addline(ban, fn);
|
||||||
|
loadbanner(fn, ban);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
strncpy(bufnew, bannerstrmangle(bufnew, "$VERSION", PACKAGE_STRING), 80);
|
strncpy(bufnew, bannerstrmangle(bufnew, "$VERSION", PACKAGE_STRING), 80);
|
||||||
strncpy(bufnew, bannerstrmangle(bufnew, "$SERVERID", globalconfig.server_id ? globalconfig.server_id : ""), 80);
|
strncpy(bufnew, bannerstrmangle(bufnew, "$SERVERID", globalconfig.server_id ? globalconfig.server_id : ""), 80);
|
||||||
if (me && loggedin) {
|
if (me && loggedin) {
|
||||||
|
@ -389,11 +419,12 @@ loadbanner (char *fname, struct dg_banner *ban)
|
||||||
} else {
|
} else {
|
||||||
strncpy(bufnew, bannerstrmangle(bufnew, "$USERNAME", "[Anonymous]"), 80);
|
strncpy(bufnew, bannerstrmangle(bufnew, "$USERNAME", "[Anonymous]"), 80);
|
||||||
}
|
}
|
||||||
ban->lines[ban->len - 1] = strdup(bufnew);
|
banner_addline(ban, bufnew);
|
||||||
|
}
|
||||||
|
|
||||||
memset (buf, 0, 80);
|
memset (buf, 0, 80);
|
||||||
|
|
||||||
if (ban->len == 24)
|
if (ban->len >= 24)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2135,7 +2166,10 @@ runmenuloop(struct dg_menu *menu)
|
||||||
mvprintw(menu->cursor_y, menu->cursor_x, "");
|
mvprintw(menu->cursor_y, menu->cursor_x, "");
|
||||||
refresh();
|
refresh();
|
||||||
userchoice = dgl_getch();
|
userchoice = dgl_getch();
|
||||||
if (userchoice == ERR) return 1;
|
if (userchoice == ERR) {
|
||||||
|
freebanner(&ban);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
tmpopt = menu->options;
|
tmpopt = menu->options;
|
||||||
while (tmpopt) {
|
while (tmpopt) {
|
||||||
if (strchr(tmpopt->keys, userchoice)) {
|
if (strchr(tmpopt->keys, userchoice)) {
|
||||||
|
@ -2148,11 +2182,13 @@ runmenuloop(struct dg_menu *menu)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (return_from_submenu) {
|
if (return_from_submenu) {
|
||||||
|
freebanner(&ban);
|
||||||
return_from_submenu = 0;
|
return_from_submenu = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (check_retard(0)) {
|
if (check_retard(0)) {
|
||||||
|
freebanner(&ban);
|
||||||
debug_write("retard");
|
debug_write("retard");
|
||||||
graceful_exit(119);
|
graceful_exit(119);
|
||||||
}
|
}
|
||||||
|
@ -2414,7 +2450,8 @@ main (int argc, char** argv)
|
||||||
graceful_exit(0);
|
graceful_exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
banner.len = 0;
|
||||||
|
banner.lines = NULL;
|
||||||
loadbanner(globalconfig.banner, &banner);
|
loadbanner(globalconfig.banner, &banner);
|
||||||
|
|
||||||
dgl_exec_cmdqueue(globalconfig.cmdqueue[DGLTIME_DGLSTART], 0, NULL);
|
dgl_exec_cmdqueue(globalconfig.cmdqueue[DGLTIME_DGLSTART], 0, NULL);
|
||||||
|
@ -2476,6 +2513,8 @@ main (int argc, char** argv)
|
||||||
if (me)
|
if (me)
|
||||||
free (me);
|
free (me);
|
||||||
|
|
||||||
|
freebanner(&banner);
|
||||||
|
|
||||||
graceful_exit (1);
|
graceful_exit (1);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
Loading…
Reference in New Issue