if (object == null || !(object instanceof L2PcInstance)) return;
L2PcInstance storePlayer = (L2PcInstance)object;
if (!(storePlayer.getPrivateStoreType() == L2PcInstance.STORE_PRIVATE_SELL || storePlayer.getPrivateStoreType() == L2PcInstance.STORE_PRIVATE_PACKAGE_SELL)) return;
TradeList storeList = storePlayer.getSellList();
if (storeList == null) return;
if (Config.GM_DISABLE_TRANSACTION && player.getAccessLevel() >= Config.GM_TRANSACTION_MIN && player.getAccessLevel() <= Config.GM_TRANSACTION_MAX)
{
player.sendMessage("Transactions are disable for your Access Level");
sendPacket(new ActionFailed());
return;
}
// FIXME: this check should be (and most probabliy is) done in the TradeList mechanics
long priceTotal = 0;
for(ItemRequest ir : _items)
{
if (ir.getCount() > Integer.MAX_VALUE || ir.getCount() < 0)
{
String msgErr = "[RequestPrivateStoreBuy] player "+getClient().getActiveChar().getName()+" tried an overflow exploit, ban this player!";
Util.handleIllegalPlayerAction(getClient().getActiveChar(),msgErr,Config.DEFAULT_PUNISH);
return;
}
TradeItem sellersItem = storeList.getItem(ir.getObjectId());
if(sellersItem == null)
{
String msgErr = "[RequestPrivateStoreBuy] player "+getClient().getActiveChar().getName()+" tried to buy an item not sold in a private store (buy), ban this player!";
Util.handleIllegalPlayerAction(getClient().getActiveChar(),msgErr,Config.DEFAULT_PUNISH);
return;
}
if(ir.getPrice() != sellersItem.getPrice())
{
String msgErr = "[RequestPrivateStoreBuy] player "+getClient().getActiveChar().getName()+" tried to change the seller's price in a private store (buy), ban this player!";
Util.handleIllegalPlayerAction(getClient().getActiveChar(),msgErr,Config.DEFAULT_PUNISH);
return;
}
priceTotal += ir.getPrice() * ir.getCount();
}
// FIXME: this check should be (and most probabliy is) done in the TradeList mechanics
if(priceTotal < 0 || priceTotal > Integer.MAX_VALUE)
{
String msgErr = "[RequestPrivateStoreBuy] player "+getClient().getActiveChar().getName()+" tried an overflow exploit, ban this player!";
Util.handleIllegalPlayerAction(getClient().getActiveChar(),msgErr,Config.DEFAULT_PUNISH);
return;
}
if (player.getAdena() < priceTotal)
{
sendPacket(new SystemMessage(SystemMessageId.YOU_NOT_ENOUGH_ADENA));
sendPacket(new ActionFailed());
return;
}
if (storePlayer.getPrivateStoreType() == L2PcInstance.STORE_PRIVATE_PACKAGE_SELL)
{
if (storeList.getItemCount() > _count)
{
String msgErr = "[RequestPrivateStoreBuy] player "+getClient().getActiveChar().getName()+" tried to buy less items then sold by package-sell, ban this player for bot-usage!";
Util.handleIllegalPlayerAction(getClient().getActiveChar(),msgErr,Config.DEFAULT_PUNISH);
return;
}
}
if (!storeList.PrivateStoreBuy(player, _items, (int) priceTotal))
{
sendPacket(new ActionFailed());
_log.warning("PrivateStore buy has failed due to invalid list or request. Player: " + player.getName() + ", Private store of: " + storePlayer.getName());
return;
}
if (storeList.getItemCount() == 0)
{
storePlayer.setPrivateStoreType(L2PcInstance.STORE_PRIVATE_NONE);
storePlayer.broadcastUserInfo();
}