mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Merge pull request #7427 from furo321/save-unknown-commands
Save unknown commands from `settings_ddnet.cfg`
This commit is contained in:
commit
37b0a5569d
|
@ -4251,6 +4251,13 @@ static bool UnknownArgumentCallback(const char *pCommand, void *pUser)
|
|||
return false;
|
||||
}
|
||||
|
||||
static bool SaveUnknownCommandCallback(const char *pCommand, void *pUser)
|
||||
{
|
||||
CClient *pClient = static_cast<CClient *>(pUser);
|
||||
pClient->ConfigManager()->StoreUnknownCommand(pCommand);
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
Server Time
|
||||
Client Mirror Time
|
||||
|
@ -4478,6 +4485,7 @@ int main(int argc, const char **argv)
|
|||
// execute config file
|
||||
if(pStorage->FileExists(CONFIG_FILE, IStorage::TYPE_ALL))
|
||||
{
|
||||
pConsole->SetUnknownCommandCallback(SaveUnknownCommandCallback, pClient);
|
||||
if(!pConsole->ExecuteFile(CONFIG_FILE))
|
||||
{
|
||||
const char *pError = "Failed to load config from '" CONFIG_FILE "'.";
|
||||
|
@ -4486,6 +4494,7 @@ int main(int argc, const char **argv)
|
|||
PerformAllCleanup();
|
||||
return -1;
|
||||
}
|
||||
pConsole->SetUnknownCommandCallback(IConsole::EmptyUnknownCommandCallback, nullptr);
|
||||
}
|
||||
|
||||
// execute autoexec file
|
||||
|
|
|
@ -20,6 +20,8 @@ public:
|
|||
virtual void RegisterCallback(SAVECALLBACKFUNC pfnFunc, void *pUserData) = 0;
|
||||
|
||||
virtual void WriteLine(const char *pLine) = 0;
|
||||
|
||||
virtual void StoreUnknownCommand(const char *pCommand) = 0;
|
||||
};
|
||||
|
||||
extern IConfigManager *CreateConfigManager();
|
||||
|
|
|
@ -110,6 +110,11 @@ bool CConfigManager::Save()
|
|||
for(int i = 0; i < m_NumCallbacks; i++)
|
||||
m_aCallbacks[i].m_pfnFunc(this, m_aCallbacks[i].m_pUserData);
|
||||
|
||||
for(const auto &Command : m_vUnknownCommands)
|
||||
{
|
||||
WriteLine(Command.c_str());
|
||||
}
|
||||
|
||||
if(io_sync(m_ConfigFile) != 0)
|
||||
{
|
||||
m_Failed = true;
|
||||
|
@ -153,4 +158,9 @@ void CConfigManager::WriteLine(const char *pLine)
|
|||
}
|
||||
}
|
||||
|
||||
void CConfigManager::StoreUnknownCommand(const char *pCommand)
|
||||
{
|
||||
m_vUnknownCommands.emplace_back(pCommand);
|
||||
}
|
||||
|
||||
IConfigManager *CreateConfigManager() { return new CConfigManager; }
|
||||
|
|
|
@ -6,6 +6,9 @@
|
|||
#include <base/detect.h>
|
||||
#include <engine/config.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// include protocol for MAX_CLIENT used in config_variables
|
||||
#include <engine/shared/protocol.h>
|
||||
|
||||
|
@ -72,6 +75,8 @@ class CConfigManager : public IConfigManager
|
|||
CCallback m_aCallbacks[MAX_CALLBACKS];
|
||||
int m_NumCallbacks;
|
||||
|
||||
std::vector<std::string> m_vUnknownCommands;
|
||||
|
||||
public:
|
||||
CConfigManager();
|
||||
|
||||
|
@ -84,6 +89,8 @@ public:
|
|||
void RegisterCallback(SAVECALLBACKFUNC pfnFunc, void *pUserData) override;
|
||||
|
||||
void WriteLine(const char *pLine) override;
|
||||
|
||||
void StoreUnknownCommand(const char *pCommand) override;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue