Add offline command prompt

Fix #42, and allow more interactive commands when not connected to a
server. /quit, /reco, /connect are the only allowed commands in this
limited command prompt.
Updated Assembly Info, version number is now 1.8.0.
This commit is contained in:
ORelio 2014-08-18 15:10:15 +02:00
parent 31e53c2dbd
commit b0b65b7ce0
3 changed files with 66 additions and 47 deletions

View file

@ -264,7 +264,7 @@ namespace MinecraftClient
} }
else else
{ {
response_msg = "Unknown command '" + command_name + "'. Use 'help' for help."; response_msg = "Unknown command '" + command_name + "'. Use '" + (Settings.internalCmdChar == ' ' ? "" : "" + Settings.internalCmdChar) + "help' for help.";
return false; return false;
} }
return true; return true;
@ -332,7 +332,7 @@ namespace MinecraftClient
foreach (ChatBot bot in bots) foreach (ChatBot bot in bots)
will_restart |= bot.OnDisconnect(reason, message); will_restart |= bot.OnDisconnect(reason, message);
if (!will_restart) { Program.ReadLineReconnect(); } if (!will_restart) { Program.OfflineCommandPrompt(); }
} }
/// <summary> /// <summary>

View file

@ -4,6 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using MinecraftClient.Protocol; using MinecraftClient.Protocol;
using System.Reflection; using System.Reflection;
using System.Threading;
namespace MinecraftClient namespace MinecraftClient
{ {
@ -25,7 +26,7 @@ namespace MinecraftClient
static void Main(string[] args) static void Main(string[] args)
{ {
Console.WriteLine("Console Client for MC 1.4.6 to 1.7.9 - v" + Version + " - By ORelio & Contributors"); Console.WriteLine("Console Client for MC 1.4.6 to 1.7.10 - v" + Version + " - By ORelio & Contributors");
//Basic Input/Output ? //Basic Input/Output ?
if (args.Length >= 1 && args[args.Length - 1] == "BasicIO") if (args.Length >= 1 && args[args.Length - 1] == "BasicIO")
@ -162,9 +163,9 @@ namespace MinecraftClient
if (Settings.AutoRelog_Enabled) if (Settings.AutoRelog_Enabled)
{ {
ChatBots.AutoRelog bot = new ChatBots.AutoRelog(Settings.AutoRelog_Delay, Settings.AutoRelog_Retries); ChatBots.AutoRelog bot = new ChatBots.AutoRelog(Settings.AutoRelog_Delay, Settings.AutoRelog_Retries);
if (!bot.OnDisconnect(ChatBot.DisconnectReason.ConnectionLost, "Failed to ping this IP.")) { ReadLineReconnect(); } if (!bot.OnDisconnect(ChatBot.DisconnectReason.ConnectionLost, "Failed to ping this IP.")) { OfflineCommandPrompt(); }
} }
else ReadLineReconnect(); else OfflineCommandPrompt();
return; return;
} }
} }
@ -183,13 +184,13 @@ namespace MinecraftClient
catch (NotSupportedException) catch (NotSupportedException)
{ {
Console.WriteLine("Cannot connect to the server : This version is not supported !"); Console.WriteLine("Cannot connect to the server : This version is not supported !");
ReadLineReconnect(); OfflineCommandPrompt();
} }
} }
else else
{ {
Console.WriteLine("Failed to determine server version."); Console.WriteLine("Failed to determine server version.");
ReadLineReconnect(); OfflineCommandPrompt();
} }
} }
else else
@ -214,7 +215,7 @@ namespace MinecraftClient
break; break;
} }
while (Console.KeyAvailable) { Console.ReadKey(false); } while (Console.KeyAvailable) { Console.ReadKey(false); }
if (Settings.SingleCommand == "") { ReadLineReconnect(); } if (Settings.SingleCommand == "") { OfflineCommandPrompt(); }
} }
} }
@ -224,7 +225,13 @@ namespace MinecraftClient
public static void Restart() public static void Restart()
{ {
new System.Threading.Thread(new System.Threading.ThreadStart(t_restart)).Start(); new Thread(new ThreadStart(delegate
{
if (Client != null) { Client.Disconnect(); ConsoleIO.Reset(); }
if (offlinePrompt != null) { offlinePrompt.Abort(); offlinePrompt = null; ConsoleIO.Reset(); }
Console.WriteLine("Restarting Minecraft Console Client...");
InitializeClient();
})).Start();
} }
/// <summary> /// <summary>
@ -233,29 +240,63 @@ namespace MinecraftClient
public static void Exit() public static void Exit()
{ {
new System.Threading.Thread(new System.Threading.ThreadStart(t_exit)).Start(); new Thread(new ThreadStart(delegate
{
if (Client != null) { Client.Disconnect(); ConsoleIO.Reset(); }
if (offlinePrompt != null) { offlinePrompt.Abort(); offlinePrompt = null; ConsoleIO.Reset(); }
if (Settings.playerHeadAsIcon) { ConsoleIcon.revertToCMDIcon(); }
Environment.Exit(0);
})).Start();
} }
/// <summary> /// <summary>
/// Pause the program, usually when an error or a kick occured, letting the user press Enter to quit OR type /reconnect /// Pause the program, usually when an error or a kick occured, letting the user press Enter to quit OR type /reconnect
/// </summary> /// </summary>
public static void ReadLineReconnect() public static void OfflineCommandPrompt()
{ {
if (!Settings.exitOnFailure) if (!Settings.exitOnFailure && offlinePrompt == null)
{ {
string text = Console.ReadLine().Trim(); offlinePrompt = new Thread(new ThreadStart(delegate
if (text.Length > 0 && (Settings.internalCmdChar == ' ' || text[0] == Settings.internalCmdChar))
{ {
if (Settings.internalCmdChar != ' ') string command = " ";
text = text.Substring(1); ConsoleIO.WriteLineFormatted("Not connected to any server. Use '" + (Settings.internalCmdChar == ' ' ? "" : "" + Settings.internalCmdChar) + "help' for help.");
ConsoleIO.WriteLineFormatted("Or press Enter to exit Minecraft Console Client.");
if (text.StartsWith("reco")) while (command.Length > 0)
new Commands.Reco().Run(null, Settings.expandVars(text)); {
if (!ConsoleIO.basicIO) { ConsoleIO.Write('>'); }
if (text.StartsWith("connect")) command = Console.ReadLine().Trim();
new Commands.Connect().Run(null, Settings.expandVars(text)); if (command.Length > 0)
} {
if (Settings.internalCmdChar != ' ' && command[0] == Settings.internalCmdChar)
{
string message = "";
command = command.Substring(1);
if (command.StartsWith("reco"))
{
message = new Commands.Reco().Run(null, Settings.expandVars(command));
}
else if (command.StartsWith("connect"))
{
message = new Commands.Connect().Run(null, Settings.expandVars(command));
}
else if (command.StartsWith("exit") || command.StartsWith("quit"))
{
message = new Commands.Exit().Run(null, Settings.expandVars(command));
}
else if (command.StartsWith("help"))
{
ConsoleIO.WriteLineFormatted("§8MCC: " + (Settings.internalCmdChar == ' ' ? "" : "" + Settings.internalCmdChar) + new Commands.Reco().CMDDesc);
ConsoleIO.WriteLineFormatted("§8MCC: " + (Settings.internalCmdChar == ' ' ? "" : "" + Settings.internalCmdChar) + new Commands.Connect().CMDDesc);
}
else ConsoleIO.WriteLineFormatted("§8Unknown command '" + command.Split(' ')[0] + "'.");
if (message != "") { ConsoleIO.WriteLineFormatted("§8MCC: " + message); }
}
else ConsoleIO.WriteLineFormatted("§8Please type a command or press Enter to exit.");
}
}
}));
offlinePrompt.Start();
} }
} }
@ -271,28 +312,6 @@ namespace MinecraftClient
} }
} }
/// <summary>
/// Private thread for restarting the program. Called through Restart()
/// </summary>
private static void t_restart()
{
if (Client != null) { Client.Disconnect(); ConsoleIO.Reset(); }
Console.WriteLine("Restarting Minecraft Console Client...");
InitializeClient();
}
/// <summary>
/// Private thread for exiting the program. Called through Exit()
/// </summary>
private static void t_exit()
{
if (Client != null) { Client.Disconnect(); ConsoleIO.Reset(); }
if (Settings.playerHeadAsIcon) { ConsoleIcon.revertToCMDIcon(); }
Environment.Exit(0);
}
/// <summary> /// <summary>
/// Enumerate types in namespace through reflection /// Enumerate types in namespace through reflection
/// </summary> /// </summary>

View file

@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.7.3")] [assembly: AssemblyVersion("1.8.0")]
[assembly: AssemblyFileVersion("1.7.3")] [assembly: AssemblyFileVersion("1.8.0")]