From 270d573af333bd42823c126994dc660ccf9cb543 Mon Sep 17 00:00:00 2001 From: terminx Date: Wed, 29 Nov 2006 10:30:25 +0000 Subject: [PATCH] Hmm.. git-svn-id: https://svn.eduke32.com/eduke32@365 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/build/src/mmulti.c | 38 +++++++++++++++++++++++++--- polymer/build/src/mmultirm.c | 45 +++++++++++++++++++-------------- polymer/eduke32/source/game.c | 5 +++- polymer/eduke32/source/menus.c | 3 +++ polymer/eduke32/source/premap.c | 1 - 5 files changed, 67 insertions(+), 25 deletions(-) diff --git a/polymer/build/src/mmulti.c b/polymer/build/src/mmulti.c index d04976ef4..7a9a9bb7b 100644 --- a/polymer/build/src/mmulti.c +++ b/polymer/build/src/mmulti.c @@ -51,10 +51,10 @@ static long GetTickCount(void) #endif #define MAXPLAYERS 16 -#define MAXPAKSIZ 256 //576 +#define MAXPAKSIZ 576 -#define PAKRATE 26 //Packet rate/sec limit ... necessary? +#define PAKRATE 250 //Packet rate/sec limit ... necessary? #define SIMMIS 0 //Release:0 Test:100 Packets per 256 missed. #define SIMLAG 0 //Release:0 Test: 10 Packets to delay receipt static long simlagcnt[MAXPLAYERS]; @@ -128,6 +128,35 @@ void netuninit () #endif } +static int set_socket_blockmode(SOCKET socket, int onOrOff) +{ +#ifdef _WIN32 + unsigned long flags; +#else + signed long flags; +#endif + int rc = 0; + + /* set socket to be (non-)blocking. */ + +#ifdef _WIN32 + flags = (onOrOff) ? 0 : 1; + rc = (ioctlsocket(socket, FIONBIO, &flags) == 0); +#else + flags = fcntl(socket, F_GETFL, 0); + if (flags != -1) + { + if (onOrOff) + flags &= ~O_NONBLOCK; + else + flags |= O_NONBLOCK; + rc = (fcntl(socket, F_SETFL, flags) == 0); + } +#endif + + return(rc); +} + long netinit (long portnum) { LPHOSTENT lpHostEnt; @@ -145,7 +174,8 @@ long netinit (long portnum) #ifdef __BEOS__ i = 1; if (setsockopt(mysock,SOL_SOCKET,SO_NONBLOCK,&i,sizeof(i)) < 0) return(0); #else - i = 1; if (ioctlsocket(mysock,FIONBIO,(unsigned long *)&i) == SOCKET_ERROR) return(0); +// i = 1; if (ioctlsocket(mysock,FIONBIO,(unsigned long *)&i) == SOCKET_ERROR) return(0); + if (!set_socket_blockmode(mysock,0)) return(0); #endif ip.sin_family = AF_INET; @@ -566,7 +596,7 @@ void dosendpackets (long other) //Host to send intially, client to send to other tims = GetTickCount(); if (tims < lastsendtims[other]) lastsendtims[other] = tims; - if (tims < lastsendtims[other]+1000/PAKRATE) return; +// if (tims < lastsendtims[other]+1000/PAKRATE) return; lastsendtims[other] = tims; k = 2; diff --git a/polymer/build/src/mmultirm.c b/polymer/build/src/mmultirm.c index b75ff8fb4..52dd6e8d3 100755 --- a/polymer/build/src/mmultirm.c +++ b/polymer/build/src/mmultirm.c @@ -14,7 +14,7 @@ #define WIN32_LEAN_AND_MEAN #include #include -#define SOCKET int +#define SOCKET signed int #define EWOULDBLOCK WSAEWOULDBLOCK #define ECONNREFUSED WSAECONNRESET #define netstrerror() win32netstrerror() @@ -31,7 +31,7 @@ #include #include #include -#define SOCKET int +#define SOCKET signed int #define INVALID_HANDLE_VALUE (-1) #define INVALID_SOCKET (-1) #define SOCKET_ERROR (-1) @@ -59,9 +59,9 @@ #define IPSEG3(ip) ((((unsigned int) ip) & 0x0000FF00) >> 8) #define IPSEG4(ip) ((((unsigned int) ip) & 0x000000FF) ) -#define BUILD_DEFAULT_UDP_PORT 1635 /* eh...why not? */ +#define BUILD_DEFAULT_UDP_PORT 23513 #define CLIENT_POLL_DELAY 3000 /* ms between pings at peer-to-peer startup. */ -#define HEADER_PEER_GREETING 245 +#define HEADER_PEER_GREETING 246 /* increment this by one so Duke3d_w32 doesn't accept EDuke32 players and vice-versa */ static SOCKET udpsocket = -1; static short udpport = BUILD_DEFAULT_UDP_PORT; @@ -239,7 +239,8 @@ void initmultiplayers(long argc, char **argv, char damultioption, char dacomrate connecthead = 0; for (i=0;i=0;i=connectpoint2[i]) if (i != myconnectindex) - { + { + sampletimer(); if (totalclock < lastsendtime[i]) lastsendtime[i] = totalclock; if (totalclock > lastsendtime[i]+timeoutcount) { @@ -480,11 +483,14 @@ short getpacket(short *other, char *bufptr) initprintf("\n%ld CNT",gcom->buffer[0]); #endif } -#if (PRINTERRORS) else { - if (!(gcom->buffer[1]&128)) /* single else double packet */ - initprintf("\n%ld cnt",gcom->buffer[0]); + if (!(gcom->buffer[1]&128)) /* single else double packet */ + { +#if (PRINTERRORS) + initprintf("\n%ld cnt",gcom->buffer[0]); +#endif + } else { if (((gcom->buffer[0]+1)&255) == (incnt[*other]&255)) @@ -498,12 +504,13 @@ short getpacket(short *other, char *bufptr) Bmemcpy(bufptr,&gcom->buffer[messleng+5],lastpacketleng); incnt[*other]++; return(lastpacketleng); - } + } +#if (PRINTERRORS) else - initprintf("\n%ld-%ld cnt ",gcom->buffer[0],(gcom->buffer[0]+1)&255); + initprintf("\n%ld-%ld cnt ",gcom->buffer[0],(gcom->buffer[0]+1)&255); +#endif } } -#endif return(0); } @@ -964,7 +971,7 @@ typedef struct unsigned char dummy1; /* so these don't confuse game after load. */ unsigned char dummy2; /* so these don't confuse game after load. */ unsigned char dummy3; /* so these don't confuse game after load. */ - unsigned char header; /* always HEADER_PEER_GREETING (245). */ + unsigned char header; /* always HEADER_PEER_GREETING (246). */ unsigned short id; } PacketPeerGreeting; @@ -1075,9 +1082,9 @@ static int connect_to_everyone(gcomtype *gcom, int myip, int bcast) } #ifdef _WIN32 - Sleep(10); + Sleep(1); #else - usleep(10); + usleep(1); #endif process_udp_send_queue(); @@ -1318,16 +1325,16 @@ static int initialize_sockets(void) #ifdef _WIN32 int rc; WSADATA data; - initprintf("initializing WinSock...\n"); + initprintf("initializing Winsock...\n"); rc = WSAStartup(0x0101, &data); if (rc != 0) { - initprintf("WinSock failed to initialize! [err==%d].\n", rc); + initprintf("Winsock failed to initialize! [err==%d].\n", rc); return(0); } else { - initprintf("WinSock initialized.\n"); + initprintf("Winsock initialized.\n"); initprintf(" - Caller uses version %d.%d, highest supported is %d.%d.\n", data.wVersion >> 8, data.wVersion & 0xFF, data.wHighVersion >> 8, data.wHighVersion & 0xFF); diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index 4b7121853..5420f05b9 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -482,7 +482,9 @@ void getpackets(void) if (numplayers < 2) return; while ((packbufleng = getpacket(&other,packbuf)) > 0) { +#ifdef TESTNET initprintf("RECEIVED PACKET: type: %d : len %d\n", packbuf[0], packbufleng); +#endif switch (packbuf[0]) { case 254: @@ -895,8 +897,9 @@ void getpackets(void) break; case 250: + if (playerreadyflag[other] == 0) + initprintf("Player %ld is ready\n", other); playerreadyflag[other]++; - initprintf("Player %ld is ready...\n", other); break; case 255: gameexit(" "); diff --git a/polymer/eduke32/source/menus.c b/polymer/eduke32/source/menus.c index 288624808..b9e556abb 100644 --- a/polymer/eduke32/source/menus.c +++ b/polymer/eduke32/source/menus.c @@ -4677,6 +4677,9 @@ VOLUME_ALL_40x: if ((!networkmode) && (myconnectindex != connecthead)) break; //slaves in M/S mode only send to master } } + if ((gametype_flags[ud.m_coop] & GAMETYPE_FLAG_PLAYERSFRIENDLY) && !(gametype_flags[ud.m_coop] & GAMETYPE_FLAG_TDM)) + ud.m_noexits = 0; + cmenu(603); } break; diff --git a/polymer/eduke32/source/premap.c b/polymer/eduke32/source/premap.c index 892a9809f..a7cc469c5 100644 --- a/polymer/eduke32/source/premap.c +++ b/polymer/eduke32/source/premap.c @@ -1423,7 +1423,6 @@ 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 }