C4SoundEffect* C4SoundSystem::GetEffect(const char *szSndName) { // Remember wildcards before adding .* extension - if there are 2 versions with different file extensions, play the last added bool bRandomSound = SCharCount('?',szSndName) || SCharCount('*',szSndName); // Evaluate sound name char szName[C4MaxSoundName+2+1]; SCopy(szSndName,szName,C4MaxSoundName); // Any extension accepted DefaultExtension(szName,"*"); // Play nth Sound. Standard: 1 int32_t iNumber = 1; // Sound with a wildcard: determine number of available matches if (bRandomSound) { iNumber = 0; // Count matching sounds for (C4SoundEffect *pSfx=FirstSound; pSfx; pSfx=pSfx->Next) if (WildcardMatch(szName,pSfx->Name)) ++iNumber; // Nothing found? Abort if(iNumber == 0) return NULL; iNumber=UnsyncedRandom(iNumber)+1; } // Find requested sound effect in bank C4SoundEffect *pSfx; for (pSfx=FirstSound; pSfx; pSfx=pSfx->Next) if (WildcardMatch(szName,pSfx->Name)) if(!--iNumber) break; return pSfx; // Is still NULL if nothing is found }
bool VFS::FindNextFile(LPVOID lpFindHandle, WIN32_FIND_DATA *pw32fd) { FINDDATA *pfd = (FINDDATA *)lpFindHandle; string str; while (pfd->ptree) { str = pfd->ptree->_data.strVirtual; if (str.find_first_of('.') == string::npos) str.push_back('.'); if (WildcardMatch(pfd->strFilespec.c_str(), str.c_str())) { GetMountPointFindData(pfd->ptree, pw32fd); pfd->ptree = pfd->ptree->_pright; return true; } pfd->ptree = pfd->ptree->_pright; } if (pfd->hFind) { return ::FindNextFile(pfd->hFind, pw32fd) ? true : false; } else { if (!Map(pfd->strVirtual.c_str(), str, &_root)) return false; if (str.length() != 0) { pfd->hFind = ::FindFirstFile(str.c_str(), pw32fd); return (pfd->hFind != INVALID_HANDLE_VALUE); } else { return false; } } }
void C4StartupMainDlg::OnShown() { #ifdef WITH_AUTOMATIC_UPDATE // Incoming update if (!Application.IncomingUpdate.empty()) { C4UpdateDlg::ApplyUpdate(Application.IncomingUpdate.c_str(), false, GetScreen()); Application.IncomingUpdate.clear(); } // Manual update by command line or url if (Application.CheckForUpdates) { C4UpdateDlg::CheckForUpdates(GetScreen(), false); Application.CheckForUpdates = false; } // Automatic update else { if (Config.Network.AutomaticUpdate) C4UpdateDlg::CheckForUpdates(GetScreen(), true); } #endif // first start evaluation if (Config.General.FirstStart) { Config.General.FirstStart = false; } // first thing that's needed is a new player, if there's none - independent of first start bool fHasPlayer = false; StdStrBuf sSearchPath(Config.General.UserDataPath); const char *szFn; // sSearchPath.Format("%s%s", (const char *) Config.General.ExePath, (const char *) Config.General.PlayerPath); for (DirectoryIterator i(sSearchPath.getData()); (szFn=*i); i++) { szFn = Config.AtRelativePath(szFn); if (*GetFilename(szFn) == '.') continue; // ignore ".", ".." and private files (".*") if (!WildcardMatch(C4CFN_PlayerFiles, GetFilename(szFn))) continue; fHasPlayer = true; break; } if (!fHasPlayer) { // no player created yet: Create one C4GUI::Dialog *pDlg; GetScreen()->ShowModalDlg(pDlg=new C4StartupPlrPropertiesDlg(nullptr, nullptr), true); } // make sure participants are updated after switching back from player selection UpdateParticipants(); // First show if (fFirstShown) { // Activate the application (trying to prevent flickering half-focus in win32...) Application.Activate(); // Set the focus to the start button (we might still not have the focus after the update-check sometimes... :/) SetFocus(pStartButton, false); } fFirstShown = false; }
eURLState CWebCore::GetURLState ( const SString& strURL, bool bOutputDebug ) { std::lock_guard<std::recursive_mutex> lock ( m_FilterMutex ); // Initialize wildcard whitelist (be careful with modifying) | Todo: Think about the following static SString wildcardWhitelist[] = { "*.googlevideo.com", "*.google.com", "*.youtube.com", "*.ytimg.com", "*.vimeocdn.com" }; for ( int i = 0; i < sizeof(wildcardWhitelist) / sizeof(SString); ++i ) { if ( WildcardMatch ( wildcardWhitelist[i], strURL ) ) return eURLState::WEBPAGE_ALLOWED; } google::dense_hash_map<SString, WebFilterPair>::iterator iter = m_Whitelist.find ( strURL ); if ( iter != m_Whitelist.end () ) { if ( iter->second.first == true ) return eURLState::WEBPAGE_ALLOWED; else { if ( m_bTestmodeEnabled && bOutputDebug ) g_pCore->DebugPrintfColor ( "[BROWSER] Blocked page: %s", 255, 0, 0, strURL.c_str() ); return eURLState::WEBPAGE_DISALLOWED; } } if ( m_bTestmodeEnabled && bOutputDebug ) g_pCore->DebugPrintfColor ( "[BROWSER] Blocked page: %s", 255, 0, 0, strURL.c_str() ); return eURLState::WEBPAGE_NOT_LISTED; }
global func FxIntInvincibilityEffect(string szNewEffectName) { // nicht anbrennen lassen if(WildcardMatch(szNewEffectName,"*Fire*")) return FX_Effect_Deny; // gleichen Effekt ablehnen if(szNewEffectName == "IntInvincibility") return FX_Effect_Deny; }
inline bool WildcardMatch(Iterator begin, Iterator end, const std::string& str, bool iCase = false) { return std::find_if(begin, end, [&](const std::string& pattern) { return WildcardMatch(pattern, str, iCase); }) != end; }
void C4Effect::Kill() { // active? C4Effect *pLastRemovedEffect=NULL; if (IsActive()) // then temp remove all higher priority effects TempRemoveUpperEffects(false, &pLastRemovedEffect); else // otherwise: temp reactivate before real removal // this happens only if a lower priority effect removes an upper priority effect in its add- or removal-call if (iPriority!=1) CallStart(C4FxCall_TempAddForRemoval, C4Value(), C4Value(), C4Value(), C4Value()); // remove this effect int32_t iPrevPrio = iPriority; SetDead(); if (CallStop(C4FxCall_Normal, false) == C4Fx_Stop_Deny) // effect denied to be removed: recover iPriority = iPrevPrio; // reactivate other effects TempReaddUpperEffects(pLastRemovedEffect); // Update OnFire cache if (Target && WildcardMatch(C4Fx_AnyFire, GetName())) if (!Get(C4Fx_AnyFire)) Target->SetOnFire(false); if (IsDead() && !GetCallbackScript()) Call(P_Destruction, &C4AulParSet(C4FxCall_Normal)); }
// // ResCache::Preload - Chapter 8, page 236 // int ResCache::Preload(const std::string pattern, void (*progressCallback)(int, bool &)) { if (m_file==NULL) return 0; int numFiles = m_file->VGetNumResources(); int loaded = 0; bool cancel = false; for (int i=0; i<numFiles; ++i) { Resource resource(m_file->VGetResourceName(i)); if (WildcardMatch(pattern.c_str(), resource.m_name.c_str())) { shared_ptr<ResHandle> handle = g_pApp->m_ResCache->GetHandle(&resource); ++loaded; } if (progressCallback != NULL) { progressCallback(i * 100/numFiles, cancel); } } return loaded; }
std::vector<SString> SharedUtil::FindFiles(const SString& strMatch, bool bFiles, bool bDirectories, bool bSortByDate) { std::vector<SString> strResult; std::multimap<uint64, SString> sortMap; DIR* Dir; struct dirent* DirEntry; // Extract any filename matching characters SString strFileMatch; SString strSearchDirectory = PathJoin(PathConform(strMatch).SplitLeft("/", &strFileMatch, -1), "/"); if ((Dir = opendir(strSearchDirectory))) { while ((DirEntry = readdir(Dir)) != NULL) { // Skip dotted entries if (strcmp(DirEntry->d_name, ".") && strcmp(DirEntry->d_name, "..")) { struct stat Info; bool bIsDir = false; // Do wildcard matching if required if (!strFileMatch.empty() && !WildcardMatch(strFileMatch, DirEntry->d_name)) { continue; } SString strPath = PathJoin(strSearchDirectory, DirEntry->d_name); // Determine the file stats if (lstat(strPath, &Info) != -1) bIsDir = S_ISDIR(Info.st_mode); if (bIsDir ? bDirectories : bFiles) { if (bSortByDate) { SString strAbsPath = strSearchDirectory + DirEntry->d_name; struct stat attrib; stat(strAbsPath, &attrib); MapInsert(sortMap, (uint64)attrib.st_mtime, SStringX(DirEntry->d_name)); } else strResult.push_back(DirEntry->d_name); } } } closedir(Dir); } // Resolve sorted map if required if (!sortMap.empty()) { for (std::multimap<uint64, SString>::iterator iter = sortMap.begin(); iter != sortMap.end(); ++iter) strResult.push_back(iter->second); } return strResult; }
global func FxIntInvincibleEffect(string new_name, object target, proplist fx) { // Block fire effects. if (WildcardMatch(new_name, "*Fire*") && !fx.allow_fire) return FX_Effect_Deny; // All other effects are okay. return FX_OK; }
////////////////////////////////////////////////////////////////////////// // WildcardMatch // pszString - Input string to match // pszMatch - Match mask that may contain wildcards like ? and * // // A ? sign matches any character, except an empty string. // A * sign matches any string inclusive an empty string. // Characters are compared caseless. bool WildcardMatch(const char *pszString, const char *pszMatch) { // We have a special case were string is empty ("") and the mask is "*". // We need to handle this too. So we can't test on !*pszString here. // The loop breaks when the match string is exhausted. while (*pszMatch) { // Single wildcard character if (*pszMatch == '?') { // Matches any character except empty string if (!*pszString) return false; // OK next ++pszString; ++pszMatch; } else if (*pszMatch== '*') { // Need to do some tricks. // 1. The wildcard * is ignored. // So just an empty string matches. This is done by recursion. // Because we eat one character from the match string, the // recursion will stop. if (WildcardMatch(pszString, pszMatch+1)) // we have a match and the * replaces no other character return true; // 2. Chance we eat the next character and try it again, with a // wildcard * match. This is done by recursion. Because we eat // one character from the string, the recursion will stop. if (*pszString && WildcardMatch(pszString+1, pszMatch)) return true; // Nothing worked with this wildcard. return false; } else { // Standard compare of 2 chars. Note that *pszSring might be 0 // here, but than we never get a match on *pszMask that has always // a value while inside this loop. if (toupper(*pszString++) != toupper(*pszMatch++)) return false; } } // Have a match? Only if both are at the end... return !*pszString && !*pszMatch; }
bool C4MusicFileOgg::HasCategory(const char *szcat) const { if (!szcat) return false; // check all stored categories for (auto i = categories.cbegin(); i != categories.cend(); ++i) if (WildcardMatch(szcat, i->getData())) return true; return false; }
bool matchWildcardList(const String& str, const StringVec& wildcardList) { for (unsigned i = 0; i < wildcardList.size(); i++) { if (WildcardMatch(str.c_str(), wildcardList[i].c_str())) { return true; } } return false; }
bool C4ScenarioSection::EnsureTempStore(bool fExtractLandscape, bool fExtractObjects) { // if it's temp store already, don't do anything if (szTempFilename) return true; // make temp filename char *szTmp = const_cast<char *>( Config.AtTempPath(szFilename ? GetFilename(szFilename) : szName)); MakeTempFilename(szTmp); // main section: extract section files from main scenario group (create group // as open dir) if (!szFilename) { if (!CreateDirectory(szTmp, NULL)) return false; C4Group hGroup; if (!hGroup.Open(szTmp, TRUE)) { EraseItem(szTmp); return false; } // extract all desired section files Game.ScenarioFile.ResetSearch(); char fn[_MAX_FNAME + 1]; *fn = 0; while (Game.ScenarioFile.FindNextEntry(C4FLS_Section, fn)) if (fExtractLandscape || !WildcardMatch(C4FLS_SectionLandscape, fn)) if (fExtractObjects || !WildcardMatch(C4FLS_SectionObjects, fn)) Game.ScenarioFile.ExtractEntry(fn, szTmp); hGroup.Close(); } else { // subsection: simply extract section from main group if (!Game.ScenarioFile.ExtractEntry(szFilename, szTmp)) return false; // delete undesired landscape/object files if (!fExtractLandscape || !fExtractObjects) { C4Group hGroup; if (hGroup.Open(szFilename)) { if (!fExtractLandscape) hGroup.Delete(C4FLS_SectionLandscape); if (!fExtractObjects) hGroup.Delete(C4FLS_SectionObjects); } } } // copy temp filename szTempFilename = new char[strlen(szTmp) + 1]; SCopy(szTmp, szTempFilename, _MAX_PATH); // done, success return true; }
/// <summary> /// Determine if a string matches a pattern containing wildcard characters, case-insensitive. /// </summary> /// <param name="pattern">The pattern to compare against.</param> /// <param name="patternEnd">The end of the pattern to compare against (one past the last character; the /// address of the '\0' if you're using NUL-terminated strings).</param> /// <param name="text">The text string to test.</param> /// <param name="textEnd">The end of the text string to test (one past the last character; the /// address of the '\0' if you're using NUL-terminated strings).</param> /// <returns>True if the string matches the pattern, false if it does not.</returns> static Bool WildcardMatch(const Byte *pattern, const Byte *patternEnd, const Byte *text, const Byte *textEnd) { Byte patternChar, textChar, nextPatternChar; while (pattern < patternEnd) { switch (patternChar = CaseFold(*pattern++)) { case '?': // If we ran out of characters, this is a fail. if (text == textEnd) return False; textChar = CaseFold(*text++); break; case '*': // Consume trailing '*' and '?' characters, since they don't mean much (except '?', // which adds mandatory filler space). while (pattern < patternEnd && ((patternChar = CaseFold(*pattern)) == '?' || patternChar == '*')) { if (patternChar == '?' && text == textEnd) return False; pattern++; text++; } // If we ran out of characters in the pattern, then this is a successful match, // since this star can consume everything after it in the text. if (pattern == patternEnd) return True; // Determine the next character in the text that we're searching for. nextPatternChar = patternChar; // Skim forward in the text looking for that next character, and then recursively // perform a pattern-match on the remainders of the pattern and text from there. // We use that next character to optimize the recursion, so that we don't recurse // if we know there won't be a match. while (text < textEnd) { textChar = CaseFold(*text); if (textChar == nextPatternChar && WildcardMatch(pattern, patternEnd, text, textEnd)) return True; text++; } // None of the recursive searches matched, so this is a fail. return False; default: if (text == textEnd) return False; // Ran out of characters. if (patternChar != CaseFold(*text++)) return False; // No match. break; } } return text == textEnd; }
bool StringParser::WildcardMatchNoCase(const String &sWildcard, const String &sString) { String sLowerWild = sWildcard; String sLowerStr = sString; sLowerWild.ToLower(); sLowerStr.ToLower(); return WildcardMatch(sLowerWild, sLowerStr); }
bool StringParser::IsValidDomainName(const String &sDomainName) { if (_AnyOfCharsExists("<>,\"\\!#¤%&[]$£/*?", sDomainName)) return false; String sWildCard = "?*.?*"; return WildcardMatch(sWildCard, sDomainName); }
int32_t C4SoundSystem::EffectInBank(const char *szSound) { int32_t iResult = 0; C4SoundEffect *pSfx; char szName[C4MaxSoundName + 4 + 1]; // Compose name (with extension) SCopy(szSound, szName, C4MaxSoundName); DefaultExtension(szName, "wav"); // Count all matching sounds in bank for (pSfx = FirstSound; pSfx; pSfx = pSfx->Next) if (WildcardMatch(szName, pSfx->Name)) iResult++; return iResult; }
/////////////////////////////////////////////////////////////// // // SharedUtil_WildcardMatch_Tests // // Tests for WildcardMatch // /////////////////////////////////////////////////////////////// void SharedUtil_WildcardMatch_Tests ( void ) { // WildcardMatch { TEST_FUNCTION assert ( WildcardMatch ( a, b ) == result ); TEST_VARS const char* a; const char* b; bool result; TEST_DATA { "*bd*", "abcbde", true }, { "*bd?f*", "abcbdef_bdgh", true }, { "*bd?h*", "abcbdef_bdgh", true }, { "*bd?g*", "abcbdef_bdgh", false }, { "scr*w?d", "screeeewywxd", true }, { "A*B", "A_B_B", true }, { "", "", true }, { "*", "", true }, { "*", "A", true }, { "", "A", false }, { "A*", "", false }, { "A*", "AAB", true }, { "A*", "BAA", false }, { "A*", "A", true }, { "A*B", "", false }, { "A*B", "AAB", true }, { "A*B", "AB", true }, { "A*B", "AABA", false }, { "A*B", "ABAB", true }, { "A*B", "ABBBB", true }, { "A*B*C", "", false }, { "A*B*C", "ABC", true }, { "A*B*C", "ABCC", true }, { "A*B*C", "ABBBC", true }, { "A*B*C", "ABBBBCCCC", true }, { "A*B*C", "ABCBBBCBCCCBCBCCCC", true }, { "A*B*", "AB", true }, { "A*B*", "AABA", true }, { "A*B*", "ABAB", true }, { "A*B*", "ABBBB", true }, { "A*B*C*", "", false }, { "A*B*C*", "ABC", true }, { "A*B*C*", "ABCC", true }, { "A*B*C*", "ABBBC", true }, { "A*B*C*", "ABBBBCCCC", true }, { "A*B*C*", "ABCBBBCBCCCBCBCCCC", true }, { "A?", "AAB", false }, { "A?B", "AAB", true }, { "A?*", "A", false }, { "A?*", "ABBCC", true }, { "A?*", "BAA", false },
C4Effect * C4Effect::Init(C4PropList *pForObj, int32_t iPrio, const C4Value &rVal1, const C4Value &rVal2, const C4Value &rVal3, const C4Value &rVal4) { Target = pForObj; // ask all effects with higher priority first - except for prio 1 effects, which are considered out of the priority call chain (as per doc) bool fRemoveUpper = (iPrio != 1); // note that apart from denying the creation of this effect, higher priority effects may also remove themselves // or do other things with the effect list // (which does not quite make sense, because the effect might be denied by another effect) // so the priority is assigned after this call, marking this effect dead before it's definitely valid if (fRemoveUpper && pNext) { C4Effect * pEffect2 = pNext->Check(GetName(), iPrio, iInterval, rVal1, rVal2, rVal3, rVal4); if (pEffect2) { // effect denied (iResult = -1), added to an effect (iResult = Number of that effect) // or added to an effect that destroyed itself (iResult = -2) if (pEffect2 != (C4Effect*)C4Fx_Effect_Deny && pEffect2 != (C4Effect*)C4Fx_Effect_Annul) return pEffect2; // effect is still marked dead return 0; } } // init effect // higher-priority effects must be deactivated temporarily, and then reactivated regarding the new effect // higher-level effects should not be inserted during the process of removing or adding a lower-level effect // because that would cause a wrong initialization order // (hardly ever causing trouble, however...) C4Effect *pLastRemovedEffect=NULL; C4AulFunc * pFn; if (!GetCallbackScript()) { Call(P_Construction, &C4AulParSet(rVal1, rVal2, rVal3, rVal4)).getInt(); if (pForObj && !pForObj->Status) return 0; pFn = GetFunc(P_Start); } else pFn = pFnStart; if (fRemoveUpper && pNext && pFn) TempRemoveUpperEffects(false, &pLastRemovedEffect); // bad things may happen if (pForObj && !pForObj->Status) return 0; // this will be invalid! iPriority = iPrio; // validate effect now if (CallStart(0, rVal1, rVal2, rVal3, rVal4) == C4Fx_Start_Deny) // the effect denied to start: assume it hasn't, and mark it dead SetDead(); if (fRemoveUpper && pNext && pFn) TempReaddUpperEffects(pLastRemovedEffect); if (pForObj && !pForObj->Status) return 0; // this will be invalid! // Update OnFire cache if (!IsDead() && pForObj && WildcardMatch(C4Fx_AnyFire, GetName())) pForObj->SetOnFire(true); return this; }
/// <summary> /// Determine if this test suite is one we should be running or not. /// </summary> /// <param name="name">The name of a test suite.</param> /// <returns>True if that test suite is in the set of requested tests, False if it should be skipped.</returns> static Bool IsTestSuiteRequested(const char *name) { int i; if (NumRequestedTests <= 0) return True; for (i = 0; i < NumRequestedTests; i++) { if (WildcardMatch(RequestedTests[i], RequestedTests[i] + strlen(RequestedTests[i]), name, name + strlen(name))) return True; } return False; }
/** * Return true if this profile inherits from the specified template */ bool BotProfile::InheritsFrom( const char *name ) const { if ( WildcardMatch( name, GetName() ) ) return true; for ( int i=0; i<m_templates.Count(); ++i ) { const BotProfile *queryTemplate = m_templates[i]; if ( queryTemplate->InheritsFrom( name ) ) { return true; } } return false; }
C4SoundInstance *C4SoundSystem::FindInstance(const char *szSndName, C4Object *pObj) { char szName[C4MaxSoundName + 4 + 1]; // Evaluate sound name (see GetEffect) SCopy(szSndName, szName, C4MaxSoundName); DefaultExtension(szName, "wav"); SReplaceChar(szName, '*', '?'); // Find an effect with a matching instance for (C4SoundEffect *csfx = FirstSound; csfx; csfx = csfx->Next) if (WildcardMatch(szName, csfx->Name)) { C4SoundInstance *pInst = csfx->GetInstance(pObj); if (pInst) return pInst; } return NULL; }
BOOL WildcardMatch (const wchar_t *Mask, const wchar_t *Value) { size_t i; size_t j = 0; size_t maskLen; size_t valueLen; maskLen = wcslen(Mask); valueLen = wcslen(Value); for (i = 0; i < maskLen + 1; i++) { if (Mask[i] == '?') { j++; continue; } if (Mask[i] == '*') { for (; j < valueLen + 1; j++) { if (WildcardMatch(Mask + i + 1, Value + j)) { return (TRUE); } } return (FALSE); } if ((j <= valueLen) && (Mask[i] == tolower(Value[j]))) { j++; continue; } return (FALSE); } return (TRUE); }
int32_t C4SoundSystem::RemoveEffect(const char *szFilename) { int32_t iResult = 0; C4SoundEffect *pNext, *pPrev = NULL; for (C4SoundEffect *pSfx = FirstSound; pSfx; pSfx = pNext) { pNext = pSfx->Next; if (WildcardMatch(szFilename, pSfx->Name)) { delete pSfx; if (pPrev) pPrev->Next = pNext; else FirstSound = pNext; iResult++; } else pPrev = pSfx; } return iResult; }
C4GUI::ContextMenu *C4StartupMainDlg::OnPlayerSelContextAdd(C4GUI::Element *pBtn, int32_t iX, int32_t iY) { C4GUI::ContextMenu *pCtx = new C4GUI::ContextMenu(); const char *szFn; StdStrBuf sSearchPath(Config.General.UserDataPath); // sSearchPath.Format("%s%s", (const char *) Config.General.ExePath, (const char *) Config.General.PlayerPath); for (DirectoryIterator i(sSearchPath.getData()); (szFn=*i); i++) { szFn = Config.AtRelativePath(szFn); if (*GetFilename(szFn) == '.') continue; if (!WildcardMatch(C4CFN_PlayerFiles, GetFilename(szFn))) continue; if (!SIsModule(Config.General.Participants, szFn, nullptr, false)) pCtx->AddItem(GetFilenameOnly(szFn), "Let this player join in next game", C4GUI::Ico_Player, new C4GUI::CBMenuHandlerEx<C4StartupMainDlg, StdCopyStrBuf>(this, &C4StartupMainDlg::OnPlayerSelContextAddPlr, StdCopyStrBuf(szFn)), nullptr); } return pCtx; }
// // ResCache::Match - not described in the book // // Searches the resource cache assets for files matching the pattern. Useful for providing a // a list of levels for a main menu screen, for example. // std::vector<std::string> ResCache::Match(const std::string pattern) { std::vector<std::string> matchingNames; if (m_file==NULL) return matchingNames; int numFiles = m_file->VGetNumResources(); for (int i=0; i<numFiles; ++i) { std::string name = m_file->VGetResourceName(i); std::transform(name.begin(), name.end(), name.begin(), (int(*)(int)) std::tolower); if (WildcardMatch(pattern.c_str(), name.c_str())) { matchingNames.push_back(name); } } return matchingNames; }
std::vector<std::string> ResCache::match( const std::string pattern ) { std::vector<std::string> matchingNames; if( m_files.empty() ) return matchingNames; for( ResourceFiles::iterator fileItr = m_files.begin(); fileItr != m_files.end(); ++fileItr ) { int numFiles = (*fileItr)->VGetNumResources(); for( int i = 0; i < numFiles; ++i ) { std::string name = (*fileItr)->VGetResourceName(i); std::transform(name.begin(), name.end(), name.begin(), (int(*)(int)) std::tolower); if( WildcardMatch(pattern.c_str(), name.c_str()) ) { matchingNames.push_back(name); } } } return matchingNames; }//ResCache::match
C4Effect * C4Effect::New(C4Object * pForObj, C4String * szName, int32_t iPrio, int32_t iTimerInterval, C4Object * pCmdTarget, C4ID idCmdTarget, const C4Value &rVal1, const C4Value &rVal2, const C4Value &rVal3, const C4Value &rVal4) { C4Effect * pEffect = new C4Effect(pForObj, szName, iPrio, iTimerInterval, pCmdTarget, idCmdTarget, rVal1, rVal2, rVal3, rVal4); // ask all effects with higher priority first - except for prio 1 effects, which are considered out of the priority call chain (as per doc) bool fRemoveUpper = (iPrio != 1); // note that apart from denying the creation of this effect, higher priority effects may also remove themselves // or do other things with the effect list // (which does not quite make sense, because the effect might be denied by another effect) // so the priority is assigned after this call, marking this effect dead before it's definitely valid if (fRemoveUpper && pEffect->pNext) { C4Effect * pEffect2 = pEffect->pNext->Check(pForObj, szName->GetCStr(), iPrio, iTimerInterval, rVal1, rVal2, rVal3, rVal4); if (pEffect2) { // effect denied (iResult = -1), added to an effect (iResult = Number of that effect) // or added to an effect that destroyed itself (iResult = -2) if (pEffect2 != (C4Effect*)C4Fx_Effect_Deny && pEffect2 != (C4Effect*)C4Fx_Effect_Annul) return pEffect2; // effect is still marked dead return 0; } } // init effect // higher-priority effects must be deactivated temporarily, and then reactivated regarding the new effect // higher-level effects should not be inserted during the process of removing or adding a lower-level effect // because that would cause a wrong initialization order // (hardly ever causing trouble, however...) C4Effect *pLastRemovedEffect=NULL; if (fRemoveUpper && pEffect->pNext && pEffect->pFnStart) pEffect->TempRemoveUpperEffects(pForObj, false, &pLastRemovedEffect); // bad things may happen if (pForObj && !pForObj->Status) return 0; // this will be invalid! pEffect->iPriority = iPrio; // validate effect now if (pEffect->pFnStart) if (pEffect->pFnStart->Exec(pCmdTarget, &C4AulParSet(C4VObj(pForObj), C4VPropList(pEffect), C4VInt(0), rVal1, rVal2, rVal3, rVal4)).getInt() == C4Fx_Start_Deny) // the effect denied to start: assume it hasn't, and mark it dead pEffect->SetDead(); if (fRemoveUpper && pEffect->pNext && pEffect->pFnStart) pEffect->TempReaddUpperEffects(pForObj, pLastRemovedEffect); if (pForObj && !pForObj->Status) return 0; // this will be invalid! // Update OnFire cache if (!pEffect->IsDead() && pForObj && WildcardMatch(C4Fx_AnyFire, szName->GetCStr())) pForObj->SetOnFire(true); return pEffect; }
bool C4MainMenu::ActivateNewPlayer(int32_t iPlayer) { // league or replay game if (Game.Parameters.isLeague() || Game.C4S.Head.Replay) return false; // Max player limit if (::Players.GetCount() >= Game.Parameters.MaxPlayers) return false; // Menu symbol/init if (GfxR->fctPlayerClr.Surface) GfxR->fctPlayerClr.Surface->SetClr(0xff); InitRefSym(GfxR->fctPlayerClr, LoadResStr("IDS_MENU_NOPLRFILES"), iPlayer); for (DirectoryIterator iter(Config.General.UserDataPath); *iter; ++iter) if (WildcardMatch("*.ocp", *iter)) { char szFilename[_MAX_PATH+1], szCommand[_MAX_PATH+30+1]; SCopy(*iter, szFilename, _MAX_PATH); if (DirectoryExists(szFilename)) continue; if (::Players.FileInUse(szFilename)) continue; // Open group C4Group hGroup; if (!hGroup.Open(szFilename)) continue; // Load player info C4PlayerInfoCore C4P; if (!C4P.Load(hGroup)) { hGroup.Close(); continue; } // Close group hGroup.Close(); // Add player item sprintf(szCommand, "JoinPlayer:%s", szFilename); StdStrBuf sItemText; sItemText.Format(LoadResStr("IDS_MENU_NEWPLAYER"), C4P.PrefName); C4FacetSurface fctSymbol; // Add menu item Add(sItemText.getData(), fctSymbol, szCommand); // Reset symbol facet (menu holds on to the surface) fctSymbol.Default(); } // Alignment SetAlignment(C4MN_Align_Left | C4MN_Align_Bottom); // Go back to options menu on close SetCloseCommand("ActivateMenu:Main"); return true; }