feat: print warning for invalid gametypes

This commit is contained in:
2024-06-10 20:31:08 +02:00
parent a3fd324479
commit 2d69f181e2
6 changed files with 55 additions and 13 deletions

View File

@ -216,9 +216,9 @@ namespace console
lock _{};
#ifdef _WIN32
SetConsoleTitleA(title.data());
SetConsoleTitleA(title.c_str());
#else
printf("\033]0;%s\007", title.data());
printf("\033]0;%s\007", title.c_str());
fflush(stdout);
#endif
}

View File

@ -2,6 +2,7 @@
#include <utils/string.hpp>
#include "console.hpp"
#include "map_rotation.hpp"
using namespace std::literals;
@ -10,6 +11,29 @@ namespace map_rotation
{
namespace
{
bool is_valid_game_type(const std::string& game_type)
{
static std::array<const char*, 14> game_types =
{
"arena",
"conf",
"ctf",
"dd",
"dm",
"dom",
"gtnw",
"gun",
"infect",
"koth",
"oneflag",
"sab",
"sd",
"war",
};
return std::ranges::find(game_types, game_type) != std::end(game_types);
}
bool is_valid_key(const std::string& key)
{
static std::array<const char*, 3> keys =
@ -69,10 +93,15 @@ namespace map_rotation
if (is_valid_key(key))
{
this->add_entry(key, value);
if (key == "gametype" && !is_valid_game_type(value))
{
console::warn("It appears you have an invalid game type in your map rotation (%s)", value.c_str());
}
}
else
{
throw map_rotation_parse_error(utils::string::va("Invalid key '%s'", key.data()));
throw map_rotation_parse_error(utils::string::va("Invalid key '%s'", key.c_str()));
}
}
}

View File

@ -2,7 +2,7 @@
namespace map_rotation
{
#define DEFAULT_ERROR_MSG "Map Rotation Parse Error"
constexpr auto* DEFAULT_ERROR_MSG = "Map Rotation Parse Error";
class map_rotation_parse_error : public std::runtime_error
{