@@ -153,6 +153,7 @@ public enum MovementType { Sneak, Walk, Sprint }
153153
154154 private static IMinecraftComHandler ? instance ;
155155 public static IMinecraftComHandler ? Instance => instance ;
156+
156157 /// <summary>
157158 /// Starts the main chat client, wich will login to the server using the MinecraftCom class.
158159 /// </summary>
@@ -245,28 +246,48 @@ public McClient(SessionToken session, PlayerKeyPair? playerKeyPair, string serve
245246
246247 return ;
247248
248- Retry :
249+ Retry :
249250 if ( timeoutdetector != null )
250251 {
251252 timeoutdetector . Item2 . Cancel ( ) ;
252253 timeoutdetector = null ;
253254 }
254- if ( ReconnectionAttemptsLeft > 0 )
255+
256+ if ( ! Config . ChatBot . AutoRelog . Enabled )
255257 {
256- Log . Info ( string . Format ( Translations . mcc_reconnect , ReconnectionAttemptsLeft ) ) ;
257- Thread . Sleep ( 5000 ) ;
258- ReconnectionAttemptsLeft -- ;
259- Program . Restart ( ) ;
260- }
261- else if ( InternalConfig . InteractiveMode )
258+ if ( ReconnectionAttemptsLeft > 0 )
259+ {
260+ Log . Info ( string . Format ( Translations . mcc_reconnect , ReconnectionAttemptsLeft ) ) ;
261+ Thread . Sleep ( 5000 ) ;
262+ ReconnectionAttemptsLeft -- ;
263+ Program . Restart ( ) ;
264+ }
265+ else if ( InternalConfig . InteractiveMode )
266+ {
267+ ConsoleInteractive . ConsoleReader . StopReadThread ( ) ;
268+ ConsoleInteractive . ConsoleReader . MessageReceived -= ConsoleReaderOnMessageReceived ;
269+ ConsoleInteractive . ConsoleReader . OnInputChange -= ConsoleIO . AutocompleteHandler ;
270+ Program . HandleFailure ( ) ;
271+ }
272+
273+ throw new Exception ( "Initialization failed." ) ;
274+ }
275+ else
262276 {
263- ConsoleInteractive . ConsoleReader . StopReadThread ( ) ;
264- ConsoleInteractive . ConsoleReader . MessageReceived -= ConsoleReaderOnMessageReceived ;
265- ConsoleInteractive . ConsoleReader . OnInputChange -= ConsoleIO . AutocompleteHandler ;
266- Program . HandleFailure ( ) ;
267- }
277+ // The AutoRelog ChatBot will handle reconnection at this point.
278+ // This is important, or else we'll have multiple instances of the client running at the same time.
268279
269- throw new Exception ( "Initialization failed." ) ;
280+ if ( ReconnectionAttemptsLeft == 0 )
281+ {
282+ if ( InternalConfig . InteractiveMode )
283+ {
284+ ConsoleInteractive . ConsoleReader . StopReadThread ( ) ;
285+ ConsoleInteractive . ConsoleReader . MessageReceived -= ConsoleReaderOnMessageReceived ;
286+ ConsoleInteractive . ConsoleReader . OnInputChange -= ConsoleIO . AutocompleteHandler ;
287+ Program . HandleFailure ( ) ;
288+ }
289+ }
290+ }
270291 }
271292
272293 /// <summary>
@@ -572,7 +593,7 @@ public void OnConnectionLost(ChatBot.DisconnectReason reason, string message)
572593 ConsoleInteractive . ConsoleReader . StopReadThread ( ) ;
573594 ConsoleInteractive . ConsoleReader . MessageReceived -= ConsoleReaderOnMessageReceived ;
574595 ConsoleInteractive . ConsoleReader . OnInputChange -= ConsoleIO . AutocompleteHandler ;
575- Program . HandleFailure ( ) ;
596+ Program . HandleFailure ( message , false , reason ) ;
576597 }
577598 }
578599
0 commit comments