- Set packet server as the default for four or more player games, and also the

default for three player games where the other players are not in the same
  private IP range.




SVN r1364 (trunk)
This commit is contained in:
Randy Heit 2009-01-24 04:47:07 +00:00
parent c5ca865a7f
commit b5a5204911
4 changed files with 80 additions and 6 deletions

View file

@ -3,6 +3,11 @@ January 24, 2009 (Changes by Graf Zahl)
- Fixed: With COMPAT_TRACE switched on linedef actions on lines having
the same sector on both sides were not triggered.
January 23, 2009
- Set packet server as the default for four or more player games, and also the
default for three player games where the other players are not in the same
private IP range.
January 18, 2009 (Changes by Graf Zahl)
- Added a CopyInfo function to FTexture that contains all code required to
clone a texture. Used for creating warping textures.

View file

@ -1583,12 +1583,16 @@ void D_CheckNetGame (void)
}
// I_InitNetwork sets doomcom and netgame
I_InitNetwork ();
if (I_InitNetwork ())
{
NetMode = NET_PacketServer;
}
if (doomcom.id != DOOMCOM_ID)
{
I_FatalError ("Doomcom buffer invalid!");
}
players[0].settings_controller = true;
consoleplayer = doomcom.consoleplayer;
v = Args->CheckValue ("-netmode");
@ -1596,6 +1600,11 @@ void D_CheckNetGame (void)
{
NetMode = atoi (v) != 0 ? NET_PacketServer : NET_PeerToPeer;
}
if (doomcom.numnodes > 1)
{
Printf ("Selected " TEXTCOLOR_BLUE "%s" TEXTCOLOR_NORMAL " networking mode. (%s)\n", NetMode == NET_PeerToPeer ? "peer to peer" : "packet server",
v != NULL ? "forced" : "auto");
}
// [RH] Setup user info
D_SetupUserInfo ();

View file

@ -777,10 +777,64 @@ void JoinGame (int i)
doomcom.numplayers = doomcom.numnodes;
}
static int PrivateNetOf(in_addr in)
{
int addr = ntohl(in.s_addr);
if ((addr & 0xFFFF0000) == 0xC0A80000) // 192.168.0.0
{
return 0xC0A80000;
}
else if ((addr & 0xFFF00000) == 0xAC100000) // 172.16.0.0
{
return 0xAC100000;
}
else if ((addr & 0xFF000000) == 0x0A000000) // 10.0.0.0
{
return 0x0A000000;
}
else if ((addr & 0xFF000000) == 0x7F000000) // 127.0.0.0 (localhost)
{
return 0x7F000000;
}
// Not a private IP
return 0;
}
//
// NodesOnSameNetwork
//
// The best I can really do here is check if the others are on the same
// private network, since that means we (probably) are too.
//
static bool NodesOnSameNetwork()
{
int net1;
net1 = PrivateNetOf(sendaddress[1].sin_addr);
// Printf("net1 = %08x\n", net1);
if (net1 == 0)
{
return false;
}
for (int i = 2; i < doomcom.numnodes; ++i)
{
int net = PrivateNetOf(sendaddress[i].sin_addr);
// Printf("Net[%d] = %08x\n", i, net);
if (net != net1)
{
return false;
}
}
return true;
}
//
// I_InitNetwork
//
void I_InitNetwork (void)
// Returns true if packet server mode might be a good idea.
//
bool I_InitNetwork (void)
{
int i;
char *v;
@ -829,8 +883,14 @@ void I_InitNetwork (void)
doomcom.id = DOOMCOM_ID;
doomcom.numplayers = doomcom.numnodes = 1;
doomcom.consoleplayer = 0;
return;
return false;
}
if (doomcom.numnodes < 3)
{ // Packet server mode with only two players is effectively the same as
// peer-to-peer but with some slightly larger packets.
return false;
}
return doomcom.numnodes > 3 || !NodesOnSameNetwork();
}

View file

@ -24,7 +24,7 @@
#define __I_NET_H__
// Called by D_DoomMain.
void I_InitNetwork (void);
bool I_InitNetwork (void);
void I_NetCmd (void);
#endif