Skip to content

Commit

Permalink
remove mtaserver.conf.template
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernando-A-Rocha committed Nov 14, 2024
1 parent 750d09a commit 525f43d
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 354 deletions.
57 changes: 0 additions & 57 deletions Server/mods/deathmatch/logic/CMainConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
#include "CHTTPD.h"
#include "CStaticFunctionDefinitions.h"

#define MTA_SERVER_CONF_TEMPLATE "mtaserver.conf.template"

extern CGame* g_pGame;

CBandwidthSettings* g_pBandwidthSettings = new CBandwidthSettings();
Expand Down Expand Up @@ -116,11 +114,6 @@ bool CMainConfig::Load()
return false;
}

if (AddMissingSettings())
{
Save();
}

// Name
int iResult = GetString(m_pRootNode, "servername", m_strServerName, 1, 96);
if (iResult == DOESNT_EXIST)
Expand Down Expand Up @@ -843,56 +836,6 @@ bool CMainConfig::Save()
return false;
}

//
// Compare against default config and add missing nodes.
// Returns true if nodes were added.
//
bool CMainConfig::AddMissingSettings()
{
// Only mtaserver.conf is currently supported
if (!g_pGame->IsUsingMtaServerConf())
return false;

SString strTemplateFilename = PathJoin(g_pServerInterface->GetServerModPath(), "mtaserver.conf.template");

if (!FileExists(strTemplateFilename))
return false;

CXMLFile* pFileTemplate = g_pServerInterface->GetXML()->CreateXML(strTemplateFilename);
CXMLNode* pRootNodeTemplate = pFileTemplate && pFileTemplate->Parse() ? pFileTemplate->GetRootNode() : nullptr;
if (!pRootNodeTemplate)
{
CLogger::ErrorPrintf("Can't parse '%s'\n", *strTemplateFilename);
return false;
}

// Check that each item in the template also exists in the server config
bool bChanged = false;
CXMLNode* pPrevNode = nullptr;
for (auto it = pRootNodeTemplate->ChildrenBegin(); it != pRootNodeTemplate->ChildrenEnd(); ++it)
{
CXMLNode* pNodeTemplate = *it;
SString strNodeName = pNodeTemplate->GetTagName();
CXMLNode* pNode = m_pRootNode->FindSubNode(strNodeName);
if (!pNode)
{
CLogger::LogPrintf("Adding missing '%s' to mtaserver.conf\n", *strNodeName);
SString strNodeValue = pNodeTemplate->GetTagContent();
SString strNodeComment = pNodeTemplate->GetCommentText();
pNode = m_pRootNode->CreateSubNode(strNodeName, pPrevNode);
pNode->SetTagContent(strNodeValue);
pNode->SetCommentText(strNodeComment, true);
bChanged = true;
}
pPrevNode = pNode;
}

// Clean up
g_pServerInterface->GetXML()->DeleteXML(pFileTemplate);
FileDelete(strTemplateFilename);
return bChanged;
}

bool CMainConfig::IsValidPassword(const char* szPassword)
{
if (!szPassword)
Expand Down
1 change: 0 additions & 1 deletion Server/mods/deathmatch/logic/CMainConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ class CMainConfig : public CXMLConfig
private:
void RegisterCommand(const char* szName, FCommandHandler* pFunction, bool bRestricted, const char* szConsoleHelpText);
bool GetSettingTable(const SString& strName, const char** szAttribNames, uint uiNumAttribNames, CLuaArguments* outTable);
bool AddMissingSettings();

CConsole* m_pConsole;
CXMLNode* m_pRootNode;
Expand Down
Loading

0 comments on commit 525f43d

Please sign in to comment.