Vanilla Netrek Server Development Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[VANILLA-L:789] Cambot patch



What follows is a patch to add the remaining components for cambot.

(This is not going out in gzip, or as an attachment. (Just in case you
didn't notice ;-) ))


================================  Start patch =========================
*** tools/cambot.c.orig	Mon Sep 29 22:41:38 1997
--- tools/cambot.c	Thu Feb  5 23:52:57 1998
***************
*** 0 ****
--- 1,305 ----
+ /*
+  * cambot.c - Robot designed to watch the shared memory segment, and generate
+  *            packets to be stored on disk for future playback.
+  */
+ 
+ #include <stdio.h>
+ #include <string.h>
+ #include <sys/types.h>
+ #include <sys/time.h>
+ #include <signal.h>
+ #include <setjmp.h>
+ #include <sys/file.h>
+ #include <sys/ipc.h>
+ #include <sys/shm.h>
+ #include <errno.h>
+ #include <pwd.h>
+ #include <ctype.h>
+ #include <time.h>
+ #include "defs.h"
+ #include "struct.h"
+ #include "data.h"
+ #include "packets.h"
+ 
+ #define UPDT_ALL 0
+ #define UPDT_MOST 1
+ #define PERSEC 5
+ 
+ #define RECORDFILE "cambot.pkt"
+ FILE *packetsFile;
+ 
+ struct you_short_spacket clientSelfs[MAXPLAYER];
+ struct youss_spacket clientSelfShips[MAXPLAYER];
+ struct player cambot_me;
+ struct itimerval udt;
+ char	*cb_from = {"GOD->ALL"};
+ int msgCurrent;
+ int use_newyou=1;
+ int f_many_self=1;
+ static LONG sequence;
+ 
+ struct feature_spacket Many_Self_F = {SP_FEATURE, 'S', 0, 0, 1, "MANY_SELF"};
+ 
+ /* Make linker happy... */
+ int ignored[MAXPLAYER];
+ int debug;
+ int parseQuery() {return 0;}
+ void message_flag() {}
+ void check_command() {}
+ void flushSockBuf() {}
+ 
+ extern struct torp_info_spacket clientTorpsInfo[MAXPLAYER*MAXTORP];
+ extern struct torp_spacket clientTorps[MAXPLAYER*MAXTORP];
+ extern struct phaser_spacket clientPhasers[MAXPLAYER];
+ extern struct phaser_s_spacket client_s_Phasers[MAXPLAYER];
+ extern struct plasma_info_spacket clientPlasmasInfo[MAXPLAYER*MAXPLASMA];
+ extern struct plasma_spacket clientPlasmas[MAXPLAYER*MAXPLASMA];
+ extern int mustUpdate[MAXPLAYER];
+ extern int clientVKillsCount;
+ extern struct plyr_info_spacket clientPlayersInfo[MAXPLAYER];
+ extern struct plyr_login_spacket clientLogin[MAXPLAYER];
+ extern struct player_spacket clientPlayers[MAXPLAYER];
+ extern struct kills_spacket clientKills[MAXPLAYER];
+ extern struct pstatus_spacket clientPStatus[MAXPLAYER];
+ extern struct stats_spacket clientStats[MAXPLAYER];
+ extern int	clientVPlanetCount;
+ extern struct planet_spacket clientPlanets[MAXPLANETS];
+ extern struct planet_loc_spacket clientPlanetLocs[MAXPLANETS];
+ extern int sizes[TOTAL_SPACKETS];
+ extern int use_newyou;
+ extern int f_many_self;
+ 
+ void
+ cleanup(void)
+ {
+     fclose(packetsFile);
+     exit(0);
+ }
+ 
+ /* HACK - Make the socket.c routines call this routine instead
+  * of the normal socket stuff */
+ void
+ sendClientPacket(struct player_spacket *packet)
+ {
+     if (!fwrite(packet, 1, sizes[(int)packet->type], packetsFile))
+     {
+ 	ERROR(1,("Bad write on packets file.\n"));
+ 	cleanup();
+     }
+ }
+ 
+ /* Main routine */
+ /* This is a mimic of updateClient from socket.c - It will call the
+    necessary routines to generate the desired packets */
+ void
+ cb_updt(void)
+ {
+     HANDLE_SIG(SIGALRM, cb_updt);
+ 
+     /*  updateTorps(); */
+     {
+ 	struct torp *t;
+ 	int i;
+ 	struct torp_info_spacket *tpi;
+ 	struct torp_spacket *tp;
+ 
+ 	for (i=0, t=firstTorp, tpi=clientTorpsInfo, tp=clientTorps; 
+ 	     t<=lastTorp; i++, t++, tpi++, tp++)
+ 	    sndTorp(tpi, tp, t, i, UPDT_ALL);
+     }
+ 
+     /*  updatePlasmas(); */
+     {
+ 	struct torp *t;
+ 	int i;
+ 	struct plasma_info_spacket *tpi;
+ 	struct plasma_spacket *tp;
+ 
+ 	for (i=0, t=firstPlasma, tpi=clientPlasmasInfo, tp=clientPlasmas; 
+ 	     t<=lastPlasma; i++, t++, tpi++, tp++)
+ 	    sndPlasma(tpi, tp, t, i, UPDT_ALL);
+     }
+ 
+     updateStatus();
+ 
+     /*  updatePhasers(); */
+     {
+ 	int i;
+ 	struct phaser_spacket *ph;
+ 	struct phaser *phase;
+ 	struct player *pl;
+ 	struct phaser_s_spacket *phs;
+ 
+ 	for (i = 0, ph = clientPhasers,phs = client_s_Phasers,
+ 		 phase = phasers, pl = players; 
+ 	     i < MAXPLAYER; i++, ph++, phs++, phase++, pl++) { 
+ 	    if (phase->ph_status==PHHIT) {
+ 		mustUpdate[phase->ph_target]=1;
+ 	    }
+ 	    sndPhaser(ph, phs, phase, i, UPDT_ALL);
+ 	}
+     }
+ 
+     /*  updateSelf(); */
+     /*  updateShips(); */
+     {
+ 	int i;
+ 	struct player *pl;
+ 	struct plyr_info_spacket *cpli;
+ 	struct player_spacket *cpl;
+ 	struct kills_spacket *kills;
+ 	struct pstatus_spacket *pstatus;
+ 	struct plyr_login_spacket *login;
+ 	struct stats_spacket *stats;
+ 	struct you_short_spacket *self;
+ 	struct youss_spacket *self2;
+ 
+ 	clientVKillsCount = 0;
+ 
+ 	/* Please excuse the ugliness of this loop declaration */
+ 	for (i=0, pl=players, cpli=clientPlayersInfo, cpl=clientPlayers,
+ 		 kills=clientKills, pstatus=clientPStatus,
+ 		 login=clientLogin, stats=clientStats,
+ 		 self=clientSelfs, self2=clientSelfShips;
+ 	     i<MAXPLAYER;
+ 	     i++, pl++, cpli++, cpl++, kills++, pstatus++, login++,
+ 		 stats++, self++, self2++) {
+ 	    sndSelfShip(self2, pl);
+ 	    sndSSelf(self, pl, UPDT_MOST);
+ 	    sndLogin(login, pl);
+ 	    sndPlayerInfo(cpli, pl);
+ 	    sndKills(kills, pl);
+ 	    sndPStatus(pstatus, pl);
+ 
+ 	    /* NOTE: Can't send VPlayer packets, it only sends player positions
+ 	     * relative to me->p_x/me->p_y.  We need to use the older packets
+ 	     * so that absolute positions are recorded */
+ 	    if (updtPlayer(cpl, pl, UPDT_ALL))
+ 		sendClientPacket(cpl);
+ 	}
+ 
+ 	sendVKills();
+     }
+ 
+     /*  updatePlanets(); */
+     {
+ 	int i;
+ 	struct planet_spacket *pl;
+ 	struct planet *plan;
+ 	struct planet_loc_spacket *pll;
+ 
+ 	clientVPlanetCount = 0;
+ 
+ 	for (i=0, pl=clientPlanets, plan=planets, pll=clientPlanetLocs; 
+ 	     i<MAXPLANETS;
+ 	     i++, pl++, plan++, pll++) {
+ 	    sndPlanet(pl, plan, UPDT_ALL);
+ 	    sndPlanetLoc(pll, plan);
+ 	}
+ 
+ 	sendVPlanets();
+ 
+     }
+ 
+     /*  updateMessages(); */
+     {
+ 	int i;
+ 	struct message *cur;
+ 	struct mesg_spacket msg;
+ 
+ 	for (i=msgCurrent; i!=(mctl->mc_current+1) % MAXMESSAGE; i=(i+1) % MAXMESSAGE) {
+ 	    if (i>=MAXMESSAGE) i=0;
+ 	    cur= &messages[i];
+ 
+ 	    if (cur->m_flags & MVALID) {
+ 		if(send_short && (cur->m_from == 255)) {
+ 		    /* Test if possible to send with SP_S_WARNING */
+ 		    if (updtMessageSMessage(cur)) {
+ 			msgCurrent=(msgCurrent+1) % MAXMESSAGE;
+ 			continue;
+ 		    }
+ 		}
+ 		updtMessage(&msg, cur);
+ 	    }
+ 	    msgCurrent=(msgCurrent+1) % MAXMESSAGE;
+ 	}
+     }
+ 
+     updatePlayerStats();
+ 
+     /* flushSockBuf() */
+     {
+ 	char buf[256];
+ 	int i;
+ 
+ 	i = addSequence(buf, &sequence);
+ 	sendClientPacket(buf);
+     }
+ 
+     repCount++;
+ }
+ 
+ int
+ main(int argc, char *argv[])
+ {
+ 
+     srandom(time(NULL));
+ 
+     getpath();
+     openmem(0);
+     readsysdefaults();
+ 
+     if ((packetsFile = fopen(RECORDFILE,"wb"))==NULL) {
+ 	ERROR(1,("Could not open recording file.\n"));
+ 	exit(1);
+     } 
+ 
+     initSPackets();
+     {
+ 	int i;
+ 
+ 	for (i=0; i<MAXPLAYER; i++)
+ 	{
+ 	    clientSelfs[i].pnum=-1;
+ 	    clientSelfShips[i].damage=-1;
+ 	}
+     }
+ 
+     send_short=2;
+ 
+     /* HACK..  Some of the sockets code is hard linked to me->...
+      * create a bogus player struct to prevent seg faults */
+     me = &cambot_me;
+     MZERO(me, sizeof(struct player));
+     me->p_timerdelay = 10/PERSEC;
+ 
+     /* Add setup packets now */
+     sendFeature(&Many_Self_F);
+ 
+     SIGNAL(SIGALRM, cb_updt);
+     SIGNAL(SIGINT, cleanup);
+     SIGNAL(SIGTERM, cleanup);
+ 
+     udt.it_interval.tv_sec = 0;        /* Robots move PERSEC times/sec */
+     udt.it_interval.tv_usec = 1000000 / PERSEC;
+ 
+     udt.it_value.tv_sec = 1;
+     udt.it_value.tv_usec = 0;
+     if (setitimer(ITIMER_REAL, &udt, 0) < 0) {
+ 	perror("setitimer");
+ 	exit(1);
+     }
+ 
+     /* allows robots to be forked by the daemon -- Evil ultrix bullshit */
+     SIGSETMASK(0);
+ 
+     while (1) {
+         PAUSE(SIGALRM);
+     }
+ }
+ 
+ /*  Hey Emacs!
+  * Local Variables:
+  * c-file-style:"bsd"
+  * End:
+  */
*** ntserv/ChangeLog.orig	Fri Oct  3 23:12:35 1997
--- ntserv/ChangeLog	Sat Jan 31 14:55:13 1998
***************
*** 0 ****
--- 1,63 ----
+ Sat Jan 31 14:02:12 1998  Kevin Oconnor  <koconnor@kerosene.eng.buffalo.edu>
+ 
+ 	* packets.h (SP2SHORTVERSION): Changed macro SHORTVERSION to
+ 	SP2SHORTVERSION.  ShortVersion alone is not descriptive enough.
+ 
+ Sat Oct 25 03:13:54 1997  Kevin Oconnor  <koconnor@harrier.eng.buffalo.edu>
+ 
+ 	* genspkt.c (SupdateTorps): This function had a failsafe #ifdef
+  	block that checked if MAXPLAYER*MAXTORP wasn't a factor of 8.  The
+  	failsafe code was just a block copy of the rest of the function
+  	with a couple of simple changes.  I reimplemented this failsafe by
+  	adding a few well placed #ifdef checks in the main routine.  This
+  	has the effect of reducing the code size by over 6K.  Also, this
+  	simplifies the code - making it easier to understand and
+  	maintain.
+ 
+ 	* genspkt.c: Changed sizes[] array definition from an unbounded
+ 	array, to a bounded array of size TOTAL_SPACKETS.  TOTAL_SPACKETS
+ 	is defined in packets.h.  This was done because sizes[] was moved
+ 	to genspkt.c, and socket.c needed to know the size of the array
+ 	at compile time.  This is a temporary solution, IMO the sizes[]
+ 	array should be phased out completely..
+ 
+ Sun Oct 12 19:08:11 1997  Kevin Oconnor  <koconnor@thunderbolt.eng.buffalo.edu>
+ 
+ 	* genspkt.c: Removed 'register' declaration from variables in
+  	non-critical routines - IE. all of genspkt.c.  Perhaps I'm missing
+  	the "big picture", but the server is compiled by default with -O
+  	on.  The compiler will automaticly combine certain variables,
+  	remove certain variables, and make other variables into registers.
+   	Blindly declaring non-critical loop variables as register is at
+  	best irrelevant, and at worst hampering performance.  Also, some
+  	of the routines declared 10 or more variables as register.  This
+  	is silly, many architectures dont even have that many registers!
+ 
+ Fri Oct  3 18:06:49 1997  Kevin Oconnor  <koconnor@heptane.eng.buffalo.edu>
+ 
+ 	* socket.c: Removed #ifdef SHORT_PACKETS from code (Making
+  	Short_packets a permanent 'feature').
+ 	Parsed source code through GNU Emacs c-mode auto-indent.  Fixed up
+  	many #ifdef/#else/#endif directives to make emacs happy.
+ 	Broke many UpdateXXX functions into multiple parts.  The UpdateX()
+  	functions determine which data is nedeed by the client, and then
+  	calls functions sndX() to generate the actual server packets.  The
+  	sndX() routines determine if the information has changed in the
+  	'eyes' of the client, and calls sendClientPacket() to send the
+  	actual data when neccessary.
+ 	Changed updatePlanet() to send 0 for armies/flags/owner when
+  	planet is no longer seen.  Done for uniformality, and it 'makes
+  	sense'.
+ 	Broke socket.c into two files, socket.c which will
+  	create,maintain,and send data over the sockets, and genspkt.c
+  	which will generate the actual server packets.  Reason - socket.c
+  	was getting too large (> 150K).
+ 	(updateClient): Moved the resetting of mustUpdate[i] to
+  	updatePhasers() in genspkt.c - It has the same effect there, and
+  	allows mustUpdate to be declared locally in genspkt.c.
+ 	(forceUpdate): Moved most of the code in this function to new
+  	function in genspkt.c - clearSPackets.
+ 
+ 	* genspkt.c (updateMessages): Moved mysterious call to
+  	update_sys_defaults in updateMessages to a more appropriate
+  	location - updateClient in socket.c.
*** ntserv/packets.h.orig	Mon Sep 15 13:13:40 1997
--- ntserv/packets.h	Thu Feb  5 23:38:10 1998
***************
*** 91,97 ****
  
  /* variable length packets */
  #define VPLAYER_SIZE    4
! #define SHORTVERSION    11      /* other number blocks, like UDP Version */
  #define OLDSHORTVERSION 10      /* S_P2 */
  #endif
  
--- 91,98 ----
  
  /* variable length packets */
  #define VPLAYER_SIZE    4
! #define TOTAL_SPACKETS  62
! #define SP2SHORTVERSION 11      /* other number blocks, like UDP Version */
  #define OLDSHORTVERSION 10      /* S_P2 */
  #endif
  
***************
*** 178,187 ****
  
  #define SOCKVERSION 	4
  #define UDPVERSION	10		/* changing this blocks other versions*/
- struct packet_handler {
-     int size;
-     int (*handler)();
- };
  
  /*
   * These are server --> client packets
--- 179,184 ----
***************
*** 472,478 ****
  
  struct sequence_spacket {	/* UDP */
      char type;		/* SP_SEQUENCE */
!     char pad1;
      u_short sequence;
  };
  
