diff --git a/source/World.cpp b/source/World.cpp index 084bf8cd2..e5e8977bd 100644 --- a/source/World.cpp +++ b/source/World.cpp @@ -1752,33 +1752,30 @@ bool cWorld::DoWithPlayer(const AString & a_PlayerName, cPlayerListCallback & a_ -bool cWorld::FindAndDoWithPlayer(const AString & a_PlayerName, cPlayerListCallback & a_Callback) +bool cWorld::FindAndDoWithPlayer(const AString & a_PlayerNameHint, cPlayerListCallback & a_Callback) { - cPlayer* BestMatch = 0; + cPlayer * BestMatch = NULL; unsigned int BestRating = 0; - unsigned int NumMatches = 0; - unsigned int NameLength = a_PlayerName.length(); + unsigned int NameLength = a_PlayerNameHint.length(); cCSLock Lock(m_CSPlayers); for (cPlayerList::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr) { - unsigned int Rating = RateCompareString (a_PlayerName, (*itr)->GetName()); - if (Rating > 0 && Rating >= BestRating) + unsigned int Rating = RateCompareString (a_PlayerNameHint, (*itr)->GetName()); + if (Rating >= BestRating) { BestMatch = *itr; - if( Rating > BestRating ) NumMatches = 0; BestRating = Rating; - ++NumMatches; } - if (Rating == NameLength) // Perfect match + if (Rating == NameLength) // Perfect match { break; } } // for itr - m_Players[] - if (NumMatches == 1) + if (BestMatch != NULL) { - LOG("Compared %s and %s with rating %i", a_PlayerName.c_str(), BestMatch->GetName().c_str(), BestRating ); + LOG("Compared %s and %s with rating %i", a_PlayerNameHint.c_str(), BestMatch->GetName().c_str(), BestRating); return a_Callback.Item (BestMatch); } return false; diff --git a/source/World.h b/source/World.h index d3ed37aa3..e30fa7981 100644 --- a/source/World.h +++ b/source/World.h @@ -180,7 +180,7 @@ public: bool DoWithPlayer(const AString & a_PlayerName, cPlayerListCallback & a_Callback); // >> EXPORTED IN MANUALBINDINGS << /// Finds a player from a partial or complete player name and calls the callback - case-insensitive - bool FindAndDoWithPlayer(const AString & a_PlayerName, cPlayerListCallback & a_Callback); // >> EXPORTED IN MANUALBINDINGS << + bool FindAndDoWithPlayer(const AString & a_PlayerNameHint, cPlayerListCallback & a_Callback); // >> EXPORTED IN MANUALBINDINGS << unsigned int GetNumPlayers(); // tolua_export