/// /// \brief Fonction qui sépare une ligne autour d'une string (voir split dans Java ou autres langage) /// \param[in] strSource Source à splitter /// \param[in] strSplitString String utilisé pour splitter /// \return UN tableau des string splitter /// StringArray String::Split(const std::string &strSource, std::string strSplitString, unsigned int nPosStart) { StringArray strReturnArray; if(!strSource.empty()) { unsigned int nPosEnd=strSource.find(strSplitString, nPosStart); unsigned int countSplit = Utils::String::Count(strSource,strSplitString, nPosStart); strReturnArray.reserve(countSplit); while (nPosEnd!=std::string::npos && nPosStart!=std::string::npos) { std::string strWord(strSource.substr(nPosStart, nPosEnd-nPosStart)); //if(strWord!="") //Ceci n'est pas acceptable car nous ne pouvons parser convenablement des strings comme: "Sainte-Thérèse,60,3,,CITLA,,,60" strReturnArray.push_back(strWord); nPosStart=nPosEnd+strSplitString.size(); nPosEnd=strSource.find(strSplitString, nPosStart); } //On ramasse la dernière séquence si elle finit pas par le string split... if(nPosStart<strSource.size()) { strReturnArray.push_back(strSource.substr(nPosStart, strSource.size()-nPosStart)); } else { assert(strSource.substr(strSource.size()-strSplitString.size(), strSplitString.size()) == strSplitString); strReturnArray.push_back(""); //Séquence fini par string split } } return strReturnArray; }
int CHighScoreList::AddEntry (const CGameRecord &NewEntry) // AddEntry // // Add another entry to the high score { int i, j; // Score of 0 doesn't count if (NewEntry.GetScore() == 0) return -1; // Modify the epitaph in the entry CGameRecord ModifiedEntry = NewEntry; if (strEquals(strWord(ModifiedEntry.GetEndGameEpitaph(), 0), CONSTLIT("was"))) ModifiedEntry.SetEndGameEpitaph(strSubString(ModifiedEntry.GetEndGameEpitaph(), 4, -1)); // Find a spot on the list for (i = 0; i < m_iCount; i++) { if (ModifiedEntry.GetScore() > m_List[i].GetScore()) break; } // If we are the end of the list, then we didn't make the // high score list. if (i == MAX_SCORES) return -1; // Otherwise, move all scores below us by one m_bModified = true; if (m_iCount < MAX_SCORES) m_iCount++; for (j = m_iCount-2; j >= i; j--) m_List[j+1] = m_List[j]; m_List[i] = ModifiedEntry; // Player name m_sMostRecentPlayerName = ModifiedEntry.GetPlayerName(); m_iMostRecentPlayerGenome = ModifiedEntry.GetPlayerGenome(); return i; }
void CGameSession::OnPlayerDestroyed (SDestroyCtx &Ctx, const CString &sEpitaph) // OnPlayerDestroyed // // Player was destroyed { DEBUG_TRY // Clean up g_pTrans->HideCommsTargetMenu(); g_pTrans->m_CurrentPicker = CTranscendenceWnd::pickNone; g_pTrans->m_CurrentMenu = CTranscendenceWnd::menuNone; g_pTrans->m_bAutopilot = false; m_bShowingSystemMap = false; if (g_pTrans->m_State == CTranscendenceWnd::gsDocked) m_Model.GetPlayer()->Undock(); // Update display CString sMsg = sEpitaph; if (strEquals(strWord(sMsg, 0), CONSTLIT("was"))) sMsg = strSubString(sMsg, 4, -1); sMsg.Capitalize(CString::capFirstLetter); g_pTrans->DisplayMessage(sMsg); m_HUD.Invalidate(hudArmor); // If we are insured, then set our state so that we come back to life if (Ctx.bResurrectPending) { // Prepare resurrect g_pTrans->m_State = CTranscendenceWnd::gsDestroyed; g_pTrans->m_iCountdown = TICKS_AFTER_DESTROYED; } // Otherwise, proceed with destruction else { // Done with ship screens g_pTrans->CleanUpPlayerShip(); // Player destroyed g_pTrans->m_State = CTranscendenceWnd::gsDestroyed; g_pTrans->m_iCountdown = TICKS_AFTER_DESTROYED; } DEBUG_CATCH }
void CTranscendenceWnd::PlayerDestroyed (const CString &sText, bool bResurrectionPending) // PlayerDestroyed // // This method gets called when the player is destroyed { // Clean up HideCommsTargetMenu(); m_CurrentPicker = pickNone; m_CurrentMenu = menuNone; m_bAutopilot = false; m_bShowingMap = false; if (m_State == gsDocked) GetPlayer()->Undock(); // Update display CString sMsg = sText; if (strEquals(strWord(sMsg, 0), CONSTLIT("was"))) sMsg = strSubString(sMsg, 4, -1); sMsg.Capitalize(CString::capFirstLetter); DisplayMessage(sMsg); UpdateArmorDisplay(); // If we are insured, then set our state so that we come back to life if (bResurrectionPending) { // Prepare resurrect m_State = gsDestroyed; m_iCountdown = TICKS_AFTER_DESTROYED; } // Otherwise, proceed with destruction else { // Done with ship screens CleanUpPlayerShip(); // Player destroyed m_State = gsDestroyed; m_iCountdown = TICKS_AFTER_DESTROYED; } }
CFileList* CLibraryDictionary::Search(const CQuerySearch* pSearch, const int nMaximum, const bool bLocal, const bool bAvailableOnly) { ASSUME_LOCK( Library.m_pSection ); if ( ! m_bValid ) { BuildHashTable(); if ( ! m_bValid ) return NULL; } // Only check the hash when a search comes from other client. if ( ! bLocal && ! m_pTable->Check( pSearch ) ) return NULL; ++m_nSearchCookie; CLibraryFile* pHit = NULL; CQuerySearch::const_iterator pWordEntry = pSearch->begin(); const CQuerySearch::const_iterator pLastWordEntry = pSearch->end(); for ( ; pWordEntry != pLastWordEntry; ++pWordEntry ) { if ( pWordEntry->first[ 0 ] == L'-' ) continue; CString strWord( pWordEntry->first, static_cast< int >( pWordEntry->second ) ); CFileList* pList = NULL; if ( m_oWordMap.Lookup( strWord, pList ) ) { for ( POSITION pos = pList->GetHeadPosition(); pos; ) { CLibraryFile* pFile = pList->GetNext( pos ); if ( bAvailableOnly && ! pFile->IsAvailable() ) continue; if ( ! bLocal && ! pFile->IsShared() ) continue; if ( pFile->m_nSearchCookie == m_nSearchCookie ) { ++pFile->m_nSearchWords; } else { pFile->m_nSearchCookie = m_nSearchCookie; pFile->m_nSearchWords = 1; pFile->m_pNextHit = pHit; pHit = pFile; } } } } size_t nLowerBound = ( pSearch->tableSize() >= 3 ) ? ( pSearch->tableSize() * 2 / 3 ) : pSearch->tableSize(); CFileList* pHits = NULL; for ( ; pHit; pHit = pHit->m_pNextHit ) { ASSERT( pHit->m_nSearchCookie == m_nSearchCookie ); if ( pHit->m_nSearchWords < nLowerBound ) continue; if ( pSearch->Match( pHit->GetSearchName(), pHit->m_pSchema ? (LPCTSTR)pHit->m_pSchema->GetURI() : NULL, pHit->m_pMetadata, pHit ) ) { if ( ! pHits ) pHits = new CFileList; pHits->AddTail( pHit ); if ( ! bLocal ) { pHit->m_nHitsToday ++; pHit->m_nHitsTotal ++; } if ( pHit->m_nCollIndex ) { CLibraryFile* pCollection = LibraryMaps.LookupFile( pHit->m_nCollIndex, ! bLocal, bAvailableOnly ); if ( pCollection ) { if ( pCollection->m_nSearchCookie != m_nSearchCookie ) { pCollection->m_nSearchCookie = m_nSearchCookie; pHits->AddHead( pCollection ); } } else { // Collection removed without deleting indexes pHit->m_nCollIndex = 0ul; } } if ( nMaximum > 0 && pHits->GetCount() >= nMaximum ) break; } } return pHits; }
void CMessageFilter::Load() { CFile pFile; CString strFilteredPhrases, strED2KSpamPhrases; const CString strFile = Settings.General.Path + _T("\\Data\\MessageFilter.dat"); // Delete current filter (if present) if ( m_pszFilteredPhrases ) delete [] m_pszFilteredPhrases; m_pszFilteredPhrases = NULL; // Load the message filter from disk if ( pFile.Open( strFile, CFile::modeRead ) ) { try { CBuffer pBuffer; DWORD nLen = (DWORD)pFile.GetLength(); if ( ! pBuffer.EnsureBuffer( nLen ) ) AfxThrowUserException(); pBuffer.m_nLength = nLen; pFile.Read( pBuffer.m_pBuffer, pBuffer.m_nLength ); pFile.Close(); pBuffer.ReadLine( strED2KSpamPhrases ); pBuffer.ReadLine( strFilteredPhrases ); } catch ( CException* pException ) { if ( pFile.m_hFile != CFile::hFileNull ) pFile.Close(); // If file is still open close it pException->Delete(); } } // Insert some defaults if there was a read error if ( strED2KSpamPhrases.IsEmpty() ) strED2KSpamPhrases = _T("Your client is connecting too fast|Join the L33cher Team|PeerFactor|Your client is making too many connections|ZamBoR 2|AUTOMATED MESSAGE:|eMule FX the BEST eMule ever|DI-Emule"); if ( strFilteredPhrases.IsEmpty() ) strFilteredPhrases = _T(""); // Load the ED2K spam into the filter if ( strED2KSpamPhrases.GetLength() > 3 ) { LPCTSTR pszPtr = strED2KSpamPhrases; int nWordLen = 3; CList< CString > pWords; int nStart = 0, nPos = 0; for ( ; *pszPtr ; nPos++, pszPtr++ ) { if ( *pszPtr == '|' ) { if ( nStart < nPos ) { pWords.AddTail( strED2KSpamPhrases.Mid( nStart, nPos - nStart ) ); nWordLen += ( nPos - nStart ) + 1; } nStart = nPos + 1; } } if ( nStart < nPos ) { pWords.AddTail( strED2KSpamPhrases.Mid( nStart, nPos - nStart ) ); nWordLen += ( nPos - nStart ) + 1; } m_pszED2KSpam = new TCHAR[ nWordLen ]; LPTSTR pszFilter = m_pszED2KSpam; for ( POSITION pos = pWords.GetHeadPosition() ; pos ; ) { CString strWord( pWords.GetNext( pos ) ); ToLower( strWord ); CopyMemory( pszFilter, (LPCTSTR)strWord, sizeof( TCHAR ) * ( strWord.GetLength() + 1 ) ); pszFilter += strWord.GetLength() + 1; } *pszFilter++ = 0; *pszFilter++ = 0; } // Load the blocked strings into the filter if ( strFilteredPhrases.GetLength() > 3 ) { LPCTSTR pszPtr = strFilteredPhrases; int nWordLen = 3; CList< CString > pWords; int nStart = 0, nPos = 0; for ( ; *pszPtr ; nPos++, pszPtr++ ) { if ( *pszPtr == '|' ) { if ( nStart < nPos ) { pWords.AddTail( strFilteredPhrases.Mid( nStart, nPos - nStart ) ); nWordLen += ( nPos - nStart ) + 1; } nStart = nPos + 1; } } if ( nStart < nPos ) { pWords.AddTail( strFilteredPhrases.Mid( nStart, nPos - nStart ) ); nWordLen += ( nPos - nStart ) + 1; } m_pszFilteredPhrases = new TCHAR[ nWordLen ]; LPTSTR pszFilter = m_pszFilteredPhrases; for ( POSITION pos = pWords.GetHeadPosition() ; pos ; ) { CString strWord( pWords.GetNext( pos ) ); ToLower( strWord ); CopyMemory( pszFilter, (LPCTSTR)strWord, sizeof( TCHAR ) * ( strWord.GetLength() + 1 ) ); pszFilter += strWord.GetLength() + 1; } *pszFilter++ = 0; *pszFilter++ = 0; } }
void CAdultFilter::Load() { CFile pFile; CString strBlockedWords, strDubiousWords, strChildWords; const CString strFile = Settings.General.Path + _T("\\Data\\AdultFilter.dat"); // Settings.General.DataPath ? // Delete current adult filters (if present) if ( m_pszBlockedWords ) delete [] m_pszBlockedWords; m_pszBlockedWords = NULL; if ( m_pszDubiousWords ) delete [] m_pszDubiousWords; m_pszDubiousWords = NULL; if ( m_pszChildWords ) delete [] m_pszChildWords; m_pszChildWords = NULL; // Load the adult filter from disk if ( pFile.Open( strFile, CFile::modeRead ) ) { try { CBuffer pBuffer; const DWORD nLen = (DWORD)pFile.GetLength(); if ( ! pBuffer.EnsureBuffer( nLen ) ) AfxThrowUserException(); pBuffer.m_nLength = nLen; pFile.Read( pBuffer.m_pBuffer, pBuffer.m_nLength ); pFile.Close(); pBuffer.ReadLine( strBlockedWords ); // Line 1: words that are blocked if ( ! strBlockedWords.IsEmpty() && strBlockedWords.GetAt( 0 ) == '#' ) strBlockedWords.Empty(); pBuffer.ReadLine( strDubiousWords ); // Line 2: words that may be okay if ( ! strDubiousWords.IsEmpty() && strDubiousWords.GetAt( 0 ) == '#' ) strDubiousWords.Empty(); pBuffer.ReadLine( strChildWords ); // Line 3: words for child pornography if ( ! strChildWords.IsEmpty() && strChildWords.GetAt( 0 ) == '#' ) strChildWords.Empty(); } catch ( CException* pException ) { if ( pFile.m_hFile != CFile::hFileNull ) pFile.Close(); // File is still open so close it pException->Delete(); } } // Insert some defaults if the load failed if ( strBlockedWords.IsEmpty() ) strBlockedWords = L"xxx p**n f**k c**k c**t v****a pussy nude naked boobs breast hentai " L"lesbian w***e shit rape preteen hardcore lolita playboy penthouse " L"topless r-rated x-rated d***o pr0n erotic sexy o****m nipple fetish " L"upskirt beastiality bestiality pedofil necrofil t**s lolicon shemale fisting"; if ( strDubiousWords.IsEmpty() ) strDubiousWords = L"ass sex anal gay teen thong babe bikini viagra dick cum s***s"; if ( strChildWords.IsEmpty() ) strChildWords = L"child preteen"; // Load the blocked words into the Adult Filter if ( strBlockedWords.GetLength() > 3 ) { LPCTSTR pszPtr = strBlockedWords; int nWordLen = 3; CList< CString > pWords; int nStart = 0, nPos = 0; for ( ; *pszPtr ; nPos++, pszPtr++ ) { if ( *pszPtr == ' ' ) { if ( nStart < nPos ) { pWords.AddTail( strBlockedWords.Mid( nStart, nPos - nStart ) ); nWordLen += ( nPos - nStart ) + 1; } nStart = nPos + 1; } } if ( nStart < nPos ) { pWords.AddTail( strBlockedWords.Mid( nStart, nPos - nStart ) ); nWordLen += ( nPos - nStart ) + 1; } m_pszBlockedWords = new TCHAR[ nWordLen ]; LPTSTR pszFilter = m_pszBlockedWords; for ( POSITION pos = pWords.GetHeadPosition() ; pos ; ) { CString strWord( pWords.GetNext( pos ) ); ToLower( strWord ); CopyMemory( pszFilter, (LPCTSTR)strWord, sizeof( TCHAR ) * ( strWord.GetLength() + 1 ) ); pszFilter += strWord.GetLength() + 1; } *pszFilter++ = 0; *pszFilter++ = 0; } // Load the possibly blocked words into the Adult Filter if ( strDubiousWords.GetLength() > 3 ) { LPCTSTR pszPtr = strDubiousWords; int nWordLen = 3; CList< CString > pWords; int nStart = 0, nPos = 0; for ( ; *pszPtr ; nPos++, pszPtr++ ) { if ( *pszPtr == ' ' ) { if ( nStart < nPos ) { pWords.AddTail( strDubiousWords.Mid( nStart, nPos - nStart ) ); nWordLen += ( nPos - nStart ) + 1; } nStart = nPos + 1; } } if ( nStart < nPos ) { pWords.AddTail( strDubiousWords.Mid( nStart, nPos - nStart ) ); nWordLen += ( nPos - nStart ) + 1; } m_pszDubiousWords = new TCHAR[ nWordLen ]; LPTSTR pszFilter = m_pszDubiousWords; for ( POSITION pos = pWords.GetHeadPosition() ; pos ; ) { CString strWord( pWords.GetNext( pos ) ); ToLower( strWord ); CopyMemory( pszFilter, (LPCTSTR)strWord, sizeof( TCHAR ) * ( strWord.GetLength() + 1 ) ); pszFilter += strWord.GetLength() + 1; } *pszFilter++ = 0; *pszFilter++ = 0; } // Load child pornography words into the Adult Filter if ( strChildWords.GetLength() > 3 ) { LPCTSTR pszPtr = strChildWords; int nWordLen = 3; CList< CString > pWords; int nStart = 0, nPos = 0; for ( ; *pszPtr ; nPos++, pszPtr++ ) { if ( *pszPtr == ' ' ) { if ( nStart < nPos ) { pWords.AddTail( strChildWords.Mid( nStart, nPos - nStart ) ); nWordLen += ( nPos - nStart ) + 1; } nStart = nPos + 1; } } if ( nStart < nPos ) { pWords.AddTail( strChildWords.Mid( nStart, nPos - nStart ) ); nWordLen += ( nPos - nStart ) + 1; } m_pszChildWords = new TCHAR[ nWordLen ]; LPTSTR pszFilter = m_pszChildWords; for ( POSITION pos = pWords.GetHeadPosition() ; pos ; ) { CString strWord( pWords.GetNext( pos ) ); ToLower( strWord ); CopyMemory( pszFilter, (LPCTSTR)strWord, sizeof( TCHAR ) * ( strWord.GetLength() + 1 ) ); pszFilter += strWord.GetLength() + 1; } *pszFilter++ = 0; *pszFilter++ = 0; } }