v02i040: multiplayer startrek game, Part06/07

Mike Wexler mikew at wyse.wyse.com
Fri Dec 9 12:01:04 AEST 1988


Submitted-by: ddickey at gonzo.eta.com (Dan A. Dickey)
Posting-number: Volume 2, Issue 40
Archive-name: xtrek/part06

#! /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 <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 6 (of 7)."
# Contents:  Makefile colors.c death.c enter.c interface.c main.c
#   phaser.c planets.h pstats.c scorelist.c stats.c util.c war.c
#   xtrek.c
# Wrapped by mikew at wyse on Thu Dec  8 17:51:43 1988
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'Makefile' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Makefile'\"
else
echo shar: Extracting \"'Makefile'\" \(2548 characters\)
sed "s/^X//" >'Makefile' <<'END_OF_FILE'
X# static char sccsid[] = "@(#)Makefile	1.2";
XCC = cc
XDESTDIR = /global/bin/X11
XXTREKDIR = /global/games/lib/xtrek
XXTREKOWNER = mikew
X
X.SUFFIXES: .ln
X
XLINTFLAGS = -iabchu
XLINTLIBS = -lX11
X.c.ln:
X	lint $(LINTFLAGS) $< > $*.p1 2>&1
X
XR_OBJS =	bitmaps.o colors.o coup.o data.o death.o detonate.o dmessage.o \
X		enter.o getship.o inform.o input.o interface.o main.o \
X		newwin.o orbit.o phaser.o planetlist.o playerlist.o \
X		pstats.o redraw.o smessage.o subdaemon.o stats.o torp.o \
X		util.o warning.o random.o rmove.o scorelist.o \
X		sintab.o trigtab.o itoa.o minisubs.o war.o DBG.o
X
XLINT_FILES =	colors.ln coup.ln data.ln death.ln detonate.ln dmessage.ln \
X		enter.ln getship.ln inform.ln input.ln interface.ln main.ln \
X		newwin.ln orbit.ln phaser.ln planetlist.ln playerlist.ln \
X		pstats.ln redraw.ln smessage.ln subdaemon.ln stats.ln torp.ln \
X		util.ln warning.ln random.ln rmove.ln \
X		sintab.ln scorelist.ln trigtab.ln itoa.ln bitmaps.ln \
X		minisubs.ln war.ln
X
XLIBS = -L/global/lib -lX11 -lm
X
X# Use -DSUN40 if Sun Release 4.0 or greater
X#CFLAGS = -DSUN40
XCFLAGS = -I/global/include
X
Xall: in.xtrekd xtrek scores xtrek.snf
X
Xin.xtrekd: $(R_OBJS)
X	${CC} $(CFLAGS) -o $@ $(R_OBJS) $(LIBS)
X
Xxtrek: xtrek.c
X	${CC} $(CFLAGS) -o $@ xtrek.c
X
Xscores: scores.c
X	${CC} $(CFLAGS) -o $@ scores.c
X
Xxtrek.snf: xtrek.bdf
X	bdftosnf -t xtrek.bdf > xtrek.snf
X	
Xbitmaps.h:	bitmaps.c
X	echo "/* DO NOT EDIT THIS FILE. It is machine generated. */" > bitmaps.h
X	sed -e 's/;$$/;`/' < bitmaps.c | tr '\012;' '@\012' | \
X		sed -e 's/ =.*$$/;@/g' | tr '@`' '\012;' >> bitmaps.h
X
Xinstall: xtrek in.xtrekd
X	-mv $(DESTDIR)/xtrek $(DESTDIR)/xtrek.old
X	cp xtrek $(DESTDIR)
X	chmod 711 $(DESTDIR)/xtrek
X	chown $(XTREKOWNER) $(DESTDIR)/xtrek
X	-mv $(XTREKDIR)/in.xtrekd $(XTREKDIR)/in.xtrekd.old
X	cp in.xtrekd $(XTREKDIR)
X	chmod 711 $(XTREKDIR)/in.xtrekd
X	chown $(XTREKOWNER) $(XTREKDIR)/in.xtrekd
X	touch $(XTREKDIR)/.planets $(XTREKDIR)/.motd
X	touch $(XTREKDIR)/scores.dir $(XTREKDIR)/scores.pag
X	chown $(XTREKOWNER) $(XTREKDIR)/.planets $(XTREKDIR)/.motd
X	chown $(XTREKOWNER) $(XTREKDIR)/scores.dir $(XTREKDIR)/scores.pag
X	chmod 600 $(XTREKDIR)/.planets $(XTREKDIR)/.motd
X	chmod 644 $(XTREKDIR)/scores.dir $(XTREKDIR)/scores.pag
X	cp doc $(XTREKDIR)/xtrek.doc
X	chmod 444 $(XTREKDIR)/xtrek.doc
X	chown $(XTREKOWNER) $(XTREKDIR)/xtrek.doc
X
Xlint: $(LINT_FILES)
X	lint $(LINTLIBS) *.ln > foo.lint 2>&1
X
Xclean:
X	-rm -f *.o core a.out in.xtrekd xtrek scores xtrek.snf bitmaps.h
X
Xshar:
X	makekit -oMANIFEST READ* TODO xtrek.6 Makefile doc *.h *.c xtrek.bdf clock.bitmap
X
Xnewwin.o: bitmaps.h
END_OF_FILE
if test 2548 -ne `wc -c <'Makefile'`; then
    echo shar: \"'Makefile'\" unpacked with wrong size!
fi
# end of 'Makefile'
fi
if test -f 'colors.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'colors.c'\"
else
echo shar: Extracting \"'colors.c'\" \(4227 characters\)
sed "s/^X//" >'colors.c' <<'END_OF_FILE'
Xstatic char sccsid[] = "@(#)colors.c	1.1";
X
X/*
X
X	Copyright (c) 1986 	Chris Guthrie
X
XPermission to use, copy, modify, and distribute this
Xsoftware and its documentation for any purpose and without
Xfee is hereby granted, provided that the above copyright
Xnotice appear in all copies and that both that copyright
Xnotice and this permission notice appear in supporting
Xdocumentation.  No representations are made about the
Xsuitability of this software for any purpose.  It is
Xprovided "as is" without express or implied warranty.
X
X*/
X
X#include <stdio.h>
X#include <X11/Xlib.h>
X#include <string.h>
X#include "defs.h"
X#include "data.h"
X
Xtypedef struct assoc {
X	char		*str;
X	int		bWDef;
X	char		*colorDef;
X} ASSOC;
X
X#define BLACKPIXEL	0
X#define WHITEPIXEL	1
X
XASSOC	assoc[] = {
X	{ "border",	WHITEPIXEL,	"blue"		},
X	{ "background",	BLACKPIXEL,	"black"		},
X	{ "text",	WHITEPIXEL,	"white"		},
X	{ "nobody",	WHITEPIXEL,	"blue"		},
X	{ "fed",	WHITEPIXEL,	"yellow",	},
X	{ "rom",	WHITEPIXEL,	"red",		},
X	{ "kli",	WHITEPIXEL,	"green",	},
X	{ "ori",	WHITEPIXEL,	"#0ff",		},
X	{ "warning",	WHITEPIXEL,	"red"		},
X	{ "unknown",	WHITEPIXEL,	"light grey"	},
X	{ "ralert",	WHITEPIXEL,	"red"		},
X	{ "yalert",	WHITEPIXEL,	"yellow"	},
X	{ "galert",	WHITEPIXEL,	"green"		},
X	{ "me",		WHITEPIXEL,	"white"		}
X};
X
XgetColorDefs(p, prog)
Xregister struct player	*p;
Xchar			*prog;
X{
X	int	i, invert = 0;
X	char	*color;
X	Colormap	default_colormap;
X	unsigned long	*pp;
X
X	XColor		def;
X	unsigned long	white_pix, black_pix;
X
X	if (p->mono) {	/* b & w */
X		white_pix = XWhitePixel(p->display, p->screen);
X		black_pix = XBlackPixel(p->display, p->screen);
X		invert = booleanDefault(p, prog, "reverseVideo");
X		for (i = 0; i < sizeof (assoc) / sizeof (*assoc); i++) {
X			switch (i) {
X				case 0:	pp = &p->borderColor;	break;
X				case 1:	pp = &p->backColor;	break;
X				case 2:	pp = &p->textColor;	break;
X				case 3:	pp = &p->shipCol[0];	break;
X				case 4:	pp = &p->shipCol[1];	break;
X				case 5:	pp = &p->shipCol[2];	break;
X				case 6:	pp = &p->shipCol[3];	break;
X				case 7:	pp = &p->shipCol[4];	break;
X				case 8:	pp = &p->warningColor;	break;
X				case 9:	pp = &p->unColor;	break;
X				case 10:pp = &p->rColor;	break;
X				case 11:pp = &p->yColor;	break;
X				case 12:pp = &p->gColor;	break;
X				case 13:pp = &p->myColor;	break;
X			}
X			if (!invert)
X				*pp = (assoc[i].bWDef == BLACKPIXEL)
X					? black_pix : white_pix;
X			else
X				*pp = (assoc[i].bWDef == BLACKPIXEL)
X					? white_pix : black_pix;
X		}
X	} else {
X		default_colormap = XDefaultColormap(p->display, p->screen);
X		for (i = 0; i < sizeof (assoc) / sizeof (*assoc); i++) {
X			switch (i) {
X				case 0:	pp = &p->borderColor;	break;
X				case 1:	pp = &p->backColor;	break;
X				case 2:	pp = &p->textColor;	break;
X				case 3:	pp = &p->shipCol[0];	break;
X				case 4:	pp = &p->shipCol[1];	break;
X				case 5:	pp = &p->shipCol[2];	break;
X				case 6:	pp = &p->shipCol[3];	break;
X				case 7:	pp = &p->shipCol[4];	break;
X				case 8:	pp = &p->warningColor;	break;
X				case 9:	pp = &p->unColor;	break;
X				case 10:pp = &p->rColor;	break;
X				case 11:pp = &p->yColor;	break;
X				case 12:pp = &p->gColor;	break;
X				case 13:pp = &p->myColor;	break;
X			}
X			if ((color = XGetDefault(p->display, PROGRAM_NAME, assoc[i].str))
X			    == NULL)
X				color = assoc[i].colorDef;
X			def.pixel = 0;
X			invert = XParseColor(p->display, default_colormap, color, &def);
X			invert = XAllocColor(p->display, default_colormap, &def);
X			*pp = def.pixel;
X		}
X	}
X}
X
XbooleanDefault(p, prog, def)
Xregister struct player	*p;
Xchar			*prog, *def;
X{
X	char	*str;
X
X	if ((str = XGetDefault(p->display, prog, def))
X	    != NULL && strcmp(str, "on") == 0)
X		return (1);
X	else
X		return (0);
X}
X
X#define iswhite(c)	((c) == ' ' || c == '\t' || (c) == ',')
X
XarrayDefault(p, prog, def, sizeP, sp)
Xregister struct player	*p;
Xchar			*prog, *def;
Xint			*sizeP;
Xchar			*sp;
X{
X	int	max;
X	char	*str;
X	int	rc;
X
X	str = XGetDefault(p->display, PROGRAM_NAME, def);
X	if (str == NULL)
X		return (-1);
X	max = *sizeP;
X	*sizeP = 0;
X
X	for (;;) {
X		while (iswhite(*str))
X			str++;
X		if (*str == '\0')
X			break;
X		if (++(*sizeP) > max)
X			return (-1);
X		if (sscanf(str, "0x%x", &rc) != 1)
X			return (-1);
X		sp[*sizeP] = rc;
X		while (!iswhite(*str) && *str != '\0')
X			str++;
X	}
X	return (0);
X}
END_OF_FILE
if test 4227 -ne `wc -c <'colors.c'`; then
    echo shar: \"'colors.c'\" unpacked with wrong size!
