mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-12-25 03:00:46 +00:00
Master/slave code
git-svn-id: https://svn.eduke32.com/eduke32@1130 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
622ab399d5
commit
95ea7c8146
3 changed files with 115 additions and 86 deletions
|
@ -81,7 +81,7 @@ ifeq ($(PLATFORM),DARWIN)
|
||||||
endif
|
endif
|
||||||
ifeq ($(PLATFORM),WINDOWS)
|
ifeq ($(PLATFORM),WINDOWS)
|
||||||
RENDERTYPE ?= WIN
|
RENDERTYPE ?= WIN
|
||||||
BUILDCFLAGS+= -DHAVE_INTTYPES
|
BUILDCFLAGS+= -DHAVE_INTTYPES -march=i686
|
||||||
EXESUFFIX=.exe
|
EXESUFFIX=.exe
|
||||||
LIBS+= -lmingwex -lwinmm -L$(DXROOT)/lib -lwsock32 -lcomctl32 #-lshfolder
|
LIBS+= -lmingwex -lwinmm -L$(DXROOT)/lib -lwsock32 -lcomctl32 #-lshfolder
|
||||||
# STDCPPLIB=-lstdc++
|
# STDCPPLIB=-lstdc++
|
||||||
|
|
|
@ -1015,9 +1015,8 @@ static void send_peer_greeting(int ip, short port, short myid)
|
||||||
/* server init. */
|
/* server init. */
|
||||||
static int wait_for_other_players(gcomtype *gcom, int myip)
|
static int wait_for_other_players(gcomtype *gcom, int myip)
|
||||||
{
|
{
|
||||||
#if 1
|
|
||||||
PacketPeerGreeting packet;
|
PacketPeerGreeting packet;
|
||||||
unsigned short my_id = 0;
|
unsigned short my_id = 1;
|
||||||
int i, j;
|
int i, j;
|
||||||
int rc;
|
int rc;
|
||||||
int ip;
|
int ip;
|
||||||
|
@ -1053,21 +1052,25 @@ static int wait_for_other_players(gcomtype *gcom, int myip)
|
||||||
{
|
{
|
||||||
char *ipstr = static_ipstring(ip);
|
char *ipstr = static_ipstring(ip);
|
||||||
|
|
||||||
|
if (rc != sizeof(packet))
|
||||||
|
{
|
||||||
|
initprintf("mmulti_unstable: Missized packet or fragment from %s:%i ?!\n", ipstr, port);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else if (packet.header != HEADER_PEER_GREETING)
|
||||||
|
{
|
||||||
|
initprintf("mmulti_unstable: Unexpected packet type from %s:%i ?!\n", ipstr, port);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < max; i++)
|
for (i = 0; i < max; i++)
|
||||||
{
|
{
|
||||||
if (!allowed_addresses[i].host)
|
if (!heard_from[i] || heard_from[i] == B_SWAP16(packet.id))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i == max)
|
if (i == max)
|
||||||
initprintf("mmulti_unstable: Disallowed player %s:%d ?!\n", ipstr, port);
|
initprintf("mmulti_unstable: Disallowed player %s:%d ?!\n", ipstr, port);
|
||||||
|
|
||||||
else if (rc != sizeof(packet))
|
|
||||||
initprintf("mmulti_unstable: Missized packet or fragment from %s:%i ?!\n", ipstr, port);
|
|
||||||
|
|
||||||
else if (packet.header != HEADER_PEER_GREETING)
|
|
||||||
initprintf("mmulti_unstable: Unexpected packet type from %s:%i ?!\n", ipstr, port);
|
|
||||||
|
|
||||||
else if (heard_from[i] == 0)
|
else if (heard_from[i] == 0)
|
||||||
{
|
{
|
||||||
packet.id = B_SWAP16(packet.id);
|
packet.id = B_SWAP16(packet.id);
|
||||||
|
@ -1076,23 +1079,30 @@ static int wait_for_other_players(gcomtype *gcom, int myip)
|
||||||
allowed_addresses[i].port = port;
|
allowed_addresses[i].port = port;
|
||||||
remaining--;
|
remaining--;
|
||||||
|
|
||||||
initprintf("Connected to %s:%i (id 0x%X). %d player%s to go.\n",
|
initprintf("%s:%i (id 0x%X) connected, %d player%s left.\n",
|
||||||
ipstr, port ,(int) packet.id,
|
ipstr, port ,(int) packet.id,
|
||||||
remaining, remaining == 1 ? "" : "s");
|
remaining, remaining == 1 ? "" : "s");
|
||||||
|
|
||||||
/* make sure they've heard from us at all... */
|
/* make sure they've heard from us at all... */
|
||||||
/* !!! FIXME: Could be fatal if packet is dropped... */
|
/* !!! FIXME: Could be fatal if packet is dropped... */
|
||||||
/*
|
|
||||||
send_peer_greeting(allowed_addresses[i].host,
|
send_peer_greeting(allowed_addresses[i].host,
|
||||||
allowed_addresses[i].port,
|
allowed_addresses[i].port,
|
||||||
my_id);
|
my_id);
|
||||||
*/
|
|
||||||
for (j=i;j>0;j--)
|
// resend greeting to other clients so they get ID for sorting
|
||||||
|
/* for (j=i;j>=0;j--)
|
||||||
|
{
|
||||||
|
int ii;
|
||||||
|
for (ii = 1; ii < max; ii++)
|
||||||
|
send_peer_greeting(allowed_addresses[j].host,
|
||||||
|
allowed_addresses[j].port,
|
||||||
|
heard_from[ii]);
|
||||||
|
|
||||||
send_peer_greeting(allowed_addresses[j].host,
|
send_peer_greeting(allowed_addresses[j].host,
|
||||||
allowed_addresses[j].port,
|
allowed_addresses[j].port,
|
||||||
heard_from[i]);
|
heard_from[i]);
|
||||||
|
}*/
|
||||||
tmpmax[i] = 1; //addfaz line addition
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1102,15 +1112,20 @@ static int wait_for_other_players(gcomtype *gcom, int myip)
|
||||||
initprintf("Connection attempt aborted.\n");
|
initprintf("Connection attempt aborted.\n");
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
// found all the clients expected so send them our greeting
|
||||||
for (j=max;j>0;j--)
|
for (j=max;j>=0;j--)
|
||||||
if (allowed_addresses[j].host)
|
if (allowed_addresses[j].host)
|
||||||
{
|
{
|
||||||
|
int ii;
|
||||||
|
for (ii = 0; ii < max; ii++)
|
||||||
send_peer_greeting(allowed_addresses[j].host,
|
send_peer_greeting(allowed_addresses[j].host,
|
||||||
allowed_addresses[j].port,
|
allowed_addresses[j].port,
|
||||||
my_id);
|
heard_from[ii]);
|
||||||
}
|
|
||||||
|
send_peer_greeting(allowed_addresses[j].host,
|
||||||
|
allowed_addresses[j].port,
|
||||||
|
1337);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ok, now everyone is talking to you. Sort them into player numbers... */
|
/* ok, now everyone is talking to you. Sort them into player numbers... */
|
||||||
|
@ -1183,13 +1198,11 @@ static int wait_for_other_players(gcomtype *gcom, int myip)
|
||||||
initprintf("mmulti_unstable: We are player #%i\n", gcom->myconnectindex);
|
initprintf("mmulti_unstable: We are player #%i\n", gcom->myconnectindex);
|
||||||
|
|
||||||
return(1);
|
return(1);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* client init. */
|
/* client init. */
|
||||||
static int connect_to_server(gcomtype *gcom, int myip)
|
static int connect_to_server(gcomtype *gcom, int myip)
|
||||||
{
|
{
|
||||||
#if 1
|
|
||||||
PacketPeerGreeting packet;
|
PacketPeerGreeting packet;
|
||||||
unsigned short my_id = 0;
|
unsigned short my_id = 0;
|
||||||
int i;
|
int i;
|
||||||
|
@ -1204,6 +1217,8 @@ static int connect_to_server(gcomtype *gcom, int myip)
|
||||||
|
|
||||||
memset(heard_from, '\0', sizeof(heard_from));
|
memset(heard_from, '\0', sizeof(heard_from));
|
||||||
|
|
||||||
|
gcom->numplayers = 2;
|
||||||
|
|
||||||
while (my_id == 0) /* player number is based on id, low to high. */
|
while (my_id == 0) /* player number is based on id, low to high. */
|
||||||
{
|
{
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
|
@ -1259,48 +1274,53 @@ static int connect_to_server(gcomtype *gcom, int myip)
|
||||||
{
|
{
|
||||||
char *ipstr = static_ipstring(ip);
|
char *ipstr = static_ipstring(ip);
|
||||||
|
|
||||||
for (i = 0; i < max; i++)
|
if (rc != sizeof(packet))
|
||||||
{
|
{
|
||||||
if (!allowed_addresses[i].host)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i == max)
|
|
||||||
initprintf("mmulti_unstable: Disallowed player %s:%d ?!\n", ipstr, port);
|
|
||||||
|
|
||||||
else if (rc != sizeof(packet))
|
|
||||||
initprintf("mmulti_unstable: Missized packet or fragment from %s:%i ?!\n", ipstr, port);
|
initprintf("mmulti_unstable: Missized packet or fragment from %s:%i ?!\n", ipstr, port);
|
||||||
|
continue;
|
||||||
else if (packet.header != HEADER_PEER_GREETING)
|
|
||||||
initprintf("mmulti_unstable: Unexpected packet type from %s:%i ?!\n", ipstr, port);
|
|
||||||
|
|
||||||
else if (heard_from[i] == 0 && B_SWAP16(packet.id) == 0)
|
|
||||||
{
|
|
||||||
packet.id = B_SWAP16(packet.id);
|
|
||||||
heard_from[i] = packet.id;
|
|
||||||
allowed_addresses[i].host = ip; /* bcast needs this. */
|
|
||||||
allowed_addresses[i].port = port;
|
|
||||||
remaining--;
|
|
||||||
|
|
||||||
initprintf("Connected to %s:%i (id 0x%X). %d player%s to go.\n",
|
|
||||||
ipstr, port ,(int) packet.id,
|
|
||||||
remaining, remaining == 1 ? "" : "s");
|
|
||||||
|
|
||||||
tmpmax[i] = 1; //addfaz line addition
|
|
||||||
}
|
}
|
||||||
else if (heard_from[i] == 0 && B_SWAP16(packet.id) != 0)
|
else if (packet.header != HEADER_PEER_GREETING)
|
||||||
|
{
|
||||||
|
initprintf("mmulti_unstable: Unexpected packet type from %s:%i ?!\n", ipstr, port);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i=0;i<MAX_PLAYERS;i++)
|
||||||
|
if (!heard_from[i] || heard_from[i] == B_SWAP16(packet.id)) break; // only increase once
|
||||||
|
|
||||||
|
if (B_SWAP16(packet.id) == 1337)
|
||||||
|
{
|
||||||
|
remaining = 0;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else if (heard_from[i] == 0 && B_SWAP16(packet.id) == 1)
|
||||||
|
{
|
||||||
|
packet.id = B_SWAP16(packet.id);
|
||||||
|
heard_from[i] = packet.id;
|
||||||
|
// allowed_addresses[i].host = ip; /* bcast needs this. */
|
||||||
|
// allowed_addresses[i].port = port;
|
||||||
|
|
||||||
|
initprintf("Connected to %s:%i\n",
|
||||||
|
ipstr, port);
|
||||||
|
initprintf("Waiting for server to launch game\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// for (i=0;i<MAX_PLAYERS;i++)
|
||||||
|
{
|
||||||
|
if (heard_from[i] == 0 && B_SWAP16(packet.id) != my_id)
|
||||||
{
|
{
|
||||||
packet.id = B_SWAP16(packet.id);
|
packet.id = B_SWAP16(packet.id);
|
||||||
heard_from[i] = packet.id;
|
heard_from[i] = packet.id;
|
||||||
|
|
||||||
initprintf("Connected to %s:%i (id 0x%X). %d player%s to go.\n",
|
initprintf("New player with id 0x%X\n",
|
||||||
ipstr, port ,(int) packet.id,
|
(int) packet.id);
|
||||||
remaining, remaining == 1 ? "" : "s");
|
|
||||||
gcom->numplayers++;
|
gcom->numplayers++;
|
||||||
max++;
|
max++;
|
||||||
tmpmax[i] = 1; //addfaz line addition
|
// initprintf("max %d np %d\n",max,gcom->numplayers);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1366,25 +1386,22 @@ static int connect_to_server(gcomtype *gcom, int myip)
|
||||||
{
|
{
|
||||||
ip = (allowed_addresses[i].host);
|
ip = (allowed_addresses[i].host);
|
||||||
|
|
||||||
|
|
||||||
if (ip == myip)
|
if (ip == myip)
|
||||||
{
|
{
|
||||||
if (udpport == allowed_addresses[i].port)
|
if (udpport == allowed_addresses[i].port)
|
||||||
gcom->myconnectindex = i;
|
gcom->myconnectindex = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
initprintf("mmulti_unstable: player #%i at %s:%i\n", i,static_ipstring(ip),allowed_addresses[i].port);
|
initprintf("mmulti_unstable: player #%i with id %d\n", i,heard_from[i]);
|
||||||
}
|
}
|
||||||
// assert(gcom->myconnectindex);
|
// assert(gcom->myconnectindex);
|
||||||
|
|
||||||
initprintf("mmulti_unstable: We are player #%i\n", gcom->myconnectindex);
|
initprintf("mmulti_unstable: We are player #%i\n", gcom->myconnectindex);
|
||||||
|
|
||||||
return(1);
|
return(1);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* peer to peer init. */
|
/* peer to peer init. */
|
||||||
static int connect_to_everyone(gcomtype *gcom, int myip, int bcast)
|
static int connect_to_everyone(gcomtype *gcom, int myip, int bcast)
|
||||||
{
|
{
|
||||||
|
@ -1731,7 +1748,7 @@ static int initialize_sockets(void)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* initprintf("WinSock initialized.\n");
|
/* initprintf("WinSock initialized.\n");
|
||||||
initprintf(" - Caller uses version %d.%d, highest supported is %d.%d.\n",
|
initprintf(" - Caller uses version %d.%d, highest supported is %d.%d.\n",
|
||||||
data.wVersion >> 8, data.wVersion & 0xFF,
|
data.wVersion >> 8, data.wVersion & 0xFF,
|
||||||
data.wHighVersion >> 8, data.wHighVersion & 0xFF);
|
data.wHighVersion >> 8, data.wHighVersion & 0xFF);
|
||||||
|
@ -1833,6 +1850,18 @@ static int parse_udp_config(const char *cfgfile, gcomtype *gcom)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if (Bstrcasecmp(tok, "players") == 0)
|
||||||
|
{
|
||||||
|
if ((tok = get_token(&ptr)) != NULL)
|
||||||
|
{
|
||||||
|
bogus = 0;
|
||||||
|
if (udpmode == udpmode_server)
|
||||||
|
gcom->numplayers = atoi(tok)-1;
|
||||||
|
else
|
||||||
|
bogus = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (bogus)
|
if (bogus)
|
||||||
initprintf("bogus token! [%s]\n", tok);
|
initprintf("bogus token! [%s]\n", tok);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue