Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
dc06cef
Fix OverflowException for server port
ORelio Oct 9, 2014
531aede
Protocol18: Redirect ping to Protocol17
ORelio Oct 28, 2014
f0f8183
Merge pull request #50 from ORelio/master
ORelio Oct 28, 2014
d6c286b
Remove useless ping method from Protocol18
ORelio Oct 28, 2014
b904664
Use usigned short to cover full range of ports
lokulin Nov 4, 2014
466ad07
Using ushort rather than keyword
lokulin Nov 4, 2014
284d335
Update short to ushort
lokulin Nov 4, 2014
006a1a5
Missed ushort in protocol handler
Nov 6, 2014
5c8c3f4
Merge branch 'master' into Indev
lokulin Nov 6, 2014
157aa2a
Merge pull request #53 from lokulin/Indev
ORelio Nov 6, 2014
07fed5c
Added a player list command /list
lokulin Nov 10, 2014
b0988a8
Ignore MonoDevelop userprefs file
lokulin Nov 10, 2014
7fa2e0d
fixed whitespace to fit with code style
lokulin Nov 10, 2014
5d1aee4
Merge pull request #54 from lokulin/Indev
ORelio Nov 10, 2014
f820412
/list command improvements
ORelio Nov 10, 2014
8d16f1e
Add /list support in Protocol17
ORelio Nov 10, 2014
8e458f7
Add /list support in Protocol16
ORelio Nov 11, 2014
2dec21d
Add Minecraft 1.8.1 in supported version list
ORelio Nov 11, 2014
4752094
Fix server version detection for Bungeecord 1.8
ORelio Nov 11, 2014
1499f8c
Refactor Alerts Bot + Fix crash
ORelio Dec 16, 2014
dd001e3
Auto-Tpaccept from everyone
ORelio Jan 2, 2015
bdbc408
Update RemoteControl.cs
medxo Jan 22, 2015
314c556
Merge pull request #61 from medxo/patch-1
ORelio Jan 22, 2015
24c4344
Fix scripts failing to send msg after reco
ORelio Jan 23, 2015
ee406b2
Use Trim instead of space deletion
ORelio Jan 27, 2015
391eca1
Add 15 seconds timeout to session and login
ORelio Jan 27, 2015
2408b51
Fix BungeeCord 1.8 (2nd attempt)
ORelio Jan 31, 2015
b566882
Quick GUI fix
ORelio Feb 3, 2015
89ccc9d
Add Herochat/Essentials PM Check
JamieSinn Feb 21, 2015
9fc8faa
Merge pull request #65 from JamieSinn/patch-1
ORelio Feb 24, 2015
c4628ba
Update README.txt
ORelio Feb 24, 2015
57024a7
Fix crash when log file is in same folder
ORelio Feb 26, 2015
72c2ff5
Handle HeroChat chat messages
ORelio Feb 26, 2015
e491603
Fix crash on disconnect when failed to connect
ORelio Mar 2, 2015
07964e9
Add build configuration
ORelio Mar 4, 2015
67e5882
Remove build configuration
ORelio Mar 11, 2015
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
Expand Up @@ -2,3 +2,4 @@
/MinecraftClient.suo
/MinecraftClientGUI.v11.suo
/MinecraftClientGUI.suo
/MinecraftClient.userprefs
41 changes: 41 additions & 0 deletions MinecraftClient/AutoTimeout.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Threading;

namespace MinecraftClient
{
/// <summary>
/// Allow easy timeout on pieces of code
/// </summary>
/// <remarks>
/// By ORelio - (c) 2014 - CDDL 1.0
/// </remarks>
public class AutoTimeout
{
/// <summary>
/// Perform the specified action with specified timeout
/// </summary>
/// <param name="action">Action to run</param>
/// <param name="timeout">Maximum timeout in milliseconds</param>
/// <returns>True if the action finished whithout timing out</returns>
public static bool Perform(Action action, int timeout)
{
return Perform(action, TimeSpan.FromMilliseconds(timeout));
}

/// <summary>
/// Perform the specified action with specified timeout
/// </summary>
/// <param name="action">Action to run</param>
/// <param name="timeout">Maximum timeout</param>
/// <returns>True if the action finished whithout timing out</returns>
public static bool Perform(Action action, TimeSpan timeout)
{
Thread thread = new Thread(new ThreadStart(action));
thread.Start();
bool success = thread.Join(timeout);
if (!success)
thread.Abort();
return success;
}
}
}
20 changes: 20 additions & 0 deletions MinecraftClient/ChatBot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,26 @@ protected static bool isPrivateMessage(string text, ref string message, ref stri
return isValidName(sender);
}

