From b5a52049116610204bdd134324efc3bd4678ab81 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Sat, 24 Jan 2009 04:47:07 +0000 Subject: [PATCH] - 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) --- docs/rh-log.txt | 5 ++++ src/d_net.cpp | 15 +++++++++--- src/i_net.cpp | 64 +++++++++++++++++++++++++++++++++++++++++++++++-- src/i_net.h | 2 +- 4 files changed, 80 insertions(+), 6 deletions(-) diff --git a/docs/rh-log.txt b/docs/rh-log.txt index da3473894..7e9621ba6 100644 --- a/docs/rh-log.txt +++ b/docs/rh-log.txt @@ -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. diff --git a/src/d_net.cpp b/src/d_net.cpp index 89c4043c0..d480ab61f 100644 --- a/src/d_net.cpp +++ b/src/d_net.cpp @@ -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 (); diff --git a/src/i_net.cpp b/src/i_net.cpp index e9945d2a5..caa3a61fb 100644 --- a/src/i_net.cpp +++ b/src/i_net.cpp @@ -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(); } diff --git a/src/i_net.h b/src/i_net.h index b5630c4c1..53e835702 100644 --- a/src/i_net.h +++ b/src/i_net.h @@ -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