Path: uunet!news.tek.com!master!saab!billr From: billr@saab.CNA.TEK.COM (Bill Randle) Newsgroups: comp.sources.games Subject: v15i031: xtb - multi-player X11 tank game and server, Patch1 Message-ID: <4073@master.CNA.TEK.COM> Date: 16 Dec 92 18:49:59 GMT Sender: news@master.CNA.TEK.COM Lines: 698 Approved: billr@saab.CNA.TEK.COM Xref: uunet comp.sources.games:1530 Submitted-by: bmh@terminus.ericsson.se (Bernard Hatt) Posting-number: Volume 15, Issue 31 Archive-name: xtb/Patch1 Patch-To: xtb: Volume 15, Issue 29-30 Environment: X11 [This patch includes fixes previously suggested in comp.sources.games.bugs so they should be applied to unmodified sources. -br] #! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh 'patches01' <<'END_OF_FILE' Xdiff -c -w ./oldxtb/Makefile ./newxtb/Makefile X*** ./oldxtb/Makefile Mon Dec 14 12:13:16 1992 X--- ./newxtb/Makefile Wed Dec 16 11:08:33 1992 X*************** X*** 6,24 **** X CC = cc X # wherever your X11 include files are X XINCS = -I/usr/openwin/include X X SOURCES = xtb.c rtb.c xtbd.c dgram.c common.c X INCLUDES = defs.h comms.h X MISC = xtb.6 README TODO X X rtb : rtb.o dgram.o common.o X! $(CC) -o rtb rtb.o dgram.o common.o -lm X X xtb : xtb.o dgram.o common.o X! $(CC) -o xtb xtb.o dgram.o common.o -lX11 -lm X X xtbd : xtbd.o dgram.o common.o X! $(CC) -o xtbd xtbd.o dgram.o common.o -lm X X xtb.o : xtb.c $(INCLUDES) X cc -c xtb.c $(XINCS) X--- 6,29 ---- X CC = cc X # wherever your X11 include files are X XINCS = -I/usr/openwin/include X+ XLIBS = -L/usr/openwin/lib X X+ # HP-UX users may want to add -lBSD to the next line. X+ LDOPTS = -lm X+ #LDOPTS = -lm -lBSD X+ X SOURCES = xtb.c rtb.c xtbd.c dgram.c common.c X INCLUDES = defs.h comms.h X MISC = xtb.6 README TODO X X rtb : rtb.o dgram.o common.o X! $(CC) -o rtb rtb.o dgram.o common.o $(LDOPTS) X X xtb : xtb.o dgram.o common.o X! $(CC) -o xtb xtb.o dgram.o common.o $(XLIBS) -lX11 $(LDOPTS) X X xtbd : xtbd.o dgram.o common.o X! $(CC) -o xtbd xtbd.o dgram.o common.o $(LDOPTS) X X xtb.o : xtb.c $(INCLUDES) X cc -c xtb.c $(XINCS) Xdiff -c -w ./oldxtb/README ./newxtb/README X*** ./oldxtb/README Mon Dec 14 12:13:05 1992 X--- ./newxtb/README Wed Dec 16 16:31:29 1992 X*************** X*** 1,3 **** X--- 1,4 ---- X+ README FILE FOR XTANKBATTLE 15th Dec 1992 X X WHAT YOU NEED TO HAVE X ===================== X*************** X*** 9,15 **** X X A three button mouse (It's playable with a two button mouse). X X! A fastish (and unloaded) CPU and reasonable drawing speed. X X A fastish network. X X--- 10,17 ---- X X A three button mouse (It's playable with a two button mouse). X X! A fastish (and unloaded) CPU and reasonable drawing speed. (X terminals X! may have problems) X X A fastish network. X X*************** X*** 40,45 **** X--- 42,50 ---- X COMPILING X ========= X X+ You may need to edit the Makefile to point to where your X11 include files X+ and X11 librarys live. X+ X Type X make X X*************** X*** 57,67 **** X workstation% xtb -h hostname X (ignore messages about datagrams and fielddata) X X RUNNING TWO (OR MORE) PLAYERS ON THE SAME NODE X ============================================== X X! The second and further players, should pick different port numbers to X! the default (and each other). eg the second player might type X X workstation% xtb -h hostname -i 1624 X X--- 62,76 ---- X workstation% xtb -h hostname X (ignore messages about datagrams and fielddata) X X+ (It seems that on HP-UX if you want to refer to your own host, you must X+ use the hostname 'localhost') X+ X RUNNING TWO (OR MORE) PLAYERS ON THE SAME NODE X ============================================== X X! For second and further players *on the same workstation*, should pick X! different port numbers to the default (and each other). eg the second X! player might type X X workstation% xtb -h hostname -i 1624 X X*************** X*** 182,187 **** X--- 191,220 ---- X X The program comes with no warranty. I would like the conditions that X apply to GNU software to apply to this software. X+ X+ Bugs fixed in version 8 X+ ======================= X+ X+ Now works on hosts with hostnames of up to 63 chars. X+ xtbd now works on HP-UX, (used to fail with 'Alarm clock') X+ You are now notified immediatly when your damage is zeroed when you kill X+ another player (Fixed by Jonathan Bayer (jbayer@ispi.COM)) X+ Now works properly on NCD X terminuals (Fixed by Martin Boyer X+ (mboyer@ireq-robot.hydro.qc.ca)) X+ X+ X+ There is a work around (in this REAME file) for the problem with using X+ your own host for xtb and xtbd on HP-UX. X+ X+ I have now changed the README file to make it more obvious when you need X+ to specify port numbers to xtb/rtb/xtbd. (ie. you shouldn't need to in X+ most cases) X+ X+ Note that version 7 programs won't work with version 8 programs. X+ X+ If you mail me about problems/bug-reports/suggestions for improvement, X+ please say what type of machine you are using, which revision of the X+ operating system, and what verson of X-windows you are using. X X Good Luck! X Xdiff -c -w ./oldxtb/comms.h ./newxtb/comms.h X*** ./oldxtb/comms.h Mon Dec 14 12:13:18 1992 X--- ./newxtb/comms.h Wed Dec 16 11:08:17 1992 X*************** X*** 1,7 **** X /* comms and common data structures */ X X /* X! * $Header: /morpork/home/bmh/xtest2/RCS/comms.h,v 1.18 92/10/19 15:34:38 bmh Exp Locker: bmh $ X * X * Bernard Hatt X * Camtec Electronics (Ericsson), Leicester, England, LE1 4SA X--- 1,7 ---- X /* comms and common data structures */ X X /* X! * $Header: /morpork/home/bmh/xtest2/RCS/comms.h,v 1.19 92/12/16 11:08:14 bmh Exp Locker: bmh $ X * X * Bernard Hatt X * Camtec Electronics (Ericsson), Leicester, England, LE1 4SA X*************** X*** 34,39 **** X--- 34,45 ---- X char hostname[HOSTLEN]; /* sending hostname */ X } USER; X X+ typedef struct struct_ip X+ { X+ int len; X+ char addr[8]; /* no one should have an IP address longer than this! */ X+ } IP; X+ X typedef struct struct_position X { X int x; /* x position on battlefield */ X*************** X*** 47,54 **** X { X int port; /* callback port no. */ X int version; /* program version */ X! char hostname[HOSTLEN]; /* sending hostname */ X! char username[NAMELEN]; X } SIGNON; X X typedef struct accept_struct X--- 53,61 ---- X { X int port; /* callback port no. */ X int version; /* program version */ X! char hostname[FULLHOSTLEN]; /* sending hostname */ X! char username[FULLNAMELEN]; X! IP ip; X } SIGNON; X X typedef struct accept_struct Xdiff -c -w ./oldxtb/defs.h ./newxtb/defs.h X*** ./oldxtb/defs.h Mon Dec 14 12:13:21 1992 X--- ./newxtb/defs.h Wed Dec 16 11:08:20 1992 X*************** X*** 1,6 **** X /* common defines */ X /* X! * $Header: /morpork/home/bmh/xtest2/RCS/defs.h,v 1.20 92/10/19 15:34:40 bmh Exp Locker: bmh $ X * X * Bernard Hatt X * Camtec Electronics (Ericsson), Leicester, England, LE1 4SA X--- 1,6 ---- X /* common defines */ X /* X! * $Header: /morpork/home/bmh/xtest2/RCS/defs.h,v 1.21 92/12/16 11:08:16 bmh Exp Locker: bmh $ X * X * Bernard Hatt X * Camtec Electronics (Ericsson), Leicester, England, LE1 4SA X*************** X*** 10,16 **** X X /* increment this version no. if the client/server protocol is */ X /* changed in any way */ X! #define VERSION 7 X X #define DEFSPORT 1622 /* default server UDP port no. */ X #define DEFCPORT 1623 /* default client UDP port no. */ X--- 10,16 ---- X X /* increment this version no. if the client/server protocol is */ X /* changed in any way */ X! #define VERSION 8 X X #define DEFSPORT 1622 /* default server UDP port no. */ X #define DEFCPORT 1623 /* default client UDP port no. */ X*************** X*** 31,38 **** X #define MAINX 768 /* X and Y of main battlefield */ X #define MAINY 768 X X! #define HOSTLEN 16 /* max chars in hostname */ X! #define NAMELEN 16 /* max chars in username */ X #define BUFLEN 128 /* general purpose char buffer */ X X #define MAINSIZE 2048 /* size of field in pixels */ X--- 31,41 ---- X #define MAINX 768 /* X and Y of main battlefield */ X #define MAINY 768 X X! #define HOSTLEN 10 /* max chars in hostname */ X! #define FULLHOSTLEN 64 /* length of full hostname */ X! X! #define NAMELEN 10 /* max chars in username */ X! #define FULLNAMELEN 64 X #define BUFLEN 128 /* general purpose char buffer */ X X #define MAINSIZE 2048 /* size of field in pixels */ Xdiff -c -w ./oldxtb/dgram.c ./newxtb/dgram.c X*** ./oldxtb/dgram.c Mon Dec 14 12:13:22 1992 X--- ./newxtb/dgram.c Wed Dec 16 11:07:48 1992 X*************** X*** 1,7 **** X /* X * Comms. X * X! * $Header: /morpork/home/bmh/xtest2/RCS/dgram.c,v 1.10 92/10/19 15:34:27 bmh Exp Locker: bmh $ X * X * Bernard Hatt X * Camtec Electronics (Ericsson), Leicester, England, LE1 4SA X--- 1,7 ---- X /* X * Comms. X * X! * $Header: /morpork/home/bmh/xtest2/RCS/dgram.c,v 1.11 92/12/16 11:07:35 bmh Exp Locker: bmh $ X * X * Bernard Hatt X * Camtec Electronics (Ericsson), Leicester, England, LE1 4SA X*************** X*** 56,64 **** X } X X int X! opensend(host,port) X char *host; X int port; X { X int ret,sd; X struct sockaddr_in name; X--- 56,65 ---- X } X X int X! opensend(host,port,ip) X char *host; X int port; X+ IP *ip; X { X int ret,sd; X struct sockaddr_in name; X*************** X*** 73,81 **** X X hent=gethostbyname(host); X if(hent==NULL) X return(-1); X! X bcopy(hent->h_addr,&name.sin_addr,hent->h_length); X name.sin_family=AF_INET; X name.sin_port=htons(port); X X--- 74,95 ---- X X hent=gethostbyname(host); X if(hent==NULL) X+ { X+ if(ip==NULL) X+ { X return(-1); X! } X! else X! { X! fprintf(stderr,"Can't find host %s's IP address trying %d.%d.%d.%d\n",host,ip->addr[0]&0xff,ip->addr[1]&0xff,ip->addr[2]&0xff,ip->addr[3]&0xff); X! bcopy(ip->addr,&name.sin_addr,INSWAP(ip->len)); X! } X! } X! else X! { X bcopy(hent->h_addr,&name.sin_addr,hent->h_length); X+ } X+ X name.sin_family=AF_INET; X name.sin_port=htons(port); X X*************** X*** 95,98 **** X--- 109,128 ---- X DATA *data; X { X return(write(sd,data,sizeof(DATA))); X+ } X+ X+ int X+ getipaddr(host,ip) X+ char *host; X+ IP *ip; X+ { X+ struct hostent *hent; X+ X+ hent=gethostbyname(host); X+ if(hent==NULL) X+ return(-1); X+ X+ bcopy(hent->h_addr,ip->addr,hent->h_length); X+ ip->len=OUTSWAP(hent->h_length); X+ return(0); X } Xdiff -c -w ./oldxtb/rtb.c ./newxtb/rtb.c X*** ./oldxtb/rtb.c Mon Dec 14 12:13:08 1992 X--- ./newxtb/rtb.c Wed Dec 16 11:08:07 1992 X*************** X*** 1,7 **** X /* X * Robot tank X * X! * $Header: /morpork/home/bmh/xtest2/RCS/rtb.c,v 1.7 92/10/19 15:34:30 bmh Exp Locker: bmh $ X * X * Bernard Hatt X * Camtec Electronics (Ericsson), Leicester, England, LE1 4SA X--- 1,7 ---- X /* X * Robot tank X * X! * $Header: /morpork/home/bmh/xtest2/RCS/rtb.c,v 1.8 92/12/16 11:07:47 bmh Exp Locker: bmh $ X * X * Bernard Hatt X * Camtec Electronics (Ericsson), Leicester, England, LE1 4SA X*************** X*** 14,20 **** X #include X #include X #include X- #include X #include X #include X #include X--- 14,19 ---- X*************** X*** 502,508 **** X exit(1); X } X X! ssd=opensend(server,outport); X if(ssd==(-1)) X { X fprintf(stderr,"%s: Connecting to %s/%d failed\n",argv[0],server,outport); X--- 501,507 ---- X exit(1); X } X X! ssd=opensend(server,outport,NULL); X if(ssd==(-1)) X { X fprintf(stderr,"%s: Connecting to %s/%d failed\n",argv[0],server,outport); X*************** X*** 515,522 **** X sdata.type=OUTSWAP(T_SIGNON); X sdata.extra.signon.version=OUTSWAP(VERSION); X sdata.extra.signon.port=OUTSWAP(inport); /* could be different to server port */ X! gethostname(sdata.extra.signon.hostname,HOSTLEN); X sprintf(sdata.extra.signon.username,"ROBOT%04d",inport); X X signal(SIGALRM,timeout); X alarm(3); X--- 514,529 ---- X sdata.type=OUTSWAP(T_SIGNON); X sdata.extra.signon.version=OUTSWAP(VERSION); X sdata.extra.signon.port=OUTSWAP(inport); /* could be different to server port */ X! X! gethostname(sdata.extra.signon.hostname,FULLHOSTLEN-1); X! sdata.extra.signon.hostname[FULLHOSTLEN-1]='\0'; X sprintf(sdata.extra.signon.username,"ROBOT%04d",inport); X+ X+ if(getipaddr(sdata.extra.signon.hostname,&(sdata.extra.signon.ip))) X+ { X+ fprintf(stderr,"%s: Couldn't get my own IP address\n",progname); X+ exit(1); X+ } X X signal(SIGALRM,timeout); X alarm(3); Xdiff -c -w ./oldxtb/xtb.6 ./newxtb/xtb.6 X*** ./oldxtb/xtb.6 Mon Dec 14 12:13:23 1992 X--- ./newxtb/xtb.6 Wed Dec 16 11:08:24 1992 X*************** X*** 1,4 **** X! .TH XTB 6 "13 January 1991" X .SH NAME X xtb, xtbd \- X11 Tank battle program and server X .SH SYNOPSIS X--- 1,4 ---- X! .TH XTB 6 "13 January 1992" X .SH NAME X xtb, xtbd \- X11 Tank battle program and server X .SH SYNOPSIS Xdiff -c -w ./oldxtb/xtb.c ./newxtb/xtb.c X*** ./oldxtb/xtb.c Mon Dec 14 12:13:09 1992 X--- ./newxtb/xtb.c Wed Dec 16 16:16:50 1992 X*************** X*** 1,7 **** X /* X * X Client X * X! * $Header: /morpork/home/bmh/xtest2/RCS/xtb.c,v 1.41 92/10/19 15:34:32 bmh Exp Locker: bmh $ X * X * Bernard Hatt X * Camtec Electronics (Ericsson), Leicester, England, LE1 4SA X--- 1,7 ---- X /* X * X Client X * X! * $Header: /morpork/home/bmh/xtest2/RCS/xtb.c,v 1.42 92/12/16 11:08:07 bmh Exp Locker: bmh $ X * X * Bernard Hatt X * Camtec Electronics (Ericsson), Leicester, England, LE1 4SA X*************** X*** 14,20 **** X #include X #include X #include X- #include X #include X #include X #include X--- 14,19 ---- X*************** X*** 1115,1124 **** X XSetForeground(Disp,GcB,bg); X XSetBackground(Disp,GcB,fg); X X! gcv.function = GXor; X GcTF=XCreateGC(Disp,Win,(GCFunction | GCPlaneMask | GCFillStyle),&gcv); X X! gcv.function = GXandInverted; X GcTB=XCreateGC(Disp,Win,(GCFunction | GCPlaneMask | GCFillStyle),&gcv); X X XSetForeground(Disp,GcTF,fg); X--- 1114,1123 ---- X XSetForeground(Disp,GcB,bg); X XSetBackground(Disp,GcB,fg); X X! gcv.function = fg > bg ? GXor : GXand; X GcTF=XCreateGC(Disp,Win,(GCFunction | GCPlaneMask | GCFillStyle),&gcv); X X! gcv.function = fg > bg ? GXandInverted : GXorInverted; X GcTB=XCreateGC(Disp,Win,(GCFunction | GCPlaneMask | GCFillStyle),&gcv); X X XSetForeground(Disp,GcTF,fg); X*************** X*** 1258,1264 **** X exit(1); X } X X! ssd=opensend(server,outport); X if(ssd==(-1)) X { X fprintf(stderr,"%s: Connecting to %s/%d failed\n",argv[0],server,outport); X--- 1257,1263 ---- X exit(1); X } X X! ssd=opensend(server,outport,NULL); X if(ssd==(-1)) X { X fprintf(stderr,"%s: Connecting to %s/%d failed\n",argv[0],server,outport); X*************** X*** 1274,1283 **** X sdata.type=OUTSWAP(T_SIGNON); X sdata.extra.signon.version=OUTSWAP(VERSION); X sdata.extra.signon.port=OUTSWAP(inport); /* could be different to server port */ X- gethostname(sdata.extra.signon.hostname,HOSTLEN); X- strncpy(sdata.extra.signon.username,((struct passwd*)getpwuid(getuid()))->pw_name,NAMELEN-1); X- sdata.extra.signon.username[NAMELEN]='\0'; X X signal(SIGALRM,timeout); X alarm(3); X senddata(ssd,&sdata); X--- 1273,1292 ---- X sdata.type=OUTSWAP(T_SIGNON); X sdata.extra.signon.version=OUTSWAP(VERSION); X sdata.extra.signon.port=OUTSWAP(inport); /* could be different to server port */ X X+ gethostname(sdata.extra.signon.hostname,FULLHOSTLEN-1); X+ sdata.extra.signon.hostname[FULLHOSTLEN-1]='\0'; X+ X+ strncpy(sdata.extra.signon.username,((struct passwd*)getpwuid(getuid()))->pw_name,FULLNAMELEN-1); X+ sdata.extra.signon.username[FULLNAMELEN-1]='\0'; X+ X+ if(getipaddr(sdata.extra.signon.hostname,&(sdata.extra.signon.ip))) X+ { X+ fprintf(stderr,"%s: Couldn't get my own IP address\n",progname); X+ exit(1); X+ } X+ X+ X signal(SIGALRM,timeout); X alarm(3); X senddata(ssd,&sdata); X*************** X*** 1284,1290 **** X X if(readdata(rsd,&rdata)!=sizeof(DATA)) X { X! fprintf(stderr,"%s: Recieved bad data\n"); X exit(1); X } X alarm(0); X--- 1293,1299 ---- X X if(readdata(rsd,&rdata)!=sizeof(DATA)) X { X! fprintf(stderr,"%s: Recieved bad data\n",progname); X exit(1); X } X alarm(0); Xdiff -c -w ./oldxtb/xtbd.c ./newxtb/xtbd.c X*** ./oldxtb/xtbd.c Mon Dec 14 12:13:24 1992 X--- ./newxtb/xtbd.c Wed Dec 16 11:08:14 1992 X*************** X*** 1,7 **** X /* X * Server X * X! * $Header: /morpork/home/bmh/xtest2/RCS/xtbd.c,v 1.28 92/10/19 15:34:36 bmh Exp Locker: bmh $ X * X * Bernard Hatt X * Camtec Electronics (Ericsson), Leicester, England, LE1 4SA X--- 1,7 ---- X /* X * Server X * X! * $Header: /morpork/home/bmh/xtest2/RCS/xtbd.c,v 1.29 92/12/16 11:08:11 bmh Exp Locker: bmh $ X * X * Bernard Hatt X * Camtec Electronics (Ericsson), Leicester, England, LE1 4SA X*************** X*** 179,185 **** X int srot,dist; X int sx,sy; X int dx,dy; X! int hflag=0,kflag=0,killed; X X newtime=gettime(); X if((newtime>(250+player[id].firetime))&&(player[id].damage(250+player[id].firetime))&&(player[id].damage