From 5311ea4f7ac4f3fe90239b526505071a384a13e3 Mon Sep 17 00:00:00 2001 From: Cliff Gordon Date: Wed, 6 May 2015 14:59:45 -0500 Subject: [PATCH 1/2] [fix/nat_multiplayer] Vestigare's submitted patch for allowing multiple users behind a NAT to connect to a remote standalone. --- code/network/multi.cpp | 7 +++++-- code/network/psnet2.cpp | 9 ++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/code/network/multi.cpp b/code/network/multi.cpp index d20e5e76292..f0dc860abdd 100644 --- a/code/network/multi.cpp +++ b/code/network/multi.cpp @@ -49,6 +49,7 @@ #include "fs2netd/fs2netd_client.h" #include "pilotfile/pilotfile.h" #include "debugconsole/console.h" +#include "network/psnet2.h" @@ -337,9 +338,11 @@ void multi_check_listen() } // the connection was accepted in check_for_listen. Find the netplayer whose address we connected - // with and assign the socket descriptor + // with and assign the socket descriptor. + // Updated to utilize psnet_same() for address comparison so the port is also taken into account. + // This allows multiple players using NAT to access a remote server simultneously. for (i = 0; i < MAX_PLAYERS; i++ ) { - if ( (Net_players[i].flags & NETINFO_FLAG_CONNECTED) && (!memcmp(&(addr.addr), &(Net_players[i].p_info.addr.addr), 6)) ) { + if ( (Net_players[i].flags & NETINFO_FLAG_CONNECTED) && (psnet_same(&addr, &(Net_players[i].p_info.addr))) ) { // mark this flag so we know he's "fully" connected Net_players[i].flags |= NETINFO_FLAG_RELIABLE_CONNECTED; Net_players[i].reliable_socket = sock; diff --git a/code/network/psnet2.cpp b/code/network/psnet2.cpp index 86c38bad9cc..eca81221cf1 100644 --- a/code/network/psnet2.cpp +++ b/code/network/psnet2.cpp @@ -905,7 +905,14 @@ void psnet_string_to_addr( net_addr * address, char * text ) */ int psnet_same( net_addr * a1, net_addr * a2 ) { - return !memcmp(a1->addr, a2->addr, 6); + int same_player_check = !memcmp(a1->addr, a2->addr, 6); + + if ( same_player_check ) + { + same_player_check = a1->port == a2->port; + } + + return same_player_check; } /** From 6e0f9c1cd2316643961de3517713a9e009bb10a5 Mon Sep 17 00:00:00 2001 From: Cliff Gordon Date: Mon, 29 Jun 2015 16:51:49 -0500 Subject: [PATCH 2/2] [fix/nat_multiplayer] Simplify the new psnet check. --- code/network/psnet2.cpp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/code/network/psnet2.cpp b/code/network/psnet2.cpp index eca81221cf1..d98a3ebfad4 100644 --- a/code/network/psnet2.cpp +++ b/code/network/psnet2.cpp @@ -905,14 +905,7 @@ void psnet_string_to_addr( net_addr * address, char * text ) */ int psnet_same( net_addr * a1, net_addr * a2 ) { - int same_player_check = !memcmp(a1->addr, a2->addr, 6); - - if ( same_player_check ) - { - same_player_check = a1->port == a2->port; - } - - return same_player_check; + return !memcmp(a1->addr, a2->addr, 6) && a1->port == a2->port; } /**