fi
# end of 'colors.c'
fi
if test -f 'death.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'death.c'\"
else
echo shar: Extracting \"'death.c'\" \(3364 characters\)
sed "s/^X//" >'death.c' <<'END_OF_FILE'
Xstatic char sccsid[] = "@(#)death.c	1.1";
X/*
X
X#ifdef HPUX
X#include <time.h>
X#else HPUX
X#include <sys/time.h>
X#endif HPUX
X	Copyright (c) 1986 	Chris Guthrie
X
XPermission to use, copy, modify, and distribute this
Xsoftware and its documentation for any purpose and without
Xfee is hereby granted, provided that the above copyright
Xnotice appear in all copies and that both that copyright
Xnotice and this permission notice appear in supporting
Xdocumentation.  No representations are made about the
Xsuitability of this software for any purpose.  It is
Xprovided "as is" without express or implied warranty.
X
X*/
X
X#include <X11/Xlib.h>
X#include <stdio.h>
X#include <signal.h>
X#include <setjmp.h>
X#include <sys/types.h>
X#ifdef hpux
X#include <time.h>
X#else hpux
X#include <sys/time.h>
X#endif hpux
X#include "defs.h"
X#include "data.h"
X
Xdeath(p)
Xregister struct player	*p;
X{
X    char buf[80];
X
X    p->p_status = PDEAD;
X    p->p_explode = DEATHTIME;
X
X    if (!(p->p_flags & PFROBOT)) {
X	    XClearWindow(p->display, p->w);
X	    if (!p->mono) {
X		    XSetWindowBorder(p->display, p->baseWin, p->gColor);
X		    XSetWindowBorder(p->display, p->iconWin, p->gColor);
X	    } else {
X		    XSetWindowBorderPixmap(p->display, p->baseWin, p->gTile);
X		    XSetWindowBorderPixmap(p->display, p->iconWin, p->gTile);
X	    }
X    }
X
X    switch (p->p_whydead) {
X	case KQUIT:
X	    sprintf(buf, "You have self-destructed");
X	    warning(p, buf);
X	    break;
X	case KTORP:
X	    sprintf(buf, "You were killed by a torp from %s (%c%x) who was %d%% damaged",
X		players[p->p_whodead].p_name,
X		teamlet[players[p->p_whodead].p_team],
X		p->p_whodead,
X		players[p->p_whodead].p_damage);
X	    warning(p, buf);
X	    break;
X	case KPHASER:
X	    sprintf(buf, "You were killed by a phaser shot from %s (%c%x) who was %d%% damaged",
X		players[p->p_whodead].p_name,
X		teamlet[players[p->p_whodead].p_team],
X		p->p_whodead,
X		players[p->p_whodead].p_damage);
X	    warning(p, buf);
X	    break;
X	case KPLANET:
X	    sprintf(buf, "You were killed by planetary fire from %s (%c)",
X		planets[p->p_whodead].pl_name,
X		teamlet[planets[p->p_whodead].pl_owner]);
X	    warning(p, buf);
X	    break;
X	case KSHIP:
X	    sprintf(buf, "You were killed by an exploding ship formerly owned by %s (%c%x) who was %d%% damaged",
X		players[p->p_whodead].p_name,
X		teamlet[players[p->p_whodead].p_team],
X		p->p_whodead,
X		players[p->p_whodead].p_damage);
X	    warning(p, buf);
X	    break;
X#ifdef notdef
X	case KDAEMON:
X	    sprintf(buf, "You were killed by a dying daemon");
X	    warning(p, buf);
X	    p->mustexit = 1;
X	    break;
X#endif
X	case KWINNER:
X	    sprintf(buf, "Galaxy has been conquered by %s (%c%x)",
X		players[p->p_whodead].p_name,
X		teamlet[players[p->p_whodead].p_team],
X		players[p->p_whodead].p_no);
X	    warning(p, buf);
X	    break;
X	default:
X	    sprintf(buf, "You were killed by something unknown to this game?");
X	    warning(p, buf);
X	    p->mustexit = 1;
X	    break;
X	}
X	savestats(p);
X	if (!(p->p_flags & PFROBOT)) {
X		if (ismapped(p, p->playerw))
X			XUnmapWindow(p->display, p->playerw);
X		if (ismapped(p, p->planetw))
X			XUnmapWindow(p->display, p->planetw);
X		if (p->infomapped)
X			destroyInfo(p);
X		if (ismapped(p, p->war))
X			XUnmapWindow(p->display, p->war);
X		if (p->p_flags & PFSHOWSTATS)
X			closeStats(p, p->statwin);
X		p->p_flags &= ~PFSHOWSTATS;
X		p->p_status = POUTFIT;
X	} else {
X		p->p_status = PFREE;
X	}
X}
END_OF_FILE
if test 3364 -ne `wc -c <'death.c'`; then
    echo shar: \"'death.c'\" unpacked with wrong size!
fi
# end of 'death.c'
fi
if test -f 'enter.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'enter.c'\"
else
echo shar: Extracting \"'enter.c'\" \(3043 characters\)
sed "s/^X//" >'enter.c' <<'END_OF_FILE'
Xstatic char sccsid[] = "@(#)enter.c	1.1";
X
X/*
X
X	Copyright (c) 1986 	Chris Guthrie
X
XPermission to use, copy, modify, and distribute this
Xsoftware and its documentation for any purpose and without
Xfee is hereby granted, provided that the above copyright
Xnotice appear in all copies and that both that copyright
Xnotice and this permission notice appear in supporting
Xdocumentation.  No representations are made about the
Xsuitability of this software for any purpose.  It is
Xprovided "as is" without express or implied warranty.
X
X*/
X
X#include <X11/Xlib.h>
X#include <stdio.h>
X#include <sys/types.h>
X#include <errno.h>
X#include <pwd.h>
X#include <string.h>
X#include <ctype.h>
X#include "defs.h"
X#include "data.h"
X
X/* Enter the game */
X
Xlong random();
X
Xenter(tno, disp, pno)
Xint tno;
Xchar	*disp;
Xint pno;
X{
X    register struct player	*p;
X    char		*pseudo, buf[80];
X
X    pseudo = (char *) NULL;
X    p = &players[pno];
X    if (strcmp(disp, "Nowhere"))
X	pseudo = XGetDefault(p->display, PROGRAM_NAME, "name");
X    if (pseudo == NULL)
X	(void) strncpy(p->p_name, p->p_login, sizeof (p->p_name));
X    else
X	(void) strncpy(p->p_name, pseudo, sizeof (p->p_name));
X    p->p_name[12] = '\0';
X    p->p_login[12] = '\0';
X
X    p->p_no = pno;
X    p->p_updates = 0;
X    p->p_flags = PFSHIELD | (p->p_flags & PFCOPILOT);
X    if (strcmp(disp, "Nowhere") && booleanDefault(p, PROGRAM_NAME, "showstats"))
X	p->p_flags |= PFSHOWSTATS;
X    else
X	p->p_flags &= ~PFSHOWSTATS;
X    p->p_dir = 0;
X    p->p_desdir = 0;
X    p->p_speed = 0;
X    p->p_desspeed = 0;
X    p->p_subspeed = 0;
X    p->p_team = (1 << tno);
X    p->p_x = planets[tno * 10].pl_x + (random() % 10000) - 5000;
X    p->p_y = planets[tno * 10].pl_y + (random() % 10000) - 5000;
X    p->p_ntorp = 0;
X    p->p_damage = 0;
X    p->p_subdamage = 0;
X    p->p_etemp = 0;
X    p->p_etime = 0;
X    p->p_wtemp = 0;
X    p->p_wtime = 0;
X    p->p_shield = 100;
X    p->p_subshield = 0;
X    p->p_swar = 0;
X    p->p_hostile = (FED|ROM|KLI|ORI);
X    p->p_hostile &= ~p->p_team;
X    p->p_kills = 0.0;
X    p->p_armies = 0;
X    sprintf(buf, "%c%x", teamlet[p->p_team], p->p_no);
X    strncpy(p->p_mapchars, buf, 2);
X    getship(&p->p_ship);
X    p->p_stats.st_entries++;
X    p->p_fuel = p->p_ship.s_maxfuel;
X    p->p_umsg.m_pending = 0;
X    p->lastm = mctl->mc_current;
X    p->p_status = PALIVE;
X    p->delay = 0;
X    p->oldalert = PFGREEN;
X    p->mapmode = 1;
X    p->namemode = 1;
X    p->statmode = 1;
X    p->warncount = 0;
X    p->warntimer = -1;
X    p->infomapped = 0;
X    p->mustexit = 0;
X    p->redrawall = 1;
X    time(&p->start_time);
X}
X
X/*ARGSUSED*/
Xenter_copilot(p, pno)
Xregister struct player	*p;
Xint pno;
X{
X    p->lastm = mctl->mc_current;
X}
X
Xopenmem()
X{
X    subdaemon();
X}
X
Xfindslot()
X{
X    register int i;
X
X    for (i = 0; i < MAXPLAYER; i++) {
X	if (players[i].p_status == PFREE) {	/* We have a free slot */
X	    players[i].p_status = PSETUP;	/* possible race code */
X	    break;
X	}
X    }
X    if (i < MAXPLAYER)
X	    bzero(&players[i].p_stats, sizeof(struct stats));  /* Slight problem for
X							  copilot */
X    return(i);
X}
END_OF_FILE
if test 3043 -ne `wc -c <'enter.c'`; then
    echo shar: \"'enter.c'\" unpacked with wrong size!
