From b691b5f9114de96aeb26ae0a65dbf05194324726 Mon Sep 17 00:00:00 2001 From: Michael Meyer Date: Tue, 12 Nov 2024 17:12:17 -0500 Subject: [PATCH] Add config "ifnxsleep" command For sleeping/delaying a certain amount of time if the specified file does not exist. Intended for use in delaying games iff no save file exists, to ease up on the server load from start scumming (especially automated start scumming). Sleep 5 seconds if /path/to/file.txt does not exist: | ifnxsleep 5 "/path/to/file.txt" --- config.l | 1 + dgamelaunch.h | 3 ++- dgl-common.c | 10 ++++++++++ examples/dgamelaunch.conf | 2 ++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/config.l b/config.l index bc06d29..6eff8ef 100644 --- a/config.l +++ b/config.l @@ -142,6 +142,7 @@ return { yylval.i = DGLCMD_RETURN; return TYPE_DGLCMD0; } redraw { yylval.i = DGLCMD_REDRAW; return TYPE_DGLCMD0; } rawprint { yylval.i = DGLCMD_RAWPRINT; return TYPE_DGLCMD1; } sleep { yylval.i = DGLCMD_SLEEP; return TYPE_DGLCMD1; } +ifnxsleep { yylval.i = DGLCMD_IF_NX_SLEEP; return TYPE_DGLCMD2; } DEFINE { return TYPE_DEFINE_GAME; } diff --git a/dgamelaunch.h b/dgamelaunch.h index 2efebee..0402d26 100644 --- a/dgamelaunch.h +++ b/dgamelaunch.h @@ -83,7 +83,8 @@ typedef enum DGLCMD_SUBMENU, /* submenu "foo" */ DGLCMD_REDRAW, /* redraw */ DGLCMD_RETURN, /* return */ - DGLCMD_SLEEP /* sleep */ + DGLCMD_SLEEP, /* sleep foo */ + DGLCMD_IF_NX_SLEEP, /* ifnxsleep foo bar */ } dglcmd_actions; typedef enum diff --git a/dgl-common.c b/dgl-common.c index 89a342f..aa23681 100644 --- a/dgl-common.c +++ b/dgl-common.c @@ -463,6 +463,16 @@ dgl_exec_cmdqueue_w(struct dg_cmdpart *queue, int game, struct dg_user *me, char case DGLCMD_RETURN: return_from_submenu = 1; break; + case DGLCMD_IF_NX_SLEEP: + if (p2) { + FILE *tmpfile; + tmpfile = fopen(p2, "r"); + if (tmpfile) { + fclose(tmpfile); + break; + } + } + /* fall through if file does not exist */ case DGLCMD_SLEEP: if (p1) { char *end; diff --git a/examples/dgamelaunch.conf b/examples/dgamelaunch.conf index b4276e3..187d526 100644 --- a/examples/dgamelaunch.conf +++ b/examples/dgamelaunch.conf @@ -146,6 +146,8 @@ default_term = "xterm" # play_if_exist "foo" "file" = start game "foo", if file "file" exists. # submenu "foo" = go to submenu "foo" # return = return from submenu +# sleep "foo" = sleep for "foo" seconds +# ifnxsleep "foo" "file" = sleep for "foo" seconds if file "file" does not exist. # # NOTE: edit_options-command was removed. use ifnxcp and exec to simulate it. # -- 2.47.3