Procházet zdrojové kódy

BETA: Misc fixes:
* NPE vulnerability:
* L2FortSiegeGuardAI
* NpcBufferTable
* TerritoryWarManager, not fixed, it should be managed in other way, check TODO task.
* PcStatus, rewrite is probably needed.
* L2Character, _skills should be moved to FastMap probably.
* TvTManager
* PcInventory
* AutoSpawnHandler
* RequestDuelStart
* FloodProtectedListener, formatted.
* SpringUtilities, probably needs rewrite, should be simplified.
* BaseGameServerRegister
* NPE vulnerability fixed using ARM:
* Config

Zoey76 před 13 roky
rodič
revize
d7d84b8b1a

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 1299 - 1302
L2J_Server_BETA/java/com/l2jserver/Config.java


+ 1 - 1
L2J_Server_BETA/java/com/l2jserver/gameserver/ai/L2FortSiegeGuardAI.java

@@ -135,7 +135,7 @@ public class L2FortSiegeGuardAI extends L2CharacterAI implements Runnable
 		}
 		
 		// Check if the target isn't invulnerable
-		if (target.isInvul())
+		if ((target != null) && target.isInvul())
 		{
 			// However EffectInvincible requires to check GMs specially
 			if (target instanceof L2PcInstance && ((L2PcInstance) target).isGM())

+ 2 - 2
L2J_Server_BETA/java/com/l2jserver/gameserver/datatables/NpcBufferTable.java

@@ -103,7 +103,7 @@ public class NpcBufferTable
 						skills = new NpcBufferSkills(npcId);
 						skills.addSkill(skillId, skillLevel, skillFeeId, skillFeeAmount, buffGroup);
 					}
-					else
+					else if (skills != null)
 					{
 						skills.addSkill(skillId, skillLevel, skillFeeId, skillFeeAmount, buffGroup);
 					}
@@ -153,7 +153,7 @@ public class NpcBufferTable
 							skills = new NpcBufferSkills(npcId);
 							skills.addSkill(skillId, skillLevel, skillFeeId, skillFeeAmount, buffGroup);
 						}
-						else
+						else if (skills != null)
 						{
 							skills.addSkill(skillId, skillLevel, skillFeeId, skillFeeAmount, buffGroup);
 						}

+ 2 - 0
L2J_Server_BETA/java/com/l2jserver/gameserver/instancemanager/TerritoryWarManager.java

@@ -328,6 +328,7 @@ public class TerritoryWarManager implements Siegable
 			door.openMe();
 	}
 	
+	@SuppressWarnings("null")
 	public L2Npc addTerritoryWard(int territoryId, int newOwnerId, int oldOwnerId, boolean broadcastMessage)
 	{
 		L2Npc ret = null;
@@ -374,6 +375,7 @@ public class TerritoryWarManager implements Siegable
 				{
 					SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.CLAN_S1_HAS_SUCCEDED_IN_CAPTURING_S2_TERRITORY_WARD);
 					sm.addString(terNew.getOwnerClan().getName());
+					// TODO: Unhardcode using territory Id.
 					sm.addString(ward.getNpc().getName().replaceAll(" Ward", ""));
 					announceToParticipants(sm, 135000, 13500);
 				}

+ 3 - 2
L2J_Server_BETA/java/com/l2jserver/gameserver/model/AutoSpawnHandler.java

@@ -527,9 +527,10 @@ public class AutoSpawnHandler
 				
 				// Announce to all players that the spawn has taken place, with
 				// the nearest town location.
-				if (spawnInst.isBroadcasting())
+				if (spawnInst.isBroadcasting() && (npcInst != null))
+				{
 					Announcements.getInstance().announceToAll("The " + npcInst.getName() + " has spawned near " + nearestTown + "!");
-				
+				}
 				if (Config.DEBUG)
 					_log.info("AutoSpawnHandler: Spawned NPC ID " + spawnInst.getNpcId() + " at " + x + ", " + y + ", " + z + " (Near "
 							+ nearestTown + ") for " + (spawnInst.getRespawnDelay() / 60000) + " minute(s).");

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

@@ -421,7 +421,7 @@ public abstract class L2Character extends L2Object
 			_skills = new L2TIntObjectHashMap<L2Skill>();
 			if (((L2NpcTemplate) template).getSkills() != null)
 				_skills.putAll(((L2NpcTemplate) template).getSkills());
