Minor refactors

This commit is contained in:
P0nk
2021-07-10 13:51:53 +02:00
parent 0e98abff41
commit fcb43af8e3
2 changed files with 8 additions and 7 deletions

View File

@@ -4,6 +4,7 @@ import client.MapleClient;
import constants.net.ServerConstants; import constants.net.ServerConstants;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.SocketChannel;
import io.netty.handler.timeout.IdleStateHandler; import io.netty.handler.timeout.IdleStateHandler;
import tools.MaplePacketCreator; import tools.MaplePacketCreator;
@@ -17,17 +18,17 @@ public abstract class ServerChannelInitializer extends ChannelInitializer<Socket
final InitializationVector sendIv = InitializationVector.generateSend(); final InitializationVector sendIv = InitializationVector.generateSend();
final InitializationVector recvIv = InitializationVector.generateReceive(); final InitializationVector recvIv = InitializationVector.generateReceive();
writeInitialUnencryptedHelloPacket(socketChannel, sendIv, recvIv); writeInitialUnencryptedHelloPacket(socketChannel, sendIv, recvIv);
setUpHandlers(socketChannel, sendIv, recvIv, client); setUpHandlers(socketChannel.pipeline(), sendIv, recvIv, client);
} }
private void writeInitialUnencryptedHelloPacket(SocketChannel socketChannel, InitializationVector sendIv, InitializationVector recvIv) { private void writeInitialUnencryptedHelloPacket(SocketChannel socketChannel, InitializationVector sendIv, InitializationVector recvIv) {
socketChannel.writeAndFlush(Unpooled.wrappedBuffer(MaplePacketCreator.getHello(ServerConstants.VERSION, sendIv, recvIv))); socketChannel.writeAndFlush(Unpooled.wrappedBuffer(MaplePacketCreator.getHello(ServerConstants.VERSION, sendIv, recvIv)));
} }
private void setUpHandlers(SocketChannel socketChannel, InitializationVector sendIv, InitializationVector recvIv, private void setUpHandlers(ChannelPipeline pipeline, InitializationVector sendIv, InitializationVector recvIv,
MapleClient client) { MapleClient client) {
socketChannel.pipeline().addFirst("IdleStateHandler", new IdleStateHandler(30, 30, 0)); pipeline.addFirst("IdleStateHandler", new IdleStateHandler(30, 30, 0));
socketChannel.pipeline().addLast("PacketCodec", new PacketCodec(ClientCyphers.of(sendIv, recvIv))); pipeline.addLast("PacketCodec", new PacketCodec(ClientCyphers.of(sendIv, recvIv)));
socketChannel.pipeline().addLast("MapleClient", client); pipeline.addLast("MapleClient", client);
} }
} }

View File

@@ -155,14 +155,14 @@ public class MapleSessionCoordinator {
return false; return false;
} }
addRemoteHostSession(remoteHost, session); addLoginRemoteHostSession(remoteHost, session);
return true; return true;
} finally { } finally {
sessionInit.finalize(remoteHost); sessionInit.finalize(remoteHost);
} }
} }
private void addRemoteHostSession(String remoteHost, IoSession session) { private void addLoginRemoteHostSession(String remoteHost, IoSession session) {
Set<IoSession> sessions = new HashSet<>(2); Set<IoSession> sessions = new HashSet<>(2);
sessions.add(session); sessions.add(session);
loginRemoteHosts.put(remoteHost, sessions); loginRemoteHosts.put(remoteHost, sessions);