fi
# end of 'enter.c'
fi
if test -f 'interface.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'interface.c'\"
else
echo shar: Extracting \"'interface.c'\" \(2825 characters\)
sed "s/^X//" >'interface.c' <<'END_OF_FILE'
Xstatic char sccsid[] = "@(#)interface.c	1.1";
X/*
X
X	Copyright (c) 1986 	Chris Guthrie
X
XPermission to use, copy, modify, and distribute this
Xsoftware and its documentation for any purpose and without
Xfee is hereby granted, provided that the above copyright
Xnotice appear in all copies and that both that copyright
Xnotice and this permission notice appear in supporting
Xdocumentation.  No representations are made about the
Xsuitability of this software for any purpose.  It is
Xprovided "as is" without express or implied warranty.
X
X*/
X
X/* This file will include all the interfaces between the input routines
X    and the daemon.  They should be useful for writing robots and the
X    like */
X
X#include <X11/Xlib.h>
X#include <stdio.h>
X#include <math.h>
X#include <signal.h>
X#include "defs.h"
X#include "data.h"
X
Xset_speed(p, speed)
Xregister struct player	*p;
Xint speed;
X{
X    p->p_desspeed = speed;
X    p->p_flags &= ~(PFREPAIR | PFBOMB | PFORBIT | PFBEAMUP | PFBEAMDOWN);
X}
X
Xset_course(p, dir)
Xregister struct player	*p;
Xunsigned char dir;
X{
X    p->p_desdir = dir;
X    p->p_flags &= ~(PFBOMB | PFORBIT | PFBEAMUP | PFBEAMDOWN);
X}
X
Xshield_up(p)
Xregister struct player	*p;
X{
X    p->p_flags |= PFSHIELD;
X    p->p_flags &= ~(PFBOMB | PFREPAIR | PFBEAMUP | PFBEAMDOWN);
X}
X
Xshield_down(p)
Xregister struct player	*p;
X{
X    p->p_flags &= ~PFSHIELD;
X}
X
Xshield_tog(p)
Xregister struct player	*p;
X{
X    p->p_flags ^= PFSHIELD;
X    p->p_flags &= ~(PFBOMB | PFREPAIR | PFBEAMUP | PFBEAMDOWN);
X}
X
Xbomb_planet(p)
Xregister struct player	*p;
X{
X    if (!(p->p_flags & PFORBIT)) {
X	warning(p, "Must be orbiting to bomb");
X	return;
X    }
X    p->p_flags |= PFBOMB;
X    p->p_flags &= ~(PFSHIELD | PFREPAIR | PFBEAMUP | PFBEAMDOWN);
X}
X
Xbeam_up(p)
Xregister struct player	*p;
X{
X    if (!(p->p_flags & PFORBIT)) {
X	warning(p, "Must be orbiting to beam up.");
X	return;
X    }
X    if (p->p_team != planets[p->p_planet].pl_owner) {
X	warning(p, "Those aren't our armies.");
X	return;
X    }
X    p->p_flags |= PFBEAMUP;
X    p->p_flags &= ~(PFSHIELD | PFREPAIR | PFBOMB | PFBEAMDOWN);
X}
X
Xbeam_down(p)
Xregister struct player	*p;
X{
X    if (!(p->p_flags & PFORBIT)) {
X	warning(p, "Must be orbiting to beam down.");
X	return;
X    }
X    p->p_flags |= PFBEAMDOWN;
X    p->p_flags &= ~(PFSHIELD | PFREPAIR | PFBOMB | PFBEAMUP);
X}
X
Xrepair(p)
Xregister struct player	*p;
X{
X    p->p_desspeed = 0;
X    p->p_flags |= PFREPAIR;
X    p->p_flags &= ~(PFSHIELD | PFBOMB | PFBEAMUP | PFBEAMDOWN);
X}
X
Xrepair_off(p)
Xregister struct player	*p;
X{
X    p->p_flags &= ~PFREPAIR;
X}
X
Xrepeat_message(p)
Xregister struct player	*p;
X{
X    if (++(p->lastm) == MAXMESSAGE) ;
X	p->lastm = 0;
X}
X
Xcloak(p)
Xregister struct player	*p;
X{
X    p->p_flags ^= PFCLOAK;
X}
X
Xcloak_on(p)
Xregister struct player	*p;
X{
X    p->p_flags |= PFCLOAK;
X}
X
Xcloak_off(p)
Xregister struct player	*p;
X{
X    p->p_flags &= ~PFCLOAK;
X}
END_OF_FILE
if test 2825 -ne `wc -c <'interface.c'`; then
    echo shar: \"'interface.c'\" unpacked with wrong size!
fi
# end of 'interface.c'
fi
if test -f 'main.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'main.c'\"
else
echo shar: Extracting \"'main.c'\" \(3174 characters\)
sed "s/^X//" >'main.c' <<'END_OF_FILE'
Xstatic char sccsid[] = "@(#)main.c	1.2";
X#ifndef lint
Xstatic char *rcsid_main_c = "$Header: /uraid2/riedl/src/xceltrek/RCS/main.c,v 1.1 88/04/18 16:10:25 riedl Exp Locker: riedl $";
X#endif	lint
X/* Copyright (c) 1986 	Chris Guthrie */
X
X#include <X11/Xlib.h>
X#include <stdio.h>
X#include <sys/types.h>
X#include <sys/time.h>
X#include <signal.h>
X#include <pwd.h>
X#include <netdb.h>
X#include <netinet/in.h>
X#include <sys/socket.h>
X#ifdef SUN40
X#include <sys/filio.h>
X#else
X#define	FD_SET(n, s)	(((s)->fds_bits[0]) |= (1 << n))
X#define	FD_CLR(n, s)	(((s)->fds_bits[0]) &= ~(1 << n))
X#define	FD_ZERO(s)	bzero((char *)(s), sizeof (*(s)))
X#define	FD_ISSET(n, s)	(((s)->fds_bits[0]) & (1 << n))
X#include <sys/ioctl.h>
X#endif /* SUN40 */
X#include "defs.h"
X#include "data.h"
X
Xextern int debug;
Xextern int	xtrek_socket;
Xstruct sockaddr_in	xtrekAddress;
X
Xmain(argc, argv)
Xint argc;
Xchar **argv;
X{
X    struct player	*p;
X    struct servent	*sp;
X    extern struct servent	*getservbyname();
X    int docycle(), move();
X    char *host;
X    register int i;
X    extern char *optarg;
X    extern int optind, opterr;
X    char *getenv();
X    char c;
X    int argerr = 0;
X    int	on = 1;
X    int oldinetd = 0;
X
X    freopen("/tmp/trek","a",stderr);
X#if defined(sun) && !defined(SUN40)
X    oldinetd = 1;
X#endif
X    while ((c = getopt(argc, argv, "dT:c:u:")) != EOF) {
X      switch (c) {
X      case 'T':
X	switch (optarg[0]) {
X#ifdef notdef
X	case 'f': LocalTeam = 0; break;
X	case 'r': LocalTeam = 1; break;
X	case 'k': LocalTeam = 2; break;
X	case 'o': LocalTeam = 3; break;
X#endif
X	default: argerr = 1; break;
X	}
X        break;
X      case 'c':
X/*	copilot = 1;*/
X	break;
X      case 'd':
X	debug++;
X	break;
X      case '?':
X      default:
X	argerr = 1;
X	break;
X      }
X    }
X    if (optind < argc) host = argv[optind];
X    else host = getenv("DISPLAY");
X
X    if (argerr) {
X      fprintf(stderr,"Usage: %s [-Tfrko] [-c pno] -u uid [ host:display ]\n",
X	      argv[0]);
X	exit(1);
X    }
X
X    if (debug || oldinetd) {
X	    sp = getservbyname("xtrek", "tcp");
X	    if (sp == (struct servent *) NULL) {
X		fprintf(stderr, "Can't find xtrek service\n");
X		exit(1);
X	    }
X	    xtrekAddress.sin_family = AF_INET;
X	    xtrekAddress.sin_addr.s_addr = INADDR_ANY;
X	    xtrekAddress.sin_port = sp->s_port;
X
X	    xtrek_socket = socket(AF_INET, SOCK_STREAM, 0);
X	    if (xtrek_socket < 0) {
X		fprintf(stderr, "Can't open xtrek socket\n");
X		perror("socket");
X		exit(1);
X	    }
X	    if (bind(xtrek_socket, &xtrekAddress, sizeof xtrekAddress) < 0) {
X		fprintf(stderr, "Can't bind to xtrek address\n");
X		perror("bind");
X		(void) close(xtrek_socket);
X		exit(1);
X	    }
X    } else {
X	    xtrek_socket = 0;
X    }
X    (void) setsockopt(xtrek_socket, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof on);
X    (void) setsockopt(xtrek_socket, SOL_SOCKET, SO_KEEPALIVE, (char *)&on, sizeof on);
X    ioctl(xtrek_socket, FIONBIO, (char *) &on);
X    if (listen(xtrek_socket, MAXPLAYER) < 0) {
X	fprintf(stderr, "Can't listen on xtrek socket\n");
X	perror("listen");
X	(void) close(xtrek_socket);
X	exit(1);
X    }
X
X    /* this finds the shared memory information plus a player slot */
X    openmem();
X
X    /* The main loop monster! */
X    input();
X}
END_OF_FILE
if test 3174 -ne `wc -c <'main.c'`; then
    echo shar: \"'main.c'\" unpacked with wrong size!
