mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool SaveUnknownCommandCallback(const char *pCommand, void *pUser)
|
||||||
|
{
|
||||||
|
CClient *pClient = static_cast<CClient *>(pUser);
|
||||||
|
pClient->ConfigManager()->StoreUnknownCommand(pCommand);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Server Time
|
Server Time
|
||||||
Client Mirror Time
|
Client Mirror Time
|
||||||
|
@ -4478,6 +4485,7 @@ int main(int argc, const char **argv)
|
||||||
// execute config file
|
// execute config file
|
||||||
if(pStorage->FileExists(CONFIG_FILE, IStorage::TYPE_ALL))
|
if(pStorage->FileExists(CONFIG_FILE, IStorage::TYPE_ALL))
|
||||||
{
|
{
|
||||||
|
pConsole->SetUnknownCommandCallback(SaveUnknownCommandCallback, pClient);
|
||||||
if(!pConsole->ExecuteFile(CONFIG_FILE))
|
if(!pConsole->ExecuteFile(CONFIG_FILE))
|
||||||
{
|
{
|
||||||
const char *pError = "Failed to load config from '" CONFIG_FILE "'.";
|
const char *pError = "Failed to load config from '" CONFIG_FILE "'.";
|
||||||
|
@ -4486,6 +4494,7 @@ int main(int argc, const char **argv)
|
||||||
PerformAllCleanup();
|
PerformAllCleanup();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
pConsole->SetUnknownCommandCallback(IConsole::EmptyUnknownCommandCallback, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// execute autoexec file
|
// execute autoexec file
|
||||||
|
|
|
@ -20,6 +20,8 @@ public:
|
||||||
virtual void RegisterCallback(SAVECALLBACKFUNC pfnFunc, void *pUserData) = 0;
|
virtual void RegisterCallback(SAVECALLBACKFUNC pfnFunc, void *pUserData) = 0;
|
||||||
|
|
||||||
virtual void WriteLine(const char *pLine) = 0;
|
virtual void WriteLine(const char *pLine) = 0;
|
||||||
|
|
||||||
|
virtual void StoreUnknownCommand(const char *pCommand) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern IConfigManager *CreateConfigManager();
|
extern IConfigManager *CreateConfigManager();
|
||||||
|
|
|
@ -110,6 +110,11 @@ bool CConfigManager::Save()
|
||||||
for(int i = 0; i < m_NumCallbacks; i++)
|
for(int i = 0; i < m_NumCallbacks; i++)
|
||||||
m_aCallbacks[i].m_pfnFunc(this, m_aCallbacks[i].m_pUserData);
|
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)
|
if(io_sync(m_ConfigFile) != 0)
|
||||||
{
|
{
|
||||||
m_Failed = true;
|
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; }
|
IConfigManager *CreateConfigManager() { return new CConfigManager; }
|
||||||
|
|
|
@ -6,6 +6,9 @@
|
||||||
#include <base/detect.h>
|
#include <base/detect.h>
|
||||||
#include <engine/config.h>
|
#include <engine/config.h>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
// include protocol for MAX_CLIENT used in config_variables
|
// include protocol for MAX_CLIENT used in config_variables
|
||||||
#include <engine/shared/protocol.h>
|
#include <engine/shared/protocol.h>
|
||||||
|
|
||||||
|
@ -72,6 +75,8 @@ class CConfigManager : public IConfigManager
|
||||||
CCallback m_aCallbacks[MAX_CALLBACKS];
|
CCallback m_aCallbacks[MAX_CALLBACKS];
|
||||||
int m_NumCallbacks;
|
int m_NumCallbacks;
|
||||||
|
|
||||||
|
std::vector<std::string> m_vUnknownCommands;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CConfigManager();
|
CConfigManager();
|
||||||
|
|
||||||
|
@ -84,6 +89,8 @@ public:
|
||||||
void RegisterCallback(SAVECALLBACKFUNC pfnFunc, void *pUserData) override;
|
void RegisterCallback(SAVECALLBACKFUNC pfnFunc, void *pUserData) override;
|
||||||
|
|
||||||
void WriteLine(const char *pLine) override;
|
void WriteLine(const char *pLine) override;
|
||||||
|
|
||||||
|
void StoreUnknownCommand(const char *pCommand) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue