From 14584f69e69ced03446dac6d30d033f63b4dc5a6 Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Mon, 2 Jul 2012 11:21:21 +0000 Subject: Added the cWorld::DoWithPlayer() function and exported it in the Lua API. Removed the obsolete cWorld::GetPlayer() function. git-svn-id: http://mc-server.googlecode.com/svn/trunk@639 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cWorld.cpp | 57 ++++++++++--------------------------------------------- 1 file changed, 10 insertions(+), 47 deletions(-) (limited to 'source/cWorld.cpp') 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); -- cgit v1.2.3