From 98a395721ee0383bd2ed046235dd644909f2f943 Mon Sep 17 00:00:00 2001 From: lonaasan Date: Mon, 9 Sep 2024 09:53:11 +0200 Subject: [Small Addition] added respawnInWorld Command --- source/frontend/StarClientCommandProcessor.cpp | 46 +++++++++++++++++++------- 1 file changed, 34 insertions(+), 12 deletions(-) (limited to 'source/frontend/StarClientCommandProcessor.cpp') diff --git a/source/frontend/StarClientCommandProcessor.cpp b/source/frontend/StarClientCommandProcessor.cpp index 2d98289..39b0d89 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 macroCommands) - : m_universeClient(std::move(universeClient)), m_cinematicOverlay(std::move(cinematicOverlay)), - m_paneManager(paneManager), m_macroCommands(std::move(macroCommands)) { + MainInterfacePaneManager* paneManager, StringMap 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)}, @@ -51,13 +51,14 @@ ClientCommandProcessor::ClientCommandProcessor(UniverseClientPtr universeClient, {"maketechavailable", bind(&ClientCommandProcessor::makeTechAvailable, this, _1)}, {"enabletech", bind(&ClientCommandProcessor::enableTech, this, _1)}, {"upgradeship", bind(&ClientCommandProcessor::upgradeShip, this, _1)}, - {"swap", bind(&ClientCommandProcessor::swap, this, _1)} + {"swap", bind(&ClientCommandProcessor::swap, this, _1)}, + {"respawnInWorld", bind(&ClientCommandProcessor::respawnInWorld, this)} }; } 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 createPane) { @@ -128,7 +129,7 @@ String ClientCommandProcessor::reload() { String ClientCommandProcessor::whoami() { return strf("Client: You are {}. You are {}an Admin.", - m_universeClient->mainPlayer()->name(), m_universeClient->mainPlayer()->isAdmin() ? "" : "not "); + m_universeClient->mainPlayer()->name(), m_universeClient->mainPlayer()->isAdmin() ? "" : "not "); } String ClientCommandProcessor::gravity() { @@ -273,8 +274,8 @@ String ClientCommandProcessor::previewNewQuest(String const& argumentsString) { return "You must be an admin to use this command."; return previewQuestPane(arguments, [this](QuestPtr const& quest) { - return make_shared(m_universeClient->questManager(), quest, m_universeClient->mainPlayer()); - }); + return make_shared(m_universeClient->questManager(), quest, m_universeClient->mainPlayer()); + }); } String ClientCommandProcessor::previewQuestComplete(String const& argumentsString) { @@ -283,8 +284,8 @@ String ClientCommandProcessor::previewQuestComplete(String const& argumentsStrin return "You must be an admin to use this command."; return previewQuestPane(arguments, [this](QuestPtr const& quest) { - return make_shared(quest, m_universeClient->mainPlayer(), CinematicPtr{}); - }); + return make_shared(quest, m_universeClient->mainPlayer(), CinematicPtr{}); + }); } String ClientCommandProcessor::previewQuestFailed(String const& argumentsString) { @@ -293,8 +294,8 @@ String ClientCommandProcessor::previewQuestFailed(String const& argumentsString) return "You must be an admin to use this command."; return previewQuestPane(arguments, [this](QuestPtr const& quest) { - return make_shared(quest, m_universeClient->mainPlayer()); - }); + return make_shared(quest, m_universeClient->mainPlayer()); + }); } String ClientCommandProcessor::clearScannedObjects() { @@ -427,4 +428,25 @@ String ClientCommandProcessor::swap(String const& argumentsString) { return "Failed to swap player"; } +String ClientCommandProcessor::respawnInWorld() { + WorldClientPtr worldClient = m_universeClient->worldClient(); + + // Make sure we got the worldClient + if (!worldClient) { + return "Error: Unable to access world client."; + } + + if (worldClient->toggleRespawnInWorld()) { + // Convert boolean to string for the response + const std::string result = worldClient->respawnInWorld() ? "true" : "false"; + + return "Successfully switched respawn in this world to " + result; + } + else + return "Failed to switch respawn in this world!"; + + // This should never trigger, but its better to have it than not :3 + return "Something unforseen happend!"; } + +} \ No newline at end of file -- cgit v1.2.3 From 732fc2a9d7e9a4c5e3cf01ac191a392462f3da8c Mon Sep 17 00:00:00 2001 From: lonaasan Date: Mon, 9 Sep 2024 11:27:14 +0200 Subject: [Revision] Applying the recommended changes from pull request #110 (return current value if no argument given, moving the methods to their correct location) --- source/frontend/StarClientCommandProcessor.cpp | 40 +++++++++++++++++--------- source/frontend/StarClientCommandProcessor.hpp | 2 +- source/game/StarWorldClient.cpp | 22 +++++++------- source/game/StarWorldClient.hpp | 4 ++- 4 files changed, 40 insertions(+), 28 deletions(-) (limited to 'source/frontend/StarClientCommandProcessor.cpp') diff --git a/source/frontend/StarClientCommandProcessor.cpp b/source/frontend/StarClientCommandProcessor.cpp index 39b0d89..0237735 100644 --- a/source/frontend/StarClientCommandProcessor.cpp +++ b/source/frontend/StarClientCommandProcessor.cpp @@ -52,7 +52,7 @@ ClientCommandProcessor::ClientCommandProcessor(UniverseClientPtr universeClient, {"enabletech", bind(&ClientCommandProcessor::enableTech, this, _1)}, {"upgradeship", bind(&ClientCommandProcessor::upgradeShip, this, _1)}, {"swap", bind(&ClientCommandProcessor::swap, this, _1)}, - {"respawnInWorld", bind(&ClientCommandProcessor::respawnInWorld, this)} + {"respawnInWorld", bind(&ClientCommandProcessor::respawnInWorld, this, _1)} }; } @@ -428,25 +428,37 @@ String ClientCommandProcessor::swap(String const& argumentsString) { return "Failed to swap player"; } -String ClientCommandProcessor::respawnInWorld() { +String ClientCommandProcessor::respawnInWorld(String const& argumentsString) { + auto arguments = m_parser.tokenizeToStringList(argumentsString); + + WorldClientPtr worldClient = m_universeClient->worldClient(); - // Make sure we got the worldClient - if (!worldClient) { - return "Error: Unable to access world client."; - } - if (worldClient->toggleRespawnInWorld()) { - // Convert boolean to string for the response - const std::string result = worldClient->respawnInWorld() ? "true" : "false"; + 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? + } - return "Successfully switched respawn in this world to " + result; + // 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 "Failed to switch respawn in this world!"; + 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"; - // This should never trigger, but its better to have it than not :3 - return "Something unforseen happend!"; + return "Successfully set respawn in this world to " + stringResult; } } \ No newline at end of file diff --git a/source/frontend/StarClientCommandProcessor.hpp b/source/frontend/StarClientCommandProcessor.hpp index 658242c..94dad5d 100644 --- a/source/frontend/StarClientCommandProcessor.hpp +++ b/source/frontend/StarClientCommandProcessor.hpp @@ -58,7 +58,7 @@ private: String enableTech(String const& argumentsString); String upgradeShip(String const& argumentsString); String swap(String const& argumentsString); - String respawnInWorld(); + String respawnInWorld(String const& argumentsString); UniverseClientPtr m_universeClient; CinematicPtr m_cinematicOverlay; diff --git a/source/game/StarWorldClient.cpp b/source/game/StarWorldClient.cpp index afe71ac..0d3e039 100644 --- a/source/game/StarWorldClient.cpp +++ b/source/game/StarWorldClient.cpp @@ -142,6 +142,16 @@ bool WorldClient::respawnInWorld() const { return m_respawnInWorld; } +bool WorldClient::setRespawnInWorld(bool value = NULL) { + + if (value != NULL) + m_respawnInWorld = value; + else + m_respawnInWorld ^= true; // dont know if we still want to set the respawn if no argument is given here + + return m_respawnInWorld; +} + void WorldClient::removeEntity(EntityId entityId, bool andDie) { auto entity = m_entityMap->entity(entityId); if (!entity) @@ -2421,16 +2431,4 @@ void WorldClient::setupForceRegions() { } } -bool WorldClient::toggleRespawnInWorld() { - // Setting oldValue to check if m_respawnInWorld triggered correctly later - const bool oldValue = respawnInWorld(); - - m_respawnInWorld ^= true; - - if (respawnInWorld() != oldValue) { - return true; - } - return false; -} - } diff --git a/source/game/StarWorldClient.hpp b/source/game/StarWorldClient.hpp index 2f1cbc0..9f15e0e 100644 --- a/source/game/StarWorldClient.hpp +++ b/source/game/StarWorldClient.hpp @@ -109,6 +109,8 @@ public: void reviveMainPlayer(); bool respawnInWorld() const; + bool setRespawnInWorld(bool value); + void removeEntity(EntityId entityId, bool andDie); WorldTemplateConstPtr currentTemplate() const; @@ -176,7 +178,7 @@ public: typedef std::function BroadcastCallback; BroadcastCallback& broadcastCallback(); - bool toggleRespawnInWorld(); + private: static const float DropDist; -- cgit v1.2.3 From 95b13f670d8ce1de5c71c35ce475de165b53cc4f Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Mon, 9 Sep 2024 20:32:23 +1000 Subject: code clean-up --- assets/opensb/help.config.patch | 2 +- source/frontend/StarClientCommandProcessor.cpp | 43 +++++++------------------- source/game/StarWorldClient.cpp | 7 ++--- source/game/StarWorldClient.hpp | 3 +- 4 files changed, 15 insertions(+), 40 deletions(-) (limited to 'source/frontend/StarClientCommandProcessor.cpp') diff --git a/assets/opensb/help.config.patch b/assets/opensb/help.config.patch index b3f31a6..ad1da12 100644 --- a/assets/opensb/help.config.patch +++ b/assets/opensb/help.config.patch @@ -11,6 +11,6 @@ "openSbCommands": { "swap": "Usage /swap . Swaps the current character, case-insensitive, only substring required.", - "respawninworld": "Usage /respawnInWorld. Sets the respawn flag for the current world until you teleport away." + "respawninworld": "Usage /respawninworld. Sets the respawn flag for the current world until you teleport away." } } 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 macroCommands) - : m_universeClient(std::move(universeClient)), m_cinematicOverlay(std::move(cinematicOverlay)), - m_paneManager(paneManager), m_macroCommands(std::move(macroCommands)) { + MainInterfacePaneManager* paneManager, StringMap 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 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(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 diff --git a/source/game/StarWorldClient.cpp b/source/game/StarWorldClient.cpp index 3e85c79..8abfcdf 100644 --- a/source/game/StarWorldClient.cpp +++ b/source/game/StarWorldClient.cpp @@ -142,11 +142,8 @@ bool WorldClient::respawnInWorld() const { return m_respawnInWorld; } -bool WorldClient::setRespawnInWorld(bool value) { - - m_respawnInWorld = value; - - return m_respawnInWorld; +void WorldClient::setRespawnInWorld(bool respawnInWorld) { + m_respawnInWorld = respawnInWorld; } void WorldClient::removeEntity(EntityId entityId, bool andDie) { diff --git a/source/game/StarWorldClient.hpp b/source/game/StarWorldClient.hpp index 9f15e0e..1616b10 100644 --- a/source/game/StarWorldClient.hpp +++ b/source/game/StarWorldClient.hpp @@ -108,8 +108,7 @@ public: bool mainPlayerDead() const; void reviveMainPlayer(); bool respawnInWorld() const; - - bool setRespawnInWorld(bool value); + void setRespawnInWorld(bool respawnInWorld); void removeEntity(EntityId entityId, bool andDie); -- cgit v1.2.3 From f59f6be5d33c64f8d0f335f6f6993f05a939afb5 Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Mon, 9 Sep 2024 20:35:08 +1000 Subject: oop --- source/frontend/StarClientCommandProcessor.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source/frontend/StarClientCommandProcessor.cpp') diff --git a/source/frontend/StarClientCommandProcessor.cpp b/source/frontend/StarClientCommandProcessor.cpp index 8a7e543..ac87397 100644 --- a/source/frontend/StarClientCommandProcessor.cpp +++ b/source/frontend/StarClientCommandProcessor.cpp @@ -430,12 +430,12 @@ String ClientCommandProcessor::swap(String const& argumentsString) { String ClientCommandProcessor::respawnInWorld(String const& argumentsString) { auto arguments = m_parser.tokenizeToStringList(argumentsString); - + auto worldClient = m_universeClient->worldClient(); + if (arguments.size() == 0) return strf("Respawn in this world is currently {}", worldClient->respawnInWorld() ? "true" : "false"); 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"); } -- cgit v1.2.3