From: gosselin@ll.mit.edu (Dave Gosselin)
Subject: Server Patch
Summary: nifty server patch to use environment variables for system files
Keywords: cool, nifty, save this file, fnord
Organization: MIT Lincoln Laboratory
Date: Fri, 6 Nov 92 22:20:28 GMT

I figured this patch may be of intrest to some. It is a patch to the
final bronco server code to allow the server god to move the server
files around without recompiling. This is done by allowing the server
god to set an environment variable (the default is NTSERV_PATH). The
code checks to see if theis variable is set and if so looks for the
appropriate server files (.global, .planets, robotII, et al) in that
directory. This mod also allows a binary server to be distributed if
people wish to. Well enough useful info, back to the flames.

Does this make me a server hack 8-)

dave
aka: Tom Servo, Crow T. Robot, BermudaTriangle, soma
gosselin@ll.mit.edu

------------- cut and save ---------------------------------------

*** Makefile	Fri Nov  6 16:08:40 1992
--- ../../ntserv/Makefile	Fri Nov  6 13:58:18 1992
***************
*** 31,43 ****
  	    timecheck.o \
  	    torp.o \
  	    util.o \
! 	    warning.o
  
  D_OBJS =        daemonII.o \
                  sintab.o \
  		sysdefaults.o \
  		wander2.o \
!                 data.o
  #               random.o   -- put this back if you have a better rand()
  
  r_OBJS =        data.o \
--- 31,45 ----
  	    timecheck.o \
  	    torp.o \
  	    util.o \
! 	    warning.o\
!             getpath.o
  
  D_OBJS =        daemonII.o \
                  sintab.o \
  		sysdefaults.o \
  		wander2.o \
!                 data.o \
!                 getpath.o
  #               random.o   -- put this back if you have a better rand()
  
  r_OBJS =        data.o \
***************
*** 53,59 ****
                  startdaemon.o \
  		sysdefaults.o \
                  torp.o \
!                 util.o
  
  P_OBJS =        data.o \
                  detonate.o \
--- 55,62 ----
                  startdaemon.o \
  		sysdefaults.o \
                  torp.o \
!                 util.o \
!                 getpath.o
  
  P_OBJS =        data.o \
                  detonate.o \
***************
*** 68,74 ****
                  startdaemon.o \
  		sysdefaults.o \
                  torp.o \
!                 util.o
  
  R_FILES =   coup.c \
  	    data.c \
--- 71,78 ----
                  startdaemon.o \
  		sysdefaults.o \
                  torp.o \
!                 util.o \
!                 getpath.o
  
  R_FILES =   coup.c \
  	    data.c \
***************
*** 94,100 ****
  	    timecheck.c \
  	    torp.c \
  	    util.c \
! 	    warning.c
  
  SRC = 		$(R_FILES) \
  		data.h \
--- 98,105 ----
  	    timecheck.c \
  	    torp.c \
  	    util.c \
! 	    warning.c \
!             getpath.c
  
  SRC = 		$(R_FILES) \
  		data.h \
***************
*** 104,115 ****
  		packets.h \
  		copyright.h
  
! LIBS = -lm 
  
! CFLAGS = -O -DFULL_HOSTNAMES  -I/usr/X11R5/include
  #CFLAGS = -g
  
! all: ntserv daemonII robotII
  
  ntserv: $(R_OBJS) tags
  	cc $(CFLAGS) -o ntserv $(R_OBJS) $(LIBS)
--- 109,120 ----
  		packets.h \
  		copyright.h
  
! LIBS = -lm
  
! CFLAGS = -O -DFULL_HOSTNAMES -I/usr/X11R5/include
  #CFLAGS = -g
  
! all: ntserv daemonII robotII puck
  
  ntserv: $(R_OBJS) tags
  	cc $(CFLAGS) -o ntserv $(R_OBJS) $(LIBS)
***************
*** 127,136 ****
  	cc $(CFLAGS) -o puck $(P_OBJS) $(LIBS)
  	chmod 4751 puck
  
! install: ntserv
! 	-mv /usr/users/terence/bin/ntserv /usr/users/terence/bin/ntserv.old
! 	cp ntserv /usr/users/terence/bin/ntserv
! 	chmod 4751 /usr/users/terence/bin/ntserv
  	-mv $(XTREKDIR)/daemonII $(XTREKDIR)/daemonII.old
  	cp daemonII $(XTREKDIR)
  	chmod 4751 $(XTREKDIR)/daemonII
--- 132,141 ----
  	cc $(CFLAGS) -o puck $(P_OBJS) $(LIBS)
  	chmod 4751 puck
  
! install: ntserv daemonII robotII puck
! 	-mv $(DESTDIR)/ntserv $(DESTDIR)/ntserv.old
! 	cp ntserv $(DESTDIR)/ntserv
! 	chmod 4751 $(DESTDIR)/ntserv
  	-mv $(XTREKDIR)/daemonII $(XTREKDIR)/daemonII.old
  	cp daemonII $(XTREKDIR)
  	chmod 4751 $(XTREKDIR)/daemonII
