From e13586a2d76c9629a0c7b2d09ad674c774dd7f2b Mon Sep 17 00:00:00 2001
From: Ferywir <65760459+Ferywir@users.noreply.github.com>
Date: Wed, 24 Jun 2026 16:25:55 +0200
Subject: [PATCH] fix(market): reject resource sends above the warehouse stock
(#277)
---
Templates/Build/17.tpl | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/Templates/Build/17.tpl b/Templates/Build/17.tpl
index 030257ac..7f844490 100644
--- a/Templates/Build/17.tpl
+++ b/Templates/Build/17.tpl
@@ -51,7 +51,19 @@ $canRepeat = ($send3 === 1) || ($send3 >= 2 && $send3 <= 3 && $session->goldclub
$validTarget = $checkexist && $getwref!== $village->wid;
$validAccess = $checkexist && ($userAccess == 2 || $userAccess == MULTIHUNTER || (defined('ADMIN_ALLOW_INCOMING_RAIDS') && ADMIN_ALLOW_INCOMING_RAIDS && $userAccess == ADMIN));
-$showConfirm = ($ft === 'check' && $canRepeat && $validTarget && $allres > 0 && $allres <= $maxTotalCarry && $validAccess && $userVacation == 0);
+// Available resources, using the same getters as the actual send (Market::sendResource),
+// so a request that passes this check also passes the execution step. The client-side
+// "(maxcarry)" shortcut can fill the inputs above the warehouse stock; without this the
+// confirm step only checked the merchant capacity and the send then failed silently.
+$avail = [
+ 1 => (int)$database->getWoodAvailable($village->wid),
+ 2 => (int)$database->getClayAvailable($village->wid),
+ 3 => (int)$database->getIronAvailable($village->wid),
+ 4 => (int)$database->getCropAvailable($village->wid),
+];
+$hasResources = ($r[1] <= $avail[1] && $r[2] <= $avail[2] && $r[3] <= $avail[3] && $r[4] <= $avail[4]);
+
+$showConfirm = ($ft === 'check' && $canRepeat && $validTarget && $allres > 0 && $allres <= $maxTotalCarry && $hasResources && $validAccess && $userVacation == 0);
// coordonate prefill din GET
$coor = ['x' => '', 'y' => ''];
@@ -176,6 +188,8 @@ if (isset($_GET['z'])) {
$error = ''.ENTER_COORDINATES.'.';
} elseif ($allres > $maxTotalCarry) {
$error = ''.TOO_FEW_MERCHANTS.'.';
+ } elseif (!$hasResources) {
+ $error = ''.NOT_ENOUGH_RESOURCES.'';
}
echo $error;
}