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.
This commit is contained in:
parent
6865b984e0
commit
b3e61b1d75
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -146,10 +146,43 @@ 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;
|
||||
|
||||
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
|
||||
{
|
||||
while ( a )
|
||||
{
|
||||
if ( strcmp( a->getUnique() ,unique ) == 0 )
|
||||
|
@ -157,6 +190,7 @@ RankSystem::RankStats* RankSystem::findEntryInRank(const char* unique, const cha
|
|||
|
||||
a = a->prev;
|
||||
}
|
||||
}
|
||||
a = new RankStats( unique ,name,this );
|
||||
if ( a == 0 ) return 0;
|
||||
put_after( a , 0 );
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -163,10 +163,43 @@ 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;
|
||||
|
||||
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
|
||||
{
|
||||
while ( a )
|
||||
{
|
||||
if ( strcmp( a->getUnique() ,unique ) == 0 )
|
||||
|
@ -174,6 +207,7 @@ RankSystem::RankStats* RankSystem::findEntryInRank(const char* unique, const cha
|
|||
|
||||
a = a->prev;
|
||||
}
|
||||
}
|
||||
a = new RankStats( unique ,name,this );
|
||||
if ( a == 0 ) return 0;
|
||||
put_after( a , 0 );
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -161,10 +161,43 @@ 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;
|
||||
|
||||
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
|
||||
{
|
||||
while ( a )
|
||||
{
|
||||
if ( strcmp( a->getUnique() ,unique ) == 0 )
|
||||
|
@ -172,6 +205,7 @@ RankSystem::RankStats* RankSystem::findEntryInRank(const char* unique, const cha
|
|||
|
||||
a = a->prev;
|
||||
}
|
||||
}
|
||||
a = new RankStats( unique ,name,this );
|
||||
if ( a == 0 ) return 0;
|
||||
put_after( a , 0 );
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -161,10 +161,43 @@ 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;
|
||||
|
||||
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
|
||||
{
|
||||
while ( a )
|
||||
{
|
||||
if ( strcmp( a->getUnique() ,unique ) == 0 )
|
||||
|
@ -172,6 +205,7 @@ RankSystem::RankStats* RankSystem::findEntryInRank(const char* unique, const cha
|
|||
|
||||
a = a->prev;
|
||||
}
|
||||
}
|
||||
a = new RankStats( unique ,name,this );
|
||||
if ( a == 0 ) return 0;
|
||||
put_after( a , 0 );
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue
Block a user