player.sendMessage("Unsufficient privileges.");
player.sendPacket(ActionFailed.STATIC_PACKET);
return;
}
TradeList storeList = storePlayer.getSellList();
if (storeList == null)
return;
// Check if player didn't choose any items
if (_items == null || _items.length == 0)
{
player.sendPacket(ActionFailed.STATIC_PACKET);
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;
}
L2ItemInstance iEnchant = storePlayer.getInventory().getItemByObjectId(ir.getObjectId());
int enchant = 0;
if (iEnchant == null)
{
enchant = 0;
}
else
{
enchant = iEnchant.getEnchantLevel();
}
ir.setEnchant(enchant);
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 (Config.SELL_BY_ITEM)
{
if (player.getItemCount(Config.SELL_ITEM, -1) < priceTotal)
{
sendPacket(SystemMessage.sendString("You do not have needed items to buy"));
sendPacket(ActionFailed.STATIC_PACKET);
return;
}
}
else
{
if (player.getAdena() < priceTotal)
{
sendPacket(new SystemMessage(SystemMessageId.YOU_NOT_ENOUGH_ADENA));
sendPacket(ActionFailed.STATIC_PACKET);
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(ActionFailed.STATIC_PACKET);
// Punishment e log in audit
Util.handleIllegalPlayerAction(storePlayer, "PrivateStore buy has failed due to invalid list or request. Player: " + player.getName(), Config.DEFAULT_PUNISH);
_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();
}