1
0

Added a RateCompareString function to StringUtils

Created a preprocessor template (define) for DoWith* functions
Exported cWorld::FindAndDoWithPlayer(), cRoot::FindAndDoWithPlayer() and cRoot::ForEachPlayer() to Lua
Added a function FindAndDoWithPlayer to cRoot and cWorld. It takes a part of a player name and finds a single player based on that.
Fixed Core's MOTD to contain the correct URL to the MCServer site
Fixed Core /kick command
Fixed Core's WebAdmin kick

git-svn-id: http://mc-server.googlecode.com/svn/trunk@779 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
faketruth
2012-08-22 23:05:12 +00:00
parent 886c7f5624
commit 49a4613d94
11 changed files with 245 additions and 104 deletions

View File

@@ -1614,6 +1614,42 @@ bool cWorld::DoWithPlayer(const AString & a_PlayerName, cPlayerListCallback & a_
bool cWorld::FindAndDoWithPlayer(const AString & a_PlayerName, cPlayerListCallback & a_Callback)
{
cPlayer* BestMatch = 0;
unsigned int BestRating = 0;
unsigned int NumMatches = 0;
unsigned int NameLength = a_PlayerName.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)
{
BestMatch = *itr;
if( Rating > BestRating ) NumMatches = 0;
BestRating = Rating;
++NumMatches;
}
if (Rating == NameLength) // Perfect match
{
break;
}
} // for itr - m_Players[]
if (NumMatches == 1)
{
LOG("Compared %s and %s with rating %i", a_PlayerName.c_str(), BestMatch->GetName().c_str(), BestRating );
return a_Callback.Item (BestMatch);
}
return false;
}
// TODO: This interface is dangerous!
cPlayer * cWorld::FindClosestPlayer(const Vector3f & a_Pos, float a_SightLimit)
{