add version command

This commit is contained in:
Lion Kortlepel
2022-11-11 21:04:42 +01:00
parent 69c2868025
commit e1c2d0d5fb
2 changed files with 14 additions and 4 deletions

View File

@@ -37,6 +37,7 @@ private:
void Command_Settings(const std::string& cmd, const std::vector<std::string>& args);
void Command_Clear(const std::string&, const std::vector<std::string>& args);
void Command_Debug(const std::string&, const std::vector<std::string>& args);
void Command_Version(const std::string&, const std::vector<std::string>& args);
void Autocomplete_Lua(const std::string&, std::vector<std::string>& suggestions);
void Autocomplete_Kick(const std::string&, std::vector<std::string>& suggestions);
@@ -58,6 +59,7 @@ private:
{ "settings", [this](const auto& a, const auto& b) { Command_Settings(a, b); } },
{ "clear", [this](const auto& a, const auto& b) { Command_Clear(a, b); } },
{ "debug", [this](const auto& a, const auto& b) { Command_Debug(a, b); } },
{ "version", [this](const auto& a, const auto& b) { Command_Version(a, b); } },
{ "say", [this](const auto&, const auto&) { Command_Say(""); } }, // shouldn't actually be called
};

View File

@@ -262,7 +262,8 @@ void TConsole::Command_Help(const std::string&, const std::vector<std::string>&
settings [command] sets or gets settings for the server, run `settings help` for more info
status how the server is doing and what it's up to
debug internal error and debug state of the server (for development)
clear clears the console window)";
clear clears the console window
version version info)";
Application::Console().WriteRaw("BeamMP-Server Console: " + std::string(sHelpString));
}
@@ -370,6 +371,13 @@ void TConsole::Command_Debug(const std::string&, const std::vector<std::string>&
});
}
void TConsole::Command_Version(const std::string&, const std::vector<std::string>& args) {
if (!EnsureArgsCount(args, 0)) {
return;
}
Application::Console().WriteRaw(fmt::format("BeamMP Server v{} ({})", Application::ServerVersionString(), BEAMMP_GIT_HASH));
}
void TConsole::Command_Kick(const std::string&, const std::vector<std::string>& args) {
if (!EnsureArgsCount(args, 1, size_t(-1))) {
return;
@@ -681,7 +689,6 @@ void TConsole::Autocomplete_Kick(const std::string& stub, std::vector<std::strin
}
return true;
});
}
void TConsole::Autocomplete_Settings(const std::string& stub, std::vector<std::string>& suggestions) {
@@ -690,7 +697,8 @@ void TConsole::Autocomplete_Settings(const std::string& stub, std::vector<std::s
auto [command, args] = ParseCommand(stub);
std::string arg;
if (!args.empty()) arg = boost::algorithm::to_lower_copy(args.at(0));
if (!args.empty())
arg = boost::algorithm::to_lower_copy(args.at(0));
// suggest setting names
if (command == "set" || command == "get") {
@@ -837,7 +845,7 @@ TConsole::TConsole() {
} else {
if (!mLuaEngine) {
beammp_error("Attempted to run a command before Lua engine started. Please wait and try again.");
} else if (cmd == "exit" || cmd == "quit") {
} else if (cmd == "exit" || cmd == "quit") {
beammp_info("gracefully shutting down");
Application::GracefullyShutdown();
} else if (cmd == "say") {