***************
*** 139,144 ****
--- 144,157 ----
  	chmod 4751 $(XTREKDIR)/robotII
  	touch $(XTREKDIR)/.planets $(XTREKDIR)/.motd
  	chmod 600 $(XTREKDIR)/.planets
+ 	-mv $(DESTDIR)/puck $(DESTDIR)/puck.old
+ 	cp puck $(DESTDIR)
+ 	chmod 4751 $(DESTDIR)/puck
+ 
+ clean:
+ 	rm -f $(R_OBJS) $(D_OBJS) $(r_OBJS) $(P_OBJS) ntserv daemonII
+ 	rm -f robotII puck *~ #*#
+ 
  
  tags:
  	ctags $(SRC)
*** defs.h	Sat Aug  1 23:38:03 1992
--- ../../ntserv/defs.h	Fri Nov  6 13:37:34 1992
***************
*** 96,112 ****
  #define TARG_SELF	0x8
  
  /* Data files to make the game play across daemon restarts. */
  
! #define GLOBAL		"/usr/users/terence/lib/xtrekII/.global"
! #define SCORES		"/usr/users/terence/lib/xtrekII/.scores"
! #define PLFILE		"/usr/users/terence/lib/xtrekII/.planets"
! #define MOTD		"/usr/users/terence/lib/xtrekII/.motd"
! #define DAEMON		"/usr/users/terence/lib/xtrekII/daemonII"
! #define ROBOT		"/usr/users/terence/lib/xtrekII/robotII"
! #define LOGFILENAME     "/usr/users/terence/lib/xtrekII/logfile"
! #define PLAYERFILE	"/usr/users/terence/lib/xtrekII/.players"
! #define CONQFILE	"/usr/users/terence/lib/xtrekII/.conquer"
! #define SYSDEF_FILE     "/usr/users/terence/lib/xtrekII/.sysdef"
  
  /* Other stuff that Ed added */
  
--- 96,132 ----
  #define TARG_SELF	0x8
  
  /* Data files to make the game play across daemon restarts. */
+ /* change 11/6/92 DRG make these into real variables
+ #define GLOBAL		"/home/gosselin/lib/xtrekII/.global"
+ #define SCORES		"/home/gosselin/lib/xtrekII/.scores"
+ #define PLFILE		"/home/gosselin/lib/xtrekII/.planets"
+ #define MOTD		"/home/gosselin/lib/xtrekII/.motd"
+ #define DAEMON		"/home/gosselin/lib/xtrekII/daemonII"
+ #define ROBOT		"/home/gosselin/lib/xtrekII/robotII"
+ #define LOGFILENAME     "/home/gosselin/lib/xtrekII/logfile"
+ #define PLAYERFILE	"/home/gosselin/lib/xtrekII/.players"
+ #define CONQFILE	"/home/gosselin/lib/xtrekII/.conquer"
+ #define SYSDEF_FILE     "/home/gosselin/lib/xtrekII/.sysdef"
+ */
  
! /* Environment variable name. added 11/6/92 DRG */
! #define ENV_NAME        "NTSERV_PATH"
! 
! /* Default path if the environment variable is not found. added 11/6/92 DRG */
! #define DEFAULT_PATH    "/home/gosselin/lib/xtrekII"
! 
! /* Names of the appropriate files. added 11/6/92 DRG */
! 
! #define N_GLOBAL	".global"
! #define N_SCORES	".scores"
! #define N_PLFILE	".planets"
! #define N_MOTD		".motd"
! #define N_DAEMON	"daemonII"
! #define N_ROBOT		"robotII"
! #define N_LOGFILENAME   "logfile"
! #define N_PLAYERFILE	".players"
! #define N_CONQFILE	".conquer"
! #define N_SYSDEF_FILE   ".sysdef"
  
  /* Other stuff that Ed added */
  
*** data.h	Sun Aug  2 02:09:07 1992
--- ../../ntserv/data.h	Fri Nov  6 13:37:37 1992
***************
*** 134,136 ****
--- 134,151 ----
  extern char login[PSEUDOSIZE];
  
  extern struct rank ranks[NUMRANKS];
+ 
+ /* make the files as real character values. added 11/6/92  DRG */
+ 
+ #define FNAMESIZE 256
+ 
+ extern char GLOBAL[FNAMESIZE];
+ extern char SCORES[FNAMESIZE];
+ extern char PLFILE[FNAMESIZE];
+ extern char MOTD[FNAMESIZE];
+ extern char DAEMON[FNAMESIZE];
+ extern char ROBOT[FNAMESIZE];
+ extern char LOGFILENAME[FNAMESIZE];
+ extern char PLAYERFILE[FNAMESIZE];
+ extern char CONQFILE[FNAMESIZE];
+ extern char SYSDEF_FILE[FNAMESIZE];
*** data.c	Sun Aug  2 02:09:04 1992
--- ../../ntserv/data.c	Fri Nov  6 13:37:36 1992
***************
*** 55,61 ****
  int 	showgalactic = 2;
  char 	*shipnos="0123456789abcdefghijklmnopqrstuvwxyz";
  int 	sock= -1;
! int 	xtrekPort=27320;
  int	shipPick;
  int	teamPick;
  int	repCount=0;
