1/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
2/* If you are missing that file, acquire a complete release at teeworlds.com. */
3
4#include <base/dbg.h>
5#include <base/io.h>
6#include <base/log.h>
7#include <base/str.h>
8
9#include <engine/config.h>
10#include <engine/console.h>
11#include <engine/shared/config.h>
12#include <engine/shared/console.h>
13#include <engine/shared/protocol.h>
14#include <engine/storage.h>
15
16CConfig g_Config;
17
18// ----------------------- Config Variables
19
20static void EscapeParam(char *pDst, const char *pSrc, int Size)
21{
22 str_escape(dst: &pDst, src: pSrc, end: pDst + Size);
23}
24
25void SConfigVariable::ExecuteLine(const char *pLine) const
26{
27 m_pConsole->ExecuteLine(pStr: pLine, ClientId: (m_Flags & CFGFLAG_GAME) != 0 ? IConsole::CLIENT_ID_GAME : IConsole::CLIENT_ID_UNSPECIFIED);
28}
29
30bool SConfigVariable::CheckReadOnly() const
31{
32 if(!m_ReadOnly)
33 return false;
34 log_error("config", "The config variable '%s' cannot be changed right now.", m_pScriptName);
35 return true;
36}
37
38// -----
39
40void SIntConfigVariable::CommandCallback(IConsole::IResult *pResult, void *pUserData)
41{
42 SIntConfigVariable *pData = static_cast<SIntConfigVariable *>(pUserData);
43
44 if(pResult->NumArguments())
45 {
46 if(pData->CheckReadOnly())
47 return;
48
49 int Value = pResult->GetInteger(Index: 0);
50
51 // do clamping
52 if(pData->m_Min != pData->m_Max)
53 {
54 if(Value < pData->m_Min)
55 Value = pData->m_Min;
56 if(pData->m_Max != 0 && Value > pData->m_Max)
57 Value = pData->m_Max;
58 }
59
60 *pData->m_pVariable = Value;
61 if(pResult->m_ClientId != IConsole::CLIENT_ID_GAME)
62 pData->m_OldValue = Value;
63 }
64 else
65 {
66 log_info("config", "Value: %d", *pData->m_pVariable);
67 }
68}
69
70void SIntConfigVariable::Register()
71{
72 m_pConsole->Register(pName: m_pScriptName, pParams: "?i", Flags: m_Flags, pfnFunc: CommandCallback, pUser: this, pHelp: m_pHelp);
73}
74
75bool SIntConfigVariable::IsDefault() const
76{
77 return *m_pVariable == m_Default;
78}
79
80void SIntConfigVariable::Serialize(char *pOut, size_t Size, int Value) const
81{
82 str_format(buffer: pOut, buffer_size: Size, format: "%s %i", m_pScriptName, Value);
83}
84
85void SIntConfigVariable::Serialize(char *pOut, size_t Size) const
86{
87 Serialize(pOut, Size, Value: *m_pVariable);
88}
89
90void SIntConfigVariable::SerializeHumanReadable(char *pOut, size_t Size) const
91{
92 Serialize(pOut, Size);
93}
94
95void SIntConfigVariable::SetValue(int Value)
96{
97 if(CheckReadOnly())
98 return;
99 char aBuf[IConsole::CMDLINE_LENGTH];
100 Serialize(pOut: aBuf, Size: sizeof(aBuf), Value);
101 ExecuteLine(pLine: aBuf);
102}
103
104void SIntConfigVariable::ResetToDefault()
105{
106 SetValue(m_Default);
107}
108
109void SIntConfigVariable::ResetToOld()
110{
111 *m_pVariable = m_OldValue;
112}
113
114// -----
115
116void SColorConfigVariable::CommandCallback(IConsole::IResult *pResult, void *pUserData)
117{
118 SColorConfigVariable *pData = static_cast<SColorConfigVariable *>(pUserData);
119 if(pResult->NumArguments())
120 {
121 if(pData->CheckReadOnly())
122 return;
123
124 const auto Color = pResult->GetColor(Index: 0, DarkestLighting: pData->m_DarkestLighting);
125 const unsigned Value = Color.Pack(Darkest: pData->m_DarkestLighting, Alpha: pData->m_Alpha);
126
127 *pData->m_pVariable = Value;
128 if(pResult->m_ClientId != IConsole::CLIENT_ID_GAME)
129 pData->m_OldValue = Value;
130 }
131 else
132 {
133 log_info("config", "Value: %u", *pData->m_pVariable);
134
135 const ColorHSLA Hsla = ColorHSLA(*pData->m_pVariable, true).UnclampLighting(Darkest: pData->m_DarkestLighting);
136 log_info("config", "H: %d°, S: %d%%, L: %d%%", round_to_int(Hsla.h * 360), round_to_int(Hsla.s * 100), round_to_int(Hsla.l * 100));
137
138 const ColorRGBA Rgba = color_cast<ColorRGBA>(hsl: Hsla);
139 log_info("config", "R: %d, G: %d, B: %d, #%06X", round_to_int(Rgba.r * 255), round_to_int(Rgba.g * 255), round_to_int(Rgba.b * 255), Rgba.Pack(false));
140
141 if(pData->m_Alpha)
142 {
143 log_info("config", "A: %d%%", round_to_int(Hsla.a * 100));
144 }
145 }
146}
147
148void SColorConfigVariable::Register()
149{
150 m_pConsole->Register(pName: m_pScriptName, pParams: "?c", Flags: m_Flags, pfnFunc: CommandCallback, pUser: this, pHelp: m_pHelp);
151}
152
153bool SColorConfigVariable::IsDefault() const
154{
155 return *m_pVariable == m_Default;
156}
157
158void SColorConfigVariable::Serialize(char *pOut, size_t Size, unsigned Value) const
159{
160 str_format(buffer: pOut, buffer_size: Size, format: "%s %u", m_pScriptName, Value);
161}
162
163void SColorConfigVariable::Serialize(char *pOut, size_t Size) const
164{
165 Serialize(pOut, Size, Value: *m_pVariable);
166}
167
168void SColorConfigVariable::SerializeHumanReadable(char *pOut, size_t Size) const
169{
170 const ColorRGBA Rgba = color_cast<ColorRGBA>(hsl: ColorHSLA(*m_pVariable, m_Alpha).UnclampLighting(Darkest: m_DarkestLighting));
171 str_format(buffer: pOut, buffer_size: Size, format: "%s $%0*X", m_pScriptName, m_Alpha ? 8 : 6, Rgba.PackAlphaLast(Alpha: m_Alpha));
172}
173
174void SColorConfigVariable::SetValue(unsigned Value)
175{
176 if(CheckReadOnly())
177 return;
178 char aBuf[IConsole::CMDLINE_LENGTH];
179 Serialize(pOut: aBuf, Size: sizeof(aBuf), Value);
180 ExecuteLine(pLine: aBuf);
181}
182
183void SColorConfigVariable::ResetToDefault()
184{
185 SetValue(m_Default);
186}
187
188void SColorConfigVariable::ResetToOld()
189{
190 *m_pVariable = m_OldValue;
191}
192
193// -----
194
195SStringConfigVariable::SStringConfigVariable(IConsole *pConsole, const char *pScriptName, EVariableType Type, int Flags, const char *pHelp, char *pStr, const char *pDefault, size_t MaxSize, char *pOldValue) :
196 SConfigVariable(pConsole, pScriptName, Type, Flags, pHelp),
197 m_pStr(pStr),
198 m_pDefault(pDefault),
199 m_MaxSize(MaxSize),
200 m_pOldValue(pOldValue)
201{
202 str_copy(dst: m_pStr, src: m_pDefault, dst_size: m_MaxSize);
203 str_copy(dst: m_pOldValue, src: m_pDefault, dst_size: m_MaxSize);
204}
205
206void SStringConfigVariable::CommandCallback(IConsole::IResult *pResult, void *pUserData)
207{
208 SStringConfigVariable *pData = static_cast<SStringConfigVariable *>(pUserData);
209
210 if(pResult->NumArguments())
211 {
212 if(pData->CheckReadOnly())
213 return;
214
215 const char *pString = pResult->GetString(Index: 0);
216 str_copy(dst: pData->m_pStr, src: pString, dst_size: pData->m_MaxSize);
217
218 if(pResult->m_ClientId != IConsole::CLIENT_ID_GAME)
219 str_copy(dst: pData->m_pOldValue, src: pData->m_pStr, dst_size: pData->m_MaxSize);
220 }
221 else
222 {
223 log_info("config", "Value: %s", pData->m_pStr);
224 }
225}
226
227void SStringConfigVariable::Register()
228{
229 m_pConsole->Register(pName: m_pScriptName, pParams: "?r", Flags: m_Flags, pfnFunc: CommandCallback, pUser: this, pHelp: m_pHelp);
230}
231
232bool SStringConfigVariable::IsDefault() const
233{
234 return str_comp(a: m_pStr, b: m_pDefault) == 0;
235}
236
237void SStringConfigVariable::Serialize(char *pOut, size_t Size, const char *pValue) const
238{
239 str_copy(dst: pOut, src: m_pScriptName, dst_size: Size);
240 str_append(dst: pOut, src: " \"", dst_size: Size);
241 const int OutLen = str_length(str: pOut);
242 EscapeParam(pDst: pOut + OutLen, pSrc: pValue, Size: Size - OutLen - 1); // -1 to ensure space for final quote
243 str_append(dst: pOut, src: "\"", dst_size: Size);
244}
245
246void SStringConfigVariable::Serialize(char *pOut, size_t Size) const
247{
248 Serialize(pOut, Size, pValue: m_pStr);
249}
250
251void SStringConfigVariable::SerializeHumanReadable(char *pOut, size_t Size) const
252{
253 Serialize(pOut, Size);
254}
255
256void SStringConfigVariable::SetValue(const char *pValue)
257{
258 if(CheckReadOnly())
259 return;
260 char aBuf[2048];
261 Serialize(pOut: aBuf, Size: sizeof(aBuf), pValue);
262 ExecuteLine(pLine: aBuf);
263}
264
265void SStringConfigVariable::ResetToDefault()
266{
267 SetValue(m_pDefault);
268}
269
270void SStringConfigVariable::ResetToOld()
271{
272 str_copy(dst: m_pStr, src: m_pOldValue, dst_size: m_MaxSize);
273}
274
275// ----------------------- Config Manager
276CConfigManager::CConfigManager()
277{
278 m_pConsole = nullptr;
279 m_pStorage = nullptr;
280 m_ConfigFile = nullptr;
281 m_Failed = false;
282}
283
284void CConfigManager::Init()
285{
286 m_pConsole = Kernel()->RequestInterface<IConsole>();
287 m_pStorage = Kernel()->RequestInterface<IStorage>();
288
289 const auto &&AddVariable = [this](SConfigVariable *pVariable) {
290 m_vpAllVariables.push_back(x: pVariable);
291 if((pVariable->m_Flags & CFGFLAG_GAME) != 0)
292 m_vpGameVariables.push_back(x: pVariable);
293 pVariable->Register();
294 };
295
296 const auto &&AddIntVariable = [this, AddVariable](const char *pScriptName, int Flags, const char *pDesc, int *pVariable, int Default, int Min, int Max) {
297 dbg_assert(Min == 0 || Max == 0 || Min < Max, "MACRO_CONFIG_INT(%s): minimum (%d) must be less than maximum (%d)", pScriptName, Min, Max);
298 dbg_assert((Min == 0 || Default >= Min) && (Max == 0 || Default <= Max), "MACRO_CONFIG_INT(%s): default (%d) must be in range of minimum (%d) and maximum (%d)", pScriptName, Default, Min, Max);
299
300 char aHelp[512];
301 size_t HelpSize;
302 if(Min == 0 && Max == 0)
303 HelpSize = str_format(buffer: aHelp, buffer_size: sizeof(aHelp), format: "%s (default: %d)", pDesc, Default);
304 else if(Max == 0)
305 HelpSize = str_format(buffer: aHelp, buffer_size: sizeof(aHelp), format: "%s (default: %d, min: %d)", pDesc, Default, Min);
306 else
307 HelpSize = str_format(buffer: aHelp, buffer_size: sizeof(aHelp), format: "%s (default: %d, min: %d, max: %d)", pDesc, Default, Min, Max);
308 dbg_assert(HelpSize < sizeof(aHelp) - UTF8_BYTE_LENGTH - 1, "MACRO_CONFIG_INT(%s): help text possibly truncated. Increase size of aHelp.", pScriptName);
309
310 AddVariable(m_ConfigHeap.Allocate<SIntConfigVariable>(
311 Args&: m_pConsole, Args&: pScriptName, Args: SConfigVariable::VAR_INT, Args&: Flags, Args: m_ConfigHeap.StoreString(pSrc: aHelp), Args&: pVariable, Args&: Default, Args&: Min, Args&: Max));
312 };
313
314 const auto &&AddColorVariable = [this, AddVariable](const char *pScriptName, int Flags, const char *pDesc, unsigned *pVariable, unsigned Default) {
315 const bool Alpha = (Flags & CFGFLAG_COLALPHA) != 0;
316
317 char aHelp[512];
318 const size_t HelpSize = str_format(buffer: aHelp, buffer_size: sizeof(aHelp), format: "%s (default: $%0*X)", pDesc, Alpha ? 8 : 6, color_cast<ColorRGBA>(hsl: ColorHSLA(Default, Alpha)).Pack(Alpha));
319 dbg_assert(HelpSize < sizeof(aHelp) - UTF8_BYTE_LENGTH - 1, "MACRO_CONFIG_COL(%s): help text possibly truncated. Increase size of aHelp.", pScriptName);
320
321 AddVariable(m_ConfigHeap.Allocate<SColorConfigVariable>(
322 Args&: m_pConsole, Args&: pScriptName, Args: SConfigVariable::VAR_COLOR, Args&: Flags, Args: m_ConfigHeap.StoreString(pSrc: aHelp), Args&: pVariable, Args&: Default));
323 };
324
325 const auto &&AddStringVariable = [this, AddVariable](const char *pScriptName, int Flags, const char *pDesc, char *pVariable, size_t Len, const char *pDefault) {
326 dbg_assert(Len > 0 && Len <= 16 * 1024, "MACRO_CONFIG_STR(%s): length (%" PRIzu ") is invalid.", pScriptName, Len);
327
328 char aHelp[512];
329 const size_t HelpSize = str_format(buffer: aHelp, buffer_size: sizeof(aHelp), format: "%s (default: \"%s\", max length: %" PRIzu ")", pDesc, pDefault, Len - 1);
330 dbg_assert(HelpSize < sizeof(aHelp) - UTF8_BYTE_LENGTH - 1, "MACRO_CONFIG_STR(%s): help text possibly truncated. Increase size of aHelp.", pScriptName);
331
332 char *pOldValue = static_cast<char *>(m_ConfigHeap.Allocate(Size: Len));
333
334 AddVariable(m_ConfigHeap.Allocate<SStringConfigVariable>(
335 Args&: m_pConsole, Args&: pScriptName, Args: SConfigVariable::VAR_STRING, Args&: Flags, Args: m_ConfigHeap.StoreString(pSrc: aHelp), Args&: pVariable, Args&: pDefault, Args&: Len, Args&: pOldValue));
336 };
337
338#define MACRO_CONFIG_INT(Name, ScriptName, Def, Min, Max, Flags, Desc) AddIntVariable(#ScriptName, Flags, Desc, &g_Config.m_##Name, Def, Min, Max);
339#define MACRO_CONFIG_COL(Name, ScriptName, Def, Flags, Desc) AddColorVariable(#ScriptName, Flags, Desc, &g_Config.m_##Name, Def);
340#define MACRO_CONFIG_STR(Name, ScriptName, Len, Def, Flags, Desc) AddStringVariable(#ScriptName, Flags, Desc, g_Config.m_##Name, Len, Def);
341
342#include "config_variables.h"
343
344#undef MACRO_CONFIG_INT
345#undef MACRO_CONFIG_COL
346#undef MACRO_CONFIG_STR
347
348 m_pConsole->Register(pName: "reset", pParams: "s[config]", Flags: CFGFLAG_SERVER | CFGFLAG_CLIENT, pfnFunc: Con_Reset, pUser: this, pHelp: "Reset a config to its default value");
349 m_pConsole->Register(pName: "toggle", pParams: "s[config] s[value 1] s[value 2]", Flags: CFGFLAG_SERVER | CFGFLAG_CLIENT, pfnFunc: Con_Toggle, pUser: this, pHelp: "Toggle config value");
350 m_pConsole->Register(pName: "+toggle", pParams: "s[config] s[value 1] s[value 2]", Flags: CFGFLAG_CLIENT, pfnFunc: Con_ToggleStroke, pUser: this, pHelp: "Toggle config value via keypress");
351}
352
353void CConfigManager::Reset(const char *pScriptName)
354{
355 for(SConfigVariable *pVariable : m_vpAllVariables)
356 {
357 if((pVariable->m_Flags & m_pConsole->FlagMask()) != 0 && str_comp(a: pScriptName, b: pVariable->m_pScriptName) == 0)
358 {
359 pVariable->ResetToDefault();
360 return;
361 }
362 }
363
364 log_error("config", "Invalid config variable: '%s'", pScriptName);
365}
366
367void CConfigManager::ResetGameSettings()
368{
369 for(SConfigVariable *pVariable : m_vpGameVariables)
370 {
371 pVariable->ResetToOld();
372 }
373}
374
375void CConfigManager::SetReadOnly(const char *pScriptName, bool ReadOnly)
376{
377 for(SConfigVariable *pVariable : m_vpAllVariables)
378 {
379 if(str_comp(a: pScriptName, b: pVariable->m_pScriptName) == 0)
380 {
381 pVariable->m_ReadOnly = ReadOnly;
382 return;
383 }
384 }
385
386 dbg_assert_failed("Invalid config variable for SetReadOnly: '%s'", pScriptName);
387}
388
389void CConfigManager::SetGameSettingsReadOnly(bool ReadOnly)
390{
391 for(SConfigVariable *pVariable : m_vpGameVariables)
392 {
393 pVariable->m_ReadOnly = ReadOnly;
394 }
395}
396
397bool CConfigManager::Save()
398{
399 if(!m_pStorage || !g_Config.m_ClSaveSettings)
400 return true;
401
402 char aConfigFileTmp[IO_MAX_PATH_LENGTH];
403 m_ConfigFile = m_pStorage->OpenFile(pFilename: IStorage::FormatTmpPath(aBuf: aConfigFileTmp, BufSize: sizeof(aConfigFileTmp), CONFIG_FILE), Flags: IOFLAG_WRITE, Type: IStorage::TYPE_SAVE);
404
405 if(!m_ConfigFile)
406 {
407 log_error("config", "ERROR: opening %s failed", aConfigFileTmp);
408 return false;
409 }
410
411 m_Failed = false;
412
413 char aLineBuf[2048];
414 for(const SConfigVariable *pVariable : m_vpAllVariables)
415 {
416 if((pVariable->m_Flags & CFGFLAG_SAVE) != 0 && !pVariable->IsDefault())
417 {
418 pVariable->Serialize(pOut: aLineBuf, Size: sizeof(aLineBuf));
419 WriteLine(pLine: aLineBuf);
420 }
421 }
422
423 for(const auto &Callback : m_vCallbacks)
424 {
425 Callback.m_pfnFunc(this, Callback.m_pUserData);
426 }
427
428 for(const char *pCommand : m_vpUnknownCommands)
429 {
430 WriteLine(pLine: pCommand);
431 }
432
433 if(m_Failed)
434 {
435 log_error("config", "ERROR: writing to %s failed", aConfigFileTmp);
436 }
437
438 if(io_sync(io: m_ConfigFile) != 0)
439 {
440 m_Failed = true;
441 log_error("config", "ERROR: synchronizing %s failed", aConfigFileTmp);
442 }
443
444 if(io_close(io: m_ConfigFile) != 0)
445 {
446 m_Failed = true;
447 log_error("config", "ERROR: closing %s failed", aConfigFileTmp);
448 }
449
450 m_ConfigFile = nullptr;
451
452 if(m_Failed)
453 {
454 return false;
455 }
456
457 if(!m_pStorage->RenameFile(pOldFilename: aConfigFileTmp, CONFIG_FILE, Type: IStorage::TYPE_SAVE))
458 {
459 log_error("config", "ERROR: renaming %s to " CONFIG_FILE " failed", aConfigFileTmp);
460 return false;
461 }
462
463 log_info("config", "saved to " CONFIG_FILE);
464 return true;
465}
466
467void CConfigManager::RegisterCallback(SAVECALLBACKFUNC pfnFunc, void *pUserData)
468{
469 m_vCallbacks.emplace_back(args&: pfnFunc, args&: pUserData);
470}
471
472void CConfigManager::WriteLine(const char *pLine)
473{
474 if(!m_ConfigFile ||
475 io_write(io: m_ConfigFile, buffer: pLine, size: str_length(str: pLine)) != static_cast<unsigned>(str_length(str: pLine)) ||
476 !io_write_newline(io: m_ConfigFile))
477 {
478 m_Failed = true;
479 }
480}
481
482void CConfigManager::StoreUnknownCommand(const char *pCommand)
483{
484 m_vpUnknownCommands.push_back(x: m_ConfigHeap.StoreString(pSrc: pCommand));
485}
486
487void CConfigManager::PossibleConfigVariables(const char *pStr, int FlagMask, POSSIBLECFGFUNC pfnCallback, void *pUserData)
488{
489 for(const SConfigVariable *pVariable : m_vpAllVariables)
490 {
491 if(pVariable->m_Flags & FlagMask)
492 {
493 if(str_find_nocase(haystack: pVariable->m_pScriptName, needle: pStr))
494 {
495 pfnCallback(pVariable, pUserData);
496 }
497 }
498 }
499}
500
501const SConfigVariable *CConfigManager::FindVariable(const char *pScriptName) const
502{
503 for(const auto *pVariable : m_vpAllVariables)
504 {
505 if(str_comp(a: pVariable->m_pScriptName, b: pScriptName) == 0)
506 return pVariable;
507 }
508 return nullptr;
509}
510
511void CConfigManager::Con_Reset(IConsole::IResult *pResult, void *pUserData)
512{
513 static_cast<CConfigManager *>(pUserData)->Reset(pScriptName: pResult->GetString(Index: 0));
514}
515
516void CConfigManager::Con_Toggle(IConsole::IResult *pResult, void *pUserData)
517{
518 CConfigManager *pConfigManager = static_cast<CConfigManager *>(pUserData);
519 IConsole *pConsole = pConfigManager->m_pConsole;
520
521 const char *pScriptName = pResult->GetString(Index: 0);
522 for(SConfigVariable *pVariable : pConfigManager->m_vpAllVariables)
523 {
524 if((pVariable->m_Flags & pConsole->FlagMask()) == 0 ||
525 str_comp(a: pScriptName, b: pVariable->m_pScriptName) != 0)
526 {
527 continue;
528 }
529
530 if(pVariable->m_Type == SConfigVariable::VAR_INT)
531 {
532 SIntConfigVariable *pIntVariable = static_cast<SIntConfigVariable *>(pVariable);
533 const bool EqualToFirst = *pIntVariable->m_pVariable == pResult->GetInteger(Index: 1);
534 pIntVariable->SetValue(pResult->GetInteger(Index: EqualToFirst ? 2 : 1));
535 }
536 else if(pVariable->m_Type == SConfigVariable::VAR_COLOR)
537 {
538 SColorConfigVariable *pColorVariable = static_cast<SColorConfigVariable *>(pVariable);
539 const bool EqualToFirst = *pColorVariable->m_pVariable == pResult->GetColor(Index: 1, DarkestLighting: pColorVariable->m_DarkestLighting).Pack(Darkest: pColorVariable->m_DarkestLighting, Alpha: pColorVariable->m_Alpha);
540 const std::optional<ColorHSLA> Value = pResult->GetColor(Index: EqualToFirst ? 2 : 1, DarkestLighting: pColorVariable->m_DarkestLighting);
541 pColorVariable->SetValue(Value.value_or(u: ColorHSLA(0, 0, 0)).Pack(Darkest: pColorVariable->m_DarkestLighting, Alpha: pColorVariable->m_Alpha));
542 }
543 else if(pVariable->m_Type == SConfigVariable::VAR_STRING)
544 {
545 SStringConfigVariable *pStringVariable = static_cast<SStringConfigVariable *>(pVariable);
546 const bool EqualToFirst = str_comp(a: pStringVariable->m_pStr, b: pResult->GetString(Index: 1)) == 0;
547 pStringVariable->SetValue(pResult->GetString(Index: EqualToFirst ? 2 : 1));
548 }
549 return;
550 }
551
552 log_error("config", "Invalid config variable: '%s'", pScriptName);
553}
554
555void CConfigManager::Con_ToggleStroke(IConsole::IResult *pResult, void *pUserData)
556{
557 CConfigManager *pConfigManager = static_cast<CConfigManager *>(pUserData);
558 IConsole *pConsole = pConfigManager->m_pConsole;
559
560 const char *pScriptName = pResult->GetString(Index: 1);
561 for(SConfigVariable *pVariable : pConfigManager->m_vpAllVariables)
562 {
563 if((pVariable->m_Flags & pConsole->FlagMask()) == 0 ||
564 pVariable->m_Type != SConfigVariable::VAR_INT ||
565 str_comp(a: pScriptName, b: pVariable->m_pScriptName) != 0)
566 {
567 continue;
568 }
569
570 SIntConfigVariable *pIntVariable = static_cast<SIntConfigVariable *>(pVariable);
571 pIntVariable->SetValue(pResult->GetInteger(Index: 0) == 0 ? pResult->GetInteger(Index: 3) : pResult->GetInteger(Index: 2));
572 return;
573 }
574
575 log_error("config", "Invalid config variable: '%s'", pScriptName);
576}
577
578IConfigManager *CreateConfigManager() { return new CConfigManager; }
579