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>
|
||||
/// Runs a list of commands
|
||||
/// Usage: bot:scripting:filename
|
||||
/// Script must be placed in the config directory
|
||||
/// </summary>
|
||||
|
||||
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>
|
||||
/// This class parses JSON chat data from MC 1.6+ and returns the appropriate string to be printed.
|
||||
/// </summary>
|
||||
|
||||
|
||||
static class ChatParser
|
||||
{
|
||||
/// <summary>
|
||||
|
|
@ -54,11 +54,11 @@ namespace MinecraftClient
|
|||
|
||||
private static string color2tag(string colorname)
|
||||
{
|
||||
switch(colorname.ToLower())
|
||||
switch (colorname.ToLower())
|
||||
{
|
||||
case "black": return "§0";
|
||||
case "dark_blue": return "§1";
|
||||
case "dark_green" : return "§2";
|
||||
case "dark_green": return "§2";
|
||||
case "dark_cyan": return "§3";
|
||||
case "dark_cyanred": return "§4";
|
||||
case "dark_magenta": return "§5";
|
||||
|
|
@ -278,7 +278,7 @@ namespace MinecraftClient
|
|||
return colorcode + TranslateString(JSONData2String(data.Properties["translate"]), using_data) + colorcode;
|
||||
}
|
||||
else return "";
|
||||
|
||||
|
||||
case JSONData.DataType.Array:
|
||||
string result = "";
|
||||
foreach (JSONData item in data.DataArray)
|
||||
|
|
|
|||
|
|
@ -141,7 +141,7 @@ namespace MinecraftClient
|
|||
ChatBot.LogToConsole("Waiting 5 seconds (" + AttemptsLeft + " attempts left)...");
|
||||
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)
|
||||
{
|
||||
if (Program.scripting_enabled)
|
||||
{
|
||||
handler.BotLoad(new Bots.scripting(Program.scripting_param));
|
||||
Program.scripting_enabled = false;
|
||||
}
|
||||
text = ConsoleIO.ReadLine();
|
||||
if (text == "/quit" || text == "/reco" || text == "/reconnect") { break; }
|
||||
while (text.Length > 0 && text[0] == ' ') { text = text.Substring(1); }
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
|
||||
<StartArguments>
|
||||
</StartArguments>
|
||||
<StartArguments>user - 127.0.0.1 bot:scripting</StartArguments>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<PublishUrlHistory>publish\</PublishUrlHistory>
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ namespace MinecraftClient
|
|||
#region Login to Minecraft.net, Obtaining a session ID
|
||||
|
||||
public enum LoginResult { Error, Success, WrongPassword, Blocked, AccountMigrated, NotPremium };
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Allows to login to a premium Minecraft account, and retrieve the session ID.
|
||||
/// </summary>
|
||||
|
|
@ -31,7 +31,8 @@ namespace MinecraftClient
|
|||
{
|
||||
Console.ForegroundColor = ConsoleColor.DarkGray;
|
||||
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");
|
||||
outdata = 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 (result == ProcessResult.OK) { printstring("§a0x" + id.ToString("X"), false); }
|
||||
//else { printstring("§c0x" + id.ToString("X"), false); }
|
||||
|
||||
|
||||
if (result == ProcessResult.ConnectionLost)
|
||||
{
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -13,6 +13,10 @@ namespace MinecraftClient
|
|||
|
||||
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 string loginusername = "";
|
||||
private static string user = "";
|
||||
|
|
@ -50,17 +54,20 @@ namespace MinecraftClient
|
|||
|
||||
//Asking the user to type in missing data such as Username and Password
|
||||
|
||||
if (user == "") {
|
||||
if (user == "")
|
||||
{
|
||||
Console.Write("Username : ");
|
||||
user = Console.ReadLine();
|
||||
}
|
||||
if (pass == "") {
|
||||
if (pass == "")
|
||||
{
|
||||
Console.Write("Password : ");
|
||||
pass = Console.ReadLine();
|
||||
|
||||
//Hide the password
|
||||
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(' '); }
|
||||
}
|
||||
|
||||
|
|
@ -78,6 +85,7 @@ namespace MinecraftClient
|
|||
|
||||
private static void InitializeClient()
|
||||
{
|
||||
|
||||
MinecraftCom.LoginResult result;
|
||||
string logindata = "";
|
||||
|
||||
|
|
@ -199,12 +207,24 @@ namespace MinecraftClient
|
|||
|
||||
case "xauth":
|
||||
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 = "";
|
||||
}
|
||||
}
|
||||
|
||||
//Start the main TCP client
|
||||
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