diff --git a/Player/Undo/UndoFile.cs b/Player/Undo/UndoFile.cs index 84772b506..9f998ee9d 100644 --- a/Player/Undo/UndoFile.cs +++ b/Player/Undo/UndoFile.cs @@ -58,8 +58,8 @@ namespace MCGalaxy.Util { Directory.CreateDirectory(playerDir); int numFiles = Directory.GetFiles(playerDir).Length; - string path = Path.Combine(playerDir, numFiles + BinFormat.Extension); - BinFormat.SaveUndoData(p.UndoBuffer, path); + string path = Path.Combine(playerDir, numFiles + NewFormat.Extension); + NewFormat.SaveUndoData(p.UndoBuffer, path); } public static void UndoPlayer(Player p, string target, Vec3U16[] marks, DateTime start, ref bool FoundUser) { diff --git a/Player/Undo/UndoFileBin.cs b/Player/Undo/UndoFileBin.cs index 371ec0829..3940c9b2e 100644 --- a/Player/Undo/UndoFileBin.cs +++ b/Player/Undo/UndoFileBin.cs @@ -18,7 +18,6 @@ using System; using System.Collections.Generic; using System.IO; -using System.Linq; using System.Text; using MCGalaxy.Drawing; @@ -30,66 +29,11 @@ namespace MCGalaxy.Util { const int entrySize = 12; protected override void SaveUndoData(List buffer, string path) { - using (FileStream fs = File.Create(path)) { - BinaryWriter w = new BinaryWriter(fs); - long entriesPos = 0; - ChunkHeader last = default(ChunkHeader); - - foreach (Player.UndoPos uP in buffer) { - DateTime time = Server.StartTime.AddSeconds(uP.timeDelta); - int timeDiff = (int)(time - last.BaseTime).TotalSeconds; - if (last.LevelName != uP.mapName || timeDiff > 65535 || last.Entries == ushort.MaxValue) { - WriteChunkEntries(w, last.Entries, entriesPos); - last = WriteEmptyChunk(w, uP.mapName, time, ref entriesPos); - } - - w.Write((ushort)timeDiff); - w.Write(uP.x); w.Write(uP.y); w.Write(uP.z); - w.Write(uP.type); w.Write(uP.extType); - w.Write(uP.newtype); w.Write(uP.newExtType); - last.Entries++; - } - if (last.Entries > 0) - WriteChunkEntries(w, last.Entries, entriesPos); - } + throw new NotSupportedException("Non-optimised binary undo files have been deprecated"); } protected override void SaveUndoData(UndoCache buffer, string path) { - using (FileStream fs = File.Create(path)) { - BinaryWriter w = new BinaryWriter(fs); - long entriesPos = 0; - ChunkHeader last = default(ChunkHeader); - UndoCacheNode node = buffer.Tail; - - while (node != null) { - List items = node.Items; - for (int i = 0; i < items.Count; i++) { - UndoCacheItem uP = items[i]; - DateTime time = node.BaseTime.AddSeconds(uP.TimeDelta); - int timeDiff = (int)(time - last.BaseTime).TotalSeconds; - if (last.LevelName != node.MapName || timeDiff > 65535 || last.Entries == ushort.MaxValue) { - WriteChunkEntries(w, last.Entries, entriesPos); - last = WriteEmptyChunk(w, node.MapName, time, ref entriesPos); - } - - ushort x, y, z; - node.Unpack(uP.Index, out x, out y, out z); - byte tile = 0, extTile = 0; - uP.GetExtBlock(out tile, out extTile); - byte newTile = 0, newExtTile = 0; - uP.GetNewExtBlock(out newTile, out newExtTile); - - w.Write((ushort)timeDiff); - w.Write(x); w.Write(y); w.Write(z); - w.Write(tile); w.Write(extTile); - w.Write(newTile); w.Write(newExtTile); - last.Entries++; - } - if (last.Entries > 0) - WriteChunkEntries(w, last.Entries, entriesPos); - node = node.Prev; - } - } + throw new NotSupportedException("Non-optimised binary undo files have been deprecated"); } protected override void ReadUndoData(List buffer, string path) { diff --git a/Player/Undo/UndoFileCBin.cs b/Player/Undo/UndoFileCBin.cs index 01e50a561..49df1333b 100644 --- a/Player/Undo/UndoFileCBin.cs +++ b/Player/Undo/UndoFileCBin.cs @@ -18,7 +18,6 @@ using System; using System.Collections.Generic; using System.IO; -using System.Linq; using System.Text; using MCGalaxy.Drawing; using MCGalaxy.Levels.IO; @@ -46,7 +45,7 @@ namespace MCGalaxy.Util { if (!LevelInfo.ExistsOffline(uP.mapName)) { if (uP.mapName != lastLoggedName) { lastLoggedName = uP.mapName; - Server.s.Log("Missing map file\"" + lastLoggedName+ "\", skipping undo entries"); + Server.s.Log("Missing map file \"" + lastLoggedName+ "\", skipping undo entries"); } continue; } @@ -169,7 +168,7 @@ namespace MCGalaxy.Util { DateTime time = chunk.BaseTime.AddTicks((item.Flags & 0x3FFF) * TimeSpan.TicksPerSecond); if (time < start) { buffer.CheckIfSend(true); return false; } - int index = NetUtils.ReadI32(temp, offset + 2); + int index = I32(temp, offset + 2); Pos.x = (ushort)(index % chunk.Width); Pos.y = (ushort)((index / chunk.Width) / chunk.Length); Pos.z = (ushort)((index / chunk.Width) % chunk.Length); @@ -213,7 +212,7 @@ namespace MCGalaxy.Util { DateTime time = chunk.BaseTime.AddTicks((flags & 0x3FFF) * TimeSpan.TicksPerSecond); if (time < start) return false; - int index = NetUtils.ReadI32(temp, offset + 2); + int index = I32(temp, offset + 2); ushort x = (ushort)(index % chunk.Width); ushort y = (ushort)((index / chunk.Width) / chunk.Length); ushort z = (ushort)((index / chunk.Width) % chunk.Length); @@ -228,6 +227,11 @@ namespace MCGalaxy.Util { return (ushort)(buffer[offset + 0] | buffer[offset + 1] << 8); } + static int I32(byte[] buffer, int offset) { + return buffer[offset + 0] | buffer[offset + 1] << 8 | + buffer[offset + 2] << 16 | buffer[offset + 3] << 24; + } + static bool CheckChunk(ChunkHeader chunk, DateTime start, Player p, out Level lvl) { DateTime time = chunk.BaseTime; lvl = null; diff --git a/Player/Undo/UndoFileText.cs b/Player/Undo/UndoFileText.cs index 151c27fb5..d671bb554 100644 --- a/Player/Undo/UndoFileText.cs +++ b/Player/Undo/UndoFileText.cs @@ -19,7 +19,6 @@ using System; using System.Collections.Generic; using System.Globalization; using System.IO; -using System.Linq; using MCGalaxy.Drawing; namespace MCGalaxy.Util { @@ -29,19 +28,11 @@ namespace MCGalaxy.Util { protected override string Extension { get { return ".undo"; } } protected override void SaveUndoData(List buffer, string path) { - using (StreamWriter w = File.CreateText(path)) { - foreach (Player.UndoPos uP in buffer) { - DateTime time = Server.StartTimeLocal.AddSeconds(uP.timeDelta); - w.Write( - uP.mapName + " " + uP.x + " " + uP.y + " " + uP.z + " " + - time.ToString(CultureInfo.InvariantCulture).Replace(' ', '&') + " " + - uP.type + " " + uP.newtype + " "); - } - } + throw new NotSupportedException("Text undo files have been deprecated"); } protected override void SaveUndoData(UndoCache buffer, string path) { - throw new NotImplementedException("The .txt based undo files are deprecated."); + throw new NotSupportedException("Text undo files have been deprecated"); } protected override void ReadUndoData(List buffer, string path) {