fi
# end of 'main.c'
fi
if test -f 'phaser.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'phaser.c'\"
else
echo shar: Extracting \"'phaser.c'\" \(2614 characters\)
sed "s/^X//" >'phaser.c' <<'END_OF_FILE'
Xstatic char sccsid[] = "@(#)phaser.c	1.1";
X
X/*
X
X	Copyright (c) 1986 	Chris Guthrie
X
XPermission to use, copy, modify, and distribute this
Xsoftware and its documentation for any purpose and without
Xfee is hereby granted, provided that the above copyright
Xnotice appear in all copies and that both that copyright
Xnotice and this permission notice appear in supporting
Xdocumentation.  No representations are made about the
Xsuitability of this software for any purpose.  It is
Xprovided "as is" without express or implied warranty.
X
X*/
X
X#include <X11/Xlib.h>
X#include <stdio.h>
X#include <math.h>
X#include <signal.h>
X#include "defs.h"
X#include "data.h"
X
Xphaser(p, course)
Xregister struct player	*p;
Xunsigned char course;
X{
X    register int i;
X    register struct player *j, *target;
X    register struct phaser *mine;
X    unsigned char dir;
X    int range, trange;
X    char buf[80];
X
X    mine = &phasers[p->p_no];
X
X    if (mine->ph_status != PHFREE) {
X	warning(p, "Phasers have not recharged");
X	return;
X    }
X    if (p->p_fuel < p->p_ship.s_phasercost) {
X	warning(p, "Not enough fuel for phaser");
X	return;
X    }
X    if (p->p_flags & PFREPAIR) {
X	warning(p, "Can't fire while repairing");
X	return;
X    }
X    if (p->p_flags & PFWEP) {
X	warning(p, "Weapons overheated");
X	return;
X    }
X    if (p->p_flags & PFCLOAK) {
X	warning(p, "Cannot fire while cloaked");
X	return;
X    }
X
X    p->p_fuel -= p->p_ship.s_phasercost;
X    p->p_wtemp += p->p_ship.s_phasercost / 10;
X    target = (struct player *) 0;
X    mine->ph_dir = course;
X    for (i = 0, j = &players[i]; i < MAXPLAYER; i++, j++) {
X	if ((j->p_status != PALIVE) || (j == p))
X	    continue;
X	if ((!((j->p_swar | j->p_hostile) & p->p_team)) &&
X	    (!((p->p_swar | p->p_hostile) & j->p_team)))
X		continue;
X	dir = (unsigned char) (atan2((double) (j->p_x - p->p_x),
X	    (double) (p->p_y - j->p_y))
X	    / 3.14159 * 128.);
X	if (angdist(dir, course) < 5) {
X	    trange = (int) hypot((double) (j->p_x - p->p_x),
X		(double) (j->p_y - p->p_y));
X	    if (target == 0) {
X		target = j;
X		range = trange;
X	    }
X	    else if (range > trange) {
X		target = j;
X		range = trange;
X	    }
X	}
X    }
X    if ((target == 0) || (range > p->p_ship.s_phasedist)) {
X	mine->ph_fuse = 10;
X	mine->ph_status = PHMISS;
X	warning(p, "Phaser missed!!!");
X    }
X    else {
X	mine->ph_fuse = 10;
X	mine->ph_target = target->p_no;
X	mine->ph_damage = (p->p_ship.s_phasedist - range) * p->p_ship.s_phaserdamage / p->p_ship.s_phasedist;
X	mine->ph_status = PHHIT;
X	(void) sprintf(buf, "Phaser hit %s for %d points",
X	    target->p_name,
X	    mine->ph_damage);
X	warning(p, buf);
X    }
X    p->p_stats.st_phasers++;
X}
END_OF_FILE
if test 2614 -ne `wc -c <'phaser.c'`; then
    echo shar: \"'phaser.c'\" unpacked with wrong size!
fi
# end of 'phaser.c'
fi
if test -f 'planets.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'planets.h'\"
else
echo shar: Extracting \"'planets.h'\" \(3246 characters\)
sed "s/^X//" >'planets.h' <<'END_OF_FILE'
X/* static char sccsid[] = "@(#)planets.h	1.1"; */
X/*
X
X	Copyright (c) 1986 	Chris Guthrie
X
XPermission to use, copy, modify, and distribute this
Xsoftware and its documentation for any purpose and without
Xfee is hereby granted, provided that the above copyright
Xnotice appear in all copies and that both that copyright
Xnotice and this permission notice appear in supporting
Xdocumentation.  No representations are made about the
Xsuitability of this software for any purpose.  It is
Xprovided "as is" without express or implied warranty.
X
X*/
X
Xstruct planet pdata[MAXPLANETS] = {
X    {  0, (FED|PLHOME|PLFUEL|PLREPAIR), FED, 20000, 80000, "Earth", 5, 30, FED, 0, 0 },
X    {  1, FED, FED, 10000, 60000, "Sasus", 5, 30, FED, 0, 0 },
X    {  2, FED, FED, 25000, 60000, "Candeleron", 10, 30, FED, 0, 0 },
X    {  3, FED, FED, 44000, 81000, "Beta III", 8, 30, FED, 0, 0 },
X    {  4, FED, FED, 33000, 55000, "Janus", 5, 30, FED, 0, 0 },
X    {  5, FED, FED, 30000, 90000, "Deneb VI", 8, 30, FED, 0, 0 },
X    {  6, FED, FED, 45000, 66000, "Ceti IV", 7, 30, FED, 0, 0 },
X    {  7, FED, FED, 11000, 75000, "Altar", 5, 30, FED, 0, 0 },
X    {  8, FED, FED,  8000, 93000, "Dekar", 5, 30, FED, 0, 0 },
X    {  9, FED, FED, 32000, 74000, "Daltus", 6, 30, FED, 0, 0 },
X    { 10, (ROM|PLHOME|PLFUEL|PLREPAIR), ROM, 20000, 20000, "Romulus", 7, 30, ROM, 0, 0 },
X    { 11, ROM, ROM, 45000,  7000, "Ethen", 5, 30, ROM, 0, 0 },
X    { 12, ROM, ROM,  4000, 12000, "Amur", 4, 30, ROM, 0, 0 },
X    { 13, ROM, ROM, 42000, 44000, "Remus", 5, 30, ROM, 0, 0 },
X    { 14, ROM, ROM, 13000, 45000, "Bal", 3, 30, ROM, 0, 0 },
X    { 15, ROM, ROM, 28000,  8000, "Tahndar", 7, 30, ROM, 0, 0 },
X    { 16, ROM, ROM, 28000, 23000, "Dact", 4, 30, ROM, 0, 0 },
X    { 17, ROM, ROM, 40000, 25000, "Sirius II", 9, 30, ROM, 0, 0 },
X    { 18, ROM, ROM, 25000, 44000, "Rakhir", 6, 30, ROM, 0, 0 },
X    { 19, ROM, ROM,  8000, 29000, "Rus", 3, 30, ROM, 0, 0 },
X    { 20, (KLI|PLHOME|PLFUEL|PLREPAIR), KLI, 80000, 20000, "Klingus", 7, 30, KLI, 0, 0 },
X    { 21, KLI, KLI, 70000, 40000, "Malatrakir", 10, 30, KLI, 0, 0 },
X    { 22, KLI, KLI, 60000, 10000, "Amakron", 7, 30, KLI, 0, 0 },
X    { 23, KLI, KLI, 54000, 40000, "Laltir", 6, 30, KLI, 0, 0 },
X    { 24, KLI, KLI, 93000,  8000, "Khartair", 8, 30, KLI, 0, 0 },
X    { 25, KLI, KLI, 90000, 37000, "Monpur III", 10, 30, KLI, 0, 0 },
X    { 26, KLI, KLI, 69000, 31000, "Sectus", 6, 30, KLI, 0, 0 },
X    { 27, KLI, KLI, 83000, 48000, "Makus", 5, 30, KLI, 0, 0 },
X    { 28, KLI, KLI, 54000, 21000, "Jakar", 5, 30, KLI, 0, 0 },
X    { 29, KLI, KLI, 73000,  5000, "Gendus", 6, 30, KLI, 0, 0 },
X    { 30, (ORI|PLHOME|PLFUEL|PLREPAIR), ORI, 80000, 80000, "Orion", 5, 30, ORI, 0, 0 },
X    { 31, ORI, ORI, 92000, 59000, "Amterion", 8, 30, ORI, 0, 0 },
X    { 32, ORI, ORI, 65000, 55000, "Lumecis", 7, 30, ORI, 0, 0 },
X    { 33, ORI, ORI, 52000, 60000, "Bitar V", 7, 30, ORI, 0, 0 },
X    { 34, ORI, ORI, 72000, 69000, "Prastan", 7, 30, ORI, 0, 0 },
X    { 35, ORI, ORI, 64000, 80000, "Sorlen", 6, 30, ORI, 0, 0 },
X    { 36, ORI, ORI, 56000, 89000, "Zetus", 5, 30, ORI, 0, 0 },
X    { 37, ORI, ORI, 91000, 94000, "Jih", 3, 30, ORI, 0, 0 },
X    { 38, ORI, ORI, 70000, 93000, "Markus II", 9, 30, ORI, 0, 0 },
X    { 39, ORI, ORI, 85000, 70000, "Oren", 4, 30, ORI, 0, 0 }
X};
END_OF_FILE
if test 3246 -ne `wc -c <'planets.h'`; then
    echo shar: \"'planets.h'\" unpacked with wrong size!
fi
# end of 'planets.h'
fi
if test -f 'pstats.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'pstats.c'\"
else
echo shar: Extracting \"'pstats.c'\" \(2527 characters\)
sed "s/^X//" >'pstats.c' <<'END_OF_FILE'
Xstatic char sccsid[] = "@(#)pstats.c	1.1";
X
X/*
X
X	Copyright (c) 1986 	Chris Guthrie
X
XPermission to use, copy, modify, and distribute this
Xsoftware and its documentation for any purpose and without
Xfee is hereby granted, provided that the above copyright
Xnotice appear in all copies and that both that copyright
Xnotice and this permission notice appear in supporting
Xdocumentation.  No representations are made about the
Xsuitability of this software for any purpose.  It is
Xprovided "as is" without express or implied warranty.
X
X*/
X
X
X#include <X11/Xlib.h>
X#include <stdio.h>
X#include <sys/types.h>
X#ifdef hpux
X#include <time.h>
X#else hpux
X#include <sys/time.h>
X#endif hpux
X#include <sys/resource.h>
X#include <sys/file.h>
X#include <ndbm.h>
X#include "defs.h"
X#include "data.h"
X
Xsavestats(p)
Xregister struct player	*p;
X{
X    register DBM	*db;
X    char		buf[80];
X    datum		key, sinfo;
X    long		now;
X    struct rusage	rbuf;
X    struct stats	old;
X
X    db = dbm_open(SCOREFILE, O_RDWR, 0700);
X    if (db == (DBM *) NULL)
X	return;
X
X    if (p->p_flags & PFROBOT)
X	sprintf(buf, "%s", p->p_name);
X    else
X	sprintf(buf, "%s:%s", p->p_login, p->p_monitor);
X    key.dptr = buf;
X    key.dsize = strlen(buf) + 1;
X    sinfo = dbm_fetch(db, key);
X    if (sinfo.dptr) {
X	bcopy(sinfo.dptr, &old, sizeof (struct stats));
X        key.dptr = buf;
X        key.dsize = strlen(buf) + 1;
X	dbm_delete(db, key);
X    } else
X	bzero(&old, sizeof (struct stats));
X
X    p->p_stats.st_kills += old.st_kills;
X    p->p_stats.st_losses += old.st_losses;
X    p->p_stats.st_entries += old.st_entries;
X    p->p_stats.st_conqs += old.st_conqs;
X    p->p_stats.st_coups += old.st_coups;
X    p->p_stats.st_torps += old.st_torps;
X    p->p_stats.st_phasers += old.st_phasers;
X    p->p_stats.st_armsbomb += old.st_armsbomb;
X    p->p_stats.st_armsship += old.st_armsship;
X    p->p_stats.st_planets += old.st_planets;
X    p->p_stats.st_genocides += old.st_genocides;
X
X    time(&now);
X    p->p_stats.st_time = old.st_time + (now - p->start_time);
X
X    getrusage(0, &rbuf);
X    p->p_stats.st_cpu = old.st_cpu + rbuf.ru_utime.tv_sec + rbuf.ru_stime.tv_sec;
X
X    if (p->p_stats.st_maxkills < old.st_maxkills)
X	p->p_stats.st_maxkills = old.st_maxkills;
X
X    if (sinfo.dptr) {
X	sinfo.dptr = (char *) &old;
X	bcopy(&p->p_stats, sinfo.dptr, sizeof (struct stats));
X    } else {
X	sinfo.dptr = (char *) &p->p_stats;
X    }
X    sinfo.dsize = sizeof (struct stats);
X    key.dptr = buf;
X    key.dsize = strlen(buf) + 1;
X    dbm_store(db, key, sinfo, DBM_INSERT);
X    (void) dbm_close(db);
X}
END_OF_FILE
if test 2527 -ne `wc -c <'pstats.c'`; then
    echo shar: \"'pstats.c'\" unpacked with wrong size!
fi
# end of 'pstats.c'
fi
if test -f 'scorelist.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'scorelist.c'\"
else
echo shar: Extracting \"'scorelist.c'\" \(3442 characters\)
sed "s/^X//" >'scorelist.c' <<'END_OF_FILE'
Xstatic char sccsid[] = "@(#)scorelist.c	1.1";
X/* Copyright (c) 1986 	Chris Guthrie */
X
X
X#include <X11/Xlib.h>
X#include <stdio.h>
X#include <math.h>
X#include <signal.h>
X#include "defs.h"
X#include "data.h"
X#include "bitmaps.h"
X
X#define TEAM(p)	(1<<(p))
X#define WINSIDE 500
X
Xscorelist(p)
Xregister struct player	*p;
X{
X    register int i, t;
X    register int k = 0;
X    char buf[BUFSIZ];
X    register struct player *j;
X    struct player team;
X    int active_team;
X
X    p->infomapped = 1;
X    p->infow = XCreateWindow(p->display, p->mapw, 10, 10, 77 * fontWidth(p->dfont),
X	(MAXPLAYER + NUMTEAM + 4) * fontHeight(p->dfont), 2, DefaultDepth(p->display, p->screen), InputOutput,
X	(Visual *) CopyFromParent, 0L, (XSetWindowAttributes *) 0);
X/*	(MAXPLAYER + NUMTEAM + 4) * fontHeight(dfont), 2, p->foreTile, p->backTile);*/
X    XSetWindowBackground(p->display, p->infow, p->backColor);
X    XMapWindow(p->display, p->infow);
X    sprintf(buf, " # Name              Kills   Max Killed Skill    Torps Phasers Planets Bombed");
X    XDrawImageString(p->display, p->infow, p->dfgc, 0, fontHeight(p->dfont), buf,
X       strlen(buf));
X    k = 2;
X    for (i = 0, j = &players[i]; i < MAXPLAYER; i++, j++) {
X	if (j->p_status == PFREE)
X	    continue;
X	sprintf(buf, " %1x %-16.16s %6.2f %5.2f %6d %5.2f %7d %7d %7d %6d",
X		j->p_no,
X		j->p_name,
X		j->p_stats.st_kills,
X		j->p_stats.st_maxkills,
X		j->p_stats.st_losses,
X		(j->p_stats.st_losses == 0) ? 
X		    0 : j->p_stats.st_kills / j->p_stats.st_losses,
X		j->p_stats.st_torps,
X		j->p_stats.st_phasers,
X		j->p_stats.st_planets,
X		j->p_stats.st_armsbomb
X		);
X	XDrawImageString(p->display, p->infow, p->dfgc, 0, fontHeight(p->dfont) * k++, buf, strlen(buf));
X	XFlush(p->display);
X    }
X
X    k++;	/* leave a blank line between players and teams */
X
X    for (t = 0; t < NUMTEAM; t++) {
X	team.p_no = t;
X	switch(TEAM(t)) {
X	case FED:
X		strcpy(team.p_name, "Federation");
X		break;
X	case ROM:
X		strcpy(team.p_name, "Romulan");
X		break;
X	case ORI:
X		strcpy(team.p_name, "Orion");
X		break;
X	case KLI:
X		strcpy(team.p_name, "Klingon");
X		break;
X	}
X	team.p_stats.st_kills = 0;
X	team.p_stats.st_maxkills = 0;
X	team.p_stats.st_losses = 0;
X	team.p_stats.st_torps = 0;
X	team.p_stats.st_phasers = 0;
X	team.p_stats.st_planets = 0;
X	team.p_stats.st_armsbomb = 0;
X	active_team = 0;
X    	for (i = 0, j = &players[i]; i < MAXPLAYER; i++, j++) {
X	    if (j->p_status == PFREE || j->p_team != TEAM(t))
X		continue;
X	    active_team = 1;
X	    team.p_stats.st_kills    += j->p_stats.st_kills;   
X	    if (team.p_stats.st_maxkills < j->p_stats.st_maxkills)
X	      team.p_stats.st_maxkills = j->p_stats.st_maxkills;
X	    team.p_stats.st_losses   += j->p_stats.st_losses;  
X	    team.p_stats.st_torps    += j->p_stats.st_torps;   
X	    team.p_stats.st_phasers  += j->p_stats.st_phasers; 
X	    team.p_stats.st_planets  += j->p_stats.st_planets; 
X	    team.p_stats.st_armsbomb += j->p_stats.st_armsbomb;
X	}
X	if (active_team) {
X	  sprintf(buf, " %1x %-16.16s %6.2f %5.2f %6d %5.2f %7d %7d %7d %6d",
X		team.p_no,
X		team.p_name,
X		team.p_stats.st_kills,
X		team.p_stats.st_maxkills,
X		team.p_stats.st_losses,
X		(team.p_stats.st_losses == 0) ? 
X		    0 : team.p_stats.st_kills / team.p_stats.st_losses,
X		team.p_stats.st_torps,
X		team.p_stats.st_phasers,
X		team.p_stats.st_planets,
X		team.p_stats.st_armsbomb
X		);
X	  XDrawImageString(p->display, p->infow, p->dfgc, 0, fontHeight(p->dfont) * k++, buf, strlen(buf));
X	  XFlush(p->display);
X	}    
X    }
X}
END_OF_FILE
if test 3442 -ne `wc -c <'scorelist.c'`; then
    echo shar: \"'scorelist.c'\" unpacked with wrong size!