//Detect HeroChat PMsend
//From Someone: message
else if (text.StartsWith("From "))
{
sender = text.Substring(5).Split(':')[0];
message = text.Substring(text.IndexOf(':') + 2);
return isValidName(sender);
}

//Detect HeroChat Messages
//[Channel] [Rank] User: Message
else if (text.StartsWith("[") && text.Contains(':') && tmp.Length > 2)
{
int name_end = text.IndexOf(':');
int name_start = text.Substring(0, name_end).LastIndexOf(']') + 2;
sender = text.Substring(name_start, name_end - name_start);
message = text.Substring(name_end + 2);
return isValidName(sender);
}

else return false;
}
catch (IndexOutOfRangeException) { return false; }
Expand Down
133 changes: 52 additions & 81 deletions MinecraftClient/ChatBots/Alerts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,125 +2,96 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace MinecraftClient.ChatBots
{
/// <summary>
/// This bot make the console beep on some specified words. Useful to detect when someone is talking to you, for example.
/// </summary>

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

public override void Initialize()
/// <summary>
/// Import alerts from the specified file
/// </summary>
/// <param name="file"></param>
/// <returns></returns>
private static string[] FromFile(string file)
{
if (System.IO.File.Exists(Settings.Alerts_MatchesFile))
if (File.Exists(file))
{
List<string> tmp_dictionary = new List<string>();
string[] file_lines = System.IO.File.ReadAllLines(Settings.Alerts_MatchesFile);
foreach (string line in file_lines)
if (line.Trim().Length > 0 && !tmp_dictionary.Contains(line.ToLower()))
tmp_dictionary.Add(line.ToLower());
dictionary = tmp_dictionary.ToArray();
//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: " + Settings.Alerts_MatchesFile);

if (System.IO.File.Exists(Settings.Alerts_ExcludesFile))
else
{
List<string> tmp_excludelist = new List<string>();
string[] file_lines = System.IO.File.ReadAllLines(Settings.Alerts_ExcludesFile);
foreach (string line in file_lines)
if (line.Trim().Length > 0 && !tmp_excludelist.Contains(line.Trim().ToLower()))
tmp_excludelist.Add(line.ToLower());
excludelist = tmp_excludelist.ToArray();
LogToConsole("File not found: " + Settings.Alerts_MatchesFile);
return new string[0];
}
else LogToConsole("File not found : " + Settings.Alerts_ExcludesFile);
}

/// <summary>
/// Intitialize the Alerts bot
/// </summary>
public override void Initialize()
{
dictionary = FromFile(Settings.Alerts_MatchesFile);
excludelist = FromFile(Settings.Alerts_ExcludesFile);
}

/// <summary>
/// Process text received from the server to display alerts
/// </summary>
/// <param name="text">Received text</param>
public override void GetText(string text)
{
text = getVerbatim(text);
string comp = text.ToLower();
foreach (string alert in dictionary)
//Remove color codes and convert to lowercase
text = getVerbatim(text).ToLower();

//Proceed only if no exclusions are found in text
if (!excludelist.Any(exclusion => text.Contains(exclusion)))
{
if (comp.Contains(alert))
//Show an alert for each alert item found in text, if any
foreach (string alert in dictionary.Where(alert => text.Contains(alert)))
{
bool ok = true;
if (Settings.Alerts_Beep_Enabled)
Console.Beep(); //Text found !

foreach (string exclusion in excludelist)
{
if (comp.Contains(exclusion))
{
ok = false;
break;
}
}
if (ConsoleIO.basicIO) //Using a GUI? Pass text as is.
ConsoleIO.WriteLine(text.Replace(alert, "§c" + alert + "§r"));

if (ok)
else //Using Consome Prompt : Print text with alert highlighted
{
if (Settings.Alerts_Beep_Enabled) { Console.Beep(); } //Text found !
string[] splitted = text.Split(new string[] { alert }, StringSplitOptions.None);

if (ConsoleIO.basicIO) { ConsoleIO.WriteLine(comp.Replace(alert, "§c" + alert + "§r")); }
else
if (splitted.Length > 0)
{

#region Displaying the text with the interesting part highlighted

Console.BackgroundColor = ConsoleColor.DarkGray;
Console.ForegroundColor = ConsoleColor.White;
ConsoleIO.Write(splitted[0]);

//Will be used for text displaying
string[] temp = comp.Split(alert.Split(','), StringSplitOptions.None);
int p = 0;

//Special case : alert in the beginning of the text
string test = "";
for (int i = 0; i < alert.Length; i++)
{
test += comp[i];
}
if (test == alert)
for (int i = 1; i < splitted.Length; i++)
{
Console.BackgroundColor = ConsoleColor.Yellow;
Console.ForegroundColor = ConsoleColor.Red;
for (int i = 0; i < alert.Length; i++)
{
ConsoleIO.Write(text[p]);
p++;
}
}
ConsoleIO.Write(alert);

//Displaying the rest of the text
for (int i = 0; i < temp.Length; i++)
{
Console.BackgroundColor = ConsoleColor.DarkGray;
Console.ForegroundColor = ConsoleColor.White;
for (int j = 0; j < temp[i].Length; j++)
{
ConsoleIO.Write(text[p]);
p++;
}
Console.BackgroundColor = ConsoleColor.Yellow;
Console.ForegroundColor = ConsoleColor.Red;
try
{
for (int j = 0; j < alert.Length; j++)
{
ConsoleIO.Write(text[p]);
p++;
}
}
catch (IndexOutOfRangeException) { }
ConsoleIO.Write(splitted[i]);
}
Console.BackgroundColor = ConsoleColor.Black;
Console.ForegroundColor = ConsoleColor.Gray;
ConsoleIO.Write('\n');

#endregion

}

Console.BackgroundColor = ConsoleColor.Black;
Console.ForegroundColor = ConsoleColor.Gray;
ConsoleIO.Write('\n');
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion MinecraftClient/ChatBots/ChatLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ private void save(string tosave)
if (dateandtime)
tosave = getTimestamp() + ' ' + tosave;

Directory.CreateDirectory(Path.GetDirectoryName(logfile));
string directory = Path.GetDirectoryName(logfile);
if (!String.IsNullOrEmpty(directory) && !Directory.Exists(directory))
Directory.CreateDirectory(directory);
FileStream stream = new FileStream(logfile, FileMode.OpenOrCreate);
StreamWriter writer = new StreamWriter(stream);
stream.Seek(0, SeekOrigin.End);
Expand Down
6 changes: 4 additions & 2 deletions MinecraftClient/ChatBots/RemoteControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public override void GetText(string text)
{
text = getVerbatim(text);
string command = "", sender = "";
if (isPrivateMessage(text, ref command, ref sender) && Settings.Bots_Owners.Contains(sender.ToLower()))
if (isPrivateMessage(text, ref command, ref sender) && Settings.Bots_Owners.Contains(sender.ToLower().Trim()))
{
string response = "";
performInternalCommand(command, ref response);
Expand All @@ -24,7 +24,9 @@ public override void GetText(string text)
SendPrivateMessage(sender, response);
}
}
else if (Settings.RemoteCtrl_AutoTpaccept && isTeleportRequest(text, ref sender) && Settings.Bots_Owners.Contains(sender.ToLower()))
else if (Settings.RemoteCtrl_AutoTpaccept
&& isTeleportRequest(text, ref sender)
&& (Settings.RemoteCtrl_AutoTpaccept_Everyone || Settings.Bots_Owners.Contains(sender.ToLower().Trim())))
{
SendText("/tpaccept");
}
Expand Down
19 changes: 19 additions & 0 deletions MinecraftClient/Commands/List.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MinecraftClient.Commands
{
public class List : Command
{
public override string CMDName { get { return "list"; } }
public override string CMDDesc { get { return "list: get the player list."; } }

public override string Run(McTcpClient handler, string command)
{
return "PlayerList: " + String.Join(", ", handler.getOnlinePlayers());
}
}
}

Loading