mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Merge branch 'Indev' of https://github.com/ORelio/Minecraft-Console-Client into Indev
This commit is contained in:
commit
b07091e3dd
4 changed files with 93 additions and 10 deletions
59
MinecraftClient/ChatBots/Auto Respond.cs
Normal file
59
MinecraftClient/ChatBots/Auto Respond.cs
Normal file
|
|
@ -0,0 +1,59 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace MinecraftClient.ChatBots
|
||||||
|
{
|
||||||
|
class Auto_Respond : ChatBot
|
||||||
|
{
|
||||||
|
private String[] respondon = new String[0];
|
||||||
|
private String[] torespond = new String[0];
|
||||||
|
|
||||||
|
private static string[] FromFile(string file)
|
||||||
|
{
|
||||||
|
if (File.Exists(file))
|
||||||
|
{
|
||||||
|
//Read all lines from file, remove lines with no text, convert to lowercase,
|
||||||
|
//remove duplicate entries, convert to a string array, and return the result.
|
||||||
|
return File.ReadAllLines(file)
|
||||||
|
.Where(line => !String.IsNullOrWhiteSpace(line))
|
||||||
|
.Select(line => line.ToLower())
|
||||||
|
.Distinct().ToArray();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LogToConsole("File not found: " + file);
|
||||||
|
return new string[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Initalize the bot
|
||||||
|
public override void Initialize()
|
||||||
|
{
|
||||||
|
respondon = FromFile(Settings.Respond_MatchesFile);
|
||||||
|
torespond = FromFile(Settings.Respond_RespondFile);
|
||||||
|
ConsoleIO.WriteLine("Auto Respond Bot Sucessfully loaded!");
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void GetText(string text)
|
||||||
|
{
|
||||||
|
//Remove colour codes
|
||||||
|
text = getVerbatim(text).ToLower();
|
||||||
|
//Check text to see if bot should respond
|
||||||
|
foreach (string alert in respondon.Where(alert => text.Contains(alert)))
|
||||||
|
{
|
||||||
|
//Find what to respond with
|
||||||
|
for (int x = 0; x < respondon.Length; x++)
|
||||||
|
{
|
||||||
|
if (respondon[x].ToString().Contains(alert))
|
||||||
|
{
|
||||||
|
//Respond
|
||||||
|
SendText(torespond[x].ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -20,7 +20,7 @@ namespace MinecraftClient
|
||||||
private static List<string> cmd_names = new List<string>();
|
private static List<string> cmd_names = new List<string>();
|
||||||
private static Dictionary<string, Command> cmds = new Dictionary<string, Command>();
|
private static Dictionary<string, Command> cmds = new Dictionary<string, Command>();
|
||||||
private List<ChatBot> bots = new List<ChatBot>();
|
private List<ChatBot> bots = new List<ChatBot>();
|
||||||
private readonly Dictionary<Guid, string> onlinePlayers = new Dictionary<Guid,string>();
|
private readonly Dictionary<Guid, string> onlinePlayers = new Dictionary<Guid, string>();
|
||||||
private static List<ChatBots.Script> scripts_on_hold = new List<ChatBots.Script>();
|
private static List<ChatBots.Script> scripts_on_hold = new List<ChatBots.Script>();
|
||||||
public void BotLoad(ChatBot b) { b.SetHandler(this); bots.Add(b); b.Initialize(); Settings.SingleCommand = ""; }
|
public void BotLoad(ChatBot b) { b.SetHandler(this); bots.Add(b); b.Initialize(); Settings.SingleCommand = ""; }
|
||||||
public void BotUnLoad(ChatBot b) { bots.RemoveAll(item => object.ReferenceEquals(item, b)); }
|
public void BotUnLoad(ChatBot b) { bots.RemoveAll(item => object.ReferenceEquals(item, b)); }
|
||||||
|
|
@ -39,7 +39,7 @@ namespace MinecraftClient
|
||||||
public string getUsername() { return username; }
|
public string getUsername() { return username; }
|
||||||
public string getUserUUID() { return uuid; }
|
public string getUserUUID() { return uuid; }
|
||||||
public string getSessionID() { return sessionid; }
|
public string getSessionID() { return sessionid; }
|
||||||
|
|
||||||
TcpClient client;
|
TcpClient client;
|
||||||
IMinecraftCom handler;
|
IMinecraftCom handler;
|
||||||
Thread cmdprompt;
|
Thread cmdprompt;
|
||||||
|
|
@ -106,6 +106,7 @@ namespace MinecraftClient
|
||||||
if (Settings.AutoRelog_Enabled) { BotLoad(new ChatBots.AutoRelog(Settings.AutoRelog_Delay, Settings.AutoRelog_Retries)); }
|
if (Settings.AutoRelog_Enabled) { BotLoad(new ChatBots.AutoRelog(Settings.AutoRelog_Delay, Settings.AutoRelog_Retries)); }
|
||||||
if (Settings.ScriptScheduler_Enabled) { BotLoad(new ChatBots.ScriptScheduler(Settings.expandVars(Settings.ScriptScheduler_TasksFile))); }
|
if (Settings.ScriptScheduler_Enabled) { BotLoad(new ChatBots.ScriptScheduler(Settings.expandVars(Settings.ScriptScheduler_TasksFile))); }
|
||||||
if (Settings.RemoteCtrl_Enabled) { BotLoad(new ChatBots.RemoteControl()); }
|
if (Settings.RemoteCtrl_Enabled) { BotLoad(new ChatBots.RemoteControl()); }
|
||||||
|
if (Settings.Respond_Enabled) { BotLoad(new ChatBots.Auto_Respond()); }
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
|
|
@ -456,7 +457,7 @@ namespace MinecraftClient
|
||||||
onlinePlayers[uuid] = name;
|
onlinePlayers[uuid] = name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Triggered when a player has left the game
|
/// Triggered when a player has left the game
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,7 @@
|
||||||
<Compile Include="AutoTimeout.cs" />
|
<Compile Include="AutoTimeout.cs" />
|
||||||
<Compile Include="ChatBots\Alerts.cs" />
|
<Compile Include="ChatBots\Alerts.cs" />
|
||||||
<Compile Include="ChatBots\AntiAFK.cs" />
|
<Compile Include="ChatBots\AntiAFK.cs" />
|
||||||
|
<Compile Include="ChatBots\Auto Respond.cs" />
|
||||||
<Compile Include="ChatBots\AutoRelog.cs" />
|
<Compile Include="ChatBots\AutoRelog.cs" />
|
||||||
<Compile Include="ChatBots\ChatLog.cs" />
|
<Compile Include="ChatBots\ChatLog.cs" />
|
||||||
<Compile Include="ChatBots\HangmanGame.cs" />
|
<Compile Include="ChatBots\HangmanGame.cs" />
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ namespace MinecraftClient
|
||||||
public static string Password = "";
|
public static string Password = "";
|
||||||
public static string ServerIP = "";
|
public static string ServerIP = "";
|
||||||
public static ushort ServerPort = 25565;
|
public static ushort ServerPort = 25565;
|
||||||
public static string ServerVersion = "";
|
public static string ServerVersion = "";
|
||||||
public static string SingleCommand = "";
|
public static string SingleCommand = "";
|
||||||
public static string ConsoleTitle = "";
|
public static string ConsoleTitle = "";
|
||||||
|
|
||||||
|
|
@ -89,12 +89,17 @@ namespace MinecraftClient
|
||||||
public static bool RemoteCtrl_AutoTpaccept = true;
|
public static bool RemoteCtrl_AutoTpaccept = true;
|
||||||
public static bool RemoteCtrl_AutoTpaccept_Everyone = false;
|
public static bool RemoteCtrl_AutoTpaccept_Everyone = false;
|
||||||
|
|
||||||
|
//Auto Respond
|
||||||
|
public static bool Respond_Enabled = false;
|
||||||
|
public static string Respond_MatchesFile = "detect.txt";
|
||||||
|
public static string Respond_RespondFile = "respond.txt";
|
||||||
|
|
||||||
//Custom app variables and Minecraft accounts
|
//Custom app variables and Minecraft accounts
|
||||||
private static Dictionary<string, string> AppVars = new Dictionary<string, string>();
|
private static Dictionary<string, string> AppVars = new Dictionary<string, string>();
|
||||||
private static Dictionary<string, KeyValuePair<string, string>> Accounts = new Dictionary<string, KeyValuePair<string, string>>();
|
private static Dictionary<string, KeyValuePair<string, string>> Accounts = new Dictionary<string, KeyValuePair<string, string>>();
|
||||||
private static Dictionary<string, KeyValuePair<string, ushort>> Servers = new Dictionary<string, KeyValuePair<string, ushort>>();
|
private static Dictionary<string, KeyValuePair<string, ushort>> Servers = new Dictionary<string, KeyValuePair<string, ushort>>();
|
||||||
|
|
||||||
private enum ParseMode { Default, Main, AppVars, Proxy, AntiAFK, Hangman, Alerts, ChatLog, AutoRelog, ScriptScheduler, RemoteControl };
|
private enum ParseMode { Default, Main, AppVars, Proxy, AntiAFK, Hangman, Alerts, ChatLog, AutoRelog, ScriptScheduler, RemoteControl, Auto_Respond };
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Load settings from the give INI file
|
/// Load settings from the give INI file
|
||||||
|
|
@ -128,6 +133,7 @@ namespace MinecraftClient
|
||||||
case "remotecontrol": pMode = ParseMode.RemoteControl; break;
|
case "remotecontrol": pMode = ParseMode.RemoteControl; break;
|
||||||
case "proxy": pMode = ParseMode.Proxy; break;
|
case "proxy": pMode = ParseMode.Proxy; break;
|
||||||
case "appvars": pMode = ParseMode.AppVars; break;
|
case "appvars": pMode = ParseMode.AppVars; break;
|
||||||
|
case "auto respond": pMode = ParseMode.Auto_Respond; break;
|
||||||
default: pMode = ParseMode.Default; break;
|
default: pMode = ParseMode.Default; break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -203,7 +209,7 @@ namespace MinecraftClient
|
||||||
Servers[server_data[0]]
|
Servers[server_data[0]]
|
||||||
= new KeyValuePair<string, ushort>(ServerIP, ServerPort);
|
= new KeyValuePair<string, ushort>(ServerIP, ServerPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Restore current server info
|
//Restore current server info
|
||||||
ServerIP = server_host_temp;
|
ServerIP = server_host_temp;
|
||||||
ServerPort = server_port_temp;
|
ServerPort = server_port_temp;
|
||||||
|
|
@ -286,7 +292,7 @@ namespace MinecraftClient
|
||||||
argValue = argValue.ToLower();
|
argValue = argValue.ToLower();
|
||||||
if (argValue == "http") { proxyType = Proxy.ProxyHandler.Type.HTTP; }
|
if (argValue == "http") { proxyType = Proxy.ProxyHandler.Type.HTTP; }
|
||||||
else if (argValue == "socks4") { proxyType = Proxy.ProxyHandler.Type.SOCKS4; }
|
else if (argValue == "socks4") { proxyType = Proxy.ProxyHandler.Type.SOCKS4; }
|
||||||
else if (argValue == "socks4a"){ proxyType = Proxy.ProxyHandler.Type.SOCKS4a;}
|
else if (argValue == "socks4a") { proxyType = Proxy.ProxyHandler.Type.SOCKS4a; }
|
||||||
else if (argValue == "socks5") { proxyType = Proxy.ProxyHandler.Type.SOCKS5; }
|
else if (argValue == "socks5") { proxyType = Proxy.ProxyHandler.Type.SOCKS5; }
|
||||||
break;
|
break;
|
||||||
case "server":
|
case "server":
|
||||||
|
|
@ -310,6 +316,15 @@ namespace MinecraftClient
|
||||||
case ParseMode.AppVars:
|
case ParseMode.AppVars:
|
||||||
setVar(argName, argValue);
|
setVar(argName, argValue);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case ParseMode.Auto_Respond:
|
||||||
|
switch (argName.ToLower())
|
||||||
|
{
|
||||||
|
case "enabled": Respond_Enabled = str2bool(argValue); break;
|
||||||
|
case "matchfile": Respond_MatchesFile = argValue; break;
|
||||||
|
case "respondfile": Respond_RespondFile = argValue; break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -405,7 +420,14 @@ namespace MinecraftClient
|
||||||
+ "[RemoteControl]\r\n"
|
+ "[RemoteControl]\r\n"
|
||||||
+ "enabled=false\r\n"
|
+ "enabled=false\r\n"
|
||||||
+ "autotpaccept=true\r\n"
|
+ "autotpaccept=true\r\n"
|
||||||
+ "tpaccepteveryone=false\r\n", Encoding.UTF8);
|
+ "tpaccepteveryone=false\r\n"
|
||||||
|
+ "\r\n"
|
||||||
|
+ "[Auto Respond]\r\n"
|
||||||
|
+ "enabled=false\r\n"
|
||||||
|
+ "matchfile=detect.txt\r\n"
|
||||||
|
+ "respondfile=respond.txt\r\n"
|
||||||
|
+ "#To use the bot, place the text to detect in the matchfile file and the text to respond with in the respondfile\r\n"
|
||||||
|
+ "#Each line in each file is relevant to the same line in the other document, for example if the bot detects the text in line 1 of the first file, it will respond with line 1 of the second file.\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; } }
|
||||||
|
|
@ -439,7 +461,7 @@ namespace MinecraftClient
|
||||||
string[] sip = server.Split(':');
|
string[] sip = server.Split(':');
|
||||||
string host = sip[0];
|
string host = sip[0];
|
||||||
ushort port = 25565;
|
ushort port = 25565;
|
||||||
|
|
||||||
if (sip.Length > 1)
|
if (sip.Length > 1)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
@ -461,7 +483,7 @@ namespace MinecraftClient
|
||||||
ServerPort = Servers[server].Value;
|
ServerPort = Servers[server].Value;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue