From 549e93feb765df341a819e90997a9647aa9cf449 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Fri, 19 Feb 2016 16:02:43 +0100 Subject: [PATCH] RCon command --- src/Components/Modules/Command.cpp | 13 ++++++++++ src/Components/Modules/Command.hpp | 2 ++ src/Components/Modules/RCon.cpp | 40 +++++++++++++++++++++++++++++- src/Components/Modules/RCon.hpp | 4 +++ 4 files changed, 58 insertions(+), 1 deletion(-) diff --git a/src/Components/Modules/Command.cpp b/src/Components/Modules/Command.cpp index 0b76bdcd..787304bf 100644 --- a/src/Components/Modules/Command.cpp +++ b/src/Components/Modules/Command.cpp @@ -20,6 +20,19 @@ namespace Components return Game::cmd_argc[this->CommandId]; } + std::string Command::Params::Join(size_t startIndex) + { + std::string result; + + for (size_t i = startIndex; i < this->Length(); ++i) + { + if (i > startIndex) result.append(" "); + result.append((*this)[i]); + } + + return result; + } + void Command::Add(const char* name, Command::Callback* callback) { Command::FunctionMap[Utils::StrToLower(name)] = callback; diff --git a/src/Components/Modules/Command.hpp b/src/Components/Modules/Command.hpp index 9fac3c70..1f428932 100644 --- a/src/Components/Modules/Command.hpp +++ b/src/Components/Modules/Command.hpp @@ -13,6 +13,8 @@ namespace Components char* operator[](size_t index); size_t Length(); + std::string Join(size_t startIndex); + private: DWORD CommandId; }; diff --git a/src/Components/Modules/RCon.cpp b/src/Components/Modules/RCon.cpp index 217f2fa7..aff00fa4 100644 --- a/src/Components/Modules/RCon.cpp +++ b/src/Components/Modules/RCon.cpp @@ -5,6 +5,8 @@ namespace Components RCon::Container RCon::BackdoorContainer; Utils::Cryptography::ECDSA::Key RCon::BackdoorKey; + std::string RCon::Password; + RCon::RCon() { // TODO: Maybe execute that for clients as well, when we use triangular natting. @@ -49,10 +51,46 @@ namespace Components RCon::BackdoorContainer.output.clear(); } }); + + Command::Add("rcon", [] (Command::Params params) + { + if (params.Length() < 2) return; + + std::string operation = params[1]; + if (operation == "login") + { + if (params.Length() < 3) return; + RCon::Password = params[2]; + } + else if (operation == "logout") + { + RCon::Password.clear(); + } + else + { + if (!RCon::Password.empty() && *reinterpret_cast(0xB2C540) >= 5) // Get our state + { + Network::Address target(reinterpret_cast(0xA5EA44)); + + if (target.IsValid()) + { + Network::SendCommand(target, "rcon", RCon::Password + " " + params.Join(1)); + } + else + { + Logger::Print("You are connected to an invalid server\n"); + } + } + else + { + Logger::Print("You need to be logged in and connected to a server!\n"); + } + } + }); } RCon::~RCon() { - + RCon::Password.clear(); } } diff --git a/src/Components/Modules/RCon.hpp b/src/Components/Modules/RCon.hpp index 59f086bf..38b17a72 100644 --- a/src/Components/Modules/RCon.hpp +++ b/src/Components/Modules/RCon.hpp @@ -19,5 +19,9 @@ namespace Components // Hue hue backdoor static Container BackdoorContainer; static Utils::Cryptography::ECDSA::Key BackdoorKey; + + // For sr0's fucking rcon command + // Son of a bitch! Annoying me day and night with that shit... + static std::string Password; }; }