mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Added remote control bot
A bot that can perform operations using /tell commands! Available commands: exit, reco, script, send. Closes #7 :)
This commit is contained in:
parent
fc281889c6
commit
d972378f0e
3 changed files with 106 additions and 5 deletions
|
|
@ -235,6 +235,28 @@ namespace MinecraftClient
|
||||||
handler.BotUnLoad(this);
|
handler.BotUnLoad(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Send a private message to a player
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="player">Player name</param>
|
||||||
|
/// <param name="message">Message</param>
|
||||||
|
|
||||||
|
protected void SendPrivateMessage(string player, string message)
|
||||||
|
{
|
||||||
|
SendText("/tell " + player + ' ' + message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Run a script from a file using a Scripting bot
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="filename">File name</param>
|
||||||
|
/// <param name="playername">Player name to send error messages, if applicable</param>
|
||||||
|
|
||||||
|
protected void RunScript(string filename, string playername = "")
|
||||||
|
{
|
||||||
|
handler.BotLoad(new Bots.Scripting(filename, playername));
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -822,11 +844,20 @@ namespace MinecraftClient
|
||||||
private int sleepticks = 10;
|
private int sleepticks = 10;
|
||||||
private int sleepticks_interval = 10;
|
private int sleepticks_interval = 10;
|
||||||
private int nextline = 0;
|
private int nextline = 0;
|
||||||
|
private string owner;
|
||||||
|
|
||||||
public Scripting(string filename)
|
public Scripting(string filename)
|
||||||
{
|
{
|
||||||
file = filename;
|
file = filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Scripting(string filename, string ownername)
|
||||||
|
:this(filename)
|
||||||
|
{
|
||||||
|
if (ownername != "")
|
||||||
|
owner = ownername;
|
||||||
|
}
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
//Load the given file from the startup parameters
|
//Load the given file from the startup parameters
|
||||||
|
|
@ -856,8 +887,12 @@ namespace MinecraftClient
|
||||||
if (!file_found)
|
if (!file_found)
|
||||||
{
|
{
|
||||||
LogToConsole("File not found: '" + file + "'");
|
LogToConsole("File not found: '" + file + "'");
|
||||||
|
if (owner != null)
|
||||||
|
SendPrivateMessage(owner, "File not found: '" + file + "'");
|
||||||
UnloadBot(); //No need to keep the bot active
|
UnloadBot(); //No need to keep the bot active
|
||||||
}
|
}
|
||||||
|
else if (owner != null)
|
||||||
|
SendPrivateMessage(owner, "Script '" + file + "' loaded.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Update()
|
public override void Update()
|
||||||
|
|
@ -912,5 +947,58 @@ namespace MinecraftClient
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Allow to perform operations using whispers to the bot
|
||||||
|
/// </summary>
|
||||||
|
|
||||||
|
public class RemoteControl : ChatBot
|
||||||
|
{
|
||||||
|
public override void GetText(string text)
|
||||||
|
{
|
||||||
|
text = getVerbatim(text);
|
||||||
|
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())
|
||||||
|
{
|
||||||
|
case "exit":
|
||||||
|
DisconnectAndExit();
|
||||||
|
break;
|
||||||
|
case "reco":
|
||||||
|
ReconnectToTheServer();
|
||||||
|
break;
|
||||||
|
case "script":
|
||||||
|
if (command.Length >= 8)
|
||||||
|
RunScript(command.Substring(7), sender);
|
||||||
|
break;
|
||||||
|
case "send":
|
||||||
|
if (command.Length >= 6)
|
||||||
|
SendText(command.Substring(5));
|
||||||
|
break;
|
||||||
|
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 <scriptname>: run a script file."); break;
|
||||||
|
case "send": SendPrivateMessage(sender, "send <text>: send a chat message or command."); break;
|
||||||
|
case "help": SendPrivateMessage(sender, "help <cmdname>: show brief help about a command."); break;
|
||||||
|
default: SendPrivateMessage(sender, "help: unknown command '" + help_cmd_name + "'."); break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else SendPrivateMessage(sender, "help <cmdname>. Available commands: exit, reco, script, send.");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
SendPrivateMessage(sender, "Unknown command '" + cmd_name + "'. Use 'help' for help.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -163,6 +163,7 @@ namespace MinecraftClient
|
||||||
if (Settings.PlayerLog_Enabled) { handler.BotLoad(new Bots.PlayerListLogger(Settings.PlayerLog_Delay, Settings.PlayerLog_File)); }
|
if (Settings.PlayerLog_Enabled) { handler.BotLoad(new Bots.PlayerListLogger(Settings.PlayerLog_Delay, Settings.PlayerLog_File)); }
|
||||||
if (Settings.AutoRelog_Enabled) { handler.BotLoad(new Bots.AutoRelog(Settings.AutoRelog_Delay, Settings.AutoRelog_Retries)); }
|
if (Settings.AutoRelog_Enabled) { handler.BotLoad(new Bots.AutoRelog(Settings.AutoRelog_Delay, Settings.AutoRelog_Retries)); }
|
||||||
if (Settings.Scripting_Enabled) { handler.BotLoad(new Bots.Scripting(Settings.Scripting_ScriptFile)); }
|
if (Settings.Scripting_Enabled) { handler.BotLoad(new Bots.Scripting(Settings.Scripting_ScriptFile)); }
|
||||||
|
if (Settings.RemoteCtrl_Enabled){ handler.BotLoad(new Bots.RemoteControl()); }
|
||||||
|
|
||||||
//Start the main TCP client
|
//Start the main TCP client
|
||||||
if (Settings.SingleCommand != "")
|
if (Settings.SingleCommand != "")
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ namespace MinecraftClient
|
||||||
public static string TranslationsFile_FromMCDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\.minecraft\assets\objects\9e\9e2fdc43fc1c7024ff5922b998fadb2971a64ee0"; //MC 1.7.4 en_GB.lang
|
public static string TranslationsFile_FromMCDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\.minecraft\assets\objects\9e\9e2fdc43fc1c7024ff5922b998fadb2971a64ee0"; //MC 1.7.4 en_GB.lang
|
||||||
public static string TranslationsFile_Website_Index = "https://s3.amazonaws.com/Minecraft.Download/indexes/1.7.4.json";
|
public static string TranslationsFile_Website_Index = "https://s3.amazonaws.com/Minecraft.Download/indexes/1.7.4.json";
|
||||||
public static string TranslationsFile_Website_Download = "http://resources.download.minecraft.net";
|
public static string TranslationsFile_Website_Download = "http://resources.download.minecraft.net";
|
||||||
public static List<string> Bots_Owners = new List<string>(new string[] { "console" });
|
public static List<string> Bots_Owners = new List<string>();
|
||||||
public static string Language = "en_GB";
|
public static string Language = "en_GB";
|
||||||
|
|
||||||
//AntiAFK Settings
|
//AntiAFK Settings
|
||||||
|
|
@ -67,8 +67,10 @@ namespace MinecraftClient
|
||||||
public static bool Scripting_Enabled = false;
|
public static bool Scripting_Enabled = false;
|
||||||
public static string Scripting_ScriptFile = "script.txt";
|
public static string Scripting_ScriptFile = "script.txt";
|
||||||
|
|
||||||
|
//Remote Control
|
||||||
|
public static bool RemoteCtrl_Enabled = false;
|
||||||
|
|
||||||
private enum ParseMode { Default, Main, AntiAFK, Hangman, Alerts, ChatLog, AutoRelog, Scripting };
|
private enum ParseMode { Default, Main, AntiAFK, Hangman, Alerts, ChatLog, AutoRelog, Scripting, RemoteControl };
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Load settings from the give INI file
|
/// Load settings from the give INI file
|
||||||
|
|
@ -99,6 +101,7 @@ namespace MinecraftClient
|
||||||
case "hangman": pMode = ParseMode.Hangman; break;
|
case "hangman": pMode = ParseMode.Hangman; break;
|
||||||
case "main": pMode = ParseMode.Main; break;
|
case "main": pMode = ParseMode.Main; break;
|
||||||
case "scripting": pMode = ParseMode.Scripting; break;
|
case "scripting": pMode = ParseMode.Scripting; break;
|
||||||
|
case "remotecontrol": pMode = ParseMode.RemoteControl; break;
|
||||||
default: pMode = ParseMode.Default; break;
|
default: pMode = ParseMode.Default; break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -121,7 +124,6 @@ namespace MinecraftClient
|
||||||
case "consoletitle": ConsoleTitle = argValue; break;
|
case "consoletitle": ConsoleTitle = argValue; break;
|
||||||
case "botowners":
|
case "botowners":
|
||||||
Bots_Owners.Clear();
|
Bots_Owners.Clear();
|
||||||
Bots_Owners.Add("console");
|
|
||||||
foreach (string name in argValue.ToLower().Replace(" ", "").Split(','))
|
foreach (string name in argValue.ToLower().Replace(" ", "").Split(','))
|
||||||
Bots_Owners.Add(name);
|
Bots_Owners.Add(name);
|
||||||
break;
|
break;
|
||||||
|
|
@ -183,6 +185,13 @@ namespace MinecraftClient
|
||||||
case "scriptfile": Scripting_ScriptFile = argValue; break;
|
case "scriptfile": Scripting_ScriptFile = argValue; break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case ParseMode.RemoteControl:
|
||||||
|
switch (argName.ToLower())
|
||||||
|
{
|
||||||
|
case "enabled": RemoteCtrl_Enabled = str2bool(argValue); break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -206,7 +215,7 @@ namespace MinecraftClient
|
||||||
+ "[Main]\r\n"
|
+ "[Main]\r\n"
|
||||||
+ "\r\n"
|
+ "\r\n"
|
||||||
+ "#General settings\r\n"
|
+ "#General settings\r\n"
|
||||||
+ "#leave blank = prompt user on startup\r\n"
|
+ "#leave blank to prompt user on startup\r\n"
|
||||||
+ "#Use \"-\" as password for offline mode\r\n"
|
+ "#Use \"-\" as password for offline mode\r\n"
|
||||||
+ "\r\n"
|
+ "\r\n"
|
||||||
+ "login=\r\npassword=\r\nserverip=\r\n"
|
+ "login=\r\npassword=\r\nserverip=\r\n"
|
||||||
|
|
@ -249,7 +258,10 @@ namespace MinecraftClient
|
||||||
+ "\r\n"
|
+ "\r\n"
|
||||||
+ "[Scripting]\r\n"
|
+ "[Scripting]\r\n"
|
||||||
+ "enabled=false\r\n"
|
+ "enabled=false\r\n"
|
||||||
+ "scriptfile=testscript.txt\r\n", Encoding.UTF8);
|
+ "scriptfile=testscript.txt\r\n"
|
||||||
|
+ "\r\n"
|
||||||
|
+ "[RemoteControl]\r\n"
|
||||||
|
+ "enabled=false\r\n", Encoding.UTF8);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int str2int(string str) { try { return Convert.ToInt32(str); } catch { return 0; } }
|
public static int str2int(string str) { try { return Convert.ToInt32(str); } catch { return 0; } }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue