From 26a5fb6d7c45dc1e3a800bd614ad1fe9ef572fe4 Mon Sep 17 00:00:00 2001 From: Bradley Bell Date: Fri, 3 Oct 2003 07:58:15 +0000 Subject: [PATCH] Make network architecture choosable from game menu, add support for UDP/IP on Mac OS X and Solaris --- ChangeLog | 11 ++ arch/dos/bak/ipx.c | 25 ++-- arch/dos/ipx.c | 43 +++---- arch/linux/Makefile.am | 9 +- arch/linux/include/ipx_lin.h | 22 ---- arch/linux/ipx_lin.c | 222 ----------------------------------- arch/linux/ipx_udp.c | 28 ++++- arch/linux/linuxnet.c | 63 +++++----- arch/linux/ukali.c | 4 +- arch/win32/winnet.c | 36 +++--- configure.ac | 26 +++- include/byteswap.h | 6 +- include/ipx.h | 35 ++++-- main/inferno.c | 45 +------ main/menu.c | 134 +++++++++++++++------ main/multi.c | 221 +++++++++++++++++----------------- 16 files changed, 378 insertions(+), 552 deletions(-) delete mode 100644 arch/linux/include/ipx_lin.h delete mode 100644 arch/linux/ipx_lin.c diff --git a/ChangeLog b/ChangeLog index 0bb3544a..cb86f157 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2003-10-03 Martin Schaffner + + * arch/dos/bak/ipx.c, arch/dos/ipx.c, arch/linux/Makefile.am, + arch/linux/include/ipx_lin.h, arch/linux/ipx_lin.c, + arch/linux/ipx_udp.c, arch/linux/linuxnet.c, arch/linux/ukali.c, + arch/win32/winnet.c, configure.ac, include/byteswap.h, + include/ipx.h, main/inferno.c, main/menu.c, main/multi.c, + main/multibot.c, main/network.c: Make network architecture + choosable from game menu, add support for UDP/IP on Mac OS X and + Solaris + 2003-10-02 Martin Schaffner * include/byteswap.h: added macros for coping with alignment diff --git a/arch/dos/bak/ipx.c b/arch/dos/bak/ipx.c index 8111453d..85483f63 100644 --- a/arch/dos/bak/ipx.c +++ b/arch/dos/bak/ipx.c @@ -1,4 +1,4 @@ -/* $Id: ipx.c,v 1.2 2003-10-03 03:37:43 btb Exp $ */ +/* $Id: ipx.c,v 1.3 2003-10-03 07:58:14 btb Exp $ */ /* THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO @@ -161,7 +161,7 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. */ #ifdef RCS -static char rcsid[] = "$Id: ipx.c,v 1.2 2003-10-03 03:37:43 btb Exp $"; +static char rcsid[] = "$Id: ipx.c,v 1.3 2003-10-03 07:58:14 btb Exp $"; #endif #ifdef __GNUC__ @@ -469,12 +469,7 @@ void ipx_close() //--------------------------------------------------------------- // Initializes all IPX internals. // If socket_number==0, then opens next available socket. -// Returns: 0 if successful. -// -1 if socket already open. -// -2 if socket table full. -// -3 if IPX not installed. -// -4 if couldn't allocate low dos memory -// -5 if error with getting internetwork address +// Returns one of the constants defined in include/ipx.h int ipx_init( int socket_number, int show_address ) { @@ -500,7 +495,7 @@ int ipx_init( int socket_number, int show_address ) dpmi_real_int386x( 0x2f, &rregs ); if ( (rregs.eax & 0xFF) != 0xFF ) { - return 3; + return IPX_NOT_INSTALLED; } ipx_vector_offset = rregs.edi & 0xFFFF; ipx_vector_segment = rregs.es; @@ -519,7 +514,7 @@ int ipx_init( int socket_number, int show_address ) if ( rregs.eax & 0xFF ) { //mprintf( (1, "IPX error opening channel %d\n", socket_number-IPX_DEFAULT_SOCKET )); - return -2; + return IPX_SOCKET_TABLE_FULL; } ipx_installed = 1; @@ -528,7 +523,7 @@ int ipx_init( int socket_number, int show_address ) ipx_real_buffer = dpmi_get_temp_low_buffer( 1024 ); // 1k block if ( ipx_real_buffer == NULL ) { //printf( "Error allocation realmode memory\n" ); - return -4; + return IPX_NO_LOW_DOS_MEM; } memset(&rregs,0,sizeof(dpmi_real_regs)); @@ -539,7 +534,7 @@ int ipx_init( int socket_number, int show_address ) if ( rregs.eax & 0xFF ) { //printf( "Error getting internetwork address!\n" ); - return -2; + return IPX_SOCKET_TABLE_FULL; } memcpy( &ipx_network, ipx_real_buffer, 4 ); @@ -558,12 +553,12 @@ int ipx_init( int socket_number, int show_address ) packets = dpmi_real_malloc( sizeof(ipx_packet)*ipx_num_packets, &ipx_packets_selector ); if ( packets == NULL ) { //printf( "Couldn't allocate real memory for %d packets\n", ipx_num_packets ); - return -4; + return IPX_NO_LOW_DOS_MEM; } #if 0 /* adb: not needed, fails with cwsdpmi */ if (!dpmi_lock_region( packets, sizeof(ipx_packet)*ipx_num_packets )) { //printf( "Couldn't lock real memory for %d packets\n", ipx_num_packets ); - return -4; + return IPX_NO_LOW_DOS_MEM; } #endif memset( packets, 0, sizeof(ipx_packet)*ipx_num_packets ); @@ -604,7 +599,7 @@ outpackets = dpmi_real_malloc( sizeof(ipx_packet)*ipx_num_packets, &ipx_packets_ //end this section replace - Kevin Bently - return 0; + return IPX_INIT_OK; } void ipx_send_packet_data( ubyte * data, int datasize, ubyte *network, ubyte *address, ubyte *immediate_address ) diff --git a/arch/dos/ipx.c b/arch/dos/ipx.c index ed2a9dbc..d6ec87f0 100644 --- a/arch/dos/ipx.c +++ b/arch/dos/ipx.c @@ -1,4 +1,4 @@ -/* $Id: ipx.c,v 1.5 2003-10-03 03:37:43 btb Exp $ */ +/* $Id: ipx.c,v 1.6 2003-10-03 07:58:14 btb Exp $ */ /* THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO @@ -14,7 +14,7 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. /* * - * Routines for IPX communications. + * Routines for IPX communications, copied from d1x * * Old Log: * Revision 2.10 1995/03/29 17:27:55 john @@ -433,7 +433,7 @@ static void ipx_dos_get_local_target( ubyte * server, ubyte * node, ubyte * loca memcpy( local_target, info->local_target, 6 ); } -static void ipx_dos_close() +static void ipx_close() { dpmi_real_regs rregs; if ( ipx_installed ) { @@ -448,18 +448,7 @@ static void ipx_dos_close() } } - -//--------------------------------------------------------------- -// Initializes all IPX internals. -// If socket_number==0, then opens next available socket. -// Returns: 0 if successful. -// -1 if socket already open. -// -2 if socket table full. -// -3 if IPX not installed. -// -4 if couldn't allocate low dos memory -// -5 if error with getting internetwork address - -static int ipx_dos_init( int socket_number ) +static int ipx_init(int socket_number) { int show_address=0; dpmi_real_regs rregs; @@ -484,7 +473,7 @@ static int ipx_dos_init( int socket_number ) dpmi_real_int386x( 0x2f, &rregs ); if ( (rregs.eax & 0xFF) != 0xFF ) { - return 3; + return IPX_NOT_INSTALLED; } ipx_vector_offset = rregs.edi & 0xFFFF; ipx_vector_segment = rregs.es; @@ -503,7 +492,7 @@ static int ipx_dos_init( int socket_number ) if ( rregs.eax & 0xFF ) { //mprintf( (1, "IPX error opening channel %d\n", socket_number-IPX_DEFAULT_SOCKET )); - return -2; + return IPX_SOCKET_TABLE_FULL; } ipx_installed = 1; @@ -512,7 +501,7 @@ static int ipx_dos_init( int socket_number ) ipx_real_buffer = dpmi_get_temp_low_buffer( 1024 ); // 1k block if ( ipx_real_buffer == NULL ) { //printf( "Error allocation realmode memory\n" ); - return -4; + return IPX_NO_LOW_DOS_MEM; } memset(&rregs,0,sizeof(dpmi_real_regs)); @@ -523,7 +512,7 @@ static int ipx_dos_init( int socket_number ) if ( rregs.eax & 0xFF ) { //printf( "Error getting internetwork address!\n" ); - return -2; + return IPX_SOCKET_TABLE_FULL; } /* memcpy( &ipx_network, ipx_real_buffer, 4 ); @@ -540,12 +529,12 @@ static int ipx_dos_init( int socket_number ) packets = dpmi_real_malloc( sizeof(ipx_packet)*ipx_num_packets, &ipx_packets_selector ); if ( packets == NULL ) { //printf( "Couldn't allocate real memory for %d packets\n", ipx_num_packets ); - return -4; + return IPX_NO_LOW_DOS_MEM; } #if 0 /* adb: not needed, fails with cwsdpmi */ if (!dpmi_lock_region( packets, sizeof(ipx_packet)*ipx_num_packets )) { //printf( "Couldn't lock real memory for %d packets\n", ipx_num_packets ); - return -4; + return IPX_NO_LOW_DOS_MEM; } #endif memset( packets, 0, sizeof(ipx_packet)*ipx_num_packets ); @@ -571,7 +560,7 @@ static int ipx_dos_init( int socket_number ) // memcpy( packets[0].ipx.destination.network_id, &ipx_network, 4 ); memset( packets[0].ipx.destination.network_id, 0, 4 ); - return 0; + return IPX_INIT_OK; } static void ipx_dos_send_packet_data( ubyte * data, int datasize, ubyte *network, ubyte *address, ubyte *immediate_address ) @@ -682,8 +671,8 @@ static void ipx_dos_send_packet_data( ubyte * data, int datasize, ubyte *network struct ipx_driver ipx_dos = { // NULL, - ipx_dos_init, - ipx_dos_close, + ipx_init, + ipx_close, NULL, NULL, NULL, @@ -694,9 +683,11 @@ struct ipx_driver ipx_dos = { ipx_dos_send_packet_data }; -struct ipx_driver * arch_ipx_set_driver(char *arg) +void arch_ipx_set_driver(int ipx_driver) { - return &ipx_dos; + driver = &ipx_dos; + if (ipx_driver != IPX_DRIVER_IPX) + Warning("Unknown network driver! Defaulting to real IPX"); } diff --git a/arch/linux/Makefile.am b/arch/linux/Makefile.am index ea61115f..ac2f20db 100644 --- a/arch/linux/Makefile.am +++ b/arch/linux/Makefile.am @@ -5,17 +5,20 @@ noinst_LIBRARIES = libarch_linux.a INCLUDES = -I$(top_srcdir)/arch/include -I$(top_srcdir)/include -I$(top_srcdir)/main -I$(srcdir)/include if USE_NETWORK -NETWORK_SRCS = ipx_bsd.c ipx_kali.c ipx_lin.c ipx_udp.c linuxnet.c ukali.c +NETWORK_SRCS = ipx_kali.c ipx_udp.c linuxnet.c ukali.c +if USE_NATIVE_IPX +IPX_SRCS = ipx_bsd.c +endif endif if USE_LINUX_JOY JOYSTICK_SRCS = joystick.c joydefs.c endif -libarch_linux_a_SOURCES = ${NETWORK_SRCS} ${JOYSTICK_SRCS} findfile.c init.c +libarch_linux_a_SOURCES = ${NETWORK_SRCS} ${IPX_SRCS} ${JOYSTICK_SRCS} findfile.c init.c EXTRA_libarch_linux_a_SOURCES = \ -ipx_bsd.c ipx_kali.c ipx_lin.c ipx_udp.c linuxnet.c ukali.c \ +ipx_bsd.c ipx_kali.c ipx_udp.c linuxnet.c ukali.c \ joydefs.c joystick.c EXTRA_DIST = ${EXTRA_SUBDIRS} \ diff --git a/arch/linux/include/ipx_lin.h b/arch/linux/include/ipx_lin.h deleted file mode 100644 index e9b064bc..00000000 --- a/arch/linux/include/ipx_lin.h +++ /dev/null @@ -1,22 +0,0 @@ -/* $Id: ipx_lin.h,v 1.4 2003-03-13 00:20:21 btb Exp $ */ -/* - * - * FIXME: add description - * - */ - -#ifndef IPX_LINUX_H_ -#define IPX_LINUX_H_ - -#include -#include "ipx_hlpr.h" - -int ipx_linux_GetMyAddress(void); -int ipx_linux_OpenSocket(ipx_socket_t *sk, int port); -void ipx_linux_CloseSocket(ipx_socket_t *mysock); -int ipx_linux_SendPacket(ipx_socket_t *mysock, IPXPacket_t *IPXHeader, - u_char *data, int dataLen); -int ipx_linux_ReceivePacket(ipx_socket_t *s, char *buffer, int bufsize, - struct ipx_recv_data *rd); - -#endif diff --git a/arch/linux/ipx_lin.c b/arch/linux/ipx_lin.c deleted file mode 100644 index c1cb8465..00000000 --- a/arch/linux/ipx_lin.c +++ /dev/null @@ -1,222 +0,0 @@ -/* $Id: ipx_lin.c,v 1.5 2003-03-13 00:20:21 btb Exp $ */ -/* - * - * Linux IPX - * - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include -#include - -#ifdef HAVE_NETIPX_IPX_H -#include -#else -# include -# ifndef IPX_TYPE -# define IPX_TYPE 1 -# endif -#endif - -#include -#include -#include -#include "pstypes.h" - -#include "ipx_ld.h" -#include "ipx_hlpr.h" -#include "ipx_lin.h" - -extern unsigned char ipx_MyAddress[10]; - -int -ipx_linux_GetMyAddress( void ) -{ - int sock; - struct sockaddr_ipx ipxs; - struct sockaddr_ipx ipxs2; - int len; - int i; - - sock=socket(AF_IPX,SOCK_DGRAM,PF_IPX); - if(sock==-1) - { - n_printf("IPX: could not open socket in GetMyAddress\n"); - return(-1); - } - - /* bind this socket to network 0 */ - ipxs.sipx_family=AF_IPX; -#ifdef IPX_MANUAL_ADDRESS - memcpy(&ipxs.sipx_network, ipx_MyAddress, 4); -#else - ipxs.sipx_network=0; -#endif - ipxs.sipx_port=0; - - if(bind(sock,(struct sockaddr *)&ipxs,sizeof(ipxs))==-1) - { - n_printf("IPX: could bind to network 0 in GetMyAddress\n"); - close( sock ); - return(-1); - } - - len = sizeof(ipxs2); - if (getsockname(sock,(struct sockaddr *)&ipxs2,&len) < 0) { - n_printf("IPX: could not get socket name in GetMyAddress\n"); - close( sock ); - return(-1); - } - - memcpy(ipx_MyAddress, &ipxs2.sipx_network, 4); - for (i = 0; i < 6; i++) { - ipx_MyAddress[4+i] = ipxs2.sipx_node[i]; - } - close( sock ); - return(0); -} - -int -ipx_linux_OpenSocket(ipx_socket_t *sk, int port) -{ - int sock; /* sock here means Linux socket handle */ - int opt; - struct sockaddr_ipx ipxs; - int len; - struct sockaddr_ipx ipxs2; - - /* DANG_FIXTHIS - kludge to support broken linux IPX stack */ - /* need to convert dynamic socket open into a real socket number */ -/* if (port == 0) { - n_printf("IPX: using socket %x\n", nextDynamicSocket); - port = nextDynamicSocket++; - } -*/ - /* do a socket call, then bind to this port */ - sock = socket(AF_IPX, SOCK_DGRAM, PF_IPX); - if (sock == -1) { - n_printf("IPX: could not open IPX socket.\n"); - return -1; - } - -#ifdef DOSEMU - opt = 1; - /* turn on socket debugging */ - if (d.network) { - enter_priv_on(); - if (setsockopt(sock, SOL_SOCKET, SO_DEBUG, &opt, sizeof(opt)) == -1) { - leave_priv_setting(); - n_printf("IPX: could not set socket option for debugging.\n"); - return -1; - } - leave_priv_setting(); - } -#endif - opt = 1; - /* Permit broadcast output */ - enter_priv_on(); - if (setsockopt(sock, SOL_SOCKET, SO_BROADCAST, - &opt, sizeof(opt)) == -1) { - leave_priv_setting(); - n_printf("IPX: could not set socket option for broadcast.\n"); - return -1; - } -#ifdef DOSEMU - /* allow setting the type field in the IPX header */ - opt = 1; -#if 0 /* this seems to be wrong: IPX_TYPE can only be set on level SOL_IPX */ - if (setsockopt(sock, SOL_SOCKET, IPX_TYPE, &opt, sizeof(opt)) == -1) { -#else - /* the socket _is_ an IPX socket, hence it first passes ipx_setsockopt() - * in file linux/net/ipx/af_ipx.c. This one handles SOL_IPX itself and - * passes SOL_SOCKET-levels down to sock_setsockopt(). - * Hence I guess the below is correct (can somebody please verify this?) - * -- Hans, June 14 1997 - */ - if (setsockopt(sock, SOL_IPX, IPX_TYPE, &opt, sizeof(opt)) == -1) { -#endif - leave_priv_setting(); - n_printf("IPX: could not set socket option for type.\n"); - return -1; - } -#endif - ipxs.sipx_family = AF_IPX; - ipxs.sipx_network = *((unsigned int *)&ipx_MyAddress[0]); -/* ipxs.sipx_network = htonl(MyNetwork); */ - bzero(ipxs.sipx_node, 6); /* Please fill in my node name */ - ipxs.sipx_port = htons(port); - - /* now bind to this port */ - if (bind(sock, (struct sockaddr *) &ipxs, sizeof(ipxs)) == -1) { - n_printf("IPX: could not bind socket to address\n"); - close( sock ); - leave_priv_setting(); - return -1; - } - - if( port==0 ) { - len = sizeof(ipxs2); - if (getsockname(sock,(struct sockaddr *)&ipxs2,&len) < 0) { - n_printf("IPX: could not get socket name in IPXOpenSocket\n"); - close( sock ); - leave_priv_setting(); - return -1; - } else { - port = htons(ipxs2.sipx_port); - n_printf("IPX: opened dynamic socket %04x\n", port); - } - } - leave_priv_setting(); - sk->fd = sock; - sk->socket = port; - return 0; -} - -void ipx_linux_CloseSocket(ipx_socket_t *mysock) { - /* now close the file descriptor for the socket, and free it */ - n_printf("IPX: closing file descriptor on socket %x\n", mysock->socket); - close(mysock->fd); -} - -int ipx_linux_SendPacket(ipx_socket_t *mysock, IPXPacket_t *IPXHeader, - u_char *data, int dataLen) { - struct sockaddr_ipx ipxs; - - ipxs.sipx_family = AF_IPX; - /* get destination address from IPX packet header */ - memcpy(&ipxs.sipx_network, IPXHeader->Destination.Network, 4); - /* if destination address is 0, then send to my net */ - if (ipxs.sipx_network == 0) { - ipxs.sipx_network = *((unsigned int *)&ipx_MyAddress[0]); -/* ipxs.sipx_network = htonl(MyNetwork); */ - } - memcpy(&ipxs.sipx_node, IPXHeader->Destination.Node, 6); - memcpy(&ipxs.sipx_port, IPXHeader->Destination.Socket, 2); - ipxs.sipx_type = IPXHeader->PacketType; - /* ipxs.sipx_port=htons(0x452); */ - return sendto(mysock->fd, data, dataLen, 0, - (struct sockaddr *) &ipxs, sizeof(ipxs)); -} - -int ipx_linux_ReceivePacket(ipx_socket_t *s, char *buffer, int bufsize, - struct ipx_recv_data *rd) { - int sz, size; - struct sockaddr_ipx ipxs; - - sz = sizeof(ipxs); - if ((size = recvfrom(s->fd, buffer, bufsize, 0, - (struct sockaddr *) &ipxs, &sz)) <= 0) - return size; - memcpy(rd->src_network, &ipxs.sipx_network, 4); - memcpy(rd->src_node, ipxs.sipx_node, 6); - rd->src_socket = ipxs.sipx_port; - rd->dst_socket = s->socket; - rd->pkt_type = ipxs.sipx_type; - - return size; -} diff --git a/arch/linux/ipx_udp.c b/arch/linux/ipx_udp.c index d04fe5d9..6b234391 100644 --- a/arch/linux/ipx_udp.c +++ b/arch/linux/ipx_udp.c @@ -1,4 +1,4 @@ -/* $Id: ipx_udp.c,v 1.6 2003-03-13 00:20:21 btb Exp $ */ +/* $Id: ipx_udp.c,v 1.7 2003-10-03 07:58:14 btb Exp $ */ /* * * IPX driver for native Linux TCP/IP networking (UDP implementation) @@ -28,6 +28,11 @@ * -------------- * No network server software is needed, neither KIX nor KaliNIX. * + * NOTE: with the change to allow the user to choose the network + * driver from the game menu, the following is not anymore precise: + * the command line argument "-udp" is only necessary to supply udp + * options! + * * Add command line argument "-udp". In default operation D1X will send * broadcasts too all the local interfaces found. But you may also use * additional parameter specified after "-udp" to modify the default @@ -73,8 +78,12 @@ #include #include #include -#include #include +#include +#ifdef __sun__ +# include +#endif +#include #include #include "ipx_drv.h" @@ -229,8 +238,16 @@ struct sockaddr_in *sinp,*sinmp; FAIL("ioctl(udp,\"%s\",SIOCGIF{DST/BRD}ADDR) error: %m",ifconf.ifc_req[i].ifr_name); } - sinp =(struct sockaddr_in *)&ifconf.ifc_req[i].ifr_broadaddr; - sinmp=(struct sockaddr_in *)&ifconf.ifc_req[i].ifr_netmask ; + sinp = (struct sockaddr_in *)&ifconf.ifc_req[i].ifr_broadaddr; +#if 0 // old, not portable code + sinmp = (struct sockaddr_in *)&ifconf.ifc_req[i].ifr_netmask; +#else // portable code + if (ioctl(sock, SIOCGIFNETMASK, ifconf.ifc_req+i)) { + close(sock); + FAIL("ioctl(udp,\"%s\",SIOCGIFNETMASK) error: %m", ifconf.ifc_req[i].ifr_name); + } + sinmp = (struct sockaddr_in *)&ifconf.ifc_req[i].ifr_addr; +#endif if (sinp->sin_family!=AF_INET || sinmp->sin_family!=AF_INET) continue; broads[j]=*sinp; broads[j].sin_port=UDP_BASEPORT; //FIXME: No possibility to override from cmdline @@ -551,6 +568,7 @@ static int ipx_udp_ReceivePacket(ipx_socket_t *s, char *outbuf, int outbufsize, } rd->dst_socket = s->socket; + // check if we already have sender of this packet in broadcast list for (i=0;i=masksnum) { if (addreq(fromaddr,broads[i])) break; @@ -561,7 +579,7 @@ static int ipx_udp_ReceivePacket(ipx_socket_t *s, char *outbuf, int outbufsize, ==(broads[i].sin_addr.s_addr & broadmasks[i].sin_addr.s_addr)) break; } } - if (i>=broadnum) { + if (i>=broadnum) { // we don't have sender of this packet in our broadcast list chkbroadsize(); broads[broadnum++]=fromaddr; fputs(MSGHDR "Adding host ",stdout); diff --git a/arch/linux/linuxnet.c b/arch/linux/linuxnet.c index e1a556ec..10b1bfaf 100644 --- a/arch/linux/linuxnet.c +++ b/arch/linux/linuxnet.c @@ -1,4 +1,4 @@ -/* $Id: linuxnet.c,v 1.9 2003-08-02 07:32:59 btb Exp $ */ +/* $Id: linuxnet.c,v 1.10 2003-10-03 07:58:14 btb Exp $ */ /* THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO @@ -14,7 +14,8 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. /* * - * Linux net + * Linux lower-level network code. + * implements functions declared in include/ipx.h * */ @@ -23,18 +24,24 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #endif #ifdef NETWORK + #include #include #include +#include #include #include #include /* for htons & co. */ #include "pstypes.h" #include "args.h" +#include "error.h" +#include "ipx.h" #include "ipx_drv.h" -#include "ipx_bsd.h" +#ifdef NATIVE_IPX +# include "ipx_bsd.h" +#endif //NATIVE_IPX #include "ipx_kali.h" #include "ipx_udp.h" //added 05/17/99 Matt Mueller - needed to redefine FD_* so that no asm is used @@ -67,8 +74,6 @@ user_address Ipx_users[MAX_USERS]; int Ipx_num_networks = 0; uint Ipx_networks[MAX_NETWORKS]; -void ipx_close(void); - int ipx_general_PacketReady(ipx_socket_t *s) { fd_set set; struct timeval tv; @@ -82,7 +87,7 @@ int ipx_general_PacketReady(ipx_socket_t *s) { return 0; } -struct ipx_driver *driver = &ipx_bsd; +struct ipx_driver *driver = &ipx_udp; ubyte * ipx_get_my_server_address() { @@ -94,31 +99,22 @@ ubyte * ipx_get_my_local_address() return (ubyte *)(ipx_MyAddress + 4); } -//--------------------------------------------------------------- -// Initializes all IPX internals. -// If socket_number==0, then opens next available socket. -// Returns: 0 if successful. -// -1 if socket already open. -// -2 if socket table full. -// -3 if IPX not installed. -// -4 if couldn't allocate low dos memory -// -5 if error with getting internetwork address -int ipx_init( int socket_number, int show_address ) +void arch_ipx_set_driver(int ipx_driver) +{ + switch(ipx_driver) { +#ifdef NATIVE_IPX + case IPX_DRIVER_IPX: driver = &ipx_bsd; break; +#endif //NATIVE_IPX + case IPX_DRIVER_KALI: driver = &ipx_kali; break; + case IPX_DRIVER_UDP: driver = &ipx_udp; break; + default: Int3(); + } +} + +int ipx_init(int socket_number) { int i; - if (FindArg("-kali")) { - printf("Using Kali for network games\n"); - driver = &ipx_kali; -//added on 12/20/98 by Jan Kratochvil for direct TCP/IP games - } else if (FindArg("-udp")) { - printf("Using native TCP/IP (UDP) for network games\n"); - driver = &ipx_udp; -//end this section addition - JK - } else { - printf("Using real IPX for network games\n"); - driver = &ipx_bsd; - } if ((i = FindArg("-ipxnetwork")) && Args[i + 1]) { unsigned long n = strtol(Args[i + 1], NULL, 16); ipx_MyAddress[0] = n >> 24; ipx_MyAddress[1] = (n >> 16) & 255; @@ -126,7 +122,7 @@ int ipx_init( int socket_number, int show_address ) printf("IPX: Using network %08x\n", (unsigned int)n); } if (driver->OpenSocket(&ipx_socket_data, socket_number)) { - return -3; + return IPX_NOT_INSTALLED; } driver->GetMyAddress(); memcpy(&ipx_network, ipx_MyAddress, 4); @@ -134,7 +130,7 @@ int ipx_init( int socket_number, int show_address ) memcpy( &Ipx_networks[Ipx_num_networks++], &ipx_network, 4 ); ipx_installed = 1; atexit(ipx_close); - return 0; + return IPX_INIT_OK; } void ipx_close() @@ -242,7 +238,12 @@ void ipx_send_internetwork_packet_data( ubyte * data, int datasize, ubyte * serv { ubyte local_address[6]; - if ( (*(uint *)server) != 0 ) { +#ifdef WORDS_NEED_ALIGNMENT + int zero = 0; + if (memcmp(server, &zero, 4)) { +#else // WORDS_NEED_ALIGNMENT + if ((*(uint *)server) != 0) { +#endif // WORDS_NEED_ALIGNMENT ipx_get_local_target( server, address, local_address ); ipx_send_packet_data( data, datasize, server, address, local_address ); } else { diff --git a/arch/linux/ukali.c b/arch/linux/ukali.c index f2def070..4b38e511 100644 --- a/arch/linux/ukali.c +++ b/arch/linux/ukali.c @@ -1,4 +1,4 @@ -/* $Id: ukali.c,v 1.5 2003-03-13 00:20:21 btb Exp $ */ +/* $Id: ukali.c,v 1.6 2003-10-03 07:58:14 btb Exp $ */ /* * * Kali support functions @@ -9,8 +9,8 @@ #include #endif -#include #include +#include #include #include #include diff --git a/arch/win32/winnet.c b/arch/win32/winnet.c index 5b4b4075..b8e05881 100644 --- a/arch/win32/winnet.c +++ b/arch/win32/winnet.c @@ -1,4 +1,4 @@ -/* $Id: winnet.c,v 1.5 2003-02-28 23:34:15 btb Exp $ */ +/* $Id: winnet.c,v 1.6 2003-10-03 07:58:14 btb Exp $ */ /* THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO @@ -14,7 +14,8 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. /* * - * Win32 net + * Win32 lower-level network code. + * implements functions declared in include/ipx.h * */ @@ -56,8 +57,6 @@ user_address Ipx_users[MAX_USERS]; int Ipx_num_networks = 0; uint Ipx_networks[MAX_NETWORKS]; -void ipx_close(void); - int ipx_general_PacketReady(ipx_socket_t *s) { fd_set set; struct timeval tv; @@ -83,16 +82,15 @@ ubyte * ipx_get_my_local_address() return (ubyte *)(ipx_MyAddress + 4); } -//--------------------------------------------------------------- -// Initializes all IPX internals. -// If socket_number==0, then opens next available socket. -// Returns: 0 if successful. -// -1 if socket already open. -// -2 if socket table full. -// -3 if IPX not installed. -// -4 if couldn't allocate low dos memory -// -5 if error with getting internetwork address -int ipx_init( int socket_number, int show_address ) +void arch_ipx_set_driver(int ipx_driver) +{ + if (ipx_driver != IPX_DRIVER_IPX) + Warning("Unknown network driver! Defaulting to real IPX"); + + driver = &ipx_win; +} + +int ipx_init(int socket_number) { int i; @@ -102,7 +100,7 @@ int ipx_init( int socket_number, int show_address ) wVersionRequested = MAKEWORD(2, 0); if (WSAStartup( wVersionRequested, &wsaData)) { - return -1; + return IPX_SOCKET_ALREADY_OPEN; } #if 0 @@ -110,12 +108,10 @@ int ipx_init( int socket_number, int show_address ) HIBYTE( wsaData.wVersion ) != 0 ) { /* We couldn't find a usable WinSock DLL. */ WSACleanup( ); - return -2; + return IPX_SOCKET_TABLE_FULL; } #endif - printf("Using real IPX for network games\n"); - driver = &ipx_win; if ((i = FindArg("-ipxnetwork")) && Args[i + 1]) { unsigned long n = strtol(Args[i + 1], NULL, 16); ipx_MyAddress[0] = (unsigned char)n >> 24; ipx_MyAddress[1] = (unsigned char)(n >> 16) & 255; @@ -123,7 +119,7 @@ int ipx_init( int socket_number, int show_address ) printf("IPX: Using network %08x\n", (int) n); } if (driver->OpenSocket(&ipx_socket_data, socket_number)) { - return -3; + return IPX_NOT_INSTALLED; } driver->GetMyAddress(); memcpy(&ipx_network, ipx_MyAddress, 4); @@ -132,7 +128,7 @@ int ipx_init( int socket_number, int show_address ) ipx_installed = 1; atexit(ipx_close); printf("ipx succesfully installed\n"); - return 0; + return IPX_INIT_OK; } void ipx_close() diff --git a/configure.ac b/configure.ac index 3ae6c56f..d92a5af4 100644 --- a/configure.ac +++ b/configure.ac @@ -269,16 +269,34 @@ dnl Check for network AC_ARG_ENABLE(network, [ --disable-network Do not build network/serial support ],,) if test x$enable_network != xno; then - if test x$MACOSX = xyes; then - AC_MSG_WARN([OS X detected. disabling network]) - enable_network="no"; - fi + case $host_os in + cygwin* | mingw* | msdos* | linux*) + enable_native_ipx="yes"; + ;; + *) + AC_MSG_WARN([d2x doesn't support native ipx on this host. disabling native ipx]) + enable_native_ipx="no"; + ;; + esac + case $host_os in + *solaris*) + AC_CHECK_LIB(socket, socket, LIBS="${LIBS} -lsocket", + [AC_MSG_ERROR(socket lib required for net support on solaris not found)]) + AC_CHECK_LIB(nsl, inet_addr, LIBS="${LIBS} -lnsl", + [AC_MSG_ERROR(nsl lib required for net support on solaris not found)]) + ;; + esac fi if test x$enable_network != xno; then + if test x$enable_native_ipx != xno; then + D2X_FEATURES="ipx ${D2X_FEATURES}" + AC_DEFINE(NATIVE_IPX,,[Define to use the IPX support of the OS]) + fi AC_DEFINE(NETWORK,,[Define if you want a network build]) D2X_FEATURES="network ${D2X_FEATURES}" fi AM_CONDITIONAL(USE_NETWORK, test x$enable_network != xno) +AM_CONDITIONAL(USE_NATIVE_IPX, test x$enable_native_ipx != xno) dnl Check for assembler AC_ARG_ENABLE(assembler, diff --git a/include/byteswap.h b/include/byteswap.h index 7622c90e..453199d9 100644 --- a/include/byteswap.h +++ b/include/byteswap.h @@ -1,4 +1,4 @@ -/* $Id: byteswap.h,v 1.8 2003-10-03 04:01:21 btb Exp $ */ +/* $Id: byteswap.h,v 1.9 2003-10-03 07:58:14 btb Exp $ */ /* THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO @@ -67,9 +67,9 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. memcpy((void *)&tmp, (void *)(s), 4); \ (ushort)(d) = INTEL_SHORT(tmp); } #define PUT_INTEL_INT(d, s) { uint tmp = INTEL_INT(s); \ - memcpy((void *)d, (void *)&tmp, 4);} + memcpy((void *)d, (void *)&tmp, 4); } #define PUT_INTEL_SHORT(d, s) { ushort tmp = INTEL_SHORT(s); \ - memcpy((void *)d, (void *)&tmp, 4);} + memcpy((void *)d, (void *)&tmp, 4); } #endif // ! WORDS_NEED_ALIGNMENT #endif // ! _BYTESWAP_H diff --git a/include/ipx.h b/include/ipx.h index a2056187..d1ef25b7 100644 --- a/include/ipx.h +++ b/include/ipx.h @@ -1,4 +1,4 @@ -/* $Id: ipx.h,v 1.5 2002-08-29 09:03:36 btb Exp $ */ +/* $Id: ipx.h,v 1.6 2003-10-03 07:58:14 btb Exp $ */ /* THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO @@ -13,7 +13,10 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. */ /* * - * Prototype for IPX communications. + * Prototypes for lower-level network routines. + * This file is called ipx.h and the prefix of these routines is "ipx_" + * because orignally IPX was the only network driver. + * * * Old Log: * Revision 2.6 1995/03/29 11:19:32 john @@ -104,16 +107,24 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #define IPX_DEFAULT_SOCKET 0x5130 #endif -//--------------------------------------------------------------- -// Initializes all IPX internals. -// If socket_number==0, then opens next available socket. -// Returns: 0 if successful. -// -1 if socket already open. -// -2 if socket table full. -// -3 if IPX not installed. -// -4 if couldn't allocate low dos memory -// -5 if error with getting internetwork address -extern int ipx_init( int socket_number, int show_address ); +#define IPX_DRIVER_IPX 1 // IPX "IPX driver" :-) +#define IPX_DRIVER_KALI 2 +#define IPX_DRIVER_UDP 3 // UDP/IP, user datagrams protocol over the internet + +/* Sets the "IPX driver" (net driver). Takes one of the above consts as argument. */ +extern void arch_ipx_set_driver(int ipx_driver); + +#define IPX_INIT_OK 0 +#define IPX_SOCKET_ALREADY_OPEN -1 +#define IPX_SOCKET_TABLE_FULL -2 +#define IPX_NOT_INSTALLED -3 +#define IPX_NO_LOW_DOS_MEM -4 // couldn't allocate low dos memory +#define IPX_ERROR_GETTING_ADDR -5 // error with getting internetwork address + +/* returns one of the above constants */ +extern int ipx_init(int socket_number); + +extern void ipx_close(void); extern int ipx_change_default_socket( ushort socket_number ); diff --git a/main/inferno.c b/main/inferno.c index 9e12a542..6acf0765 100644 --- a/main/inferno.c +++ b/main/inferno.c @@ -1,4 +1,4 @@ -/* $Id: inferno.c,v 1.63 2003-06-16 07:11:40 btb Exp $ */ +/* $Id: inferno.c,v 1.64 2003-10-03 07:58:15 btb Exp $ */ /* THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO @@ -758,7 +758,6 @@ char copyright[] = "DESCENT II COPYRIGHT (C) 1994-1996 PARALLAX SOFTWARE CORPOR #include "titles.h" #include "player.h" #include "text.h" -#include "ipx.h" #include "newdemo.h" #ifdef NETWORK #include "network.h" @@ -1104,44 +1103,6 @@ void do_register_player(ubyte *title_pal) } -#ifdef NETWORK -void do_network_init() -{ - if (!FindArg( "-nonetwork" )) { - int socket = 0, showaddress = 0, t; - int ipx_error; - - con_printf(CON_VERBOSE, "\n%s ", TXT_INITIALIZING_NETWORK); - if ((t=FindArg("-socket"))) - socket = atoi( Args[t+1] ); - //@@if ( FindArg("-showaddress") ) showaddress=1; - if ((ipx_error=ipx_init(IPX_DEFAULT_SOCKET+socket, showaddress))==0) { - con_printf(CON_VERBOSE, "%s %d.\n", TXT_IPX_CHANNEL, socket ); - Network_active = 1; - } else { - switch( ipx_error ) { - case 3: con_printf(CON_VERBOSE, "%s\n", TXT_NO_NETWORK); break; - case -2: con_printf(CON_VERBOSE, "%s 0x%x.\n", TXT_SOCKET_ERROR, IPX_DEFAULT_SOCKET+socket); break; - case -4: con_printf(CON_VERBOSE, "%s\n", TXT_MEMORY_IPX ); break; - default: - con_printf(CON_VERBOSE, "%s %d", TXT_ERROR_IPX, ipx_error ); - } - con_printf(CON_VERBOSE, "%s\n",TXT_NETWORK_DISABLED); - Network_active = 0; // Assume no network - } - ipx_read_user_file( "descent.usr" ); - ipx_read_network_file( "descent.net" ); - //@@if ( FindArg( "-dynamicsockets" )) - //@@ Network_allow_socket_changes = 1; - //@@else - //@@ Network_allow_socket_changes = 0; - } else { - con_printf(CON_VERBOSE, "%s\n", TXT_NETWORK_DISABLED); - Network_active = 0; // Assume no network - } -} -#endif - #define PROGNAME argv[0] extern char Language[]; @@ -1325,10 +1286,6 @@ int main(int argc, char *argv[]) do_joystick_init(); -#ifdef NETWORK - do_network_init(); -#endif - #if defined(POLY_ACC) Current_display_mode = -1; game_init_render_buffers(SM_640x480x15xPA, 640, 480, VR_NONE, VRF_COMPATIBLE_MENUS+VRF_ALLOW_COCKPIT ); diff --git a/main/menu.c b/main/menu.c index dc1547f7..c95ee5f3 100644 --- a/main/menu.c +++ b/main/menu.c @@ -1,4 +1,4 @@ -/* $Id: menu.c,v 1.24 2003-04-12 02:52:38 btb Exp $ */ +/* $Id: menu.c,v 1.25 2003-10-03 07:58:15 btb Exp $ */ /* THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO @@ -58,13 +58,14 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #include "gamefont.h" #include "newmenu.h" #ifdef NETWORK -#include "network.h" +# include "network.h" +# include "ipx.h" +# include "multi.h" #endif #include "scores.h" #include "joydefs.h" #include "modem.h" #include "playsave.h" -#include "multi.h" #include "kconfig.h" #include "titles.h" #include "credits.h" @@ -120,10 +121,14 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #define MENU_SHOW_CREDITS 23 #define MENU_ORDER_INFO 24 #define MENU_PLAY_SONG 25 -#define MENU_START_TCP_NETGAME 26 -#define MENU_JOIN_TCP_NETGAME 27 +//#define MENU_START_TCP_NETGAME 26 // TCP/IP support was planned in Descent II, +//#define MENU_JOIN_TCP_NETGAME 27 // but never realized. #define MENU_START_APPLETALK_NETGAME 28 -#define MENU_JOIN_APPLETALK_NETGAME 30 +#define MENU_JOIN_APPLETALK_NETGAME 29 +#define MENU_START_UDP_NETGAME 30 // UDP/IP support copied from d1x +#define MENU_JOIN_UDP_NETGAME 31 +#define MENU_START_KALI_NETGAME 32 // Kali support copied from d1x +#define MENU_JOIN_KALI_NETGAME 33 //ADD_ITEM("Start netgame...", MENU_START_NETGAME, -1 ); //ADD_ITEM("Send net message...", MENU_SEND_NET_MESSAGE, -1 ); @@ -149,10 +154,12 @@ int EscortHotKeys=1; // Function Prototypes added after LINTING void do_option(int select); -void do_detail_level_menu_custon(void); -void do_multi_player_menu(void); void do_detail_level_menu_custom(void); void do_new_game_menu(void); +#ifdef NETWORK +void do_multi_player_menu(void); +void ipx_set_driver(int ipx_driver); +#endif //NETWORK //returns the number of demo files on the disk int newdemo_count_demos(); @@ -407,7 +414,7 @@ void do_option ( int select) do_show_help(); break; - #ifndef RELEASE +#ifndef RELEASE case MENU_PLAY_SONG: { int i; @@ -441,28 +448,34 @@ void do_option ( int select) break; } - #endif +#endif //ifndef RELEASE #ifdef NETWORK + //case MENU_START_TCP_NETGAME: + //case MENU_JOIN_TCP_NETGAME: case MENU_START_IPX_NETGAME: - case MENU_START_TCP_NETGAME: - load_mission(Builtin_mission_num); - #ifdef MACINTOSH - Network_game_type = IPX_GAME; - #endif -// WIN(ipx_create_read_thread()); - network_start_game(); - break; - case MENU_JOIN_IPX_NETGAME: - case MENU_JOIN_TCP_NETGAME: + case MENU_START_UDP_NETGAME: + case MENU_JOIN_UDP_NETGAME: + case MENU_START_KALI_NETGAME: + case MENU_JOIN_KALI_NETGAME: load_mission(Builtin_mission_num); - #ifdef MACINTOSH +#ifdef MACINTOSH Network_game_type = IPX_GAME; - #endif +#endif // WIN(ipx_create_read_thread()); - network_join_game(); + switch (select & ~0x1) { + case MENU_START_IPX_NETGAME: ipx_set_driver(IPX_DRIVER_IPX); break; + case MENU_START_UDP_NETGAME: ipx_set_driver(IPX_DRIVER_UDP); break; + case MENU_START_KALI_NETGAME: ipx_set_driver(IPX_DRIVER_KALI); break; + default: Int3(); + } + + if ((select & 0x1) == 0) // MENU_START_*_NETGAME + network_start_game(); + else // MENU_JOIN_*_NETGAME + network_join_game(); break; #ifdef MACINTOSH @@ -1689,10 +1702,11 @@ void do_toggles_menu() } +#ifdef NETWORK void do_multi_player_menu() { - int menu_choice[5]; - newmenu_item m[5]; + int menu_choice[9]; + newmenu_item m[9]; int choice = 0, num_options = 0; int old_game_mode; @@ -1702,18 +1716,23 @@ void do_multi_player_menu() old_game_mode = Game_mode; num_options = 0; - if (!FindArg("-udp")) { - ADD_ITEM(TXT_START_IPX_NET_GAME, MENU_START_IPX_NETGAME, -1 ); - ADD_ITEM(TXT_JOIN_IPX_NET_GAME, MENU_JOIN_IPX_NETGAME, -1 ); - } else { - ADD_ITEM(TXT_START_TCP_NET_GAME, MENU_START_TCP_NETGAME, -1 ); - ADD_ITEM(TXT_JOIN_TCP_NET_GAME, MENU_JOIN_TCP_NETGAME, -1 ); - } +#ifdef NATIVE_IPX + ADD_ITEM(TXT_START_IPX_NET_GAME, MENU_START_IPX_NETGAME, -1); + ADD_ITEM(TXT_JOIN_IPX_NET_GAME, MENU_JOIN_IPX_NETGAME, -1); +#endif //NATIVE_IPX + //ADD_ITEM(TXT_START_TCP_NET_GAME, MENU_START_TCP_NETGAME, -1); + //ADD_ITEM(TXT_JOIN_TCP_NET_GAME, MENU_JOIN_TCP_NETGAME, -1); +#ifdef __unix__ + ADD_ITEM("Start UDP/IP Netgame", MENU_START_UDP_NETGAME, -1); + ADD_ITEM("Join UDP/IP Netgame\n", MENU_JOIN_UDP_NETGAME, -1); + ADD_ITEM("Start Kali Netgame", MENU_START_KALI_NETGAME, -1); + ADD_ITEM("Join Kali Netgame\n", MENU_JOIN_KALI_NETGAME, -1); +#endif //__unix__ - #ifdef MACINTOSH +#ifdef MACINTOSH ADD_ITEM("Start Appletalk Netgame", MENU_START_APPLETALK_NETGAME, -1 ); ADD_ITEM("Join Appletalk Netgame\n", MENU_JOIN_APPLETALK_NETGAME, -1 ); - #endif +#endif ADD_ITEM(TXT_MODEM_GAME, MENU_START_SERIAL, -1); @@ -1729,6 +1748,51 @@ void do_multi_player_menu() } +/* + * ipx_set_driver was called do_network_init and located in main/inferno + * before the change which allows the user to choose the network driver + * from the game menu instead of having to supply command line args. + */ +void ipx_set_driver(int ipx_driver) +{ + ipx_close(); + + if (!FindArg("-nonetwork")) { + int ipx_error; + int socket = 0, t; + + con_printf(CON_VERBOSE, "\n%s ", TXT_INITIALIZING_NETWORK); + + if ((t = FindArg("-socket"))) + socket = atoi(Args[t + 1]); + + arch_ipx_set_driver(ipx_driver); + + if ((ipx_error = ipx_init(IPX_DEFAULT_SOCKET + socket)) == IPX_INIT_OK) { + con_printf(CON_VERBOSE, "%s %d.\n", TXT_IPX_CHANNEL, socket ); + Network_active = 1; + } else { + switch(ipx_error) { + case IPX_NOT_INSTALLED: con_printf(CON_VERBOSE, "%s\n", TXT_NO_NETWORK); break; + case IPX_SOCKET_TABLE_FULL: con_printf(CON_VERBOSE, "%s 0x%x.\n", TXT_SOCKET_ERROR, IPX_DEFAULT_SOCKET+socket); break; + case IPX_NO_LOW_DOS_MEM: con_printf(CON_VERBOSE, "%s\n", TXT_MEMORY_IPX ); break; + default: con_printf(CON_VERBOSE, "%s %d", TXT_ERROR_IPX, ipx_error ); + } + con_printf(CON_VERBOSE, "%s\n",TXT_NETWORK_DISABLED); + Network_active = 0; // Assume no network + } + ipx_read_user_file("descent.usr"); + ipx_read_network_file("descent.net"); + //@@if (FindArg("-dynamicsockets")) + //@@ Network_allow_socket_changes = 1; + //@@else + //@@ Network_allow_socket_changes = 0; + } else { + con_printf(CON_VERBOSE, "%s\n", TXT_NETWORK_DISABLED); + Network_active = 0; // Assume no network + } +} + void DoNewIPAddress () { newmenu_item m[4]; @@ -1746,3 +1810,5 @@ void DoNewIPAddress () nm_messagebox (TXT_SORRY,1,TXT_OK,"That address is not valid!"); } + +#endif // NETWORK diff --git a/main/multi.c b/main/multi.c index df20ac3d..4e47b83f 100644 --- a/main/multi.c +++ b/main/multi.c @@ -1,4 +1,4 @@ -/* $Id: multi.c,v 1.11 2003-08-02 07:32:59 btb Exp $ */ +/* $Id: multi.c,v 1.12 2003-10-03 07:58:15 btb Exp $ */ /* THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO @@ -1539,7 +1539,7 @@ multi_do_fire(char *buf) weapon = buf[2]; #endif flags = buf[4]; - Network_laser_track = INTEL_SHORT(*(short *)(buf+6)); + GET_INTEL_SHORT(Network_laser_track, buf+6); Assert (pnum < N_players); @@ -1679,7 +1679,7 @@ multi_do_reappear(char *buf) { short objnum; - objnum = INTEL_SHORT(*(short *)(buf+1)); + GET_INTEL_SHORT(objnum, buf+1); Assert(objnum >= 0); // Assert(Players[Objects[objnum].id]].objnum == objnum); @@ -1725,8 +1725,8 @@ multi_do_player_explode(char *buf) // Stuff the Players structure to prepare for the explosion count = 2; - Players[pnum].primary_weapon_flags = INTEL_SHORT(*(ushort *)(buf+count)); count += 2; - Players[pnum].secondary_weapon_flags = INTEL_SHORT(*(ushort *)(buf+count)); count += 2; + GET_INTEL_SHORT(Players[pnum].primary_weapon_flags, buf+count); count += 2; + GET_INTEL_SHORT(Players[pnum].secondary_weapon_flags, buf+count); count += 2; Players[pnum].laser_level = buf[count]; count++; Players[pnum].secondary_ammo[HOMING_INDEX] = buf[count]; count++; Players[pnum].secondary_ammo[CONCUSSION_INDEX] = buf[count];count++; @@ -1740,9 +1740,9 @@ multi_do_player_explode(char *buf) Players[pnum].secondary_ammo[SMISSILE4_INDEX] = buf[count]; count++; Players[pnum].secondary_ammo[SMISSILE5_INDEX] = buf[count]; count++; - Players[pnum].primary_ammo[VULCAN_INDEX] = INTEL_SHORT(*(ushort *)(buf+count)); count += 2; - Players[pnum].primary_ammo[GAUSS_INDEX] = INTEL_SHORT(*(ushort *)(buf+count)); count += 2; - Players[pnum].flags = INTEL_INT(*(uint *)(buf+count)); count += 4; + GET_INTEL_SHORT(Players[pnum].primary_ammo[VULCAN_INDEX], buf+count); count += 2; + GET_INTEL_SHORT(Players[pnum].primary_ammo[GAUSS_INDEX], buf+count); count += 2; + GET_INTEL_INT(Players[pnum].flags, buf+count); count += 4; multi_adjust_remote_cap (pnum); @@ -1769,11 +1769,11 @@ multi_do_player_explode(char *buf) { short s; - s = INTEL_SHORT(*(short *)(buf+count)); + GET_INTEL_SHORT(s, buf+count); if ((i < Net_create_loc) && (s > 0)) map_objnum_local_to_remote((short)Net_create_objnums[i], s, pnum); - else if (*(short *)(buf+count) <= 0) + else if (s <= 0) { mprintf((0, "WARNING: Remote created object has non-valid number %d (player %d)", s, pnum)); } @@ -1821,7 +1821,7 @@ multi_do_kill(char *buf) killed = Players[pnum].objnum; count += 1; - killer = INTEL_SHORT(*(short *)(buf+count)); + GET_INTEL_SHORT(killer, buf+count); if (killer > 0) killer = objnum_remote_to_local(killer, (byte)buf[count+2]); @@ -1846,7 +1846,7 @@ void multi_do_controlcen_destroy(char *buf) byte who; short objnum; - objnum = INTEL_SHORT(*(short *)(buf+1)); + GET_INTEL_SHORT(objnum, buf+1); who = buf[3]; if (Control_center_destroyed != 1) @@ -1903,7 +1903,7 @@ multi_do_remobj(char *buf) short local_objnum; byte obj_owner; // which remote list is it entered in - objnum = INTEL_SHORT(*(short *)(buf+1)); + GET_INTEL_SHORT(objnum, buf+1); obj_owner = buf[3]; Assert(objnum >= 0); @@ -2037,7 +2037,7 @@ multi_do_door_open(char *buf) wall *w; ubyte flag; - segnum = INTEL_SHORT(*(short *)(buf+1)); + GET_INTEL_SHORT(segnum, buf+1); side = buf[3]; flag= buf[4]; @@ -2099,14 +2099,14 @@ multi_do_controlcen_fire(char *buf) short objnum; int count = 1; - memcpy(&to_target, buf+count, 12); count += 12; -#ifdef WORDS_BIGENDIAN // swap the vector to_target + memcpy(&to_target, buf+count, 12); count += 12; +#ifdef WORDS_BIGENDIAN // swap the vector to_target to_target.x = (fix)INTEL_INT((int)to_target.x); to_target.y = (fix)INTEL_INT((int)to_target.y); to_target.z = (fix)INTEL_INT((int)to_target.z); #endif - gun_num = buf[count]; count += 1; - objnum = INTEL_SHORT(*(short *)(buf+count)); count += 2; + gun_num = buf[count]; count += 1; + GET_INTEL_SHORT(objnum, buf+count); count += 2; Laser_create_new_easy(&to_target, &Gun_pos[(int)gun_num], objnum, CONTROLCEN_WEAPON_NUM, 1); } @@ -2127,15 +2127,15 @@ multi_do_create_powerup(char *buf) pnum = buf[count++]; powerup_type = buf[count++]; - segnum = INTEL_SHORT(*(short *)(buf+count)); count+=2; - objnum = INTEL_SHORT(*(short *)(buf+count)); count+=2; + GET_INTEL_SHORT(segnum, buf+count); count+=2; + GET_INTEL_SHORT(objnum, buf+count); count+=2; if ((segnum < 0) || (segnum > Highest_segment_index)) { Int3(); return; } - new_pos = *(vms_vector *)(buf+count); count+=sizeof(vms_vector); + memcpy(&new_pos, buf+count, sizeof(vms_vector)); count+=sizeof(vms_vector); #ifdef WORDS_BIGENDIAN new_pos.x = (fix)SWAPINT((int)new_pos.x); new_pos.y = (fix)SWAPINT((int)new_pos.y); @@ -2198,10 +2198,13 @@ multi_do_score(char *buf) return; } - if (Newdemo_state == ND_STATE_RECORDING) - newdemo_record_multi_score(pnum, INTEL_INT(*(int *)(buf+2)) ); + if (Newdemo_state == ND_STATE_RECORDING) { + int score; + GET_INTEL_INT(score, buf+2); + newdemo_record_multi_score(pnum, score); + } - Players[pnum].score = INTEL_INT(*(int *)(buf+2)); + GET_INTEL_INT(Players[pnum].score, buf+2); multi_sort_kill_list(); } @@ -2237,9 +2240,9 @@ void multi_do_drop_marker (char *buf) if (pnum==Player_num) // my marker? don't set it down cuz it might screw up the orientation return; - position.x=(fix)INTEL_INT(*(int *)(buf+3)); - position.y=(fix)INTEL_INT(*(int *)(buf+7)); - position.z=(fix)INTEL_INT(*(int *)(buf+11)); + GET_INTEL_INT(position.x, buf+3); + GET_INTEL_INT(position.y, buf+7); + GET_INTEL_INT(position.z, buf+11); for (i=0;i<40;i++) MarkerMessage[(pnum*2)+mesnum][i]=buf[15+i]; @@ -2263,8 +2266,8 @@ void multi_do_hostage_door_status(char *buf) int wallnum; fix hps; - wallnum = INTEL_SHORT(*(short *)(buf+count)); count += 2; - hps = (fix)INTEL_INT(*(int *)(buf+count)); count += 4; + GET_INTEL_SHORT(wallnum, buf+count); count += 2; + GET_INTEL_INT(hps, buf+count); count += 4; if ((wallnum < 0) || (wallnum > Num_walls) || (hps < 0) || (Walls[wallnum].type != WALL_BLASTABLE)) { @@ -2286,7 +2289,7 @@ void multi_do_save_game(char *buf) char desc[25]; slot = *(ubyte *)(buf+count); count += 1; - id = INTEL_INT(*(uint *)(buf+count)); count += 4; + GET_INTEL_INT(id, buf+count); count += 4; memcpy( desc, &buf[count], 20 ); count += 20; multi_save_game( slot, id, desc ); @@ -2299,7 +2302,7 @@ void multi_do_restore_game(char *buf) uint id; slot = *(ubyte *)(buf+count); count += 1; - id = INTEL_INT(*(uint *)(buf+count)); count += 4; + GET_INTEL_INT(id, buf+count); count += 4; multi_restore_game( slot, id ); } @@ -2471,7 +2474,7 @@ multi_send_fire(void) multibuf[4] = (char)Network_laser_flags; multibuf[5] = (char)Network_laser_fired; - *(short *)(multibuf+6) = INTEL_SHORT(Network_laser_track); + PUT_INTEL_SHORT(multibuf+6, Network_laser_track); multi_send_data(multibuf, 8, 0); @@ -2489,7 +2492,7 @@ multi_send_destroy_controlcen(int objnum, int player) HUD_init_message(TXT_CONTROL_DESTROYED); multibuf[0] = (char)MULTI_CONTROLCEN; - *(ushort *)(multibuf+1) = INTEL_SHORT(objnum); + PUT_INTEL_SHORT(multibuf+1, objnum); multibuf[3] = player; multi_send_data(multibuf, 4, 2); } @@ -2504,9 +2507,9 @@ void multi_send_drop_marker (int player,vms_vector position,char messagenum,char multibuf[0]=(char)MULTI_MARKER; multibuf[1]=(char)player; multibuf[2]=messagenum; - *(fix *)(multibuf+3)=INTEL_INT(position.x); - *(fix *)(multibuf+7)=INTEL_INT(position.y); - *(fix *)(multibuf+11)=INTEL_INT(position.z); + PUT_INTEL_INT(multibuf+3, position.x); + PUT_INTEL_INT(multibuf+7, position.y); + PUT_INTEL_INT(multibuf+11, position.z); for (i=0;i<40;i++) multibuf[15+i]=text[i]; } @@ -2552,9 +2555,9 @@ multi_send_player_explode(char type) multibuf[count++] = type; multibuf[count++] = Player_num; - *(ushort *)(multibuf+count) = INTEL_SHORT((ushort)Players[Player_num].primary_weapon_flags); + PUT_INTEL_SHORT(multibuf+count, Players[Player_num].primary_weapon_flags); count += 2; - *(ushort *)(multibuf+count) = INTEL_SHORT((ushort)Players[Player_num].secondary_weapon_flags); + PUT_INTEL_SHORT(multibuf+count, Players[Player_num].secondary_weapon_flags); count += 2; multibuf[count++] = (char)Players[Player_num].laser_level; @@ -2570,11 +2573,11 @@ multi_send_player_explode(char type) multibuf[count++] = (char)Players[Player_num].secondary_ammo[SMISSILE4_INDEX]; multibuf[count++] = (char)Players[Player_num].secondary_ammo[SMISSILE5_INDEX]; - *(ushort *)(multibuf+count) = INTEL_SHORT( (ushort)Players[Player_num].primary_ammo[VULCAN_INDEX] ); + PUT_INTEL_SHORT(multibuf+count, Players[Player_num].primary_ammo[VULCAN_INDEX] ); count += 2; - *(ushort *)(multibuf+count) = INTEL_SHORT( (ushort)Players[Player_num].primary_ammo[GAUSS_INDEX] ); + PUT_INTEL_SHORT(multibuf+count, Players[Player_num].primary_ammo[GAUSS_INDEX] ); count += 2; - *(uint *)(multibuf+count) = INTEL_INT( (uint)Players[Player_num].flags ); + PUT_INTEL_INT(multibuf+count, Players[Player_num].flags ); count += 4; multibuf[count++] = Net_create_loc; @@ -2593,7 +2596,7 @@ multi_send_player_explode(char type) continue; } - *(short *)(multibuf+count) = INTEL_SHORT( (short)Net_create_objnums[i] ); count += 2; + PUT_INTEL_SHORT(multibuf+count, Net_create_objnums[i]); count += 2; // We created these objs so our local number = the network number map_objnum_local_to_local((short)Net_create_objnums[i]); @@ -2842,7 +2845,7 @@ void multi_send_reappear() { multibuf[0] = (char)MULTI_REAPPEAR; - *(short *)(multibuf+1) = INTEL_SHORT(Players[Player_num].objnum); + PUT_INTEL_SHORT(multibuf+1, Players[Player_num].objnum); multi_send_data(multibuf, 3, 2); PKilledFlags[Player_num]=0; @@ -2894,11 +2897,11 @@ multi_send_kill(int objnum) short s; // do it with variable since INTEL_SHORT won't work on return val from function. s = (short)objnum_local_to_remote(killer_objnum, (byte *)&multibuf[count+2]); - *(short *)(multibuf+count) = INTEL_SHORT(s); + PUT_INTEL_SHORT(multibuf+count, s); } else { - *(short *)(multibuf+count) = INTEL_SHORT((short)-1); + PUT_INTEL_SHORT(multibuf+count, -1); multibuf[count+2] = (char)-1; } count += 3; @@ -2940,7 +2943,7 @@ multi_send_remobj(int objnum) remote_objnum = objnum_local_to_remote((short)objnum, &obj_owner); - *(short *)(multibuf+1) = INTEL_SHORT(remote_objnum); // Map to network objnums + PUT_INTEL_SHORT(multibuf+1, remote_objnum); // Map to network objnums multibuf[3] = obj_owner; @@ -3001,7 +3004,7 @@ multi_send_door_open(int segnum, int side,ubyte flag) // When we open a door make sure everyone else opens that door multibuf[0] = MULTI_DOOR_OPEN; - *(short *)(multibuf+1) = INTEL_SHORT( (short)segnum ); + PUT_INTEL_SHORT(multibuf+1, segnum ); multibuf[3] = (byte)side; multibuf[4] = flag; @@ -3019,7 +3022,7 @@ multi_send_door_open_specific(int pnum,int segnum, int side,ubyte flag) // Assert (pnum>-1 && pnumx ); swapped_vec.y = (fix)INTEL_INT( (int)pos->y ); @@ -3159,7 +3162,7 @@ multi_send_score(void) multi_sort_kill_list(); multibuf[count] = MULTI_SCORE; count += 1; multibuf[count] = Player_num; count += 1; - *(int *)(multibuf+count) = INTEL_INT( Players[Player_num].score ); count += 4; + PUT_INTEL_INT(multibuf+count, Players[Player_num].score); count += 4; multi_send_data(multibuf, count, 0); } } @@ -3172,7 +3175,7 @@ multi_send_save_game(ubyte slot, uint id, char * desc) multibuf[count] = MULTI_SAVE_GAME; count += 1; multibuf[count] = slot; count += 1; // Save slot=0 - *(uint *)(multibuf+count) = INTEL_INT( id ); count += 4; // Save id + PUT_INTEL_INT(multibuf+count, id ); count += 4; // Save id memcpy( &multibuf[count], desc, 20 ); count += 20; multi_send_data(multibuf, count, 2); @@ -3185,7 +3188,7 @@ multi_send_restore_game(ubyte slot, uint id) multibuf[count] = MULTI_RESTORE_GAME; count += 1; multibuf[count] = slot; count += 1; // Save slot=0 - *(uint *)(multibuf+count) = INTEL_INT( id ); count += 4; // Save id + PUT_INTEL_INT(multibuf+count, id); count += 4; // Save id multi_send_data(multibuf, count, 2); } @@ -3229,8 +3232,8 @@ multi_send_hostage_door_status(int wallnum) Assert(Walls[wallnum].type == WALL_BLASTABLE); multibuf[count] = MULTI_HOSTAGE_DOOR; count += 1; - *(short *)(multibuf+count) = INTEL_SHORT( (short)wallnum ); count += 2; - *(fix *)(multibuf+count) = (fix)INTEL_INT( (int)Walls[wallnum].hps ); count += 4; + PUT_INTEL_SHORT(multibuf+count, wallnum ); count += 2; + PUT_INTEL_INT(multibuf+count, Walls[wallnum].hps ); count += 4; // mprintf((0, "Door %d damaged by %f points.\n", wallnum, f2fl(Walls[wallnum].hps))); @@ -3864,10 +3867,10 @@ void multi_send_drop_weapon (int objnum,int seed) multibuf[count++]=(char)MULTI_DROP_WEAPON; multibuf[count++]=(char)objp->id; - *(short *) (multibuf+count)=INTEL_SHORT(Player_num); count += 2; - *(short *) (multibuf+count)=INTEL_SHORT(objnum); count += 2; - *(short *) (multibuf+count)=INTEL_SHORT(ammo_count); count += 2; - *(int *) (multibuf+count)=INTEL_INT(seed); + PUT_INTEL_SHORT(multibuf+count, Player_num); count += 2; + PUT_INTEL_SHORT(multibuf+count, objnum); count += 2; + PUT_INTEL_SHORT(multibuf+count, ammo_count); count += 2; + PUT_INTEL_INT(multibuf+count, seed); map_objnum_local_to_local(objnum); @@ -3884,10 +3887,10 @@ void multi_do_drop_weapon (char *buf) int powerup_id; powerup_id=(int)(buf[1]); - pnum = INTEL_SHORT(*(short *)(buf+2)); - remote_objnum = INTEL_SHORT(*(short *)(buf+4)); - ammo = INTEL_SHORT(*(ushort *)(buf+6)); - seed = INTEL_INT(*(int *)(buf+8)); + GET_INTEL_SHORT(pnum, buf+2); + GET_INTEL_SHORT(remote_objnum, buf+4); + GET_INTEL_SHORT(ammo, buf+6); + GET_INTEL_INT(seed, buf+8); objp = &Objects[Players[pnum].objnum]; @@ -4017,7 +4020,7 @@ void multi_send_wall_status (int wallnum,ubyte type,ubyte flags,ubyte state) { int count=0; multibuf[count]=MULTI_WALL_STATUS; count++; - *(short *)(multibuf+count)=INTEL_SHORT(wallnum); count+=2; + PUT_INTEL_SHORT(multibuf+count, wallnum); count+=2; multibuf[count]=type; count++; multibuf[count]=flags; count++; multibuf[count]=state; count++; @@ -4045,7 +4048,7 @@ void multi_send_wall_status_specific (int pnum,int wallnum,ubyte type,ubyte flag //Assert (pnum>-1 && pnum-1 && pnumn_parts = INTEL_INT(ad->n_parts); + ad->front_wallnum[0] = INTEL_SHORT(ad->front_wallnum[0]); + ad->front_wallnum[1] = INTEL_SHORT(ad->front_wallnum[1]); + ad->back_wallnum[0] = INTEL_SHORT(ad->back_wallnum[0]); + ad->back_wallnum[1] = INTEL_SHORT(ad->back_wallnum[1]); + ad->time = INTEL_INT(ad->time); + } +#endif //WORDS_BIGENDIAN } -void multi_send_sound_function (char whichfunc,char sound) +void multi_send_sound_function (char whichfunc, char sound) { int count=0; @@ -4702,10 +4705,10 @@ void multi_send_drop_flag (int objnum,int seed) multibuf[count++]=(char)MULTI_DROP_FLAG; multibuf[count++]=(char)objp->id; - *(short *) (multibuf+count)=INTEL_SHORT(Player_num); count += 2; - *(short *) (multibuf+count)=INTEL_SHORT(objnum); count += 2; - *(short *) (multibuf+count)=INTEL_SHORT(objp->ctype.powerup_info.count); count += 2; - *(int *) (multibuf+count)=INTEL_INT(seed); + PUT_INTEL_SHORT(multibuf+count, Player_num); count += 2; + PUT_INTEL_SHORT(multibuf+count, objnum); count += 2; + PUT_INTEL_SHORT(multibuf+count, objp->ctype.powerup_info.count); count += 2; + PUT_INTEL_INT(multibuf+count, seed); map_objnum_local_to_local(objnum); @@ -4723,10 +4726,10 @@ void multi_do_drop_flag (char *buf) int powerup_id; powerup_id=buf[1]; - pnum=INTEL_SHORT( *(short *)(buf+2) ); - remote_objnum=INTEL_SHORT( *(short *)(buf+4) ); - ammo=INTEL_SHORT( *(short *)(buf+6) ); - seed=INTEL_INT( *(int *)(buf+8) ); + GET_INTEL_SHORT(pnum, buf+2); + GET_INTEL_SHORT(remote_objnum, buf+4); + GET_INTEL_SHORT(ammo, buf+6); + GET_INTEL_INT(seed, buf+8); objp = &Objects[Players[pnum].objnum]; -- 2.39.2