diff --git a/relay/crefmgr.cpp b/relay/crefmgr.cpp index 9a4d3cd69..0778b5981 100644 --- a/relay/crefmgr.cpp +++ b/relay/crefmgr.cpp @@ -93,7 +93,7 @@ CRefMgr::CloseAll() CookieRef* CRefMgr::FindOpenGameFor( const char* cORn, bool isCookie, - HostID hid, int nPlayersH, int nPlayersT ) + HostID hid, int socket, int nPlayersH, int nPlayersT ) { logf( XW_LOGINFO, "%s(%s)", __func__, cORn ); CookieRef* cref = NULL; @@ -106,6 +106,9 @@ CRefMgr::FindOpenGameFor( const char* cORn, bool isCookie, if ( 0 == strcmp( cref->Cookie(), cORn ) ) { if ( cref->NeverFullyConnected() ) { break; + } else if ( cref->HasSocket(socket) ) { + logf( XW_LOGINFO, "%s: HasSocket case", __func__ ); + break; } } } else { @@ -154,7 +157,7 @@ CRefMgr::cookieIDForConnName( const char* connName ) CookieRef* CRefMgr::getMakeCookieRef_locked( const char* cORn, bool isCookie, HostID hid, - int nPlayersH, int nPlayersT ) + int socket, int nPlayersH, int nPlayersT ) { CookieRef* cref; @@ -168,10 +171,11 @@ CRefMgr::getMakeCookieRef_locked( const char* cORn, bool isCookie, HostID hid, /* We have a cookie from a new connection. This may be the first time it's been seen, or there may be a game currently in the - XW_ST_CONNECTING state. So we need to look up the cookie first, then - generate new connName and cookieIDs if it's not found. */ + XW_ST_CONNECTING state, or it may be a dupe of a connect packet. So we + need to look up the cookie first, then generate new connName and + cookieIDs if it's not found. */ - cref = FindOpenGameFor( cORn, isCookie, hid, nPlayersH, nPlayersT ); + cref = FindOpenGameFor( cORn, isCookie, hid, socket, nPlayersH, nPlayersT ); if ( cref == NULL ) { string s; const char* connName; @@ -562,14 +566,14 @@ CookieMapIterator::Next() // SafeCref ////////////////////////////////////////////////////////////////////////////// -SafeCref::SafeCref( const char* cORn, bool isCookie, HostID hid, +SafeCref::SafeCref( const char* cORn, bool isCookie, HostID hid, int socket, int nPlayersH, int nPlayersT ) : m_cref( NULL ) , m_mgr( CRefMgr::Get() ) { CookieRef* cref; - cref = m_mgr->getMakeCookieRef_locked( cORn, isCookie, hid, + cref = m_mgr->getMakeCookieRef_locked( cORn, isCookie, hid, socket, nPlayersH, nPlayersT ); if ( cref != NULL ) { if ( m_mgr->LockCref( cref ) ) { diff --git a/relay/crefmgr.h b/relay/crefmgr.h index 3ce123a8b..e09e3e316 100644 --- a/relay/crefmgr.h +++ b/relay/crefmgr.h @@ -79,7 +79,7 @@ class CRefMgr { private: friend class SafeCref; CookieRef* getMakeCookieRef_locked( const char* cORn, bool isCookie, - HostID hid, + HostID hid, int socket, int nPlayersH, int nPlayersT ); CookieRef* getCookieRef_locked( CookieID cookieID ); CookieRef* getCookieRef_locked( int socket ); @@ -87,7 +87,7 @@ class CRefMgr { CookieRef* getCookieRef_impl( CookieID cookieID ); CookieRef* AddNew( const char* cookie, const char* connName, CookieID id ); CookieRef* FindOpenGameFor( const char* cORn, bool isCookie, - HostID hid, int nPlayersH, int nPlayersT ); + HostID hid, int socket, int nPlayersH, int nPlayersT ); CookieID cookieIDForConnName( const char* connName ); CookieID nextCID( const char* connName ); @@ -120,7 +120,7 @@ class SafeCref { public: SafeCref( const char* cookieOrConnName, bool cookie, HostID hid, - int nPlayersH, int nPlayersT ); + int socket, int nPlayersH, int nPlayersT ); SafeCref( CookieID cid ); SafeCref( int socket ); SafeCref( CookieRef* cref ); diff --git a/relay/xwrelay.cpp b/relay/xwrelay.cpp index fa1091fcf..7928643cb 100644 --- a/relay/xwrelay.cpp +++ b/relay/xwrelay.cpp @@ -273,7 +273,7 @@ processConnect( unsigned char* bufp, int bufLen, int socket ) && getNetByte( &bufp, end, &nPlayersH ) && getNetByte( &bufp, end, &nPlayersT ) ) { - SafeCref scr( cookie, 1, srcID, nPlayersH, nPlayersT ); + SafeCref scr( cookie, 1, srcID, socket, nPlayersH, nPlayersT ); success = scr.Connect( socket, srcID, nPlayersH, nPlayersT ); } @@ -308,7 +308,7 @@ processReconnect( unsigned char* bufp, int bufLen, int socket ) && getNetByte( &bufp, end, &nPlayersT ) && readStr( &bufp, end, connName, sizeof(connName) ) ) { - SafeCref scr( connName, 0, srcID, nPlayersH, nPlayersT ); + SafeCref scr( connName, 0, srcID, socket, nPlayersH, nPlayersT ); success = scr.Reconnect( socket, srcID, nPlayersH, nPlayersT ); }