Patch to let a client record a game ---- Newsgroups: rec.games.netrek Date: Sun, 7 Jun 1992 21:20:59 -0400 From: "Julian L. Ho" Subject: Flight Recorder Here are patches that give the netrek client the ability to record a game. The patches are from the UDP-ized client used here at CMU... but they very simple and should be easy to apply by hand if you aren't using UDP. I've not done any recent work on the player, but I can mail people what I have. ensign *** data.c.old Sun Jun 7 20:51:59 1992 --- data.c Sun Jun 7 20:51:59 1992 *************** *** 77,82 **** --- 77,83 ---- int udpClientSend=1; /* UDP: send packets with simple UDP */ int udpClientRecv=1; /* UDP: receive with simple UDP */ int udpSequenceChk=1; /* UDP: check sequence numbers */ + FILE *recordFile; /* recorder: slurp packets here */ W_Icon stipple, clockpic, icon; *** data.h.old Sun Jun 7 20:52:00 1992 --- data.h Sun Jun 7 20:52:00 1992 *************** *** 105,110 **** --- 105,111 ---- extern int udpClientSend; /* UDP */ extern int udpClientRecv; /* UDP */ extern int udpSequenceChk; /* UDP */ + extern FILE *recordFile; /* recorder */ extern double Sin[], Cos[]; *** main.c.old Sun Jun 7 20:52:01 1992 --- main.c Sun Jun 7 20:52:01 1992 *************** *** 41,46 **** --- 41,47 ---- int reaper(); int passive=0; char *defaultsFile=NULL; + char *recordFileName=NULL; name = *argv++; argc--; *************** *** 82,87 **** --- 83,93 ---- argc--; argv++; break; + case 'f': + recordFileName = *argv; + argv++; + argc--; + break; case 'r': defaultsFile = *argv; argv++; *************** *** 93,98 **** --- 99,111 ---- break; } ptr++; + } + } + if (recordFileName != NULL) { + recordFile = fopen(recordFileName, "wb"); + if (recordFile == NULL) { + perror(recordFileName); + exit(1); } } initDefaults(defaultsFile); *** packets.h.old Sun Jun 7 20:52:02 1992 --- packets.h Sun Jun 7 20:52:02 1992 *************** *** 100,105 **** --- 100,124 ---- }; + #define RECORDPACKET(p) (\ + p==SP_MESSAGE ||\ + p==SP_PLAYER_INFO ||\ + p==SP_KILLS ||\ + p==SP_PLAYER ||\ + p==SP_YOU ||\ + p==SP_STATUS ||\ + p==SP_PLANET ||\ + p==SP_LOGIN ||\ + p==SP_FLAGS ||\ + p==SP_MASK ||\ + p==SP_PSTATUS ||\ + p==SP_BADVERSION ||\ + p==SP_HOSTILE ||\ + p==SP_STATS ||\ + p==SP_PL_LOGIN ||\ + p==SP_RESERVED ||\ + p==SP_PLANET_LOC) + /* * These are server --> client packets */ *** socket.c.old Sun Jun 7 20:52:03 1992 --- socket.c Sun Jun 7 20:52:03 1992 *************** *** 562,570 **** } if (handlers[*bufptr].handler != NULL) { if (asock != udpSock || ! (!drop_flag || *bufptr == SP_SEQUENCE || *bufptr == SP_SC_SEQUENCE)) (*(handlers[*bufptr].handler))(bufptr); ! else UDPDIAG(("Ignored type %d\n", *bufptr)); } else { printf("Handler for packet %d not installed...\n", *bufptr); --- 562,577 ---- } if (handlers[*bufptr].handler != NULL) { if (asock != udpSock || ! (!drop_flag || *bufptr == SP_SEQUENCE || *bufptr == SP_SC_SEQUENCE)) { ! if (recordFile != NULL && RECORDPACKET(*bufptr)) ! if ((fwrite(bufptr, size, 1, recordFile) != 1) || ! (putc(*bufptr, recordFile) == EOF)) { ! perror("write: (recordFile)"); ! fclose(recordFile); ! recordFile = NULL; ! } (*(handlers[*bufptr].handler))(bufptr); ! } else UDPDIAG(("Ignored type %d\n", *bufptr)); } else { printf("Handler for packet %d not installed...\n", *bufptr);