summaryrefslogtreecommitdiffstats
path: root/source/cWorld.cpp
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-07-02 13:21:21 +0200
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-07-02 13:21:21 +0200
commit14584f69e69ced03446dac6d30d033f63b4dc5a6 (patch)
tree59f127efa926d5c717f3be4ecc46c43c1e2a49cb /source/cWorld.cpp
parentChunkDef: Fixed getters taking a const ptr (diff)
downloadcuberite-14584f69e69ced03446dac6d30d033f63b4dc5a6.tar
cuberite-14584f69e69ced03446dac6d30d033f63b4dc5a6.tar.gz
cuberite-14584f69e69ced03446dac6d30d033f63b4dc5a6.tar.bz2
cuberite-14584f69e69ced03446dac6d30d033f63b4dc5a6.tar.lz
cuberite-14584f69e69ced03446dac6d30d033f63b4dc5a6.tar.xz
cuberite-14584f69e69ced03446dac6d30d033f63b4dc5a6.tar.zst
cuberite-14584f69e69ced03446dac6d30d033f63b4dc5a6.zip
Diffstat (limited to '')
-rw-r--r--source/cWorld.cpp57
1 files changed, 10 insertions, 47 deletions
diff --git a/source/cWorld.cpp b/source/cWorld.cpp
index e438760af..2c732df7f 100644
--- a/source/cWorld.cpp
+++ b/source/cWorld.cpp
@@ -1529,64 +1529,27 @@ bool cWorld::ForEachPlayer(cPlayerListCallback & a_Callback)
-// TODO: This interface is dangerous!
-cPlayer* cWorld::GetPlayer( const char* a_PlayerName )
-{
- cPlayer* BestMatch = 0;
- unsigned int MatchedLetters = 0;
- unsigned int NumMatches = 0;
- bool bPerfectMatch = false;
- unsigned int NameLength = strlen( a_PlayerName );
+bool cWorld::DoWithPlayer(const AString & a_PlayerName, cPlayerListCallback & a_Callback)
+{
+ // Calls the callback for each player in the list
cCSLock Lock(m_CSPlayers);
- for (cPlayerList::iterator itr = m_Players.begin(); itr != m_Players.end(); itr++ )
+ for (cPlayerList::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
{
- std::string Name = (*itr)->GetName();
- if( NameLength > Name.length() ) continue; // Definitely not a match
-
- for (unsigned int i = 0; i < NameLength; i++)
+ if ((*itr)->GetName() == a_PlayerName)
{
- char c1 = (char)toupper( a_PlayerName[i] );
- char c2 = (char)toupper( Name[i] );
- if( c1 == c2 )
- {
- if( i+1 > MatchedLetters )
- {
- MatchedLetters = i+1;
- BestMatch = *itr;
- }
- if( i+1 == NameLength )
- {
- NumMatches++;
- if( NameLength == Name.length() )
- {
- bPerfectMatch = true;
- break;
- }
- }
- }
- else
- {
- if( BestMatch == *itr ) BestMatch = 0;
- break;
- }
- if( bPerfectMatch )
- break;
+ a_Callback.Item(*itr);
+ return true;
}
- }
- if ( NumMatches == 1 )
- {
- return BestMatch;
- }
-
- // More than one matches, so it's undefined. Return NULL instead
- return NULL;
+ } // for itr - m_Players[]
+ return false;
}
+// TODO: This interface is dangerous!
cPlayer * cWorld::FindClosestPlayer(const Vector3f & a_Pos, float a_SightLimit)
{
cTracer LineOfSight(this);