[net.sources.games] patches to search

matt@oddjob.UUCP (Matt Crawford) (08/16/85)

Run this article through "patch", if you have it.
These fixes are due in part to hammer!steveh, pucc-j!rsk and pur-ee!karrmann.
They should make search work under 4.3 as well as 4.2, and they
fix an oops for those who compile without -DINET.

RCS file: RCS/init.c,v
retrieving revision 2.2
diff -c -r2.2 init.c
*** /tmp/,RCSt1011405	Thu Aug 15 17:15:54 1985
--- init.c	Thu Aug 15 17:10:35 1985
***************
*** 1,5
  #ifndef lint
! static char rcsid[] = "$Header: init.c,v 2.2 85/08/06 22:29:44 matt Exp $";
  #endif
  /*
   *

--- 1,5 -----
  #ifndef lint
! static char rcsid[] = "$Header: init.c,v 2.3 85/08/15 17:10:29 matt Exp $";
  #endif
  /*
   *
***************
*** 19,24
   * Copyright (c) 1979
   *
   * $Log:	init.c,v $
   * Revision 2.2  85/08/06  22:29:44  matt
   * Change handling of "r", "b", "g", "j", "q" commands to
   * provide better feedback, using per-player message buffer.

--- 19,27 -----
   * Copyright (c) 1979
   *
   * $Log:	init.c,v $
+  * Revision 2.3  85/08/15  17:10:29  matt
+  * Try to handle missing files a little better.
+  * 
   * Revision 2.2  85/08/06  22:29:44  matt
   * Change handling of "r", "b", "g", "j", "q" commands to
   * provide better feedback, using per-player message buffer.
***************
*** 48,54
  			core_dump(),
  			srand(),
  			rand();
- 	extern	long	lseek();
  	extern	t_player player[NPLAYER];
  	extern	t_alien alien[NALIEN];
  	extern	t_sbase sbase[NBASE];

--- 51,56 -----
  			core_dump(),
  			srand(),
  			rand();
  	extern	t_player player[NPLAYER];
  	extern	t_alien alien[NALIEN];
  	extern	t_sbase sbase[NBASE];
***************
*** 79,89
  	 * clear everything out
  	 */
  	bzero((char *)player, sizeof(t_player) * NPLAYER);
- 	pfd = open(POINTFILE, O_RDWR, 0);
- 	if (pfd < 0) {
- 		perror(POINTFILE);
- 		exit(1);
- 	}
  	/*
  	 * no big deal if we can't open the error log
  	 */

--- 81,86 -----
  	 * clear everything out
  	 */
  	bzero((char *)player, sizeof(t_player) * NPLAYER);
  	/*
  	 * no big deal if we can't open the error log
  	 */
***************
*** 87,93
  	/*
  	 * no big deal if we can't open the error log
  	 */
