diff --git a/Admin/Templates/ban_msg.tpl b/Admin/Templates/ban_msg.tpl index ea8e991e..53dd1bfd 100644 --- a/Admin/Templates/ban_msg.tpl +++ b/Admin/Templates/ban_msg.tpl @@ -8,7 +8,7 @@ ## ## ################################################################################# $time = time(); -$ban = mysql_query("SELECT * FROM ".TB_PREFIX."banlist WHERE `uid` = '".$session->uid."' and `end` < '".$time."' and active = 1"); +$ban = mysql_query("SELECT * FROM ".TB_PREFIX."banlist WHERE `uid` = '".$session->uid."' and active = 1"); $ban1 = mysql_fetch_array($ban); ?> diff --git a/Admin/_notes/dwsync.xml b/Admin/_notes/dwsync.xml new file mode 100644 index 00000000..3e3fb3c1 --- /dev/null +++ b/Admin/_notes/dwsync.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Admin/database.php b/Admin/database.php new file mode 100644 index 00000000..b1354aee --- /dev/null +++ b/Admin/database.php @@ -0,0 +1,317 @@ +connection = mysql_connect(SQL_SERVER, SQL_USER, SQL_PASS) or die(mysql_error()); + mysql_select_db(SQL_DB, $this->connection) or die(mysql_error()); + } + + function Login($username,$password){ + $q = "SELECT password FROM ".TB_PREFIX."users where username = '$username' and access >= ".MULTIHUNTER; + $result = mysql_query($q, $this->connection); + $dbarray = mysql_fetch_array($result); + if($dbarray['password'] == md5($password)) { + mysql_query("Insert into ".TB_PREFIX."admin_log values (0,'X','$username logged in (IP: ".$_SERVER['REMOTE_ADDR'].")',".time().")"); + return true; + } + else { + mysql_query("Insert into ".TB_PREFIX."admin_log values (0,'X','IP: ".$_SERVER['REMOTE_ADDR']." tried to log in with username $username but access was denied!',".time().")"); + return false; + } + } + + function recountPopUser($uid){ + global $database; + $villages = $database->getProfileVillages($uid); + for ($i = 0; $i <= count($villages)-1; $i++) { + $vid = $villages[$i]['wref']; + $this->recountPop($vid); + } + } + + function recountPop($vid){ + global $database; + $fdata = $database->getResourceLevel($vid); + $popTot = 0; + for ($i = 1; $i <= 40; $i++) { + $lvl = $fdata["f".$i]; + $building = $fdata["f".$i."t"]; + if($building){ + $popTot += $this->buildingPOP($building,$lvl); + } + } + $q = "UPDATE ".TB_PREFIX."vdata set pop = $popTot where wref = $vid"; + mysql_query($q, $this->connection); + } + + function buildingPOP($f,$lvl){ + $name = "bid".$f; + global $$name; + $popT = 0; + $dataarray = $$name; + for ($i = 0; $i <= $lvl; $i++) { + $popT += $dataarray[$i]['pop']; + } + return $popT; + } + + function getWref($x,$y) { + $q = "SELECT id FROM ".TB_PREFIX."wdata where x = $x and y = $y"; + $result = mysql_query($q, $this->connection); + $r = mysql_fetch_array($result); + return $r['id']; + } + + function AddVillage($post){ + global $database; + $wid = $this->getWref($post['x'],$post['y']); + $uid = $post['uid']; + $status = $database->getVillageState($wid); + $status = 0; + if($status == 0){ + mysql_query("Insert into ".TB_PREFIX."admin_log values (0,".$_SESSION['id'].",'Added new village $wid to user $uid',".time().")"); + $database->setFieldTaken($wid); + $database->addVillage($wid,$uid,'new village','0'); + $database->addResourceFields($wid,$database->getVillageType($wid)); + $database->addUnits($wid); + $database->addTech($wid); + $database->addABTech($wid); + } + } + + function Punish($post){ + global $database; + $villages = $database->getProfileVillages($post['uid']); + $admid = $post['admid']; + $user = $database->getUserArray($post['uid'],1); + for ($i = 0; $i <= count($villages)-1; $i++) { + $vid = $villages[$i]['wref']; + if($post['punish']){ + $popOld = $villages[$i]['pop']; + $proc = 100-$post['punish']; + $pop = floor(($popOld/100)*($proc)); + if($pop <= 1 ){$pop = 2;} + $this->PunishBuilding($vid,$proc,$pop); + + } + if($post['del_troop']){ + if($user['tribe'] == 1) { + $unit = 1; + }else if($user['tribe'] == 2) { + $unit = 11; + }else if($user['tribe'] == 3) { + $unit = 21; + } + $this->DelUnits($villages[$i]['wref'],$unit); + } + if($post['clean_ware']){ + $time = time(); + $q = "UPDATE ".TB_PREFIX."vdata SET `wood` = '0', `clay` = '0', `iron` = '0', `crop` = '0', `lastupdate` = '$time' WHERE wref = $vid;"; + mysql_query($q, $this->connection); + } + } + mysql_query("Insert into ".TB_PREFIX."admin_log values (0,".$_SESSION['id'].",'Punished user: ".$post['uid']." with -".$post['punish']."% population',".time().")"); + } + + function PunishBuilding($vid,$proc,$pop){ + global $database; + $q = "UPDATE ".TB_PREFIX."vdata set pop = $pop where wref = $vid;"; + mysql_query($q, $this->connection); + $fdata = $database->getResourceLevel($vid); + for ($i = 1; $i <= 40; $i++) { + if($fdata['f'.$i]>1){ + $zm = ($fdata['f'.$i]/100)*$proc; + if($zm < 1){$zm = 1;}else{$zm = floor($zm);} + $q = "UPDATE ".TB_PREFIX."fdata SET `f$i` = '$zm' WHERE `vref` = $vid;"; + mysql_query($q, $this->connection); + } + } + } + + function DelUnits($vid,$unit){ + for ($i = $unit; $i <= 9+$unit; $i++) { + $this->DelUnits2($vid,$unit); + } + } + + function DelUnits2($vid,$unit){ + $q = "UPDATE ".TB_PREFIX."units SET `u$unit` = '0' WHERE `vref` = $vid;"; + mysql_query($q, $this->connection); + } + + function DelPlayer($uid,$pass){ + global $database; + $ID = $_SESSION['id'];//$database->getUserField($_SESSION['username'],'id',1); + if($this->CheckPass($pass,$ID)){ + $villages = $database->getProfileVillages($uid); + for ($i = 0; $i <= count($villages)-1; $i++) { + $this->DelVillage($villages[$i]['wref']); + } + $name = $database->getUserField($uid,"username",0); + mysql_query("Insert into ".TB_PREFIX."admin_log values (0,$ID,'Deleted user $name',".time().")"); + $q = "DELETE FROM ".TB_PREFIX."users WHERE `id` = $uid;"; + mysql_query($q, $this->connection); + } + } + + function getUserActive() { + $time = time() - (60*5); + $q = "SELECT * FROM ".TB_PREFIX."users where timestamp > $time and username != 'support'"; + $result = mysql_query($q, $this->connection); + return $this->mysql_fetch_all($result); + } + + function CheckPass($password,$uid){ + $q = "SELECT password FROM ".TB_PREFIX."users where id = '$uid' and access = ".ADMIN; + $result = mysql_query($q, $this->connection); + $dbarray = mysql_fetch_array($result); + if($dbarray['password'] == md5($password)) { + return true; + }else{ + return false; + } + } + + function DelVillage($wref){ + $q = "SELECT * FROM ".TB_PREFIX."vdata WHERE `wref` = $wref and capital = 0"; + $result = mysql_query($q, $this->connection); + if(mysql_num_rows($result) > 0){ + mysql_query("Insert into ".TB_PREFIX."admin_log values (0,".$_SESSION['id'].",'Deleted village $wref',".time().")"); + $q = "DELETE FROM ".TB_PREFIX."vdata WHERE `wref` = $wref"; + mysql_query($q, $this->connection); + $q = "DELETE FROM ".TB_PREFIX."units WHERE `vref` = $wref"; + mysql_query($q, $this->connection); + $q = "DELETE FROM ".TB_PREFIX."bdata WHERE `wid` = $wref"; + mysql_query($q, $this->connection); + $q = "DELETE FROM ".TB_PREFIX."abdata WHERE `wid` = $wref"; + mysql_query($q, $this->connection); + $q = "DELETE FROM ".TB_PREFIX."fdata WHERE `vref` = $wref"; + mysql_query($q, $this->connection); + $q = "DELETE FROM ".TB_PREFIX."training WHERE `vref` = $wref"; + mysql_query($q, $this->connection); + $q = "DELETE FROM ".TB_PREFIX."movement WHERE `from` = $wref"; + mysql_query($q, $this->connection); + $q = "UPDATE ".TB_PREFIX."wdata SET `occupied` = '0' WHERE `id` = $wref"; + mysql_query($q, $this->connection); + } + } + + function DelBan($uid,$id){ + global $database; + $name = $database->getUserField($uid,"username",0); + mysql_query("Insert into ".TB_PREFIX."admin_log values (0,".$_SESSION['id'].",'Unbanned user $name',".time().")"); + $q = "UPDATE ".TB_PREFIX."users SET `access` = '".USER."' WHERE `id` = $uid;"; + mysql_query($q, $this->connection); + $q = "UPDATE ".TB_PREFIX."banlist SET `active` = '0' WHERE `id` = $id;"; + mysql_query($q, $this->connection); + } + + function AddBan($uid,$end,$reason){ + global $database; + $name = $database->getUserField($uid,"username",0); + mysql_query("Insert into ".TB_PREFIX."admin_log values (0,".$_SESSION['id'].",'Banned user $name',".time().")"); + $q = "UPDATE ".TB_PREFIX."users SET `access` = '0' WHERE `id` = $uid;"; + mysql_query($q, $this->connection); + $time = time(); + $admin = $_SESSION['id']; //$database->getUserField($_SESSION['username'],'id',1); + $name = $database->getUserField($uid,'username',0); + $q = "INSERT INTO ".TB_PREFIX."banlist (`uid`, `name`, `reason`, `time`, `end`, `admin`, `active`) VALUES ($uid, '$name' , '$reason', '$time', '$end', '$admin', '1');"; + mysql_query($q, $this->connection); + } + + function search_player($player){ + $q = "SELECT id,username FROM ".TB_PREFIX."users WHERE `username` LIKE '%$player%' and username != 'support'"; + $result = mysql_query($q, $this->connection); + return $this->mysql_fetch_all($result); + } + + function search_email($email){ + $q = "SELECT id,email FROM ".TB_PREFIX."users WHERE `email` LIKE '%$email%' and username != 'support'"; + $result = mysql_query($q, $this->connection); + return $this->mysql_fetch_all($result); + } + + function search_village($village){ + $q = "SELECT * FROM ".TB_PREFIX."vdata WHERE `name` LIKE '%$village%' or `wref` LIKE '%$village%'"; + $result = mysql_query($q, $this->connection); + return $this->mysql_fetch_all($result); + } + + function search_alliance($alliance){ + $q = "SELECT * FROM ".TB_PREFIX."alidata WHERE `name` LIKE '%$alliance%' or `tag` LIKE '%$alliance%' or `id` LIKE '%$alliance%'"; + $result = mysql_query($q, $this->connection); + return $this->mysql_fetch_all($result); + } + + function search_ip($ip){ + $q = "SELECT * FROM ".TB_PREFIX."login_log WHERE `ip` LIKE '%$ip%'"; + $result = mysql_query($q, $this->connection); + return $this->mysql_fetch_all($result); + } + + function search_banned(){ + $q = "SELECT * FROM ".TB_PREFIX."banlist where active = '1'"; + $result = mysql_query($q, $this->connection); + return $this->mysql_fetch_all($result); + } + + function Del_banned(){ + //$q = "SELECT * FROM ".TB_PREFIX."banlist"; + $result = mysql_query($q, $this->connection); + return $this->mysql_fetch_all($result); + } + + /*************************** + Function to process MYSQLi->fetch_all (Only exist in MYSQL) + References: Result + ***************************/ + function mysql_fetch_all($result) { + $all = array(); + if($result) { + while ($row = mysql_fetch_assoc($result)){ $all[] = $row; } + return $all; + } + } + + function query_return($q) { + $result = mysql_query($q, $this->connection); + return $this->mysql_fetch_all($result); + } + + /*************************** + Function to do free query + References: Query + ***************************/ + function query($query) { + return mysql_query($query, $this->connection); + } + + +}; + +$admin = new adm_DB; +include("function.php"); +?> \ No newline at end of file diff --git a/Admin/function.php b/Admin/function.php new file mode 100644 index 00000000..69971d89 --- /dev/null +++ b/Admin/function.php @@ -0,0 +1,168 @@ += MULTIHUNTER and $_SESSION['id']){ + return true; + }else{ + return false; + } + } + + function Act($get){ + global $admin,$database; + + switch($get['action']){ + case recountPop: + $admin->recountPop($get['did']); + break; + case recountPopUsr: + $admin->recountPopUser($get['uid']); + break; + case StopDel: + //stop deleting + break; + case delVil: + $admin->DelVillage($get['did']); + break; + case delBan: + $admin->DelBan($get['uid'],$get['id']); + //remove ban + break; + case addBan: + if($get['time']){$end = time()+$get['time']; }else{$end = '';} + + if(preg_match("/^[0-9]+$/",$get['uid'])){ + //if(eregi("^[0-9]*+$",$get['uid'])){ + $get['uid'] = $get['uid']; + }else{ + $get['uid'] = $database->getUserField($get['uid'],'id',1); + } + + $admin->AddBan($get['uid'],$end,$get['reason']); + //add ban + break; + case delOas: + //oaza + break; + case logout: + $this->LogOut(); + break; + } + if($get['action'] == 'logout'){ + header("Location: admin.php"); + }else{ + header("Location: ".$_SERVER['HTTP_REFERER']); + } + } + + function Act2($post){ + global $admin,$database; + switch($post['action']){ + case DelPlayer: + $admin->DelPlayer($post['uid'],$post['pass']); + header("Location: ?p=search&msg=ursdel"); + break; + case punish: + $admin->Punish($post); + header("Location: ".$_SERVER['HTTP_REFERER']); + break; + case addVillage: + $admin->AddVillage($post); + header("Location: ".$_SERVER['HTTP_REFERER']); + break; + } + } + + function LogIN($username,$password){ + global $admin,$database; + if($admin->Login($username,$password)){ + //$_SESSION['username'] = $username; + $_SESSION['access'] = $database->getUserField($username,'access',1); + $_SESSION['id'] = $database->getUserField($username,'id',1); + header("Location: ".$_SERVER['HTTP_REFERER']); + //header("Location: admin.php"); + }else{ + echo "Error"; + } + } + + function LogOut(){ + $_SESSION['access'] = ''; + $_SESSION['id'] = ''; + } + + public function procResType($ref) { + global $session; + switch($ref) { + case 1: $build = "Woodcutter"; break; + case 2: $build = "Clay Pit"; break; + case 3: $build = "Iron Mine"; break; + case 4: $build = "Cropland"; break; + case 5: $build = "Sawmill"; break; + case 6: $build = "Brickyard"; break; + case 7: $build = "Iron Foundry"; break; + case 8: $build = "Grain Mill"; break; + case 9: $build = "Bakery"; break; + case 10: $build = "Warehouse"; break; + case 11: $build = "Granary"; break; + case 12: $build = "Blacksmith"; break; + case 13: $build = "Armoury"; break; + case 14: $build = "Tournament Square"; break; + case 15: $build = "Main Building"; break; + case 16: $build = "Rally Point"; break; + case 17: $build = "Marketplace"; break; + case 18: $build = "Embassy"; break; + case 19: $build = "Barracks"; break; + case 20: $build = "Stable"; break; + case 21: $build = "Workshop"; break; + case 22: $build = "Academy"; break; + case 23: $build = "Cranny"; break; + case 24: $build = "Town Hall"; break; + case 25: $build = "Residence"; break; + case 26: $build = "Palace"; break; + case 27: $build = "Treasury"; break; + case 28: $build = "Trade Office"; break; + case 29: $build = "Great Barracks"; break; + case 30: $build = "Great Stable"; break; + case 31: $build = "City Wall"; break; + case 32: $build = "Earth Wall"; break; + case 33: $build = "Palisade"; break; + case 34: $build = "Stonemason's Lodge"; break; + case 35: $build = "Brewery"; break; + case 36: $build = "Trapper"; break; + case 37: $build = "Hero's Mansion"; break; + case 38: $build = "Great Warehouse"; break; + case 39: $build = "Great Granary"; break; + case 40: $build = "Wonder of the World"; break; + case 41: $build = "Horse Drinking Trough"; break; + default: $build = "Error"; break; + } + return $build; + } + +}; + +$funct = new funct; +if($funct->CheckLogin()){ + if($_GET['action']){ + $funct->Act($_GET); + } + if($_POST['action']){ + $funct->Act2($_POST); + } +} +if($_POST['action']=='login'){ + $funct->LogIN($_POST['name'],$_POST['pw']); +} +?> \ No newline at end of file diff --git a/Admin/welcome.tpl b/Admin/welcome.tpl new file mode 100644 index 00000000..10fe562c --- /dev/null +++ b/Admin/welcome.tpl @@ -0,0 +1,6 @@ +Hello %USER%, + +Thank you for registering on our server. +Since the %START% at %TIME% Romans, Gauls and Teutons attack each other on this game world. Right now, %PLAYERS% players in %ALLI% Alliances are fighting for supremacy. + +TravianX Team \ No newline at end of file diff --git a/GameEngine/Admin/Mods/addTroops.php b/GameEngine/Admin/Mods/addTroops.php index bf9f4f43..bf78592b 100644 --- a/GameEngine/Admin/Mods/addTroops.php +++ b/GameEngine/Admin/Mods/addTroops.php @@ -16,8 +16,6 @@ include_once("../../Account.php"); mysql_connect(SQL_SERVER, SQL_USER, SQL_PASS); mysql_select_db(SQL_DB); -if ($session->access < ADMIN) die("Access Denied: You are not Admin!"); - $id = $_POST['id']; $village = $database->getVillage($id); $user = $database->getUserArray($village['owner'],1); diff --git a/GameEngine/Admin/Mods/natarbuildingplan.php b/GameEngine/Admin/Mods/natarbuildingplan.php index 219fbf7b..ea335298 100644 --- a/GameEngine/Admin/Mods/natarbuildingplan.php +++ b/GameEngine/Admin/Mods/natarbuildingplan.php @@ -13,7 +13,6 @@ include_once("../../config.php"); include_once("../../Session.php"); mysql_connect(SQL_SERVER, SQL_USER, SQL_PASS); mysql_select_db(SQL_DB); -if ($session->access < ADMIN) die("Access Denied: You are not Admin!"); $id = $_POST['id']; $amt = $_POST['vill_amount']; @@ -27,7 +26,7 @@ for($i=1;$i<=$amt;$i++) { $time = time(); $pop = rand(50,233); $cp = $pop-1; - $q = "insert into `s1_vdata`(`wref`,`owner`,`name`,`capital`,`pop`,`cp`,`celebration`,`type`,`wood`,`clay`,`iron`,`maxstore`,`crop`,`maxcrop`,`lastupdate`,`loyalty`,`exp1`,`exp2`,`exp3`,`created`) values ('$wid','3','WW Buildingplan',0,$pop,$cp,0,0,80000.00,80000.00,80000.00,80000,80000.00,80000,1314974534,100,0,0,0,1314968914)"; + $q = "insert into ".TB_PREFIX."vdata (`wref`,`owner`,`name`,`capital`,`pop`,`cp`,`celebration`,`type`,`wood`,`clay`,`iron`,`maxstore`,`crop`,`maxcrop`,`lastupdate`,`loyalty`,`exp1`,`exp2`,`exp3`,`created`) values ('$wid','3','WW Buildingplan',0,$pop,$cp,0,0,80000.00,80000.00,80000.00,80000,80000.00,80000,1314974534,100,0,0,0,1314968914)"; mysql_query($q) or die(mysql_error()); $q = "insert into ".TB_PREFIX."fdata (`vref`,`f1`,`f1t`,`f2`,`f2t`,`f3`,`f3t`,`f4`,`f4t`,`f5`,`f5t`,`f6`,`f6t`,`f7`,`f7t`,`f8`,`f8t`,`f9`,`f9t`,`f10`,`f10t`,`f11`,`f11t`,`f12`,`f12t`,`f13`,`f13t`,`f14`,`f14t`,`f15`,`f15t`,`f16`,`f16t`,`f17`,`f17t`,`f18`,`f18t`,`f19`,`f19t`,`f20`,`f20t`,`f21`,`f21t`,`f22`,`f22t`,`f23`,`f23t`,`f24`,`f24t`,`f25`,`f25t`,`f26`,`f26t`,`f27`,`f27t`,`f28`,`f28t`,`f29`,`f29t`,`f30`,`f30t`,`f31`,`f31t`,`f32`,`f32t`,`f33`,`f33t`,`f34`,`f34t`,`f35`,`f35t`,`f36`,`f36t`,`f37`,`f37t`,`f38`,`f38t`,`f39`,`f39t`,`f40`,`f40t`,`f99`,`f99t`,`wwname`) values ($wid,0,1,0,4,0,1,0,3,0,2,0,2,0,3,0,4,0,4,0,3,0,3,0,4,0,4,0,1,0,4,0,2,0,1,0,2,20,17,20,11,10,27,20,10,10,22,10,25,0,0,20,15,10,19,0,0,0,0,0,0,10,23,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,16,0,0,0,0,'World Wonder')"; mysql_query($q); diff --git a/GameEngine/Admin/Mods/natarend.php b/GameEngine/Admin/Mods/natarend.php index 30ee68e2..475a3a8c 100644 --- a/GameEngine/Admin/Mods/natarend.php +++ b/GameEngine/Admin/Mods/natarend.php @@ -13,7 +13,6 @@ include_once("../../config.php"); include_once("../../Session.php"); mysql_connect(SQL_SERVER, SQL_USER, SQL_PASS); mysql_select_db(SQL_DB); -if ($session->access < ADMIN) die("Access Denied: You are not Admin!"); $id = $_POST['id']; $amt = $_POST['vill_amount']; @@ -27,7 +26,7 @@ for($i=1;$i<=$amt;$i++) { $time = time(); $pop = rand(50,233); $cp = $pop-1; - $q = "insert into `s1_vdata`(`wref`,`owner`,`name`,`capital`,`pop`,`cp`,`celebration`,`type`,`wood`,`clay`,`iron`,`maxstore`,`crop`,`maxcrop`,`lastupdate`,`loyalty`,`exp1`,`exp2`,`exp3`,`created`,`natar`) values ('$wid','3','WW village',0,$pop,$cp,0,0,80000.00,80000.00,80000.00,80000,80000.00,80000,1314974534,100,0,0,0,$time,1)"; + $q = "insert into ".TB_PREFIX."vdata (`wref`,`owner`,`name`,`capital`,`pop`,`cp`,`celebration`,`type`,`wood`,`clay`,`iron`,`maxstore`,`crop`,`maxcrop`,`lastupdate`,`loyalty`,`exp1`,`exp2`,`exp3`,`created`,`natar`) values ('$wid','3','WW village',0,$pop,$cp,0,0,80000.00,80000.00,80000.00,80000,80000.00,80000,1314974534,100,0,0,0,$time,1)"; mysql_query($q) or die(mysql_error()); $q = "insert into ".TB_PREFIX."fdata (`vref`,`f1`,`f1t`,`f2`,`f2t`,`f3`,`f3t`,`f4`,`f4t`,`f5`,`f5t`,`f6`,`f6t`,`f7`,`f7t`,`f8`,`f8t`,`f9`,`f9t`,`f10`,`f10t`,`f11`,`f11t`,`f12`,`f12t`,`f13`,`f13t`,`f14`,`f14t`,`f15`,`f15t`,`f16`,`f16t`,`f17`,`f17t`,`f18`,`f18t`,`f19`,`f19t`,`f20`,`f20t`,`f21`,`f21t`,`f22`,`f22t`,`f23`,`f23t`,`f24`,`f24t`,`f25`,`f25t`,`f26`,`f26t`,`f27`,`f27t`,`f28`,`f28t`,`f29`,`f29t`,`f30`,`f30t`,`f31`,`f31t`,`f32`,`f32t`,`f33`,`f33t`,`f34`,`f34t`,`f35`,`f35t`,`f36`,`f36t`,`f37`,`f37t`,`f38`,`f38t`,`f39`,`f39t`,`f40`,`f40t`,`f99`,`f99t`,`wwname`) values ($wid,0,1,0,4,0,1,0,3,0,2,0,2,0,3,0,4,0,4,0,3,0,3,0,4,0,4,0,1,0,4,0,2,0,1,0,2,20,17,20,11,20,15,20,10,10,22,10,25,0,0,0,0,10,19,0,0,0,0,0,0,10,23,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,16,0,0,0,40,'World Wonder')"; mysql_query($q); diff --git a/GameEngine/Automation.php b/GameEngine/Automation.php index cd476ab5..42b715df 100644 --- a/GameEngine/Automation.php +++ b/GameEngine/Automation.php @@ -1069,9 +1069,21 @@ class Automation { //top 10 attack and defence update $totaldead_att = $dead1+$dead2+$dead3+$dead4+$dead5+$dead6+$dead7+$dead8+$dead9+$dead10+$dead11; $totalattackdead += $totaldead_att; + $troopsdead1 = $dead1; + $troopsdead2 = $dead2; + $troopsdead3 = $dead3; + $troopsdead4 = $dead4; + $troopsdead5 = $dead5; + $troopsdead6 = $dead6; + $troopsdead7 = $dead7; + $troopsdead8 = $dead8; + $troopsdead9 = $dead9; + $troopsdead10 = $dead10; + $troopsdead11 = $dead11; for($i=1;$i<=50;$i++) { $totaldead_def += $dead[''.$i.'']; } + $totaldead_def += $dead['hero']; if ($Attacker['uhero'] != 0){ $heroxp = $totaldead_def; $database->modifyHeroXp("experience",$heroxp,$from['owner']); @@ -1763,10 +1775,45 @@ class Automation { //chiefing village //there are senators if(($data['t9']-$dead9)>0){ + + $palacelevel = $database->getResourceLevel($from['wref']); + if($palacelevel < 10){ + $canconquer = 0; + } + elseif($palacelevel < 15){ + $canconquer = 1; + } + elseif($palacelevel < 20){ + $canconquer = 2; + } + else{ + $canconquer = 3; + } + + $exp1 = $database->getVillageField($from['wref'],'exp1'); + $exp2 = $database->getVillageField($from['wref'],'exp2'); + $exp3 = $database->getVillageField($from['wref'],'exp3'); + if($exp1 == 0){ + $villexp = 0; + } + elseif($exp2 == 0){ + $villexp = 1; + } + elseif($exp2 == 0){ + $villexp = 2; + } + else{ + $villexp = 3; + } $varray = $database->getProfileVillages($to['owner']); + $varray1 = count($database->getProfileVillages($from['owner'])); + $mode = CP; + $need_cps = ${'cp'.$mode}[$varray1]; + $user_cps = $database->getUserField($from['owner'],"cp",0); //kijken of laatste dorp is, of hoofddorp - if(count($varray)!='1' AND $to['capital']!='1'){ - if($to['owenr']!=3 AND $to['name']!='WW Buildingplan'){ + if($user_cps >= $need_cps){ + if(count($varray)!='1' AND $to['capital']!='1' AND $villexp < $canconquer){ + if($to['owenr']!=3 OR $to['name']!='WW Buildingplan'){ //if there is no Palace/Residence for ($i=18; $i<39; $i++){ if ($database->getFieldLevel($data['to'],"".$i."t")==25 or $database->getFieldLevel($data['to'],"".$i."t")==26){ @@ -1854,6 +1901,9 @@ class Automation { } else { $info_chief = "".$chief_pic.",You cant take over this village."; } + } else { + $info_chief = "".$chief_pic.",Not enough culture points."; + } } if($data['t11'] > 0){ @@ -2006,23 +2056,7 @@ $crannyimg = "addMovement(4,$to['wref'],$from['wref'],$data['ref'],time(),$endtime); }else{ - $villreinf = $database->addEnforce($data); - $villtribe = $database->getUserField($from['owner'],"tribe",0); - $unittribe = $villtribe-1; - if($unittribe == 0){ - $unittribe = ""; - } - $database->modifyEnforce($villreinf,$unittribe.'1',$data['t1']-$dead1,1); - $database->modifyEnforce($villreinf,$unittribe.'2',$data['t2']-$dead2,1); - $database->modifyEnforce($villreinf,$unittribe.'3',$data['t3']-$dead3,1); - $database->modifyEnforce($villreinf,$unittribe.'4',$data['t4']-$dead4,1); - $database->modifyEnforce($villreinf,$unittribe.'5',$data['t5']-$dead5,1); - $database->modifyEnforce($villreinf,$unittribe.'6',$data['t6']-$dead6,1); - $database->modifyEnforce($villreinf,$unittribe.'7',$data['t7']-$dead7,1); - $database->modifyEnforce($villreinf,$unittribe.'8',$data['t8']-$dead8,1); - $database->modifyEnforce($villreinf,$unittribe.'9',$data['t9']-$dead9-1,1); - $database->modifyEnforce($villreinf,$unittribe.'10',$data['t10']-$dead10,1); - $database->modifyEnforce($villreinf,$unittribe.'11',$data['t11']-$dead11,1); + $database->addEnforce2($data,$owntribe,$troopsdead1,$troopsdead2,$troopsdead3,$troopsdead4,$troopsdead5,$troopsdead6,$troopsdead7,$troopsdead8,$troopsdead9,$troopsdead10,$troopsdead11); } // send the bounty on type 6. if($type !== 1) @@ -2093,6 +2127,17 @@ $crannyimg = "calculateBattle($attacker,$defender,$wall,$post['a1_v'],$deftribe,$post['palast'],$post['ew1'],$post['ew2'],1,$def_ab,$att_ab,$post['kata'],1,0,0,0); } + public function getTypeLevel($tid,$vid) { + global $village,$database; + $keyholder = array(); + $resourcearray = $database->getResourceLevel($vid); + + foreach(array_keys($resourcearray,$tid) as $key) { + if(strpos($key,'t')) { + $key = preg_replace("/[^0-9]/", '', $key); + array_push($keyholder, $key); + } + } + $element = count($keyholder); + if($element >= 2) { + if($tid <= 4) { + $temparray = array(); + for($i=0;$i<=$element-1;$i++) { + array_push($temparray,$resourcearray['f'.$keyholder[$i]]); + } + foreach ($temparray as $key => $val) { + if ($val == max($temparray)) + $target = $key; + } + } + else { + $target = 0; + for($i=1;$i<=$element-1;$i++) { + if($resourcearray['f'.$keyholder[$i]] > $resourcearray['f'.$keyholder[$target]]) { + $target = $i; + } + } + } + } + else if($element == 1) { + $target = 0; + } + else { + return 0; + } + if($keyholder[$target] != "") { + return $resourcearray['f'.$keyholder[$target]]; + } + else { + return 0; + } + } + //1 raid 0 normal function calculateBattle($Attacker,$Defender,$def_wall,$att_tribe,$def_tribe,$residence,$attpop,$defpop,$type,$def_ab,$att_ab,$tblevel,$stonemason,$walllevel,$AttackerID,$DefenderID,$AttackerWref) { - global $database,$bid34; + global $database,$bid34,$bid35; // Definieer de array met de eenheden $calvary = array(4,5,6,15,16,23,24,25,26,35,36,45,46); $catapult = array(8,18,28,38,48); @@ -349,7 +395,7 @@ class Battle { // // Formule voor het berekenen van punten aanvallers (Infanterie & Cavalry) // - $rap = ($ap+$cap)+(($ap+$cap)/100*$bid35[$automation->getTypeLevel(35,$AttackerWref)]['attri']); + $rap = ($ap+$cap)+(($ap+$cap)/100*$bid35[$this->getTypeLevel(35,$AttackerWref)]['attri']); // // Formule voor de berekening van Defensive Punten // diff --git a/GameEngine/Database/db_MYSQL.php b/GameEngine/Database/db_MYSQL.php index 05a3f0f3..cb13958d 100644 --- a/GameEngine/Database/db_MYSQL.php +++ b/GameEngine/Database/db_MYSQL.php @@ -2259,6 +2259,31 @@ $this->modifyEnforce($id,'hero',$data['t11'],1); return mysql_insert_id($this->connection); } + + function addEnforce2($data,$tribe,$dead1,$dead2,$dead3,$dead4,$dead5,$dead6,$dead7,$dead8,$dead9,$dead10,$dead11) { + $q = "INSERT into " . TB_PREFIX . "enforcement (vref,`from`) values (" . $data['to'] . "," . $data['from'] . ")"; + mysql_query($q, $this->connection); + $id = mysql_insert_id($this->connection); + $owntribe = $this->getUserField($this->getVillageField($data['from'], "owner"), "tribe", 0); + $start = ($owntribe - 1) * 10 + 1; + $end = ($owntribe * 10); + $start2 = ($tribe - 1) * 10 + 1; + $start3 = ($tribe - 1) * 10; + if($start3 == 0){ + $start3 = ""; + } + $end2 = ($tribe * 10); + //add unit + $j = '1'; + for($i = $start; $i <= $end; $i++) { + $this->modifyEnforce($id, $i, $data['t' . $j . ''], 1); + $this->modifyEnforce($id, $i, ${dead.$j}, 0); + $j++; + } + $this->modifyEnforce($id,'hero',$data['t11'],1); + $this->modifyEnforce($id,'hero',$dead11,0); + return mysql_insert_id($this->connection); + } function modifyEnforce($id, $unit, $amt, $mode) { if($unit != 'hero') { $unit = 'u' . $unit; }