Sfoglia il codice sorgente

Hiding real mob HP from packet sniffers.
Some cleanup, minor update.

JIV 15 anni fa
parent
commit
fccb8e99bd

+ 1 - 1
L2_GameServer/java/com/l2jserver/gameserver/instancemanager/TerritoryWarManager.java

@@ -1081,7 +1081,7 @@ public class TerritoryWarManager implements Siegable
 			if (isTWInProgress())
 			{
 				for(L2PcInstance player : L2World.getInstance().getAllPlayers().values())
-					if (player.getSiegeSide() > 0)
+					if (player != null && player.getSiegeSide() > 0)
 						giveTWPoint(player, 1000, 6);
 			}
 			else

+ 6 - 6
L2_GameServer/java/com/l2jserver/gameserver/model/L2World.java

@@ -129,9 +129,9 @@ public final class L2World
 	
 	public long timeStoreObject(L2Object object)
 	{
-		long time = System.currentTimeMillis();
+		long time = System.nanoTime();
 		_allObjects.put(object.getObjectId(), object);
-		time -= System.currentTimeMillis();
+		time = System.nanoTime() - time;
 		return time;
 	}
 	
@@ -171,9 +171,9 @@ public final class L2World
 	
 	public long timeRemoveObject(L2Object object)
 	{
-		long time = System.currentTimeMillis();
+		long time = System.nanoTime();
 		_allObjects.remove(Integer.valueOf(object.getObjectId()));
-		time -= System.currentTimeMillis();
+		time = System.nanoTime() - time;
 		return time;
 	}
 	
@@ -192,9 +192,9 @@ public final class L2World
 	
 	public long timeFindObject(int objectID)
 	{
-		long time = System.currentTimeMillis();
+		long time = System.nanoTime();
 		_allObjects.get(Integer.valueOf(objectID));
-		time -= System.currentTimeMillis();
+		time = System.nanoTime() - time;
 		return time;
 	}
 	

+ 5 - 5
L2_GameServer/java/com/l2jserver/gameserver/model/actor/L2Character.java

@@ -546,7 +546,7 @@ public abstract class L2Character extends L2Object
 			_log.fine("Broadcast Status Update for " + getObjectId() + "(" + getName() + "). HP: " + getCurrentHp());
 
 		// Create the Server->Client packet StatusUpdate with current HP
-		StatusUpdate su = new StatusUpdate(getObjectId());
+		StatusUpdate su = new StatusUpdate(this);
 		su.addAttribute(StatusUpdate.CUR_HP, (int)getCurrentHp());
 
 		// Go through the StatusListener
