mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Script Works?
This commit is contained in:
parent
0332df909c
commit
7e70494f23
7 changed files with 94 additions and 15 deletions
|
|
@ -845,11 +845,65 @@ namespace MinecraftClient
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Runs a list of commands
|
/// Runs a list of commands
|
||||||
/// Usage: bot:scripting:filename
|
/// Usage: bot:scripting:filename
|
||||||
|
/// Script must be placed in the config directory
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
||||||
public class scripting : ChatBot
|
public class scripting : ChatBot
|
||||||
{
|
{
|
||||||
|
private string file;
|
||||||
|
private string[] lines = new string[0];
|
||||||
|
public scripting(string filename)
|
||||||
|
{
|
||||||
|
file = filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Initialize()
|
||||||
|
{
|
||||||
|
// Loads the given file from the startup parameters
|
||||||
|
if (System.IO.File.Exists("config/" + file))
|
||||||
|
{
|
||||||
|
lines = System.IO.File.ReadAllLines("config/" + file); // Load the given bot text file (containing commands)
|
||||||
|
for (int i = 0; i < lines.Length; i++) // Parse through each line of the bot text file
|
||||||
|
{
|
||||||
|
System.Threading.Thread.Sleep(100);
|
||||||
|
|
||||||
|
string this_line = lines[i].Trim(); // Removes all whitespaces at start and end of current line
|
||||||
|
|
||||||
|
if (this_line.Length == 0) {
|
||||||
|
// Skip a completely empty line
|
||||||
|
}
|
||||||
|
else if (this_line.Trim().StartsWith("//"))
|
||||||
|
{
|
||||||
|
Console.ForegroundColor = ConsoleColor.DarkGray;
|
||||||
|
Console.WriteLine("BOT:" + this_line);
|
||||||
|
Console.ForegroundColor = ConsoleColor.Gray;
|
||||||
|
// Don't do anything for a comment line, denoted by '//'
|
||||||
|
}
|
||||||
|
else if (this_line.StartsWith("send "))
|
||||||
|
{
|
||||||
|
Console.ForegroundColor = ConsoleColor.Gray;
|
||||||
|
SendText((lines[i].Trim().Substring(5, lines[i].Length - 5)));
|
||||||
|
// Send the command
|
||||||
|
}
|
||||||
|
else if (this_line.StartsWith("wait "))
|
||||||
|
{
|
||||||
|
Console.ForegroundColor = ConsoleColor.DarkGray;
|
||||||
|
Console.WriteLine("BOT:Pausing for " + Convert.ToInt32(lines[i].Substring(5, lines[i].Length - 5)) * 100 + "ms...");
|
||||||
|
Console.ForegroundColor = ConsoleColor.Gray;
|
||||||
|
System.Threading.Thread.Sleep(Convert.ToInt32(lines[i].Substring(5, lines[i].Length - 5)) * 100);
|
||||||
|
// Do a wait (given in milliseconds)
|
||||||
|
}
|
||||||
|
else if (this_line.StartsWith("exit")) {
|
||||||
|
//Program.Client.Disconnect();
|
||||||
|
} // Optional exit only if called in bot text file,
|
||||||
|
}
|
||||||
|
UnloadBot(); // Otherwise continue operation of Client to normal (non-bot) usage
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine(file + " not found! Please make sure that the file is located in the config directory.");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ namespace MinecraftClient
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This class parses JSON chat data from MC 1.6+ and returns the appropriate string to be printed.
|
/// This class parses JSON chat data from MC 1.6+ and returns the appropriate string to be printed.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
||||||
static class ChatParser
|
static class ChatParser
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -54,11 +54,11 @@ namespace MinecraftClient
|
||||||
|
|
||||||
private static string color2tag(string colorname)
|
private static string color2tag(string colorname)
|
||||||
{
|
{
|
||||||
switch(colorname.ToLower())
|
switch (colorname.ToLower())
|
||||||
{
|
{
|
||||||
case "black": return "§0";
|
case "black": return "§0";
|
||||||
case "dark_blue": return "§1";
|
case "dark_blue": return "§1";
|
||||||
case "dark_green" : return "§2";
|
case "dark_green": return "§2";
|
||||||
case "dark_cyan": return "§3";
|
case "dark_cyan": return "§3";
|
||||||
case "dark_cyanred": return "§4";
|
case "dark_cyanred": return "§4";
|
||||||
case "dark_magenta": return "§5";
|
case "dark_magenta": return "§5";
|
||||||
|
|
@ -278,7 +278,7 @@ namespace MinecraftClient
|
||||||
return colorcode + TranslateString(JSONData2String(data.Properties["translate"]), using_data) + colorcode;
|
return colorcode + TranslateString(JSONData2String(data.Properties["translate"]), using_data) + colorcode;
|
||||||
}
|
}
|
||||||
else return "";
|
else return "";
|
||||||
|
|
||||||
case JSONData.DataType.Array:
|
case JSONData.DataType.Array:
|
||||||
string result = "";
|
string result = "";
|
||||||
foreach (JSONData item in data.DataArray)
|
foreach (JSONData item in data.DataArray)
|
||||||
|
|
|
||||||
|
|
@ -141,7 +141,7 @@ namespace MinecraftClient
|
||||||
ChatBot.LogToConsole("Waiting 5 seconds (" + AttemptsLeft + " attempts left)...");
|
ChatBot.LogToConsole("Waiting 5 seconds (" + AttemptsLeft + " attempts left)...");
|
||||||
Thread.Sleep(5000); AttemptsLeft--; Program.Restart();
|
Thread.Sleep(5000); AttemptsLeft--; Program.Restart();
|
||||||
}
|
}
|
||||||
else if (!singlecommand){ Console.ReadLine(); }
|
else if (!singlecommand) { Console.ReadLine(); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -156,6 +156,11 @@ namespace MinecraftClient
|
||||||
{
|
{
|
||||||
while (client.Client.Connected)
|
while (client.Client.Connected)
|
||||||
{
|
{
|
||||||
|
if (Program.scripting_enabled)
|
||||||
|
{
|
||||||
|
handler.BotLoad(new Bots.scripting(Program.scripting_param));
|
||||||
|
Program.scripting_enabled = false;
|
||||||
|
}
|
||||||
text = ConsoleIO.ReadLine();
|
text = ConsoleIO.ReadLine();
|
||||||
if (text == "/quit" || text == "/reco" || text == "/reconnect") { break; }
|
if (text == "/quit" || text == "/reco" || text == "/reconnect") { break; }
|
||||||
while (text.Length > 0 && text[0] == ' ') { text = text.Substring(1); }
|
while (text.Length > 0 && text[0] == ' ') { text = text.Substring(1); }
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
|
||||||
<StartArguments>
|
<StartArguments>user - 127.0.0.1 bot:scripting</StartArguments>
|
||||||
</StartArguments>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<PublishUrlHistory>publish\</PublishUrlHistory>
|
<PublishUrlHistory>publish\</PublishUrlHistory>
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ namespace MinecraftClient
|
||||||
#region Login to Minecraft.net, Obtaining a session ID
|
#region Login to Minecraft.net, Obtaining a session ID
|
||||||
|
|
||||||
public enum LoginResult { Error, Success, WrongPassword, Blocked, AccountMigrated, NotPremium };
|
public enum LoginResult { Error, Success, WrongPassword, Blocked, AccountMigrated, NotPremium };
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Allows to login to a premium Minecraft account, and retrieve the session ID.
|
/// Allows to login to a premium Minecraft account, and retrieve the session ID.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -31,7 +31,8 @@ namespace MinecraftClient
|
||||||
{
|
{
|
||||||
Console.ForegroundColor = ConsoleColor.DarkGray;
|
Console.ForegroundColor = ConsoleColor.DarkGray;
|
||||||
WebClient wClient = new WebClient();
|
WebClient wClient = new WebClient();
|
||||||
Console.WriteLine("https://login.minecraft.net/?user=" + user + "&password=<******>&version=13");
|
string str_len = new String('*', pass.Length);
|
||||||
|
Console.WriteLine("https://login.minecraft.net/?user=" + user + "&password=<" + str_len + ">&version=13");
|
||||||
string result = wClient.DownloadString("https://login.minecraft.net/?user=" + user + "&password=" + pass + "&version=13");
|
string result = wClient.DownloadString("https://login.minecraft.net/?user=" + user + "&password=" + pass + "&version=13");
|
||||||
outdata = result;
|
outdata = result;
|
||||||
Console.WriteLine(result);
|
Console.WriteLine(result);
|
||||||
|
|
@ -133,7 +134,7 @@ namespace MinecraftClient
|
||||||
//If the client gets out of sync, check the last green packet processing code.
|
//If the client gets out of sync, check the last green packet processing code.
|
||||||
//if (result == ProcessResult.OK) { printstring("§a0x" + id.ToString("X"), false); }
|
//if (result == ProcessResult.OK) { printstring("§a0x" + id.ToString("X"), false); }
|
||||||
//else { printstring("§c0x" + id.ToString("X"), false); }
|
//else { printstring("§c0x" + id.ToString("X"), false); }
|
||||||
|
|
||||||
if (result == ProcessResult.ConnectionLost)
|
if (result == ProcessResult.ConnectionLost)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,10 @@ namespace MinecraftClient
|
||||||
|
|
||||||
class Program
|
class Program
|
||||||
{
|
{
|
||||||
|
// Scripting Bot Parameters - bearbear12345
|
||||||
|
public static bool scripting_enabled;
|
||||||
|
public static string scripting_param;
|
||||||
|
// End Scripting Bot Parameters
|
||||||
private static McTcpClient Client;
|
private static McTcpClient Client;
|
||||||
private static string loginusername = "";
|
private static string loginusername = "";
|
||||||
private static string user = "";
|
private static string user = "";
|
||||||
|
|
@ -50,17 +54,20 @@ namespace MinecraftClient
|
||||||
|
|
||||||
//Asking the user to type in missing data such as Username and Password
|
//Asking the user to type in missing data such as Username and Password
|
||||||
|
|
||||||
if (user == "") {
|
if (user == "")
|
||||||
|
{
|
||||||
Console.Write("Username : ");
|
Console.Write("Username : ");
|
||||||
user = Console.ReadLine();
|
user = Console.ReadLine();
|
||||||
}
|
}
|
||||||
if (pass == "") {
|
if (pass == "")
|
||||||
|
{
|
||||||
Console.Write("Password : ");
|
Console.Write("Password : ");
|
||||||
pass = Console.ReadLine();
|
pass = Console.ReadLine();
|
||||||
|
|
||||||
//Hide the password
|
//Hide the password
|
||||||
Console.CursorTop--;
|
Console.CursorTop--;
|
||||||
Console.Write("Password : <******>");
|
string str_len = new String('*', pass.Length);
|
||||||
|
Console.Write("Password : <" + str_len + ">");
|
||||||
for (int i = 19; i < Console.BufferWidth; i++) { Console.Write(' '); }
|
for (int i = 19; i < Console.BufferWidth; i++) { Console.Write(' '); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -78,6 +85,7 @@ namespace MinecraftClient
|
||||||
|
|
||||||
private static void InitializeClient()
|
private static void InitializeClient()
|
||||||
{
|
{
|
||||||
|
|
||||||
MinecraftCom.LoginResult result;
|
MinecraftCom.LoginResult result;
|
||||||
string logindata = "";
|
string logindata = "";
|
||||||
|
|
||||||
|
|
@ -199,12 +207,24 @@ namespace MinecraftClient
|
||||||
|
|
||||||
case "xauth":
|
case "xauth":
|
||||||
if (botargs.Length > 2) { handler.BotLoad(new Bots.xAuth(botargs[2])); } break;
|
if (botargs.Length > 2) { handler.BotLoad(new Bots.xAuth(botargs[2])); } break;
|
||||||
|
case "scripting":
|
||||||
|
if (botargs.Length > 2)
|
||||||
|
{
|
||||||
|
scripting_enabled = true;
|
||||||
|
scripting_param = botargs[2];
|
||||||
|
//handler.BotLoad(new Bots.scripting(botargs[2]));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
scripting_enabled = true;
|
||||||
|
scripting_param = "scripting.txt";
|
||||||
|
//Launches later on after connected in MinecraftCom.cs
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
command = "";
|
command = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Start the main TCP client
|
//Start the main TCP client
|
||||||
if (command != "")
|
if (command != "")
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 194 KiB After Width: | Height: | Size: 161 KiB |
Loading…
Add table
Add a link
Reference in a new issue