Skip to content

Commit

Permalink
Merge pull request #77 from chief1983/fix/nat_multiplayer
Browse files Browse the repository at this point in the history
[fix/nat_multiplayer] Fix for multiple users behind a NAT
  • Loading branch information
Goober5000 committed Jun 30, 2015
2 parents 0a9ae3e + 6e0f9c1 commit bd18c88
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions code/network/multi.cpp
Expand Up @@ -49,6 +49,7 @@
#include "fs2netd/fs2netd_client.h"
#include "pilotfile/pilotfile.h"
#include "debugconsole/console.h"
#include "network/psnet2.h"



Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion code/network/psnet2.cpp
Expand Up @@ -905,7 +905,7 @@ 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);
return !memcmp(a1->addr, a2->addr, 6) && a1->port == a2->port;
}

/**
Expand Down

0 comments on commit bd18c88

Please sign in to comment.