Skip to content
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

Main script config fixes #989

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions Server/Components/LegacyConfig/config_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,17 +487,15 @@ class LegacyConfigComponent final : public ILegacyConfigComponent, public Consol
processFallback(logger, config, typeIt->second, name, line.substr(idx + 1));
}
}
size_t gmcount = 0;
DynamicArray<StringView> list;
for (int i = 0; i < gamemodes_.size(); ++i)
{
if (gamemodes_[i] != "")
{
++gmcount;
list.emplace_back(gamemodes_[i]);
}
}
if (gmcount != 0)
if (!list.empty())
{
config.setStrings("pawn.main_scripts", list);
}
Expand Down
12 changes: 7 additions & 5 deletions Server/Components/Pawn/Manager/Manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "Manager.hpp"
#include "../PluginManager/PluginManager.hpp"
#include "../utils.hpp"
#include <utils.hpp>

#ifdef WIN32
#include <Windows.h>
Expand Down Expand Up @@ -416,25 +417,26 @@ bool PawnManager::Load(DynamicArray<StringView> const& mainScripts)
}
gamemodes_.clear();
gamemodeIndex_ = 0;
for (auto const& i : mainScripts)
for (StringView script : mainScripts)
{
script = trim(script);
// Split the mode name and count.
auto space = i.find_last_of(' ');
auto space = script.find_last_of(' ');
if (space == std::string::npos)
{
repeats_.push_back(1);
gamemodes_.push_back(String(i));
gamemodes_.push_back(String(script));
}
else
{
int count = 0;
auto conv = std::from_chars(i.data() + space + 1, i.data() + i.size(), count, 10);
auto conv = std::from_chars(script.data() + space + 1, script.data() + script.size(), count, 10);
if (conv.ec == std::errc::invalid_argument || conv.ec == std::errc::result_out_of_range || count < 1)
{
count = 1;
}
repeats_.push_back(count);
gamemodes_.push_back(String(i.substr(0, space)));
gamemodes_.push_back(String(trim(script.substr(0, space))));
}
}
gamemodeRepeat_ = repeats_[0];
Expand Down
5 changes: 3 additions & 2 deletions Server/Source/core_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,11 +553,12 @@ class Config final : public IEarlyConfig

void setStrings(StringView key, Span<const StringView> value) override
{
auto& vec = processed[String(key)].emplace<DynamicArray<String>>();
DynamicArray<String> newStrings;
for (const StringView v : value)
{
vec.emplace_back(String(v));
newStrings.emplace_back(String(v));
}
processed[String(key)].emplace<DynamicArray<String>>(std::move(newStrings));
}

void addBan(const BanEntry& entry) override
Expand Down
Loading