--- 55,61 ----
  int 	showgalactic = 2;
  char 	*shipnos="0123456789abcdefghijklmnopqrstuvwxyz";
  int 	sock= -1;
! int 	xtrekPort=2592;
  int	shipPick;
  int	teamPick;
  int	repCount=0;
***************
*** 117,119 ****
--- 117,132 ----
      {30.0, 7.0, 0.0, "Rear Adm."},
      {40.0, 8.0, 0.0, "Admiral"}};
  
+ 
+ /* make the files as real character values. added 11/6/92  DRG */
+ 
+ char GLOBAL[FNAMESIZE];
+ char SCORES[FNAMESIZE];
+ char PLFILE[FNAMESIZE];
+ char MOTD[FNAMESIZE];
+ char DAEMON[FNAMESIZE];
+ char ROBOT[FNAMESIZE];
+ char LOGFILENAME[FNAMESIZE];
+ char PLAYERFILE[FNAMESIZE];
+ char CONQFILE[FNAMESIZE];
+ char SYSDEF_FILE[FNAMESIZE];
*** main.c	Sat Aug  1 23:38:04 1992
--- ../../ntserv/main.c	Fri Nov  6 13:58:15 1992
***************
*** 47,52 ****
--- 47,53 ----
  
      name = *argv++;
      argc--;
+     getpath();  /* added 11/6/92 DRG */
      if ((ptr = rindex(name, '/')) != NULL)
  	name = ptr + 1;
      while (*argv) {
*** puck.c	Sat Aug  1 23:38:05 1992
--- ../../ntserv/puck.c	Fri Nov  6 13:58:16 1992
***************
*** 58,63 ****
--- 58,64 ----
      char str[80];
      int class;			/* ship class 8/9/91 TC */
      
+     getpath();  /* added 11/6/92 DRG */
      class = STARBASE;
      target = -1;		/* no target 7/27/91 TC */
      for( ; argc>1 && argv[1][0]=='-'; argc--,argv++) {
*** daemonII.c	Sat Aug  1 23:38:03 1992
--- ../../ntserv/daemonII.c	Fri Nov  6 13:58:13 1992
***************
*** 64,69 ****
--- 64,70 ----
  	debug = 1;
  
      fprintf(stderr,"Daemon says 'hello!'\n");
+     getpath();  /* added 11/6/92 DRG */
      srandom(getpid());
      readsysdefaults();
      if (!debug) {
*** robotII.c	Sat Aug  1 23:38:06 1992
--- ../../ntserv/robotII.c	Fri Nov  6 13:58:12 1992
***************
*** 58,63 ****
--- 58,64 ----
      char str[80];
      int class;			/* ship class 8/9/91 TC */
      
+     getpath();  /* added 11/6/92 DRG */
      class = BATTLESHIP;
      target = -1;		/* no target 7/27/91 TC */
      for( ; argc>1 && argv[1][0]=='-'; argc--,argv++) {
*** /dev/null	Fri Nov  6 15:01:05 1992
--- ../../ntserv/getpath.c	Fri Nov  6 14:32:34 1992
***************
*** 0 ****
--- 1,62 ----
+ /* 
+  * getpath.c
+  *
+  * David Gosselin 11/6/92
+  *
+  */
+ 
+ #include <stdio.h>
+ #include <sys/types.h>
+ #include <stdlib.h>
+ #include <string.h>
+ #include "defs.h"
+ #include "data.h"
+ 
+ getpath()
+ {
+    char *env_path;
+    char path[256];
+ 
+    if ((env_path = getenv(ENV_NAME)) != NULL) {
+       strcpy(path,env_path);
+       fprintf(stderr,"Got path %s\n",env_path);
+    }
+    else {
+       strcpy(path,DEFAULT_PATH);
+       fprintf(stderr,"Unable to find environment variable %s.",ENV_NAME);
+       fprintf(stderr,"  Assuming: %s\n",DEFAULT_PATH);
+    }
+ 
+    strcat(path,"/");
+ 
+    strcpy(GLOBAL,path);
+    strcat(GLOBAL,N_GLOBAL);
+ 
+    strcpy(SCORES,path);
+    strcat(SCORES,N_SCORES);
+ 
+    strcpy(PLFILE,path);
+    strcat(PLFILE,N_PLFILE);
+    
+    strcpy(MOTD,path);
+    strcat(MOTD,N_MOTD);
+ 
+    strcpy(DAEMON,path);
+    strcat(DAEMON,N_DAEMON);
+ 
+    strcpy(ROBOT,path);
+    strcat(ROBOT,N_ROBOT);
+ 
+    strcpy(LOGFILENAME,path);
+    strcat(LOGFILENAME,N_LOGFILENAME);
+ 
+    strcpy(PLAYERFILE,path);
+    strcat(PLAYERFILE,N_PLAYERFILE);
+ 
+    strcpy(CONQFILE,path);
+    strcat(CONQFILE,N_CONQFILE);
+ 
+    strcpy(SYSDEF_FILE,path);
+    strcat(SYSDEF_FILE,N_SYSDEF_FILE);
+ 
+ }