From b3e61b1d750f821356c3608840ac265a7e36d99a Mon Sep 17 00:00:00 2001 From: Steve Dudenhoeffer Date: Fri, 22 Jun 2007 15:35:46 +0000 Subject: [PATCH] Fix for amb108 - statsx keeping port when saving stats by ip - this should still allow for old stats files to work, but there is a small chance for idiosyncrasies if there are multiple users with the same ip (but different port) saved. --- dlls/cstrike/csx/CMisc.cpp | 13 ++++++++++- dlls/cstrike/csx/CRank.cpp | 44 +++++++++++++++++++++++++++++++++----- dlls/cstrike/csx/CRank.h | 2 +- dlls/dod/dodx/CMisc.cpp | 13 ++++++++++- dlls/dod/dodx/CRank.cpp | 44 +++++++++++++++++++++++++++++++++----- dlls/dod/dodx/CRank.h | 2 +- dlls/tfcx/CMisc.cpp | 13 ++++++++++- dlls/tfcx/CRank.cpp | 44 +++++++++++++++++++++++++++++++++----- dlls/tfcx/CRank.h | 2 +- dlls/ts/tsx/CMisc.cpp | 14 +++++++++++- dlls/ts/tsx/CRank.cpp | 44 +++++++++++++++++++++++++++++++++----- dlls/ts/tsx/CRank.h | 2 +- 12 files changed, 209 insertions(+), 28 deletions(-) diff --git a/dlls/cstrike/csx/CMisc.cpp b/dlls/cstrike/csx/CMisc.cpp index 28f71306..7fe5648b 100755 --- a/dlls/cstrike/csx/CMisc.cpp +++ b/dlls/cstrike/csx/CMisc.cpp @@ -85,6 +85,7 @@ void CPlayer::PutInServer(){ restartStats(); const char* name = STRING(pEdict->v.netname); const char* unique = name; + bool isip = false; switch((int)csstats_rank->value) { case 1: if ( (unique = GETPLAYERAUTHID(pEdict)) == 0 ) @@ -92,13 +93,23 @@ void CPlayer::PutInServer(){ break; case 2: unique = ip; + isip = true; } - rank = g_rank.findEntryInRank( unique , name ); + rank = g_rank.findEntryInRank( unique , name , isip); } void CPlayer::Connect(const char* address ){ bot = IsBot(); strcpy(ip,address); + // Strip the port from the ip + for (size_t i = 0; i < sizeof(ip); i++) + { + if (ip[i] == ':') + { + ip[i] = '\0'; + break; + } + } rank = 0; clearStats = 0.0f; } diff --git a/dlls/cstrike/csx/CRank.cpp b/dlls/cstrike/csx/CRank.cpp index c0e9243c..776c1868 100755 --- a/dlls/cstrike/csx/CRank.cpp +++ b/dlls/cstrike/csx/CRank.cpp @@ -146,16 +146,50 @@ void RankSystem::unloadCalc() MF_UnloadAmxScript(&calc.amx , &calc.code); } -RankSystem::RankStats* RankSystem::findEntryInRank(const char* unique, const char* name ) +RankSystem::RankStats* RankSystem::findEntryInRank(const char* unique, const char* name, bool isip) { RankStats* a = head; - while ( a ) + if (isip) // IP lookups need to strip the port from already saved instances. + { // Otherwise the stats file would be essentially reset. + + // The IP passed does not contain the port any more for unique + size_t iplen = strlen(unique); + + + while ( a ) + { + const char* targetUnique = a->getUnique(); + if ( strncmp( targetUnique, unique, iplen) == 0 ) + { + // It mostly matches, make sure this isn't a false match + // eg: checking 4.2.2.2 would match 4.2.2.24 here. + + // Get the next character stored in targetUnique + char c = targetUnique[iplen]; + + // If c is either a colon or end of line, then this + // is a valid match. + if (c == ':' || + c == '\0') + { + // Yes, this is a match. + return a; + } + // Any other case was a false match. + + } + } + } + else // No special case { - if ( strcmp( a->getUnique() ,unique ) == 0 ) - return a; + while ( a ) + { + if ( strcmp( a->getUnique() ,unique ) == 0 ) + return a; - a = a->prev; + a = a->prev; + } } a = new RankStats( unique ,name,this ); if ( a == 0 ) return 0; diff --git a/dlls/cstrike/csx/CRank.h b/dlls/cstrike/csx/CRank.h index 797799e1..2b538d8e 100755 --- a/dlls/cstrike/csx/CRank.h +++ b/dlls/cstrike/csx/CRank.h @@ -98,7 +98,7 @@ public: void saveRank( const char* filename ); void loadRank( const char* filename ); - RankStats* findEntryInRank(const char* unique, const char* name ); + RankStats* findEntryInRank(const char* unique, const char* name, bool isip=false); bool loadCalc(const char* filename, char* error); inline int getRankNum( ) const { return rankNum; } void clear(); diff --git a/dlls/dod/dodx/CMisc.cpp b/dlls/dod/dodx/CMisc.cpp index 4bf79aaa..6f1aa8e7 100755 --- a/dlls/dod/dodx/CMisc.cpp +++ b/dlls/dod/dodx/CMisc.cpp @@ -77,6 +77,7 @@ void CPlayer::PutInServer(){ const char* unique; const char* name = STRING(pEdict->v.netname); + bool isip = false; switch((int)dodstats_rank->value) { case 1: if ( (unique = GETPLAYERAUTHID(pEdict)) == 0 ) @@ -84,17 +85,27 @@ void CPlayer::PutInServer(){ break; case 2: unique = ip; + isip = true; break; default: unique = name; } - if ( ( rank = g_rank.findEntryInRank( unique , name ) ) == 0 ) + if ( ( rank = g_rank.findEntryInRank( unique , name , isip) ) == 0 ) ingame = false; } void CPlayer::Connect(const char* nn,const char* ippp ){ bot = IsBot(); strcpy(ip,ippp); + // Strip the port from the ip + for (size_t i = 0; i < sizeof(ip); i++) + { + if (ip[i] == ':') + { + ip[i] = '\0'; + break; + } + } } void CPlayer::restartStats(bool all) diff --git a/dlls/dod/dodx/CRank.cpp b/dlls/dod/dodx/CRank.cpp index 4cc3e169..221dbd8d 100755 --- a/dlls/dod/dodx/CRank.cpp +++ b/dlls/dod/dodx/CRank.cpp @@ -163,16 +163,50 @@ void RankSystem::unloadCalc() MF_UnloadAmxScript(&calc.amx , &calc.code); } -RankSystem::RankStats* RankSystem::findEntryInRank(const char* unique, const char* name ) +RankSystem::RankStats* RankSystem::findEntryInRank(const char* unique, const char* name, bool isip) { RankStats* a = head; - while ( a ) + if (isip) // IP lookups need to strip the port from already saved instances. + { // Otherwise the stats file would be essentially reset. + + // The IP passed does not contain the port any more for unique + size_t iplen = strlen(unique); + + + while ( a ) + { + const char* targetUnique = a->getUnique(); + if ( strncmp( targetUnique, unique, iplen) == 0 ) + { + // It mostly matches, make sure this isn't a false match + // eg: checking 4.2.2.2 would match 4.2.2.24 here. + + // Get the next character stored in targetUnique + char c = targetUnique[iplen]; + + // If c is either a colon or end of line, then this + // is a valid match. + if (c == ':' || + c == '\0') + { + // Yes, this is a match. + return a; + } + // Any other case was a false match. + + } + } + } + else // No special case { - if ( strcmp( a->getUnique() ,unique ) == 0 ) - return a; + while ( a ) + { + if ( strcmp( a->getUnique() ,unique ) == 0 ) + return a; - a = a->prev; + a = a->prev; + } } a = new RankStats( unique ,name,this ); if ( a == 0 ) return 0; diff --git a/dlls/dod/dodx/CRank.h b/dlls/dod/dodx/CRank.h index e5b623d4..dc77a09b 100755 --- a/dlls/dod/dodx/CRank.h +++ b/dlls/dod/dodx/CRank.h @@ -120,7 +120,7 @@ public: void saveRank( const char* filename ); void loadRank( const char* filename ); - RankStats* findEntryInRank(const char* unique, const char* name ); + RankStats* findEntryInRank(const char* unique, const char* name , bool isip = false); bool loadCalc(const char* filename, char* error); inline int getRankNum( ) const { return rankNum; } void clear(); diff --git a/dlls/tfcx/CMisc.cpp b/dlls/tfcx/CMisc.cpp index 3ff69929..96f7f980 100755 --- a/dlls/tfcx/CMisc.cpp +++ b/dlls/tfcx/CMisc.cpp @@ -113,6 +113,7 @@ void CPlayer::PutInServer(){ const char* name = STRING(pEdict->v.netname); const char* unique = name; + bool isip = false; switch((int)tfcstats_rank->value) { case 1: if ( (unique = GETPLAYERAUTHID(pEdict)) == 0 ) @@ -120,12 +121,22 @@ void CPlayer::PutInServer(){ break; case 2: unique = ip; + isip = true; } - rank = g_rank.findEntryInRank( unique , name ); + rank = g_rank.findEntryInRank( unique , name , isip); } void CPlayer::Connect(const char* address ){ bot = IsBot(); strcpy(ip,address); + // Strip the port from the ip + for (size_t i = 0; i < sizeof(ip); i++) + { + if (ip[i] == ':') + { + ip[i] = '\0'; + break; + } + } rank = 0; clearStats = 0.0f; } diff --git a/dlls/tfcx/CRank.cpp b/dlls/tfcx/CRank.cpp index 33b2312c..f2c69729 100755 --- a/dlls/tfcx/CRank.cpp +++ b/dlls/tfcx/CRank.cpp @@ -161,16 +161,50 @@ void RankSystem::unloadCalc() MF_UnloadAmxScript(&calc.amx , &calc.code); } -RankSystem::RankStats* RankSystem::findEntryInRank(const char* unique, const char* name ) +RankSystem::RankStats* RankSystem::findEntryInRank(const char* unique, const char* name, bool isip) { RankStats* a = head; - while ( a ) + if (isip) // IP lookups need to strip the port from already saved instances. + { // Otherwise the stats file would be essentially reset. + + // The IP passed does not contain the port any more for unique + size_t iplen = strlen(unique); + + + while ( a ) + { + const char* targetUnique = a->getUnique(); + if ( strncmp( targetUnique, unique, iplen) == 0 ) + { + // It mostly matches, make sure this isn't a false match + // eg: checking 4.2.2.2 would match 4.2.2.24 here. + + // Get the next character stored in targetUnique + char c = targetUnique[iplen]; + + // If c is either a colon or end of line, then this + // is a valid match. + if (c == ':' || + c == '\0') + { + // Yes, this is a match. + return a; + } + // Any other case was a false match. + + } + } + } + else // No special case { - if ( strcmp( a->getUnique() ,unique ) == 0 ) - return a; + while ( a ) + { + if ( strcmp( a->getUnique() ,unique ) == 0 ) + return a; - a = a->prev; + a = a->prev; + } } a = new RankStats( unique ,name,this ); if ( a == 0 ) return 0; diff --git a/dlls/tfcx/CRank.h b/dlls/tfcx/CRank.h index 0fff54ea..a7e8f884 100755 --- a/dlls/tfcx/CRank.h +++ b/dlls/tfcx/CRank.h @@ -89,7 +89,7 @@ public: void saveRank( const char* filename ); void loadRank( const char* filename ); - RankStats* findEntryInRank(const char* unique, const char* name ); + RankStats* findEntryInRank(const char* unique, const char* name , bool isip = false); bool loadCalc(const char* filename, char* error); inline int getRankNum( ) const { return rankNum; } void clear(); diff --git a/dlls/ts/tsx/CMisc.cpp b/dlls/ts/tsx/CMisc.cpp index ff6e5c31..5dde272a 100755 --- a/dlls/ts/tsx/CMisc.cpp +++ b/dlls/ts/tsx/CMisc.cpp @@ -62,6 +62,7 @@ void CPlayer::PutInServer() const char* unique; const char* name = STRING(pEdict->v.netname); + bool isip = false; switch((int)tsstats_rank->value) { case 1: if ( (unique = GETPLAYERAUTHID(pEdict)) == 0 ) @@ -69,16 +70,27 @@ void CPlayer::PutInServer() break; case 2: unique = ip; + isip = true; break; default: unique = name; } - if ( ( rank = g_rank.findEntryInRank( unique , name ) ) == 0 ) + if ( ( rank = g_rank.findEntryInRank( unique , name , isip) ) == 0 ) ingame = false; } void CPlayer::Connect(const char* ippp) { strcpy(ip,ippp); + // Strip the port from the ip + for (size_t i = 0; i < sizeof(ip); i++) + { + if (ip[i] == ':') + { + ip[i] = '\0'; + break; + } + } + } void CPlayer::restartStats(bool all) diff --git a/dlls/ts/tsx/CRank.cpp b/dlls/ts/tsx/CRank.cpp index 051b3586..a667be11 100755 --- a/dlls/ts/tsx/CRank.cpp +++ b/dlls/ts/tsx/CRank.cpp @@ -161,16 +161,50 @@ void RankSystem::unloadCalc() MF_UnloadAmxScript(&calc.amx , &calc.code); } -RankSystem::RankStats* RankSystem::findEntryInRank(const char* unique, const char* name ) +RankSystem::RankStats* RankSystem::findEntryInRank(const char* unique, const char* name, bool isip) { RankStats* a = head; - while ( a ) + if (isip) // IP lookups need to strip the port from already saved instances. + { // Otherwise the stats file would be essentially reset. + + // The IP passed does not contain the port any more for unique + size_t iplen = strlen(unique); + + + while ( a ) + { + const char* targetUnique = a->getUnique(); + if ( strncmp( targetUnique, unique, iplen) == 0 ) + { + // It mostly matches, make sure this isn't a false match + // eg: checking 4.2.2.2 would match 4.2.2.24 here. + + // Get the next character stored in targetUnique + char c = targetUnique[iplen]; + + // If c is either a colon or end of line, then this + // is a valid match. + if (c == ':' || + c == '\0') + { + // Yes, this is a match. + return a; + } + // Any other case was a false match. + + } + } + } + else // No special case { - if ( strcmp( a->getUnique() ,unique ) == 0 ) - return a; + while ( a ) + { + if ( strcmp( a->getUnique() ,unique ) == 0 ) + return a; - a = a->prev; + a = a->prev; + } } a = new RankStats( unique ,name,this ); if ( a == 0 ) return 0; diff --git a/dlls/ts/tsx/CRank.h b/dlls/ts/tsx/CRank.h index 0fff54ea..39595b13 100755 --- a/dlls/ts/tsx/CRank.h +++ b/dlls/ts/tsx/CRank.h @@ -89,7 +89,7 @@ public: void saveRank( const char* filename ); void loadRank( const char* filename ); - RankStats* findEntryInRank(const char* unique, const char* name ); + RankStats* findEntryInRank(const char* unique, const char* name , bool isip = false ); bool loadCalc(const char* filename, char* error); inline int getRankNum( ) const { return rankNum; } void clear();