Hashing now supports xp. Simply append "-xp" to the algorithm name.

Fixed kicking for mana over 200, max mana was raised to 400 in 1.0.6.
This commit is contained in:
high 2011-08-10 05:25:17 -04:00
parent 923358a4b2
commit 2a0bf9036a
4 changed files with 30 additions and 34 deletions

View file

@ -107,7 +107,7 @@ namespace TShockAPI
public bool DisableSpewLogs = true;
/// <summary>
/// Valid types are "sha512", "sha256", "md5"
/// Valid types are "sha512", "sha256", "md5", append with "-xp" for the xp supported algorithms
/// </summary>
public string HashAlgorithm = "sha512";

View file

@ -36,5 +36,5 @@ using System.Runtime.InteropServices;
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("3.2.4.0809")]
[assembly: AssemblyFileVersion("3.2.4.0809")]
[assembly: AssemblyVersion("3.2.5.0810")]
[assembly: AssemblyFileVersion("3.2.5.0810")]

View file

@ -448,7 +448,7 @@ namespace TShockAPI
private void OnChat(messageBuffer msg, int ply, string text, HandledEventArgs e)
{
if (e.Handled)
if (e.Handled)
return;
var tsplr = Players[msg.whoAmI];
@ -560,7 +560,7 @@ namespace TShockAPI
private void GetData(GetDataEventArgs e)
{
if (e.Handled)
if (e.Handled)
return;
PacketTypes type = e.MsgID;
@ -732,8 +732,8 @@ namespace TShockAPI
public static bool HackedHealth(TSPlayer player)
{
return (player.TPlayer.statManaMax > 200) ||
(player.TPlayer.statMana > 200) ||
return (player.TPlayer.statManaMax > 400) ||
(player.TPlayer.statMana > 400) ||
(player.TPlayer.statLifeMax > 400) ||
(player.TPlayer.statLife > 400);
}
@ -759,22 +759,7 @@ namespace TShockAPI
RconHandler.Password = file.RconPassword;
RconHandler.ListenPort = file.RconPort;
Type hash;
if (Tools.HashTypes.TryGetValue(file.HashAlgorithm, out hash))
{
lock (Tools.HashAlgo)
{
if (!Tools.HashAlgo.GetType().Equals(hash))
{
Tools.HashAlgo.Dispose();
Tools.HashAlgo = (HashAlgorithm)Activator.CreateInstance(Tools.HashTypes[file.HashAlgorithm]);
}
}
}
else
{
Log.ConsoleError("Invalid or not supported hashing algorithm: " + file.HashAlgorithm);
}
Tools.HashAlgo = file.HashAlgorithm;
}
}
}

View file

@ -438,15 +438,15 @@ namespace TShockAPI
{
string possibleColor = foo.Substring(0, 13);
foo = foo.Remove(0, 13);
float[] pC = {0, 0, 0};
float[] pC = { 0, 0, 0 };
possibleColor = possibleColor.Replace("%", "");
string[] pCc = possibleColor.Split(',');
if (pCc.Length == 3)
{
try
{
player.SendMessage(foo, (byte) Convert.ToInt32(pCc[0]), (byte) Convert.ToInt32(pCc[1]),
(byte) Convert.ToInt32(pCc[2]));
player.SendMessage(foo, (byte)Convert.ToInt32(pCc[0]), (byte)Convert.ToInt32(pCc[1]),
(byte)Convert.ToInt32(pCc[2]));
continue;
}
catch (Exception e)
@ -489,13 +489,16 @@ namespace TShockAPI
return ip != null ? ip.ToString() : "";
}
public static HashAlgorithm HashAlgo = new MD5Cng();
public static string HashAlgo = "md5";
public static readonly Dictionary<string, Type> HashTypes = new Dictionary<string, Type>
{
{"sha512", typeof(SHA512Managed)},
{"sha256", typeof(SHA256Managed)},
{"md5", typeof(MD5Cng)},
public static readonly Dictionary<string, Func<HashAlgorithm>> HashTypes = new Dictionary<string, Func<HashAlgorithm>>
{
{"sha512", () => new SHA512Managed()},
{"sha256", () => new SHA256Managed()},
{"md5", () => new MD5Cng()},
{"sha512-xp", () => SHA512.Create()},
{"sha256-xp", () => SHA256.Create()},
{"md5-xp", () => MD5.Create()},
};
/// <summary>
@ -507,8 +510,16 @@ namespace TShockAPI
{
if (string.IsNullOrEmpty(password) || password == "non-existant password")
return "non-existant password";
var bytes = HashAlgo.ComputeHash(Encoding.ASCII.GetBytes(password));
return bytes.Aggregate("", (s, b) => s + b.ToString("X2"));
Func<HashAlgorithm> func;
if (!HashTypes.TryGetValue(HashAlgo.ToLower(), out func))
throw new NotSupportedException("Hashing algorithm {0} is not supported".SFormat(HashAlgo.ToLower()));
using (var hash = func())
{
var bytes = hash.ComputeHash(Encoding.ASCII.GetBytes(password));
return bytes.Aggregate("", (s, b) => s + b.ToString("X2"));
}
}
/// <summary>