summaryrefslogtreecommitdiffstats
path: root/source/cRoot.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--source/cRoot.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/source/cRoot.cpp b/source/cRoot.cpp
index 5c0c08f7d..4c87210c7 100644
--- a/source/cRoot.cpp
+++ b/source/cRoot.cpp
@@ -14,6 +14,7 @@
#include "cThread.h"
#include "cFileFormatUpdater.h"
#include "cRedstone.h"
+#include "cPlayer.h"
#include "blocks/Block.h"
#include "items/Item.h"
#include "cChunk.h"
@@ -423,6 +424,58 @@ bool cRoot::ForEachPlayer(cPlayerListCallback & a_Callback)
+bool cRoot::FindAndDoWithPlayer(const AString & a_PlayerName, cPlayerListCallback & a_Callback)
+{
+ class cCallback : public cPlayerListCallback
+ {
+ unsigned int BestRating;
+ unsigned int NameLength;
+ const AString PlayerName;
+
+ cPlayerListCallback & m_Callback;
+ virtual bool Item (cPlayer * a_pPlayer)
+ {
+ unsigned int Rating = RateCompareString (PlayerName, a_pPlayer->GetName());
+ if (Rating > 0 && Rating >= BestRating)
+ {
+ BestMatch = a_pPlayer;
+ if( Rating > BestRating ) NumMatches = 0;
+ BestRating = Rating;
+ ++NumMatches;
+ }
+ if (Rating == NameLength) // Perfect match
+ {
+ return false;
+ }
+ return true;
+ }
+
+ public:
+ cCallback (const AString & a_PlayerName, cPlayerListCallback & a_Callback)
+ : m_Callback( a_Callback )
+ , BestMatch( NULL )
+ , BestRating( 0 )
+ , NumMatches( 0 )
+ , NameLength( a_PlayerName.length() )
+ , PlayerName( a_PlayerName )
+ {}
+
+ cPlayer * BestMatch;
+ unsigned int NumMatches;
+ } Callback (a_PlayerName, a_Callback);
+ ForEachPlayer( Callback );
+
+ if (Callback.NumMatches == 1)
+ {
+ return a_Callback.Item (Callback.BestMatch);
+ }
+ return false;
+}
+
+
+
+
+
void cRoot::LogChunkStats(void)
{
int SumNumValid = 0;