-			if (_skills != null)
+			if (!_skills.isEmpty())
 			{
 				for (L2Skill skill : getAllSkills())
 				{
@@ -444,8 +444,11 @@ public abstract class L2Character extends L2Object
 				// The skills list can be affected by spell effects so it's necessary to make a copy
 				// to avoid that a spell affecting a L2Summon, affects others L2Summon of the same type too.
 				_skills = new L2TIntObjectHashMap<L2Skill>();
-				_skills.putAll(((L2NpcTemplate) template).getSkills());
-				if (_skills != null)
+				if (template != null)
+				{
+					_skills.putAll(((L2NpcTemplate) template).getSkills());
+				}
+				if (!_skills.isEmpty())
 				{
 					for (L2Skill skill : getAllSkills())
 					{
@@ -459,7 +462,6 @@ public abstract class L2Character extends L2Object
 			}
 			else
 			{
-				// Initialize the FastMap _skills to null
 				_skills = new L2TIntObjectHashMap<L2Skill>();
 			}
 			
@@ -6642,7 +6644,7 @@ public abstract class L2Character extends L2Object
 		final L2Object target = mut.targets.length > 0 ? mut.targets[0] : null;
 		
 		// Attack target after skill use
-		if ((skill.nextActionIsAttack()) && (getTarget() instanceof L2Character) && (getTarget() != this) && (getTarget() == target) && (target.isAttackable()))
+		if ((skill.nextActionIsAttack()) && (getTarget() instanceof L2Character) && (getTarget() != this) && (target != null) && (getTarget() == target) && target.isAttackable())
 		{
 			if (getAI() == null || getAI().getNextIntention() == null || getAI().getNextIntention().getCtrlIntention() != CtrlIntention.AI_INTENTION_MOVE_TO)
 			{

+ 5 - 3
L2J_Server_BETA/java/com/l2jserver/gameserver/model/actor/status/PcStatus.java

@@ -246,9 +246,11 @@ public class PcStatus extends PlayableStatus
 				{
 					getActiveChar().disableAllSkills();
 					stopHpMpRegeneration();
-					attacker.getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
-					attacker.sendPacket(ActionFailed.STATIC_PACKET);
-					
+					if (attacker != null)
+					{
+						attacker.getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
+						attacker.sendPacket(ActionFailed.STATIC_PACKET);
+					}
 					// let the DuelManager know of his defeat
 					DuelManager.getInstance().onPlayerDefeat(getActiveChar());
 					value = 1;

+ 5 - 2
L2J_Server_BETA/java/com/l2jserver/gameserver/model/entity/TvTManager.java

@@ -90,8 +90,11 @@ public class TvTManager
 					nextStartTime = testStartTime;
 				}
 			}
-			_task = new TvTStartTask(nextStartTime.getTimeInMillis());
-			ThreadPoolManager.getInstance().executeTask(_task);
+			if (nextStartTime != null)
+			{
+				_task = new TvTStartTask(nextStartTime.getTimeInMillis());
+				ThreadPoolManager.getInstance().executeTask(_task);
+			}
 		}
 		catch (Exception e)
 		{

+ 1 - 1
L2J_Server_BETA/java/com/l2jserver/gameserver/model/itemcontainer/PcInventory.java

@@ -150,7 +150,7 @@ public class PcInventory extends Inventory
 					break;
 				}
 			}
-			if (!isDuplicate && (!onlyAvailable || (item.isSellable() && item.isAvailable(getOwner(), false, false)))) list.add(item);
+			if (!isDuplicate && (!onlyAvailable || ((item != null) && item.isSellable() && item.isAvailable(getOwner(), false, false)))) list.add(item);
 		}
 		
 		L2ItemInstance[] result = list.toArray(new L2ItemInstance[list.size()]);

+ 23 - 20
L2J_Server_BETA/java/com/l2jserver/gameserver/network/clientpackets/RequestDuelStart.java

@@ -121,27 +121,30 @@ public final class RequestDuelStart extends L2GameClientPacket
 			}
 			
 			// Send request to targetChar's party leader
