Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/MinecraftClient.v11.suo
2 changes: 2 additions & 0 deletions MinecraftClient/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/bin/
/obj/
110 changes: 88 additions & 22 deletions MinecraftClient/Bots.cs
Original file line number Diff line number Diff line change
Expand Up @@ -486,14 +486,14 @@ private void start()

private string chooseword()
{
if (System.IO.File.Exists(English ? "words.txt" : "mots.txt"))
if (System.IO.File.Exists(English ? "config/hangman-words.txt" : "config/pendu-mots.txt"))
{
string[] dico = System.IO.File.ReadAllLines(English ? "words.txt" : "mots.txt");
return dico[new Random().Next(dico.Length)];
}
else
{
LogToConsole(English ? "Cannot find words.txt !" : "Fichier mots.txt introuvable !");
LogToConsole(English ? "Cannot find words.txt in config directory !" : "Fichier mots.txt introuvable dans config/hangman dossier!");
return English ? "WORDSAREMISSING" : "DICOMANQUANT";
}
}
Expand All @@ -502,14 +502,14 @@ private string[] getowners()
{
List<string> owners = new List<string>();
owners.Add("CONSOLE");
if (System.IO.File.Exists("bot-owners.txt"))
if (System.IO.File.Exists("config/bot-owners.txt"))
{
foreach (string s in System.IO.File.ReadAllLines("bot-owners.txt"))
foreach (string s in System.IO.File.ReadAllLines("config/bot-owners.txt"))
{
owners.Add(s.ToUpper());
}
}
else LogToConsole(English ? "Cannot find bot-owners.txt !" : "Fichier bot-owners.txt introuvable !");
else LogToConsole(English ? "Cannot find bot-owners.txt in config folder!" : "Fichier bot-owners.txt introuvable dans config!");
return owners.ToArray();
}

Expand Down Expand Up @@ -552,39 +552,39 @@ private bool winner

