diff --git a/GameEngine/Database.php b/GameEngine/Database.php index bd9f7c28..28828d5c 100755 --- a/GameEngine/Database.php +++ b/GameEngine/Database.php @@ -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 * diff --git a/GameEngine/Technology.php b/GameEngine/Technology.php index 989e32a8..c07d5179 100755 --- a/GameEngine/Technology.php +++ b/GameEngine/Technology.php @@ -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) {