public bool TakeDamage(IProtection protection, IAttack attack, bool ActionCommandSuccessful) { //can be attacked by the 'hammer' (attack) bool successful = false; if (Attrs == null) { if (ActionCommandSuccessful) { successful = true; this.Health.TakeDamage(attack.Power + 1); } else { successful = true; this.Health.TakeDamage(attack.Power); } } else if (Array.TrueForAll(Attrs, attr => attr.CanAttack(protection, attack))) { if (ActionCommandSuccessful) { successful = true; this.Health.TakeDamage(attack.Power + 1); } else { successful = true; this.Health.TakeDamage(attack.Power); } } return(successful); }
public static string Protect(IProtection protection, SecureString secure_secret) { var credential = new NetworkCredential("temp", secure_secret); var bytes = Encoding.UTF8.GetBytes(credential.Password); var secret_bytes = protection.Protect(bytes); return Convert.ToBase64String(secret_bytes); }
private void RemoveProtection(ref byte[] Data, ref uint Offset, ref uint Length, ref PacketHeader header, ProtectionType Type) { if (Protections.ContainsKey(Type)) { List <IProtection> protections = Protections[Type]; for (int i = protections.Count - 1; i >= 0; i--) { IProtection protection = protections[i]; if (protection.Enabled) { Data = protection.Decode(ref Data, ref Offset, ref Length, ref header); } } } }
/// <summary> /// Add a protection to use with this connection, you can add Encryptions, Compressions and more as a extra layer of security /// </summary> /// <param name="protection">The protection to add</param> public void AddProtection(IProtection protection) { lock (connection.Client) { if (protection == null) { return; } protection.Enabled = true; if (!this.Protections.ContainsKey(protection.Type)) { this.Protections.Add(protection.Type, new List <IProtection>()); } this.Protections[protection.Type].Add(protection); } }
public Shoes([DependencyKey(ImplementationName.Second)] TProtection protection) { description = "Shoes: "; this.protection = protection; }
public Boots(TProtection protection) { description = "Boots: "; this.protection = protection; }
public static SecureString Unprotect(IProtection protection, string encrypted_secret) { var secret_bytes = Convert.FromBase64String(encrypted_secret); var bytes = protection.Unprotect(secret_bytes); return Credential.MakeSecureString(Encoding.UTF8.GetString(bytes)); }
public Mario(IProtection protection) : this(new Hero[0], new Inventory(), new IAttack[0]) { this.protection = protection; }