package handling.login.handler;
import client.MapleClient;
import constants.WorldConstants;
import handling.channel.ChannelServer;
import handling.login.LoginServer;
import tools.MaplePacketCreator;
import tools.data.input.SeekableLittleEndianAccessor;
public class CharSelectedHandler {
private static boolean loginFailCount(MapleClient c) {
c.loginAttempt = (short) (c.loginAttempt + 1);
return c.loginAttempt > 5;
}
public static void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
int charId = slea.readInt();
if (!c.isLoggedIn() || loginFailCount(c) || (!c.login_Auth(charId))) {
c.getSession().write(MaplePacketCreator.enableActions());
return;
}
if ((ChannelServer.getInstance(c.getChannel()) == null) || !WorldConstants.isExists(c.getWorld())) {
c.getSession().close(true);
return;
}
if (c.getIdleTask() != null) {
c.getIdleTask().cancel(true);
}
String ip = c.getSessionIPAddress();
LoginServer.putLoginAuth(charId, ip.substring(ip.indexOf('/') + 1, ip.length()), c.getTempIP(), c.getChannel());
c.updateLoginState(MapleClient.LOGIN_SERVER_TRANSITION, ip);
c.getSession().write(MaplePacketCreator.getServerIP(c, Integer.parseInt(ChannelServer.getInstance(c.getChannel()).getIP().split(":")[1]), charId));
}
}