diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs
index 707d9008..1bbb7052 100755
--- a/TShockAPI/TShock.cs
+++ b/TShockAPI/TShock.cs
@@ -72,6 +72,9 @@ namespace TShockAPI
///
internal static bool NoRestart;
+ /// Will be set to true once Utils.StopServer() is called.
+ public static bool ShuttingDown;
+
/// Players - Contains all TSPlayer objects for accessing TSPlayers currently on the server
public static TSPlayer[] Players = new TSPlayer[Main.maxPlayers];
/// Bans - Static reference to the ban manager for accessing bans & related functions.
@@ -1200,6 +1203,13 @@ namespace TShockAPI
/// args - The ConnectEventArgs object.
private void OnConnect(ConnectEventArgs args)
{
+ if (ShuttingDown)
+ {
+ NetMessage.SendData((int)PacketTypes.Disconnect, args.Who, -1, "Server is shutting down...");
+ args.Handled = true;
+ return;
+ }
+
var player = new TSPlayer(args.Who);
if (Utils.ActivePlayers() + 1 > Config.MaxSlots + Config.ReservedSlots)
diff --git a/TShockAPI/Utils.cs b/TShockAPI/Utils.cs
index b26e22ae..d596f054 100644
--- a/TShockAPI/Utils.cs
+++ b/TShockAPI/Utils.cs
@@ -538,6 +538,8 @@ namespace TShockAPI
/// string reason (default: "Server shutting down!")
public void StopServer(bool save = true, string reason = "Server shutting down!")
{
+ TShock.ShuttingDown = true;
+
ForceKickAll(reason);
if (save)
SaveManager.Instance.SaveWorld();