Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
4f8fb8e
Add .gitignore for Microsoft Visual Studio files.
featherbear Jul 19, 2013
2acf12b
Added Library Folder (Aesthetic)
featherbear Jul 19, 2013
2262af9
+Application Icon :)
featherbear Jul 19, 2013
f4e5d97
Whoops.
featherbear Jul 19, 2013
d5cb14d
Typo: lenght -> length
featherbear Jul 19, 2013
7ad24fb
Edited to have the txt config files in a config folder, hangman words…
featherbear Jul 19, 2013
4c4319a
Update Bots.cs
dogwatch Jul 19, 2013
36c3c51
Hangman Config Files in Config folder now. Hangman folder deleted
featherbear Jul 19, 2013
019cd67
Renamed original icon into appicon_old.ico
featherbear Jul 19, 2013
222b533
Started command list sequence.
featherbear Jul 19, 2013
0332df9
Half-Done bot
featherbear Jul 19, 2013
7e70494
Script Works?
featherbear Jul 20, 2013
eda2710
Ok now I'm done :)
featherbear Jul 20, 2013
55b49c7
Merge pull request #5 from bearbear12345/Indev
ORelio Jul 20, 2013
4171095
Fix some words in English hangman dictionary
Or3L1o Jul 20, 2013
52d6030
Updated App Icon
Or3L1o Jul 20, 2013
2d174f8
Rewrite Scripting bot respecting the Bot API + Code Optimization
ORelio Jul 20, 2013
9d01d2c
Reverted password length change (privacy)
ORelio Jul 20, 2013
e31866f
Merge pull request #6 from dogwatch/patch-2
ORelio Jul 20, 2013
1ca3819
Small adjustments to Bots.cs
ORelio Jul 20, 2013
de50e07
Manually add changes from pull #8
ORelio Jul 20, 2013
6347d83
Improve translation rule parsing
ORelio Jul 27, 2013
b40ad6e
Removed useless using
ORelio Jul 27, 2013
ea27740
Improved console input/output
ORelio Jul 27, 2013
d6f4b97
Small code optimizations
ORelio Jul 27, 2013
d1770eb
Added respawn ability in /reco
ORelio Aug 6, 2013
88105d3
Added TAB autocomplete
ORelio Aug 6, 2013
df4a9cd
Added Settings class & Settings file
ORelio Aug 6, 2013
551c152
Support for unicode chars in JSON strings: \u0123
ORelio Aug 8, 2013
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/MinecraftClient.v11.suo
/MinecraftClient.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/
212 changes: 153 additions & 59 deletions MinecraftClient/Bots.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,19 @@ protected void SendText(string text)

protected static string getVerbatim(string text)
{
string verbatim = "";
for (int i = 0; i < text.Length; i++)
{
if (text[i] == '§')
{
i++; //Will skip also the next char
}
else verbatim += text[i]; //Add the char
}
return verbatim;
if ( String.IsNullOrEmpty(text) )
return String.Empty;

int idx = 0;
var data = new char[text.Length];

for ( int i = 0; i < text.Length; i++ )
if ( text[i] != '§' )
data[idx++] = text[i];
else
i++;

return new string(data, 0, idx);
}

/// <summary>
Expand All @@ -95,32 +98,17 @@ protected static string getVerbatim(string text)

protected static bool isValidName(string username)
{
if (username == "") { return false; }
string validchars =
"abcdefghijklmnopqrstuvwxyz"
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "1234567890_";

bool passe = false;
bool ok = true;
for (int i = 0; i < username.Length; i++)
{
passe = false;
for (int j = 0; j < validchars.Length; j++)
{
if (username[i] == validchars[j])
{
passe = true;
break;
}
}
if (!passe)
{
ok = false;
break;
}
}
return ok;
if ( String.IsNullOrEmpty(username) )
return false;

foreach ( char c in username )
if ( !((c >= 'a' && c <= 'z')
|| (c >= 'A' && c <= 'Z')
|| (c >= '0' && c <= '9')
|| c == '_') )
return false;

return true;
}

/// <summary>
Expand Down Expand Up @@ -229,6 +217,15 @@ protected void ReconnectToTheServer(int ExtraAttempts)
Program.Restart();
}

/// <summary>
/// Disconnect from the server and exit the program
/// </summary>

protected void DisconnectAndExit()
{
Program.Exit();
}

/// <summary>
/// Unload the chatbot, and release associated memory.
/// </summary>
Expand Down Expand Up @@ -486,14 +483,14 @@ private void start()

