1
0

Simplified cWorld::FindAndDoWithPlayer()

It should still work the same - call the callback for the player with the most similar name.

git-svn-id: http://mc-server.googlecode.com/svn/trunk@1184 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
madmaxoft@gmail.com 2013-02-01 19:59:58 +00:00
parent 019c8b5bc7
commit 0be125aa07
2 changed files with 9 additions and 12 deletions

View File

@ -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;

View File

@ -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