MCPcopy Create free account
hub / github.com/ddnet/ddnet / ExecuteFile

Method ExecuteFile

src/engine/shared/console.cpp:681–726  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

679}
680
681bool CConsole::ExecuteFile(const char *pFilename, int ClientId, bool LogFailure, int StorageType)
682{
683 int Count = 0;
684 // make sure that this isn't being executed already and that recursion limit isn't met
685 for(CExecFile *pCur = m_pFirstExec; pCur; pCur = pCur->m_pPrev)
686 {
687 Count++;
688
689 if(str_comp(pFilename, pCur->m_pFilename) == 0 || Count > FILE_RECURSION_LIMIT)
690 return false;
691 }
692 if(!m_pStorage)
693 return false;
694
695 // push this one to the stack
696 CExecFile ThisFile;
697 CExecFile *pPrev = m_pFirstExec;
698 ThisFile.m_pFilename = pFilename;
699 ThisFile.m_pPrev = m_pFirstExec;
700 m_pFirstExec = &ThisFile;
701
702 // exec the file
703 CLineReader LineReader;
704 bool Success = false;
705 char aBuf[32 + IO_MAX_PATH_LENGTH];
706 if(LineReader.OpenFile(m_pStorage->OpenFile(pFilename, IOFLAG_READ, StorageType)))
707 {
708 str_format(aBuf, sizeof(aBuf), "executing '%s'", pFilename);
709 Print(IConsole::OUTPUT_LEVEL_STANDARD, "console", aBuf);
710
711 while(const char *pLine = LineReader.Get())
712 {
713 ExecuteLine(pLine, ClientId);
714 }
715
716 Success = true;
717 }
718 else if(LogFailure)
719 {
720 str_format(aBuf, sizeof(aBuf), "failed to open '%s'", pFilename);
721 Print(IConsole::OUTPUT_LEVEL_STANDARD, "console", aBuf);
722 }
723
724 m_pFirstExec = pPrev;
725 return Success;
726}
727
728void CConsole::Con_Echo(IResult *pResult, void *pUserData)
729{

Callers 5

OnInitMethod · 0.80
LoadMapSettingsMethod · 0.80
mainFunction · 0.80
Con_ExecMethod · 0.80
mainFunction · 0.80

Calls 4

str_compFunction · 0.85
str_formatFunction · 0.85
OpenFileMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected