mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Improve offline interactions
- Add prompt for Minecraft version - Improve offline-mode command prompt - Fix default value on parse error in protocol handler - Fix failed to connect not showing offline prompt
This commit is contained in:
parent
7757d5ae03
commit
05a141c50d
4 changed files with 78 additions and 30 deletions
|
|
@ -149,7 +149,10 @@ namespace MinecraftClient
|
|||
ChatBot.LogToConsole("Waiting 5 seconds (" + AttemptsLeft + " attempts left)...");
|
||||
Thread.Sleep(5000); AttemptsLeft--; Program.Restart();
|
||||
}
|
||||
else if (!singlecommand) { Console.ReadLine(); }
|
||||
else if (!singlecommand && Settings.interactiveMode)
|
||||
{
|
||||
Program.OfflineCommandPrompt();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ namespace MinecraftClient
|
|||
public static string[] startupargs;
|
||||
public const string Version = "1.8.2";
|
||||
private static Thread offlinePrompt = null;
|
||||
private static bool useMcVersionOnce = false;
|
||||
|
||||
/// <summary>
|
||||
/// The main entry point of Minecraft Console Client
|
||||
|
|
@ -148,11 +149,18 @@ namespace MinecraftClient
|
|||
if (Settings.ServerVersion != "" && Settings.ServerVersion.ToLower() != "auto")
|
||||
{
|
||||
protocolversion = Protocol.ProtocolHandler.MCVer2ProtocolVersion(Settings.ServerVersion);
|
||||
|
||||
if (protocolversion != 0)
|
||||
{
|
||||
ConsoleIO.WriteLineFormatted("§8Using Minecraft version " + Settings.ServerVersion + " (protocol v" + protocolversion + ')');
|
||||
}
|
||||
else ConsoleIO.WriteLineFormatted("§8Unknown or not supported MC version '" + Settings.ServerVersion + "'.\nSwitching to autodetection mode.");
|
||||
|
||||
if (useMcVersionOnce)
|
||||
{
|
||||
useMcVersionOnce = false;
|
||||
Settings.ServerVersion = "";
|
||||
}
|
||||
}
|
||||
|
||||
if (protocolversion == 0)
|
||||
|
|
@ -166,7 +174,18 @@ namespace MinecraftClient
|
|||
ChatBots.AutoRelog bot = new ChatBots.AutoRelog(Settings.AutoRelog_Delay, Settings.AutoRelog_Retries);
|
||||
if (!bot.OnDisconnect(ChatBot.DisconnectReason.ConnectionLost, "Failed to ping this IP.")) { OfflineCommandPrompt(); }
|
||||
}
|
||||
else OfflineCommandPrompt();
|
||||
else
|
||||
{
|
||||
if (Settings.interactiveMode)
|
||||
{
|
||||
if (MinecraftVersionPrompt())
|
||||
{
|
||||
Restart();
|
||||
return;
|
||||
}
|
||||
OfflineCommandPrompt();
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
@ -191,7 +210,11 @@ namespace MinecraftClient
|
|||
else
|
||||
{
|
||||
Console.WriteLine("Failed to determine server version.");
|
||||
OfflineCommandPrompt();
|
||||
if (Settings.interactiveMode && MinecraftVersionPrompt())
|
||||
{
|
||||
Restart();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
@ -256,7 +279,7 @@ namespace MinecraftClient
|
|||
|
||||
public static void OfflineCommandPrompt()
|
||||
{
|
||||
if (!Settings.exitOnFailure && offlinePrompt == null)
|
||||
if (Settings.interactiveMode && offlinePrompt == null)
|
||||
{
|
||||
offlinePrompt = new Thread(new ThreadStart(delegate
|
||||
{
|
||||
|
|
@ -268,11 +291,13 @@ namespace MinecraftClient
|
|||
if (!ConsoleIO.basicIO) { ConsoleIO.Write('>'); }
|
||||
command = Console.ReadLine().Trim();
|
||||
if (command.Length > 0)
|
||||
{
|
||||
if (Settings.internalCmdChar != ' ' && command[0] == Settings.internalCmdChar)
|
||||
{
|
||||
string message = "";
|
||||
|
||||
if (Settings.internalCmdChar != ' '
|
||||
&& command[0] == Settings.internalCmdChar)
|
||||
command = command.Substring(1);
|
||||
|
||||
if (command.StartsWith("reco"))
|
||||
{
|
||||
message = new Commands.Reco().Run(null, Settings.expandVars(command));
|
||||
|
|
@ -291,9 +316,9 @@ namespace MinecraftClient
|
|||
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.");
|
||||
|
||||
if (message != "")
|
||||
ConsoleIO.WriteLineFormatted("§8MCC: " + message);
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
|
@ -301,6 +326,26 @@ namespace MinecraftClient
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
|
||||
public static bool MinecraftVersionPrompt()
|
||||
{
|
||||
if (Settings.interactiveMode)
|
||||
{
|
||||
Console.Write("Server version : ");
|
||||
Settings.ServerVersion = Console.ReadLine();
|
||||
if (Settings.ServerVersion != "")
|
||||
{
|
||||
useMcVersionOnce = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Detect if the user is running Minecraft Console Client through Mono
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -124,7 +124,7 @@ namespace MinecraftClient.Protocol
|
|||
}
|
||||
catch
|
||||
{
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ namespace MinecraftClient
|
|||
public static List<string> Bots_Owners = new List<string>();
|
||||
public static string Language = "en_GB";
|
||||
public static bool chatTimeStamps = false;
|
||||
public static bool exitOnFailure = false;
|
||||
public static bool interactiveMode = true;
|
||||
public static char internalCmdChar = '/';
|
||||
public static bool playerHeadAsIcon = false;
|
||||
public static string chatbotLogFile = "";
|
||||
|
|
@ -148,7 +148,7 @@ namespace MinecraftClient
|
|||
case "language": Language = argValue; break;
|
||||
case "consoletitle": ConsoleTitle = argValue; break;
|
||||
case "timestamps": chatTimeStamps = str2bool(argValue); break;
|
||||
case "exitonfailure": exitOnFailure = str2bool(argValue); break;
|
||||
case "exitonfailure": interactiveMode = !str2bool(argValue); break;
|
||||
case "playerheadicon": playerHeadAsIcon = str2bool(argValue); break;
|
||||
case "chatbotlogfile": chatbotLogFile = argValue; break;
|
||||
case "mcversion": ServerVersion = argValue; break;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue