VanguardReMaster/server/src/Vanguard.Rules/Replay/EventHasher.cs

33 lines
858 B
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Vanguard.Rules.Engine;
namespace Vanguard.Rules.Replay;
/// <summary>FNV-1a по тексту событий. Не криптография, а быстрая проверка расхождений.</summary>
public static class EventHasher
{
private const ulong Offset = 14695981039346656037UL;
private const ulong Prime = 1099511628211UL;
public static string Hash(IEnumerable<GameEvent> events)
{
unchecked
{
var hash = Offset;
foreach (var gameEvent in events)
{
foreach (var ch in gameEvent.ToString() ?? string.Empty)
{
hash ^= ch;
hash *= Prime;
}
hash ^= '\n';
hash *= Prime;
}
return hash.ToString("x16");
}
}
}