Bläddra i källkod

GS<->LS communication fix.

JIV 15 år sedan
förälder
incheckning
701fb14d26

+ 6 - 8
L2_GameServer/java/com/l2jserver/gameserver/LoginServerThread.java

@@ -162,16 +162,16 @@ public class LoginServerThread extends Thread
 						break;
 					}
 					
-					byte[] incoming = new byte[length];
-					incoming[0] = (byte) lengthLo;
-					incoming[1] = (byte) lengthHi;
+					byte[] incoming = new byte[length - 2];
 					
 					int receivedBytes = 0;
 					int newBytes = 0;
-					while (newBytes != -1 && receivedBytes < length - 2)
+					int left = length - 2;
+					while (newBytes != -1 && receivedBytes < left)
 					{
-						newBytes = _in.read(incoming, 2, length - 2);
+						newBytes =  _in.read(incoming, receivedBytes, left);
 						receivedBytes = receivedBytes + newBytes;
+						left -= newBytes;
 					}
 					
 					if (receivedBytes != length - 2)
@@ -180,10 +180,8 @@ public class LoginServerThread extends Thread
 						break;
 					}
 					
-					byte[] decrypt = new byte[length - 2];
-					System.arraycopy(incoming, 2, decrypt, 0, decrypt.length);
 					// decrypt if we have a key
-					decrypt = _blowfish.decrypt(decrypt);
+					byte[] decrypt = _blowfish.decrypt(incoming);
 					checksumOk = NewCrypt.verifyChecksum(decrypt);
 					
 					if (!checksumOk)

+ 4 - 2
L2_GameServer/java/com/l2jserver/loginserver/GameServerThread.java

@@ -113,10 +113,12 @@ public class GameServerThread extends Thread
 
 				int receivedBytes = 0;
 				int newBytes = 0;
-				while (newBytes != -1 && receivedBytes<length-2)
+				int left = length - 2;
+				while (newBytes != -1 && receivedBytes < left)
 				{
-					newBytes =  _in.read(data, 0, length-2);
+					newBytes =  _in.read(data, receivedBytes, left);
 					receivedBytes = receivedBytes + newBytes;
+					left -= newBytes;
 				}
 
 				if (receivedBytes != length-2)