private string chooseword()
{
if (System.IO.File.Exists(English ? "words.txt" : "mots.txt"))
if (System.IO.File.Exists(English ? Settings.Hangman_FileWords_EN : Settings.Hangman_FileWords_FR))
{
string[] dico = System.IO.File.ReadAllLines(English ? "words.txt" : "mots.txt");
string[] dico = System.IO.File.ReadAllLines(English ? Settings.Hangman_FileWords_EN : Settings.Hangman_FileWords_FR);
return dico[new Random().Next(dico.Length)];
}
else
{
LogToConsole(English ? "Cannot find words.txt !" : "Fichier mots.txt introuvable !");
LogToConsole(English ? "File not found: " + Settings.Hangman_FileWords_EN : "Fichier introuvable : " + Settings.Hangman_FileWords_FR);
return English ? "WORDSAREMISSING" : "DICOMANQUANT";
}
}
Expand All @@ -502,14 +499,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(Settings.Bots_OwnersFile))
{
foreach (string s in System.IO.File.ReadAllLines("bot-owners.txt"))
foreach (string s in System.IO.File.ReadAllLines(Settings.Bots_OwnersFile))
{
owners.Add(s.ToUpper());
}
}
else LogToConsole(English ? "Cannot find bot-owners.txt !" : "Fichier bot-owners.txt introuvable !");
else LogToConsole(English ? "File not found: " + Settings.Bots_OwnersFile : "Fichier introuvable : " + Settings.Bots_OwnersFile);
return owners.ToArray();
}

Expand Down Expand Up @@ -552,39 +549,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(Settings.Alerts_MatchesFile))
{
dictionnary = System.IO.File.ReadAllLines("alerts.txt");
dictionary = System.IO.File.ReadAllLines(Settings.Alerts_MatchesFile);

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("File not found: " + Settings.Alerts_MatchesFile);

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

for (int i = 0; i < excludelist.Length; i++)
{
excludelist[i] = excludelist[i].ToLower();
}
}
else LogToConsole("Cannot find alerts-exclude.txt !");
else LogToConsole("File not found : " + Settings.Alerts_ExcludesFile);
}

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 @@ -711,6 +708,18 @@ public ChatLog(string file, MessageFilter filter, bool AddDateAndTime)
}
}

public static MessageFilter str2filter(string filtername)
{
switch (filtername.ToLower())
{
case "all": return MessageFilter.AllText;
case "messages": return MessageFilter.AllMessages;
case "chat": return MessageFilter.OnlyChat;
case "private": return MessageFilter.OnlyWhispers;
default: return MessageFilter.AllText;
}
}

public override void GetText(string text)
{
text = getVerbatim(text);
Expand Down Expand Up @@ -764,7 +773,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 +795,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(Settings.AutoRelog_KickMessagesFile))
{
dictionnary = System.IO.File.ReadAllLines("kickmessages.txt");
dictionary = System.IO.File.ReadAllLines(Settings.AutoRelog_KickMessagesFile);

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("File not found: " + Settings.AutoRelog_KickMessagesFile);
}

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 +850,90 @@ 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];
private int sleepticks = 10;
private int sleepticks_interval = 10;
private int nextline = 0;
public Scripting(string filename)
{
file = filename;
}

public override void Initialize()
{
// Loads the given file from the startup parameters
if (System.IO.File.Exists(file))
{
lines = System.IO.File.ReadAllLines(file); // Load the given bot text file (containing commands)
}
else
{
LogToConsole("File not found: " + file);
UnloadBot(); //No need to keep the bot active
}
}

public override void Update()
{
if (sleepticks > 0) { sleepticks--; }
else
{
if (nextline < lines.Length) //Is there an instruction left to interpret?
{
string instruction_line = lines[nextline].Trim(); // Removes all whitespaces at start and end of current line
nextline++; //Move the cursor so that the next time the following line will be interpreted
sleepticks = sleepticks_interval; //Used to delay next command sending and prevent from beign kicked for spamming

if (instruction_line.Length > 0)
{
if (!instruction_line.StartsWith("//") && !instruction_line.StartsWith("#"))
{
string instruction_name = instruction_line.Split(' ')[0];
switch (instruction_name.ToLower())
{
case "send":
SendText(instruction_line.Substring(5, instruction_line.Length - 5));
break;
case "wait":
int ticks = 10;
try
{
ticks = Convert.ToInt32(instruction_line.Substring(5, instruction_line.Length - 5));
}
catch { }
sleepticks = ticks;
break;
case "disconnect":
DisconnectAndExit();
break;
case "exit": //Exit bot & stay connected to the server
UnloadBot();
break;
default:
sleepticks = 0; Update(); //Unknown command : process next line immediately
break;
}
}
else { sleepticks = 0; Update(); } //Comment: process next line immediately
}
}
else
{
//No more instructions to interpret
UnloadBot();
}
}
}
}
}
}
Loading