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 (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? } - if (worldClient->toggleRespawnInWorld()) { + // 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 result = worldClient->respawnInWorld() ? "true" : "false"; + const std::string stringResult = result ? "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!"; + 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;