Ejemplo n.º 1
0
    @Override
    public void run() {
      boolean verify =
          this.session.hasFlag(MinecraftConstants.VERIFY_USERS_KEY)
              ? this.session.<Boolean>getFlag(MinecraftConstants.VERIFY_USERS_KEY)
              : true;

      GameProfile profile = null;
      if (verify && this.key != null) {
        Proxy proxy = this.session.<Proxy>getFlag(MinecraftConstants.AUTH_PROXY_KEY);
        if (proxy == null) {
          proxy = Proxy.NO_PROXY;
        }

        try {
          profile =
              new SessionService(proxy)
                  .getProfileByServer(
                      username,
                      new BigInteger(
                              CryptUtil.getServerIdHash(serverId, KEY_PAIR.getPublic(), this.key))
                          .toString(16));
        } catch (RequestException e) {
          this.session.disconnect("Failed to make session service request.", e);
          return;
        }

        if (profile == null) {
          this.session.disconnect("Failed to verify username.");
        }
      } else {
        profile =
            new GameProfile(
                UUID.nameUUIDFromBytes(("OfflinePlayer:" + username).getBytes()), username);
      }

      int threshold;
      if (this.session.hasFlag(MinecraftConstants.SERVER_COMPRESSION_THRESHOLD)) {
        threshold = this.session.getFlag(MinecraftConstants.SERVER_COMPRESSION_THRESHOLD);
      } else {
        threshold = 256;
      }

      this.session.send(new LoginSetCompressionPacket(threshold));
      this.session.setCompressionThreshold(threshold);
      this.session.send(new LoginSuccessPacket(profile));
      this.session.setFlag(MinecraftConstants.PROFILE_KEY, profile);
      ((MinecraftProtocol) this.session.getPacketProtocol())
          .setSubProtocol(SubProtocol.GAME, false, this.session);
      ServerLoginHandler handler =
          this.session.getFlag(MinecraftConstants.SERVER_LOGIN_HANDLER_KEY);
      if (handler != null) {
        handler.loggedIn(this.session);
      }

      new Thread(new KeepAliveTask(this.session)).start();
    }