Make sure sendPacket ByteBuffer has no remaining bytes.

This commit is contained in:
MobiusDevelopment
2023-06-14 00:47:59 +03:00
parent 3c4449a121
commit 670b7e6982
31 changed files with 620 additions and 733 deletions

View File

@@ -17,6 +17,7 @@
package org.l2jmobius.gameserver.network; package org.l2jmobius.gameserver.network;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.SQLException; import java.sql.SQLException;
@@ -219,40 +220,35 @@ public class GameClient extends NetClient
} }
} }
if (Config.PACKET_ENCRYPTION) // Keep the order of packets if sent by multiple threads.
_pendingPackets.add(packet);
synchronized (_pendingPackets)
{ {
_pendingPackets.add(packet); final SocketChannel channel = getChannel();
synchronized (_pendingPackets) if ((channel != null) && channel.isConnected())
{ {
writePacket(_pendingPackets.poll()); final ServerPacket sendPacket = _pendingPackets.poll();
} final ByteBuffer byteBuffer = sendPacket.getSendableByteBuffer(_encryption);
}
else
{
writePacket(packet);
}
}
private void writePacket(ServerPacket packet)
{
try
{
if ((getChannel() != null) && getChannel().isConnected())
{
final ByteBuffer byteBuffer = packet.getSendableByteBuffer(_encryption);
if (byteBuffer != null) if (byteBuffer != null)
{ {
// Send the packet data. // Send the packet data.
getChannel().write(byteBuffer); try
{
// Loop while there are remaining bytes in the buffer.
while (byteBuffer.hasRemaining())
{
channel.write(byteBuffer);
}
}
catch (Exception ignored)
{
}
// Run packet implementation. // Run packet implementation.
packet.run(_player); sendPacket.run(_player);
} }
} }
} }
catch (Exception ignored)
{
}
} }
public void sendPacket(SystemMessageId systemMessageId) public void sendPacket(SystemMessageId systemMessageId)

View File

@@ -17,6 +17,7 @@
package org.l2jmobius.gameserver.network; package org.l2jmobius.gameserver.network;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.SQLException; import java.sql.SQLException;
@@ -219,40 +220,35 @@ public class GameClient extends NetClient
} }
} }
if (Config.PACKET_ENCRYPTION) // Keep the order of packets if sent by multiple threads.
_pendingPackets.add(packet);
synchronized (_pendingPackets)
{ {
_pendingPackets.add(packet); final SocketChannel channel = getChannel();
synchronized (_pendingPackets) if ((channel != null) && channel.isConnected())
{ {
writePacket(_pendingPackets.poll()); final ServerPacket sendPacket = _pendingPackets.poll();
} final ByteBuffer byteBuffer = sendPacket.getSendableByteBuffer(_encryption);
}
else
{
writePacket(packet);
}
}
private void writePacket(ServerPacket packet)
{
try
{
if ((getChannel() != null) && getChannel().isConnected())
{
final ByteBuffer byteBuffer = packet.getSendableByteBuffer(_encryption);
if (byteBuffer != null) if (byteBuffer != null)
{ {
// Send the packet data. // Send the packet data.
getChannel().write(byteBuffer); try
{
// Loop while there are remaining bytes in the buffer.
while (byteBuffer.hasRemaining())
{
channel.write(byteBuffer);
}
}
catch (Exception ignored)
{
}
// Run packet implementation. // Run packet implementation.
packet.run(_player); sendPacket.run(_player);
} }
} }
} }
catch (Exception ignored)
{
}
} }
public void sendPacket(SystemMessageId systemMessageId) public void sendPacket(SystemMessageId systemMessageId)

View File

@@ -17,6 +17,7 @@
package org.l2jmobius.gameserver.network; package org.l2jmobius.gameserver.network;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.SQLException; import java.sql.SQLException;
@@ -219,40 +220,35 @@ public class GameClient extends NetClient
} }
} }
if (Config.PACKET_ENCRYPTION) // Keep the order of packets if sent by multiple threads.
_pendingPackets.add(packet);
synchronized (_pendingPackets)
{ {
_pendingPackets.add(packet); final SocketChannel channel = getChannel();
synchronized (_pendingPackets) if ((channel != null) && channel.isConnected())
{ {
writePacket(_pendingPackets.poll()); final ServerPacket sendPacket = _pendingPackets.poll();
} final ByteBuffer byteBuffer = sendPacket.getSendableByteBuffer(_encryption);
}
else
{
writePacket(packet);
}
}
private void writePacket(ServerPacket packet)
{
try
{
if ((getChannel() != null) && getChannel().isConnected())
{
final ByteBuffer byteBuffer = packet.getSendableByteBuffer(_encryption);
if (byteBuffer != null) if (byteBuffer != null)
{ {
// Send the packet data. // Send the packet data.
getChannel().write(byteBuffer); try
{
// Loop while there are remaining bytes in the buffer.
while (byteBuffer.hasRemaining())
{
channel.write(byteBuffer);
}
}
catch (Exception ignored)
{
}
// Run packet implementation. // Run packet implementation.
packet.run(_player); sendPacket.run(_player);
} }
} }
} }
catch (Exception ignored)
{
}
} }
public void sendPacket(SystemMessageId systemMessageId) public void sendPacket(SystemMessageId systemMessageId)

View File

@@ -17,6 +17,7 @@
package org.l2jmobius.gameserver.network; package org.l2jmobius.gameserver.network;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.SQLException; import java.sql.SQLException;
@@ -219,40 +220,35 @@ public class GameClient extends NetClient
} }
} }
if (Config.PACKET_ENCRYPTION) // Keep the order of packets if sent by multiple threads.
_pendingPackets.add(packet);
synchronized (_pendingPackets)
{ {
_pendingPackets.add(packet); final SocketChannel channel = getChannel();
synchronized (_pendingPackets) if ((channel != null) && channel.isConnected())
{ {
writePacket(_pendingPackets.poll()); final ServerPacket sendPacket = _pendingPackets.poll();
} final ByteBuffer byteBuffer = sendPacket.getSendableByteBuffer(_encryption);
}
else
{
writePacket(packet);
}
}
private void writePacket(ServerPacket packet)
{
try
{
if ((getChannel() != null) && getChannel().isConnected())
{
final ByteBuffer byteBuffer = packet.getSendableByteBuffer(_encryption);
if (byteBuffer != null) if (byteBuffer != null)
{ {
// Send the packet data. // Send the packet data.
getChannel().write(byteBuffer); try
{
// Loop while there are remaining bytes in the buffer.
while (byteBuffer.hasRemaining())
{
channel.write(byteBuffer);
}
}
catch (Exception ignored)
{
}
// Run packet implementation. // Run packet implementation.
packet.run(_player); sendPacket.run(_player);
} }
} }
} }
catch (Exception ignored)
{
}
} }
public void sendPacket(SystemMessageId systemMessageId) public void sendPacket(SystemMessageId systemMessageId)