--- 469,475 ----
  
  struct sequence_spacket {	/* UDP */
      char type;		/* SP_SEQUENCE */
!     u_char flag8;
      u_short sequence;
  };
  
*** manifest.orig	Thu Feb  5 23:13:22 1998
--- manifest	Thu Feb  5 23:53:54 1998
***************
*** 302,304 ****
--- 302,307 ----
  Server/xsg/x11window.c
  Server/xsg/xsg_defs.h
  Server/pwstats.pl
+ Server/ntserv/genspkt.c
+ Server/tools/cambot.c
+ Server/ntserv/ChangeLog
*** tools/Makefile.orig	Fri Feb  6 00:04:58 1998
--- tools/Makefile	Fri Feb  6 00:00:12 1998
***************
*** 9,15 ****
  
  # this is for revised ntserv/struct.h
  
! CFLAGS = $(OPT) $(EXTRAINCS) $(DIRS) $(FLAGS)
  
  LIBS = $(EXTRALIBS)
  
--- 9,15 ----
  
  # this is for revised ntserv/struct.h
  
! CFLAGS = $(EXTRAINCS) $(DIRS) $(FLAGS)
  
  LIBS = $(EXTRALIBS)
  
***************
*** 30,40 ****
         xtkill.c keyman.c ../ntserv/getpath.c ../ntserv/data.c \
         ../ntserv/distress.c getship.c update.c openmem.c  \
         convert.c conq_vert.c ../ntserv/slotmaint.c $(RANDOMC) \