public class Alerts : ChatBot
{
private string[] dictionnary = new string[0];
private string[] dictionary = new string[0];
private string[] excludelist = new string[0];

public override void Initialize()
{
if (System.IO.File.Exists("alerts.txt"))
if (System.IO.File.Exists("config/alerts.txt"))
{
dictionnary = System.IO.File.ReadAllLines("alerts.txt");
dictionary = System.IO.File.ReadAllLines("config/alerts.txt");

for (int i = 0; i < dictionnary.Length; i++)
for (int i = 0; i < dictionary.Length; i++)
{
dictionnary[i] = dictionnary[i].ToLower();
dictionary[i] = dictionary[i].ToLower();
}
}
else LogToConsole("Cannot find alerts.txt !");
else LogToConsole("Cannot find alerts.txt in the config folder!");

if (System.IO.File.Exists("alerts-exclude.txt"))
if (System.IO.File.Exists("config/alerts-exclude.txt"))
{
excludelist = System.IO.File.ReadAllLines("alerts-exclude.txt");
excludelist = System.IO.File.ReadAllLines("config/alerts-exclude.txt");

for (int i = 0; i < excludelist.Length; i++)
{
excludelist[i] = excludelist[i].ToLower();
}
}
else LogToConsole("Cannot find alerts-exclude.txt !");
else LogToConsole("Cannot find alerts-exclude.txt in the config folder!");
}

public override void GetText(string text)
{
text = getVerbatim(text);
string comp = text.ToLower();
foreach (string alert in dictionnary)
foreach (string alert in dictionary)
{
if (comp.Contains(alert))
{
Expand Down Expand Up @@ -764,7 +764,7 @@ private void save(string tosave)

public class AutoRelog : ChatBot
{
private string[] dictionnary = new string[0];
private string[] dictionary = new string[0];
private int attempts;
private int delay;

Expand All @@ -786,23 +786,23 @@ public AutoRelog(int DelayBeforeRelog, int retries)
public override void Initialize()
{
McTcpClient.AttemptsLeft = attempts;
if (System.IO.File.Exists("kickmessages.txt"))
if (System.IO.File.Exists("config/kickmessages.txt"))
{
dictionnary = System.IO.File.ReadAllLines("kickmessages.txt");
dictionary = System.IO.File.ReadAllLines("config/kickmessages.txt");

for (int i = 0; i < dictionnary.Length; i++)
for (int i = 0; i < dictionary.Length; i++)
{
dictionnary[i] = dictionnary[i].ToLower();
dictionary[i] = dictionary[i].ToLower();
}
}
else LogToConsole("Cannot find kickmessages.txt !");
else LogToConsole("Cannot find kickmessages.txt in the config directory!");
}

public override bool OnDisconnect(DisconnectReason reason, string message)
{
message = getVerbatim(message);
string comp = message.ToLower();
foreach (string msg in dictionnary)
foreach (string msg in dictionary)
{
if (comp.Contains(msg))
{
Expand Down Expand Up @@ -841,5 +841,71 @@ public override void Update()
}
}
}

/// <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.B_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 changes: 4 additions & 4 deletions MinecraftClient/ChatParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -54,11 +54,11 @@ public JSONData(DataType datatype)

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";
Expand Down Expand Up @@ -278,7 +278,7 @@ private static string JSONData2String(JSONData data)
return colorcode + TranslateString(JSONData2String(data.Properties["translate"]), using_data) + colorcode;
}
else return "";

case JSONData.DataType.Array:
string result = "";
foreach (JSONData item in data.DataArray)
Expand Down
7 changes: 6 additions & 1 deletion MinecraftClient/McTcpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ private void StartClient(string user, string sessionID, string server_port, bool
ChatBot.LogToConsole("Waiting 5 seconds (" + AttemptsLeft + " attempts left)...");
Thread.Sleep(5000); AttemptsLeft--; Program.Restart();
}
else if (!singlecommand){ Console.ReadLine(); }
else if (!singlecommand) { Console.ReadLine(); }
}
}

Expand All @@ -156,6 +156,11 @@ private void StartTalk()
{
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); }
Expand Down
18 changes: 13 additions & 5 deletions MinecraftClient/MinecraftClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@
<PropertyGroup>
<SignManifests>false</SignManifests>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>resources\appicon.ico</ApplicationIcon>
</PropertyGroup>
<PropertyGroup>
<StartupObject>MinecraftClient.Program</StartupObject>
</PropertyGroup>
<PropertyGroup />
<ItemGroup>
<Reference Include="BouncyCastle.Crypto, Version=1.7.4114.6375, Culture=neutral, PublicKeyToken=0e99375e54769942">
<SpecificVersion>False</SpecificVersion>
Expand Down Expand Up @@ -110,11 +117,12 @@
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<Content Include="BouncyCastle.Crypto.dll" />
<Content Include="IKVM.OpenJDK.Core.dll" />
<Content Include="IKVM.OpenJDK.Security.dll" />
<Content Include="IKVM.OpenJDK.Util.dll" />
<Content Include="IKVM.Runtime.dll" />
<Content Include="resources\appicon.ico" />
<Content Include="lib\BouncyCastle.Crypto.dll" />
<Content Include="lib\IKVM.OpenJDK.Core.dll" />
<Content Include="lib\IKVM.OpenJDK.Security.dll" />
<Content Include="lib\IKVM.OpenJDK.Util.dll" />
<Content Include="lib\IKVM.Runtime.dll" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
3 changes: 1 addition & 2 deletions MinecraftClient/MinecraftClient.csproj.user
Original file line number Diff line number Diff line change
@@ -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>
Expand Down
17 changes: 9 additions & 8 deletions MinecraftClient/MinecraftCom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class MinecraftCom
#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>
Expand All @@ -31,7 +31,8 @@ public static LoginResult GetLogin(string user, string pass, ref string outdata)
{
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);
Expand Down Expand Up @@ -133,7 +134,7 @@ public bool Update()
//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;
Expand Down Expand Up @@ -283,11 +284,11 @@ private void readData(int offset)
}
private string readNextString()
{
short lenght = readNextShort();
if (lenght > 0)
short length = readNextShort();
if (length > 0)
{
byte[] cache = new byte[lenght * 2];
Receive(cache, 0, lenght * 2, SocketFlags.None);
byte[] cache = new byte[length * 2];
Receive(cache, 0, length * 2, SocketFlags.None);
string result = ByteArrayToString(cache);
return result;
}
Expand Down Expand Up @@ -329,7 +330,7 @@ private void readNextItemSlot()
readData(1); //Item count
readData(2); //Item damage
short length = readNextShort();
//If lenght of optional NBT data > 0, read it
//If length of optional NBT data > 0, read it
if (length > 0) { readData(length); }
}
}
Expand Down
Loading