diff --git a/MinecraftClient/ChatBot.cs b/MinecraftClient/ChatBot.cs
index 61e9b244..8fc29e62 100644
--- a/MinecraftClient/ChatBot.cs
+++ b/MinecraftClient/ChatBot.cs
@@ -84,25 +84,27 @@ namespace MinecraftClient
}
///
- /// Check if the given command is a valid internal MCC command
+ /// Perform an internal MCC command (not a server command, use SendText() instead for that!)
///
- /// The command or command name
- /// TRUE if this is an internal command
+ /// The command to process
+ /// TRUE if the command was indeed an internal MCC command
- protected bool isInternalCommand(string command)
+ protected bool performInternalCommand(string command)
{
- return handler.isInternalCommand(command);
+ string temp = "";
+ return handler.performInternalCommand(command, ref temp);
}
///
/// Perform an internal MCC command (not a server command, use SendText() instead for that!)
///
- /// The command
- /// TRUE if the command was successfully recognized and performed
+ /// The command to process
+ /// May contain a confirmation or error message after processing the command, or "" otherwise.
+ /// TRUE if the command was indeed an internal MCC command
- protected bool performInternalCommand(string command)
+ protected bool performInternalCommand(string command, ref string response_msg)
{
- return handler.performInternalCommand(command);
+ return handler.performInternalCommand(command, ref response_msg);
}
///
diff --git a/MinecraftClient/ChatBots/RemoteControl.cs b/MinecraftClient/ChatBots/RemoteControl.cs
index cc66d412..e5e62d36 100644
--- a/MinecraftClient/ChatBots/RemoteControl.cs
+++ b/MinecraftClient/ChatBots/RemoteControl.cs
@@ -17,33 +17,11 @@ namespace MinecraftClient.ChatBots
string command = "", sender = "";
if (isPrivateMessage(text, ref command, ref sender) && Settings.Bots_Owners.Contains(sender.ToLower()))
{
- string cmd_name = command.Split(' ')[0];
- switch (cmd_name.ToLower())
+ string response = "";
+ performInternalCommand(command, ref response);
+ if (response.Length > 0)
{
- case "help":
- if (command.Length >= 6)
- {
- string help_cmd_name = command.Substring(5).ToLower();
- switch (help_cmd_name)
- {
- case "exit": SendPrivateMessage(sender, "exit: disconnect from the server."); break;
- case "reco": SendPrivateMessage(sender, "reco: restart and reconnct to the server."); break;
- case "script": SendPrivateMessage(sender, "script : run a script file."); break;
- case "send": SendPrivateMessage(sender, "send : send a chat message or command."); break;
- case "connect": SendPrivateMessage(sender, "connect : connect to the specified server."); break;
- case "help": SendPrivateMessage(sender, "help : show brief help about a command."); break;
- default: SendPrivateMessage(sender, "help: unknown command '" + help_cmd_name + "'."); break;
- }
- }
- else SendPrivateMessage(sender, "help . Available commands: exit, reco, script, send, connect.");
- break;
- default:
- if (isInternalCommand(command))
- {
- performInternalCommand(command);
- }
- else SendPrivateMessage(sender, "Unknown command '" + cmd_name + "'. Use 'help' for help.");
- break;
+ SendPrivateMessage(sender, response);
}
}
else if (isTeleportRequest(text, ref sender) && Settings.Bots_Owners.Contains(sender.ToLower()))
diff --git a/MinecraftClient/ChatBots/Script.cs b/MinecraftClient/ChatBots/Script.cs
index 18d83cf4..d8dbec96 100644
--- a/MinecraftClient/ChatBots/Script.cs
+++ b/MinecraftClient/ChatBots/Script.cs
@@ -87,6 +87,7 @@ namespace MinecraftClient.ChatBots
{
if (instruction_line[0] != '#' && instruction_line[0] != '/' && instruction_line[1] != '/')
{
+ instruction_line = Settings.expandVars(instruction_line);
string instruction_name = instruction_line.Split(' ')[0];
switch (instruction_name.ToLower())
{
@@ -100,11 +101,10 @@ namespace MinecraftClient.ChatBots
sleepticks = ticks;
break;
default:
- if (isInternalCommand(instruction_line))
+ if (!performInternalCommand(instruction_line))
{
- performInternalCommand(instruction_line);
+ sleepticks = 0; Update(); //Unknown command : process next line immediately
}
- else sleepticks = 0; Update(); //Unknown command : process next line immediately
break;
}
}
diff --git a/MinecraftClient/McTcpClient.cs b/MinecraftClient/McTcpClient.cs
index 488c8439..27333e9c 100644
--- a/MinecraftClient/McTcpClient.cs
+++ b/MinecraftClient/McTcpClient.cs
@@ -175,12 +175,16 @@ namespace MinecraftClient
{
if (text[0] == '/')
{
+ string response_msg = "";
string command = text.Substring(1);
- if (isInternalCommand(command))
+ if (!performInternalCommand(Settings.expandVars(command), ref response_msg))
{
- performInternalCommand(command, true);
+ SendChatMessage(text);
+ }
+ else if (response_msg.Length > 0)
+ {
+ ConsoleIO.WriteLineFormatted("ยง8" + response_msg);
}
- else SendChatMessage(text);
}
}
}
@@ -189,39 +193,17 @@ namespace MinecraftClient
catch (IOException) { }
}
- ///
- /// Check if the given command is a valid internal MCC command
- ///
- /// The command or command name
- /// TRUE if this is an internal command
-
- public bool isInternalCommand(string command)
- {
- string command_name = command.Split(' ')[0].ToLower();
- switch (command_name)
- {
- case "exit":
- case "quit":
- case "reco":
- case "respawn":
- case "send":
- case "script":
- case "connect":
- return true;
- default:
- return false;
- }
- }
-
///
/// Perform an internal MCC command (not a server command, use SendChatMessage() instead for that!)
///
/// The command
/// Set to true if command was sent by the user using the command prompt
- /// TRUE if the command was successfully recognized and performed
+ /// May contain a confirmation or error message after processing the command, or "" otherwise.
+ /// TRUE if the command was indeed an internal MCC command
- public bool performInternalCommand(string command, bool interactive_mode = false)
+ public bool performInternalCommand(string command, ref string response_msg)
{
+ response_msg = "";
string[] command_args = command.Split(' ');
string command_name = command_args[0].ToLower();
switch (command_name)
@@ -237,8 +219,7 @@ namespace MinecraftClient
case "respawn":
handler.SendRespawnPacket();
- if (interactive_mode)
- ConsoleIO.WriteLine("You have respawned.");
+ response_msg = "You have respawned.";
break;
case "send":
@@ -247,22 +228,65 @@ namespace MinecraftClient
string text = command.Substring(5);
SendChatMessage(text);
}
+ else response_msg = "send : send a chat message or command.";
+ break;
+
+ case "set":
+ if (command.Length > 3)
+ {
+ string[] temp = command.Substring(3).Split('=');
+ if (temp.Length > 1)
+ {
+ if (!Settings.setVar(temp[0], command.Substring(temp[0].Length + 5)))
+ {
+ response_msg = "variable name must be A-Za-z0-9.";
+ }
+ }
+ else response_msg = "set varname=value: set a custom %variable%.";
+ }
+ else response_msg = "set varname=value: set a custom %variable%.";
break;
case "script":
if (command.Length > 8)
+ {
BotLoad(new ChatBots.Script(command.Substring(8)));
- break;
+ }
+ else response_msg = "script : run a script file.";
+ break;
case "connect":
- if (command_args.Length > 1)
+ if (command_args.Length > 1)
+ {
+ Settings.setServerIP(command_args[1]);
+ Program.Restart();
+ }
+ else response_msg = "connect : connect to the specified server.";
+ break;
+
+ case "help":
+ if (command.Length >= 6)
+ {
+ string help_cmd_name = command.Substring(5).ToLower();
+ switch (help_cmd_name)
{
- Settings.setServerIP(command_args[1]);
- Program.Restart();
+ case "quit": response_msg = "quit: disconnect from the server."; break;
+ case "exit": response_msg = "exit: disconnect from the server."; break;
+ case "reco": response_msg = "reco: restart and reconnct to the server."; break;
+ case "respawn": response_msg = "respawn: respawn after death."; break;
+ case "send": response_msg = "send : send a chat message or command."; break;
+ case "set": response_msg = "set varname=value: set a custom %variable%."; break;
+ case "script": response_msg = "script : run a script file."; break;
+ case "connect": response_msg = "connect : connect to the specified server."; break;
+ case "help": response_msg = "help : show brief help about a command."; break;
+ default: response_msg = "help: unknown command '" + help_cmd_name + "'."; break;
}
+ }
+ else response_msg = "help . Available commands: exit, reco, script, send, connect.";
break;
default:
+ response_msg = "Unknown command '" + command_name + "'. Use 'help' for help.";
return false;
}
return true;
diff --git a/MinecraftClient/Settings.cs b/MinecraftClient/Settings.cs
index f13d5f12..e6841202 100644
--- a/MinecraftClient/Settings.cs
+++ b/MinecraftClient/Settings.cs
@@ -233,9 +233,7 @@ namespace MinecraftClient
break;
case ParseMode.AppVars:
- string varName = new string(argName.TakeWhile(char.IsLetterOrDigit).ToArray()).ToLower();
- if (varName.Length > 0)
- AppVars[varName] = argValue;
+ setVar(argName, argValue);
break;
}
}
@@ -353,6 +351,24 @@ namespace MinecraftClient
}
}
+ ///
+ /// Set a custom %variable% which will be available through expandVars()
+ ///
+ /// Name of the variable
+ /// Value of the variable
+ /// True if the parameters were valid
+
+ public static bool setVar(string varName, string varData)
+ {
+ varName = new string(varName.TakeWhile(char.IsLetterOrDigit).ToArray()).ToLower();
+ if (varName.Length > 0)
+ {
+ AppVars[varName] = varData;
+ return true;
+ }
+ else return false;
+ }
+
///
/// Replace %variables% with their value
///