| 2418 | |
| 2419 | |
| 2420 | bool cWorld::FindAndDoWithPlayer(const AString & a_PlayerNameHint, cPlayerListCallback & a_Callback) |
| 2421 | { |
| 2422 | cPlayer * BestMatch = NULL; |
| 2423 | unsigned int BestRating = 0; |
| 2424 | unsigned int NameLength = a_PlayerNameHint.length(); |
| 2425 | |
| 2426 | cCSLock Lock(m_CSPlayers); |
| 2427 | for (cPlayerList::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr) |
| 2428 | { |
| 2429 | unsigned int Rating = RateCompareString (a_PlayerNameHint, (*itr)->GetName()); |
| 2430 | if (Rating >= BestRating) |
| 2431 | { |
| 2432 | BestMatch = *itr; |
| 2433 | BestRating = Rating; |
| 2434 | } |
| 2435 | if (Rating == NameLength) // Perfect match |
| 2436 | { |
| 2437 | break; |
| 2438 | } |
| 2439 | } // for itr - m_Players[] |
| 2440 | |
| 2441 | if (BestMatch != NULL) |
| 2442 | { |
| 2443 | LOG("Compared %s and %s with rating %i", a_PlayerNameHint.c_str(), BestMatch->GetName().c_str(), BestRating); |
| 2444 | return a_Callback.Item (BestMatch); |
| 2445 | } |
| 2446 | return false; |
| 2447 | } |
| 2448 | |
| 2449 | |
| 2450 | |