/// <summary>Reveal one card's identity</summary>
/// <param name="card">The card, whose identity is revealed</param>
/// <param name="revealed">Either the salted CardIdentity id (in the case of an alias), or the salted, condensed Card GUID.</param>
/// <param name="guid"> </param>
public void Reveal(Card card, ulong revealed, Guid guid)
{
// Save old id
CardIdentity oldType = card.Type;
// Check if the card is rightfully revealed
if (!card.Type.Revealing)
Program.Trace.TraceEvent(TraceEventType.Warning, EventIds.Event, "Someone tries to reveal a card which is not visible to everybody.");
// Check if we can trust other clients
if (!card.Type.MySecret)
{
if (guid != Guid.Empty && (uint)revealed != guid.Condense())
Program.Trace.TraceEvent(TraceEventType.Warning, EventIds.Event, "[Reveal] Alias and id aren't the same. One client is buggy or tries to cheat.");
if (Crypto.ModExp(revealed) != card.Type.Key)
Program.Trace.TraceEvent(TraceEventType.Warning, EventIds.Event, "[Reveal] Card identity doesn't match. One client is buggy or tries to cheat.");
}
else
card.Type.MySecret = false;
// Reveal an alias
if (guid == Guid.Empty)
{
// Find the new type
CardIdentity newId = CardIdentity.Find((int)revealed);
// HACK: it is unclear to me how the CardIdentity could not be found and newId ends up null
// see this bug report: https://octgn.16bugs.com/projects/3602/bugs/192070
// for now I'm just doing nothing (supposing that it means the type was already revealed).
if (newId == null) { card.Reveal(); return; }
// Possibly copy the model, if it was known and isn't anymore
// (possible when the alias has beeen locally revealed)
if (newId.Model == null) newId.Model = card.Type.Model;
// Set the new type
card.Type = newId;
// Delete the old identity
CardIdentity.Delete(oldType.Id);
// Possibly reveal the alias further
card.Reveal();
// Raise a notification
oldType.OnRevealed(newId);
}
// Reveal a card's type
else if (card.Type.Model == null)
{
card.SetModel(Program.GameEngine.Definition.GetCardById(guid));
// Raise a notification
oldType.OnRevealed(oldType);
}
}