-			if (!partyLeader.isProcessingRequest())
+			if (partyLeader != null)
 			{
-				activeChar.onTransactionRequest(partyLeader);
-				partyLeader.sendPacket(new ExDuelAskStart(activeChar.getName(), _partyDuel));
-				
-				if (Config.DEBUG)
-					_log.fine(activeChar.getName() + " requested a duel with " + partyLeader.getName());
-				
-				SystemMessage msg = SystemMessage.getSystemMessage(SystemMessageId.C1_PARTY_HAS_BEEN_CHALLENGED_TO_A_DUEL);
-				msg.addString(partyLeader.getName());
-				activeChar.sendPacket(msg);
-				
-				msg = SystemMessage.getSystemMessage(SystemMessageId.C1_PARTY_HAS_CHALLENGED_YOUR_PARTY_TO_A_DUEL);
-				msg.addString(activeChar.getName());
-				targetChar.sendPacket(msg);
-			}
-			else
-			{
-				SystemMessage msg = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_BUSY_TRY_LATER);
-				msg.addString(partyLeader.getName());
-				activeChar.sendPacket(msg);
+				if (!partyLeader.isProcessingRequest())
+				{
+					activeChar.onTransactionRequest(partyLeader);
+					partyLeader.sendPacket(new ExDuelAskStart(activeChar.getName(), _partyDuel));
+					
+					if (Config.DEBUG)
+						_log.fine(activeChar.getName() + " requested a duel with " + partyLeader.getName());
+					
+					SystemMessage msg = SystemMessage.getSystemMessage(SystemMessageId.C1_PARTY_HAS_BEEN_CHALLENGED_TO_A_DUEL);
+					msg.addString(partyLeader.getName());
+					activeChar.sendPacket(msg);
+					
+					msg = SystemMessage.getSystemMessage(SystemMessageId.C1_PARTY_HAS_CHALLENGED_YOUR_PARTY_TO_A_DUEL);
+					msg.addString(activeChar.getName());
+					targetChar.sendPacket(msg);
+				}
+				else
+				{
+					SystemMessage msg = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_BUSY_TRY_LATER);
+					msg.addString(partyLeader.getName());
+					activeChar.sendPacket(msg);
+				}
 			}
 		}
 		else // 1vs1 duel

+ 35 - 23
L2J_Server_BETA/java/com/l2jserver/loginserver/FloodProtectedListener.java

