From d1d7521ee859f10e99fb3f82e710c8bbeb7c41c5 Mon Sep 17 00:00:00 2001 From: untodesu Date: Sun, 16 Mar 2025 22:19:39 +0500 Subject: Fix the bizzare CRC32 callback I forgot to remove - This fixes bother not working - Separated client and server splashes - Added server splashes --- game/shared/splash.cc | 46 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 8 deletions(-) (limited to 'game/shared/splash.cc') diff --git a/game/shared/splash.cc b/game/shared/splash.cc index ec7b3c8..068c5c6 100644 --- a/game/shared/splash.cc +++ b/game/shared/splash.cc @@ -1,14 +1,29 @@ #include "shared/pch.hh" #include "shared/splash.hh" -constexpr static const char *SPLASHES_FILENAME = "misc/splashes.txt"; +constexpr static const char *SPLASHES_FILENAME_CLIENT = "misc/splashes_client.txt"; +constexpr static const char *SPLASHES_FILENAME_SERVER = "misc/splashes_server.txt"; +constexpr static std::size_t SPLASH_SERVER_MAX_LENGTH = 32; static std::mt19937_64 splash_random; static std::vector splash_lines; -void splash::init(void) +static std::string sanitize_line(const std::string &line) { - if(auto file = PHYSFS_openRead(SPLASHES_FILENAME)) { + std::string result; + + for(auto chr : line) { + if((chr == '\r') || (chr == '\n')) + continue; + result.push_back(chr); + } + + return result; +} + +static void splash_init_filename(const char *filename) +{ + if(auto file = PHYSFS_openRead(filename)) { auto source = std::string(PHYSFS_fileLength(file), char(0x00)); PHYSFS_readBytes(file, source.data(), source.size()); PHYSFS_close(file); @@ -16,14 +31,29 @@ void splash::init(void) std::string line; std::istringstream stream(source); - while(std::getline(stream, line)) { - splash_lines.push_back(line); - } - + while(std::getline(stream, line)) + splash_lines.push_back(sanitize_line(line)); splash_random.seed(std::random_device()()); } else { - splash_lines.push_back(fmt::format("{}: {}", SPLASHES_FILENAME, PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()))); + splash_lines.push_back(fmt::format("{}: {}", filename, PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode()))); + splash_random.seed(std::random_device()()); + } +} + +void splash::init_client(void) +{ + splash_init_filename(SPLASHES_FILENAME_CLIENT); +} + +void splash::init_server(void) +{ + splash_init_filename(SPLASHES_FILENAME_SERVER); + + // Server browser GUI should be able to display + // these splash messages without text clipping over + for(int i = 0; i < splash_lines.size(); i++) { + splash_lines[i] = splash_lines[i].substr(0, SPLASH_SERVER_MAX_LENGTH); } } -- cgit