Core/Errors: Stop using System.Diagnostics.Contracts, Its just closing the server without error or warning. We now log the error and then throw a exception

This commit is contained in:
hondacrx
2018-06-15 12:34:56 -04:00
parent 1289bc3ed1
commit 7aa494d5dd
86 changed files with 520 additions and 558 deletions
+5 -6
View File
@@ -28,7 +28,6 @@ using Game.PvP;
using Game.Spells;
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
namespace Game.Entities
@@ -168,7 +167,7 @@ namespace Game.Entities
public void TauntApply(Unit taunter)
{
Contract.Assert(IsTypeId(TypeId.Unit));
Cypher.Assert(IsTypeId(TypeId.Unit));
if (!taunter || (taunter.IsTypeId(TypeId.Player) && taunter.ToPlayer().IsGameMaster()))
return;
@@ -192,7 +191,7 @@ namespace Game.Entities
public void TauntFadeOut(Unit taunter)
{
Contract.Assert(IsTypeId(TypeId.Unit));
Cypher.Assert(IsTypeId(TypeId.Unit));
if (!taunter || (taunter.IsTypeId(TypeId.Player) && taunter.ToPlayer().IsGameMaster()))
return;
@@ -1091,7 +1090,7 @@ namespace Game.Entities
{
Player he = duel_wasMounted ? victim.GetCharmer().ToPlayer() : victim.ToPlayer();
Contract.Assert(he && he.duel != null);
Cypher.Assert(he && he.duel != null);
if (duel_wasMounted) // In this case victim==mount
victim.SetHealth(1);
@@ -2882,7 +2881,7 @@ namespace Game.Entities
// function based on function Unit.CanAttack from 13850 client
public bool _IsValidAttackTarget(Unit target, SpellInfo bySpell, WorldObject obj = null)
{
Contract.Assert(target != null);
Cypher.Assert(target != null);
// can't attack self
if (this == target)
@@ -3019,7 +3018,7 @@ namespace Game.Entities
// function based on function Unit.CanAssist from 13850 client
public bool _IsValidAssistTarget(Unit target, SpellInfo bySpell)
{
Contract.Assert(target != null);
Cypher.Assert(target != null);
// can assist to self
if (this == target)
+12 -11
View File
@@ -20,7 +20,6 @@ using Game.AI;
using Game.Network.Packets;
using Game.Spells;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
namespace Game.Entities
@@ -163,7 +162,8 @@ namespace Game.Entities
minion.SetOwnerGUID(GetGUID());
m_Controlled.Add(minion);
if (!m_Controlled.Contains(minion))
m_Controlled.Add(minion);
if (IsTypeId(TypeId.Player))
{
@@ -269,12 +269,12 @@ namespace Game.Entities
if (GetGUID() == unit.GetCharmerGUID())
continue;
Contract.Assert(unit.GetOwnerGUID() == GetGUID());
Cypher.Assert(unit.GetOwnerGUID() == GetGUID());
if (unit.GetOwnerGUID() != GetGUID())
{
Contract.Assert(false);
Cypher.Assert(false);
}
Contract.Assert(unit.IsTypeId(TypeId.Unit));
Cypher.Assert(unit.IsTypeId(TypeId.Unit));
if (!unit.HasUnitTypeMask(UnitTypeMask.Guardian))
continue;
@@ -308,8 +308,8 @@ namespace Game.Entities
if (charmer.IsTypeId(TypeId.Player))
charmer.RemoveAurasByType(AuraType.Mounted);
Contract.Assert(type != CharmType.Possess || charmer.IsTypeId(TypeId.Player));
Contract.Assert((type == CharmType.Vehicle) == IsVehicle());
Cypher.Assert(type != CharmType.Possess || charmer.IsTypeId(TypeId.Player));
Cypher.Assert((type == CharmType.Vehicle) == IsVehicle());
Log.outDebug(LogFilter.Unit, "SetCharmedBy: charmer {0} (GUID {1}), charmed {2} (GUID {3}), type {4}.", charmer.GetEntry(), charmer.GetGUID().ToString(), GetEntry(), GetGUID().ToString(), type);
@@ -505,8 +505,8 @@ namespace Game.Entities
if (!charmer)
return;
Contract.Assert(type != CharmType.Possess || charmer.IsTypeId(TypeId.Player));
Contract.Assert(type != CharmType.Vehicle || (IsTypeId(TypeId.Unit) && IsVehicle()));
Cypher.Assert(type != CharmType.Possess || charmer.IsTypeId(TypeId.Player));
Cypher.Assert(type != CharmType.Vehicle || (IsTypeId(TypeId.Unit) && IsVehicle()));
charmer.SetCharm(this, false);
@@ -574,7 +574,7 @@ namespace Game.Entities
}
}
void RemoveAllMinionsByEntry(uint entry)
public void RemoveAllMinionsByEntry(uint entry)
{
for (var i = 0; i < m_Controlled.Count; ++i)
{
@@ -612,7 +612,8 @@ namespace Game.Entities
if (_isWalkingBeforeCharm)
charm.SetWalk(false);
m_Controlled.Add(charm);
if (!m_Controlled.Contains(charm))
m_Controlled.Add(charm);
}
else
{
+21 -22
View File
@@ -22,7 +22,6 @@ using Game.Network.Packets;
using Game.Spells;
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
namespace Game.Entities
@@ -1787,7 +1786,7 @@ namespace Game.Entities
{
foreach (AuraApplication aurApp in procAuras)
{
Contract.Assert(aurApp.GetTarget() == this);
Cypher.Assert(aurApp.GetTarget() == this);
uint procEffectMask = aurApp.GetBase().IsProcTriggeredOnEvent(aurApp, eventInfo, now);
if (procEffectMask != 0)
{
@@ -1890,7 +1889,7 @@ namespace Game.Entities
++m_procDeep;
else
{
Contract.Assert(m_procDeep != 0);
Cypher.Assert(m_procDeep != 0);
--m_procDeep;
}
}
@@ -1989,7 +1988,7 @@ namespace Game.Entities
}
public void SetCurrentCastSpell(Spell pSpell)
{
Contract.Assert(pSpell != null); // NULL may be never passed here, use InterruptSpell or InterruptNonMeleeSpells
Cypher.Assert(pSpell != null); // NULL may be never passed here, use InterruptSpell or InterruptNonMeleeSpells
CurrentSpellTypes CSpellType = pSpell.GetCurrentContainer();
@@ -2789,7 +2788,7 @@ namespace Game.Entities
}
public void InterruptSpell(CurrentSpellTypes spellType, bool withDelayed = true, bool withInstant = true)
{
Contract.Assert(spellType < CurrentSpellTypes.Max);
Cypher.Assert(spellType < CurrentSpellTypes.Max);
Log.outDebug(LogFilter.Unit, "Interrupt spell for unit {0}", GetEntry());
Spell spell = m_currentSpells.LookupByKey(spellType);
@@ -3375,7 +3374,7 @@ namespace Game.Entities
{
Aura aura = keyValuePair.Value;
Contract.Assert(!aura.IsRemoved());
Cypher.Assert(!aura.IsRemoved());
m_ownedAuras.Remove(keyValuePair);
m_removedAuras.Add(aura);
@@ -3402,7 +3401,7 @@ namespace Game.Entities
if (auraToRemove.IsRemoved())
return;
Contract.Assert(auraToRemove.GetOwner() == this);
Cypher.Assert(auraToRemove.GetOwner() == this);
if (removeMode == AuraRemoveMode.None)
{
@@ -3423,7 +3422,7 @@ namespace Game.Entities
}
}
Contract.Assert(false);
Cypher.Assert(false);
}
public void RemoveAurasDueToSpell(uint spellId, ObjectGuid casterGUID = default(ObjectGuid), uint reqEffMask = 0, AuraRemoveMode removeMode = AuraRemoveMode.Default)
@@ -3612,7 +3611,7 @@ namespace Game.Entities
{
Aura aura = m_modAuras[auraType][i].GetBase();
AuraApplication aurApp = aura.GetApplicationOfTarget(GetGUID());
Contract.Assert(aurApp != null);
Cypher.Assert(aurApp != null);
if (check(aurApp))
{
@@ -3833,16 +3832,16 @@ namespace Game.Entities
public void _UnapplyAura(KeyValuePair<uint, AuraApplication> pair, AuraRemoveMode removeMode)
{
AuraApplication aurApp = pair.Value;
Contract.Assert(aurApp != null);
Contract.Assert(!aurApp.HasRemoveMode());
Contract.Assert(aurApp.GetTarget() == this);
Cypher.Assert(aurApp != null);
Cypher.Assert(!aurApp.HasRemoveMode());
Cypher.Assert(aurApp.GetTarget() == this);
aurApp.SetRemoveMode(removeMode);
Aura aura = aurApp.GetBase();
Log.outDebug(LogFilter.Spells, "Aura {0} now is remove mode {1}", aura.GetId(), removeMode);
// dead loop is killing the server probably
Contract.Assert(m_removedAurasCount < 0xFFFFFFFF);
Cypher.Assert(m_removedAurasCount < 0xFFFFFFFF);
++m_removedAurasCount;
@@ -3889,7 +3888,7 @@ namespace Game.Entities
}
// all effect mustn't be applied
Contract.Assert(aurApp.GetEffectMask() == 0);
Cypher.Assert(aurApp.GetEffectMask() == 0);
// Remove totem at next update if totem loses its aura
if (aurApp.GetRemoveMode() == AuraRemoveMode.Expire && IsTypeId(TypeId.Unit) && IsTotem())
@@ -3908,7 +3907,7 @@ namespace Game.Entities
public void _UnapplyAura(AuraApplication aurApp, AuraRemoveMode removeMode)
{
// aura can be removed from unit only if it's applied on it, shouldn't happen
Contract.Assert(aurApp.GetBase().GetApplicationOfTarget(GetGUID()) == aurApp);
Cypher.Assert(aurApp.GetBase().GetApplicationOfTarget(GetGUID()) == aurApp);
uint spellId = aurApp.GetBase().GetId();
var range = m_appliedAuras.LookupByKey(spellId);
@@ -3921,7 +3920,7 @@ namespace Game.Entities
return;
}
}
Contract.Assert(false);
Cypher.Assert(false);
}
public AuraEffect GetAuraEffect(uint spellId, uint effIndex, ObjectGuid casterGUID = default(ObjectGuid))
@@ -4009,10 +4008,10 @@ namespace Game.Entities
public void _ApplyAuraEffect(Aura aura, uint effIndex)
{
Contract.Assert(aura != null);
Contract.Assert(aura.HasEffect(effIndex));
Cypher.Assert(aura != null);
Cypher.Assert(aura.HasEffect(effIndex));
AuraApplication aurApp = aura.GetApplicationOfTarget(GetGUID());
Contract.Assert(aurApp != null);
Cypher.Assert(aurApp != null);
if (aurApp.GetEffectMask() == 0)
_ApplyAura(aurApp, (uint)(1 << (int)effIndex));
else
@@ -4058,7 +4057,7 @@ namespace Game.Entities
}
public void _AddAura(UnitAura aura, Unit caster)
{
Contract.Assert(!m_cleanupDone);
Cypher.Assert(!m_cleanupDone);
m_ownedAuras.Add(aura.GetId(), aura);
_RemoveNoStackAurasDueToAura(aura);
@@ -4073,7 +4072,7 @@ namespace Game.Entities
// @HACK: Player is not in world during loading auras.
//Single target auras are not saved or loaded from database
//but may be created as a result of aura links (player mounts with passengers)
Contract.Assert((IsInWorld && !IsDuringRemoveFromWorld()) || (aura.GetCasterGUID() == GetGUID()) || (IsLoading() && aura.HasEffectType(AuraType.ControlVehicle)));
Cypher.Assert((IsInWorld && !IsDuringRemoveFromWorld()) || (aura.GetCasterGUID() == GetGUID()) || (IsLoading() && aura.HasEffectType(AuraType.ControlVehicle)));
// register single target aura
caster.m_scAuras.Add(aura);
@@ -4090,7 +4089,7 @@ namespace Game.Entities
}
public Aura _TryStackingOrRefreshingExistingAura(SpellInfo newAura, uint effMask, Unit caster, int[] baseAmount = null, Item castItem = null, ObjectGuid casterGUID = default(ObjectGuid), bool resetPeriodicTimer = true, ObjectGuid castItemGuid = default(ObjectGuid), int castItemLevel = -1)
{
Contract.Assert(!casterGUID.IsEmpty() || caster);
Cypher.Assert(!casterGUID.IsEmpty() || caster);
// Check if these can stack anyway
if (casterGUID.IsEmpty() && !newAura.IsStackableOnOneSlotWithDifferentCasters())
+8 -9
View File
@@ -30,7 +30,6 @@ using Game.Network.Packets;
using Game.Spells;
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
namespace Game.Entities
@@ -139,7 +138,7 @@ namespace Game.Entities
// If this is set during update SetCantProc(false) call is missing somewhere in the code
// Having this would prevent spells from being proced, so let's crash
Contract.Assert(m_procDeep == 0);
Cypher.Assert(m_procDeep == 0);
if (CanHaveThreatList() && GetThreatManager().isNeedUpdateToClient(diff))
SendThreatListUpdate();
@@ -811,7 +810,7 @@ namespace Game.Entities
public void _EnterVehicle(Vehicle vehicle, sbyte seatId, AuraApplication aurApp)
{
// Must be called only from aura handler
Contract.Assert(aurApp != null);
Cypher.Assert(aurApp != null);
if (!IsAlive() || GetVehicleKit() == vehicle || vehicle.GetBase().IsOnVehicle(this))
return;
@@ -840,7 +839,7 @@ namespace Game.Entities
}
}
Contract.Assert(!m_vehicle);
Cypher.Assert(!m_vehicle);
vehicle.AddPassenger(this, seatId);
}
@@ -866,12 +865,12 @@ namespace Game.Entities
continue;
// Make sure there is only one ride vehicle aura on target cast by the unit changing seat
Contract.Assert(rideVehicleEffect == null);
Cypher.Assert(rideVehicleEffect == null);
rideVehicleEffect = eff;
}
// Unit riding a vehicle must always have control vehicle aura on target
Contract.Assert(rideVehicleEffect != null);
Cypher.Assert(rideVehicleEffect != null);
rideVehicleEffect.ChangeAmount((seatId < 0 ? GetTransSeat() : seatId) + 1);
}
@@ -1764,12 +1763,12 @@ namespace Game.Entities
public AuraApplication _CreateAuraApplication(Aura aura, uint effMask)
{
// can't apply aura on unit which is going to be deleted - to not create a memory leak
Contract.Assert(!m_cleanupDone);
Cypher.Assert(!m_cleanupDone);
// aura musn't be removed
Contract.Assert(!aura.IsRemoved());
Cypher.Assert(!aura.IsRemoved());
// aura mustn't be already applied on target
Contract.Assert(!aura.IsAppliedOnTarget(GetGUID()), "Unit._CreateAuraApplication: aura musn't be applied on target");
Cypher.Assert(!aura.IsAppliedOnTarget(GetGUID()), "Unit._CreateAuraApplication: aura musn't be applied on target");
SpellInfo aurSpellInfo = aura.GetSpellInfo();
uint aurId = aurSpellInfo.Id;