mirror of
https://github.com/Shadowss/TravianZ.git
synced 2026-09-02 16:37:15 +00:00
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:
@@ -4580,6 +4580,18 @@ References: User ID/Message ID, Mode
|
|||||||
mysqli_query($this->dblink, "SELECT RELEASE_LOCK('research_village_$wid')");
|
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
|
* Get the time required to build a specified building
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -447,6 +447,8 @@ class Technology {
|
|||||||
private function trainUnit($unit, $amt, $great = false) {
|
private function trainUnit($unit, $amt, $great = false) {
|
||||||
global $session, $database, ${'u'.$unit}, $building, $village, $bid19, $bid20, $bid21, $bid25, $bid26, $bid29, $bid30, $bid36, $bid41, $bid42;
|
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) {
|
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];
|
$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];
|
$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);
|
$database->trainUnit($village->wid, $unit + ($great ? 60 : 0), $amt, ${'u'.$unit}['pop'], $each, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
$database->releaseTrainingLock($village->wid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function meetRRequirement($tech) {
|
public function meetRRequirement($tech) {
|
||||||
|
|||||||
Reference in New Issue
Block a user