@@ -27,23 +27,21 @@ import javolution.util.FastMap;
 import com.l2jserver.Config;
 
 /**
- *
  * @author -Wooden-
- *
  */
 public abstract class FloodProtectedListener extends Thread
 {
-	private Logger _log = Logger.getLogger(FloodProtectedListener.class.getName());
-	private Map<String, ForeignConnection> _floodProtection = new FastMap<String, ForeignConnection>();
-	private String _listenIp;
-	private int _port;
+	private final Logger _log = Logger.getLogger(FloodProtectedListener.class.getName());
+	private final Map<String, ForeignConnection> _floodProtection = new FastMap<String, ForeignConnection>();
+	private final String _listenIp;
+	private final int _port;
 	private ServerSocket _serverSocket;
 	
 	public FloodProtectedListener(String listenIp, int port) throws IOException
 	{
 		_port = port;
 		_listenIp = listenIp;
-		if(_listenIp.equals("*"))
+		if (_listenIp.equals("*"))
 		{
 			_serverSocket = new ServerSocket(_port);
 		}
@@ -63,46 +61,58 @@ public abstract class FloodProtectedListener extends Thread
 			try
 			{
 				connection = _serverSocket.accept();
-				if(Config.FLOOD_PROTECTION)
+				if (Config.FLOOD_PROTECTION)
 				{
 					ForeignConnection fConnection = _floodProtection.get(connection.getInetAddress().getHostAddress());
-					if(fConnection != null)
+					if (fConnection != null)
 					{
 						fConnection.connectionNumber += 1;
-						if( (fConnection.connectionNumber > Config.FAST_CONNECTION_LIMIT
-								&& (System.currentTimeMillis() - fConnection.lastConnection) < Config.NORMAL_CONNECTION_TIME)
-								|| (System.currentTimeMillis() - fConnection.lastConnection) < Config.FAST_CONNECTION_TIME
-								|| fConnection.connectionNumber > Config.MAX_CONNECTION_PER_IP)
+						if (((fConnection.connectionNumber > Config.FAST_CONNECTION_LIMIT) && ((System.currentTimeMillis() - fConnection.lastConnection) < Config.NORMAL_CONNECTION_TIME)) || ((System.currentTimeMillis() - fConnection.lastConnection) < Config.FAST_CONNECTION_TIME) || (fConnection.connectionNumber > Config.MAX_CONNECTION_PER_IP))
 						{
 							fConnection.lastConnection = System.currentTimeMillis();
 							connection.close();
 							fConnection.connectionNumber -= 1;
-							if(!fConnection.isFlooding)_log.warning("Potential Flood from "+connection.getInetAddress().getHostAddress());
+							if (!fConnection.isFlooding)
+							{
+								_log.warning("Potential Flood from " + connection.getInetAddress().getHostAddress());
+							}
 							fConnection.isFlooding = true;
 							continue;
 						}
-						if(fConnection.isFlooding) //if connection was flooding server but now passed the check
+						if (fConnection.isFlooding) // if connection was flooding server but now passed the check
 						{
 							fConnection.isFlooding = false;
-							_log.info(connection.getInetAddress().getHostAddress()+" is not considered as flooding anymore.");
+							_log.info(connection.getInetAddress().getHostAddress() + " is not considered as flooding anymore.");
 						}
 						fConnection.lastConnection = System.currentTimeMillis();
 					}
 					else
 					{
 						fConnection = new ForeignConnection(System.currentTimeMillis());
-						_floodProtection.put(connection.getInetAddress().getHostAddress(),fConnection);
+						_floodProtection.put(connection.getInetAddress().getHostAddress(), fConnection);
 					}
 				}
 				addClient(connection);
 			}
 			catch (Exception e)
 			{
-				try { connection.close(); } catch (Exception e2) {}
-				if (this.isInterrupted())
+				try
+				{
+					if (connection != null)
+					{
+						connection.close();
+					}
+				}
+				catch (Exception e2)
+				{
+				}
+				if (isInterrupted())
 				{
 					// shutdown?
-					try { _serverSocket.close();}
+					try
+					{
+						_serverSocket.close();
+					}
 					catch (IOException io)
 					{
 						_log.log(Level.INFO, "", io);
@@ -133,10 +143,12 @@ public abstract class FloodProtectedListener extends Thread
 	
 	public void removeFloodProtection(String ip)
 	{
-		if(!Config.FLOOD_PROTECTION)
+		if (!Config.FLOOD_PROTECTION)
+		{
 			return;
+		}
 		ForeignConnection fConnection = _floodProtection.get(ip);
-		if(fConnection != null)
+		if (fConnection != null)
 		{
 			fConnection.connectionNumber -= 1;
 			if (fConnection.connectionNumber == 0)
@@ -146,7 +158,7 @@ public abstract class FloodProtectedListener extends Thread
 		}
 		else
 		{
-			_log.warning("Removing a flood protection for a GameServer that was not in the connection map??? :"+ip);
+			_log.warning("Removing a flood protection for a GameServer that was not in the connection map??? :" + ip);
 		}
 	}
 	

+ 19 - 7
L2J_Server_BETA/java/com/l2jserver/tools/dbinstaller/util/swing/SpringUtilities.java

@@ -117,25 +117,37 @@ public class SpringUtilities
 				cons.setX(initialXSpring);
 			}
 			else
-			{ // x position depends on previous component
-				cons.setX(Spring.sum(lastCons.getConstraint(SpringLayout.EAST), xPadSpring));
+			{
+				// x position depends on previous component
+				if (lastCons != null)
+				{
+					cons.setX(Spring.sum(lastCons.getConstraint(SpringLayout.EAST), xPadSpring));
+				}
 			}
 			
 			if (i / cols == 0)
-			{ // first row
+			{
+				// first row
 				cons.setY(initialYSpring);
 			}
 			else
-			{ // y position depends on previous row
-				cons.setY(Spring.sum(lastRowCons.getConstraint(SpringLayout.SOUTH), yPadSpring));
+			{
+				// y position depends on previous row
+				if (lastRowCons != null)
+				{
+					cons.setY(Spring.sum(lastRowCons.getConstraint(SpringLayout.SOUTH), yPadSpring));
+				}
 			}
 			lastCons = cons;
 		}
 		
 		// Set the parent's size.
 		SpringLayout.Constraints pCons = layout.getConstraints(parent);
-		pCons.setConstraint(SpringLayout.SOUTH, Spring.sum(Spring.constant(yPad), lastCons.getConstraint(SpringLayout.SOUTH)));
-		pCons.setConstraint(SpringLayout.EAST, Spring.sum(Spring.constant(xPad), lastCons.getConstraint(SpringLayout.EAST)));
+		if (lastCons != null)
+		{
+			pCons.setConstraint(SpringLayout.SOUTH, Spring.sum(Spring.constant(yPad), lastCons.getConstraint(SpringLayout.SOUTH)));
+			pCons.setConstraint(SpringLayout.EAST, Spring.sum(Spring.constant(xPad), lastCons.getConstraint(SpringLayout.EAST)));
+		}
 	}
 	
 	/* Used by makeCompactGrid. */

+ 4 - 1
L2J_Server_BETA/java/com/l2jserver/tools/gsregistering/BaseGameServerRegister.java

@@ -122,7 +122,10 @@ public abstract class BaseGameServerRegister
 					}
 					catch (NumberFormatException e)
 					{
-						System.out.printf(bundle.getString("wrongUnregisterArg") + '\n', gsId);
+						if (bundle != null)
+						{
+							System.out.printf(bundle.getString("wrongUnregisterArg") + '\n', gsId);
+						}
 						System.exit(1);
 					}
 				}

Některé soubory nejsou zobrazeny, neboť je v těchto rozdílových datech změněno mnoho souborů