View File

@@ -17,6 +17,7 @@
package org.l2jmobius.gameserver.network; package org.l2jmobius.gameserver.network;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.SQLException; import java.sql.SQLException;
@@ -219,40 +220,35 @@ public class GameClient extends NetClient
} }
} }
if (Config.PACKET_ENCRYPTION) // Keep the order of packets if sent by multiple threads.
_pendingPackets.add(packet);
synchronized (_pendingPackets)
{ {
_pendingPackets.add(packet); final SocketChannel channel = getChannel();
synchronized (_pendingPackets) if ((channel != null) && channel.isConnected())
{ {
writePacket(_pendingPackets.poll()); final ServerPacket sendPacket = _pendingPackets.poll();
} final ByteBuffer byteBuffer = sendPacket.getSendableByteBuffer(_encryption);
}
else
{
writePacket(packet);
}
}
private void writePacket(ServerPacket packet)
{
try
{
if ((getChannel() != null) && getChannel().isConnected())
{
final ByteBuffer byteBuffer = packet.getSendableByteBuffer(_encryption);
if (byteBuffer != null) if (byteBuffer != null)
{ {
// Send the packet data. // Send the packet data.
getChannel().write(byteBuffer); try
{
// Loop while there are remaining bytes in the buffer.
while (byteBuffer.hasRemaining())
{
channel.write(byteBuffer);
}
}
catch (Exception ignored)
{
}
// Run packet implementation. // Run packet implementation.
packet.run(_player); sendPacket.run(_player);
} }
} }
} }
catch (Exception ignored)
{
}
} }
public void sendPacket(SystemMessageId systemMessageId) public void sendPacket(SystemMessageId systemMessageId)

View File

@@ -17,6 +17,7 @@
package org.l2jmobius.gameserver.network; package org.l2jmobius.gameserver.network;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.SQLException; import java.sql.SQLException;
@@ -219,40 +220,35 @@ public class GameClient extends NetClient
} }
} }
if (Config.PACKET_ENCRYPTION) // Keep the order of packets if sent by multiple threads.
_pendingPackets.add(packet);
synchronized (_pendingPackets)
{ {
_pendingPackets.add(packet); final SocketChannel channel = getChannel();
synchronized (_pendingPackets) if ((channel != null) && channel.isConnected())
{ {
writePacket(_pendingPackets.poll()); final ServerPacket sendPacket = _pendingPackets.poll();
} final ByteBuffer byteBuffer = sendPacket.getSendableByteBuffer(_encryption);
}
else
{
writePacket(packet);
}
}
private void writePacket(ServerPacket packet)
{
try
{
if ((getChannel() != null) && getChannel().isConnected())
{
final ByteBuffer byteBuffer = packet.getSendableByteBuffer(_encryption);
if (byteBuffer != null) if (byteBuffer != null)
{ {
// Send the packet data. // Send the packet data.
getChannel().write(byteBuffer); try
{
// Loop while there are remaining bytes in the buffer.
while (byteBuffer.hasRemaining())
{
channel.write(byteBuffer);
}
}
catch (Exception ignored)
{
}
// Run packet implementation. // Run packet implementation.
packet.run(_player); sendPacket.run(_player);
} }
} }
} }
catch (Exception ignored)
{
}
} }
public void sendPacket(SystemMessageId systemMessageId) public void sendPacket(SystemMessageId systemMessageId)

View File

@@ -17,6 +17,7 @@
package org.l2jmobius.gameserver.network; package org.l2jmobius.gameserver.network;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.SQLException; import java.sql.SQLException;
@@ -219,40 +220,35 @@ public class GameClient extends NetClient
} }
} }
if (Config.PACKET_ENCRYPTION) // Keep the order of packets if sent by multiple threads.
_pendingPackets.add(packet);
synchronized (_pendingPackets)
{ {
_pendingPackets.add(packet); final SocketChannel channel = getChannel();
synchronized (_pendingPackets) if ((channel != null) && channel.isConnected())
{ {
writePacket(_pendingPackets.poll()); final ServerPacket sendPacket = _pendingPackets.poll();
} final ByteBuffer byteBuffer = sendPacket.getSendableByteBuffer(_encryption);
}
else
{
writePacket(packet);
}
}
private void writePacket(ServerPacket packet)
{
try
{
if ((getChannel() != null) && getChannel().isConnected())
{
final ByteBuffer byteBuffer = packet.getSendableByteBuffer(_encryption);
if (byteBuffer != null) if (byteBuffer != null)
{ {
// Send the packet data. // Send the packet data.
getChannel().write(byteBuffer); try
{
// Loop while there are remaining bytes in the buffer.
while (byteBuffer.hasRemaining())
{
channel.write(byteBuffer);
}
}
catch (Exception ignored)
{
}
// Run packet implementation. // Run packet implementation.
packet.run(_player); sendPacket.run(_player);
} }
} }
} }
catch (Exception ignored)
{
}
} }
public void sendPacket(SystemMessageId systemMessageId) public void sendPacket(SystemMessageId systemMessageId)

View File

@@ -17,6 +17,7 @@
package org.l2jmobius.gameserver.network; package org.l2jmobius.gameserver.network;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.SQLException; import java.sql.SQLException;
@@ -219,40 +220,35 @@ public class GameClient extends NetClient
} }
} }
if (Config.PACKET_ENCRYPTION) // Keep the order of packets if sent by multiple threads.
_pendingPackets.add(packet);
synchronized (_pendingPackets)
{ {
_pendingPackets.add(packet); final SocketChannel channel = getChannel();
synchronized (_pendingPackets) if ((channel != null) && channel.isConnected())
{ {
writePacket(_pendingPackets.poll()); final ServerPacket sendPacket = _pendingPackets.poll();
} final ByteBuffer byteBuffer = sendPacket.getSendableByteBuffer(_encryption);
}
else
{
writePacket(packet);
}
}
private void writePacket(ServerPacket packet)
{
try
{
if ((getChannel() != null) && getChannel().isConnected())
{
final ByteBuffer byteBuffer = packet.getSendableByteBuffer(_encryption);
if (byteBuffer != null) if (byteBuffer != null)
{ {
// Send the packet data. // Send the packet data.
getChannel().write(byteBuffer); try
{
// Loop while there are remaining bytes in the buffer.
while (byteBuffer.hasRemaining())
{
channel.write(byteBuffer);
}
}
catch (Exception ignored)
{
}
// Run packet implementation. // Run packet implementation.
packet.run(_player); sendPacket.run(_player);
} }
} }
} }
catch (Exception ignored)
{
}
} }
public void sendPacket(SystemMessageId systemMessageId) public void sendPacket(SystemMessageId systemMessageId)

View File

@@ -17,6 +17,7 @@
package org.l2jmobius.gameserver.network; package org.l2jmobius.gameserver.network;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.SQLException; import java.sql.SQLException;
@@ -219,40 +220,35 @@ public class GameClient extends NetClient
} }
} }
if (Config.PACKET_ENCRYPTION) // Keep the order of packets if sent by multiple threads.
_pendingPackets.add(packet);
synchronized (_pendingPackets)
{ {
_pendingPackets.add(packet); final SocketChannel channel = getChannel();
synchronized (_pendingPackets) if ((channel != null) && channel.isConnected())
{ {
writePacket(_pendingPackets.poll()); final ServerPacket sendPacket = _pendingPackets.poll();
} final ByteBuffer byteBuffer = sendPacket.getSendableByteBuffer(_encryption);
}
else
{
writePacket(packet);
}
}
private void writePacket(ServerPacket packet)
{
try
{
if ((getChannel() != null) && getChannel().isConnected())
{
final ByteBuffer byteBuffer = packet.getSendableByteBuffer(_encryption);
if (byteBuffer != null) if (byteBuffer != null)
{ {
// Send the packet data. // Send the packet data.
getChannel().write(byteBuffer); try
{
// Loop while there are remaining bytes in the buffer.
while (byteBuffer.hasRemaining())
{
channel.write(byteBuffer);
}
}
catch (Exception ignored)
{
}
// Run packet implementation. // Run packet implementation.
packet.run(_player); sendPacket.run(_player);
} }
} }
} }
catch (Exception ignored)
{
}
} }
public void sendPacket(SystemMessageId systemMessageId) public void sendPacket(SystemMessageId systemMessageId)

View File

@@ -17,6 +17,7 @@
package org.l2jmobius.gameserver.network; package org.l2jmobius.gameserver.network;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.SQLException; import java.sql.SQLException;
@@ -219,40 +220,35 @@ public class GameClient extends NetClient
} }
} }
if (Config.PACKET_ENCRYPTION) // Keep the order of packets if sent by multiple threads.
_pendingPackets.add(packet);
synchronized (_pendingPackets)
{ {
_pendingPackets.add(packet); final SocketChannel channel = getChannel();
synchronized (_pendingPackets) if ((channel != null) && channel.isConnected())
{ {
writePacket(_pendingPackets.poll()); final ServerPacket sendPacket = _pendingPackets.poll();
} final ByteBuffer byteBuffer = sendPacket.getSendableByteBuffer(_encryption);
}
else
{
writePacket(packet);
}
}
private void writePacket(ServerPacket packet)
{
try
{
if ((getChannel() != null) && getChannel().isConnected())
{
final ByteBuffer byteBuffer = packet.getSendableByteBuffer(_encryption);
if (byteBuffer != null) if (byteBuffer != null)
{ {
// Send the packet data. // Send the packet data.
getChannel().write(byteBuffer); try
{
// Loop while there are remaining bytes in the buffer.
while (byteBuffer.hasRemaining())
{
channel.write(byteBuffer);
}
}
catch (Exception ignored)
{
}
// Run packet implementation. // Run packet implementation.
packet.run(_player); sendPacket.run(_player);
} }
} }
} }
catch (Exception ignored)
{
}
} }
public void sendPacket(SystemMessageId systemMessageId) public void sendPacket(SystemMessageId systemMessageId)

View File

@@ -17,6 +17,7 @@
package org.l2jmobius.gameserver.network; package org.l2jmobius.gameserver.network;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.SQLException; import java.sql.SQLException;
@@ -219,40 +220,35 @@ public class GameClient extends NetClient
} }
} }
if (Config.PACKET_ENCRYPTION) // Keep the order of packets if sent by multiple threads.
_pendingPackets.add(packet);
synchronized (_pendingPackets)
{ {
_pendingPackets.add(packet); final SocketChannel channel = getChannel();
synchronized (_pendingPackets) if ((channel != null) && channel.isConnected())
{ {
writePacket(_pendingPackets.poll()); final ServerPacket sendPacket = _pendingPackets.poll();
} final ByteBuffer byteBuffer = sendPacket.getSendableByteBuffer(_encryption);
}
else
{
writePacket(packet);
}
}
private void writePacket(ServerPacket packet)
{
try
{
if ((getChannel() != null) && getChannel().isConnected())
{
final ByteBuffer byteBuffer = packet.getSendableByteBuffer(_encryption);
if (byteBuffer != null) if (byteBuffer != null)
{ {
// Send the packet data. // Send the packet data.
getChannel().write(byteBuffer); try
{
// Loop while there are remaining bytes in the buffer.
while (byteBuffer.hasRemaining())
{
channel.write(byteBuffer);
}
}
catch (Exception ignored)
{
}
// Run packet implementation. // Run packet implementation.
packet.run(_player); sendPacket.run(_player);
} }
} }
} }
catch (Exception ignored)
{
}
} }
public void sendPacket(SystemMessageId systemMessageId) public void sendPacket(SystemMessageId systemMessageId)

View File