!        sortdb.c
  
  EXECS =	loadchecker mess message newscores planets players scores \
          setgalaxy showgalaxy stat trimscores watchmes xtkill \
!         mergescores keyman updated fun conq_vert convert sortdb
  
  all: $(PMAKE) $(EXECS)
  
--- 30,40 ----
         xtkill.c keyman.c ../ntserv/getpath.c ../ntserv/data.c \
         ../ntserv/distress.c getship.c update.c openmem.c  \
         convert.c conq_vert.c ../ntserv/slotmaint.c $(RANDOMC) \
!        sortdb.c ../robots/roboshar.c ../ntserv/smessage.c
  
  EXECS =	loadchecker mess message newscores planets players scores \
          setgalaxy showgalaxy stat trimscores watchmes xtkill \
!         mergescores keyman updated fun conq_vert convert sortdb cambot
  
  all: $(PMAKE) $(EXECS)
  
***************
*** 66,72 ****
--- 66,79 ----
  	$(INSTALL) $(INSTALLOPTS) fun $(LIBDIR)/tools/fun
  	$(INSTALL) $(INSTALLOPTS) sortdb $(LIBDIR)/tools/sortdb
  	$(INSTALL) $(INSTALLOPTS) updated $(LIBDIR)/updated
+ 	$(INSTALL) $(INSTALLOPTS) cambot $(LIBDIR)/cambot
  
