feat: print warning for invalid gametypes

This commit is contained in:
6arelyFuture 2024-06-10 20:31:08 +02:00
parent a3fd324479
commit 2d69f181e2
Signed by: Future
GPG Key ID: FA77F074E98D98A5
6 changed files with 55 additions and 13 deletions

View File

@ -29,9 +29,12 @@ jobs:
- debug
- release
arch:
- x86
- x64
- arm64
include:
- arch: x86
platform: Win32
- arch: x64
platform: x64
- arch: arm64
@ -79,6 +82,7 @@ jobs:
- debug
- release
arch:
- x86
- x64
- arm64
steps:
@ -95,6 +99,13 @@ jobs:
sudo apt-get update
sudo apt-get install crossbuild-essential-arm64 -y
- name: Install dependencies (x86)
if: matrix.arch == 'x86'
run: |
sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get -y install gcc-multilib g++-multilib
- name: Install Premake5
uses: diamante0018/setup-premake@master
with:
@ -184,10 +195,10 @@ jobs:
shell: bash
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3.2.0
uses: docker/setup-buildx-action@v3.3.0
- name: Login to DockerHub
uses: docker/login-action@v3.1.0
uses: docker/login-action@v3.2.0
with:
username: ${{ secrets.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
@ -203,7 +214,7 @@ jobs:
- name: Build and Push Docker Image
id: build-and-push
uses: docker/build-push-action@v5.1.0
uses: docker/build-push-action@v5.3.0
with:
context: .
platforms: linux/amd64

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
{

View File

@ -21,12 +21,12 @@ namespace
std::string data;
if (!utils::io::read_file(filename, &data) || data.empty())
{
throw std::runtime_error(utils::string::va("'%s' is empty", filename.data()));
throw std::runtime_error(utils::string::va("'%s' is empty", filename.c_str()));
}
if (game::parse_client_effects(data.data()))
{
console::info("Successfully parsed '%s'\n", filename.data());
console::info("Successfully parsed '%s'\n", filename.c_str());
}
}
@ -41,9 +41,11 @@ namespace
std::string data;
if (!utils::io::read_file(filename, &data) || data.empty())
{
throw std::runtime_error(utils::string::va("'%s' is empty", filename.data()));
throw std::runtime_error(utils::string::va("'%s' is empty", filename.c_str()));
}
console::info("Please ensure that the map rotation is in all lowercase\n");
try
{
map_rotation::rotation_data rotation_data;
@ -53,7 +55,7 @@ namespace
}
catch (const std::exception& ex)
{
console::error(utils::string::va("%s. '%s' contains invalid data!\n", ex.what(), filename.data()));
console::error(utils::string::va("%s. '%s' contains invalid data!\n", ex.what(), filename.c_str()));
}
}

View File

@ -7,12 +7,12 @@ namespace utils
{
bool remove_file(const std::string& file)
{
return std::remove(file.data()) == 0;
return std::remove(file.c_str()) == 0;
}
bool move_file(const std::string& src, const std::string& target)
{
return std::rename(src.data(), target.data()) == 0;
return std::rename(src.c_str(), target.c_str()) == 0;
}
bool file_exists(const std::string& file)