diff --git a/deps/commandline b/deps/commandline index 71240f6..e9218e5 160000 --- a/deps/commandline +++ b/deps/commandline @@ -1 +1 @@ -Subproject commit 71240f634b211d830679e7d2841b897c7c30dad9 +Subproject commit e9218e554bb93c383873344f4703c103834c6005 diff --git a/include/Common.h b/include/Common.h index 930d329..76640aa 100644 --- a/include/Common.h +++ b/include/Common.h @@ -12,6 +12,7 @@ extern TSentry Sentry; #include #include #include +#include #include "Compat.h" diff --git a/include/TConfig.h b/include/TConfig.h index 3fcc597..fe43d5c 100644 --- a/include/TConfig.h +++ b/include/TConfig.h @@ -3,6 +3,7 @@ #include "Common.h" #include +#include #define TOML11_PRESERVE_COMMENTS_BY_DEFAULT #include // header-only version of TOML++ diff --git a/include/TConsole.h b/include/TConsole.h index 8a9f383..c181c5c 100644 --- a/include/TConsole.h +++ b/include/TConsole.h @@ -49,6 +49,7 @@ private: { "list", [this](const auto& a, const auto& b) { Command_List(a, b); } }, { "status", [this](const auto& a, const auto& b) { Command_Status(a, b); } }, { "settings", [this](const auto& a, const auto& b) { Command_Settings(a, b); } }, + { "say", [this](const auto& a, const auto& b) { Command_Say(""); } }, // shouldn't actually be called }; Commandline mCommandline; diff --git a/include/TLuaEngine.h b/include/TLuaEngine.h index 64d1a9c..9017400 100644 --- a/include/TLuaEngine.h +++ b/include/TLuaEngine.h @@ -154,6 +154,8 @@ public: static constexpr const char* BeamMPFnNotFoundError = "BEAMMP_FN_NOT_FOUND"; + std::vector GetStateGlobalKeysForState(TLuaStateId StateId); + // Debugging functions (slow) std::unordered_map /* handlers */> Debug_GetEventsForState(TLuaStateId StateId); std::queue>> Debug_GetStateExecuteQueueForState(TLuaStateId StateId); @@ -178,6 +180,8 @@ private: void operator()() override; sol::state_view State() { return sol::state_view(mState); } + std::vector GetStateGlobalKeys(); + // Debug functions, slow std::queue>> Debug_GetStateExecuteQueue(); std::queue, std::vector>> Debug_GetStateFunctionQueue(); diff --git a/src/TConsole.cpp b/src/TConsole.cpp index 18af61d..1682a3a 100644 --- a/src/TConsole.cpp +++ b/src/TConsole.cpp @@ -417,12 +417,12 @@ void TConsole::Command_Status(const std::string&, const std::vector << "\t\tEvent handlers: " << mLuaEngine->GetRegisteredEventHandlerCount() << "\n" << "\tSubsystems:\n" << "\t\tGood/Starting/Bad: " << SystemsGood << "/" << SystemsStarting << "/" << SystemsBad << "\n" - << "\t\tShutting down/Shutdown: " << SystemsShuttingDown << "/" << SystemsShutdown << "\n" + << "\t\tShutting down/Shut down: " << SystemsShuttingDown << "/" << SystemsShutdown << "\n" << "\t\tGood: [ " << SystemsGoodList << " ]\n" << "\t\tStarting: [ " << SystemsStartingList << " ]\n" << "\t\tBad: [ " << SystemsBadList << " ]\n" << "\t\tShutting down: [ " << SystemsShuttingDownList << " ]\n" - << "\t\tShutdown: [ " << SystemsShutdownList << " ]\n" + << "\t\tShut down: [ " << SystemsShutdownList << " ]\n" << ""; Application::Console().WriteRaw(Status.str()); @@ -573,6 +573,47 @@ TConsole::TConsole() { beammp_error("Console died with: " + std::string(e.what()) + ". This could be a fatal error and could cause the server to terminate."); } }; + mCommandline.on_autocomplete = [this](Commandline& c, std::string stub) { + std::vector suggestions; + try { + auto cmd = TrimString(stub); + //beammp_error("yes 1"); + //beammp_error(stub); + if (mIsLuaConsole) { // if lua + if (!mLuaEngine) { + beammp_info("Lua not started yet, please try again in a second"); + } else { + std::string prefix {}; + for (size_t i = stub.length(); i > 0; i--) { + if (!std::isalnum(stub[i - 1]) && stub[i - 1] != '_') { + prefix = stub.substr(0, i); + stub = stub.substr(i); + break; + } + } + auto keys = mLuaEngine->GetStateGlobalKeysForState(mStateId); + for (const auto& key : keys) { + std::string::size_type n = key.find(stub); + if (n == 0) { + suggestions.push_back(prefix + key); + //beammp_warn(cmd_name); + } + } + } + } else { // if not lua + for (const auto& [cmd_name, cmd_fn] : mCommandMap) { + std::string::size_type n = cmd_name.find(stub); + if (n == 0) { + suggestions.push_back(cmd_name); + //beammp_warn(cmd_name); + } + } + } + } catch (const std::exception& e) { + beammp_error("Console died with: " + std::string(e.what()) + ". This could be a fatal error and could cause the server to terminate."); + } + return suggestions; + }; } void TConsole::Write(const std::string& str) { diff --git a/src/TLuaEngine.cpp b/src/TLuaEngine.cpp index c71a9c5..f17a34f 100644 --- a/src/TLuaEngine.cpp +++ b/src/TLuaEngine.cpp @@ -192,6 +192,21 @@ std::vector TLuaEngine::Debug_GetResultsToCheckForState(TLuaStateId return Result; } +std::vector TLuaEngine::GetStateGlobalKeysForState(TLuaStateId StateId) { + std::unique_lock Lock(mLuaStatesMutex); + auto Result = mLuaStates.at(StateId)->GetStateGlobalKeys(); + return Result; +} + +std::vector TLuaEngine::StateThreadData::GetStateGlobalKeys() { + auto globals = mStateView.globals(); + std::vector Result; + for (const auto& [key, value] : globals) { + Result.push_back(key.as()); + } + return Result; +} + void TLuaEngine::WaitForAll(std::vector>& Results, const std::optional& Max) { for (const auto& Result : Results) { bool Cancelled = false;