mirror of
https://github.com/Shadowss/TravianZ.git
synced 2026-06-28 00:24:23 +00:00
refactor: installation happens at MySQL side
A lot has happened here. Here's the list: 1. autoloader was added that should prevent various "failed to open stream" errors when trying to load new classes 2. PHP-based data generation was replaced by MySQL-based one, hopefully fixing the installation problems when insert payload it too high and the DB wouldn't populate with some users 3. thanks to step 2, the installation should be really almost instantenious, instead of waiting a long time for many SQL connections and queries to populate the world 4. World Data & Oasis generation and population is done in 1 step now
This commit is contained in:
@@ -1,30 +0,0 @@
|
||||
<?php
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// TRAVIANX //
|
||||
// Only for advanced users, do not edit if you dont know what are you doing! //
|
||||
// Made by: Dzoki & Dixie (TravianX) //
|
||||
// - TravianX = Travian Clone Project - //
|
||||
// DO NOT REMOVE COPYRIGHT NOTICE! //
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
include("constant.php");
|
||||
class MYSQLi_DB {
|
||||
var $connection;
|
||||
function MYSQLi_DB() {
|
||||
$this->connection = mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS, SQL_DB) or die(mysqli_error($database->dblink));
|
||||
}
|
||||
|
||||
function query($query) {
|
||||
return mysqli_query($this->connection, $query);
|
||||
}
|
||||
|
||||
function query_return($query) {
|
||||
$q = mysqli_query($this->connection, $query);
|
||||
return mysqli_fetch_assoc($q);
|
||||
}
|
||||
};
|
||||
|
||||
if(DB_TYPE) {
|
||||
$database = new MYSQLi_DB;
|
||||
}
|
||||
?>
|
||||
@@ -1,28 +0,0 @@
|
||||
<?php
|
||||
|
||||
// don't let SQL time out when 30-500 seconds (depending on php.ini) is not enough
|
||||
@set_time_limit(0);
|
||||
|
||||
if(!isset($_SESSION)) session_start();
|
||||
$gameinstall = 1;
|
||||
include ("../../GameEngine/config.php");
|
||||
include ("../../GameEngine/Database.php");
|
||||
include ("../../GameEngine/Admin/database.php");
|
||||
|
||||
// check if we don't already have world data
|
||||
$data_exist = $database->query_return("SELECT * FROM " . TB_PREFIX . "odata LIMIT 1");
|
||||
if (count($data_exist)) {
|
||||
header("Location: ../index.php?s=6&err=1");
|
||||
exit;
|
||||
}
|
||||
|
||||
$database->populateOasisdata();
|
||||
$database->populateOasis();
|
||||
$database->populateOasisUnits2();
|
||||
|
||||
|
||||
|
||||
|
||||
header("Location: ../index.php?s=7");
|
||||
|
||||
?>
|
||||
@@ -1,140 +0,0 @@
|
||||
<?php
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// TRAVIANX //
|
||||
// Only for advanced users, do not edit if you dont know what are you doing! //
|
||||
// Made by: Dzoki & Dixie (TravianX) //
|
||||
// - TravianX = Travian Clone Project - //
|
||||
// DO NOT REMOVE COPYRIGHT NOTICE! //
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// don't let SQL time out when 30-500 seconds (depending on php.ini) is not enough
|
||||
@set_time_limit(0);
|
||||
|
||||
include("database.php");
|
||||
|
||||
// check if we don't already have world data
|
||||
$data_exist = $database->query_return("SELECT * FROM " . TB_PREFIX . "wdata LIMIT 1");
|
||||
if (count($data_exist)) {
|
||||
header("Location: ../index.php?s=3&err=1");
|
||||
exit;
|
||||
}
|
||||
|
||||
$xyas=(1+(2*WORLD_MAX));
|
||||
$values_batch = [];
|
||||
$max_batch_size = 10000;
|
||||
|
||||
for($i=0; $i<$xyas; $i++){
|
||||
$y=(WORLD_MAX-$i);
|
||||
|
||||
for($j=0; $j<$xyas; $j++){
|
||||
$x=((WORLD_MAX*-1)+$j);
|
||||
|
||||
//choose a field type
|
||||
if(($x == 0 & $y == 0) || ($x == WORLD_MAX & $y == WORLD_MAX)) {
|
||||
$typ='3';
|
||||
$otype='0';
|
||||
}else{
|
||||
$rand=rand(1, 1000);
|
||||
if("10" >= $rand){
|
||||
$typ='1';
|
||||
$otype='0';
|
||||
} else if("90" >= $rand){
|
||||
$typ='2';
|
||||
$otype='0';
|
||||
} else if("400" >= $rand){
|
||||
$typ='3';
|
||||
$otype='0';
|
||||
} else if("480" >= $rand){
|
||||
$typ='4';
|
||||
$otype='0';
|
||||
} else if("560" >= $rand){
|
||||
$typ='5';
|
||||
$otype='0';
|
||||
} else if("570" >= $rand){
|
||||
$typ='6';
|
||||
$otype='0';
|
||||
} else if("600" >= $rand){
|
||||
$typ='7';
|
||||
$otype='0';
|
||||
} else if("630" >= $rand){
|
||||
$typ='8';
|
||||
$otype='0';
|
||||
} else if("660" >= $rand){
|
||||
$typ='9';
|
||||
$otype='0';
|
||||
} else if("740" >= $rand){
|
||||
$typ='10';
|
||||
$otype='0';
|
||||
} else if("820" >= $rand){
|
||||
$typ='11';
|
||||
$otype='0';
|
||||
} else if("900" >= $rand){
|
||||
$typ='12';
|
||||
$otype='0';
|
||||
} else if("908" >= $rand){
|
||||
$typ='0';
|
||||
$otype='1';
|
||||
} else if("916" >= $rand){
|
||||
$typ='0';
|
||||
$otype='2';
|
||||
} else if("924" >= $rand){
|
||||
$typ='0';
|
||||
$otype='3';
|
||||
} else if("932" >= $rand){
|
||||
$typ='0';
|
||||
$otype='4';
|
||||
} else if("940" >= $rand){
|
||||
$typ='0';
|
||||
$otype='5';
|
||||
} else if("948" >= $rand){
|
||||
$typ='0';
|
||||
$otype='6';
|
||||
} else if("956" >= $rand){
|
||||
$typ='0';
|
||||
$otype='7';
|
||||
} else if("964" >= $rand){
|
||||
$typ='0';
|
||||
$otype='8';
|
||||
} else if("972" >= $rand){
|
||||
$typ='0';
|
||||
$otype='9';
|
||||
} else if("980" >= $rand){
|
||||
$typ='0';
|
||||
$otype='10';
|
||||
} else if("988" >= $rand){
|
||||
$typ='0';
|
||||
$otype='11';
|
||||
} else {
|
||||
$typ='0';
|
||||
$otype='12';
|
||||
}
|
||||
}
|
||||
//image pick
|
||||
if($otype=='0'){
|
||||
$image="t".rand(0,9)."";
|
||||
} else {
|
||||
$image="o".$otype."";
|
||||
}
|
||||
|
||||
//into database
|
||||
$values_batch[] = "(0,'".$typ."','".$otype."','".$x."','".$y."',0,'".$image."')";
|
||||
|
||||
// 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");
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user