fi
# end of 'scorelist.c'
fi
if test -f 'stats.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'stats.c'\"
else
echo shar: Extracting \"'stats.c'\" \(6138 characters\)
sed "s/^X//" >'stats.c' <<'END_OF_FILE'
Xstatic char sccsid[] = "@(#)stats.c	1.1";
X/*
X
X	Copyright (c) 1986 	Chris Guthrie
X
XPermission to use, copy, modify, and distribute this
Xsoftware and its documentation for any purpose and without
Xfee is hereby granted, provided that the above copyright
Xnotice appear in all copies and that both that copyright
Xnotice and this permission notice appear in supporting
Xdocumentation.  No representations are made about the
Xsuitability of this software for any purpose.  It is
Xprovided "as is" without express or implied warranty.
X
X*/
X
X#include <X11/Xlib.h>
X#include <X11/cursorfont.h>
X#include <X11/Xutil.h>
X#include <stdio.h>
X#include "defs.h"
X#include "data.h"
X
X#define	MIN(a,b)	(((a) < (b)) ? (a) : (b))
X#define	MAX(a,b)	(((a) > (b)) ? (a) : (b))
X
X/* NOTE: These should be set in player data? */
X#define	BX_OFF()	((p->textWidth + 1) * fontWidth(p->dfont) + S_IBORDER)
X#define	BY_OFF(line)	((line) * (fontHeight(p->dfont) + S_IBORDER) + S_IBORDER)
X#define	TX_OFF(len)	((p->textWidth - len) * fontWidth(p->dfont) + S_IBORDER)
X#define	TY_OFF(line)	BY_OFF(line)
X
X#define STAT_WIDTH		160
X#define STAT_HEIGHT		BY_OFF(NUM_SLIDERS)
X#define STAT_BORDER		2
X#define S_IBORDER		5
X#define STAT_X			422
X#define STAT_Y			13
X
X#define SL_WID			\
X	(STAT_WIDTH - 2 * S_IBORDER - (p->textWidth + 1) * fontWidth(p->dfont))
X#define SL_HEI			(fontHeight(p->dfont))
X
X#define NUM_ELS(a)		(sizeof (a) / sizeof (*(a)))
X#define NUM_SLIDERS		NUM_ELS(sliders)
X
Xtypedef struct slider {
X	char	*label;
X	int	min, max;
X	int	low_red, high_red;
X	int	label_length;
X	int	diff;
X} SLIDER;
X
Xstatic SLIDER	sliders[] = {
X	{ "Shields",		0,	100,	20,	100	},
X	{ "Damage",		0,	100,	0,	0	},
X	{ "Fuel",		0,	10000,	1000,	10000	},
X	{ "Warp",		0,	9,	0,	9	},
X	{ "Weapon Temp",	0,	1200,	0,	1000	},
X	{ "Engine Temp",	0,	1200,	0,	1000	},
X};
X
XinitStats(p, prog)
Xregister struct player	*p;
X	char	*prog;
X{
X	int	i;
X	char	*str;
X	unsigned int dummy1, dummy2;
X
X	if ((str = XGetDefault(p->display, prog, "stats.geometry")) != NULL) {
X		p->uspec = XParseGeometry(str, &p->statX, &p->statY, &dummy1, &dummy2);
X		if ((p->uspec & (XValue|XNegative)) == (XValue|XNegative))
X			p->statX = -(p->statX);
X		if ((p->uspec & (YValue|YNegative)) == (YValue|YNegative))
X			p->statY = -(p->statY);
X	}
X	for (i = 0; i < NUM_SLIDERS; i++) {
X		sliders[i].label_length = strlen(sliders[i].label);
X		p->textWidth = MAX(p->textWidth, sliders[i].label_length);
X		sliders[i].diff = sliders[i].max - sliders[i].min;
X	}
X}
X
XWindow
XopenStats(p)
Xstruct player	*p;
X{
X	Window		w;
X	extern char 	*calloc();
X	XSizeHints	wininfo;
X	XGCValues	values;
X
X	w = XCreateWindow(p->display, RootWindow(p->display, p->screen), p->statX, p->statY,
X		(unsigned) STAT_WIDTH, (unsigned) STAT_HEIGHT, STAT_BORDER, DefaultDepth(p->display, p->screen), InputOutput,
X		(Visual *)CopyFromParent, 0L, (XSetWindowAttributes *)0);
X	XDefineCursor(p->display, w, (Cursor) XCreateFontCursor(p->display, XC_crosshair));
X	wininfo.x = p->statX;
X	wininfo.y = p->statY;
X	wininfo.width = STAT_WIDTH;
X	wininfo.height = STAT_HEIGHT;
X	wininfo.min_width = STAT_WIDTH;
X	wininfo.min_height = STAT_HEIGHT;
X	wininfo.max_width = STAT_WIDTH;
X	wininfo.max_height = STAT_HEIGHT;
X	if (p->uspec & (XValue|YValue|XNegative|YNegative))
X		wininfo.flags = USPosition | PSize | PMinSize | PMaxSize;
X	else
X		wininfo.flags = PPosition | PSize | PMinSize | PMaxSize;
X	XSetNormalHints(p->display, w, &wininfo);
X	XStoreName(p->display, w, "xtrek-stats");
X	XSetWindowBackground(p->display, w, p->backColor);
X	XSetWindowBorder(p->display, w, p->borderColor);
X	values.foreground = p->myColor;
X	values.background = p->backColor;
X	p->sgc = XCreateGC(p->display, w, GCForeground|GCBackground, &values);
X	p->rp = (RECORD *) calloc(NUM_SLIDERS, sizeof (RECORD));
X	p->rp[0].data = &(p->p_shield);
X	p->rp[1].data = &(p->p_damage);
X	p->rp[2].data = &(p->p_fuel);
X	p->rp[3].data = &(p->p_speed);
X	p->rp[4].data = &(p->p_wtemp);
X	p->rp[5].data = &(p->p_etemp);
X	XSelectInput(p->display, w, ExposureMask);
X	XMapWindow(p->display, w);
X	return (w);
X}
X
XredrawStats(p, w)
Xregister struct player	*p;
XWindow	w;
X{
X	int	i;
X
X	if (p->rp == NULL) {
X		fputs("You gave redrawStats a bum window\n", stderr);
X		return;
X	}
X	XClearWindow(p->display, w);
X	for (i = 0; i < NUM_SLIDERS; i++) {
X		p->rp[i].last_value = 0;
X		XSetForeground(p->display, p->sgc, p->myColor);
X		XDrawImageString(p->display, w, p->sgc, TX_OFF(sliders[i].label_length), TY_OFF(i) + p->dfont->ascent,
X			sliders[i].label, sliders[i].label_length);
X		box(p, w, 0, BX_OFF() - 1, BY_OFF(i) - 1, SL_WID+1, SL_HEI+1, p->myColor);
X	}
X}
X
XcloseStats(p, w)
Xregister struct player	*p;
X	Window	w;
X{
X	XWindowAttributes wa;
X
X	XFreeGC(p->display, p->sgc);
X	XGetWindowAttributes(p->display, w, &wa);
X	p->statX = wa.x;
X	p->statY = wa.y;
X	XDestroyWindow(p->display, w);
X}
X
XupdateStats(p, w)
Xregister struct player *p;
X	Window		w;
X{
X	int	i, value, diff, old_x, new_x, wid;
X	unsigned long	color;
X	RECORD	*r;
X	SLIDER	*s;
X
X	for (i = 0; i < NUM_SLIDERS; i++) {
X		r = &p->rp[i];
X		s = &sliders[i];
X		value = *(r->data);
X		if (value < s->min)
X			value = s->min;
X		else if (value > s->max)
X			value = s->max;
X		if (value == r->last_value)
X			continue;
X		diff = value - r->last_value;
X		color = p->myColor;
X		if (value < s->low_red)
X			color = p->warningColor;
X		else if (value > s->high_red)
X			color = p->warningColor;
X		old_x = r->last_value * SL_WID / s->diff;
X		new_x = value * SL_WID / s->diff;
X		wid = new_x - old_x;
X		if (wid == 0)
X			continue;
X		if (wid < 0)
X			wid = -wid;
X		if (new_x > 0)
X			box(p, w, 1, BX_OFF(), BY_OFF(i), new_x, SL_HEI, color);
X		if (diff < 0)
X			cbox(p, w, BX_OFF() + new_x, BY_OFF(i), wid, SL_HEI);
X		r->last_value = value;
X	}
X}
X
X/*ARGSUSED*/
Xbox(p, w, filled, x, y, width, height, color)
Xregister struct player	*p;
XWindow	w;
Xint	filled;
Xint	x, y;
Xunsigned width, height;
Xunsigned long	color;
X{
X	XSetForeground(p->display, p->sgc, color);
X	if (filled)
X		XFillRectangle(p->display, w, p->sgc, x, y, width, height);
X	else
X		XDrawRectangle(p->display, w, p->sgc, x, y, width, height);
X}
X
Xcbox(p, w, x, y, width, height)
Xregister struct player	*p;
XWindow	w;
Xint	x, y;
Xunsigned width, height;
X{
X	XClearArea(p->display, w, x, y, width, height, False);
X}
END_OF_FILE
if test 6138 -ne `wc -c <'stats.c'`; then
    echo shar: \"'stats.c'\" unpacked with wrong size!
fi
# end of 'stats.c'
fi
if test -f 'util.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'util.c'\"
else
echo shar: Extracting \"'util.c'\" \(3356 characters\)
sed "s/^X//" >'util.c' <<'END_OF_FILE'
Xstatic char sccsid[] = "@(#)util.c	1.1";
X
X/*
X
X	Copyright (c) 1986 	Chris Guthrie
X
XPermission to use, copy, modify, and distribute this
Xsoftware and its documentation for any purpose and without
Xfee is hereby granted, provided that the above copyright
Xnotice appear in all copies and that both that copyright
Xnotice and this permission notice appear in supporting
Xdocumentation.  No representations are made about the
Xsuitability of this software for any purpose.  It is
Xprovided "as is" without express or implied warranty.
X
X*/
X
X#include <X11/Xlib.h>
X#include <stdio.h>
X#include <math.h>
X#include <signal.h>
X#include "defs.h"
X#include "data.h"
X
X/*
X** Provide the angular distance between two angles.
X*/
Xangdist(x, y)
Xunsigned char x, y;
X{
X    register unsigned char res;
X
X    res = ABS(x - y);
X    if (res > 128)
X	return(256 - (int) res);
X    return((int) res);
X}
X
X#define WINSIDE 500
X
X/*
X** Find the object nearest mouse.  Returns a pointer to an
X** obtype structure.  This is used for info and locking on.
X**
X** Because we are never interested in it, this function will
X** never return your own ship as the target.
X**
X** Finally, this only works on the two main windows
X*/
X
Xstatic struct obtype _target;
X
Xstruct obtype *
Xgettarget(p, ww, x, y, targtype)
Xregister struct player	*p;
XWindow ww;
Xint x, y;
Xint targtype;
X{
X    register int i;
X    register struct player *j;
X    register struct planet *k;
X    int	g_x, g_y;
X    double dist, closedist;
X
X    if (ww == p->mapw) {
X	g_x = x * GWIDTH / WINSIDE;
X	g_y = y * GWIDTH / WINSIDE;
X    }
X    else {
X	g_x = p->p_x + ((x - WINSIDE/2) * SCALE);
X	g_y = p->p_y + ((y - WINSIDE/2) * SCALE);
X    }
X    closedist = GWIDTH;
X
X    if (targtype & TARG_PLANET) {
X	for (i = 0, k = &planets[0]; i < MAXPLANETS; i++, k++) {
X	    dist = hypot((double) (g_x - k->pl_x), (double) (g_y - k->pl_y));
X	    if (dist < closedist) {
X		_target.o_type = PLANETTYPE;
X		_target.o_num = i;
X		closedist = dist;
X	    }
X
X	}
X    }
X
X    if (targtype & TARG_PLAYER) {
X	for (i = 0, j = &players[i]; i < MAXPLAYER; i++, j++) {
X	    if (j->p_status != PALIVE)
X		continue;
X	    if ((j->p_flags & PFCLOAK) && (!(targtype & TARG_CLOAK)))
X		continue;
X	    if (j == p && (targtype & TARG_MYSELF) == 0)
X		continue;
X	    dist = hypot((double) (g_x - j->p_x), (double) (g_y - j->p_y));
X	    if (dist < closedist) {
X		_target.o_type = PLAYERTYPE;
X		_target.o_num = i;
X		closedist = dist;
X	    }
X	}
X    }
X
X    if (closedist == GWIDTH) {		/* Didn't get one.  bad news */
X	_target.o_type = PLAYERTYPE;
X	_target.o_num = p->p_no;	/* Return myself.  Oh well... */
X	return(&_target);
X    }
X    else {
X	return(&_target);
X    }
X}
X
X/*
X** Tell us if a window is currently visible on the screen
X*/
X
Xismapped(p, win)
Xregister struct player	*p;
XWindow win;
X{
X    XWindowAttributes info;
X    
X    XGetWindowAttributes(p->display, win, &info);
X
X    return (info.map_state == IsViewable);
X}
X
X#ifdef hpux
X
Xsrandom(foo)
Xint foo;
X{
X    rand(foo);
X}
X
Xrandom()
X{
X    return(rand());
X}
X
X#include <time.h>
X#include <sys/resource.h>
X
Xgetrusage(foo, buf)
Xint foo;
Xstruct rusage *buf;
X{
X    buf->ru_utime.tv_sec = 0;
X    buf->ru_stime.tv_sec = 0;
X}
X
X#include <sys/signal.h>
X
Xint (*
Xsignal(sig, funct))()
Xint sig;
Xint (*funct)();
X{
X    struct sigvec vec, oldvec;
X
X    sigvector(sig, 0, &vec);
X    vec.sv_handler = funct;
X    sigvector(sig, &vec, (struct sigvec *) 0);
X}
X#endif hpux
END_OF_FILE
if test 3356 -ne `wc -c <'util.c'`; then
    echo shar: \"'util.c'\" unpacked with wrong size!
