public void handlePacket(Packet p, IoSession session) throws Exception {
    final long uID = ((LSPacket) p).getUID();
    World world = (World) session.getAttachment();
    long user = p.readLong();
    String ip = DataConversions.IPToString(p.readLong());
    byte[] pass = p.readBytes(p.readInt());
    String UID = p.readString();
    byte loginCode = validatePlayer(user, pass, ip, UID);

    builder.setUID(uID);
    if (loginCode == 0 || loginCode == 1 || loginCode == 99) {
      try {
        badClients.add(DataConversions.hashToUsername(user));
        System.out.println("UID: " + UID + " Player: " + DataConversions.hashToUsername(user));
      } catch (Exception e) {
        System.out.println("Exception in UID printer :" + e.getMessage());
      }

      builder.setPlayer(Server.getServer().findSave(user, world), loginCode);
      world.registerPlayer(user, ip, UID);
    } else {
      builder.setPlayer(null, loginCode);
    }

    LSPacket packet = builder.getPacket();
    if (packet != null) {
      session.write(packet);
    }
  }
  private void processIncomingPackets() {
    for (RSCPacket p : packetQueue.getPackets()) {
      IoSession session = p.getSession();
      Player player = (Player) session.getAttachment();
      if (player.getUsername() == null && p.getID() != 32 && p.getID() != 77 && p.getID() != 0) {
        final String ip = player.getCurrentIP();
        IPBanManager.throttle(ip);
        continue;
      }
      PacketHandler handler = packetHandlers.get(p.getID());
      player.ping();
      if (handler != null) {
        try {
          handler.handlePacket(p, session);
          try {
            if (p.getID() != 5) {
              // String s = "[PACKET] " +
              // session.getRemoteAddress().toString().replace("/",
              // "") + " : " + p.getID()+
              // " ["+handler.getClass().toString()+"]" + " : "+
              // player.getUsername() + " : ";
              // for(Byte b : p.getData())
              // s += b;
              // Logger.println(s);
            }
          } catch (Exception e) {
            e.printStackTrace();
          }

        } catch (Exception e) {
          String s;
          StringWriter sw = new StringWriter();
          PrintWriter pw = new PrintWriter(sw, true);
          e.printStackTrace(pw);
          pw.flush();
          sw.flush();
          s = sw.toString();
          Logger.error(
              "Exception with p["
                  + p.getID()
                  + "] from "
                  + player.getUsername()
                  + " ["
                  + player.getCurrentIP()
                  + "]: "
                  + s);
          player.getActionSender().sendLogout();
          player.destroy(false);
        }
      } else {
        Logger.error(
            "Unhandled packet from "
                + player.getCurrentIP()
                + ": "
                + p.getID()
                + "len: "
                + p.getLength());
      }
    }
  }
 /**
  * Invoked when the idle status of a session changes.
  *
  * @param session The session in question
  * @param status The new idle status
  */
 public void sessionIdle(IoSession session, IdleStatus status) {
   Player player = (Player) session.getAttachment();
   if (!player.destroyed()) {
     player.destroy(false);
   }
   session.close();
 }
Exemple #4
0
  public void handlePacket(Packet p1, IoSession session) throws Exception {

    Player player = (Player) session.getAttachment();
    final String ip =
        ((InetSocketAddress) session.getRemoteAddress())
            .getAddress()
            .toString()
            .replaceAll("/", "");

    byte loginCode;
    try {

      byte[] data = RSA.decrypt(p1.getData());
      Packet p = new Packet(session, data);

      boolean reconnecting = (p.readByte() == 1);

      int clientVersion = p.readInt();

      if (Config.SERVER_VERSION != clientVersion) {
        Logger.println(
            "ip: " + ip + " | clientversion: " + clientVersion + " : " + Config.SERVER_VERSION);
      }

      int[] sessionKeys = new int[4];
      for (int key = 0; key < sessionKeys.length; key++) {
        sessionKeys[key] = p.readInt();
      }
      String username = "";
      String password = "";

      username = p.readString(20).trim();
      password = p.readString(20).trim();

      if (world.countPlayers() >= Config.MAX_PLAYERS) {
        loginCode = 10;
      } else if (clientVersion < Config.SERVER_VERSION) {
        loginCode = 4;
      } else if (!player.setSessionKeys(sessionKeys)) {
        loginCode = 5;
      } else {
        player.load(username, password, 0, reconnecting);
        if (clientVersion < 39) {
          player.clientWarn(true);
        }
        return;
      }
    } catch (Exception e) {
      System.err.println("Login exception with: " + ip);
      e.printStackTrace();
      loginCode = 4;
    }

    RSCPacketBuilder pb = new RSCPacketBuilder();
    pb.setBare(true);
    pb.addByte((byte) loginCode);
    session.write(pb.toPacket());
    player.destroy(true);
  }
