-
-
Notifications
You must be signed in to change notification settings - Fork 445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor mtaserver.conf.template #3857
base: master
Are you sure you want to change the base?
Refactor mtaserver.conf.template #3857
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
Hmm, check out what I did. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks good, although I recommend inserting a comment at the beginning of the template file to let the user know that they shouldn't change it
Please resolve conflicts, @Fernando-A-Rocha |
@Dutchman101 Merge conflict resolved. I will apply Nico's suggestion now. |
@Nico8340 All good now? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Future WorkI believe that later we should refactor the config system removing the need to have 2 separate files local.conf and editor.conf (as well as editor_acl.xml) for the configuration of Host-Game and Map-Editor servers. It's bad practice that we are duplicating all config values to those files, while in reality all that is happening is some values changing when these servers are started (like startup resources and server name etc). This could be hardcoded in C++, and for Host-Game, the values of the last used preferred settings can be cached to core client config. I volunteer to do this refactoring if you guys agree. ->feedback, @Dutchman101 |
@@ -855,44 +855,53 @@ bool CMainConfig::AddMissingSettings() | |||
if (!g_pGame->IsUsingMtaServerConf()) | |||
return false; | |||
|
|||
SString strTemplateFilename = PathJoin(g_pServerInterface->GetServerModPath(), "mtaserver.conf.template"); | |||
const std::string templateFileName = PathJoin(g_pServerInterface->GetServerModPath(), SETTINGS_TEMPLATE_PATH); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::string_view
here and below?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::string_view
isn't the best choice here because PathJoin
returns a temporal object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but this object is no longer needed outside the function. Until the function completes and "exits", there should be a guarantee that the object created by PathJoin will exist, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The lifetime of a temporary object may be extended by binding to a reference, yes. But here is not the case. The result of PathJoin will be invalidated and std::string_view will deal with a dangling pointer.
pNode->SetCommentText(strNodeComment, true); | ||
bChanged = true; | ||
const std::string templateNodeValue = templateNode->GetTagContent(); | ||
const std::string templateNodeComment = templateNode->GetCommentText(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GetCommentText
returns SString
. This triggers an unnecessary string copying. It is recommended to use matching types for a variable and a function's return type.
foundNode->SetTagContent(templateNodeValue.c_str()); | ||
foundNode->SetCommentText(templateNodeComment.c_str(), true); | ||
|
||
CLogger::LogPrintf("Added missing '%s' setting to mtaserver.conf\n", &templateNodeName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean templateNodeName.c_str()
?
Context
The
mtaserver.conf.template
file is a copy of mtaserver.conf without the<module>
and<resource>
nodes, that devs have been maintaining manually. Default config already comes in mtaserver.conf. Without this PR, the script looks for mtaserver.conf.template, and if it finds it, it will scan for missing config nodes in the existing mtaserver.conf config, and then after it's done with the changes, it deletes the .template file. So it's only ever used once. The problem is that real MTA servers never get their hands on the .template file, so it is never used. Mtaserver.conf.template file is not shipped with the server via the installer or zip provided by mtasa.com. Devs compiling MTA:SA also don't need this template ever, because the default config is already in the mtaserver.conf file... Also, the note in the beginning of the mtaserver.conf.template file is false<!-- This file is compiled into the server binary.
This file is never compiled in the server binary, it gets deleted after use. So, it has zero practical use.What I changed
install_data.lua
to automatically duplicatemtaserver.conf
=>mtaserver.conf.template
compose_files.lua
to do thismtaserver.conf.template
to be included by the Installer (nightly.nsi)mtaserver.conf.template
after runningWhy?
mtaserver.conf.template
.