Jump to content
  • 0

AIOItem - Request buy only works with GM


Question

Posted

Hey there, so, first I have this code, so this AIOItem (a item that don't need to talk with NPCs, if you have on BAG just click and choose the option you want) do not work GMSHOP if the charecter is not a gm (if i put true in accesslevel.properties on option isGM the item works, but when the player hold shift and click on the npc or mob they can see admin menu of npc):

 

Here is the code of RequestBuyItem.java:

/*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.gameserver.network.clientpackets;

import static com.l2jserver.gameserver.model.actor.L2Npc.INTERACTION_DISTANCE;
import static com.l2jserver.gameserver.model.itemcontainer.PcInventory.MAX_ADENA;

import java.util.ArrayList;
import java.util.List;

import com.l2jserver.Config;
import com.l2jserver.gameserver.TradeController;
import com.l2jserver.gameserver.datatables.ItemTable;
import com.l2jserver.gameserver.model.L2Object;
import com.l2jserver.gameserver.model.L2TradeList;
import com.l2jserver.gameserver.model.L2TradeList.L2TradeItem;
import com.l2jserver.gameserver.model.actor.L2Character;
import com.l2jserver.gameserver.model.actor.instance.L2MerchantInstance;
import com.l2jserver.gameserver.model.actor.instance.L2MerchantSummonInstance;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
import com.l2jserver.gameserver.model.holders.ItemHolder;
import com.l2jserver.gameserver.model.items.L2Item;
import com.l2jserver.gameserver.network.SystemMessageId;
import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
import com.l2jserver.gameserver.network.serverpackets.ExBuySellList;
import com.l2jserver.gameserver.network.serverpackets.StatusUpdate;
import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
import com.l2jserver.gameserver.util.Util;

/**
* RequestBuyItem client packet class.
*/
public final class RequestBuyItem extends L2GameClientPacket
{
        private static final String _C__1F_REQUESTBUYITEM = "[C] 1F RequestBuyItem";
        
        private static final int BATCH_LENGTH = 12; // length of the one item
        private int _listId;
        private Item[] _items = null;

        @Override
        protected void readImpl()
        {
                _listId = readD();
                int count = readD();
                if (count <= 0 || count > Config.MAX_ITEM_IN_PACKET || count * BATCH_LENGTH != _buf.remaining())
                {
                        return;
                }

                _items = new Item[count];
                for (int i = 0; i < count; i++)
                {
                        int itemId = readD();
                        long cnt = readQ();
                        if (itemId < 1 || cnt < 1)
                        {
                                _items = null;
                                return;
                        }
                        _items[i] = new Item(itemId, cnt);
                }
        }

        @Override
        protected void runImpl()
        {
                L2PcInstance player = getClient().getActiveChar();
                if (player == null)
                        return;
                
                if (!getClient().getFloodProtectors().getTransaction().tryPerformAction("buy"))
                {
                        player.sendMessage("You buying too fast.");
                        return;
                }

                if (_items == null)
                {
                        sendPacket(ActionFailed.STATIC_PACKET);
                        return;
                }

                // Alt game - Karma punishment
                if (!Config.ALT_GAME_KARMA_PLAYER_CAN_SHOP && player.getKarma() > 0)
                {
                        sendPacket(ActionFailed.STATIC_PACKET);
                        return;
                }

                L2Object target = player.getTarget();
                L2Character merchant = null;
                if(!player.isUsingAIOItemMultisell())
                {
                        if(target == null 
                                        || (!player.isInsideRadius(target, INTERACTION_DISTANCE, true, false)) // Distance is too far)
                                        || (player.getInstanceId() != target.getInstanceId()))
                        {
                                sendPacket(ActionFailed.STATIC_PACKET);
                                return;
                        }
                        
                        if (target instanceof L2MerchantInstance || target instanceof L2MerchantSummonInstance)
                                merchant = (L2Character)target;
                        else  if (!player.isGM())
                        {
                                sendPacket(ActionFailed.STATIC_PACKET);
                                return;
                        }
                }

                L2TradeList list = null;

                double castleTaxRate = 0;
                double baseTaxRate = 0;

                if (merchant != null)
                {
                        List<L2TradeList> lists;
                        if (merchant instanceof L2MerchantInstance)
                        {
                                lists = TradeController.getInstance().getBuyListByNpcId(((L2MerchantInstance) merchant).getNpcId());
                                castleTaxRate = ((L2MerchantInstance) merchant).getMpc().getCastleTaxRate();
                                baseTaxRate = ((L2MerchantInstance) merchant).getMpc().getBaseTaxRate();
                        }
                        else
                        {
                                lists = TradeController.getInstance().getBuyListByNpcId(((L2MerchantSummonInstance) merchant).getNpcId());
                                baseTaxRate = 50;
                        }
                        
                        if (!player.isGM())
                        {
                                if (lists == null)
                                {
                                        Util.handleIllegalPlayerAction(player, "Warning!! Character " + player.getName() + " of account " + player.getAccountName() + " sent a false BuyList list_id " + _listId, Config.DEFAULT_PUNISH);
                                        return;
                                }
                                for (L2TradeList tradeList : lists)
                                {
                                        if (tradeList.getListId() == _listId)
                                                list = tradeList;
                                }
                        }
                        else
                                list = TradeController.getInstance().getBuyList(_listId);
                }
                else
                        list = TradeController.getInstance().getBuyList(_listId);

                if (list == null)
                {
                        Util.handleIllegalPlayerAction(player, "Warning!! Character " + player.getName() + " of account " + player.getAccountName() + " sent a false BuyList list_id " + _listId, Config.DEFAULT_PUNISH);
                        return;
                }

                _listId = list.getListId();

                long subTotal = 0;

                // Check for buylist validity and calculates summary values
                long slots = 0;
                long weight = 0;
                for (Item i : _items)
                {
                        L2TradeItem tradeItem = list.getItemById(i.getItemId());
                        if (tradeItem == null)
                        {
                                Util.handleIllegalPlayerAction(player, "Warning!! Character " + player.getName() + " of account " + player.getAccountName() + " sent a false BuyList list_id " + _listId + " and item_id " + i.getItemId(), Config.DEFAULT_PUNISH);
                                return;
                        }

                        L2Item template = ItemTable.getInstance().getTemplate(i.getItemId());
                        if (template == null)
                                continue;

            if (!template.isStackable() && i.getCount() > 1)
                        {
                                Util.handleIllegalPlayerAction(player, "Warning!! Character " + player.getName() + " of account " + player.getAccountName() + " tried to purchase invalid quantity of items at the same time.", Config.DEFAULT_PUNISH);
                                sendPacket(SystemMessage.getSystemMessage(SystemMessageId.YOU_HAVE_EXCEEDED_QUANTITY_THAT_CAN_BE_INPUTTED));
                                return;
                        }

            long price = list.getPriceForItemId(i.getItemId());
            if (price < 0)
            {
                                _log.warning("ERROR, no price found .. wrong buylist ??");
                                sendPacket(ActionFailed.STATIC_PACKET);
                                return;
                        }

                        if (price == 0 && !player.isGM() && Config.ONLY_GM_ITEMS_FREE)
                        {
                                player.sendMessage("Ohh Cheat dont work? You have a problem now!");
                                Util.handleIllegalPlayerAction(player, "Warning!! Character " + player.getName() + " of account " + player.getAccountName() + " tried buy item for 0 adena.", Config.DEFAULT_PUNISH);
                                return;
                        }

                        if (tradeItem.hasLimitedStock())
                        {
                                // trying to buy more then available
                                if (i.getCount() > tradeItem.getCurrentCount())
                                        return;
                        }

                        if ((MAX_ADENA / i.getCount()) < price)
                        {
                                Util.handleIllegalPlayerAction(player, "Warning!! Character " + player.getName() + " of account " + player.getAccountName() + " tried to purchase over " + MAX_ADENA + " adena worth of goods.", Config.DEFAULT_PUNISH);
                                return;
                        }
                        // first calculate price per item with tax, then multiply by count
                        price = (long) (price * (1 + castleTaxRate + baseTaxRate));
                        subTotal += i.getCount() * price;
                        if (subTotal > MAX_ADENA)
                        {
                                Util.handleIllegalPlayerAction(player, "Warning!! Character " + player.getName() + " of account " + player.getAccountName() + " tried to purchase over " + MAX_ADENA + " adena worth of goods.", Config.DEFAULT_PUNISH);
                                return;
                        }

                        weight += i.getCount() * template.getWeight();
                        if (!template.isStackable())
                                slots += i.getCount();
                        else if (player.getInventory().getItemByItemId(i.getItemId()) == null)
                                slots++;
                }
                
                if (!player.isGM() && (weight > Integer.MAX_VALUE || weight < 0 || !player.getInventory().validateWeight((int) weight)))
                {
                        sendPacket(SystemMessage.getSystemMessage(SystemMessageId.WEIGHT_LIMIT_EXCEEDED));
                        sendPacket(ActionFailed.STATIC_PACKET);
                        return;
                }
                
                if (!player.isGM() && (slots > Integer.MAX_VALUE || slots < 0 || !player.getInventory().validateCapacity((int) slots)))
                {
                        sendPacket(SystemMessage.getSystemMessage(SystemMessageId.SLOTS_FULL));
                        sendPacket(ActionFailed.STATIC_PACKET);
                        return;
                }

                // Charge buyer and add tax to castle treasury if not owned by npc clan
                if ((subTotal < 0) || !player.reduceAdena("Buy", subTotal, player.getLastFolkNPC(), false))
                {
                        sendPacket(SystemMessage.getSystemMessage(SystemMessageId.YOU_NOT_ENOUGH_ADENA));
                        sendPacket(ActionFailed.STATIC_PACKET);
                        return;
                }

                // Proceed the purchase
                for (Item i : _items)
                {
                        L2TradeItem tradeItem = list.getItemById(i.getItemId());
                        if (tradeItem == null)
                        {
                                Util.handleIllegalPlayerAction(player, "Warning!! Character " + player.getName() + " of account " + player.getAccountName() + " sent a false BuyList list_id " + _listId + " and item_id " + i.getItemId(), Config.DEFAULT_PUNISH);
                                continue;
                        }

                        if (tradeItem.hasLimitedStock())
                        {
                                if (tradeItem.decreaseCount(i.getCount()))
                                        player.getInventory().addItem("Buy", i.getItemId(), i.getCount(), player, merchant);
                        }
                        else
                                player.getInventory().addItem("Buy", i.getItemId(), i.getCount(), player, merchant);
                }

                // add to castle treasury
                if(!player.isUsingAIOItemMultisell())
                {
                        // add to castle treasury
                        if (merchant instanceof L2MerchantInstance)
                                ((L2MerchantInstance) merchant).getCastle().addToTreasury((long) (subTotal * castleTaxRate));
                }
                
                StatusUpdate su = new StatusUpdate(player);
                player.sendPacket(su);
                player.sendPacket(new ExBuySellList(player, castleTaxRate + baseTaxRate, true));
        }

        private static class Item
        {
                private final int _itemId;
                private final long _count;
                
                public Item(int id, long num)
                {
                        _itemId = id;
                        _count = num;
                }

                public int getItemId()
                {
                        return _itemId;
                }

                public long getCount()
                {
                        return _count;
                }
        }

        @Override
        public String getType()
        {
                return _C__1F_REQUESTBUYITEM;
        }
}

 

What is the problem guys? this tool is a troll!

 

Thank you

 

Recommended Posts

  • 0
Posted

                        else  if (!player.isGM())
                        {
                                sendPacket(ActionFailed.STATIC_PACKET);
                                return;
                        }

 

This action is checking if player is GM or no, and

If players is not GM !player.isGM()

sendPacket(ActionFailed.STATIC_PACKET);

 

Hope you understand...

 

I've actualy understand half of your problem...

please explain better...

  • 0
Posted

                        else  if (!player.isGM())
                        {
                                sendPacket(ActionFailed.STATIC_PACKET);
                                return;
                        }

 

 

This action is checking if player is GM or no, and

If players is not GM !player.isGM()

sendPacket(ActionFailed.STATIC_PACKET);

 

Hope you understand...

 

I've actualy understand half of your problem...

please explain better...

 

Hey dude, thanks for you reply...

 

The problem is, normal characters can't buy on GMSHOP of this item... I want to enable for normal characters buy.

 

  • 0
Posted

If it works only with GM and doesn't work with normal characters that means that if you change

(!player.isGM())

to

(player.isGM())

 

It will works with normal characters only.

 

or switch it with

 

(player.isInCombat())

 

This will make unable to use if player is in combat ....

  • 0
Posted

Try this lol

/*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.gameserver.network.clientpackets;

import static com.l2jserver.gameserver.model.actor.L2Npc.INTERACTION_DISTANCE;
import static com.l2jserver.gameserver.model.itemcontainer.PcInventory.MAX_ADENA;

import java.util.ArrayList;
import java.util.List;

import com.l2jserver.Config;
import com.l2jserver.gameserver.TradeController;
import com.l2jserver.gameserver.datatables.ItemTable;
import com.l2jserver.gameserver.model.L2Object;
import com.l2jserver.gameserver.model.L2TradeList;
import com.l2jserver.gameserver.model.L2TradeList.L2TradeItem;
import com.l2jserver.gameserver.model.actor.L2Character;
import com.l2jserver.gameserver.model.actor.instance.L2MerchantInstance;
import com.l2jserver.gameserver.model.actor.instance.L2MerchantSummonInstance;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
import com.l2jserver.gameserver.model.holders.ItemHolder;
import com.l2jserver.gameserver.model.items.L2Item;
import com.l2jserver.gameserver.network.SystemMessageId;
import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
import com.l2jserver.gameserver.network.serverpackets.ExBuySellList;
import com.l2jserver.gameserver.network.serverpackets.StatusUpdate;
import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
import com.l2jserver.gameserver.util.Util;

/**
* RequestBuyItem client packet class.
*/
public final class RequestBuyItem extends L2GameClientPacket
{
        private static final String _C__1F_REQUESTBUYITEM = "[C] 1F RequestBuyItem";
        
        private static final int BATCH_LENGTH = 12; // length of the one item
        private int _listId;
        private Item[] _items = null;

        @Override
        protected void readImpl()
        {
                _listId = readD();
                int count = readD();
                if (count <= 0 || count > Config.MAX_ITEM_IN_PACKET || count * BATCH_LENGTH != _buf.remaining())
                {
                        return;
                }

                _items = new Item[count];
                for (int i = 0; i < count; i++)
                {
                        int itemId = readD();
                        long cnt = readQ();
                        if (itemId < 1 || cnt < 1)
                        {
                                _items = null;
                                return;
                        }
                        _items[i] = new Item(itemId, cnt);
                }
        }

        @Override
        protected void runImpl()
        {
                L2PcInstance player = getClient().getActiveChar();
                if (player == null)
                        return;
                
                if (!getClient().getFloodProtectors().getTransaction().tryPerformAction("buy"))
                {
                        player.sendMessage("You buying too fast.");
                        return;
                }

                if (_items == null)
                {
                        sendPacket(ActionFailed.STATIC_PACKET);
                        return;
                }

                // Alt game - Karma punishment
                if (!Config.ALT_GAME_KARMA_PLAYER_CAN_SHOP && player.getKarma() > 0)
                {
                        sendPacket(ActionFailed.STATIC_PACKET);
                        return;
                }

                L2Object target = player.getTarget();
                L2Character merchant = null;
                if(!player.isUsingAIOItemMultisell())
                {
                        if(target == null 
                                        || (!player.isInsideRadius(target, INTERACTION_DISTANCE, true, false)) // Distance is too far)
                                        || (player.getInstanceId() != target.getInstanceId()))
                        {
                                sendPacket(ActionFailed.STATIC_PACKET);
                                return;
                        }
                        
                        if (target instanceof L2MerchantInstance || target instanceof L2MerchantSummonInstance)
                                merchant = (L2Character)target;
                        else  if (player.isGM())
                        {
                                sendPacket(ActionFailed.STATIC_PACKET);
                                return;
                        }
                }

                L2TradeList list = null;

                double castleTaxRate = 0;
                double baseTaxRate = 0;

                if (merchant != null)
                {
                        List<L2TradeList> lists;
                        if (merchant instanceof L2MerchantInstance)
                        {
                                lists = TradeController.getInstance().getBuyListByNpcId(((L2MerchantInstance) merchant).getNpcId());
                                castleTaxRate = ((L2MerchantInstance) merchant).getMpc().getCastleTaxRate();
                                baseTaxRate = ((L2MerchantInstance) merchant).getMpc().getBaseTaxRate();
                        }
                        else
                        {
                                lists = TradeController.getInstance().getBuyListByNpcId(((L2MerchantSummonInstance) merchant).getNpcId());
                                baseTaxRate = 50;
                        }
                        
                        if (player.isGM())
                        {
                                if (lists == null)
                                {
                                        Util.handleIllegalPlayerAction(player, "Warning!! Character " + player.getName() + " of account " + player.getAccountName() + " sent a false BuyList list_id " + _listId, Config.DEFAULT_PUNISH);
                                        return;
                                }
                                for (L2TradeList tradeList : lists)
                                {
                                        if (tradeList.getListId() == _listId)
                                                list = tradeList;
                                }
                        }
                        else
                                list = TradeController.getInstance().getBuyList(_listId);
                }
                else
                        list = TradeController.getInstance().getBuyList(_listId);

                if (list == null)
                {
                        Util.handleIllegalPlayerAction(player, "Warning!! Character " + player.getName() + " of account " + player.getAccountName() + " sent a false BuyList list_id " + _listId, Config.DEFAULT_PUNISH);
                        return;
                }

                _listId = list.getListId();

                long subTotal = 0;

                // Check for buylist validity and calculates summary values
                long slots = 0;
                long weight = 0;
                for (Item i : _items)
                {
                        L2TradeItem tradeItem = list.getItemById(i.getItemId());
                        if (tradeItem == null)
                        {
                                Util.handleIllegalPlayerAction(player, "Warning!! Character " + player.getName() + " of account " + player.getAccountName() + " sent a false BuyList list_id " + _listId + " and item_id " + i.getItemId(), Config.DEFAULT_PUNISH);
                                return;
                        }

                        L2Item template = ItemTable.getInstance().getTemplate(i.getItemId());
                        if (template == null)
                                continue;

            if (!template.isStackable() && i.getCount() > 1)
                        {
                                Util.handleIllegalPlayerAction(player, "Warning!! Character " + player.getName() + " of account " + player.getAccountName() + " tried to purchase invalid quantity of items at the same time.", Config.DEFAULT_PUNISH);
                                sendPacket(SystemMessage.getSystemMessage(SystemMessageId.YOU_HAVE_EXCEEDED_QUANTITY_THAT_CAN_BE_INPUTTED));
                                return;
                        }

            long price = list.getPriceForItemId(i.getItemId());
            if (price < 0)
            {
                                _log.warning("ERROR, no price found .. wrong buylist ??");
                                sendPacket(ActionFailed.STATIC_PACKET);
                                return;
                        }

                        if (price == 0 && !player.isGM() && Config.ONLY_GM_ITEMS_FREE)
                        {
                                player.sendMessage("Ohh Cheat dont work? You have a problem now!");
                                Util.handleIllegalPlayerAction(player, "Warning!! Character " + player.getName() + " of account " + player.getAccountName() + " tried buy item for 0 adena.", Config.DEFAULT_PUNISH);
                                return;
                        }

                        if (tradeItem.hasLimitedStock())
                        {
                                // trying to buy more then available
                                if (i.getCount() > tradeItem.getCurrentCount())
                                        return;
                        }

                        if ((MAX_ADENA / i.getCount()) < price)
                        {
                                Util.handleIllegalPlayerAction(player, "Warning!! Character " + player.getName() + " of account " + player.getAccountName() + " tried to purchase over " + MAX_ADENA + " adena worth of goods.", Config.DEFAULT_PUNISH);
                                return;
                        }
                        // first calculate price per item with tax, then multiply by count
                        price = (long) (price * (1 + castleTaxRate + baseTaxRate));
                        subTotal += i.getCount() * price;
                        if (subTotal > MAX_ADENA)
                        {
                                Util.handleIllegalPlayerAction(player, "Warning!! Character " + player.getName() + " of account " + player.getAccountName() + " tried to purchase over " + MAX_ADENA + " adena worth of goods.", Config.DEFAULT_PUNISH);
                                return;
                        }

                        weight += i.getCount() * template.getWeight();
                        if (!template.isStackable())
                                slots += i.getCount();
                        else if (player.getInventory().getItemByItemId(i.getItemId()) == null)
                                slots++;
                }
                
                if (player.isGM() && (weight > Integer.MAX_VALUE || weight < 0 || !player.getInventory().validateWeight((int) weight)))
                {
                        sendPacket(SystemMessage.getSystemMessage(SystemMessageId.WEIGHT_LIMIT_EXCEEDED));
                        sendPacket(ActionFailed.STATIC_PACKET);
                        return;
                }
                
                if (player.isGM() && (slots > Integer.MAX_VALUE || slots < 0 || !player.getInventory().validateCapacity((int) slots)))
                {
                        sendPacket(SystemMessage.getSystemMessage(SystemMessageId.SLOTS_FULL));
                        sendPacket(ActionFailed.STATIC_PACKET);
                        return;
                }

                // Charge buyer and add tax to castle treasury if not owned by npc clan
                if ((subTotal < 0) || !player.reduceAdena("Buy", subTotal, player.getLastFolkNPC(), false))
                {
                        sendPacket(SystemMessage.getSystemMessage(SystemMessageId.YOU_NOT_ENOUGH_ADENA));
                        sendPacket(ActionFailed.STATIC_PACKET);
                        return;
                }

                // Proceed the purchase
                for (Item i : _items)
                {
                        L2TradeItem tradeItem = list.getItemById(i.getItemId());
                        if (tradeItem == null)
                        {
                                Util.handleIllegalPlayerAction(player, "Warning!! Character " + player.getName() + " of account " + player.getAccountName() + " sent a false BuyList list_id " + _listId + " and item_id " + i.getItemId(), Config.DEFAULT_PUNISH);
                                continue;
                        }

                        if (tradeItem.hasLimitedStock())
                        {
                                if (tradeItem.decreaseCount(i.getCount()))
                                        player.getInventory().addItem("Buy", i.getItemId(), i.getCount(), player, merchant);
                        }
                        else
                                player.getInventory().addItem("Buy", i.getItemId(), i.getCount(), player, merchant);
                }

                // add to castle treasury
                if(!player.isUsingAIOItemMultisell())
                {
                        // add to castle treasury
                        if (merchant instanceof L2MerchantInstance)
                                ((L2MerchantInstance) merchant).getCastle().addToTreasury((long) (subTotal * castleTaxRate));
                }
                
                StatusUpdate su = new StatusUpdate(player);
                player.sendPacket(su);
                player.sendPacket(new ExBuySellList(player, castleTaxRate + baseTaxRate, true));
        }

        private static class Item
        {
                private final int _itemId;
                private final long _count;
                
                public Item(int id, long num)
                {
                        _itemId = id;
                        _count = num;
                }

                public int getItemId()
                {
                        return _itemId;
                }

                public long getCount()
                {
                        return _count;
                }
        }

        @Override
        public String getType()
        {
                return _C__1F_REQUESTBUYITEM;
        }
}

  • 0
Posted

Try this lol

/*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.gameserver.network.clientpackets;

import static com.l2jserver.gameserver.model.actor.L2Npc.INTERACTION_DISTANCE;
import static com.l2jserver.gameserver.model.itemcontainer.PcInventory.MAX_ADENA;

import java.util.ArrayList;
import java.util.List;

import com.l2jserver.Config;
import com.l2jserver.gameserver.TradeController;
import com.l2jserver.gameserver.datatables.ItemTable;
import com.l2jserver.gameserver.model.L2Object;
import com.l2jserver.gameserver.model.L2TradeList;
import com.l2jserver.gameserver.model.L2TradeList.L2TradeItem;
import com.l2jserver.gameserver.model.actor.L2Character;
import com.l2jserver.gameserver.model.actor.instance.L2MerchantInstance;
import com.l2jserver.gameserver.model.actor.instance.L2MerchantSummonInstance;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
import com.l2jserver.gameserver.model.holders.ItemHolder;
import com.l2jserver.gameserver.model.items.L2Item;
import com.l2jserver.gameserver.network.SystemMessageId;
import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
import com.l2jserver.gameserver.network.serverpackets.ExBuySellList;
import com.l2jserver.gameserver.network.serverpackets.StatusUpdate;
import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
import com.l2jserver.gameserver.util.Util;

/**
* RequestBuyItem client packet class.
*/
public final class RequestBuyItem extends L2GameClientPacket
{
        private static final String _C__1F_REQUESTBUYITEM = "[C] 1F RequestBuyItem";
        
        private static final int BATCH_LENGTH = 12; // length of the one item
        private int _listId;
        private Item[] _items = null;

        @Override
        protected void readImpl()
        {
                _listId = readD();
                int count = readD();
                if (count <= 0 || count > Config.MAX_ITEM_IN_PACKET || count * BATCH_LENGTH != _buf.remaining())
                {
                        return;
                }

                _items = new Item[count];
                for (int i = 0; i < count; i++)
                {
                        int itemId = readD();
                        long cnt = readQ();
                        if (itemId < 1 || cnt < 1)
                        {
                                _items = null;
                                return;
                        }
                        _items[i] = new Item(itemId, cnt);
                }
        }

        @Override
        protected void runImpl()
        {
                L2PcInstance player = getClient().getActiveChar();
                if (player == null)
                        return;
                
                if (!getClient().getFloodProtectors().getTransaction().tryPerformAction("buy"))
                {
                        player.sendMessage("You buying too fast.");
                        return;
                }

                if (_items == null)
                {
                        sendPacket(ActionFailed.STATIC_PACKET);
                        return;
                }

                // Alt game - Karma punishment
                if (!Config.ALT_GAME_KARMA_PLAYER_CAN_SHOP && player.getKarma() > 0)
                {
                        sendPacket(ActionFailed.STATIC_PACKET);
                        return;
                }

                L2Object target = player.getTarget();
                L2Character merchant = null;
                if(!player.isUsingAIOItemMultisell())
                {
                        if(target == null 
                                        || (!player.isInsideRadius(target, INTERACTION_DISTANCE, true, false)) // Distance is too far)
                                        || (player.getInstanceId() != target.getInstanceId()))
                        {
                                sendPacket(ActionFailed.STATIC_PACKET);
                                return;
                        }
                        
                        if (target instanceof L2MerchantInstance || target instanceof L2MerchantSummonInstance)
                                merchant = (L2Character)target;
                        else  if (player.isGM())
                        {
                                sendPacket(ActionFailed.STATIC_PACKET);
                                return;
                        }
                }

                L2TradeList list = null;

                double castleTaxRate = 0;
                double baseTaxRate = 0;

                if (merchant != null)
                {
                        List<L2TradeList> lists;
                        if (merchant instanceof L2MerchantInstance)
                        {
                                lists = TradeController.getInstance().getBuyListByNpcId(((L2MerchantInstance) merchant).getNpcId());
                                castleTaxRate = ((L2MerchantInstance) merchant).getMpc().getCastleTaxRate();
                                baseTaxRate = ((L2MerchantInstance) merchant).getMpc().getBaseTaxRate();
                        }
                        else
                        {
                                lists = TradeController.getInstance().getBuyListByNpcId(((L2MerchantSummonInstance) merchant).getNpcId());
                                baseTaxRate = 50;
                        }
                        
                        if (player.isGM())
                        {
                                if (lists == null)
                                {
                                        Util.handleIllegalPlayerAction(player, "Warning!! Character " + player.getName() + " of account " + player.getAccountName() + " sent a false BuyList list_id " + _listId, Config.DEFAULT_PUNISH);
                                        return;
                                }
                                for (L2TradeList tradeList : lists)
                                {
                                        if (tradeList.getListId() == _listId)
                                                list = tradeList;
                                }
                        }
                        else
                                list = TradeController.getInstance().getBuyList(_listId);
                }
                else
                        list = TradeController.getInstance().getBuyList(_listId);

                if (list == null)
                {
                        Util.handleIllegalPlayerAction(player, "Warning!! Character " + player.getName() + " of account " + player.getAccountName() + " sent a false BuyList list_id " + _listId, Config.DEFAULT_PUNISH);
                        return;
                }

                _listId = list.getListId();

                long subTotal = 0;

                // Check for buylist validity and calculates summary values
                long slots = 0;
                long weight = 0;
                for (Item i : _items)
                {
                        L2TradeItem tradeItem = list.getItemById(i.getItemId());
                        if (tradeItem == null)
                        {
                                Util.handleIllegalPlayerAction(player, "Warning!! Character " + player.getName() + " of account " + player.getAccountName() + " sent a false BuyList list_id " + _listId + " and item_id " + i.getItemId(), Config.DEFAULT_PUNISH);
                                return;
                        }

                        L2Item template = ItemTable.getInstance().getTemplate(i.getItemId());
                        if (template == null)
                                continue;

            if (!template.isStackable() && i.getCount() > 1)
                        {
                                Util.handleIllegalPlayerAction(player, "Warning!! Character " + player.getName() + " of account " + player.getAccountName() + " tried to purchase invalid quantity of items at the same time.", Config.DEFAULT_PUNISH);
                                sendPacket(SystemMessage.getSystemMessage(SystemMessageId.YOU_HAVE_EXCEEDED_QUANTITY_THAT_CAN_BE_INPUTTED));
                                return;
                        }

            long price = list.getPriceForItemId(i.getItemId());
            if (price < 0)
            {
                                _log.warning("ERROR, no price found .. wrong buylist ??");
                                sendPacket(ActionFailed.STATIC_PACKET);
                                return;
                        }

                        if (price == 0 && !player.isGM() && Config.ONLY_GM_ITEMS_FREE)
                        {
                                player.sendMessage("Ohh Cheat dont work? You have a problem now!");
                                Util.handleIllegalPlayerAction(player, "Warning!! Character " + player.getName() + " of account " + player.getAccountName() + " tried buy item for 0 adena.", Config.DEFAULT_PUNISH);
                                return;
                        }

                        if (tradeItem.hasLimitedStock())
                        {
                                // trying to buy more then available
                                if (i.getCount() > tradeItem.getCurrentCount())
                                        return;
                        }

                        if ((MAX_ADENA / i.getCount()) < price)
                        {
                                Util.handleIllegalPlayerAction(player, "Warning!! Character " + player.getName() + " of account " + player.getAccountName() + " tried to purchase over " + MAX_ADENA + " adena worth of goods.", Config.DEFAULT_PUNISH);
                                return;
                        }
                        // first calculate price per item with tax, then multiply by count
                        price = (long) (price * (1 + castleTaxRate + baseTaxRate));
                        subTotal += i.getCount() * price;
                        if (subTotal > MAX_ADENA)
                        {
                                Util.handleIllegalPlayerAction(player, "Warning!! Character " + player.getName() + " of account " + player.getAccountName() + " tried to purchase over " + MAX_ADENA + " adena worth of goods.", Config.DEFAULT_PUNISH);
                                return;
                        }

                        weight += i.getCount() * template.getWeight();
                        if (!template.isStackable())
                                slots += i.getCount();
                        else if (player.getInventory().getItemByItemId(i.getItemId()) == null)
                                slots++;
                }
                
                if (player.isGM() && (weight > Integer.MAX_VALUE || weight < 0 || !player.getInventory().validateWeight((int) weight)))
                {
                        sendPacket(SystemMessage.getSystemMessage(SystemMessageId.WEIGHT_LIMIT_EXCEEDED));
                        sendPacket(ActionFailed.STATIC_PACKET);
                        return;
                }
                
                if (player.isGM() && (slots > Integer.MAX_VALUE || slots < 0 || !player.getInventory().validateCapacity((int) slots)))
                {
                        sendPacket(SystemMessage.getSystemMessage(SystemMessageId.SLOTS_FULL));
                        sendPacket(ActionFailed.STATIC_PACKET);
                        return;
                }

                // Charge buyer and add tax to castle treasury if not owned by npc clan
                if ((subTotal < 0) || !player.reduceAdena("Buy", subTotal, player.getLastFolkNPC(), false))
                {
                        sendPacket(SystemMessage.getSystemMessage(SystemMessageId.YOU_NOT_ENOUGH_ADENA));
                        sendPacket(ActionFailed.STATIC_PACKET);
                        return;
                }

                // Proceed the purchase
                for (Item i : _items)
                {
                        L2TradeItem tradeItem = list.getItemById(i.getItemId());
                        if (tradeItem == null)
                        {
                                Util.handleIllegalPlayerAction(player, "Warning!! Character " + player.getName() + " of account " + player.getAccountName() + " sent a false BuyList list_id " + _listId + " and item_id " + i.getItemId(), Config.DEFAULT_PUNISH);
                                continue;
                        }

                        if (tradeItem.hasLimitedStock())
                        {
                                if (tradeItem.decreaseCount(i.getCount()))
                                        player.getInventory().addItem("Buy", i.getItemId(), i.getCount(), player, merchant);
                        }
                        else
                                player.getInventory().addItem("Buy", i.getItemId(), i.getCount(), player, merchant);
                }

                // add to castle treasury
                if(!player.isUsingAIOItemMultisell())
                {
                        // add to castle treasury
                        if (merchant instanceof L2MerchantInstance)
                                ((L2MerchantInstance) merchant).getCastle().addToTreasury((long) (subTotal * castleTaxRate));
                }
                
                StatusUpdate su = new StatusUpdate(player);
                player.sendPacket(su);
                player.sendPacket(new ExBuySellList(player, castleTaxRate + baseTaxRate, true));
        }

        private static class Item
        {
                private final int _itemId;
                private final long _count;
                
                public Item(int id, long num)
                {
                        _itemId = id;
                        _count = num;
                }

                public int getItemId()
                {
                        return _itemId;
                }

                public long getCount()
                {
                        return _count;
                }
        }

        @Override
        public String getType()
        {
                return _C__1F_REQUESTBUYITEM;
        }
}

 

Hey dude, thanks for you very fast reply...

 

but don't work...

  • 0
Posted

Hey dude, thanks for you very fast reply...

 

but don't work...

 

It doesn't work at all, or doesn't work again only for normal access characters?

Also do you get any message in GS console or as a system message?

  • 0
Posted

with admin characters level WORK and with normal characters level DON'T WORK:

 

proof with admin:

TSi9VJD.jpg

 

With normal characters NOTHING HAPPENS including errors on gameserver and loginserver!

  • 0
Posted

Edit*

 

I don't see any peoblem actualy in this code... i've read it all.. and all i see is checks... and warnings... wich works only if player is not GM ... but i don't see restriction for access level or smth.... i see only warnings but they should shop if player is not GM...

Anyway, continue re-checking i will reply if i found...

 

  • 0
Posted

Edit*

 

I don't see any peoblem actualy in this code... i've read it all.. and all i see is checks... and warnings... wich works only if player is not GM ... but i don't see restriction for access level or smth.... i see only warnings but they should shop if player is not GM...

Anyway, continue re-checking i will reply if i found...

 

 

 

Here i have the RequestSellItem.java:

/*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
* 
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
* 
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.gameserver.network.clientpackets;

import static com.l2jserver.gameserver.model.actor.L2Npc.INTERACTION_DISTANCE;
import static com.l2jserver.gameserver.model.itemcontainer.PcInventory.MAX_ADENA;

import java.util.ArrayList;
import java.util.List;

import com.l2jserver.Config;
import com.l2jserver.gameserver.TradeController;
import com.l2jserver.gameserver.model.L2Object;
import com.l2jserver.gameserver.model.L2TradeList;
import com.l2jserver.gameserver.model.actor.L2Character;
import com.l2jserver.gameserver.model.actor.instance.L2MerchantInstance;
import com.l2jserver.gameserver.model.actor.instance.L2MerchantSummonInstance;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
import com.l2jserver.gameserver.model.holders.ItemHolder;
import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
import com.l2jserver.gameserver.network.serverpackets.ExBuySellList;
import com.l2jserver.gameserver.network.serverpackets.StatusUpdate;
import com.l2jserver.gameserver.util.Util;

/**
* RequestSellItem client packet class.
*/
public final class RequestSellItem extends L2GameClientPacket
{
private static final String _C__37_REQUESTSELLITEM = "[C] 37 RequestSellItem";

private static final int BATCH_LENGTH = 16;

private int _listId;
private List<ItemHolder> _items = null;

@Override
protected void readImpl()
{
	_listId = readD();
	int size = readD();
	if ((size <= 0) || (size > Config.MAX_ITEM_IN_PACKET) || ((size * BATCH_LENGTH) != _buf.remaining()))
	{
		return;
	}

	_items = new ArrayList<>(size);
	for (int i = 0; i < size; i++)
	{
		int objectId = readD();
		int itemId = readD();
		long count = readQ();
		if ((objectId < 1) || (itemId < 1) || (count < 1))
		{
			_items = null;
			return;
		}
		_items.add(new ItemHolder(itemId, objectId, count));
	}
}

@Override
protected void runImpl()
{
	processSell();
}

protected void processSell()
{
	L2PcInstance player = getClient().getActiveChar();

	if (player == null)
	{
		return;
	}

	if (!getClient().getFloodProtectors().getTransaction().tryPerformAction("buy"))
	{
		player.sendMessage("You are buying too fast.");
		return;
	}

	if (_items == null)
	{
		sendPacket(ActionFailed.STATIC_PACKET);
		return;
	}

	// Alt game - Karma punishment
	if (!Config.ALT_GAME_KARMA_PLAYER_CAN_SHOP && (player.getKarma() > 0))
	{
		sendPacket(ActionFailed.STATIC_PACKET);
		return;
	}

	L2Object target = player.getTarget();
	L2Character merchant = null;
	if (!player.isGM())
	{
		if ((target == null) || (!player.isInsideRadius(target, INTERACTION_DISTANCE, true, false)) // Distance is too far)
			|| (player.getInstanceId() != target.getInstanceId()))
		{
			sendPacket(ActionFailed.STATIC_PACKET);
			return;
		}
		if ((target instanceof L2MerchantInstance) || (target instanceof L2MerchantSummonInstance))
		{
			merchant = (L2Character) target;
		}
		else
		{
			sendPacket(ActionFailed.STATIC_PACKET);
			return;
		}
	}

	double taxRate = 0;

	L2TradeList list = null;
	if (!player.isUsingAIOItemMultisell() && merchant != null)
	{
		List<L2TradeList> lists;
		if (merchant instanceof L2MerchantInstance)
		{
			lists = TradeController.getInstance().getBuyListByNpcId(((L2MerchantInstance) merchant).getNpcId());
			taxRate = ((L2MerchantInstance) merchant).getMpc().getTotalTaxRate();
		}
		else
		{
			lists = TradeController.getInstance().getBuyListByNpcId(((L2MerchantSummonInstance) merchant).getNpcId());
			taxRate = 50;
		}

		if (!player.isGM())
		{
			if (lists == null)
			{
				Util.handleIllegalPlayerAction(player, "Warning!! Character " + player.getName() + " of account " + player.getAccountName() + " sent a false BuyList list_id " + _listId, Config.DEFAULT_PUNISH);
				return;
			}
			for (L2TradeList tradeList : lists)
			{
				if (tradeList.getListId() == _listId)
				{
					list = tradeList;
				}
			}
		}
		else
		{
			list = TradeController.getInstance().getBuyList(_listId);
		}
	}
	else
	{
		list = TradeController.getInstance().getBuyList(_listId);
	}

	if (list == null)
	{
		Util.handleIllegalPlayerAction(player, "Warning!! Character " + player.getName() + " of account " + player.getAccountName() + " sent a false BuyList list_id " + _listId, Config.DEFAULT_PUNISH);
		return;
	}

	long totalPrice = 0;
	// Proceed the sell
	for (ItemHolder i : _items)
	{
		L2ItemInstance item = player.checkItemManipulation(i.getObjectId(), i.getCount(), "sell");
		if ((item == null) || (!item.isSellable()))
		{
			continue;
		}

		long price = item.getReferencePrice() / 2;
		totalPrice += price * i.getCount();
		if (((MAX_ADENA / i.getCount()) < price) || (totalPrice > MAX_ADENA))
		{
			Util.handleIllegalPlayerAction(player, "Warning!! Character " + player.getName() + " of account " + player.getAccountName() + " tried to purchase over " + MAX_ADENA + " adena worth of goods.", Config.DEFAULT_PUNISH);
			return;
		}

		if (Config.ALLOW_REFUND)
		{
			item = player.getInventory().transferItem("Sell", i.getObjectId(), i.getCount(), player.getRefund(), player, merchant);
		}
		else
		{
			item = player.getInventory().destroyItem("Sell", i.getObjectId(), i.getCount(), player, merchant);
		}
	}
	player.addAdena("Sell", totalPrice, merchant, false);

	// Update current load as well
	StatusUpdate su = new StatusUpdate(player);
	su.addAttribute(StatusUpdate.CUR_LOAD, player.getCurrentLoad());
	player.sendPacket(su);
	player.sendPacket(new ExBuySellList(player, taxRate, true));
}

@Override
public String getType()
{
	return _C__37_REQUESTSELLITEM;
}
}

 

And with RequestBuyItem.java nothing happens with normal accesslevel, if I change the properties of accesslevel.properties on /config folder from:

<access level="0" name="User" nameColor="FFFFFF" titleColor="FFFFFF" childAccess="0" isGM="false" allowPeaceAttack="false" allowFixedRes="false" allowTransaction="true" allowAltg="false" giveDamage="true" takeAggro="true" gainExp="true" />

 

to:

 

<access level="0" name="User" nameColor="FFFFFF" titleColor="FFFFFF" childAccess="0" isGM="true" allowPeaceAttack="false" allowFixedRes="false" allowTransaction="true" allowAltg="false" giveDamage="true" takeAggro="true" gainExp="true" />

Work but the player can see admin of npcs

  • 0
Posted

This is so confuzed :D

 

If you Want I can send the patch to see all I work. I will see here the AIOITEM handler!

  • 0
Posted

If you Want I can send the patch to see all I work. I will see here the AIOITEM handler!

 

I've already answer your post :D

The code is correct...

If you have something else to ask... do it... but i'm not giving support ( only trough forum ).

Guest
This topic is now closed to further replies.


×
×
  • Create New...