Change MSGHANDLER from compile-time to sysconf

This commit is contained in:
Pasi Kallinen
2024-10-19 10:47:53 +03:00
parent d35aa35c3f
commit 696af89299
11 changed files with 39 additions and 29 deletions
+4
View File
@@ -6064,6 +6064,10 @@ escape command (!). The syntax is the same as WIZARDS.
EXPLORERS\ =\ A list of users who are allowed to use the explore mode. EXPLORERS\ =\ A list of users who are allowed to use the explore mode.
The syntax is the same as WIZARDS. The syntax is the same as WIZARDS.
.lp .lp
MSGHANDLER\ =\ A path and filename of executable. Whenever a message-window
message is shown, NetHack runs this program. The program will get
the message as the only parameter.
.lp
MAXPLAYERS\ =\ Limit the maximum number of games that can be running MAXPLAYERS\ =\ Limit the maximum number of games that can be running
at the same time. at the same time.
.lp .lp
+5
View File
@@ -6703,6 +6703,11 @@ The syntax is the same as WIZARDS.
A list of users who are allowed to use the explore mode. A list of users who are allowed to use the explore mode.
The syntax is the same as WIZARDS. The syntax is the same as WIZARDS.
%.lp %.lp
\item[\ib{MSGHANDLER}]
A path and filename of executable. Whenever a message-window
message is shown, NetHack runs this program. The program will get
the message as the only parameter.
%.lp
\item[\ib{MAXPLAYERS}] \item[\ib{MAXPLAYERS}]
Limit the maximum number of games that can be running at the same time. Limit the maximum number of games that can be running at the same time.
%.lp %.lp
+1
View File
@@ -1474,6 +1474,7 @@ interactively setting a status highlight for hunger with 'O' and choosing
a pet with the hides-under attribute could "move reluctantly over" a cursed a pet with the hides-under attribute could "move reluctantly over" a cursed
object and then hide under it object and then hide under it
prevent monster generation in the sokoban trap hallway prevent monster generation in the sokoban trap hallway
change MSGHANDLER from compile-time to sysconf option
Fixes to 3.7.0-x General Problems Exposed Via git Repository Fixes to 3.7.0-x General Problems Exposed Via git Repository
-6
View File
@@ -641,12 +641,6 @@ typedef unsigned char uchar;
* at least 28 additional rows beneath the status window on your terminal */ * at least 28 additional rows beneath the status window on your terminal */
/* #define TTY_PERM_INVENT */ /* #define TTY_PERM_INVENT */
/* NetHack will execute an external program whenever a new message-window
* message is shown. The program to execute is given in environment variable
* NETHACK_MSGHANDLER. It will get the message as the only parameter.
* Only available with POSIX_TYPES, GNU C, or WIN32 */
/* #define MSGHANDLER */
/* enable status highlighting via STATUS_HILITE directives in run-time /* enable status highlighting via STATUS_HILITE directives in run-time
config file and the 'statushilites' option */ config file and the 'statushilites' option */
#define STATUS_HILITES /* support hilites of status fields */ #define STATUS_HILITES /* support hilites of status fields */
+1
View File
@@ -15,6 +15,7 @@ struct sysopt {
char *shellers; /* like wizards, for ! command (-DSHELL); also ^Z */ char *shellers; /* like wizards, for ! command (-DSHELL); also ^Z */
char *genericusers; /* usernames that prompt for user name */ char *genericusers; /* usernames that prompt for user name */
char *debugfiles; /* files to show debugplines in. '*' is all. */ char *debugfiles; /* files to show debugplines in. '*' is all. */
char *msghandler;
#ifdef DUMPLOG #ifdef DUMPLOG
char *dumplogfile; /* where the dump file is saved */ char *dumplogfile; /* where the dump file is saved */
#endif #endif
+11
View File
@@ -173,6 +173,7 @@ staticfn boolean cnf_line_catname(char *);
#ifdef SYSCF #ifdef SYSCF
staticfn boolean cnf_line_WIZARDS(char *); staticfn boolean cnf_line_WIZARDS(char *);
staticfn boolean cnf_line_SHELLERS(char *); staticfn boolean cnf_line_SHELLERS(char *);
staticfn boolean cnf_line_MSGHANDLER(char *);
staticfn boolean cnf_line_EXPLORERS(char *); staticfn boolean cnf_line_EXPLORERS(char *);
staticfn boolean cnf_line_DEBUGFILES(char *); staticfn boolean cnf_line_DEBUGFILES(char *);
staticfn boolean cnf_line_DUMPLOGFILE(char *); staticfn boolean cnf_line_DUMPLOGFILE(char *);
@@ -2756,6 +2757,15 @@ cnf_line_SHELLERS(char *bufp)
return TRUE; return TRUE;
} }
staticfn boolean
cnf_line_MSGHANDLER(char *bufp)
{
if (sysopt.msghandler)
free((genericptr_t) sysopt.msghandler);
sysopt.msghandler = dupstr(bufp);
return TRUE;
}
staticfn boolean staticfn boolean
cnf_line_EXPLORERS(char *bufp) cnf_line_EXPLORERS(char *bufp)
{ {
@@ -3272,6 +3282,7 @@ static const struct match_config_line_stmt {
#ifdef SYSCF #ifdef SYSCF
CNFL_S(WIZARDS, 7), CNFL_S(WIZARDS, 7),
CNFL_S(SHELLERS, 8), CNFL_S(SHELLERS, 8),
CNFL_S(MSGHANDLER, 9),
CNFL_S(EXPLORERS, 7), CNFL_S(EXPLORERS, 7),
CNFL_S(DEBUGFILES, 5), CNFL_S(DEBUGFILES, 5),
CNFL_S(DUMPLOGFILE, 7), CNFL_S(DUMPLOGFILE, 7),
-3
View File
@@ -478,9 +478,6 @@ static const char *const build_opts[] = {
#ifdef HOLD_LOCKFILE_OPEN #ifdef HOLD_LOCKFILE_OPEN
"exclusive lock on level 0 file", "exclusive lock on level 0 file",
#endif #endif
#ifdef MSGHANDLER
"external program as a message handler",
#endif
#if defined(HANGUPHANDLING) && !defined(NO_SIGNAL) #if defined(HANGUPHANDLING) && !defined(NO_SIGNAL)
#ifdef SAFERHANGUP #ifdef SAFERHANGUP
"deferred handling of hangup signal", "deferred handling of hangup signal",
+6 -20
View File
@@ -11,9 +11,7 @@
staticfn void putmesg(const char *); staticfn void putmesg(const char *);
staticfn char *You_buf(int); staticfn char *You_buf(int);
#if defined(MSGHANDLER)
staticfn void execplinehandler(const char *); staticfn void execplinehandler(const char *);
#endif
#ifdef USER_SOUNDS #ifdef USER_SOUNDS
extern void maybe_play_sound(const char *); extern void maybe_play_sound(const char *);
#endif #endif
@@ -262,9 +260,7 @@ vpline(const char *line, va_list the_args)
putmesg(line); putmesg(line);
#if defined(MSGHANDLER)
execplinehandler(line); execplinehandler(line);
#endif
/* this gets cleared after every pline message */ /* this gets cleared after every pline message */
iflags.last_msg = PLNMSG_UNKNOWN; iflags.last_msg = PLNMSG_UNKNOWN;
@@ -564,9 +560,7 @@ vraw_printf(const char *line, va_list the_args)
pbuf[BUFSZ - 1] = '\0'; /* terminate strncpy or truncate vsprintf */ pbuf[BUFSZ - 1] = '\0'; /* terminate strncpy or truncate vsprintf */
} }
raw_print(line); raw_print(line);
#if defined(MSGHANDLER)
execplinehandler(line); execplinehandler(line);
#endif
if (!program_state.beyond_savefile_load) if (!program_state.beyond_savefile_load)
ge.early_raw_messages++; ge.early_raw_messages++;
} }
@@ -626,7 +620,6 @@ impossible(const char *s, ...)
RESTORE_WARNING_FORMAT_NONLITERAL RESTORE_WARNING_FORMAT_NONLITERAL
#if defined(MSGHANDLER)
static boolean use_pline_handler = TRUE; static boolean use_pline_handler = TRUE;
staticfn void staticfn void
@@ -636,27 +629,21 @@ execplinehandler(const char *line)
int f; int f;
#endif #endif
const char *args[3]; const char *args[3];
char *env;
if (!use_pline_handler) if (!use_pline_handler || !sysopt.msghandler)
return; return;
if (!(env = nh_getenv("NETHACK_MSGHANDLER"))) {
use_pline_handler = FALSE;
return;
}
#if defined(POSIX_TYPES) || defined(__GNUC__) #if defined(POSIX_TYPES) || defined(__GNUC__)
f = fork(); f = fork();
if (f == 0) { /* child */ if (f == 0) { /* child */
args[0] = env; args[0] = sysopt.msghandler;
args[1] = line; args[1] = line;
args[2] = NULL; args[2] = NULL;
(void) setgid(getgid()); (void) setgid(getgid());
(void) setuid(getuid()); (void) setuid(getuid());
(void) execv(args[0], (char *const *) args); (void) execv(args[0], (char *const *) args);
perror((char *) 0); perror((char *) 0);
(void) fprintf(stderr, "Exec to message handler %s failed.\n", env); (void) fprintf(stderr, "Exec to message handler %s failed.\n", sysopt.msghandler);
nh_terminate(EXIT_FAILURE); nh_terminate(EXIT_FAILURE);
} else if (f > 0) { } else if (f > 0) {
int status; int status;
@@ -670,16 +657,15 @@ execplinehandler(const char *line)
#elif defined(WIN32) #elif defined(WIN32)
{ {
intptr_t ret; intptr_t ret;
args[0] = env; args[0] = sysopt.msghandler;
args[1] = line; args[1] = line;
args[2] = NULL; args[2] = NULL;
ret = _spawnv(_P_NOWAIT, env, args); ret = _spawnv(_P_NOWAIT, sysopt.msghandler, args);
} }
#else #else
#error MSGHANDLER is not implemented on this system. use_pline_handler = FALSE;
#endif #endif
} }
#endif /* MSGHANDLER */
/* /*
* varargs handling for files.c * varargs handling for files.c
+3
View File
@@ -48,6 +48,7 @@ sys_early_init(void)
sysopt.shellers = (char *) 0; sysopt.shellers = (char *) 0;
sysopt.explorers = (char *) 0; sysopt.explorers = (char *) 0;
sysopt.genericusers = (char *) 0; sysopt.genericusers = (char *) 0;
sysopt.msghandler = (char *) 0;
sysopt.maxplayers = 0; /* XXX eventually replace MAX_NR_OF_PLAYERS */ sysopt.maxplayers = 0; /* XXX eventually replace MAX_NR_OF_PLAYERS */
sysopt.bones_pools = 0; sysopt.bones_pools = 0;
sysopt.livelog = LL_NONE; sysopt.livelog = LL_NONE;
@@ -115,6 +116,8 @@ sysopt_release(void)
free((genericptr_t) sysopt.debugfiles), free((genericptr_t) sysopt.debugfiles),
sysopt.debugfiles = (char *) 0; sysopt.debugfiles = (char *) 0;
sysopt.env_dbgfl = 0; sysopt.env_dbgfl = 0;
if (sysopt.msghandler)
free((genericptr_t) sysopt.msghandler), sysopt.msghandler = (char *) 0;
#ifdef DUMPLOG #ifdef DUMPLOG
if (sysopt.dumplogfile) if (sysopt.dumplogfile)
free((genericptr_t) sysopt.dumplogfile), sysopt.dumplogfile=(char *) 0; free((genericptr_t) sysopt.dumplogfile), sysopt.dumplogfile=(char *) 0;
+4
View File
@@ -32,6 +32,10 @@ EXPLORERS=*
# Uses the same syntax as the WIZARDS and EXPLORERS options above. # Uses the same syntax as the WIZARDS and EXPLORERS options above.
#SHELLERS= #SHELLERS=
# Execute this program whenever a new message-window message is shown.
# The program will get the message text as the only parameter.
#MSGHANDLER=/usr/bin/espeak
# If the user name is found in this list, prompt for username instead. # If the user name is found in this list, prompt for username instead.
# Uses the same syntax as the WIZARDS option above. # Uses the same syntax as the WIZARDS option above.
# A public server should probably disable this. # A public server should probably disable this.
+4
View File
@@ -15,6 +15,10 @@ WIZARDS=*
# Uses the same syntax as the WIZARDS option above. # Uses the same syntax as the WIZARDS option above.
#SHELLERS= #SHELLERS=
# Execute this program whenever a new message-window message is shown.
# The program will get the message text as the only parameter.
#MSGHANDLER=\path\program
# Show debugging information originating from these source files. # Show debugging information originating from these source files.
# Use '*' for all, or list source files separated by spaces. # Use '*' for all, or list source files separated by spaces.
# Only available if game has been compiled with DEBUG. # Only available if game has been compiled with DEBUG.