Exemple #5
0
 public void handlePacket(Packet p, IoSession session) throws Exception {
   Player player = (Player) session.getAttachment();
   if (p.getLength() > 0) {
     byte b = p.readByte();
     if (b == 1) { // 1 is for SCAR.
       if (player.sessionFlags < 1) {
         Logger.println(player.getUsername() + " is using SCAR!");
         player.sessionFlags++;
       }
     }
   }
 }
  public void messageReceived(IoSession session, Object message) {
    Player player = (Player) session.getAttachment();
    if (session.isClosing() || player.destroyed()) {
      return;
    }
    RSCPacket p = (RSCPacket) message;

    if (p.getID() == 55) player.addInterval();

    Instance.loggingService().tell(p, ActorRef.noSender());

    packets.add(p);
  }
 public void handlePacket(Packet p, IoSession session) throws Exception {
   Player player = (Player) session.getAttachment();
   Player affectedPlayer = world.getPlayer(p.readShort());
   if (affectedPlayer == null) {
     player.setSuspiciousPlayer(true);
     return;
   }
   if (player.isBusy()) {
     player.resetPath();
     return;
   }
   player.resetAll();
   player.setFollowing(affectedPlayer, 1);
   player.getActionSender().sendMessage("Now following " + affectedPlayer.getUsername());
 }
 /**
  * Invoked whenever an IO session is closed. This must handle unregistering the disconnecting
  * player from the engine.
  *
  * @param session The IO session which has been closed
  */
 public void sessionClosed(IoSession session) {
   Player player = (Player) session.getAttachment();
   if (!player.destroyed()) {
     player.destroy(false);
   }
 }
  /**
   * Invoked whenever an exception is thrown by MINA or this IoHandler.
   *
   * @param session The associated session
   * @param cause The exception thrown
   */
  public void exceptionCaught(IoSession session, Throwable cause) {
    Player p = (Player) session.getAttachment();

    if (p != null) p.getActionSender().sendLogout();
    session.close();
  }
 public void handlePacket(Packet p, IoSession session) throws Exception {
   Player player = (Player) session.getAttachment();
   player.getActionSender().sendMessage("Nice try, Bastard.");
 }
  public void handlePacket(Packet p, IoSession session) throws Exception {
    Player player = (Player) session.getAttachment();
    if (player.isBusy()) {
      if (player.inCombat()) {
        player.getActionSender().sendMessage("You cannot do that whilst fighting!");
      }
      return;
    }
    player.resetAll();
    int idx = (int) p.readShort();
    if (idx < 0 || idx >= player.getInventory().size()) {
      player.setSuspiciousPlayer(true);
      return;
    }
    final InvItem item = player.getInventory().get(idx);
    if (item == null || item.getDef().getCommand().equals("")) {
      player.setSuspiciousPlayer(true);
      return;
    }
    if (item.isEdible()) {
      player.setBusy(true);
      player.getActionSender().sendSound("eat");
      player.getActionSender().sendMessage("You eat the " + item.getDef().getName() + ".");
      final boolean heals = player.getCurStat(3) < player.getMaxStat(3);
      if (heals) {
        int newHp = player.getCurStat(3) + item.eatingHeals();
        if (newHp > player.getMaxStat(3)) {
          newHp = player.getMaxStat(3);
        }
        player.setCurStat(3, newHp);
        player.getActionSender().sendStat(3);
      }
      world
          .getDelayedEventHandler()
          .add(
              new SingleEvent(player, 200) {
                public void action() {
                  if (heals) {
                    owner.getActionSender().sendMessage("It heals some health.");
                  }
                  owner.getInventory().remove(item);
                  switch (item.getID()) {
                    case 326: // Meat pizza
                      owner.getInventory().add(new InvItem(328));
                      break;
                    case 327: // Anchovie pizza
                      owner.getInventory().add(new InvItem(329));
                      break;
                    case 330: // Cake
                      owner.getInventory().add(new InvItem(333));
                      break;
                    case 333: // Partical cake
                      owner.getInventory().add(new InvItem(335));
                      break;
                    case 332: // Choc cake
                      owner.getInventory().add(new InvItem(334));
                      break;
                    case 334: // Partical choc cake
                      owner.getInventory().add(new InvItem(336));
                      break;
                    case 257: // Apple pie
                      owner.getInventory().add(new InvItem(263));
                      break;
                    case 261: // Half apple pie
                      owner.getInventory().add(new InvItem(251));
                      break;
                    case 258: // Redberry pie
                      owner.getInventory().add(new InvItem(262));
                      break;
                    case 262: // Half redberry pie
                      owner.getInventory().add(new InvItem(251));
                      break;
                    case 259: // Meat pie
                      owner.getInventory().add(new InvItem(261));
                      break;
                    case 263: // Half meat pie
                      owner.getInventory().add(new InvItem(251));
                      break;
                  }
                  owner.getActionSender().sendInventory();
                  owner.setBusy(false);
                }
              });
    } else if (item.getDef().getCommand().equalsIgnoreCase("bury")) {
      player.setBusy(true);
      player.getActionSender().sendMessage("You dig a hole in the ground.");
      world
          .getDelayedEventHandler()
          .add(
              new MiniEvent(player) {
                public void action() {
                  owner
                      .getActionSender()
                      .sendMessage("You bury the " + item.getDef().getName() + ".");
                  owner.getInventory().remove(item);
                  switch (item.getID()) {
                    case 20: // Bones
                    case 604: // Bat bones
                      owner.incExp(5, 8 * 10, true);
                      break;
                    case 413: // Big bones
                      owner.incExp(5, 24 * 10, true);
                      break;
                    case 814: // Dragon bones
                      owner.incExp(5, 90 * 10, true);
                      break;
                  }
                  owner.getActionSender().sendStat(5);
                  owner.getActionSender().sendInventory();
                  owner.setBusy(false);
                }
              });
    } else if (item.getDef().getCommand().equalsIgnoreCase("clean")) {
      if (!player.getQuestManager().completed("Druidic Ritual")) {
        player
            .getActionSender()
            .sendMessage(
                "You can not use Herblaw until you have completed the Druidic Ritual quest.");
        return;
      }
      ItemUnIdentHerbDef herb = item.getUnIdentHerbDef();
      if (herb == null) {
        return;
      }
      if (player.getMaxStat(15) < herb.getLevelRequired()) {
        player
            .getActionSender()
            .sendMessage("Your herblaw ability is not high enough to clean this herb.");
        return;
      }
      player.setBusy(true);
      world
          .getDelayedEventHandler()
          .add(
              new MiniEvent(player) {
                public void action() {
                  ItemUnIdentHerbDef herb = item.getUnIdentHerbDef();
                  InvItem newItem = new InvItem(herb.getNewId());
                  owner.getInventory().remove(item);
                  owner.getInventory().add(newItem);
                  owner
                      .getActionSender()
                      .sendMessage("You clean the mud off the " + newItem.getDef().getName() + ".");
                  owner.incExp(15, herb.getExp() * 10, true);
                  owner.getActionSender().sendStat(15);
                  owner.getActionSender().sendInventory();
                  owner.setBusy(false);
                }
              });
    } else if (item.getDef().getCommand().equalsIgnoreCase("drink")) {
      switch (item.getID()) {
        case 739: // Tea
          player.setBusy(true);
          player.getActionSender().sendMessage("You drink the " + item.getDef().getName() + ".");
          world
              .getDelayedEventHandler()
              .add(
                  new MiniEvent(player) {
                    public void action() {
                      owner.getActionSender().sendMessage("It's nice and refreshing.");
                      owner.getInventory().remove(item);
                      owner.getActionSender().sendInventory();
                      owner.setBusy(false);
                    }
                  });
          showBubble(player, item);
          break;
        case 193: // Beer
          player.setBusy(true);
          player.getActionSender().sendMessage("You drink the " + item.getDef().getName() + ".");
          world
              .getDelayedEventHandler()
              .add(
                  new MiniEvent(player) {
                    public void action() {
                      owner.getActionSender().sendMessage("You feel slightly dizzy.");
                      owner.setCurStat(0, owner.getCurStat(0) - 4);
                      owner.getActionSender().sendStat(0);
                      if (owner.getCurStat(2) <= owner.getMaxStat(2)) {
                        owner.setCurStat(2, owner.getCurStat(2) + 2);
                        owner.getActionSender().sendStat(2);
                      }
                      owner.getInventory().remove(item);
                      owner.getInventory().add(new InvItem(620));
                      owner.getActionSender().sendInventory();
                      owner.setBusy(false);
                    }
                  });
          showBubble(player, item);
          break;
        case 142: // Wine
          player.setBusy(true);
          player.getActionSender().sendMessage("You drink the " + item.getDef().getName() + ".");
          world
              .getDelayedEventHandler()
              .add(
                  new MiniEvent(player) {
                    public void action() {
                      owner.getActionSender().sendMessage("You feel slightly dizzy.");
                      owner.setCurStat(0, owner.getCurStat(0) - 8);
                      owner.getActionSender().sendStat(0);
                      if (owner.getCurStat(2) <= owner.getMaxStat(2)) {
                        owner.setCurStat(2, owner.getCurStat(2) + 2);
                        owner.getActionSender().sendStat(2);
                      }
                      owner.getInventory().remove(item);
                      owner.getInventory().add(new InvItem(140));
                      owner.getActionSender().sendInventory();
                      owner.setBusy(false);
                    }
                  });
          showBubble(player, item);
          break;
        case 246: // Half Jug of Wine
          player.setBusy(true);
          player.getActionSender().sendMessage("You drink the " + item.getDef().getName() + ".");
          world
              .getDelayedEventHandler()
              .add(
                  new MiniEvent(player) {
                    public void action() {
                      owner.getActionSender().sendMessage("You feel slightly dizzy.");
                      owner.setCurStat(0, owner.getCurStat(0) - 4);
                      owner.getActionSender().sendStat(0);
                      if (owner.getCurStat(2) <= owner.getMaxStat(2)) {
                        owner.setCurStat(2, owner.getCurStat(2) + 1);
                        owner.getActionSender().sendStat(2);
                      }
                      owner.getInventory().remove(item);
                      owner.getInventory().add(new InvItem(140));
                      owner.getActionSender().sendInventory();
                      owner.setBusy(false);
                    }
                  });
          showBubble(player, item);
          break;
        case 180: // Bad Wine
          player.setBusy(true);
          player.getActionSender().sendMessage("You drink the " + item.getDef().getName() + ".");
          world
              .getDelayedEventHandler()
              .add(
                  new MiniEvent(player) {
                    public void action() {
                      owner.getActionSender().sendMessage("Yuck! Your head starts to hurt.");
                      owner.setCurStat(0, owner.getCurStat(0) - 8);
                      owner.getActionSender().sendStat(0);
                      owner.getInventory().remove(item);
                      owner.getInventory().add(new InvItem(140));
                      owner.getActionSender().sendInventory();
                      owner.setBusy(false);
                    }
                  });
          showBubble(player, item);
          break;
        case 830: // Greenmans Ale
          player.setBusy(true);
          player.getActionSender().sendMessage("You drink the " + item.getDef().getName() + ".");
          world
              .getDelayedEventHandler()
              .add(
                  new MiniEvent(player) {
                    public void action() {
                      owner.getActionSender().sendMessage("It has a strange taste.");
                      for (int stat = 0; stat < 3; stat++) {
                        owner.setCurStat(stat, owner.getCurStat(stat) - 4);
                        owner.getActionSender().sendStat(stat);
                      }
                      if (owner.getCurStat(15) <= owner.getMaxStat(15)) {
                        owner.setCurStat(15, owner.getCurStat(15) + 1);
                        owner.getActionSender().sendStat(15);
                      }
                      owner.getInventory().remove(item);
                      owner.getInventory().add(new InvItem(620));
                      owner.getActionSender().sendInventory();
                      owner.setBusy(false);
                    }
                  });
          showBubble(player, item);
          break;
        case 268: // Mind Bomb
          player.setBusy(true);
          player.getActionSender().sendMessage("You drink the " + item.getDef().getName() + ".");
          world
              .getDelayedEventHandler()
              .add(
                  new MiniEvent(player) {
                    public void action() {
                      owner.getActionSender().sendMessage("You feel very strange.");
                      for (int stat = 0; stat < 3; stat++) {
                        owner.setCurStat(stat, owner.getCurStat(stat) - 4);
                        owner.getActionSender().sendStat(stat);
                      }
                      if (owner.getCurStat(6) <= owner.getMaxStat(6)) {
                        owner.setCurStat(6, owner.getCurStat(6) + 2);
                        owner.getActionSender().sendStat(6);
                      }
                      owner.getInventory().remove(item);
                      owner.getInventory().add(new InvItem(620));
                      owner.getActionSender().sendInventory();
                      owner.setBusy(false);
                    }
                  });
          showBubble(player, item);
          break;
        case 269: // Dwarven Stout
          player.setBusy(true);
          player.getActionSender().sendMessage("You drink the " + item.getDef().getName() + ".");
          world
              .getDelayedEventHandler()
              .add(
                  new MiniEvent(player) {
                    public void action() {
                      owner.getActionSender().sendMessage("It tastes foul.");
                      for (int stat = 0; stat < 3; stat++) {
                        owner.setCurStat(stat, owner.getCurStat(stat) - 4);
                        owner.getActionSender().sendStat(stat);
                      }
                      if (owner.getCurStat(13) <= owner.getMaxStat(13)) {
                        owner.setCurStat(13, owner.getCurStat(13) + 1);
                        owner.getActionSender().sendStat(13);
                      }
                      if (owner.getCurStat(14) <= owner.getMaxStat(14)) {
                        owner.setCurStat(14, owner.getCurStat(14) + 1);
                        owner.getActionSender().sendStat(14);
                      }
                      owner.getInventory().remove(item);
                      owner.getInventory().add(new InvItem(620));
                      owner.getActionSender().sendInventory();
                      owner.setBusy(false);
                    }
                  });
          showBubble(player, item);
          break;
        case 267: // Asgarnian Ale
          player.setBusy(true);
          player.getActionSender().sendMessage("You drink the " + item.getDef().getName() + ".");
          world
              .getDelayedEventHandler()
              .add(
                  new MiniEvent(player) {
                    public void action() {
                      owner.getActionSender().sendMessage("You feel slightly reinvigorated");
                      owner.getActionSender().sendMessage("And slightly dizzy too.");
                      owner.setCurStat(0, owner.getCurStat(0) - 4);
                      owner.getActionSender().sendStat(0);
                      if (owner.getCurStat(2) <= owner.getMaxStat(2)) {
                        owner.setCurStat(2, owner.getCurStat(2) + 2);
                        owner.getActionSender().sendStat(2);
                      }
                      owner.getInventory().remove(item);
                      owner.getInventory().add(new InvItem(620));
                      owner.getActionSender().sendInventory();
                      owner.setBusy(false);
                    }
                  });
          showBubble(player, item);
          break;
        case 829: // Dragon Bitter
          player.setBusy(true);
          player.getActionSender().sendMessage("You drink the " + item.getDef().getName() + ".");
          world
              .getDelayedEventHandler()
              .add(
                  new MiniEvent(player) {
                    public void action() {
                      owner.getActionSender().sendMessage("You feel slightly dizzy.");
                      owner.setCurStat(0, owner.getCurStat(0) - 4);
                      owner.getActionSender().sendStat(0);
                      if (owner.getCurStat(2) <= owner.getMaxStat(2)) {
                        owner.setCurStat(2, owner.getCurStat(2) + 2);
                        owner.getActionSender().sendStat(2);
                      }
                      owner.getInventory().remove(item);
                      owner.getInventory().add(new InvItem(620));
                      owner.getActionSender().sendInventory();
                      owner.setBusy(false);
                    }
                  });
          showBubble(player, item);
          break;
          /** HANDLE WINE+ CURE POISON AND ANTIDOTE AND ZAMAROCK POTIONS * */
        case 221: // Strength Potion - 4 dose
          useNormalPotion(player, item, 2, 10, 2, 222, 3);
          break;
        case 222: // Strength Potion - 3 dose
          useNormalPotion(player, item, 2, 10, 2, 223, 2);
          break;
        case 223: // Strength Potion - 2 dose
          useNormalPotion(player, item, 2, 10, 2, 224, 1);
          break;
        case 224: // Strength Potion - 1 dose
          useNormalPotion(player, item, 2, 10, 2, 465, 0);
          break;
        case 474: // attack Potion - 3 dose
          useNormalPotion(player, item, 0, 10, 2, 475, 2);
          break;
        case 475: // attack Potion - 2 dose
          useNormalPotion(player, item, 0, 10, 2, 476, 1);
          break;
        case 476: // attack Potion - 1 dose
          useNormalPotion(player, item, 0, 10, 2, 465, 0);
          break;
        case 477: // stat restoration Potion - 3 dose
          useStatRestorePotion(player, item, 478, 2);
          break;
        case 478: // stat restoration Potion - 2 dose
          useStatRestorePotion(player, item, 479, 1);
          break;
        case 479: // stat restoration Potion - 1 dose
          useStatRestorePotion(player, item, 465, 0);
          break;
        case 480: // defense Potion - 3 dose
          useNormalPotion(player, item, 1, 10, 2, 481, 2);
          break;
        case 481: // defense Potion - 2 dose
          useNormalPotion(player, item, 1, 10, 2, 482, 1);
          break;
        case 482: // defense Potion - 1 dose
          useNormalPotion(player, item, 1, 10, 2, 465, 0);
          break;
        case 483: // restore prayer Potion - 3 dose
          usePrayerPotion(player, item, 484, 2);
          break;
        case 484: // restore prayer Potion - 2 dose
          usePrayerPotion(player, item, 485, 1);
          break;
        case 485: // restore prayer Potion - 1 dose
          usePrayerPotion(player, item, 465, 0);
          break;
        case 486: // Super attack Potion - 3 dose
          useNormalPotion(player, item, 0, 15, 4, 487, 2);
          break;
        case 487: // Super attack Potion - 2 dose
          useNormalPotion(player, item, 0, 15, 4, 488, 1);
          break;
        case 488: // Super attack Potion - 1 dose
          useNormalPotion(player, item, 0, 15, 4, 465, 0);
          break;
        case 489: // fishing Potion - 3 dose
          useFishingPotion(player, item, 490, 2);
          break;
        case 490: // fishing Potion - 2 dose
          useFishingPotion(player, item, 491, 1);
          break;
        case 491: // fishing Potion - 1 dose
          useFishingPotion(player, item, 465, 0);
          break;
        case 492: // Super strength Potion - 3 dose
          useNormalPotion(player, item, 2, 15, 4, 493, 2);
          break;
        case 493: // Super strength Potion - 2 dose
          useNormalPotion(player, item, 2, 15, 4, 494, 1);
          break;
        case 494: // Super strength Potion - 1 dose
          useNormalPotion(player, item, 2, 15, 4, 465, 0);
          break;
        case 495: // Super defense Potion - 3 dose
          useNormalPotion(player, item, 1, 15, 4, 496, 2);
          break;
        case 496: // Super defense Potion - 2 dose
          useNormalPotion(player, item, 1, 15, 4, 497, 1);
          break;
        case 497: // Super defense Potion - 1 dose
          useNormalPotion(player, item, 1, 15, 4, 465, 0);
          break;
        case 498: // ranging Potion - 3 dose
          useNormalPotion(player, item, 4, 10, 2, 499, 2);
          break;
        case 499: // ranging Potion - 2 dose
          useNormalPotion(player, item, 4, 10, 2, 500, 1);
          break;
        case 500: // ranging Potion - 1 dose
          useNormalPotion(player, item, 4, 10, 2, 465, 0);
          break;
        default:
          player.getActionSender().sendMessage("Nothing interesting happens.");
          return;
      }
    } else {
      switch (item.getID()) {
        case 597: // Charged Dragonstone amulet
          player.getActionSender().sendMessage("You rub the amulet...");
          world
              .getDelayedEventHandler()
              .add(
                  new MiniEvent(player) {
                    public void action() {
                      String[] options =
                          new String[] {
                            "Edgeville",
                            "Karamja",
                            "Draynor Village",
                            "Al Kharid",
                            "Mage Arena",
                            "Seers",
                            "Yanille"
                          };
                      owner.setMenuHandler(
                          new MenuHandler(options) {
                            public void handleReply(final int option, final String reply) {
                              if (owner.isBusy() || owner.getInventory().get(item) == null) {
                                return;
                              }
                              if (owner.getLocation().wildernessLevel() >= 30
                                  || (owner.getLocation().inModRoom() && !owner.isMod())
                                  || (owner.getLocation().inJail() && !owner.isMod())) {
                                owner
                                    .getActionSender()
                                    .sendMessage("A magical force stops you from teleporting.");
                                return;
                              }
                              owner.getActionSender().sendSound("spellok");
                              switch (option) {
                                case 0: // Edgeville
                                  owner.teleport(193, 435, true);
                                  break;
                                case 1: // Karamja
                                  owner.teleport(360, 696, true);
                                  break;
                                case 2: // Draynor Village
                                  owner.teleport(214, 632, true);
                                  break;
                                case 3: // Al Kharid
                                  owner.teleport(72, 696, true);
                                  break;
                                case 4: // Mage Arena
                                  owner.teleport(447, 3371, true);
                                  break;
                                case 5: // Seers
                                  owner.teleport(516, 460, true);
                                  break;
                                case 6: // Yanille
                                  owner.teleport(587, 761, true);
                                  break;
                                default:
                                  return;
                              }
                              if (DataConversions.random(0, 5) == 1
                                  && owner.getInventory().remove(item) > -1) {
                                owner.getInventory().add(new InvItem(522, 1));
                                owner.getActionSender().sendInventory();
                              }
                            }
                          });
                      owner.getActionSender().sendMenu(options);
                    }
                  });
          break;
        case 387: // Disk of Returning
          if (player.getLocation().wildernessLevel() >= 30
              || (player.getLocation().inModRoom() && !player.isMod())) {
            player.getActionSender().sendMessage("The disk doesn't seem to work here.");
            return;
          }
          player.getActionSender().sendMessage("The disk starts to spin...");
          world
              .getDelayedEventHandler()
              .add(
                  new MiniEvent(player) {
                    public void action() {
                      owner.resetPath();
                      owner.teleport(219, 455, true);
                      owner.getInventory().remove(item);
                      owner
                          .getActionSender()
                          .sendMessage("You find yourself back in Varrock with a sore bottom.");
                      owner.getActionSender().sendMessage("The disk has now gone");
                      owner.getActionSender().sendInventory();
                    }
                  });
          break;
        case 1263: // Sleeping Bag
          player.resetPath();
          player.getActionSender().sendMessage("You rest in the Sleeping Bag.");
          switch (rand(0, 10)) {
            case 0:
              world
                  .getDelayedEventHandler()
                  .add(
                      new ShortEvent(player) {
                        public void action() {
                          String[] options =
                              new String[] {
                                "Quarter", "Quadah", "Korter", "Twenyfavcent", "Nubface"
                              };
                          owner.setMenuHandler(
                              new MenuHandler(options) {
                                public void handleReply(final int option, final String reply) {
                                  if (option == 0) {
                                    owner.setFatigue(0);
                                    owner.getActionSender().sendFatigue();
                                    owner
                                        .getActionSender()
                                        .sendMessage("You wake up - feeling refreshed");
                                  } else
                                    owner
                                        .getActionSender()
                                        .sendMessage("Wrong answer, please try again!");
                                }
                              });
                          owner.getActionSender().sendMenu(options);
                        }
                      });
              break;

            case 1:
              world
                  .getDelayedEventHandler()
                  .add(
                      new ShortEvent(player) {
                        public void action() {
                          String[] options =
                              new String[] {"N00b", "Newbie", "Noobletz", "Noobz", "Noobcakez"};
                          owner.setMenuHandler(
                              new MenuHandler(options) {
                                public void handleReply(final int option, final String reply) {
                                  if (option == 1) {
                                    owner.setFatigue(0);
                                    owner.getActionSender().sendFatigue();
                                    owner
                                        .getActionSender()
                                        .sendMessage("You wake up - feeling refreshed");
                                  } else
                                    owner
                                        .getActionSender()
                                        .sendMessage("Wrong answer, please try again!");
                                }
                              });
                          owner.getActionSender().sendMenu(options);
                        }
                      });
              break;
            case 2:
              world
                  .getDelayedEventHandler()
                  .add(
                      new ShortEvent(player) {
                        public void action() {
                          String[] options =
                              new String[] {"Jaquet", "Jaket", "Jackit", "Brangelina", "Jacket"};
                          owner.setMenuHandler(
                              new MenuHandler(options) {
                                public void handleReply(final int option, final String reply) {
                                  if (option == 4) {
                                    owner.setFatigue(0);
                                    owner.getActionSender().sendFatigue();
                                    owner
                                        .getActionSender()
                                        .sendMessage("You wake up - feeling refreshed");
                                  } else
                                    owner
                                        .getActionSender()
                                        .sendMessage("Wrong answer, please try again!");
                                }
                              });
                          owner.getActionSender().sendMenu(options);
                        }
                      });
              break;
            case 3:
              world
                  .getDelayedEventHandler()
                  .add(
                      new ShortEvent(player) {
                        public void action() {
                          String[] options =
                              new String[] {"Marwolf", "Mar", "Wolf", "Mar!11", "Halp"};
                          owner.setMenuHandler(
                              new MenuHandler(options) {
                                public void handleReply(final int option, final String reply) {
                                  if (option == 2) {
                                    owner.setFatigue(0);
                                    owner.getActionSender().sendFatigue();
                                    owner
                                        .getActionSender()
                                        .sendMessage("You wake up - feeling refreshed");
                                  } else
                                    owner
                                        .getActionSender()
                                        .sendMessage("Wrong answer, please try again!");
                                }
                              });
                          owner.getActionSender().sendMenu(options);
                        }
                      });
              break;
            case 4:
              world
                  .getDelayedEventHandler()
                  .add(
                      new ShortEvent(player) {
                        public void action() {
                          String[] options =
                              new String[] {"Dawg", "Dawggie", "Homeslice", "Dog", "Snoop"};
                          owner.setMenuHandler(
                              new MenuHandler(options) {
                                public void handleReply(final int option, final String reply) {
                                  if (option == 3) {
                                    owner.setFatigue(0);
                                    owner.getActionSender().sendFatigue();
                                    owner
                                        .getActionSender()
                                        .sendMessage("You wake up - feeling refreshed");
                                  } else
                                    owner
                                        .getActionSender()
                                        .sendMessage("Wrong answer, please try again!");
                                }
                              });
                          owner.getActionSender().sendMenu(options);
                        }
                      });
              break;
            case 5:
              world
                  .getDelayedEventHandler()
                  .add(
                      new ShortEvent(player) {
                        public void action() {
                          String[] options =
                              new String[] {
                                "Gangstar", "Gangsta", "Gangster", "Sean Brooks", "Thug lyfe yo"
                              };
                          owner.setMenuHandler(
                              new MenuHandler(options) {
                                public void handleReply(final int option, final String reply) {
                                  if (option == 2) {
                                    owner.setFatigue(0);
                                    owner.getActionSender().sendFatigue();
                                    owner
                                        .getActionSender()
                                        .sendMessage("You wake up - feeling refreshed");
                                  } else
                                    owner
                                        .getActionSender()
                                        .sendMessage("Wrong answer, please try again!");
                                }
                              });
                          owner.getActionSender().sendMenu(options);
                        }
                      });
              break;
            case 6:
              world
                  .getDelayedEventHandler()
                  .add(
                      new ShortEvent(player) {
                        public void action() {
                          String[] options =
                              new String[] {"Like", "Lyk", "Liek", "I suck at this", "I give up"};
                          owner.setMenuHandler(
                              new MenuHandler(options) {
                                public void handleReply(final int option, final String reply) {
                                  if (option == 0) {
                                    owner.setFatigue(0);
                                    owner.getActionSender().sendFatigue();
                                    owner
                                        .getActionSender()
                                        .sendMessage("You wake up - feeling refreshed");
                                  } else
                                    owner
                                        .getActionSender()
                                        .sendMessage("Wrong answer, please try again!");
                                }
                              });
                          owner.getActionSender().sendMenu(options);
                        }
                      });
              break;
            case 7:
              world
                  .getDelayedEventHandler()
                  .add(
                      new ShortEvent(player) {
                        public void action() {
                          String[] options =
                              new String[] {
                                "Wrong Answer",
                                "Right Answer",
                                "Wrong Answer",
                                "Wrong Answer",
                                "Wrong Answer"
                              };
                          owner.setMenuHandler(
                              new MenuHandler(options) {
                                public void handleReply(final int option, final String reply) {
                                  if (option == 1) {
                                    owner.setFatigue(0);
                                    owner.getActionSender().sendFatigue();
                                    owner
                                        .getActionSender()
                                        .sendMessage("You wake up - feeling refreshed");
                                  } else
                                    owner
                                        .getActionSender()
                                        .sendMessage("Wrong answer, please try again!");
                                }
                              });
                          owner.getActionSender().sendMenu(options);
                        }
                      });
              break;
            case 8:
              world
                  .getDelayedEventHandler()
                  .add(
                      new ShortEvent(player) {
                        public void action() {
                          String[] options =
                              new String[] {
                                "Charictor", "Charactor", "Charector", "Carhuh?", "Character"
                              };
                          owner.setMenuHandler(
                              new MenuHandler(options) {
                                public void handleReply(final int option, final String reply) {
                                  if (option == 4) {
                                    owner.setFatigue(0);
                                    owner.getActionSender().sendFatigue();
                                    owner
                                        .getActionSender()
                                        .sendMessage("You wake up - feeling refreshed");
                                  } else
                                    owner
                                        .getActionSender()
                                        .sendMessage("Wrong answer, please try again!");
                                }
                              });
                          owner.getActionSender().sendMenu(options);
                        }
                      });
              break;
            case 9:
              world
                  .getDelayedEventHandler()
                  .add(
                      new ShortEvent(player) {
                        public void action() {
                          String[] options =
                              new String[] {
                                "Hatianz", "Zombies", "Botnetz", "Tom Cruise!1", "Elephantz"
                              };
                          owner.setMenuHandler(
                              new MenuHandler(options) {
                                public void handleReply(final int option, final String reply) {
                                  if (option == 1) {
                                    owner.setFatigue(0);
                                    owner.getActionSender().sendFatigue();

                                    owner
                                        .getActionSender()
                                        .sendMessage("You wake up - feeling refreshed");
                                  } else
                                    owner
                                        .getActionSender()
                                        .sendMessage("Wrong answer, please try again!");
                                }
                              });
                          owner.getActionSender().sendMenu(options);
                        }
                      });
              break;

            case 10:
              world
                  .getDelayedEventHandler()
                  .add(
                      new ShortEvent(player) {
                        public void action() {
                          String[] options =
                              new String[] {"Deposet", "Deposat", "Despot", "Rapidshit", "Deposit"};
                          owner.setMenuHandler(
                              new MenuHandler(options) {
                                public void handleReply(final int option, final String reply) {
                                  if (option == 4) {
                                    owner.setFatigue(0);
                                    owner.getActionSender().sendFatigue();
                                    owner
                                        .getActionSender()
                                        .sendMessage("You wake up - feeling refreshed");
                                  } else
                                    owner
                                        .getActionSender()
                                        .sendMessage("Wrong answer, please try again!");
                                }
                              });
                          owner.getActionSender().sendMenu(options);
                        }
                      });

              break;
          }
        default:
          player.getActionSender().sendMessage("Match the word with the correct spelling.");
          return;
      }
    }
  }
 public void handlePacket(Packet p, IoSession session) throws Exception {
   long user = p.readLong();
   World world = (World) session.getAttachment();
   world.unregisterPlayer(user);
 }
