detect duplicate initial connect packets by checking what socket they're on.

This commit is contained in:
ehouse 2009-02-07 18:17:17 +00:00
parent 1fa517693a
commit 628b39ba65
3 changed files with 16 additions and 12 deletions

View file

@ -93,7 +93,7 @@ CRefMgr::CloseAll()
CookieRef* CookieRef*
CRefMgr::FindOpenGameFor( const char* cORn, bool isCookie, 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 ); logf( XW_LOGINFO, "%s(%s)", __func__, cORn );
CookieRef* cref = NULL; CookieRef* cref = NULL;
@ -106,6 +106,9 @@ CRefMgr::FindOpenGameFor( const char* cORn, bool isCookie,
if ( 0 == strcmp( cref->Cookie(), cORn ) ) { if ( 0 == strcmp( cref->Cookie(), cORn ) ) {
if ( cref->NeverFullyConnected() ) { if ( cref->NeverFullyConnected() ) {
break; break;
} else if ( cref->HasSocket(socket) ) {
logf( XW_LOGINFO, "%s: HasSocket case", __func__ );
break;
} }
} }
} else { } else {
@ -154,7 +157,7 @@ CRefMgr::cookieIDForConnName( const char* connName )
CookieRef* CookieRef*
CRefMgr::getMakeCookieRef_locked( const char* cORn, bool isCookie, HostID hid, CRefMgr::getMakeCookieRef_locked( const char* cORn, bool isCookie, HostID hid,
int nPlayersH, int nPlayersT ) int socket, int nPlayersH, int nPlayersT )
{ {
CookieRef* cref; 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 /* 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 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 XW_ST_CONNECTING state, or it may be a dupe of a connect packet. So we
generate new connName and cookieIDs if it's not found. */ 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 ) { if ( cref == NULL ) {
string s; string s;
const char* connName; const char* connName;
@ -562,14 +566,14 @@ CookieMapIterator::Next()
// SafeCref // 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 ) int nPlayersH, int nPlayersT )
: m_cref( NULL ) : m_cref( NULL )
, m_mgr( CRefMgr::Get() ) , m_mgr( CRefMgr::Get() )
{ {
CookieRef* cref; CookieRef* cref;
cref = m_mgr->getMakeCookieRef_locked( cORn, isCookie, hid, cref = m_mgr->getMakeCookieRef_locked( cORn, isCookie, hid, socket,
nPlayersH, nPlayersT ); nPlayersH, nPlayersT );
if ( cref != NULL ) { if ( cref != NULL ) {
if ( m_mgr->LockCref( cref ) ) { if ( m_mgr->LockCref( cref ) ) {

View file

@ -79,7 +79,7 @@ class CRefMgr {
private: private:
friend class SafeCref; friend class SafeCref;
CookieRef* getMakeCookieRef_locked( const char* cORn, bool isCookie, CookieRef* getMakeCookieRef_locked( const char* cORn, bool isCookie,
HostID hid, HostID hid, int socket,
int nPlayersH, int nPlayersT ); int nPlayersH, int nPlayersT );
CookieRef* getCookieRef_locked( CookieID cookieID ); CookieRef* getCookieRef_locked( CookieID cookieID );
CookieRef* getCookieRef_locked( int socket ); CookieRef* getCookieRef_locked( int socket );
@ -87,7 +87,7 @@ class CRefMgr {
CookieRef* getCookieRef_impl( CookieID cookieID ); CookieRef* getCookieRef_impl( CookieID cookieID );
CookieRef* AddNew( const char* cookie, const char* connName, CookieID id ); CookieRef* AddNew( const char* cookie, const char* connName, CookieID id );
CookieRef* FindOpenGameFor( const char* cORn, bool isCookie, 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 cookieIDForConnName( const char* connName );
CookieID nextCID( const char* connName ); CookieID nextCID( const char* connName );
@ -120,7 +120,7 @@ class SafeCref {
public: public:
SafeCref( const char* cookieOrConnName, bool cookie, HostID hid, SafeCref( const char* cookieOrConnName, bool cookie, HostID hid,
int nPlayersH, int nPlayersT ); int socket, int nPlayersH, int nPlayersT );
SafeCref( CookieID cid ); SafeCref( CookieID cid );
SafeCref( int socket ); SafeCref( int socket );
SafeCref( CookieRef* cref ); SafeCref( CookieRef* cref );

View file

@ -273,7 +273,7 @@ processConnect( unsigned char* bufp, int bufLen, int socket )
&& getNetByte( &bufp, end, &nPlayersH ) && getNetByte( &bufp, end, &nPlayersH )
&& getNetByte( &bufp, end, &nPlayersT ) ) { && 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 ); success = scr.Connect( socket, srcID, nPlayersH, nPlayersT );
} }
@ -308,7 +308,7 @@ processReconnect( unsigned char* bufp, int bufLen, int socket )
&& getNetByte( &bufp, end, &nPlayersT ) && getNetByte( &bufp, end, &nPlayersT )
&& readStr( &bufp, end, connName, sizeof(connName) ) ) { && 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 ); success = scr.Reconnect( socket, srcID, nPlayersH, nPlayersT );
} }