fi
# end of 'util.c'
fi
if test -f 'war.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'war.c'\"
else
echo shar: Extracting \"'war.c'\" \(4996 characters\)
sed "s/^X//" >'war.c' <<'END_OF_FILE'
Xstatic char sccsid[] = "@(#)war.c	1.1";
X/*
X
X	Copyright (c) 1986 	Chris Guthrie
X
XPermission to use, copy, modify, and distribute this
Xsoftware and its documentation for any purpose and without
Xfee is hereby granted, provided that the above copyright
Xnotice appear in all copies and that both that copyright
Xnotice and this permission notice appear in supporting
Xdocumentation.  No representations are made about the
Xsuitability of this software for any purpose.  It is
Xprovided "as is" without express or implied warranty.
X
X*/
X
X#include <X11/Xlib.h>
X#include <stdio.h>
X#include <math.h>
X#include <signal.h>
X#include "defs.h"
X#include "data.h"
X
X#define WINSIDE 500
X
X/* Set up the war window and map it */
Xstatic char *feds = "FED - ";
Xstatic char *roms = "ROM - ";
Xstatic char *klis = "KLI - ";
Xstatic char *oris = "ORI - ";
Xstatic char *gos = "  Re-program";
Xstatic char *exs = "  Exit - no change";
Xstatic char *peaces = "Peace";
Xstatic char *hostiles = "Hostile";
Xstatic char *wars = "War";
X
Xwarwindow(p)
Xregister struct player	*p;
X{
X    XMapWindow(p->display, p->war);
X    p->newhostile = p->p_hostile;
X    p->reprogram = 0;
X    warrefresh(p);
X}
X
Xwarrefresh(p)
Xregister struct player	*p;
X{
X    fillwin(p, p->warf, feds, p->newhostile, p->p_swar, FED);
X    fillwin(p, p->warr, roms, p->newhostile, p->p_swar, ROM);
X    fillwin(p, p->wark, klis, p->newhostile, p->p_swar, KLI);
X    fillwin(p, p->waro, oris, p->newhostile, p->p_swar, ORI);
X    XDrawImageString(p->display, p->wargo, p->dfgc, 0, fontHeight(p->dfont) / 2 + p->dfont->ascent, gos, strlen(gos));
X    XDrawImageString(p->display, p->warno, p->dfgc, 0, fontHeight(p->dfont) / 2 + p->dfont->ascent, exs, strlen(exs));
X}
X
Xfillwin(p, win, string, hostile, warbits, team)
Xregister struct player	*p;
XWindow win;
Xchar *string;
Xint hostile, warbits;
Xint team;
X{
X    char buf[80];
X
X	XFillRectangle(p->display, win, p->cleargc, 0, fontHeight(p->dfont) / 2, fontWidth(p->dfont) * 20,
X	fontHeight(p->dfont));
X/*    XPixSet(win, 0, fontHeight(dfont) / 2, fontWidth(dfont) * 20,
X	fontHeight(dfont), backColor); */
X    if (team & warbits) {
X	(void) sprintf(buf, "  %s%s", string, wars);
X	XDrawImageString(p->display, win, p->dfgc, 0, fontHeight(p->dfont) / 2 + p->dfont->ascent, buf, strlen(buf));
X    }
X    else if (team & hostile) {
X	(void) sprintf(buf, "  %s%s", string, hostiles);
X	XDrawImageString(p->display, win, p->dfgc, 0, fontHeight(p->dfont) / 2 + p->dfont->ascent, buf, strlen(buf));
X    }
X    else {
X	(void) sprintf(buf, "  %s%s", string, peaces);
X	XDrawImageString(p->display, win, p->dfgc, 0, fontHeight(p->dfont) / 2 + p->dfont->ascent, buf, strlen(buf));
X    }
X}
X
Xwaraction(p, data)
Xregister struct player	*p;
XXKeyEvent *data;
X{
X    int changes;
X
X#ifdef notdef
X    if ((data->window != warno) && (watch)) {
X	warning(p, "can't modify war settings from watch");
X	return;
X    }
X#endif
X    if (data->window == p->warf) {
X	if (p->p_swar & FED) {
X	    warning(p, "You are already at war with the Federation");
X	    XBell(p->display, 0);
X	}
X	else {
X	    p->newhostile ^= FED;
X	}
X    }
X    if (data->window == p->warr) {
X	if (p->p_swar & ROM) {
X	    warning(p, "You are already at war with the Romulans");
X	    XBell(p->display, 0);
X	}
X	else {
X	    p->newhostile ^= ROM;
X	}
X    }
X    if (data->window == p->wark) {
X	if (p->p_swar & KLI) {
X	    warning(p, "You are already at war with the Klingons");
X	    XBell(p->display, 0);
X	}
X	else {
X	    p->newhostile ^= KLI;
X	}
X    }
X    if (data->window == p->waro) {
X	if (p->p_swar & ORI) {
X	    warning(p, "You are already at war with the Orions");
X	    XBell(p->display, 0);
X	}
X	else {
X	    p->newhostile ^= ORI;
X	}
X    }
X    warrefresh(p);
X
X    if (data->window == p->wargo) {
X	changes = p->p_hostile ^ p->newhostile;
X	if (changes & FED) {
X	    sendwarn(p, "Federation", p->newhostile & FED, FED);
X	}
X	if (changes & ROM) {
X	    sendwarn(p, "Romulans", p->newhostile & ROM, ROM);
X	}
X	if (changes & KLI) {
X	    sendwarn(p, "Klingons", p->newhostile & KLI, KLI);
X	}
X	if (changes & ORI) {
X	    sendwarn(p, "Orions", p->newhostile & ORI, ORI);
X	}
X	p->p_hostile = p->newhostile;
X	if (p->reprogram) {
X	    p->delay = p->p_updates + 100;
X	    p->p_flags |= PFWAR;	/* stop copilots, mostly */
X	    warning(p, "Pausing ten seconds to re-program battle computers.");
X	}
X	XUnmapWindow(p->display, p->war);
X	return;
X    }
X
X    if (data->window == p->warno) {
X	XUnmapWindow(p->display, p->war);
X	return;
X    }
X}
X
Xsendwarn(p, string, atwar, team)
Xregister struct player	*p;
Xchar *string;
Xint atwar;
Xint team;
X{
X    char buf[BUFSIZ];
X    char addrbuf[10];
X
X    if (atwar) {
X	(void) sprintf(buf, "%s (%c%x) declaring war on the %s",
X	    p->p_name,
X	    teamlet[p->p_team],
X	    p->p_no,
X	    string);
X	p->reprogram = 1;
X    }
X    else {
X	(void) sprintf(buf, "%s (%c%x) declaring peace with the %s",
X	    p->p_name,
X	    teamlet[p->p_team],
X	    p->p_no,
X	    string);
X    }
X
X    (void) sprintf(addrbuf, " %c%x->%-3s",
X	teamlet[p->p_team],
X	p->p_no,
X	teamshort[team]);
X    pmessage(buf, team, MTEAM, addrbuf);
X}
END_OF_FILE
if test 4996 -ne `wc -c <'war.c'`; then
    echo shar: \"'war.c'\" unpacked with wrong size!
fi
# end of 'war.c'
fi
if test -f 'xtrek.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'xtrek.c'\"
else
echo shar: Extracting \"'xtrek.c'\" \(3265 characters\)
sed "s/^X//" >'xtrek.c' <<'END_OF_FILE'
Xstatic char sccsid[] = "@(#)xtrek.c	1.2";
X#include <sys/types.h>
X#include <stdio.h>
X#include <pwd.h>
X#include <sys/socket.h>
X#include <sys/ioctl.h>
X#include <netinet/in.h>
X#ifdef SUN40
X#include <sys/filio.h>
X#else
X#define	FD_SET(n, s)	(((s)->fds_bits[0]) |= (1 << n))
X#define	FD_CLR(n, s)	(((s)->fds_bits[0]) &= ~(1 << n))
X#define	FD_ZERO(s)	bzero((char *)(s), sizeof (*(s)))
X#define	FD_ISSET(n, s)	(((s)->fds_bits[0]) & (1 << n))
X#include <sys/ioctl.h>
X#endif /* SUN40 */
X#include <setjmp.h>
X#include <netdb.h>
X#include <signal.h>
X#include <string.h>
X
Xstruct sockaddr_in	sin;
Xstruct sockaddr_in	udp_sin;
Xstruct servent		*sp;
Xjmp_buf			sdied;
X
Xdone()
X{
X	fprintf(stderr, "broken pipe\n");
X	longjmp(sdied);
X}
X
Xmain(ac, av)
Xregister int	ac;
Xregister char	**av;
X{
X	register struct hostent	*host = (struct hostent *) NULL;
X	struct passwd	*pwent;
X	int	s;
X	char	*h, *p;
X	char	hostname[80];	/* The xtrek-server-machine */
X	char	*display;
X	struct servent	*sp;
X	extern struct servent	*getservbyname();
X	extern char	*getenv();
X
X	p = strrchr(av[0], '/');
X	if (p == (char *) NULL)
X		p = av[0];
X	if (ac != 2)
X		usage(p);
X
X	pwent = getpwuid(getuid());
X	if (pwent == (struct passwd *) NULL) {
X		printf("Who are you?\n");
X		exit(2);
X	}
X	display = getenv("DISPLAY");
X	if (display == (char *) NULL) {
X		printf("Your DISPLAY environment variable is not set.\n");
X		exit(3);
X	}
X
X	h = av[1];
X	sin.sin_addr.s_addr = inet_addr(h);
X	if (sin.sin_addr.s_addr != -1) {
X		sin.sin_family = AF_INET;
X		(void) strcpy(hostname, h);
X	} else {
X		host = gethostbyname(h);
X		if (host) {
X			sin.sin_family = host->h_addrtype;
X			bcopy(host->h_addr, (caddr_t) &sin.sin_addr,
X				host->h_length);
X			strcpy(hostname, host->h_name, strlen(host->h_name));
X		} else {
X			printf("%s: unknown host\n", h);
X			exit(1);
X		}
X	}
X	sin.sin_port = 5701;
X
X	signal(SIGPIPE, done);
X#if defined(sun) && !defined(SUN40)
X	/* Do something to get inetd to start up in.xtrekd */
X	sp = getservbyname("xtrek", "udp");
X	if (sp == (struct servent *) NULL) {
X		goto normal;
X	}
X	udp_sin = sin;
X	udp_sin.sin_port = sp->s_port;
X	s = socket(AF_INET, SOCK_DGRAM, 0);
X	if (s < 0) {
X		fprintf(stderr, "Can't open xtrek datagram socket\n");
X		perror("socket");
X		exit(1);
X	}
X	if (connect(s, (struct sockaddr *) &udp_sin, sizeof (udp_sin)) < 0) {
X		perror("connect udp");
X		(void) close(s);
X		exit(1);
X	}
X	send(s, "WAKEUP!\015\012", 9, 0);
X	close(s);
Xnormal:
X	sleep(3);		/* give the daemon a chance to start */
X#endif
X	s = socket(AF_INET, SOCK_STREAM, 0);
X	if (s < 0) {
X		perror("socket");
X		exit(1);
X	}
X	if (connect(s, (struct sockaddr *) &sin, sizeof (sin)) < 0) {
X		perror("connect");
X		(void) close(s);
X		exit(1);
X	}
X	if (setjmp(sdied) == 0)
X		startup(s, display, pwent->pw_name);
X	exit(0);
X}
X
Xstartup(s, d, l)
Xregister int	s;
Xregister char	*d, *l;
X{
X	char	buf[80];
X	int	n = 1;
X
X	sprintf(buf, "Display: %s Login: %s", d, l);
X	write(s, buf, strlen(buf));
X	write(s, "\015\012", 2);
X	fflush(stdout);
X	while ((n = read(s, buf, sizeof buf)) >= 0) {
X		if (n <= 0) {
X			write(s, "DONE\n", 5);	/* Does this cause SIGPIPE? */
X			/* No, I think it causes read() above to return -1 */
X			sleep(1);
X		} else
X			write(fileno(stdout), buf, n);
X	}
X	return 1;
X}
X
Xusage(p)
Xregister char	*p;
X{
X	printf("Usage: %s xtrek-server-machine\n", p);
X	exit(1);
X}
END_OF_FILE
if test 3265 -ne `wc -c <'xtrek.c'`; then
    echo shar: \"'xtrek.c'\" unpacked with wrong size!
fi
# end of 'xtrek.c'
fi
echo shar: End of archive 6 \(of 7\).
cp /dev/null ark6isdone
MISSING=""
for I in 1 2 3 4 5 6 7 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 7 archives.
    rm -f ark[1-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0
-- 
Mike Wexler(wyse!mikew)    Phone: (408)433-1000 x1330
Moderator of comp.sources.x



More information about the Comp.sources.x mailing list