@@ -17,6 +17,7 @@
package org.l2jmobius.gameserver.network; package org.l2jmobius.gameserver.network;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.SQLException; import java.sql.SQLException;
@@ -219,40 +220,35 @@ public class GameClient extends NetClient
} }
} }
if (Config.PACKET_ENCRYPTION) // Keep the order of packets if sent by multiple threads.
_pendingPackets.add(packet);
synchronized (_pendingPackets)
{ {
_pendingPackets.add(packet); final SocketChannel channel = getChannel();
synchronized (_pendingPackets) if ((channel != null) && channel.isConnected())
{ {
writePacket(_pendingPackets.poll()); final ServerPacket sendPacket = _pendingPackets.poll();
} final ByteBuffer byteBuffer = sendPacket.getSendableByteBuffer(_encryption);
}
else
{
writePacket(packet);
}
}
private void writePacket(ServerPacket packet)
{
try
{
if ((getChannel() != null) && getChannel().isConnected())
{
final ByteBuffer byteBuffer = packet.getSendableByteBuffer(_encryption);
if (byteBuffer != null) if (byteBuffer != null)
{ {
// Send the packet data. // Send the packet data.
getChannel().write(byteBuffer); try
{
// Loop while there are remaining bytes in the buffer.
while (byteBuffer.hasRemaining())
{
channel.write(byteBuffer);
}
}
catch (Exception ignored)
{
}
// Run packet implementation. // Run packet implementation.
packet.run(_player); sendPacket.run(_player);
} }
} }
} }
catch (Exception ignored)
{
}
} }
public void sendPacket(SystemMessageId systemMessageId) public void sendPacket(SystemMessageId systemMessageId)

View File

@@ -17,6 +17,7 @@
package org.l2jmobius.gameserver.network; package org.l2jmobius.gameserver.network;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
@@ -185,28 +186,34 @@ public class GameClient extends NetClient
return; return;
} }
// Keep the order of packets if sent by multiple threads.
_pendingPackets.add(packet); _pendingPackets.add(packet);
synchronized (_pendingPackets) synchronized (_pendingPackets)
{ {
try final SocketChannel channel = getChannel();
if ((channel != null) && channel.isConnected())
{ {
if ((getChannel() != null) && getChannel().isConnected()) final ServerPacket sendPacket = _pendingPackets.poll();
final ByteBuffer byteBuffer = sendPacket.getSendableByteBuffer(_encryption);
if (byteBuffer != null)
{ {
final ServerPacket nextPacket = _pendingPackets.poll(); // Send the packet data.
final ByteBuffer byteBuffer = nextPacket.getSendableByteBuffer(_encryption); try
if (byteBuffer != null)
{ {
// Send the packet data. // Loop while there are remaining bytes in the buffer.
getChannel().write(byteBuffer); while (byteBuffer.hasRemaining())
{
// Run packet implementation. channel.write(byteBuffer);
nextPacket.run(_player); }
} }
catch (Exception ignored)
{
}
// Run packet implementation.
sendPacket.run(_player);
} }
} }
catch (Exception ignored)
{
}
} }
} }

View File

@@ -17,6 +17,7 @@
package org.l2jmobius.gameserver.network; package org.l2jmobius.gameserver.network;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
@@ -177,40 +178,35 @@ public class GameClient extends NetClient
return; return;
} }
if (Config.PACKET_ENCRYPTION) // Keep the order of packets if sent by multiple threads.
_pendingPackets.add(packet);
synchronized (_pendingPackets)
{ {
_pendingPackets.add(packet); final SocketChannel channel = getChannel();
synchronized (_pendingPackets) if ((channel != null) && channel.isConnected())
{ {
writePacket(_pendingPackets.poll()); final ServerPacket sendPacket = _pendingPackets.poll();
} final ByteBuffer byteBuffer = sendPacket.getSendableByteBuffer(_encryption);
}
else
{
writePacket(packet);
}
}
private void writePacket(ServerPacket packet)
{
try
{
if ((getChannel() != null) && getChannel().isConnected())
{
final ByteBuffer byteBuffer = packet.getSendableByteBuffer(_encryption);
if (byteBuffer != null) if (byteBuffer != null)
{ {
// Send the packet data. // Send the packet data.
getChannel().write(byteBuffer); try
{
// Loop while there are remaining bytes in the buffer.
while (byteBuffer.hasRemaining())
{
channel.write(byteBuffer);
}
}
catch (Exception ignored)
{
}
// Run packet implementation. // Run packet implementation.
packet.run(_player); sendPacket.run(_player);
} }
} }
} }
catch (Exception ignored)
{
}
} }
public void sendPacket(SystemMessageId systemMessageId) public void sendPacket(SystemMessageId systemMessageId)

View File

@@ -17,6 +17,7 @@
package org.l2jmobius.gameserver.network; package org.l2jmobius.gameserver.network;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
@@ -194,40 +195,35 @@ public class GameClient extends NetClient
} }
} }
if (Config.PACKET_ENCRYPTION) // Keep the order of packets if sent by multiple threads.
_pendingPackets.add(packet);
synchronized (_pendingPackets)
{ {
_pendingPackets.add(packet); final SocketChannel channel = getChannel();
synchronized (_pendingPackets) if ((channel != null) && channel.isConnected())
{ {
writePacket(_pendingPackets.poll()); final ServerPacket sendPacket = _pendingPackets.poll();
} final ByteBuffer byteBuffer = sendPacket.getSendableByteBuffer(_encryption);
}
else
{
writePacket(packet);
}
}
private void writePacket(ServerPacket packet)
{
try
{
if ((getChannel() != null) && getChannel().isConnected())
{
final ByteBuffer byteBuffer = packet.getSendableByteBuffer(_encryption);
if (byteBuffer != null) if (byteBuffer != null)
{ {
// Send the packet data. // Send the packet data.
getChannel().write(byteBuffer); try
{
// Loop while there are remaining bytes in the buffer.
while (byteBuffer.hasRemaining())
{
channel.write(byteBuffer);
}
}
catch (Exception ignored)
{
}
// Run packet implementation. // Run packet implementation.
packet.run(_player); sendPacket.run(_player);
} }
} }
} }
catch (Exception ignored)
{
}
} }
public void sendPacket(SystemMessageId systemMessageId) public void sendPacket(SystemMessageId systemMessageId)

View File

@@ -17,6 +17,7 @@
package org.l2jmobius.gameserver.network; package org.l2jmobius.gameserver.network;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
@@ -194,40 +195,35 @@ public class GameClient extends NetClient
} }
} }
if (Config.PACKET_ENCRYPTION) // Keep the order of packets if sent by multiple threads.
_pendingPackets.add(packet);
synchronized (_pendingPackets)
{ {
_pendingPackets.add(packet); final SocketChannel channel = getChannel();
synchronized (_pendingPackets) if ((channel != null) && channel.isConnected())
{ {
writePacket(_pendingPackets.poll()); final ServerPacket sendPacket = _pendingPackets.poll();
} final ByteBuffer byteBuffer = sendPacket.getSendableByteBuffer(_encryption);
}
else
{
writePacket(packet);
}
}
private void writePacket(ServerPacket packet)
{
try
{
if ((getChannel() != null) && getChannel().isConnected())
{
final ByteBuffer byteBuffer = packet.getSendableByteBuffer(_encryption);
if (byteBuffer != null) if (byteBuffer != null)
{ {
// Send the packet data. // Send the packet data.
getChannel().write(byteBuffer); try
{
// Loop while there are remaining bytes in the buffer.
while (byteBuffer.hasRemaining())
{
channel.write(byteBuffer);
}
}
catch (Exception ignored)
{
}
// Run packet implementation. // Run packet implementation.
packet.run(_player); sendPacket.run(_player);
} }
} }
} }
catch (Exception ignored)
{
}
} }
public void sendPacket(SystemMessageId systemMessageId) public void sendPacket(SystemMessageId systemMessageId)

