/* Sample code to access Bolo's game infomation packet interface */ /* (C) 1993 Stuart Cheshire /* Unix C file -- tabs are 8 spaces -- compile with gcc for best results */ /* run with "a.out " to listen on a UDP port for games starting */ /* run with "a.out " to ping a running Bolo game and then wait for replies. */ /* run with "a.out to locate ALL Bolo games running within a particular IP broadcast domain. */ /* There is no reliability here -- this is just to illustrate how to send and receive the packets. You may wish to do retransmissions and timeouts. */ #include #include #include #include #include #include /* Bolo uses little-endian byte ordering -- like the BBC micro's 6502 processor, 80x86 series, Acorn Risk Machine, and DEC computers, and unlike Macs and Suns. The following macro should convert to and from local byte ordering on any unix machine. I don't know a better way to do it, but a good compiler will optimize it out anyway. */ #define netshort(X) (htons(X) >> 8 | htons(X) << 8) /* Macs count time since Midnight, 1st Jan 1904. Unix counts from 1970. This value adjusts for the 66 years and 17 leap-days difference. */ #define TIME_ADJUST (((1970 - 1904) * 365 + 17) * 24 * 60 * 60) /* Also note the following two bugs in Bolo 0.99 and 0.99.1: 1. The GameID was intended to be simply an opaque identifier to distinguish games. Hence I did not make Bolo put the components in canonical network byte order, since IDs were not supposed to be disassembled, but just compared for equality or inequality. However, I changed my mind and decided that it is useful (or at least interesting) to know when and where a game started. So, for now, the game timestamp is in the wrong byte order. This will be fixed in a future version of Bolo. 2. The Mac system call "GetDateTime" returns the time in LOCAL time, not GMT. Bolo neglects to convert this time to GMT before sending it over the network, resulting in the game start time being given in local time for the Mac that started it. There is no way at present to convert this time to a real time, except if you happen to know what time zone the offending Mac is in. This will be fixed in a future version of Bolo. */ /* Convert Bolo's pascal string to C string so we can work with it easily */ static void PtoCStr(unsigned char *string) { int i, len = string[0]; for (i=0; i