Skip to content

Commit c50ccb0

Browse files
committed
Automatically insert missing settings into mtaserver.conf at server start
1 parent 97ab9f7 commit c50ccb0

File tree

7 files changed

+406
-11
lines changed

7 files changed

+406
-11
lines changed

Server/mods/deathmatch/logic/CMainConfig.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*****************************************************************************/
1919

2020
#include "StdInc.h"
21+
#define MTA_SERVER_CONF_TEMPLATE "mtaserver.conf.template"
2122

2223
extern CGame * g_pGame;
2324

@@ -132,6 +133,11 @@ bool CMainConfig::Load ( void )
132133
return false;
133134
}
134135

136+
if (AddMissingSettings())
137+
{
138+
Save();
139+
}
140+
135141
// Name
136142
int iResult = GetString ( m_pRootNode, "servername", m_strServerName, 1, 96 );
137143
if ( iResult == DOESNT_EXIST )
@@ -851,6 +857,54 @@ bool CMainConfig::Save ( void )
851857
}
852858

853859

860+
//
861+
// Compare against default config and add missing nodes.
862+
// Returns true if nodes were added.
863+
//
864+
bool CMainConfig::AddMissingSettings(void)
865+
{
866+
// Load template
867+
const char *szTemplateText =
868+
#include MTA_SERVER_CONF_TEMPLATE
869+
;
870+
SString strTemplateFilename = PathJoin(g_pServerInterface->GetServerModPath(), "resource-cache", "conf.template");
871+
FileSave(strTemplateFilename, szTemplateText);
872+
CXMLFile* pFileTemplate = g_pServerInterface->GetXML()->CreateXML(strTemplateFilename);
873+
CXMLNode* pRootNodeTemplate = pFileTemplate && pFileTemplate->Parse() ? pFileTemplate->GetRootNode() : nullptr;
874+
if (!pRootNodeTemplate)
875+
{
876+
CLogger::ErrorPrintf("Can't parse '%s'\n", *strTemplateFilename);
877+
return false;
878+
}
879+
880+
// Check that each item in the template also exists in the server config
881+
bool bChanged = false;
882+
CXMLNode* pPrevNode = nullptr;
883+
for(auto it = pRootNodeTemplate->ChildrenBegin(); it != pRootNodeTemplate->ChildrenEnd(); ++it)
884+
{
885+
CXMLNode* pNodeTemplate = *it;
886+
SString strNodeName = pNodeTemplate->GetTagName();
887+
CXMLNode* pNode = m_pRootNode->FindSubNode(strNodeName);
888+
if (!pNode)
889+
{
890+
CLogger::LogPrintf("Adding missing '%s' to mtaserver.conf\n", *strNodeName);
891+
SString strNodeValue = pNodeTemplate->GetTagContent();
892+
SString strNodeComment = pNodeTemplate->GetCommentText();
893+
pNode = m_pRootNode->CreateSubNode(strNodeName, pPrevNode);
894+
pNode->SetTagContent(strNodeValue);
895+
pNode->SetCommentText(strNodeComment, true);
896+
bChanged = true;
897+
}
898+
pPrevNode = pNode;
899+
}
900+
901+
// Clean up
902+
g_pServerInterface->GetXML()->DeleteXML(pFileTemplate);
903+
FileDelete(strTemplateFilename);
904+
return bChanged;
905+
}
906+
907+
854908
bool CMainConfig::IsValidPassword ( const char* szPassword )
855909
{
856910
if ( !szPassword )

Server/mods/deathmatch/logic/CMainConfig.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ class CMainConfig: public CXMLConfig
153153
private:
154154
void RegisterCommand ( const char* szName, FCommandHandler* pFunction, bool bRestricted );
155155
bool GetSettingTable ( const SString& strName, const char** szAttribNames, uint uiNumAttribNames, CLuaArguments* outTable );
156+
bool AddMissingSettings ( void );
156157

157158
CConsole* m_pConsole;
158159
CLuaManager* m_pLuaManager;
Lines changed: 266 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,266 @@
1+
R"=====(
2+
<!-- This file is compiled into the server binary.
3+
It is used for inserting missing settings into mtaserver.conf at server startup -->
4+
<config>
5+
<!-- This parameter specifies the name the server will be visible as in the ingame server browser
6+
and on Game-Monitor. It is a required parameter. -->
7+
<servername>Default MTA Server</servername>
8+
9+
<!-- This parameter specifies the contact email addresses for the owner(s) of this server.
10+
The email addresses will not be publicly available, and only used by MTA administrators
11+
to contact the server owner.
12+
Note: Missing or incorrect owner_email_address can affect visibility in the master server list.
13+
Values: Comma separated list of email addresses -->
14+
<owner_email_address></owner_email_address>
15+
16+
<!-- ONLY USE THIS PARAMETER IF YOU ARE SURE OF WHAT YOU ARE DOING - it is generally only
17+
needed for professional servers and should be left at the default value otherwise.
18+
This parameter specifies the IP to use for servers that have multiple IP addresses. If set
19+
to auto, it will automatically detect and use the server's standard local IP address.
20+
Values: auto or x.x.x.x ; default value: auto
21+
** SERVERIP SHOULD BE LEFT SET TO auto UNLESS YOU ARE SURE OF WHAT YOU ARE DOING **
22+
** WARNING: SETTING serverip AND THEN ASKING FOR SUPPORT CAN CAUSE DEATH OR INJURY ** -->
23+
<serverip>auto</serverip>
24+
25+
<!-- This parameter specifies the UDP port on which the server will be accepting incoming player
26+
connections; default value: 22003. It is a required parameter. -->
27+
<serverport>22003</serverport>
28+
29+
<!-- This parameter specifies the number of maximum player slots available on the server; default
30+
value: 32. It is a required parameter. -->
31+
<maxplayers>32</maxplayers>
32+
33+
<!-- This parameter specifies the TCP port on which the server will be accepting incoming http
34+
connections. It can be set to the same value as <serverport>. It is a required parameter
35+
if <httpserver> is set to 1. -->
36+
<httpport>22005</httpport>
37+
38+
<!-- If set, this parameter specifies the external URL from which clients will be able to download
39+
needed resources ingame. If not set (or the external URL files are incorrect), resource downloads
40+
are switched to the internal http server. -->
41+
<httpdownloadurl></httpdownloadurl>
42+
43+
<!-- This parameter limits the number of http connections each client can make. Depending on the type
44+
of http server that is used, a lower figure may reduce download timeouts.
45+
Available range: 1 to 8. -->
46+
<httpmaxconnectionsperclient>5</httpmaxconnectionsperclient>
47+
48+
<!-- This parameter limits the number http connections that an IP can initiate over a short period of time.
49+
Available range: 1 to 100. default value: 20 -->
50+
<httpdosthreshold>20</httpdosthreshold>
51+
52+
<!-- This parameter lists the IP addresses that are to be excluded from http dos threshold limits.
53+
e.g. 88.11.22.33,101.2.3.4 -->
54+
<http_dos_exclude></http_dos_exclude>
55+
56+
<!-- By default, the server will block the use of locally customized gta3.img player skins
57+
This setting can be used to allow such mods. Not recommended for competitive servers.
58+
Values: none, peds ; default value: none -->
59+
<allow_gta3_img_mods>none</allow_gta3_img_mods>
60+
61+
<!-- By default, the server will block the use of customized GTA:SA data files. -->
62+
<!-- To allow specific client files, add one or more of the following: -->
63+
<!-- <client_file name="data/carmods.dat" verify="0"/> -->
64+
65+
<!-- Comma separated list of disabled anti-cheats.
66+
For details see http://wiki.multitheftauto.com/wiki/Anti-cheat_guide
67+
e.g. To disable anti-cheat #2 and #3, use: 2,3 -->
68+
<disableac></disableac>
69+
70+
<!-- Comma separated list of enabled special detections.
71+
A special detection is a type of anti-cheat for (usually) harmless game modifications.
72+
Competitive servers may wish to enable special detections, but most servers should leave this setting blank.
73+
For details see http://wiki.multitheftauto.com/wiki/Anti-cheat_guide
74+
e.g. To enable special detection #12 use: 12 -->
75+
<enablesd></enablesd>
76+
77+
<!-- Minimum client version. Clients with a lower version will not be allowed to connect. After
78+
disconnection, clients will be given an opportunity to download an update.
79+
If left blank, this setting is disabled and there are no restrictions on who can connect.
80+
Version numbers are described here: http://wiki.multitheftauto.com/wiki/GetPlayerVersion
81+
and look like this: 1.1.0-9.03100.0
82+
Note that this setting only determines if the client should be prompted to update. The actual
83+
build number they receive will be the highest available. See: http://nightly.mtasa.com/ver -->
84+
<minclientversion></minclientversion>
85+
86+
<!-- This parameter specifies if/when the <minclientversion> setting is automatically updated.
87+
Keeping <minclientversion> updated can help reduce cheating.
88+
Note: The instant setting (2) is only recommended for competitive servers.
89+
Values: 0 - disabled, 1 - enabled (delayed by a few days), 2 - enabled (instant) ; default value: 1. -->
90+
<minclientversion_auto_update>1</minclientversion_auto_update>
91+
92+
<!-- Recommended client version. When connecting, if clients have a lower version, they will be given
93+
the option to download an update. If left blank, this setting is disabled.
94+
Note that this setting only determines if the client should be prompted to update. The actual
95+
build number they receive will be the highest available. See: http://nightly.mtasa.com/ver -->
96+
<recommendedclientversion></recommendedclientversion>
97+
98+
<!-- This parameter can be used to make the server report to Game-Monitor master servers, allowing it to
99+
be visible in the ingame server browser. An additional UDP port needs to be available for this to
100+
work (value from <serverport> + 123 , so on a default <serverport> value 22003 the right port
101+
will be 22126 ). Available values: 0 - disabled , 1 - enabled. Optional parameter, defaults to 0. -->
102+
<ase>1</ase>
103+
104+
<!-- This parameter allows you to disable LAN broadcasting. -->
105+
<donotbroadcastlan>0</donotbroadcastlan>
106+
107+
<!-- If set, players will have to provide a password specified below, before they can connect to the
108+
server. If left blank, server doesn't require a password from them. -->
109+
<password></password>
110+
111+
<!-- This parameter reduces the server's bandwidth usage by using various optimizations.
112+
Values: none, medium or maximum ; default value: medium -->
113+
<bandwidth_reduction>medium</bandwidth_reduction>
114+
115+
<!-- The following ???_sync_interval parameters determine the time in milliseconds between certain
116+
network packets being sent. More information on how each settings works is available here:
117+
http://wiki.multitheftauto.com/wiki/Server_mtaserver.conf -->
118+
<!-- Player sync interval. Default: 100 -->
119+
<player_sync_interval>100</player_sync_interval>
120+
<!-- Lightweight (player) sync interval. Used when players are far apart. Default: 1500 -->
121+
<lightweight_sync_interval>1500</lightweight_sync_interval>
122+
<!-- Camera sync interval. Default: 500 -->
123+
<camera_sync_interval>500</camera_sync_interval>
124+
<!-- Ped sync interval. Default: 400 -->
125+
<ped_sync_interval>400</ped_sync_interval>
126+
<!-- Unoccupied_vehicle sync interval. Default: 400 -->
127+
<unoccupied_vehicle_sync_interval>400</unoccupied_vehicle_sync_interval>
128+
<!-- Keysync mouse rotation sync interval. For limiting key sync packets due to mouse movement. Default: 100 -->
129+
<keysync_mouse_sync_interval>100</keysync_mouse_sync_interval>
130+
<!-- Keysync analog movement sync interval. For limiting key sync packets due to joystick movement. Default: 100 -->
131+
<keysync_analog_sync_interval>100</keysync_analog_sync_interval>
132+
133+
<!-- This parameter can improve the reliability of shots when using certain weapons. However, it uses more bandwidth.
134+
Values: 0 - disabled , 1 - enabled ; default value: 1. -->
135+
<bullet_sync>1</bullet_sync>
136+
137+
<!-- This parameter sets the amount of extrapolation that clients will apply to remote vehicles. This can reduce
138+
some of the latency induced location disparency by predicting where the remote vehicles will probably be.
139+
Depending on the gamemode, an incorrect prediction may have a negative effect. Therefore this setting
140+
should be considered experimental.
141+
Available range: 0 to 100. Default - 0 -->
142+
<vehext_percent>0</vehext_percent>
143+
144+
<!-- This parameter places a limit on how much time (in milliseconds) the vehicle extrapolation will attempt to
145+
compensate for.
146+
Only relevant if <vehext_percent> is greater than zero.
147+
Available range: 50 to 500. Default - 150 -->
148+
<vehext_ping_limit>150</vehext_ping_limit>
149+
150+
<!-- This parameter can reduce the delay of player actions appearing on remote clients by 2 frames (approx 50ms).
151+
Due to the impact this may have on shot lag compensation, it should be considered experimental.
152+
Values: 0 - disabled , 1 - enabled ; default value: 0. -->
153+
<latency_reduction>0</latency_reduction>
154+
155+
<!-- Specifies the location and file name of this servers unique private key.
156+
This is used to prevent private files saved on the client from being read by other servers.
157+
More infomation about client private files can be found here: http://wiki.multitheftauto.com/wiki/Filepath
158+
Keep a backup of this file in a safe place. Default value: server-id.keys-->
159+
<idfile>server-id.keys</idfile>
160+
161+
<!-- Specifies the location and name of the main server log file. If left blank, server won't be saving this file. -->
162+
<logfile>logs/server.log</logfile>
163+
164+
<!-- As well as the main log file, login successes and failures are logged here for easy reviewing of security issues.
165+
If left blank, this file is not used -->
166+
<authfile>logs/server_auth.log</authfile>
167+
168+
<!-- Specifies the location and name of the file used to log database queries.
169+
The server command 'debugdb' sets the amount of logging. -->
170+
<dbfile>logs/db.log</dbfile>
171+
172+
<!-- Specifies the location and name of the file used to log loadstring function calls.
173+
If left blank or not set, no logging is done. -->
174+
<!-- <loadstringfile>logs/loadstring.log</loadstringfile> -->
175+
176+
<!-- This parameter specifies the location and name of the Access Control List settings file. If left
177+
blank, server will use acl.xml file, located in the same folder as this configuration file. -->
178+
<acl>acl.xml</acl>
179+
180+
<!-- Specifies the location and name of the debugscript log file. If left blank, server won't be saving this file. -->
181+
<scriptdebuglogfile>logs/scripts.log</scriptdebuglogfile>
182+
183+
<!-- Specifies the level of the debugscript log file. Available values: 0, 1, 2, 3. When not set, defaults to 0. -->
184+
<scriptdebugloglevel>0</scriptdebugloglevel>
185+
186+
<!-- Specifies the level of the html debug. Available values: 0, 1, 2, 3. When not set, defaults to 0. -->
187+
<htmldebuglevel>0</htmldebuglevel>
188+
189+
<!-- Specifies whether or not duplicate log lines should be filtered. Available values: 0 or 1, defaults to 1. -->
190+
<filter_duplicate_log_lines>1</filter_duplicate_log_lines>
191+
192+
<!-- Specifies the frame rate limit that will be applied to connecting clients.
193+
Available range: 25 to 100. Default: 36. -->
194+
<fpslimit>36</fpslimit>
195+
196+
<!-- This parameter specifies whether or not to enable player voice chat in-game
197+
Values: 0 - disabled , 1 - enabled -->
198+
<voice>0</voice>
199+
200+
<!-- This parameter specifies the sample rate for voice chat. 'voice' parameter must be set to 1 for this to be effective.
201+
Higher settings use more bandwidth and increase the sampling quality of voice chat
202+
Values: 0 - Narrowband (8kHz), 1 - Wideband (16kHz), 2 - Ultrawideband (32kHz). Default - 1 -->
203+
<voice_samplerate>1</voice_samplerate>
204+
205+
<!-- This parameter specifies the voice quality for voice chat. 'voice' parameter must be set to 1 for this to be effective.
206+
Higher settings use more bandwidth and increase the the overall quality of voice chat
207+
Available range: 0 to 10. Default - 4 -->
208+
<voice_quality>4</voice_quality>
209+
210+
<!-- Specifies the voice bitrate, in bps. This optional parameter overrides the previous two settings.
211+
If not set, MTA handles this automatically. Use with care. -->
212+
<!-- <voice_bitrate>24600</voice_bitrate> -->
213+
214+
<!-- This parameter specifies the path to use for a basic backup of some server files.
215+
Note that basic backups are only made during server startup. Default value: backups -->
216+
<backup_path>backups</backup_path>
217+
218+
<!-- This parameter specifies the number of days between each basic backup.
219+
Backups are only made during server startup, so the actual interval may be much longer.
220+
Setting backup_interval to 0 will disable backups
221+
Available range: 0 to 30. Default - 3 -->
222+
<backup_interval>3</backup_interval>
223+
224+
<!-- This parameter specifies the maximum number of backup copies to keep.
225+
Setting backup_copies to 0 will disable backups
226+
Available range: 0 to 100. Default - 10 -->
227+
<backup_copies>10</backup_copies>
228+
229+
<!-- This parameter specifies when the internal sqlite databases should be defragmented.
230+
http://www.sqlite.org/lang_vacuum.html
231+
Values: 0 - Never, 1 - On server start only after basic backup, 2 - On server start always. Default - 1 -->
232+
<compact_internal_databases>1</compact_internal_databases>
233+
234+
<!-- This parameter specifies whether server crash dump files should be sent to MTA HQ.
235+
Values: 0 - Off, 1 - On. Default - 1 -->
236+
<crash_dump_upload>1</crash_dump_upload>
237+
238+
<!-- This parameter lists the ACL groups that are protected by serial authorization.
239+
Login attempts to a protected account from a second serial are blocked until the serial is manually authorized via
240+
the authserial command.
241+
For more info see: https://mtasa.com/authserial
242+
Note: This is security critical feature and disabling auth_serial_groups can affect visibility in the master server list.
243+
Values: Comma separated list of ACL groups. Default - Admin -->
244+
<auth_serial_groups>Admin</auth_serial_groups>
245+
246+
<!-- This parameter specifies if the authorized serial login checks should also apply to the http interface.
247+
Protected account login attempts to the http interface will only succeed if the IP address matches one
248+
recently used by the account holder in-game
249+
For more info see: https://mtasa.com/authserialhttp
250+
Note: This is security critical feature and disabling auth_serial_http can affect visibility in the master server list.
251+
Values: 0 - Off, 1 - Enabled. Default - 1 -->
252+
<auth_serial_http>1</auth_serial_http>
253+
254+
<!-- This parameter specifies which IP addresses should always pass auth_serial_http checks.
255+
Values: Comma separated list of IP addresses -->
256+
<auth_serial_http_ip_exceptions>127.0.0.1</auth_serial_http_ip_exceptions>
257+
258+
<!-- This parameter specifies if extra security measures are applied to resources which use dbConnect with mysql.
259+
The extra measures are:
260+
- Script files cannot be accessed with fileOpen()
261+
- meta.xml is read only
262+
*NOTE* This only protects resources which use dbConnect with mysql
263+
Values: 0 - Off, 1 - Enabled. Default - 1 -->
264+
<database_credentials_protection>1</database_credentials_protection>
265+
</config>
266+
)====="

0 commit comments

Comments
 (0)