View File

@@ -17,6 +17,7 @@
package org.l2jmobius.gameserver.network; package org.l2jmobius.gameserver.network;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
@@ -201,40 +202,35 @@ public class GameClient extends NetClient
} }
} }
if (Config.PACKET_ENCRYPTION) // Keep the order of packets if sent by multiple threads.
_pendingPackets.add(packet);
synchronized (_pendingPackets)
{ {
_pendingPackets.add(packet); final SocketChannel channel = getChannel();
synchronized (_pendingPackets) if ((channel != null) && channel.isConnected())
{ {
writePacket(_pendingPackets.poll()); final ServerPacket sendPacket = _pendingPackets.poll();
} final ByteBuffer byteBuffer = sendPacket.getSendableByteBuffer(_encryption);
}
else
{
writePacket(packet);
}
}
private void writePacket(ServerPacket packet)
{
try
{
if ((getChannel() != null) && getChannel().isConnected())
{
final ByteBuffer byteBuffer = packet.getSendableByteBuffer(_encryption);
if (byteBuffer != null) if (byteBuffer != null)
{ {
// Send the packet data. // Send the packet data.
getChannel().write(byteBuffer); try
{
// Loop while there are remaining bytes in the buffer.
while (byteBuffer.hasRemaining())
{
channel.write(byteBuffer);
}
}
catch (Exception ignored)
{
}
// Run packet implementation. // Run packet implementation.
packet.run(_player); sendPacket.run(_player);
} }
} }
} }
catch (Exception ignored)
{
}
} }
public void sendPacket(SystemMessageId systemMessageId) public void sendPacket(SystemMessageId systemMessageId)

View File

@@ -17,6 +17,7 @@
package org.l2jmobius.gameserver.network; package org.l2jmobius.gameserver.network;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.SQLException; import java.sql.SQLException;
@@ -219,40 +220,35 @@ public class GameClient extends NetClient
} }
} }
if (Config.PACKET_ENCRYPTION) // Keep the order of packets if sent by multiple threads.
_pendingPackets.add(packet);
synchronized (_pendingPackets)
{ {
_pendingPackets.add(packet); final SocketChannel channel = getChannel();
synchronized (_pendingPackets) if ((channel != null) && channel.isConnected())
{ {
writePacket(_pendingPackets.poll()); final ServerPacket sendPacket = _pendingPackets.poll();
} final ByteBuffer byteBuffer = sendPacket.getSendableByteBuffer(_encryption);
}
else
{
writePacket(packet);
}
}
private void writePacket(ServerPacket packet)
{
try
{
if ((getChannel() != null) && getChannel().isConnected())
{
final ByteBuffer byteBuffer = packet.getSendableByteBuffer(_encryption);
if (byteBuffer != null) if (byteBuffer != null)
{ {
// Send the packet data. // Send the packet data.
getChannel().write(byteBuffer); try
{
// Loop while there are remaining bytes in the buffer.
while (byteBuffer.hasRemaining())
{
channel.write(byteBuffer);
}
}
catch (Exception ignored)
{
}
// Run packet implementation. // Run packet implementation.
packet.run(_player); sendPacket.run(_player);
} }
} }
} }
catch (Exception ignored)
{
}
} }
public void sendPacket(SystemMessageId systemMessageId) public void sendPacket(SystemMessageId systemMessageId)

View File

@@ -17,6 +17,7 @@
package org.l2jmobius.gameserver.network; package org.l2jmobius.gameserver.network;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.SQLException; import java.sql.SQLException;
@@ -219,40 +220,35 @@ public class GameClient extends NetClient
} }
} }
if (Config.PACKET_ENCRYPTION) // Keep the order of packets if sent by multiple threads.
_pendingPackets.add(packet);
synchronized (_pendingPackets)
{ {
_pendingPackets.add(packet); final SocketChannel channel = getChannel();
synchronized (_pendingPackets) if ((channel != null) && channel.isConnected())
{ {
writePacket(_pendingPackets.poll()); final ServerPacket sendPacket = _pendingPackets.poll();
} final ByteBuffer byteBuffer = sendPacket.getSendableByteBuffer(_encryption);
}
else
{
writePacket(packet);
}
}
private void writePacket(ServerPacket packet)
{
try
{
if ((getChannel() != null) && getChannel().isConnected())
{
final ByteBuffer byteBuffer = packet.getSendableByteBuffer(_encryption);
if (byteBuffer != null) if (byteBuffer != null)
{ {
// Send the packet data. // Send the packet data.
getChannel().write(byteBuffer); try
{
// Loop while there are remaining bytes in the buffer.
while (byteBuffer.hasRemaining())
{
channel.write(byteBuffer);
}
}
catch (Exception ignored)
{
}
// Run packet implementation. // Run packet implementation.
packet.run(_player); sendPacket.run(_player);
} }
} }
} }
catch (Exception ignored)
{
}
} }
public void sendPacket(SystemMessageId systemMessageId) public void sendPacket(SystemMessageId systemMessageId)

View File