+ cb_sock.o: packets.h ../ntserv/socket.c
+ #	$(CC) -o ./cb_sock.o -g $(CFLAGS) -DCAMBOT -c ../ntserv/socket.c
+ 
+ cambot: cambot.o $(M_OBJS) $(GETPATH)
+ 	$(CC) -o $@ $(CFLAGS) cambot.o ../ntserv/genspkt.o ../ntserv/sysdefaults.o ../ntserv/getship.o ../ntserv/warning.o ../ntserv/smessage.o ../ntserv/distress.o $(M_OBJS) getpath.o
+ 
  sortdb: sortdb.c struct.h defs.h
  	$(CC) -o $@ $(CFLAGS) sortdb.c
  
*** ntserv/Makefile.orig	Fri Feb  6 00:05:19 1998
--- ntserv/Makefile	Thu Feb  5 23:59:43 1998
***************
*** 11,17 ****
  R_OBJS =    cluecheck.o  coup.o  data.o  death.o  detonate.o  enter.o \
  	    findslot.o  getentry.o  getname.o  getship.o  input.o \
  	    interface.o  main.o  orbit.o  phaser.o  plasma.o  redraw.o \
! 	    reserved.o  sintab.o  socket.o  smessage.o  startrobot.o \
  	    sysdefaults.o  timecheck.o  torp.o  util.o  warning.o \
  	    $(RSA_OBJS)  ping.o $(RANDOMO) getpath.o $(STRDUPO) features.o \
  	    distress.o transwarp.o gencmds.o ntscmds.o openmem.o feature.o \
