diff --git a/MCGalaxy/Database/Undo/UndoFormat.Helpers.cs b/MCGalaxy/Database/Undo/UndoFormat.Helpers.cs
deleted file mode 100644
index dc012dc60..000000000
--- a/MCGalaxy/Database/Undo/UndoFormat.Helpers.cs
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- Copyright 2015 MCGalaxy
-
- Dual-licensed under the Educational Community License, Version 2.0 and
- the GNU General Public License, Version 3 (the "Licenses"); you may
- not use this file except in compliance with the Licenses. You may
- obtain a copy of the Licenses at
-
- http://www.opensource.org/licenses/ecl2.php
- http://www.gnu.org/licenses/gpl-3.0.html
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the Licenses are distributed on an "AS IS"
- BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
- or implied. See the Licenses for the specific language governing
- permissions and limitations under the Licenses.
- */
-using System;
-using System.Collections.Generic;
-using System.IO;
-using MCGalaxy.Maths;
-
-namespace MCGalaxy.Undo {
-
- /// Retrieves and saves undo data in a particular format.
- /// Note most formats only support retrieving undo data.
- public abstract partial class UndoFormat {
-
- public static void DoUndo(string target, ref bool found, UndoFormatArgs args) {
- List files = GetUndoFiles(target);
- if (files.Count == 0) return;
- found = true;
-
- foreach (string file in files) {
- using (Stream s = File.OpenRead(file)) {
- DoUndo(s, GetFormat(file), args);
- if (args.Stop) break;
- }
- }
- }
-
- static void DoUndo(Stream s, UndoFormat format, UndoFormatArgs args) {
- Level lvl = args.Player == null ? null : args.Player.level;
- string lastMap = null;
- Vec3S32 min = args.Min, max = args.Max;
- DrawOpBlock block;
-
- foreach (UndoFormatEntry P in format.GetEntries(s, args)) {
- if (P.LevelName != lastMap) lvl = LevelInfo.FindExact(P.LevelName);
- if (lvl == null || P.Time > args.End) continue;
- if (P.X < min.X || P.Y < min.Y || P.Z < min.Z) continue;
- if (P.X > max.X || P.Y > max.Y || P.Z > max.Z) continue;
-
- byte lvlBlock = lvl.GetTile(P.X, P.Y, P.Z);
- if (lvlBlock == P.NewBlock.BlockID || Block.Convert(lvlBlock) == Block.water
- || Block.Convert(lvlBlock) == Block.lava || lvlBlock == Block.grass) {
-
- block.X = P.X; block.Y = P.Y; block.Z = P.Z;
- block.Block = P.Block;
- args.Output(block);
- }
- }
- }
-
-
- public static void DoHighlight(string target, ref bool found, UndoFormatArgs args) {
- List files = GetUndoFiles(target);
- if (files.Count == 0) return;
- found = true;
-
- foreach (string file in files) {
- using (Stream s = File.OpenRead(file)) {
- DoHighlight(s, GetFormat(file), args);
- if (args.Stop) break;
- }
- }
- }
-
- static void DoHighlight(Stream s, UndoFormat format, UndoFormatArgs args) {
- Level lvl = args.Player.level;
- Vec3S32 min = args.Min, max = args.Max;
- DrawOpBlock block;
-
- foreach (UndoFormatEntry P in format.GetEntries(s, args)) {
- ExtBlock old = P.Block, newBlock = P.NewBlock;
- if (P.X < min.X || P.Y < min.Y || P.Z < min.Z) continue;
- if (P.X > max.X || P.Y > max.Y || P.Z > max.Z) continue;
-
- block.Block = (newBlock.BlockID == Block.air
- || Block.Convert(old.BlockID) == Block.water || old.BlockID == Block.waterstill
- || Block.Convert(old.BlockID) == Block.lava || old.BlockID == Block.lavastill)
- ? args.DeleteHighlight : args.PlaceHighlight;
-
- block.X = P.X; block.Y = P.Y; block.Z = P.Z;
- args.Output(block);
- }
- }
- }
-}
\ No newline at end of file
diff --git a/MCGalaxy/Database/Undo/UndoFormat.cs b/MCGalaxy/Database/Undo/UndoFormat.cs
index 1c55e5b58..a4754cc82 100644
--- a/MCGalaxy/Database/Undo/UndoFormat.cs
+++ b/MCGalaxy/Database/Undo/UndoFormat.cs
@@ -38,7 +38,7 @@ namespace MCGalaxy.Undo {
public static UndoFormat NewFormat = new UndoFormatCBin();
/// Enumerates through all the entries in the undo file.
- protected abstract IEnumerable GetEntries(Stream s, UndoFormatArgs args);
+ public abstract IEnumerable GetEntries(Stream s, UndoFormatArgs args);
/// File extension of undo files in this format.
protected abstract string Ext { get; }
@@ -81,7 +81,7 @@ namespace MCGalaxy.Undo {
return files;
}
- static UndoFormat GetFormat(string file) {
+ public static UndoFormat GetFormat(string file) {
if (file.EndsWith(TxtFormat.Ext)) return TxtFormat;
if (file.EndsWith(BinFormat.Ext)) return BinFormat;
if (file.EndsWith(NewFormat.Ext)) return NewFormat;
@@ -110,36 +110,13 @@ namespace MCGalaxy.Undo {
/// Whether the format has finished retrieving undo data,
/// due to finding an entry before the start range.
- public bool Stop;
-
- /// Block to highlight placements with.
- public ExtBlock PlaceHighlight = (ExtBlock)Block.green;
-
- /// Block to highlight deletions with.
- public ExtBlock DeleteHighlight = (ExtBlock)Block.red;
-
+ public bool Stop;
/// First instance in time that undo data should be retrieved back to.
internal readonly DateTime Start;
- /// Last instance in time that undo data should be retrieved up to.
- internal readonly DateTime End;
-
- /// Minimum coordinate of region to process blocks within.
- internal readonly Vec3S32 Min;
-
- /// Minimum coordinate of region to process blocks within.
- internal readonly Vec3S32 Max;
-
- /// Action invoked for each block processed.
- internal Action Output;
-
- public UndoFormatArgs(Player p, DateTime start, DateTime end,
- Vec3S32 min, Vec3S32 max, Action output) {
- Player = p;
- Start = start; End = end;
- Min = min; Max = max;
- Output = output;
+ public UndoFormatArgs(Player p, DateTime start) {
+ Player = p; Start = start;
}
}
diff --git a/MCGalaxy/Database/Undo/UndoFormatBin.cs b/MCGalaxy/Database/Undo/UndoFormatBin.cs
index 8bffa3d8b..838cb6f1b 100644
--- a/MCGalaxy/Database/Undo/UndoFormatBin.cs
+++ b/MCGalaxy/Database/Undo/UndoFormatBin.cs
@@ -28,7 +28,7 @@ namespace MCGalaxy.Undo {
protected override string Ext { get { return ".unbin"; } }
const int entrySize = 12;
- protected override IEnumerable GetEntries(Stream s, UndoFormatArgs args) {
+ public override IEnumerable GetEntries(Stream s, UndoFormatArgs args) {
List list = new List();
UndoFormatEntry pos;
bool super = Player.IsSuper(args.Player);
diff --git a/MCGalaxy/Database/Undo/UndoFormatCBin.cs b/MCGalaxy/Database/Undo/UndoFormatCBin.cs
index 9c7f55e90..052f6bd80 100644
--- a/MCGalaxy/Database/Undo/UndoFormatCBin.cs
+++ b/MCGalaxy/Database/Undo/UndoFormatCBin.cs
@@ -28,7 +28,7 @@ namespace MCGalaxy.Undo {
protected override string Ext { get { return ".uncbin"; } }
const int entrySize = 8;
- protected override IEnumerable GetEntries(Stream s, UndoFormatArgs args) {
+ public override IEnumerable GetEntries(Stream s, UndoFormatArgs args) {
List list = new List();
UndoFormatEntry pos;
bool super = Player.IsSuper(args.Player);
diff --git a/MCGalaxy/Database/Undo/UndoFormatText.cs b/MCGalaxy/Database/Undo/UndoFormatText.cs
index 5021bf850..8469e7a12 100644
--- a/MCGalaxy/Database/Undo/UndoFormatText.cs
+++ b/MCGalaxy/Database/Undo/UndoFormatText.cs
@@ -27,7 +27,7 @@ namespace MCGalaxy.Undo {
protected override string Ext { get { return ".undo"; } }
- protected override IEnumerable GetEntries(Stream s, UndoFormatArgs args) {
+ public override IEnumerable GetEntries(Stream s, UndoFormatArgs args) {
UndoFormatEntry pos = default(UndoFormatEntry);
string[] lines = new StreamReader(s).ReadToEnd().SplitSpaces();
Player p = args.Player;
diff --git a/MCGalaxy/Drawing/DrawOps/HighlightDrawOp.cs b/MCGalaxy/Drawing/DrawOps/HighlightDrawOp.cs
index d9ea80293..55b572d02 100644
--- a/MCGalaxy/Drawing/DrawOps/HighlightDrawOp.cs
+++ b/MCGalaxy/Drawing/DrawOps/HighlightDrawOp.cs
@@ -16,6 +16,8 @@
permissions and limitations under the Licenses.
*/
using System;
+using System.Collections.Generic;
+using System.IO;
using MCGalaxy.DB;
using MCGalaxy.Drawing.Brushes;
using MCGalaxy.Maths;
@@ -65,10 +67,8 @@ namespace MCGalaxy.Drawing.Ops {
}
}
- UndoFormatArgs args = new UndoFormatArgs(Player, Start, DateTime.MaxValue, Min, Max, output);
- args.PlaceHighlight = PlaceHighlight;
- args.DeleteHighlight = DeleteHighlight;
- UndoFormat.DoHighlight(who.ToLower(), ref found, args);
+ UndoFormatArgs args = new UndoFormatArgs(Player, Start);
+ DoOldHighlight(args);
}
Action output;
@@ -93,5 +93,37 @@ namespace MCGalaxy.Drawing.Ops {
output(Place((ushort)x, (ushort)y, (ushort)z, highlight));
found = true;
}
+
+
+ void DoOldHighlight(UndoFormatArgs args) {
+ List files = UndoFormat.GetUndoFiles(who.ToLower());
+ if (files.Count == 0) return;
+ found = true;
+
+ foreach (string file in files) {
+ using (Stream s = File.OpenRead(file)) {
+ DoOldHighlight(s, UndoFormat.GetFormat(file), args);
+ if (args.Stop) break;
+ }
+ }
+ }
+
+ void DoOldHighlight(Stream s, UndoFormat format, UndoFormatArgs args) {
+ DrawOpBlock block;
+
+ foreach (UndoFormatEntry P in format.GetEntries(s, args)) {
+ ExtBlock old = P.Block, newBlock = P.NewBlock;
+ if (P.X < Min.X || P.Y < Min.Y || P.Z < Min.Z) continue;
+ if (P.X > Max.X || P.Y > Max.Y || P.Z > Max.Z) continue;
+
+ block.Block = (newBlock.BlockID == Block.air
+ || Block.Convert(old.BlockID) == Block.water || old.BlockID == Block.waterstill
+ || Block.Convert(old.BlockID) == Block.lava || old.BlockID == Block.lavastill)
+ ? DeleteHighlight : PlaceHighlight;
+
+ block.X = P.X; block.Y = P.Y; block.Z = P.Z;
+ output(block);
+ }
+ }
}
}
diff --git a/MCGalaxy/Drawing/DrawOps/UndoDrawOp.cs b/MCGalaxy/Drawing/DrawOps/UndoDrawOp.cs
index 65a2c7ab8..26707eb62 100644
--- a/MCGalaxy/Drawing/DrawOps/UndoDrawOp.cs
+++ b/MCGalaxy/Drawing/DrawOps/UndoDrawOp.cs
@@ -16,11 +16,12 @@
permissions and limitations under the Licenses.
*/
using System;
-using MCGalaxy.Blocks.Physics;
+using System.Collections.Generic;
+using System.IO;
using MCGalaxy.DB;
using MCGalaxy.Drawing.Brushes;
+using MCGalaxy.Maths;
using MCGalaxy.Undo;
-using MCGalaxy.Maths;
namespace MCGalaxy.Drawing.Ops {
@@ -69,9 +70,9 @@ namespace MCGalaxy.Drawing.Ops {
if (BlockDBReadLock != null) BlockDBReadLock.Dispose();
}
}
-
- UndoFormatArgs args = new UndoFormatArgs(Player, Start, End, Min, Max, output);
- UndoFormat.DoUndo(who.ToLower(), ref found, args);
+
+ UndoFormatArgs args = new UndoFormatArgs(Player, Start);
+ DoOldUndo(args);
}
Action output;
@@ -90,57 +91,41 @@ namespace MCGalaxy.Drawing.Ops {
output(Place((ushort)x, (ushort)y, (ushort)z, block));
found = true;
}
- }
-
- public class UndoPhysicsDrawOp : DrawOp {
- public override string Name { get { return "UndoPhysics"; } }
- public override bool AffectedByTransform { get { return false; } }
- internal DateTime Start;
- public override long BlocksAffected(Level lvl, Vec3S32[] marks) { return -1; }
-
- public override void Perform(Vec3S32[] marks, Brush brush, Action output) {
- if (Level.UndoBuffer.Count != Server.physUndo) {
- int count = Level.currentUndo;
- for (int i = count; i >= 0; i--) {
- try {
- if (!CheckBlockPhysics(Player, Level, i)) break;
- } catch { }
- }
- } else {
- int count = Level.currentUndo;
- for (int i = count; i >= 0; i--) {
- try {
- if (!CheckBlockPhysics(Player, Level, i)) break;
- } catch { }
- }
- for (int i = Level.UndoBuffer.Count - 1; i > count; i--) {
- try {
- if (!CheckBlockPhysics(Player, Level, i)) break;
- } catch { }
+ void DoOldUndo(UndoFormatArgs args) {
+ List files = UndoFormat.GetUndoFiles(who.ToLower());
+ if (files.Count == 0) return;
+ found = true;
+
+ foreach (string file in files) {
+ using (Stream s = File.OpenRead(file)) {
+ DoOldUndo(s, UndoFormat.GetFormat(file), args);
+ if (args.Stop) break;
}
}
}
- bool CheckBlockPhysics(Player p, Level lvl, int i) {
- Level.UndoPos undo = lvl.UndoBuffer[i];
- byte b = lvl.GetTile(undo.index);
- DateTime time = Server.StartTime.AddTicks((undo.flags >> 2) * TimeSpan.TicksPerSecond);
- if (time < Start) return false;
+ void DoOldUndo(Stream s, UndoFormat format, UndoFormatArgs args) {
+ Level lvl = args.Player == null ? null : args.Player.level;
+ string lastMap = null;
+ DrawOpBlock block;
- byte newType = (undo.flags & 2) != 0 ? Block.custom_block : undo.newRaw;
- if (b == newType || Block.Convert(b) == Block.water || Block.Convert(b) == Block.lava) {
- ushort x, y, z;
- lvl.IntToPos(undo.index, out x, out y, out z);
- int undoIndex = lvl.currentUndo;
- lvl.currentUndo = i;
- lvl.currentUndo = undoIndex;
+ foreach (UndoFormatEntry P in format.GetEntries(s, args)) {
+ if (P.LevelName != lastMap) lvl = LevelInfo.FindExact(P.LevelName);
+ if (lvl == null || P.Time > End) continue;
+ if (P.X < Min.X || P.Y < Min.Y || P.Z < Min.Z) continue;
+ if (P.X > Max.X || P.Y > Max.Y || P.Z > Max.Z) continue;
- ExtBlock oldBlock = ExtBlock.FromRaw(undo.oldRaw, (undo.flags & 1) != 0);
- lvl.Blockchange(x, y, z, oldBlock, true, default(PhysicsArgs), false);
+ byte lvlBlock = lvl.GetTile(P.X, P.Y, P.Z);
+ if (lvlBlock == P.NewBlock.BlockID || Block.Convert(lvlBlock) == Block.water
+ || Block.Convert(lvlBlock) == Block.lava || lvlBlock == Block.grass) {
+
+ block.X = P.X; block.Y = P.Y; block.Z = P.Z;
+ block.Block = P.Block;
+ output(block);
+ }
}
- return true;
}
}
}
diff --git a/MCGalaxy/Drawing/DrawOps/UndoPhysicsDrawOp.cs b/MCGalaxy/Drawing/DrawOps/UndoPhysicsDrawOp.cs
new file mode 100644
index 000000000..b4365012c
--- /dev/null
+++ b/MCGalaxy/Drawing/DrawOps/UndoPhysicsDrawOp.cs
@@ -0,0 +1,76 @@
+/*
+ Copyright 2015 MCGalaxy
+
+ Dual-licensed under the Educational Community License, Version 2.0 and
+ the GNU General Public License, Version 3 (the "Licenses"); you may
+ not use this file except in compliance with the Licenses. You may
+ obtain a copy of the Licenses at
+
+ http://www.opensource.org/licenses/ecl2.php
+ http://www.gnu.org/licenses/gpl-3.0.html
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the Licenses are distributed on an "AS IS"
+ BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ or implied. See the Licenses for the specific language governing
+ permissions and limitations under the Licenses.
+ */
+using System;
+using MCGalaxy.Blocks.Physics;
+using MCGalaxy.Drawing.Brushes;
+using MCGalaxy.Maths;
+
+namespace MCGalaxy.Drawing.Ops {
+
+ public class UndoPhysicsDrawOp : DrawOp {
+ public override string Name { get { return "UndoPhysics"; } }
+ public override bool AffectedByTransform { get { return false; } }
+
+ internal DateTime Start;
+
+ public override long BlocksAffected(Level lvl, Vec3S32[] marks) { return -1; }
+
+ public override void Perform(Vec3S32[] marks, Brush brush, Action output) {
+ if (Level.UndoBuffer.Count != Server.physUndo) {
+ int count = Level.currentUndo;
+ for (int i = count; i >= 0; i--) {
+ try {
+ if (!CheckBlockPhysics(Player, Level, i)) break;
+ } catch { }
+ }
+ } else {
+ int count = Level.currentUndo;
+ for (int i = count; i >= 0; i--) {
+ try {
+ if (!CheckBlockPhysics(Player, Level, i)) break;
+ } catch { }
+ }
+ for (int i = Level.UndoBuffer.Count - 1; i > count; i--) {
+ try {
+ if (!CheckBlockPhysics(Player, Level, i)) break;
+ } catch { }
+ }
+ }
+ }
+
+ bool CheckBlockPhysics(Player p, Level lvl, int i) {
+ Level.UndoPos undo = lvl.UndoBuffer[i];
+ byte b = lvl.GetTile(undo.index);
+ DateTime time = Server.StartTime.AddTicks((undo.flags >> 2) * TimeSpan.TicksPerSecond);
+ if (time < Start) return false;
+
+ byte newType = (undo.flags & 2) != 0 ? Block.custom_block : undo.newRaw;
+ if (b == newType || Block.Convert(b) == Block.water || Block.Convert(b) == Block.lava) {
+ ushort x, y, z;
+ lvl.IntToPos(undo.index, out x, out y, out z);
+ int undoIndex = lvl.currentUndo;
+ lvl.currentUndo = i;
+ lvl.currentUndo = undoIndex;
+
+ ExtBlock oldBlock = ExtBlock.FromRaw(undo.oldRaw, (undo.flags & 1) != 0);
+ lvl.Blockchange(x, y, z, oldBlock, true, default(PhysicsArgs), false);
+ }
+ return true;
+ }
+ }
+}
diff --git a/MCGalaxy/MCGalaxy_.csproj b/MCGalaxy/MCGalaxy_.csproj
index 6589e1a37..cc0d43d91 100644
--- a/MCGalaxy/MCGalaxy_.csproj
+++ b/MCGalaxy/MCGalaxy_.csproj
@@ -451,6 +451,7 @@
+
@@ -586,7 +587,6 @@
-
@@ -652,7 +652,6 @@
-
diff --git a/MCGalaxy/sharkbite.thresher/Identd.cs b/MCGalaxy/sharkbite.thresher/Identd.cs
deleted file mode 100644
index 94cd7ac99..000000000
--- a/MCGalaxy/sharkbite.thresher/Identd.cs
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
- * Thresher IRC client library
- * Copyright (C) 2002 Aaron Hunter
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * See the gpl.txt file located in the top-level-directory of
- * the archive of this library for complete text of license.
-*/
-
-using System;
-using System.IO;
-using System.Net;
-using System.Net.Sockets;
-using System.Threading;
-using System.Diagnostics;
-
-
-namespace Sharkbite.Irc
-{
- ///
- /// An Ident daemon is still used by some IRC networks for
- /// authentication. It is a simple service which when queried
- /// by a remote system returns a username. The server is controlled via static
- /// methods all of which are Thread safe.
- ///
- public sealed class Identd
- {
- private static TcpListener listener;
- private static bool running;
- private static object lockObject;
- private static string username;
- private const string Reply = " : USERID : UNIX : ";
- private const int IdentdPort = 113;
-
- static Identd()
- {
- running = false;
- lockObject = new object();
- }
-
- //Declare constructor private so it cannot be instatiated.
- private Identd() {}
-
- ///
- /// The Identd server will start listening for queries
- /// in its own thread. It can be stopped by calling
- /// .
- ///
- /// Should be the same username as the one used
- /// in the ConnectionArgs object when establishing a connection.
- /// If the server has already been started.
- public static void Start( string userName )
- {
- lock( lockObject )
- {
- if( running )
- {
- throw new Exception("Identd already started.");
- }
- running = true;
- username = userName;
- Thread socketThread = new Thread( new ThreadStart( Identd.Run ) );
- socketThread.Name = "Identd";
- socketThread.Start();
- }
- }
- ///
- /// Check if the Identd server is running
- ///
- /// True if it is running
- public static bool IsRunning()
- {
- lock( lockObject )
- {
- return running;
- }
- }
- ///
- /// Stop the Identd server and close the thread.
- ///
- public static void Stop()
- {
- lock( lockObject )
- {
- if( running )
- {
- listener.Stop();
- Debug.WriteLineIf( Rfc2812Util.IrcTrace.TraceInfo,"[" + Thread.CurrentThread.Name +"] Identd::Stop()");
- listener = null;
- running = false;
- }
- }
- }
-
- private static void Run()
- {
- Debug.WriteLineIf( Rfc2812Util.IrcTrace.TraceInfo,"[" + Thread.CurrentThread.Name +"] Identd::Run()");
- try
- {
- listener = new TcpListener( IPAddress.Any, IdentdPort );
- listener.Start();
-
- while (true)
- {
- try
- {
- TcpClient client = listener.AcceptTcpClient();
- //Read query
- StreamReader reader = new StreamReader(client.GetStream() );
- string line = reader.ReadLine();
- Debug.WriteLineIf( Rfc2812Util.IrcTrace.TraceVerbose,"[" + Thread.CurrentThread.Name +"] Identd::Run() received=" + line);
-
- //Send back reply
- StreamWriter writer = new StreamWriter( client.GetStream() );
- writer.WriteLine( line.Trim() + Reply + username );
- writer.Flush();
-
- //Close connection with client
- client.Close();
- }
- catch( IOException ioe )
- {
- Debug.WriteLineIf( Rfc2812Util.IrcTrace.TraceWarning,"[" + Thread.CurrentThread.Name +"] Identd::Run() exception=" + ioe);
- }
- }
- }
- catch( Exception )
- {
- Debug.WriteLineIf( Rfc2812Util.IrcTrace.TraceInfo,"[" + Thread.CurrentThread.Name +"] Identd::Run() Identd stopped");
- }
- finally
- {
- running = false;
- }
- }
-
- }
-}