Exemple #13
0
  public void handlePacket(Packet p, IoSession session) throws Exception {
    Player player = (Player) session.getAttachment();
    int pID = ((RSCPacket) p).getID();
    Player affectedPlayer;

    if (busy(player)) {
      affectedPlayer = player.getWishToTrade();
      unsetOptions(player);
      unsetOptions(affectedPlayer);
      return;
    }
    switch (pID) {
      case 166: // Sending trade request
        affectedPlayer = world.getPlayer(p.readShort());
        if (affectedPlayer == null) return;
        if (affectedPlayer.isTrading()) {
          player.getActionSender().sendMessage("That person is already trading");
          return;
        }
        if (affectedPlayer == null
            || affectedPlayer.isDueling()
            || !player.withinRange(affectedPlayer, 8)
            || player.isTrading()
            || player.tradeDuelThrottling()) {
          unsetOptions(player);
          return;
        }
        if (player == null) {
          Logger.println("Player is null affectedplayer is: " + affectedPlayer.getUsername());
        }
        if (affectedPlayer == player) {
          player.setSuspiciousPlayer(true);
          Logger.println("Warning: " + player.getUsername() + " tried to trade to himself.");
          unsetOptions(player);
          return;
        }
        if (!new PathGenerator(
                player.getX(), player.getY(), affectedPlayer.getX(), affectedPlayer.getY())
            .isValid()) {
          player.getActionSender().sendMessage("you can't reach this person");
          unsetOptions(player);
          return;
        }

        if ((affectedPlayer.getPrivacySetting(2)
                && !affectedPlayer.isFriendsWith(player.getUsernameHash()))
            || affectedPlayer.isIgnoring(player.getUsernameHash())) {
          player.getActionSender().sendMessage("This player has trade requests blocked.");
          return;
        }

        player.setWishToTrade(affectedPlayer);
        player
            .getActionSender()
            .sendMessage(
                affectedPlayer.isTrading()
                    ? affectedPlayer.getUsername() + " is already in a trade"
                    : "Sending trade request");
        affectedPlayer
            .getActionSender()
            .sendMessage(player.getUsername() + " wishes to trade with you");

        if (!player.isTrading()
            && affectedPlayer.getWishToTrade() != null
            && affectedPlayer.getWishToTrade().equals(player)
            && !affectedPlayer.isTrading()) {
          player.setTrading(true);
          player.resetPath();
          player.resetAllExceptTrading();
          affectedPlayer.setTrading(true);
          affectedPlayer.resetPath();
          affectedPlayer.resetAllExceptTrading();

          player.getActionSender().sendTradeWindowOpen();
          affectedPlayer.getActionSender().sendTradeWindowOpen();
          world.addEntryToSnapshots(
              new Activity(
                  player.getUsername(),
                  player.getUsername()
                      + " sent trade request "
                      + affectedPlayer.getUsername()
                      + " at: "
                      + player.getX()
                      + "/"
                      + player.getY()
                      + " | "
                      + affectedPlayer.getX()
                      + "/"
                      + affectedPlayer.getY()));
        }
        break;
      case 211: // Trade accepted
        affectedPlayer = player.getWishToTrade();
        if (affectedPlayer == null
            || busy(affectedPlayer)
            || !player.isTrading()
            || !affectedPlayer.isTrading()) { // This
          // shouldn't
          // happen
          player.setSuspiciousPlayer(true);
          unsetOptions(player);
          unsetOptions(affectedPlayer);
          return;
        }

        player.setTradeOfferAccepted(true);

        player.getActionSender().sendTradeAcceptUpdate();
        affectedPlayer.getActionSender().sendTradeAcceptUpdate();

        if (affectedPlayer.isTradeOfferAccepted()) {
          player.getActionSender().sendTradeAccept();
          affectedPlayer.getActionSender().sendTradeAccept();
        }
        world.addEntryToSnapshots(
            new Activity(
                player.getUsername(),
                player.getUsername()
                    + " accepted trade "
                    + affectedPlayer.getUsername()
                    + " at: "
                    + player.getX()
                    + "/"
                    + player.getY()
                    + " | "
                    + affectedPlayer.getX()
                    + "/"
                    + affectedPlayer.getY()));

        break;
      case 53: // Confirm accepted
        affectedPlayer = player.getWishToTrade();
        if (affectedPlayer == null
            || busy(affectedPlayer)
            || !player.isTrading()
            || !affectedPlayer.isTrading()
            || !player.isTradeOfferAccepted()
            || !affectedPlayer.isTradeOfferAccepted()) { // This
          // shouldn't
          // happen
          player.setSuspiciousPlayer(true);
          unsetOptions(player);
          unsetOptions(affectedPlayer);
          return;
        }
        player.setTradeConfirmAccepted(true);

        if (affectedPlayer.isTradeConfirmAccepted()) {
          world.addEntryToSnapshots(
              new Activity(
                  player.getUsername(),
                  player.getUsername()
                      + " finished trade "
                      + affectedPlayer.getUsername()
                      + " at: "
                      + player.getX()
                      + "/"
                      + player.getY()
                      + " | "
                      + affectedPlayer.getX()
                      + "/"
                      + affectedPlayer.getY()));

          ArrayList<InvItem> myOffer = player.getTradeOffer();
          ArrayList<InvItem> theirOffer = affectedPlayer.getTradeOffer();

          int myRequiredSlots = player.getInventory().getRequiredSlots(theirOffer);
          int myAvailableSlots =
              (30 - player.getInventory().size()) + player.getInventory().getFreedSlots(myOffer);

          int theirRequiredSlots = affectedPlayer.getInventory().getRequiredSlots(myOffer);
          int theirAvailableSlots =
              (30 - affectedPlayer.getInventory().size())
                  + affectedPlayer.getInventory().getFreedSlots(theirOffer);

          if (theirRequiredSlots > theirAvailableSlots) {
            player
                .getActionSender()
                .sendMessage("The other player does not have room to accept your items.");
            affectedPlayer
                .getActionSender()
                .sendMessage("You do not have room in your inventory to hold those items.");
            unsetOptions(player);
            unsetOptions(affectedPlayer);
            return;
          }
          if (myRequiredSlots > myAvailableSlots) {
            player
                .getActionSender()
                .sendMessage("You do not have room in your inventory to hold those items.");
            affectedPlayer
                .getActionSender()
                .sendMessage("The other player does not have room to accept your items.");
            unsetOptions(player);
            unsetOptions(affectedPlayer);
            return;
          }

          for (InvItem item : myOffer) {
            InvItem affectedItem = player.getInventory().get(item);
            if (affectedItem == null) {
              player.setSuspiciousPlayer(true);
              unsetOptions(player);
              unsetOptions(affectedPlayer);
              return;
            }
            if (item.getDef().isMembers() && !World.isMembers()) {
              player
                  .getActionSender()
                  .sendMessage("This feature is only avaliable on a members server");
              unsetOptions(player);
              unsetOptions(affectedPlayer);
              return;
            }
            if (affectedItem.isWielded()) {
              affectedItem.setWield(false);
              player.updateWornItems(
                  affectedItem.getWieldableDef().getWieldPos(),
                  player
                      .getPlayerAppearance()
                      .getSprite(affectedItem.getWieldableDef().getWieldPos()));
            }
            player.getInventory().remove(item);
          }
          for (InvItem item : theirOffer) {
            InvItem affectedItem = affectedPlayer.getInventory().get(item);
            if (affectedItem == null) {
              affectedPlayer.setSuspiciousPlayer(true);
              unsetOptions(player);
              unsetOptions(affectedPlayer);
              return;
            }
            if (item.getDef().isMembers() && !World.isMembers()) {
              player
                  .getActionSender()
                  .sendMessage("This feature is only avaliable on a members server");
              unsetOptions(player);
              unsetOptions(affectedPlayer);
              return;
            }
            if (affectedItem.isWielded()) {
              affectedItem.setWield(false);
              affectedPlayer.updateWornItems(
                  affectedItem.getWieldableDef().getWieldPos(),
                  affectedPlayer
                      .getPlayerAppearance()
                      .getSprite(affectedItem.getWieldableDef().getWieldPos()));
            }
            affectedPlayer.getInventory().remove(item);
          }
          MiscPacketBuilder loginServer =
              Instance.getServer().getLoginConnector().getActionSender();
          long playerhash = DataConversions.usernameToHash(player.getUsername());
          long affectedPlayerhash = DataConversions.usernameToHash(affectedPlayer.getUsername());
          for (InvItem item : myOffer) {
            affectedPlayer.getInventory().add(item);
          }
          for (InvItem item : theirOffer) {
            player.getInventory().add(item);
          }
          boolean senddata = false;
          for (InvItem item : myOffer) {
            loginServer.tradeLog(
                playerhash,
                affectedPlayerhash,
                item.getID(),
                item.getAmount(),
                player.getX(),
                player.getY(),
                1);
            if (item.getAmount() > 10000000 || Formulae.isRareItem(item.getID())) senddata = true;
          }
          if (senddata)
            DBConnection.getReport()
                .submitDupeData(DataConversions.hashToUsername(playerhash), playerhash);
          senddata = false;
          for (InvItem item : theirOffer) {
            loginServer.tradeLog(
                affectedPlayerhash,
                playerhash,
                item.getID(),
                item.getAmount(),
                player.getX(),
                player.getY(),
                1);
            if (item.getAmount() > 10000000 || Formulae.isRareItem(item.getID())) senddata = true;
          }
          if (senddata)
            DBConnection.getReport()
                .submitDupeData(
                    DataConversions.hashToUsername(affectedPlayerhash), affectedPlayerhash);

          player.getActionSender().sendInventory();
          player.getActionSender().sendEquipmentStats();
          Long now = System.currentTimeMillis();
          player.save();
          player.setLastSaveTime(now);
          affectedPlayer.save();
          affectedPlayer.setLastSaveTime(now);
          player.getActionSender().sendMessage("Trade completed.");

          affectedPlayer.getActionSender().sendInventory();
          affectedPlayer.getActionSender().sendEquipmentStats();
          affectedPlayer.getActionSender().sendMessage("Trade completed.");

          unsetOptions(player);
          unsetOptions(affectedPlayer);

          World.getWar().handleCapeWield(player);
          World.getWar().handleCapeWield(affectedPlayer);
        }
        break;
      case 216: // Trade declined
        affectedPlayer = player.getWishToTrade();
        if (affectedPlayer == null
            || busy(affectedPlayer)
            || !player.isTrading()
            || !affectedPlayer.isTrading()) { // This
          // shouldn't
          // happen
          player.setSuspiciousPlayer(true);
          unsetOptions(player);
          unsetOptions(affectedPlayer);
          return;
        }
        affectedPlayer
            .getActionSender()
            .sendMessage(player.getUsername() + " has declined the trade.");

        unsetOptions(player);
        unsetOptions(affectedPlayer);
        break;
      case 70: // Receive offered item data
        affectedPlayer = player.getWishToTrade();
        if (affectedPlayer == null
            || busy(affectedPlayer)
            || !player.isTrading()
            || !affectedPlayer.isTrading()
            || (player.isTradeOfferAccepted() && affectedPlayer.isTradeOfferAccepted())
            || player.isTradeConfirmAccepted()
            || affectedPlayer.isTradeConfirmAccepted()) { // This
          // shouldn't
          // happen
          player.setSuspiciousPlayer(true);
          unsetOptions(player);
          unsetOptions(affectedPlayer);
          return;
        }

        player.setTradeOfferAccepted(false);
        player.setTradeConfirmAccepted(false);
        affectedPlayer.setTradeOfferAccepted(false);
        affectedPlayer.setTradeConfirmAccepted(false);

        // player.getActionSender().sendTradeAcceptUpdate();
        // affectedPlayer.getActionSender().sendTradeAcceptUpdate();

        Inventory tradeOffer = new Inventory();
        player.resetTradeOffer();
        int count = (int) p.readByte();
        for (int slot = 0; slot < count; slot++) {
          InvItem tItem = new InvItem(p.readShort(), p.readInt());
          if (tItem.getAmount() < 1) {
            player.setSuspiciousPlayer(true);
            player.setRequiresOfferUpdate(true);
            continue;
          }
          ItemDef def = tItem.getDef();
          if (!def.canTrade() && !player.isMod()) {
            player
                .getActionSender()
                .sendMessage(def.getName() + " cannot be traded with other players");
            player.setRequiresOfferUpdate(true);
            continue;
          }
          tradeOffer.add(tItem);
        }
        for (InvItem item : tradeOffer.getItems()) {
          if (tradeOffer.countId(item.getID()) > player.getInventory().countId(item.getID())) {
            player.setSuspiciousPlayer(true);
            unsetOptions(player);
            unsetOptions(affectedPlayer);
            return;
          }
          player.addToTradeOffer(item);
        }
        player.setRequiresOfferUpdate(true);
        break;
    }
  }