refactor: much speedier installation process

This commit is contained in:
Martin Ambrus
2017-10-23 13:38:32 +02:00
parent 50eb34db57
commit 12687766b6
7 changed files with 60 additions and 83 deletions
+35 -75
View File
@@ -721,14 +721,8 @@ class MYSQLi_DB {
} }
function populateOasis() { function populateOasis() {
$q = "SELECT * FROM " . TB_PREFIX . "wdata where oasistype != 0"; $q = "INSERT INTO " . TB_PREFIX . "units (vref) SELECT id FROM " . TB_PREFIX . "wdata WHERE oasistype <> 0";
$result = mysqli_query($this->dblink,$q); mysqli_query($this->dblink,$q);
while($row = mysqli_fetch_array($result)) {
$wid = $row['id'];
$this->addUnits($wid);
}
} }
function populateOasisUnits($wid, $high) { function populateOasisUnits($wid, $high) {
@@ -799,57 +793,37 @@ class MYSQLi_DB {
} }
function populateOasisUnits2() { function populateOasisUnits2() {
$q2 = "SELECT * FROM " . TB_PREFIX . "wdata where oasistype != 0"; // +25% lumber oasis
$result2 = mysqli_query($this->dblink,$q2); $q = "UPDATE " . TB_PREFIX . "units SET u35 = u35 + (FLOOR(5 + RAND() * 10)), u36 = u36 + (FLOOR(0 + RAND() * 5)), u37 = u37 + (FLOOR(0 + RAND() * 5)) WHERE vref IN(SELECT id FROM " . TB_PREFIX . "wdata WHERE oasistype IN(1,2)) AND u35 <= 10 AND u36 <= 10 AND u37 <= 10";
while($row = mysqli_fetch_array($result2)) { mysqli_query($this->dblink,$q);
$wid = (int) $row['id'];
switch($row['oasistype']) { // +25% lumber and +25% crop oasis
case 1: $q = "UPDATE " . TB_PREFIX . "units SET u35 = u35 + (FLOOR(5 + RAND() * 15)), u36 = u36 + (FLOOR(0 + RAND() * 5)), u37 = u37 + (FLOOR(0 + RAND() * 5)) WHERE vref IN(SELECT id FROM " . TB_PREFIX . "wdata WHERE oasistype IN(3)) AND u35 <= 10 AND u36 <= 10 AND u37 <= 10";
case 2: mysqli_query($this->dblink,$q);
//+25% lumber oasis
$q = "UPDATE " . TB_PREFIX . "units SET u35 = u35 + '".rand(5,10)."', u36 = u36 + '".rand(0,5)."', u37 = u37 + '".rand(0,5)."' WHERE vref = '" . $wid . "' AND u35 <= '10' AND u36 <= '10' AND u37 <= '10'"; // +25% clay oasis
$result = mysqli_query($this->dblink,$q); $q = "UPDATE " . TB_PREFIX . "units SET u31 = u31 + (FLOOR(10 + RAND() * 15)), u32 = u32 + (FLOOR(5 + RAND() * 15)), u35 = u35 + (FLOOR(0 + RAND() * 10)) WHERE vref IN(SELECT id FROM " . TB_PREFIX . "wdata WHERE oasistype IN(4,5)) AND u31 <= 10 AND u32 <= 10 AND u35 <= 10";
break; mysqli_query($this->dblink,$q);
case 3:
//+25% lumber and +25% crop oasis // +25% clay and +25% crop oasis
$q = "UPDATE " . TB_PREFIX . "units SET u35 = u35 + '".rand(5,15)."', u36 = u36 + '".rand(0,5)."', u37 = u37 + '".rand(0,5)."' WHERE vref = '" . $wid . "' AND u35 <= '10' AND u36 <= '10' AND u37 <='10'"; $q = "UPDATE " . TB_PREFIX . "units SET u31 = u31 + (FLOOR(15 + RAND() * 20)), u32 = u32 + (FLOOR(10 + RAND() * 15)), u35 = u35 + (FLOOR(0 + RAND() * 10)) WHERE vref IN(SELECT id FROM " . TB_PREFIX . "wdata WHERE oasistype IN(6)) AND u31 <= 10 AND u32 <= 10 AND u35 <= 10";
$result = mysqli_query($this->dblink,$q); mysqli_query($this->dblink,$q);
break;
case 4: // +25% iron oasis
case 5: $q = "UPDATE " . TB_PREFIX . "units SET u31 = u31 + (FLOOR(10 + RAND() * 15)), u32 = u32 + (FLOOR(5 + RAND() * 15)), u34 = u34 + (FLOOR(0 + RAND() * 10)) WHERE vref IN(SELECT id FROM " . TB_PREFIX . "wdata WHERE oasistype IN(7,8)) AND u31 <= 10 AND u32 <= 10 AND u34 <= 10";
//+25% clay oasis mysqli_query($this->dblink,$q);
$q = "UPDATE " . TB_PREFIX . "units SET u31 = u31 + '".rand(10,15)."', u32 = u32 + '".rand(5,15)."', u35 = u35 + '".rand(0,10)."' WHERE vref = '" . $wid . "' AND u31 <= '10' AND u32 <= '10' AND u35 <= '10'";
$result = mysqli_query($this->dblink,$q); // +25% iron and +25% crop oasis
break; $q = "UPDATE " . TB_PREFIX . "units SET u31 = u31 + (FLOOR(15 + RAND() * 20)), u32 = u32 + (FLOOR(10 + RAND() * 15)), u34 = u34 + (FLOOR(0 + RAND() * 10)) WHERE vref IN(SELECT id FROM " . TB_PREFIX . "wdata WHERE oasistype IN(9)) AND u31 <= 10 AND u32 <= 10 AND u34 <= 10";
case 6: mysqli_query($this->dblink,$q);
//+25% clay and +25% crop oasis
$q = "UPDATE " . TB_PREFIX . "units SET u31 = u31 + '".rand(15,20)."', u32 = u32 + '".rand(10,15)."', u35 = u35 + '".rand(0,10)."' WHERE vref = '" . $wid . "' AND u31 <= '10' AND u32 <= '10' AND u35 <='10'"; // +25% crop oasis
$result = mysqli_query($this->dblink,$q); $q = "UPDATE " . TB_PREFIX . "units SET u31 = u31 + (FLOOR(5 + RAND() * 15)), u33 = u33 + (FLOOR(5 + RAND() * 10)), u37 = u37 + (FLOOR(0 + RAND() * 10)), u39 = u39 + (FLOOR(0 + RAND() * 5)) WHERE vref IN(SELECT id FROM " . TB_PREFIX . "wdata WHERE oasistype IN(10,11)) AND u31 <= 10 AND u33 <= 10 AND u37 <= 10 AND u39 <= 10";
break; mysqli_query($this->dblink,$q);
case 7:
case 8: // +50% crop oasis
//+25% iron oasis $q = "UPDATE " . TB_PREFIX . "units SET u31 = u31 + (FLOOR(10 + RAND() * 15)), u33 = u33 + (FLOOR(5 + RAND() * 10)), u38 = u38 + (FLOOR(0 + RAND() * 5)), u39 = u39 + (FLOOR(0 + RAND() * 5)) WHERE vref IN(SELECT id FROM " . TB_PREFIX . "wdata WHERE oasistype IN(12)) AND u31 <= 10 AND u33 <= 10 AND u38 <= 10 AND u39 <= 10";
$q = "UPDATE " . TB_PREFIX . "units SET u31 = u31 + '".rand(10,15)."', u32 = u32 + '".rand(5,15)."', u34 = u34 + '".rand(0,10)."' WHERE vref = '" . $wid . "' AND u31 <= '10' AND u32 <= '10' AND u34 <= '10'"; mysqli_query($this->dblink,$q);
$result = mysqli_query($this->dblink,$q);
break;
case 9:
//+25% iron and +25% crop oasis
$q = "UPDATE " . TB_PREFIX . "units SET u31 = u31 + '".rand(15,20)."', u32 = u32 + '".rand(10,15)."', u34 = u34 + '".rand(0,10)."' WHERE vref = '" . $wid . "' AND u31 <= '10' AND u32 <= '10' AND u34 <='10'";
$result = mysqli_query($this->dblink,$q);
break;
case 10:
case 11:
//+25% crop oasis
$q = "UPDATE " . TB_PREFIX . "units SET u31 = u31 + '".rand(5,15)."', u33 = u33 + '".rand(5,10)."', u37 = u37 + '".rand(0,10)."', u39 = u39 + '".rand(0,5)."' WHERE vref = '" . $wid . "' AND u31 <= '10' AND u33 <= '10' AND u37 <='10' AND u39 <='10'";
$result = mysqli_query($this->dblink,$q);
break;
case 12:
//+50% crop oasis
$q = "UPDATE " . TB_PREFIX . "units SET u31 = u31 + '".rand(10,15)."', u33 = u33 + '".rand(5,10)."', u38 = u38 + '".rand(0,5)."', u39 = u39 + '".rand(0,5)."' WHERE vref = '" . $wid . "' AND u31 <= '10' AND u33 <= '10' AND u38 <='10'AND u39 <='10'";
$result = mysqli_query($this->dblink,$q);
break;
}
}
} }
function removeOases($wref) { function removeOases($wref) {
@@ -3797,22 +3771,8 @@ class MYSQLi_DB {
} }
function populateOasisdata() { function populateOasisdata() {
$q2 = "SELECT * FROM " . TB_PREFIX . "wdata where oasistype != 0"; $q = "INSERT INTO " . TB_PREFIX . "odata SELECT id, oasistype, 0, 800, 800, 800, 800, 800, 800, UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), 100, 2 , \"Unoccupied Oasis\", CASE WHEN oasistype < 4 THEN 1 WHEN oasistype < 10 THEN 2 ELSE 0 END FROM " . TB_PREFIX . "wdata WHERE oasistype <> 0";
$result2 = mysqli_query($this->dblink,$q2); mysqli_query($this->dblink,$q) OR DIE (mysqli_error($this->dblink));
while($row = mysqli_fetch_array($result2)) {
$wid = $row['id'];
$basearray = $this->getOMInfo($wid);
if($basearray['oasistype'] < 4) {
$high = 1;
} else if ($basearray['oasistype'] < 10){
$high = 2;
}else {
$high = 0;
}
//We switch type of oasis and instert record with apropriate infomation.
$q = "INSERT into " . TB_PREFIX . "odata VALUES ('" . $basearray['id'] . "'," . (int) $basearray['oasistype'] . ",0,800,800,800,800,800,800," . time() . "," . time() . ",100,2,'Unoccupied Oasis',".(int) $high.")";
$result = mysqli_query($this->dblink,$q);
}
} }
public function getAvailableExpansionTraining() { public function getAvailableExpansionTraining() {
+2
View File
@@ -55,6 +55,8 @@ martinambrus changes:
43. players who post in an Alliance forum are now notified of each subsequent post in that topic via messages 43. players who post in an Alliance forum are now notified of each subsequent post in that topic via messages
44. editing troops in Admin now saves them when Enter is used instead of clicking on "Save" as well 44. editing troops in Admin now saves them when Enter is used instead of clicking on "Save" as well
45. added option into Admin config to allow Administrative accounts to be raided and attacked (which also permits trading with them via Market) 45. added option into Admin config to allow Administrative accounts to be raided and attacked (which also permits trading with them via Market)
46. vastly improved speed of world and oasis generation steps
47. Multihunter & Support password fields are now really password fields
Shadowss changes: Shadowss changes:
+2 -2
View File
@@ -1571,9 +1571,9 @@ CREATE TABLE IF NOT EXISTS `%PREFIX%users` (
-- --
INSERT INTO `%PREFIX%users` (`id`, `username`, `password`, `email`, `tribe`, `access`, `gold`, `gender`, `birthday`, `location`, `desc1`, `desc2`, `plus`, `b1`, `b2`, `b3`, `b4`, `sit1`, `sit2`, `alliance`, `sessid`, `act`, `timestamp`, `ap`, `apall`, `dp`, `dpall`, `protect`, `quest`, `gpack`, `cp`, `lastupdate`, `RR`, `Rc`, `ok`) VALUES INSERT INTO `%PREFIX%users` (`id`, `username`, `password`, `email`, `tribe`, `access`, `gold`, `gender`, `birthday`, `location`, `desc1`, `desc2`, `plus`, `b1`, `b2`, `b3`, `b4`, `sit1`, `sit2`, `alliance`, `sessid`, `act`, `timestamp`, `ap`, `apall`, `dp`, `dpall`, `protect`, `quest`, `gpack`, `cp`, `lastupdate`, `RR`, `Rc`, `ok`) VALUES
(5, 'Multihunter', '', 'multihunter@travianx.mail', 0, 9, 0, 0, '1970-01-01', '', '', '', 0, 0, 0, 0, 0, 0, 0, 0, '', '', 0, 0, 0, 0, 0, 0, 0, 'gpack/travian_default/', 1, 0, 0, 0, 0), (5, 'Multihunter', '', 'multihunter@travianz.game', 0, 9, 0, 0, '1970-01-01', '', '', '', 0, 0, 0, 0, 0, 0, 0, 0, '', '', 0, 0, 0, 0, 0, 0, 0, 'gpack/travian_default/', 1, 0, 0, 0, 0),
(1, 'Support', '', 'support@travianz.game', 0, 8, 0, 0, '1970-01-01', '', '', '', 0, 0, 0, 0, 0, 0, 0, 0, '', '', 0, 0, 0, 0, 0, 0, 0, 'gpack/travian_default/', 1, 0, 0, 0, 0), (1, 'Support', '', 'support@travianz.game', 0, 8, 0, 0, '1970-01-01', '', '', '', 0, 0, 0, 0, 0, 0, 0, 0, '', '', 0, 0, 0, 0, 0, 0, 0, 'gpack/travian_default/', 1, 0, 0, 0, 0),
(2, 'Nature', '4262cc190152adfc1a3fcf32af6aa430', 'nature@travianz.game', 4, 9, 0, 0, '1970-01-01', '', '', '', 0, 0, 0, 0, 0, 0, 0, 0, '', '', 0, 0, 0, 0, 0, 0, 0, 'gpack/travian_default/', 1, 0, 0, 0, 0), (2, 'Nature', '', 'nature@travianz.game', 4, 2, 0, 0, '1970-01-01', '', '', '', 0, 0, 0, 0, 0, 0, 0, 0, '', '', 0, 0, 0, 0, 0, 0, 0, 'gpack/travian_default/', 1, 0, 0, 0, 0),
(4, 'Taskmaster', '', 'taskmaster@travianz.game', 0, 8, 0, 0, '1970-01-01', '', '', '', 0, 0, 0, 0, 0, 0, 0, 0, '', '', 0, 0, 0, 0, 0, 0, 0, 'gpack/travian_default/', 1, 0, 0, 0, 0); (4, 'Taskmaster', '', 'taskmaster@travianz.game', 0, 8, 0, 0, '1970-01-01', '', '', '', 0, 0, 0, 0, 0, 0, 0, 0, '', '', 0, 0, 0, 0, 0, 0, 0, 'gpack/travian_default/', 1, 0, 0, 0, 0);
-- -------------------------------------------------------- -- --------------------------------------------------------
+1 -1
View File
@@ -23,6 +23,6 @@
header("Location: ../index.php?s=6"); header("Location: ../index.php?s=7");
?> ?>
+17 -2
View File
@@ -20,6 +20,8 @@ if (count($data_exist)) {
} }
$xyas=(1+(2*WORLD_MAX)); $xyas=(1+(2*WORLD_MAX));
$values_batch = [];
$max_batch_size = 10000;
for($i=0; $i<$xyas; $i++){ for($i=0; $i<$xyas; $i++){
$y=(WORLD_MAX-$i); $y=(WORLD_MAX-$i);
@@ -115,11 +117,24 @@ $y=(WORLD_MAX-$i);
} }
//into database //into database
$q = "INSERT into ".TB_PREFIX."wdata values (0,'".$typ."','".$otype."','".$x."','".$y."',0,'".$image."')"; $values_batch[] = "(0,'".$typ."','".$otype."','".$x."','".$y."',0,'".$image."')";
$database->query($q);
// insert the full batch when threshold is reached
if (count($values_batch) === $max_batch_size) {
$q = "INSERT into ".TB_PREFIX."wdata VALUES ".implode(',', $values_batch);
$database->query($q);
$values_batch = [];
}
} }
} }
// last batch may not be as big as $max_batch_size
if (count($values_batch)) {
$q = "INSERT into ".TB_PREFIX."wdata VALUES ".implode(',', $values_batch);
$database->query($q);
$values_batch = [];
}
header("Location: ../index.php?s=4"); header("Location: ../index.php?s=4");
?> ?>
+2 -1
View File
@@ -14,6 +14,7 @@
## Source code: https://github.com/Shadowss/TravianZ ## ## Source code: https://github.com/Shadowss/TravianZ ##
## ## ## ##
################################################################################# #################################################################################
rename("include/constant.php","../GameEngine/config.php");
?> ?>
@@ -24,7 +25,7 @@
<span class="f10 c">Create Multihunter account</span> <span class="f10 c">Create Multihunter account</span>
<table> <table>
<tr><td>Name:</td><td><input type="text" name="mhpw" id="mhpw" value="Multihunter" disabled="disabled"></td></tr> <tr><td>Name:</td><td><input type="text" name="mhpw" id="mhpw" value="Multihunter" disabled="disabled"></td></tr>
<tr><td>Password:</td><td><input type="text" name="mhpw" id="mhpw" value=""></td></tr> <tr><td>Password:</td><td><input type="password" name="mhpw" id="mhpw" value=""></td></tr>
<tr><td>Note: Rember this password! You need it for the ACP</td><td></td></tr> <tr><td>Note: Rember this password! You need it for the ACP</td><td></td></tr>
</table> </table>
</p> </p>
+1 -2
View File
@@ -14,7 +14,6 @@
## Source code: https://github.com/Shadowss/TravianZ ## ## Source code: https://github.com/Shadowss/TravianZ ##
## ## ## ##
################################################################################# #################################################################################
rename("include/constant.php","../GameEngine/config.php");
?> ?>
@@ -25,7 +24,7 @@
<span class="f10 c">Create Support account</span> <span class="f10 c">Create Support account</span>
<table> <table>
<tr><td>Name:</td><td><input type="text" name="sname" value="Support" disabled="disabled"></td></tr> <tr><td>Name:</td><td><input type="text" name="sname" value="Support" disabled="disabled"></td></tr>
<tr><td>Password:</td><td><input type="text" name="spw" id="spw" value=""></td></tr> <tr><td>Password:</td><td><input type="password" name="spw" id="spw" value=""></td></tr>
<tr><td>Note: Rember this password! You need it for the ACP</td><td></td></tr> <tr><td>Note: Rember this password! You need it for the ACP</td><td></td></tr>
</table> </table>
</p> </p>