--- 11,17 ----
  R_OBJS =    cluecheck.o  coup.o  data.o  death.o  detonate.o  enter.o \
  	    findslot.o  getentry.o  getname.o  getship.o  input.o \
  	    interface.o  main.o  orbit.o  phaser.o  plasma.o  redraw.o \
! 	    reserved.o  sintab.o  socket.o  genspkt.o  smessage.o  startrobot.o \
  	    sysdefaults.o  timecheck.o  torp.o  util.o  warning.o \
  	    $(RSA_OBJS)  ping.o $(RANDOMO) getpath.o $(STRDUPO) features.o \
  	    distress.o transwarp.o gencmds.o ntscmds.o openmem.o feature.o \
***************
*** 29,35 ****
  R_FILES =   cluecheck.c coup.c  data.c  death.c  detonate.c  enter.c \
  	    findslot.c  getentry.c  getname.c  getship.c  input.c \
  	    interface.c  main.c  orbit.c  phaser.c  plasma.c \
! 	    redraw.c  reserved.c  sintab.c  socket.c  smessage.c \
  	    startrobot.c  timecheck.c  torp.c  util.c  warning.c \
  	    $(RANDOMC)  ping.c getpath.c $(STRDUPC) $(RSA_SRC) features.c \
  	    distress.c transwarp.c gencmds.c ntscmds.c openmem.c feature.c \
--- 29,35 ----
  R_FILES =   cluecheck.c coup.c  data.c  death.c  detonate.c  enter.c \
  	    findslot.c  getentry.c  getname.c  getship.c  input.c \
  	    interface.c  main.c  orbit.c  phaser.c  plasma.c \
! 	    redraw.c  reserved.c  sintab.c  socket.c  genspkt.c  smessage.c \
  	    startrobot.c  timecheck.c  torp.c  util.c  warning.c \
  	    $(RANDOMC)  ping.c getpath.c $(STRDUPC) $(RSA_SRC) features.c \
  	    distress.c transwarp.c gencmds.c ntscmds.c openmem.c feature.c \
+
++ Vanilla-l Mailing List ++
To unsubscribe: send "unsubscribe vanilla-l" to majordomo@real-time.com
For more information: http://archives.real-time.com