Bläddra i källkod

BETA: Fix for ObjName(Id)[ObjId] already exist in OID map! #5427
* Synchronization in L2Character and L2PcInstance by JIV
* Fix for banned characters by gmpf with some tweaks by me.

Zoey76 14 år sedan
förälder
incheckning
bad0d2a930

+ 24 - 2
L2J_Server_BETA/java/com/l2jserver/gameserver/model/CharSelectInfoPackage.java

@@ -18,7 +18,7 @@ import com.l2jserver.gameserver.model.itemcontainer.Inventory;
 import com.l2jserver.gameserver.model.itemcontainer.PcInventory;
 
 /**
- * Used to Store data sent to Client for Character
+ * Used to Store data sent to Client for Character.<br>
  * Selection screen.
  *
  * @version $Revision: 1.2.2.2.2.4 $ $Date: 2005/03/27 15:29:33 $
@@ -56,9 +56,12 @@ public class CharSelectInfoPackage
 	private int _z = 0;
 	private String _htmlPrefix = null;
 	private int _vitalityPoints = 0;
+	private byte _accessLevel = 0;
 	
 	/**
-	 * @param int1
+	 * Constructor for CharSelectInfoPackage.
+	 * @param objectId character object Id.
+	 * @param name the character's name.
 	 */
 	public CharSelectInfoPackage(int objectId, String name)
 	{
@@ -67,6 +70,9 @@ public class CharSelectInfoPackage
 		_paperdoll = PcInventory.restoreVisibleInventory(objectId);
 	}
 	
+	/**
+	 * @return the character object Id.
+	 */
 	public int getObjectId()
 	{
 		return _objectId;
@@ -77,6 +83,22 @@ public class CharSelectInfoPackage
 		_objectId = objectId;
 	}
 	
+	/**
+	 * @return the character's access level.
+	 */
+	public byte getAccessLevel()
+	{
+		return _accessLevel;
+	}
+	
+	/**
+	 * @param level the character's access level to be set.
+	 */
+	public void setAccessLevel(byte level)
+	{
+		_accessLevel = level;
+	}
+	
 	public int getCharId()
 	{
 		return _charId;

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

@@ -456,12 +456,13 @@ public abstract class L2Character extends L2Object
 	
 	public void onTeleported()
 	{
-		if (!isTeleporting())
-			return;
-		spawnMe(getPosition().getX(), getPosition().getY(), getPosition().getZ());
-		
-		setIsTeleporting(false);
-		
+		synchronized(this)
+		{
+			if (!isTeleporting())
+				return;
+			spawnMe(getPosition().getX(), getPosition().getY(), getPosition().getZ());
+			setIsTeleporting(false);
+		}
 		if (_isPendingRevive)
 			doRevive();
 	}

+ 19 - 11
L2J_Server_BETA/java/com/l2jserver/gameserver/model/actor/instance/L2PcInstance.java

@@ -11126,8 +11126,14 @@ public final class L2PcInstance extends L2Playable
 			return;
 		if (teleport)
 		{
-			if (_teleportWatchdog == null && Config.TELEPORT_WATCHDOG_TIMEOUT > 0)
-				_teleportWatchdog = ThreadPoolManager.getInstance().scheduleGeneral(new TeleportWatchdog(), Config.TELEPORT_WATCHDOG_TIMEOUT * 1000);
+			if ((_teleportWatchdog == null) && (Config.TELEPORT_WATCHDOG_TIMEOUT > 0))
+			{
+				synchronized(this)
+				{
+					if (_teleportWatchdog == null)
+						_teleportWatchdog = ThreadPoolManager.getInstance().scheduleGeneral(new TeleportWatchdog(), Config.TELEPORT_WATCHDOG_TIMEOUT * 1000);
+				}
+			}
 		}
 		else
 		{
@@ -11647,7 +11653,10 @@ public final class L2PcInstance extends L2Playable
 		}
 		
 		// Remove from world regions zones
-		L2WorldRegion oldRegion = getWorldRegion();
+		final L2WorldRegion oldRegion = getWorldRegion();
+		
+		if (oldRegion != null)
+			oldRegion.removeFromZones(this);
 		
 		// Remove the L2PcInstance from the world
 		try
@@ -11659,18 +11668,17 @@ public final class L2PcInstance extends L2Playable
 			_log.log(Level.SEVERE, "deleteMe()", e);
 		}
 		
-		if (oldRegion != null)
-			oldRegion.removeFromZones(this);
-		
 		// If a Party is in progress, leave it (and festival party)
 		if (isInParty())
