From 88f75fca4e8c09c02acecd11cbfee8ad0f99c4cb Mon Sep 17 00:00:00 2001 From: Diamante Date: Fri, 19 Apr 2024 16:49:37 +0200 Subject: [PATCH] fix(rcon): patch buffer flush bug (#216) --- src/client/component/command.cpp | 8 ++++---- src/client/component/rcon.cpp | 14 ++++++++++---- src/client/game/demonware/services/bdDML.cpp | 2 +- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/client/component/command.cpp b/src/client/component/command.cpp index ba2e2f92..d6f00813 100644 --- a/src/client/component/command.cpp +++ b/src/client/component/command.cpp @@ -169,11 +169,11 @@ namespace command { if (args.size() == 1) { - const auto current = game::Dvar_ValueToString(dvar, dvar->current); - const auto reset = game::Dvar_ValueToString(dvar, dvar->reset); + const std::string current = game::Dvar_ValueToString(dvar, dvar->current); + const std::string reset = game::Dvar_ValueToString(dvar, dvar->reset); console::info("\"%s\" is: \"%s\" default: \"%s\" checksum: %d type: %i\n", - dvars::dvar_get_name(dvar).data(), current, reset, dvar->checksum, dvar->type); + dvars::dvar_get_name(dvar).data(), current.data(), reset.data(), dvar->checksum, dvar->type); const auto dvar_info = dvars::dvar_get_description(dvar); @@ -184,7 +184,7 @@ namespace command } else { - char command[0x1000] = { 0 }; + char command[0x1000]{}; game::Dvar_GetCombinedString(command, 1); game::Dvar_SetCommand(args[0], command); } diff --git a/src/client/component/rcon.cpp b/src/client/component/rcon.cpp index 5f56df17..2d5f0073 100644 --- a/src/client/component/rcon.cpp +++ b/src/client/component/rcon.cpp @@ -20,6 +20,7 @@ namespace rcon std::atomic_bool is_redirecting_{ false }; std::atomic_bool has_redirected_{ false }; game::netadr_s redirect_target_ = {}; + std::string redirect_buffer = {}; std::recursive_mutex redirect_lock; void setup_redirect(const game::netadr_s& target) @@ -29,15 +30,19 @@ namespace rcon has_redirected_ = false; is_redirecting_ = true; redirect_target_ = target; + redirect_buffer.clear(); } void clear_redirect() { std::lock_guard $(redirect_lock); + network::send(redirect_target_, "print", redirect_buffer, '\n'); + has_redirected_ = false; is_redirecting_ = false; redirect_target_ = {}; + redirect_buffer.clear(); } void send_rcon_command(const std::string& password, const std::string& data) @@ -69,7 +74,7 @@ namespace rcon std::string build_status_buffer() { - const auto mapname = game::Dvar_FindVar("mapname"); + const auto* mapname = game::Dvar_FindVar("mapname"); std::string buffer{}; buffer.append(utils::string::va("map: %s\n", mapname->current.string)); @@ -78,7 +83,7 @@ namespace rcon buffer.append( "--- ----- --- ---- -------------------------------- ---------------- --------------------- -----\n"); - const auto svs_clients = *game::svs_clients; + const auto* svs_clients = *game::svs_clients; if (svs_clients == nullptr) { return buffer; @@ -86,7 +91,7 @@ namespace rcon for (auto i = 0u; i < *game::svs_numclients; i++) { - const auto client = &svs_clients[i]; + const auto* client = &svs_clients[i]; if (client->header.state >= 1 && client->gentity && client->gentity->client) { @@ -122,9 +127,10 @@ namespace rcon if (is_redirecting_) { has_redirected_ = true; - network::send(redirect_target_, "print", message, '\n'); + redirect_buffer.append(message); return true; } + return false; } diff --git a/src/client/game/demonware/services/bdDML.cpp b/src/client/game/demonware/services/bdDML.cpp index 08aee84b..6d54ea51 100644 --- a/src/client/game/demonware/services/bdDML.cpp +++ b/src/client/game/demonware/services/bdDML.cpp @@ -22,7 +22,7 @@ namespace demonware { auto result = std::make_unique(); result->country_code = "US"; - result->country_code = "'Murica"; + result->country = "United States of America"; result->region = "New York"; result->city = "New York"; result->latitude = 0;