diff options
author | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2013-02-01 20:59:58 +0100 |
---|---|---|
committer | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2013-02-01 20:59:58 +0100 |
commit | 0be125aa07a9d6cebf47b81fc23eb61cc96cd7b6 (patch) | |
tree | 81e4529268e419a79fd18be90a4e517e340ead88 /source | |
parent | Moved command API into cPluginManager. (diff) | |
download | cuberite-0be125aa07a9d6cebf47b81fc23eb61cc96cd7b6.tar cuberite-0be125aa07a9d6cebf47b81fc23eb61cc96cd7b6.tar.gz cuberite-0be125aa07a9d6cebf47b81fc23eb61cc96cd7b6.tar.bz2 cuberite-0be125aa07a9d6cebf47b81fc23eb61cc96cd7b6.tar.lz cuberite-0be125aa07a9d6cebf47b81fc23eb61cc96cd7b6.tar.xz cuberite-0be125aa07a9d6cebf47b81fc23eb61cc96cd7b6.tar.zst cuberite-0be125aa07a9d6cebf47b81fc23eb61cc96cd7b6.zip |
Diffstat (limited to 'source')
-rw-r--r-- | source/World.cpp | 19 | ||||
-rw-r--r-- | source/World.h | 2 |
2 files changed, 9 insertions, 12 deletions
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 |