@@ -17,6 +17,7 @@
package org.l2jmobius.gameserver.network; package org.l2jmobius.gameserver.network;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.SQLException; import java.sql.SQLException;
@@ -219,40 +220,35 @@ public class GameClient extends NetClient
} }
} }
if (Config.PACKET_ENCRYPTION) // Keep the order of packets if sent by multiple threads.
_pendingPackets.add(packet);
synchronized (_pendingPackets)
{ {
_pendingPackets.add(packet); final SocketChannel channel = getChannel();
synchronized (_pendingPackets) if ((channel != null) && channel.isConnected())
{ {
writePacket(_pendingPackets.poll()); final ServerPacket sendPacket = _pendingPackets.poll();
} final ByteBuffer byteBuffer = sendPacket.getSendableByteBuffer(_encryption);
}
else
{
writePacket(packet);
}
}
private void writePacket(ServerPacket packet)
{
try
{
if ((getChannel() != null) && getChannel().isConnected())
{
final ByteBuffer byteBuffer = packet.getSendableByteBuffer(_encryption);
if (byteBuffer != null) if (byteBuffer != null)
{ {
// Send the packet data. // Send the packet data.
getChannel().write(byteBuffer); try
{
// Loop while there are remaining bytes in the buffer.
while (byteBuffer.hasRemaining())
{
channel.write(byteBuffer);
}
}
catch (Exception ignored)
{
}
// Run packet implementation. // Run packet implementation.
packet.run(_player); sendPacket.run(_player);
} }
} }
} }
catch (Exception ignored)
{
}
} }
public void sendPacket(SystemMessageId systemMessageId) public void sendPacket(SystemMessageId systemMessageId)

View File

@@ -17,6 +17,7 @@
package org.l2jmobius.gameserver.network; package org.l2jmobius.gameserver.network;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.SQLException; import java.sql.SQLException;
@@ -219,40 +220,35 @@ public class GameClient extends NetClient
} }
} }
if (Config.PACKET_ENCRYPTION) // Keep the order of packets if sent by multiple threads.
_pendingPackets.add(packet);
synchronized (_pendingPackets)
{ {
_pendingPackets.add(packet); final SocketChannel channel = getChannel();
synchronized (_pendingPackets) if ((channel != null) && channel.isConnected())
{ {
writePacket(_pendingPackets.poll()); final ServerPacket sendPacket = _pendingPackets.poll();
} final ByteBuffer byteBuffer = sendPacket.getSendableByteBuffer(_encryption);
}
else
{
writePacket(packet);
}
}
private void writePacket(ServerPacket packet)
{
try
{
if ((getChannel() != null) && getChannel().isConnected())
{
final ByteBuffer byteBuffer = packet.getSendableByteBuffer(_encryption);
if (byteBuffer != null) if (byteBuffer != null)
{ {
// Send the packet data. // Send the packet data.
getChannel().write(byteBuffer); try
{
// Loop while there are remaining bytes in the buffer.
while (byteBuffer.hasRemaining())
{
channel.write(byteBuffer);
}
}
catch (Exception ignored)
{
}
// Run packet implementation. // Run packet implementation.
packet.run(_player); sendPacket.run(_player);
} }
} }
} }
catch (Exception ignored)
{
}
} }
public void sendPacket(SystemMessageId systemMessageId) public void sendPacket(SystemMessageId systemMessageId)

View File

@@ -17,6 +17,7 @@
package org.l2jmobius.gameserver.network; package org.l2jmobius.gameserver.network;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.SQLException; import java.sql.SQLException;
@@ -219,40 +220,35 @@ public class GameClient extends NetClient
} }
} }
if (Config.PACKET_ENCRYPTION) // Keep the order of packets if sent by multiple threads.
_pendingPackets.add(packet);
synchronized (_pendingPackets)
{ {
_pendingPackets.add(packet); final SocketChannel channel = getChannel();
synchronized (_pendingPackets) if ((channel != null) && channel.isConnected())
{ {
writePacket(_pendingPackets.poll()); final ServerPacket sendPacket = _pendingPackets.poll();
} final ByteBuffer byteBuffer = sendPacket.getSendableByteBuffer(_encryption);
}
else
{
writePacket(packet);
}
}
private void writePacket(ServerPacket packet)
{
try
{
if ((getChannel() != null) && getChannel().isConnected())
{
final ByteBuffer byteBuffer = packet.getSendableByteBuffer(_encryption);
if (byteBuffer != null) if (byteBuffer != null)
{ {
// Send the packet data. // Send the packet data.
getChannel().write(byteBuffer); try
{
// Loop while there are remaining bytes in the buffer.
while (byteBuffer.hasRemaining())
{
channel.write(byteBuffer);
}
}
catch (Exception ignored)
{
}
// Run packet implementation. // Run packet implementation.
packet.run(_player); sendPacket.run(_player);
} }
} }
} }
catch (Exception ignored)
{
}
} }
public void sendPacket(SystemMessageId systemMessageId) public void sendPacket(SystemMessageId systemMessageId)

View File

@@ -17,6 +17,7 @@
package org.l2jmobius.gameserver.network; package org.l2jmobius.gameserver.network;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.SQLException; import java.sql.SQLException;
@@ -219,40 +220,35 @@ public class GameClient extends NetClient
} }
} }
if (Config.PACKET_ENCRYPTION) // Keep the order of packets if sent by multiple threads.
_pendingPackets.add(packet);
synchronized (_pendingPackets)
{ {
_pendingPackets.add(packet); final SocketChannel channel = getChannel();
synchronized (_pendingPackets) if ((channel != null) && channel.isConnected())
{ {
writePacket(_pendingPackets.poll()); final ServerPacket sendPacket = _pendingPackets.poll();
} final ByteBuffer byteBuffer = sendPacket.getSendableByteBuffer(_encryption);
}
else
{
writePacket(packet);
}
}
private void writePacket(ServerPacket packet)
{
try
{
if ((getChannel() != null) && getChannel().isConnected())
{
final ByteBuffer byteBuffer = packet.getSendableByteBuffer(_encryption);
if (byteBuffer != null) if (byteBuffer != null)
{ {
// Send the packet data. // Send the packet data.
getChannel().write(byteBuffer); try
{
// Loop while there are remaining bytes in the buffer.
while (byteBuffer.hasRemaining())
{
channel.write(byteBuffer);
}
}
catch (Exception ignored)
{
}
// Run packet implementation. // Run packet implementation.
packet.run(_player); sendPacket.run(_player);
} }
} }
} }
catch (Exception ignored)
{
}
} }
public void sendPacket(SystemMessageId systemMessageId) public void sendPacket(SystemMessageId systemMessageId)

View File