-			try
 		{
+			try
+			{
 				leaveParty();
-		}
-		catch (Exception e)
-		{
-			_log.log(Level.SEVERE, "deleteMe()", e);
+			}
+			catch (Exception e)
+			{
+				_log.log(Level.SEVERE, "deleteMe()", e);
+			}
 		}
 		
 		if (OlympiadManager.getInstance().isRegistered(this) || getOlympiadGameId() != -1) // handle removal from olympiad game

+ 31 - 31
L2J_Server_BETA/java/com/l2jserver/gameserver/network/clientpackets/CharacterSelect.java

@@ -14,7 +14,6 @@
  */
 package com.l2jserver.gameserver.network.clientpackets;
 
-
 import java.util.logging.Level;
 import java.util.logging.LogRecord;
 import java.util.logging.Logger;
@@ -24,11 +23,12 @@ import com.l2jserver.gameserver.datatables.CharNameTable;
 import com.l2jserver.gameserver.instancemanager.AntiFeedManager;
 import com.l2jserver.gameserver.model.CharSelectInfoPackage;
 import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
+import com.l2jserver.gameserver.network.L2GameClient;
 import com.l2jserver.gameserver.network.L2GameClient.GameClientState;
 import com.l2jserver.gameserver.network.serverpackets.CharSelected;
 import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
 import com.l2jserver.gameserver.network.serverpackets.SSQInfo;
-
+import com.l2jserver.gameserver.network.serverpackets.ServerClose;
 
 /**
  * This class ...
@@ -66,36 +66,42 @@ public class CharacterSelect extends L2GameClientPacket
 	@Override
 	protected void runImpl()
 	{
-		if (!getClient().getFloodProtectors().getCharacterSelect().tryPerformAction("CharacterSelect"))
+		final L2GameClient client = getClient();
+		if (!client.getFloodProtectors().getCharacterSelect().tryPerformAction("CharacterSelect"))
 			return;
 		
-		if (Config.SECOND_AUTH_ENABLED && !getClient().getSecondaryAuth().isAuthed())
+		if (Config.SECOND_AUTH_ENABLED && !client.getSecondaryAuth().isAuthed())
 		{
-			getClient().getSecondaryAuth().openDialog();
+			client.getSecondaryAuth().openDialog();
 			return;
 		}
 		
-		// we should always be abble to acquire the lock
-		// but if we cant lock then nothing should be done (ie repeated packet)
-		if (this.getClient().getActiveCharLock().tryLock())
+		// We should always be able to acquire the lock
+		// But if we can't lock then nothing should be done (i.e. repeated packet)
+		if (client.getActiveCharLock().tryLock())
 		{
 			try
 			{
 				// should always be null
 				// but if not then this is repeated packet and nothing should be done here
-				if (this.getClient().getActiveChar() == null)
+				if (client.getActiveChar() == null)
 				{
-					if (Config.L2JMOD_DUALBOX_CHECK_MAX_PLAYERS_PER_IP > 0
-							&& !AntiFeedManager.getInstance().tryAddClient(AntiFeedManager.GAME_ID, getClient(), Config.L2JMOD_DUALBOX_CHECK_MAX_PLAYERS_PER_IP))
+					final CharSelectInfoPackage info = client.getCharSelection(_charSlot);
+					if (info == null)
+						return;
+					
+					//Selected character is banned.
+					if (info.getAccessLevel() < 0)
+					{
+						client.close(ServerClose.STATIC_PACKET);
+						return;
+					}
+					if ((Config.L2JMOD_DUALBOX_CHECK_MAX_PLAYERS_PER_IP > 0) && !AntiFeedManager.getInstance().tryAddClient(AntiFeedManager.GAME_ID, client, Config.L2JMOD_DUALBOX_CHECK_MAX_PLAYERS_PER_IP))
 					{
-						final CharSelectInfoPackage info = getClient().getCharSelection(_charSlot);
-						if (info == null)
-							return;
-
 						final NpcHtmlMessage msg = new NpcHtmlMessage(0);
 						msg.setFile(info.getHtmlPrefix(), "data/html/mods/IPRestriction.htm");
-						msg.replace("%max%", String.valueOf(AntiFeedManager.getInstance().getLimit(getClient(), Config.L2JMOD_DUALBOX_CHECK_MAX_PLAYERS_PER_IP)));
-						getClient().sendPacket(msg);
+						msg.replace("%max%", String.valueOf(AntiFeedManager.getInstance().getLimit(client, Config.L2JMOD_DUALBOX_CHECK_MAX_PLAYERS_PER_IP)));
+						client.sendPacket(msg);
 						return;
 					}
 
@@ -106,41 +112,35 @@ public class CharacterSelect extends L2GameClientPacket
 					}
 					
 					//load up character from disk
-					L2PcInstance cha = getClient().loadCharFromDisk(_charSlot);
+					final L2PcInstance cha = client.loadCharFromDisk(_charSlot);
 					if (cha == null)
 						return; // handled in L2GameClient
 					
-					if (cha.getAccessLevel().getLevel() < 0)
-					{
-						cha.logout();
-						return;
-					}
-					
 					CharNameTable.getInstance().addName(cha);
 					
-					cha.setClient(this.getClient());
-					getClient().setActiveChar(cha);
+					cha.setClient(client);
+					client.setActiveChar(cha);
 					cha.setOnlineStatus(true, true);
 					
 					sendPacket(new SSQInfo());
 					
-					this.getClient().setState(GameClientState.IN_GAME);
-					CharSelected cs = new CharSelected(cha, getClient().getSessionId().playOkID1);
+					client.setState(GameClientState.IN_GAME);
+					CharSelected cs = new CharSelected(cha, client.getSessionId().playOkID1);
 					sendPacket(cs);
 				}
 			}
 			finally
 			{
-				this.getClient().getActiveCharLock().unlock();
+				client.getActiveCharLock().unlock();
 			}
 			
 			LogRecord record = new LogRecord(Level.INFO, "Logged in");
-			record.setParameters(new Object[]{this.getClient()});
+			record.setParameters(new Object[]{ client });
 			_logAccounting.log(record);
 		}
 	}
 	
-	/* (non-Javadoc)
+	/**
 	 * @see com.l2jserver.gameserver.clientpackets.ClientBasePacket#getType()
 	 */
 	@Override

+ 7 - 10
L2J_Server_BETA/java/com/l2jserver/gameserver/network/serverpackets/CharSelectionInfo.java

@@ -41,15 +41,16 @@ import com.l2jserver.gameserver.network.L2GameClient;
 public class CharSelectionInfo extends L2GameServerPacket
 {
 	// d SdSddddddddddffddddddddddddddddddddddddddddddddddddddddddddddffd
-	private static final String _S__1F_CHARSELECTINFO = "[S] 09 CharSelectInfo";
+	private static final String _S__09_CHARSELECTINFO = "[S] 09 CharSelectInfo";
 	private static Logger _log = Logger.getLogger(CharSelectionInfo.class.getName());
 	private String _loginName;
 	private int _sessionId, _activeId;
 	private CharSelectInfoPackage[] _characterPackages;
-	
-	
+
 	/**
-	 * @param _characters
+	 * Constructor for CharSelectionInfo.
+	 * @param loginName
+	 * @param sessionId
 	 */
 	public CharSelectionInfo(String loginName, int sessionId)
 	{
@@ -217,7 +218,6 @@ public class CharSelectionInfo extends L2GameServerPacket
 		List<CharSelectInfoPackage> characterList = new FastList<CharSelectInfoPackage>();
 		
 		Connection con = null;
-		
 		try
 		{
 			con = L2DatabaseFactory.getInstance().getConnection();
@@ -245,14 +245,12 @@ public class CharSelectionInfo extends L2GameServerPacket
 		{
 			L2DatabaseFactory.close(con);
 		}
-		
 		return new CharSelectInfoPackage[0];
 	}
 	
 	private static void loadCharacterSubclassInfo(CharSelectInfoPackage charInfopackage, int ObjectId, int activeClassId)
 	{
 		Connection con = null;
-		
 		try
 		{
 			con = L2DatabaseFactory.getInstance().getConnection();
@@ -280,10 +278,8 @@ public class CharSelectionInfo extends L2GameServerPacket
 		{
 			try { L2DatabaseFactory.close(con); } catch (Exception e) {}
 		}
-		
 	}
 	
-	
 	private static CharSelectInfoPackage restoreChar(ResultSet chardata) throws Exception
 	{
 		int objectId = chardata.getInt("charId");
@@ -305,6 +301,7 @@ public class CharSelectionInfo extends L2GameServerPacket
 		}
 		
 		CharSelectInfoPackage charInfopackage = new CharSelectInfoPackage(objectId, name);
+		charInfopackage.setAccessLevel(chardata.getByte("accesslevel"));
 		charInfopackage.setLevel(chardata.getInt("level"));
 		charInfopackage.setMaxHp(chardata.getInt("maxhp"));
 		charInfopackage.setCurrentHp(chardata.getDouble("curhp"));
@@ -415,6 +412,6 @@ public class CharSelectionInfo extends L2GameServerPacket
 	@Override
 	public String getType()
 	{
-		return _S__1F_CHARSELECTINFO;
+		return _S__09_CHARSELECTINFO;
 	}
 }