diff --git a/GameEngine/Database/db_MYSQL.php b/GameEngine/Database/db_MYSQL.php index 0862713b..c9501283 100644 --- a/GameEngine/Database/db_MYSQL.php +++ b/GameEngine/Database/db_MYSQL.php @@ -12,285 +12,292 @@ class MYSQL_DB { - var $connection; - function MYSQL_DB() { - $this->connection = mysql_connect(SQL_SERVER, SQL_USER, SQL_PASS) or die(mysql_error()); - mysql_select_db(SQL_DB, $this->connection) or die(mysql_error()); - } + var $connection; + function MYSQL_DB() { + $this->connection = mysql_connect(SQL_SERVER, SQL_USER, SQL_PASS) or die(mysql_error()); + mysql_select_db(SQL_DB, $this->connection) or die(mysql_error()); + } - function register($username, $password, $email, $tribe, $locate, $act) { - $time = time(); - $timep = (time() + PROTECTION); - $q = "INSERT INTO " . TB_PREFIX . "users (username,password,access,email,timestamp,tribe,location,act,protect,regtime) VALUES ('$username', '$password', " . USER . ", '$email', $time, $tribe, $locate, '$act', $timep, $time)"; - if(mysql_query($q, $this->connection)) { - return mysql_insert_id($this->connection); - } else { - return false; - } - } + function register($username, $password, $email, $tribe, $locate, $act) { + $time = time(); + $timep = (time() + PROTECTION); + $q = "INSERT INTO " . TB_PREFIX . "users (username,password,access,email,timestamp,tribe,location,act,protect,regtime) VALUES ('$username', '$password', " . USER . ", '$email', $time, $tribe, $locate, '$act', $timep, $time)"; + if(mysql_query($q, $this->connection)) { + return mysql_insert_id($this->connection); + } else { + return false; + } + } - 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(mysql_query($q, $this->connection)) { - return mysql_insert_id($this->connection); - } else { - return false; - } - } + 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(mysql_query($q, $this->connection)) { + return mysql_insert_id($this->connection); + } else { + return false; + } + } - function unreg($username) { - $q = "DELETE from " . TB_PREFIX . "activate where username = '$username'"; - return mysql_query($q, $this->connection); - } - function deleteReinf($id) { - $q = "DELETE from " . TB_PREFIX . "enforcement where id = '$id'"; - mysql_query($q, $this->connection); - } - function updateResource($vid, $what, $number) { + function unreg($username) { + $q = "DELETE from " . TB_PREFIX . "activate where username = '$username'"; + return mysql_query($q, $this->connection); + } + function deleteReinf($id) { + $q = "DELETE from " . TB_PREFIX . "enforcement where id = '$id'"; + mysql_query($q, $this->connection); + } + function updateResource($vid, $what, $number) { - $q = "UPDATE " . TB_PREFIX . "vdata set " . $what . "=" . $number . " where wref = $vid"; - $result = mysql_query($q, $this->connection); - return mysql_query($q, $this->connection); - } + $q = "UPDATE " . TB_PREFIX . "vdata set " . $what . "=" . $number . " where wref = $vid"; + $result = mysql_query($q, $this->connection); + return mysql_query($q, $this->connection); + } - function checkExist($ref, $mode) { + function checkExist($ref, $mode) { - if(!$mode) { - $q = "SELECT username FROM " . TB_PREFIX . "users where username = '$ref' LIMIT 1"; - } else { - $q = "SELECT email FROM " . TB_PREFIX . "users where email = '$ref' LIMIT 1"; - } - $result = mysql_query($q, $this->connection); - if(mysql_num_rows($result)) { - return true; - } else { - return false; - } - } + if(!$mode) { + $q = "SELECT username FROM " . TB_PREFIX . "users where username = '$ref' LIMIT 1"; + } else { + $q = "SELECT email FROM " . TB_PREFIX . "users where email = '$ref' LIMIT 1"; + } + $result = mysql_query($q, $this->connection); + if(mysql_num_rows($result)) { + return true; + } else { + return false; + } + } - function checkExist_activate($ref, $mode) { + function checkExist_activate($ref, $mode) { - if(!$mode) { - $q = "SELECT username FROM " . TB_PREFIX . "activate where username = '$ref' LIMIT 1"; - } else { - $q = "SELECT email FROM " . TB_PREFIX . "activate where email = '$ref' LIMIT 1"; - } - $result = mysql_query($q, $this->connection); - if(mysql_num_rows($result)) { - return true; - } else { - return false; - } - } + if(!$mode) { + $q = "SELECT username FROM " . TB_PREFIX . "activate where username = '$ref' LIMIT 1"; + } else { + $q = "SELECT email FROM " . TB_PREFIX . "activate where email = '$ref' LIMIT 1"; + } + $result = mysql_query($q, $this->connection); + if(mysql_num_rows($result)) { + return true; + } else { + return false; + } + } - 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 = mysql_query($q, $this->connection); - $dbarray = mysql_fetch_array($result); - if(!empty($dbarray)) { - if(time()<$dbarray[0]) { - return true; - } else { - return false; - } - } else { - return false; - } - } + 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 = mysql_query($q, $this->connection); + $dbarray = mysql_fetch_array($result); + if(!empty($dbarray)) { + if(time()<$dbarray[0]) { + return true; + } else { + return false; + } + } else { + return false; + } + } - function updateUserField($ref, $field, $value, $switch) { - if(!$switch) { - $q = "UPDATE " . TB_PREFIX . "users set $field = '$value' where username = '$ref'"; - } else { - $q = "UPDATE " . TB_PREFIX . "users set $field = '$value' where id = '$ref'"; - } - return mysql_query($q, $this->connection); - } + function updateUserField($ref, $field, $value, $switch) { + if(!$switch) { + $q = "UPDATE " . TB_PREFIX . "users set $field = '$value' where username = '$ref'"; + } else { + $q = "UPDATE " . TB_PREFIX . "users set $field = '$value' where id = '$ref'"; + } + return mysql_query($q, $this->connection); + } - function getSitee($uid) { - $q = "SELECT id from " . TB_PREFIX . "users where sit1 = $uid or sit2 = $uid"; - $result = mysql_query($q, $this->connection); - return $this->mysql_fetch_all($result); - } + function getSitee($uid) { + $q = "SELECT id from " . TB_PREFIX . "users where sit1 = $uid or sit2 = $uid"; + $result = mysql_query($q, $this->connection); + return $this->mysql_fetch_all($result); + } - function removeMeSit($uid, $uid2) { - $q = "UPDATE " . TB_PREFIX . "users set sit1 = 0 where id = $uid and sit1 = $uid2"; - mysql_query($q, $this->connection); - $q2 = "UPDATE " . TB_PREFIX . "users set sit2 = 0 where id = $uid and sit2 = $uid2"; - mysql_query($q2, $this->connection); - } +function getVilWref($x, $y) { + $q = "SELECT * FROM " . TB_PREFIX . "wdata where x = $x AND y = $y"; + $result = mysql_query($q, $this->connection); + $dbarray = mysql_fetch_array($result); + return $dbarray['id']; + } - 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 = mysql_query($q, $this->connection) or die(mysql_error()); - $dbarray = mysql_fetch_array($result); - return $dbarray[$field]; - } + function removeMeSit($uid, $uid2) { + $q = "UPDATE " . TB_PREFIX . "users set sit1 = 0 where id = $uid and sit1 = $uid2"; + mysql_query($q, $this->connection); + $q2 = "UPDATE " . TB_PREFIX . "users set sit2 = 0 where id = $uid and sit2 = $uid2"; + mysql_query($q2, $this->connection); + } - 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 = mysql_query($q, $this->connection) or die(mysql_error()); - $dbarray = mysql_fetch_array($result); - 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 = mysql_query($q, $this->connection) or die(mysql_error()); + $dbarray = mysql_fetch_array($result); + return $dbarray[$field]; + } - function login($username, $password) { - $q = "SELECT password,sessid FROM " . TB_PREFIX . "users where username = '$username'"; - $result = mysql_query($q, $this->connection); - $dbarray = mysql_fetch_array($result); - if($dbarray['password'] == md5($password)) { - return true; - } else { - return false; - } - } + 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 = mysql_query($q, $this->connection) or die(mysql_error()); + $dbarray = mysql_fetch_array($result); + return $dbarray[$field]; + } - function checkActivate($act) { - $q = "SELECT * FROM " . TB_PREFIX . "activate where act = '$act'"; - $result = mysql_query($q, $this->connection); - $dbarray = mysql_fetch_array($result); + function login($username, $password) { + $q = "SELECT password,sessid FROM " . TB_PREFIX . "users where username = '$username'"; + $result = mysql_query($q, $this->connection); + $dbarray = mysql_fetch_array($result); + if($dbarray['password'] == md5($password)) { + return true; + } else { + return false; + } + } - return $dbarray; - } + function checkActivate($act) { + $q = "SELECT * FROM " . TB_PREFIX . "activate where act = '$act'"; + $result = mysql_query($q, $this->connection); + $dbarray = mysql_fetch_array($result); - function sitterLogin($username, $password) { - $q = "SELECT sit1,sit2 FROM " . TB_PREFIX . "users where username = '$username' and access != " . BANNED; - $result = mysql_query($q, $this->connection); - $dbarray = mysql_fetch_array($result); - if($dbarray['sit1'] != 0) { - $q2 = "SELECT password FROM " . TB_PREFIX . "users where id = " . $dbarray['sit1'] . " and access != " . BANNED; - $result2 = mysql_query($q2, $this->connection); - $dbarray2 = mysql_fetch_array($result2); - } else - if($dbarray['sit2'] != 0) { - $q3 = "SELECT password FROM " . TB_PREFIX . "users where id = " . $dbarray['sit2'] . " and access != " . BANNED; - $result3 = mysql_query($q3, $this->connection); - $dbarray3 = mysql_fetch_array($result3); - } - if($dbarray['sit1'] != 0 || $dbarray['sit2'] != 0) { - if($dbarray2['password'] == md5($password) || $dbarray3['password'] == md5($password)) { - return true; - } else { - return false; - } - } else { - return false; - } - } + return $dbarray; + } - function setDeleting($uid, $mode) { - $time = time() + 72 * 3600; - if(!$mode) { - $q = "INSERT into " . TB_PREFIX . "deleting values ($uid,$time)"; - } else { - $q = "DELETE FROM " . TB_PREFIX . "deleting where uid = $uid"; - } - mysql_query($q, $this->connection); - } + function sitterLogin($username, $password) { + $q = "SELECT sit1,sit2 FROM " . TB_PREFIX . "users where username = '$username' and access != " . BANNED; + $result = mysql_query($q, $this->connection); + $dbarray = mysql_fetch_array($result); + if($dbarray['sit1'] != 0) { + $q2 = "SELECT password FROM " . TB_PREFIX . "users where id = " . $dbarray['sit1'] . " and access != " . BANNED; + $result2 = mysql_query($q2, $this->connection); + $dbarray2 = mysql_fetch_array($result2); + } else + if($dbarray['sit2'] != 0) { + $q3 = "SELECT password FROM " . TB_PREFIX . "users where id = " . $dbarray['sit2'] . " and access != " . BANNED; + $result3 = mysql_query($q3, $this->connection); + $dbarray3 = mysql_fetch_array($result3); + } + if($dbarray['sit1'] != 0 || $dbarray['sit2'] != 0) { + if($dbarray2['password'] == md5($password) || $dbarray3['password'] == md5($password)) { + return true; + } else { + return false; + } + } else { + return false; + } + } - function isDeleting($uid) { - $q = "SELECT timestamp from " . TB_PREFIX . "deleting where uid = $uid"; - $result = mysql_query($q, $this->connection); - $dbarray = mysql_fetch_array($result); - return $dbarray['timestamp']; - } + function setDeleting($uid, $mode) { + $time = time() + 72 * 3600; + if(!$mode) { + $q = "INSERT into " . TB_PREFIX . "deleting values ($uid,$time)"; + } else { + $q = "DELETE FROM " . TB_PREFIX . "deleting where uid = $uid"; + } + mysql_query($q, $this->connection); + } - function modifyGold($userid, $amt, $mode) { - if(!$mode) { - $q = "UPDATE " . TB_PREFIX . "users set gold = gold - $amt where id = $userid"; - } else { - $q = "UPDATE " . TB_PREFIX . "users set gold = gold + $amt where id = $userid"; - } - return mysql_query($q, $this->connection); - } + function isDeleting($uid) { + $q = "SELECT timestamp from " . TB_PREFIX . "deleting where uid = $uid"; + $result = mysql_query($q, $this->connection); + $dbarray = mysql_fetch_array($result); + return $dbarray['timestamp']; + } - /***************************************** - Function to retrieve user array via Username or ID - Mode 0: Search by Username - Mode 1: Search by ID - References: Alliance ID - *****************************************/ + function modifyGold($userid, $amt, $mode) { + if(!$mode) { + $q = "UPDATE " . TB_PREFIX . "users set gold = gold - $amt where id = $userid"; + } else { + $q = "UPDATE " . TB_PREFIX . "users set gold = gold + $amt where id = $userid"; + } + return mysql_query($q, $this->connection); + } - function getUserArray($ref, $mode) { - if(!$mode) { - $q = "SELECT * FROM " . TB_PREFIX . "users where username = '$ref'"; - } else { - $q = "SELECT * FROM " . TB_PREFIX . "users where id = $ref"; - } - $result = mysql_query($q, $this->connection); - return mysql_fetch_array($result); - } + /***************************************** + Function to retrieve user array via Username or ID + Mode 0: Search by Username + Mode 1: Search by ID + References: Alliance ID + *****************************************/ - function activeModify($username, $mode) { - $time = time(); - if(!$mode) { - $q = "INSERT into " . TB_PREFIX . "active VALUES ('$username',$time)"; - } else { - $q = "DELETE FROM " . TB_PREFIX . "active where username = '$username'"; - } - return mysql_query($q, $this->connection); - } + function getUserArray($ref, $mode) { + if(!$mode) { + $q = "SELECT * FROM " . TB_PREFIX . "users where username = '$ref'"; + } else { + $q = "SELECT * FROM " . TB_PREFIX . "users where id = $ref"; + } + $result = mysql_query($q, $this->connection); + return mysql_fetch_array($result); + } - function addActiveUser($username, $time) { - $q = "REPLACE into " . TB_PREFIX . "active values ('$username',$time)"; - if(mysql_query($q, $this->connection)) { - return true; - } else { - return false; - } - } + function activeModify($username, $mode) { + $time = time(); + if(!$mode) { + $q = "INSERT into " . TB_PREFIX . "active VALUES ('$username',$time)"; + } else { + $q = "DELETE FROM " . TB_PREFIX . "active where username = '$username'"; + } + return mysql_query($q, $this->connection); + } - 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 = mysql_query($q, $this->connection); - $exec2 = mysql_query($q2, $this->connection); - if($exec1 && $exec2) { - return true; - } else { - return false; - } - } + function addActiveUser($username, $time) { + $q = "REPLACE into " . TB_PREFIX . "active values ('$username',$time)"; + if(mysql_query($q, $this->connection)) { + return true; + } else { + return false; + } + } - function checkactiveSession($username, $sessid) { - $q = "SELECT username FROM " . TB_PREFIX . "users where username = '$username' and sessid = '$sessid' LIMIT 1"; - $result = mysql_query($q, $this->connection); - if(mysql_num_rows($result) != 0) { - return true; - } else { - return false; - } - } + 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 = mysql_query($q, $this->connection); + $exec2 = mysql_query($q2, $this->connection); + if($exec1 && $exec2) { + return true; + } else { + return false; + } + } - 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 mysql_query($q, $this->connection); - } + function checkactiveSession($username, $sessid) { + $q = "SELECT username FROM " . TB_PREFIX . "users where username = '$username' and sessid = '$sessid' LIMIT 1"; + $result = mysql_query($q, $this->connection); + if(mysql_num_rows($result) != 0) { + return true; + } else { + return false; + } + } - function gpack($uid, $gpack) { - $q = "UPDATE " . TB_PREFIX . "users set gpack = '$gpack' where id = $uid"; - return mysql_query($q, $this->connection); - } + 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 mysql_query($q, $this->connection); + } - function UpdateOnline($mode, $name = "", $time = "") { - global $session; - if($mode == "login") { - $q = "INSERT IGNORE INTO " . TB_PREFIX . "online (name, time) VALUES ('$name', " . time() . ")"; - return mysql_query($q, $this->connection); - } else { - $q = "DELETE FROM " . TB_PREFIX . "online WHERE name ='" . $session->username . "'"; - return mysql_query($q, $this->connection); - } - } + function gpack($uid, $gpack) { + $q = "UPDATE " . TB_PREFIX . "users set gpack = '$gpack' where id = $uid"; + return mysql_query($q, $this->connection); + } + + function UpdateOnline($mode, $name = "", $time = "") { + global $session; + if($mode == "login") { + $q = "INSERT IGNORE INTO " . TB_PREFIX . "online (name, time) VALUES ('$name', " . time() . ")"; + return mysql_query($q, $this->connection); + } else { + $q = "DELETE FROM " . TB_PREFIX . "online WHERE name ='" . $session->username . "'"; + return mysql_query($q, $this->connection); + } + } function generateBase($sector) { switch($sector) { @@ -314,77 +321,77 @@ return $result[$base]['id']; } - function setFieldTaken($id) { - $q = "UPDATE " . TB_PREFIX . "wdata set occupied = 1 where id = $id"; - return mysql_query($q, $this->connection); - } + function setFieldTaken($id) { + $q = "UPDATE " . TB_PREFIX . "wdata set occupied = 1 where id = $id"; + return mysql_query($q, $this->connection); + } - function addVillage($wid, $uid, $username, $capital) { - $total = count($this->getVillagesID($uid)); - if($total >= 1) { - $vname = $username . "\'s village " . ($total + 1); - } else { - $vname = $username . "\'s village"; - } - $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 mysql_query($q, $this->connection) or die(mysql_error()); - } + function addVillage($wid, $uid, $username, $capital) { + $total = count($this->getVillagesID($uid)); + if($total >= 1) { + $vname = $username . "\'s village " . ($total + 1); + } else { + $vname = $username . "\'s village"; + } + $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 mysql_query($q, $this->connection) or die(mysql_error()); + } - function addResourceFields($vid, $type) { - switch($type) { - case 1: - $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,4,4,1,4,4,2,3,4,4,3,3,4,4,1,4,2,1,2,1,15)"; - break; - case 2: - $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,3,4,1,3,2,2,3,4,4,3,3,4,4,1,4,2,1,2,1,15)"; - break; - case 3: - $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,3,2,2,3,4,4,3,3,4,4,1,4,2,1,2,1,15)"; - break; - case 4: - $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,2,2,2,3,4,4,3,3,4,4,1,4,2,1,2,1,15)"; - break; - case 5: - $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,3,1,2,3,4,4,3,3,4,4,1,4,2,1,2,1,15)"; - break; - case 6: - $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,4,4,1,3,4,4,4,4,4,4,4,4,4,4,4,2,4,4,1,15)"; - break; - case 7: - $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,4,1,2,2,3,4,4,3,3,4,4,1,4,2,1,2,1,15)"; - break; - case 8: - $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,3,4,4,1,2,2,3,4,4,3,3,4,4,1,4,2,1,2,1,15)"; - break; - case 9: - $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,3,4,4,1,1,2,3,4,4,3,3,4,4,1,4,2,1,2,1,15)"; - break; - case 10: - $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,3,4,1,2,2,2,3,4,4,3,3,4,4,1,4,2,1,2,1,15)"; - break; - case 11: - $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,3,1,1,3,1,4,4,3,3,2,2,3,1,4,4,2,4,4,1,15)"; - break; - case 12: - $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 mysql_query($q, $this->connection); - } - function isVillageOases($wref) { - $q = "SELECT id, oasistype FROM " . TB_PREFIX . "wdata where id = $wref"; - $result = mysql_query($q, $this->connection); - $dbarray = mysql_fetch_array($result); - return $dbarray['oasistype']; - } + function addResourceFields($vid, $type) { + switch($type) { + case 1: + $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,4,4,1,4,4,2,3,4,4,3,3,4,4,1,4,2,1,2,1,15)"; + break; + case 2: + $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,3,4,1,3,2,2,3,4,4,3,3,4,4,1,4,2,1,2,1,15)"; + break; + case 3: + $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,3,2,2,3,4,4,3,3,4,4,1,4,2,1,2,1,15)"; + break; + case 4: + $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,2,2,2,3,4,4,3,3,4,4,1,4,2,1,2,1,15)"; + break; + case 5: + $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,3,1,2,3,4,4,3,3,4,4,1,4,2,1,2,1,15)"; + break; + case 6: + $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,4,4,1,3,4,4,4,4,4,4,4,4,4,4,4,2,4,4,1,15)"; + break; + case 7: + $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,4,1,2,2,3,4,4,3,3,4,4,1,4,2,1,2,1,15)"; + break; + case 8: + $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,3,4,4,1,2,2,3,4,4,3,3,4,4,1,4,2,1,2,1,15)"; + break; + case 9: + $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,3,4,4,1,1,2,3,4,4,3,3,4,4,1,4,2,1,2,1,15)"; + break; + case 10: + $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,3,4,1,2,2,2,3,4,4,3,3,4,4,1,4,2,1,2,1,15)"; + break; + case 11: + $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,3,1,1,3,1,4,4,3,3,2,2,3,1,4,4,2,4,4,1,15)"; + break; + case 12: + $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 mysql_query($q, $this->connection); + } + function isVillageOases($wref) { + $q = "SELECT id, oasistype FROM " . TB_PREFIX . "wdata where id = $wref"; + $result = mysql_query($q, $this->connection); + $dbarray = mysql_fetch_array($result); + return $dbarray['oasistype']; + } - public function VillageOasisCount($vref) { - $q = "SELECT count(*) FROM `".TB_PREFIX."odata` WHERE conqured=$vref"; - $result = mysql_query($q, $this->connection); - $row = mysql_fetch_row($result); - return $row[0]; - } + public function VillageOasisCount($vref) { + $q = "SELECT count(*) FROM `".TB_PREFIX."odata` WHERE conqured=$vref"; + $result = mysql_query($q, $this->connection); + $row = mysql_fetch_row($result); + return $row[0]; + } public function countOasisTroops($vref){ //count oasis troops: $troops_o @@ -410,774 +417,798 @@ 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); + 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); - if(abs($CoordsOasis['x']-$CoordsVillage['x'])<=3 && abs($CoordsOasis['y']-$CoordsVillage['y'])<=3) { - return True; - } else { - return False; - } - } else { - return False; - } - } else { - return False; - } - } + 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); + if(abs($CoordsOasis['x']-$CoordsVillage['x'])<=3 && abs($CoordsOasis['y']-$CoordsVillage['y'])<=3) { + return True; + } else { + return False; + } + } else { + return False; + } + } else { + return False; + } + } - 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 mysql_query($q, $this->connection); - } + 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 mysql_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 mysql_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 mysql_query($q, $this->connection); + } + } + } - function populateOasis() { - $q = "SELECT * FROM " . TB_PREFIX . "wdata where oasistype != 0"; - $result = mysql_query($q, $this->connection); - while($row = mysql_fetch_array($result)) { - $wid = $row['id']; + function populateOasis() { + $q = "SELECT * FROM " . TB_PREFIX . "wdata where oasistype != 0"; + $result = mysql_query($q, $this->connection); + while($row = mysql_fetch_array($result)) { + $wid = $row['id']; - $this->addUnits($wid); + $this->addUnits($wid); - } - } + } + } - function populateOasisUnitsLow() { - $q2 = "SELECT * FROM " . TB_PREFIX . "odata where conqured == 0"; - $result2 = mysql_query($q2, $this->connection); - while($row = mysql_fetch_array($result2)) { - $wid = $row['wref']; - $basearray = $this->getMInfo($wid); - //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['oasistype']) { - case 1: - case 2: - //+25% lumber per hour - $q = "UPDATE " . TB_PREFIX . "units SET u36 = u36 + '".rand(0,20)."', u37 = u37 + '".rand(0,10)."' WHERE vref = '" . $wid . "' AND u36 <= '2' AND u37 <= '2'"; - $result = mysql_query($q, $this->connection); - break; - case 3: - //+25% lumber and +25% crop per hour - $q = "UPDATE " . TB_PREFIX . "units SET u36 = u36 + '".rand(0,20)."', u37 = u37 + '".rand(0,10)."', u38 = u38 + '".rand(0,10)."' WHERE vref = '" . $wid . "' AND u36 <= '2' AND u37 <= '2' AND u38 <='2'"; - $result = mysql_query($q, $this->connection); - break; - case 4: - case 5: - //+25% clay per hour - $q = "UPDATE " . TB_PREFIX . "units SET u36 = u36 + '".rand(0,20)."', u37 = u37 + '".rand(0,10)."' WHERE vref = '" . $wid . "' AND u36 <= '2' AND u37 <= '2'"; - $result = mysql_query($q, $this->connection); - break; - case 6: - //+25% clay and +25% crop per hour - $q = "UPDATE " . TB_PREFIX . "units SET u36 = u36 + '".rand(0,20)."', u37 = u37 + '".rand(0,10)."', u38 = u38 + '".rand(0,10)."' WHERE vref = '" . $wid . "' AND u36 <= '2' AND u37 <= '2' AND u38 <='2'"; - $result = mysql_query($q, $this->connection); - break; - case 7: - case 8: - //+25% iron per hour - $q = "UPDATE " . TB_PREFIX . "units SET u31 = u31 + '".rand(0,20)."', u32 = u32 + '".rand(0,10)."', u34 = u34 + '".rand(0,10)."' WHERE vref = '" . $wid . "' AND u31 <= '2' AND u32 <= '2'"; - $result = mysql_query($q, $this->connection); - break; - case 9: - //+25% iron and +25% crop - $q = "UPDATE " . TB_PREFIX . "units SET u31 = u31 + '".rand(0,20)."', u32 = u32 + '".rand(0,10)."', u34 = u34 + '".rand(0,10)."' WHERE vref = '" . $wid . "' AND u31 <= '2' AND u32 <= '2' AND u34 <='2'"; - $result = mysql_query($q, $this->connection); - break; - case 10: - case 11: - //+25% crop per hour - $q = "UPDATE " . TB_PREFIX . "units SET u33 = u33 + '".rand(0,20)."', u37 = u37 + '".rand(0,10)."', u38 = u38 + '".rand(0,10)."' WHERE vref = '" . $wid . "' AND u33 <= '2' AND u37 <= '2' AND u38 <='2'"; - $result = mysql_query($q, $this->connection); - break; - case 12: - //+50% crop per hour - $q = "UPDATE " . TB_PREFIX . "units SET u33 = u33 + '".rand(0,20)."', u37 = u37 + '".rand(0,10)."', u38 = u38 + '".rand(0,10)."', u39 = u39 + '".rand(0,10)."' WHERE vref = '" . $wid . "' AND u33 <= '2' AND u37 <= '2' AND u38 <='2'AND u38 <='2'"; - $result = mysql_query($q, $this->connection); - break; - } - } - } + function populateOasisUnitsLow() { + $q2 = "SELECT * FROM " . TB_PREFIX . "odata where conqured == 0"; + $result2 = mysql_query($q2, $this->connection); + while($row = mysql_fetch_array($result2)) { + $wid = $row['wref']; + $basearray = $this->getMInfo($wid); + //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['oasistype']) { + case 1: + case 2: + //+25% lumber per hour + $q = "UPDATE " . TB_PREFIX . "units SET u36 = u36 + '".rand(0,20)."', u37 = u37 + '".rand(0,10)."' WHERE vref = '" . $wid . "' AND u36 <= '2' AND u37 <= '2'"; + $result = mysql_query($q, $this->connection); + break; + case 3: + //+25% lumber and +25% crop per hour + $q = "UPDATE " . TB_PREFIX . "units SET u36 = u36 + '".rand(0,20)."', u37 = u37 + '".rand(0,10)."', u38 = u38 + '".rand(0,10)."' WHERE vref = '" . $wid . "' AND u36 <= '2' AND u37 <= '2' AND u38 <='2'"; + $result = mysql_query($q, $this->connection); + break; + case 4: + case 5: + //+25% clay per hour + $q = "UPDATE " . TB_PREFIX . "units SET u36 = u36 + '".rand(0,20)."', u37 = u37 + '".rand(0,10)."' WHERE vref = '" . $wid . "' AND u36 <= '2' AND u37 <= '2'"; + $result = mysql_query($q, $this->connection); + break; + case 6: + //+25% clay and +25% crop per hour + $q = "UPDATE " . TB_PREFIX . "units SET u36 = u36 + '".rand(0,20)."', u37 = u37 + '".rand(0,10)."', u38 = u38 + '".rand(0,10)."' WHERE vref = '" . $wid . "' AND u36 <= '2' AND u37 <= '2' AND u38 <='2'"; + $result = mysql_query($q, $this->connection); + break; + case 7: + case 8: + //+25% iron per hour + $q = "UPDATE " . TB_PREFIX . "units SET u31 = u31 + '".rand(0,20)."', u32 = u32 + '".rand(0,10)."', u34 = u34 + '".rand(0,10)."' WHERE vref = '" . $wid . "' AND u31 <= '2' AND u32 <= '2'"; + $result = mysql_query($q, $this->connection); + break; + case 9: + //+25% iron and +25% crop + $q = "UPDATE " . TB_PREFIX . "units SET u31 = u31 + '".rand(0,20)."', u32 = u32 + '".rand(0,10)."', u34 = u34 + '".rand(0,10)."' WHERE vref = '" . $wid . "' AND u31 <= '2' AND u32 <= '2' AND u34 <='2'"; + $result = mysql_query($q, $this->connection); + break; + case 10: + case 11: + //+25% crop per hour + $q = "UPDATE " . TB_PREFIX . "units SET u33 = u33 + '".rand(0,20)."', u37 = u37 + '".rand(0,10)."', u38 = u38 + '".rand(0,10)."' WHERE vref = '" . $wid . "' AND u33 <= '2' AND u37 <= '2' AND u38 <='2'"; + $result = mysql_query($q, $this->connection); + break; + case 12: + //+50% crop per hour + $q = "UPDATE " . TB_PREFIX . "units SET u33 = u33 + '".rand(0,20)."', u37 = u37 + '".rand(0,10)."', u38 = u38 + '".rand(0,10)."', u39 = u39 + '".rand(0,10)."' WHERE vref = '" . $wid . "' AND u33 <= '2' AND u37 <= '2' AND u38 <='2'AND u38 <='2'"; + $result = mysql_query($q, $this->connection); + break; + } + } + } function populateOasisUnitsHigh() { - $q2 = "SELECT * FROM " . TB_PREFIX . "odata where conqured == 0"; - $result2 = mysql_query($q2, $this->connection); - while($row = mysql_fetch_array($result2)) { - $wid = $row['wref']; - $basearray = $this->getMInfo($wid); - //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['oasistype']) { - case 1: - case 2: - //+25% lumber per hour - $q = "UPDATE " . TB_PREFIX . "units SET u36 = u36 + '".rand(15,40)."', u37 = u37 + '".rand(10,20)."' WHERE vref = '" . $wid . "' AND u36 <= '2' AND u37 <= '2'"; - $result = mysql_query($q, $this->connection); - break; - case 3: - //+25% lumber and +25% crop per hour - $q = "UPDATE " . TB_PREFIX . "units SET u36 = u36 + '".rand(15,40)."', u37 = u37 + '".rand(10,20)."', u38 = u38 + '".rand(10,20)."' WHERE vref = '" . $wid . "' AND u36 <= '2' AND u37 <= '2' AND u38 <='2'"; - $result = mysql_query($q, $this->connection); - break; - case 4: - case 5: - //+25% clay per hour - $q = "UPDATE " . TB_PREFIX . "units SET u36 = u36 + '".rand(15,40)."', u37 = u37 + '".rand(10,20)."' WHERE vref = '" . $wid . "' AND u36 <= '2' AND u37 <= '2'"; - $result = mysql_query($q, $this->connection); - break; - case 6: - //+25% clay and +25% crop per hour - $q = "UPDATE " . TB_PREFIX . "units SET u36 = u36 + '".rand(15,40)."', u37 = u37 + '".rand(10,20)."', u38 = u38 + '".rand(10,20)."' WHERE vref = '" . $wid . "' AND u36 <= '2' AND u37 <= '2' AND u38 <='2'"; - $result = mysql_query($q, $this->connection); - break; - case 7: - case 8: - //+25% iron per hour - $q = "UPDATE " . TB_PREFIX . "units SET u31 = u31 + '".rand(15,40)."', u32 = u32 + '".rand(10,20)."', u34 = u34 + '".rand(10,20)."' WHERE vref = '" . $wid . "' AND u31 <= '2' AND u32 <= '2'"; - $result = mysql_query($q, $this->connection); - break; - case 9: - //+25% iron and +25% crop - $q = "UPDATE " . TB_PREFIX . "units SET u31 = u31 + '".rand(15,40)."', u32 = u32 + '".rand(10,20)."', u34 = u34 + '".rand(10,20)."' WHERE vref = '" . $wid . "' AND u31 <= '2' AND u32 <= '2' AND u34 <='2'"; - $result = mysql_query($q, $this->connection); - break; - case 10: - case 11: - //+25% crop per hour - $q = "UPDATE " . TB_PREFIX . "units SET u33 = u33 + '".rand(0,20)."', u37 = u37 + '".rand(0,10)."', u38 = u38 + '".rand(0,10)."' WHERE vref = '" . $wid . "' AND u33 <= '2' AND u37 <= '2' AND u38 <='2'"; - $result = mysql_query($q, $this->connection); - break; - case 12: - //+50% crop per hour - $q = "UPDATE " . TB_PREFIX . "units SET u33 = u33 + '".rand(0,20)."', u37 = u37 + '".rand(0,10)."', u38 = u38 + '".rand(0,10)."', u39 = u39 + '".rand(0,10)."' WHERE vref = '" . $wid . "' AND u33 <= '2' AND u37 <= '2' AND u38 <='2'AND u38 <='2'"; - $result = mysql_query($q, $this->connection); - break; - } - } - } - - function removeOases($wref) { + $q2 = "SELECT * FROM " . TB_PREFIX . "odata where conqured == 0"; + $result2 = mysql_query($q2, $this->connection); + while($row = mysql_fetch_array($result2)) { + $wid = $row['wref']; + $basearray = $this->getMInfo($wid); + //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['oasistype']) { + case 1: + case 2: + //+25% lumber per hour + $q = "UPDATE " . TB_PREFIX . "units SET u36 = u36 + '".rand(15,40)."', u37 = u37 + '".rand(10,20)."' WHERE vref = '" . $wid . "' AND u36 <= '2' AND u37 <= '2'"; + $result = mysql_query($q, $this->connection); + break; + case 3: + //+25% lumber and +25% crop per hour + $q = "UPDATE " . TB_PREFIX . "units SET u36 = u36 + '".rand(15,40)."', u37 = u37 + '".rand(10,20)."', u38 = u38 + '".rand(10,20)."' WHERE vref = '" . $wid . "' AND u36 <= '2' AND u37 <= '2' AND u38 <='2'"; + $result = mysql_query($q, $this->connection); + break; + case 4: + case 5: + //+25% clay per hour + $q = "UPDATE " . TB_PREFIX . "units SET u36 = u36 + '".rand(15,40)."', u37 = u37 + '".rand(10,20)."' WHERE vref = '" . $wid . "' AND u36 <= '2' AND u37 <= '2'"; + $result = mysql_query($q, $this->connection); + break; + case 6: + //+25% clay and +25% crop per hour + $q = "UPDATE " . TB_PREFIX . "units SET u36 = u36 + '".rand(15,40)."', u37 = u37 + '".rand(10,20)."', u38 = u38 + '".rand(10,20)."' WHERE vref = '" . $wid . "' AND u36 <= '2' AND u37 <= '2' AND u38 <='2'"; + $result = mysql_query($q, $this->connection); + break; + case 7: + case 8: + //+25% iron per hour + $q = "UPDATE " . TB_PREFIX . "units SET u31 = u31 + '".rand(15,40)."', u32 = u32 + '".rand(10,20)."', u34 = u34 + '".rand(10,20)."' WHERE vref = '" . $wid . "' AND u31 <= '2' AND u32 <= '2'"; + $result = mysql_query($q, $this->connection); + break; + case 9: + //+25% iron and +25% crop + $q = "UPDATE " . TB_PREFIX . "units SET u31 = u31 + '".rand(15,40)."', u32 = u32 + '".rand(10,20)."', u34 = u34 + '".rand(10,20)."' WHERE vref = '" . $wid . "' AND u31 <= '2' AND u32 <= '2' AND u34 <='2'"; + $result = mysql_query($q, $this->connection); + break; + case 10: + case 11: + //+25% crop per hour + $q = "UPDATE " . TB_PREFIX . "units SET u33 = u33 + '".rand(0,20)."', u37 = u37 + '".rand(0,10)."', u38 = u38 + '".rand(0,10)."' WHERE vref = '" . $wid . "' AND u33 <= '2' AND u37 <= '2' AND u38 <='2'"; + $result = mysql_query($q, $this->connection); + break; + case 12: + //+50% crop per hour + $q = "UPDATE " . TB_PREFIX . "units SET u33 = u33 + '".rand(0,20)."', u37 = u37 + '".rand(0,10)."', u38 = u38 + '".rand(0,10)."', u39 = u39 + '".rand(0,10)."' WHERE vref = '" . $wid . "' AND u33 <= '2' AND u37 <= '2' AND u38 <='2'AND u38 <='2'"; + $result = mysql_query($q, $this->connection); + break; + } + } + } + + function removeOases($wref) { $q = "UPDATE ".TB_PREFIX."odata SET conqured = 0, owner = 2, name = 'Unoccupied Oasis' WHERE wref = $wref"; return mysql_query($q, $this->connection); } - /*************************** - Function to retrieve type of village via ID - References: Village ID - ***************************/ - function getVillageType($wref) { - $q = "SELECT id, fieldtype FROM " . TB_PREFIX . "wdata where id = $wref"; - $result = mysql_query($q, $this->connection); - $dbarray = mysql_fetch_array($result); - return $dbarray['fieldtype']; - } - - - - /***************************************** - Function to retrieve if is ocuped via ID - References: Village ID - *****************************************/ - function getVillageState($wref) { - $q = "SELECT oasistype,occupied FROM " . TB_PREFIX . "wdata where id = $wref"; - $result = mysql_query($q, $this->connection); - $dbarray = mysql_fetch_array($result); - if($dbarray['occupied'] != 0 || $dbarray['oasistype'] != 0) { - return true; - } else { - return false; - } - } - - function getProfileVillages($uid) { - $q = "SELECT capital,wref,name,pop,created from " . TB_PREFIX . "vdata where owner = $uid order by pop desc"; - $result = mysql_query($q, $this->connection); - return $this->mysql_fetch_all($result); - } - - function getProfileMedal($uid) { - $q = "SELECT id,categorie,plaats,week,img,points from " . TB_PREFIX . "medal where userid = $uid order by id desc"; - $result = mysql_query($q, $this->connection); - return $this->mysql_fetch_all($result); - - } - - function getProfileMedalAlly($uid) { - $q = "SELECT id,categorie,plaats,week,img,points from " . TB_PREFIX . "allimedal where allyid = $uid order by id desc"; - $result = mysql_query($q, $this->connection); - return $this->mysql_fetch_all($result); - - } - - function getVillageID($uid) { - $q = "SELECT wref FROM " . TB_PREFIX . "vdata WHERE owner = $uid"; - $result = mysql_query($q, $this->connection); - $dbarray = mysql_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 = mysql_query($q, $this->connection); - $array = $this->mysql_fetch_all($result); - $newarray = array(); - for($i = 0; $i < count($array); $i++) { - array_push($newarray, $array[$i]['wref']); - } - return $newarray; - } - - function getVillage($vid) { - $q = "SELECT * FROM " . TB_PREFIX . "vdata where wref = $vid"; - $result = mysql_query($q, $this->connection); - return mysql_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 = mysql_query($q, $this->connection); - return mysql_fetch_array($result); - } - - public function getPopulation($uid) { - $q = "SELECT sum(pop) AS pop FROM ".TB_PREFIX."vdata WHERE owner=".$uid; - $result = mysql_query($q, $this->connection); - $dbarray = mysql_fetch_array($result); - return $dbarray['pop']; - } - - function getOasisV($vid) { - $q = "SELECT * FROM " . TB_PREFIX . "odata where wref = $vid"; - $result = mysql_query($q, $this->connection); - return mysql_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 = mysql_query($q, $this->connection); - return mysql_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 = mysql_query($q, $this->connection); - return mysql_fetch_array($result); - } - - function getOasis($vid) { - $q = "SELECT * FROM " . TB_PREFIX . "odata where conqured = $vid"; - $result = mysql_query($q, $this->connection); - return $this->mysql_fetch_all($result); - } - - function getOasisInfo($wid) { - $q = "SELECT * FROM " . TB_PREFIX . "odata where wref = $wid"; - $result = mysql_query($q, $this->connection); - return mysql_fetch_assoc($result); - } - - function getVillageField($ref, $field) { - $q = "SELECT $field FROM " . TB_PREFIX . "vdata where wref = $ref"; - $result = mysql_query($q, $this->connection); - $dbarray = mysql_fetch_array($result); - return $dbarray[$field]; - - } - - function getOasisField($ref, $field) { - $q = "SELECT $field FROM " . TB_PREFIX . "odata where wref = $ref"; - $result = mysql_query($q, $this->connection); - $dbarray = mysql_fetch_array($result); - return $dbarray[$field]; - } - - function setVillageField($ref, $field, $value) { - $q = "UPDATE " . TB_PREFIX . "vdata set $field = '$value' where wref = $ref"; - return mysql_query($q, $this->connection); - } - - function setVillageLevel($ref, $field, $value) { - $q = "UPDATE " . TB_PREFIX . "fdata set " . $field . " = '" . $value . "' where vref = " . $ref . ""; - return mysql_query($q, $this->connection); - } - - function getResourceLevel($vid) { - $q = "SELECT * from " . TB_PREFIX . "fdata where vref = $vid"; - $result = mysql_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 = mysql_query($q, $this->connection); - return $this->mysql_fetch_all($result); - } - - function getCoor($wref) { - if ($wref !=""){ - $q = "SELECT x,y FROM " . TB_PREFIX . "wdata where id = $wref"; - $result = mysql_query($q, $this->connection); - return mysql_fetch_array($result); - } - } - - function CheckForum($id) { - $q = "SELECT * from " . TB_PREFIX . "forum_cat where alliance = '$id'"; - $result = mysql_query($q, $this->connection); - if(mysql_num_rows($result)) { - return true; - } else { - return false; - } - } - - function CountCat($id) { - $q = "SELECT count(id) FROM " . TB_PREFIX . "forum_topic where cat = '$id'"; - $result = mysql_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 = mysql_query($q, $this->connection); - return $this->mysql_fetch_all($result); - } - - function CheckLastTopic($id) { - $q = "SELECT * from " . TB_PREFIX . "forum_topic where cat = '$id'"; - $result = mysql_query($q, $this->connection); - if(mysql_num_rows($result)) { - return true; - } else { - return false; - } - } - - function CheckLastPost($id) { - $q = "SELECT * from " . TB_PREFIX . "forum_post where topic = '$id'"; - $result = mysql_query($q, $this->connection); - if(mysql_num_rows($result)) { - return true; - } else { - return false; - } - } - - function LastPost($id) { - $q = "SELECT * from " . TB_PREFIX . "forum_post where topic = '$id'"; - $result = mysql_query($q, $this->connection); - return $this->mysql_fetch_all($result); - } - - function CountTopic($id) { - $q = "SELECT count(id) FROM " . TB_PREFIX . "forum_post where owner = '$id'"; - $result = mysql_query($q, $this->connection); - $row = mysql_fetch_row($result); - - $qs = "SELECT count(id) FROM " . TB_PREFIX . "forum_topic where owner = '$id'"; - $results = mysql_query($qs, $this->connection); - $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 = mysql_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 = mysql_query($q, $this->connection); - return $this->mysql_fetch_all($result); - } - - function ForumCatEdit($id) { - $q = "SELECT * from " . TB_PREFIX . "forum_cat where id = '$id'"; - $result = mysql_query($q, $this->connection); - return $this->mysql_fetch_all($result); - } - - function ForumCatName($id) { - $q = "SELECT forum_name from " . TB_PREFIX . "forum_cat where id = $id"; - $result = mysql_query($q, $this->connection); - $dbarray = mysql_fetch_array($result); - return $dbarray['forum_name']; - } - - function CheckCatTopic($id) { - $q = "SELECT * from " . TB_PREFIX . "forum_topic where cat = '$id'"; - $result = mysql_query($q, $this->connection); - if(mysql_num_rows($result)) { - return true; - } else { - return false; - } - } - - function CheckResultEdit($alli) { - $q = "SELECT * from " . TB_PREFIX . "forum_edit where alliance = '$alli'"; - $result = mysql_query($q, $this->connection); - if(mysql_num_rows($result)) { - return true; - } else { - return false; - } - } - - function CheckCloseTopic($id) { - $q = "SELECT close from " . TB_PREFIX . "forum_topic where id = '$id'"; - $result = mysql_query($q, $this->connection); - $dbarray = mysql_fetch_array($result); - return $dbarray['close']; - } - - function CheckEditRes($alli) { - $q = "SELECT result from " . TB_PREFIX . "forum_edit where alliance = '$alli'"; - $result = mysql_query($q, $this->connection); - $dbarray = mysql_fetch_array($result); - return $dbarray['result']; - } - - function CreatResultEdit($alli, $result) { - $q = "INSERT into " . TB_PREFIX . "forum_edit values (0,'$alli','$result')"; - mysql_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 mysql_query($q, $this->connection); - } - - function UpdateEditTopic($id, $title, $cat) { - $q = "UPDATE " . TB_PREFIX . "forum_topic set title = '$title', cat = '$cat' where id = $id"; - return mysql_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 mysql_query($q, $this->connection); - } - - function StickTopic($id, $mode) { - $q = "UPDATE " . TB_PREFIX . "forum_topic set stick = '$mode' where id = '$id'"; - return mysql_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 = mysql_query($q, $this->connection); - return $this->mysql_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 = mysql_query($q, $this->connection); - return $this->mysql_fetch_all($result); - } - - function ShowTopic($id) { - $q = "SELECT * from " . TB_PREFIX . "forum_topic where id = '$id'"; - $result = mysql_query($q, $this->connection); - return $this->mysql_fetch_all($result); - } - - function ShowPost($id) { - $q = "SELECT * from " . TB_PREFIX . "forum_post where topic = '$id'"; - $result = mysql_query($q, $this->connection); - return $this->mysql_fetch_all($result); - } - - function ShowPostEdit($id) { - $q = "SELECT * from " . TB_PREFIX . "forum_post where id = '$id'"; - $result = mysql_query($q, $this->connection); - return $this->mysql_fetch_all($result); - } - - function CreatForum($owner, $alli, $name, $des, $area) { - $q = "INSERT into " . TB_PREFIX . "forum_cat values (0,'$owner','$alli','$name','$des','$area')"; - mysql_query($q, $this->connection); - return mysql_insert_id($this->connection); - } - - function CreatTopic($title, $post, $cat, $owner, $alli, $ends) { - $date = time(); - $q = "INSERT into " . TB_PREFIX . "forum_topic values (0,'$title','$post','$date','$date','$cat','$owner','$alli','$ends','','')"; - mysql_query($q, $this->connection); - return mysql_insert_id($this->connection); - } - - function CreatPost($post, $tids, $owner) { - $date = time(); - $q = "INSERT into " . TB_PREFIX . "forum_post values (0,'$post','$tids','$owner','$date')"; - mysql_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 mysql_query($q, $this->connection); - } - - function EditUpdateTopic($id, $post) { - $q = "UPDATE " . TB_PREFIX . "forum_topic set post = '$post' where id = $id"; - return mysql_query($q, $this->connection); - } - - function EditUpdatePost($id, $post) { - $q = "UPDATE " . TB_PREFIX . "forum_post set post = '$post' where id = $id"; - return mysql_query($q, $this->connection); - } - - function LockTopic($id, $mode) { - $q = "UPDATE " . TB_PREFIX . "forum_topic set close = '$mode' where id = '$id'"; - return mysql_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'"; - mysql_query($qs, $this->connection); - return mysql_query($q, $this->connection); - } - - function DeleteTopic($id) { - $qs = "DELETE from " . TB_PREFIX . "forum_topic where id = '$id'"; - // $q = "DELETE from ".TB_PREFIX."forum_post where topic = '$id'";// - return mysql_query($qs, $this->connection); // - // mysql_query($q,$this->connection); - } - - function DeletePost($id) { - $q = "DELETE from " . TB_PREFIX . "forum_post where id = '$id'"; - return mysql_query($q, $this->connection); - } - - function getAllianceName($id) { - $q = "SELECT tag from " . TB_PREFIX . "alidata where id = $id"; - $result = mysql_query($q, $this->connection); - $dbarray = mysql_fetch_array($result); - return $dbarray['tag']; - } - - function getAlliancePermission($ref, $field, $mode) { - if(!$mode) { - $q = "SELECT $field FROM " . TB_PREFIX . "ali_permission where uid = '$ref'"; - } else { - $q = "SELECT $field FROM " . TB_PREFIX . "ali_permission where username = '$ref'"; - } - $result = mysql_query($q, $this->connection) or die(mysql_error()); - $dbarray = mysql_fetch_array($result); - return $dbarray[$field]; - } - - function getAlliance($id) { - $q = "SELECT * from " . TB_PREFIX . "alidata where id = $id"; - $result = mysql_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 mysql_query($q, $this->connection); - } - - function isAllianceOwner($id) { - $q = "SELECT * from " . TB_PREFIX . "alidata where leader = '$id'"; - $result = mysql_query($q, $this->connection); - if(mysql_num_rows($result)) { - return true; - } else { - return false; - } - } - - function aExist($ref, $type) { - $q = "SELECT $type FROM " . TB_PREFIX . "alidata where $type = '$ref'"; - $result = mysql_query($q, $this->connection); - if(mysql_num_rows($result)) { - return true; - } else { - return false; - } - } - - function modifyPoints($aid, $points, $amt) { - $q = "UPDATE " . TB_PREFIX . "users set $points = $points + $amt where id = $aid"; - return mysql_query($q, $this->connection); - } - - function modifyPointsAlly($aid, $points, $amt) { - $q = "UPDATE " . TB_PREFIX . "alidata set $points = $points + $amt where id = $aid"; - return mysql_query($q, $this->connection); - } - - /***************************************** - Function to create an alliance - References: - *****************************************/ - function createAlliance($tag, $name, $uid, $max) { - $q = "INSERT into " . TB_PREFIX . "alidata values (0,'$name','$tag',$uid,0,0,0,'','',$max,'','','','','','','','')"; - mysql_query($q, $this->connection); - return mysql_insert_id($this->connection); - } - - /***************************************** - Function to insert an alliance new - References: - *****************************************/ - function insertAlliNotice($aid, $notice) { - $time = time(); - $q = "INSERT into " . TB_PREFIX . "ali_log values (0,'$aid','$notice',$time)"; - mysql_query($q, $this->connection); - return mysql_insert_id($this->connection); - } - - /***************************************** - Function to delete alliance if empty - References: - *****************************************/ - function deleteAlliance($aid) { - $result = mysql_query("SELECT * FROM " . TB_PREFIX . "users where alliance = $aid"); - $num_rows = mysql_num_rows($result); - if($num_rows == 0) { - $q = "DELETE FROM " . TB_PREFIX . "alidata WHERE id = $aid"; - } - mysql_query($q, $this->connection); - return mysql_insert_id($this->connection); - } - - /***************************************** - Function to read all alliance news - References: - *****************************************/ - function readAlliNotice($aid) { - $q = "SELECT * from " . TB_PREFIX . "ali_log where aid = $aid ORDER BY date DESC"; - $result = mysql_query($q, $this->connection); - return $this->mysql_fetch_all($result); - } - - /***************************************** - Function to create alliance permissions - References: ID, notice, description - *****************************************/ - 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')"; - mysql_query($q, $this->connection); - return mysql_insert_id($this->connection); - } - - /***************************************** - Function to update alliance permissions - References: - *****************************************/ - function deleteAlliPermissions($uid) { - $q = "DELETE from " . TB_PREFIX . "ali_permission where uid = '$uid'"; - return mysql_query($q, $this->connection); - } - /***************************************** - Function to update alliance permissions - References: - *****************************************/ - 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 mysql_query($q, $this->connection); - } - - /***************************************** - Function to read alliance permissions - References: ID, notice, description - *****************************************/ - function getAlliPermissions($uid, $aid) { - $q = "SELECT * FROM " . TB_PREFIX . "ali_permission where uid = $uid && alliance = $aid"; - $result = mysql_query($q, $this->connection); - return mysql_fetch_assoc($result); - } - - /***************************************** - Function to update an alliance description and notice - References: ID, notice, description - *****************************************/ - function submitAlliProfile($aid, $notice, $desc) { - - $q = "UPDATE " . TB_PREFIX . "alidata SET `notice` = '$notice', `desc` = '$desc' where id = $aid"; - return mysql_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 mysql_query($q, $this->connection); - } - - function diplomacyOwnOffers($session_alliance) { - $q = "SELECT * FROM " . TB_PREFIX . "diplomacy WHERE alli1 = $session_alliance AND accepted = 0"; - $result = mysql_query($q, $this->connection); - return $this->mysql_fetch_all($result); - } + /*************************** + Function to retrieve type of village via ID + References: Village ID + ***************************/ + function getVillageType($wref) { + $q = "SELECT id, fieldtype FROM " . TB_PREFIX . "wdata where id = $wref"; + $result = mysql_query($q, $this->connection); + $dbarray = mysql_fetch_array($result); + return $dbarray['fieldtype']; + } + + + + /***************************************** + Function to retrieve if is ocuped via ID + References: Village ID + *****************************************/ + function getVillageState($wref) { + $q = "SELECT oasistype,occupied FROM " . TB_PREFIX . "wdata where id = $wref"; + $result = mysql_query($q, $this->connection); + $dbarray = mysql_fetch_array($result); + if($dbarray['occupied'] != 0 || $dbarray['oasistype'] != 0) { + return true; + } else { + return false; + } + } + + function getProfileVillages($uid) { + $q = "SELECT capital,wref,name,pop,created from " . TB_PREFIX . "vdata where owner = $uid order by pop desc"; + $result = mysql_query($q, $this->connection); + return $this->mysql_fetch_all($result); + } + + function getProfileMedal($uid) { + $q = "SELECT id,categorie,plaats,week,img,points from " . TB_PREFIX . "medal where userid = $uid order by id desc"; + $result = mysql_query($q, $this->connection); + return $this->mysql_fetch_all($result); + + } + + function getProfileMedalAlly($uid) { + $q = "SELECT id,categorie,plaats,week,img,points from " . TB_PREFIX . "allimedal where allyid = $uid order by id desc"; + $result = mysql_query($q, $this->connection); + return $this->mysql_fetch_all($result); + + } + + function getVillageID($uid) { + $q = "SELECT wref FROM " . TB_PREFIX . "vdata WHERE owner = $uid"; + $result = mysql_query($q, $this->connection); + $dbarray = mysql_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 = mysql_query($q, $this->connection); + $array = $this->mysql_fetch_all($result); + $newarray = array(); + for($i = 0; $i < count($array); $i++) { + array_push($newarray, $array[$i]['wref']); + } + return $newarray; + } + + function getVillage($vid) { + $q = "SELECT * FROM " . TB_PREFIX . "vdata where wref = $vid"; + $result = mysql_query($q, $this->connection); + return mysql_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 = mysql_query($q, $this->connection); + return mysql_fetch_array($result); + } + + public function getPopulation($uid) { + $q = "SELECT sum(pop) AS pop FROM ".TB_PREFIX."vdata WHERE owner=".$uid; + $result = mysql_query($q, $this->connection); + $dbarray = mysql_fetch_array($result); + return $dbarray['pop']; + } + + function getOasisV($vid) { + $q = "SELECT * FROM " . TB_PREFIX . "odata where wref = $vid"; + $result = mysql_query($q, $this->connection); + return mysql_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 = mysql_query($q, $this->connection); + return mysql_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 = mysql_query($q, $this->connection); + return mysql_fetch_array($result); + } + + function getOasis($vid) { + $q = "SELECT * FROM " . TB_PREFIX . "odata where conqured = $vid"; + $result = mysql_query($q, $this->connection); + return $this->mysql_fetch_all($result); + } + + function getOasisInfo($wid) { + $q = "SELECT * FROM " . TB_PREFIX . "odata where wref = $wid"; + $result = mysql_query($q, $this->connection); + return mysql_fetch_assoc($result); + } + + function getVillageField($ref, $field) { + $q = "SELECT $field FROM " . TB_PREFIX . "vdata where wref = $ref"; + $result = mysql_query($q, $this->connection); + $dbarray = mysql_fetch_array($result); + return $dbarray[$field]; + + } + + function getOasisField($ref, $field) { + $q = "SELECT $field FROM " . TB_PREFIX . "odata where wref = $ref"; + $result = mysql_query($q, $this->connection); + $dbarray = mysql_fetch_array($result); + return $dbarray[$field]; + } + + function setVillageField($ref, $field, $value) { + $q = "UPDATE " . TB_PREFIX . "vdata set $field = '$value' where wref = $ref"; + return mysql_query($q, $this->connection); + } + + function setVillageLevel($ref, $field, $value) { + $q = "UPDATE " . TB_PREFIX . "fdata set " . $field . " = '" . $value . "' where vref = " . $ref . ""; + return mysql_query($q, $this->connection); + } + + function getResourceLevel($vid) { + $q = "SELECT * from " . TB_PREFIX . "fdata where vref = $vid"; + $result = mysql_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 = mysql_query($q, $this->connection); + return $this->mysql_fetch_all($result); + } + + function getCoor($wref) { + if ($wref !=""){ + $q = "SELECT x,y FROM " . TB_PREFIX . "wdata where id = $wref"; + $result = mysql_query($q, $this->connection); + return mysql_fetch_array($result); + } + } + + function CheckForum($id) { + $q = "SELECT * from " . TB_PREFIX . "forum_cat where alliance = '$id'"; + $result = mysql_query($q, $this->connection); + if(mysql_num_rows($result)) { + return true; + } else { + return false; + } + } + + function CountCat($id) { + $q = "SELECT count(id) FROM " . TB_PREFIX . "forum_topic where cat = '$id'"; + $result = mysql_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 = mysql_query($q, $this->connection); + return $this->mysql_fetch_all($result); + } + + function CheckLastTopic($id) { + $q = "SELECT * from " . TB_PREFIX . "forum_topic where cat = '$id'"; + $result = mysql_query($q, $this->connection); + if(mysql_num_rows($result)) { + return true; + } else { + return false; + } + } + + function CheckLastPost($id) { + $q = "SELECT * from " . TB_PREFIX . "forum_post where topic = '$id'"; + $result = mysql_query($q, $this->connection); + if(mysql_num_rows($result)) { + return true; + } else { + return false; + } + } + + function LastPost($id) { + $q = "SELECT * from " . TB_PREFIX . "forum_post where topic = '$id'"; + $result = mysql_query($q, $this->connection); + return $this->mysql_fetch_all($result); + } + + function CountTopic($id) { + $q = "SELECT count(id) FROM " . TB_PREFIX . "forum_post where owner = '$id'"; + $result = mysql_query($q, $this->connection); + $row = mysql_fetch_row($result); + + $qs = "SELECT count(id) FROM " . TB_PREFIX . "forum_topic where owner = '$id'"; + $results = mysql_query($qs, $this->connection); + $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 = mysql_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 = mysql_query($q, $this->connection); + return $this->mysql_fetch_all($result); + } + + function ForumCatEdit($id) { + $q = "SELECT * from " . TB_PREFIX . "forum_cat where id = '$id'"; + $result = mysql_query($q, $this->connection); + return $this->mysql_fetch_all($result); + } + + function ForumCatName($id) { + $q = "SELECT forum_name from " . TB_PREFIX . "forum_cat where id = $id"; + $result = mysql_query($q, $this->connection); + $dbarray = mysql_fetch_array($result); + return $dbarray['forum_name']; + } + + function CheckCatTopic($id) { + $q = "SELECT * from " . TB_PREFIX . "forum_topic where cat = '$id'"; + $result = mysql_query($q, $this->connection); + if(mysql_num_rows($result)) { + return true; + } else { + return false; + } + } + + function CheckResultEdit($alli) { + $q = "SELECT * from " . TB_PREFIX . "forum_edit where alliance = '$alli'"; + $result = mysql_query($q, $this->connection); + if(mysql_num_rows($result)) { + return true; + } else { + return false; + } + } + + function CheckCloseTopic($id) { + $q = "SELECT close from " . TB_PREFIX . "forum_topic where id = '$id'"; + $result = mysql_query($q, $this->connection); + $dbarray = mysql_fetch_array($result); + return $dbarray['close']; + } + + function CheckEditRes($alli) { + $q = "SELECT result from " . TB_PREFIX . "forum_edit where alliance = '$alli'"; + $result = mysql_query($q, $this->connection); + $dbarray = mysql_fetch_array($result); + return $dbarray['result']; + } + + function CreatResultEdit($alli, $result) { + $q = "INSERT into " . TB_PREFIX . "forum_edit values (0,'$alli','$result')"; + mysql_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 mysql_query($q, $this->connection); + } + +function getVillageType2($wref) { + $q = "SELECT * FROM " . TB_PREFIX . "wdata where id = $wref"; +//$q = "SELECT * FROM " . TB_PREFIX . "units where id = $wref"; + $result = mysql_query($q, $this->connection); + $dbarray = mysql_fetch_array($result); + return $dbarray['oasistype']; + } + +function getFLData($id) { + $q = "SELECT * FROM " . TB_PREFIX . "farmlist where id = $id"; + $result = mysql_query($q, $this->connection); + return mysql_fetch_array($result); + } + +function checkVilExist($wref) { + $q = "SELECT * FROM " . TB_PREFIX . "vdata where wref = '$wref'"; + $result = mysql_query($q, $this->connection); + if(mysql_num_rows($result)) { + return true; + } else { + return false; + } + } + + function UpdateEditTopic($id, $title, $cat) { + $q = "UPDATE " . TB_PREFIX . "forum_topic set title = '$title', cat = '$cat' where id = $id"; + return mysql_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 mysql_query($q, $this->connection); + } + + function StickTopic($id, $mode) { + $q = "UPDATE " . TB_PREFIX . "forum_topic set stick = '$mode' where id = '$id'"; + return mysql_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 = mysql_query($q, $this->connection); + return $this->mysql_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 = mysql_query($q, $this->connection); + return $this->mysql_fetch_all($result); + } + + function ShowTopic($id) { + $q = "SELECT * from " . TB_PREFIX . "forum_topic where id = '$id'"; + $result = mysql_query($q, $this->connection); + return $this->mysql_fetch_all($result); + } + + function ShowPost($id) { + $q = "SELECT * from " . TB_PREFIX . "forum_post where topic = '$id'"; + $result = mysql_query($q, $this->connection); + return $this->mysql_fetch_all($result); + } + + function ShowPostEdit($id) { + $q = "SELECT * from " . TB_PREFIX . "forum_post where id = '$id'"; + $result = mysql_query($q, $this->connection); + return $this->mysql_fetch_all($result); + } + + function CreatForum($owner, $alli, $name, $des, $area) { + $q = "INSERT into " . TB_PREFIX . "forum_cat values (0,'$owner','$alli','$name','$des','$area')"; + mysql_query($q, $this->connection); + return mysql_insert_id($this->connection); + } + + function CreatTopic($title, $post, $cat, $owner, $alli, $ends) { + $date = time(); + $q = "INSERT into " . TB_PREFIX . "forum_topic values (0,'$title','$post','$date','$date','$cat','$owner','$alli','$ends','','')"; + mysql_query($q, $this->connection); + return mysql_insert_id($this->connection); + } + + function CreatPost($post, $tids, $owner) { + $date = time(); + $q = "INSERT into " . TB_PREFIX . "forum_post values (0,'$post','$tids','$owner','$date')"; + mysql_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 mysql_query($q, $this->connection); + } + + function EditUpdateTopic($id, $post) { + $q = "UPDATE " . TB_PREFIX . "forum_topic set post = '$post' where id = $id"; + return mysql_query($q, $this->connection); + } + + function EditUpdatePost($id, $post) { + $q = "UPDATE " . TB_PREFIX . "forum_post set post = '$post' where id = $id"; + return mysql_query($q, $this->connection); + } + + function LockTopic($id, $mode) { + $q = "UPDATE " . TB_PREFIX . "forum_topic set close = '$mode' where id = '$id'"; + return mysql_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'"; + mysql_query($qs, $this->connection); + return mysql_query($q, $this->connection); + } + + function DeleteTopic($id) { + $qs = "DELETE from " . TB_PREFIX . "forum_topic where id = '$id'"; + // $q = "DELETE from ".TB_PREFIX."forum_post where topic = '$id'";// + return mysql_query($qs, $this->connection); // + // mysql_query($q,$this->connection); + } + + function DeletePost($id) { + $q = "DELETE from " . TB_PREFIX . "forum_post where id = '$id'"; + return mysql_query($q, $this->connection); + } + + function getAllianceName($id) { + $q = "SELECT tag from " . TB_PREFIX . "alidata where id = $id"; + $result = mysql_query($q, $this->connection); + $dbarray = mysql_fetch_array($result); + return $dbarray['tag']; + } + + function getAlliancePermission($ref, $field, $mode) { + if(!$mode) { + $q = "SELECT $field FROM " . TB_PREFIX . "ali_permission where uid = '$ref'"; + } else { + $q = "SELECT $field FROM " . TB_PREFIX . "ali_permission where username = '$ref'"; + } + $result = mysql_query($q, $this->connection) or die(mysql_error()); + $dbarray = mysql_fetch_array($result); + return $dbarray[$field]; + } + + function getAlliance($id) { + $q = "SELECT * from " . TB_PREFIX . "alidata where id = $id"; + $result = mysql_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 mysql_query($q, $this->connection); + } + + function isAllianceOwner($id) { + $q = "SELECT * from " . TB_PREFIX . "alidata where leader = '$id'"; + $result = mysql_query($q, $this->connection); + if(mysql_num_rows($result)) { + return true; + } else { + return false; + } + } + + function aExist($ref, $type) { + $q = "SELECT $type FROM " . TB_PREFIX . "alidata where $type = '$ref'"; + $result = mysql_query($q, $this->connection); + if(mysql_num_rows($result)) { + return true; + } else { + return false; + } + } + + function modifyPoints($aid, $points, $amt) { + $q = "UPDATE " . TB_PREFIX . "users set $points = $points + $amt where id = $aid"; + return mysql_query($q, $this->connection); + } + + function modifyPointsAlly($aid, $points, $amt) { + $q = "UPDATE " . TB_PREFIX . "alidata set $points = $points + $amt where id = $aid"; + return mysql_query($q, $this->connection); + } + + /***************************************** + Function to create an alliance + References: + *****************************************/ + function createAlliance($tag, $name, $uid, $max) { + $q = "INSERT into " . TB_PREFIX . "alidata values (0,'$name','$tag',$uid,0,0,0,'','',$max,'','','','','','','','')"; + mysql_query($q, $this->connection); + return mysql_insert_id($this->connection); + } + + /***************************************** + Function to insert an alliance new + References: + *****************************************/ + function insertAlliNotice($aid, $notice) { + $time = time(); + $q = "INSERT into " . TB_PREFIX . "ali_log values (0,'$aid','$notice',$time)"; + mysql_query($q, $this->connection); + return mysql_insert_id($this->connection); + } + + /***************************************** + Function to delete alliance if empty + References: + *****************************************/ + function deleteAlliance($aid) { + $result = mysql_query("SELECT * FROM " . TB_PREFIX . "users where alliance = $aid"); + $num_rows = mysql_num_rows($result); + if($num_rows == 0) { + $q = "DELETE FROM " . TB_PREFIX . "alidata WHERE id = $aid"; + } + mysql_query($q, $this->connection); + return mysql_insert_id($this->connection); + } + + /***************************************** + Function to read all alliance news + References: + *****************************************/ + function readAlliNotice($aid) { + $q = "SELECT * from " . TB_PREFIX . "ali_log where aid = $aid ORDER BY date DESC"; + $result = mysql_query($q, $this->connection); + return $this->mysql_fetch_all($result); + } + + /***************************************** + Function to create alliance permissions + References: ID, notice, description + *****************************************/ + 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')"; + mysql_query($q, $this->connection); + return mysql_insert_id($this->connection); + } + + /***************************************** + Function to update alliance permissions + References: + *****************************************/ + function deleteAlliPermissions($uid) { + $q = "DELETE from " . TB_PREFIX . "ali_permission where uid = '$uid'"; + return mysql_query($q, $this->connection); + } + /***************************************** + Function to update alliance permissions + References: + *****************************************/ + 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 mysql_query($q, $this->connection); + } + + /***************************************** + Function to read alliance permissions + References: ID, notice, description + *****************************************/ + function getAlliPermissions($uid, $aid) { + $q = "SELECT * FROM " . TB_PREFIX . "ali_permission where uid = $uid && alliance = $aid"; + $result = mysql_query($q, $this->connection); + return mysql_fetch_assoc($result); + } + + /***************************************** + Function to update an alliance description and notice + References: ID, notice, description + *****************************************/ + function submitAlliProfile($aid, $notice, $desc) { + + $q = "UPDATE " . TB_PREFIX . "alidata SET `notice` = '$notice', `desc` = '$desc' where id = $aid"; + return mysql_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 mysql_query($q, $this->connection); + } + + function diplomacyOwnOffers($session_alliance) { + $q = "SELECT * FROM " . TB_PREFIX . "diplomacy WHERE alli1 = $session_alliance AND accepted = 0"; + $result = mysql_query($q, $this->connection); + return $this->mysql_fetch_all($result); + } function getAllianceID($name) { - $q = "SELECT id FROM " . TB_PREFIX . "alidata WHERE tag ='" . $this->RemoveXSS($name) . "'"; - $result = mysql_query($q, $this->connection); - $dbarray = mysql_fetch_array($result); - return $dbarray['id']; - } + $q = "SELECT id FROM " . TB_PREFIX . "alidata WHERE tag ='" . $this->RemoveXSS($name) . "'"; + $result = mysql_query($q, $this->connection); + $dbarray = mysql_fetch_array($result); + return $dbarray['id']; + } - function getDiplomacy($aid) { - $q = "SELECT * FROM " . TB_PREFIX . "diplomacy WHERE id = $aid"; - $result = mysql_query($q, $this->connection); - return $this->mysql_fetch_all($result); - } + function getDiplomacy($aid) { + $q = "SELECT * FROM " . TB_PREFIX . "diplomacy WHERE id = $aid"; + $result = mysql_query($q, $this->connection); + return $this->mysql_fetch_all($result); + } - function diplomacyCancelOffer($id) { - $q = "DELETE FROM " . TB_PREFIX . "diplomacy WHERE id = $id"; - return mysql_query($q, $this->connection); - } + function diplomacyCancelOffer($id) { + $q = "DELETE FROM " . TB_PREFIX . "diplomacy WHERE id = $id"; + return mysql_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 mysql_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 mysql_query($q, $this->connection); + } - function diplomacyInviteDenied($id, $session_alliance) { - $q = "DELETE FROM " . TB_PREFIX . "diplomacy WHERE id = $id AND alli2 = $session_alliance"; - return mysql_query($q, $this->connection); - } + function diplomacyInviteDenied($id, $session_alliance) { + $q = "DELETE FROM " . TB_PREFIX . "diplomacy WHERE id = $id AND alli2 = $session_alliance"; + return mysql_query($q, $this->connection); + } - function diplomacyInviteCheck($session_alliance) { - $q = "SELECT * FROM " . TB_PREFIX . "diplomacy WHERE alli2 = $session_alliance AND accepted = 0"; - $result = mysql_query($q, $this->connection); - return $this->mysql_fetch_all($result); - } + function diplomacyInviteCheck($session_alliance) { + $q = "SELECT * FROM " . TB_PREFIX . "diplomacy WHERE alli2 = $session_alliance AND accepted = 0"; + $result = mysql_query($q, $this->connection); + return $this->mysql_fetch_all($result); + } function getAllianceDipProfile($aid, $type){ $q = "SELECT * FROM ".TB_PREFIX."diplomacy WHERE alli1 = '$aid' AND type = '$type' AND accepted = '1'"; @@ -1202,7 +1233,7 @@ } return $text; } - + function getAllianceWar($aid){ $q = "SELECT * FROM ".TB_PREFIX."diplomacy WHERE alli1 = '$aid' AND type = '3'"; $result = mysql_query($q, $this->connection); @@ -1226,96 +1257,96 @@ } return $text; } - + function getAllianceAlly($aid, $type){ $q = "SELECT * FROM ".TB_PREFIX."diplomacy WHERE (alli1 = '$aid' or alli2 = '$aid') AND (type = '$type' AND accepted = '1')"; $result = mysql_query($q, $this->connection); return $this->mysql_fetch_all($result); } - function getAllianceWar2($aid){ + function getAllianceWar2($aid){ $q = "SELECT * FROM ".TB_PREFIX."diplomacy WHERE alli2 = '$aid' or alli1 = '$aid' AND accepted = '1'"; $result = mysql_query($q, $this->connection); return $this->mysql_fetch_all($result); } - function diplomacyExistingRelationships($session_alliance) { - $q = "SELECT * FROM " . TB_PREFIX . "diplomacy WHERE alli2 = $session_alliance AND accepted = 1"; - $result = mysql_query($q, $this->connection); - return $this->mysql_fetch_all($result); - } + function diplomacyExistingRelationships($session_alliance) { + $q = "SELECT * FROM " . TB_PREFIX . "diplomacy WHERE alli2 = $session_alliance AND accepted = 1"; + $result = mysql_query($q, $this->connection); + return $this->mysql_fetch_all($result); + } function diplomacyExistingRelationships2($session_alliance) { - $q = "SELECT * FROM " . TB_PREFIX . "diplomacy WHERE alli1 = $session_alliance AND accepted = 1"; - $result = mysql_query($q, $this->connection); - return $this->mysql_fetch_all($result); - } + $q = "SELECT * FROM " . TB_PREFIX . "diplomacy WHERE alli1 = $session_alliance AND accepted = 1"; + $result = mysql_query($q, $this->connection); + return $this->mysql_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 mysql_query($q, $this->connection); - } + 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 mysql_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 = mysql_query($q, $this->connection); - $dbarray = mysql_fetch_array($result); - if($dbarray['tag'] == "") { - return "-"; - } else { - return $dbarray['tag']; - } - } + 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 = mysql_query($q, $this->connection); + $dbarray = mysql_fetch_array($result); + if($dbarray['tag'] == "") { + return "-"; + } else { + return $dbarray['tag']; + } + } - function modifyResource($vid, $wood, $clay, $iron, $crop, $mode) { - if(!$mode) { - $q = "UPDATE " . TB_PREFIX . "vdata set wood = wood - $wood, clay = clay - $clay, iron = iron - $iron, crop = crop - $crop where wref = $vid"; - } else { - $q = "UPDATE " . TB_PREFIX . "vdata set wood = wood + $wood, clay = clay + $clay, iron = iron + $iron, crop = crop + $crop where wref = $vid"; - } - return mysql_query($q, $this->connection); - } + function modifyResource($vid, $wood, $clay, $iron, $crop, $mode) { + if(!$mode) { + $q = "UPDATE " . TB_PREFIX . "vdata set wood = wood - $wood, clay = clay - $clay, iron = iron - $iron, crop = crop - $crop where wref = $vid"; + } else { + $q = "UPDATE " . TB_PREFIX . "vdata set wood = wood + $wood, clay = clay + $clay, iron = iron + $iron, crop = crop + $crop where wref = $vid"; + } + return mysql_query($q, $this->connection); + } - 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 mysql_query($q, $this->connection); - } + 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 mysql_query($q, $this->connection); + } - function getFieldLevel($vid, $field) { - $q = "SELECT f" . $field . " from " . TB_PREFIX . "fdata where vref = $vid"; - $result = mysql_query($q, $this->connection); - return mysql_result($result, 0); - } + function getFieldLevel($vid, $field) { + $q = "SELECT f" . $field . " from " . TB_PREFIX . "fdata where vref = $vid"; + $result = mysql_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 = mysql_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 = mysql_query($q, $this->connection); + return mysql_result($result, 0); + } - function getVSumField($uid, $field) { - $q = "SELECT sum(" . $field . ") FROM " . TB_PREFIX . "vdata where owner = $uid"; - $result = mysql_query($q, $this->connection); - $row = mysql_fetch_row($result); - return $row[0]; - } + function getVSumField($uid, $field) { + $q = "SELECT sum(" . $field . ") FROM " . TB_PREFIX . "vdata where owner = $uid"; + $result = mysql_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 mysql_query($q, $this->connection); - } - function updateOasis($vid) { - $time = time(); - $q = "UPDATE " . TB_PREFIX . "odata set lastupdated = $time where wref = $vid"; - return mysql_query($q, $this->connection); - } + function updateVillage($vid) { + $time = time(); + $q = "UPDATE " . TB_PREFIX . "vdata set lastupdate = $time where wref = $vid"; + return mysql_query($q, $this->connection); + } + function updateOasis($vid) { + $time = time(); + $q = "UPDATE " . TB_PREFIX . "odata set lastupdated = $time where wref = $vid"; + return mysql_query($q, $this->connection); + } - function setVillageName($vid, $name) { + function setVillageName($vid, $name) { if(!empty($name)) { $q = "UPDATE " . TB_PREFIX . "vdata set name = '$name' where wref = $vid"; @@ -1323,552 +1354,552 @@ } } - function modifyPop($vid, $pop, $mode) { - if(!$mode) { - $q = "UPDATE " . TB_PREFIX . "vdata set pop = pop + $pop where wref = $vid"; - } else { - $q = "UPDATE " . TB_PREFIX . "vdata set pop = pop - $pop where wref = $vid"; - } - return mysql_query($q, $this->connection); - } + function modifyPop($vid, $pop, $mode) { + if(!$mode) { + $q = "UPDATE " . TB_PREFIX . "vdata set pop = pop + $pop where wref = $vid"; + } else { + $q = "UPDATE " . TB_PREFIX . "vdata set pop = pop - $pop where wref = $vid"; + } + return mysql_query($q, $this->connection); + } - function addCP($ref, $cp) { - $q = "UPDATE " . TB_PREFIX . "vdata set cp = cp + $cp where wref = $ref"; - return mysql_query($q, $this->connection); - } + function addCP($ref, $cp) { + $q = "UPDATE " . TB_PREFIX . "vdata set cp = cp + $cp where wref = $ref"; + return mysql_query($q, $this->connection); + } - function addCel($ref, $cel, $type) { - $q = "UPDATE " . TB_PREFIX . "vdata set celebration = $cel, type= $type where wref = $ref"; - return mysql_query($q, $this->connection); - } - function getCel() { - $time = time(); - $q = "SELECT * FROM " . TB_PREFIX . "vdata where celebration < $time AND celebration != 0"; - $result = mysql_query($q, $this->connection); - return $this->mysql_fetch_all($result); - } + function addCel($ref, $cel, $type) { + $q = "UPDATE " . TB_PREFIX . "vdata set celebration = $cel, type= $type where wref = $ref"; + return mysql_query($q, $this->connection); + } + function getCel() { + $time = time(); + $q = "SELECT * FROM " . TB_PREFIX . "vdata where celebration < $time AND celebration != 0"; + $result = mysql_query($q, $this->connection); + return $this->mysql_fetch_all($result); + } - function clearCel($ref) { - $q = "UPDATE " . TB_PREFIX . "vdata set celebration = 0, type = 0 where wref = $ref"; - return mysql_query($q, $this->connection); - } - function setCelCp($user, $cp) { - $q = "UPDATE " . TB_PREFIX . "users set cp = cp + $cp where id = $user"; - return mysql_query($q, $this->connection); - } + function clearCel($ref) { + $q = "UPDATE " . TB_PREFIX . "vdata set celebration = 0, type = 0 where wref = $ref"; + return mysql_query($q, $this->connection); + } + function setCelCp($user, $cp) { + $q = "UPDATE " . TB_PREFIX . "users set cp = cp + $cp where id = $user"; + return mysql_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; - mysql_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; + mysql_query($q, $this->connection); + } + } - function getInvitation($uid) { - $q = "SELECT * FROM " . TB_PREFIX . "ali_invite where uid = $uid"; - $result = mysql_query($q, $this->connection); - return $this->mysql_fetch_all($result); - } + function getInvitation($uid) { + $q = "SELECT * FROM " . TB_PREFIX . "ali_invite where uid = $uid"; + $result = mysql_query($q, $this->connection); + return $this->mysql_fetch_all($result); + } - function getAliInvitations($aid) { - $q = "SELECT * FROM " . TB_PREFIX . "ali_invite where alliance = $aid && accept = 0"; - $result = mysql_query($q, $this->connection); - return $this->mysql_fetch_all($result); - } + function getAliInvitations($aid) { + $q = "SELECT * FROM " . TB_PREFIX . "ali_invite where alliance = $aid && accept = 0"; + $result = mysql_query($q, $this->connection); + return $this->mysql_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 mysql_query($q, $this->connection) or die(mysql_error()); - } + function sendInvitation($uid, $alli, $sender) { + $time = time(); + $q = "INSERT INTO " . TB_PREFIX . "ali_invite values (0,$uid,$alli,$sender,$time,0)"; + return mysql_query($q, $this->connection) or die(mysql_error()); + } - function removeInvitation($id) { - $q = "DELETE FROM " . TB_PREFIX . "ali_invite where id = $id"; - return mysql_query($q, $this->connection); - } + function removeInvitation($id) { + $q = "DELETE FROM " . TB_PREFIX . "ali_invite where id = $id"; + return mysql_query($q, $this->connection); + } - function sendMessage($client, $owner, $topic, $message, $send) { - $time = time(); - $q = "INSERT INTO " . TB_PREFIX . "mdata values (0,$client,$owner,'$topic',\"$message\",0,0,$send,$time)"; - return mysql_query($q, $this->connection); - } + function sendMessage($client, $owner, $topic, $message, $send) { + $time = time(); + $q = "INSERT INTO " . TB_PREFIX . "mdata values (0,$client,$owner,'$topic',\"$message\",0,0,$send,$time)"; + return mysql_query($q, $this->connection); + } - function setArchived($id) { - $q = "UPDATE " . TB_PREFIX . "mdata set archived = 1 where id = $id"; - return mysql_query($q, $this->connection); - } + function setArchived($id) { + $q = "UPDATE " . TB_PREFIX . "mdata set archived = 1 where id = $id"; + return mysql_query($q, $this->connection); + } - function setNorm($id) { - $q = "UPDATE " . TB_PREFIX . "mdata set archived = 0 where id = $id"; - return mysql_query($q, $this->connection); - } + function setNorm($id) { + $q = "UPDATE " . TB_PREFIX . "mdata set archived = 0 where id = $id"; + return mysql_query($q, $this->connection); + } - /*************************** - Function to get messages - Mode 1: Get inbox - Mode 2: Get sent - Mode 3: Get message - Mode 4: Set viewed - Mode 5: Remove message - Mode 6: Retrieve archive - References: User ID/Message ID, Mode - ***************************/ - function getMessage($id, $mode) { - global $session; - switch($mode) { - case 1: - $q = "SELECT * FROM " . TB_PREFIX . "mdata WHERE target = $id and send = 0 and archived = 0 ORDER BY time DESC"; - break; - case 2: - // removed send no longer needed as we dont send 2 messages any more just 1 - $q = "SELECT * FROM " . TB_PREFIX . "mdata WHERE owner = $id ORDER BY time DESC"; - break; - case 3: - $q = "SELECT * FROM " . TB_PREFIX . "mdata where id = $id"; - break; - case 4: - $q = "UPDATE " . TB_PREFIX . "mdata set viewed = 1 where id = $id AND target = $session->uid"; - break; - case 5: - $q = "DELETE FROM " . TB_PREFIX . "mdata where id = $id"; - break; - case 6: - $q = "SELECT * FROM " . TB_PREFIX . "mdata where target = $id and send = 0 and archived = 1"; - break; - } - if($mode <= 3 || $mode == 6) { - $result = mysql_query($q, $this->connection); - return $this->mysql_fetch_all($result); - } else { - return mysql_query($q, $this->connection); - } - } + /*************************** + Function to get messages + Mode 1: Get inbox + Mode 2: Get sent + Mode 3: Get message + Mode 4: Set viewed + Mode 5: Remove message + Mode 6: Retrieve archive + References: User ID/Message ID, Mode + ***************************/ + function getMessage($id, $mode) { + global $session; + switch($mode) { + case 1: + $q = "SELECT * FROM " . TB_PREFIX . "mdata WHERE target = $id and send = 0 and archived = 0 ORDER BY time DESC"; + break; + case 2: + // removed send no longer needed as we dont send 2 messages any more just 1 + $q = "SELECT * FROM " . TB_PREFIX . "mdata WHERE owner = $id ORDER BY time DESC"; + break; + case 3: + $q = "SELECT * FROM " . TB_PREFIX . "mdata where id = $id"; + break; + case 4: + $q = "UPDATE " . TB_PREFIX . "mdata set viewed = 1 where id = $id AND target = $session->uid"; + break; + case 5: + $q = "DELETE FROM " . TB_PREFIX . "mdata where id = $id"; + break; + case 6: + $q = "SELECT * FROM " . TB_PREFIX . "mdata where target = $id and send = 0 and archived = 1"; + break; + } + if($mode <= 3 || $mode == 6) { + $result = mysql_query($q, $this->connection); + return $this->mysql_fetch_all($result); + } else { + return mysql_query($q, $this->connection); + } + } - function unarchiveNotice($id) { - $q = "UPDATE " . TB_PREFIX . "ndata set ntype = archive, archive = 0 where id = $id"; - return mysql_query($q, $this->connection); - } + function unarchiveNotice($id) { + $q = "UPDATE " . TB_PREFIX . "ndata set ntype = archive, archive = 0 where id = $id"; + return mysql_query($q, $this->connection); + } - function archiveNotice($id) { - $q = "update " . TB_PREFIX . "ndata set archive = ntype, ntype = 9 where id = $id"; - return mysql_query($q, $this->connection); - } + function archiveNotice($id) { + $q = "update " . TB_PREFIX . "ndata set archive = ntype, ntype = 9 where id = $id"; + return mysql_query($q, $this->connection); + } - function removeNotice($id) { - $q = "DELETE FROM " . TB_PREFIX . "ndata where id = $id"; - return mysql_query($q, $this->connection); - } + function removeNotice($id) { + $q = "DELETE FROM " . TB_PREFIX . "ndata where id = $id"; + return mysql_query($q, $this->connection); + } - function noticeViewed($id) { - $q = "UPDATE " . TB_PREFIX . "ndata set viewed = 1 where id = $id"; - return mysql_query($q, $this->connection); - } + function noticeViewed($id) { + $q = "UPDATE " . TB_PREFIX . "ndata set viewed = 1 where id = $id"; + return mysql_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 mysql_query($q, $this->connection) or die(mysql_error()); - } + 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 mysql_query($q, $this->connection) or die(mysql_error()); + } - function getNotice($uid) { - $q = "SELECT * FROM " . TB_PREFIX . "ndata where uid = $uid ORDER BY time DESC"; - $result = mysql_query($q, $this->connection); - return $this->mysql_fetch_all($result); - } - - function getNotice2($id, $field) { - $q = "SELECT ".$field." FROM " . TB_PREFIX . "ndata where `id` = '$id'"; - $result = mysql_query($q, $this->connection); - $dbarray = mysql_fetch_array($result); - return $dbarray[$field]; - } + function getNotice($uid) { + $q = "SELECT * FROM " . TB_PREFIX . "ndata where uid = $uid ORDER BY time DESC"; + $result = mysql_query($q, $this->connection); + return $this->mysql_fetch_all($result); + } + + function getNotice2($id, $field) { + $q = "SELECT ".$field." FROM " . TB_PREFIX . "ndata where `id` = '$id'"; + $result = mysql_query($q, $this->connection); + $dbarray = mysql_fetch_array($result); + return $dbarray[$field]; + } - function addBuilding($wid, $field, $type, $loop, $time) { - $x = "UPDATE " . TB_PREFIX . "fdata SET f" . $field . "t=" . $type . " WHERE vref=" . $wid; - mysql_query($x, $this->connection) or die(mysql_error()); - $q = "INSERT into " . TB_PREFIX . "bdata values (0,$wid,$field,$type,$loop,$time)"; - return mysql_query($q, $this->connection); - } + function addBuilding($wid, $field, $type, $loop, $time) { + $x = "UPDATE " . TB_PREFIX . "fdata SET f" . $field . "t=" . $type . " WHERE vref=" . $wid; + mysql_query($x, $this->connection) or die(mysql_error()); + $q = "INSERT into " . TB_PREFIX . "bdata values (0,$wid,$field,$type,$loop,$time)"; + return mysql_query($q, $this->connection); + } - function removeBuilding($d) { - global $building; - $jobLoopconID = -1; - $SameBuildCount = 0; - $jobs = $building->buildArray; - for($i = 0; $i < sizeof($jobs); $i++) { - if($jobs[$i]['id'] == $d) { - $jobDeleted = $i; - } - if($jobs[$i]['loopcon'] == 1) { - $jobLoopconID = $i; - } - } - if(count($jobs) > 1 && ($jobs[0]['field'] == $jobs[1]['field'])) { - $SameBuildCount = 1; - } - if(count($jobs) > 2 && ($jobs[0]['field'] == $jobs[2]['field'])) { - $SameBuildCount = 2; - } - if(count($jobs) > 2 && ($jobs[1]['field'] == $jobs[2]['field'])) { - $SameBuildCount = 3; - } + function removeBuilding($d) { + global $building; + $jobLoopconID = -1; + $SameBuildCount = 0; + $jobs = $building->buildArray; + for($i = 0; $i < sizeof($jobs); $i++) { + if($jobs[$i]['id'] == $d) { + $jobDeleted = $i; + } + if($jobs[$i]['loopcon'] == 1) { + $jobLoopconID = $i; + } + } + if(count($jobs) > 1 && ($jobs[0]['field'] == $jobs[1]['field'])) { + $SameBuildCount = 1; + } + if(count($jobs) > 2 && ($jobs[0]['field'] == $jobs[2]['field'])) { + $SameBuildCount = 2; + } + if(count($jobs) > 2 && ($jobs[1]['field'] == $jobs[2]['field'])) { + $SameBuildCount = 3; + } - if($SameBuildCount > 0) { - if($d == $jobs[floor($SameBuildCount / 3)]['id'] || $d == $jobs[floor($SameBuildCount / 2) + 1]['id']) { - $q = "UPDATE " . TB_PREFIX . "bdata SET loopcon=0,timestamp=" . $jobs[floor($SameBuildCount / 3)]['timestamp'] . " WHERE ID=" . $jobs[floor($SameBuildCount / 3)]['id'] . " OR ID=" . $jobs[floor($SameBuildCount / 2) + 1]['id']; - mysql_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 = mysql_query($x, $this->connection) or die(mysql_error()); - $fieldlevel = mysql_fetch_row($result); - if($fieldlevel[0] == 0) { - $x = "UPDATE " . TB_PREFIX . "fdata SET f" . $jobs[$jobDeleted]['field'] . "t=0 WHERE vref=" . $jobs[$jobDeleted]['wid']; - mysql_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)) { - $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"; - mysql_query($x, $this->connection) or die(mysql_error()); - } - } - } - $q = "DELETE FROM " . TB_PREFIX . "bdata where id = $d"; - return mysql_query($q, $this->connection); - } + if($SameBuildCount > 0) { + if($d == $jobs[floor($SameBuildCount / 3)]['id'] || $d == $jobs[floor($SameBuildCount / 2) + 1]['id']) { + $q = "UPDATE " . TB_PREFIX . "bdata SET loopcon=0,timestamp=" . $jobs[floor($SameBuildCount / 3)]['timestamp'] . " WHERE ID=" . $jobs[floor($SameBuildCount / 3)]['id'] . " OR ID=" . $jobs[floor($SameBuildCount / 2) + 1]['id']; + mysql_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 = mysql_query($x, $this->connection) or die(mysql_error()); + $fieldlevel = mysql_fetch_row($result); + if($fieldlevel[0] == 0) { + $x = "UPDATE " . TB_PREFIX . "fdata SET f" . $jobs[$jobDeleted]['field'] . "t=0 WHERE vref=" . $jobs[$jobDeleted]['wid']; + mysql_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)) { + $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"; + mysql_query($x, $this->connection) or die(mysql_error()); + } + } + } + $q = "DELETE FROM " . TB_PREFIX . "bdata where id = $d"; + return mysql_query($q, $this->connection); + } - function addDemolition($wid, $field) { - global $building, $village; - $q = "DELETE FROM ".TB_PREFIX."bdata WHERE field=$field AND wid=$wid"; - mysql_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 mysql_query($q, $this->connection); - } + function addDemolition($wid, $field) { + global $building, $village; + $q = "DELETE FROM ".TB_PREFIX."bdata WHERE field=$field AND wid=$wid"; + mysql_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 mysql_query($q, $this->connection); + } - function getDemolition($wid = 0) { - if($wid) { - $q = "SELECT * FROM " . TB_PREFIX . "demolition WHERE vref=" . $wid; - } else { - $q = "SELECT * FROM " . TB_PREFIX . "demolition WHERE timetofinish<=" . time(); - } - $result = mysql_query($q, $this->connection); - if(!empty($result)) { - return $this->mysql_fetch_all($result); - } else { - return NULL; - } - } + function getDemolition($wid = 0) { + if($wid) { + $q = "SELECT * FROM " . TB_PREFIX . "demolition WHERE vref=" . $wid; + } else { + $q = "SELECT * FROM " . TB_PREFIX . "demolition WHERE timetofinish<=" . time(); + } + $result = mysql_query($q, $this->connection); + if(!empty($result)) { + return $this->mysql_fetch_all($result); + } else { + return NULL; + } + } - function finishDemolition($wid) { - $q = "UPDATE " . TB_PREFIX . "demolition SET timetofinish=" . time() . " WHERE vref=" . $wid; - return mysql_query($q, $this->connection); - } + function finishDemolition($wid) { + $q = "UPDATE " . TB_PREFIX . "demolition SET timetofinish=" . time() . " WHERE vref=" . $wid; + return mysql_query($q, $this->connection); + } - function delDemolition($wid) { - $q = "DELETE FROM " . TB_PREFIX . "demolition WHERE vref=" . $wid; - return mysql_query($q, $this->connection); - } + function delDemolition($wid) { + $q = "DELETE FROM " . TB_PREFIX . "demolition WHERE vref=" . $wid; + return mysql_query($q, $this->connection); + } - function getJobs($wid) { - $q = "SELECT * FROM " . TB_PREFIX . "bdata where wid = $wid order by timestamp ASC"; - $result = mysql_query($q, $this->connection); - return $this->mysql_fetch_all($result); - } + function getJobs($wid) { + $q = "SELECT * FROM " . TB_PREFIX . "bdata where wid = $wid order by timestamp ASC"; + $result = mysql_query($q, $this->connection); + return $this->mysql_fetch_all($result); + } - function getVillageByName($name) { - $q = "SELECT wref FROM " . TB_PREFIX . "vdata where name = '$name' limit 1"; - $result = mysql_query($q, $this->connection); - $dbarray = mysql_fetch_array($result); - return $dbarray['wref']; - } + function getVillageByName($name) { + $q = "SELECT wref FROM " . TB_PREFIX . "vdata where name = '$name' limit 1"; + $result = mysql_query($q, $this->connection); + $dbarray = mysql_fetch_array($result); + return $dbarray['wref']; + } - /*************************** - Function to set accept flag on market - References: id - ***************************/ - function setMarketAcc($id) { - $q = "UPDATE " . TB_PREFIX . "market set accept = 1 where id = $id"; - return mysql_query($q, $this->connection); - } + /*************************** + Function to set accept flag on market + References: id + ***************************/ + function setMarketAcc($id) { + $q = "UPDATE " . TB_PREFIX . "market set accept = 1 where id = $id"; + return mysql_query($q, $this->connection); + } - /*************************** - Function to send resource to other village - Mode 0: Send - Mode 1: Cancel - References: Wood/ID, Clay, Iron, Crop, Mode - ***************************/ - function sendResource($ref, $clay, $iron, $crop, $merchant, $mode) { - if(!$mode) { - $q = "INSERT INTO " . TB_PREFIX . "send values (0,$ref,$clay,$iron,$crop,$merchant)"; - mysql_query($q, $this->connection); - return mysql_insert_id($this->connection); - } else { - $q = "DELETE FROM " . TB_PREFIX . "send where id = $ref"; - return mysql_query($q, $this->connection); - } - } + /*************************** + Function to send resource to other village + Mode 0: Send + Mode 1: Cancel + References: Wood/ID, Clay, Iron, Crop, Mode + ***************************/ + function sendResource($ref, $clay, $iron, $crop, $merchant, $mode) { + if(!$mode) { + $q = "INSERT INTO " . TB_PREFIX . "send values (0,$ref,$clay,$iron,$crop,$merchant)"; + mysql_query($q, $this->connection); + return mysql_insert_id($this->connection); + } else { + $q = "DELETE FROM " . TB_PREFIX . "send where id = $ref"; + return mysql_query($q, $this->connection); + } + } - /*************************** - Function to get resources back if you delete offer - References: VillageRef (vref) - Made by: Dzoki - ***************************/ + /*************************** + Function to get resources back if you delete offer + References: VillageRef (vref) + Made by: Dzoki + ***************************/ - function getResourcesBack($vref, $gtype, $gamt) { - //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 mysql_query($q, $this->connection); - } else - if($gtype == 2) { - $q = "UPDATE " . TB_PREFIX . "vdata SET `clay` = `clay` + '$gamt' WHERE wref = $vref"; - return mysql_query($q, $this->connection); - } else - if($gtype == 3) { - $q = "UPDATE " . TB_PREFIX . "vdata SET `iron` = `iron` + '$gamt' WHERE wref = $vref"; - return mysql_query($q, $this->connection); - } else - if($gtype == 4) { - $q = "UPDATE " . TB_PREFIX . "vdata SET `crop` = `crop` + '$gamt' WHERE wref = $vref"; - return mysql_query($q, $this->connection); - } - } + function getResourcesBack($vref, $gtype, $gamt) { + //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 mysql_query($q, $this->connection); + } else + if($gtype == 2) { + $q = "UPDATE " . TB_PREFIX . "vdata SET `clay` = `clay` + '$gamt' WHERE wref = $vref"; + return mysql_query($q, $this->connection); + } else + if($gtype == 3) { + $q = "UPDATE " . TB_PREFIX . "vdata SET `iron` = `iron` + '$gamt' WHERE wref = $vref"; + return mysql_query($q, $this->connection); + } else + if($gtype == 4) { + $q = "UPDATE " . TB_PREFIX . "vdata SET `crop` = `crop` + '$gamt' WHERE wref = $vref"; + return mysql_query($q, $this->connection); + } + } - /*************************** - Function to get info about offered resources - References: VillageRef (vref) - Made by: Dzoki - ***************************/ + /*************************** + Function to get info about offered resources + References: VillageRef (vref) + Made by: Dzoki + ***************************/ - function getMarketField($vref, $field) { - $q = "SELECT $field FROM " . TB_PREFIX . "market where vref = '$vref'"; - $result = mysql_query($q, $this->connection) or die(mysql_error()); - $dbarray = mysql_fetch_array($result); - return $dbarray[$field]; - } + function getMarketField($vref, $field) { + $q = "SELECT $field FROM " . TB_PREFIX . "market where vref = '$vref'"; + $result = mysql_query($q, $this->connection) or die(mysql_error()); + $dbarray = mysql_fetch_array($result); + return $dbarray[$field]; + } - function removeAcceptedOffer($id) { - $q = "DELETE FROM " . TB_PREFIX . "market where id = $id"; - $result = mysql_query($q, $this->connection); - return mysql_fetch_assoc($result); - } + function removeAcceptedOffer($id) { + $q = "DELETE FROM " . TB_PREFIX . "market where id = $id"; + $result = mysql_query($q, $this->connection); + return mysql_fetch_assoc($result); + } - /*************************** - Function to add market offer - Mode 0: Add - Mode 1: Cancel - References: Village, Give, Amt, Want, Amt, Time, Alliance, Mode - ***************************/ - 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)"; - mysql_query($q, $this->connection); - return mysql_insert_id($this->connection); - } else { - $q = "DELETE FROM " . TB_PREFIX . "market where id = $gtype and vref = $vid"; - return mysql_query($q, $this->connection); - } - } + /*************************** + Function to add market offer + Mode 0: Add + Mode 1: Cancel + References: Village, Give, Amt, Want, Amt, Time, Alliance, Mode + ***************************/ + 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)"; + mysql_query($q, $this->connection); + return mysql_insert_id($this->connection); + } else { + $q = "DELETE FROM " . TB_PREFIX . "market where id = $gtype and vref = $vid"; + return mysql_query($q, $this->connection); + } + } - /*************************** - Function to get market offer - References: Village, Mode - ***************************/ - function getMarket($vid, $mode) { - $alliance = $this->getUserField($this->getVillageField($vid, "owner"), "alliance", 0); - if(!$mode) { - $q = "SELECT * FROM " . TB_PREFIX . "market where vref = $vid and accept = 0"; - } else { - $q = "SELECT * FROM " . TB_PREFIX . "market where vref != $vid and alliance = $alliance or vref != $vid and alliance = 0 and accept = 0"; - } - $result = mysql_query($q, $this->connection); - return $this->mysql_fetch_all($result); - } + /*************************** + Function to get market offer + References: Village, Mode + ***************************/ + function getMarket($vid, $mode) { + $alliance = $this->getUserField($this->getVillageField($vid, "owner"), "alliance", 0); + if(!$mode) { + $q = "SELECT * FROM " . TB_PREFIX . "market where vref = $vid and accept = 0"; + } else { + $q = "SELECT * FROM " . TB_PREFIX . "market where vref != $vid and alliance = $alliance or vref != $vid and alliance = 0 and accept = 0"; + } + $result = mysql_query($q, $this->connection); + return $this->mysql_fetch_all($result); + } - /*************************** - Function to get market offer - References: ID - ***************************/ - function getMarketInfo($id) { - $q = "SELECT * FROM " . TB_PREFIX . "market where id = $id"; - $result = mysql_query($q, $this->connection); - return mysql_fetch_assoc($result); - } + /*************************** + Function to get market offer + References: ID + ***************************/ + function getMarketInfo($id) { + $q = "SELECT * FROM " . TB_PREFIX . "market where id = $id"; + $result = mysql_query($q, $this->connection); + return mysql_fetch_assoc($result); + } - function setMovementProc($moveid) { - $q = "UPDATE " . TB_PREFIX . "movement set proc = 1 where moveid = $moveid"; - return mysql_query($q, $this->connection); - } + function setMovementProc($moveid) { + $q = "UPDATE " . TB_PREFIX . "movement set proc = 1 where moveid = $moveid"; + return mysql_query($q, $this->connection); + } - /*************************** - Function to retrieve used merchant - References: Village - ***************************/ - 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 = mysql_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 = mysql_query($q2, $this->connection); - $row2 = mysql_fetch_row($result2); - $q3 = "SELECT sum(merchant) from " . TB_PREFIX . "market where vref = $vid and accept = 0"; - $result3 = mysql_query($q3, $this->connection); - $row3 = mysql_fetch_row($result3); - return $row[0] + $row2[0] + $row3[0]; - } + /*************************** + Function to retrieve used merchant + References: Village + ***************************/ + 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 = mysql_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 = mysql_query($q2, $this->connection); + $row2 = mysql_fetch_row($result2); + $q3 = "SELECT sum(merchant) from " . TB_PREFIX . "market where vref = $vid and accept = 0"; + $result3 = mysql_query($q3, $this->connection); + $row3 = mysql_fetch_row($result3); + return $row[0] + $row2[0] + $row3[0]; + } - /*************************** - Function to retrieve movement of village - Type 0: Send Resource - Type 1: Send Merchant - Type 2: Return Resource - Type 3: Attack - Type 4: Return - Type 5: Settler - Type 6: Bounty Type 7: Reinf. - Mode 0: Send/Out - Mode 1: Recieve/In - References: Type, Village, Mode - ***************************/ - function getMovement($type, $village, $mode) { - $time = time(); - if(!$mode) { - $where = "from"; - } else { - $where = "to"; - } - switch($type) { - case 0: - $q = "SELECT * FROM " . TB_PREFIX . "movement, " . TB_PREFIX . "send where " . TB_PREFIX . "movement." . $where . " = $village and " . TB_PREFIX . "movement.ref = " . TB_PREFIX . "send.id and " . TB_PREFIX . "movement.proc = 0 and " . TB_PREFIX . "movement.sort_type = 0 ORDER BY endtime ASC"; - break; - case 1: - $q = "SELECT * FROM " . TB_PREFIX . "movement, " . TB_PREFIX . "send where " . TB_PREFIX . "movement." . $where . " = $village and " . TB_PREFIX . "movement.ref = " . TB_PREFIX . "send.id and " . TB_PREFIX . "movement.proc = 0 and " . TB_PREFIX . "movement.sort_type = 6 ORDER BY endtime ASC"; - break; - case 2: - $q = "SELECT * FROM " . TB_PREFIX . "movement where " . TB_PREFIX . "movement." . $where . " = $village and " . TB_PREFIX . "movement.proc = 0 and " . TB_PREFIX . "movement.sort_type = 2 ORDER BY endtime ASC"; - break; - case 3: - $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 ORDER BY endtime ASC"; - break; - case 4: - $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 = 4 ORDER BY endtime ASC"; - break; - case 5: - $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"; - break; - case 34: - $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 = mysql_query($q, $this->connection); - $array = $this->mysql_fetch_all($result); - return $array; - } + /*************************** + Function to retrieve movement of village + Type 0: Send Resource + Type 1: Send Merchant + Type 2: Return Resource + Type 3: Attack + Type 4: Return + Type 5: Settler + Type 6: Bounty Type 7: Reinf. + Mode 0: Send/Out + Mode 1: Recieve/In + References: Type, Village, Mode + ***************************/ + function getMovement($type, $village, $mode) { + $time = time(); + if(!$mode) { + $where = "from"; + } else { + $where = "to"; + } + switch($type) { + case 0: + $q = "SELECT * FROM " . TB_PREFIX . "movement, " . TB_PREFIX . "send where " . TB_PREFIX . "movement." . $where . " = $village and " . TB_PREFIX . "movement.ref = " . TB_PREFIX . "send.id and " . TB_PREFIX . "movement.proc = 0 and " . TB_PREFIX . "movement.sort_type = 0 ORDER BY endtime ASC"; + break; + case 1: + $q = "SELECT * FROM " . TB_PREFIX . "movement, " . TB_PREFIX . "send where " . TB_PREFIX . "movement." . $where . " = $village and " . TB_PREFIX . "movement.ref = " . TB_PREFIX . "send.id and " . TB_PREFIX . "movement.proc = 0 and " . TB_PREFIX . "movement.sort_type = 6 ORDER BY endtime ASC"; + break; + case 2: + $q = "SELECT * FROM " . TB_PREFIX . "movement where " . TB_PREFIX . "movement." . $where . " = $village and " . TB_PREFIX . "movement.proc = 0 and " . TB_PREFIX . "movement.sort_type = 2 ORDER BY endtime ASC"; + break; + case 3: + $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 ORDER BY endtime ASC"; + break; + case 4: + $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 = 4 ORDER BY endtime ASC"; + break; + case 5: + $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"; + break; + case 34: + $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 = mysql_query($q, $this->connection); + $array = $this->mysql_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')"; - mysql_query($q, $this->connection); - return mysql_insert_id($this->connection); - } + 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')"; + mysql_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 = mysql_query($q, $this->connection); - if($result) { - return mysql_fetch_assoc($result); - } else { - return false; - } - } + function getA2b($ckey, $check) { + $q = "SELECT * from " . TB_PREFIX . "a2b where ckey = '" . $ckey . "' AND time_check = '" . $check . "'"; + $result = mysql_query($q, $this->connection); + if($result) { + return mysql_fetch_assoc($result); + } else { + return false; + } + } - function addMovement($type, $from, $to, $ref, $time, $endtime) { - $q = "INSERT INTO " . TB_PREFIX . "movement values (0,$type,$from,$to,$ref,$time,$endtime,0)"; - return mysql_query($q, $this->connection); - } + function addMovement($type, $from, $to, $ref, $time, $endtime) { + $q = "INSERT INTO " . TB_PREFIX . "movement values (0,$type,$from,$to,$ref,$time,$endtime,0)"; + return mysql_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)"; - mysql_query($q, $this->connection); - return mysql_insert_id($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)"; + mysql_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 mysql_query($q, $this->connection); - } + function modifyAttack($aid, $unit, $amt) { + $unit = 't' . $unit; + $q = "UPDATE " . TB_PREFIX . "attacks set $unit = $unit - $amt where id = $aid"; + return mysql_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 = mysql_query($q, $this->connection); - return $this->mysql_fetch_all($result); - } + 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 = mysql_query($q, $this->connection); + return $this->mysql_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 = mysql_query($q, $this->connection); - return $this->mysql_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 = mysql_query($q, $this->connection); + return $this->mysql_fetch_all($result); + } - function getARanking() { - $q = "SELECT id,name,tag FROM " . TB_PREFIX . "alidata where id != ''"; - $result = mysql_query($q, $this->connection); - return $this->mysql_fetch_all($result); - } + function getARanking() { + $q = "SELECT id,name,tag FROM " . TB_PREFIX . "alidata where id != ''"; + $result = mysql_query($q, $this->connection); + return $this->mysql_fetch_all($result); + } - function getHeroRanking() { - $q = "SELECT * FROM " . TB_PREFIX . "hero WHERE dead = 0"; - $result = mysql_query($q, $this->connection); - return $this->mysql_fetch_all($result); - } + function getHeroRanking() { + $q = "SELECT * FROM " . TB_PREFIX . "hero WHERE dead = 0"; + $result = mysql_query($q, $this->connection); + return $this->mysql_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"; - $result = mysql_query($q, $this->connection); - return $this->mysql_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"; + $result = mysql_query($q, $this->connection); + return $this->mysql_fetch_all($result); + } - function addUnits($vid) { - $q = "INSERT into " . TB_PREFIX . "units (vref) values ($vid)"; - return mysql_query($q, $this->connection); - } + function addUnits($vid) { + $q = "INSERT into " . TB_PREFIX . "units (vref) values ($vid)"; + return mysql_query($q, $this->connection); + } - function getUnit($vid) { - $q = "SELECT * from " . TB_PREFIX . "units where vref = $vid"; - $result = mysql_query($q, $this->connection); - if (!empty($result)) { - return mysql_fetch_assoc($result); - } else { - return NULL; - } - } + function getUnit($vid) { + $q = "SELECT * from " . TB_PREFIX . "units where vref = $vid"; + $result = mysql_query($q, $this->connection); + if (!empty($result)) { + return mysql_fetch_assoc($result); + } else { + return NULL; + } + } - function getHero($uid=0,$all=0) { - if ($all) { - $q = "SELECT * FROM ".TB_PREFIX."hero WHERE uid=$uid"; - } elseif (!$uid) { - $q = "SELECT * FROM ".TB_PREFIX."hero"; - } else { - $q = "SELECT * FROM ".TB_PREFIX."hero WHERE dead=0 AND uid=$uid LIMIT 1"; - } - $result = mysql_query($q, $this->connection); - if (!empty($result)) { - return $this->mysql_fetch_all($result); - } else { - return NULL; - } - } + function getHero($uid=0,$all=0) { + if ($all) { + $q = "SELECT * FROM ".TB_PREFIX."hero WHERE uid=$uid"; + } elseif (!$uid) { + $q = "SELECT * FROM ".TB_PREFIX."hero"; + } else { + $q = "SELECT * FROM ".TB_PREFIX."hero WHERE dead=0 AND uid=$uid LIMIT 1"; + } + $result = mysql_query($q, $this->connection); + if (!empty($result)) { + return $this->mysql_fetch_all($result); + } else { + return NULL; + } + } function getHeroField($uid,$field){ $q = "SELECT * FROM ".TB_PREFIX."hero WHERE uid = $uid"; @@ -1876,120 +1907,120 @@ return $this->mysql_fetch_all($result); } - function modifyHero($column,$value,$heroid,$mode=0) { - if(!$mode) { - $q = "UPDATE `".TB_PREFIX."hero` SET $column = $value WHERE heroid = $heroid"; - } elseif($mode=1) { - $q = "UPDATE `".TB_PREFIX."hero` SET $column = $column + $value WHERE heroid = $heroid"; - } else { - $q = "UPDATE `".TB_PREFIX."hero` SET $column = $column - $value WHERE heroid = $heroid"; - } - return mysql_query($q, $this->connection); - } + function modifyHero($column,$value,$heroid,$mode=0) { + if(!$mode) { + $q = "UPDATE `".TB_PREFIX."hero` SET $column = $value WHERE heroid = $heroid"; + } elseif($mode=1) { + $q = "UPDATE `".TB_PREFIX."hero` SET $column = $column + $value WHERE heroid = $heroid"; + } else { + $q = "UPDATE `".TB_PREFIX."hero` SET $column = $column - $value WHERE heroid = $heroid"; + } + return mysql_query($q, $this->connection); + } function modifyHeroXp($column,$value,$heroid) { $q = "UPDATE ".TB_PREFIX."hero SET $column = $column + $value WHERE uid=$heroid"; return mysql_query($q, $this->connection); } - function addTech($vid) { - $q = "INSERT into " . TB_PREFIX . "tdata (vref) values ($vid)"; - return mysql_query($q, $this->connection); - } + function addTech($vid) { + $q = "INSERT into " . TB_PREFIX . "tdata (vref) values ($vid)"; + return mysql_query($q, $this->connection); + } - function addABTech($vid) { - $q = "INSERT into " . TB_PREFIX . "abdata (vref) values ($vid)"; - return mysql_query($q, $this->connection); - } + function addABTech($vid) { + $q = "INSERT into " . TB_PREFIX . "abdata (vref) values ($vid)"; + return mysql_query($q, $this->connection); + } - function getABTech($vid) { - $q = "SELECT * FROM " . TB_PREFIX . "abdata where vref = $vid"; - $result = mysql_query($q, $this->connection); - return mysql_fetch_assoc($result); - } + function getABTech($vid) { + $q = "SELECT * FROM " . TB_PREFIX . "abdata where vref = $vid"; + $result = mysql_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 mysql_query($q, $this->connection); - } + function addResearch($vid, $tech, $time) { + $q = "INSERT into " . TB_PREFIX . "research values (0,$vid,'$tech',$time)"; + return mysql_query($q, $this->connection); + } - function getResearching($vid) { - $q = "SELECT * FROM " . TB_PREFIX . "research where vref = $vid"; - $result = mysql_query($q, $this->connection); - return $this->mysql_fetch_all($result); - } + function getResearching($vid) { + $q = "SELECT * FROM " . TB_PREFIX . "research where vref = $vid"; + $result = mysql_query($q, $this->connection); + return $this->mysql_fetch_all($result); + } - function checkIfResearched($vref, $unit) { - $q = "SELECT $unit FROM " . TB_PREFIX . "tdata WHERE vref = $vref"; - $result = mysql_query($q, $this->connection) or die(mysql_error()); - $dbarray = mysql_fetch_array($result); - return $dbarray[$unit]; - } + function checkIfResearched($vref, $unit) { + $q = "SELECT $unit FROM " . TB_PREFIX . "tdata WHERE vref = $vref"; + $result = mysql_query($q, $this->connection) or die(mysql_error()); + $dbarray = mysql_fetch_array($result); + return $dbarray[$unit]; + } - function getTech($vid) { - $q = "SELECT * from " . TB_PREFIX . "tdata where vref = $vid"; - $result = mysql_query($q, $this->connection); - return mysql_fetch_assoc($result); - } + function getTech($vid) { + $q = "SELECT * from " . TB_PREFIX . "tdata where vref = $vid"; + $result = mysql_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 = mysql_query($q, $this->connection); - return $this->mysql_fetch_all($result); - } + function getTraining($vid) { + $q = "SELECT * FROM " . TB_PREFIX . "training where vref = $vid ORDER BY id"; + $result = mysql_query($q, $this->connection); + return $this->mysql_fetch_all($result); + } - function countTraining($vid) { - $q = "SELECT * FROM " . TB_PREFIX . "training WHERE vref = $vid"; - $result = mysql_query($q, $this->connection); - $row = mysql_fetch_row($result); - return $row[0]; - } + function countTraining($vid) { + $q = "SELECT * FROM " . TB_PREFIX . "training WHERE vref = $vid"; + $result = mysql_query($q, $this->connection); + $row = mysql_fetch_row($result); + return $row[0]; + } - function trainUnit($vid, $unit, $amt, $pop, $each, $time, $mode) { - global $village, $building, $session, $technology; + function trainUnit($vid, $unit, $amt, $pop, $each, $time, $mode) { + global $village, $building, $session, $technology; - if(!$mode) { - $barracks = array(1, 2, 3, 11, 12, 13, 14, 21, 22, 31, 32, 33, 34, 41, 42, 43, 44); - $stables = array(4, 5, 6, 15, 16, 23, 24, 25, 26, 35, 36, 45, 46); - $workshop = array(7, 8, 17, 18, 27, 28, 37, 38, 47, 48); - $residence = array(9, 10, 19, 20, 29, 30, 39, 40, 49, 50); + if(!$mode) { + $barracks = array(1, 2, 3, 11, 12, 13, 14, 21, 22, 31, 32, 33, 34, 41, 42, 43, 44); + $stables = array(4, 5, 6, 15, 16, 23, 24, 25, 26, 35, 36, 45, 46); + $workshop = array(7, 8, 17, 18, 27, 28, 37, 38, 47, 48); + $residence = array(9, 10, 19, 20, 29, 30, 39, 40, 49, 50); $greatstables = array(64,65,66,75,76,83,84,85,86,95,96,105,106,); $greatbarracks = array(61,62,63,71,72,73,84,81,82,91,92,93,94,101,102,103,104,111,112,113,114); $greatworkshop = array(67,68,77,78,87,88,97,98,107,108); - if(in_array($unit, $barracks)) { - $queued = $technology->getTrainingList(1); - } elseif(in_array($unit, $stables)) { - $queued = $technology->getTrainingList(2); - } elseif(in_array($unit, $workshop)) { - $queued = $technology->getTrainingList(3); - } elseif(in_array($unit, $residence)) { - $queued = $technology->getTrainingList(4); - } elseif(in_array($unit, $greatstables)) { + if(in_array($unit, $barracks)) { + $queued = $technology->getTrainingList(1); + } elseif(in_array($unit, $stables)) { + $queued = $technology->getTrainingList(2); + } elseif(in_array($unit, $workshop)) { + $queued = $technology->getTrainingList(3); + } elseif(in_array($unit, $residence)) { + $queued = $technology->getTrainingList(4); + } elseif(in_array($unit, $greatstables)) { $queued = $technology->getTrainingList(6); } elseif(in_array($unit, $greatbarracks)) { $queued = $technology->getTrainingList(5); } elseif(in_array($unit, $greatworkshop)) { $queued = $technology->getTrainingList(7); } - if(count($queued) > 0) { - $time = $queued[count($queued) - 1]['commence'] + $queued[count($queued) - 1]['eachtime'] * $queued[count($queued) - 1]['amt']; - } - $now = time(); - $q = "INSERT INTO " . TB_PREFIX . "training values (0,$vid,$unit,$amt,$pop,$now,$each,$time)"; - } else { - $q = "DELETE FROM " . TB_PREFIX . "training where id = $vid"; - } - return mysql_query($q, $this->connection); - } + if(count($queued) > 0) { + $time = $queued[count($queued) - 1]['commence'] + $queued[count($queued) - 1]['eachtime'] * $queued[count($queued) - 1]['amt']; + } + $now = time(); + $q = "INSERT INTO " . TB_PREFIX . "training values (0,$vid,$unit,$amt,$pop,$now,$each,$time)"; + } else { + $q = "DELETE FROM " . TB_PREFIX . "training where id = $vid"; + } + return mysql_query($q, $this->connection); + } - function updateTraining($id, $trained) { - $time = time(); - $q = "UPDATE " . TB_PREFIX . "training set amt = amt - $trained, timestamp = $time where id = $id"; - return mysql_query($q, $this->connection); - } + function updateTraining($id, $trained) { + $time = time(); + $q = "UPDATE " . TB_PREFIX . "training set amt = amt - $trained, timestamp = $time where id = $id"; + return mysql_query($q, $this->connection); + } - function modifyUnit($vref, $array_unit, $array_amt, $array_mode){ + function modifyUnit($vref, $array_unit, $array_amt, $array_mode){ $i = -1; $units=''; $number = count($array_unit); @@ -2008,457 +2039,457 @@ $q = "UPDATE ".TB_PREFIX."units set $units WHERE vref = $vref"; return mysql_query($q, $this->connection); } - - function getEnforce($vid, $from) { - $q = "SELECT * from " . TB_PREFIX . "enforcement where `from` = $from and vref = $vid"; - $result = mysql_query($q, $this->connection); - return mysql_fetch_assoc($result); - } + + function getEnforce($vid, $from) { + $q = "SELECT * from " . TB_PREFIX . "enforcement where `from` = $from and vref = $vid"; + $result = mysql_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'] . ")"; - mysql_query($q, $this->connection); - $id = mysql_insert_id($this->connection); - $owntribe = $this->getUserField($this->getVillageField($data['from'], "owner"), "tribe", 0); - $start = ($owntribe - 1) * 10 + 1; - $end = ($owntribe * 10); - //add unit - $j = '1'; - for($i = $start; $i <= $end; $i++) { - $this->modifyEnforce($id, $i, $data['t' . $j . ''], 1); - $j++; - } - $this->modifyEnforce($id,'hero',$data['t11'],1); - return mysql_insert_id($this->connection); - } + function addEnforce($data) { + $q = "INSERT into " . TB_PREFIX . "enforcement (vref,`from`) values (" . $data['to'] . "," . $data['from'] . ")"; + mysql_query($q, $this->connection); + $id = mysql_insert_id($this->connection); + $owntribe = $this->getUserField($this->getVillageField($data['from'], "owner"), "tribe", 0); + $start = ($owntribe - 1) * 10 + 1; + $end = ($owntribe * 10); + //add unit + $j = '1'; + for($i = $start; $i <= $end; $i++) { + $this->modifyEnforce($id, $i, $data['t' . $j . ''], 1); + $j++; + } + $this->modifyEnforce($id,'hero',$data['t11'],1); + return mysql_insert_id($this->connection); + } - function modifyEnforce($id, $unit, $amt, $mode) { - if($unit != 'hero') { $unit = 'u' . $unit; } - if(!$mode) { - $q = "UPDATE " . TB_PREFIX . "enforcement set $unit = $unit - $amt where id = $id"; - } else { - $q = "UPDATE " . TB_PREFIX . "enforcement set $unit = $unit + $amt where id = $id"; - } - mysql_query($q, $this->connection); - } + function modifyEnforce($id, $unit, $amt, $mode) { + if($unit != 'hero') { $unit = 'u' . $unit; } + if(!$mode) { + $q = "UPDATE " . TB_PREFIX . "enforcement set $unit = $unit - $amt where id = $id"; + } else { + $q = "UPDATE " . TB_PREFIX . "enforcement set $unit = $unit + $amt where id = $id"; + } + mysql_query($q, $this->connection); + } - function getEnforceArray($id, $mode) { - if(!$mode) { - $q = "SELECT * from " . TB_PREFIX . "enforcement where id = $id"; - } else { - $q = "SELECT * from " . TB_PREFIX . "enforcement where `from` = $id"; - } - $result = mysql_query($q, $this->connection); - return mysql_fetch_assoc($result); - } + function getEnforceArray($id, $mode) { + if(!$mode) { + $q = "SELECT * from " . TB_PREFIX . "enforcement where id = $id"; + } else { + $q = "SELECT * from " . TB_PREFIX . "enforcement where `from` = $id"; + } + $result = mysql_query($q, $this->connection); + return mysql_fetch_assoc($result); + } - function getEnforceVillage($id, $mode) { - if(!$mode) { - $q = "SELECT * from " . TB_PREFIX . "enforcement where vref = $id"; - } else { - $q = "SELECT * from " . TB_PREFIX . "enforcement where `from` = $id"; - } - $result = mysql_query($q, $this->connection); - return $this->mysql_fetch_all($result); - } + function getEnforceVillage($id, $mode) { + if(!$mode) { + $q = "SELECT * from " . TB_PREFIX . "enforcement where vref = $id"; + } else { + $q = "SELECT * from " . TB_PREFIX . "enforcement where `from` = $id"; + } + $result = mysql_query($q, $this->connection); + return $this->mysql_fetch_all($result); + } - function getVillageMovement($id) { - $vinfo = $this->getVillage($id); - $vtribe = $this->getUserField($vinfo['owner'], "tribe", 0); - $movingunits = array(); - $outgoingarray = $this->getMovement(3, $id, 0); - if(!empty($outgoingarray)) { - foreach($outgoingarray as $out) { - for($i = 1; $i <= 10; $i++) { - $movingunits['u' . (($vtribe - 1) * 10 + $i)] += $out['t' . $i]; - } - $movingunits['hero'] += $out['t11']; - } - } - $returningarray = $this->getMovement(4, $id, 1); - if(!empty($returningarray)) { - foreach($returningarray as $ret) { - if($ret['attack_type'] != 1) { - for($i = 1; $i <= 10; $i++) { - $movingunits['u' . (($vtribe - 1) * 10 + $i)] += $ret['t' . $i]; - } - $movingunits['hero'] += $ret['t11']; - } - } - } - $settlerarray = $this->getMovement(5, $id, 0); - if(!empty($settlerarray)) { - $movingunits['u' . ($vtribe * 10)] += 3 * count($settlerarray); - } - return $movingunits; - } + function getVillageMovement($id) { + $vinfo = $this->getVillage($id); + $vtribe = $this->getUserField($vinfo['owner'], "tribe", 0); + $movingunits = array(); + $outgoingarray = $this->getMovement(3, $id, 0); + if(!empty($outgoingarray)) { + foreach($outgoingarray as $out) { + for($i = 1; $i <= 10; $i++) { + $movingunits['u' . (($vtribe - 1) * 10 + $i)] += $out['t' . $i]; + } + $movingunits['hero'] += $out['t11']; + } + } + $returningarray = $this->getMovement(4, $id, 1); + if(!empty($returningarray)) { + foreach($returningarray as $ret) { + if($ret['attack_type'] != 1) { + for($i = 1; $i <= 10; $i++) { + $movingunits['u' . (($vtribe - 1) * 10 + $i)] += $ret['t' . $i]; + } + $movingunits['hero'] += $ret['t11']; + } + } + } + $settlerarray = $this->getMovement(5, $id, 0); + if(!empty($settlerarray)) { + $movingunits['u' . ($vtribe * 10)] += 3 * count($settlerarray); + } + return $movingunits; + } - ################# -START- ################## - ## WORLD WONDER STATISTICS FUNCTIONS! ## - ############################################ + ################# -START- ################## + ## WORLD WONDER STATISTICS FUNCTIONS! ## + ############################################ - /*************************** - Function to get all World Wonders - Made by: Dzoki - ***************************/ + /*************************** + Function to get all World Wonders + Made by: Dzoki + ***************************/ - function getWW() { - $q = "SELECT * FROM " . TB_PREFIX . "fdata WHERE f99t = 40"; - $result = mysql_query($q, $this->connection); - if(mysql_num_rows($result)) { - return true; - } else { - return false; - } - } + function getWW() { + $q = "SELECT * FROM " . TB_PREFIX . "fdata WHERE f99t = 40"; + $result = mysql_query($q, $this->connection); + if(mysql_num_rows($result)) { + return true; + } else { + return false; + } + } - /*************************** - Function to get world wonder level! - Made by: Dzoki - ***************************/ + /*************************** + Function to get world wonder level! + Made by: Dzoki + ***************************/ - function getWWLevel($vref) { - $q = "SELECT f99 FROM " . TB_PREFIX . "fdata WHERE vref = $vref"; - $result = mysql_query($q, $this->connection) or die(mysql_error()); - $dbarray = mysql_fetch_array($result); - return $dbarray['f99']; - } + function getWWLevel($vref) { + $q = "SELECT f99 FROM " . TB_PREFIX . "fdata WHERE vref = $vref"; + $result = mysql_query($q, $this->connection) or die(mysql_error()); + $dbarray = mysql_fetch_array($result); + return $dbarray['f99']; + } - /*************************** - Function to get world wonder owner ID! - Made by: Dzoki - ***************************/ + /*************************** + Function to get world wonder owner ID! + Made by: Dzoki + ***************************/ - function getWWOwnerID($vref) { - $q = "SELECT owner FROM " . TB_PREFIX . "vdata WHERE wref = $vref"; - $result = mysql_query($q, $this->connection) or die(mysql_error()); - $dbarray = mysql_fetch_array($result); - return $dbarray['owner']; - } + function getWWOwnerID($vref) { + $q = "SELECT owner FROM " . TB_PREFIX . "vdata WHERE wref = $vref"; + $result = mysql_query($q, $this->connection) or die(mysql_error()); + $dbarray = mysql_fetch_array($result); + return $dbarray['owner']; + } - /*************************** - Function to get user alliance name! - Made by: Dzoki - ***************************/ + /*************************** + Function to get user alliance name! + Made by: Dzoki + ***************************/ - function getUserAllianceID($id) { - $q = "SELECT alliance FROM " . TB_PREFIX . "users where id = $id"; - $result = mysql_query($q, $this->connection) or die(mysql_error()); - $dbarray = mysql_fetch_array($result); - return $dbarray['alliance']; - } + function getUserAllianceID($id) { + $q = "SELECT alliance FROM " . TB_PREFIX . "users where id = $id"; + $result = mysql_query($q, $this->connection) or die(mysql_error()); + $dbarray = mysql_fetch_array($result); + return $dbarray['alliance']; + } - /*************************** - Function to get WW name - Made by: Dzoki - ***************************/ + /*************************** + Function to get WW name + Made by: Dzoki + ***************************/ - function getWWName($vref) { - $q = "SELECT wwname FROM " . TB_PREFIX . "fdata WHERE vref = $vref"; - $result = mysql_query($q, $this->connection) or die(mysql_error()); - $dbarray = mysql_fetch_array($result); - return $dbarray['wwname']; - } + function getWWName($vref) { + $q = "SELECT wwname FROM " . TB_PREFIX . "fdata WHERE vref = $vref"; + $result = mysql_query($q, $this->connection) or die(mysql_error()); + $dbarray = mysql_fetch_array($result); + return $dbarray['wwname']; + } - /*************************** - Function to change WW name - Made by: Dzoki - ***************************/ + /*************************** + Function to change WW name + Made by: Dzoki + ***************************/ - function submitWWname($vref, $name) { - $q = "UPDATE " . TB_PREFIX . "fdata SET `wwname` = '$name' WHERE " . TB_PREFIX . "fdata.`vref` = $vref"; - return mysql_query($q, $this->connection); - } + function submitWWname($vref, $name) { + $q = "UPDATE " . TB_PREFIX . "fdata SET `wwname` = '$name' WHERE " . TB_PREFIX . "fdata.`vref` = $vref"; + return mysql_query($q, $this->connection); + } - //medal functions - function addclimberpop($user, $cp) { - $q = "UPDATE " . TB_PREFIX . "users set Rc = Rc + '$cp' where id = $user"; - return mysql_query($q, $this->connection); - } - function addclimberrankpop($user, $cp) { - $q = "UPDATE " . TB_PREFIX . "users set clp = clp + '$cp' where id = $user"; - return mysql_query($q, $this->connection); - } - function removeclimberrankpop($user, $cp) { - $q = "UPDATE " . TB_PREFIX . "users set clp = clp - '$cp'' where id = $user"; - return mysql_query($q, $this->connection); - } - function updateoldrank($user, $cp) { - $q = "UPDATE " . TB_PREFIX . "users set oldrank = '$cp' where id = $user"; - return mysql_query($q, $this->connection); - } - function removeclimberpop($user, $cp) { - $q = "UPDATE " . TB_PREFIX . "users set Rc = Rc - '$cp' where id = $user"; - return mysql_query($q, $this->connection); - } - // ALLIANCE MEDAL FUNCTIONS - function addclimberpopAlly($user, $cp) { - $q = "UPDATE " . TB_PREFIX . "alidata set Rc = Rc + '$cp' where id = $user"; - return mysql_query($q, $this->connection); - } - function addclimberrankpopAlly($user, $cp) { - $q = "UPDATE " . TB_PREFIX . "alidata set clp = clp + '$cp' where id = $user"; - return mysql_query($q, $this->connection); - } - function removeclimberrankpopAlly($user, $cp) { - $q = "UPDATE " . TB_PREFIX . "alidata set clp = clp - '$cp'' where id = $user"; - return mysql_query($q, $this->connection); - } - function updateoldrankAlly($user, $cp) { - $q = "UPDATE " . TB_PREFIX . "alidata set oldrank = '$cp' where id = $user"; - return mysql_query($q, $this->connection); - } - function removeclimberpopAlly($user, $cp) { - $q = "UPDATE " . TB_PREFIX . "alidata set Rc = Rc - '$cp' where id = $user"; - return mysql_query($q, $this->connection); - } + //medal functions + function addclimberpop($user, $cp) { + $q = "UPDATE " . TB_PREFIX . "users set Rc = Rc + '$cp' where id = $user"; + return mysql_query($q, $this->connection); + } + function addclimberrankpop($user, $cp) { + $q = "UPDATE " . TB_PREFIX . "users set clp = clp + '$cp' where id = $user"; + return mysql_query($q, $this->connection); + } + function removeclimberrankpop($user, $cp) { + $q = "UPDATE " . TB_PREFIX . "users set clp = clp - '$cp'' where id = $user"; + return mysql_query($q, $this->connection); + } + function updateoldrank($user, $cp) { + $q = "UPDATE " . TB_PREFIX . "users set oldrank = '$cp' where id = $user"; + return mysql_query($q, $this->connection); + } + function removeclimberpop($user, $cp) { + $q = "UPDATE " . TB_PREFIX . "users set Rc = Rc - '$cp' where id = $user"; + return mysql_query($q, $this->connection); + } + // ALLIANCE MEDAL FUNCTIONS + function addclimberpopAlly($user, $cp) { + $q = "UPDATE " . TB_PREFIX . "alidata set Rc = Rc + '$cp' where id = $user"; + return mysql_query($q, $this->connection); + } + function addclimberrankpopAlly($user, $cp) { + $q = "UPDATE " . TB_PREFIX . "alidata set clp = clp + '$cp' where id = $user"; + return mysql_query($q, $this->connection); + } + function removeclimberrankpopAlly($user, $cp) { + $q = "UPDATE " . TB_PREFIX . "alidata set clp = clp - '$cp'' where id = $user"; + return mysql_query($q, $this->connection); + } + function updateoldrankAlly($user, $cp) { + $q = "UPDATE " . TB_PREFIX . "alidata set oldrank = '$cp' where id = $user"; + return mysql_query($q, $this->connection); + } + function removeclimberpopAlly($user, $cp) { + $q = "UPDATE " . TB_PREFIX . "alidata set Rc = Rc - '$cp' where id = $user"; + return mysql_query($q, $this->connection); + } - function modifyCommence($id) { - $time = time(); - $q = "UPDATE " . TB_PREFIX . "training set commence = $time WHERE id=$id"; - return mysql_query($q, $this->connection); - } + function modifyCommence($id) { + $time = time(); + $q = "UPDATE " . TB_PREFIX . "training set commence = $time WHERE id=$id"; + return mysql_query($q, $this->connection); + } - function getTrainingList() { - $q = "SELECT * FROM " . TB_PREFIX . "training where vref != ''"; - $result = mysql_query($q, $this->connection); - return $this->mysql_fetch_all($result); - } + function getTrainingList() { + $q = "SELECT * FROM " . TB_PREFIX . "training where vref != ''"; + $result = mysql_query($q, $this->connection); + return $this->mysql_fetch_all($result); + } - function getNeedDelete() { - $time = time(); - $q = "SELECT uid FROM " . TB_PREFIX . "deleting where timestamp < $time"; - $result = mysql_query($q, $this->connection); - return $this->mysql_fetch_all($result); - } + function getNeedDelete() { + $time = time(); + $q = "SELECT uid FROM " . TB_PREFIX . "deleting where timestamp < $time"; + $result = mysql_query($q, $this->connection); + return $this->mysql_fetch_all($result); + } - function countUser() { - $q = "SELECT count(id) FROM " . TB_PREFIX . "users where id != 0"; - $result = mysql_query($q, $this->connection); - $row = mysql_fetch_row($result); - return $row[0]; - } + function countUser() { + $q = "SELECT count(id) FROM " . TB_PREFIX . "users where id != 0"; + $result = mysql_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 = mysql_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 = mysql_query($q, $this->connection); + $row = mysql_fetch_row($result); + return $row[0]; + } - /*************************** - Function to process MYSQLi->fetch_all (Only exist in MYSQL) - References: Result - ***************************/ - function mysql_fetch_all($result) { - $all = array(); - if($result) { - while($row = mysql_fetch_assoc($result)) { - $all[] = $row; - } - return $all; - } - } + /*************************** + Function to process MYSQLi->fetch_all (Only exist in MYSQL) + References: Result + ***************************/ + function mysql_fetch_all($result) { + $all = array(); + if($result) { + while($row = mysql_fetch_assoc($result)) { + $all[] = $row; + } + return $all; + } + } - function query_return($q) { - $result = mysql_query($q, $this->connection); - return $this->mysql_fetch_all($result); - } + function query_return($q) { + $result = mysql_query($q, $this->connection); + return $this->mysql_fetch_all($result); + } - /*************************** - Function to do free query - References: Query - ***************************/ - function query($query) { - return mysql_query($query, $this->connection); - } + /*************************** + Function to do free query + References: Query + ***************************/ + function query($query) { + return mysql_query($query, $this->connection); + } - function RemoveXSS($val) { - return htmlspecialchars($val, ENT_QUOTES); - } + function RemoveXSS($val) { + return htmlspecialchars($val, ENT_QUOTES); + } - //MARKET FIXES - function getWoodAvailable($wref) { - $q = "SELECT wood FROM " . TB_PREFIX . "vdata WHERE wref = $wref"; - $result = mysql_query($q, $this->connection) or die(mysql_error()); - $dbarray = mysql_fetch_array($result); - return $dbarray['wood']; - } + //MARKET FIXES + function getWoodAvailable($wref) { + $q = "SELECT wood FROM " . TB_PREFIX . "vdata WHERE wref = $wref"; + $result = mysql_query($q, $this->connection) or die(mysql_error()); + $dbarray = mysql_fetch_array($result); + return $dbarray['wood']; + } - function getClayAvailable($wref) { - $q = "SELECT clay FROM " . TB_PREFIX . "vdata WHERE wref = $wref"; - $result = mysql_query($q, $this->connection) or die(mysql_error()); - $dbarray = mysql_fetch_array($result); - return $dbarray['clay']; - } + function getClayAvailable($wref) { + $q = "SELECT clay FROM " . TB_PREFIX . "vdata WHERE wref = $wref"; + $result = mysql_query($q, $this->connection) or die(mysql_error()); + $dbarray = mysql_fetch_array($result); + return $dbarray['clay']; + } - function getIronAvailable($wref) { - $q = "SELECT iron FROM " . TB_PREFIX . "vdata WHERE wref = $wref"; - $result = mysql_query($q, $this->connection) or die(mysql_error()); - $dbarray = mysql_fetch_array($result); - return $dbarray['iron']; - } + function getIronAvailable($wref) { + $q = "SELECT iron FROM " . TB_PREFIX . "vdata WHERE wref = $wref"; + $result = mysql_query($q, $this->connection) or die(mysql_error()); + $dbarray = mysql_fetch_array($result); + return $dbarray['iron']; + } - function getCropAvailable($wref) { - $q = "SELECT crop FROM " . TB_PREFIX . "vdata WHERE wref = $wref"; - $result = mysql_query($q, $this->connection) or die(mysql_error()); - $dbarray = mysql_fetch_array($result); - return $dbarray['crop']; - } + function getCropAvailable($wref) { + $q = "SELECT crop FROM " . TB_PREFIX . "vdata WHERE wref = $wref"; + $result = mysql_query($q, $this->connection) or die(mysql_error()); + $dbarray = mysql_fetch_array($result); + return $dbarray['crop']; + } - function Getowner($vid) { - $s = "SELECT owner FROM " . TB_PREFIX . "vdata where wref = $vid"; - $result1 = mysql_query($s, $this->connection); - $row1 = mysql_fetch_row($result1); - return $row1[0]; - } + function Getowner($vid) { + $s = "SELECT owner FROM " . TB_PREFIX . "vdata where wref = $vid"; + $result1 = mysql_query($s, $this->connection); + $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(mysql_query($q, $this->connection)) { - return mysql_insert_id($this->connection); - } else { - return false; - } - } - function populateOasisdata() { - $q2 = "SELECT * FROM " . TB_PREFIX . "wdata where oasistype != 0"; - $result2 = mysql_query($q2, $this->connection); - while($row = mysql_fetch_array($result2)) { - $wid = $row['id']; - $basearray = $this->getOMInfo($wid); - //We switch type of oasis and instert record with apropriate infomation. - $q = "INSERT into " . TB_PREFIX . "odata VALUES ('" . $basearray['id'] . "'," . $basearray['oasistype'] . ",0,400,400,400,400,400,400," . time() . ",100,2,'Unoccupied Oasis')"; - $result = mysql_query($q, $this->connection); - } - } + public function debug($time, $uid, $debug_info) { + $q = "INSERT INTO " . TB_PREFIX . "debug_info (time,uid,debug_info) VALUES ($time,$uid,$debug_info)"; + if(mysql_query($q, $this->connection)) { + return mysql_insert_id($this->connection); + } else { + return false; + } + } + function populateOasisdata() { + $q2 = "SELECT * FROM " . TB_PREFIX . "wdata where oasistype != 0"; + $result2 = mysql_query($q2, $this->connection); + while($row = mysql_fetch_array($result2)) { + $wid = $row['id']; + $basearray = $this->getOMInfo($wid); + //We switch type of oasis and instert record with apropriate infomation. + $q = "INSERT into " . TB_PREFIX . "odata VALUES ('" . $basearray['id'] . "'," . $basearray['oasistype'] . ",0,400,400,400,400,400,400," . time() . ",100,2,'Unoccupied Oasis')"; + $result = mysql_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 = mysql_query($q, $this->connection); - $row = mysql_fetch_row($result); - $maxslots = $row[0]; - $residence = $building->getTypeLevel(25); - $palace = $building->getTypeLevel(26); - if($residence > 0) { - $maxslots -= (3 - floor($residence / 10)); - } - if($palace > 0) { - $maxslots -= (3 - floor(($palace - 5) / 5)); - } + 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 = mysql_query($q, $this->connection); + $row = mysql_fetch_row($result); + $maxslots = $row[0]; + $residence = $building->getTypeLevel(25); + $palace = $building->getTypeLevel(26); + if($residence > 0) { + $maxslots -= (3 - floor($residence / 10)); + } + if($palace > 0) { + $maxslots -= (3 - floor(($palace - 5) / 5)); + } - $q = "SELECT (u10+u20+u30) FROM " . TB_PREFIX . "units WHERE vref = $village->wid"; - $result = mysql_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 = mysql_query($q, $this->connection); - $row = mysql_fetch_row($result); - $chiefs = $row[0]; + $q = "SELECT (u10+u20+u30) FROM " . TB_PREFIX . "units WHERE vref = $village->wid"; + $result = mysql_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 = mysql_query($q, $this->connection); + $row = mysql_fetch_row($result); + $chiefs = $row[0]; - $settlers += 3 * count($this->getMovement(5, $village->wid, 0)); - $current_movement = $this->getMovement(3, $village->wid, 0); - if(!empty($current_movement)) { - foreach($current_movement as $build) { - $settlers += $build['t10']; - $chiefs += $build['t9']; - } - } - $current_movement = $this->getMovement(3, $village->wid, 1); - if(!empty($current_movement)) { - foreach($current_movement as $build) { - $settlers += $build['t10']; - $chiefs += $build['t9']; - } - } - $current_movement = $this->getMovement(4, $village->wid, 0); - if(!empty($current_movement)) { - foreach($current_movement as $build) { - $settlers += $build['t10']; - $chiefs += $build['t9']; - } - } - $current_movement = $this->getMovement(4, $village->wid, 1); - if(!empty($current_movement)) { - foreach($current_movement as $build) { - $settlers += $build['t10']; - $chiefs += $build['t9']; - } - } - $q = "SELECT (u10+u20+u30) FROM " . TB_PREFIX . "enforcement WHERE `from` = $village->wid"; - $result = mysql_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 = mysql_query($q, $this->connection); - $row = mysql_fetch_row($result); - if(!empty($row)) { - foreach($row as $reinf) { - $chiefs += $reinf[0]; - } - } - $trainlist = $technology->getTrainingList(4); - if(!empty($trainlist)) { - foreach($trainlist as $train) { - if($train['unit'] % 10 == 0) { - $settlers += $train['amt']; - } - if($train['unit'] % 10 == 9) { - $chiefs += $train['amt']; - } - } - } - // trapped settlers/chiefs calculation required + $settlers += 3 * count($this->getMovement(5, $village->wid, 0)); + $current_movement = $this->getMovement(3, $village->wid, 0); + if(!empty($current_movement)) { + foreach($current_movement as $build) { + $settlers += $build['t10']; + $chiefs += $build['t9']; + } + } + $current_movement = $this->getMovement(3, $village->wid, 1); + if(!empty($current_movement)) { + foreach($current_movement as $build) { + $settlers += $build['t10']; + $chiefs += $build['t9']; + } + } + $current_movement = $this->getMovement(4, $village->wid, 0); + if(!empty($current_movement)) { + foreach($current_movement as $build) { + $settlers += $build['t10']; + $chiefs += $build['t9']; + } + } + $current_movement = $this->getMovement(4, $village->wid, 1); + if(!empty($current_movement)) { + foreach($current_movement as $build) { + $settlers += $build['t10']; + $chiefs += $build['t9']; + } + } + $q = "SELECT (u10+u20+u30) FROM " . TB_PREFIX . "enforcement WHERE `from` = $village->wid"; + $result = mysql_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 = mysql_query($q, $this->connection); + $row = mysql_fetch_row($result); + if(!empty($row)) { + foreach($row as $reinf) { + $chiefs += $reinf[0]; + } + } + $trainlist = $technology->getTrainingList(4); + if(!empty($trainlist)) { + foreach($trainlist as $train) { + if($train['unit'] % 10 == 0) { + $settlers += $train['amt']; + } + if($train['unit'] % 10 == 9) { + $chiefs += $train['amt']; + } + } + } + // trapped settlers/chiefs calculation required - $settlerslots = $maxslots * 3 - $settlers - $chiefs * 3; - $chiefslots = $maxslots - $chiefs - floor(($settlers + 2) / 3); + $settlerslots = $maxslots * 3 - $settlers - $chiefs * 3; + $chiefslots = $maxslots - $chiefs - floor(($settlers + 2) / 3); - if(!$technology->getTech(($session->tribe - 1) * 10 + 9)) { - $chiefslots = 0; - } - $slots = array("chiefs" => $chiefslots, "settlers" => $settlerslots); - return $slots; - } + if(!$technology->getTech(($session->tribe - 1) * 10 + 9)) { + $chiefslots = 0; + } + $slots = array("chiefs" => $chiefslots, "settlers" => $settlerslots); + return $slots; + } - 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`) VALUES ('$vref', '$owner', '$type', '$size', '" . time() . "', '$name', '$desc', '$effect', '$img')"; - return mysql_query($q, $this->connection); - } + 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`) VALUES ('$vref', '$owner', '$type', '$size', '" . time() . "', '$name', '$desc', '$effect', '$img')"; + return mysql_query($q, $this->connection); + } - function getOwnArtefactInfo($vref) { - $q = "SELECT * FROM " . TB_PREFIX . "artefacts WHERE vref = $vref"; - $result = mysql_query($q, $this->connection); - return mysql_fetch_array($result); - } - function getOwnArtefactInfoByType($vref, $type) { - $q = "SELECT * FROM " . TB_PREFIX . "artefacts WHERE vref = $vref AND type = $type"; - $result = mysql_query($q, $this->connection); - return mysql_fetch_array($result); - } - function getOwnUniqueArtefactInfo($id, $type, $size) { - $q = "SELECT * FROM " . TB_PREFIX . "artefacts WHERE owner = $id AND type = $type AND size=$size"; - $result = mysql_query($q, $this->connection); - return mysql_fetch_array($result); - } + function getOwnArtefactInfo($vref) { + $q = "SELECT * FROM " . TB_PREFIX . "artefacts WHERE vref = $vref"; + $result = mysql_query($q, $this->connection); + return mysql_fetch_array($result); + } + function getOwnArtefactInfoByType($vref, $type) { + $q = "SELECT * FROM " . TB_PREFIX . "artefacts WHERE vref = $vref AND type = $type"; + $result = mysql_query($q, $this->connection); + return mysql_fetch_array($result); + } + function getOwnUniqueArtefactInfo($id, $type, $size) { + $q = "SELECT * FROM " . TB_PREFIX . "artefacts WHERE owner = $id AND type = $type AND size=$size"; + $result = mysql_query($q, $this->connection); + return mysql_fetch_array($result); + } - function getArtefactInfo() { - $q = "SELECT * FROM " . TB_PREFIX . "artefacts WHERE id > 0"; - $result = mysql_query($q, $this->connection); - return mysql_fetch_array($result); - } - - function claimArtefact($vref, $ovref, $id) { + function getArtefactInfo() { + $q = "SELECT * FROM " . TB_PREFIX . "artefacts WHERE id > 0"; + $result = mysql_query($q, $this->connection); + return mysql_fetch_array($result); + } + + function claimArtefact($vref, $ovref, $id) { $time = time(); $q = "UPDATE " . TB_PREFIX . "artefacts SET vref = $vref, owner = $id, conquered = $time WHERE vref = $ovref"; return mysql_query($q, $this->connection); } - + public function canClaimArtifact($from,$vref,$type) { $DefenderFields = $this->getResourceLevel($vref); $defcanclaim = TRUE; @@ -2511,13 +2542,13 @@ } } - function getArtefactDetails($id) { - $q = "SELECT * FROM " . TB_PREFIX . "artefacts WHERE id = " . $id . ""; - $result = mysql_query($q, $this->connection); - return mysql_fetch_array($result); - } - - function getMovementById($id){ + function getArtefactDetails($id) { + $q = "SELECT * FROM " . TB_PREFIX . "artefacts WHERE id = " . $id . ""; + $result = mysql_query($q, $this->connection); + return mysql_fetch_array($result); + } + + function getMovementById($id){ $q="SELECT * FROM ".TB_PREFIX."movement where moveid = ".$id; $result=mysql_query($q); $array=$this->mysql_fetch_all($result); @@ -2529,88 +2560,88 @@ return mysql_query($q, $this->connection); } - - function removeLinks($id){ + + function removeLinks($id){ $q = "DELETE FROM " . TB_PREFIX . "links WHERE `id` = ".$id.""; return mysql_query($q, $this->connection); } - function getVilFarmlist($wref){ + function getVilFarmlist($wref){ $q = 'SELECT * FROM ' . TB_PREFIX . 'farmlist WHERE wref = ' . $wref . ' ORDER BY wref ASC'; - $result = mysql_query($q, $this->connection); - $dbarray = mysql_fetch_array($result); - - if($dbarray['id']!=0) { - return true; - } else { - return false; - } + $result = mysql_query($q, $this->connection); + $dbarray = mysql_fetch_array($result); + + if($dbarray['id']!=0) { + return true; + } else { + return false; + } } - - function getRaidList($id) { - $q = "SELECT * FROM " . TB_PREFIX . "raidlist WHERE id = ".$id.""; - $result = mysql_query($q, $this->connection); - return mysql_fetch_array($result); - } - - function delFarmList($id, $owner) { - $q = "DELETE FROM " . TB_PREFIX . "farmlist where id = $id and owner = $owner"; - return mysql_query($q, $this->connection); - } - - - function delSlotFarm($id) { - $q = "DELETE FROM " . TB_PREFIX . "raidlist where id = $id"; - return mysql_query($q, $this->connection); - } - - - function createFarmList($wref, $owner, $name) { - $q = "INSERT INTO " . TB_PREFIX . "farmlist (`wref`, `owner`, `name`) VALUES ('$wref', '$owner', '$name')"; - return mysql_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 mysql_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 mysql_query($q, $this->connection); + + function getRaidList($id) { + $q = "SELECT * FROM " . TB_PREFIX . "raidlist WHERE id = ".$id.""; + $result = mysql_query($q, $this->connection); + return mysql_fetch_array($result); + } + + function delFarmList($id, $owner) { + $q = "DELETE FROM " . TB_PREFIX . "farmlist where id = $id and owner = $owner"; + return mysql_query($q, $this->connection); + } + + + function delSlotFarm($id) { + $q = "DELETE FROM " . TB_PREFIX . "raidlist where id = $id"; + return mysql_query($q, $this->connection); + } + + + function createFarmList($wref, $owner, $name) { + $q = "INSERT INTO " . TB_PREFIX . "farmlist (`wref`, `owner`, `name`) VALUES ('$wref', '$owner', '$name')"; + return mysql_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 mysql_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 mysql_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 = mysql_query($q, $this->connection); - $array = $this->mysql_fetch_all($result); - return $array; - } + $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 = mysql_query($q, $this->connection); + $array = $this->mysql_fetch_all($result); + return $array; + } - function addPassword($uid, $npw, $cpw){ - $q = "REPLACE INTO `" . TB_PREFIX . "password`(uid, npw, cpw) VALUES ($uid, '$npw', '$cpw')"; - mysql_query($q, $this->connection) or die(mysql_error()); - } + function addPassword($uid, $npw, $cpw){ + $q = "REPLACE INTO `" . TB_PREFIX . "password`(uid, npw, cpw) VALUES ($uid, '$npw', '$cpw')"; + mysql_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 = mysql_query($q, $this->connection) or die(mysql_error()); - $dbarray = mysql_fetch_array($result); + function resetPassword($uid, $cpw){ + $q = "SELECT npw FROM `" . TB_PREFIX . "password` WHERE uid = $uid AND cpw = '$cpw' AND used = 0"; + $result = mysql_query($q, $this->connection) or die(mysql_error()); + $dbarray = mysql_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"; - mysql_query($q, $this->connection) or die(mysql_error()); - return true; - } + 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"; + mysql_query($q, $this->connection) or die(mysql_error()); + return true; + } - return false; - } + return false; + } } ; diff --git a/GameEngine/Technology.php b/GameEngine/Technology.php index 800a7b85..b37c251b 100644 --- a/GameEngine/Technology.php +++ b/GameEngine/Technology.php @@ -12,8 +12,8 @@ class Technology { - private $unarray = array(1=>U1,U2,U3,U4,U5,U6,U7,U8,U9,U10,U11,U12,U13,U14,U15,U16,U17,U18,U19,U20,U21,U22,U23,U24,U25,U26,U27,U28,U29,U30,U31,U32,U33,U34,U35,U36,U37,U38,U39,U40,U41,U42,U43,U44,U45,U46,U47,U48,U49,U50,U0); - + public $unarray = array(1=>U1,U2,U3,U4,U5,U6,U7,U8,U9,U10,U11,U12,U13,U14,U15,U16,U17,U18,U19,U20,U21,U22,U23,U24,U25,U26,U27,U28,U29,U30,U31,U32,U33,U34,U35,U36,U37,U38,U39,U40,U41,U42,U43,U44,U45,U46,U47,U48,U49,U50,U0); + public function grabAcademyRes() { global $village; $holder = array(); diff --git a/Templates/goldClub/farmlist.tpl b/Templates/goldClub/farmlist.tpl index 84826812..cf7a2a7b 100644 --- a/Templates/goldClub/farmlist.tpl +++ b/Templates/goldClub/farmlist.tpl @@ -3,7 +3,7 @@ if(isset($_GET['t'])==99 && isset($_GET['action'])==0) { if(isset($_GET['t'])==99 && isset($_POST['action'])=='addList'){ - $database->createFarmList($_POST['did'], $session->uid, $_POST['name']); + $database->createFarmList($_POST['did'], $session->uid, $_POST['name']); } $sql = mysql_query("SELECT * FROM ".TB_PREFIX."farmlist WHERE owner = $session->uid ORDER BY wref = $village->wid DESC"); @@ -16,7 +16,6 @@ while($row = mysql_fetch_array($sql)){ $lvname = $database->getVillageField($row["wref"], 'name'); if($lwref == $village->wid){ ?> -
@@ -24,53 +23,51 @@ while($row = mysql_fetch_array($sql)){ -
-
- del - - - بارگذاری... -
-
- جزئیات
-
-
-
-
- - - - - - - - - - - - - +
+ del + - + Loading... +
+
+
+ +
+
+
دهکدهجمعیتفاصلهلشکریانآخرین غارت
+ + + + + + + + + + + + هیچ غارتی افزوده نشده است.'; + echo ''; }else{ while($row = mysql_fetch_array($sql2)){ $id= $row['id'];$lid = $row['lid'];$towref = $row['towref'];$x = $row['x'];$y = $row['y']; if($village->wid == $towref){ - $distance = '0'; + $distance = '0'; }else{ - $distance = $row['distance']; + $distance = $row['distance']; } $t1 = $row['t1'];$t2 = $row['t2'];$t3 = $row['t3'];$t4 = $row['t4'];$t5 = $row['t5'];$t6 = $row['t6'];$t7 = $row['t7']; @@ -81,32 +78,32 @@ $vdata = $database->getVillage($towref); - + - - - + + + - - +
+ + - + -
VilliageEwDistanceTroopsLastRaid
There is no any raid list.
- - + + getMovement(3,$towref,1); - $att = ''; + $incoming_attacks = $database->getMovement(3,$towref,1); + $att = ''; - if (count($incoming_attacks) > 0) { - $inc_atts = count($incoming_attacks); - if($incoming_attacks[$i]['attack_type'] == 2) { - $inc_atts -= 1; - } - if($inc_atts > 0) { - echo ''; - } - } + if (count($incoming_attacks) > 0) { + $inc_atts = count($incoming_attacks); + if($incoming_attacks[$i]['attack_type'] == 2) { + $inc_atts -= 1; + } + if($inc_atts > 0) { + echo ''; + } + } ?> - + tribe == 1){ + if($session->tribe == 1){ if($t1 != 0){ - echo '
'.$t1.'
'; } + echo '
'.$t1.'
'; } if($t2 != 0){ - echo '
'.$t2.'
'; } + echo '
'.$t2.'
'; } if($t3 != 0){ - echo '
'.$t3.'
'; } + echo '
'.$t3.'
'; } if($t4 != 0){ - echo '
'.$t4.'
'; } + echo '
'.$t4.'
'; } if($t5 != 0){ - echo '
'.$t5.'
'; } + echo '
'.$t5.'
'; } if($t6 != 0){ - echo '
'.$t6.'
'; } + echo '
'.$t6.'
'; } if($t7 != 0){ - echo '
'.$t7.'
'; } + echo '
'.$t7.'
'; } if($t8 != 0){ - echo '
'.$t8.'
'; } + echo '
'.$t8.'
'; } if($t9 != 0){ - echo '
'.$t9.'
'; } + echo '
'.$t9.'
'; } if($t10 != 0){ - echo '
'.$t10.'
'; } - }elseif($session->tribe == 2){ - if($t1 != 0){ - echo '
'.$t1.'
'; } + echo '
'.$t10.'
'; } + }elseif($session->tribe == 2){ + if($t1 != 0){ + echo '
'.$t1.'
'; } if($t2 != 0){ - echo '
'.$t2.'
'; } + echo '
'.$t2.'
'; } if($t3 != 0){ - echo '
'.$t3.'
'; } + echo '
'.$t3.'
'; } if($t4 != 0){ - echo '
'.$t4.'
'; } + echo '
'.$t4.'
'; } if($t5 != 0){ - echo '
'.$t5.'
'; } + echo '
'.$t5.'
'; } if($t6 != 0){ - echo '
'.$t6.'
'; } + echo '
'.$t6.'
'; } if($t7 != 0){ - echo '
'.$t7.'
'; } + echo '
'.$t7.'
'; } if($t8 != 0){ - echo '
'.$t8.'
'; } + echo '
'.$t8.'
'; } if($t9 != 0){ - echo '
'.$t9.'
'; } + echo '
'.$t9.'
'; } if($t10 != 0){ - echo '
'.$t10.'
'; } + echo '
'.$t10.'
'; } - }elseif($session->tribe == 3){ - if($t1 != 0){ - echo '
'.$t1.'
'; } + }elseif($session->tribe == 3){ + if($t1 != 0){ + echo '
'.$t1.'
'; } if($t2 != 0){ - echo '
'.$t2.'
'; } + echo '
'.$t2.'
'; } if($t3 != 0){ - echo '
'.$t3.'
'; } + echo '
'.$t3.'
'; } if($t4 != 0){ - echo '
'.$t4.'
'; } + echo '
'.$t4.'
'; } if($t5 != 0){ - echo '
'.$t5.'
'; } + echo '
'.$t5.'
'; } if($t6 != 0){ - echo '
'.$t6.'
'; } + echo '
'.$t6.'
'; } if($t7 != 0){ - echo '
'.$t7.'
'; } + echo '
'.$t7.'
'; } if($t8 != 0){ - echo '
'.$t8.'
'; } + echo '
'.$t8.'
'; } if($t9 != 0){ - echo '
'.$t9.'
'; } + echo '
'.$t9.'
'; } if($t10 != 0){ - echo '
'.$t10.'
'; } - } + echo '
'.$t10.'
'; } + } ?>
+ "; $allres = ($dataarray[25]+$dataarray[26]+$dataarray[27]+$dataarray[28]); $carry = $dataarray[29]; if ($dataarray[25]+$dataarray[26]+$dataarray[27]+$dataarray[28] == 0) { - echo ""; + echo ""; - } elseif ($dataarray[25]+$dataarray[26]+$dataarray[27]+$dataarray[28] != $dataarray[29]) { - echo ""; + } elseif ($dataarray[25]+$dataarray[26]+$dataarray[27]+$dataarray[28] != $dataarray[29]) { + echo ""; } else { - echo ""; + echo ""; } $date = $generator->procMtime($row2['time']); echo "".$date[0]." ".date('H:i',$row2['time'])." "; } ?> -
-
- ویرایش - + edit +
-
- - -
+ +
+ + +
-
-
+
@@ -254,46 +250,45 @@ $start = ($session->tribe-1)*10+1; $end = ($session->tribe*10); $un = 1; for($i=$start;$i<=$end;$i++){ - echo ' - + echo ' + 0 - '; + '; } ?> -
+
-
+
-
- del - - - بارگذاری... -
-
جزئیات
-
-
-
-
-
+
+ del + - + Loading... +
+
Details
+
+ +
+
+ -
- » create new list + Create a new list
getUnit($village->wid); if($session->tribe==1){ - $unit1 = $getUnit['u1'];$unit2 = $getUnit['u2'];$unit3 = $getUnit['u3'];$unit4 = $getUnit['u4'];$unit5 = $getUnit['u5']; + $unit1 = $getUnit['u1'];$unit2 = $getUnit['u2'];$unit3 = $getUnit['u3'];$unit4 = $getUnit['u4'];$unit5 = $getUnit['u5']; $unit6 = $getUnit['u6'];$unit7 = $getUnit['u7'];$unit8 = $getUnit['u8'];$unit9 = $getUnit['u9'];$unit10 = $getUnit['u10']; }elseif($session->tribe==2){ - $unit1 = $getUnit['u11'];$unit2 = $getUnit['u12'];$unit3 = $getUnit['u13'];$unit4 = $getUnit['u14'];$unit5 = $getUnit['u15']; + $unit1 = $getUnit['u11'];$unit2 = $getUnit['u12'];$unit3 = $getUnit['u13'];$unit4 = $getUnit['u14'];$unit5 = $getUnit['u15']; $unit6 = $getUnit['u16'];$unit7 = $getUnit['u17'];$unit8 = $getUnit['u18'];$unit9 = $getUnit['u19'];$unit10 = $getUnit['u20']; }elseif($session->tribe==3){ - $unit1 = $getUnit['u21'];$unit2 = $getUnit['u22'];$unit3 = $getUnit['u23'];$unit4 = $getUnit['u24'];$unit5 = $getUnit['u25']; + $unit1 = $getUnit['u21'];$unit2 = $getUnit['u22'];$unit3 = $getUnit['u23'];$unit4 = $getUnit['u24'];$unit5 = $getUnit['u25']; $unit6 = $getUnit['u26'];$unit7 = $getUnit['u27'];$unit8 = $getUnit['u28'];$unit9 = $getUnit['u29'];$unit10 = $getUnit['u30']; } ?> @@ -316,16 +311,16 @@ if($session->tribe==1){ if(!$database->getVilFarmlist($village->wid)){ ?> + +getVilWref($_POST['y'], $_POST['x']); + $type = $database->getVillageType2($Wref); + $oasistype = $type['oasistype']; + $vdata = $database->getVillage($Wref); + } + if(!$_POST['x'] && !$_POST['y']){ + $errormsg .= "Enter coordinates."; + }elseif(!$_POST['x'] || !$_POST['y']){ + $errormsg .= "Enter the correct coordinates."; + }elseif($oasistype == 0 && $vdata == 0){ + $errormsg .= "In this village there are no coordinates."; + }elseif($troops == 0){ + $errormsg .= "No troops has been selected."; + }else{ + + $Wref = $database->getVilWref($_POST['y'], $_POST['x']); + $coor = $database->getCoor($village->wid); + + function getDistance($coorx1, $coory1, $coorx2, $coory2) { + $max = 2 * WORLD_MAX + 1; + $x1 = intval($coorx1); + $y1 = intval($coory1); + $x2 = intval($coorx2); + $y2 = intval($coory2); + $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)); + return round($dist, 1); + } + + $distance = getDistance($coor['x'], $coor['y'], $_POST['y'], $_POST['x']); + + $database->addSlotFarm($_POST['lid'], $Wref, $_POST['x'], $_POST['y'], $distance, $_POST['t1'], $_POST['t2'], $_POST['t3'], $_POST['t4'], $_POST['t5'], $_POST['t6'], $_POST['t7'], $_POST['t8'], $_POST['t9'], $_POST['t10']); + + header("Location: build.php?id=39&t=99"); +} +} +?> + + + +
+

Add Raid

+ + + + +
+
+ + + + + + + + + + + + + + +
From List + +
Coordinates: + +
+
+ + +
+
+ + +
+
+
+
+ + +
+
+
+
+
+ + + + + +
+
\ No newline at end of file diff --git a/Templates/goldClub/farmlist_add.tpl b/Templates/goldClub/farmlist_add.tpl index d7361d65..9f0890f4 100644 --- a/Templates/goldClub/farmlist_add.tpl +++ b/Templates/goldClub/farmlist_add.tpl @@ -1,19 +1,19 @@
-

ایجاد لیست جدید

+

Create a new list

+ Name: + Village:
- نام:
- دهکده: - + + - - - - - + + + + + +
لیست فارم‌ها: - + + + - - - - - -
Farm Name: + -
هدفی انتخاب کنید: - -
-
- - -
-
- - -
-
-
-
- - -
-
-
- - - +?> + +
Select target: + +
+
+ + +
+
+ + +
+
+
+
+ + +
+
+
+ + + - - + + \ No newline at end of file diff --git a/Templates/goldClub/farmlist_editraid.tpl b/Templates/goldClub/farmlist_editraid.tpl index a59ec11f..071615dc 100644 --- a/Templates/goldClub/farmlist_editraid.tpl +++ b/Templates/goldClub/farmlist_editraid.tpl @@ -16,13 +16,13 @@ $vdata = $database->getVillage($Wref); $troops = "".$_POST['t1']."+".$_POST['t2']."+".$_POST['t3']."+".$_POST['t4']."+".$_POST['t5']."+".$_POST['t6']."+".$_POST['t7']."+".$_POST['t8']."+".$_POST['t9']."+".$_POST['t10'].""; if(!$_POST['x'] && !$_POST['y']){ - $errormsg .= "مختصات را وارد کنید."; + $errormsg .= "Enter coordinates."; }elseif(!$_POST['x'] || !$_POST['y']){ - $errormsg .= "مختصات را صحیح وارد کنید."; + $errormsg .= "Enter the correct coordinates."; }elseif($oasistype == 0 && $vdata == 0){ - $errormsg .= "در این مختصات دهکده ای وجود ندارد."; + $errormsg .= "There is no village on those coordinates."; }elseif($troops == 0){ - $errormsg .= "هیچ نیرویی انتخاب نشده."; + $errormsg .= "No troops has been selected."; }else{ $Wref = $database->getVilWref($_POST['y'], $_POST['x']); @@ -61,7 +61,7 @@ $troops = "".$_POST['t1']."+".$_POST['t2']."+".$_POST['t3']."+".$_POST['t4']."+" var option = new Element('option', { - 'html': 'دهکده‌ای انتخاب کنید' + 'html': 'Select village' }); targetId.insert(option); @@ -137,7 +137,7 @@ $troops = "".$_POST['t1']."+".$_POST['t2']."+".$_POST['t3']."+".$_POST['t4']."+"
-

افزودن غارت

+

Add Slot

@@ -155,7 +155,7 @@ $lid2 = $getlid['lid']; - + - +
لیست فارم‌ها:Farm Name:
هدفی انتخاب کنید:Select target:
@@ -190,9 +190,9 @@ $lvname = $database->getVillageField($row["wref"], 'name');
- +
@@ -204,9 +204,9 @@ $lvname = $database->getVillageField($row["wref"], 'name'); -  -  + +
Delete
\ No newline at end of file diff --git a/build.php b/build.php index 34b5a6e4..1356a286 100644 --- a/build.php +++ b/build.php @@ -1,3 +1,4 @@ + pageLoadTimeStart(); $alliance->procAlliForm($_POST); $technology->procTech($_POST); -$market->procMarket($_POST); +$market->procMarket($_POST); if(isset($_GET['gid'])) { - $_GET['id'] = strval($building->getTypeField($_GET['gid'])); + $_GET['id'] = strval($building->getTypeField($_GET['gid'])); } else if(isset($_POST['id'])) { - $_GET['id'] = $_POST['id']; + $_GET['id'] = $_POST['id']; } if(isset($_POST['t'])){ - $_GET['t'] = $_POST['t']; + $_GET['t'] = $_POST['t']; } if(isset($_GET['id'])) { - if (!ctype_digit($_GET['id'])){ + if (!ctype_digit($_GET['id'])){ $_GET['id'] = "1"; } - if($village->resarray['f'.$_GET['id'].'t'] == 17) { - $market->procRemove($_GET); - } - if($village->resarray['f'.$_GET['id'].'t'] == 18) { - $alliance->procAlliance($_GET); - } - if($village->resarray['f'.$_GET['id'].'t'] == 12 || $village->resarray['f'.$_GET['id'].'t'] == 13 || $village->resarray['f'.$_GET['id'].'t'] == 22) { - $technology->procTechno($_GET); - } + if($village->resarray['f'.$_GET['id'].'t'] == 17) { + $market->procRemove($_GET); + } + if($village->resarray['f'.$_GET['id'].'t'] == 18) { + $alliance->procAlliance($_GET); + } + if($village->resarray['f'.$_GET['id'].'t'] == 12 || $village->resarray['f'.$_GET['id'].'t'] == 13 || $village->resarray['f'.$_GET['id'].'t'] == 22) { + $technology->procTechno($_GET); + } } if($session->goldclub){ - if(isset($_GET['t'])==99) { - - if($_GET['action'] == 'addList') { - include("Templates/goldClub/farmlist_add.tpl"); - } - if($_GET['action'] == 'showSlot' && $_GET['lid']) { - include("Templates/goldClub/farmlist_addraid.tpl"); - }elseif($_GET['action'] == 'showSlot' && $_GET['eid']) { - include("Templates/goldClub/farmlist_editraid.tpl"); - } - if($_GET['action'] == 'deleteList') { - $database->delFarmList($_GET['lid'], $session->uid); - header("Location: build.php?id=39&t=99"); - }elseif($_GET['action'] == 'deleteSlot') { - $database->delSlotFarm($_GET['eid']); - header("Location: build.php?id=39&t=99"); - } - } - } + if(isset($_GET['t'])==99) { + + if($_GET['action'] == 'addList') { + include("Templates/goldClub/farmlist_add.tpl"); + } + + if($_GET['action'] == 'addraid') { + include("Templates/goldClub/farmlist_addraid.tpl"); + } + }elseif($_GET['action'] == 'showSlot' && $_GET['eid']) { + include("Templates/goldClub/farmlist_editraid.tpl"); + } + if($_GET['action'] == 'deleteList') { + $database->delFarmList($_GET['lid'], $session->uid); + header("Location: build.php?id=39&t=99"); + }elseif($_GET['action'] == 'deleteSlot') { + $database->delSlotFarm($_GET['eid']); + header("Location: build.php?id=39&t=99"); + } + } if (isset($_POST['a']) == 533374 && isset($_POST['id']) == 39){ - $units->Settlers($_POST); + $units->Settlers($_POST); } if ($_GET['mode']=='troops'&&$_GET['cancel']==1){ @@ -76,22 +78,22 @@ if (($now-$oldmovement[0]['starttime'])<90){ $qc="SELECT * FROM " . TB_PREFIX . "movement where proc = 0 and moveid = ".$_GET['moveid']; $resultc=$database->query($qc) or die(mysql_error()); - if (mysql_num_rows($resultc)==1){ + if (mysql_num_rows($resultc)==1){ - $q = "UPDATE " . TB_PREFIX . "movement set proc = 1 where proc = 0 and moveid = ".$_GET['moveid']; - $database->query($q); - $end=$now+($now-$oldmovement[0]['starttime']); - //echo "6,".$oldmovement[0]['to'].",".$oldmovement[0]['from'].",0,".$now.",".$end; - $q2 = "SELECT id FROM " . TB_PREFIX . "send ORDER BY id DESC"; - $lastid=mysql_fetch_array(mysql_query($q2)); - $newid=$lastid['id']+1; - $q2 = "INSERT INTO " . TB_PREFIX . "send values ($newid,0,0,0,0,0)"; - $database->query($q2); - $database->addMovement(4,$oldmovement[0]['to'],$oldmovement[0]['from'],$oldmovement[0]['ref'],$oldmovement[0]['starttime'],$end); + $q = "UPDATE " . TB_PREFIX . "movement set proc = 1 where proc = 0 and moveid = ".$_GET['moveid']; + $database->query($q); + $end=$now+($now-$oldmovement[0]['starttime']); + //echo "6,".$oldmovement[0]['to'].",".$oldmovement[0]['from'].",0,".$now.",".$end; + $q2 = "SELECT id FROM " . TB_PREFIX . "send ORDER BY id DESC"; + $lastid=mysql_fetch_array(mysql_query($q2)); + $newid=$lastid['id']+1; + $q2 = "INSERT INTO " . TB_PREFIX . "send values ($newid,0,0,0,0,0)"; + $database->query($q2); + $database->addMovement(4,$oldmovement[0]['to'],$oldmovement[0]['from'],$oldmovement[0]['ref'],$oldmovement[0]['starttime'],$end); - $database->addMovement(6,$oldmovement[0]['to'],$oldmovement[0]['from'],$newid,$oldmovement[0]['strattime'],$end); - } + $database->addMovement(6,$oldmovement[0]['to'],$oldmovement[0]['from'],$newid,$oldmovement[0]['strattime'],$end); + } } header("Location: ".$_SERVER['PHP_SELF']."?id=".$_GET['id']); } @@ -102,34 +104,34 @@ $automation->isWinner(); - <?php echo SERVER_NAME; ?> + <?php echo SERVER_NAME; ?> - - - - - + + + + + - - - - - - gpack == null || GP_ENABLE == false) { - echo " - - "; - } else { - echo " - - "; - } - ?> - + + + + + gpack == null || GP_ENABLE == false) { + echo " + + "; + } else { + echo " + + "; + } + ?> + + window.addEvent('domready', start); + @@ -137,49 +139,49 @@ $automation->isWinner();
-
+
resarray['f99t'] == 40){ - include("Templates/Build/ww.tpl"); - } else - if($village->resarray['f'.$_GET['id'].'t'] == 0 && $_GET['id'] >= 19) { - include("Templates/Build/avaliable.tpl"); - } - else { - if(isset($_GET['t'])) { - if($_GET['t'] == 1) { - $_SESSION['loadMarket'] = 1; - } - include("Templates/Build/".$village->resarray['f'.$_GET['id'].'t']."_".$_GET['t'].".tpl"); - } else - if(isset($_GET['s'])) { - include("Templates/Build/".$village->resarray['f'.$_GET['id'].'t']."_".$_GET['s'].".tpl"); - } - else { - include("Templates/Build/".$village->resarray['f'.$_GET['id'].'t'].".tpl"); - } - } + if(isset($_GET['s'])) + { + if (!ctype_digit($_GET['s'])) { + $_GET['s'] = null; + } + } + if(isset($_GET['t'])) + { + if (!ctype_digit($_GET['t'])) { + $_GET['t'] = null; + } + } + if (!ctype_digit($_GET['id'])) { + $_GET['id'] = "1"; + } + $id = $_GET['id']; + if($id=='99' AND $village->resarray['f99t'] == 40){ + include("Templates/Build/ww.tpl"); + } else + if($village->resarray['f'.$_GET['id'].'t'] == 0 && $_GET['id'] >= 19) { + include("Templates/Build/avaliable.tpl"); + } + else { + if(isset($_GET['t'])) { + if($_GET['t'] == 1) { + $_SESSION['loadMarket'] = 1; + } + include("Templates/Build/".$village->resarray['f'.$_GET['id'].'t']."_".$_GET['t'].".tpl"); + } else + if(isset($_GET['s'])) { + include("Templates/Build/".$village->resarray['f'.$_GET['id'].'t']."_".$_GET['s'].".tpl"); + } + else { + include("Templates/Build/".$village->resarray['f'.$_GET['id'].'t'].".tpl"); + } + } }else{ header("Location: dorf1.php"); } @@ -213,9 +215,9 @@ echo round(($generator->pageLoadTimeEnd()-$start)*1000);
Server time:
-
+ -
+
- + \ No newline at end of file diff --git a/startRaid.php b/startRaid.php new file mode 100644 index 00000000..dcdee626 --- /dev/null +++ b/startRaid.php @@ -0,0 +1,118 @@ + WORLD_MAX) { + $xdistance = (2 * WORLD_MAX + 1) - $xdistance; + } + $ydistance = ABS($thiscoor['y'] - $coor['y']); + if($ydistance > WORLD_MAX) { + $ydistance = (2 * WORLD_MAX + 1) - $ydistance; + } + $distance = SQRT(POW($xdistance,2)+POW($ydistance,2)); + if(!$mode) { + if($ref == 1) { + $speed = 16; + } + else if($ref == 2) { + $speed = 12; + } + else if($ref == 3) { + $speed = 24; + } + else if($ref == 300) { + $speed = 5; + } + else { + $speed = 1; + } + } + else { + $speed = $ref; + } + return round(($distance/$speed) * 3600 / INCREASE_SPEED); + } + + $slots = $_POST['slot']; + $lid = $_POST['lid']; + $tribe = $_POST['tribe']; + $enforce = $database->getEnforceArray($r, 0); + $getFLData = $database->getFLData($lid); + $unitslist = $database->getFLData($lid); + $sql = mysql_query("SELECT * FROM ".TB_PREFIX."raidlist WHERE lid = ".$lid.""); + $sql1 = mysql_query("SELECT * FROM ".TB_PREFIX."units WHERE vref = ".$getFLData['wref']); + while($row = mysql_fetch_array($sql)){ + $sid = $row['id']; + $wref = $row['towref']; + $t1 = $row['t1'];$t2 = $row['t2'];$t3 = $row['t3'];$t4 = $row['t4'];$t5 = $row['t5']; + $t6 = $row['t6'];$t7 = $row['t7'];$t8 = $row['t8'];$t9 = $row['t9'];$t10 = $row['t10']; + $t11 = 0; + if($tribe == 1){ $u = ""; } elseif($tribe == 2){ $u = "1"; } elseif($tribe == 3){ $u = "2"; }elseif($tribe == 4){ $u = "3"; }else {$u = "4"; } + if($sql[$u.'1']>=$t1 && $sql[$u.'2']>=$t2 && $sql[$u.'3']>=$t3 && $sql[$u.'4']>=$t4 && $sql[$u.'5']>=$t5 && $sql[$u.'6']>=$t6 && $sql[$u.'7']>=$t7 && $sql[$u.'8']>=$t8 && $sql[$u.'9']>=$t9 && $sql[$u.'10']>=$t10 && $sql['hero']>=$t11){ + if($slots[$sid]=='on'){ + $ckey = $generator->generateRandStr(6); + $id = $database->addA2b($ckey,time(),$wref,$t1,$t2,$t3,$t4,$t5,$t6,$t7,$t8,$t9,$t10,$t11,4); + + $data = $database->getA2b($ckey, time()); + + if($database->checkVilExist($data['to_vid'])){ + $query1 = mysql_query('SELECT * FROM `' . TB_PREFIX . 'vdata` WHERE `wref` = ' . $data['to_vid']); + }else{ + $query1 = mysql_query('SELECT * FROM `' . TB_PREFIX . 'odata` WHERE `wref` = ' . $data['to_vid']); + } + $data1 = mysql_fetch_assoc($query1); + $query2 = mysql_query('SELECT * FROM `' . TB_PREFIX . 'users` WHERE `id` = '.$data1['owner']); + $data2 = mysql_fetch_assoc($query2); + $query11 = mysql_query('SELECT * FROM `' . TB_PREFIX . 'vdata` WHERE `wref` = '.$getFLData['wref']); + $data11 = mysql_fetch_assoc($query11); + $query21 = mysql_query('SELECT * FROM `' . TB_PREFIX . 'users` WHERE `id` = '.$data11['owner']); + $data21 = mysql_fetch_assoc($query21); + + $eigen = $database->getCoor($getFLData['wref']); + $from = array('x'=>$eigen['x'], 'y'=>$eigen['y']); + $ander = $database->getCoor($data['to_vid']); + $to = array('x'=>$ander['x'], 'y'=>$ander['y']); + $start = ($data21['tribe']-1)*10+1; + $end = ($data21['tribe']*10); + + $speeds = array(); + $scout = 1; + + //find slowest unit. + for($i=1;$i<=10;$i++){ + if ($data['u'.$i]){ + if($data['u'.$i] != '' && $data['u'.$i] > 0){ + if($unitarray) { reset($unitarray); } + $unitarray = $GLOBALS["u".(($tribe-1)*10+$i)]; + $speeds[] = $unitarray['speed']; + } + } + } + + $time = procDistanceTime2($from,$to,min($speeds),1); + + $ctar1 = 0; + $ctar2 = 0; + $abdata = $database->getABTech($getFLData['wref']); + $reference = $database->addAttack(($getFLData['wref']),$data['u1'],$data['u2'],$data['u3'],$data['u4'],$data['u5'],$data['u6'],$data['u7'],$data['u8'],$data['u9'],$data['u10'],$data['u11'],$data['type'],$ctar1,$ctar2,0,$abdata['b1'],$abdata['b2'],$abdata['b3'],$abdata['b4'],$abdata['b5'],$abdata['b6'],$abdata['b7'],$abdata['b8']); + $totalunits = $data['u1']+$data['u2']+$data['u3']+$data['u4']+$data['u5']+$data['u6']+$data['u7']+$data['u8']+$data['u9']+$data['u10']+$data['u11']; + $database->modifyUnit($getFLData['wref'], array($u.'1'), array($data['u1']), array(0)); + $database->modifyUnit($getFLData['wref'], array($u.'2'), array($data['u2']), array(0)); + $database->modifyUnit($getFLData['wref'], array($u.'3'), array($data['u3']), array(0)); + $database->modifyUnit($getFLData['wref'], array($u.'4'), array($data['u4']), array(0)); + $database->modifyUnit($getFLData['wref'], array($u.'5'), array($data['u5']), array(0)); + $database->modifyUnit($getFLData['wref'], array($u.'6'), array($data['u6']), array(0)); + $database->modifyUnit($getFLData['wref'], array($u.'7'), array($data['u7']), array(0)); + $database->modifyUnit($getFLData['wref'], array($u.'8'), array($data['u8']), array(0)); + $database->modifyUnit($getFLData['wref'], array($u.'9'), array($data['u9']), array(0)); + $database->modifyUnit($getFLData['wref'], array($u.'10'), array($data['u10']), array(0)); + $database->modifyUnit($getFLData['wref'], array('hero'), array($data['u11']), array(0)); + + $database->addMovement(3,$getFLData['wref'],$data['to_vid'],$reference,0,($time+time())); + } + } + } +header("Location: build.php?id=39&t=99"); +?> \ No newline at end of file