From 2340f45354fc31b2eb4c3fdc7505066be1af9b34 Mon Sep 17 00:00:00 2001 From: MobiusDevelopment <8391001+MobiusDevelopment@users.noreply.github.com> Date: Sun, 11 Dec 2022 22:02:34 +0000 Subject: [PATCH] Continue read if data length is less than expected. --- .../l2jmobius/commons/network/ReadThread.java | 17 ++++++++++++++++- .../l2jmobius/commons/network/ReadThread.java | 17 ++++++++++++++++- .../l2jmobius/commons/network/ReadThread.java | 17 ++++++++++++++++- .../l2jmobius/commons/network/ReadThread.java | 17 ++++++++++++++++- .../l2jmobius/commons/network/ReadThread.java | 17 ++++++++++++++++- .../l2jmobius/commons/network/ReadThread.java | 17 ++++++++++++++++- .../l2jmobius/commons/network/ReadThread.java | 17 ++++++++++++++++- .../l2jmobius/commons/network/ReadThread.java | 17 ++++++++++++++++- .../l2jmobius/commons/network/ReadThread.java | 17 ++++++++++++++++- .../l2jmobius/commons/network/ReadThread.java | 17 ++++++++++++++++- .../l2jmobius/commons/network/ReadThread.java | 17 ++++++++++++++++- .../l2jmobius/commons/network/ReadThread.java | 17 ++++++++++++++++- .../l2jmobius/commons/network/ReadThread.java | 17 ++++++++++++++++- .../l2jmobius/commons/network/ReadThread.java | 17 ++++++++++++++++- .../l2jmobius/commons/network/ReadThread.java | 17 ++++++++++++++++- .../l2jmobius/commons/network/ReadThread.java | 17 ++++++++++++++++- .../l2jmobius/commons/network/ReadThread.java | 17 ++++++++++++++++- .../l2jmobius/commons/network/ReadThread.java | 17 ++++++++++++++++- .../l2jmobius/commons/network/ReadThread.java | 17 ++++++++++++++++- .../l2jmobius/commons/network/ReadThread.java | 17 ++++++++++++++++- .../l2jmobius/commons/network/ReadThread.java | 17 ++++++++++++++++- .../l2jmobius/commons/network/ReadThread.java | 17 ++++++++++++++++- .../l2jmobius/commons/network/ReadThread.java | 17 ++++++++++++++++- .../l2jmobius/commons/network/ReadThread.java | 17 ++++++++++++++++- .../l2jmobius/commons/network/ReadThread.java | 17 ++++++++++++++++- .../l2jmobius/commons/network/ReadThread.java | 17 ++++++++++++++++- .../l2jmobius/commons/network/ReadThread.java | 17 ++++++++++++++++- .../l2jmobius/commons/network/ReadThread.java | 17 ++++++++++++++++- .../l2jmobius/commons/network/ReadThread.java | 17 ++++++++++++++++- .../l2jmobius/commons/network/ReadThread.java | 17 ++++++++++++++++- .../l2jmobius/commons/network/ReadThread.java | 17 ++++++++++++++++- 31 files changed, 496 insertions(+), 31 deletions(-) diff --git a/L2J_Mobius_01.0_Ertheia/java/org/l2jmobius/commons/network/ReadThread.java b/L2J_Mobius_01.0_Ertheia/java/org/l2jmobius/commons/network/ReadThread.java index af52d6fc40..9cf00e3486 100644 --- a/L2J_Mobius_01.0_Ertheia/java/org/l2jmobius/commons/network/ReadThread.java +++ b/L2J_Mobius_01.0_Ertheia/java/org/l2jmobius/commons/network/ReadThread.java @@ -64,7 +64,8 @@ public class ReadThread implements Runnable default: { // Allocate a new ByteBuffer based on packet size read. - final ByteBuffer packetByteBuffer = ByteBuffer.allocate(calculatePacketSize()); + final int packetSize = calculatePacketSize(); + final ByteBuffer packetByteBuffer = ByteBuffer.allocate(packetSize); switch (channel.read(packetByteBuffer)) { // Disconnected. @@ -81,6 +82,20 @@ public class ReadThread implements Runnable // Send data read to the client packet queue. default: { + // Continue read if data length is less than expected. + if (packetByteBuffer.position() < packetSize) + { + int attempt = 0; // Keep it under 10 attempts. + while ((attempt++ < 10) && (packetByteBuffer.position() < packetSize)) + { + final ByteBuffer additionalData = ByteBuffer.allocate(packetSize - packetByteBuffer.position()); + channel.read(additionalData); + packetByteBuffer.put(packetByteBuffer.position(), additionalData, 0, additionalData.position()); + packetByteBuffer.position(packetByteBuffer.position() + additionalData.position()); + } + } + + // Add packet data to client. client.addPacketData(packetByteBuffer.array()); } } diff --git a/L2J_Mobius_02.5_Underground/java/org/l2jmobius/commons/network/ReadThread.java b/L2J_Mobius_02.5_Underground/java/org/l2jmobius/commons/network/ReadThread.java index af52d6fc40..9cf00e3486 100644 --- a/L2J_Mobius_02.5_Underground/java/org/l2jmobius/commons/network/ReadThread.java +++ b/L2J_Mobius_02.5_Underground/java/org/l2jmobius/commons/network/ReadThread.java @@ -64,7 +64,8 @@ public class ReadThread implements Runnable default: { // Allocate a new ByteBuffer based on packet size read. - final ByteBuffer packetByteBuffer = ByteBuffer.allocate(calculatePacketSize()); + final int packetSize = calculatePacketSize(); + final ByteBuffer packetByteBuffer = ByteBuffer.allocate(packetSize); switch (channel.read(packetByteBuffer)) { // Disconnected. @@ -81,6 +82,20 @@ public class ReadThread implements Runnable // Send data read to the client packet queue. default: { + // Continue read if data length is less than expected. + if (packetByteBuffer.position() < packetSize) + { + int attempt = 0; // Keep it under 10 attempts. + while ((attempt++ < 10) && (packetByteBuffer.position() < packetSize)) + { + final ByteBuffer additionalData = ByteBuffer.allocate(packetSize - packetByteBuffer.position()); + channel.read(additionalData); + packetByteBuffer.put(packetByteBuffer.position(), additionalData, 0, additionalData.position()); + packetByteBuffer.position(packetByteBuffer.position() + additionalData.position()); + } + } + + // Add packet data to client. client.addPacketData(packetByteBuffer.array()); } } diff --git a/L2J_Mobius_03.0_Helios/java/org/l2jmobius/commons/network/ReadThread.java b/L2J_Mobius_03.0_Helios/java/org/l2jmobius/commons/network/ReadThread.java index af52d6fc40..9cf00e3486 100644 --- a/L2J_Mobius_03.0_Helios/java/org/l2jmobius/commons/network/ReadThread.java +++ b/L2J_Mobius_03.0_Helios/java/org/l2jmobius/commons/network/ReadThread.java @@ -64,7 +64,8 @@ public class ReadThread implements Runnable default: { // Allocate a new ByteBuffer based on packet size read. - final ByteBuffer packetByteBuffer = ByteBuffer.allocate(calculatePacketSize()); + final int packetSize = calculatePacketSize(); + final ByteBuffer packetByteBuffer = ByteBuffer.allocate(packetSize); switch (channel.read(packetByteBuffer)) { // Disconnected. @@ -81,6 +82,20 @@ public class ReadThread implements Runnable // Send data read to the client packet queue. default: { + // Continue read if data length is less than expected. + if (packetByteBuffer.position() < packetSize) + { + int attempt = 0; // Keep it under 10 attempts. + while ((attempt++ < 10) && (packetByteBuffer.position() < packetSize)) + { + final ByteBuffer additionalData = ByteBuffer.allocate(packetSize - packetByteBuffer.position()); + channel.read(additionalData); + packetByteBuffer.put(packetByteBuffer.position(), additionalData, 0, additionalData.position()); + packetByteBuffer.position(packetByteBuffer.position() + additionalData.position()); + } + } + + // Add packet data to client. client.addPacketData(packetByteBuffer.array()); } } diff --git a/L2J_Mobius_04.0_GrandCrusade/java/org/l2jmobius/commons/network/ReadThread.java b/L2J_Mobius_04.0_GrandCrusade/java/org/l2jmobius/commons/network/ReadThread.java index af52d6fc40..9cf00e3486 100644 --- a/L2J_Mobius_04.0_GrandCrusade/java/org/l2jmobius/commons/network/ReadThread.java +++ b/L2J_Mobius_04.0_GrandCrusade/java/org/l2jmobius/commons/network/ReadThread.java @@ -64,7 +64,8 @@ public class ReadThread implements Runnable default: { // Allocate a new ByteBuffer based on packet size read. - final ByteBuffer packetByteBuffer = ByteBuffer.allocate(calculatePacketSize()); + final int packetSize = calculatePacketSize(); + final ByteBuffer packetByteBuffer = ByteBuffer.allocate(packetSize); switch (channel.read(packetByteBuffer)) { // Disconnected. @@ -81,6 +82,20 @@ public class ReadThread implements Runnable // Send data read to the client packet queue. default: { + // Continue read if data length is less than expected. + if (packetByteBuffer.position() < packetSize) + { + int attempt = 0; // Keep it under 10 attempts. + while ((attempt++ < 10) && (packetByteBuffer.position() < packetSize)) + { + final ByteBuffer additionalData = ByteBuffer.allocate(packetSize - packetByteBuffer.position()); + channel.read(additionalData); + packetByteBuffer.put(packetByteBuffer.position(), additionalData, 0, additionalData.position()); + packetByteBuffer.position(packetByteBuffer.position() + additionalData.position()); + } + } + + // Add packet data to client. client.addPacketData(packetByteBuffer.array()); } } diff --git a/L2J_Mobius_05.0_Salvation/java/org/l2jmobius/commons/network/ReadThread.java b/L2J_Mobius_05.0_Salvation/java/org/l2jmobius/commons/network/ReadThread.java index af52d6fc40..9cf00e3486 100644 --- a/L2J_Mobius_05.0_Salvation/java/org/l2jmobius/commons/network/ReadThread.java +++ b/L2J_Mobius_05.0_Salvation/java/org/l2jmobius/commons/network/ReadThread.java @@ -64,7 +64,8 @@ public class ReadThread implements Runnable default: { // Allocate a new ByteBuffer based on packet size read. - final ByteBuffer packetByteBuffer = ByteBuffer.allocate(calculatePacketSize()); + final int packetSize = calculatePacketSize(); + final ByteBuffer packetByteBuffer = ByteBuffer.allocate(packetSize); switch (channel.read(packetByteBuffer)) { // Disconnected. @@ -81,6 +82,20 @@ public class ReadThread implements Runnable // Send data read to the client packet queue. default: { + // Continue read if data length is less than expected. + if (packetByteBuffer.position() < packetSize) + { + int attempt = 0; // Keep it under 10 attempts. + while ((attempt++ < 10) && (packetByteBuffer.position() < packetSize)) + { + final ByteBuffer additionalData = ByteBuffer.allocate(packetSize - packetByteBuffer.position()); + channel.read(additionalData); + packetByteBuffer.put(packetByteBuffer.position(), additionalData, 0, additionalData.position()); + packetByteBuffer.position(packetByteBuffer.position() + additionalData.position()); + } + } + + // Add packet data to client. client.addPacketData(packetByteBuffer.array()); } } diff --git a/L2J_Mobius_05.5_EtinasFate/java/org/l2jmobius/commons/network/ReadThread.java b/L2J_Mobius_05.5_EtinasFate/java/org/l2jmobius/commons/network/ReadThread.java index af52d6fc40..9cf00e3486 100644 --- a/L2J_Mobius_05.5_EtinasFate/java/org/l2jmobius/commons/network/ReadThread.java +++ b/L2J_Mobius_05.5_EtinasFate/java/org/l2jmobius/commons/network/ReadThread.java @@ -64,7 +64,8 @@ public class ReadThread implements Runnable default: { // Allocate a new ByteBuffer based on packet size read. - final ByteBuffer packetByteBuffer = ByteBuffer.allocate(calculatePacketSize()); + final int packetSize = calculatePacketSize(); + final ByteBuffer packetByteBuffer = ByteBuffer.allocate(packetSize); switch (channel.read(packetByteBuffer)) { // Disconnected. @@ -81,6 +82,20 @@ public class ReadThread implements Runnable // Send data read to the client packet queue. default: { + // Continue read if data length is less than expected. + if (packetByteBuffer.position() < packetSize) + { + int attempt = 0; // Keep it under 10 attempts. + while ((attempt++ < 10) && (packetByteBuffer.position() < packetSize)) + { + final ByteBuffer additionalData = ByteBuffer.allocate(packetSize - packetByteBuffer.position()); + channel.read(additionalData); + packetByteBuffer.put(packetByteBuffer.position(), additionalData, 0, additionalData.position()); + packetByteBuffer.position(packetByteBuffer.position() + additionalData.position()); + } + } + + // Add packet data to client. client.addPacketData(packetByteBuffer.array()); } } diff --git a/L2J_Mobius_06.0_Fafurion/java/org/l2jmobius/commons/network/ReadThread.java b/L2J_Mobius_06.0_Fafurion/java/org/l2jmobius/commons/network/ReadThread.java index af52d6fc40..9cf00e3486 100644 --- a/L2J_Mobius_06.0_Fafurion/java/org/l2jmobius/commons/network/ReadThread.java +++ b/L2J_Mobius_06.0_Fafurion/java/org/l2jmobius/commons/network/ReadThread.java @@ -64,7 +64,8 @@ public class ReadThread implements Runnable default: { // Allocate a new ByteBuffer based on packet size read. - final ByteBuffer packetByteBuffer = ByteBuffer.allocate(calculatePacketSize()); + final int packetSize = calculatePacketSize(); + final ByteBuffer packetByteBuffer = ByteBuffer.allocate(packetSize); switch (channel.read(packetByteBuffer)) { // Disconnected. @@ -81,6 +82,20 @@ public class ReadThread implements Runnable // Send data read to the client packet queue. default: { + // Continue read if data length is less than expected. + if (packetByteBuffer.position() < packetSize) + { + int attempt = 0; // Keep it under 10 attempts. + while ((attempt++ < 10) && (packetByteBuffer.position() < packetSize)) + { + final ByteBuffer additionalData = ByteBuffer.allocate(packetSize - packetByteBuffer.position()); + channel.read(additionalData); + packetByteBuffer.put(packetByteBuffer.position(), additionalData, 0, additionalData.position()); + packetByteBuffer.position(packetByteBuffer.position() + additionalData.position()); + } + } + + // Add packet data to client. client.addPacketData(packetByteBuffer.array()); } } diff --git a/L2J_Mobius_07.0_PreludeOfWar/java/org/l2jmobius/commons/network/ReadThread.java b/L2J_Mobius_07.0_PreludeOfWar/java/org/l2jmobius/commons/network/ReadThread.java index af52d6fc40..9cf00e3486 100644 --- a/L2J_Mobius_07.0_PreludeOfWar/java/org/l2jmobius/commons/network/ReadThread.java +++ b/L2J_Mobius_07.0_PreludeOfWar/java/org/l2jmobius/commons/network/ReadThread.java @@ -64,7 +64,8 @@ public class ReadThread implements Runnable default: { // Allocate a new ByteBuffer based on packet size read. - final ByteBuffer packetByteBuffer = ByteBuffer.allocate(calculatePacketSize()); + final int packetSize = calculatePacketSize(); + final ByteBuffer packetByteBuffer = ByteBuffer.allocate(packetSize); switch (channel.read(packetByteBuffer)) { // Disconnected. @@ -81,6 +82,20 @@ public class ReadThread implements Runnable // Send data read to the client packet queue. default: { + // Continue read if data length is less than expected. + if (packetByteBuffer.position() < packetSize) + { + int attempt = 0; // Keep it under 10 attempts. + while ((attempt++ < 10) && (packetByteBuffer.position() < packetSize)) + { + final ByteBuffer additionalData = ByteBuffer.allocate(packetSize - packetByteBuffer.position()); + channel.read(additionalData); + packetByteBuffer.put(packetByteBuffer.position(), additionalData, 0, additionalData.position()); + packetByteBuffer.position(packetByteBuffer.position() + additionalData.position()); + } + } + + // Add packet data to client. client.addPacketData(packetByteBuffer.array()); } } diff --git a/L2J_Mobius_08.2_Homunculus/java/org/l2jmobius/commons/network/ReadThread.java b/L2J_Mobius_08.2_Homunculus/java/org/l2jmobius/commons/network/ReadThread.java index af52d6fc40..9cf00e3486 100644 --- a/L2J_Mobius_08.2_Homunculus/java/org/l2jmobius/commons/network/ReadThread.java +++ b/L2J_Mobius_08.2_Homunculus/java/org/l2jmobius/commons/network/ReadThread.java @@ -64,7 +64,8 @@ public class ReadThread implements Runnable default: { // Allocate a new ByteBuffer based on packet size read. - final ByteBuffer packetByteBuffer = ByteBuffer.allocate(calculatePacketSize()); + final int packetSize = calculatePacketSize(); + final ByteBuffer packetByteBuffer = ByteBuffer.allocate(packetSize); switch (channel.read(packetByteBuffer)) { // Disconnected. @@ -81,6 +82,20 @@ public class ReadThread implements Runnable // Send data read to the client packet queue. default: { + // Continue read if data length is less than expected. + if (packetByteBuffer.position() < packetSize) + { + int attempt = 0; // Keep it under 10 attempts. + while ((attempt++ < 10) && (packetByteBuffer.position() < packetSize)) + { + final ByteBuffer additionalData = ByteBuffer.allocate(packetSize - packetByteBuffer.position()); + channel.read(additionalData); + packetByteBuffer.put(packetByteBuffer.position(), additionalData, 0, additionalData.position()); + packetByteBuffer.position(packetByteBuffer.position() + additionalData.position()); + } + } + + // Add packet data to client. client.addPacketData(packetByteBuffer.array()); } } diff --git a/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/commons/network/ReadThread.java b/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/commons/network/ReadThread.java index af52d6fc40..9cf00e3486 100644 --- a/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/commons/network/ReadThread.java +++ b/L2J_Mobius_09.2_ReturnOfTheQueenAnt/java/org/l2jmobius/commons/network/ReadThread.java @@ -64,7 +64,8 @@ public class ReadThread implements Runnable default: { // Allocate a new ByteBuffer based on packet size read. - final ByteBuffer packetByteBuffer = ByteBuffer.allocate(calculatePacketSize()); + final int packetSize = calculatePacketSize(); + final ByteBuffer packetByteBuffer = ByteBuffer.allocate(packetSize); switch (channel.read(packetByteBuffer)) { // Disconnected. @@ -81,6 +82,20 @@ public class ReadThread implements Runnable // Send data read to the client packet queue. default: { + // Continue read if data length is less than expected. + if (packetByteBuffer.position() < packetSize) + { + int attempt = 0; // Keep it under 10 attempts. + while ((attempt++ < 10) && (packetByteBuffer.position() < packetSize)) + { + final ByteBuffer additionalData = ByteBuffer.allocate(packetSize - packetByteBuffer.position()); + channel.read(additionalData); + packetByteBuffer.put(packetByteBuffer.position(), additionalData, 0, additionalData.position()); + packetByteBuffer.position(packetByteBuffer.position() + additionalData.position()); + } + } + + // Add packet data to client. client.addPacketData(packetByteBuffer.array()); } } diff --git a/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/commons/network/ReadThread.java b/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/commons/network/ReadThread.java index af52d6fc40..9cf00e3486 100644 --- a/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/commons/network/ReadThread.java +++ b/L2J_Mobius_10.2_MasterClass/java/org/l2jmobius/commons/network/ReadThread.java @@ -64,7 +64,8 @@ public class ReadThread implements Runnable default: { // Allocate a new ByteBuffer based on packet size read. - final ByteBuffer packetByteBuffer = ByteBuffer.allocate(calculatePacketSize()); + final int packetSize = calculatePacketSize(); + final ByteBuffer packetByteBuffer = ByteBuffer.allocate(packetSize); switch (channel.read(packetByteBuffer)) { // Disconnected. @@ -81,6 +82,20 @@ public class ReadThread implements Runnable // Send data read to the client packet queue. default: { + // Continue read if data length is less than expected. + if (packetByteBuffer.position() < packetSize) + { + int attempt = 0; // Keep it under 10 attempts. + while ((attempt++ < 10) && (packetByteBuffer.position() < packetSize)) + { + final ByteBuffer additionalData = ByteBuffer.allocate(packetSize - packetByteBuffer.position()); + channel.read(additionalData); + packetByteBuffer.put(packetByteBuffer.position(), additionalData, 0, additionalData.position()); + packetByteBuffer.position(packetByteBuffer.position() + additionalData.position()); + } + } + + // Add packet data to client. client.addPacketData(packetByteBuffer.array()); } } diff --git a/L2J_Mobius_10.3_MasterClass/java/org/l2jmobius/commons/network/ReadThread.java b/L2J_Mobius_10.3_MasterClass/java/org/l2jmobius/commons/network/ReadThread.java index af52d6fc40..9cf00e3486 100644 --- a/L2J_Mobius_10.3_MasterClass/java/org/l2jmobius/commons/network/ReadThread.java +++ b/L2J_Mobius_10.3_MasterClass/java/org/l2jmobius/commons/network/ReadThread.java @@ -64,7 +64,8 @@ public class ReadThread implements Runnable default: { // Allocate a new ByteBuffer based on packet size read. - final ByteBuffer packetByteBuffer = ByteBuffer.allocate(calculatePacketSize()); + final int packetSize = calculatePacketSize(); + final ByteBuffer packetByteBuffer = ByteBuffer.allocate(packetSize); switch (channel.read(packetByteBuffer)) { // Disconnected. @@ -81,6 +82,20 @@ public class ReadThread implements Runnable // Send data read to the client packet queue. default: { + // Continue read if data length is less than expected. + if (packetByteBuffer.position() < packetSize) + { + int attempt = 0; // Keep it under 10 attempts. + while ((attempt++ < 10) && (packetByteBuffer.position() < packetSize)) + { + final ByteBuffer additionalData = ByteBuffer.allocate(packetSize - packetByteBuffer.position()); + channel.read(additionalData); + packetByteBuffer.put(packetByteBuffer.position(), additionalData, 0, additionalData.position()); + packetByteBuffer.position(packetByteBuffer.position() + additionalData.position()); + } + } + + // Add packet data to client. client.addPacketData(packetByteBuffer.array()); } } diff --git a/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/commons/network/ReadThread.java b/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/commons/network/ReadThread.java index af52d6fc40..9cf00e3486 100644 --- a/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/commons/network/ReadThread.java +++ b/L2J_Mobius_C4_ScionsOfDestiny/java/org/l2jmobius/commons/network/ReadThread.java @@ -64,7 +64,8 @@ public class ReadThread implements Runnable default: { // Allocate a new ByteBuffer based on packet size read. - final ByteBuffer packetByteBuffer = ByteBuffer.allocate(calculatePacketSize()); + final int packetSize = calculatePacketSize(); + final ByteBuffer packetByteBuffer = ByteBuffer.allocate(packetSize); switch (channel.read(packetByteBuffer)) { // Disconnected. @@ -81,6 +82,20 @@ public class ReadThread implements Runnable // Send data read to the client packet queue. default: { + // Continue read if data length is less than expected. + if (packetByteBuffer.position() < packetSize) + { + int attempt = 0; // Keep it under 10 attempts. + while ((attempt++ < 10) && (packetByteBuffer.position() < packetSize)) + { + final ByteBuffer additionalData = ByteBuffer.allocate(packetSize - packetByteBuffer.position()); + channel.read(additionalData); + packetByteBuffer.put(packetByteBuffer.position(), additionalData, 0, additionalData.position()); + packetByteBuffer.position(packetByteBuffer.position() + additionalData.position()); + } + } + + // Add packet data to client. client.addPacketData(packetByteBuffer.array()); } } diff --git a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/commons/network/ReadThread.java b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/commons/network/ReadThread.java index af52d6fc40..9cf00e3486 100644 --- a/L2J_Mobius_C6_Interlude/java/org/l2jmobius/commons/network/ReadThread.java +++ b/L2J_Mobius_C6_Interlude/java/org/l2jmobius/commons/network/ReadThread.java @@ -64,7 +64,8 @@ public class ReadThread implements Runnable default: { // Allocate a new ByteBuffer based on packet size read. - final ByteBuffer packetByteBuffer = ByteBuffer.allocate(calculatePacketSize()); + final int packetSize = calculatePacketSize(); + final ByteBuffer packetByteBuffer = ByteBuffer.allocate(packetSize); switch (channel.read(packetByteBuffer)) { // Disconnected. @@ -81,6 +82,20 @@ public class ReadThread implements Runnable // Send data read to the client packet queue. default: { + // Continue read if data length is less than expected. + if (packetByteBuffer.position() < packetSize) + { + int attempt = 0; // Keep it under 10 attempts. + while ((attempt++ < 10) && (packetByteBuffer.position() < packetSize)) + { + final ByteBuffer additionalData = ByteBuffer.allocate(packetSize - packetByteBuffer.position()); + channel.read(additionalData); + packetByteBuffer.put(packetByteBuffer.position(), additionalData, 0, additionalData.position()); + packetByteBuffer.position(packetByteBuffer.position() + additionalData.position()); + } + } + + // Add packet data to client. client.addPacketData(packetByteBuffer.array()); } } diff --git a/L2J_Mobius_CT_0_Interlude/java/org/l2jmobius/commons/network/ReadThread.java b/L2J_Mobius_CT_0_Interlude/java/org/l2jmobius/commons/network/ReadThread.java index af52d6fc40..9cf00e3486 100644 --- a/L2J_Mobius_CT_0_Interlude/java/org/l2jmobius/commons/network/ReadThread.java +++ b/L2J_Mobius_CT_0_Interlude/java/org/l2jmobius/commons/network/ReadThread.java @@ -64,7 +64,8 @@ public class ReadThread implements Runnable default: { // Allocate a new ByteBuffer based on packet size read. - final ByteBuffer packetByteBuffer = ByteBuffer.allocate(calculatePacketSize()); + final int packetSize = calculatePacketSize(); + final ByteBuffer packetByteBuffer = ByteBuffer.allocate(packetSize); switch (channel.read(packetByteBuffer)) { // Disconnected. @@ -81,6 +82,20 @@ public class ReadThread implements Runnable // Send data read to the client packet queue. default: { + // Continue read if data length is less than expected. + if (packetByteBuffer.position() < packetSize) + { + int attempt = 0; // Keep it under 10 attempts. + while ((attempt++ < 10) && (packetByteBuffer.position() < packetSize)) + { + final ByteBuffer additionalData = ByteBuffer.allocate(packetSize - packetByteBuffer.position()); + channel.read(additionalData); + packetByteBuffer.put(packetByteBuffer.position(), additionalData, 0, additionalData.position()); + packetByteBuffer.position(packetByteBuffer.position() + additionalData.position()); + } + } + + // Add packet data to client. client.addPacketData(packetByteBuffer.array()); } } diff --git a/L2J_Mobius_CT_2.4_Epilogue/java/org/l2jmobius/commons/network/ReadThread.java b/L2J_Mobius_CT_2.4_Epilogue/java/org/l2jmobius/commons/network/ReadThread.java index af52d6fc40..9cf00e3486 100644 --- a/L2J_Mobius_CT_2.4_Epilogue/java/org/l2jmobius/commons/network/ReadThread.java +++ b/L2J_Mobius_CT_2.4_Epilogue/java/org/l2jmobius/commons/network/ReadThread.java @@ -64,7 +64,8 @@ public class ReadThread implements Runnable default: { // Allocate a new ByteBuffer based on packet size read. - final ByteBuffer packetByteBuffer = ByteBuffer.allocate(calculatePacketSize()); + final int packetSize = calculatePacketSize(); + final ByteBuffer packetByteBuffer = ByteBuffer.allocate(packetSize); switch (channel.read(packetByteBuffer)) { // Disconnected. @@ -81,6 +82,20 @@ public class ReadThread implements Runnable // Send data read to the client packet queue. default: { + // Continue read if data length is less than expected. + if (packetByteBuffer.position() < packetSize) + { + int attempt = 0; // Keep it under 10 attempts. + while ((attempt++ < 10) && (packetByteBuffer.position() < packetSize)) + { + final ByteBuffer additionalData = ByteBuffer.allocate(packetSize - packetByteBuffer.position()); + channel.read(additionalData); + packetByteBuffer.put(packetByteBuffer.position(), additionalData, 0, additionalData.position()); + packetByteBuffer.position(packetByteBuffer.position() + additionalData.position()); + } + } + + // Add packet data to client. client.addPacketData(packetByteBuffer.array()); } } diff --git a/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/commons/network/ReadThread.java b/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/commons/network/ReadThread.java index af52d6fc40..9cf00e3486 100644 --- a/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/commons/network/ReadThread.java +++ b/L2J_Mobius_CT_2.6_HighFive/java/org/l2jmobius/commons/network/ReadThread.java @@ -64,7 +64,8 @@ public class ReadThread implements Runnable default: { // Allocate a new ByteBuffer based on packet size read. - final ByteBuffer packetByteBuffer = ByteBuffer.allocate(calculatePacketSize()); + final int packetSize = calculatePacketSize(); + final ByteBuffer packetByteBuffer = ByteBuffer.allocate(packetSize); switch (channel.read(packetByteBuffer)) { // Disconnected. @@ -81,6 +82,20 @@ public class ReadThread implements Runnable // Send data read to the client packet queue. default: { + // Continue read if data length is less than expected. + if (packetByteBuffer.position() < packetSize) + { + int attempt = 0; // Keep it under 10 attempts. + while ((attempt++ < 10) && (packetByteBuffer.position() < packetSize)) + { + final ByteBuffer additionalData = ByteBuffer.allocate(packetSize - packetByteBuffer.position()); + channel.read(additionalData); + packetByteBuffer.put(packetByteBuffer.position(), additionalData, 0, additionalData.position()); + packetByteBuffer.position(packetByteBuffer.position() + additionalData.position()); + } + } + + // Add packet data to client. client.addPacketData(packetByteBuffer.array()); } } diff --git a/L2J_Mobius_Classic_1.0/java/org/l2jmobius/commons/network/ReadThread.java b/L2J_Mobius_Classic_1.0/java/org/l2jmobius/commons/network/ReadThread.java index af52d6fc40..9cf00e3486 100644 --- a/L2J_Mobius_Classic_1.0/java/org/l2jmobius/commons/network/ReadThread.java +++ b/L2J_Mobius_Classic_1.0/java/org/l2jmobius/commons/network/ReadThread.java @@ -64,7 +64,8 @@ public class ReadThread implements Runnable default: { // Allocate a new ByteBuffer based on packet size read. - final ByteBuffer packetByteBuffer = ByteBuffer.allocate(calculatePacketSize()); + final int packetSize = calculatePacketSize(); + final ByteBuffer packetByteBuffer = ByteBuffer.allocate(packetSize); switch (channel.read(packetByteBuffer)) { // Disconnected. @@ -81,6 +82,20 @@ public class ReadThread implements Runnable // Send data read to the client packet queue. default: { + // Continue read if data length is less than expected. + if (packetByteBuffer.position() < packetSize) + { + int attempt = 0; // Keep it under 10 attempts. + while ((attempt++ < 10) && (packetByteBuffer.position() < packetSize)) + { + final ByteBuffer additionalData = ByteBuffer.allocate(packetSize - packetByteBuffer.position()); + channel.read(additionalData); + packetByteBuffer.put(packetByteBuffer.position(), additionalData, 0, additionalData.position()); + packetByteBuffer.position(packetByteBuffer.position() + additionalData.position()); + } + } + + // Add packet data to client. client.addPacketData(packetByteBuffer.array()); } } diff --git a/L2J_Mobius_Classic_1.5_AgeOfSplendor/java/org/l2jmobius/commons/network/ReadThread.java b/L2J_Mobius_Classic_1.5_AgeOfSplendor/java/org/l2jmobius/commons/network/ReadThread.java index af52d6fc40..9cf00e3486 100644 --- a/L2J_Mobius_Classic_1.5_AgeOfSplendor/java/org/l2jmobius/commons/network/ReadThread.java +++ b/L2J_Mobius_Classic_1.5_AgeOfSplendor/java/org/l2jmobius/commons/network/ReadThread.java @@ -64,7 +64,8 @@ public class ReadThread implements Runnable default: { // Allocate a new ByteBuffer based on packet size read. - final ByteBuffer packetByteBuffer = ByteBuffer.allocate(calculatePacketSize()); + final int packetSize = calculatePacketSize(); + final ByteBuffer packetByteBuffer = ByteBuffer.allocate(packetSize); switch (channel.read(packetByteBuffer)) { // Disconnected. @@ -81,6 +82,20 @@ public class ReadThread implements Runnable // Send data read to the client packet queue. default: { + // Continue read if data length is less than expected. + if (packetByteBuffer.position() < packetSize) + { + int attempt = 0; // Keep it under 10 attempts. + while ((attempt++ < 10) && (packetByteBuffer.position() < packetSize)) + { + final ByteBuffer additionalData = ByteBuffer.allocate(packetSize - packetByteBuffer.position()); + channel.read(additionalData); + packetByteBuffer.put(packetByteBuffer.position(), additionalData, 0, additionalData.position()); + packetByteBuffer.position(packetByteBuffer.position() + additionalData.position()); + } + } + + // Add packet data to client. client.addPacketData(packetByteBuffer.array()); } } diff --git a/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/commons/network/ReadThread.java b/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/commons/network/ReadThread.java index af52d6fc40..9cf00e3486 100644 --- a/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/commons/network/ReadThread.java +++ b/L2J_Mobius_Classic_2.0_Saviors/java/org/l2jmobius/commons/network/ReadThread.java @@ -64,7 +64,8 @@ public class ReadThread implements Runnable default: { // Allocate a new ByteBuffer based on packet size read. - final ByteBuffer packetByteBuffer = ByteBuffer.allocate(calculatePacketSize()); + final int packetSize = calculatePacketSize(); + final ByteBuffer packetByteBuffer = ByteBuffer.allocate(packetSize); switch (channel.read(packetByteBuffer)) { // Disconnected. @@ -81,6 +82,20 @@ public class ReadThread implements Runnable // Send data read to the client packet queue. default: { + // Continue read if data length is less than expected. + if (packetByteBuffer.position() < packetSize) + { + int attempt = 0; // Keep it under 10 attempts. + while ((attempt++ < 10) && (packetByteBuffer.position() < packetSize)) + { + final ByteBuffer additionalData = ByteBuffer.allocate(packetSize - packetByteBuffer.position()); + channel.read(additionalData); + packetByteBuffer.put(packetByteBuffer.position(), additionalData, 0, additionalData.position()); + packetByteBuffer.position(packetByteBuffer.position() + additionalData.position()); + } + } + + // Add packet data to client. client.addPacketData(packetByteBuffer.array()); } } diff --git a/L2J_Mobius_Classic_2.5_Zaken/java/org/l2jmobius/commons/network/ReadThread.java b/L2J_Mobius_Classic_2.5_Zaken/java/org/l2jmobius/commons/network/ReadThread.java index af52d6fc40..9cf00e3486 100644 --- a/L2J_Mobius_Classic_2.5_Zaken/java/org/l2jmobius/commons/network/ReadThread.java +++ b/L2J_Mobius_Classic_2.5_Zaken/java/org/l2jmobius/commons/network/ReadThread.java @@ -64,7 +64,8 @@ public class ReadThread implements Runnable default: { // Allocate a new ByteBuffer based on packet size read. - final ByteBuffer packetByteBuffer = ByteBuffer.allocate(calculatePacketSize()); + final int packetSize = calculatePacketSize(); + final ByteBuffer packetByteBuffer = ByteBuffer.allocate(packetSize); switch (channel.read(packetByteBuffer)) { // Disconnected. @@ -81,6 +82,20 @@ public class ReadThread implements Runnable // Send data read to the client packet queue. default: { + // Continue read if data length is less than expected. + if (packetByteBuffer.position() < packetSize) + { + int attempt = 0; // Keep it under 10 attempts. + while ((attempt++ < 10) && (packetByteBuffer.position() < packetSize)) + { + final ByteBuffer additionalData = ByteBuffer.allocate(packetSize - packetByteBuffer.position()); + channel.read(additionalData); + packetByteBuffer.put(packetByteBuffer.position(), additionalData, 0, additionalData.position()); + packetByteBuffer.position(packetByteBuffer.position() + additionalData.position()); + } + } + + // Add packet data to client. client.addPacketData(packetByteBuffer.array()); } } diff --git a/L2J_Mobius_Classic_2.7_Antharas/java/org/l2jmobius/commons/network/ReadThread.java b/L2J_Mobius_Classic_2.7_Antharas/java/org/l2jmobius/commons/network/ReadThread.java index af52d6fc40..9cf00e3486 100644 --- a/L2J_Mobius_Classic_2.7_Antharas/java/org/l2jmobius/commons/network/ReadThread.java +++ b/L2J_Mobius_Classic_2.7_Antharas/java/org/l2jmobius/commons/network/ReadThread.java @@ -64,7 +64,8 @@ public class ReadThread implements Runnable default: { // Allocate a new ByteBuffer based on packet size read. - final ByteBuffer packetByteBuffer = ByteBuffer.allocate(calculatePacketSize()); + final int packetSize = calculatePacketSize(); + final ByteBuffer packetByteBuffer = ByteBuffer.allocate(packetSize); switch (channel.read(packetByteBuffer)) { // Disconnected. @@ -81,6 +82,20 @@ public class ReadThread implements Runnable // Send data read to the client packet queue. default: { + // Continue read if data length is less than expected. + if (packetByteBuffer.position() < packetSize) + { + int attempt = 0; // Keep it under 10 attempts. + while ((attempt++ < 10) && (packetByteBuffer.position() < packetSize)) + { + final ByteBuffer additionalData = ByteBuffer.allocate(packetSize - packetByteBuffer.position()); + channel.read(additionalData); + packetByteBuffer.put(packetByteBuffer.position(), additionalData, 0, additionalData.position()); + packetByteBuffer.position(packetByteBuffer.position() + additionalData.position()); + } + } + + // Add packet data to client. client.addPacketData(packetByteBuffer.array()); } } diff --git a/L2J_Mobius_Classic_2.8_SevenSigns/java/org/l2jmobius/commons/network/ReadThread.java b/L2J_Mobius_Classic_2.8_SevenSigns/java/org/l2jmobius/commons/network/ReadThread.java index af52d6fc40..9cf00e3486 100644 --- a/L2J_Mobius_Classic_2.8_SevenSigns/java/org/l2jmobius/commons/network/ReadThread.java +++ b/L2J_Mobius_Classic_2.8_SevenSigns/java/org/l2jmobius/commons/network/ReadThread.java @@ -64,7 +64,8 @@ public class ReadThread implements Runnable default: { // Allocate a new ByteBuffer based on packet size read. - final ByteBuffer packetByteBuffer = ByteBuffer.allocate(calculatePacketSize()); + final int packetSize = calculatePacketSize(); + final ByteBuffer packetByteBuffer = ByteBuffer.allocate(packetSize); switch (channel.read(packetByteBuffer)) { // Disconnected. @@ -81,6 +82,20 @@ public class ReadThread implements Runnable // Send data read to the client packet queue. default: { + // Continue read if data length is less than expected. + if (packetByteBuffer.position() < packetSize) + { + int attempt = 0; // Keep it under 10 attempts. + while ((attempt++ < 10) && (packetByteBuffer.position() < packetSize)) + { + final ByteBuffer additionalData = ByteBuffer.allocate(packetSize - packetByteBuffer.position()); + channel.read(additionalData); + packetByteBuffer.put(packetByteBuffer.position(), additionalData, 0, additionalData.position()); + packetByteBuffer.position(packetByteBuffer.position() + additionalData.position()); + } + } + + // Add packet data to client. client.addPacketData(packetByteBuffer.array()); } } diff --git a/L2J_Mobius_Classic_2.9.5_Saviors/java/org/l2jmobius/commons/network/ReadThread.java b/L2J_Mobius_Classic_2.9.5_Saviors/java/org/l2jmobius/commons/network/ReadThread.java index af52d6fc40..9cf00e3486 100644 --- a/L2J_Mobius_Classic_2.9.5_Saviors/java/org/l2jmobius/commons/network/ReadThread.java +++ b/L2J_Mobius_Classic_2.9.5_Saviors/java/org/l2jmobius/commons/network/ReadThread.java @@ -64,7 +64,8 @@ public class ReadThread implements Runnable default: { // Allocate a new ByteBuffer based on packet size read. - final ByteBuffer packetByteBuffer = ByteBuffer.allocate(calculatePacketSize()); + final int packetSize = calculatePacketSize(); + final ByteBuffer packetByteBuffer = ByteBuffer.allocate(packetSize); switch (channel.read(packetByteBuffer)) { // Disconnected. @@ -81,6 +82,20 @@ public class ReadThread implements Runnable // Send data read to the client packet queue. default: { + // Continue read if data length is less than expected. + if (packetByteBuffer.position() < packetSize) + { + int attempt = 0; // Keep it under 10 attempts. + while ((attempt++ < 10) && (packetByteBuffer.position() < packetSize)) + { + final ByteBuffer additionalData = ByteBuffer.allocate(packetSize - packetByteBuffer.position()); + channel.read(additionalData); + packetByteBuffer.put(packetByteBuffer.position(), additionalData, 0, additionalData.position()); + packetByteBuffer.position(packetByteBuffer.position() + additionalData.position()); + } + } + + // Add packet data to client. client.addPacketData(packetByteBuffer.array()); } } diff --git a/L2J_Mobius_Classic_2.9_SecretOfEmpire/java/org/l2jmobius/commons/network/ReadThread.java b/L2J_Mobius_Classic_2.9_SecretOfEmpire/java/org/l2jmobius/commons/network/ReadThread.java index af52d6fc40..9cf00e3486 100644 --- a/L2J_Mobius_Classic_2.9_SecretOfEmpire/java/org/l2jmobius/commons/network/ReadThread.java +++ b/L2J_Mobius_Classic_2.9_SecretOfEmpire/java/org/l2jmobius/commons/network/ReadThread.java @@ -64,7 +64,8 @@ public class ReadThread implements Runnable default: { // Allocate a new ByteBuffer based on packet size read. - final ByteBuffer packetByteBuffer = ByteBuffer.allocate(calculatePacketSize()); + final int packetSize = calculatePacketSize(); + final ByteBuffer packetByteBuffer = ByteBuffer.allocate(packetSize); switch (channel.read(packetByteBuffer)) { // Disconnected. @@ -81,6 +82,20 @@ public class ReadThread implements Runnable // Send data read to the client packet queue. default: { + // Continue read if data length is less than expected. + if (packetByteBuffer.position() < packetSize) + { + int attempt = 0; // Keep it under 10 attempts. + while ((attempt++ < 10) && (packetByteBuffer.position() < packetSize)) + { + final ByteBuffer additionalData = ByteBuffer.allocate(packetSize - packetByteBuffer.position()); + channel.read(additionalData); + packetByteBuffer.put(packetByteBuffer.position(), additionalData, 0, additionalData.position()); + packetByteBuffer.position(packetByteBuffer.position() + additionalData.position()); + } + } + + // Add packet data to client. client.addPacketData(packetByteBuffer.array()); } } diff --git a/L2J_Mobius_Classic_3.0_TheKamael/java/org/l2jmobius/commons/network/ReadThread.java b/L2J_Mobius_Classic_3.0_TheKamael/java/org/l2jmobius/commons/network/ReadThread.java index af52d6fc40..9cf00e3486 100644 --- a/L2J_Mobius_Classic_3.0_TheKamael/java/org/l2jmobius/commons/network/ReadThread.java +++ b/L2J_Mobius_Classic_3.0_TheKamael/java/org/l2jmobius/commons/network/ReadThread.java @@ -64,7 +64,8 @@ public class ReadThread implements Runnable default: { // Allocate a new ByteBuffer based on packet size read. - final ByteBuffer packetByteBuffer = ByteBuffer.allocate(calculatePacketSize()); + final int packetSize = calculatePacketSize(); + final ByteBuffer packetByteBuffer = ByteBuffer.allocate(packetSize); switch (channel.read(packetByteBuffer)) { // Disconnected. @@ -81,6 +82,20 @@ public class ReadThread implements Runnable // Send data read to the client packet queue. default: { + // Continue read if data length is less than expected. + if (packetByteBuffer.position() < packetSize) + { + int attempt = 0; // Keep it under 10 attempts. + while ((attempt++ < 10) && (packetByteBuffer.position() < packetSize)) + { + final ByteBuffer additionalData = ByteBuffer.allocate(packetSize - packetByteBuffer.position()); + channel.read(additionalData); + packetByteBuffer.put(packetByteBuffer.position(), additionalData, 0, additionalData.position()); + packetByteBuffer.position(packetByteBuffer.position() + additionalData.position()); + } + } + + // Add packet data to client. client.addPacketData(packetByteBuffer.array()); } } diff --git a/L2J_Mobius_Classic_Interlude/java/org/l2jmobius/commons/network/ReadThread.java b/L2J_Mobius_Classic_Interlude/java/org/l2jmobius/commons/network/ReadThread.java index af52d6fc40..9cf00e3486 100644 --- a/L2J_Mobius_Classic_Interlude/java/org/l2jmobius/commons/network/ReadThread.java +++ b/L2J_Mobius_Classic_Interlude/java/org/l2jmobius/commons/network/ReadThread.java @@ -64,7 +64,8 @@ public class ReadThread implements Runnable default: { // Allocate a new ByteBuffer based on packet size read. - final ByteBuffer packetByteBuffer = ByteBuffer.allocate(calculatePacketSize()); + final int packetSize = calculatePacketSize(); + final ByteBuffer packetByteBuffer = ByteBuffer.allocate(packetSize); switch (channel.read(packetByteBuffer)) { // Disconnected. @@ -81,6 +82,20 @@ public class ReadThread implements Runnable // Send data read to the client packet queue. default: { + // Continue read if data length is less than expected. + if (packetByteBuffer.position() < packetSize) + { + int attempt = 0; // Keep it under 10 attempts. + while ((attempt++ < 10) && (packetByteBuffer.position() < packetSize)) + { + final ByteBuffer additionalData = ByteBuffer.allocate(packetSize - packetByteBuffer.position()); + channel.read(additionalData); + packetByteBuffer.put(packetByteBuffer.position(), additionalData, 0, additionalData.position()); + packetByteBuffer.position(packetByteBuffer.position() + additionalData.position()); + } + } + + // Add packet data to client. client.addPacketData(packetByteBuffer.array()); } } diff --git a/L2J_Mobius_Essence_4.2_DwellingOfSpirits/java/org/l2jmobius/commons/network/ReadThread.java b/L2J_Mobius_Essence_4.2_DwellingOfSpirits/java/org/l2jmobius/commons/network/ReadThread.java index af52d6fc40..9cf00e3486 100644 --- a/L2J_Mobius_Essence_4.2_DwellingOfSpirits/java/org/l2jmobius/commons/network/ReadThread.java +++ b/L2J_Mobius_Essence_4.2_DwellingOfSpirits/java/org/l2jmobius/commons/network/ReadThread.java @@ -64,7 +64,8 @@ public class ReadThread implements Runnable default: { // Allocate a new ByteBuffer based on packet size read. - final ByteBuffer packetByteBuffer = ByteBuffer.allocate(calculatePacketSize()); + final int packetSize = calculatePacketSize(); + final ByteBuffer packetByteBuffer = ByteBuffer.allocate(packetSize); switch (channel.read(packetByteBuffer)) { // Disconnected. @@ -81,6 +82,20 @@ public class ReadThread implements Runnable // Send data read to the client packet queue. default: { + // Continue read if data length is less than expected. + if (packetByteBuffer.position() < packetSize) + { + int attempt = 0; // Keep it under 10 attempts. + while ((attempt++ < 10) && (packetByteBuffer.position() < packetSize)) + { + final ByteBuffer additionalData = ByteBuffer.allocate(packetSize - packetByteBuffer.position()); + channel.read(additionalData); + packetByteBuffer.put(packetByteBuffer.position(), additionalData, 0, additionalData.position()); + packetByteBuffer.position(packetByteBuffer.position() + additionalData.position()); + } + } + + // Add packet data to client. client.addPacketData(packetByteBuffer.array()); } } diff --git a/L2J_Mobius_Essence_5.2_FrostLord/java/org/l2jmobius/commons/network/ReadThread.java b/L2J_Mobius_Essence_5.2_FrostLord/java/org/l2jmobius/commons/network/ReadThread.java index af52d6fc40..9cf00e3486 100644 --- a/L2J_Mobius_Essence_5.2_FrostLord/java/org/l2jmobius/commons/network/ReadThread.java +++ b/L2J_Mobius_Essence_5.2_FrostLord/java/org/l2jmobius/commons/network/ReadThread.java @@ -64,7 +64,8 @@ public class ReadThread implements Runnable default: { // Allocate a new ByteBuffer based on packet size read. - final ByteBuffer packetByteBuffer = ByteBuffer.allocate(calculatePacketSize()); + final int packetSize = calculatePacketSize(); + final ByteBuffer packetByteBuffer = ByteBuffer.allocate(packetSize); switch (channel.read(packetByteBuffer)) { // Disconnected. @@ -81,6 +82,20 @@ public class ReadThread implements Runnable // Send data read to the client packet queue. default: { + // Continue read if data length is less than expected. + if (packetByteBuffer.position() < packetSize) + { + int attempt = 0; // Keep it under 10 attempts. + while ((attempt++ < 10) && (packetByteBuffer.position() < packetSize)) + { + final ByteBuffer additionalData = ByteBuffer.allocate(packetSize - packetByteBuffer.position()); + channel.read(additionalData); + packetByteBuffer.put(packetByteBuffer.position(), additionalData, 0, additionalData.position()); + packetByteBuffer.position(packetByteBuffer.position() + additionalData.position()); + } + } + + // Add packet data to client. client.addPacketData(packetByteBuffer.array()); } } diff --git a/L2J_Mobius_Essence_6.2_Vanguard/java/org/l2jmobius/commons/network/ReadThread.java b/L2J_Mobius_Essence_6.2_Vanguard/java/org/l2jmobius/commons/network/ReadThread.java index af52d6fc40..9cf00e3486 100644 --- a/L2J_Mobius_Essence_6.2_Vanguard/java/org/l2jmobius/commons/network/ReadThread.java +++ b/L2J_Mobius_Essence_6.2_Vanguard/java/org/l2jmobius/commons/network/ReadThread.java @@ -64,7 +64,8 @@ public class ReadThread implements Runnable default: { // Allocate a new ByteBuffer based on packet size read. - final ByteBuffer packetByteBuffer = ByteBuffer.allocate(calculatePacketSize()); + final int packetSize = calculatePacketSize(); + final ByteBuffer packetByteBuffer = ByteBuffer.allocate(packetSize); switch (channel.read(packetByteBuffer)) { // Disconnected. @@ -81,6 +82,20 @@ public class ReadThread implements Runnable // Send data read to the client packet queue. default: { + // Continue read if data length is less than expected. + if (packetByteBuffer.position() < packetSize) + { + int attempt = 0; // Keep it under 10 attempts. + while ((attempt++ < 10) && (packetByteBuffer.position() < packetSize)) + { + final ByteBuffer additionalData = ByteBuffer.allocate(packetSize - packetByteBuffer.position()); + channel.read(additionalData); + packetByteBuffer.put(packetByteBuffer.position(), additionalData, 0, additionalData.position()); + packetByteBuffer.position(packetByteBuffer.position() + additionalData.position()); + } + } + + // Add packet data to client. client.addPacketData(packetByteBuffer.array()); } } diff --git a/L2J_Mobius_Essence_6.3_Crusader/java/org/l2jmobius/commons/network/ReadThread.java b/L2J_Mobius_Essence_6.3_Crusader/java/org/l2jmobius/commons/network/ReadThread.java index af52d6fc40..9cf00e3486 100644 --- a/L2J_Mobius_Essence_6.3_Crusader/java/org/l2jmobius/commons/network/ReadThread.java +++ b/L2J_Mobius_Essence_6.3_Crusader/java/org/l2jmobius/commons/network/ReadThread.java @@ -64,7 +64,8 @@ public class ReadThread implements Runnable default: { // Allocate a new ByteBuffer based on packet size read. - final ByteBuffer packetByteBuffer = ByteBuffer.allocate(calculatePacketSize()); + final int packetSize = calculatePacketSize(); + final ByteBuffer packetByteBuffer = ByteBuffer.allocate(packetSize); switch (channel.read(packetByteBuffer)) { // Disconnected. @@ -81,6 +82,20 @@ public class ReadThread implements Runnable // Send data read to the client packet queue. default: { + // Continue read if data length is less than expected. + if (packetByteBuffer.position() < packetSize) + { + int attempt = 0; // Keep it under 10 attempts. + while ((attempt++ < 10) && (packetByteBuffer.position() < packetSize)) + { + final ByteBuffer additionalData = ByteBuffer.allocate(packetSize - packetByteBuffer.position()); + channel.read(additionalData); + packetByteBuffer.put(packetByteBuffer.position(), additionalData, 0, additionalData.position()); + packetByteBuffer.position(packetByteBuffer.position() + additionalData.position()); + } + } + + // Add packet data to client. client.addPacketData(packetByteBuffer.array()); } }