Fix parallel training exploit (#145)

* Fix parallel building exploit via race condition

* Fix parallel research exploit via race condition

* Fix parallel training exploit

---------

Co-authored-by: hdmaniak <bombo15.forum@gmail.com>
Co-authored-by: Catalin Novgorodschi <1140613+Shadowss@users.noreply.github.com>
This commit is contained in:
hdmaniak2
2026-03-25 07:22:39 +01:00
committed by GitHub
parent 2e5f9f6169
commit 9b03def903
2 changed files with 17 additions and 0 deletions
+12
View File
@@ -4580,6 +4580,18 @@ References: User ID/Message ID, Mode
mysqli_query($this->dblink, "SELECT RELEASE_LOCK('research_village_$wid')");
}
function getTrainingLock($wid) {
$wid = (int) $wid;
$result = mysqli_query($this->dblink, "SELECT GET_LOCK('train_village_$wid', 10) AS locked");
$row = mysqli_fetch_assoc($result);
return $row['locked'] == 1;
}
function releaseTrainingLock($wid) {
$wid = (int) $wid;
mysqli_query($this->dblink, "SELECT RELEASE_LOCK('train_village_$wid')");
}
/**
* Get the time required to build a specified building
*
+5
View File
@@ -447,6 +447,8 @@ class Technology {
private function trainUnit($unit, $amt, $great = false) {
global $session, $database, ${'u'.$unit}, $building, $village, $bid19, $bid20, $bid21, $bid25, $bid26, $bid29, $bid30, $bid36, $bid41, $bid42;
if (!$database->getTrainingLock($village->wid)) return;
try {
if($this->getTech($unit) || $unit % 10 <= 1 || $unit == 99) {
$footies = [1, 2, 3, 11, 12, 13, 14, 21, 22, 31, 32, 33, 34, 41, 42, 43, 44];
$calvary = [4, 5, 6, 15, 16, 23, 24, 25, 26, 35, 36, 45, 46];
@@ -529,6 +531,9 @@ class Technology {
$database->trainUnit($village->wid, $unit + ($great ? 60 : 0), $amt, ${'u'.$unit}['pop'], $each, 0);
}
}
} finally {
$database->releaseTrainingLock($village->wid);
}
}
public function meetRRequirement($tech) {