mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Add timeout detect on server login
This commit is contained in:
parent
7fd0f9157f
commit
ad14edad2e
1 changed files with 28 additions and 16 deletions
|
|
@ -225,6 +225,13 @@ namespace MinecraftClient
|
|||
handler = Protocol.ProtocolHandler.GetProtocolHandler(client, protocolversion, forgeInfo, this);
|
||||
Log.Info(Translations.Get("mcc.version_supported"));
|
||||
|
||||
if (!singlecommand)
|
||||
{
|
||||
timeoutdetector = new Thread(new ThreadStart(TimeoutDetector));
|
||||
timeoutdetector.Name = "MCC Connection timeout detector";
|
||||
timeoutdetector.Start();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (handler.Login())
|
||||
|
|
@ -248,10 +255,6 @@ namespace MinecraftClient
|
|||
cmdprompt = new Thread(new ThreadStart(CommandPrompt));
|
||||
cmdprompt.Name = "MCC Command prompt";
|
||||
cmdprompt.Start();
|
||||
|
||||
timeoutdetector = new Thread(new ThreadStart(TimeoutDetector));
|
||||
timeoutdetector.Name = "MCC Connection timeout detector";
|
||||
timeoutdetector.Start();
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
@ -276,6 +279,11 @@ namespace MinecraftClient
|
|||
|
||||
if (retry)
|
||||
{
|
||||
if (timeoutdetector != null)
|
||||
{
|
||||
timeoutdetector.Abort();
|
||||
timeoutdetector = null;
|
||||
}
|
||||
if (ReconnectionAttemptsLeft > 0)
|
||||
{
|
||||
Log.Info(Translations.Get("mcc.reconnect", ReconnectionAttemptsLeft));
|
||||
|
|
@ -358,10 +366,7 @@ namespace MinecraftClient
|
|||
/// </summary>
|
||||
private void TimeoutDetector()
|
||||
{
|
||||
lock (lastKeepAliveLock)
|
||||
{
|
||||
lastKeepAlive = DateTime.Now;
|
||||
}
|
||||
UpdateKeepAlive();
|
||||
do
|
||||
{
|
||||
Thread.Sleep(TimeSpan.FromSeconds(15));
|
||||
|
|
@ -377,6 +382,17 @@ namespace MinecraftClient
|
|||
while (true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update last keep alive to current time
|
||||
/// </summary>
|
||||
private void UpdateKeepAlive()
|
||||
{
|
||||
lock (lastKeepAliveLock)
|
||||
{
|
||||
lastKeepAlive = DateTime.Now;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Perform an internal MCC command (not a server command, use SendText() instead for that!)
|
||||
/// </summary>
|
||||
|
|
@ -1747,10 +1763,7 @@ namespace MinecraftClient
|
|||
/// <param name="isJson">TRUE if the text is JSON-Encoded</param>
|
||||
public void OnTextReceived(string text, bool isJson)
|
||||
{
|
||||
lock (lastKeepAliveLock)
|
||||
{
|
||||
lastKeepAlive = DateTime.Now;
|
||||
}
|
||||
UpdateKeepAlive();
|
||||
|
||||
List<string> links = new List<string>();
|
||||
string json = null;
|
||||
|
|
@ -1776,10 +1789,7 @@ namespace MinecraftClient
|
|||
/// </summary>
|
||||
public void OnServerKeepAlive()
|
||||
{
|
||||
lock (lastKeepAliveLock)
|
||||
{
|
||||
lastKeepAlive = DateTime.Now;
|
||||
}
|
||||
UpdateKeepAlive();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -2116,6 +2126,8 @@ namespace MinecraftClient
|
|||
/// <param name="TimeOfDay"></param>
|
||||
public void OnTimeUpdate(long WorldAge, long TimeOfDay)
|
||||
{
|
||||
// TimeUpdate sent every server tick hence used as timeout detect
|
||||
UpdateKeepAlive();
|
||||
// calculate server tps
|
||||
if (lastAge != 0)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue