Przeglądaj źródła

Updated MMOCore. If there are any problems, feel free to Revert. Big tnx to Forsaiken!

nBd 16 lat temu
rodzic
commit
d7ba51ebfa

+ 1 - 0
L2_GameServer/build.xml

@@ -209,6 +209,7 @@
     	<copy todir="${build.dist.login}/config">
 			<fileset dir="java/config">
 				<include name="loginserver.properties"/>
+				<include name="mmo.properties"/>
 				<include name="telnet.properties"/>
 			</fileset>
 		</copy>

+ 21 - 0
L2_GameServer/java/config/mmo.properties

@@ -0,0 +1,21 @@
+#---------------------------------------------------------------
+#--MMO------------------------------------------------------
+#---------------------------------------------------------------
+
+# Sleep time for all Selectors
+# After he finished his job the Selector waits the given time in milliseconds
+# Lower values will speed up the loop and the Ping is smaller
+SleepTime = 20
+
+# Every loop it send a maximum of the given packages to each connection
+# Lower values will speed up the loop and the Ping is smaller but cause less output
+MaxSendPerPass = 12
+
+# Every loop it read a maximum of the given packages from each connection
+# Lower values will speed up the loop and the Ping is smaller but cause less input
+MaxReadPerPass = 12
+
+# Each unfinished read/write need a TEMP storage Buffer
+# on large player amount we need more Buffers
+# if there are not enough buffers new ones are generated but not stored for future usage
+HelperBufferCount = 20

+ 53 - 0
L2_GameServer/java/net/sf/l2j/Config.java

@@ -57,6 +57,7 @@ public final class Config
 	public static final String SIEGE_CONFIGURATION_FILE = "./config/siege.properties";
 	public static final String TELNET_FILE = "./config/telnet.properties";
 	public static final String FLOOD_PROTECTOR_FILE = "./config/floodprotector.properties";
+	public static final String MMO_CONFIG_FILE = "./config/mmo.properties";
 
 
 	//--------------------------------------------------
@@ -709,6 +710,20 @@ public final class Config
 	public static int MIN_PROTOCOL_REVISION;
 	public static int MAX_PROTOCOL_REVISION;
 	public static boolean LOG_LOGIN_CONTROLLER;
+	
+	/** ************************************************** **/
+	/** MMO Settings - Begin **/
+	/** ************************************************** **/
+	
+	public static int MMO_SELECTOR_SLEEP_TIME;
+	public static int MMO_MAX_SEND_PER_PASS;
+	public static int MMO_MAX_READ_PER_PASS;
+	public static int MMO_HELPER_BUFFER_COUNT;
+	public static int MMO_IO_SELECTOR_THREAD_COUNT;
+	
+	/** ************************************************** **/
+	/** MMO Settings - End **/
+	/** ************************************************** **/
 
 
 	//--------------------------------------------------
@@ -1305,6 +1320,25 @@ public final class Config
 					e.printStackTrace();
 					throw new Error("Failed to Load "+TELNET_FILE+" File.");
 				}
+				
+				// MMO
+				try
+				{
+					_log.info("Loading " + MMO_CONFIG_FILE.replaceAll("./config/", ""));
+					Properties mmoSettings = new Properties();
+					is = new FileInputStream(new File(MMO_CONFIG_FILE));
+					mmoSettings.load(is);
+					MMO_SELECTOR_SLEEP_TIME = Integer.parseInt(mmoSettings.getProperty("SleepTime", "20"));
+					MMO_IO_SELECTOR_THREAD_COUNT = Integer.parseInt(mmoSettings.getProperty("IOSelectorThreadCount", "2"));
+					MMO_MAX_SEND_PER_PASS = Integer.parseInt(mmoSettings.getProperty("MaxSendPerPass", "12"));
+					MMO_MAX_READ_PER_PASS = Integer.parseInt(mmoSettings.getProperty("MaxReadPerPass", "12"));
+					MMO_HELPER_BUFFER_COUNT = Integer.parseInt(mmoSettings.getProperty("HelperBufferCount", "20"));
+				}
+				catch (Exception e)
+				{
+					e.printStackTrace();
+					throw new Error("Failed to Load " + MMO_CONFIG_FILE + " File.");
+				}
 
 				// Load IdFactory Properties file (if exists)
 				try
@@ -1976,6 +2010,25 @@ public final class Config
 					e.printStackTrace();
 					throw new Error("Failed to Load "+CONFIGURATION_FILE+" File.");
 				}
+				
+				// MMO 
+				try
+				{
+					_log.info("Loading " + MMO_CONFIG_FILE.replaceAll("./config/", ""));
+					Properties mmoSettings = new Properties();
+					is = new FileInputStream(new File(MMO_CONFIG_FILE));
+					mmoSettings.load(is);
+					MMO_SELECTOR_SLEEP_TIME = Integer.parseInt(mmoSettings.getProperty("SleepTime", "20"));
+					MMO_IO_SELECTOR_THREAD_COUNT = Integer.parseInt(mmoSettings.getProperty("IOSelectorThreadCount", "2"));
+					MMO_MAX_SEND_PER_PASS = Integer.parseInt(mmoSettings.getProperty("MaxSendPerPass", "12"));
+					MMO_MAX_READ_PER_PASS = Integer.parseInt(mmoSettings.getProperty("MaxReadPerPass", "12"));
+					MMO_HELPER_BUFFER_COUNT = Integer.parseInt(mmoSettings.getProperty("HelperBufferCount", "20"));
+				}
+				catch (Exception e)
+				{
+					e.printStackTrace();
+					throw new Error("Failed to Load " + MMO_CONFIG_FILE + " File.");
+				}
 
 				// Load Telnet Properties file (if exists)
 				try

+ 8 - 6
L2_GameServer/java/net/sf/l2j/gameserver/GameServer.java

@@ -480,12 +480,14 @@ public class GameServer
 		_loginThread = LoginServerThread.getInstance();
 		_loginThread.start();
 		
-		L2GamePacketHandler gph = new L2GamePacketHandler();
-		SelectorConfig<L2GameClient> sc = new SelectorConfig<L2GameClient>(null, null, gph, gph);
-		sc.setMaxSendPerPass(12);
-		sc.setSelectorSleepTime(20);
-		
-		_selectorThread = new SelectorThread<L2GameClient>(sc, gph, gph, null);
+		final SelectorConfig sc = new SelectorConfig();
+		sc.MAX_READ_PER_PASS = Config.MMO_MAX_READ_PER_PASS;
+		sc.MAX_SEND_PER_PASS = Config.MMO_MAX_SEND_PER_PASS;
+		sc.SLEEP_TIME = Config.MMO_SELECTOR_SLEEP_TIME;
+		sc.HELPER_BUFFER_COUNT = Config.MMO_HELPER_BUFFER_COUNT;
+		
+		final L2GamePacketHandler gph = new L2GamePacketHandler();
+		_selectorThread = new SelectorThread<L2GameClient>(sc, gph, gph, gph, null);
 		
 		InetAddress bindAddress = null;
 		if (!Config.GAMESERVER_HOSTNAME.equals("*"))

+ 2 - 3
L2_GameServer/java/net/sf/l2j/gameserver/network/L2GameClient.java

@@ -546,10 +546,9 @@ public final class L2GameClient extends MMOClient<MMOConnection<L2GameClient>>
     	}
     }
 
-    @Override
     public void closeNow()
     {
-    	super.closeNow();
+    	super.getConnection().close(null);
     	cleanMe(true);
     }
     
@@ -561,7 +560,7 @@ public final class L2GameClient extends MMOClient<MMOConnection<L2GameClient>>
 	{
 		try
 		{
-			InetAddress address = getConnection().getSocket().getInetAddress();
+			InetAddress address = getConnection().getInetAddress();
 			switch (getState())
 			{
 				case CONNECTED:

+ 1 - 32
L2_GameServer/java/net/sf/l2j/gameserver/network/L2GamePacketHandler.java

@@ -15,7 +15,6 @@
 package net.sf.l2j.gameserver.network;
 
 import java.nio.ByteBuffer;
-import java.nio.channels.SelectionKey;
 import java.util.concurrent.RejectedExecutionException;
 import java.util.logging.Logger;
 
@@ -25,13 +24,11 @@ import net.sf.l2j.gameserver.network.L2GameClient.GameClientState;
 import net.sf.l2j.gameserver.network.clientpackets.*;
 import net.sf.l2j.util.Util;
 
-import org.mmocore.network.HeaderInfo;
 import org.mmocore.network.IClientFactory;
 import org.mmocore.network.IMMOExecutor;
 import org.mmocore.network.IPacketHandler;
 import org.mmocore.network.MMOConnection;
 import org.mmocore.network.ReceivablePacket;
-import org.mmocore.network.TCPHeaderHandler;
 
 /**
  * Stateful Packet Handler<BR>
@@ -42,16 +39,8 @@ import org.mmocore.network.TCPHeaderHandler;
  * Note: If for a given exception a packet needs to be handled on more then one state, then it should be added to all these states.
  * @author  KenM
  */
-public final class L2GamePacketHandler extends TCPHeaderHandler<L2GameClient> implements IPacketHandler<L2GameClient>, IClientFactory<L2GameClient>, IMMOExecutor<L2GameClient>
+public final class L2GamePacketHandler implements IPacketHandler<L2GameClient>, IClientFactory<L2GameClient>, IMMOExecutor<L2GameClient>
 {
-	/**
-     * @param subHeaderHandler
-     */
-    public L2GamePacketHandler()
-    {
-        super(null);
-    }
-
     private static final Logger _log = Logger.getLogger(L2GamePacketHandler.class.getName());
 
 	// implementation
@@ -1067,24 +1056,4 @@ public final class L2GamePacketHandler extends TCPHeaderHandler<L2GameClient> im
 			}
 		}
 	}
-    
-    /**
-     * @see org.mmocore.network.TCPHeaderHandler#handleHeader(java.nio.channels.SelectionKey, java.nio.ByteBuffer)
-     */
-    @SuppressWarnings("unchecked")
-    @Override
-    public HeaderInfo handleHeader(SelectionKey key, ByteBuffer buf)
-    {
-        if (buf.remaining() >= 2)
-        {
-            int dataPending = (buf.getShort() & 0xffff) - 2;
-            L2GameClient client = ((MMOConnection<L2GameClient>) key.attachment()).getClient(); 
-            return this.getHeaderInfoReturn().set(0, dataPending, false, client);
-        }
-        else
-        {
-            L2GameClient client = ((MMOConnection<L2GameClient>) key.attachment()).getClient(); 
-            return this.getHeaderInfoReturn().set(2 - buf.remaining(), 0, false, client);
-        }
-    }
 }

+ 0 - 18
L2_GameServer/java/net/sf/l2j/gameserver/network/serverpackets/L2GameServerPacket.java

@@ -79,22 +79,4 @@ public abstract class L2GameServerPacket extends SendablePacket<L2GameClient>
 	 * @return A String with this packet name for debuging purposes
 	 */
 	public abstract String getType();
-
-    /**
-     * @see org.mmocore.network.SendablePacket#getHeaderSize()
-     */
-    @Override
-    protected int getHeaderSize()
-    {
-        return 2;
-    }
-
-    /**
-     * @see org.mmocore.network.SendablePacket#writeHeader(int)
-     */
-    @Override
-    protected void writeHeader(int dataSize)
-    {
-        writeH(dataSize + this.getHeaderSize());
-    }
 }

+ 11 - 5
L2_GameServer/java/net/sf/l2j/loginserver/L2LoginClient.java

@@ -69,7 +69,7 @@ public final class L2LoginClient extends MMOClient<MMOConnection<L2LoginClient>>
 	{
 		super(con);
 		_state = LoginClientState.CONNECTED;
-		String ip = getConnection().getSocket().getInetAddress().getHostAddress();
+		String ip = getConnection().getInetAddress().getHostAddress();
 
 		if (Util.isInternalIP(ip))
 		{
@@ -103,7 +103,7 @@ public final class L2LoginClient extends MMOClient<MMOConnection<L2LoginClient>>
 		catch (IOException e)
 		{
 			e.printStackTrace();
-			closeNow();
+			super.getConnection().close(null);
 			return false;
 		}
 
@@ -112,7 +112,7 @@ public final class L2LoginClient extends MMOClient<MMOConnection<L2LoginClient>>
 			byte[] dump = new byte[size];
 			System.arraycopy(buf.array(), buf.position(), dump, 0, size);
 			_log.warning("Wrong checksum from client: "+toString());
-			closeNow();
+			super.getConnection().close(null);
 		}
 
 		return ret;
@@ -265,7 +265,7 @@ public final class L2LoginClient extends MMOClient<MMOConnection<L2LoginClient>>
 	@Override
 	public String toString()
 	{
-		InetAddress address = getConnection().getSocket().getInetAddress();
+		InetAddress address = getConnection().getInetAddress();
 		if (getState() == LoginClientState.AUTHED_LOGIN)
 		{
 			return "["+getAccount()+" ("+(address == null ? "disconnected" : address.getHostAddress())+")]";
@@ -275,4 +275,10 @@ public final class L2LoginClient extends MMOClient<MMOConnection<L2LoginClient>>
 			return "["+(address == null ? "disconnected" : address.getHostAddress())+"]";
 		}
 	}
-}
+	
+	@Override
+	protected void onForcedDisconnection()
+	{
+		// Empty
+	}
+}

+ 10 - 6
L2_GameServer/java/net/sf/l2j/loginserver/L2LoginServer.java

@@ -177,17 +177,21 @@ public class L2LoginServer
 		}
 
 		
-		L2LoginPacketHandler loginPacketHandler = new L2LoginPacketHandler();
-		SelectorHelper sh = new SelectorHelper();
-        SelectorConfig ssc = new SelectorConfig(null, null, sh, loginPacketHandler);
+		final SelectorConfig sc = new SelectorConfig();
+		sc.MAX_READ_PER_PASS = Config.MMO_MAX_READ_PER_PASS;
+		sc.MAX_SEND_PER_PASS = Config.MMO_MAX_SEND_PER_PASS;
+		sc.SLEEP_TIME = Config.MMO_SELECTOR_SLEEP_TIME;
+		sc.HELPER_BUFFER_COUNT = Config.MMO_HELPER_BUFFER_COUNT;
+		
+		final L2LoginPacketHandler lph = new L2LoginPacketHandler();
+		final SelectorHelper sh = new SelectorHelper();
 		try
 		{
-			_selectorThread = new SelectorThread<L2LoginClient>(ssc, sh, sh, sh);
-			_selectorThread.setAcceptFilter(sh);
+			_selectorThread = new SelectorThread<L2LoginClient>(sc, sh, lph, sh, sh);
 		}
 		catch (IOException e)
 		{
-			_log.log(Level.SEVERE, "FATAL: Failed to open Selector. Reason: "+e.getMessage(), e);
+			_log.log(Level.SEVERE, "FATAL: Failed to open Selector. Reason: " + e.getMessage(), e);
 			if (Config.DEVELOPER)
 			{
 				e.printStackTrace();

+ 1 - 1
L2_GameServer/java/net/sf/l2j/loginserver/LoginController.java

@@ -533,7 +533,7 @@ public class LoginController
 	public boolean loginValid(String user, String password, L2LoginClient client)// throws HackingException
 	{
 		boolean ok = false;
-		InetAddress address = client.getConnection().getSocket().getInetAddress();
+		InetAddress address = client.getConnection().getInetAddress();
 		// log it anyway
 		if (Config.LOG_LOGIN_CONTROLLER)
 			Log.add("'" + (user == null ? "null" : user) + "' " + (address == null ? "null" : address.getHostAddress()), "logins_ip");

+ 1 - 27
L2_GameServer/java/net/sf/l2j/loginserver/SelectorHelper.java

@@ -14,8 +14,6 @@
  */
 package net.sf.l2j.loginserver;
 
-import java.nio.ByteBuffer;
-import java.nio.channels.SelectionKey;
 import java.nio.channels.SocketChannel;
 import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.ThreadPoolExecutor;
@@ -23,25 +21,22 @@ import java.util.concurrent.TimeUnit;
 
 import net.sf.l2j.loginserver.serverpackets.Init;
 
-import org.mmocore.network.HeaderInfo;
 import org.mmocore.network.IAcceptFilter;
 import org.mmocore.network.IClientFactory;
 import org.mmocore.network.IMMOExecutor;
 import org.mmocore.network.MMOConnection;
 import org.mmocore.network.ReceivablePacket;
-import org.mmocore.network.TCPHeaderHandler;
 
 /**
  *
  * @author  KenM
  */
-public class SelectorHelper extends TCPHeaderHandler<L2LoginClient> implements IMMOExecutor<L2LoginClient>, IClientFactory<L2LoginClient>, IAcceptFilter
+public class SelectorHelper implements IMMOExecutor<L2LoginClient>, IClientFactory<L2LoginClient>, IAcceptFilter
 {
 	private ThreadPoolExecutor _generalPacketsThreadPool;
 
     public SelectorHelper()
 	{
-        super(null);
 		_generalPacketsThreadPool = new ThreadPoolExecutor(4, 6, 15L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
 	}
 
@@ -70,25 +65,4 @@ public class SelectorHelper extends TCPHeaderHandler<L2LoginClient> implements I
 	{
 		return !LoginController.getInstance().isBannedAddress(sc.socket().getInetAddress());
 	}
-
-    /**
-     * @see org.mmocore.network.TCPHeaderHandler#handleHeader(java.nio.channels.SelectionKey, java.nio.ByteBuffer)
-     */
-    @SuppressWarnings("unchecked")
-    @Override
-    public HeaderInfo handleHeader(SelectionKey key, ByteBuffer buf)
-    {
-        if (buf.remaining() >= 2)
-        {
-            int dataPending = (buf.getShort() & 0xffff) - 2;
-            L2LoginClient client = ((MMOConnection<L2LoginClient>) key.attachment()).getClient(); 
-            return this.getHeaderInfoReturn().set(0, dataPending, false, client);
-        }
-        else
-        {
-            L2LoginClient client = ((MMOConnection<L2LoginClient>) key.attachment()).getClient(); 
-            return this.getHeaderInfoReturn().set(2 - buf.remaining(), 0, false, client);
-        }
-    }
-
 }

+ 1 - 1
L2_GameServer/java/net/sf/l2j/loginserver/clientpackets/AuthGameGuard.java

@@ -62,7 +62,7 @@ public class AuthGameGuard extends L2LoginClientPacket
 	@Override
 	protected boolean readImpl()
 	{
-		if (getAvaliableBytes() >= 20)
+		if (super._buf.remaining() >= 20)
 		{
 			_sessionId = readD();
 			_data1 = readD();

+ 2 - 2
L2_GameServer/java/net/sf/l2j/loginserver/clientpackets/RequestAuthLogin.java

@@ -72,7 +72,7 @@ public class RequestAuthLogin extends L2LoginClientPacket
 	@Override
 	public boolean readImpl()
 	{
-		if (getAvaliableBytes() >= 128)
+		if (super._buf.remaining() >= 128)
 		{
 			readB(_raw);
 			return true;
@@ -162,7 +162,7 @@ public class RequestAuthLogin extends L2LoginClientPacket
 		}
 		catch (HackingException e)
 		{
-			InetAddress address = getClient().getConnection().getSocket().getInetAddress();
+			InetAddress address = getClient().getConnection().getInetAddress();
 			lc.addBanForAddress(address, Config.LOGIN_BLOCK_AFTER_BAN*1000);
 			_log.info("Banned ("+address+") for "+Config.LOGIN_BLOCK_AFTER_BAN+" seconds, due to "+e.getConnects()+" incorrect login attempts.");
 		}

+ 1 - 1
L2_GameServer/java/net/sf/l2j/loginserver/clientpackets/RequestServerList.java

@@ -56,7 +56,7 @@ public class RequestServerList extends L2LoginClientPacket
 	@Override
 	public boolean readImpl()
 	{
-		if (getAvaliableBytes() >= 8)
+		if (super._buf.remaining() >= 8)
 		{
 			_skey1  = readD(); // loginOk 1
 			_skey2  = readD(); // loginOk 2

+ 1 - 1
L2_GameServer/java/net/sf/l2j/loginserver/clientpackets/RequestServerLogin.java

@@ -60,7 +60,7 @@ public class RequestServerLogin extends L2LoginClientPacket
 	@Override
 	public boolean readImpl()
 	{
-		if (getAvaliableBytes() >= 9)
+		if (super._buf.remaining() >= 9)
 		{
 			_skey1 = readD();
 			_skey2 = readD();

+ 1 - 19
L2_GameServer/java/net/sf/l2j/loginserver/serverpackets/L2LoginServerPacket.java

@@ -24,23 +24,5 @@ import org.mmocore.network.SendablePacket;
  */
 public abstract class L2LoginServerPacket extends SendablePacket<L2LoginClient>
 {
-
-    /**
-     * @see org.mmocore.network.SendablePacket#getHeaderSize()
-     */
-    @Override
-    protected int getHeaderSize()
-    {
-        return 2;
-    }
-
-    /**
-     * @see org.mmocore.network.SendablePacket#writeHeader(int)
-     */
-    @Override
-    protected void writeHeader(int dataSize)
-    {
-        writeH(dataSize + this.getHeaderSize());
-    }
-    
+	
 }

BIN
L2_GameServer/lib/mmocore.jar