@@ -3816,17 +3816,17 @@ public abstract class L2Character extends L2Object
 			}
 			else if (stat == Stats.POWER_ATTACK_SPEED) 
 			{
-				if (su == null) su = new StatusUpdate(getObjectId());
+				if (su == null) su = new StatusUpdate(this);
 				su.addAttribute(StatusUpdate.ATK_SPD, getPAtkSpd());
 			}
 			else if (stat == Stats.MAGIC_ATTACK_SPEED) 
 			{
-				if (su == null) su = new StatusUpdate(getObjectId());
+				if (su == null) su = new StatusUpdate(this);
 				su.addAttribute(StatusUpdate.CAST_SPD, getMAtkSpd());
 			}
 			else if (stat == Stats.MAX_HP && this instanceof L2Attackable)
 			{
-				if (su == null) su = new StatusUpdate(getObjectId());
+				if (su == null) su = new StatusUpdate(this);
 				su.addAttribute(StatusUpdate.MAX_HP, getMaxHp());
 			}
 			/*else if (stat == Stats.MAX_CP) 
@@ -6034,7 +6034,7 @@ public abstract class L2Character extends L2Object
 				}
 			}
 
-			StatusUpdate su = new StatusUpdate(getObjectId());
+			StatusUpdate su = new StatusUpdate(this);
 			boolean isSendStatus = false;
 
 			// Consume MP of the L2Character and Send the Server->Client packet StatusUpdate with current HP and MP to all other L2PcInstance to inform

+ 0 - 3
L2_GameServer/java/com/l2jserver/gameserver/network/serverpackets/ExBrExtraUserInfo.java

@@ -33,9 +33,6 @@ public class ExBrExtraUserInfo extends L2GameServerPacket
 	}
 
 	@Override
-	/**
-	 * This packet should belong to Quest windows, not UserInfo in T3.
-	 */
 	protected final void writeImpl()
 	{
 		

+ 126 - 88
L2_GameServer/java/com/l2jserver/gameserver/network/serverpackets/StatusUpdate.java

@@ -16,6 +16,11 @@ package com.l2jserver.gameserver.network.serverpackets;
 
 import java.util.ArrayList;
 
+import com.l2jserver.gameserver.model.L2Object;
+import com.l2jserver.gameserver.model.L2World;
+import com.l2jserver.gameserver.model.actor.L2Attackable;
+import com.l2jserver.gameserver.model.actor.L2Character;
+
 /**
  *
  * 01                // Packet Identifier <BR>
@@ -32,93 +37,126 @@ import java.util.ArrayList;
  */
 public final class StatusUpdate extends L2GameServerPacket
 {
-    private static final String _S__1A_STATUSUPDATE = "[S] 18 StatusUpdate";
-    public static final int LEVEL = 0x01;
-    public static final int EXP = 0x02;
-    public static final int STR = 0x03;
-    public static final int DEX = 0x04;
-    public static final int CON = 0x05;
-    public static final int INT = 0x06;
-    public static final int WIT = 0x07;
-    public static final int MEN = 0x08;
-
-    public static final int CUR_HP = 0x09;
-    public static final int MAX_HP = 0x0a;
-    public static final int CUR_MP = 0x0b;
-    public static final int MAX_MP = 0x0c;
-
-    public static final int SP = 0x0d;
-    public static final int CUR_LOAD = 0x0e;
-    public static final int MAX_LOAD = 0x0f;
-
-    public static final int P_ATK = 0x11;
-    public static final int ATK_SPD = 0x12;
-    public static final int P_DEF = 0x13;
-    public static final int EVASION = 0x14;
-    public static final int ACCURACY = 0x15;
-    public static final int CRITICAL = 0x16;
-    public static final int M_ATK = 0x17;
-    public static final int CAST_SPD = 0x18;
-    public static final int M_DEF = 0x19;
-    public static final int PVP_FLAG = 0x1a;
-    public static final int KARMA = 0x1b;
-
-    public static final int CUR_CP = 0x21;
-    public static final int MAX_CP = 0x22;
-
-    private int _objectId;
-    private ArrayList<Attribute> _attributes;
-
-    class Attribute
-    {
-        /** id values
-         * 09 - current health
-         * 0a - max health
-         * 0b - current mana
-         * 0c - max mana
-         *
-         */
-        public int id;
-        public int value;
-
-        Attribute(int pId, int pValue)
-        {
-            id = pId;
-            value = pValue;
-        }
-    }
-
-    public StatusUpdate(int objectId)
-    {
-        _attributes = new ArrayList<Attribute>();
-        _objectId = objectId;
-    }
-
-    public void addAttribute(int id, int level)
-    {
-        _attributes.add(new Attribute(id, level));
-    }
-
-    @Override
+	private static final String _S__1A_STATUSUPDATE = "[S] 18 StatusUpdate";
+	private static final int HP_MOD = 10000000;
+	
+	public static final int LEVEL = 0x01;
+	public static final int EXP = 0x02;
+	public static final int STR = 0x03;
+	public static final int DEX = 0x04;
+	public static final int CON = 0x05;
+	public static final int INT = 0x06;
+	public static final int WIT = 0x07;
+	public static final int MEN = 0x08;
+	
+	public static final int CUR_HP = 0x09;
+	public static final int MAX_HP = 0x0a;
+	public static final int CUR_MP = 0x0b;
+	public static final int MAX_MP = 0x0c;
+	
+	public static final int SP = 0x0d;
+	public static final int CUR_LOAD = 0x0e;
+	public static final int MAX_LOAD = 0x0f;
+	
+	public static final int P_ATK = 0x11;
+	public static final int ATK_SPD = 0x12;
+	public static final int P_DEF = 0x13;
+	public static final int EVASION = 0x14;
+	public static final int ACCURACY = 0x15;
+	public static final int CRITICAL = 0x16;
+	public static final int M_ATK = 0x17;
+	public static final int CAST_SPD = 0x18;
+	public static final int M_DEF = 0x19;
+	public static final int PVP_FLAG = 0x1a;
+	public static final int KARMA = 0x1b;
+	
+	public static final int CUR_CP = 0x21;
+	public static final int MAX_CP = 0x22;
+	
+	private int _objectId;
+	private int _maxHp = -1;
+	private ArrayList<Attribute> _attributes;
+	
+	class Attribute
+	{
+		/** id values
+		 * 09 - current health
+		 * 0a - max health
+		 * 0b - current mana
+		 * 0c - max mana
+		 *
+		 */
+		public int id;
+		public int value;
+		
+		Attribute(int pId, int pValue)
+		{
+			id = pId;
+			value = pValue;
+		}
+	}
+	
+	/**
+	 * If you have access to object itself use {@link StatusUpdate#StatusUpdate(L2Object)}.
+	 * @param objectId
+	 */
+	public StatusUpdate(int objectId)
+	{
+		_attributes = new ArrayList<Attribute>();
+		_objectId = objectId;
+		L2Object obj = L2World.getInstance().findObject(objectId);
+		if (obj != null && obj instanceof L2Attackable)
+		{
+			_maxHp = ((L2Character) obj).getMaxHp();
+		}
+	}
+	
+	/**
+	 * Create {@link StatusUpdate} packet for given {@link L2Object}.
+	 * @param object
+	 */
+	public StatusUpdate(L2Object object)
+	{
+		_attributes = new ArrayList<Attribute>();
+		_objectId = object.getObjectId();
+		if (object instanceof L2Attackable)
+			_maxHp = ((L2Character) object).getMaxHp();
+	}
+	
+	public void addAttribute(int id, int level)
+	{
+		if (_maxHp != -1)
+		{
+			if (id == MAX_HP)
+				level = HP_MOD;
+			else if (id == CUR_HP)
+			{
+				level = (int) ((level / (float)_maxHp) * HP_MOD);
+			}
+		}
+		_attributes.add(new Attribute(id, level));
+	}
+	
+	@Override
 	protected final void writeImpl()
-    {
-        writeC(0x18);
-        writeD(_objectId);
-        writeD(_attributes.size());
-
-        for (Attribute temp: _attributes)
-        {
-            writeD(temp.id);
-            writeD(temp.value);
-        }
-    }
-
-    /* (non-Javadoc)
-     * @see com.l2jserver.gameserver.serverpackets.ServerBasePacket#getType()
-     */
-    @Override
-	public String getType()
-    {
-        return _S__1A_STATUSUPDATE;
-    }
+	{
+		writeC(0x18);
+		writeD(_objectId);
+		writeD(_attributes.size());
+		
+		for (Attribute temp: _attributes)
+		{
+			writeD(temp.id);
+			writeD(temp.value);
+		}
+	}
+	
+	/* (non-Javadoc)
+	 * @see com.l2jserver.gameserver.serverpackets.ServerBasePacket#getType()
+	 */
+	 @Override
+	 public String getType()
+	 {
+		 return _S__1A_STATUSUPDATE;
+	 }
 }

+ 1 - 1
L2_GameServer/java/com/l2jserver/gameserver/skills/effects/EffectHealOverTime.java

@@ -75,7 +75,7 @@ public class EffectHealOverTime extends L2Effect
 			hp = maxhp;
 		
 		getEffected().setCurrentHp(hp);
-		StatusUpdate suhp = new StatusUpdate(getEffected().getObjectId());
+		StatusUpdate suhp = new StatusUpdate(getEffected());
 		suhp.addAttribute(StatusUpdate.CUR_HP, (int) hp);
 		getEffected().sendPacket(suhp);
 		return true;

+ 2 - 2
L2_GameServer/java/com/l2jserver/gameserver/skills/l2skills/L2SkillDrain.java

@@ -127,7 +127,7 @@ public class L2SkillDrain extends L2Skill
 
             activeChar.setCurrentHp(hp);
 
-			StatusUpdate suhp = new StatusUpdate(activeChar.getObjectId());
+			StatusUpdate suhp = new StatusUpdate(activeChar);
 			suhp.addAttribute(StatusUpdate.CUR_HP, (int)hp);
 			activeChar.sendPacket(suhp);
 
@@ -221,7 +221,7 @@ public class L2SkillDrain extends L2Skill
 
             owner.setCurrentHp(hp);
             
-			StatusUpdate suhp = new StatusUpdate(owner.getObjectId());
+			StatusUpdate suhp = new StatusUpdate(owner);
 			suhp.addAttribute(StatusUpdate.CUR_HP, (int)hp); 
 			owner.sendPacket(suhp);