// Check if the player has a clan
if(activeChar.getClan() == null)
{
return;
}
Residence unit = CastleManager.getInstance().getCastleByIndex(_UnitId);
if(unit == null)
{
unit = FortressManager.getInstance().getFortressByIndex(_UnitId);
}
if(unit == null)
{
activeChar.sendActionFailed();
return;
}
// Check if leader of the clan who owns the castle?
if(unit.getOwnerId() != activeChar.getClanId() || !activeChar.isClanLeader())
{
activeChar.sendActionFailed();
return;
}
L2Clan clan = ClanTable.getInstance().getClan(_ClanId);
if(clan == null)
{
return;
}
if(!unit.getSiege().isRegistrationOver())
{
if(_Approved == 1)
{
if(unit.getSiege().checkIsDefenderWaiting(clan) || unit.getSiege().checkIsDefenderRefused(clan))
{
unit.getSiege().approveSiegeDefenderClan(_ClanId);
}
else
{
return;
}
}
else if(unit.getSiege().checkIsDefenderWaiting(clan) || unit.getSiege().checkIsDefender(clan))
{
unit.getSiege().refuseSiegeDefenderClan(_ClanId);
}
}
// Update the defender list
activeChar.sendPacket(new SiegeDefenderList(unit));
}