summaryrefslogtreecommitdiffstats
path: root/source/cWorld.cpp
diff options
context:
space:
mode:
authorfaketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-08-23 01:05:12 +0200
committerfaketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-08-23 01:05:12 +0200
commit49a4613d94d8e500e5bd3c259693fb5ccec4612e (patch)
treeea2db28bde16c472f02b6a83651df8cf2fe486a9 /source/cWorld.cpp
parentAdded a documentation for block and item handlers (diff)
downloadcuberite-49a4613d94d8e500e5bd3c259693fb5ccec4612e.tar
cuberite-49a4613d94d8e500e5bd3c259693fb5ccec4612e.tar.gz
cuberite-49a4613d94d8e500e5bd3c259693fb5ccec4612e.tar.bz2
cuberite-49a4613d94d8e500e5bd3c259693fb5ccec4612e.tar.lz
cuberite-49a4613d94d8e500e5bd3c259693fb5ccec4612e.tar.xz
cuberite-49a4613d94d8e500e5bd3c259693fb5ccec4612e.tar.zst
cuberite-49a4613d94d8e500e5bd3c259693fb5ccec4612e.zip
Diffstat (limited to 'source/cWorld.cpp')
-rw-r--r--source/cWorld.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/source/cWorld.cpp b/source/cWorld.cpp
index a981a24c0..f12f9f1a8 100644
--- a/source/cWorld.cpp
+++ b/source/cWorld.cpp
@@ -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)
{