@@ -153,6 +153,7 @@ public enum MovementType { Sneak, Walk, Sprint }
153
153
154
154
private static IMinecraftComHandler ? instance ;
155
155
public static IMinecraftComHandler ? Instance => instance ;
156
+
156
157
/// <summary>
157
158
/// Starts the main chat client, wich will login to the server using the MinecraftCom class.
158
159
/// </summary>
@@ -245,28 +246,48 @@ public McClient(SessionToken session, PlayerKeyPair? playerKeyPair, string serve
245
246
246
247
return ;
247
248
248
- Retry :
249
+ Retry :
249
250
if ( timeoutdetector != null )
250
251
{
251
252
timeoutdetector . Item2 . Cancel ( ) ;
252
253
timeoutdetector = null ;
253
254
}
254
- if ( ReconnectionAttemptsLeft > 0 )
255
+
256
+ if ( ! Config . ChatBot . AutoRelog . Enabled )
255
257
{
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
262
276
{
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.
268
279
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
+ }
270
291
}
271
292
272
293
/// <summary>
@@ -572,7 +593,7 @@ public void OnConnectionLost(ChatBot.DisconnectReason reason, string message)
572
593
ConsoleInteractive . ConsoleReader . StopReadThread ( ) ;
573
594
ConsoleInteractive . ConsoleReader . MessageReceived -= ConsoleReaderOnMessageReceived ;
574
595
ConsoleInteractive . ConsoleReader . OnInputChange -= ConsoleIO . AutocompleteHandler ;
575
- Program . HandleFailure ( ) ;
596
+ Program . HandleFailure ( message , false , reason ) ;
576
597
}
577
598
}
578
599
0 commit comments