git-svn-id: https://svn.eduke32.com/eduke32@365 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2006-11-29 10:30:25 +00:00
parent 44fcea85a8
commit 270d573af3
5 changed files with 67 additions and 25 deletions

View File

@ -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;

View File

@ -14,7 +14,7 @@
#define WIN32_LEAN_AND_MEAN
#include <winsock2.h>
#include <ws2tcpip.h>
#define SOCKET int
#define SOCKET signed int
#define EWOULDBLOCK WSAEWOULDBLOCK
#define ECONNREFUSED WSAECONNRESET
#define netstrerror() win32netstrerror()
@ -31,7 +31,7 @@
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <netdb.h>
#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<numplayers-1;i++) connectpoint2[i] = i+1;
connectpoint2[numplayers-1] = -1;
sampletimer();
for (i=0;i<numplayers;i++) lastsendtime[i] = totalclock;
}
@ -346,8 +347,9 @@ void sendpacket(long other, char *bufptr, long messleng)
bakpacketbuf[(bakpacketplc+i)&(BAKSIZ-1)] = bufptr[i];
bakpacketplc = ((bakpacketplc+messleng)&(BAKSIZ-1));
}
outcntend[other]++;
outcntend[other]++;
sampletimer();
lastsendtime[other] = totalclock;
dosendpackets(other);
}
@ -406,7 +408,8 @@ short getpacket(short *other, char *bufptr)
for (i=connecthead;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);

View File

@ -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(" ");

View File

@ -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;

View File

@ -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
}