コード例 #1
0
  public static void Compose(ServerHandler Client, Habbo User, Environment Server)
      throws Exception {
    Habbo CurrentHabbo = User;
    Channel Socket = Client.Socket;
    int PageId = Client.inreader.readInt();
    int ItemId = Client.inreader.readInt();
    String ExtraData = Client.inreader.readUTF();

    CatalogPage Page = CatalogPage.Pages.get(PageId);
    CatalogItem Item = CatalogItem.Items.get(ItemId);

    if (Item.Name.contains("HABBO_CLUB_VIP_")) {
      if (Item.CostCredits > 0 && CurrentHabbo.Credits > Item.CostCredits)
        CurrentHabbo.UpdateCredits(
            (CurrentHabbo.Credits - Item.CostCredits), Client.Socket, Server);
      else return;
      SubscriptionManager Sub = new SubscriptionManager(CurrentHabbo, Server);
      if (Item.Id == 331) {
        // 1 day
        Sub.AddOrExtendSubscription("habbo_vip", (60 * 60 * 24));
        CurrentHabbo.UpdateFuserights(Client.Socket, Server);
        CurrentHabbo.Updateclub(Server, Client);
      } else if (Item.Id == 332) {
        // 7 days
        Sub.AddOrExtendSubscription("habbo_vip", (60 * 60 * 24 * 7));
        CurrentHabbo.UpdateFuserights(Client.Socket, Server);
        CurrentHabbo.Updateclub(Server, Client);
      } else if (Item.Id == 333) {
        // 3 days
        Sub.AddOrExtendSubscription("habbo_vip", (60 * 60 * 24 * 3));
        CurrentHabbo.UpdateFuserights(Client.Socket, Server);
        CurrentHabbo.Updateclub(Server, Client);
      } else if (Item.Id == 334) {
        // 1 month
        Server.WriteLine(CurrentHabbo.UserName + " wants 1 month of vip!");
        Sub.AddOrExtendSubscription("habbo_vip", (60 * 60 * 24 * 31));
        CurrentHabbo.UpdateFuserights(Client.Socket, Server);
        CurrentHabbo.Updateclub(Server, Client);
      } else if (Item.Id == 335) {
        // 3 months
        Sub.AddOrExtendSubscription("habbo_vip", (60 * 60 * 24 * 31 * 3));
        CurrentHabbo.UpdateFuserights(Client.Socket, Server);
        CurrentHabbo.Updateclub(Server, Client);
      }
    } else {

      Iterator ItemsToPurchase = Item.ItemIds.iterator();

      if (Item.CostCredits > 0) {
        if (CurrentHabbo.Credits > Item.CostCredits)
          CurrentHabbo.UpdateCredits(
              (CurrentHabbo.Credits - Item.CostCredits), Client.Socket, Server);
        else return;
      }

      if (Item.CostPixels > 0) {
        if (CurrentHabbo.Pixels > Item.CostPixels)
          CurrentHabbo.UpdatePixels((CurrentHabbo.Pixels - Item.CostPixels), Client.Socket, Server);
        else return;
      }

      while (ItemsToPurchase.hasNext()) {
        int furniId = (Integer) ItemsToPurchase.next();
        ItemInformation furniData = ItemInformation.Items.get(furniId);

        ServerMessage PurchaseItem = new ServerMessage(ServerEvents.SendItem);
        PurchaseItem.writeInt(furniData.Id);
        if (Item.ItemIds.size() == 1) PurchaseItem.writeUTF(Item.Name);
        else PurchaseItem.writeUTF(furniData.Name);
        PurchaseItem.writeInt(Item.CostCredits);
        PurchaseItem.writeInt(Item.CostPixels);
        PurchaseItem.writeInt(0);
        PurchaseItem.writeInt(0);
        PurchaseItem.writeBoolean(true);
        PurchaseItem.writeUTF(furniData.Type.toLowerCase());
        PurchaseItem.writeInt(furniData.SpriteId);
        if (Item.Name.contains("wallpaper"))
          PurchaseItem.writeUTF(Item.Name.split("_")[2]); // shit for wallpapers
        else if (Item.Name.contains("floor"))
          PurchaseItem.writeUTF(Item.Name.split("_")[2]); // shit for wallpapers
        else if (Item.Name.contains("landscape"))
          PurchaseItem.writeUTF(Item.Name.split("_")[2]); // shit for wallpapers
        else
          PurchaseItem.writeUTF(
              Item.ExtraInformation); // shit for music and other shit
        PurchaseItem.writeInt(1);
        PurchaseItem.writeInt(0);
        PurchaseItem.writeInt(0);
        PurchaseItem.Send(Socket);

        ServerMessage AlertPurchase = new ServerMessage(ServerEvents.InventoryWarn);
        AlertPurchase.writeInt(1); // items alert!
        int Type = 2;
        if (furniData.Type.equals("s")) {
          if (furniData.Interactor.equals("pet")) Type = 3;
          else Type = 1;
        }
        AlertPurchase.writeInt(Type);
        int Amount = Item.Amount;
        if (Item.ExtraAmounts.containsKey(furniId)) Amount = Item.ExtraAmounts.get(furniId);
        AlertPurchase.writeInt(Amount);

        for (int i = 0; i != Amount; i++) {
          Server.GetDatabase()
              .executeUpdate(
                  "INSERT INTO users_items (id, userid, itemid, extradata) VALUES (NULL, '"
                      + CurrentHabbo.Id
                      + "', '"
                      + furniId
                      + "', '"
                      + ExtraData
                      + "');");
          UserItem I = new UserItem();
          I.Id = UserItem.LastId + 1;
          UserItem.LastId++;
          I.UserId = CurrentHabbo.Id;
          I.ItemId = furniId;
          I.ExtraData = ExtraData;
          UserItem.Items.put(I.Id, I);
          AlertPurchase.writeInt(furniId);
        }
        AlertPurchase.Send(Socket);

        ServerMessage UpdateInv = new ServerMessage(ServerEvents.UpdateInventory);
        UpdateInv.Send(Socket);
      }
    }
  }