! 	errfile = open(ERRLOG, O_RDWR|O_CREAT, 0666);
  	if (errfile >= 0) {
  		lseek(errfile, 0L, 2);
  		sprintf(buf, "starting daemon, pid %d\n", getpid());

--- 84,90 -----
  	/*
  	 * no big deal if we can't open the error log
  	 */
! 	errfile = open(ERRLOG, O_RDWR|O_CREAT|O_APPEND, 0666);
  	if (errfile >= 0) {
  		sprintf(buf, "starting daemon, pid %d\n", getpid());
  		errlog(buf);
***************
*** 89,95
  	 */
  	errfile = open(ERRLOG, O_RDWR|O_CREAT, 0666);
  	if (errfile >= 0) {
- 		lseek(errfile, 0L, 2);
  		sprintf(buf, "starting daemon, pid %d\n", getpid());
  		errlog(buf);
  	}

--- 86,91 -----
  	 */
  	errfile = open(ERRLOG, O_RDWR|O_CREAT|O_APPEND, 0666);
  	if (errfile >= 0) {
  		sprintf(buf, "starting daemon, pid %d\n", getpid());
  		errlog(buf);
  	}
***************
*** 92,97
  		lseek(errfile, 0L, 2);
  		sprintf(buf, "starting daemon, pid %d\n", getpid());
  		errlog(buf);
  	}
  	tvec = time((time_t *)0);
  	srand(tvec);

--- 88,98 -----
  	if (errfile >= 0) {
  		sprintf(buf, "starting daemon, pid %d\n", getpid());
  		errlog(buf);
+ 	}
+ 	pfd = open(POINTFILE, O_RDWR|O_CREAT, 0664);
+ 	if (pfd < 0) {
+ 		errlog("Cannot open score file\n");
+ 		exit(1);
  	}
  	tvec = time((time_t *)0);
  	srand(tvec);
RCS file: RCS/ipc.c,v
retrieving revision 2.1
diff -c -r2.1 ipc.c
*** /tmp/,RCSt1011413	Thu Aug 15 17:16:23 1985
--- ipc.c	Thu Aug 15 17:11:49 1985
***************
*** 1,5
  #ifndef lint
! static char rcsid[] = "$Header: ipc.c,v 2.1 85/04/10 17:31:13 matt Stab $";
  #endif
  /*
   *

--- 1,5 -----
  #ifndef lint
! static char rcsid[] = "$Header: ipc.c,v 2.2 85/08/15 17:11:09 matt Exp $";
  #endif
  /*
   *
***************
*** 17,22
   * Copyright (c) 1984
   *
   * $Log:	ipc.c,v $
   * Revision 2.1  85/04/10  17:31:13  matt
   * Major de-linting and minor restructuring.
   * 

--- 17,25 -----
   * Copyright (c) 1984
   *
   * $Log:	ipc.c,v $
+  * Revision 2.2  85/08/15  17:11:09  matt
+  * Adapt to 4.3 (and BRL ?)
+  * 
   * Revision 2.1  85/04/10  17:31:13  matt
   * Major de-linting and minor restructuring.
   * 
***************
*** 132,137
  	/*
  	 * don't take forever when we close the socket!
  	 */
  	if (setsockopt(newsock, SOL_SOCKET, SO_DONTLINGER, 0, 0))
  		errlog("error in setsockopt call\n");
  	/*

--- 135,141 -----
  	/*
  	 * don't take forever when we close the socket!
  	 */
+ #ifdef SO_DONTLINGER
  	if (setsockopt(newsock, SOL_SOCKET, SO_DONTLINGER, 0, 0))
  		errlog("error in setsockopt call\n");
  #else
***************
*** 134,139
  	 */
  	if (setsockopt(newsock, SOL_SOCKET, SO_DONTLINGER, 0, 0))
  		errlog("error in setsockopt call\n");
  	/*
  	 * Sure hope the following read gives all the data in
  	 * one shot.  It isn't guaranteed to, you know!

--- 138,151 -----
  #ifdef SO_DONTLINGER
  	if (setsockopt(newsock, SOL_SOCKET, SO_DONTLINGER, 0, 0))
  		errlog("error in setsockopt call\n");
+ #else
+ 	{
+ 		struct linger linger;
+ 		linger.l_onoff = 0; linger.l_linger = 0;
+ 		if (setsockopt(newsock, SOL_SOCKET, SO_LINGER, &linger, sizeof(linger)))
+ 			errlog("error in setsockopt call\n");
+ 	}
+ #endif
  	/*
  	 * Sure hope the following read gives all the data in
  	 * one shot.  It isn't guaranteed to, you know!
***************
*** 219,224
  	extern	int in_sock;
  	char	hostname[40];
  	struct	servent *serv;
  #endif
  	char	buf[255];
  

--- 231,237 -----
  	extern	int in_sock;
  	char	hostname[40];
  	struct	servent *serv;
+ 	int	on = 1;
  #endif
  	char	buf[255];
  
***************
*** 243,249
  		in_addr.sin_port = htons((short)port);
  	} else
  		in_addr.sin_port = serv->s_port;
! 	if (setsockopt(in_sock, SOL_SOCKET, SO_REUSEADDR, 0, 0) < 0)
  		errlog("error in setsockopt (SO_REUSEADDR)\n");
  	if (bind(in_sock, (struct sockaddr *)&in_addr, sizeof(in_addr))) {
  		errlog("error binding internet port\n");

--- 256,262 -----
  		in_addr.sin_port = htons((short)port);
  	} else
  		in_addr.sin_port = serv->s_port;
! 	if (setsockopt(in_sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof on) < 0)
  		errlog("error in setsockopt (SO_REUSEADDR)\n");
  	if (bind(in_sock, (struct sockaddr *)&in_addr, sizeof(in_addr))) {
  		errlog("error binding internet port\n");
RCS file: RCS/main.c,v
retrieving revision 2.2
diff -c -r2.2 main.c
*** /tmp/,RCSt1011401	Thu Aug 15 17:15:49 1985
--- main.c	Thu Aug 15 17:12:01 1985
***************
*** 1,5
  #ifndef lint
! static char rcsid[] = "$Header: main.c,v 2.2 85/08/06 22:26:37 matt Exp $";
  #endif
  /*
   *

--- 1,5 -----
  #ifndef lint
! static char rcsid[] = "$Header: main.c,v 2.3 85/08/15 17:11:50 matt Exp $";
  #endif
  /*
   *
***************
*** 18,23
   * Copyright (c) 1979
   *
   * $Log:	main.c,v $
   * Revision 2.2  85/08/06  22:26:37  matt
   * Victims lose 20% of their points to their killers.
   * 

--- 18,26 -----
   * Copyright (c) 1979
   *
   * $Log:	main.c,v $
+  * Revision 2.3  85/08/15  17:11:50  matt
+  * Adapt to 4.3 (and BRL ?)
+  * 
   * Revision 2.2  85/08/06  22:26:37  matt
   * Victims lose 20% of their points to their killers.
   * 
***************
*** 48,54
  
  #include <stdio.h>
  #include <sgtty.h>
! #include <sys/types.h>
  #include <sys/ioctl.h>
  #include <errno.h>
  #include <sys/socket.h>

--- 51,57 -----
  
  #include <stdio.h>
  #include <sgtty.h>
! #include <sys/param.h>		/* includes <sys/types.h> */
  #include <sys/ioctl.h>
  #include <errno.h>
  #include <sys/socket.h>
***************
*** 173,178
  	int	save_mask;
  
  	dtabsiz = getdtablesize();
  
  #ifdef INET
  	if (argc > 2) {

--- 176,183 -----
  	int	save_mask;
  
  	dtabsiz = getdtablesize();
+ 	if (dtabsiz > NBBY * sizeof (int))
+ 		dtabsiz = NBBY * sizeof (int);
  
  #ifdef INET
  	if (argc > 2) {
RCS file: RCS/search.c,v
retrieving revision 2.4
diff -c -r2.4 search.c
*** /tmp/,RCSt1007862	Thu Aug 15 13:24:49 1985
--- search.c	Thu Aug 15 13:24:51 1985
***************
*** 1,5
  #ifndef lint
! static char rcsid[] = "$Header: search.c,v 2.4 85/08/06 19:20:08 matt Exp $";
  #endif
  /*
   *

--- 1,5 -----
  #ifndef lint
! static char rcsid[] = "$Header: search.c,v 2.5 85/08/15 13:22:30 matt Exp $";
  #endif
  /*
   *
***************
*** 21,26
   * Copyright (c) 1983
   *
   * $Log:	search.c,v $
   * Revision 2.4  85/08/06  19:20:08  matt
   * Must byte-swap [htons()] a non-standard port number.
   * 

--- 21,30 -----
   * Copyright (c) 1983
   *
   * $Log:	search.c,v $
+  * Revision 2.5  85/08/15  13:22:30  matt
+  * Big blooper:  getdtablesize() was called inside of #ifdef INET !
+  * Also, restrict dtabsiz to an int's worth of bits.
+  * 
   * Revision 2.4  85/08/06  19:20:08  matt
   * Must byte-swap [htons()] a non-standard port number.
   * 
***************
*** 54,60
   */
  
  #include <stdio.h>
! #include <sys/types.h>
  #include <sys/stat.h>
  #include <sys/file.h>
  #include <sgtty.h>

--- 58,64 -----
   */
  
  #include <stdio.h>
! #include <sys/param.h>		/* includes <sys/types.h> and <signal.h> */
  #include <sys/stat.h>
  #include <sys/file.h>
  #include <sgtty.h>
***************
*** 60,66
  #include <sgtty.h>
  #include <ctype.h>
  #include <pwd.h>
- #include <signal.h>
  #include <sys/time.h>
  #include <errno.h>
  #include <sys/socket.h>

--- 64,69 -----
  #include <sgtty.h>
  #include <ctype.h>
  #include <pwd.h>
  #include <sys/time.h>
  #include <errno.h>
  #include <sys/socket.h>
***************
*** 119,124
  		printf("search: must be played from a terminal");
  		exit(1);
  	}
  #ifdef INET
  	if (argc > 3) {
  		printf("usage: search [hostname] [portnum]\n");

--- 122,130 -----
  		printf("search: must be played from a terminal");
  		exit(1);
  	}
+ 	dtabsiz = getdtablesize();
+ 	if (dtabsiz > NBBY * sizeof (int))
+ 		dtabsiz = NBBY * sizeof (int);
  #ifdef INET
  	if (argc > 3) {
  		printf("usage: search [hostname] [portnum]\n");
***************
*** 132,138
  		port_num = atoi(argv[2]);
  	else
  		port_num = DEFAULT_IN_PORT;
- 	dtabsiz = getdtablesize();
  	if (to_in) {
  		(void) gethostname(hostname, sizeof(hostname));
  		/*

--- 138,143 -----
  		port_num = atoi(argv[2]);
  	else
  		port_num = DEFAULT_IN_PORT;
  	if (to_in) {
  		(void) gethostname(hostname, sizeof(hostname));
  		/*
RCS file: RCS/searchwho.c,v
retrieving revision 2.1
diff -c -r2.1 searchwho.c
*** /tmp/,RCSt1008000	Thu Aug 15 13:38:57 1985
--- searchwho.c	Thu Aug 15 13:38:58 1985
***************
*** 1,5
  #ifndef lint
! static char rcsid[] = "$Header: searchwho.c,v 2.1 85/04/10 17:31:55 matt Stab $";
  #endif
  /*
   *

--- 1,5 -----
  #ifndef lint
! static char rcsid[] = "$Header: searchwho.c,v 2.2 85/08/15 13:37:49 matt Exp $";
  #endif
  /*
   *
***************
*** 16,21
   * Copyright (c) 1983
   *
   * $Log:	searchwho.c,v $
   * Revision 2.1  85/04/10  17:31:55  matt
   * Major de-linting and minor restructuring.
   * 

--- 16,24 -----
   * Copyright (c) 1983
   *
   * $Log:	searchwho.c,v $
+  * Revision 2.2  85/08/15  13:37:49  matt
+  * Limit dtabsiz to an int's worth of bits.
+  * 
   * Revision 2.1  85/04/10  17:31:55  matt
   * Major de-linting and minor restructuring.
   * 
***************
*** 30,36
   */
  
  #include <stdio.h>
! #include <sys/types.h>
  #include <sys/stat.h>
  #include <sys/file.h>
  #include <sgtty.h>

--- 33,39 -----
   */
  
  #include <stdio.h>
! #include <sys/param.h>		/* includes <sys/types.h> and <signal.h> */
  #include <sys/stat.h>
  #include <sys/file.h>
  #include <sgtty.h>
***************
*** 36,42
  #include <sgtty.h>
  #include <ctype.h>
  #include <pwd.h>
- #include <signal.h>
  #include <sys/time.h>
  #include <errno.h>
  #include <sys/socket.h>

--- 39,44 -----
  #include <sgtty.h>
  #include <ctype.h>
  #include <pwd.h>
  #include <sys/time.h>
  #include <errno.h>
  #include <sys/socket.h>
***************
*** 84,89
  	struct sockaddr loc_addr;/* local socket address */
  
  	dtabsiz = getdtablesize();
  #ifdef INET
  	if (argc > 3) {
  		printf("usage: searchwho [hostname [port]]\n");

--- 86,93 -----
  	struct sockaddr loc_addr;/* local socket address */
  
  	dtabsiz = getdtablesize();
+ 	if (dtabsiz > NBBY * sizeof (int))
+ 		dtabsiz = NBBY * sizeof (int);
  #ifdef INET
  	if (argc > 3) {
  		printf("usage: searchwho [hostname [port]]\n");
RCS file: RCS/util.c,v
retrieving revision 2.1
diff -c -r2.1 util.c
*** /tmp/,RCSt1011418	Thu Aug 15 17:16:38 1985
--- util.c	Thu Aug 15 17:10:28 1985
***************
*** 1,5
  #ifndef lint
! static char rcsid[] = "$Header: util.c,v 2.1 85/04/10 17:32:11 matt Stab $";
  #endif
  /*
   *

--- 1,5 -----
  #ifndef lint
! static char rcsid[] = "$Header: util.c,v 2.3 85/08/15 17:10:06 matt Exp $";
  #endif
  /*
   *
***************
*** 18,23
   * Copyright (c) 1979
   *
   * $Log:	util.c,v $
   * Revision 2.1  85/04/10  17:32:11  matt
   * Major de-linting and minor restructuring.
   * 

--- 18,30 -----
   * Copyright (c) 1979
   *
   * $Log:	util.c,v $
+  * Revision 2.3  85/08/15  17:10:06  matt
+  * Try to handle missing files a little better.
+  * 
+  * Revision 2.2  85/08/06  22:29:53  matt
+  * Change handling of "r", "b", "g", "j", "q" commands to
+  * provide better feedback, using per-player message buffer.
+  * 
   * Revision 2.1  85/04/10  17:32:11  matt
   * Major de-linting and minor restructuring.
   * 
***************
*** 77,88
  			putplayer();
  	extern	t_player	player[NPLAYER];
  	extern	char	visual[NPLAYER][NPLAYER];
! 	extern	char	*bbpnt,	*rmp;
! 	extern	char	bbuffer[40],	rmessb[40];
! 	extern	t_player	*r_dst,
! 				*r_owner,
! 				*b_owner,
! 				*whoscab;
  	extern	int	dtabsiz,	nplayer;
  	register	t_player	*pl;
  	register	int	i,	j;

--- 84,90 -----
  			putplayer();
  	extern	t_player	player[NPLAYER];
  	extern	char	visual[NPLAYER][NPLAYER];
! 	extern	t_player	*whoscab;
  	extern	int	dtabsiz,	nplayer;
  	register	t_player	*pl;
  	register	int	i,	j;
***************
*** 121,130
  			if (pl->home[y] == (thing *)p)
  				pl->home[y] = NOTHING;
  	}
- 	if (b_owner == p) {
- 		b_owner = NOBODY;
- 		bbpnt = bbuffer;
- 	}
  	if (whoscab == p)
  		whoscab = NOBODY;
  	if (r_owner == p) {

--- 123,128 -----
  			if (pl->home[y] == (thing *)p)
  				pl->home[y] = NOTHING;
  	}
  	if (whoscab == p)
  		whoscab = NOBODY;
  	(void) putplayer(p);
***************
*** 127,137
  	}
  	if (whoscab == p)
  		whoscab = NOBODY;
- 	if (r_owner == p) {
- 		r_owner = NOBODY;
- 		rmp = rmessb;
- 		r_dst = NOBODY;
- 	}
  	(void) putplayer(p);
  	(void) fnode(p->plstp);
  	(void) pldisplay(p, p->status.killed ? "d" : "q");

--- 125,130 -----
  	}
  	if (whoscab == p)
  		whoscab = NOBODY;
  	(void) putplayer(p);
  	(void) fnode(p->plstp);
  	(void) pldisplay(p, p->status.killed ? "d" : "q");
***************
*** 200,206
  char *msg;
  {
  	extern	int	errfile;
- 	extern	long	lseek();
  
  	if (errfile < 0) {
  		signal(SIGQUIT, SIG_DFL);

--- 193,198 -----
  char *msg;
  {
  	extern	int	errfile;
  
  	if (errfile < 0) {
  		signal(SIGQUIT, SIG_DFL);
***************
*** 206,212
  		signal(SIGQUIT, SIG_DFL);
  		kill(getpid(), SIGQUIT);
  	}
- 	(void)lseek(errfile, 0L, 2);
  	write(errfile, msg, strlen(msg));
  }
  

--- 198,203 -----
  		signal(SIGQUIT, SIG_DFL);
  		kill(getpid(), SIGQUIT);
  	}
  	write(errfile, msg, strlen(msg));
  }