Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/frontend/StarClientCommandProcessor.cpp
diff options
context:
space:
mode:
authorlonaasan <shadowlona@shadowlona.dev>2024-09-09 11:27:14 +0200
committerlonaasan <shadowlona@shadowlona.dev>2024-09-09 11:27:14 +0200
commit732fc2a9d7e9a4c5e3cf01ac191a392462f3da8c (patch)
tree5f6764ac49aec0a20bd45add222b0409f7f0a55f /source/frontend/StarClientCommandProcessor.cpp
parent98a395721ee0383bd2ed046235dd644909f2f943 (diff)
[Revision] Applying the recommended changes from pull request #110 (return current value if no argument given, moving the methods to their correct location)
Diffstat (limited to 'source/frontend/StarClientCommandProcessor.cpp')
-rw-r--r--source/frontend/StarClientCommandProcessor.cpp40
1 files changed, 26 insertions, 14 deletions
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