コード例 #2
0
  public static void Compose(ServerHandler Client, Habbo cUser, Environment Server)
      throws Exception {
    Room RoomData = Room.Rooms.get(cUser.CurrentRoomId);
    int lol = Client.inreader.readInt();
    int ItemId = Client.inreader.readInt();
    Server.WriteLine("To remove: " + ItemId);
    RoomItem Item = RoomItem.Items.get(ItemId);
    ItemInformation furniData = ItemInformation.Items.get(Item.FurniId);
    if (!RoomData.HavePowers(cUser.Id)) {
      return;
    }
    Server.GetDatabase().executeUpdate("DELETE FROM rooms_items WHERE id = " + Item.Id);
    Server.GetDatabase()
        .executeUpdate(
            "INSERT INTO users_items (id, userid, itemid, extradata) VALUES (NULL, '"
                + cUser.Id
                + "', '"
                + Item.FurniId
                + "', '"
                + Item.ExtraData
                + "');");
    UserItem I = new UserItem();
    I.Id = UserItem.LastId + 1;
    UserItem.LastId++;
    I.UserId = cUser.Id;
    I.ItemId = Item.FurniId;
    I.ExtraData = Item.ExtraData;
    UserItem.Items.put(I.Id, I);
    RoomItem.Items.remove(Item);

    if (lol == 2) {
      ServerMessage RemoveFloorItem = new ServerMessage(ServerEvents.RemoveFloorItem);
      RemoveFloorItem.writeUTF(Item.Id + "");
      RemoveFloorItem.writeInt(0);
      RemoveFloorItem.writeInt(cUser.Id);
      RemoveFloorItem.Send(Client.Socket);

      ServerMessage Remove = new ServerMessage(ServerEvents.RemoveWhatItem);
      Remove.writeInt(Item.Id);
      UserManager.SendMessageToUsersOnRoomId(cUser.CurrentRoomId, Remove);
      RoomData.FloorItems.remove(Item);
    } else {
      ServerMessage RemoveWallItem = new ServerMessage(ServerEvents.RemoveWallItem);
      RemoveWallItem.writeUTF(I.Id + "");
      RemoveWallItem.writeInt(cUser.Id);
      UserManager.SendMessageToUsersOnRoomId(cUser.CurrentRoomId, RemoveWallItem);
      RoomData.WallItems.remove(Item);
    }

    ServerMessage Message = new ServerMessage(ServerEvents.UpdateInventory);
    Message.Send(Client.Socket);
    /*ServerMessage FloorInventory = new ServerMessage(ServerEvents.AddItemToInventary);
    if(lol == 2)
    {
    	FloorInventory.writeInt(I.Id);
           FloorInventory.writeUTF(furniData.Type.toUpperCase());
           FloorInventory.writeInt(furniData.Id);
           FloorInventory.writeInt(furniData.SpriteId);
           FloorInventory.writeInt(1);
           FloorInventory.writeUTF(Item.ExtraData);
           FloorInventory.writeInt(0);
           FloorInventory.writeBoolean(furniData.CanRecycle);
           FloorInventory.writeBoolean(furniData.CanTrade);
           FloorInventory.writeBoolean(furniData.CanStack);
           FloorInventory.writeBoolean(furniData.CanSell);
           FloorInventory.writeInt(-1);
           FloorInventory.writeUTF("");
           FloorInventory.writeInt(0);
           FloorInventory.writeInt(24);
    } else {
    	FloorInventory.writeInt(I.Id);
           FloorInventory.writeUTF(furniData.Type.toUpperCase());
           FloorInventory.writeInt(furniData.Id);
           FloorInventory.writeInt(furniData.SpriteId);
           FloorInventory.writeInt(1);
           FloorInventory.writeInt(0);
           FloorInventory.writeUTF(Item.ExtraData);
           FloorInventory.writeBoolean(furniData.CanRecycle);
           FloorInventory.writeBoolean(furniData.CanTrade);
           FloorInventory.writeBoolean(furniData.CanStack);
           FloorInventory.writeBoolean(furniData.CanSell);
           FloorInventory.writeInt(-1);
           FloorInventory.writeInt(25);
    }*/
    // FloorInventory.Send(Client.Socket);
  }