Makes server save in background, stops server lag on save

Keeping lag broadcast just in case
This commit is contained in:
Twitchy 2011-07-03 18:27:57 +12:00 committed by Steven French
parent 473d554de1
commit 058ae345d0
3 changed files with 18 additions and 7 deletions

View file

@ -67,11 +67,9 @@ namespace TShockAPI
if (worldpath != null && !Directory.Exists(worldpath)) if (worldpath != null && !Directory.Exists(worldpath))
Directory.CreateDirectory(worldpath); Directory.CreateDirectory(worldpath);
//Tools.Broadcast("Server map saving, potential lag spike"); Tools.Broadcast("Server map saving, potential lag spike");
WorldGen.saveWorld(); Thread SaveWorld = new Thread(Tools.SaveWorld);
SaveWorld.Start();
Console.WriteLine("World backed up");
Log.Info(string.Format("World backed up ({0})", Main.worldPathName));
Main.worldPathName = worldname; Main.worldPathName = worldname;
} }

View file

@ -23,6 +23,7 @@ using System.Diagnostics;
using System.IO; using System.IO;
using System.Net; using System.Net;
using System.Reflection; using System.Reflection;
using System.Threading;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Content;
using Terraria; using Terraria;
@ -543,8 +544,8 @@ namespace TShockAPI
{ {
WorldSaving = true; WorldSaving = true;
Tools.Broadcast("Saving world, might lag.", Color.Red); Tools.Broadcast("Saving world, might lag.", Color.Red);
WorldGen.saveWorld(resettime); Thread SaveWorld = new Thread(Tools.SaveWorld);
Tools.Broadcast("World saved.", Color.LimeGreen); SaveWorld.Start();
WorldSaving = false; WorldSaving = false;
e.Handled = true; e.Handled = true;
} }

View file

@ -101,6 +101,18 @@ namespace TShockAPI
return result; return result;
} }
/// <summary>
/// Saves the map data
/// </summary>
public static void SaveWorld()
{
WorldGen.saveWorld();
Broadcast("World Saved", Color.Yellow);
Console.WriteLine("World backed up");
Log.Info(string.Format("World backed up ({0})", Main.worldPathName));
}
/// <summary> /// <summary>
/// Broadcasts a message to all players /// Broadcasts a message to all players
/// </summary> /// </summary>