diff options
author | Kae <80987908+Novaenia@users.noreply.github.com> | 2024-09-09 20:32:23 +1000 |
---|---|---|
committer | Kae <80987908+Novaenia@users.noreply.github.com> | 2024-09-09 20:32:23 +1000 |
commit | 95b13f670d8ce1de5c71c35ce475de165b53cc4f (patch) | |
tree | 95fe62f2e012277e50dcb29a409478ab6b7ecbd2 /source/frontend/StarClientCommandProcessor.cpp | |
parent | 227585f1dc027dec43152a409dbadb26b19e2c3d (diff) |
code clean-up
Diffstat (limited to 'source/frontend/StarClientCommandProcessor.cpp')
-rw-r--r-- | source/frontend/StarClientCommandProcessor.cpp | 43 |
1 files changed, 11 insertions, 32 deletions
diff --git a/source/frontend/StarClientCommandProcessor.cpp b/source/frontend/StarClientCommandProcessor.cpp index 0237735..8a7e543 100644 --- a/source/frontend/StarClientCommandProcessor.cpp +++ b/source/frontend/StarClientCommandProcessor.cpp @@ -15,9 +15,9 @@ namespace Star { ClientCommandProcessor::ClientCommandProcessor(UniverseClientPtr universeClient, CinematicPtr cinematicOverlay, - MainInterfacePaneManager* paneManager, StringMap<StringList> macroCommands) - : m_universeClient(std::move(universeClient)), m_cinematicOverlay(std::move(cinematicOverlay)), - m_paneManager(paneManager), m_macroCommands(std::move(macroCommands)) { + MainInterfacePaneManager* paneManager, StringMap<StringList> macroCommands) + : m_universeClient(std::move(universeClient)), m_cinematicOverlay(std::move(cinematicOverlay)), + m_paneManager(paneManager), m_macroCommands(std::move(macroCommands)) { m_builtinCommands = { {"reload", bind(&ClientCommandProcessor::reload, this)}, {"whoami", bind(&ClientCommandProcessor::whoami, this)}, @@ -58,7 +58,7 @@ ClientCommandProcessor::ClientCommandProcessor(UniverseClientPtr universeClient, bool ClientCommandProcessor::adminCommandAllowed() const { return Root::singleton().configuration()->get("allowAdminCommandsFromAnyone").toBool() || - m_universeClient->mainPlayer()->isAdmin(); + m_universeClient->mainPlayer()->isAdmin(); } String ClientCommandProcessor::previewQuestPane(StringList const& arguments, function<PanePtr(QuestPtr)> createPane) { @@ -187,7 +187,7 @@ String ClientCommandProcessor::setGravity(String const& argumentsString) { return "You must be an admin to use this command."; m_universeClient->worldClient()->overrideGravity(lexicalCast<float>(arguments.at(0))); - return strf("Gravity set to {}, the change is LOCAL ONLY", arguments.at(0)); + return strf("Gravity set to {} (This is client-side!)", arguments.at(0)); } String ClientCommandProcessor::resetGravity() { @@ -431,34 +431,13 @@ String ClientCommandProcessor::swap(String const& argumentsString) { String ClientCommandProcessor::respawnInWorld(String const& argumentsString) { auto arguments = m_parser.tokenizeToStringList(argumentsString); + if (arguments.size() == 0) + return strf("Respawn in this world is currently {}", worldClient->respawnInWorld() ? "true" : "false"); - WorldClientPtr worldClient = m_universeClient->worldClient(); - - - if (arguments.size() == 0) { - const std::string stringResult = worldClient->respawnInWorld() ? "true" : "false"; - return "Respawn in this world is currently " + stringResult; // return the current state of the respawn value when no argument is given - } - if (arguments.size() > 1) { - return "Too many arguments for this command!"; // we dont wanna have too much, right? - } - - // behold: probably one of the least efficient ways to convert a Star::String to a boolean - bool value; - if (arguments[0].toLower() == "true") { - value = true; - } else if(arguments[0].toLower() == "false") { - value = false; - } - else { - return "Invalid argument!"; // at least we get validation if it was not a boolean - } - - bool result = worldClient->setRespawnInWorld(value); - // Convert boolean to string for the response - const std::string stringResult = result ? "true" : "false"; - - return "Successfully set respawn in this world to " + stringResult; + bool respawnInWorld = Json::parse(arguments.at(0)).toBool(); + auto worldClient = m_universeClient->worldClient(); + worldClient->setRespawnInWorld(respawnInWorld); + return strf("Respawn in this world set to {} (This is client-side!)", respawnInWorld ? "true" : "false"); } }
\ No newline at end of file |