Content packages & MD5 hash comparison between client and server

This commit is contained in:
Regalis
2015-07-20 21:27:44 +03:00
parent 4aa3d9d7ee
commit 326b46cf18
45 changed files with 1217 additions and 158 deletions
+24 -13
View File
@@ -5,16 +5,16 @@ using System.Xml.Linq;
namespace Subsurface
{
class Md5Hash
public class Md5Hash
{
private string md5Hash;
private string hash;
private string shortHash;
public string MD5Hash
public string Hash
{
get
{
return md5Hash;
return hash;
}
}
@@ -28,30 +28,41 @@ namespace Subsurface
public Md5Hash(string md5Hash)
{
this.md5Hash = md5Hash;
this.hash = md5Hash;
shortHash = GetShortHash(md5Hash);
}
public Md5Hash(byte[] bytes)
{
hash = CalculateHash(bytes);
shortHash = GetShortHash(hash);
}
public Md5Hash(XDocument doc)
{
string docString = Regex.Replace(doc.ToString(), @"\s+", "");
// step 1, calculate MD5 hash from input
MD5 md5 = MD5.Create();
byte[] inputBytes = Encoding.ASCII.GetBytes(docString);
byte[] hash = md5.ComputeHash(inputBytes);
hash = CalculateHash(inputBytes);
shortHash = GetShortHash(hash);
}
private string CalculateHash(byte[] bytes)
{
MD5 md5 = MD5.Create();
byte[] byteHash = md5.ComputeHash(bytes);
// step 2, convert byte array to hex string
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hash.Length; i++)
for (int i = 0; i < byteHash.Length; i++)
{
sb.Append(hash[i].ToString("X2"));
sb.Append(byteHash[i].ToString("X2"));
}
md5Hash = sb.ToString();
shortHash = GetShortHash(md5Hash);
return sb.ToString();
}
private string GetShortHash(string fullHash)
+13 -9
View File
@@ -4,6 +4,7 @@ using System.Xml.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System.Collections.Generic;
namespace Subsurface
{
@@ -49,18 +50,21 @@ namespace Subsurface
get { return stairDirection; }
}
public static void LoadAll(string filePath)
{
XDocument doc = ToolBox.TryLoadXml(filePath);
if (doc == null) return;
public static void LoadAll(List<string> filePaths)
{
foreach (string filePath in filePaths)
{
XDocument doc = ToolBox.TryLoadXml(filePath);
if (doc == null) return;
foreach (XElement el in doc.Root.Elements())
{
StructurePrefab sp = Load(el);
foreach (XElement el in doc.Root.Elements())
{
StructurePrefab sp = Load(el);
Debug.WriteLine(sp.name);
Debug.WriteLine(sp.name);
list.Add(sp);
list.Add(sp);
}
}
}
+1 -1
View File
@@ -616,7 +616,7 @@ namespace Subsurface
}
hash = new Md5Hash(doc);
doc.Root.Add(new XAttribute("md5hash", hash.MD5Hash));
doc.Root.Add(new XAttribute("md5hash", hash.Hash));
try
{