diff --git a/CHANGELOG.md b/CHANGELOG.md index dae86230..45c57510 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,7 @@ This is the rolling changelog for TShock for Terraria. Use past tense when addin * If there is no section called "Upcoming changes" below this line, please add one with `## Upcoming changes` as the first line, and then a bulleted item directly after with the first change. ## Upcoming changes -* Hopefully not another Terraria version for a few days. +* Changed the server behavior when `SIGINT` is received. When `SIGINT` is trapped, the server will attempt to shut down safely. When it is trapped a second time in a session, it will immediately exit. (`SIGINT` is typically triggered via CTRL + C.) This means that it is possible to corrupt your world if you force shutdown at the wrong time (e.g., while the world is saving), but hopefully you expect this to happen if you hit CTRL + C twice in a session and you read the warning. (@hakusaro, @Onusai) ## TShock 4.5.9 * Added the ability to change a `TSPlayer`'s PVP mode. (@AgaSpace) diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 1634fe77..7e15128c 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -640,15 +640,24 @@ namespace TShockAPI } } + private bool tryingToShutdown = false; + /// ConsoleCancelHandler - Handles when Ctrl + C is sent to the server for a safe shutdown. /// The sender /// The ConsoleCancelEventArgs associated with the event. private void ConsoleCancelHandler(object sender, ConsoleCancelEventArgs args) { + if (tryingToShutdown) + { + System.Environment.Exit(1); + return; + } // Cancel the default behavior args.Cancel = true; - Log.ConsoleInfo("Interrupt received. Saving the world and shutting down."); + tryingToShutdown = true; + + Log.ConsoleInfo("Shutting down safely. To force shutdown, send SIGINT (CTRL + C) again."); // Perform a safe shutdown TShock.Utils.StopServer(true, "Server console interrupted!");