@@ -17,6 +17,7 @@
package org.l2jmobius.gameserver.network; package org.l2jmobius.gameserver.network;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.SQLException; import java.sql.SQLException;
@@ -219,40 +220,35 @@ public class GameClient extends NetClient
} }
} }
if (Config.PACKET_ENCRYPTION) // Keep the order of packets if sent by multiple threads.
_pendingPackets.add(packet);
synchronized (_pendingPackets)
{ {
_pendingPackets.add(packet); final SocketChannel channel = getChannel();
synchronized (_pendingPackets) if ((channel != null) && channel.isConnected())
{ {
writePacket(_pendingPackets.poll()); final ServerPacket sendPacket = _pendingPackets.poll();
} final ByteBuffer byteBuffer = sendPacket.getSendableByteBuffer(_encryption);
}
else
{
writePacket(packet);
}
}
private void writePacket(ServerPacket packet)
{
try
{
if ((getChannel() != null) && getChannel().isConnected())
{
final ByteBuffer byteBuffer = packet.getSendableByteBuffer(_encryption);
if (byteBuffer != null) if (byteBuffer != null)
{ {
// Send the packet data. // Send the packet data.
getChannel().write(byteBuffer); try
{
// Loop while there are remaining bytes in the buffer.
while (byteBuffer.hasRemaining())
{
channel.write(byteBuffer);
}
}
catch (Exception ignored)
{
}
// Run packet implementation. // Run packet implementation.
packet.run(_player); sendPacket.run(_player);
} }
} }
} }
catch (Exception ignored)
{
}
} }
public void sendPacket(SystemMessageId systemMessageId) public void sendPacket(SystemMessageId systemMessageId)

View File

@@ -17,6 +17,7 @@
package org.l2jmobius.gameserver.network; package org.l2jmobius.gameserver.network;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.SQLException; import java.sql.SQLException;
@@ -219,40 +220,35 @@ public class GameClient extends NetClient
} }
} }
if (Config.PACKET_ENCRYPTION) // Keep the order of packets if sent by multiple threads.
_pendingPackets.add(packet);
synchronized (_pendingPackets)
{ {
_pendingPackets.add(packet); final SocketChannel channel = getChannel();
synchronized (_pendingPackets) if ((channel != null) && channel.isConnected())
{ {
writePacket(_pendingPackets.poll()); final ServerPacket sendPacket = _pendingPackets.poll();
} final ByteBuffer byteBuffer = sendPacket.getSendableByteBuffer(_encryption);
}
else
{
writePacket(packet);
}
}
private void writePacket(ServerPacket packet)
{
try
{
if ((getChannel() != null) && getChannel().isConnected())
{
final ByteBuffer byteBuffer = packet.getSendableByteBuffer(_encryption);
if (byteBuffer != null) if (byteBuffer != null)
{ {
// Send the packet data. // Send the packet data.
getChannel().write(byteBuffer); try
{
// Loop while there are remaining bytes in the buffer.
while (byteBuffer.hasRemaining())
{
channel.write(byteBuffer);
}
}
catch (Exception ignored)
{
}
// Run packet implementation. // Run packet implementation.
packet.run(_player); sendPacket.run(_player);
} }
} }
} }
catch (Exception ignored)
{
}
} }
public void sendPacket(SystemMessageId systemMessageId) public void sendPacket(SystemMessageId systemMessageId)

View File

@@ -17,6 +17,7 @@
package org.l2jmobius.gameserver.network; package org.l2jmobius.gameserver.network;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.SQLException; import java.sql.SQLException;
@@ -219,40 +220,35 @@ public class GameClient extends NetClient
} }
} }
if (Config.PACKET_ENCRYPTION) // Keep the order of packets if sent by multiple threads.
_pendingPackets.add(packet);
synchronized (_pendingPackets)
{ {
_pendingPackets.add(packet); final SocketChannel channel = getChannel();
synchronized (_pendingPackets) if ((channel != null) && channel.isConnected())
{ {
writePacket(_pendingPackets.poll()); final ServerPacket sendPacket = _pendingPackets.poll();
} final ByteBuffer byteBuffer = sendPacket.getSendableByteBuffer(_encryption);
}
else
{
writePacket(packet);
}
}
private void writePacket(ServerPacket packet)
{
try
{
if ((getChannel() != null) && getChannel().isConnected())
{
final ByteBuffer byteBuffer = packet.getSendableByteBuffer(_encryption);
if (byteBuffer != null) if (byteBuffer != null)
{ {
// Send the packet data. // Send the packet data.
getChannel().write(byteBuffer); try
{
// Loop while there are remaining bytes in the buffer.
while (byteBuffer.hasRemaining())
{
channel.write(byteBuffer);
}
}
catch (Exception ignored)
{
}
// Run packet implementation. // Run packet implementation.
packet.run(_player); sendPacket.run(_player);
} }
} }
} }
catch (Exception ignored)
{
}
} }
public void sendPacket(SystemMessageId systemMessageId) public void sendPacket(SystemMessageId systemMessageId)

View File

@@ -17,6 +17,7 @@
package org.l2jmobius.gameserver.network; package org.l2jmobius.gameserver.network;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.SQLException; import java.sql.SQLException;
@@ -219,40 +220,35 @@ public class GameClient extends NetClient
} }
} }
if (Config.PACKET_ENCRYPTION) // Keep the order of packets if sent by multiple threads.
_pendingPackets.add(packet);
synchronized (_pendingPackets)
{ {
_pendingPackets.add(packet); final SocketChannel channel = getChannel();
synchronized (_pendingPackets) if ((channel != null) && channel.isConnected())
{ {
writePacket(_pendingPackets.poll()); final ServerPacket sendPacket = _pendingPackets.poll();
} final ByteBuffer byteBuffer = sendPacket.getSendableByteBuffer(_encryption);
}
else
{
writePacket(packet);
}
}
private void writePacket(ServerPacket packet)
{
try
{
if ((getChannel() != null) && getChannel().isConnected())
{
final ByteBuffer byteBuffer = packet.getSendableByteBuffer(_encryption);
if (byteBuffer != null) if (byteBuffer != null)
{ {
// Send the packet data. // Send the packet data.
getChannel().write(byteBuffer); try
{
// Loop while there are remaining bytes in the buffer.
while (byteBuffer.hasRemaining())
{
channel.write(byteBuffer);
}
}
catch (Exception ignored)
{
}
// Run packet implementation. // Run packet implementation.
packet.run(_player); sendPacket.run(_player);
} }
} }
} }
catch (Exception ignored)
{
}
} }
public void sendPacket(SystemMessageId systemMessageId) public void sendPacket(SystemMessageId systemMessageId)

View File

