Refactor MapleClient constructor, fix issue with multiclient check
This commit is contained in:
@@ -88,13 +88,14 @@ public class MapleClient extends ChannelInboundHandlerAdapter {
|
|||||||
public static final int LOGIN_LOGGEDIN = 2;
|
public static final int LOGIN_LOGGEDIN = 2;
|
||||||
|
|
||||||
private final Type type;
|
private final Type type;
|
||||||
|
private final long sessionId;
|
||||||
|
private final PacketProcessor packetProcessor;
|
||||||
|
|
||||||
private Hwid hwid;
|
private Hwid hwid;
|
||||||
private String remoteAddress;
|
private String remoteAddress;
|
||||||
private volatile boolean inTransition;
|
private volatile boolean inTransition;
|
||||||
|
|
||||||
private io.netty.channel.Channel ioChannel;
|
private io.netty.channel.Channel ioChannel;
|
||||||
private PacketProcessor packetProcessor;
|
|
||||||
private MapleCharacter player;
|
private MapleCharacter player;
|
||||||
private int channel = 1;
|
private int channel = 1;
|
||||||
private int accId = -4;
|
private int accId = -4;
|
||||||
@@ -126,7 +127,6 @@ public class MapleClient extends ChannelInboundHandlerAdapter {
|
|||||||
private int voteTime = -1;
|
private int voteTime = -1;
|
||||||
private int visibleWorlds;
|
private int visibleWorlds;
|
||||||
private long lastNpcClick;
|
private long lastNpcClick;
|
||||||
private long sessionId;
|
|
||||||
private long lastPacket = System.currentTimeMillis();
|
private long lastPacket = System.currentTimeMillis();
|
||||||
private int lang = 0;
|
private int lang = 0;
|
||||||
|
|
||||||
@@ -135,15 +135,27 @@ public class MapleClient extends ChannelInboundHandlerAdapter {
|
|||||||
CHANNEL
|
CHANNEL
|
||||||
}
|
}
|
||||||
|
|
||||||
public MapleClient(Type type, PacketProcessor packetProcessor, int world, int channel) {
|
public MapleClient(Type type, long sessionId, String remoteAddress, PacketProcessor packetProcessor, int world, int channel) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
this.sessionId = sessionId;
|
||||||
|
this.remoteAddress = remoteAddress;
|
||||||
this.packetProcessor = packetProcessor;
|
this.packetProcessor = packetProcessor;
|
||||||
this.world = world;
|
this.world = world;
|
||||||
this.channel = channel;
|
this.channel = channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static MapleClient createLoginClient(long sessionId, String remoteAddress, PacketProcessor packetProcessor,
|
||||||
|
int world, int channel) {
|
||||||
|
return new MapleClient(Type.LOGIN, sessionId, remoteAddress, packetProcessor, world, channel);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MapleClient createChannelClient(long sessionId, String remoteAddress, PacketProcessor packetProcessor,
|
||||||
|
int world, int channel) {
|
||||||
|
return new MapleClient(Type.CHANNEL, sessionId, remoteAddress, packetProcessor, world, channel);
|
||||||
|
}
|
||||||
|
|
||||||
public static MapleClient createMock() {
|
public static MapleClient createMock() {
|
||||||
return new MapleClient(null, null, -123, -123);
|
return new MapleClient(null, -1,null, null, -123, -123);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1528,10 +1540,6 @@ public class MapleClient extends ChannelInboundHandlerAdapter {
|
|||||||
return this.sessionId;
|
return this.sessionId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSessionId(long sessionId) {
|
|
||||||
this.sessionId = sessionId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean canRequestCharlist() {
|
public boolean canRequestCharlist() {
|
||||||
return lastNpcClick + 877 < Server.getInstance().getCurrentTime();
|
return lastNpcClick + 877 < Server.getInstance().getCurrentTime();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,8 +25,9 @@ public class ChannelServerInitializer extends ServerChannelInitializer {
|
|||||||
log.debug("Client connecting to world {}, channel {} from {}", world, channel, clientIp);
|
log.debug("Client connecting to world {}, channel {} from {}", world, channel, clientIp);
|
||||||
|
|
||||||
PacketProcessor packetProcessor = PacketProcessor.getChannelServerProcessor(world, channel);
|
PacketProcessor packetProcessor = PacketProcessor.getChannelServerProcessor(world, channel);
|
||||||
final MapleClient client = new MapleClient(MapleClient.Type.CHANNEL, packetProcessor, world, channel);
|
final long clientSessionId = sessionId.getAndIncrement();
|
||||||
client.setSessionId(sessionId.getAndIncrement());
|
final String remoteAddress = getRemoteAddress(socketChannel);
|
||||||
|
final MapleClient client = MapleClient.createChannelClient(clientSessionId, remoteAddress, packetProcessor, world, channel);
|
||||||
|
|
||||||
if (Server.getInstance().getChannel(world, channel) == null) {
|
if (Server.getInstance().getChannel(world, channel) == null) {
|
||||||
MapleSessionCoordinator.getInstance().closeSession(client, true);
|
MapleSessionCoordinator.getInstance().closeSession(client, true);
|
||||||
|
|||||||
@@ -16,8 +16,9 @@ public class LoginServerInitializer extends ServerChannelInitializer {
|
|||||||
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(MapleClient.Type.LOGIN, packetProcessor, LoginServer.WORLD_ID, LoginServer.CHANNEL_ID);
|
final long clientSessionId = sessionId.getAndIncrement();
|
||||||
client.setSessionId(sessionId.getAndIncrement());
|
final String remoteAddress = getRemoteAddress(socketChannel);
|
||||||
|
final MapleClient client = MapleClient.createLoginClient(clientSessionId, remoteAddress, packetProcessor, LoginServer.WORLD_ID, LoginServer.CHANNEL_ID);
|
||||||
|
|
||||||
if (!MapleSessionCoordinator.getInstance().canStartLoginSession(client)) {
|
if (!MapleSessionCoordinator.getInstance().canStartLoginSession(client)) {
|
||||||
socketChannel.close();
|
socketChannel.close();
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import client.MapleClient;
|
|||||||
import config.YamlConfig;
|
import config.YamlConfig;
|
||||||
import constants.net.ServerConstants;
|
import constants.net.ServerConstants;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.ChannelHandler;
|
import io.netty.channel.ChannelHandler;
|
||||||
import io.netty.channel.ChannelInitializer;
|
import io.netty.channel.ChannelInitializer;
|
||||||
import io.netty.channel.ChannelPipeline;
|
import io.netty.channel.ChannelPipeline;
|
||||||
@@ -14,11 +15,16 @@ import net.encryption.InitializationVector;
|
|||||||
import net.encryption.PacketCodec;
|
import net.encryption.PacketCodec;
|
||||||
import net.packet.logging.InPacketLogger;
|
import net.packet.logging.InPacketLogger;
|
||||||
import net.packet.logging.OutPacketLogger;
|
import net.packet.logging.OutPacketLogger;
|
||||||
|
import net.server.coordinator.session.IpAddresses;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import tools.MaplePacketCreator;
|
import tools.MaplePacketCreator;
|
||||||
|
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
public abstract class ServerChannelInitializer extends ChannelInitializer<SocketChannel> {
|
public abstract class ServerChannelInitializer extends ChannelInitializer<SocketChannel> {
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(ServerChannelInitializer.class);
|
||||||
private static final int IDLE_TIME_SECONDS = 30;
|
private static final int IDLE_TIME_SECONDS = 30;
|
||||||
private static final boolean LOG_PACKETS = YamlConfig.config.server.USE_DEBUG_SHOW_PACKET;
|
private static final boolean LOG_PACKETS = YamlConfig.config.server.USE_DEBUG_SHOW_PACKET;
|
||||||
private static final ChannelHandler sendPacketLogger = new OutPacketLogger();
|
private static final ChannelHandler sendPacketLogger = new OutPacketLogger();
|
||||||
@@ -26,6 +32,20 @@ public abstract class ServerChannelInitializer extends ChannelInitializer<Socket
|
|||||||
|
|
||||||
static final AtomicLong sessionId = new AtomicLong(7777);
|
static final AtomicLong sessionId = new AtomicLong(7777);
|
||||||
|
|
||||||
|
String getRemoteAddress(Channel channel) {
|
||||||
|
String remoteAddress = "null";
|
||||||
|
try {
|
||||||
|
String hostAddress = ((InetSocketAddress) channel.remoteAddress()).getAddress().getHostAddress();
|
||||||
|
if (hostAddress != null) {
|
||||||
|
remoteAddress = IpAddresses.evaluateRemoteAddress(hostAddress); // thanks dyz for noticing Local/LAN/WAN connections not interacting properly
|
||||||
|
}
|
||||||
|
} catch (NullPointerException npe) {
|
||||||
|
log.warn("Unable to get remote address from netty Channel: {}", channel, npe);
|
||||||
|
}
|
||||||
|
|
||||||
|
return remoteAddress;
|
||||||
|
}
|
||||||
|
|
||||||
void initPipeline(SocketChannel socketChannel, MapleClient client) {
|
void initPipeline(SocketChannel socketChannel, MapleClient client) {
|
||||||
final InitializationVector sendIv = InitializationVector.generateSend();
|
final InitializationVector sendIv = InitializationVector.generateSend();
|
||||||
final InitializationVector recvIv = InitializationVector.generateReceive();
|
final InitializationVector recvIv = InitializationVector.generateReceive();
|
||||||
|
|||||||
Reference in New Issue
Block a user