aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.Server/Console/ServerCliEngine.h
blob: b2d72bace6d5e9466ce4c9181cbcd07b7e1c0215 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#pragma once

#include <memory>
#include <mutex>
#include <queue>
#include <string>
#include <vector>

#include "..\..\Minecraft.World\ArrayWithLength.h"
#include "..\..\Minecraft.World\CommandsEnum.h"

class GameType;
class ServerPlayer;
class CommandSender;

namespace ServerRuntime
{
	class ServerCliRegistry;

	/**
	 * **CLI execution engine**
	 *
	 * Handles parsing, command dispatch, completion suggestions, and server-side helpers.
	 * 解析・実行・補完エンジン
	 */
	class ServerCliEngine
	{
	public:
		ServerCliEngine();
		~ServerCliEngine();

		/**
		 * **Queue one raw command line**
		 *
		 * Called by input thread; execution is deferred to `Poll()`.
		 * 入力行を実行キューに追加
		 */
		void EnqueueCommandLine(const std::string &line);

		/**
		 * **Execute queued commands**
		 *
		 * Drains pending lines and dispatches them in order.
		 * キュー済みコマンドを順番に実行
		 */
		void Poll();

		/**
		 * **Execute one command line immediately**
		 *
		 * Parses and dispatches a normalized line to a registered command.
		 * 1行を直接パースしてコマンド実行
		 */
		bool ExecuteCommandLine(const std::string &line);

		/**
		 * **Build completion candidates for current line**
		 *
		 * Produces command or argument suggestions based on parser context.
		 * 現在入力に対する補完候補を作成
		 */
		void BuildCompletions(const std::string &line, std::vector<std::string> *out) const;

		void LogInfo(const std::string &message) const;
		void LogWarn(const std::string &message) const;
		void LogError(const std::string &message) const;
		void RequestShutdown() const;

		/**
		 * **List connected players as UTF-8 names**
		 * 
		 * ここら辺は分けてもいいかも
		 */
		std::vector<std::string> GetOnlinePlayerNamesUtf8() const;

		/**
		 * **Find a player by UTF-8 name**
		 */
		std::shared_ptr<ServerPlayer> FindPlayerByNameUtf8(const std::string &name) const;

		/**
		 * **Suggest player-name arguments**
		 *
		 * Appends matching player candidates using the given completion prefix.
		 * プレイヤー名の補完候補
		 */
		void SuggestPlayers(const std::string &prefix, const std::string &linePrefix, std::vector<std::string> *out) const;

		/**
		 * **Suggest gamemode arguments**
		 *
		 * Appends standard gamemode aliases (survival/creative/0/1).
		 * ゲームモードの補完候補
		 */
		void SuggestGamemodes(const std::string &prefix, const std::string &linePrefix, std::vector<std::string> *out) const;

		/**
		 * **Parse gamemode token**
		 *
		 * Supports names, short aliases, and numeric ids.
		 * 文字列からゲームモードを解決
		 */
		GameType *ParseGamemode(const std::string &token) const;

		/**
		 * **Dispatch one Minecraft.World game command**
		 *
		 * Uses `Minecraft.World::CommandDispatcher` for actual execution.
		 * When `sender` is null, an internal console command sender is used.
		 * 
		 * Minecraft.Worldのコマンドを実行するためのディスパッチャーのラッパー
		 * 内部でsenderがnullの場合はコンソールコマンド送信者を使用
		 */
		bool DispatchWorldCommand(EGameCommand command, byteArray commandData, const std::shared_ptr<CommandSender> &sender = nullptr) const;

		const ServerCliRegistry &Registry() const;

	private:
		void RegisterDefaultCommands();

	private:
		mutable std::mutex m_queueMutex;
		std::queue<std::string> m_pendingLines;
		std::unique_ptr<ServerCliRegistry> m_registry;
		std::shared_ptr<CommandSender> m_consoleSender;
	};
}