From 98a395721ee0383bd2ed046235dd644909f2f943 Mon Sep 17 00:00:00 2001 From: lonaasan Date: Mon, 9 Sep 2024 09:53:11 +0200 Subject: [PATCH] [Small Addition] added respawnInWorld Command --- assets/opensb/help.config.patch | 3 +- .../frontend/StarClientCommandProcessor.cpp | 46 ++++++++++++++----- .../frontend/StarClientCommandProcessor.hpp | 1 + source/game/StarWorldClient.cpp | 12 +++++ source/game/StarWorldClient.hpp | 3 ++ 5 files changed, 52 insertions(+), 13 deletions(-) diff --git a/assets/opensb/help.config.patch b/assets/opensb/help.config.patch index 15375e8..b3f31a6 100644 --- a/assets/opensb/help.config.patch +++ b/assets/opensb/help.config.patch @@ -10,6 +10,7 @@ }, "openSbCommands": { - "swap": "Usage /swap . Swaps the current character, case-insensitive, only substring required." + "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." } } 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 diff --git a/source/frontend/StarClientCommandProcessor.hpp b/source/frontend/StarClientCommandProcessor.hpp index b06f3d5..658242c 100644 --- a/source/frontend/StarClientCommandProcessor.hpp +++ b/source/frontend/StarClientCommandProcessor.hpp @@ -58,6 +58,7 @@ private: String enableTech(String const& argumentsString); String upgradeShip(String const& argumentsString); String swap(String const& argumentsString); + String respawnInWorld(); UniverseClientPtr m_universeClient; CinematicPtr m_cinematicOverlay; diff --git a/source/game/StarWorldClient.cpp b/source/game/StarWorldClient.cpp index 9e0478a..afe71ac 100644 --- a/source/game/StarWorldClient.cpp +++ b/source/game/StarWorldClient.cpp @@ -2421,4 +2421,16 @@ 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 e00a3b8..2f1cbc0 100644 --- a/source/game/StarWorldClient.hpp +++ b/source/game/StarWorldClient.hpp @@ -175,6 +175,9 @@ public: typedef std::function BroadcastCallback; BroadcastCallback& broadcastCallback(); + + bool toggleRespawnInWorld(); + private: static const float DropDist;