aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.Server/Console/commands/kill
diff options
context:
space:
mode:
Diffstat (limited to 'Minecraft.Server/Console/commands/kill')
-rw-r--r--Minecraft.Server/Console/commands/kill/CliCommandKill.cpp64
-rw-r--r--Minecraft.Server/Console/commands/kill/CliCommandKill.h16
2 files changed, 80 insertions, 0 deletions
diff --git a/Minecraft.Server/Console/commands/kill/CliCommandKill.cpp b/Minecraft.Server/Console/commands/kill/CliCommandKill.cpp
new file mode 100644
index 00000000..04b2c419
--- /dev/null
+++ b/Minecraft.Server/Console/commands/kill/CliCommandKill.cpp
@@ -0,0 +1,64 @@
+#include "stdafx.h"
+
+#include "CliCommandKill.h"
+
+#include "..\..\ServerCliEngine.h"
+#include "..\..\ServerCliParser.h"
+#include "..\..\..\..\Minecraft.World\CommandSender.h"
+#include "..\..\..\..\Minecraft.Client\ServerPlayer.h"
+
+namespace ServerRuntime
+{
+ namespace
+ {
+ constexpr const char *kKillUsage = "kill <player>";
+ }
+
+ const char *CliCommandKill::Name() const
+ {
+ return "kill";
+ }
+
+ const char *CliCommandKill::Usage() const
+ {
+ return kKillUsage;
+ }
+
+ const char *CliCommandKill::Description() const
+ {
+ return "Kill a player via Minecraft.World command dispatcher.";
+ }
+
+ bool CliCommandKill::Execute(const ServerCliParsedLine &line, ServerCliEngine *engine)
+ {
+ if (line.tokens.size() != 2)
+ {
+ engine->LogWarn(std::string("Usage: ") + kKillUsage);
+ return false;
+ }
+
+ std::shared_ptr<ServerPlayer> target = engine->FindPlayerByNameUtf8(line.tokens[1]);
+ if (target == nullptr)
+ {
+ engine->LogWarn("Unknown player: " + line.tokens[1]);
+ return false;
+ }
+
+ std::shared_ptr<CommandSender> sender = std::dynamic_pointer_cast<CommandSender>(target);
+ if (sender == nullptr)
+ {
+ engine->LogWarn("Cannot resolve target command sender.");
+ return false;
+ }
+
+ return engine->DispatchWorldCommand(eGameCommand_Kill, byteArray(), sender);
+ }
+
+ void CliCommandKill::Complete(const ServerCliCompletionContext &context, const ServerCliEngine *engine, std::vector<std::string> *out) const
+ {
+ if (context.currentTokenIndex == 1)
+ {
+ engine->SuggestPlayers(context.prefix, context.linePrefix, out);
+ }
+ }
+}
diff --git a/Minecraft.Server/Console/commands/kill/CliCommandKill.h b/Minecraft.Server/Console/commands/kill/CliCommandKill.h
new file mode 100644
index 00000000..e558fac0
--- /dev/null
+++ b/Minecraft.Server/Console/commands/kill/CliCommandKill.h
@@ -0,0 +1,16 @@
+#pragma once
+
+#include "..\IServerCliCommand.h"
+
+namespace ServerRuntime
+{
+ class CliCommandKill : public IServerCliCommand
+ {
+ public:
+ const char *Name() const override;
+ const char *Usage() const override;
+ const char *Description() const override;
+ bool Execute(const ServerCliParsedLine &line, ServerCliEngine *engine) override;
+ void Complete(const ServerCliCompletionContext &context, const ServerCliEngine *engine, std::vector<std::string> *out) const override;
+ };
+}