Added a custom timeout setting

Added an option for custom timeout as requested in #1337.
This commit is contained in:
Anon 2022-09-06 14:10:24 +00:00 committed by GitHub
commit 81579a7e40
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 7 deletions

View file

@ -62,7 +62,7 @@ namespace MinecraftClient
private float playerYaw; private float playerYaw;
private float playerPitch; private float playerPitch;
private double motionY; private double motionY;
public enum MovementType { Sneak, Walk, Sprint} public enum MovementType { Sneak, Walk, Sprint }
public int currentMovementSpeed = 4; public int currentMovementSpeed = 4;
private int sequenceId; // User for player block synchronization (Aka. digging, placing blocks, etc..) private int sequenceId; // User for player block synchronization (Aka. digging, placing blocks, etc..)
@ -205,7 +205,7 @@ namespace MinecraftClient
{ {
client = ProxyHandler.newTcpClient(host, port); client = ProxyHandler.newTcpClient(host, port);
client.ReceiveBufferSize = 1024 * 1024; client.ReceiveBufferSize = 1024 * 1024;
client.ReceiveTimeout = 30000; // 30 seconds client.ReceiveTimeout = Settings.Timeout * 1000; // Default: 30 seconds
handler = Protocol.ProtocolHandler.GetProtocolHandler(client, protocolversion, forgeInfo, this); handler = Protocol.ProtocolHandler.GetProtocolHandler(client, protocolversion, forgeInfo, this);
Log.Info(Translations.Get("mcc.version_supported")); Log.Info(Translations.Get("mcc.version_supported"));
@ -398,7 +398,7 @@ namespace MinecraftClient
lock (lastKeepAliveLock) lock (lastKeepAliveLock)
{ {
if (lastKeepAlive.AddSeconds(30) < DateTime.Now) if (lastKeepAlive.AddSeconds(Settings.Timeout) < DateTime.Now)
{ {
if (((CancellationToken)o!).IsCancellationRequested) if (((CancellationToken)o!).IsCancellationRequested)
return; return;

View file

@ -47,6 +47,7 @@ timestamps=false # Prepend timestamps to chat messages
autorespawn=false # Toggle auto respawn if client player was dead (make sure your spawn point is safe) autorespawn=false # Toggle auto respawn if client player was dead (make sure your spawn point is safe)
minecraftrealms=false # Enable support for joining Minecraft Realms worlds minecraftrealms=false # Enable support for joining Minecraft Realms worlds
moveheadwhilewalking=true # Enable head movement while walking to avoid anti-cheat triggers moveheadwhilewalking=true # Enable head movement while walking to avoid anti-cheat triggers
timeout=30 # Set a custom timeout in seconds (Default: 30). Use only if you know what you're doing.
[Signature] [Signature]
# Chat settings (affects minecraft 1.19+) # Chat settings (affects minecraft 1.19+)

View file

@ -108,6 +108,7 @@ namespace MinecraftClient
public static bool AutoRespawn = false; public static bool AutoRespawn = false;
public static bool MinecraftRealmsEnabled = true; public static bool MinecraftRealmsEnabled = true;
public static bool MoveHeadWhileWalking = true; public static bool MoveHeadWhileWalking = true;
public static int Timeout = 30;
// Signature // Signature
public static bool LoginWithSecureProfile = true; public static bool LoginWithSecureProfile = true;
@ -209,7 +210,7 @@ namespace MinecraftClient
//AutoCraft //AutoCraft
public static bool AutoCraft_Enabled = false; public static bool AutoCraft_Enabled = false;
public static string AutoCraft_configFile = @"autocraft\config.ini"; public static string AutoCraft_configFile = @"autocraft\config.ini";
//Mailer //Mailer
public static bool Mailer_Enabled = false; public static bool Mailer_Enabled = false;
public static string Mailer_DatabaseFile = "MailerDatabase.ini"; public static string Mailer_DatabaseFile = "MailerDatabase.ini";
@ -354,7 +355,8 @@ namespace MinecraftClient
{ {
case "login": Login = argValue; return true; case "login": Login = argValue; return true;
case "password": Password = argValue; return true; case "password": Password = argValue; return true;
case "type": AccountType = argValue == "mojang" case "type":
AccountType = argValue == "mojang"
? ProtocolHandler.AccountType.Mojang ? ProtocolHandler.AccountType.Mojang
: ProtocolHandler.AccountType.Microsoft; return true; : ProtocolHandler.AccountType.Microsoft; return true;
case "method": case "method":
@ -385,6 +387,7 @@ namespace MinecraftClient
case "debugmessages": DebugMessages = str2bool(argValue); return true; case "debugmessages": DebugMessages = str2bool(argValue); return true;
case "minecraftrealms": MinecraftRealmsEnabled = str2bool(argValue); return true; case "minecraftrealms": MinecraftRealmsEnabled = str2bool(argValue); return true;
case "moveheadwhilewalking": MoveHeadWhileWalking = str2bool(argValue); return true; case "moveheadwhilewalking": MoveHeadWhileWalking = str2bool(argValue); return true;
case "timeout": Timeout = str2int(argValue); return true;
case "botowners": case "botowners":
Bots_Owners.Clear(); Bots_Owners.Clear();
@ -822,7 +825,7 @@ namespace MinecraftClient
public static void WriteDefaultSettings(string settingsfile) public static void WriteDefaultSettings(string settingsfile)
{ {
// Load embedded default config and adjust line break for the current operating system // Load embedded default config and adjust line break for the current operating system
string settingsContents = String.Join(Environment.NewLine, string settingsContents = String.Join(Environment.NewLine,
DefaultConfigResource.MinecraftClient.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None)); DefaultConfigResource.MinecraftClient.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None));
// Write configuration file with current version number // Write configuration file with current version number
@ -844,7 +847,8 @@ namespace MinecraftClient
{ {
return Convert.ToInt32(str.Trim()); return Convert.ToInt32(str.Trim());
} }
catch { catch
{
ConsoleIO.WriteLogLine(Translations.Get("error.setting.str2int", str)); ConsoleIO.WriteLogLine(Translations.Get("error.setting.str2int", str));
return 0; return 0;
} }