diff --git a/GameEngine/Database/db_MYSQLi.php b/GameEngine/Database/db_MYSQLi.php index 0b513c8b..aaf58deb 100644 --- a/GameEngine/Database/db_MYSQLi.php +++ b/GameEngine/Database/db_MYSQLi.php @@ -1,37 +1,42 @@ connection = mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS, SQL_DB) or die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error()); - - ## Added even MySQL connection for inline mysql commands in temeplate files - $con = mysql_connect(SQL_SERVER, SQL_USER, SQL_PASS); - mysql_select_db(SQL_DB, $this->connection); + $this->connection = mysqli_connect(SQL_SERVER, SQL_USER, SQL_PASS) or die(mysql_error()); + mysql_select_db(SQL_DB, $this->connection) or die(mysql_error()); + mysqli_query("SET NAMES 'UTF8'"); //Fix utf8 phpmyadmin by gm4st3r } function register($username, $password, $email, $tribe, $act) { $time = time(); - $stime = strtotime(START_DATE)-strtotime(date('m/d/Y'))+strtotime(START_TIME); + $stime = strtotime(START_DATE)-strtotime(date('m/d/Y'))+strtotime(START_TIME); if($stime > time()){ $time = $stime; } $timep = $time + PROTECTION; $time = time(); $q = "INSERT INTO " . TB_PREFIX . "users (username,password,access,email,timestamp,tribe,act,protect,lastupdate,regtime) VALUES ('$username', '$password', " . USER . ", '$email', $time, $tribe, '$act', $timep, $time, $time)"; - if(mysql_query($this->connection, $q)) { - return mysql_insert_id($this->connection); + if(mysqli_query($q, $this->connection)) { + return mysqli_insert_id($this->connection); } else { return false; } @@ -40,7 +45,7 @@ class MYSQLi_DB { function activate($username, $password, $email, $tribe, $locate, $act, $act2) { $time = time(); $q = "INSERT INTO " . TB_PREFIX . "activate (username,password,access,email,tribe,timestamp,location,act,act2) VALUES ('$username', '$password', " . USER . ", '$email', $tribe, $time, $locate, '$act', '$act2')"; - if(mysqli_query($this->connection, $q)) { + if(mysqli_query($q, $this->connection)) { return mysqli_insert_id($this->connection); } else { return false; @@ -49,17 +54,17 @@ class MYSQLi_DB { function unreg($username) { $q = "DELETE from " . TB_PREFIX . "activate where username = '$username'"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function deleteReinf($id) { $q = "DELETE from " . TB_PREFIX . "enforcement where id = '$id'"; - mysqli_query($this->connection, $q); + mysqli_query($q, $this->connection); } function updateResource($vid, $what, $number) { $q = "UPDATE " . TB_PREFIX . "vdata set " . $what . "=" . $number . " where wref = $vid"; - $result = mysqli_query($this->connection, $q); - return mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); + return mysqli_query($q, $this->connection); } function checkExist($ref, $mode) { @@ -69,7 +74,7 @@ class MYSQLi_DB { } else { $q = "SELECT email FROM " . TB_PREFIX . "users where email = '$ref' LIMIT 1"; } - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); if(mysqli_num_rows($result)) { return true; } else { @@ -84,7 +89,7 @@ class MYSQLi_DB { } else { $q = "SELECT email FROM " . TB_PREFIX . "activate where email = '$ref' LIMIT 1"; } - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); if(mysqli_num_rows($result)) { return true; } else { @@ -94,8 +99,8 @@ class MYSQLi_DB { public function hasBeginnerProtection($vid) { $q = "SELECT u.protect FROM ".TB_PREFIX."users u,".TB_PREFIX."vdata v WHERE u.id=v.owner AND v.wref=".$vid; - $result = mysqli_query($this->connection, $q); - $dbarray = mysqli_fetch_array($result, MYSQLI_BOTH); + $result = mysqli_query($q, $this->connection); + $dbarray = mysqli_fetch_array($result); if(!empty($dbarray)) { if(time()<$dbarray[0]) { return true; @@ -113,92 +118,102 @@ class MYSQLi_DB { } else { $q = "UPDATE " . TB_PREFIX . "users set $field = '$value' where id = '$ref'"; } - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function getSitee($uid) { $q = "SELECT id from " . TB_PREFIX . "users where sit1 = $uid or sit2 = $uid"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } function getVilWref($x, $y) { $q = "SELECT * FROM " . TB_PREFIX . "wdata where x = $x AND y = $y"; - $result = mysqli_query($this->connection, $q); - $dbarray = mysqli_fetch_array($result, MYSQLI_BOTH); + $result = mysqli_query($q, $this->connection); + $dbarray = mysqli_fetch_array($result); return $dbarray['id']; } function caststruc($user) { //loop search village user - $query = mysqli_query($this->connection, "SELECT * FROM ".TB_PREFIX."vdata WHERE owner = ".$user.""); - while($villaggi_array = mysqli_fetch_array($query, MYSQLI_BOTH)) + $query = mysqli_query("SELECT * FROM ".TB_PREFIX."vdata WHERE owner = ".$user.""); + while($villaggi_array = mysqli_fetch_array($query)) //loop structure village - $query1 = mysqli_query($this->connection, "SELECT * FROM ".TB_PREFIX."fdata WHERE vref = ".$villaggi_array['wref'].""); - $strutture= mysqli_fetch_array($query1, MYSQLI_BOTH); + $query1 = mysqli_query("SELECT * FROM ".TB_PREFIX."fdata WHERE vref = ".$villaggi_array['wref'].""); + $strutture= mysqli_fetch_array($query1); return $strutture; } - + function removeMeSit($uid, $uid2) { $q = "UPDATE " . TB_PREFIX . "users set sit1 = 0 where id = $uid and sit1 = $uid2"; - mysqli_query($this->connection, $q); + mysqli_query($q, $this->connection); $q2 = "UPDATE " . TB_PREFIX . "users set sit2 = 0 where id = $uid and sit2 = $uid2"; - mysqli_query($this->connection, $q2); + mysqli_query($q2, $this->connection); } - function getUserField($ref, $field, $mode) { - if(!$mode) { - $q = "SELECT $field FROM " . TB_PREFIX . "users where id = '$ref'"; - } else { - $q = "SELECT $field FROM " . TB_PREFIX . "users where username = '$ref'"; - } - $result = mysqli_query($this->connection, $q) or die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error()); - $dbarray = mysqli_fetch_array($result, MYSQLI_BOTH); - return $dbarray[$field]; - } + function getUserField($ref, $field, $mode) { + if(!$mode) { + $q = "SELECT $field FROM " . TB_PREFIX . "users where id = '$ref'"; + } else { + $q = "SELECT $field FROM " . TB_PREFIX . "users where username = '$ref'"; + } + $result = mysqli_query($q, $this->connection) or die(mysql_error()); + if($result) { + $dbarray = mysqli_fetch_array($result); + return $dbarray[$field]; + }elseif($field=="username"){ + return "??"; + }else return 0; + } function getInvitedUser($uid) { $q = "SELECT * FROM " . TB_PREFIX . "users where invited = $uid order by regtime desc"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } function getVrefField($ref, $field){ $q = "SELECT $field FROM " . TB_PREFIX . "vdata where wref = '$ref'"; - $result = mysqli_query($this->connection, $q) or die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error()); - $dbarray = mysqli_fetch_array($result, MYSQLI_BOTH); + $result = mysqli_query($q, $this->connection) or die(mysql_error()); + $dbarray = mysqli_fetch_array($result); return $dbarray[$field]; } function getVrefCapital($ref){ $q = "SELECT * FROM " . TB_PREFIX . "vdata where owner = '$ref' and capital = 1"; - $result = mysqli_query($this->connection, $q) or die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error()); - $dbarray = mysqli_fetch_array($result, MYSQLI_BOTH); + $result = mysqli_query($q, $this->connection) or die(mysql_error()); + $dbarray = mysqli_fetch_array($result); return $dbarray; } function getStarvation(){ $q = "SELECT * FROM " . TB_PREFIX . "vdata where starv != 0 and owner != 3"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } + function getUnstarvation(){ + $q = "SELECT * FROM " . TB_PREFIX . "vdata where starv = 0 and starvupdate = 0"; + $result = mysqli_query($q, $this->connection); + return $this->mysqli_fetch_all($result); + } + function getActivateField($ref, $field, $mode) { if(!$mode) { $q = "SELECT $field FROM " . TB_PREFIX . "activate where id = '$ref'"; } else { $q = "SELECT $field FROM " . TB_PREFIX . "activate where username = '$ref'"; } - $result = mysqli_query($this->connection, $q) or die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error()); - $dbarray = mysqli_fetch_array($result, MYSQLI_BOTH); + $result = mysqli_query($q, $this->connection) or die(mysql_error()); + $dbarray = mysqli_fetch_array($result); return $dbarray[$field]; } function login($username, $password) { $q = "SELECT password,sessid FROM " . TB_PREFIX . "users where username = '$username'"; - $result = mysqli_query($this->connection, $q); - $dbarray = mysqli_fetch_array($result, MYSQLI_BOTH); + $result = mysqli_query($q, $this->connection); + $dbarray = mysqli_fetch_array($result); if($dbarray['password'] == md5($password)) { return true; } else { @@ -208,25 +223,25 @@ class MYSQLi_DB { function checkActivate($act) { $q = "SELECT * FROM " . TB_PREFIX . "activate where act = '$act'"; - $result = mysqli_query($this->connection, $q); - $dbarray = mysqli_fetch_array($result, MYSQLI_BOTH); + $result = mysqli_query($q, $this->connection); + $dbarray = mysqli_fetch_array($result); return $dbarray; } function sitterLogin($username, $password) { $q = "SELECT sit1,sit2 FROM " . TB_PREFIX . "users where username = '$username' and access != " . BANNED; - $result = mysqli_query($this->connection, $q); - $dbarray = mysqli_fetch_array($result, MYSQLI_BOTH); + $result = mysqli_query($q, $this->connection); + $dbarray = mysqli_fetch_array($result); if($dbarray['sit1'] != 0) { $q2 = "SELECT password FROM " . TB_PREFIX . "users where id = " . $dbarray['sit1'] . " and access != " . BANNED; - $result2 = mysqli_query($this->connection, $q2); - $dbarray2 = mysqli_fetch_array($result2, MYSQLI_BOTH); + $result2 = mysqli_query($q2, $this->connection); + $dbarray2 = mysqli_fetch_array($result2); } if($dbarray['sit2'] != 0) { $q3 = "SELECT password FROM " . TB_PREFIX . "users where id = " . $dbarray['sit2'] . " and access != " . BANNED; $result3 = mysqli_query($q3, $this->connection); - $dbarray3 = mysqli_fetch_array($result3, MYSQLI_BOTH); + $dbarray3 = mysqli_fetch_array($result3); } if($dbarray['sit1'] != 0 || $dbarray['sit2'] != 0) { if($dbarray2['password'] == md5($password) || $dbarray3['password'] == md5($password)) { @@ -246,13 +261,13 @@ class MYSQLi_DB { } else { $q = "DELETE FROM " . TB_PREFIX . "deleting where uid = $uid"; } - mysqli_query($this->connection, $q); + mysqli_query($q, $this->connection); } function isDeleting($uid) { $q = "SELECT timestamp from " . TB_PREFIX . "deleting where uid = $uid"; - $result = mysqli_query($this->connection, $q); - $dbarray = mysqli_fetch_array($result, MYSQLI_BOTH); + $result = mysqli_query($q, $this->connection); + $dbarray = mysqli_fetch_array($result); return $dbarray['timestamp']; } @@ -262,7 +277,7 @@ class MYSQLi_DB { } else { $q = "UPDATE " . TB_PREFIX . "users set gold = gold + $amt where id = $userid"; } - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } /***************************************** @@ -278,8 +293,8 @@ class MYSQLi_DB { } else { $q = "SELECT * FROM " . TB_PREFIX . "users where id = $ref"; } - $result = mysqli_query($this->connection, $q); - return mysqli_fetch_array($result, MYSQLI_BOTH); + $result = mysqli_query($q, $this->connection); + return mysqli_fetch_array($result); } function activeModify($username, $mode) { @@ -289,12 +304,12 @@ class MYSQLi_DB { } else { $q = "DELETE FROM " . TB_PREFIX . "active where username = '$username'"; } - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function addActiveUser($username, $time) { $q = "REPLACE into " . TB_PREFIX . "active values ('$username',$time)"; - if(mysqli_query($this->connection, $q)) { + if(mysqli_query($q, $this->connection)) { return true; } else { return false; @@ -304,8 +319,8 @@ class MYSQLi_DB { function updateActiveUser($username, $time) { $q = "REPLACE into " . TB_PREFIX . "active values ('$username',$time)"; $q2 = "UPDATE " . TB_PREFIX . "users set timestamp = $time where username = '$username'"; - $exec1 = mysqli_query($this->connection, $q); - $exec2 = mysqli_query($this->connection, $q2); + $exec1 = mysqli_query($q, $this->connection); + $exec2 = mysqli_query($q2, $this->connection); if($exec1 && $exec2) { return true; } else { @@ -315,8 +330,8 @@ class MYSQLi_DB { function checkactiveSession($username, $sessid) { $q = "SELECT username FROM " . TB_PREFIX . "users where username = '$username' and sessid = '$sessid' LIMIT 1"; - $result = mysqli_query($this->connection, $q); - if(mysqli_num_rows($result) != 0) { + $result = mysqli_query($q, $this->connection); + if(mysql_num_rows($result) != 0) { return true; } else { return false; @@ -325,18 +340,18 @@ class MYSQLi_DB { function submitProfile($uid, $gender, $location, $birthday, $des1, $des2) { $q = "UPDATE " . TB_PREFIX . "users set gender = $gender, location = '$location', birthday = '$birthday', desc1 = '$des1', desc2 = '$des2' where id = $uid"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function gpack($uid, $gpack) { $q = "UPDATE " . TB_PREFIX . "users set gpack = '$gpack' where id = $uid"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function GetOnline($uid) { $q = "SELECT sit FROM " . TB_PREFIX . "online where uid = $uid"; - $result = mysqli_query($this->connection, $q); - $dbarray = mysqli_fetch_array($result, MYSQLI_BOTH); + $result = mysqli_query($q, $this->connection); + $dbarray = mysqli_fetch_array($result); return $dbarray['sit']; } @@ -344,41 +359,66 @@ class MYSQLi_DB { global $session; if($mode == "login") { $q = "INSERT IGNORE INTO " . TB_PREFIX . "online (name, uid, time, sit) VALUES ('$name', '$uid', " . time() . ", 0)"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } else if($mode == "sitter") { $q = "INSERT IGNORE INTO " . TB_PREFIX . "online (name, uid, time, sit) VALUES ('$name', '$uid', " . time() . ", 1)"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } else { $q = "DELETE FROM " . TB_PREFIX . "online WHERE name ='" . addslashes($session->username) . "'"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } } - - function generateBase($sector) { - switch($sector) { - case 1: - $q = "Select * from ".TB_PREFIX."wdata where fieldtype = 3 and x < 0 and y > 0 and occupied = 0"; - break; - case 2: - $q = "Select * from ".TB_PREFIX."wdata where fieldtype = 3 and x > 0 and y > 0 and occupied = 0"; - break; - case 3: - $q = "Select * from ".TB_PREFIX."wdata where fieldtype = 3 and x < 0 and y < 0 and occupied = 0"; - break; - case 4: - $q = "Select * from ".TB_PREFIX."wdata where fieldtype = 3 and x > 0 and y < 0 and occupied = 0"; - break; - } - $result = mysqli_query($this->connection, $q); - $num_rows = mysqli_num_rows($result); - $result = $this->mysqli_fetch_all($result); - $base = rand(0, ($num_rows-1)); - return $result[$base]['id']; - } + + function generateBase($sector, $mode=1) { + $num_rows = 0; + $count_while = 0; + while (!$num_rows){ + if (!$mode) { + $gamesday=time()-COMMENCE; + if ($gamesday<3600*24*10 && $count_while==0) { //10 day + $wide1=1; + $wide2=20; + } elseif ($gamesday<3600*24*20 && $count_while==1) { //20 day + $wide1=20; + $wide2=40; + } elseif ($gamesday<3600*24*30 && $count_while==2) { //30 day + $wide1=40; + $wide2=80; + } else { // over 30 day + $wide1=80; + $wide2=WORLD_MAX; + } + } + else { + $wide1=1; + $wide2=WORLD_MAX; + } + switch($sector) { + case 1: + $q = "Select * from ".TB_PREFIX."wdata where fieldtype = 3 and (x < -$wide1 and x > -$wide2) and (y > $wide1 and y < $wide2) and occupied = 0"; //x- y+ + break; + case 2: + $q = "Select * from ".TB_PREFIX."wdata where fieldtype = 3 and (x > $wide1 and x < $wide2) and (y > $wide1 and y < $wide2) and occupied = 0"; //x+ y+ + break; + case 3: + $q = "Select * from ".TB_PREFIX."wdata where fieldtype = 3 and (x < -$wide1 and x > -$wide2) and (y < -$wide1 and y > -$wide2) and occupied = 0"; //x- y- + break; + case 4: + $q = "Select * from ".TB_PREFIX."wdata where fieldtype = 3 and (x > $wide1 and x < $wide2) and (y < -$wide1 and y > -$wide2) and occupied = 0"; //x+ y- + break; + } + $result = mysqli_query($q, $this->connection); + $num_rows = mysql_num_rows($result); + $count_while++; + } + $result = $this->mysqli_fetch_all($result); + $base = rand(0, ($num_rows-1)); + return $result[$base]['id']; + } function setFieldTaken($id) { $q = "UPDATE " . TB_PREFIX . "wdata set occupied = 1 where id = $id"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function addVillage($wid, $uid, $username, $capital) { @@ -390,7 +430,7 @@ class MYSQLi_DB { } $time = time(); $q = "INSERT into " . TB_PREFIX . "vdata (wref, owner, name, capital, pop, cp, celebration, wood, clay, iron, maxstore, crop, maxcrop, lastupdate, created) values ('$wid', '$uid', '$vname', '$capital', 2, 1, 0, 750, 750, 750, ".STORAGE_BASE.", 750, ".STORAGE_BASE.", '$time', '$time')"; - return mysqli_query($this->connection, $q) or die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error()); + return mysqli_query($q, $this->connection) or die(mysql_error()); } function addResourceFields($vid, $type) { @@ -432,19 +472,21 @@ class MYSQLi_DB { $q = "INSERT into " . TB_PREFIX . "fdata (vref,f1t,f2t,f3t,f4t,f5t,f6t,f7t,f8t,f9t,f10t,f11t,f12t,f13t,f14t,f15t,f16t,f17t,f18t,f26,f26t) values($vid,1,4,1,1,2,2,3,4,4,3,3,4,4,1,4,2,1,2,1,15)"; break; } - return mysqli_query($this->connection, $q); - } - function isVillageOases($wref) { - $q = "SELECT id, oasistype FROM " . TB_PREFIX . "wdata where id = $wref"; - $result = mysqli_query($this->connection, $q); - $dbarray = mysqli_fetch_array($result, MYSQLI_BOTH); - return $dbarray['oasistype']; + return mysqli_query($q, $this->connection); } + function isVillageOases($wref) { + $q = "SELECT id, oasistype FROM " . TB_PREFIX . "wdata where id = $wref"; + $result = mysqli_query($q, $this->connection); + if($result){ + $dbarray = mysqli_fetch_array($result); + return $dbarray['oasistype']; + }else return 0; + } public function VillageOasisCount($vref) { $q = "SELECT count(*) FROM `".TB_PREFIX."odata` WHERE conqured=$vref"; - $result = mysqli_query($this->connection, $q); - $row = mysqli_fetch_row($result); + $result = mysqli_query($q, $this->connection); + $row = mysql_fetch_row($result); return $row[0]; } @@ -452,7 +494,7 @@ class MYSQLi_DB { //count oasis troops: $troops_o $troops_o=0; $o_unit2=mysqli_query("select * from ".TB_PREFIX."units where `vref`='".$vref."'"); - $o_unit=mysqli_fetch_array($o_unit2, MYSQLI_BOTH); + $o_unit=mysqli_fetch_array($o_unit2); for ($i=1;$i<51;$i++) { @@ -461,7 +503,7 @@ class MYSQLi_DB { $troops_o+=$o_unit['hero']; $o_unit2=mysqli_query("select * from ".TB_PREFIX."enforcement where `vref`='".$vref."'"); - while ($o_unit=@mysqil_fetch_array($o_unit2, MYSQLI_BOTH)) + while ($o_unit=@mysqli_fetch_array($o_unit2)) { for ($i=1;$i<51;$i++) { @@ -472,61 +514,60 @@ class MYSQLi_DB { return $troops_o; } - public function canConquerOasis($vref,$wref) { - $AttackerFields = $this->getResourceLevel($vref); - for($i=19;$i<=38;$i++) { - if($AttackerFields['f'.$i.'t'] == 37) { $HeroMansionLevel = $AttackerFields['f'.$i]; } - } - if($this->VillageOasisCount($vref) < floor(($HeroMansionLevel-5)/5)) { - $OasisInfo = $this->getOasisInfo($wref); - $troopcount = $this->countOasisTroops($wref); - if($OasisInfo['conqured'] == 0 || $OasisInfo['conqured'] != 0 && $OasisInfo['loyalty'] < 99 / min(3,(4-$this->VillageOasisCount($OasisInfo['conqured']))) && $troopcount == 0) { - $CoordsVillage = $this->getCoor($vref); - $CoordsOasis = $this->getCoor($wref); - $max = 2 * WORLD_MAX + 1; - $x1 = intval($CoordsOasis['x']); - $y1 = intval($CoordsOasis['y']); - $x2 = intval($CoordsVillage['x']); - $y2 = intval($CoordsVillage['y']); - $distanceX = min(abs($x2 - $x1), abs($max - abs($x2 - $x1))); - $distanceY = min(abs($y2 - $y1), abs($max - abs($y2 - $y1))); - if ($distanceX<=3 && $distanceY<=3) { - return True; - } else { - return False; - } - } else { - return False; - } - } else { - return False; - } - } - - + public function canConquerOasis($vref,$wref) { + $AttackerFields = $this->getResourceLevel($vref); + for($i=19;$i<=38;$i++) { + if($AttackerFields['f'.$i.'t'] == 37) { $HeroMansionLevel = $AttackerFields['f'.$i]; } + } + if($this->VillageOasisCount($vref) < floor(($HeroMansionLevel-5)/5)) { + $OasisInfo = $this->getOasisInfo($wref); + //fix by ronix + if($OasisInfo['conqured'] == 0 || $OasisInfo['conqured'] != 0 && intval($OasisInfo['loyalty']) < 99 / min(3,(4-$this->VillageOasisCount($OasisInfo['conqured'])))){ + $CoordsVillage = $this->getCoor($vref); + $CoordsOasis = $this->getCoor($wref); + $max = 2 * WORLD_MAX + 1; + $x1 = intval($CoordsOasis['x']); + $y1 = intval($CoordsOasis['y']); + $x2 = intval($CoordsVillage['x']); + $y2 = intval($CoordsVillage['y']); + $distanceX = min(abs($x2 - $x1), abs($max - abs($x2 - $x1))); + $distanceY = min(abs($y2 - $y1), abs($max - abs($y2 - $y1))); + if ($distanceX<=3 && $distanceY<=3) { + return 1; //can + } else { + return 2; //can but not in 7x7 field + } + } else { + return 3; //loyalty >0 + } + } else { + return 0; //req level hero mansion + } + } public function conquerOasis($vref,$wref) { $vinfo = $this->getVillage($vref); $uid = $vinfo['owner']; $q = "UPDATE `".TB_PREFIX."odata` SET conqured=$vref,loyalty=100,lastupdated=".time().",owner=$uid,name='Occupied Oasis' WHERE wref=$wref"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } - public function modifyOasisLoyalty($wref) { - if($this->isVillageOases($wref) != 0) { - $OasisInfo = $this->getOasisInfo($wref); - if($OasisInfo['conqured'] != 0) { - $LoyaltyAmendment = floor(100 / min(3,(4-$this->VillageOasisCount($OasisInfo['conqured'])))); - $q = "UPDATE `".TB_PREFIX."odata` SET loyalty=loyalty-$LoyaltyAmendment WHERE wref=$wref"; - return mysqli_query($this->connection, $q); - } - } - } + public function modifyOasisLoyalty($wref) { + if($this->isVillageOases($wref) != 0) { + $OasisInfo = $this->getOasisInfo($wref); + if($OasisInfo['conqured'] != 0) { + $LoyaltyAmendment = floor(100 / min(3,(4-$this->VillageOasisCount($OasisInfo['conqured'])))); + $q = "UPDATE `".TB_PREFIX."odata` SET loyalty=loyalty-$LoyaltyAmendment, lastupdated=".time()." WHERE wref=$wref"; + $result=mysqli_query($q, $this->connection); + return $OasisInfo['loyalty']-$LoyaltyAmendment; + } + } + } function populateOasis() { $q = "SELECT * FROM " . TB_PREFIX . "wdata where oasistype != 0"; - $result = mysqli_query($this->connection, $q); - while($row = mysqli_fetch_array($result, MYSQLI_BOTH)) { + $result = mysqli_query($q, $this->connection); + while($row = mysqli_fetch_array($result)) { $wid = $row['id']; $this->addUnits($wid); @@ -539,113 +580,113 @@ class MYSQLi_DB { if($high == 0){ $max = rand(15,30); }elseif($high == 1){ - $max = rand(50,70); - }elseif($high == 2){ - $max = rand(90,120); - } - $max2 = 0; - $rand = rand(0,3); - if($rand == 1){ - $max2 = 3; + $max = rand(50,70); + }elseif($high == 2){ + $max = rand(90,120); + } + $max2 = 0; + $rand = rand(0,3); + if($rand == 1){ + $max2 = 3; } //each Troop is a Set for oasis type like mountains have rats spiders and snakes fields tigers elphants clay wolves so on stonger one more not so less switch($basearray['type']) { case 1: case 2: //+25% lumber per hour - $q = "UPDATE " . TB_PREFIX . "units SET u35 = u35 + '".rand(0,5)."', u36 = u36 + '".rand(0,5)."', u37 = u37 + '".rand(0,5)."' WHERE vref = '" . $wid . "' AND (u36 <= ".$max." OR u37 <= ".$max.")"; - $result = mysqli_query($this->connection, $q); + $q = "UPDATE " . TB_PREFIX . "units SET u35 = u35 + '".rand(0,5)."', u36 = u36 + '".rand(0,5)."', u37 = u37 + '".rand(0,5)."' WHERE vref = '" . $wid . "' AND (u35 <= ".$max." OR u36 <= ".$max." OR u37 <= ".$max.")"; + $result = mysqli_query($q, $this->connection); break; case 3: //+25% lumber and +25% crop per hour $q = "UPDATE " . TB_PREFIX . "units SET u35 = u35 + '".rand(0,5)."', u36 = u36 + '".rand(0,5)."', u37 = u37 + '".rand(0,5)."', u38 = u38 + '".rand(0,5)."', u40 = u40 + '".rand(0,$max2)."' WHERE vref = '" . $wid . "' AND (u36 <= ".$max." OR u37 <= ".$max." OR u38 <= ".$max.")"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); break; case 4: case 5: //+25% clay per hour - $q = "UPDATE " . TB_PREFIX . "units SET u36 = u36 + '".rand(0,5)."', u37 = u37 + '".rand(0,5)."' WHERE vref = '" . $wid . "' AND (u36 <= ".$max." OR u37 <= ".$max.")"; - $result = mysqli_query($this->connection, $q); + $q = "UPDATE " . TB_PREFIX . "units SET u31 = u31 + '".rand(0,5)."', u32 = u32 + '".rand(0,5)."', u35 = u35 + '".rand(0,5)."' WHERE vref = '" . $wid . "' AND (u31 <= ".$max." OR u32 <= ".$max." OR u35 <= ".$max.")"; + $result = mysqli_query($q, $this->connection); break; case 6: //+25% clay and +25% crop per hour - $q = "UPDATE " . TB_PREFIX . "units SET u36 = u36 + '".rand(0,5)."', u37 = u37 + '".rand(0,5)."', u38 = u38 + '".rand(0,5)."', u40 = u40 + '".rand(0,$max2)."' WHERE vref = '" . $wid . "' AND (u36 <= ".$max." OR u37 <= ".$max." OR u38 <= ".$max.")"; - $result = mysqli_query($this->connection, $q); + $q = "UPDATE " . TB_PREFIX . "units SET u31 = u31 + '".rand(0,5)."', u32 = u32 + '".rand(0,5)."', u35 = u35 + '".rand(0,5)."', u40 = u40 + '".rand(0,$max2)."' WHERE vref = '" . $wid . "' AND (u31 <= ".$max." OR u32 <= ".$max." OR u35 <= ".$max.")"; + $result = mysqli_query($q, $this->connection); break; case 7: case 8: //+25% iron per hour - $q = "UPDATE " . TB_PREFIX . "units SET u31 = u31 + '".rand(0,5)."', u32 = u32 + '".rand(0,5)."', u34 = u34 + '".rand(0,5)."' WHERE vref = '" . $wid . "' AND (u31 <= ".$max." OR u32 <= ".$max.")"; - $result = mysqli_query($this->connection, $q); + $q = "UPDATE " . TB_PREFIX . "units SET u31 = u31 + '".rand(0,5)."', u32 = u32 + '".rand(0,5)."', u34 = u34 + '".rand(0,5)."' WHERE vref = '" . $wid . "' AND (u31 <= ".$max." OR u32 <= ".$max." OR u34 <= ".$max.")"; + $result = mysqli_query($q, $this->connection); break; case 9: //+25% iron and +25% crop - $q = "UPDATE " . TB_PREFIX . "units SET u31 = u31 + '".rand(0,5)."', u32 = u32 + '".rand(0,5)."', u34 = u34 + '".rand(0,5)."', u40 = u40 + '".rand(0,$max2)."' WHERE vref = '" . $wid . "' AND (u31 <= ".$max." OR u32 <= ".$max." OR u34 <= ".$max.")"; - $result = mysqli_query($this->connection, $q); + $q = "UPDATE " . TB_PREFIX . "units SET u31 = u31 + '".rand(0,5)."', u32 = u32 + '".rand(0,5)."', u34 = u34 + '".rand(0,5)."', u39 = u39 + '".rand(0,$max2)."' WHERE vref = '" . $wid . "' AND (u31 <= ".$max." OR u32 <= ".$max." OR u34 <= ".$max.")"; + $result = mysqli_query($q, $this->connection); break; case 10: case 11: //+25% crop per hour - $q = "UPDATE " . TB_PREFIX . "units SET u33 = u33 + '".rand(0,5)."', u37 = u37 + '".rand(0,5)."', u38 = u38 + '".rand(0,5)."' WHERE vref = '" . $wid . "' AND (u33 <= ".$max." OR u37 <= ".$max." OR u38 <= ".$max.")"; - $result = mysqli_query($this->connection, $q); + $q = "UPDATE " . TB_PREFIX . "units SET u33 = u33 + '".rand(0,5)."', u37 = u37 + '".rand(0,5)."', u38 = u38 + '".rand(0,5)."', u39 = u39 + '".rand(0,$max2)."' WHERE vref = '" . $wid . "' AND (u33 <= ".$max." OR u37 <= ".$max." OR u38 <= ".$max.")"; + $result = mysqli_query($q, $this->connection); break; case 12: //+50% crop per hour $q = "UPDATE " . TB_PREFIX . "units SET u33 = u33 + '".rand(0,5)."', u37 = u37 + '".rand(0,5)."', u38 = u38 + '".rand(0,5)."', u39 = u39 + '".rand(0,5)."', u40 = u40 + '".rand(0,$max2)."' WHERE vref = '" . $wid . "' AND (u33 <= ".$max." OR u37 <= ".$max." OR u38 <= ".$max." OR u39 <= ".$max.")"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); break; - } - } + } + } function populateOasisUnits2() { $q2 = "SELECT * FROM " . TB_PREFIX . "wdata where oasistype != 0"; - $result2 = mysqli_query($this->connection, $q2); - while($row = mysqli_fetch_array($result2, MYSQLI_BOTH)) { + $result2 = mysqli_query($q2, $this->connection); + while($row = mysqli_fetch_array($result2)) { $wid = $row['id']; switch($row['oasistype']) { case 1: case 2: //+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'"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); break; case 3: //+25% lumber 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'"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); break; case 4: case 5: //+25% clay oasis $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->connection, $q); + $result = mysqli_query($q, $this->connection); break; case 6: //+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'"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); break; case 7: case 8: //+25% iron oasis $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'"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); 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->connection, $q); + $result = mysqli_query($q, $this->connection); 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->connection, $q); + $result = mysqli_query($q, $this->connection); 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->connection, $q); + $result = mysqli_query($q, $this->connection); break; } } @@ -653,7 +694,7 @@ class MYSQLi_DB { function removeOases($wref) { $q = "UPDATE ".TB_PREFIX."odata SET conqured = 0, owner = 2, name = 'Unoccupied Oasis' WHERE wref = $wref"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } @@ -663,8 +704,8 @@ class MYSQLi_DB { ***************************/ function getVillageType($wref) { $q = "SELECT id, fieldtype FROM " . TB_PREFIX . "wdata where id = $wref"; - $result = mysqli_query($this->connection, $q); - $dbarray = mysqli_fetch_array($result, MYSQLI_BOTH); + $result = mysqli_query($q, $this->connection); + $dbarray = mysqli_fetch_array($result); return $dbarray['fieldtype']; } @@ -676,8 +717,8 @@ class MYSQLi_DB { *****************************************/ function getVillageState($wref) { $q = "SELECT oasistype,occupied FROM " . TB_PREFIX . "wdata where id = $wref"; - $result = mysqli_query($this->connection, $q); - $dbarray = mysqli_fetch_array($result, MYSQLI_BOTH); + $result = mysqli_query($q, $this->connection); + $dbarray = mysqli_fetch_array($result); if($dbarray['occupied'] != 0 || $dbarray['oasistype'] != 0) { return true; } else { @@ -687,35 +728,35 @@ class MYSQLi_DB { function getProfileVillages($uid) { $q = "SELECT capital,wref,name,pop,created from " . TB_PREFIX . "vdata where owner = $uid order by pop desc"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } function getProfileMedal($uid) { $q = "SELECT id,categorie,plaats,week,img,points from " . TB_PREFIX . "medal where userid = $uid and del = 0 order by id desc"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } function getProfileMedalAlly($uid) { $q = "SELECT id,categorie,plaats,week,img,points from " . TB_PREFIX . "allimedal where allyid = $uid and del = 0 order by id desc"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } function getVillageID($uid) { $q = "SELECT wref FROM " . TB_PREFIX . "vdata WHERE owner = $uid"; - $result = mysqli_query($this->connection, $q); - $dbarray = mysqli_fetch_array($result, MYSQLI_BOTH); + $result = mysqli_query($q, $this->connection); + $dbarray = mysqli_fetch_array($result); return $dbarray['wref']; } function getVillagesID($uid) { $q = "SELECT wref from " . TB_PREFIX . "vdata where owner = $uid order by capital DESC,pop DESC"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); $array = $this->mysqli_fetch_all($result); $newarray = array(); for($i = 0; $i < count($array); $i++) { @@ -726,109 +767,130 @@ class MYSQLi_DB { function getVillagesID2($uid) { $q = "SELECT wref from " . TB_PREFIX . "vdata where owner = $uid order by capital DESC,pop DESC"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); $array = $this->mysqli_fetch_all($result); return $array; } function getVillage($vid) { $q = "SELECT * FROM " . TB_PREFIX . "vdata where wref = $vid"; - $result = mysqli_query($this->connection, $q); - return mysqli_fetch_array($result, MYSQLI_BOTH); + $result = mysqli_query($q, $this->connection); + return mysqli_fetch_array($result); } public function getVillageBattleData($vid) { $q = "SELECT u.id,u.tribe,v.capital,f.f40 AS wall FROM ".TB_PREFIX."users u,".TB_PREFIX."fdata f,".TB_PREFIX."vdata v WHERE u.id=v.owner AND f.vref=v.wref AND v.wref=".$vid; - $result = mysqli_query($this->connection, $q); - return mysqli_fetch_array($result, MYSQLI_BOTH); + $result = mysqli_query($q, $this->connection); + return mysqli_fetch_array($result); } public function getPopulation($uid) { $q = "SELECT sum(pop) AS pop FROM ".TB_PREFIX."vdata WHERE owner=".$uid; - $result = mysqli_query($this->connection, $q); - $dbarray = mysqli_fetch_array($result, MYSQLI_BOTH); + $result = mysqli_query($q, $this->connection); + $dbarray = mysqli_fetch_array($result); return $dbarray['pop']; } function getOasisV($vid) { $q = "SELECT * FROM " . TB_PREFIX . "odata where wref = $vid"; - $result = mysqli_query($this->connection, $q); - return mysqli_fetch_array($result, MYSQLI_BOTH); + $result = mysqli_query($q, $this->connection); + return mysqli_fetch_array($result); } function getMInfo($id) { $q = "SELECT * FROM " . TB_PREFIX . "wdata left JOIN " . TB_PREFIX . "vdata ON " . TB_PREFIX . "vdata.wref = " . TB_PREFIX . "wdata.id where " . TB_PREFIX . "wdata.id = $id"; - $result = mysqli_query($this->connection, $q); - return mysqli_fetch_array($result, MYSQLI_BOTH); + $result = mysqli_query($q, $this->connection); + return mysqli_fetch_array($result); } function getOMInfo($id) { $q = "SELECT * FROM " . TB_PREFIX . "wdata left JOIN " . TB_PREFIX . "odata ON " . TB_PREFIX . "odata.wref = " . TB_PREFIX . "wdata.id where " . TB_PREFIX . "wdata.id = $id"; - $result = mysqli_query($this->connection, $q); - return mysqli_fetch_array($result, MYSQLI_BOTH); + $result = mysqli_query($q, $this->connection); + return mysqli_fetch_array($result); } function getOasis($vid) { $q = "SELECT * FROM " . TB_PREFIX . "odata where conqured = $vid"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } function getOasisInfo($wid) { $q = "SELECT * FROM " . TB_PREFIX . "odata where wref = $wid"; - $result = mysqli_query($this->connection, $q); - return mysqli_fetch_assoc($result); + $result = mysqli_query($q, $this->connection); + return mysql_fetch_assoc($result); } - function getVillageField($ref, $field) { - $q = "SELECT $field FROM " . TB_PREFIX . "vdata where wref = $ref"; - $result = mysqli_query($this->connection, $q); - $dbarray = mysqli_fetch_array($result, MYSQLI_BOTH); - return $dbarray[$field]; - - } + function getVillageField($ref, $field) { + $q = "SELECT $field FROM " . TB_PREFIX . "vdata where wref = $ref"; + $result = mysqli_query($q, $this->connection); + if($result){ + $dbarray = mysqli_fetch_array($result); + return $dbarray[$field]; + }elseif($field=="name"){ + return "??"; + }else return 0; + } function getOasisField($ref, $field) { $q = "SELECT $field FROM " . TB_PREFIX . "odata where wref = $ref"; - $result = mysqli_query($this->connection, $q); - $dbarray = mysqli_fetch_array($result, MYSQLI_BOTH); + $result = mysqli_query($q, $this->connection); + $dbarray = mysqli_fetch_array($result); return $dbarray[$field]; } function setVillageField($ref, $field, $value) { $q = "UPDATE " . TB_PREFIX . "vdata set $field = '$value' where wref = $ref"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function setVillageLevel($ref, $field, $value) { $q = "UPDATE " . TB_PREFIX . "fdata set " . $field . " = '" . $value . "' where vref = " . $ref . ""; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function getResourceLevel($vid) { $q = "SELECT * from " . TB_PREFIX . "fdata where vref = $vid"; - $result = mysqli_query($this->connection, $q); - return mysqli_fetch_assoc($result); + $result = mysqli_query($q, $this->connection); + return mysql_fetch_assoc($result); } function getAdminLog() { $q = "SELECT id,user,log,time from " . TB_PREFIX . "admin_log where id != 0 ORDER BY id ASC"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } + //fix market log + function getMarketLog() { + $q = "SELECT id,wid,log from " . TB_PREFIX . "market_log where id != 0 ORDER BY id ASC"; + $result = mysqli_query($q, $this->connection); + return $this->mysqli_fetch_all($result); + } + function getMarketLogVillage($village) { + $q = "SELECT wref,owner,name from " . TB_PREFIX . "vdata where wref =$village "; + $result = mysqli_query($q, $this->connection); + return $this->mysqli_fetch_all($result); + } + function getMarketLogUsers($id_user) { + $q = "SELECT id,username from " . TB_PREFIX . "users where id =$id_user "; + $result = mysqli_query($q, $this->connection); + return $this->mysqli_fetch_all($result); + } + //end fix + function getCoor($wref) { if ($wref !=""){ $q = "SELECT x,y FROM " . TB_PREFIX . "wdata where id = $wref"; - $result = mysqli_query($this->connection, $q); - return mysqli_fetch_array($result, MYSQLI_BOTH); + $result = mysqli_query($q, $this->connection); + return mysqli_fetch_array($result); } } function CheckForum($id) { $q = "SELECT * from " . TB_PREFIX . "forum_cat where alliance = '$id'"; - $result = mysqli_query($this->connection, $q); - if(mysqli_num_rows($result)) { + $result = mysqli_query($q, $this->connection); + if(mysql_num_rows($result)) { return true; } else { return false; @@ -837,21 +899,21 @@ class MYSQLi_DB { function CountCat($id) { $q = "SELECT count(id) FROM " . TB_PREFIX . "forum_topic where cat = '$id'"; - $result = mysqli_query($this->connection, $q); - $row = mysqli_fetch_row($result); + $result = mysqli_query($q, $this->connection); + $row = mysql_fetch_row($result); return $row[0]; } function LastTopic($id) { $q = "SELECT * from " . TB_PREFIX . "forum_topic where cat = '$id' order by post_date"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } function CheckLastTopic($id) { $q = "SELECT * from " . TB_PREFIX . "forum_topic where cat = '$id'"; - $result = mysqli_query($this->connection, $q); - if(mysqli_num_rows($result)) { + $result = mysqli_query($q, $this->connection); + if(mysql_num_rows($result)) { return true; } else { return false; @@ -860,8 +922,8 @@ class MYSQLi_DB { function CheckLastPost($id) { $q = "SELECT * from " . TB_PREFIX . "forum_post where topic = '$id'"; - $result = mysqli_query($this->connection, $q); - if(mysqli_num_rows($result)) { + $result = mysqli_query($q, $this->connection); + if(mysql_num_rows($result)) { return true; } else { return false; @@ -870,58 +932,58 @@ class MYSQLi_DB { function LastPost($id) { $q = "SELECT * from " . TB_PREFIX . "forum_post where topic = '$id'"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } function CountTopic($id) { $q = "SELECT count(id) FROM " . TB_PREFIX . "forum_post where owner = '$id'"; - $result = mysqli_query($this->connection, $q); - $row = mysqli_fetch_row($result); + $result = mysqli_query($q, $this->connection); + $row = mysql_fetch_row($result); $qs = "SELECT count(id) FROM " . TB_PREFIX . "forum_topic where owner = '$id'"; $results = mysqli_query($qs, $this->connection); - $rows = mysqli_fetch_row($results); + $rows = mysql_fetch_row($results); return $row[0] + $rows[0]; } function CountPost($id) { $q = "SELECT count(id) FROM " . TB_PREFIX . "forum_post where topic = '$id'"; - $result = mysqli_query($this->connection, $q); - $row = mysqli_fetch_row($result); + $result = mysqli_query($q, $this->connection); + $row = mysql_fetch_row($result); return $row[0]; } function ForumCat($id) { $q = "SELECT * from " . TB_PREFIX . "forum_cat where alliance = '$id' ORDER BY id"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } function ForumCatEdit($id) { $q = "SELECT * from " . TB_PREFIX . "forum_cat where id = '$id'"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } function ForumCatAlliance($id) { $q = "SELECT alliance from " . TB_PREFIX . "forum_cat where id = $id"; - $result = mysqli_query($this->connection, $q); - $dbarray = mysqli_fetch_array($result, MYSQLI_BOTH); + $result = mysqli_query($q, $this->connection); + $dbarray = mysqli_fetch_array($result); return $dbarray['alliance']; } function ForumCatName($id) { $q = "SELECT forum_name from " . TB_PREFIX . "forum_cat where id = $id"; - $result = mysqli_query($this->connection, $q); - $dbarray = mysqli_fetch_array($result, MYSQLI_BOTH); + $result = mysqli_query($q, $this->connection); + $dbarray = mysqli_fetch_array($result); return $dbarray['forum_name']; } function CheckCatTopic($id) { $q = "SELECT * from " . TB_PREFIX . "forum_topic where cat = '$id'"; - $result = mysqli_query($this->connection, $q); - if(mysqli_num_rows($result)) { + $result = mysqli_query($q, $this->connection); + if(mysql_num_rows($result)) { return true; } else { return false; @@ -930,8 +992,8 @@ class MYSQLi_DB { function CheckResultEdit($alli) { $q = "SELECT * from " . TB_PREFIX . "forum_edit where alliance = '$alli'"; - $result = mysqli_query($this->connection, $q); - if(mysqli_num_rows($result)) { + $result = mysqli_query($q, $this->connection); + if(mysql_num_rows($result)) { return true; } else { return false; @@ -940,54 +1002,54 @@ class MYSQLi_DB { function CheckCloseTopic($id) { $q = "SELECT close from " . TB_PREFIX . "forum_topic where id = '$id'"; - $result = mysqli_query($this->connection, $q); - $dbarray = mysqli_fetch_array($result, MYSQLI_BOTH); + $result = mysqli_query($q, $this->connection); + $dbarray = mysqli_fetch_array($result); return $dbarray['close']; } function CheckEditRes($alli) { $q = "SELECT result from " . TB_PREFIX . "forum_edit where alliance = '$alli'"; - $result = mysqli_query($this->connection, $q); - $dbarray = mysqli_fetch_array($result, MYSQLI_BOTH); + $result = mysqli_query($q, $this->connection); + $dbarray = mysqli_fetch_array($result); return $dbarray['result']; } function CreatResultEdit($alli, $result) { $q = "INSERT into " . TB_PREFIX . "forum_edit values (0,'$alli','$result')"; - mysqli_query($this->connection, $q); - return mysqli_insert_id($this->connection); + mysqli_query($q, $this->connection); + return mysql_insert_id($this->connection); } function UpdateResultEdit($alli, $result) { $date = time(); $q = "UPDATE " . TB_PREFIX . "forum_edit set result = '$result' where alliance = '$alli'"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function getVillageType2($wref) { $q = "SELECT * FROM " . TB_PREFIX . "wdata where id = $wref"; - $result = mysqli_query($this->connection, $q); - $dbarray = mysqli_fetch_array($result, MYSQLI_BOTH); + $result = mysqli_query($q, $this->connection); + $dbarray = mysqli_fetch_array($result); return $dbarray['oasistype']; } function getVillageType3($wref) { $q = "SELECT * FROM " . TB_PREFIX . "wdata where id = $wref"; - $result = mysqli_query($this->connection, $q); - $dbarray = mysqli_fetch_array($result, MYSQLI_BOTH); + $result = mysqli_query($q, $this->connection); + $dbarray = mysqli_fetch_array($result); return $dbarray; } function getFLData($id) { $q = "SELECT * FROM " . TB_PREFIX . "farmlist where id = $id"; - $result = mysqli_query($this->connection, $q); - return mysqli_fetch_array($result, MYSQLI_BOTH); + $result = mysqli_query($q, $this->connection); + return mysqli_fetch_array($result); } function checkVilExist($wref) { $q = "SELECT * FROM " . TB_PREFIX . "vdata where wref = '$wref'"; - $result = mysqli_query($this->connection, $q); - if(mysqli_num_rows($result)) { + $result = mysqli_query($q, $this->connection); + if(mysql_num_rows($result)) { return true; } else { return false; @@ -996,8 +1058,8 @@ class MYSQLi_DB { function checkOasisExist($wref) { $q = "SELECT * FROM " . TB_PREFIX . "odata where wref = '$wref'"; - $result = mysqli_query($this->connection, $q); - if(mysqli_num_rows($result)) { + $result = mysqli_query($q, $this->connection); + if(mysql_num_rows($result)) { return true; } else { return false; @@ -1006,145 +1068,167 @@ class MYSQLi_DB { function UpdateEditTopic($id, $title, $cat) { $q = "UPDATE " . TB_PREFIX . "forum_topic set title = '$title', cat = '$cat' where id = $id"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function UpdateEditForum($id, $name, $des) { $q = "UPDATE " . TB_PREFIX . "forum_cat set forum_name = '$name', forum_des = '$des' where id = $id"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function StickTopic($id, $mode) { $q = "UPDATE " . TB_PREFIX . "forum_topic set stick = '$mode' where id = '$id'"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function ForumCatTopic($id) { $q = "SELECT * from " . TB_PREFIX . "forum_topic where cat = '$id' AND stick = '' ORDER BY post_date desc"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } function ForumCatTopicStick($id) { $q = "SELECT * from " . TB_PREFIX . "forum_topic where cat = '$id' AND stick = '1' ORDER BY post_date desc"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } function ShowTopic($id) { $q = "SELECT * from " . TB_PREFIX . "forum_topic where id = '$id'"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } function ShowPost($id) { $q = "SELECT * from " . TB_PREFIX . "forum_post where topic = '$id'"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } function ShowPostEdit($id) { $q = "SELECT * from " . TB_PREFIX . "forum_post where id = '$id'"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } function CreatForum($owner, $alli, $name, $des, $area) { $q = "INSERT into " . TB_PREFIX . "forum_cat values (0,'$owner','$alli','$name','$des','$area')"; - mysqli_query($this->connection, $q); - return mysqli_insert_id($this->connection); + mysqli_query($q, $this->connection); + return mysql_insert_id($this->connection); } function CreatTopic($title, $post, $cat, $owner, $alli, $ends, $alliance, $player, $coor, $report) { $date = time(); $q = "INSERT into " . TB_PREFIX . "forum_topic values (0,'$title','$post','$date','$date','$cat','$owner','$alli','$ends','','','$alliance','$player','$coor','$report')"; - mysqli_query($this->connection, $q); - return mysqli_insert_id($this->connection); + mysqli_query($q, $this->connection); + return mysql_insert_id($this->connection); } - function createSurvey($topic, $title, $option1, $option2, $option3, $option4, $option5, $option6, $option7, $option8, $ends) { + /************************* + FORUM SUREY + *************************/ + + function createSurvey($topic, $title, $option1, $option2, $option3, $option4, $option5, $option6, $option7, $option8, $ends) { $q = "INSERT into " . TB_PREFIX . "forum_survey (topic,title,option1,option2,option3,option4,option5,option6,option7,option8,ends) values ('$topic','$title','$option1','$option2','$option3','$option4','$option5','$option6','$option7','$option8','$ends')"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } - function getSurvey($topic) { - $q = "SELECT * FROM " . TB_PREFIX . "forum_survey where topic = $topic"; - $result = mysql_query($q, $this->connection); - return mysqli_fetch_array($result); - } + function getSurvey($topic) { + $q = "SELECT * FROM " . TB_PREFIX . "forum_survey where topic = $topic"; + $result = mysqli_query($q, $this->connection); + return mysqli_fetch_array($result); + } - function checkSurvey($topic) { + function checkSurvey($topic) { + $q = "SELECT * FROM " . TB_PREFIX . "forum_survey where topic = $topic"; + $result = mysqli_query($q, $this->connection); + if(mysql_num_rows($result)) { + return true; + } else { + return false; + } + } + + function Vote($topic, $num, $text) { + $q = "UPDATE " . TB_PREFIX . "forum_survey set vote".$num." = vote".$num." + 1, voted = '$text' where topic = ".$topic.""; + return mysqli_query($q, $this->connection); + } + + function checkVote($topic, $uid) { $q = "SELECT * FROM " . TB_PREFIX . "forum_survey where topic = $topic"; - $result = mysqli_query($this->connection, $q); - if(mysqli_num_rows($result)) { - return true; - } else { - return false; - } + $result = mysqli_query($q, $this->connection); + $array = mysqli_fetch_array($result); + $text = $array['voted']; + if(preg_match('/,'.$uid.',/',$text)) { + return true; + } else { + return false; + } } - function Vote($topic, $num, $text) { - $q = "UPDATE " . TB_PREFIX . "forum_survey set vote".$num." = vote".$num." + 1, voted = '$text' where topic = ".$topic.""; - return mysqli_query($this->connection, $q); - } - - function checkVote($topic, $uid) { + function getVoteSum($topic) { $q = "SELECT * FROM " . TB_PREFIX . "forum_survey where topic = $topic"; - $result = mysqli_query($this->connection, $q); - $array = mysqli_fetch_array($result); - $text = $array['voted']; - if(preg_match('/,'.$uid.',/',$text)) { - return true; - } else { - return false; - } + $result = mysqli_query($q, $this->connection); + $array = mysqli_fetch_array($result); + $sum = 0; + for($i=1;$i<=8;$i++){ + $sum += $array['vote'.$i]; } + return $sum; + } - function getVoteSum($topic) { - $q = "SELECT * FROM " . TB_PREFIX . "forum_survey where topic = $topic"; - $result = mysqli_query($this->connection, $q); - $array = mysqli_fetch_array($result); - $sum = 0; - for($i=1;$i<=8;$i++){ - $sum += $array['vote'.$i]; - } - return $sum; - } + + /************************* + FORUM SUREY + *************************/ function CreatPost($post, $tids, $owner, $alliance, $player, $coor, $report) { $date = time(); $q = "INSERT into " . TB_PREFIX . "forum_post values (0,'$post','$tids','$owner','$date','$alliance','$player','$coor','$report')"; - mysqli_query($this->connection, $q); - return mysqli_insert_id($this->connection); + mysqli_query($q, $this->connection); + return mysql_insert_id($this->connection); } function UpdatePostDate($id) { $date = time(); $q = "UPDATE " . TB_PREFIX . "forum_topic set post_date = '$date' where id = $id"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function EditUpdateTopic($id, $post, $alliance, $player, $coor, $report) { $q = "UPDATE " . TB_PREFIX . "forum_topic set post = '$post', alliance0 = '$alliance', player0 = '$player', coor0 = '$coor', report0 = '$report' where id = $id"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function EditUpdatePost($id, $post, $alliance, $player, $coor, $report) { - $q = "UPDATE " . TB_PREFIX . "forum_post set post = '$post', alliance0 = '$alliance', player0 = '$player', coor0 = '$coor', report0 = '$report' where id = $id"; - return mysqli_query($this->connection, $q); + $q = "UPDATE " . TB_PREFIX . "forum_post set post = '$post', alliance0 = '$alliance', player0 = '$player', coor0 = '$coor', report0 = '$report' where id = $id"; + return mysqli_query($q, $this->connection); } function LockTopic($id, $mode) { $q = "UPDATE " . TB_PREFIX . "forum_topic set close = '$mode' where id = '$id'"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } - function DeleteCat($id) { - $qs = "DELETE from " . TB_PREFIX . "forum_cat where id = '$id'"; - $q = "DELETE from " . TB_PREFIX . "forum_topic where cat = '$id'"; - mysqli_query($qs, $this->connection); - return mysqli_query($this->connection, $q); - } + function DeleteCat($id) { + $qs = "DELETE from " . TB_PREFIX . "forum_cat where id = '$id'"; + $q = "DELETE from " . TB_PREFIX . "forum_topic where cat = '$id'"; + $q2="SELECT id from ".TB_PREFIX."forum_topic where cat ='$id'"; + $result = mysqli_query($q2, $this->connection); + if (!empty($result)) { + $array=$this->mysqli_fetch_all($result); + foreach($array as $ss) { + $this->DeleteSurvey($ss['id']); + } + } + mysqli_query($qs, $this->connection); + return mysqli_query($q, $this->connection); + } + + function DeleteSurvey($id) { + $qs = "DELETE from " . TB_PREFIX . "forum_survey where topic = '$id'"; + return mysqli_query($qs, $this->connection); + } function DeleteTopic($id) { $qs = "DELETE from " . TB_PREFIX . "forum_topic where id = '$id'"; @@ -1155,13 +1239,13 @@ class MYSQLi_DB { function DeletePost($id) { $q = "DELETE from " . TB_PREFIX . "forum_post where id = '$id'"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function getAllianceName($id) { $q = "SELECT tag from " . TB_PREFIX . "alidata where id = $id"; - $result = mysqli_query($this->connection, $q); - $dbarray = mysqli_fetch_array($result, MYSQLI_BOTH); + $result = mysqli_query($q, $this->connection); + $dbarray = mysqli_fetch_array($result); return $dbarray['tag']; } @@ -1171,26 +1255,26 @@ class MYSQLi_DB { } else { $q = "SELECT $field FROM " . TB_PREFIX . "ali_permission where username = '$ref'"; } - $result = mysqli_query($this->connection, $q) or die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error()); - $dbarray = mysqli_fetch_array($result, MYSQLI_BOTH); + $result = mysqli_query($q, $this->connection) or die(mysql_error()); + $dbarray = mysqli_fetch_array($result); return $dbarray[$field]; } function getAlliance($id) { $q = "SELECT * from " . TB_PREFIX . "alidata where id = $id"; - $result = mysqli_query($this->connection, $q); - return mysqli_fetch_assoc($result); + $result = mysqli_query($q, $this->connection); + return mysql_fetch_assoc($result); } function setAlliName($aid, $name, $tag) { $q = "UPDATE " . TB_PREFIX . "alidata set name = '$name', tag = '$tag' where id = $aid"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function isAllianceOwner($id) { $q = "SELECT * from " . TB_PREFIX . "alidata where leader = '$id'"; - $result = mysqli_query($this->connection, $q); - if(mysqli_num_rows($result)) { + $result = mysqli_query($q, $this->connection); + if(mysql_num_rows($result)) { return true; } else { return false; @@ -1199,8 +1283,8 @@ class MYSQLi_DB { function aExist($ref, $type) { $q = "SELECT $type FROM " . TB_PREFIX . "alidata where $type = '$ref'"; - $result = mysqli_query($this->connection, $q); - if(mysqli_num_rows($result)) { + $result = mysqli_query($q, $this->connection); + if(mysql_num_rows($result)) { return true; } else { return false; @@ -1209,12 +1293,12 @@ class MYSQLi_DB { function modifyPoints($aid, $points, $amt) { $q = "UPDATE " . TB_PREFIX . "users set $points = $points + $amt where id = $aid"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function modifyPointsAlly($aid, $points, $amt) { $q = "UPDATE " . TB_PREFIX . "alidata set $points = $points + $amt where id = $aid"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } /***************************************** @@ -1223,8 +1307,8 @@ class MYSQLi_DB { *****************************************/ function createAlliance($tag, $name, $uid, $max) { $q = "INSERT into " . TB_PREFIX . "alidata values (0,'$name','$tag',$uid,0,0,0,'','',$max,'','','','','','','','','')"; - mysqli_query($this->connection, $q); - return mysqli_insert_id($this->connection); + mysqli_query($q, $this->connection); + return mysql_insert_id($this->connection); } function procAllyPop($aid) { @@ -1255,8 +1339,8 @@ class MYSQLi_DB { function insertAlliNotice($aid, $notice) { $time = time(); $q = "INSERT into " . TB_PREFIX . "ali_log values (0,'$aid','$notice',$time)"; - mysqli_query($this->connection, $q); - return mysqli_insert_id($this->connection); + mysqli_query($q, $this->connection); + return mysql_insert_id($this->connection); } /***************************************** @@ -1265,12 +1349,12 @@ class MYSQLi_DB { *****************************************/ function deleteAlliance($aid) { $result = mysqli_query("SELECT * FROM " . TB_PREFIX . "users where alliance = $aid"); - $num_rows = mysqli_num_rows($result); + $num_rows = mysql_num_rows($result); if($num_rows == 0) { $q = "DELETE FROM " . TB_PREFIX . "alidata WHERE id = $aid"; } - mysqli_query($this->connection, $q); - return mysqli_insert_id($this->connection); + mysqli_query($q, $this->connection); + return mysql_insert_id($this->connection); } /***************************************** @@ -1279,7 +1363,7 @@ class MYSQLi_DB { *****************************************/ function readAlliNotice($aid) { $q = "SELECT * from " . TB_PREFIX . "ali_log where aid = $aid ORDER BY date DESC"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } @@ -1290,8 +1374,8 @@ class MYSQLi_DB { function createAlliPermissions($uid, $aid, $rank, $opt1, $opt2, $opt3, $opt4, $opt5, $opt6, $opt7, $opt8) { $q = "INSERT into " . TB_PREFIX . "ali_permission values(0,'$uid','$aid','$rank','$opt1','$opt2','$opt3','$opt4','$opt5','$opt6','$opt7','$opt8')"; - mysqli_query($this->connection, $q); - return mysqli_insert_id($this->connection); + mysqli_query($q, $this->connection); + return mysql_insert_id($this->connection); } /***************************************** @@ -1300,7 +1384,7 @@ class MYSQLi_DB { *****************************************/ function deleteAlliPermissions($uid) { $q = "DELETE from " . TB_PREFIX . "ali_permission where uid = '$uid'"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } /***************************************** Function to update alliance permissions @@ -1309,7 +1393,7 @@ class MYSQLi_DB { function updateAlliPermissions($uid, $aid, $rank, $opt1, $opt2, $opt3, $opt4, $opt5, $opt6, $opt7) { $q = "UPDATE " . TB_PREFIX . "ali_permission SET rank = '$rank', opt1 = '$opt1', opt2 = '$opt2', opt3 = '$opt3', opt4 = '$opt4', opt5 = '$opt5', opt6 = '$opt6', opt7 = '$opt7' where uid = $uid && alliance =$aid"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } /***************************************** @@ -1318,8 +1402,8 @@ class MYSQLi_DB { *****************************************/ function getAlliPermissions($uid, $aid) { $q = "SELECT * FROM " . TB_PREFIX . "ali_permission where uid = $uid && alliance = $aid"; - $result = mysqli_query($this->connection, $q); - return mysqli_fetch_assoc($result); + $result = mysqli_query($q, $this->connection); + return mysql_fetch_assoc($result); } /***************************************** @@ -1329,58 +1413,58 @@ class MYSQLi_DB { function submitAlliProfile($aid, $notice, $desc) { $q = "UPDATE " . TB_PREFIX . "alidata SET `notice` = '$notice', `desc` = '$desc' where id = $aid"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function diplomacyInviteAdd($alli1, $alli2, $type) { $q = "INSERT INTO " . TB_PREFIX . "diplomacy (alli1,alli2,type,accepted) VALUES ($alli1,$alli2," . (int)intval($type) . ",0)"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function diplomacyOwnOffers($session_alliance) { $q = "SELECT * FROM " . TB_PREFIX . "diplomacy WHERE alli1 = $session_alliance AND accepted = 0"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } function getAllianceID($name) { $q = "SELECT id FROM " . TB_PREFIX . "alidata WHERE tag ='" . $this->RemoveXSS($name) . "'"; - $result = mysqli_query($this->connection, $q); - $dbarray = mysqli_fetch_array($result, MYSQLI_BOTH); + $result = mysqli_query($q, $this->connection); + $dbarray = mysqli_fetch_array($result); return $dbarray['id']; } function getDiplomacy($aid) { $q = "SELECT * FROM " . TB_PREFIX . "diplomacy WHERE id = $aid"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } function diplomacyCancelOffer($id) { $q = "DELETE FROM " . TB_PREFIX . "diplomacy WHERE id = $id"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function diplomacyInviteAccept($id, $session_alliance) { $q = "UPDATE " . TB_PREFIX . "diplomacy SET accepted = 1 WHERE id = $id AND alli2 = $session_alliance"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function diplomacyInviteDenied($id, $session_alliance) { $q = "DELETE FROM " . TB_PREFIX . "diplomacy WHERE id = $id AND alli2 = $session_alliance"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function diplomacyInviteCheck($session_alliance) { $q = "SELECT * FROM " . TB_PREFIX . "diplomacy WHERE alli2 = $session_alliance AND accepted = 0"; - $result = mysql_query($this->connection, $q); - return $this->mysql_fetch_all($result); + $result = mysqli_query($q, $this->connection); + return $this->mysqli_fetch_all($result); } function diplomacyInviteCheck2($ally1, $ally2) { $q = "SELECT * FROM " . TB_PREFIX . "diplomacy WHERE alli1 = $ally1 AND alli2 = $ally2 accepted = 0"; - $result = mysql_query($this->connection, $q); - return $this->mysql_fetch_all($result); + $result = mysqli_query($q, $this->connection); + return $this->mysqli_fetch_all($result); } function getAllianceDipProfile($aid, $type){ @@ -1421,40 +1505,40 @@ class MYSQLi_DB { function getAllianceAlly($aid, $type){ $q = "SELECT * FROM ".TB_PREFIX."diplomacy WHERE (alli1 = '$aid' or alli2 = '$aid') AND (type = '$type' AND accepted = '1')"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } function getAllianceWar2($aid){ $q = "SELECT * FROM ".TB_PREFIX."diplomacy WHERE alli1 = '$aid' AND type = '3' OR alli2 = '$aid' AND type = '3' AND accepted = '1'"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } function diplomacyExistingRelationships($session_alliance) { $q = "SELECT * FROM " . TB_PREFIX . "diplomacy WHERE alli2 = $session_alliance AND accepted = 1"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } function diplomacyExistingRelationships2($session_alliance) { $q = "SELECT * FROM " . TB_PREFIX . "diplomacy WHERE alli1 = $session_alliance AND accepted = 1"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } function diplomacyCancelExistingRelationship($id, $session_alliance) { $q = "DELETE FROM " . TB_PREFIX . "diplomacy WHERE id = $id AND alli2 = $session_alliance OR id = $id AND alli1 = $session_alliance"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function checkDiplomacyInviteAccept($aid, $type) { $q = "SELECT * FROM " . TB_PREFIX . "diplomacy WHERE alli1 = $aid AND type = $type AND accepted = 1 OR alli2 = $aid AND type = $type AND accepted = 1"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); if($type == 3){ return true; }else{ - if(mysqli_num_rows($result) < 4) { + if(mysql_num_rows($result) < 4) { return true; } else { return false; @@ -1464,13 +1548,13 @@ class MYSQLi_DB { function setAlliForumLink($aid, $link) { $q = "UPDATE " . TB_PREFIX . "alidata SET `forumlink` = '$link' WHERE id = $aid"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function getUserAlliance($id) { $q = "SELECT " . TB_PREFIX . "alidata.tag from " . TB_PREFIX . "users join " . TB_PREFIX . "alidata where " . TB_PREFIX . "users.alliance = " . TB_PREFIX . "alidata.id and " . TB_PREFIX . "users.id = $id"; - $result = mysqli_query($this->connection, $q); - $dbarray = mysqli_fetch_array($result, MYSQLI_BOTH); + $result = mysqli_query($q, $this->connection); + $dbarray = mysqli_fetch_array($result); if($dbarray['tag'] == "") { return "-"; } else { @@ -1478,55 +1562,105 @@ class MYSQLi_DB { } } + /////////////ADDED BY BRAINIAC - THANK YOU + function modifyResource($vid, $wood, $clay, $iron, $crop, $mode) { - $q="SELECT wood,clay,iron,crop,maxstore,maxcrop from " . TB_PREFIX . "vdata where wref = ".$vid.""; - $result = mysqli_query($this->connection, $q); - $checkres= $this->mysqli_fetch_all($result); + $q="SELECT wood,clay,iron,crop,maxstore,maxcrop from " . TB_PREFIX . "vdata where wref = ".$vid.""; + $result = mysqli_query($q, $this->connection); + $checkres= $this->mysqli_fetch_all($result); if(!$mode){ - $nwood=$checkres[0]['wood']-$wood; - $nclay=$checkres[0]['clay']-$clay; - $niron=$checkres[0]['iron']-$iron; - $ncrop=$checkres[0]['crop']-$crop; - if($nwood<0 or $nclay<0 or $niron<0 or $ncrop<0){$shit=true;} - $dwood=($nwood<0)?0:$nwood; - $dclay=($nclay<0)?0:$nclay; - $diron=($niron<0)?0:$niron; - $dcrop=($ncrop<0)?0:$ncrop; - }else{ - $nwood=$checkres[0]['wood']+$wood; - $nclay=$checkres[0]['clay']+$clay; - $niron=$checkres[0]['iron']+$iron; - $ncrop=$checkres[0]['crop']+$crop; - $dwood=($nwood>$checkres[0]['maxstore'])?$checkres[0]['maxstore']:$nwood; - $dclay=($nclay>$checkres[0]['maxstore'])?$checkres[0]['maxstore']:$nclay; - $diron=($niron>$checkres[0]['maxstore'])?$checkres[0]['maxstore']:$niron; - $dcrop=($ncrop>$checkres[0]['maxcrop'])?$checkres[0]['maxcrop']:$ncrop; - } - if(!$shit){ - $q = "UPDATE " . TB_PREFIX . "vdata set wood = $dwood, clay = $dclay, iron = $diron, crop = $dcrop where wref = ".$vid; - return mysqli_query($this->connection, $q); }else{return false;} - } + $nwood=$checkres[0]['wood']-$wood; + $nclay=$checkres[0]['clay']-$clay; + $niron=$checkres[0]['iron']-$iron; + $ncrop=$checkres[0]['crop']-$crop; + if($nwood<0 or $nclay<0 or $niron<0 or $ncrop<0){$shit=true;} + $dwood=($nwood<0)?0:$nwood; + $dclay=($nclay<0)?0:$nclay; + $diron=($niron<0)?0:$niron; + $dcrop=($ncrop<0)?0:$ncrop; + }else{ + $nwood=$checkres[0]['wood']+$wood; + $nclay=$checkres[0]['clay']+$clay; + $niron=$checkres[0]['iron']+$iron; + $ncrop=$checkres[0]['crop']+$crop; + $dwood=($nwood>$checkres[0]['maxstore'])?$checkres[0]['maxstore']:$nwood; + $dclay=($nclay>$checkres[0]['maxstore'])?$checkres[0]['maxstore']:$nclay; + $diron=($niron>$checkres[0]['maxstore'])?$checkres[0]['maxstore']:$niron; + $dcrop=($ncrop>$checkres[0]['maxcrop'])?$checkres[0]['maxcrop']:$ncrop; + } + if(!$shit){ + $q = "UPDATE " . TB_PREFIX . "vdata set wood = $dwood, clay = $dclay, iron = $diron, crop = $dcrop where wref = ".$vid; + return mysqli_query($q, $this->connection); }else{return false;} + } function modifyOasisResource($vid, $wood, $clay, $iron, $crop, $mode) { - if(!$mode) { - $q = "UPDATE " . TB_PREFIX . "odata set wood = wood - $wood, clay = clay - $clay, iron = iron - $iron, crop = crop - $crop where wref = $vid"; - } else { - $q = "UPDATE " . TB_PREFIX . "odata set wood = wood + $wood, clay = clay + $clay, iron = iron + $iron, crop = crop + $crop where wref = $vid"; - } - return mysqli_query($this->connection, $q); - } + $q="SELECT wood,clay,iron,crop,maxstore,maxcrop from " . TB_PREFIX . "odata where wref = ".$vid.""; + $result = mysqli_query($q, $this->connection); + $checkres= $this->mysqli_fetch_all($result); + if(!$mode){ + $nwood=$checkres[0]['wood']-$wood; + $nclay=$checkres[0]['clay']-$clay; + $niron=$checkres[0]['iron']-$iron; + $ncrop=$checkres[0]['crop']-$crop; + if($nwood<0 or $nclay<0 or $niron<0 or $ncrop<0){$shit=true;} + $dwood=($nwood<0)?0:$nwood; + $dclay=($nclay<0)?0:$nclay; + $diron=($niron<0)?0:$niron; + $dcrop=($ncrop<0)?0:$ncrop; + }else{ + $nwood=$checkres[0]['wood']+$wood; + $nclay=$checkres[0]['clay']+$clay; + $niron=$checkres[0]['iron']+$iron; + $ncrop=$checkres[0]['crop']+$crop; + $dwood=($nwood>$checkres[0]['maxstore'])?$checkres[0]['maxstore']:$nwood; + $dclay=($nclay>$checkres[0]['maxstore'])?$checkres[0]['maxstore']:$nclay; + $diron=($niron>$checkres[0]['maxstore'])?$checkres[0]['maxstore']:$niron; + $dcrop=($ncrop>$checkres[0]['maxcrop'])?$checkres[0]['maxcrop']:$ncrop; + } + if(!$shit){ + $q = "UPDATE " . TB_PREFIX . "odata set wood = $dwood, clay = $dclay, iron = $diron, crop = $dcrop where wref = ".$vid; + return mysqli_query($q, $this->connection); }else{return false;} + } function getFieldLevel($vid, $field) { $q = "SELECT f" . $field . " from " . TB_PREFIX . "fdata where vref = $vid"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return mysql_result($result, 0); } function getFieldType($vid, $field) { $q = "SELECT f" . $field . "t from " . TB_PREFIX . "fdata where vref = $vid"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return mysql_result($result, 0); } + + function getFieldDistance($wid) { + $q = "SELECT * FROM " . TB_PREFIX . "vdata where owner > 4 and wref != $wid"; + $array = $this->query_return($q); + $coor = $this->getCoor($wid); + $x1 = intval($coor['x']); + $y1 = intval($coor['y']); + $prevdist = 0; + $q2 = "SELECT * FROM " . TB_PREFIX . "vdata where owner = 4"; + $array2 = mysqli_fetch_array(mysqli_query($q2)); + $vill = $array2['wref']; + if(mysql_num_rows(mysqli_query($q)) > 0){ + foreach($array as $village){ + $coor2 = $this->getCoor($village['wref']); + $max = 2 * WORLD_MAX + 1; + $x2 = intval($coor2['x']); + $y2 = intval($coor2['y']); + $distanceX = min(abs($x2 - $x1), abs($max - abs($x2 - $x1))); + $distanceY = min(abs($y2 - $y1), abs($max - abs($y2 - $y1))); + $dist = sqrt(pow($distanceX, 2) + pow($distanceY, 2)); + if($dist < $prevdist or $prevdist == 0){ + $prevdist = $dist; + $vill = $village['wref']; + } + } + } + return $vill; + } function getVSumField($uid, $field) { if($field != "cp"){ @@ -1534,34 +1668,36 @@ class MYSQLi_DB { }else{ $q = "SELECT sum(" . $field . ") FROM " . TB_PREFIX . "vdata where owner = $uid and natar = 0"; } - $result = mysqli_query($this->connection, $q); - $row = mysqli_fetch_row($result); + $result = mysqli_query($q, $this->connection); + $row = mysql_fetch_row($result); return $row[0]; } function updateVillage($vid) { $time = time(); $q = "UPDATE " . TB_PREFIX . "vdata set lastupdate = $time where wref = $vid"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } + function updateOasis($vid) { $time = time(); $q = "UPDATE " . TB_PREFIX . "odata set lastupdated = $time where wref = $vid"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } - + function updateOasis2($vid, $time) { $time = time(); - $q = "UPDATE " . TB_PREFIX . "odata set lastupdated2 = lastupdated2 + $time where wref = $vid"; - return mysqli_query($this->connection, $q); + $time2 = NATURE_REGTIME; + $q = "UPDATE " . TB_PREFIX . "odata set lastupdated2 = $time + $time2 where wref = $vid"; + return mysqli_query($q, $this->connection); } function setVillageName($vid, $name) { if(!empty($name)) { $q = "UPDATE " . TB_PREFIX . "vdata set name = '$name' where wref = $vid"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } } @@ -1571,84 +1707,84 @@ class MYSQLi_DB { } else { $q = "UPDATE " . TB_PREFIX . "vdata set pop = pop - $pop where wref = $vid"; } - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function addCP($ref, $cp) { $q = "UPDATE " . TB_PREFIX . "vdata set cp = cp + $cp where wref = $ref"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function addCel($ref, $cel, $type) { $q = "UPDATE " . TB_PREFIX . "vdata set celebration = $cel, type= $type where wref = $ref"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function getCel() { $time = time(); $q = "SELECT * FROM " . TB_PREFIX . "vdata where celebration < $time AND celebration != 0"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } function clearCel($ref) { $q = "UPDATE " . TB_PREFIX . "vdata set celebration = 0, type = 0 where wref = $ref"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function setCelCp($user, $cp) { $q = "UPDATE " . TB_PREFIX . "users set cp = cp + $cp where id = $user"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function clearExpansionSlot($id) { for($i = 1; $i <= 3; $i++) { $q = "UPDATE " . TB_PREFIX . "vdata SET exp" . $i . "=0 WHERE exp" . $i . "=" . $id; - mysqli_query($this->connection, $q); + mysqli_query($q, $this->connection); } } function getInvitation($uid) { $q = "SELECT * FROM " . TB_PREFIX . "ali_invite where uid = $uid"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } function getInvitation2($uid, $aid) { $q = "SELECT * FROM " . TB_PREFIX . "ali_invite where uid = $uid and alliance = $aid"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } function getAliInvitations($aid) { $q = "SELECT * FROM " . TB_PREFIX . "ali_invite where alliance = $aid && accept = 0"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } function sendInvitation($uid, $alli, $sender) { $time = time(); $q = "INSERT INTO " . TB_PREFIX . "ali_invite values (0,$uid,$alli,$sender,$time,0)"; - return mysqli_query($this->connection, $q) or die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error()); + return mysqli_query($q, $this->connection) or die(mysql_error()); } function removeInvitation($id) { $q = "DELETE FROM " . TB_PREFIX . "ali_invite where id = $id"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function sendMessage($client, $owner, $topic, $message, $send, $alliance, $player, $coor, $report) { $time = time(); $q = "INSERT INTO " . TB_PREFIX . "mdata values (0,$client,$owner,'$topic',\"$message\",0,0,$send,$time,0,0,$alliance,$player,$coor,$report)"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function setArchived($id) { $q = "UPDATE " . TB_PREFIX . "mdata set archived = 1 where id = $id"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function setNorm($id) { $q = "UPDATE " . TB_PREFIX . "mdata set archived = 0 where id = $id"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } /*************************** @@ -1699,109 +1835,113 @@ class MYSQLi_DB { break; } if($mode <= 3 || $mode == 6 || $mode > 8) { - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } else { - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } } function getDelSent($uid) { $q = "SELECT * FROM " . TB_PREFIX . "mdata WHERE owner = $uid and delowner = 1 ORDER BY time DESC"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } function getDelInbox($uid) { $q = "SELECT * FROM " . TB_PREFIX . "mdata WHERE target = $uid and deltarget = 1 ORDER BY time DESC"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } function getDelArchive($uid) { $q = "SELECT * FROM " . TB_PREFIX . "mdata WHERE target = $uid and archived = 1 and deltarget = 1 OR owner = $uid and archived = 1 and delowner = 1 ORDER BY time DESC"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } function unarchiveNotice($id) { $q = "UPDATE " . TB_PREFIX . "ndata set ntype = archive, archive = 0 where id = $id"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function archiveNotice($id) { $q = "update " . TB_PREFIX . "ndata set archive = ntype, ntype = 9 where id = $id"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function removeNotice($id) { $q = "UPDATE " . TB_PREFIX . "ndata set del = 1,viewed = 1 where id = $id"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function noticeViewed($id) { $q = "UPDATE " . TB_PREFIX . "ndata set viewed = 1 where id = $id"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } - function addNotice($uid, $wref, $aid, $type, $topic, $data, $time = 0) { - if($time == 0) { - $time = time(); - } - $q = "INSERT INTO " . TB_PREFIX . "ndata (id, uid, toWref, ally, topic, ntype, data, time, viewed) values (0,'$uid','$wref','$aid','$topic',$type,'$data',$time,0)"; - return mysqli_query($this->connection, $q) or die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error()); - } + function addNotice($uid, $toWref, $ally, $type, $topic, $data, $time = 0) { + if($time == 0) { + $time = time(); + } + $q = "INSERT INTO " . TB_PREFIX . "ndata (id, uid, toWref, ally, topic, ntype, data, time, viewed) values (0,'$uid','$toWref','$ally','$topic',$type,'$data',$time,0)"; + return mysqli_query($q, $this->connection) or die(mysql_error()); + } function getNotice($uid) { $q = "SELECT * FROM " . TB_PREFIX . "ndata where uid = $uid and del = 0 ORDER BY time DESC"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } function getNotice2($id, $field) { $q = "SELECT ".$field." FROM " . TB_PREFIX . "ndata where `id` = '$id'"; - $result = mysqli_query($this->connection, $q); - $dbarray = mysqli_fetch_array($result, MYSQLI_BOTH); + $result = mysqli_query($q, $this->connection); + $dbarray = mysqli_fetch_array($result); return $dbarray[$field]; } function getNotice3($uid) { $q = "SELECT * FROM " . TB_PREFIX . "ndata where uid = $uid ORDER BY time DESC"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } function getNotice4($id) { $q = "SELECT * FROM " . TB_PREFIX . "ndata where id = $id ORDER BY time DESC"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); + return $this->mysqli_fetch_all($result); + } + function getUnViewNotice($uid) { + $q = "SELECT * FROM " . TB_PREFIX . "ndata where uid = $uid AND viewed=0"; + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } - function createTradeRoute($uid,$wid,$from,$r1,$r2,$r3,$r4,$start,$deliveries,$merchant,$time) { $x = "UPDATE " . TB_PREFIX . "users SET gold = gold - 2 WHERE id = ".$uid.""; mysqli_query($x, $this->connection); $timeleft = time()+604800; $q = "INSERT into " . TB_PREFIX . "route values (0,$uid,$wid,$from,$r1,$r2,$r3,$r4,$start,$deliveries,$merchant,$time,$timeleft)"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function getTradeRoute($uid) { $q = "SELECT * FROM " . TB_PREFIX . "route where uid = $uid ORDER BY timestamp ASC"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } function getTradeRoute2($id) { $q = "SELECT * FROM " . TB_PREFIX . "route where id = $id"; - $result = mysqli_query($this->connection, $q) or die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error()); - $dbarray = mysqli_fetch_array($result, MYSQLI_BOTH); + $result = mysqli_query($q, $this->connection) or die(mysql_error()); + $dbarray = mysqli_fetch_array($result); return $dbarray; } function getTradeRouteUid($id) { $q = "SELECT * FROM " . TB_PREFIX . "route where id = $id"; - $result = mysqli_query($this->connection, $q) or die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error()); - $dbarray = mysqli_fetch_array($result, MYSQLI_BOTH); + $result = mysqli_query($q, $this->connection) or die(mysql_error()); + $dbarray = mysqli_fetch_array($result); return $dbarray['uid']; } @@ -1811,23 +1951,23 @@ class MYSQLi_DB { }else{ $q = "UPDATE " . TB_PREFIX . "route set $column = $column + $value where id = $id"; } - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function deleteTradeRoute($id) { $q = "DELETE FROM " . TB_PREFIX . "route where id = $id"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function addBuilding($wid, $field, $type, $loop, $time, $master, $level) { $x = "UPDATE " . TB_PREFIX . "fdata SET f" . $field . "t=" . $type . " WHERE vref=" . $wid; - mysqli_query($x, $this->connection) or die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error()); + mysqli_query($x, $this->connection) or die(mysql_error()); $q = "INSERT into " . TB_PREFIX . "bdata values (0,$wid,$field,$type,$loop,$time,$master,$level)"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function removeBuilding($d) { - global $building; + global $building, $village; $jobLoopconID = -1; $SameBuildCount = 0; $jobs = $building->buildArray; @@ -1880,7 +2020,7 @@ class MYSQLi_DB { $time = $uprequire['time']; $timestamp = $time+time(); $q = "UPDATE " . TB_PREFIX . "bdata SET loopcon=0,level=level-1,timestamp=".$timestamp." WHERE id=".$jobs[1]['id'].""; - mysqli_query($this->connection, $q); + mysqli_query($q, $this->connection); } }else if($SameBuildCount == 6){ if($jobDeleted == 0){ @@ -1888,7 +2028,7 @@ class MYSQLi_DB { $time = $uprequire['time']; $timestamp = $time+time(); $q = "UPDATE " . TB_PREFIX . "bdata SET loopcon=0,level=level-1,timestamp=".$timestamp." WHERE id=".$jobs[2]['id'].""; - mysqli_query($this->connection, $q); + mysqli_query($q, $this->connection); } }else if($SameBuildCount == 7){ if($jobDeleted == 1){ @@ -1896,7 +2036,7 @@ class MYSQLi_DB { $time = $uprequire['time']; $timestamp = $time+time(); $q = "UPDATE " . TB_PREFIX . "bdata SET loopcon=0,level=level-1,timestamp=".$timestamp." WHERE id=".$jobs[2]['id'].""; - mysqli_query($this->connection, $q); + mysqli_query($q, $this->connection); } } if($SameBuildCount < 8){ @@ -1914,37 +2054,40 @@ class MYSQLi_DB { } }else if($d == $jobs[floor($SameBuildCount / 3)]['id'] || $d == $jobs[floor($SameBuildCount / 2) + 1]['id']) { $q = "UPDATE " . TB_PREFIX . "bdata SET loopcon=0,level=level-1,timestamp=" . $jobs[floor($SameBuildCount / 3)]['timestamp'] . " WHERE master = 0 AND id > ".$d." and (ID=" . $jobs[floor($SameBuildCount / 3)]['id'] . " OR ID=" . $jobs[floor($SameBuildCount / 2) + 1]['id'] . ")"; - mysqli_query($this->connection, $q); + mysqli_query($q, $this->connection); } } else { - if($jobs[$jobDeleted]['field'] >= 19) { - $x = "SELECT f" . $jobs[$jobDeleted]['field'] . " FROM " . TB_PREFIX . "fdata WHERE vref=" . $jobs[$jobDeleted]['wid']; - $result = mysqli_query($x, $this->connection) or die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error()); - $fieldlevel = mysqli_fetch_row($result); - if($fieldlevel[0] == 0) { - $x = "UPDATE " . TB_PREFIX . "fdata SET f" . $jobs[$jobDeleted]['field'] . "t=0 WHERE vref=" . $jobs[$jobDeleted]['wid']; - mysqli_query($x, $this->connection) or die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error()); - } + if($jobs[$jobDeleted]['field'] >= 19) { + $x = "SELECT f" . $jobs[$jobDeleted]['field'] . " FROM " . TB_PREFIX . "fdata WHERE vref=" . $jobs[$jobDeleted]['wid']; + $result = mysqli_query($x, $this->connection) or die(mysql_error()); + $fieldlevel = mysql_fetch_row($result); + if($fieldlevel[0] == 0) { + if ($village->natar==1 && $jobs[$jobDeleted]['field']==99) { //fix by ronix + }else{ + $x = "UPDATE " . TB_PREFIX . "fdata SET f" . $jobs[$jobDeleted]['field'] . "t=0 WHERE vref=" . $jobs[$jobDeleted]['wid']; + mysqli_query($x, $this->connection) or die(mysql_error()); + } + } } if(($jobLoopconID >= 0) && ($jobs[$jobDeleted]['loopcon'] != 1)) { if(($jobs[$jobLoopconID]['field'] <= 18 && $jobs[$jobDeleted]['field'] <= 18) || ($jobs[$jobLoopconID]['field'] >= 19 && $jobs[$jobDeleted]['field'] >= 19) || sizeof($jobs) < 3) { $uprequire = $building->resourceRequired($jobs[$jobLoopconID]['field'], $jobs[$jobLoopconID]['type']); $x = "UPDATE " . TB_PREFIX . "bdata SET loopcon=0,timestamp=" . (time() + $uprequire['time']) . " WHERE wid=" . $jobs[$jobDeleted]['wid'] . " AND loopcon=1 AND master=0"; - mysqli_query($x, $this->connection) or die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error()); + mysqli_query($x, $this->connection) or die(mysql_error()); } } } $q = "DELETE FROM " . TB_PREFIX . "bdata where id = $d"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function addDemolition($wid, $field) { global $building, $village; $q = "DELETE FROM ".TB_PREFIX."bdata WHERE field=$field AND wid=$wid"; - mysqli_query($this->connection, $q); + mysqli_query($q, $this->connection); $uprequire = $building->resourceRequired($field,$village->resarray['f'.$field.'t'],0); $q = "INSERT INTO ".TB_PREFIX."demolition VALUES (".$wid.",".$field.",".($this->getFieldLevel($wid,$field)-1).",".(time()+floor($uprequire['time']/2)).")"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } @@ -1954,7 +2097,7 @@ class MYSQLi_DB { } else { $q = "SELECT * FROM " . TB_PREFIX . "demolition WHERE timetofinish<=" . time(); } - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); if(!empty($result)) { return $this->mysqli_fetch_all($result); } else { @@ -1963,18 +2106,19 @@ class MYSQLi_DB { } function finishDemolition($wid) { - $q = "UPDATE " . TB_PREFIX . "demolition SET timetofinish=" . time() . " WHERE vref=" . $wid; - return mysqli_query($this->connection, $q); - } + $q = "UPDATE " . TB_PREFIX . "demolition SET timetofinish=" . time() . " WHERE vref=" . $wid; + $result= mysqli_query($q, $this->connection); + return mysql_affected_rows(); + } function delDemolition($wid) { $q = "DELETE FROM " . TB_PREFIX . "demolition WHERE vref=" . $wid; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function getJobs($wid) { $q = "SELECT * FROM " . TB_PREFIX . "bdata where wid = $wid order by master,timestamp ASC"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } @@ -1982,10 +2126,9 @@ class MYSQLi_DB { $time = time()-1; $q = "SELECT * FROM " . TB_PREFIX . "bdata where wid = $wid and type = 1 order by master,timestamp ASC"; $result = mysqli_query($q); - $dbarray = mysqli_fetch_array($result, MYSQLI_BOTH); + $dbarray = mysqli_fetch_array($result); $q = "UPDATE ".TB_PREFIX."bdata SET timestamp = $time WHERE id = '".$dbarray['id']."'"; $this->query($q); - $tribe = $this->getUserField($this->getVillageField($wid, "owner"), "tribe", 0); if($tribe == 1){ $q2 = "SELECT * FROM " . TB_PREFIX . "bdata where wid = $wid and loopcon = 1 and field >= 19 order by master,timestamp ASC"; @@ -1993,8 +2136,8 @@ class MYSQLi_DB { $q2 = "SELECT * FROM " . TB_PREFIX . "bdata where wid = $wid and loopcon = 1 order by master,timestamp ASC"; } $result2 = mysqli_query($q2); - if(mysqli_num_rows($result2) > 0){ - $dbarray2 = mysql_fetch_array($result2); + if(mysql_num_rows($result2) > 0){ + $dbarray2 = mysqli_fetch_array($result2); $wc_time = $dbarray['timestamp']; $q2 = "UPDATE ".TB_PREFIX."bdata SET timestamp = timestamp - $wc_time WHERE id = '".$dbarray2['id']."'"; $this->query($q2); @@ -2003,61 +2146,61 @@ class MYSQLi_DB { function getMasterJobs($wid) { $q = "SELECT * FROM " . TB_PREFIX . "bdata where wid = $wid and master = 1 order by master,timestamp ASC"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } function getMasterJobsByField($wid,$field) { $q = "SELECT * FROM " . TB_PREFIX . "bdata where wid = $wid and field = $field and master = 1 order by master,timestamp ASC"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } function getBuildingByField($wid,$field) { $q = "SELECT * FROM " . TB_PREFIX . "bdata where wid = $wid and field = $field and master = 0"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } function getBuildingByField2($wid,$field) { $q = "SELECT * FROM " . TB_PREFIX . "bdata where wid = $wid and field = $field and master = 0"; - $result = mysqli_query($this->connection, $q); - return mysqli_num_rows($result); + $result = mysqli_query($q, $this->connection); + return mysql_num_rows($result); } function getBuildingByType($wid,$type) { $q = "SELECT * FROM " . TB_PREFIX . "bdata where wid = $wid and type = $type and master = 0"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } function getBuildingByType2($wid,$type) { $q = "SELECT * FROM " . TB_PREFIX . "bdata where wid = $wid and type = $type and master = 0"; - $result = mysqli_query($this->connection, $q); - return mysqli_num_rows($result); + $result = mysqli_query($q, $this->connection); + return mysql_num_rows($result); } function getDorf1Building($wid) { $q = "SELECT * FROM " . TB_PREFIX . "bdata where wid = $wid and field < 19 and master = 0"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } function getDorf2Building($wid) { $q = "SELECT * FROM " . TB_PREFIX . "bdata where wid = $wid and field > 18 and master = 0"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } function updateBuildingWithMaster($id, $time,$loop) { $q = "UPDATE " . TB_PREFIX . "bdata SET master = 0, timestamp = ".$time.",loopcon = ".$loop." WHERE id = ".$id.""; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function getVillageByName($name) { $q = "SELECT wref FROM " . TB_PREFIX . "vdata where name = '$name' limit 1"; - $result = mysqli_query($this->connection, $q); - $dbarray = mysqli_fetch_array($result, MYSQLI_BOTH); + $result = mysqli_query($q, $this->connection); + $dbarray = mysqli_fetch_array($result); return $dbarray['wref']; } @@ -2067,7 +2210,7 @@ class MYSQLi_DB { ***************************/ function setMarketAcc($id) { $q = "UPDATE " . TB_PREFIX . "market set accept = 1 where id = $id"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } /*************************** @@ -2079,11 +2222,11 @@ class MYSQLi_DB { function sendResource($ref, $clay, $iron, $crop, $merchant, $mode) { if(!$mode) { $q = "INSERT INTO " . TB_PREFIX . "send values (0,$ref,$clay,$iron,$crop,$merchant)"; - mysqli_query($this->connection, $q); - return mysqli_insert_id($this->connection); + mysqli_query($q, $this->connection); + return mysql_insert_id($this->connection); } else { $q = "DELETE FROM " . TB_PREFIX . "send where id = $ref"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } } @@ -2097,19 +2240,19 @@ class MYSQLi_DB { //Xtype (1) = wood, (2) = clay, (3) = iron, (4) = crop if($gtype == 1) { $q = "UPDATE " . TB_PREFIX . "vdata SET `wood` = `wood` + '$gamt' WHERE wref = $vref"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } else if($gtype == 2) { $q = "UPDATE " . TB_PREFIX . "vdata SET `clay` = `clay` + '$gamt' WHERE wref = $vref"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } else if($gtype == 3) { $q = "UPDATE " . TB_PREFIX . "vdata SET `iron` = `iron` + '$gamt' WHERE wref = $vref"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } else if($gtype == 4) { $q = "UPDATE " . TB_PREFIX . "vdata SET `crop` = `crop` + '$gamt' WHERE wref = $vref"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } } @@ -2121,15 +2264,15 @@ class MYSQLi_DB { function getMarketField($vref, $field) { $q = "SELECT $field FROM " . TB_PREFIX . "market where vref = '$vref'"; - $result = mysqli_query($this->connection, $q) or die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error()); - $dbarray = mysqli_fetch_array($result, MYSQLI_BOTH); + $result = mysqli_query($q, $this->connection) or die(mysql_error()); + $dbarray = mysqli_fetch_array($result); return $dbarray[$field]; } function removeAcceptedOffer($id) { $q = "DELETE FROM " . TB_PREFIX . "market where id = $id"; - $result = mysqli_query($this->connection, $q); - return mysqli_fetch_assoc($result); + $result = mysqli_query($q, $this->connection); + return mysql_fetch_assoc($result); } /*************************** @@ -2141,11 +2284,11 @@ class MYSQLi_DB { function addMarket($vid, $gtype, $gamt, $wtype, $wamt, $time, $alliance, $merchant, $mode) { if(!$mode) { $q = "INSERT INTO " . TB_PREFIX . "market values (0,$vid,$gtype,$gamt,$wtype,$wamt,0,$time,$alliance,$merchant)"; - mysqli_query($this->connection, $q); - return mysqli_insert_id($this->connection); + mysqli_query($q, $this->connection); + return mysql_insert_id($this->connection); } else { $q = "DELETE FROM " . TB_PREFIX . "market where id = $gtype and vref = $vid"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } } @@ -2160,7 +2303,7 @@ class MYSQLi_DB { } else { $q = "SELECT * FROM " . TB_PREFIX . "market where vref != $vid and alliance = $alliance or vref != $vid and alliance = 0 and accept = 0"; } - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } @@ -2170,13 +2313,13 @@ class MYSQLi_DB { ***************************/ function getMarketInfo($id) { $q = "SELECT * FROM " . TB_PREFIX . "market where id = $id"; - $result = mysqli_query($this->connection, $q); - return mysqli_fetch_assoc($result); + $result = mysqli_query($q, $this->connection); + return mysql_fetch_assoc($result); } function setMovementProc($moveid) { $q = "UPDATE " . TB_PREFIX . "movement set proc = 1 where moveid = $moveid"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } /*************************** @@ -2186,14 +2329,14 @@ class MYSQLi_DB { function totalMerchantUsed($vid) { $time = time(); $q = "SELECT sum(" . TB_PREFIX . "send.merchant) from " . TB_PREFIX . "send, " . TB_PREFIX . "movement where " . TB_PREFIX . "movement.from = $vid and " . TB_PREFIX . "send.id = " . TB_PREFIX . "movement.ref and " . TB_PREFIX . "movement.proc = 0 and sort_type = 0"; - $result = mysqli_query($this->connection, $q); - $row = mysqli_fetch_row($result); + $result = mysqli_query($q, $this->connection); + $row = mysql_fetch_row($result); $q2 = "SELECT sum(ref) from " . TB_PREFIX . "movement where sort_type = 2 and " . TB_PREFIX . "movement.to = $vid and proc = 0"; - $result2 = mysqli_query($this->connection, $q2); - $row2 = mysqli_fetch_row($result2); + $result2 = mysqli_query($q2, $this->connection); + $row2 = mysql_fetch_row($result2); $q3 = "SELECT sum(merchant) from " . TB_PREFIX . "market where vref = $vid and accept = 0"; $result3 = mysqli_query($q3, $this->connection); - $row3 = mysqli_fetch_row($result3); + $row3 = mysql_fetch_row($result3); return $row[0] + $row2[0] + $row3[0]; } @@ -2224,7 +2367,8 @@ class MYSQLi_DB { $q = "SELECT * FROM " . TB_PREFIX . "movement where " . TB_PREFIX . "movement." . $where . " = $village and sort_type = 5 and proc = 0 ORDER BY endtime ASC"; break; case 6: - $q = "SELECT * FROM " . TB_PREFIX . "movement," . TB_PREFIX . "odata, " . TB_PREFIX . "attacks where " . TB_PREFIX . "odata.conqured = $village and " . TB_PREFIX . "movement.to = " . TB_PREFIX . "odata.wref and " . TB_PREFIX . "movement.ref = " . TB_PREFIX . "attacks.id and " . TB_PREFIX . "movement.proc = 0 and " . TB_PREFIX . "movement.sort_type = 3 ORDER BY endtime ASC"; + $q = "SELECT * FROM " . TB_PREFIX . "movement," . TB_PREFIX . "odata, " . TB_PREFIX . "attacks where " . TB_PREFIX . "odata.wref = $village and " . TB_PREFIX . "movement.to = $village and " . TB_PREFIX . "movement.ref = " . TB_PREFIX . "attacks.id and " . TB_PREFIX . "attacks.attack_type != 1 and " . TB_PREFIX . "movement.proc = 0 and " . TB_PREFIX . "movement.sort_type = 3 ORDER BY endtime ASC"; + //$q = "SELECT * FROM " . TB_PREFIX . "movement," . TB_PREFIX . "odata, " . TB_PREFIX . "attacks where " . TB_PREFIX . "odata.conqured = $village and " . TB_PREFIX . "movement.to = " . TB_PREFIX . "odata.wref and " . TB_PREFIX . "movement.ref = " . TB_PREFIX . "attacks.id and " . TB_PREFIX . "movement.proc = 0 and " . TB_PREFIX . "movement.sort_type = 3 ORDER BY endtime ASC"; break; case 7: $q = "SELECT * FROM " . TB_PREFIX . "movement where " . TB_PREFIX . "movement." . $where . " = $village and sort_type = 4 and ref = 0 and proc = 0 ORDER BY endtime ASC"; @@ -2236,22 +2380,22 @@ class MYSQLi_DB { $q = "SELECT * FROM " . TB_PREFIX . "movement, " . TB_PREFIX . "attacks where " . TB_PREFIX . "movement." . $where . " = $village and " . TB_PREFIX . "movement.ref = " . TB_PREFIX . "attacks.id and " . TB_PREFIX . "movement.proc = 0 and " . TB_PREFIX . "movement.sort_type = 3 or " . TB_PREFIX . "movement." . $where . " = $village and " . TB_PREFIX . "movement.ref = " . TB_PREFIX . "attacks.id and " . TB_PREFIX . "movement.proc = 0 and " . TB_PREFIX . "movement.sort_type = 4 ORDER BY endtime ASC"; break; } - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); $array = $this->mysqli_fetch_all($result); return $array; } function addA2b($ckey, $timestamp, $to, $t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10, $t11, $type) { $q = "INSERT INTO " . TB_PREFIX . "a2b (ckey,time_check,to_vid,u1,u2,u3,u4,u5,u6,u7,u8,u9,u10,u11,type) VALUES ('$ckey', '$timestamp', '$to', '$t1', '$t2', '$t3', '$t4', '$t5', '$t6', '$t7', '$t8', '$t9', '$t10', '$t11', '$type')"; - mysqli_query($this->connection, $q); - return mysqli_insert_id($this->connection); + mysqli_query($q, $this->connection); + return mysql_insert_id($this->connection); } function getA2b($ckey, $check) { $q = "SELECT * from " . TB_PREFIX . "a2b where ckey = '" . $ckey . "' AND time_check = '" . $check . "'"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); if($result) { - return mysqli_fetch_assoc($result); + return mysql_fetch_assoc($result); } else { return false; } @@ -2259,85 +2403,90 @@ class MYSQLi_DB { function addMovement($type, $from, $to, $ref, $time, $endtime, $send = 1, $wood = 0, $clay = 0, $iron = 0, $crop = 0, $ref2 = 0) { $q = "INSERT INTO " . TB_PREFIX . "movement values (0,$type,$from,$to,$ref,$ref2,$time,$endtime,0,$send,$wood,$clay,$iron,$crop)"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function addAttack($vid, $t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10, $t11, $type, $ctar1, $ctar2, $spy,$b1=0,$b2=0,$b3=0,$b4=0,$b5=0,$b6=0,$b7=0,$b8=0) { $q = "INSERT INTO " . TB_PREFIX . "attacks values (0,$vid,$t1,$t2,$t3,$t4,$t5,$t6,$t7,$t8,$t9,$t10,$t11,$type,$ctar1,$ctar2,$spy,$b1,$b2,$b3,$b4,$b5,$b6,$b7,$b8)"; - mysqli_query($this->connection, $q); - return mysqli_insert_id($this->connection); + mysqli_query($q, $this->connection); + return mysql_insert_id($this->connection); } function modifyAttack($aid, $unit, $amt) { $unit = 't' . $unit; $q = "UPDATE " . TB_PREFIX . "attacks set $unit = $unit - $amt where id = $aid"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function modifyAttack2($aid, $unit, $amt) { $unit = 't' . $unit; $q = "UPDATE " . TB_PREFIX . "attacks set $unit = $unit + $amt where id = $aid"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } + + function modifyAttack3($aid, $units) { + $q = "UPDATE ".TB_PREFIX."attacks set $units WHERE id = $aid"; + return mysqli_query($q, $this->connection); + } function getRanking() { $q = "SELECT id,username,alliance,ap,apall,dp,dpall,access FROM " . TB_PREFIX . "users WHERE tribe<=3 AND access<" . (INCLUDE_ADMIN ? "10" : "8"); - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } function getVRanking() { $q = "SELECT v.wref,v.name,v.owner,v.pop FROM " . TB_PREFIX . "vdata AS v," . TB_PREFIX . "users AS u WHERE v.owner=u.id AND u.tribe<=3 AND v.wref != '' AND u.access<" . (INCLUDE_ADMIN ? "10" : "8"); - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } function getARanking() { $q = "SELECT id,name,tag,oldrank,Aap,Adp FROM " . TB_PREFIX . "alidata where id != '' ORDER BY id DESC"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } function getUserByTribe($tribe){ $q = "SELECT * FROM " . TB_PREFIX . "users where tribe = $tribe"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } function getUserByAlliance($aid){ $q = "SELECT * FROM " . TB_PREFIX . "users where alliance = $aid"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } function getHeroRanking() { $q = "SELECT * FROM " . TB_PREFIX . "hero WHERE dead = 0"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } function getAllMember($aid) { $q = "SELECT * FROM " . TB_PREFIX . "users where alliance = $aid order by (SELECT sum(pop) FROM " . TB_PREFIX . "vdata WHERE owner = " . TB_PREFIX . "users.id) desc, " . TB_PREFIX . "users.id desc"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } function getAllMember2($aid) { $q = "SELECT * FROM " . TB_PREFIX . "users where alliance = $aid order by (SELECT sum(pop) FROM " . TB_PREFIX . "vdata WHERE owner = " . TB_PREFIX . "users.id) desc, " . TB_PREFIX . "users.id desc LIMIT 1"; - $result = mysqli_query($this->connection, $q); - return mysqli_fetch_array($result, MYSQLI_BOTH); + $result = mysqli_query($q, $this->connection); + return mysqli_fetch_array($result); } function addUnits($vid) { $q = "INSERT into " . TB_PREFIX . "units (vref) values ($vid)"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function getUnit($vid) { $q = "SELECT * from " . TB_PREFIX . "units where vref = $vid"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); if (!empty($result)) { - return mysqli_fetch_assoc($result); + return mysql_fetch_assoc($result); } else { return NULL; } @@ -2345,8 +2494,8 @@ class MYSQLi_DB { function getUnitsNumber($vid) { $q = "SELECT * from " . TB_PREFIX . "units where vref = $vid"; - $result = mysqli_query($this->connection, $q); - $dbarray = mysqli_fetch_assoc($result); + $result = mysqli_query($q, $this->connection); + $dbarray = mysql_fetch_assoc($result); $totalunits = 0; $movingunits = $this->getVillageMovement($vid); for($i=1;$i<=50;$i++){ @@ -2376,7 +2525,7 @@ class MYSQLi_DB { } else { $q = "SELECT * FROM ".TB_PREFIX."hero WHERE dead=0 AND uid=$uid LIMIT 1"; } - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); if (!empty($result)) { return $this->mysqli_fetch_all($result); } else { @@ -2398,7 +2547,7 @@ class MYSQLi_DB { } else { $q = "UPDATE `".TB_PREFIX."hero` SET $column = $column - $value WHERE heroid = $heroid"; } - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function modifyHeroByOwner($column,$value,$uid,$mode=0) { @@ -2409,64 +2558,64 @@ class MYSQLi_DB { } else { $q = "UPDATE `".TB_PREFIX."hero` SET $column = $column - $value WHERE uid = $uid"; } - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function modifyHeroXp($column,$value,$heroid) { $q = "UPDATE ".TB_PREFIX."hero SET $column = $column + $value WHERE uid=$heroid"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function addTech($vid) { $q = "INSERT into " . TB_PREFIX . "tdata (vref) values ($vid)"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function addABTech($vid) { $q = "INSERT into " . TB_PREFIX . "abdata (vref) values ($vid)"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function getABTech($vid) { $q = "SELECT * FROM " . TB_PREFIX . "abdata where vref = $vid"; - $result = mysqli_query($this->connection, $q); - return mysqli_fetch_assoc($result); + $result = mysqli_query($q, $this->connection); + return mysql_fetch_assoc($result); } function addResearch($vid, $tech, $time) { $q = "INSERT into " . TB_PREFIX . "research values (0,$vid,'$tech',$time)"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function getResearching($vid) { $q = "SELECT * FROM " . TB_PREFIX . "research where vref = $vid"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } function checkIfResearched($vref, $unit) { $q = "SELECT $unit FROM " . TB_PREFIX . "tdata WHERE vref = $vref"; - $result = mysqli_query($this->connection, $q) or die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error()); - $dbarray = mysqli_fetch_array($result, MYSQLI_BOTH); + $result = mysqli_query($q, $this->connection) or die(mysql_error()); + $dbarray = mysqli_fetch_array($result); return $dbarray[$unit]; } function getTech($vid) { $q = "SELECT * from " . TB_PREFIX . "tdata where vref = $vid"; - $result = mysqli_query($this->connection, $q); - return mysqli_fetch_assoc($result); + $result = mysqli_query($q, $this->connection); + return mysql_fetch_assoc($result); } function getTraining($vid) { $q = "SELECT * FROM " . TB_PREFIX . "training where vref = $vid ORDER BY id"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } function countTraining($vid) { $q = "SELECT * FROM " . TB_PREFIX . "training WHERE vref = $vid"; - $result = mysqli_query($this->connection, $q); - $row = mysqli_fetch_row($result); + $result = mysqli_query($q, $this->connection); + $row = mysql_fetch_row($result); return $row[0]; } @@ -2475,6 +2624,7 @@ class MYSQLi_DB { if(!$mode) { $barracks = array(1,2,3,11,12,13,14,21,22,31,32,33,34,35,36,37,38,39,40,41,42,43,44); + // fix by brainiac - THANK YOU $greatbarracks = array(61,62,63,71,72,73,74,81,82,91,92,93,94,95,96,97,98,99,100,101,102,103,104); $stables = array(4,5,6,15,16,23,24,25,26,45,46); $greatstables = array(64,65,66,75,76,83,84,85,86,105,106); @@ -2538,16 +2688,22 @@ class MYSQLi_DB { $time += $queued[count($queued) - 1]['timestamp'] - $now; $time2 += $queued[count($queued) - 1]['timestamp'] - $now; } + // TROOPS MAKE SUM IN BARAKS , ETC + //if($queued[count($queued) - 1]['unit'] == $unit){ + //$time = $amt*$queued[count($queued) - 1]['eachtime']; + //$q = "UPDATE " . TB_PREFIX . "training SET amt = amt + $amt, timestamp = timestamp + $time WHERE id = ".$queued[count($queued) - 1]['id'].""; + //}else{ $q = "INSERT INTO " . TB_PREFIX . "training values (0,$vid,$unit,$amt,$pop,$time,$each,$time2)"; + //} } else { $q = "DELETE FROM " . TB_PREFIX . "training where id = $vid"; } - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function updateTraining($id, $trained, $each) { $q = "UPDATE " . TB_PREFIX . "training set amt = amt - $trained, timestamp2 = timestamp2 + $each where id = $id"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function modifyUnit($vref, $array_unit, $array_amt, $array_mode){ @@ -2561,25 +2717,52 @@ class MYSQLi_DB { if($unit == 121){$unit = 21;} if($unit =="hero"){$unit = 'hero';} else{$unit = 'u' . $unit;} - - ++$i; - $units .= $unit.' = '.$unit.' '.(($array_mode[$i] == 1)? '+':'-').' '.$array_amt[$i].(($number > $i+1) ? ', ' : ''); + ++$i; + //Fixed part of negativ troops (double troops) - by InCube + $array_amt[$i] = $array_amt[$i] < 0 ? 0 : $array_amt[$i]; + //Fixed part of negativ troops (double troops) - by InCube + $units .= $unit.' = '.$unit.' '.(($array_mode[$i] == 1)? '+':'-').' '.$array_amt[$i].(($number > $i+1) ? ', ' : ''); } - $q = "UPDATE ".TB_PREFIX."units set $units WHERE vref = $vref"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function getEnforce($vid, $from) { $q = "SELECT * from " . TB_PREFIX . "enforcement where `from` = $from and vref = $vid"; - $result = mysqli_query($this->connection, $q); - return mysqli_fetch_assoc($result); + $result = mysqli_query($q, $this->connection); + return mysql_fetch_assoc($result); } + + function getOasisEnforce($ref, $mode=0) { + if (!$mode) { + $q = "SELECT e.*,o.conqured FROM ".TB_PREFIX."enforcement as e LEFT JOIN ".TB_PREFIX."odata as o ON e.vref=o.wref where o.conqured = $ref AND e.from !=$ref"; + }else{ + $q = "SELECT e.*,o.conqured FROM ".TB_PREFIX."enforcement as e LEFT JOIN ".TB_PREFIX."odata as o ON e.vref=o.wref where o.conqured = $ref"; + } + $result = mysqli_query($q, $this->connection); + return $this->mysqli_fetch_all($result); + } + + function getOasisEnforceArray($id, $mode=0) { + if (!$mode) { + $q = "SELECT e.*,o.conqured FROM ".TB_PREFIX."enforcement as e LEFT JOIN ".TB_PREFIX."odata as o ON e.vref=o.wref where e.id = $id"; + }else{ + $q = "SELECT e.*,o.conqured FROM ".TB_PREFIX."enforcement as e LEFT JOIN ".TB_PREFIX."odata as o ON e.from=o.wref where e.id =$id"; + } + $result = mysqli_query($q, $this->connection); + return mysql_fetch_assoc($result); + } + + function getEnforceControllTroops($vid) { + $q = "SELECT * from " . TB_PREFIX . "enforcement where vref = $vid"; + $result = mysqli_query($q, $this->connection); + return mysql_fetch_assoc($result); + } function addEnforce($data) { $q = "INSERT into " . TB_PREFIX . "enforcement (vref,`from`) values (" . $data['to'] . "," . $data['from'] . ")"; - mysqli_query($this->connection, $q); - $id = mysqli_insert_id($this->connection); + mysqli_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); @@ -2590,13 +2773,13 @@ class MYSQLi_DB { $j++; } $this->modifyEnforce($id,'hero',$data['t11'],1); - return mysqli_insert_id($this->connection); + 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'] . ")"; - mysqli_query($this->connection, $q); - $id = mysqli_insert_id($this->connection); + mysqli_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); @@ -2615,7 +2798,7 @@ class MYSQLi_DB { } $this->modifyEnforce($id,'hero',$data['t11'],1); $this->modifyEnforce($id,'hero',$dead11,0); - return mysqli_insert_id($this->connection); + return mysql_insert_id($this->connection); } function modifyEnforce($id, $unit, $amt, $mode) { @@ -2625,7 +2808,7 @@ class MYSQLi_DB { } else { $q = "UPDATE " . TB_PREFIX . "enforcement set $unit = $unit + $amt where id = $id"; } - mysqli_query($this->connection, $q); + mysqli_query($q, $this->connection); } function getEnforceArray($id, $mode) { @@ -2634,8 +2817,8 @@ class MYSQLi_DB { } else { $q = "SELECT * from " . TB_PREFIX . "enforcement where `from` = $id"; } - $result = mysqli_query($this->connection, $q); - return mysqli_fetch_assoc($result); + $result = mysqli_query($q, $this->connection); + return mysql_fetch_assoc($result); } function getEnforceVillage($id, $mode) { @@ -2644,7 +2827,7 @@ class MYSQLi_DB { } else { $q = "SELECT * from " . TB_PREFIX . "enforcement where `from` = $id"; } - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } @@ -2690,8 +2873,8 @@ class MYSQLi_DB { function getWW() { $q = "SELECT * FROM " . TB_PREFIX . "fdata WHERE f99t = 40"; - $result = mysqli_query($this->connection, $q); - if(mysqli_num_rows($result)) { + $result = mysqli_query($q, $this->connection); + if(mysql_num_rows($result)) { return true; } else { return false; @@ -2705,8 +2888,8 @@ class MYSQLi_DB { function getWWLevel($vref) { $q = "SELECT f99 FROM " . TB_PREFIX . "fdata WHERE vref = $vref"; - $result = mysqli_query($this->connection, $q) or die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error()); - $dbarray = mysqli_fetch_array($result, MYSQLI_BOTH); + $result = mysqli_query($q, $this->connection) or die(mysql_error()); + $dbarray = mysqli_fetch_array($result); return $dbarray['f99']; } @@ -2717,8 +2900,8 @@ class MYSQLi_DB { function getWWOwnerID($vref) { $q = "SELECT owner FROM " . TB_PREFIX . "vdata WHERE wref = $vref"; - $result = mysqli_query($this->connection, $q) or die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error()); - $dbarray = mysqli_fetch_array($result, MYSQLI_BOTH); + $result = mysqli_query($q, $this->connection) or die(mysql_error()); + $dbarray = mysqli_fetch_array($result); return $dbarray['owner']; } @@ -2729,8 +2912,8 @@ class MYSQLi_DB { function getUserAllianceID($id) { $q = "SELECT alliance FROM " . TB_PREFIX . "users where id = $id"; - $result = mysqli_query($this->connection, $q) or die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error()); - $dbarray = mysqli_fetch_array($result, MYSQLI_BOTH); + $result = mysqli_query($q, $this->connection) or die(mysql_error()); + $dbarray = mysqli_fetch_array($result); return $dbarray['alliance']; } @@ -2741,8 +2924,8 @@ class MYSQLi_DB { function getWWName($vref) { $q = "SELECT wwname FROM " . TB_PREFIX . "fdata WHERE vref = $vref"; - $result = mysqli_query($this->connection, $q) or die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error()); - $dbarray = mysqli_fetch_array($result, MYSQLI_BOTH); + $result = mysqli_query($q, $this->connection) or die(mysql_error()); + $dbarray = mysqli_fetch_array($result); return $dbarray['wwname']; } @@ -2753,80 +2936,80 @@ class MYSQLi_DB { function submitWWname($vref, $name) { $q = "UPDATE " . TB_PREFIX . "fdata SET `wwname` = '$name' WHERE " . TB_PREFIX . "fdata.`vref` = $vref"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } //medal functions function addclimberpop($user, $cp) { $q = "UPDATE " . TB_PREFIX . "users set Rc = Rc + '$cp' where id = $user"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function addclimberrankpop($user, $cp) { $q = "UPDATE " . TB_PREFIX . "users set clp = clp + '$cp' where id = $user"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function removeclimberrankpop($user, $cp) { $q = "UPDATE " . TB_PREFIX . "users set clp = clp - '$cp' where id = $user"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function setclimberrankpop($user, $cp) { $q = "UPDATE " . TB_PREFIX . "users set clp = '$cp' where id = $user"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function updateoldrank($user, $cp) { $q = "UPDATE " . TB_PREFIX . "users set oldrank = '$cp' where id = $user"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function removeclimberpop($user, $cp) { $q = "UPDATE " . TB_PREFIX . "users set Rc = Rc - '$cp' where id = $user"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } // ALLIANCE MEDAL FUNCTIONS function addclimberpopAlly($user, $cp) { $q = "UPDATE " . TB_PREFIX . "alidata set Rc = Rc + '$cp' where id = $user"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function addclimberrankpopAlly($user, $cp) { $q = "UPDATE " . TB_PREFIX . "alidata set clp = clp + '$cp' where id = $user"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function removeclimberrankpopAlly($user, $cp) { $q = "UPDATE " . TB_PREFIX . "alidata set clp = clp - '$cp'' where id = $user"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function updateoldrankAlly($user, $cp) { $q = "UPDATE " . TB_PREFIX . "alidata set oldrank = '$cp' where id = $user"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function removeclimberpopAlly($user, $cp) { $q = "UPDATE " . TB_PREFIX . "alidata set Rc = Rc - '$cp' where id = $user"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function getTrainingList() { $q = "SELECT * FROM " . TB_PREFIX . "training where vref != ''"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } function getNeedDelete() { $time = time(); $q = "SELECT uid FROM " . TB_PREFIX . "deleting where timestamp < $time"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } function countUser() { $q = "SELECT count(id) FROM " . TB_PREFIX . "users where id > 5"; - $result = mysqli_query($this->connection, $q); - $row = mysqli_fetch_row($result); + $result = mysqli_query($q, $this->connection); + $row = mysql_fetch_row($result); return $row[0]; } function countAlli() { $q = "SELECT count(id) FROM " . TB_PREFIX . "alidata where id != 0"; - $result = mysqli_query($this->connection, $q); - $row = mysqli_fetch_row($result); + $result = mysqli_query($q, $this->connection); + $row = mysql_fetch_row($result); return $row[0]; } @@ -2837,7 +3020,7 @@ class MYSQLi_DB { function mysqli_fetch_all($result) { $all = array(); if($result) { - while($row = mysqli_fetch_assoc($result)) { + while($row = mysql_fetch_assoc($result)) { $all[] = $row; } return $all; @@ -2845,7 +3028,7 @@ class MYSQLi_DB { } function query_return($q) { - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } @@ -2864,43 +3047,43 @@ class MYSQLi_DB { //MARKET FIXES function getWoodAvailable($wref) { $q = "SELECT wood FROM " . TB_PREFIX . "vdata WHERE wref = $wref"; - $result = mysqli_query($this->connection, $q) or die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error()); - $dbarray = mysqli_fetch_array($result, MYSQLI_BOTH); + $result = mysqli_query($q, $this->connection) or die(mysql_error()); + $dbarray = mysqli_fetch_array($result); return $dbarray['wood']; } function getClayAvailable($wref) { $q = "SELECT clay FROM " . TB_PREFIX . "vdata WHERE wref = $wref"; - $result = mysqli_query($this->connection, $q) or die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error()); - $dbarray = mysqli_fetch_array($result, MYSQLI_BOTH); + $result = mysqli_query($q, $this->connection) or die(mysql_error()); + $dbarray = mysqli_fetch_array($result); return $dbarray['clay']; } function getIronAvailable($wref) { $q = "SELECT iron FROM " . TB_PREFIX . "vdata WHERE wref = $wref"; - $result = mysqli_query($this->connection, $q) or die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error()); - $dbarray = mysqli_fetch_array($result, MYSQLI_BOTH); + $result = mysqli_query($q, $this->connection) or die(mysql_error()); + $dbarray = mysqli_fetch_array($result); return $dbarray['iron']; } function getCropAvailable($wref) { $q = "SELECT crop FROM " . TB_PREFIX . "vdata WHERE wref = $wref"; - $result = mysqli_query($this->connection, $q) or die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error()); - $dbarray = mysqli_fetch_array($result, MYSQLI_BOTH); + $result = mysqli_query($q, $this->connection) or die(mysql_error()); + $dbarray = mysqli_fetch_array($result); return $dbarray['crop']; } function Getowner($vid) { $s = "SELECT owner FROM " . TB_PREFIX . "vdata where wref = $vid"; $result1 = mysqli_query($s, $this->connection); - $row1 = mysqli_fetch_row($result1); + $row1 = mysql_fetch_row($result1); return $row1[0]; } public function debug($time, $uid, $debug_info) { $q = "INSERT INTO " . TB_PREFIX . "debug_info (time,uid,debug_info) VALUES ($time,$uid,$debug_info)"; - if(mysqli_query($this->connection, $q)) { - return mysqli_insert_id($this->connection); + if(mysqli_query($q, $this->connection)) { + return mysql_insert_id($this->connection); } else { return false; } @@ -2908,21 +3091,28 @@ class MYSQLi_DB { function populateOasisdata() { $q2 = "SELECT * FROM " . TB_PREFIX . "wdata where oasistype != 0"; - $result2 = mysqli_query($this->connection, $q2); - while($row = mysql_fetch_array($result2)) { + $result2 = mysqli_query($q2, $this->connection); + 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'] . "'," . $basearray['oasistype'] . ",0,800,800,800,800,800,800," . time() . "," . time() . ",100,2,'Unoccupied Oasis',".rand(0,2).")"; - $result = mysqli_query($this->connection, $q); + $q = "INSERT into " . TB_PREFIX . "odata VALUES ('" . $basearray['id'] . "'," . $basearray['oasistype'] . ",0,800,800,800,800,800,800," . time() . "," . time() . ",100,2,'Unoccupied Oasis',".$high.")"; + $result = mysqli_query($q, $this->connection); } } public function getAvailableExpansionTraining() { global $building, $session, $technology, $village; $q = "SELECT (IF(exp1=0,1,0)+IF(exp2=0,1,0)+IF(exp3=0,1,0)) FROM " . TB_PREFIX . "vdata WHERE wref = $village->wid"; - $result = mysqli_query($this->connection, $q); - $row = mysqli_fetch_row($result); + $result = mysqli_query($q, $this->connection); + $row = mysql_fetch_row($result); $maxslots = $row[0]; $residence = $building->getTypeLevel(25); $palace = $building->getTypeLevel(26); @@ -2934,12 +3124,12 @@ class MYSQLi_DB { } $q = "SELECT (u10+u20+u30) FROM " . TB_PREFIX . "units WHERE vref = $village->wid"; - $result = mysqli_query($this->connection, $q); - $row = mysqli_fetch_row($result); + $result = mysqli_query($q, $this->connection); + $row = mysql_fetch_row($result); $settlers = $row[0]; $q = "SELECT (u9+u19+u29) FROM " . TB_PREFIX . "units WHERE vref = $village->wid"; - $result = mysqli_query($this->connection, $q); - $row = mysqli_fetch_row($result); + $result = mysqli_query($q, $this->connection); + $row = mysql_fetch_row($result); $chiefs = $row[0]; $settlers += 3 * count($this->getMovement(5, $village->wid, 0)); @@ -2972,16 +3162,16 @@ class MYSQLi_DB { } } $q = "SELECT (u10+u20+u30) FROM " . TB_PREFIX . "enforcement WHERE `from` = $village->wid"; - $result = mysqli_query($this->connection, $q); - $row = mysqli_fetch_row($result); + $result = mysqli_query($q, $this->connection); + $row = mysql_fetch_row($result); if(!empty($row)) { foreach($row as $reinf) { $settlers += $reinf[0]; } } $q = "SELECT (u9+u19+u29) FROM " . TB_PREFIX . "enforcement WHERE `from` = $village->wid"; - $result = mysqli_query($this->connection, $q); - $row = mysqli_fetch_row($result); + $result = mysqli_query($q, $this->connection); + $row = mysql_fetch_row($result); if(!empty($row)) { foreach($row as $reinf) { $chiefs += $reinf[0]; @@ -3012,43 +3202,43 @@ class MYSQLi_DB { function addArtefact($vref, $owner, $type, $size, $name, $desc, $effect, $img) { $q = "INSERT INTO `" . TB_PREFIX . "artefacts` (`vref`, `owner`, `type`, `size`, `conquered`, `name`, `desc`, `effect`, `img`, `active`) VALUES ('$vref', '$owner', '$type', '$size', '" . time() . "', '$name', '$desc', '$effect', '$img', '0')"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function getOwnArtefactInfo($vref) { $q = "SELECT * FROM " . TB_PREFIX . "artefacts WHERE vref = $vref"; - $result = mysqli_query($this->connection, $q); - return mysqli_fetch_array($result, MYSQLI_BOTH); + $result = mysqli_query($q, $this->connection); + return mysqli_fetch_array($result); } function getOwnArtefactInfo2($vref) { $q = "SELECT * FROM " . TB_PREFIX . "artefacts WHERE vref = $vref"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } function getOwnArtefactInfo3($uid) { $q = "SELECT * FROM " . TB_PREFIX . "artefacts WHERE owner = $uid"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } function getOwnArtefactInfoByType($vref, $type) { $q = "SELECT * FROM " . TB_PREFIX . "artefacts WHERE vref = $vref AND type = $type order by size"; - $result = mysqli_query($this->connection, $q); - return mysqli_fetch_array($result, MYSQLI_BOTH); + $result = mysqli_query($q, $this->connection); + return mysqli_fetch_array($result); } function getOwnArtefactInfoByType2($vref, $type) { $q = "SELECT * FROM " . TB_PREFIX . "artefacts WHERE vref = $vref AND type = $type"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } function getOwnUniqueArtefactInfo($id, $type, $size) { $q = "SELECT * FROM " . TB_PREFIX . "artefacts WHERE owner = $id AND type = $type AND size=$size"; - $result = mysqli_query($this->connection, $q); - return mysqli_fetch_array($result, MYSQLI_BOTH); + $result = mysqli_query($q, $this->connection); + return mysqli_fetch_array($result); } function getOwnUniqueArtefactInfo2($id, $type, $size, $mode) { @@ -3057,89 +3247,100 @@ class MYSQLi_DB { }else{ $q = "SELECT * FROM " . TB_PREFIX . "artefacts WHERE vref = $id AND active = 1 AND type = $type AND size=$size"; } - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } function getFoolArtefactInfo($type,$vid,$uid) { $q = "SELECT * FROM " . TB_PREFIX . "artefacts WHERE vref = $vid AND type = 8 AND kind = $type OR owner = $uid AND size > 1 AND active = 1 AND type = 8 AND kind = $type"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } function claimArtefact($vref, $ovref, $id) { $time = time(); $q = "UPDATE " . TB_PREFIX . "artefacts SET vref = $vref, owner = $id, conquered = $time, active = 1 WHERE vref = $ovref"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } - public function canClaimArtifact($from,$vref,$type,$kind) { - $type2 = $type3 = 0; - if(count($this->getOwnUniqueArtefactInfo2($this->getVillagefield($from,"owner"),2,2,0)) > 0 && $type == 2){ - $type2 = 1; - } - if(count($this->getOwnUniqueArtefactInfo2($this->getVillagefield($from,"owner"),2,3,0)) > 0 && $type == 3){ - $type3 = 1; - } - if((count($this->getOwnArtefactInfo2($from)) < 3 && $type2 == 0 && $type3 == 0) or $kind == 11){ - $DefenderFields = $this->getResourceLevel($vref); - $defcanclaim = TRUE; - for($i=19;$i<=38;$i++) { - if($DefenderFields['f'.$i.'t'] == 27) { - $defTresuaryLevel = $DefenderFields['f'.$i]; - if($defTresuaryLevel > 0) { - $defcanclaim = FALSE; - } else { - $defcanclaim = TRUE; - } - } - } - $AttackerFields = $this->getResourceLevel($from); - for($i=19;$i<=38;$i++) { - if($AttackerFields['f'.$i.'t'] == 27) { - $attTresuaryLevel = $AttackerFields['f'.$i]; - if ($attTresuaryLevel >= 10) { - $villageartifact = TRUE; - } else { - $villageartifact = FALSE; - } - if ($attTresuaryLevel >= 20){ - $accountartifact = TRUE; - } else { - $accountartifact = FALSE; - } - } - } - if ($type == 1) { - if ($defcanclaim == TRUE && $villageartifact == TRUE) { - return TRUE; - } else { - return FALSE; - } - } else if ($type == 2) { - if ($defcanclaim == TRUE && $accountartifact == TRUE) { - return TRUE; - } else { - return FALSE; - } - } else if ($type == 3) { - if ($defcanclaim == TRUE && $accountartifact == TRUE) { - return TRUE; - } else { - return FALSE; - } - } else { - return FALSE; - } - }else{ - return FALSE; - } - } + public function canClaimArtifact($from,$vref,$size,$type) { + //fix by Ronix + global $session, $form; + $size1 = $size2 = $size3 = 0; + + $artifact = $this->getOwnArtefactInfo($from); + if (!empty($artifact)) { + $form->addError("error","Treasury is full. Your hero could not claim the artefact"); + return false; + } + $uid=$session->uid; + $q="SELECT Count(size) AS totals, + SUM(IF(size = '1',1,0)) small, + SUM(IF(size = '2',1,0)) great, + SUM(IF(size = '3',1,0)) `unique` + FROM ".TB_PREFIX."artefacts WHERE owner = ".$uid; + $result = mysqli_query($q, $this->connection); + $artifact= $this->mysqli_fetch_all($result); + + if($artifact['totals'] < 3 || $type==11) { + $DefenderFields = $this->getResourceLevel($vref); + $defcanclaim = TRUE; + for($i=19;$i<=38;$i++) { + if($DefenderFields['f'.$i.'t'] == 27) { + $defTresuaryLevel = $DefenderFields['f'.$i]; + if($defTresuaryLevel > 0) { + $defcanclaim = FALSE; + $form->addError("error","Treasury has not been destroyed. Your hero could not claim the artefact"); + return false; + } else { + $defcanclaim = TRUE; + } + } + } + $AttackerFields = $this->getResourceLevel($from,2); + for($i=19;$i<=38;$i++) { + if($AttackerFields['f'.$i.'t'] == 27) { + $attTresuaryLevel = $AttackerFields['f'.$i]; + if ($attTresuaryLevel >= 10) { + $villageartifact = TRUE; + } else { + $villageartifact = FALSE; + } + if ($attTresuaryLevel >= 20){ + $accountartifact = TRUE; + } else { + $accountartifact = FALSE; + } + } + } + if (($artifact['great']>0 || $artifact['unique']>0) && $size>1) { + $form->addError("error","Max num. of great/unique artefacts. Your hero could not claim the artefact"); + return FALSE; + } + if (($size == 1 && ($villageartifact || $accountartifact)) || (($size == 2 || $size == 3)&& $accountartifact)) { + return true; +/* + if($this->getVillageField($from,"capital")==1 && $type==11) { + $form->addError("error","Ancient Construction Plan cannot kept in capital village"); + return FALSE; + }else{ + return TRUE; + } +*/ + } else { + $form->addError("error","Your level treasury is low. Your hero could not claim the artefact"); + return FALSE; + } + } else { + $form->addError("error","Max num. of artefacts. Your hero could not claim the artefact"); + return FALSE; + } +} function getArtefactDetails($id) { $q = "SELECT * FROM " . TB_PREFIX . "artefacts WHERE id = " . $id . ""; - $result = mysqli_query($this->connection, $q); - return mysqli_fetch_array($result, MYSQLI_BOTH); + $result = mysqli_query($q, $this->connection); + return mysqli_fetch_array($result); } function getMovementById($id){ @@ -3151,18 +3352,18 @@ class MYSQLi_DB { function getLinks($id){ $q = 'SELECT * FROM `' . TB_PREFIX . 'links` WHERE `userid` = ' . $id . ' ORDER BY `pos` ASC'; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function removeLinks($id,$uid){ $q = "DELETE FROM " . TB_PREFIX . "links WHERE `id` = ".$id." and `userid` = ".$uid.""; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function getVilFarmlist($wref){ $q = 'SELECT * FROM ' . TB_PREFIX . 'farmlist WHERE wref = ' . $wref . ' ORDER BY wref ASC'; - $result = mysqli_query($this->connection, $q); - $dbarray = mysqli_fetch_array($result, MYSQLI_BOTH); + $result = mysqli_query($q, $this->connection); + $dbarray = mysqli_fetch_array($result); if($dbarray['id']!=0) { return true; @@ -3174,56 +3375,56 @@ class MYSQLi_DB { function getRaidList($id) { $q = "SELECT * FROM " . TB_PREFIX . "raidlist WHERE id = ".$id.""; - $result = mysqli_query($this->connection, $q); - return mysqli_fetch_array($result, MYSQLI_BOTH); + $result = mysqli_query($q, $this->connection); + return mysqli_fetch_array($result); } function delFarmList($id, $owner) { $q = "DELETE FROM " . TB_PREFIX . "farmlist where id = $id and owner = $owner"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function delSlotFarm($id) { $q = "DELETE FROM " . TB_PREFIX . "raidlist where id = $id"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function createFarmList($wref, $owner, $name) { $q = "INSERT INTO " . TB_PREFIX . "farmlist (`wref`, `owner`, `name`) VALUES ('$wref', '$owner', '$name')"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function addSlotFarm($lid, $towref, $x, $y, $distance, $t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10) { $q = "INSERT INTO " . TB_PREFIX . "raidlist (`lid`, `towref`, `x`, `y`, `distance`, `t1`, `t2`, `t3`, `t4`, `t5`, `t6`, `t7`, `t8`, `t9`, `t10`) VALUES ('$lid', '$towref', '$x', '$y', '$distance', '$t1', '$t2', '$t3', '$t4', '$t5', '$t6', '$t7', '$t8', '$t9', '$t10')"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function editSlotFarm($eid, $lid, $wref, $x, $y, $dist, $t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10) { $q = "UPDATE " . TB_PREFIX . "raidlist set lid = '$lid', towref = '$wref', x = '$x', y = '$y', t1 = '$t1', t2 = '$t2', t3 = '$t3', t4 = '$t4', t5 = '$t5', t6 = '$t6', t7 = '$t7', t8 = '$t8', t9 = '$t9', t10 = '$t10' WHERE id = $eid"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function getArrayMemberVillage($uid){ $q = 'SELECT a.wref, a.name, b.x, b.y from '.TB_PREFIX.'vdata AS a left join '.TB_PREFIX.'wdata AS b ON b.id = a.wref where owner = '.$uid.' order by capital DESC,pop DESC'; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); $array = $this->mysqli_fetch_all($result); return $array; } function addPassword($uid, $npw, $cpw){ $q = "REPLACE INTO `" . TB_PREFIX . "password`(uid, npw, cpw) VALUES ($uid, '$npw', '$cpw')"; - mysqli_query($this->connection, $q) or die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error()); + mysqli_query($q, $this->connection) or die(mysql_error()); } function resetPassword($uid, $cpw){ $q = "SELECT npw FROM `" . TB_PREFIX . "password` WHERE uid = $uid AND cpw = '$cpw' AND used = 0"; - $result = mysqli_query($this->connection, $q) or die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error()); - $dbarray = mysqli_fetch_array($result, MYSQLI_BOTH); + $result = mysqli_query($q, $this->connection) or die(mysql_error()); + $dbarray = mysqli_fetch_array($result); if(!empty($dbarray)) { if(!$this->updateUserField($uid, 'password', md5($dbarray['npw']), 1)) return false; $q = "UPDATE `" . TB_PREFIX . "password` SET used = 1 WHERE uid = $uid AND cpw = '$cpw' AND used = 0"; - mysqli_query($this->connection, $q) or die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error()); + mysqli_query($q, $this->connection) or die(mysql_error()); return true; } @@ -3235,7 +3436,7 @@ class MYSQLi_DB { $basecrop = $grainmill = $bakery = 0; $owner = $this->getVrefField($wref, 'owner'); - $bonus = $this->getUserField($owner, b4, 0); + $bonus = $this->getUserField($owner, 'b4', 0); $buildarray = $this->getResourceLevel($wref); $cropholder = array(); @@ -3304,7 +3505,7 @@ class MYSQLi_DB { function addGeneralAttack($casualties) { $time = time(); $q = "INSERT INTO " . TB_PREFIX . "general values (0,'$casualties','$time',1)"; - return mysqli_query($this->connection, $q) or die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error()); + return mysqli_query($q, $this->connection) or die(mysql_error()); } function getAttackByDate($time) { @@ -3335,12 +3536,12 @@ class MYSQLi_DB { function addFriend($uid, $column, $friend) { $q = "UPDATE " . TB_PREFIX . "users SET $column = $friend WHERE id = $uid"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function deleteFriend($uid, $column) { $q = "UPDATE " . TB_PREFIX . "users SET $column = 0 WHERE id = $uid"; - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function checkFriends($uid) { @@ -3371,50 +3572,297 @@ class MYSQLi_DB { }else{ $q = "UPDATE " . TB_PREFIX . "vdata SET evasion = 0 WHERE wref = $vid"; } - return mysqli_query($this->connection, $q); + return mysqli_query($q, $this->connection); } function addPrisoners($wid,$from,$t1,$t2,$t3,$t4,$t5,$t6,$t7,$t8,$t9,$t10,$t11) { $q = "INSERT INTO " . TB_PREFIX . "prisoners values (0,$wid,$from,$t1,$t2,$t3,$t4,$t5,$t6,$t7,$t8,$t9,$t10,$t11)"; - mysqli_query($this->connection, $q); - return mysqli_insert_id($this->connection); + mysqli_query($q, $this->connection); + return mysql_insert_id($this->connection); } function updatePrisoners($wid,$from,$t1,$t2,$t3,$t4,$t5,$t6,$t7,$t8,$t9,$t10,$t11) { - $q = "UPDATE " . TB_PREFIX . "prisoners set t1 = t1 + $t1, t2 = t2 + $t2, t3 = t3 + $t3, t4 = t4 + $t4, t5 = t5 + $t5, t6 = t6 + $t6, t7 = t7 + $t7, t8 = t8 + $t8, t9 = t9 + $t9, t10 = t10 + $t10, t11 = t11 + $t11 where wid = $wid and from = $from"; - return mysqli_query($this->connection, $q) or die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error()); - } + $q = "UPDATE " . TB_PREFIX . "prisoners set t1 = t1 + $t1, t2 = t2 + $t2, t3 = t3 + $t3, t4 = t4 + $t4, t5 = t5 + $t5, t6 = t6 + $t6, t7 = t7 + $t7, t8 = t8 + $t8, t9 = t9 + $t9, t10 = t10 + $t10, t11 = t11 + $t11 where wref = $wid and ".TB_PREFIX."prisoners.from = $from"; + return mysqli_query($q, $this->connection) or die(mysql_error()); + } - function getPrisoners($wid) { - $q = "SELECT * FROM " . TB_PREFIX . "prisoners where wref = $wid"; - $result = mysqli_query($this->connection, $q); - return $this->mysqli_fetch_all($result); - } + function getPrisoners($wid,$mode=0) { + if(!$mode) { + $q = "SELECT * FROM " . TB_PREFIX . "prisoners where wref = $wid"; + }else { + $q = "SELECT * FROM " . TB_PREFIX . "prisoners where `from` = $wid"; + } + $result = mysqli_query($q, $this->connection); + return $this->mysqli_fetch_all($result); + } function getPrisoners2($wid,$from) { $q = "SELECT * FROM " . TB_PREFIX . "prisoners where wref = $wid and " . TB_PREFIX . "prisoners.from = $from"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } function getPrisonersByID($id) { $q = "SELECT * FROM " . TB_PREFIX . "prisoners where id = $id"; - $result = mysqli_query($this->connection, $q); - return mysqli_fetch_array($result, MYSQLI_BOTH); + $result = mysqli_query($q, $this->connection); + return mysqli_fetch_array($result); } function getPrisoners3($from) { $q = "SELECT * FROM " . TB_PREFIX . "prisoners where " . TB_PREFIX . "prisoners.from = $from"; - $result = mysqli_query($this->connection, $q); + $result = mysqli_query($q, $this->connection); return $this->mysqli_fetch_all($result); } function deletePrisoners($id) { $q = "DELETE from " . TB_PREFIX . "prisoners where id = '$id'"; - mysqli_query($this->connection, $q); + mysqli_query($q, $this->connection); } + +/***************************************** +Function to vacation mode - by advocaite +References: +*****************************************/ + + function setvacmode($uid,$days){ + $days1 =60*60*24*$days; + $time =time()+$days1; + $q ="UPDATE ".TB_PREFIX."users SET vac_mode = '1' , vac_time=".$time." WHERE id=".$uid.""; + $result =mysqli_query($q,$this->connection); + } + + function removevacationmode($uid){ + $q ="UPDATE ".TB_PREFIX."users SET vac_mode = '0' , vac_time='0' WHERE id=".$uid.""; + $result =mysqli_query($q,$this->connection); + } + + function getvacmodexy($wref){ + $q = "SELECT id,oasistype,occupied FROM " . TB_PREFIX . "wdata where id = $wref"; + $result = mysqli_query($q, $this->connection); + $dbarray = mysqli_fetch_array($result); + if($dbarray['occupied'] != 0 && $dbarray['oasistype'] == 0) { + $q1 = "SELECT owner FROM " . TB_PREFIX . "vdata where wref = ".$dbarray['id'].""; + $result1 = mysqli_query($q1, $this->connection); + $dbarray1 = mysqli_fetch_array($result1); + if($dbarray1['owner'] != 0){ + $q2 = "SELECT vac_mode,vac_time FROM " . TB_PREFIX . "users where id = ".$dbarray1['owner'].""; + $result2 = mysqli_query($q2, $this->connection); + $dbarray2 = mysqli_fetch_array($result2); + if($dbarray2['vac_mode'] ==1){ + return true; + }else{ + return false; + } + } + } else { + return false; + } + } + + /***************************************** + Function to vacation mode - by advocaite + References: + *****************************************/ + + /*************************** + Function to get Hero Dead + Made by: Shadow and brainiacX + ***************************/ + + function getHeroDead($id) { + $q = "SELECT dead FROM " . TB_PREFIX . "hero WHERE `uid` = $id"; + $result = mysqli_query($q, $this->connection); + $notend= mysqli_fetch_array($result); + return $notend['dead']; + } + + /*************************** + Function to get Hero In Revive + Made by: Shadow + ***************************/ + + function getHeroInRevive($id) { + $q = "SELECT inrevive FROM " . TB_PREFIX . "hero WHERE `uid` = $id"; + $result = mysqli_query($q, $this->connection); + $notend= mysqli_fetch_array($result); + return $notend['inrevive']; + } + + /*************************** + Function to get Hero In Training + Made by: Shadow + ***************************/ + + function getHeroInTraining($id) { + $q = "SELECT intraining FROM " . TB_PREFIX . "hero WHERE `uid` = $id"; + $result = mysqli_query($q, $this->connection); + $notend= mysqli_fetch_array($result); + return $notend['intraining']; + } + + /*************************** + Function to check Hero Not in Village + Made by: Shadow and brainiacX + ***************************/ + + function HeroNotInVil($id) { + $heronum=0; + $outgoingarray = $this->getMovement(3, $id, 0); + if(!empty($outgoingarray)) { + foreach($outgoingarray as $out) { + $heronum += $out['t11']; + } + } + $returningarray = $this->getMovement(4, $id, 1); + if(!empty($returningarray)) { + foreach($returningarray as $ret) { + if($ret['attack_type'] != 1) { + $heronum += $ret['t11']; + } + } + } + return $heronum; + } + + /*************************** + Function to Kill hero if not found + Made by: Shadow and brainiacX + ***************************/ + + function KillMyHero($id) { + $q = "UPDATE " . TB_PREFIX . "hero set dead = 1 where uid = ".$id; + return mysqli_query($q, $this->connection); + } + + /*************************** + Function to find Hero place + Made by: ronix + ***************************/ + function FindHeroInVil($wid) { + $result = $this->query("SELECT * FROM ".TB_PREFIX."units WHERE hero>0 AND vref='".$wid."'"); + if (!empty($result)) { + $dbarray = mysqli_fetch_array($result); + if(isset($dbarray['hero'])) { + $this->query("UPDATE ".TB_PREFIX."units SET hero=0 WHERE vref='".$wid."'"); + unset($dbarray); + return true; + } + } + return false; + } + function FindHeroInDef($wid) { + $delDef=true; + $result = $this->query_return("SELECT * FROM ".TB_PREFIX."enforcement WHERE hero>0 AND `from` = ".$wid); + if (!empty($result)) { + $dbarray = mysqli_fetch_array($result); + if(isset($dbarray['hero'])) { + $this->query("UPDATE ".TB_PREFIX."enforcement SET hero=0 WHERE `from` = ".$wid); + for ($i=0;$i<50;$i++) { + if($dbarray['u'.$i]>0) { + $delDef=false; + break; + } + } + if ($delDef) $this->deleteReinf($wid); + unset($dbarray); + return true; + } + } + return false; + } + function FindHeroInOasis($uid) { + $delDef=true; + $dbarray = $this->query_return("SELECT e.*,o.conqured,o.owner FROM ".TB_PREFIX."enforcement as e LEFT JOIN ".TB_PREFIX."odata as o ON e.vref=o.wref where o.owner=".$uid." AND e.hero>0"); + if(!empty($dbarray)) { + foreach($dbarray as $defoasis) { + if($defoasis['hero']>0) { + $this->query("UPDATE ".TB_PREFIX."enforcement SET hero=0 WHERE `from` = ".$defoasis['from']); + for ($i=0;$i<50;$i++) { + if($dbarray['u'.$i]>0) { + $delDef=false; + break; + } + } + if ($delDef) $this->deleteReinf($defoasis['from']); + unset($dbarray); + return true; + } + } + } + return 0; + } + + function FindHeroInMovement($wid) { + $outgoingarray = $this->getMovement(3, $wid, 0); + if(!empty($outgoingarray)) { + foreach($outgoingarray as $out) { + if ($out['t11']>0) { + $dbarray = $this->query("UPDATE ".TB_PREFIX."attacks SET t11=0 WHERE `id` = ".$out['ref']); + return true; + break; + } + } + } + $returningarray = $this->getMovement(4, $wid, 1); + if(!empty($returningarray)) { + foreach($returningarray as $ret) { + if($ret['attack_type'] != 1 && $ret['t11']>0) { + $dbarray = $this->query("UPDATE ".TB_PREFIX."attacks SET t11=0 WHERE `id` = ".$ret['ref']); + return true; + break; + } + } + } + return false; + } + + /*************************** + Function checkAttack + Made by: Shadow + ***************************/ + + function checkAttack($wref, $toWref){ + $q = "SELECT * FROM " . TB_PREFIX . "movement, " . TB_PREFIX . "attacks where " . TB_PREFIX . "movement.from = $wref and " . TB_PREFIX . "movement.to = $toWref and " . TB_PREFIX . "movement.ref = " . TB_PREFIX . "attacks.id and " . TB_PREFIX . "movement.proc = 0 and " . TB_PREFIX . "movement.sort_type = 3 and (" . TB_PREFIX . "attacks.attack_type = 3 or " . TB_PREFIX . "attacks.attack_type = 4) ORDER BY endtime ASC"; + $result = mysqli_query($q, $this->connection); + if(mysql_num_rows($result)) { + return true; + } else { + return false; + } + } + + /*************************** + Function checkEnforce + Made by: Shadow + ***************************/ + + function checkEnforce($wref, $toWref) { + $q = "SELECT * FROM " . TB_PREFIX . "movement, " . TB_PREFIX . "attacks where " . TB_PREFIX . "movement.from = $wref and " . TB_PREFIX . "movement.to = $toWref and " . TB_PREFIX . "movement.ref = " . TB_PREFIX . "attacks.id and " . TB_PREFIX . "movement.proc = 0 and " . TB_PREFIX . "movement.sort_type = 3 and " . TB_PREFIX . "attacks.attack_type = 2 ORDER BY endtime ASC"; + $result = mysqli_query($q, $this->connection); + if(mysql_num_rows($result)) { + return true; + }else{ + return false; + } + } + + /*************************** + Function checkScout + Made by: yi12345 + ***************************/ + + function checkScout($wref, $toWref) { + $q = "SELECT * FROM " . TB_PREFIX . "movement, " . TB_PREFIX . "attacks where " . TB_PREFIX . "movement.from = $wref and " . TB_PREFIX . "movement.to = $toWref and " . TB_PREFIX . "movement.ref = " . TB_PREFIX . "attacks.id and " . TB_PREFIX . "movement.proc = 0 and " . TB_PREFIX . "movement.sort_type = 3 and " . TB_PREFIX . "attacks.attack_type = 1 ORDER BY endtime ASC"; + $result = mysqli_query($q, $this->connection); + if(mysql_num_rows($result)) { + return true; + }else{ + return false; + } + } + }; -$database = new MYSQLi_DB; +$database = new MYSQL_DB; ?>