From 2d69f181e254aac22760ad4786c23d9636cd36e1 Mon Sep 17 00:00:00 2001 From: Future Date: Mon, 10 Jun 2024 20:31:08 +0200 Subject: [PATCH] feat: print warning for invalid gametypes --- .github/workflows/build.yml | 17 ++++++++++++++--- src/component/console.cpp | 4 ++-- src/component/map_rotation.cpp | 31 ++++++++++++++++++++++++++++++- src/component/map_rotation.hpp | 2 +- src/main.cpp | 10 ++++++---- src/utils/io.cpp | 4 ++-- 6 files changed, 55 insertions(+), 13 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index afcfef1..2b4793e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 diff --git a/src/component/console.cpp b/src/component/console.cpp index e3adc9e..0d3e0d2 100644 --- a/src/component/console.cpp +++ b/src/component/console.cpp @@ -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 } diff --git a/src/component/map_rotation.cpp b/src/component/map_rotation.cpp index 5484ebe..e51b13a 100644 --- a/src/component/map_rotation.cpp +++ b/src/component/map_rotation.cpp @@ -2,6 +2,7 @@ #include +#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 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 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())); } } } diff --git a/src/component/map_rotation.hpp b/src/component/map_rotation.hpp index f54e644..4eccac4 100644 --- a/src/component/map_rotation.hpp +++ b/src/component/map_rotation.hpp @@ -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 { diff --git a/src/main.cpp b/src/main.cpp index d892ccf..4c21eb2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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())); } } diff --git a/src/utils/io.cpp b/src/utils/io.cpp index 2145539..8c07735 100644 --- a/src/utils/io.cpp +++ b/src/utils/io.cpp @@ -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)