From 97abafd41a1c6bc198530bc68ddaeac15963cae4 Mon Sep 17 00:00:00 2001 From: keni Date: Mon, 7 Apr 2008 22:27:18 +0000 Subject: [PATCH] add MAXPLAYERS to SYSCF (trunk only) Add MAXPLAYERS to SYSCF config file; deprecate (but continue to support) MAX_NR_OF_PLAYERS in nethack.sh since it is trivially overridden in many (all?) cases and isn't useful for ports that don't use nethack.sh. --- include/config.h | 6 +++++- include/sys.h | 1 + src/files.c | 9 +++++++++ src/sys.c | 1 + sys/unix/hints/macosx | 3 ++- sys/unix/nethack.sh | 1 + sys/unix/unixmain.c | 9 +++++++++ 7 files changed, 28 insertions(+), 2 deletions(-) diff --git a/include/config.h b/include/config.h index 9cc1baa10..bdcf023f5 100644 --- a/include/config.h +++ b/include/config.h @@ -149,6 +149,9 @@ * available in a global config space, with the compiled-in * entries as defaults: * WIZARD ( a value of * allows anyone to be wizard) + * MAXPLAYERS (see MAX_NR_OF_PLAYERS above and nethack.sh) + * SUPPORT (how to get local support)(no default) + * RECOVER (how to recover a game at your site)(no default) * * The following options select how the config space is stored: * SYSCF_FILE in the named file @@ -270,7 +273,8 @@ /* * If it is desirable to limit the number of people that can play Hack - * simultaneously, define HACKDIR, SECURE and MAX_NR_OF_PLAYERS. + * simultaneously, define HACKDIR, SECURE and MAX_NR_OF_PLAYERS (or use + * MAXPLAYERS under SYSCF). * #define MAX_NR_OF_PLAYERS 6 */ #endif /* CHDIR */ diff --git a/include/sys.h b/include/sys.h index 61209f452..7ec3db55b 100644 --- a/include/sys.h +++ b/include/sys.h @@ -13,6 +13,7 @@ struct sysopt { char *support; /* local support contact */ char *recover; /* how to run recover - may be overridden by win port */ char *wizards; + int maxplayers; }; E struct sysopt sysopt; diff --git a/src/files.c b/src/files.c index bddfc2131..411972145 100644 --- a/src/files.c +++ b/src/files.c @@ -2078,6 +2078,15 @@ int src; if(sysopt.recover) free(sysopt.recover); sysopt.recover = alloc(strlen(bufp)); (void) strcpy(sysopt.recover, bufp); + } else if ( (src==SET_IN_SYS) && match_varname(buf, "MAXPLAYERS", 10)) { + int temp = atoi(bufp); + /* XXX to get more than 25, need to rewrite all lock code */ + if(temp > 0 && temp <= 25){ + sysopt.maxplayers = temp; + } else { + raw_printf("Illegal value in MAXPLAYERS."); + return 0; + } #endif } else if (match_varname(buf, "BOULDER", 3)) { (void) get_uchars(fp, buf, bufp, &iflags.bouldersym, TRUE, diff --git a/src/sys.c b/src/sys.c index 3a950132c..895c73438 100644 --- a/src/sys.c +++ b/src/sys.c @@ -14,5 +14,6 @@ sys_early_init(){ /* replace use of WIZARD vs WIZARD_NAME vs KR1ED, by filling this in */ #endif sysopt.wizards = NULL; + sysopt.maxplayers = 0; /* XXX eventually replace MAX_NR_OF_PLAYERS */ } diff --git a/sys/unix/hints/macosx b/sys/unix/hints/macosx index 2b93c341f..c6778f4e5 100644 --- a/sys/unix/hints/macosx +++ b/sys/unix/hints/macosx @@ -18,8 +18,9 @@ HACKDIR=$(PREFIX)/nethackdir CC=gcc -W -Wimplicit -Wreturn-type -Wunused -Wformat -Wswitch -Wshadow -Wcast-qual -Wwrite-strings -DGCC_WARN # XXX -g vs -O should go here, -I../include goes in the makefile -CFLAGS=-g -I../include $(CFLAGS2) +CFLAGS=-g -I../include $(CFLAGS2) $(CFLAGS3) CFLAGS2=-DNOCLIPPING -DNOMAIL -DNOTPARMDECL -DHACKDIR=\"$(HACKDIR)\" +CFLAGS3=-DSYSCF -DSYSCF_FILE=\"$(HACKDIR)/sysconf\" -DSECURE WINSRC = $(WINTTYSRC) WINOBJ = $(WINTTYOBJ) diff --git a/sys/unix/nethack.sh b/sys/unix/nethack.sh index ebf4ede75..3966fb63b 100644 --- a/sys/unix/nethack.sh +++ b/sys/unix/nethack.sh @@ -4,6 +4,7 @@ HACKDIR=/usr/games/lib/nethackdir export HACKDIR HACK=$HACKDIR/nethack +# NB: MAXNROFPLAYERS is deprecated in favor of MAXPLAYERS in SYSCF. MAXNROFPLAYERS=4 # Since Nethack.ad is installed in HACKDIR, add it to XUSERFILESEARCHPATH diff --git a/sys/unix/unixmain.c b/sys/unix/unixmain.c index fd0b27d0b..773cda08f 100644 --- a/sys/unix/unixmain.c +++ b/sys/unix/unixmain.c @@ -7,6 +7,7 @@ #include "hack.h" #include "dlb.h" +#include #include #include #include @@ -373,12 +374,20 @@ char *argv[]; } } + /* XXX This is deprecated in favor of SYSCF with MAXPLAYERS. Make + * an error in next release. */ if(argc > 1) locknum = atoi(argv[1]); #ifdef MAX_NR_OF_PLAYERS + /* limit to compile-time limit */ if(!locknum || locknum > MAX_NR_OF_PLAYERS) locknum = MAX_NR_OF_PLAYERS; #endif +#ifdef SYSCF + /* let syscf override compile-time limit */ + if(!locknum || (sysopt.maxplayers && locknum > sysopt.maxplayers)) + locknum = sysopt.maxplayers; +#endif } #ifdef CHDIR -- 2.40.0