Example #1
0
  public static final void login(final LittleEndianAccessor slea, final MapleClient c) {
    String login = c.isLocalhost() ? "admin" : slea.readMapleAsciiString();
    String pwd = c.isLocalhost() ? "admin" : slea.readMapleAsciiString();

    int loginok = 0;
    final boolean ipBan = c.hasBannedIP();
    final boolean macBan = c.hasBannedMac();

    if (AutoRegister.getAccountExists(login) != false) {
      loginok = c.login(login, pwd, ipBan || macBan);
    } else if (AutoRegister.autoRegister != false && (!c.hasBannedIP() || !c.hasBannedMac())) {
      AutoRegister.createAccount(login, pwd, c.getSession().getRemoteAddress().toString());
      if (AutoRegister.success != false) {
        loginok = c.login(login, pwd, ipBan || macBan);
      }
    }
    final Calendar tempbannedTill = c.getTempBanCalendar();

    if (loginok == 0 && (ipBan || macBan) && !c.isGm()) {
      loginok = 3;
      if (macBan) {
        // this is only an ipban o.O" - maybe we should refactor this a bit so it's more readable
        MapleCharacter.ban(
            c.getSession().getRemoteAddress().toString().split(":")[0],
            "Enforcing account ban, account " + login,
            false,
            4,
            false);
      }
    }
    if (loginok != 0) {
      if (!loginFailCount(c)) {
        c.clearInformation();
        c.getSession().write(LoginPacket.getLoginFailed(loginok));
      } else {
        c.getSession().close();
      }
    } else if (tempbannedTill.getTimeInMillis() != 0) {
      if (!loginFailCount(c)) {
        c.clearInformation();
        c.getSession()
            .write(
                LoginPacket.getTempBan(
                    PacketHelper.getTime(tempbannedTill.getTimeInMillis()), c.getBanReason()));
      } else {
        c.getSession().close();
      }
    } else {
      c.loginAttempt = 0;
      LoginWorker.registerClient(c);
    }
  }
  public static final void login(String username, MapleClient c, String pwd) {
    String login = username;
    int loginok = 0;
    boolean isBanned = c.hasBannedIP() || c.hasBannedMac() || c.hasProxyBan();
    loginok = c.login(login, pwd, isBanned);
    Calendar tempbannedTill = c.getTempBanCalendar();

    if ((loginok == 0) && (isBanned)) {
      loginok = 3;
    }
    if (loginok != 0) {
      if (!loginFailCount(c)) {
        c.clearInformation();
        c.getSession().write(LoginPacket.getLoginFailed(loginok));
      } else {
        c.getSession().close(true);
      }
    } else if (tempbannedTill.getTimeInMillis() != 0L) {
      if (!loginFailCount(c)) {
        c.clearInformation();
        c.getSession()
            .write(
                LoginPacket.getTempBan(
                    PacketHelper.getTime(tempbannedTill.getTimeInMillis()), c.getBanReason()));
      } else {
        c.getSession().close(true);
      }
    } else {
      c.loginAttempt = 0;
      LoginWorker.registerClient(c);
    }
  }
  @Override
  public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {

    String pic = slea.readMapleAsciiString();
    int charId = slea.readInt();
    byte world = (byte) slea.readInt(); // world
    c.setWorld(world);
    byte channel =
        (byte) Randomizer.rand(0, Server.getInstance().getWorld(world).getChannels().size());
    c.setChannel(channel);
    String macs = slea.readMapleAsciiString();
    c.updateMacs(macs);

    if (c.hasBannedMac()) {
      c.getSession().close(true);
      return;
    }
    if (c.checkPic(pic)) {
      try {
        if (c.getIdleTask() != null) {
          c.getIdleTask().cancel(true);
        }
        c.updateLoginState(MapleClient.LOGIN_SERVER_TRANSITION);

        String channelServerIP =
            MapleClient.getChannelServerIPFromSubnet(
                c.getSession().getRemoteAddress().toString().replace("/", "").split(":")[0],
                channel);
        if (channelServerIP.equals("0.0.0.0")) {
          String[] socket = Server.getInstance().getIP(world, channel).split(":");

          c.announce(
              MaplePacketCreator.getServerIP(
                  InetAddress.getByName(socket[0]), Integer.parseInt(socket[1]), charId));
        } else {
          String[] socket = Server.getInstance().getIP(world, channel).split(":");
          c.announce(
              MaplePacketCreator.getServerIP(
                  InetAddress.getByName(channelServerIP), Integer.parseInt(socket[1]), charId));
        }
      } catch (UnknownHostException e) {
        log.error("Host not found", e);
      }

    } else {

      c.announce(MaplePacketCreator.wrongPic());
    }
  }