Skip to content

Commit cf339e4

Browse files
authored
Merge pull request #989 from openmultiplayer/hual/main_script_config_fixes
Main script config fixes
2 parents a2cc944 + dc6ec26 commit cf339e4

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

Server/Components/LegacyConfig/config_main.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -487,17 +487,15 @@ class LegacyConfigComponent final : public ILegacyConfigComponent, public Consol
487487
processFallback(logger, config, typeIt->second, name, line.substr(idx + 1));
488488
}
489489
}
490-
size_t gmcount = 0;
491490
DynamicArray<StringView> list;
492491
for (int i = 0; i < gamemodes_.size(); ++i)
493492
{
494493
if (gamemodes_[i] != "")
495494
{
496-
++gmcount;
497495
list.emplace_back(gamemodes_[i]);
498496
}
499497
}
500-
if (gmcount != 0)
498+
if (!list.empty())
501499
{
502500
config.setStrings("pawn.main_scripts", list);
503501
}

Server/Components/Pawn/Manager/Manager.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "Manager.hpp"
1515
#include "../PluginManager/PluginManager.hpp"
1616
#include "../utils.hpp"
17+
#include <utils.hpp>
1718

1819
#ifdef WIN32
1920
#include <Windows.h>
@@ -416,25 +417,26 @@ bool PawnManager::Load(DynamicArray<StringView> const& mainScripts)
416417
}
417418
gamemodes_.clear();
418419
gamemodeIndex_ = 0;
419-
for (auto const& i : mainScripts)
420+
for (StringView script : mainScripts)
420421
{
422+
script = trim(script);
421423
// Split the mode name and count.
422-
auto space = i.find_last_of(' ');
424+
auto space = script.find_last_of(' ');
423425
if (space == std::string::npos)
424426
{
425427
repeats_.push_back(1);
426-
gamemodes_.push_back(String(i));
428+
gamemodes_.push_back(String(script));
427429
}
428430
else
429431
{
430432
int count = 0;
431-
auto conv = std::from_chars(i.data() + space + 1, i.data() + i.size(), count, 10);
433+
auto conv = std::from_chars(script.data() + space + 1, script.data() + script.size(), count, 10);
432434
if (conv.ec == std::errc::invalid_argument || conv.ec == std::errc::result_out_of_range || count < 1)
433435
{
434436
count = 1;
435437
}
436438
repeats_.push_back(count);
437-
gamemodes_.push_back(String(i.substr(0, space)));
439+
gamemodes_.push_back(String(trim(script.substr(0, space))));
438440
}
439441
}
440442
gamemodeRepeat_ = repeats_[0];

Server/Source/core_impl.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -553,11 +553,12 @@ class Config final : public IEarlyConfig
553553

554554
void setStrings(StringView key, Span<const StringView> value) override
555555
{
556-
auto& vec = processed[String(key)].emplace<DynamicArray<String>>();
556+
DynamicArray<String> newStrings;
557557
for (const StringView v : value)
558558
{
559-
vec.emplace_back(String(v));
559+
newStrings.emplace_back(String(v));
560560
}
561+
processed[String(key)].emplace<DynamicArray<String>>(std::move(newStrings));
561562
}
562563

563564
void addBan(const BanEntry& entry) override

0 commit comments

Comments
 (0)