public void handlePacket(Packet p, Channel session) throws Exception {
   try {
     long user = p.readLong();
     p.readLong();
     World world = (World) session.getAttachment();
     world.unregisterPlayer(user);
   } catch (Exception e) {
     System.out.println("------- EXCEPTION @ PlayerLogoutHandler: -----------");
     e.printStackTrace();
   }
 }
Esempio n. 2
0
  @Override
  public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
    Channel channel = ctx.getChannel();
    if (channel.getAttachment() != null
        && (Error.class.isAssignableFrom(channel.getAttachment().getClass())
            || WRITING.equals(channel.getAttachment().toString()))) {
      return;
    }

    if (!isReceived(ctx)) {
      return;
    }

    try {
      log.error(e.getCause().getMessage(), e.getCause());
      channel.setAttachment(new Error());
      DefaultHttpResponse response =
          new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.INTERNAL_SERVER_ERROR);
      response.setContent(
          ChannelBuffers.copiedBuffer(
              response.getStatus().toString() + ":" + e.getCause().getMessage(),
              CharsetUtil.UTF_8));
      response.headers().set(Names.CONTENT_LENGTH, response.getContent().readableBytes());
      response.headers().set(Names.SERVER, "NAVI/1.1.4(UNIX)");
      response.headers().set(Names.CONNECTION, "close");
      ChannelFuture f = channel.write(response);
      f.addListener(ChannelFutureListener.CLOSE);
      f.addListener(
          new ChannelFutureListener() {

            public void operationComplete(ChannelFuture f) throws Exception {
              if (!f.isSuccess()) {
                log.error(f.getCause().getMessage(), f.getCause());
              }
            }
          });
    } catch (Exception ex) {
      log.error(e.getCause().getMessage(), e.getCause());
      e.getFuture().addListener(ChannelFutureListener.CLOSE);
    }
  }
Esempio n. 3
0
  public void handlePacket(Packet p, Channel session) throws Exception {
    Player player = (Player) session.getAttachment();
    int pID = ((RSCPacket) p).getID();
    if (player.isBusy()) {
      player.resetShop();
      return;
    }
    final Shop shop = player.getShop();
    if (shop == null) {
      player.setSuspiciousPlayer(true);
      player.resetShop();
      return;
    }
    int value;
    InvItem item;

    switch (pID) {
      case 253: // Close shop
        player.resetShop();
        // Services.lookup(DatabaseManager.class).addQuery(new GenericLog(player.getUsername() + "
        // closed shop window at: " + player.getLocation()));
        break;
      case 128: // Buy item
        Short s = p.readShort();
        item = new InvItem(s, 1);
        value = p.readInt();

        // Services.lookup(DatabaseManager.class).addQuery(new GenericLog(player.getUsername() + "
        // tried to buy item " + s + " for " + value + " at " + player.getLocation()));

        if (value < shop.getItemBuyPrice(s)) {
          return;
        }
        if (shop.getItemCount(item.getID()) < 1) return;
        if (player.getInventory().countId(10) < value) {
          player.getActionSender().sendMessage("You don't have enough money!");
          return;
        }
        if ((Inventory.MAX_SIZE - player.getInventory().size())
                + player.getInventory().getFreedSlots(new InvItem(10, value))
            < player.getInventory().getRequiredSlots(item)) {
          player.getActionSender().sendMessage("You can't hold the objects you are trying to buy!");
          return;
        }
        int itemprice = item.getDef().getBasePrice();
        int userHasToPay = shop.getItemBuyPrice(item.getID());

        if (itemprice == 0 || userHasToPay < itemprice) return;

        if (player.getInventory().remove(10, userHasToPay) > -1) {
          shop.removeShopItem(item);
          player.getInventory().add(item);
          player.getActionSender().sendSound("coins");
          player.getActionSender().sendInventory();
        }
        break;
      case 255: // Sell item
        Short s1 = p.readShort();
        item = new InvItem(s1, 1);
        value = p.readInt();

        // Services.lookup(DatabaseManager.class).addQuery(new GenericLog(player.getUsername() + "
        // tried to sell item " + s1 + " for " + value + " at " + player.getLocation()));
        if (player.getInventory().countId(item.getID()) < 1) {
          return;
        }
        if (!shop.shouldStock(item.getID())) {
          return;
        }
        if (!shop.canHoldItem(item)) {
          player.getActionSender().sendMessage("The shop is currently full!");
          return;
        }

        int itempricez;

        if (shop.getItemCount(item.getID()) == 0) {
          itempricez = shop.getGenericPrice(item, false);
        } else {
          itempricez = shop.getItemSellPrice(item.getID());
        }
        if (itempricez > 300000) return;

        if (player.getInventory().remove(item) > -1) {
          player.getInventory().add(new InvItem(10, itempricez));
          shop.addShopItem(item);
          player.getActionSender().sendSound("coins");
          player.getActionSender().sendInventory();
        }
        break;
    }
  }