@@ -17,6 +17,7 @@
package org.l2jmobius.gameserver.network; package org.l2jmobius.gameserver.network;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.SQLException; import java.sql.SQLException;
@@ -219,40 +220,35 @@ public class GameClient extends NetClient
} }
} }
if (Config.PACKET_ENCRYPTION) // Keep the order of packets if sent by multiple threads.
_pendingPackets.add(packet);
synchronized (_pendingPackets)
{ {
_pendingPackets.add(packet); final SocketChannel channel = getChannel();
synchronized (_pendingPackets) if ((channel != null) && channel.isConnected())
{ {
writePacket(_pendingPackets.poll()); final ServerPacket sendPacket = _pendingPackets.poll();
} final ByteBuffer byteBuffer = sendPacket.getSendableByteBuffer(_encryption);
}
else
{
writePacket(packet);
}
}
private void writePacket(ServerPacket packet)
{
try
{
if ((getChannel() != null) && getChannel().isConnected())
{
final ByteBuffer byteBuffer = packet.getSendableByteBuffer(_encryption);
if (byteBuffer != null) if (byteBuffer != null)
{ {
// Send the packet data. // Send the packet data.
getChannel().write(byteBuffer); try
{
// Loop while there are remaining bytes in the buffer.
while (byteBuffer.hasRemaining())
{
channel.write(byteBuffer);
}
}
catch (Exception ignored)
{
}
// Run packet implementation. // Run packet implementation.
packet.run(_player); sendPacket.run(_player);
} }
} }
} }
catch (Exception ignored)
{
}
} }
public void sendPacket(SystemMessageId systemMessageId) public void sendPacket(SystemMessageId systemMessageId)

View File

@@ -17,6 +17,7 @@
package org.l2jmobius.gameserver.network; package org.l2jmobius.gameserver.network;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.SQLException; import java.sql.SQLException;
@@ -219,40 +220,35 @@ public class GameClient extends NetClient
} }
} }
if (Config.PACKET_ENCRYPTION) // Keep the order of packets if sent by multiple threads.
_pendingPackets.add(packet);
synchronized (_pendingPackets)
{ {
_pendingPackets.add(packet); final SocketChannel channel = getChannel();
synchronized (_pendingPackets) if ((channel != null) && channel.isConnected())
{ {
writePacket(_pendingPackets.poll()); final ServerPacket sendPacket = _pendingPackets.poll();
} final ByteBuffer byteBuffer = sendPacket.getSendableByteBuffer(_encryption);
}
else
{
writePacket(packet);
}
}
private void writePacket(ServerPacket packet)
{
try
{
if ((getChannel() != null) && getChannel().isConnected())
{
final ByteBuffer byteBuffer = packet.getSendableByteBuffer(_encryption);
if (byteBuffer != null) if (byteBuffer != null)
{ {
// Send the packet data. // Send the packet data.
getChannel().write(byteBuffer); try
{
// Loop while there are remaining bytes in the buffer.
while (byteBuffer.hasRemaining())
{
channel.write(byteBuffer);
}
}
catch (Exception ignored)
{
}
// Run packet implementation. // Run packet implementation.
packet.run(_player); sendPacket.run(_player);
} }
} }
} }
catch (Exception ignored)
{
}
} }
public void sendPacket(SystemMessageId systemMessageId) public void sendPacket(SystemMessageId systemMessageId)

View File

@@ -17,6 +17,7 @@
package org.l2jmobius.gameserver.network; package org.l2jmobius.gameserver.network;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.SQLException; import java.sql.SQLException;
@@ -219,40 +220,35 @@ public class GameClient extends NetClient
} }
} }
if (Config.PACKET_ENCRYPTION) // Keep the order of packets if sent by multiple threads.
_pendingPackets.add(packet);
synchronized (_pendingPackets)
{ {
_pendingPackets.add(packet); final SocketChannel channel = getChannel();
synchronized (_pendingPackets) if ((channel != null) && channel.isConnected())
{ {
writePacket(_pendingPackets.poll()); final ServerPacket sendPacket = _pendingPackets.poll();
} final ByteBuffer byteBuffer = sendPacket.getSendableByteBuffer(_encryption);
}
else
{
writePacket(packet);
}
}
private void writePacket(ServerPacket packet)
{
try
{
if ((getChannel() != null) && getChannel().isConnected())
{
final ByteBuffer byteBuffer = packet.getSendableByteBuffer(_encryption);
if (byteBuffer != null) if (byteBuffer != null)
{ {
// Send the packet data. // Send the packet data.
getChannel().write(byteBuffer); try
{
// Loop while there are remaining bytes in the buffer.
while (byteBuffer.hasRemaining())
{
channel.write(byteBuffer);
}
}
catch (Exception ignored)
{
}
// Run packet implementation. // Run packet implementation.
packet.run(_player); sendPacket.run(_player);
} }
} }
} }
catch (Exception ignored)
{
}
} }
public void sendPacket(SystemMessageId systemMessageId) public void sendPacket(SystemMessageId systemMessageId)

View File

@@ -17,6 +17,7 @@
package org.l2jmobius.gameserver.network; package org.l2jmobius.gameserver.network;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.SQLException; import java.sql.SQLException;
@@ -219,40 +220,35 @@ public class GameClient extends NetClient
} }
} }
if (Config.PACKET_ENCRYPTION) // Keep the order of packets if sent by multiple threads.
_pendingPackets.add(packet);
synchronized (_pendingPackets)
{ {
_pendingPackets.add(packet); final SocketChannel channel = getChannel();
synchronized (_pendingPackets) if ((channel != null) && channel.isConnected())
{ {
writePacket(_pendingPackets.poll()); final ServerPacket sendPacket = _pendingPackets.poll();
} final ByteBuffer byteBuffer = sendPacket.getSendableByteBuffer(_encryption);
}
else
{
writePacket(packet);
}
}
private void writePacket(ServerPacket packet)
{
try
{
if ((getChannel() != null) && getChannel().isConnected())
{
final ByteBuffer byteBuffer = packet.getSendableByteBuffer(_encryption);
if (byteBuffer != null) if (byteBuffer != null)
{ {
// Send the packet data. // Send the packet data.
getChannel().write(byteBuffer); try
{
// Loop while there are remaining bytes in the buffer.
while (byteBuffer.hasRemaining())
{
channel.write(byteBuffer);
}
}
catch (Exception ignored)
{
}
// Run packet implementation. // Run packet implementation.
packet.run(_player); sendPacket.run(_player);
} }
} }
} }
catch (Exception ignored)
{
}
} }
public void sendPacket(SystemMessageId systemMessageId) public void sendPacket(SystemMessageId systemMessageId)