From 8727166e24c49e6d68558903e8fa4397403c3695 Mon Sep 17 00:00:00 2001 From: terminx Date: Tue, 28 Nov 2006 16:23:37 +0000 Subject: [PATCH] I wish I knew why this doesn't work git-svn-id: https://svn.eduke32.com/eduke32@363 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/build/src/mmultirm.c | 192 ++++++++------------------------ polymer/eduke32/source/game.c | 3 +- polymer/eduke32/source/premap.c | 7 ++ 3 files changed, 54 insertions(+), 148 deletions(-) diff --git a/polymer/build/src/mmultirm.c b/polymer/build/src/mmultirm.c index 77aa3a5ce..3f0a6dc96 100755 --- a/polymer/build/src/mmultirm.c +++ b/polymer/build/src/mmultirm.c @@ -1,24 +1,22 @@ -/* - * "Build Engine & Tools" Copyright (c) 1993-1997 Ken Silverman - * Ken Silverman's official web site: "http://www.advsys.net/ken" - * See the included license file "BUILDLIC.TXT" for license info. - * This file has been modified from Ken Silverman's original release - */ - #include #include #include #include #include -#include +// #include + +#include "compat.h" +#include "cache1d.h" +#include "pragmas.h" +#include "baselayer.h" #ifdef _WIN32 #define WIN32_LEAN_AND_MEAN #include #include +#define SOCKET int #define EWOULDBLOCK WSAEWOULDBLOCK #define ECONNREFUSED WSAECONNRESET -#define socklen_t size_t #define netstrerror() win32netstrerror() #define neterrno() WSAGetLastError() #else @@ -41,14 +39,8 @@ #define ioctlsocket ioctl #define netstrerror() strerror(errno) #define neterrno() errno -#define LPHOSTENT struct hostent * #endif -#include "compat.h" -#include "cache1d.h" -#include "pragmas.h" -#include "baselayer.h" - //STL //#include //#include "buildqueue.h" @@ -60,8 +52,6 @@ #define SHOWGETPACKETS 1 #define PRINTERRORS 1 -#define updatecrc16(crc,dat) crc = (((crc<<8)&65535)^crctable[((((unsigned short)crc)>>8)&65535)^dat]) - #define SOCKET_SHUTDOWN_BOTH 2 #define IPSEG1(ip) ((((unsigned int) ip) & 0xFF000000) >> 24) @@ -91,7 +81,6 @@ static char errorresendnum[MAXPLAYERS]; static char lasterrorgotnum[MAXPLAYERS]; #endif -long crctable[256]; int tmpmax[8]; //addfaz variable addition (you could probs think of something better) int itmp = 0; //addfaz router fix STUN @@ -177,41 +166,35 @@ void deinit_network_transport(gcomtype *gcom); void callcommit(void); void dosendpackets(long other); - -void initcrc(void) -{ - long i, j, k, a; - - for (j=0;j<256;j++) /* Calculate CRC table */ - { - k = (j<<8); a = 0; - for (i=7;i>=0;i--) - { - if (((k^a)&0x8000) > 0) - a = ((a<<1)&65535) ^ 0x1021; /* 0x1021 = genpoly */ - else - a = ((a<<1)&65535); - k = ((k<<1)&65535); - } - crctable[j] = (a&65535); - } -} - - -long getcrc(char *buffer, short bufleng) -{ - long i, j; - - j = 0; - for (i=bufleng-1;i>=0;i--) updatecrc16(j,buffer[i]); - return(j&65535); -} +static long crctab16[256]; +static void initcrc16 () +{ + long i, j, k, a; + for (j=0;j<256;j++) + { + for (i=7,k=(j<<8),a=0;i>=0;i--,k=((k<<1)&65535)) + { + if ((k^a)&0x8000) a = ((a<<1)&65535)^0x1021; + else a = ((a<<1)&65535); + } + crctab16[j] = (a&65535); + } +} +#define updatecrc16(crc,dat) crc = (((crc<<8)&65535)^crctab16[((((unsigned short)crc)>>8)&65535)^dat]) +static unsigned short getcrc16 (char *buffer, long bufleng) +{ + long i, j; + + j = 0; + for (i=bufleng-1;i>=0;i--) updatecrc16(j,buffer[i]); + return((unsigned short)(j&65535)); +} void initmultiplayers(long argc, char **argv, char damultioption, char dacomrateoption, char dapriority) { long i; - initcrc(); + initcrc16(); for (i=0;ibuffer,(short)k); + dacrc = getcrc16(gcom->buffer,(short)k); gcom->buffer[k++] = (dacrc&255); gcom->buffer[k++] = (dacrc>>8); @@ -367,7 +349,6 @@ void sendpacket(long other, char *bufptr, long messleng) outcntend[other]++; lastsendtime[other] = totalclock; - initprintf("totalclock: %ld\n",totalclock); dosendpackets(other); } @@ -431,7 +412,6 @@ short getpacket(short *other, char *bufptr) { #if (PRINTERRORS) initprintf(" TimeOut!"); - initprintf("totalclock: %ld\n",totalclock); #endif errorgotnum[i] = errorfixnum[i]+1; @@ -472,7 +452,7 @@ short getpacket(short *other, char *bufptr) dacrc = ((unsigned short)gcom->buffer[messleng-2]); dacrc += (((unsigned short)gcom->buffer[messleng-1])<<8); - if (dacrc != getcrc(gcom->buffer,(short)(messleng-2))) /* CRC check */ + if (dacrc != getcrc16(gcom->buffer,(short)(messleng-2))) /* CRC check */ { #if (PRINTERRORS) initprintf("\n%ld CRC",gcom->buffer[0]); @@ -701,7 +681,7 @@ static int get_udp_packet(int *ip, short *_port, void *pkt, size_t pktsize) /* FIXME: Will this ever receive a partial packet? */ int rc = recvfrom(udpsocket, pkt, pktsize, 0, - (struct sockaddr *) &addr, (int *)&fromlen); + (struct sockaddr *) &addr, (socklen_t *)&fromlen); if (rc == -1) err = neterrno(); @@ -822,7 +802,7 @@ static char *read_whole_file(const char *cfgfile) if (cfgfile == NULL) return(NULL); - handle = kopen4load(cfgfile, 0); + handle = kopen4load((char *)cfgfile, 0); if (handle == -1) { initprintf("ERROR: Failed to open config file [%s].\n", cfgfile); @@ -875,8 +855,12 @@ static char *get_token(char **ptr) } static int set_socket_blockmode(int onOrOff) -{ - unsigned long flags; +{ +#ifdef _WIN32 + unsigned long flags; +#else + signed long flags; +#endif int rc = 0; /* set socket to be (non-)blocking. */ @@ -1091,9 +1075,9 @@ static int connect_to_everyone(gcomtype *gcom, int myip, int bcast) } #ifdef _WIN32 - Sleep(1); + Sleep(10); #else - usleep(1); + usleep(10); #endif process_udp_send_queue(); @@ -1267,7 +1251,7 @@ static int connect_to_everyone(gcomtype *gcom, int myip, int bcast) initprintf("%s:%i is player #%i.\n", static_ipstring(ip),allowed_addresses[i].port,i); } - assert(gcom->myconnectindex); +// assert(gcom->myconnectindex); initprintf("Everyone ready! We are player #%i\n", gcom->myconnectindex); @@ -1462,7 +1446,7 @@ static int parse_udp_config(const char *cfgfile, gcomtype *gcom) return(connect_to_everyone(gcom, ip, bcast)); initprintf("wtf?!"); /* Should be handled by a udpmode above... */ - assert(0); +// assert(0); } return(0); @@ -1636,89 +1620,3 @@ void callcommit(void) break; } } - -#if 0 -char tempbuf[512],ipaddr[32]; - -const char *getexternaladdress(void) -{ - int sockfd, bytes_sent, i=0, j=0; - struct sockaddr_in dest_addr; - struct hostent *h; - char *host = "checkip.dyndns.org"; - char *req = "GET / HTTP/1.0\r\n\r\n"; - - if (ipaddr[0]) - return(ipaddr); - -#ifdef _WIN32 - { - WSADATA ws; - - if (WSAStartup(0x101,&ws) == SOCKET_ERROR) - { - initprintf("mmulti: Winsock error in getexternaladdress() (%d)\n",errno); - return(0); - } - } -#endif - - if ((h=gethostbyname(host)) == NULL) - { - initprintf("mmulti: gethostbyname() error in getexternaladdress() (%d)\n",h_errno); - return(0); - } - - dest_addr.sin_addr.s_addr = ((struct in_addr *)(h->h_addr))->s_addr; - dest_addr.sin_family = AF_INET; - dest_addr.sin_port = htons(8245); - - Bmemset(&(dest_addr.sin_zero), '\0', 8); - - sockfd = socket(PF_INET, SOCK_STREAM, 0); - if (sockfd == SOCKET_ERROR) - { - initprintf("mmulti: socket() error in getexternaladdress() (%d)\n",errno); - return(0); - } - - if (connect(sockfd, (struct sockaddr *)&dest_addr, sizeof(struct sockaddr)) == SOCKET_ERROR) - { - initprintf("mmulti: connect() error in getexternaladdress() (%d)\n",errno); - return(0); - } - - bytes_sent = send(sockfd, req, strlen(req), 0); - if (bytes_sent == SOCKET_ERROR) - { - initprintf("mmulti: send() error in getexternaladdress() (%d)\n",errno); - return(0); - } - - // initprintf("sent %d bytes\n",bytes_sent); - recv(sockfd, (char *)&tempbuf, sizeof(tempbuf), 0); - closesocket(sockfd); - -#ifdef _WIN32 - WSACleanup(); -#endif - - for (i=0;(unsigned)i i+1) { + NoSetup = TRUE; + networkmode = 1; #ifndef RMNET CommandNet = argv[i+1]; #endif diff --git a/polymer/eduke32/source/premap.c b/polymer/eduke32/source/premap.c index ac1e31e73..892a9809f 100644 --- a/polymer/eduke32/source/premap.c +++ b/polymer/eduke32/source/premap.c @@ -1423,6 +1423,7 @@ void waitforeverybody() packbuf[0] = 250; for (i=connecthead;i>=0;i=connectpoint2[i]) { + initprintf("sending 250\n"); if (i != myconnectindex) sendpacket(i,packbuf,1); if ((!networkmode) && (myconnectindex != connecthead)) break; //slaves in M/S mode only send to master } @@ -1430,6 +1431,12 @@ void waitforeverybody() while (1) { +#ifdef _WIN32 + Sleep(10); +#else + usleep(10); +#endif + sampletimer(); handleevents(); AudioUpdate();