Packet sending during Netty migration
This commit is contained in:
@@ -30,7 +30,9 @@ import io.netty.handler.timeout.IdleStateEvent;
|
|||||||
import net.MaplePacketHandler;
|
import net.MaplePacketHandler;
|
||||||
import net.PacketProcessor;
|
import net.PacketProcessor;
|
||||||
import net.netty.InvalidPacketHeaderException;
|
import net.netty.InvalidPacketHeaderException;
|
||||||
|
import net.packet.ByteBufOutPacket;
|
||||||
import net.packet.InPacket;
|
import net.packet.InPacket;
|
||||||
|
import net.packet.OutPacket;
|
||||||
import net.server.Server;
|
import net.server.Server;
|
||||||
import net.server.audit.locks.MonitoredLockType;
|
import net.server.audit.locks.MonitoredLockType;
|
||||||
import net.server.audit.locks.factory.MonitoredReentrantLockFactory;
|
import net.server.audit.locks.factory.MonitoredReentrantLockFactory;
|
||||||
@@ -1160,7 +1162,7 @@ public class MapleClient extends ChannelInboundHandlerAdapter {
|
|||||||
try {
|
try {
|
||||||
if (lastPong < pingedAt) {
|
if (lastPong < pingedAt) {
|
||||||
if (ioChannel.isActive()) {
|
if (ioChannel.isActive()) {
|
||||||
log.info("Disconnected {} due to being idle. Idle state: {}", remoteAddress, event.state());
|
log.info("Disconnected {} due to being idle. Cause: {}", remoteAddress, event.state());
|
||||||
updateLoginState(MapleClient.LOGIN_NOTLOGGEDIN);
|
updateLoginState(MapleClient.LOGIN_NOTLOGGEDIN);
|
||||||
disconnectSession();
|
disconnectSession();
|
||||||
}
|
}
|
||||||
@@ -1462,10 +1464,34 @@ public class MapleClient extends ChannelInboundHandlerAdapter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated(forRemoval = true, since = "Netty migration")
|
||||||
public void announce(final byte[] packet) { // thanks GitGud for noticing an opportunity for improvement by overcoming "synchronized announce"
|
public void announce(final byte[] packet) { // thanks GitGud for noticing an opportunity for improvement by overcoming "synchronized announce"
|
||||||
announcerLock.lock();
|
announcerLock.lock();
|
||||||
try {
|
try {
|
||||||
session.write(packet);
|
// session.write(packet);
|
||||||
|
sendPacket(packet);
|
||||||
|
} finally {
|
||||||
|
announcerLock.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Workaround for old packets. All uses of Client#announce(byte[]) should be migrated to Client#sendPacket(OutPacket)
|
||||||
|
private void sendPacket(final byte[] packet) {
|
||||||
|
announcerLock.lock();
|
||||||
|
try {
|
||||||
|
OutPacket outPacket = new ByteBufOutPacket();
|
||||||
|
outPacket.writeBytes(packet);
|
||||||
|
|
||||||
|
ioChannel.writeAndFlush(outPacket);
|
||||||
|
} finally {
|
||||||
|
announcerLock.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendPacket(OutPacket outPacket) {
|
||||||
|
announcerLock.lock();
|
||||||
|
try {
|
||||||
|
ioChannel.writeAndFlush(outPacket.getBytes());
|
||||||
} finally {
|
} finally {
|
||||||
announcerLock.unlock();
|
announcerLock.unlock();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,11 +11,11 @@ public class LoginServerInitializer extends ServerChannelInitializer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initChannel(SocketChannel socketChannel) {
|
public void initChannel(SocketChannel socketChannel) {
|
||||||
final String clientIp = socketChannel.remoteAddress().getHostName();
|
final String clientIp = socketChannel.remoteAddress().getHostString();
|
||||||
log.debug("Client connected to login server from {} ", clientIp);
|
log.debug("Client connected to login server from {} ", clientIp);
|
||||||
|
|
||||||
PacketProcessor packetProcessor = PacketProcessor.getLoginServerProcessor();
|
PacketProcessor packetProcessor = PacketProcessor.getLoginServerProcessor();
|
||||||
final MapleClient client = new MapleClient(packetProcessor, LoginServer.WORLD, LoginServer.CHANNEL);
|
final MapleClient client = new MapleClient(packetProcessor, LoginServer.WORLD_ID, LoginServer.CHANNEL_ID);
|
||||||
client.setSessionId(sessionId.getAndIncrement());
|
client.setSessionId(sessionId.getAndIncrement());
|
||||||
|
|
||||||
initPipeline(socketChannel, client);
|
initPipeline(socketChannel, client);
|
||||||
|
|||||||
@@ -12,6 +12,11 @@ import java.awt.*;
|
|||||||
public class ByteBufOutPacket implements OutPacket {
|
public class ByteBufOutPacket implements OutPacket {
|
||||||
private final ByteBuf byteBuf;
|
private final ByteBuf byteBuf;
|
||||||
|
|
||||||
|
@Deprecated(forRemoval = true)
|
||||||
|
public ByteBufOutPacket() {
|
||||||
|
this.byteBuf = Unpooled.buffer();
|
||||||
|
}
|
||||||
|
|
||||||
public ByteBufOutPacket(SendOpcode op) {
|
public ByteBufOutPacket(SendOpcode op) {
|
||||||
ByteBuf byteBuf = Unpooled.buffer();
|
ByteBuf byteBuf = Unpooled.buffer();
|
||||||
byteBuf.writeShortLE((short) op.getValue());
|
byteBuf.writeShortLE((short) op.getValue());
|
||||||
|
|||||||
Reference in New Issue
Block a user