PageRenderTime 44ms CodeModel.GetById 33ms RepoModel.GetById 1ms app.codeStats 0ms

/GameEngine/Database/db_MYSQL.php

https://github.com/DEVVELO/TravianZ-By-Shadowss
PHP | 3784 lines | 3280 code | 320 blank | 184 comment | 361 complexity | 277f55d1c5a8b1877999f72931fb9fb3 MD5 | raw file
  1. <?php
  2. #################################################################################
  3. ## -= YOU MAY NOT REMOVE OR CHANGE THIS NOTICE =- ##
  4. ## --------------------------------------------------------------------------- ##
  5. ## Project: TravianZ ##
  6. ## Version: 01.09.2013 ##
  7. ## Filename db_MYSQL.php ##
  8. ## Developed by: Mr.php , Advocaite , brainiacX , yi12345 , Shadow , ronix ##
  9. ## Fixed by: Shadow - Doubleing Troops , STARVATION , HERO FIXED COMPL. ##
  10. ## License: TravianZ Project ##
  11. ## Copyright: TravianZ (c) 2010-2013. All rights reserved. ##
  12. ## URLs: http://travian.shadowss.ro ##
  13. ## Source code: http://github.com/Shadowss/TravianZ-by-Shadow/ ##
  14. ## ##
  15. #################################################################################
  16. class MYSQL_DB {
  17. var $connection;
  18. function MYSQL_DB() {
  19. $this->connection = mysql_connect(SQL_SERVER, SQL_USER, SQL_PASS) or die(mysql_error());
  20. mysql_select_db(SQL_DB, $this->connection) or die(mysql_error());
  21. mysql_query("SET NAMES 'UTF8'"); //Fix utf8 phpmyadmin by gm4st3r
  22. }
  23. function register($username, $password, $email, $tribe, $act) {
  24. $time = time();
  25. $stime = strtotime(START_DATE)-strtotime(date('m/d/Y'))+strtotime(START_TIME);
  26. if($stime > time()){
  27. $time = $stime;
  28. }
  29. $timep = $time + PROTECTION;
  30. $time = time();
  31. $q = "INSERT INTO " . TB_PREFIX . "users (username,password,access,email,timestamp,tribe,act,protect,lastupdate,regtime) VALUES ('$username', '$password', " . USER . ", '$email', $time, $tribe, '$act', $timep, $time, $time)";
  32. if(mysql_query($q, $this->connection)) {
  33. return mysql_insert_id($this->connection);
  34. } else {
  35. return false;
  36. }
  37. }
  38. function activate($username, $password, $email, $tribe, $locate, $act, $act2) {
  39. $time = time();
  40. $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')";
  41. if(mysql_query($q, $this->connection)) {
  42. return mysql_insert_id($this->connection);
  43. } else {
  44. return false;
  45. }
  46. }
  47. function unreg($username) {
  48. $q = "DELETE from " . TB_PREFIX . "activate where username = '$username'";
  49. return mysql_query($q, $this->connection);
  50. }
  51. function deleteReinf($id) {
  52. $q = "DELETE from " . TB_PREFIX . "enforcement where id = '$id'";
  53. mysql_query($q, $this->connection);
  54. }
  55. function updateResource($vid, $what, $number) {
  56. $q = "UPDATE " . TB_PREFIX . "vdata set " . $what . "=" . $number . " where wref = $vid";
  57. $result = mysql_query($q, $this->connection);
  58. return mysql_query($q, $this->connection);
  59. }
  60. function checkExist($ref, $mode) {
  61. if(!$mode) {
  62. $q = "SELECT username FROM " . TB_PREFIX . "users where username = '$ref' LIMIT 1";
  63. } else {
  64. $q = "SELECT email FROM " . TB_PREFIX . "users where email = '$ref' LIMIT 1";
  65. }
  66. $result = mysql_query($q, $this->connection);
  67. if(mysql_num_rows($result)) {
  68. return true;
  69. } else {
  70. return false;
  71. }
  72. }
  73. function checkExist_activate($ref, $mode) {
  74. if(!$mode) {
  75. $q = "SELECT username FROM " . TB_PREFIX . "activate where username = '$ref' LIMIT 1";
  76. } else {
  77. $q = "SELECT email FROM " . TB_PREFIX . "activate where email = '$ref' LIMIT 1";
  78. }
  79. $result = mysql_query($q, $this->connection);
  80. if(mysql_num_rows($result)) {
  81. return true;
  82. } else {
  83. return false;
  84. }
  85. }
  86. public function hasBeginnerProtection($vid) {
  87. $q = "SELECT u.protect FROM ".TB_PREFIX."users u,".TB_PREFIX."vdata v WHERE u.id=v.owner AND v.wref=".$vid;
  88. $result = mysql_query($q, $this->connection);
  89. $dbarray = mysql_fetch_array($result);
  90. if(!empty($dbarray)) {
  91. if(time()<$dbarray[0]) {
  92. return true;
  93. } else {
  94. return false;
  95. }
  96. } else {
  97. return false;
  98. }
  99. }
  100. function updateUserField($ref, $field, $value, $switch) {
  101. if(!$switch) {
  102. $q = "UPDATE " . TB_PREFIX . "users set $field = '$value' where username = '$ref'";
  103. } else {
  104. $q = "UPDATE " . TB_PREFIX . "users set $field = '$value' where id = '$ref'";
  105. }
  106. return mysql_query($q, $this->connection);
  107. }
  108. function getSitee($uid) {
  109. $q = "SELECT id from " . TB_PREFIX . "users where sit1 = $uid or sit2 = $uid";
  110. $result = mysql_query($q, $this->connection);
  111. return $this->mysql_fetch_all($result);
  112. }
  113. function getVilWref($x, $y) {
  114. $q = "SELECT * FROM " . TB_PREFIX . "wdata where x = $x AND y = $y";
  115. $result = mysql_query($q, $this->connection);
  116. $dbarray = mysql_fetch_array($result);
  117. return $dbarray['id'];
  118. }
  119. function caststruc($user) {
  120. //loop search village user
  121. $query = mysql_query("SELECT * FROM ".TB_PREFIX."vdata WHERE owner = ".$user."");
  122. while($villaggi_array = mysql_fetch_array($query))
  123. //loop structure village
  124. $query1 = mysql_query("SELECT * FROM ".TB_PREFIX."fdata WHERE vref = ".$villaggi_array['wref']."");
  125. $strutture= mysql_fetch_array($query1);
  126. return $strutture;
  127. }
  128. function removeMeSit($uid, $uid2) {
  129. $q = "UPDATE " . TB_PREFIX . "users set sit1 = 0 where id = $uid and sit1 = $uid2";
  130. mysql_query($q, $this->connection);
  131. $q2 = "UPDATE " . TB_PREFIX . "users set sit2 = 0 where id = $uid and sit2 = $uid2";
  132. mysql_query($q2, $this->connection);
  133. }
  134. function getUserField($ref, $field, $mode) {
  135. if(!$mode) {
  136. $q = "SELECT $field FROM " . TB_PREFIX . "users where id = '$ref'";
  137. } else {
  138. $q = "SELECT $field FROM " . TB_PREFIX . "users where username = '$ref'";
  139. }
  140. $result = mysql_query($q, $this->connection) or die(mysql_error());
  141. if($result) {
  142. $dbarray = mysql_fetch_array($result);
  143. return $dbarray[$field];
  144. }elseif($field=="username"){
  145. return "??";
  146. }else return 0;
  147. }
  148. function getInvitedUser($uid) {
  149. $q = "SELECT * FROM " . TB_PREFIX . "users where invited = $uid order by regtime desc";
  150. $result = mysql_query($q, $this->connection);
  151. return $this->mysql_fetch_all($result);
  152. }
  153. function getVrefField($ref, $field){
  154. $q = "SELECT $field FROM " . TB_PREFIX . "vdata where wref = '$ref'";
  155. $result = mysql_query($q, $this->connection) or die(mysql_error());
  156. $dbarray = mysql_fetch_array($result);
  157. return $dbarray[$field];
  158. }
  159. function getVrefCapital($ref){
  160. $q = "SELECT * FROM " . TB_PREFIX . "vdata where owner = '$ref' and capital = 1";
  161. $result = mysql_query($q, $this->connection) or die(mysql_error());
  162. $dbarray = mysql_fetch_array($result);
  163. return $dbarray;
  164. }
  165. function getStarvation(){
  166. $q = "SELECT * FROM " . TB_PREFIX . "vdata where starv != 0 and owner != 3";
  167. $result = mysql_query($q, $this->connection);
  168. return $this->mysql_fetch_all($result);
  169. }
  170. function getUnstarvation(){
  171. $q = "SELECT * FROM " . TB_PREFIX . "vdata where starv = 0 and starvupdate = 0";
  172. $result = mysql_query($q, $this->connection);
  173. return $this->mysql_fetch_all($result);
  174. }
  175. function getActivateField($ref, $field, $mode) {
  176. if(!$mode) {
  177. $q = "SELECT $field FROM " . TB_PREFIX . "activate where id = '$ref'";
  178. } else {
  179. $q = "SELECT $field FROM " . TB_PREFIX . "activate where username = '$ref'";
  180. }
  181. $result = mysql_query($q, $this->connection) or die(mysql_error());
  182. $dbarray = mysql_fetch_array($result);
  183. return $dbarray[$field];
  184. }
  185. function login($username, $password) {
  186. $q = "SELECT password,sessid FROM " . TB_PREFIX . "users where username = '$username'";
  187. $result = mysql_query($q, $this->connection);
  188. $dbarray = mysql_fetch_array($result);
  189. if($dbarray['password'] == md5($password)) {
  190. return true;
  191. } else {
  192. return false;
  193. }
  194. }
  195. function checkActivate($act) {
  196. $q = "SELECT * FROM " . TB_PREFIX . "activate where act = '$act'";
  197. $result = mysql_query($q, $this->connection);
  198. $dbarray = mysql_fetch_array($result);
  199. return $dbarray;
  200. }
  201. function sitterLogin($username, $password) {
  202. $q = "SELECT sit1,sit2 FROM " . TB_PREFIX . "users where username = '$username' and access != " . BANNED;
  203. $result = mysql_query($q, $this->connection);
  204. $dbarray = mysql_fetch_array($result);
  205. if($dbarray['sit1'] != 0) {
  206. $q2 = "SELECT password FROM " . TB_PREFIX . "users where id = " . $dbarray['sit1'] . " and access != " . BANNED;
  207. $result2 = mysql_query($q2, $this->connection);
  208. $dbarray2 = mysql_fetch_array($result2);
  209. }
  210. if($dbarray['sit2'] != 0) {
  211. $q3 = "SELECT password FROM " . TB_PREFIX . "users where id = " . $dbarray['sit2'] . " and access != " . BANNED;
  212. $result3 = mysql_query($q3, $this->connection);
  213. $dbarray3 = mysql_fetch_array($result3);
  214. }
  215. if($dbarray['sit1'] != 0 || $dbarray['sit2'] != 0) {
  216. if($dbarray2['password'] == md5($password) || $dbarray3['password'] == md5($password)) {
  217. return true;
  218. } else {
  219. return false;
  220. }
  221. } else {
  222. return false;
  223. }
  224. }
  225. function setDeleting($uid, $mode) {
  226. $time = time() + 72 * 3600;
  227. if(!$mode) {
  228. $q = "INSERT into " . TB_PREFIX . "deleting values ($uid,$time)";
  229. } else {
  230. $q = "DELETE FROM " . TB_PREFIX . "deleting where uid = $uid";
  231. }
  232. mysql_query($q, $this->connection);
  233. }
  234. function isDeleting($uid) {
  235. $q = "SELECT timestamp from " . TB_PREFIX . "deleting where uid = $uid";
  236. $result = mysql_query($q, $this->connection);
  237. $dbarray = mysql_fetch_array($result);
  238. return $dbarray['timestamp'];
  239. }
  240. function modifyGold($userid, $amt, $mode) {
  241. if(!$mode) {
  242. $q = "UPDATE " . TB_PREFIX . "users set gold = gold - $amt where id = $userid";
  243. } else {
  244. $q = "UPDATE " . TB_PREFIX . "users set gold = gold + $amt where id = $userid";
  245. }
  246. return mysql_query($q, $this->connection);
  247. }
  248. /*****************************************
  249. Function to retrieve user array via Username or ID
  250. Mode 0: Search by Username
  251. Mode 1: Search by ID
  252. References: Alliance ID
  253. *****************************************/
  254. function getUserArray($ref, $mode) {
  255. if(!$mode) {
  256. $q = "SELECT * FROM " . TB_PREFIX . "users where username = '$ref'";
  257. } else {
  258. $q = "SELECT * FROM " . TB_PREFIX . "users where id = $ref";
  259. }
  260. $result = mysql_query($q, $this->connection);
  261. return mysql_fetch_array($result);
  262. }
  263. function activeModify($username, $mode) {
  264. $time = time();
  265. if(!$mode) {
  266. $q = "INSERT into " . TB_PREFIX . "active VALUES ('$username',$time)";
  267. } else {
  268. $q = "DELETE FROM " . TB_PREFIX . "active where username = '$username'";
  269. }
  270. return mysql_query($q, $this->connection);
  271. }
  272. function addActiveUser($username, $time) {
  273. $q = "REPLACE into " . TB_PREFIX . "active values ('$username',$time)";
  274. if(mysql_query($q, $this->connection)) {
  275. return true;
  276. } else {
  277. return false;
  278. }
  279. }
  280. function updateActiveUser($username, $time) {
  281. $q = "REPLACE into " . TB_PREFIX . "active values ('$username',$time)";
  282. $q2 = "UPDATE " . TB_PREFIX . "users set timestamp = $time where username = '$username'";
  283. $exec1 = mysql_query($q, $this->connection);
  284. $exec2 = mysql_query($q2, $this->connection);
  285. if($exec1 && $exec2) {
  286. return true;
  287. } else {
  288. return false;
  289. }
  290. }
  291. function checkactiveSession($username, $sessid) {
  292. $q = "SELECT username FROM " . TB_PREFIX . "users where username = '$username' and sessid = '$sessid' LIMIT 1";
  293. $result = mysql_query($q, $this->connection);
  294. if(mysql_num_rows($result) != 0) {
  295. return true;
  296. } else {
  297. return false;
  298. }
  299. }
  300. function submitProfile($uid, $gender, $location, $birthday, $des1, $des2) {
  301. $q = "UPDATE " . TB_PREFIX . "users set gender = $gender, location = '$location', birthday = '$birthday', desc1 = '$des1', desc2 = '$des2' where id = $uid";
  302. return mysql_query($q, $this->connection);
  303. }
  304. function gpack($uid, $gpack) {
  305. $q = "UPDATE " . TB_PREFIX . "users set gpack = '$gpack' where id = $uid";
  306. return mysql_query($q, $this->connection);
  307. }
  308. function GetOnline($uid) {
  309. $q = "SELECT sit FROM " . TB_PREFIX . "online where uid = $uid";
  310. $result = mysql_query($q, $this->connection);
  311. $dbarray = mysql_fetch_array($result);
  312. return $dbarray['sit'];
  313. }
  314. function UpdateOnline($mode, $name = "", $time = "", $uid = 0) {
  315. global $session;
  316. if($mode == "login") {
  317. $q = "INSERT IGNORE INTO " . TB_PREFIX . "online (name, uid, time, sit) VALUES ('$name', '$uid', " . time() . ", 0)";
  318. return mysql_query($q, $this->connection);
  319. } else if($mode == "sitter") {
  320. $q = "INSERT IGNORE INTO " . TB_PREFIX . "online (name, uid, time, sit) VALUES ('$name', '$uid', " . time() . ", 1)";
  321. return mysql_query($q, $this->connection);
  322. } else {
  323. $q = "DELETE FROM " . TB_PREFIX . "online WHERE name ='" . addslashes($session->username) . "'";
  324. return mysql_query($q, $this->connection);
  325. }
  326. }
  327. function generateBase($sector, $mode=1) {
  328. $num_rows = 0;
  329. $count_while = 0;
  330. while (!$num_rows){
  331. if (!$mode) {
  332. $gamesday=time()-COMMENCE;
  333. if ($gamesday<3600*24*10 && $count_while==0) { //10 day
  334. $wide1=1;
  335. $wide2=20;
  336. } elseif ($gamesday<3600*24*20 && $count_while==1) { //20 day
  337. $wide1=20;
  338. $wide2=40;
  339. } elseif ($gamesday<3600*24*30 && $count_while==2) { //30 day
  340. $wide1=40;
  341. $wide2=80;
  342. } else { // over 30 day
  343. $wide1=80;
  344. $wide2=WORLD_MAX;
  345. }
  346. }
  347. else {
  348. $wide1=1;
  349. $wide2=WORLD_MAX;
  350. }
  351. switch($sector) {
  352. case 1:
  353. $q = "Select * from ".TB_PREFIX."wdata where fieldtype = 3 and (x < -$wide1 and x > -$wide2) and (y > $wide1 and y < $wide2) and occupied = 0"; //x- y+
  354. break;
  355. case 2:
  356. $q = "Select * from ".TB_PREFIX."wdata where fieldtype = 3 and (x > $wide1 and x < $wide2) and (y > $wide1 and y < $wide2) and occupied = 0"; //x+ y+
  357. break;
  358. case 3:
  359. $q = "Select * from ".TB_PREFIX."wdata where fieldtype = 3 and (x < -$wide1 and x > -$wide2) and (y < -$wide1 and y > -$wide2) and occupied = 0"; //x- y-
  360. break;
  361. case 4:
  362. $q = "Select * from ".TB_PREFIX."wdata where fieldtype = 3 and (x > $wide1 and x < $wide2) and (y < -$wide1 and y > -$wide2) and occupied = 0"; //x+ y-
  363. break;
  364. }
  365. $result = mysql_query($q, $this->connection);
  366. $num_rows = mysql_num_rows($result);
  367. $count_while++;
  368. }
  369. $result = $this->mysql_fetch_all($result);
  370. $base = rand(0, ($num_rows-1));
  371. return $result[$base]['id'];
  372. }
  373. function setFieldTaken($id) {
  374. $q = "UPDATE " . TB_PREFIX . "wdata set occupied = 1 where id = $id";
  375. return mysql_query($q, $this->connection);
  376. }
  377. function addVillage($wid, $uid, $username, $capital) {
  378. $total = count($this->getVillagesID($uid));
  379. if($total >= 1) {
  380. $vname = $username . "\'s village " . ($total + 1);
  381. } else {
  382. $vname = $username . "\'s village";
  383. }
  384. $time = time();
  385. $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')";
  386. return mysql_query($q, $this->connection) or die(mysql_error());
  387. }
  388. function addResourceFields($vid, $type) {
  389. switch($type) {
  390. case 1:
  391. $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)";
  392. break;
  393. case 2:
  394. $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)";
  395. break;
  396. case 3:
  397. $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)";
  398. break;
  399. case 4:
  400. $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)";
  401. break;
  402. case 5:
  403. $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)";
  404. break;
  405. case 6:
  406. $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)";
  407. break;
  408. case 7:
  409. $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)";
  410. break;
  411. case 8:
  412. $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)";
  413. break;
  414. case 9:
  415. $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)";
  416. break;
  417. case 10:
  418. $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)";
  419. break;
  420. case 11:
  421. $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)";
  422. break;
  423. case 12:
  424. $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)";
  425. break;
  426. }
  427. return mysql_query($q, $this->connection);
  428. }
  429. function isVillageOases($wref) {
  430. $q = "SELECT id, oasistype FROM " . TB_PREFIX . "wdata where id = $wref";
  431. $result = mysql_query($q, $this->connection);
  432. if($result){
  433. $dbarray = mysql_fetch_array($result);
  434. return $dbarray['oasistype'];
  435. }else return 0;
  436. }
  437. public function VillageOasisCount($vref) {
  438. $q = "SELECT count(*) FROM `".TB_PREFIX."odata` WHERE conqured=$vref";
  439. $result = mysql_query($q, $this->connection);
  440. $row = mysql_fetch_row($result);
  441. return $row[0];
  442. }
  443. public function countOasisTroops($vref){
  444. //count oasis troops: $troops_o
  445. $troops_o=0;
  446. $o_unit2=mysql_query("select * from ".TB_PREFIX."units where `vref`='".$vref."'");
  447. $o_unit=mysql_fetch_array($o_unit2);
  448. for ($i=1;$i<51;$i++)
  449. {
  450. $troops_o+=$o_unit[$i];
  451. }
  452. $troops_o+=$o_unit['hero'];
  453. $o_unit2=mysql_query("select * from ".TB_PREFIX."enforcement where `vref`='".$vref."'");
  454. while ($o_unit=@mysql_fetch_array($o_unit2))
  455. {
  456. for ($i=1;$i<51;$i++)
  457. {
  458. $troops_o+=$o_unit[$i];
  459. }
  460. $troops_o+=$o_unit['hero'];
  461. }
  462. return $troops_o;
  463. }
  464. public function canConquerOasis($vref,$wref) {
  465. $AttackerFields = $this->getResourceLevel($vref);
  466. for($i=19;$i<=38;$i++) {
  467. if($AttackerFields['f'.$i.'t'] == 37) { $HeroMansionLevel = $AttackerFields['f'.$i]; }
  468. }
  469. if($this->VillageOasisCount($vref) < floor(($HeroMansionLevel-5)/5)) {
  470. $OasisInfo = $this->getOasisInfo($wref);
  471. //fix by ronix
  472. if($OasisInfo['conqured'] == 0 || $OasisInfo['conqured'] != 0 && intval($OasisInfo['loyalty']) < 99 / min(3,(4-$this->VillageOasisCount($OasisInfo['conqured'])))){
  473. $CoordsVillage = $this->getCoor($vref);
  474. $CoordsOasis = $this->getCoor($wref);
  475. $max = 2 * WORLD_MAX + 1;
  476. $x1 = intval($CoordsOasis['x']);
  477. $y1 = intval($CoordsOasis['y']);
  478. $x2 = intval($CoordsVillage['x']);
  479. $y2 = intval($CoordsVillage['y']);
  480. $distanceX = min(abs($x2 - $x1), abs($max - abs($x2 - $x1)));
  481. $distanceY = min(abs($y2 - $y1), abs($max - abs($y2 - $y1)));
  482. if ($distanceX<=3 && $distanceY<=3) {
  483. return 1; //can
  484. } else {
  485. return 2; //can but not in 7x7 field
  486. }
  487. } else {
  488. return 3; //loyalty >0
  489. }
  490. } else {
  491. return 0; //req level hero mansion
  492. }
  493. }
  494. public function conquerOasis($vref,$wref) {
  495. $vinfo = $this->getVillage($vref);
  496. $uid = $vinfo['owner'];
  497. $q = "UPDATE `".TB_PREFIX."odata` SET conqured=$vref,loyalty=100,lastupdated=".time().",owner=$uid,name='Occupied Oasis' WHERE wref=$wref";
  498. return mysql_query($q, $this->connection);
  499. }
  500. public function modifyOasisLoyalty($wref) {
  501. if($this->isVillageOases($wref) != 0) {
  502. $OasisInfo = $this->getOasisInfo($wref);
  503. if($OasisInfo['conqured'] != 0) {
  504. $LoyaltyAmendment = floor(100 / min(3,(4-$this->VillageOasisCount($OasisInfo['conqured']))));
  505. $q = "UPDATE `".TB_PREFIX."odata` SET loyalty=loyalty-$LoyaltyAmendment, lastupdated=".time()." WHERE wref=$wref";
  506. $result=mysql_query($q, $this->connection);
  507. return $OasisInfo['loyalty']-$LoyaltyAmendment;
  508. }
  509. }
  510. }
  511. function populateOasis() {
  512. $q = "SELECT * FROM " . TB_PREFIX . "wdata where oasistype != 0";
  513. $result = mysql_query($q, $this->connection);
  514. while($row = mysql_fetch_array($result)) {
  515. $wid = $row['id'];
  516. $this->addUnits($wid);
  517. }
  518. }
  519. function populateOasisUnits($wid, $high) {
  520. $basearray = $this->getOasisInfo($wid);
  521. if($high == 0){
  522. $max = rand(15,30);
  523. }elseif($high == 1){
  524. $max = rand(50,70);
  525. }elseif($high == 2){
  526. $max = rand(90,120);
  527. }
  528. $max2 = 0;
  529. $rand = rand(0,3);
  530. if($rand == 1){
  531. $max2 = 3;
  532. }
  533. //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
  534. switch($basearray['type']) {
  535. case 1:
  536. case 2:
  537. //+25% lumber per hour
  538. $q = "UPDATE " . TB_PREFIX . "units SET u35 = u35 + '".rand(0,5)."', u36 = u36 + '".rand(0,5)."', u37 = u37 + '".rand(0,5)."' WHERE vref = '" . $wid . "' AND (u35 <= ".$max." OR u36 <= ".$max." OR u37 <= ".$max.")";
  539. $result = mysql_query($q, $this->connection);
  540. break;
  541. case 3:
  542. //+25% lumber and +25% crop per hour
  543. $q = "UPDATE " . TB_PREFIX . "units SET u35 = u35 + '".rand(0,5)."', u36 = u36 + '".rand(0,5)."', u37 = u37 + '".rand(0,5)."', u38 = u38 + '".rand(0,5)."', u40 = u40 + '".rand(0,$max2)."' WHERE vref = '" . $wid . "' AND (u36 <= ".$max." OR u37 <= ".$max." OR u38 <= ".$max.")";
  544. $result = mysql_query($q, $this->connection);
  545. break;
  546. case 4:
  547. case 5:
  548. //+25% clay per hour
  549. $q = "UPDATE " . TB_PREFIX . "units SET u31 = u31 + '".rand(0,5)."', u32 = u32 + '".rand(0,5)."', u35 = u35 + '".rand(0,5)."' WHERE vref = '" . $wid . "' AND (u31 <= ".$max." OR u32 <= ".$max." OR u35 <= ".$max.")";
  550. $result = mysql_query($q, $this->connection);
  551. break;
  552. case 6:
  553. //+25% clay and +25% crop per hour
  554. $q = "UPDATE " . TB_PREFIX . "units SET u31 = u31 + '".rand(0,5)."', u32 = u32 + '".rand(0,5)."', u35 = u35 + '".rand(0,5)."', u40 = u40 + '".rand(0,$max2)."' WHERE vref = '" . $wid . "' AND (u31 <= ".$max." OR u32 <= ".$max." OR u35 <= ".$max.")";
  555. $result = mysql_query($q, $this->connection);
  556. break;
  557. case 7:
  558. case 8:
  559. //+25% iron per hour
  560. $q = "UPDATE " . TB_PREFIX . "units SET u31 = u31 + '".rand(0,5)."', u32 = u32 + '".rand(0,5)."', u34 = u34 + '".rand(0,5)."' WHERE vref = '" . $wid . "' AND (u31 <= ".$max." OR u32 <= ".$max." OR u34 <= ".$max.")";
  561. $result = mysql_query($q, $this->connection);
  562. break;
  563. case 9:
  564. //+25% iron and +25% crop
  565. $q = "UPDATE " . TB_PREFIX . "units SET u31 = u31 + '".rand(0,5)."', u32 = u32 + '".rand(0,5)."', u34 = u34 + '".rand(0,5)."', u39 = u39 + '".rand(0,$max2)."' WHERE vref = '" . $wid . "' AND (u31 <= ".$max." OR u32 <= ".$max." OR u34 <= ".$max.")";
  566. $result = mysql_query($q, $this->connection);
  567. break;
  568. case 10:
  569. case 11:
  570. //+25% crop per hour
  571. $q = "UPDATE " . TB_PREFIX . "units SET u33 = u33 + '".rand(0,5)."', u37 = u37 + '".rand(0,5)."', u38 = u38 + '".rand(0,5)."', u39 = u39 + '".rand(0,$max2)."' WHERE vref = '" . $wid . "' AND (u33 <= ".$max." OR u37 <= ".$max." OR u38 <= ".$max.")";
  572. $result = mysql_query($q, $this->connection);
  573. break;
  574. case 12:
  575. //+50% crop per hour
  576. $q = "UPDATE " . TB_PREFIX . "units SET u33 = u33 + '".rand(0,5)."', u37 = u37 + '".rand(0,5)."', u38 = u38 + '".rand(0,5)."', u39 = u39 + '".rand(0,5)."', u40 = u40 + '".rand(0,$max2)."' WHERE vref = '" . $wid . "' AND (u33 <= ".$max." OR u37 <= ".$max." OR u38 <= ".$max." OR u39 <= ".$max.")";
  577. $result = mysql_query($q, $this->connection);
  578. break;
  579. }
  580. }
  581. function populateOasisUnits2() {
  582. $q2 = "SELECT * FROM " . TB_PREFIX . "wdata where oasistype != 0";
  583. $result2 = mysql_query($q2, $this->connection);
  584. while($row = mysql_fetch_array($result2)) {
  585. $wid = $row['id'];
  586. switch($row['oasistype']) {
  587. case 1:
  588. case 2:
  589. //+25% lumber oasis
  590. $q = "UPDATE " . TB_PREFIX . "units SET u35 = u35 + '".rand(5,10)."', u36 = u36 + '".rand(0,5)."', u37 = u37 + '".rand(0,5)."' WHERE vref = '" . $wid . "' AND u35 <= '10' AND u36 <= '10' AND u37 <= '10'";
  591. $result = mysql_query($q, $this->connection);
  592. break;
  593. case 3:
  594. //+25% lumber and +25% crop oasis
  595. $q = "UPDATE " . TB_PREFIX . "units SET u35 = u35 + '".rand(5,15)."', u36 = u36 + '".rand(0,5)."', u37 = u37 + '".rand(0,5)."' WHERE vref = '" . $wid . "' AND u35 <= '10' AND u36 <= '10' AND u37 <='10'";
  596. $result = mysql_query($q, $this->connection);
  597. break;
  598. case 4:
  599. case 5:
  600. //+25% clay oasis
  601. $q = "UPDATE " . TB_PREFIX . "units SET u31 = u31 + '".rand(10,15)."', u32 = u32 + '".rand(5,15)."', u35 = u35 + '".rand(0,10)."' WHERE vref = '" . $wid . "' AND u31 <= '10' AND u32 <= '10' AND u35 <= '10'";
  602. $result = mysql_query($q, $this->connection);
  603. break;
  604. case 6:
  605. //+25% clay and +25% crop oasis
  606. $q = "UPDATE " . TB_PREFIX . "units SET u31 = u31 + '".rand(15,20)."', u32 = u32 + '".rand(10,15)."', u35 = u35 + '".rand(0,10)."' WHERE vref = '" . $wid . "' AND u31 <= '10' AND u32 <= '10' AND u35 <='10'";
  607. $result = mysql_query($q, $this->connection);
  608. break;
  609. case 7:
  610. case 8:
  611. //+25% iron oasis
  612. $q = "UPDATE " . TB_PREFIX . "units SET u31 = u31 + '".rand(10,15)."', u32 = u32 + '".rand(5,15)."', u34 = u34 + '".rand(0,10)."' WHERE vref = '" . $wid . "' AND u31 <= '10' AND u32 <= '10' AND u34 <= '10'";
  613. $result = mysql_query($q, $this->connection);
  614. break;
  615. case 9:
  616. //+25% iron and +25% crop oasis
  617. $q = "UPDATE " . TB_PREFIX . "units SET u31 = u31 + '".rand(15,20)."', u32 = u32 + '".rand(10,15)."', u34 = u34 + '".rand(0,10)."' WHERE vref = '" . $wid . "' AND u31 <= '10' AND u32 <= '10' AND u34 <='10'";
  618. $result = mysql_query($q, $this->connection);
  619. break;
  620. case 10:
  621. case 11:
  622. //+25% crop oasis
  623. $q = "UPDATE " . TB_PREFIX . "units SET u31 = u31 + '".rand(5,15)."', u33 = u33 + '".rand(5,10)."', u37 = u37 + '".rand(0,10)."', u39 = u39 + '".rand(0,5)."' WHERE vref = '" . $wid . "' AND u31 <= '10' AND u33 <= '10' AND u37 <='10' AND u39 <='10'";
  624. $result = mysql_query($q, $this->connection);
  625. break;
  626. case 12:
  627. //+50% crop oasis
  628. $q = "UPDATE " . TB_PREFIX . "units SET u31 = u31 + '".rand(10,15)."', u33 = u33 + '".rand(5,10)."', u38 = u38 + '".rand(0,5)."', u39 = u39 + '".rand(0,5)."' WHERE vref = '" . $wid . "' AND u31 <= '10' AND u33 <= '10' AND u38 <='10'AND u39 <='10'";
  629. $result = mysql_query($q, $this->connection);
  630. break;
  631. }
  632. }
  633. }
  634. function removeOases($wref) {
  635. $q = "UPDATE ".TB_PREFIX."odata SET conqured = 0, owner = 2, name = 'Unoccupied Oasis' WHERE wref = $wref";
  636. return mysql_query($q, $this->connection);
  637. }
  638. /***************************
  639. Function to retrieve type of village via ID
  640. References: Village ID
  641. ***************************/
  642. function getVillageType($wref) {
  643. $q = "SELECT id, fieldtype FROM " . TB_PREFIX . "wdata where id = $wref";
  644. $result = mysql_query($q, $this->connection);
  645. $dbarray = mysql_fetch_array($result);
  646. return $dbarray['fieldtype'];
  647. }
  648. /*****************************************
  649. Function to retrieve if is ocuped via ID
  650. References: Village ID
  651. *****************************************/
  652. function getVillageState($wref) {
  653. $q = "SELECT oasistype,occupied FROM " . TB_PREFIX . "wdata where id = $wref";
  654. $result = mysql_query($q, $this->connection);
  655. $dbarray = mysql_fetch_array($result);
  656. if($dbarray['occupied'] != 0 || $dbarray['oasistype'] != 0) {
  657. return true;
  658. } else {
  659. return false;
  660. }
  661. }
  662. function getProfileVillages($uid) {
  663. $q = "SELECT capital,wref,name,pop,created from " . TB_PREFIX . "vdata where owner = $uid order by pop desc";
  664. $result = mysql_query($q, $this->connection);
  665. return $this->mysql_fetch_all($result);
  666. }
  667. function getProfileMedal($uid) {
  668. $q = "SELECT id,categorie,plaats,week,img,points from " . TB_PREFIX . "medal where userid = $uid and del = 0 order by id desc";
  669. $result = mysql_query($q, $this->connection);
  670. return $this->mysql_fetch_all($result);
  671. }
  672. function getProfileMedalAlly($uid) {
  673. $q = "SELECT id,categorie,plaats,week,img,points from " . TB_PREFIX . "allimedal where allyid = $uid and del = 0 order by id desc";
  674. $result = mysql_query($q, $this->connection);
  675. return $this->mysql_fetch_all($result);
  676. }
  677. function getVillageID($uid) {
  678. $q = "SELECT wref FROM " . TB_PREFIX . "vdata WHERE owner = $uid";
  679. $result = mysql_query($q, $this->connection);
  680. $dbarray = mysql_fetch_array($result);
  681. return $dbarray['wref'];
  682. }
  683. function getVillagesID($uid) {
  684. $q = "SELECT wref from " . TB_PREFIX . "vdata where owner = $uid order by capital DESC,pop DESC";
  685. $result = mysql_query($q, $this->connection);
  686. $array = $this->mysql_fetch_all($result);
  687. $newarray = array();
  688. for($i = 0; $i < count($array); $i++) {
  689. array_push($newarray, $array[$i]['wref']);
  690. }
  691. return $newarray;
  692. }
  693. function getVillagesID2($uid) {
  694. $q = "SELECT wref from " . TB_PREFIX . "vdata where owner = $uid order by capital DESC,pop DESC";
  695. $result = mysql_query($q, $this->connection);
  696. $array = $this->mysql_fetch_all($result);
  697. return $array;
  698. }
  699. function getVillage($vid) {
  700. $q = "SELECT * FROM " . TB_PREFIX . "vdata where wref = $vid";
  701. $result = mysql_query($q, $this->connection);
  702. return mysql_fetch_array($result);
  703. }
  704. public function getVillageBattleData($vid) {
  705. $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;
  706. $result = mysql_query($q, $this->connection);
  707. return mysql_fetch_array($result);
  708. }
  709. public function getPopulation($uid) {
  710. $q = "SELECT sum(pop) AS pop FROM ".TB_PREFIX."vdata WHERE owner=".$uid;
  711. $result = mysql_query($q, $this->connection);
  712. $dbarray = mysql_fetch_array($result);
  713. return $dbarray['pop'];
  714. }
  715. function getOasisV($vid) {
  716. $q = "SELECT * FROM " . TB_PREFIX . "odata where wref = $vid";
  717. $result = mysql_query($q, $this->connection);
  718. return mysql_fetch_array($result);
  719. }
  720. function getMInfo($id) {
  721. $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";
  722. $result = mysql_query($q, $this->connection);
  723. return mysql_fetch_array($result);
  724. }
  725. function getOMInfo($id) {
  726. $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";
  727. $result = mysql_query($q, $this->connection);
  728. return mysql_fetch_array($result);
  729. }
  730. function getOasis($vid) {
  731. $q = "SELECT * FROM " . TB_PREFIX . "odata where conqured = $vid";
  732. $result = mysql_query($q, $this->connection);
  733. return $this->mysql_fetch_all($result);
  734. }
  735. function getOasisInfo($wid) {
  736. $q = "SELECT * FROM " . TB_PREFIX . "odata where wref = $wid";
  737. $result = mysql_query($q, $this->connection);
  738. return mysql_fetch_assoc($result);
  739. }
  740. function getVillageField($ref, $field) {
  741. $q = "SELECT $field FROM " . TB_PREFIX . "vdata where wref = $ref";
  742. $result = mysql_query($q, $this->connection);
  743. if($result){
  744. $dbarray = mysql_fetch_array($result);
  745. return $dbarray[$field];
  746. }elseif($field=="name"){
  747. return "??";
  748. }else return 0;
  749. }
  750. function getOasisField($ref, $field) {
  751. $q = "SELECT $field FROM " . TB_PREFIX . "odata where wref = $ref";
  752. $result = mysql_query($q, $this->connection);
  753. $dbarray = mysql_fetch_array($result);
  754. return $dbarray[$field];
  755. }
  756. function setVillageField($ref, $field, $value) {
  757. $q = "UPDATE " . TB_PREFIX . "vdata set $field = '$value' where wref = $ref";
  758. return mysql_query($q, $this->connection);
  759. }
  760. function setVillageLevel($ref, $field, $value) {
  761. $q = "UPDATE " . TB_PREFIX . "fdata set " . $field . " = '" . $value . "' where vref = " . $ref . "";
  762. return mysql_query($q, $this->connection);
  763. }
  764. function getResourceLevel($vid) {
  765. $q = "SELECT * from " . TB_PREFIX . "fdata where vref = $vid";
  766. $result = mysql_query($q, $this->connection);
  767. return mysql_fetch_assoc($result);
  768. }
  769. function getAdminLog() {
  770. $q = "SELECT id,user,log,time from " . TB_PREFIX . "admin_log where id != 0 ORDER BY id ASC";
  771. $result = mysql_query($q, $this->connection);
  772. return $this->mysql_fetch_all($result);
  773. }
  774. //fix market log
  775. function getMarketLog() {
  776. $q = "SELECT id,wid,log from " . TB_PREFIX . "market_log where id != 0 ORDER BY id ASC";
  777. $result = mysql_query($q, $this->connection);
  778. return $this->mysql_fetch_all($result);
  779. }
  780. function getMarketLogVillage($village) {
  781. $q = "SELECT wref,owner,name from " . TB_PREFIX . "vdata where wref =$village ";
  782. $result = mysql_query($q, $this->connection);
  783. return $this->mysql_fetch_all($result);
  784. }
  785. function getMarketLogUsers($id_user) {
  786. $q = "SELECT id,username from " . TB_PREFIX . "users where id =$id_user ";
  787. $result = mysql_query($q, $this->connection);
  788. return $this->mysql_fetch_all($result);
  789. }
  790. //end fix
  791. function getCoor($wref) {
  792. if ($wref !=""){
  793. $q = "SELECT x,y FROM " . TB_PREFIX . "wdata where id = $wref";
  794. $result = mysql_query($q, $this->connection);
  795. return mysql_fetch_array($result);
  796. }
  797. }
  798. function CheckForum($id) {
  799. $q = "SELECT * from " . TB_PREFIX . "forum_cat where alliance = '$id'";
  800. $result = mysql_query($q, $this->connection);
  801. if(mysql_num_rows($result)) {
  802. return true;
  803. } else {
  804. return false;
  805. }
  806. }
  807. function CountCat($id) {
  808. $q = "SELECT count(id) FROM " . TB_PREFIX . "forum_topic where cat = '$id'";
  809. $result = mysql_query($q, $this->connection);
  810. $row = mysql_fetch_row($result);
  811. return $row[0];
  812. }
  813. function LastTopic($id) {
  814. $q = "SELECT * from " . TB_PREFIX . "forum_topic where cat = '$id' order by post_date";
  815. $result = mysql_query($q, $this->connection);
  816. return $this->mysql_fetch_all($result);
  817. }
  818. function CheckLastTopic($id) {
  819. $q = "SELECT * from " . TB_PREFIX . "forum_topic where cat = '$id'";
  820. $result = mysql_query($q, $this->connection);
  821. if(mysql_num_rows($result)) {
  822. return true;
  823. } else {
  824. return false;
  825. }
  826. }
  827. function CheckLastPost($id) {
  828. $q = "SELECT * from " . TB_PREFIX . "forum_post where topic = '$id'";
  829. $result = mysql_query($q, $this->connection);
  830. if(mysql_num_rows($result)) {
  831. return true;
  832. } else {
  833. return false;
  834. }
  835. }
  836. function LastPost($id) {
  837. $q = "SELECT * from " . TB_PREFIX . "forum_post where topic = '$id'";
  838. $result = mysql_query($q, $this->connection);
  839. return $this->mysql_fetch_all($result);
  840. }
  841. function CountTopic($id) {
  842. $q = "SELECT count(id) FROM " . TB_PREFIX . "forum_post where owner = '$id'";
  843. $result = mysql_query($q, $this->connection);
  844. $row = mysql_fetch_row($result);
  845. $qs = "SELECT count(id) FROM " . TB_PREFIX . "forum_topic where owner = '$id'";
  846. $results = mysql_query($qs, $this->connection);
  847. $rows = mysql_fetch_row($results);
  848. return $row[0] + $rows[0];
  849. }
  850. function CountPost($id) {
  851. $q = "SELECT count(id) FROM " . TB_PREFIX . "forum_post where topic = '$id'";
  852. $result = mysql_query($q, $this->connection);
  853. $row = mysql_fetch_row($result);
  854. return $row[0];
  855. }
  856. function ForumCat($id) {
  857. $q = "SELECT * from " . TB_PREFIX . "forum_cat where alliance = '$id' ORDER BY id";
  858. $result = mysql_query($q, $this->connection);
  859. return $this->mysql_fetch_all($result);
  860. }
  861. function ForumCatEdit($id) {
  862. $q = "SELECT * from " . TB_PREFIX . "forum_cat where id = '$id'";
  863. $result = mysql_query($q, $this->connection);
  864. return $this->mysql_fetch_all($result);
  865. }
  866. function ForumCatAlliance($id) {
  867. $q = "SELECT alliance from " . TB_PREFIX . "forum_cat where id = $id";
  868. $result = mysql_query($q, $this->connection);
  869. $dbarray = mysql_fetch_array($result);
  870. return $dbarray['alliance'];
  871. }
  872. function ForumCatName($id) {
  873. $q = "SELECT forum_name from " . TB_PREFIX . "forum_cat where id = $id";
  874. $result = mysql_query($q, $this->connection);
  875. $dbarray = mysql_fetch_array($result);
  876. return $dbarray['forum_name'];
  877. }
  878. function CheckCatTopic($id) {
  879. $q = "SELECT * from " . TB_PREFIX . "forum_topic where cat = '$id'";
  880. $result = mysql_query($q, $this->connection);
  881. if(mysql_num_rows($result)) {
  882. return true;
  883. } else {
  884. return false;
  885. }
  886. }
  887. function CheckResultEdit($alli) {
  888. $q = "SELECT * from " . TB_PREFIX . "forum_edit where alliance = '$alli'";
  889. $result = mysql_query($q, $this->connection);
  890. if(mysql_num_rows($result)) {
  891. return true;
  892. } else {
  893. return false;
  894. }
  895. }
  896. function CheckCloseTopic($id) {
  897. $q = "SELECT close from " . TB_PREFIX . "forum_topic where id = '$id'";
  898. $result = mysql_query($q, $this->connection);
  899. $dbarray = mysql_fetch_array($result);
  900. return $dbarray['close'];
  901. }
  902. function CheckEditRes($alli) {
  903. $q = "SELECT result from " . TB_PREFIX . "forum_edit where alliance = '$alli'";
  904. $result = mysql_query($q, $this->connection);
  905. $dbarray = mysql_fetch_array($result);
  906. return $dbarray['result'];
  907. }
  908. function CreatResultEdit($alli, $result) {
  909. $q = "INSERT into " . TB_PREFIX . "forum_edit values (0,'$alli','$result')";
  910. mysql_query($q, $this->connection);
  911. return mysql_insert_id($this->connection);
  912. }
  913. function UpdateResultEdit($alli, $result) {
  914. $date = time();
  915. $q = "UPDATE " . TB_PREFIX . "forum_edit set result = '$result' where alliance = '$alli'";
  916. return mysql_query($q, $this->connection);
  917. }
  918. function getVillageType2($wref) {
  919. $q = "SELECT * FROM " . TB_PREFIX . "wdata where id = $wref";
  920. $result = mysql_query($q, $this->connection);
  921. $dbarray = mysql_fetch_array($result);
  922. return $dbarray['oasistype'];
  923. }
  924. function getVillageType3($wref) {
  925. $q = "SELECT * FROM " . TB_PREFIX . "wdata where id = $wref";
  926. $result = mysql_query($q, $this->connection);
  927. $dbarray = mysql_fetch_array($result);
  928. return $dbarray;
  929. }
  930. function getFLData($id) {
  931. $q = "SELECT * FROM " . TB_PREFIX . "farmlist where id = $id";
  932. $result = mysql_query($q, $this->connection);
  933. return mysql_fetch_array($result);
  934. }
  935. function checkVilExist($wref) {
  936. $q = "SELECT * FROM " . TB_PREFIX . "vdata where wref = '$wref'";
  937. $result = mysql_query($q, $this->connection);
  938. if(mysql_num_rows($result)) {
  939. return true;
  940. } else {
  941. return false;
  942. }
  943. }
  944. function checkOasisExist($wref) {
  945. $q = "SELECT * FROM " . TB_PREFIX . "odata where wref = '$wref'";
  946. $result = mysql_query($q, $this->connection);
  947. if(mysql_num_rows($result)) {
  948. return true;
  949. } else {
  950. return false;
  951. }
  952. }
  953. function UpdateEditTopic($id, $title, $cat) {
  954. $q = "UPDATE " . TB_PREFIX . "forum_topic set title = '$title', cat = '$cat' where id = $id";
  955. return mysql_query($q, $this->connection);
  956. }
  957. function UpdateEditForum($id, $name, $des) {
  958. $q = "UPDATE " . TB_PREFIX . "forum_cat set forum_name = '$name', forum_des = '$des' where id = $id";
  959. return mysql_query($q, $this->connection);
  960. }
  961. function StickTopic($id, $mode) {
  962. $q = "UPDATE " . TB_PREFIX . "forum_topic set stick = '$mode' where id = '$id'";
  963. return mysql_query($q, $this->connection);
  964. }
  965. function ForumCatTopic($id) {
  966. $q = "SELECT * from " . TB_PREFIX . "forum_topic where cat = '$id' AND stick = '' ORDER BY post_date desc";
  967. $result = mysql_query($q, $this->connection);
  968. return $this->mysql_fetch_all($result);
  969. }
  970. function ForumCatTopicStick($id) {
  971. $q = "SELECT * from " . TB_PREFIX . "forum_topic where cat = '$id' AND stick = '1' ORDER BY post_date desc";
  972. $result = mysql_query($q, $this->connection);
  973. return $this->mysql_fetch_all($result);
  974. }
  975. function ShowTopic($id) {
  976. $q = "SELECT * from " . TB_PREFIX . "forum_topic where id = '$id'";
  977. $result = mysql_query($q, $this->connection);
  978. return $this->mysql_fetch_all($result);
  979. }
  980. function ShowPost($id) {
  981. $q = "SELECT * from " . TB_PREFIX . "forum_post where topic = '$id'";
  982. $result = mysql_query($q, $this->connection);
  983. return $this->mysql_fetch_all($result);
  984. }
  985. function ShowPostEdit($id) {
  986. $q = "SELECT * from " . TB_PREFIX . "forum_post where id = '$id'";
  987. $result = mysql_query($q, $this->connection);
  988. return $this->mysql_fetch_all($result);
  989. }
  990. function CreatForum($owner, $alli, $name, $des, $area) {
  991. $q = "INSERT into " . TB_PREFIX . "forum_cat values (0,'$owner','$alli','$name','$des','$area')";
  992. mysql_query($q, $this->connection);
  993. return mysql_insert_id($this->connection);
  994. }
  995. function CreatTopic($title, $post, $cat, $owner, $alli, $ends, $alliance, $player, $coor, $report) {
  996. $date = time();
  997. $q = "INSERT into " . TB_PREFIX . "forum_topic values (0,'$title','$post','$date','$date','$cat','$owner','$alli','$ends','','','$alliance','$player','$coor','$report')";
  998. mysql_query($q, $this->connection);
  999. return mysql_insert_id($this->connection);
  1000. }
  1001. /*************************
  1002. FORUM SUREY
  1003. *************************/
  1004. function createSurvey($topic, $title, $option1, $option2, $option3, $option4, $option5, $option6, $option7, $option8, $ends) {
  1005. $q = "INSERT into " . TB_PREFIX . "forum_survey (topic,title,option1,option2,option3,option4,option5,option6,option7,option8,ends) values ('$topic','$title','$option1','$option2','$option3','$option4','$option5','$option6','$option7','$option8','$ends')";
  1006. return mysql_query($q, $this->connection);
  1007. }
  1008. function getSurvey($topic) {
  1009. $q = "SELECT * FROM " . TB_PREFIX . "forum_survey where topic = $topic";
  1010. $result = mysql_query($q, $this->connection);
  1011. return mysql_fetch_array($result);
  1012. }
  1013. function checkSurvey($topic) {
  1014. $q = "SELECT * FROM " . TB_PREFIX . "forum_survey where topic = $topic";
  1015. $result = mysql_query($q, $this->connection);
  1016. if(mysql_num_rows($result)) {
  1017. return true;
  1018. } else {
  1019. return false;
  1020. }
  1021. }
  1022. function Vote($topic, $num, $text) {
  1023. $q = "UPDATE " . TB_PREFIX . "forum_survey set vote".$num." = vote".$num." + 1, voted = '$text' where topic = ".$topic."";
  1024. return mysql_query($q, $this->connection);
  1025. }
  1026. function checkVote($topic, $uid) {
  1027. $q = "SELECT * FROM " . TB_PREFIX . "forum_survey where topic = $topic";
  1028. $result = mysql_query($q, $this->connection);
  1029. $array = mysql_fetch_array($result);
  1030. $text = $array['voted'];
  1031. if(preg_match('/,'.$uid.',/',$text)) {
  1032. return true;
  1033. } else {
  1034. return false;
  1035. }
  1036. }
  1037. function getVoteSum($topic) {
  1038. $q = "SELECT * FROM " . TB_PREFIX . "forum_survey where topic = $topic";
  1039. $result = mysql_query($q, $this->connection);
  1040. $array = mysql_fetch_array($result);
  1041. $sum = 0;
  1042. for($i=1;$i<=8;$i++){
  1043. $sum += $array['vote'.$i];
  1044. }
  1045. return $sum;
  1046. }
  1047. /*************************
  1048. FORUM SUREY
  1049. *************************/
  1050. function CreatPost($post, $tids, $owner, $alliance, $player, $coor, $report) {
  1051. $date = time();
  1052. $q = "INSERT into " . TB_PREFIX . "forum_post values (0,'$post','$tids','$owner','$date','$alliance','$player','$coor','$report')";
  1053. mysql_query($q, $this->connection);
  1054. return mysql_insert_id($this->connection);
  1055. }
  1056. function UpdatePostDate($id) {
  1057. $date = time();
  1058. $q = "UPDATE " . TB_PREFIX . "forum_topic set post_date = '$date' where id = $id";
  1059. return mysql_query($q, $this->connection);
  1060. }
  1061. function EditUpdateTopic($id, $post, $alliance, $player, $coor, $report) {
  1062. $q = "UPDATE " . TB_PREFIX . "forum_topic set post = '$post', alliance0 = '$alliance', player0 = '$player', coor0 = '$coor', report0 = '$report' where id = $id";
  1063. return mysql_query($q, $this->connection);
  1064. }
  1065. function EditUpdatePost($id, $post, $alliance, $player, $coor, $report) {
  1066. $q = "UPDATE " . TB_PREFIX . "forum_post set post = '$post', alliance0 = '$alliance', player0 = '$player', coor0 = '$coor', report0 = '$report' where id = $id";
  1067. return mysql_query($q, $this->connection);
  1068. }
  1069. function LockTopic($id, $mode) {
  1070. $q = "UPDATE " . TB_PREFIX . "forum_topic set close = '$mode' where id = '$id'";
  1071. return mysql_query($q, $this->connection);
  1072. }
  1073. function DeleteCat($id) {
  1074. $qs = "DELETE from " . TB_PREFIX . "forum_cat where id = '$id'";
  1075. $q = "DELETE from " . TB_PREFIX . "forum_topic where cat = '$id'";
  1076. $q2="SELECT id from ".TB_PREFIX."forum_topic where cat ='$id'";
  1077. $result = mysql_query($q2, $this->connection);
  1078. if (!empty($result)) {
  1079. $array=$this->mysql_fetch_all($result);
  1080. foreach($array as $ss) {
  1081. $this->DeleteSurvey($ss['id']);
  1082. }
  1083. }
  1084. mysql_query($qs, $this->connection);
  1085. return mysql_query($q, $this->connection);
  1086. }
  1087. function DeleteSurvey($id) {
  1088. $qs = "DELETE from " . TB_PREFIX . "forum_survey where topic = '$id'";
  1089. return mysql_query($qs, $this->connection);
  1090. }
  1091. function DeleteTopic($id) {
  1092. $qs = "DELETE from " . TB_PREFIX . "forum_topic where id = '$id'";
  1093. // $q = "DELETE from ".TB_PREFIX."forum_post where topic = '$id'";//
  1094. return mysql_query($qs, $this->connection); //
  1095. // mysql_query($q,$this->connection);
  1096. }
  1097. function DeletePost($id) {
  1098. $q = "DELETE from " . TB_PREFIX . "forum_post where id = '$id'";
  1099. return mysql_query($q, $this->connection);
  1100. }
  1101. function getAllianceName($id) {
  1102. $q = "SELECT tag from " . TB_PREFIX . "alidata where id = $id";
  1103. $result = mysql_query($q, $this->connection);
  1104. $dbarray = mysql_fetch_array($result);
  1105. return $dbarray['tag'];
  1106. }
  1107. function getAlliancePermission($ref, $field, $mode) {
  1108. if(!$mode) {
  1109. $q = "SELECT $field FROM " . TB_PREFIX . "ali_permission where uid = '$ref'";
  1110. } else {
  1111. $q = "SELECT $field FROM " . TB_PREFIX . "ali_permission where username = '$ref'";
  1112. }
  1113. $result = mysql_query($q, $this->connection) or die(mysql_error());
  1114. $dbarray = mysql_fetch_array($result);
  1115. return $dbarray[$field];
  1116. }
  1117. function getAlliance($id) {
  1118. $q = "SELECT * from " . TB_PREFIX . "alidata where id = $id";
  1119. $result = mysql_query($q, $this->connection);
  1120. return mysql_fetch_assoc($result);
  1121. }
  1122. function setAlliName($aid, $name, $tag) {
  1123. $q = "UPDATE " . TB_PREFIX . "alidata set name = '$name', tag = '$tag' where id = $aid";
  1124. return mysql_query($q, $this->connection);
  1125. }
  1126. function isAllianceOwner($id) {
  1127. $q = "SELECT * from " . TB_PREFIX . "alidata where leader = '$id'";
  1128. $result = mysql_query($q, $this->connection);
  1129. if(mysql_num_rows($result)) {
  1130. return true;
  1131. } else {
  1132. return false;
  1133. }
  1134. }
  1135. function aExist($ref, $type) {
  1136. $q = "SELECT $type FROM " . TB_PREFIX . "alidata where $type = '$ref'";
  1137. $result = mysql_query($q, $this->connection);
  1138. if(mysql_num_rows($result)) {
  1139. return true;
  1140. } else {
  1141. return false;
  1142. }
  1143. }
  1144. function modifyPoints($aid, $points, $amt) {
  1145. $q = "UPDATE " . TB_PREFIX . "users set $points = $points + $amt where id = $aid";
  1146. return mysql_query($q, $this->connection);
  1147. }
  1148. function modifyPointsAlly($aid, $points, $amt) {
  1149. $q = "UPDATE " . TB_PREFIX . "alidata set $points = $points + $amt where id = $aid";
  1150. return mysql_query($q, $this->connection);
  1151. }
  1152. /*****************************************
  1153. Function to create an alliance
  1154. References:
  1155. *****************************************/
  1156. function createAlliance($tag, $name, $uid, $max) {
  1157. $q = "INSERT into " . TB_PREFIX . "alidata values (0,'$name','$tag',$uid,0,0,0,'','',$max,'','','','','','','','','')";
  1158. mysql_query($q, $this->connection);
  1159. return mysql_insert_id($this->connection);
  1160. }
  1161. function procAllyPop($aid) {
  1162. $ally = $this->getAlliance($aid);
  1163. $memberlist = $this->getAllMember($ally['id']);
  1164. $oldrank = 0;
  1165. foreach($memberlist as $member) {
  1166. $oldrank += $this->getVSumField($member['id'],"pop");
  1167. }
  1168. if($ally['oldrank'] != $oldrank){
  1169. if($ally['oldrank'] < $oldrank) {
  1170. $totalpoints = $oldrank - $ally['oldrank'];
  1171. $this->addclimberrankpopAlly($ally['id'], $totalpoints);
  1172. $this->updateoldrankAlly($ally['id'], $oldrank);
  1173. } else
  1174. if($ally['oldrank'] > $oldrank) {
  1175. $totalpoints = $ally['oldrank'] - $oldrank;
  1176. $this->removeclimberrankpopAlly($ally['id'], $totalpoints);
  1177. $this->updateoldrankAlly($ally['id'], $oldrank);
  1178. }
  1179. }
  1180. }
  1181. /*****************************************
  1182. Function to insert an alliance new
  1183. References:
  1184. *****************************************/
  1185. function insertAlliNotice($aid, $notice) {
  1186. $time = time();
  1187. $q = "INSERT into " . TB_PREFIX . "ali_log values (0,'$aid','$notice',$time)";
  1188. mysql_query($q, $this->connection);
  1189. return mysql_insert_id($this->connection);
  1190. }
  1191. /*****************************************
  1192. Function to delete alliance if empty
  1193. References:
  1194. *****************************************/
  1195. function deleteAlliance($aid) {
  1196. $result = mysql_query("SELECT * FROM " . TB_PREFIX . "users where alliance = $aid");
  1197. $num_rows = mysql_num_rows($result);
  1198. if($num_rows == 0) {
  1199. $q = "DELETE FROM " . TB_PREFIX . "alidata WHERE id = $aid";
  1200. }
  1201. mysql_query($q, $this->connection);
  1202. return mysql_insert_id($this->connection);
  1203. }
  1204. /*****************************************
  1205. Function to read all alliance news
  1206. References:
  1207. *****************************************/
  1208. function readAlliNotice($aid) {
  1209. $q = "SELECT * from " . TB_PREFIX . "ali_log where aid = $aid ORDER BY date DESC";
  1210. $result = mysql_query($q, $this->connection);
  1211. return $this->mysql_fetch_all($result);
  1212. }
  1213. /*****************************************
  1214. Function to create alliance permissions
  1215. References: ID, notice, description
  1216. *****************************************/
  1217. function createAlliPermissions($uid, $aid, $rank, $opt1, $opt2, $opt3, $opt4, $opt5, $opt6, $opt7, $opt8) {
  1218. $q = "INSERT into " . TB_PREFIX . "ali_permission values(0,'$uid','$aid','$rank','$opt1','$opt2','$opt3','$opt4','$opt5','$opt6','$opt7','$opt8')";
  1219. mysql_query($q, $this->connection);
  1220. return mysql_insert_id($this->connection);
  1221. }
  1222. /*****************************************
  1223. Function to update alliance permissions
  1224. References:
  1225. *****************************************/
  1226. function deleteAlliPermissions($uid) {
  1227. $q = "DELETE from " . TB_PREFIX . "ali_permission where uid = '$uid'";
  1228. return mysql_query($q, $this->connection);
  1229. }
  1230. /*****************************************
  1231. Function to update alliance permissions
  1232. References:
  1233. *****************************************/
  1234. function updateAlliPermissions($uid, $aid, $rank, $opt1, $opt2, $opt3, $opt4, $opt5, $opt6, $opt7) {
  1235. $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";
  1236. return mysql_query($q, $this->connection);
  1237. }
  1238. /*****************************************
  1239. Function to read alliance permissions
  1240. References: ID, notice, description
  1241. *****************************************/
  1242. function getAlliPermissions($uid, $aid) {
  1243. $q = "SELECT * FROM " . TB_PREFIX . "ali_permission where uid = $uid && alliance = $aid";
  1244. $result = mysql_query($q, $this->connection);
  1245. return mysql_fetch_assoc($result);
  1246. }
  1247. /*****************************************
  1248. Function to update an alliance description and notice
  1249. References: ID, notice, description
  1250. *****************************************/
  1251. function submitAlliProfile($aid, $notice, $desc) {
  1252. $q = "UPDATE " . TB_PREFIX . "alidata SET `notice` = '$notice', `desc` = '$desc' where id = $aid";
  1253. return mysql_query($q, $this->connection);
  1254. }
  1255. function diplomacyInviteAdd($alli1, $alli2, $type) {
  1256. $q = "INSERT INTO " . TB_PREFIX . "diplomacy (alli1,alli2,type,accepted) VALUES ($alli1,$alli2," . (int)intval($type) . ",0)";
  1257. return mysql_query($q, $this->connection);
  1258. }
  1259. function diplomacyOwnOffers($session_alliance) {
  1260. $q = "SELECT * FROM " . TB_PREFIX . "diplomacy WHERE alli1 = $session_alliance AND accepted = 0";
  1261. $result = mysql_query($q, $this->connection);
  1262. return $this->mysql_fetch_all($result);
  1263. }
  1264. function getAllianceID($name) {
  1265. $q = "SELECT id FROM " . TB_PREFIX . "alidata WHERE tag ='" . $this->RemoveXSS($name) . "'";
  1266. $result = mysql_query($q, $this->connection);
  1267. $dbarray = mysql_fetch_array($result);
  1268. return $dbarray['id'];
  1269. }
  1270. function getDiplomacy($aid) {
  1271. $q = "SELECT * FROM " . TB_PREFIX . "diplomacy WHERE id = $aid";
  1272. $result = mysql_query($q, $this->connection);
  1273. return $this->mysql_fetch_all($result);
  1274. }
  1275. function diplomacyCancelOffer($id) {
  1276. $q = "DELETE FROM " . TB_PREFIX . "diplomacy WHERE id = $id";
  1277. return mysql_query($q, $this->connection);
  1278. }
  1279. function diplomacyInviteAccept($id, $session_alliance) {
  1280. $q = "UPDATE " . TB_PREFIX . "diplomacy SET accepted = 1 WHERE id = $id AND alli2 = $session_alliance";
  1281. return mysql_query($q, $this->connection);
  1282. }
  1283. function diplomacyInviteDenied($id, $session_alliance) {
  1284. $q = "DELETE FROM " . TB_PREFIX . "diplomacy WHERE id = $id AND alli2 = $session_alliance";
  1285. return mysql_query($q, $this->connection);
  1286. }
  1287. function diplomacyInviteCheck($session_alliance) {
  1288. $q = "SELECT * FROM " . TB_PREFIX . "diplomacy WHERE alli2 = $session_alliance AND accepted = 0";
  1289. $result = mysql_query($q, $this->connection);
  1290. return $this->mysql_fetch_all($result);
  1291. }
  1292. function diplomacyInviteCheck2($ally1, $ally2) {
  1293. $q = "SELECT * FROM " . TB_PREFIX . "diplomacy WHERE alli1 = $ally1 AND alli2 = $ally2 accepted = 0";
  1294. $result = mysql_query($q, $this->connection);
  1295. return $this->mysql_fetch_all($result);
  1296. }
  1297. function getAllianceDipProfile($aid, $type){
  1298. $q = "SELECT * FROM ".TB_PREFIX."diplomacy WHERE alli1 = '$aid' AND type = '$type' AND accepted = '1' OR alli2 = '$aid' AND type = '$type' AND accepted = '1'";
  1299. $array = $this->query_return($q);
  1300. foreach($array as $row){
  1301. if($row['alli1'] == $aid){
  1302. $alliance = $this->getAlliance($row['alli2']);
  1303. }elseif($row['alli2'] == $aid){
  1304. $alliance = $this->getAlliance($row['alli1']);
  1305. }
  1306. $text .= "";
  1307. $text .= "<a href=allianz.php?aid=".$alliance['id'].">".$alliance['tag']."</a><br> ";
  1308. }
  1309. if(strlen($text) == 0){
  1310. $text = "-<br>";
  1311. }
  1312. return $text;
  1313. }
  1314. function getAllianceWar($aid){
  1315. $q = "SELECT * FROM ".TB_PREFIX."diplomacy WHERE alli1 = '$aid' AND type = '3' OR alli2 = '$aid' AND type = '3' AND accepted = '1'";
  1316. $array = $this->query_return($q);
  1317. foreach($array as $row){
  1318. if($row['alli1'] == $aid){
  1319. $alliance = $this->getAlliance($row['alli2']);
  1320. }elseif($row['alli2'] == $aid){
  1321. $alliance = $this->getAlliance($row['alli1']);
  1322. }
  1323. $text .= "";
  1324. $text .= "<a href=allianz.php?aid=".$alliance['id'].">".$alliance['tag']."</a><br> ";
  1325. }
  1326. if(strlen($text) == 0){
  1327. $text = "-<br>";
  1328. }
  1329. return $text;
  1330. }
  1331. function getAllianceAlly($aid, $type){
  1332. $q = "SELECT * FROM ".TB_PREFIX."diplomacy WHERE (alli1 = '$aid' or alli2 = '$aid') AND (type = '$type' AND accepted = '1')";
  1333. $result = mysql_query($q, $this->connection);
  1334. return $this->mysql_fetch_all($result);
  1335. }
  1336. function getAllianceWar2($aid){
  1337. $q = "SELECT * FROM ".TB_PREFIX."diplomacy WHERE alli1 = '$aid' AND type = '3' OR alli2 = '$aid' AND type = '3' AND accepted = '1'";
  1338. $result = mysql_query($q, $this->connection);
  1339. return $this->mysql_fetch_all($result);
  1340. }
  1341. function diplomacyExistingRelationships($session_alliance) {
  1342. $q = "SELECT * FROM " . TB_PREFIX . "diplomacy WHERE alli2 = $session_alliance AND accepted = 1";
  1343. $result = mysql_query($q, $this->connection);
  1344. return $this->mysql_fetch_all($result);
  1345. }
  1346. function diplomacyExistingRelationships2($session_alliance) {
  1347. $q = "SELECT * FROM " . TB_PREFIX . "diplomacy WHERE alli1 = $session_alliance AND accepted = 1";
  1348. $result = mysql_query($q, $this->connection);
  1349. return $this->mysql_fetch_all($result);
  1350. }
  1351. function diplomacyCancelExistingRelationship($id, $session_alliance) {
  1352. $q = "DELETE FROM " . TB_PREFIX . "diplomacy WHERE id = $id AND alli2 = $session_alliance OR id = $id AND alli1 = $session_alliance";
  1353. return mysql_query($q, $this->connection);
  1354. }
  1355. function checkDiplomacyInviteAccept($aid, $type) {
  1356. $q = "SELECT * FROM " . TB_PREFIX . "diplomacy WHERE alli1 = $aid AND type = $type AND accepted = 1 OR alli2 = $aid AND type = $type AND accepted = 1";
  1357. $result = mysql_query($q, $this->connection);
  1358. if($type == 3){
  1359. return true;
  1360. }else{
  1361. if(mysql_num_rows($result) < 4) {
  1362. return true;
  1363. } else {
  1364. return false;
  1365. }
  1366. }
  1367. }
  1368. function setAlliForumLink($aid, $link) {
  1369. $q = "UPDATE " . TB_PREFIX . "alidata SET `forumlink` = '$link' WHERE id = $aid";
  1370. return mysql_query($q, $this->connection);
  1371. }
  1372. function getUserAlliance($id) {
  1373. $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";
  1374. $result = mysql_query($q, $this->connection);
  1375. $dbarray = mysql_fetch_array($result);
  1376. if($dbarray['tag'] == "") {
  1377. return "-";
  1378. } else {
  1379. return $dbarray['tag'];
  1380. }
  1381. }
  1382. /////////////ADDED BY BRAINIAC - THANK YOU
  1383. function modifyResource($vid, $wood, $clay, $iron, $crop, $mode) {
  1384. $q="SELECT wood,clay,iron,crop,maxstore,maxcrop from " . TB_PREFIX . "vdata where wref = ".$vid."";
  1385. $result = mysql_query($q, $this->connection);
  1386. $checkres= $this->mysql_fetch_all($result);
  1387. if(!$mode){
  1388. $nwood=$checkres[0]['wood']-$wood;
  1389. $nclay=$checkres[0]['clay']-$clay;
  1390. $niron=$checkres[0]['iron']-$iron;
  1391. $ncrop=$checkres[0]['crop']-$crop;
  1392. if($nwood<0 or $nclay<0 or $niron<0 or $ncrop<0){$shit=true;}
  1393. $dwood=($nwood<0)?0:$nwood;
  1394. $dclay=($nclay<0)?0:$nclay;
  1395. $diron=($niron<0)?0:$niron;
  1396. $dcrop=($ncrop<0)?0:$ncrop;
  1397. }else{
  1398. $nwood=$checkres[0]['wood']+$wood;
  1399. $nclay=$checkres[0]['clay']+$clay;
  1400. $niron=$checkres[0]['iron']+$iron;
  1401. $ncrop=$checkres[0]['crop']+$crop;
  1402. $dwood=($nwood>$checkres[0]['maxstore'])?$checkres[0]['maxstore']:$nwood;
  1403. $dclay=($nclay>$checkres[0]['maxstore'])?$checkres[0]['maxstore']:$nclay;
  1404. $diron=($niron>$checkres[0]['maxstore'])?$checkres[0]['maxstore']:$niron;
  1405. $dcrop=($ncrop>$checkres[0]['maxcrop'])?$checkres[0]['maxcrop']:$ncrop;
  1406. }
  1407. if(!$shit){
  1408. $q = "UPDATE " . TB_PREFIX . "vdata set wood = $dwood, clay = $dclay, iron = $diron, crop = $dcrop where wref = ".$vid;
  1409. return mysql_query($q, $this->connection); }else{return false;}
  1410. }
  1411. function modifyOasisResource($vid, $wood, $clay, $iron, $crop, $mode) {
  1412. $q="SELECT wood,clay,iron,crop,maxstore,maxcrop from " . TB_PREFIX . "odata where wref = ".$vid."";
  1413. $result = mysql_query($q, $this->connection);
  1414. $checkres= $this->mysql_fetch_all($result);
  1415. if(!$mode){
  1416. $nwood=$checkres[0]['wood']-$wood;
  1417. $nclay=$checkres[0]['clay']-$clay;
  1418. $niron=$checkres[0]['iron']-$iron;
  1419. $ncrop=$checkres[0]['crop']-$crop;
  1420. if($nwood<0 or $nclay<0 or $niron<0 or $ncrop<0){$shit=true;}
  1421. $dwood=($nwood<0)?0:$nwood;
  1422. $dclay=($nclay<0)?0:$nclay;
  1423. $diron=($niron<0)?0:$niron;
  1424. $dcrop=($ncrop<0)?0:$ncrop;
  1425. }else{
  1426. $nwood=$checkres[0]['wood']+$wood;
  1427. $nclay=$checkres[0]['clay']+$clay;
  1428. $niron=$checkres[0]['iron']+$iron;
  1429. $ncrop=$checkres[0]['crop']+$crop;
  1430. $dwood=($nwood>$checkres[0]['maxstore'])?$checkres[0]['maxstore']:$nwood;
  1431. $dclay=($nclay>$checkres[0]['maxstore'])?$checkres[0]['maxstore']:$nclay;
  1432. $diron=($niron>$checkres[0]['maxstore'])?$checkres[0]['maxstore']:$niron;
  1433. $dcrop=($ncrop>$checkres[0]['maxcrop'])?$checkres[0]['maxcrop']:$ncrop;
  1434. }
  1435. if(!$shit){
  1436. $q = "UPDATE " . TB_PREFIX . "odata set wood = $dwood, clay = $dclay, iron = $diron, crop = $dcrop where wref = ".$vid;
  1437. return mysql_query($q, $this->connection); }else{return false;}
  1438. }
  1439. function getFieldLevel($vid, $field) {
  1440. $q = "SELECT f" . $field . " from " . TB_PREFIX . "fdata where vref = $vid";
  1441. $result = mysql_query($q, $this->connection);
  1442. return mysql_result($result, 0);
  1443. }
  1444. function getFieldType($vid, $field) {
  1445. $q = "SELECT f" . $field . "t from " . TB_PREFIX . "fdata where vref = $vid";
  1446. $result = mysql_query($q, $this->connection);
  1447. return mysql_result($result, 0);
  1448. }
  1449. function getFieldDistance($wid) {
  1450. $q = "SELECT * FROM " . TB_PREFIX . "vdata where owner > 4 and wref != $wid";
  1451. $array = $this->query_return($q);
  1452. $coor = $this->getCoor($wid);
  1453. $x1 = intval($coor['x']);
  1454. $y1 = intval($coor['y']);
  1455. $prevdist = 0;
  1456. $q2 = "SELECT * FROM " . TB_PREFIX . "vdata where owner = 4";
  1457. $array2 = mysql_fetch_array(mysql_query($q2));
  1458. $vill = $array2['wref'];
  1459. if(mysql_num_rows(mysql_query($q)) > 0){
  1460. foreach($array as $village){
  1461. $coor2 = $this->getCoor($village['wref']);
  1462. $max = 2 * WORLD_MAX + 1;
  1463. $x2 = intval($coor2['x']);
  1464. $y2 = intval($coor2['y']);
  1465. $distanceX = min(abs($x2 - $x1), abs($max - abs($x2 - $x1)));
  1466. $distanceY = min(abs($y2 - $y1), abs($max - abs($y2 - $y1)));
  1467. $dist = sqrt(pow($distanceX, 2) + pow($distanceY, 2));
  1468. if($dist < $prevdist or $prevdist == 0){
  1469. $prevdist = $dist;
  1470. $vill = $village['wref'];
  1471. }
  1472. }
  1473. }
  1474. return $vill;
  1475. }
  1476. function getVSumField($uid, $field) {
  1477. if($field != "cp"){
  1478. $q = "SELECT sum(" . $field . ") FROM " . TB_PREFIX . "vdata where owner = $uid";
  1479. }else{
  1480. $q = "SELECT sum(" . $field . ") FROM " . TB_PREFIX . "vdata where owner = $uid and natar = 0";
  1481. }
  1482. $result = mysql_query($q, $this->connection);
  1483. $row = mysql_fetch_row($result);
  1484. return $row[0];
  1485. }
  1486. function updateVillage($vid) {
  1487. $time = time();
  1488. $q = "UPDATE " . TB_PREFIX . "vdata set lastupdate = $time where wref = $vid";
  1489. return mysql_query($q, $this->connection);
  1490. }
  1491. function updateOasis($vid) {
  1492. $time = time();
  1493. $q = "UPDATE " . TB_PREFIX . "odata set lastupdated = $time where wref = $vid";
  1494. return mysql_query($q, $this->connection);
  1495. }
  1496. function updateOasis2($vid, $time) {
  1497. $time = time();
  1498. $time2 = NATURE_REGTIME;
  1499. $q = "UPDATE " . TB_PREFIX . "odata set lastupdated2 = $time + $time2 where wref = $vid";
  1500. return mysql_query($q, $this->connection);
  1501. }
  1502. function setVillageName($vid, $name) {
  1503. if(!empty($name))
  1504. {
  1505. $q = "UPDATE " . TB_PREFIX . "vdata set name = '$name' where wref = $vid";
  1506. return mysql_query($q, $this->connection);
  1507. }
  1508. }
  1509. function modifyPop($vid, $pop, $mode) {
  1510. if(!$mode) {
  1511. $q = "UPDATE " . TB_PREFIX . "vdata set pop = pop + $pop where wref = $vid";
  1512. } else {
  1513. $q = "UPDATE " . TB_PREFIX . "vdata set pop = pop - $pop where wref = $vid";
  1514. }
  1515. return mysql_query($q, $this->connection);
  1516. }
  1517. function addCP($ref, $cp) {
  1518. $q = "UPDATE " . TB_PREFIX . "vdata set cp = cp + $cp where wref = $ref";
  1519. return mysql_query($q, $this->connection);
  1520. }
  1521. function addCel($ref, $cel, $type) {
  1522. $q = "UPDATE " . TB_PREFIX . "vdata set celebration = $cel, type= $type where wref = $ref";
  1523. return mysql_query($q, $this->connection);
  1524. }
  1525. function getCel() {
  1526. $time = time();
  1527. $q = "SELECT * FROM " . TB_PREFIX . "vdata where celebration < $time AND celebration != 0";
  1528. $result = mysql_query($q, $this->connection);
  1529. return $this->mysql_fetch_all($result);
  1530. }
  1531. function clearCel($ref) {
  1532. $q = "UPDATE " . TB_PREFIX . "vdata set celebration = 0, type = 0 where wref = $ref";
  1533. return mysql_query($q, $this->connection);
  1534. }
  1535. function setCelCp($user, $cp) {
  1536. $q = "UPDATE " . TB_PREFIX . "users set cp = cp + $cp where id = $user";
  1537. return mysql_query($q, $this->connection);
  1538. }
  1539. function clearExpansionSlot($id) {
  1540. for($i = 1; $i <= 3; $i++) {
  1541. $q = "UPDATE " . TB_PREFIX . "vdata SET exp" . $i . "=0 WHERE exp" . $i . "=" . $id;
  1542. mysql_query($q, $this->connection);
  1543. }
  1544. }
  1545. function getInvitation($uid) {
  1546. $q = "SELECT * FROM " . TB_PREFIX . "ali_invite where uid = $uid";
  1547. $result = mysql_query($q, $this->connection);
  1548. return $this->mysql_fetch_all($result);
  1549. }
  1550. function getInvitation2($uid, $aid) {
  1551. $q = "SELECT * FROM " . TB_PREFIX . "ali_invite where uid = $uid and alliance = $aid";
  1552. $result = mysql_query($q, $this->connection);
  1553. return $this->mysql_fetch_all($result);
  1554. }
  1555. function getAliInvitations($aid) {
  1556. $q = "SELECT * FROM " . TB_PREFIX . "ali_invite where alliance = $aid && accept = 0";
  1557. $result = mysql_query($q, $this->connection);
  1558. return $this->mysql_fetch_all($result);
  1559. }
  1560. function sendInvitation($uid, $alli, $sender) {
  1561. $time = time();
  1562. $q = "INSERT INTO " . TB_PREFIX . "ali_invite values (0,$uid,$alli,$sender,$time,0)";
  1563. return mysql_query($q, $this->connection) or die(mysql_error());
  1564. }
  1565. function removeInvitation($id) {
  1566. $q = "DELETE FROM " . TB_PREFIX . "ali_invite where id = $id";
  1567. return mysql_query($q, $this->connection);
  1568. }
  1569. function sendMessage($client, $owner, $topic, $message, $send, $alliance, $player, $coor, $report) {
  1570. $time = time();
  1571. $q = "INSERT INTO " . TB_PREFIX . "mdata values (0,$client,$owner,'$topic',\"$message\",0,0,$send,$time,0,0,$alliance,$player,$coor,$report)";
  1572. return mysql_query($q, $this->connection);
  1573. }
  1574. function setArchived($id) {
  1575. $q = "UPDATE " . TB_PREFIX . "mdata set archived = 1 where id = $id";
  1576. return mysql_query($q, $this->connection);
  1577. }
  1578. function setNorm($id) {
  1579. $q = "UPDATE " . TB_PREFIX . "mdata set archived = 0 where id = $id";
  1580. return mysql_query($q, $this->connection);
  1581. }
  1582. /***************************
  1583. Function to get messages
  1584. Mode 1: Get inbox
  1585. Mode 2: Get sent
  1586. Mode 3: Get message
  1587. Mode 4: Set viewed
  1588. Mode 5: Remove message
  1589. Mode 6: Retrieve archive
  1590. References: User ID/Message ID, Mode
  1591. ***************************/
  1592. function getMessage($id, $mode) {
  1593. global $session;
  1594. switch($mode) {
  1595. case 1:
  1596. $q = "SELECT * FROM " . TB_PREFIX . "mdata WHERE target = $id and send = 0 and archived = 0 ORDER BY time DESC";
  1597. break;
  1598. case 2:
  1599. $q = "SELECT * FROM " . TB_PREFIX . "mdata WHERE owner = $id ORDER BY time DESC";
  1600. break;
  1601. case 3:
  1602. $q = "SELECT * FROM " . TB_PREFIX . "mdata where id = $id";
  1603. break;
  1604. case 4:
  1605. $q = "UPDATE " . TB_PREFIX . "mdata set viewed = 1 where id = $id AND target = $session->uid";
  1606. break;
  1607. case 5:
  1608. $q = "UPDATE " . TB_PREFIX . "mdata set deltarget = 1,viewed = 1 where id = $id";
  1609. break;
  1610. case 6:
  1611. $q = "SELECT * FROM " . TB_PREFIX . "mdata where target = $id and send = 0 and archived = 1";
  1612. break;
  1613. case 7:
  1614. $q = "UPDATE " . TB_PREFIX . "mdata set delowner = 1 where id = $id";
  1615. break;
  1616. case 8:
  1617. $q = "UPDATE " . TB_PREFIX . "mdata set deltarget = 1,delowner = 1,viewed = 1 where id = $id";
  1618. break;
  1619. case 9:
  1620. $q = "SELECT * FROM " . TB_PREFIX . "mdata WHERE target = $id and send = 0 and archived = 0 and deltarget = 0 ORDER BY time DESC";
  1621. break;
  1622. case 10:
  1623. $q = "SELECT * FROM " . TB_PREFIX . "mdata WHERE owner = $id and delowner = 0 ORDER BY time DESC";
  1624. break;
  1625. case 11:
  1626. $q = "SELECT * FROM " . TB_PREFIX . "mdata where target = $id and send = 0 and archived = 1 and deltarget = 0";
  1627. break;
  1628. }
  1629. if($mode <= 3 || $mode == 6 || $mode > 8) {
  1630. $result = mysql_query($q, $this->connection);
  1631. return $this->mysql_fetch_all($result);
  1632. } else {
  1633. return mysql_query($q, $this->connection);
  1634. }
  1635. }
  1636. function getDelSent($uid) {
  1637. $q = "SELECT * FROM " . TB_PREFIX . "mdata WHERE owner = $uid and delowner = 1 ORDER BY time DESC";
  1638. $result = mysql_query($q, $this->connection);
  1639. return $this->mysql_fetch_all($result);
  1640. }
  1641. function getDelInbox($uid) {
  1642. $q = "SELECT * FROM " . TB_PREFIX . "mdata WHERE target = $uid and deltarget = 1 ORDER BY time DESC";
  1643. $result = mysql_query($q, $this->connection);
  1644. return $this->mysql_fetch_all($result);
  1645. }
  1646. function getDelArchive($uid) {
  1647. $q = "SELECT * FROM " . TB_PREFIX . "mdata WHERE target = $uid and archived = 1 and deltarget = 1 OR owner = $uid and archived = 1 and delowner = 1 ORDER BY time DESC";
  1648. $result = mysql_query($q, $this->connection);
  1649. return $this->mysql_fetch_all($result);
  1650. }
  1651. function unarchiveNotice($id) {
  1652. $q = "UPDATE " . TB_PREFIX . "ndata set ntype = archive, archive = 0 where id = $id";
  1653. return mysql_query($q, $this->connection);
  1654. }
  1655. function archiveNotice($id) {
  1656. $q = "update " . TB_PREFIX . "ndata set archive = ntype, ntype = 9 where id = $id";
  1657. return mysql_query($q, $this->connection);
  1658. }
  1659. function removeNotice($id) {
  1660. $q = "UPDATE " . TB_PREFIX . "ndata set del = 1,viewed = 1 where id = $id";
  1661. return mysql_query($q, $this->connection);
  1662. }
  1663. function noticeViewed($id) {
  1664. $q = "UPDATE " . TB_PREFIX . "ndata set viewed = 1 where id = $id";
  1665. return mysql_query($q, $this->connection);
  1666. }
  1667. function addNotice($uid, $toWref, $ally, $type, $topic, $data, $time = 0) {
  1668. if($time == 0) {
  1669. $time = time();
  1670. }
  1671. $q = "INSERT INTO " . TB_PREFIX . "ndata (id, uid, toWref, ally, topic, ntype, data, time, viewed) values (0,'$uid','$toWref','$ally','$topic',$type,'$data',$time,0)";
  1672. return mysql_query($q, $this->connection) or die(mysql_error());
  1673. }
  1674. function getNotice($uid) {
  1675. $q = "SELECT * FROM " . TB_PREFIX . "ndata where uid = $uid and del = 0 ORDER BY time DESC";
  1676. $result = mysql_query($q, $this->connection);
  1677. return $this->mysql_fetch_all($result);
  1678. }
  1679. function getNotice2($id, $field) {
  1680. $q = "SELECT ".$field." FROM " . TB_PREFIX . "ndata where `id` = '$id'";
  1681. $result = mysql_query($q, $this->connection);
  1682. $dbarray = mysql_fetch_array($result);
  1683. return $dbarray[$field];
  1684. }
  1685. function getNotice3($uid) {
  1686. $q = "SELECT * FROM " . TB_PREFIX . "ndata where uid = $uid ORDER BY time DESC";
  1687. $result = mysql_query($q, $this->connection);
  1688. return $this->mysql_fetch_all($result);
  1689. }
  1690. function getNotice4($id) {
  1691. $q = "SELECT * FROM " . TB_PREFIX . "ndata where id = $id ORDER BY time DESC";
  1692. $result = mysql_query($q, $this->connection);
  1693. return $this->mysql_fetch_all($result);
  1694. }
  1695. function getUnViewNotice($uid) {
  1696. $q = "SELECT * FROM " . TB_PREFIX . "ndata where uid = $uid AND viewed=0";
  1697. $result = mysql_query($q, $this->connection);
  1698. return $this->mysql_fetch_all($result);
  1699. }
  1700. function createTradeRoute($uid,$wid,$from,$r1,$r2,$r3,$r4,$start,$deliveries,$merchant,$time) {
  1701. $x = "UPDATE " . TB_PREFIX . "users SET gold = gold - 2 WHERE id = ".$uid."";
  1702. mysql_query($x, $this->connection);
  1703. $timeleft = time()+604800;
  1704. $q = "INSERT into " . TB_PREFIX . "route values (0,$uid,$wid,$from,$r1,$r2,$r3,$r4,$start,$deliveries,$merchant,$time,$timeleft)";
  1705. return mysql_query($q, $this->connection);
  1706. }
  1707. function getTradeRoute($uid) {
  1708. $q = "SELECT * FROM " . TB_PREFIX . "route where uid = $uid ORDER BY timestamp ASC";
  1709. $result = mysql_query($q, $this->connection);
  1710. return $this->mysql_fetch_all($result);
  1711. }
  1712. function getTradeRoute2($id) {
  1713. $q = "SELECT * FROM " . TB_PREFIX . "route where id = $id";
  1714. $result = mysql_query($q, $this->connection) or die(mysql_error());
  1715. $dbarray = mysql_fetch_array($result);
  1716. return $dbarray;
  1717. }
  1718. function getTradeRouteUid($id) {
  1719. $q = "SELECT * FROM " . TB_PREFIX . "route where id = $id";
  1720. $result = mysql_query($q, $this->connection) or die(mysql_error());
  1721. $dbarray = mysql_fetch_array($result);
  1722. return $dbarray['uid'];
  1723. }
  1724. function editTradeRoute($id,$column,$value,$mode) {
  1725. if(!$mode){
  1726. $q = "UPDATE " . TB_PREFIX . "route set $column = $value where id = $id";
  1727. }else{
  1728. $q = "UPDATE " . TB_PREFIX . "route set $column = $column + $value where id = $id";
  1729. }
  1730. return mysql_query($q, $this->connection);
  1731. }
  1732. function deleteTradeRoute($id) {
  1733. $q = "DELETE FROM " . TB_PREFIX . "route where id = $id";
  1734. return mysql_query($q, $this->connection);
  1735. }
  1736. function addBuilding($wid, $field, $type, $loop, $time, $master, $level) {
  1737. $x = "UPDATE " . TB_PREFIX . "fdata SET f" . $field . "t=" . $type . " WHERE vref=" . $wid;
  1738. mysql_query($x, $this->connection) or die(mysql_error());
  1739. $q = "INSERT into " . TB_PREFIX . "bdata values (0,$wid,$field,$type,$loop,$time,$master,$level)";
  1740. return mysql_query($q, $this->connection);
  1741. }
  1742. function removeBuilding($d) {
  1743. global $building, $village;
  1744. $jobLoopconID = -1;
  1745. $SameBuildCount = 0;
  1746. $jobs = $building->buildArray;
  1747. for($i = 0; $i < sizeof($jobs); $i++) {
  1748. if($jobs[$i]['id'] == $d) {
  1749. $jobDeleted = $i;
  1750. }
  1751. if($jobs[$i]['loopcon'] == 1) {
  1752. $jobLoopconID = $i;
  1753. }
  1754. if($jobs[$i]['master'] == 1) {
  1755. $jobMaster = $i;
  1756. }
  1757. }
  1758. if(count($jobs) > 1 && ($jobs[0]['field'] == $jobs[1]['field'])) {
  1759. $SameBuildCount = 1;
  1760. }
  1761. if(count($jobs) > 2 && ($jobs[0]['field'] == $jobs[2]['field'])) {
  1762. $SameBuildCount = 2;
  1763. }
  1764. if(count($jobs) > 2 && ($jobs[1]['field'] == $jobs[2]['field'])) {
  1765. $SameBuildCount = 3;
  1766. }
  1767. if(count($jobs) > 3 && ($jobs[0]['field'] == $jobs[3]['field'])) {
  1768. $SameBuildCount = 8;
  1769. }
  1770. if(count($jobs) > 3 && ($jobs[1]['field'] == $jobs[3]['field'])) {
  1771. $SameBuildCount = 9;
  1772. }
  1773. if(count($jobs) > 3 && ($jobs[2]['field'] == $jobs[3]['field'])) {
  1774. $SameBuildCount = 10;
  1775. }
  1776. if(count($jobs) > 2 && ($jobs[0]['field'] == $jobs[1]['field'] && $jobs[1]['field'] == $jobs[2]['field'])) {
  1777. $SameBuildCount = 4;
  1778. }
  1779. if(count($jobs) > 3 && ($jobs[0]['field'] == $jobs[1]['field'] && $jobs[1]['field'] == $jobs[3]['field'])) {
  1780. $SameBuildCount = 5;
  1781. }
  1782. if(count($jobs) > 3 && ($jobs[0]['field'] == $jobs[2]['field'] && $jobs[2]['field'] == $jobs[3]['field'])) {
  1783. $SameBuildCount = 6;
  1784. }
  1785. if(count($jobs) > 3 && ($jobs[1]['field'] == $jobs[2]['field'] && $jobs[2]['field'] == $jobs[3]['field'])) {
  1786. $SameBuildCount = 7;
  1787. }
  1788. if($SameBuildCount > 0) {
  1789. if($SameBuildCount > 3){
  1790. if($SameBuildCount == 4 or $SameBuildCount == 5){
  1791. if($jobDeleted == 0){
  1792. $uprequire = $building->resourceRequired($jobs[1]['field'],$jobs[1]['type'],1);
  1793. $time = $uprequire['time'];
  1794. $timestamp = $time+time();
  1795. $q = "UPDATE " . TB_PREFIX . "bdata SET loopcon=0,level=level-1,timestamp=".$timestamp." WHERE id=".$jobs[1]['id']."";
  1796. mysql_query($q, $this->connection);
  1797. }
  1798. }else if($SameBuildCount == 6){
  1799. if($jobDeleted == 0){
  1800. $uprequire = $building->resourceRequired($jobs[2]['field'],$jobs[2]['type'],1);
  1801. $time = $uprequire['time'];
  1802. $timestamp = $time+time();
  1803. $q = "UPDATE " . TB_PREFIX . "bdata SET loopcon=0,level=level-1,timestamp=".$timestamp." WHERE id=".$jobs[2]['id']."";
  1804. mysql_query($q, $this->connection);
  1805. }
  1806. }else if($SameBuildCount == 7){
  1807. if($jobDeleted == 1){
  1808. $uprequire = $building->resourceRequired($jobs[2]['field'],$jobs[2]['type'],1);
  1809. $time = $uprequire['time'];
  1810. $timestamp = $time+time();
  1811. $q = "UPDATE " . TB_PREFIX . "bdata SET loopcon=0,level=level-1,timestamp=".$timestamp." WHERE id=".$jobs[2]['id']."";
  1812. mysql_query($q, $this->connection);
  1813. }
  1814. }
  1815. if($SameBuildCount < 8){
  1816. $uprequire1 = $building->resourceRequired($jobs[$jobMaster]['field'],$jobs[$jobMaster]['type'],2);
  1817. $time1 = $uprequire1['time'];
  1818. $timestamp1 = $time1;
  1819. $q1 = "UPDATE " . TB_PREFIX . "bdata SET level=level-1,timestamp=".$timestamp1." WHERE id=".$jobs[$jobMaster]['id']."";
  1820. mysql_query($q1, $this->connection);
  1821. }else{
  1822. $uprequire1 = $building->resourceRequired($jobs[$jobMaster]['field'],$jobs[$jobMaster]['type'],1);
  1823. $time1 = $uprequire1['time'];
  1824. $timestamp1 = $time1;
  1825. $q1 = "UPDATE " . TB_PREFIX . "bdata SET level=level-1,timestamp=".$timestamp1." WHERE id=".$jobs[$jobMaster]['id']."";
  1826. mysql_query($q1, $this->connection);
  1827. }
  1828. }else if($d == $jobs[floor($SameBuildCount / 3)]['id'] || $d == $jobs[floor($SameBuildCount / 2) + 1]['id']) {
  1829. $q = "UPDATE " . TB_PREFIX . "bdata SET loopcon=0,level=level-1,timestamp=" . $jobs[floor($SameBuildCount / 3)]['timestamp'] . " WHERE master = 0 AND id > ".$d." and (ID=" . $jobs[floor($SameBuildCount / 3)]['id'] . " OR ID=" . $jobs[floor($SameBuildCount / 2) + 1]['id'] . ")";
  1830. mysql_query($q, $this->connection);
  1831. }
  1832. } else {
  1833. if($jobs[$jobDeleted]['field'] >= 19) {
  1834. $x = "SELECT f" . $jobs[$jobDeleted]['field'] . " FROM " . TB_PREFIX . "fdata WHERE vref=" . $jobs[$jobDeleted]['wid'];
  1835. $result = mysql_query($x, $this->connection) or die(mysql_error());
  1836. $fieldlevel = mysql_fetch_row($result);
  1837. if($fieldlevel[0] == 0) {
  1838. if ($village->natar==1 && $jobs[$jobDeleted]['field']==99) { //fix by ronix
  1839. }else{
  1840. $x = "UPDATE " . TB_PREFIX . "fdata SET f" . $jobs[$jobDeleted]['field'] . "t=0 WHERE vref=" . $jobs[$jobDeleted]['wid'];
  1841. mysql_query($x, $this->connection) or die(mysql_error());
  1842. }
  1843. }
  1844. }
  1845. if(($jobLoopconID >= 0) && ($jobs[$jobDeleted]['loopcon'] != 1)) {
  1846. if(($jobs[$jobLoopconID]['field'] <= 18 && $jobs[$jobDeleted]['field'] <= 18) || ($jobs[$jobLoopconID]['field'] >= 19 && $jobs[$jobDeleted]['field'] >= 19) || sizeof($jobs) < 3) {
  1847. $uprequire = $building->resourceRequired($jobs[$jobLoopconID]['field'], $jobs[$jobLoopconID]['type']);
  1848. $x = "UPDATE " . TB_PREFIX . "bdata SET loopcon=0,timestamp=" . (time() + $uprequire['time']) . " WHERE wid=" . $jobs[$jobDeleted]['wid'] . " AND loopcon=1 AND master=0";
  1849. mysql_query($x, $this->connection) or die(mysql_error());
  1850. }
  1851. }
  1852. }
  1853. $q = "DELETE FROM " . TB_PREFIX . "bdata where id = $d";
  1854. return mysql_query($q, $this->connection);
  1855. }
  1856. function addDemolition($wid, $field) {
  1857. global $building, $village;
  1858. $q = "DELETE FROM ".TB_PREFIX."bdata WHERE field=$field AND wid=$wid";
  1859. mysql_query($q, $this->connection);
  1860. $uprequire = $building->resourceRequired($field,$village->resarray['f'.$field.'t'],0);
  1861. $q = "INSERT INTO ".TB_PREFIX."demolition VALUES (".$wid.",".$field.",".($this->getFieldLevel($wid,$field)-1).",".(time()+floor($uprequire['time']/2)).")";
  1862. return mysql_query($q, $this->connection);
  1863. }
  1864. function getDemolition($wid = 0) {
  1865. if($wid) {
  1866. $q = "SELECT * FROM " . TB_PREFIX . "demolition WHERE vref=" . $wid;
  1867. } else {
  1868. $q = "SELECT * FROM " . TB_PREFIX . "demolition WHERE timetofinish<=" . time();
  1869. }
  1870. $result = mysql_query($q, $this->connection);
  1871. if(!empty($result)) {
  1872. return $this->mysql_fetch_all($result);
  1873. } else {
  1874. return NULL;
  1875. }
  1876. }
  1877. function finishDemolition($wid) {
  1878. $q = "UPDATE " . TB_PREFIX . "demolition SET timetofinish=" . time() . " WHERE vref=" . $wid;
  1879. $result= mysql_query($q, $this->connection);
  1880. return mysql_affected_rows();
  1881. }
  1882. function delDemolition($wid) {
  1883. $q = "DELETE FROM " . TB_PREFIX . "demolition WHERE vref=" . $wid;
  1884. return mysql_query($q, $this->connection);
  1885. }
  1886. function getJobs($wid) {
  1887. $q = "SELECT * FROM " . TB_PREFIX . "bdata where wid = $wid order by master,timestamp ASC";
  1888. $result = mysql_query($q, $this->connection);
  1889. return $this->mysql_fetch_all($result);
  1890. }
  1891. function FinishWoodcutter($wid) {
  1892. $time = time()-1;
  1893. $q = "SELECT * FROM " . TB_PREFIX . "bdata where wid = $wid and type = 1 order by master,timestamp ASC";
  1894. $result = mysql_query($q);
  1895. $dbarray = mysql_fetch_array($result);
  1896. $q = "UPDATE ".TB_PREFIX."bdata SET timestamp = $time WHERE id = '".$dbarray['id']."'";
  1897. $this->query($q);
  1898. $tribe = $this->getUserField($this->getVillageField($wid, "owner"), "tribe", 0);
  1899. if($tribe == 1){
  1900. $q2 = "SELECT * FROM " . TB_PREFIX . "bdata where wid = $wid and loopcon = 1 and field >= 19 order by master,timestamp ASC";
  1901. }else{
  1902. $q2 = "SELECT * FROM " . TB_PREFIX . "bdata where wid = $wid and loopcon = 1 order by master,timestamp ASC";
  1903. }
  1904. $result2 = mysql_query($q2);
  1905. if(mysql_num_rows($result2) > 0){
  1906. $dbarray2 = mysql_fetch_array($result2);
  1907. $wc_time = $dbarray['timestamp'];
  1908. $q2 = "UPDATE ".TB_PREFIX."bdata SET timestamp = timestamp - $wc_time WHERE id = '".$dbarray2['id']."'";
  1909. $this->query($q2);
  1910. }
  1911. }
  1912. function getMasterJobs($wid) {
  1913. $q = "SELECT * FROM " . TB_PREFIX . "bdata where wid = $wid and master = 1 order by master,timestamp ASC";
  1914. $result = mysql_query($q, $this->connection);
  1915. return $this->mysql_fetch_all($result);
  1916. }
  1917. function getMasterJobsByField($wid,$field) {
  1918. $q = "SELECT * FROM " . TB_PREFIX . "bdata where wid = $wid and field = $field and master = 1 order by master,timestamp ASC";
  1919. $result = mysql_query($q, $this->connection);
  1920. return $this->mysql_fetch_all($result);
  1921. }
  1922. function getBuildingByField($wid,$field) {
  1923. $q = "SELECT * FROM " . TB_PREFIX . "bdata where wid = $wid and field = $field and master = 0";
  1924. $result = mysql_query($q, $this->connection);
  1925. return $this->mysql_fetch_all($result);
  1926. }
  1927. function getBuildingByField2($wid,$field) {
  1928. $q = "SELECT * FROM " . TB_PREFIX . "bdata where wid = $wid and field = $field and master = 0";
  1929. $result = mysql_query($q, $this->connection);
  1930. return mysql_num_rows($result);
  1931. }
  1932. function getBuildingByType($wid,$type) {
  1933. $q = "SELECT * FROM " . TB_PREFIX . "bdata where wid = $wid and type = $type and master = 0";
  1934. $result = mysql_query($q, $this->connection);
  1935. return $this->mysql_fetch_all($result);
  1936. }
  1937. function getBuildingByType2($wid,$type) {
  1938. $q = "SELECT * FROM " . TB_PREFIX . "bdata where wid = $wid and type = $type and master = 0";
  1939. $result = mysql_query($q, $this->connection);
  1940. return mysql_num_rows($result);
  1941. }
  1942. function getDorf1Building($wid) {
  1943. $q = "SELECT * FROM " . TB_PREFIX . "bdata where wid = $wid and field < 19 and master = 0";
  1944. $result = mysql_query($q, $this->connection);
  1945. return $this->mysql_fetch_all($result);
  1946. }
  1947. function getDorf2Building($wid) {
  1948. $q = "SELECT * FROM " . TB_PREFIX . "bdata where wid = $wid and field > 18 and master = 0";
  1949. $result = mysql_query($q, $this->connection);
  1950. return $this->mysql_fetch_all($result);
  1951. }
  1952. function updateBuildingWithMaster($id, $time,$loop) {
  1953. $q = "UPDATE " . TB_PREFIX . "bdata SET master = 0, timestamp = ".$time.",loopcon = ".$loop." WHERE id = ".$id."";
  1954. return mysql_query($q, $this->connection);
  1955. }
  1956. function getVillageByName($name) {
  1957. $q = "SELECT wref FROM " . TB_PREFIX . "vdata where name = '$name' limit 1";
  1958. $result = mysql_query($q, $this->connection);
  1959. $dbarray = mysql_fetch_array($result);
  1960. return $dbarray['wref'];
  1961. }
  1962. /***************************
  1963. Function to set accept flag on market
  1964. References: id
  1965. ***************************/
  1966. function setMarketAcc($id) {
  1967. $q = "UPDATE " . TB_PREFIX . "market set accept = 1 where id = $id";
  1968. return mysql_query($q, $this->connection);
  1969. }
  1970. /***************************
  1971. Function to send resource to other village
  1972. Mode 0: Send
  1973. Mode 1: Cancel
  1974. References: Wood/ID, Clay, Iron, Crop, Mode
  1975. ***************************/
  1976. function sendResource($ref, $clay, $iron, $crop, $merchant, $mode) {
  1977. if(!$mode) {
  1978. $q = "INSERT INTO " . TB_PREFIX . "send values (0,$ref,$clay,$iron,$crop,$merchant)";
  1979. mysql_query($q, $this->connection);
  1980. return mysql_insert_id($this->connection);
  1981. } else {
  1982. $q = "DELETE FROM " . TB_PREFIX . "send where id = $ref";
  1983. return mysql_query($q, $this->connection);
  1984. }
  1985. }
  1986. /***************************
  1987. Function to get resources back if you delete offer
  1988. References: VillageRef (vref)
  1989. Made by: Dzoki
  1990. ***************************/
  1991. function getResourcesBack($vref, $gtype, $gamt) {
  1992. //Xtype (1) = wood, (2) = clay, (3) = iron, (4) = crop
  1993. if($gtype == 1) {
  1994. $q = "UPDATE " . TB_PREFIX . "vdata SET `wood` = `wood` + '$gamt' WHERE wref = $vref";
  1995. return mysql_query($q, $this->connection);
  1996. } else
  1997. if($gtype == 2) {
  1998. $q = "UPDATE " . TB_PREFIX . "vdata SET `clay` = `clay` + '$gamt' WHERE wref = $vref";
  1999. return mysql_query($q, $this->connection);
  2000. } else
  2001. if($gtype == 3) {
  2002. $q = "UPDATE " . TB_PREFIX . "vdata SET `iron` = `iron` + '$gamt' WHERE wref = $vref";
  2003. return mysql_query($q, $this->connection);
  2004. } else
  2005. if($gtype == 4) {
  2006. $q = "UPDATE " . TB_PREFIX . "vdata SET `crop` = `crop` + '$gamt' WHERE wref = $vref";
  2007. return mysql_query($q, $this->connection);
  2008. }
  2009. }
  2010. /***************************
  2011. Function to get info about offered resources
  2012. References: VillageRef (vref)
  2013. Made by: Dzoki
  2014. ***************************/
  2015. function getMarketField($vref, $field) {
  2016. $q = "SELECT $field FROM " . TB_PREFIX . "market where vref = '$vref'";
  2017. $result = mysql_query($q, $this->connection) or die(mysql_error());
  2018. $dbarray = mysql_fetch_array($result);
  2019. return $dbarray[$field];
  2020. }
  2021. function removeAcceptedOffer($id) {
  2022. $q = "DELETE FROM " . TB_PREFIX . "market where id = $id";
  2023. $result = mysql_query($q, $this->connection);
  2024. return mysql_fetch_assoc($result);
  2025. }
  2026. /***************************
  2027. Function to add market offer
  2028. Mode 0: Add
  2029. Mode 1: Cancel
  2030. References: Village, Give, Amt, Want, Amt, Time, Alliance, Mode
  2031. ***************************/
  2032. function addMarket($vid, $gtype, $gamt, $wtype, $wamt, $time, $alliance, $merchant, $mode) {
  2033. if(!$mode) {
  2034. $q = "INSERT INTO " . TB_PREFIX . "market values (0,$vid,$gtype,$gamt,$wtype,$wamt,0,$time,$alliance,$merchant)";
  2035. mysql_query($q, $this->connection);
  2036. return mysql_insert_id($this->connection);
  2037. } else {
  2038. $q = "DELETE FROM " . TB_PREFIX . "market where id = $gtype and vref = $vid";
  2039. return mysql_query($q, $this->connection);
  2040. }
  2041. }
  2042. /***************************
  2043. Function to get market offer
  2044. References: Village, Mode
  2045. ***************************/
  2046. function getMarket($vid, $mode) {
  2047. $alliance = $this->getUserField($this->getVillageField($vid, "owner"), "alliance", 0);
  2048. if(!$mode) {
  2049. $q = "SELECT * FROM " . TB_PREFIX . "market where vref = $vid and accept = 0";
  2050. } else {
  2051. $q = "SELECT * FROM " . TB_PREFIX . "market where vref != $vid and alliance = $alliance or vref != $vid and alliance = 0 and accept = 0";
  2052. }
  2053. $result = mysql_query($q, $this->connection);
  2054. return $this->mysql_fetch_all($result);
  2055. }
  2056. /***************************
  2057. Function to get market offer
  2058. References: ID
  2059. ***************************/
  2060. function getMarketInfo($id) {
  2061. $q = "SELECT * FROM " . TB_PREFIX . "market where id = $id";
  2062. $result = mysql_query($q, $this->connection);
  2063. return mysql_fetch_assoc($result);
  2064. }
  2065. function setMovementProc($moveid) {
  2066. $q = "UPDATE " . TB_PREFIX . "movement set proc = 1 where moveid = $moveid";
  2067. return mysql_query($q, $this->connection);
  2068. }
  2069. /***************************
  2070. Function to retrieve used merchant
  2071. References: Village
  2072. ***************************/
  2073. function totalMerchantUsed($vid) {
  2074. $time = time();
  2075. $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";
  2076. $result = mysql_query($q, $this->connection);
  2077. $row = mysql_fetch_row($result);
  2078. $q2 = "SELECT sum(ref) from " . TB_PREFIX . "movement where sort_type = 2 and " . TB_PREFIX . "movement.to = $vid and proc = 0";
  2079. $result2 = mysql_query($q2, $this->connection);
  2080. $row2 = mysql_fetch_row($result2);
  2081. $q3 = "SELECT sum(merchant) from " . TB_PREFIX . "market where vref = $vid and accept = 0";
  2082. $result3 = mysql_query($q3, $this->connection);
  2083. $row3 = mysql_fetch_row($result3);
  2084. return $row[0] + $row2[0] + $row3[0];
  2085. }
  2086. function getMovement($type, $village, $mode) {
  2087. $time = time();
  2088. if(!$mode) {
  2089. $where = "from";
  2090. } else {
  2091. $where = "to";
  2092. }
  2093. switch($type) {
  2094. case 0:
  2095. $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";
  2096. break;
  2097. case 1:
  2098. $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";
  2099. break;
  2100. case 2:
  2101. $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";
  2102. break;
  2103. case 3:
  2104. $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";
  2105. break;
  2106. case 4:
  2107. $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";
  2108. break;
  2109. case 5:
  2110. $q = "SELECT * FROM " . TB_PREFIX . "movement where " . TB_PREFIX . "movement." . $where . " = $village and sort_type = 5 and proc = 0 ORDER BY endtime ASC";
  2111. break;
  2112. case 6:
  2113. $q = "SELECT * FROM " . TB_PREFIX . "movement," . TB_PREFIX . "odata, " . TB_PREFIX . "attacks where " . TB_PREFIX . "odata.wref = $village and " . TB_PREFIX . "movement.to = $village and " . TB_PREFIX . "movement.ref = " . TB_PREFIX . "attacks.id and " . TB_PREFIX . "attacks.attack_type != 1 and " . TB_PREFIX . "movement.proc = 0 and " . TB_PREFIX . "movement.sort_type = 3 ORDER BY endtime ASC";
  2114. //$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";
  2115. break;
  2116. case 7:
  2117. $q = "SELECT * FROM " . TB_PREFIX . "movement where " . TB_PREFIX . "movement." . $where . " = $village and sort_type = 4 and ref = 0 and proc = 0 ORDER BY endtime ASC";
  2118. break;
  2119. case 8:
  2120. $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 and " . TB_PREFIX . "attacks.attack_type = 1 ORDER BY endtime ASC";
  2121. break;
  2122. case 34:
  2123. $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";
  2124. break;
  2125. }
  2126. $result = mysql_query($q, $this->connection);
  2127. $array = $this->mysql_fetch_all($result);
  2128. return $array;
  2129. }
  2130. function addA2b($ckey, $timestamp, $to, $t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10, $t11, $type) {
  2131. $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')";
  2132. mysql_query($q, $this->connection);
  2133. return mysql_insert_id($this->connection);
  2134. }
  2135. function getA2b($ckey, $check) {
  2136. $q = "SELECT * from " . TB_PREFIX . "a2b where ckey = '" . $ckey . "' AND time_check = '" . $check . "'";
  2137. $result = mysql_query($q, $this->connection);
  2138. if($result) {
  2139. return mysql_fetch_assoc($result);
  2140. } else {
  2141. return false;
  2142. }
  2143. }
  2144. function addMovement($type, $from, $to, $ref, $time, $endtime, $send = 1, $wood = 0, $clay = 0, $iron = 0, $crop = 0, $ref2 = 0) {
  2145. $q = "INSERT INTO " . TB_PREFIX . "movement values (0,$type,$from,$to,$ref,$ref2,$time,$endtime,0,$send,$wood,$clay,$iron,$crop)";
  2146. return mysql_query($q, $this->connection);
  2147. }
  2148. 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) {
  2149. $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)";
  2150. mysql_query($q, $this->connection);
  2151. return mysql_insert_id($this->connection);
  2152. }
  2153. function modifyAttack($aid, $unit, $amt) {
  2154. $unit = 't' . $unit;
  2155. $q = "UPDATE " . TB_PREFIX . "attacks set $unit = $unit - $amt where id = $aid";
  2156. return mysql_query($q, $this->connection);
  2157. }
  2158. function modifyAttack2($aid, $unit, $amt) {
  2159. $unit = 't' . $unit;
  2160. $q = "UPDATE " . TB_PREFIX . "attacks set $unit = $unit + $amt where id = $aid";
  2161. return mysql_query($q, $this->connection);
  2162. }
  2163. function modifyAttack3($aid, $units) {
  2164. $q = "UPDATE ".TB_PREFIX."attacks set $units WHERE id = $aid";
  2165. return mysql_query($q, $this->connection);
  2166. }
  2167. function getRanking() {
  2168. $q = "SELECT id,username,alliance,ap,apall,dp,dpall,access FROM " . TB_PREFIX . "users WHERE tribe<=3 AND access<" . (INCLUDE_ADMIN ? "10" : "8");
  2169. $result = mysql_query($q, $this->connection);
  2170. return $this->mysql_fetch_all($result);
  2171. }
  2172. function getVRanking() {
  2173. $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");
  2174. $result = mysql_query($q, $this->connection);
  2175. return $this->mysql_fetch_all($result);
  2176. }
  2177. function getARanking() {
  2178. $q = "SELECT id,name,tag,oldrank,Aap,Adp FROM " . TB_PREFIX . "alidata where id != '' ORDER BY id DESC";
  2179. $result = mysql_query($q, $this->connection);
  2180. return $this->mysql_fetch_all($result);
  2181. }
  2182. function getUserByTribe($tribe){
  2183. $q = "SELECT * FROM " . TB_PREFIX . "users where tribe = $tribe";
  2184. $result = mysql_query($q, $this->connection);
  2185. return $this->mysql_fetch_all($result);
  2186. }
  2187. function getUserByAlliance($aid){
  2188. $q = "SELECT * FROM " . TB_PREFIX . "users where alliance = $aid";
  2189. $result = mysql_query($q, $this->connection);
  2190. return $this->mysql_fetch_all($result);
  2191. }
  2192. function getHeroRanking() {
  2193. $q = "SELECT * FROM " . TB_PREFIX . "hero WHERE dead = 0";
  2194. $result = mysql_query($q, $this->connection);
  2195. return $this->mysql_fetch_all($result);
  2196. }
  2197. function getAllMember($aid) {
  2198. $q = "SELECT * FROM " . TB_PREFIX . "users where alliance = $aid order by (SELECT sum(pop) FROM " . TB_PREFIX . "vdata WHERE owner = " . TB_PREFIX . "users.id) desc, " . TB_PREFIX . "users.id desc";
  2199. $result = mysql_query($q, $this->connection);
  2200. return $this->mysql_fetch_all($result);
  2201. }
  2202. function getAllMember2($aid) {
  2203. $q = "SELECT * FROM " . TB_PREFIX . "users where alliance = $aid order by (SELECT sum(pop) FROM " . TB_PREFIX . "vdata WHERE owner = " . TB_PREFIX . "users.id) desc, " . TB_PREFIX . "users.id desc LIMIT 1";
  2204. $result = mysql_query($q, $this->connection);
  2205. return mysql_fetch_array($result);
  2206. }
  2207. function addUnits($vid) {
  2208. $q = "INSERT into " . TB_PREFIX . "units (vref) values ($vid)";
  2209. return mysql_query($q, $this->connection);
  2210. }
  2211. function getUnit($vid) {
  2212. $q = "SELECT * from " . TB_PREFIX . "units where vref = $vid";
  2213. $result = mysql_query($q, $this->connection);
  2214. if (!empty($result)) {
  2215. return mysql_fetch_assoc($result);
  2216. } else {
  2217. return NULL;
  2218. }
  2219. }
  2220. function getUnitsNumber($vid) {
  2221. $q = "SELECT * from " . TB_PREFIX . "units where vref = $vid";
  2222. $result = mysql_query($q, $this->connection);
  2223. $dbarray = mysql_fetch_assoc($result);
  2224. $totalunits = 0;
  2225. $movingunits = $this->getVillageMovement($vid);
  2226. for($i=1;$i<=50;$i++){
  2227. $totalunits += $dbarray['u'.$i];
  2228. }
  2229. $totalunits += $dbarray['hero'];
  2230. $movingunits = $this->getVillageMovement($vid);
  2231. $reinforcingunits = $this->getEnforceArray($vid,1);
  2232. $owner = $this->getVillageField($vid,"owner");
  2233. $ownertribe = $this->getUserField($owner,"tribe",0);
  2234. $start = ($ownertribe-1)*10+1;
  2235. $end = ($ownertribe*10);
  2236. for($i=$start;$i<=$end;$i++){
  2237. $totalunits += $movingunits['u'.$i];
  2238. $totalunits += $reinforcingunits['u'.$i];
  2239. }
  2240. $totalunits += $movingunits['hero'];
  2241. $totalunits += $reinforcingunits['hero'];
  2242. return $totalunits;
  2243. }
  2244. function getHero($uid=0,$all=0) {
  2245. if ($all) {
  2246. $q = "SELECT * FROM ".TB_PREFIX."hero WHERE uid=$uid";
  2247. } elseif (!$uid) {
  2248. $q = "SELECT * FROM ".TB_PREFIX."hero";
  2249. } else {
  2250. $q = "SELECT * FROM ".TB_PREFIX."hero WHERE dead=0 AND uid=$uid LIMIT 1";
  2251. }
  2252. $result = mysql_query($q, $this->connection);
  2253. if (!empty($result)) {
  2254. return $this->mysql_fetch_all($result);
  2255. } else {
  2256. return NULL;
  2257. }
  2258. }
  2259. function getHeroField($uid,$field){
  2260. $q = "SELECT * FROM ".TB_PREFIX."hero WHERE uid = $uid";
  2261. $result = mysql_query($q,$this->connection);
  2262. return $this->mysql_fetch_all($result);
  2263. }
  2264. function modifyHero($column,$value,$heroid,$mode=0) {
  2265. if(!$mode) {
  2266. $q = "UPDATE `".TB_PREFIX."hero` SET $column = $value WHERE heroid = $heroid";
  2267. } elseif($mode=1) {
  2268. $q = "UPDATE `".TB_PREFIX."hero` SET $column = $column + $value WHERE heroid = $heroid";
  2269. } else {
  2270. $q = "UPDATE `".TB_PREFIX."hero` SET $column = $column - $value WHERE heroid = $heroid";
  2271. }
  2272. return mysql_query($q, $this->connection);
  2273. }
  2274. function modifyHeroByOwner($column,$value,$uid,$mode=0) {
  2275. if(!$mode) {
  2276. $q = "UPDATE `".TB_PREFIX."hero` SET $column = $value WHERE uid = $uid";
  2277. } elseif($mode=1) {
  2278. $q = "UPDATE `".TB_PREFIX."hero` SET $column = $column + $value WHERE uid = $uid";
  2279. } else {
  2280. $q = "UPDATE `".TB_PREFIX."hero` SET $column = $column - $value WHERE uid = $uid";
  2281. }
  2282. return mysql_query($q, $this->connection);
  2283. }
  2284. function modifyHeroXp($column,$value,$heroid) {
  2285. $q = "UPDATE ".TB_PREFIX."hero SET $column = $column + $value WHERE uid=$heroid";
  2286. return mysql_query($q, $this->connection);
  2287. }
  2288. function addTech($vid) {
  2289. $q = "INSERT into " . TB_PREFIX . "tdata (vref) values ($vid)";
  2290. return mysql_query($q, $this->connection);
  2291. }
  2292. function addABTech($vid) {
  2293. $q = "INSERT into " . TB_PREFIX . "abdata (vref) values ($vid)";
  2294. return mysql_query($q, $this->connection);
  2295. }
  2296. function getABTech($vid) {
  2297. $q = "SELECT * FROM " . TB_PREFIX . "abdata where vref = $vid";
  2298. $result = mysql_query($q, $this->connection);
  2299. return mysql_fetch_assoc($result);
  2300. }
  2301. function addResearch($vid, $tech, $time) {
  2302. $q = "INSERT into " . TB_PREFIX . "research values (0,$vid,'$tech',$time)";
  2303. return mysql_query($q, $this->connection);
  2304. }
  2305. function getResearching($vid) {
  2306. $q = "SELECT * FROM " . TB_PREFIX . "research where vref = $vid";
  2307. $result = mysql_query($q, $this->connection);
  2308. return $this->mysql_fetch_all($result);
  2309. }
  2310. function checkIfResearched($vref, $unit) {
  2311. $q = "SELECT $unit FROM " . TB_PREFIX . "tdata WHERE vref = $vref";
  2312. $result = mysql_query($q, $this->connection) or die(mysql_error());
  2313. $dbarray = mysql_fetch_array($result);
  2314. return $dbarray[$unit];
  2315. }
  2316. function getTech($vid) {
  2317. $q = "SELECT * from " . TB_PREFIX . "tdata where vref = $vid";
  2318. $result = mysql_query($q, $this->connection);
  2319. return mysql_fetch_assoc($result);
  2320. }
  2321. function getTraining($vid) {
  2322. $q = "SELECT * FROM " . TB_PREFIX . "training where vref = $vid ORDER BY id";
  2323. $result = mysql_query($q, $this->connection);
  2324. return $this->mysql_fetch_all($result);
  2325. }
  2326. function countTraining($vid) {
  2327. $q = "SELECT * FROM " . TB_PREFIX . "training WHERE vref = $vid";
  2328. $result = mysql_query($q, $this->connection);
  2329. $row = mysql_fetch_row($result);
  2330. return $row[0];
  2331. }
  2332. function trainUnit($vid, $unit, $amt, $pop, $each, $time, $mode) {
  2333. global $village, $building, $session, $technology;
  2334. if(!$mode) {
  2335. $barracks = array(1,2,3,11,12,13,14,21,22,31,32,33,34,35,36,37,38,39,40,41,42,43,44);
  2336. // fix by brainiac - THANK YOU
  2337. $greatbarracks = array(61,62,63,71,72,73,74,81,82,91,92,93,94,95,96,97,98,99,100,101,102,103,104);
  2338. $stables = array(4,5,6,15,16,23,24,25,26,45,46);
  2339. $greatstables = array(64,65,66,75,76,83,84,85,86,105,106);
  2340. $workshop = array(7,8,17,18,27,28,47,48);
  2341. $greatworkshop = array(67,68,77,78,87,88,107,108);
  2342. $residence = array(9,10,19,20,29,30,49,50);
  2343. $trapper = array(99);
  2344. if(in_array($unit, $barracks)) {
  2345. $queued = $technology->getTrainingList(1);
  2346. } elseif(in_array($unit, $stables)) {
  2347. $queued = $technology->getTrainingList(2);
  2348. } elseif(in_array($unit, $workshop)) {
  2349. $queued = $technology->getTrainingList(3);
  2350. } elseif(in_array($unit, $residence)) {
  2351. $queued = $technology->getTrainingList(4);
  2352. } elseif(in_array($unit, $greatstables)) {
  2353. $queued = $technology->getTrainingList(6);
  2354. } elseif(in_array($unit, $greatbarracks)) {
  2355. $queued = $technology->getTrainingList(5);
  2356. } elseif(in_array($unit, $greatworkshop)) {
  2357. $queued = $technology->getTrainingList(7);
  2358. } elseif(in_array($unit, $trapper)) {
  2359. $queued = $technology->getTrainingList(8);
  2360. }
  2361. $now = time();
  2362. $uid = $this->getVillageField($vid, "owner");
  2363. $artefact = count($this->getOwnUniqueArtefactInfo2($uid,5,3,0));
  2364. $artefact1 = count($this->getOwnUniqueArtefactInfo2($vid,5,1,1));
  2365. $artefact2 = count($this->getOwnUniqueArtefactInfo2($uid,5,2,0));
  2366. if($artefact > 0){
  2367. $time = $now+round(($time-$now)/2);
  2368. $each /= 2;
  2369. $each = round($each);
  2370. }else if($artefact1 > 0){
  2371. $time = $now+round(($time-$now)/2);
  2372. $each /= 2;
  2373. $each = round($each);
  2374. }else if($artefact2 > 0){
  2375. $time = $now+round(($time-$now)/4*3);
  2376. $each /= 4;
  2377. $each = round($each);
  2378. $each *= 3;
  2379. $each = round($each);
  2380. }
  2381. $foolartefact = $this->getFoolArtefactInfo(5,$vid,$uid);
  2382. if(count($foolartefact) > 0){
  2383. foreach($foolartefact as $arte){
  2384. if($arte['bad_effect'] == 1){
  2385. $each *= $arte['effect2'];
  2386. }else{
  2387. $each /= $arte['effect2'];
  2388. $each = round($each);
  2389. }
  2390. }
  2391. }
  2392. if($each == 0){ $each = 1; }
  2393. $time2 = $now+$each;
  2394. if(count($queued) > 0) {
  2395. $time += $queued[count($queued) - 1]['timestamp'] - $now;
  2396. $time2 += $queued[count($queued) - 1]['timestamp'] - $now;
  2397. }
  2398. // TROOPS MAKE SUM IN BARAKS , ETC
  2399. //if($queued[count($queued) - 1]['unit'] == $unit){
  2400. //$time = $amt*$queued[count($queued) - 1]['eachtime'];
  2401. //$q = "UPDATE " . TB_PREFIX . "training SET amt = amt + $amt, timestamp = timestamp + $time WHERE id = ".$queued[count($queued) - 1]['id']."";
  2402. //}else{
  2403. $q = "INSERT INTO " . TB_PREFIX . "training values (0,$vid,$unit,$amt,$pop,$time,$each,$time2)";
  2404. //}
  2405. } else {
  2406. $q = "DELETE FROM " . TB_PREFIX . "training where id = $vid";
  2407. }
  2408. return mysql_query($q, $this->connection);
  2409. }
  2410. function updateTraining($id, $trained, $each) {
  2411. $q = "UPDATE " . TB_PREFIX . "training set amt = amt - $trained, timestamp2 = timestamp2 + $each where id = $id";
  2412. return mysql_query($q, $this->connection);
  2413. }
  2414. function modifyUnit($vref, $array_unit, $array_amt, $array_mode){
  2415. $i = -1;
  2416. $units='';
  2417. $number = count($array_unit);
  2418. foreach($array_unit as $unit){
  2419. if($unit == 230){$unit = 30;}
  2420. if($unit == 231){$unit = 31;}
  2421. if($unit == 120){$unit = 20;}
  2422. if($unit == 121){$unit = 21;}
  2423. if($unit =="hero"){$unit = 'hero';}
  2424. else{$unit = 'u' . $unit;}
  2425. ++$i;
  2426. $units .= $unit.' = '.$unit.' '.(($array_mode[$i] == 1)? '+':'-').' '.$array_amt[$i].(($number > $i+1) ? ', ' : '');
  2427. }
  2428. $q = "UPDATE ".TB_PREFIX."units set $units WHERE vref = $vref";
  2429. return mysql_query($q, $this->connection);
  2430. }
  2431. function getEnforce($vid, $from) {
  2432. $q = "SELECT * from " . TB_PREFIX . "enforcement where `from` = $from and vref = $vid";
  2433. $result = mysql_query($q, $this->connection);
  2434. return mysql_fetch_assoc($result);
  2435. }
  2436. function getOasisEnforce($ref, $mode=0) {
  2437. if (!$mode) {
  2438. $q = "SELECT e.*,o.conqured FROM ".TB_PREFIX."enforcement as e LEFT JOIN ".TB_PREFIX."odata as o ON e.vref=o.wref where o.conqured = $ref AND e.from !=$ref";
  2439. }else{
  2440. $q = "SELECT e.*,o.conqured FROM ".TB_PREFIX."enforcement as e LEFT JOIN ".TB_PREFIX."odata as o ON e.vref=o.wref where o.conqured = $ref";
  2441. }
  2442. $result = mysql_query($q, $this->connection);
  2443. return $this->mysql_fetch_all($result);
  2444. }
  2445. function getOasisEnforceArray($id, $mode=0) {
  2446. if (!$mode) {
  2447. $q = "SELECT e.*,o.conqured FROM ".TB_PREFIX."enforcement as e LEFT JOIN ".TB_PREFIX."odata as o ON e.vref=o.wref where e.id = $id";
  2448. }else{
  2449. $q = "SELECT e.*,o.conqured FROM ".TB_PREFIX."enforcement as e LEFT JOIN ".TB_PREFIX."odata as o ON e.from=o.wref where e.id =$id";
  2450. }
  2451. $result = mysql_query($q, $this->connection);
  2452. return mysql_fetch_assoc($result);
  2453. }
  2454. function getEnforceControllTroops($vid) {
  2455. $q = "SELECT * from " . TB_PREFIX . "enforcement where vref = $vid";
  2456. $result = mysql_query($q, $this->connection);
  2457. return mysql_fetch_assoc($result);
  2458. }
  2459. function addEnforce($data) {
  2460. $q = "INSERT into " . TB_PREFIX . "enforcement (vref,`from`) values (" . $data['to'] . "," . $data['from'] . ")";
  2461. mysql_query($q, $this->connection);
  2462. $id = mysql_insert_id($this->connection);
  2463. $owntribe = $this->getUserField($this->getVillageField($data['from'], "owner"), "tribe", 0);
  2464. $start = ($owntribe - 1) * 10 + 1;
  2465. $end = ($owntribe * 10);
  2466. //add unit
  2467. $j = '1';
  2468. for($i = $start; $i <= $end; $i++) {
  2469. $this->modifyEnforce($id, $i, $data['t' . $j . ''], 1);
  2470. $j++;
  2471. }
  2472. $this->modifyEnforce($id,'hero',$data['t11'],1);
  2473. return mysql_insert_id($this->connection);
  2474. }
  2475. function addEnforce2($data,$tribe,$dead1,$dead2,$dead3,$dead4,$dead5,$dead6,$dead7,$dead8,$dead9,$dead10,$dead11) {
  2476. $q = "INSERT into " . TB_PREFIX . "enforcement (vref,`from`) values (" . $data['to'] . "," . $data['from'] . ")";
  2477. mysql_query($q, $this->connection);
  2478. $id = mysql_insert_id($this->connection);
  2479. $owntribe = $this->getUserField($this->getVillageField($data['from'], "owner"), "tribe", 0);
  2480. $start = ($owntribe - 1) * 10 + 1;
  2481. $end = ($owntribe * 10);
  2482. $start2 = ($tribe - 1) * 10 + 1;
  2483. $start3 = ($tribe - 1) * 10;
  2484. if($start3 == 0){
  2485. $start3 = "";
  2486. }
  2487. $end2 = ($tribe * 10);
  2488. //add unit
  2489. $j = '1';
  2490. for($i = $start; $i <= $end; $i++) {
  2491. $this->modifyEnforce($id, $i, $data['t' . $j . ''], 1);
  2492. $this->modifyEnforce($id, $i, ${dead.$j}, 0);
  2493. $j++;
  2494. }
  2495. $this->modifyEnforce($id,'hero',$data['t11'],1);
  2496. $this->modifyEnforce($id,'hero',$dead11,0);
  2497. return mysql_insert_id($this->connection);
  2498. }
  2499. function modifyEnforce($id, $unit, $amt, $mode) {
  2500. if($unit != 'hero') { $unit = 'u' . $unit; }
  2501. if(!$mode) {
  2502. $q = "UPDATE " . TB_PREFIX . "enforcement set $unit = $unit - $amt where id = $id";
  2503. } else {
  2504. $q = "UPDATE " . TB_PREFIX . "enforcement set $unit = $unit + $amt where id = $id";
  2505. }
  2506. mysql_query($q, $this->connection);
  2507. }
  2508. function getEnforceArray($id, $mode) {
  2509. if(!$mode) {
  2510. $q = "SELECT * from " . TB_PREFIX . "enforcement where id = $id";
  2511. } else {
  2512. $q = "SELECT * from " . TB_PREFIX . "enforcement where `from` = $id";
  2513. }
  2514. $result = mysql_query($q, $this->connection);
  2515. return mysql_fetch_assoc($result);
  2516. }
  2517. function getEnforceVillage($id, $mode) {
  2518. if(!$mode) {
  2519. $q = "SELECT * from " . TB_PREFIX . "enforcement where vref = $id";
  2520. } else {
  2521. $q = "SELECT * from " . TB_PREFIX . "enforcement where `from` = $id";
  2522. }
  2523. $result = mysql_query($q, $this->connection);
  2524. return $this->mysql_fetch_all($result);
  2525. }
  2526. function getVillageMovement($id) {
  2527. $vinfo = $this->getVillage($id);
  2528. $vtribe = $this->getUserField($vinfo['owner'], "tribe", 0);
  2529. $movingunits = array();
  2530. $outgoingarray = $this->getMovement(3, $id, 0);
  2531. if(!empty($outgoingarray)) {
  2532. foreach($outgoingarray as $out) {
  2533. for($i = 1; $i <= 10; $i++) {
  2534. $movingunits['u' . (($vtribe - 1) * 10 + $i)] += $out['t' . $i];
  2535. }
  2536. $movingunits['hero'] += $out['t11'];
  2537. }
  2538. }
  2539. $returningarray = $this->getMovement(4, $id, 1);
  2540. if(!empty($returningarray)) {
  2541. foreach($returningarray as $ret) {
  2542. if($ret['attack_type'] != 1) {
  2543. for($i = 1; $i <= 10; $i++) {
  2544. $movingunits['u' . (($vtribe - 1) * 10 + $i)] += $ret['t' . $i];
  2545. }
  2546. $movingunits['hero'] += $ret['t11'];
  2547. }
  2548. }
  2549. }
  2550. $settlerarray = $this->getMovement(5, $id, 0);
  2551. if(!empty($settlerarray)) {
  2552. $movingunits['u' . ($vtribe * 10)] += 3 * count($settlerarray);
  2553. }
  2554. return $movingunits;
  2555. }
  2556. ################# -START- ##################
  2557. ## WORLD WONDER STATISTICS FUNCTIONS! ##
  2558. ############################################
  2559. /***************************
  2560. Function to get all World Wonders
  2561. Made by: Dzoki
  2562. ***************************/
  2563. function getWW() {
  2564. $q = "SELECT * FROM " . TB_PREFIX . "fdata WHERE f99t = 40";
  2565. $result = mysql_query($q, $this->connection);
  2566. if(mysql_num_rows($result)) {
  2567. return true;
  2568. } else {
  2569. return false;
  2570. }
  2571. }
  2572. /***************************
  2573. Function to get world wonder level!
  2574. Made by: Dzoki
  2575. ***************************/
  2576. function getWWLevel($vref) {
  2577. $q = "SELECT f99 FROM " . TB_PREFIX . "fdata WHERE vref = $vref";
  2578. $result = mysql_query($q, $this->connection) or die(mysql_error());
  2579. $dbarray = mysql_fetch_array($result);
  2580. return $dbarray['f99'];
  2581. }
  2582. /***************************
  2583. Function to get world wonder owner ID!
  2584. Made by: Dzoki
  2585. ***************************/
  2586. function getWWOwnerID($vref) {
  2587. $q = "SELECT owner FROM " . TB_PREFIX . "vdata WHERE wref = $vref";
  2588. $result = mysql_query($q, $this->connection) or die(mysql_error());
  2589. $dbarray = mysql_fetch_array($result);
  2590. return $dbarray['owner'];
  2591. }
  2592. /***************************
  2593. Function to get user alliance name!
  2594. Made by: Dzoki
  2595. ***************************/
  2596. function getUserAllianceID($id) {
  2597. $q = "SELECT alliance FROM " . TB_PREFIX . "users where id = $id";
  2598. $result = mysql_query($q, $this->connection) or die(mysql_error());
  2599. $dbarray = mysql_fetch_array($result);
  2600. return $dbarray['alliance'];
  2601. }
  2602. /***************************
  2603. Function to get WW name
  2604. Made by: Dzoki
  2605. ***************************/
  2606. function getWWName($vref) {
  2607. $q = "SELECT wwname FROM " . TB_PREFIX . "fdata WHERE vref = $vref";
  2608. $result = mysql_query($q, $this->connection) or die(mysql_error());
  2609. $dbarray = mysql_fetch_array($result);
  2610. return $dbarray['wwname'];
  2611. }
  2612. /***************************
  2613. Function to change WW name
  2614. Made by: Dzoki
  2615. ***************************/
  2616. function submitWWname($vref, $name) {
  2617. $q = "UPDATE " . TB_PREFIX . "fdata SET `wwname` = '$name' WHERE " . TB_PREFIX . "fdata.`vref` = $vref";
  2618. return mysql_query($q, $this->connection);
  2619. }
  2620. //medal functions
  2621. function addclimberpop($user, $cp) {
  2622. $q = "UPDATE " . TB_PREFIX . "users set Rc = Rc + '$cp' where id = $user";
  2623. return mysql_query($q, $this->connection);
  2624. }
  2625. function addclimberrankpop($user, $cp) {
  2626. $q = "UPDATE " . TB_PREFIX . "users set clp = clp + '$cp' where id = $user";
  2627. return mysql_query($q, $this->connection);
  2628. }
  2629. function removeclimberrankpop($user, $cp) {
  2630. $q = "UPDATE " . TB_PREFIX . "users set clp = clp - '$cp' where id = $user";
  2631. return mysql_query($q, $this->connection);
  2632. }
  2633. function setclimberrankpop($user, $cp) {
  2634. $q = "UPDATE " . TB_PREFIX . "users set clp = '$cp' where id = $user";
  2635. return mysql_query($q, $this->connection);
  2636. }
  2637. function updateoldrank($user, $cp) {
  2638. $q = "UPDATE " . TB_PREFIX . "users set oldrank = '$cp' where id = $user";
  2639. return mysql_query($q, $this->connection);
  2640. }
  2641. function removeclimberpop($user, $cp) {
  2642. $q = "UPDATE " . TB_PREFIX . "users set Rc = Rc - '$cp' where id = $user";
  2643. return mysql_query($q, $this->connection);
  2644. }
  2645. // ALLIANCE MEDAL FUNCTIONS
  2646. function addclimberpopAlly($user, $cp) {
  2647. $q = "UPDATE " . TB_PREFIX . "alidata set Rc = Rc + '$cp' where id = $user";
  2648. return mysql_query($q, $this->connection);
  2649. }
  2650. function addclimberrankpopAlly($user, $cp) {
  2651. $q = "UPDATE " . TB_PREFIX . "alidata set clp = clp + '$cp' where id = $user";
  2652. return mysql_query($q, $this->connection);
  2653. }
  2654. function removeclimberrankpopAlly($user, $cp) {
  2655. $q = "UPDATE " . TB_PREFIX . "alidata set clp = clp - '$cp'' where id = $user";
  2656. return mysql_query($q, $this->connection);
  2657. }
  2658. function updateoldrankAlly($user, $cp) {
  2659. $q = "UPDATE " . TB_PREFIX . "alidata set oldrank = '$cp' where id = $user";
  2660. return mysql_query($q, $this->connection);
  2661. }
  2662. function removeclimberpopAlly($user, $cp) {
  2663. $q = "UPDATE " . TB_PREFIX . "alidata set Rc = Rc - '$cp' where id = $user";
  2664. return mysql_query($q, $this->connection);
  2665. }
  2666. function getTrainingList() {
  2667. $q = "SELECT * FROM " . TB_PREFIX . "training where vref != ''";
  2668. $result = mysql_query($q, $this->connection);
  2669. return $this->mysql_fetch_all($result);
  2670. }
  2671. function getNeedDelete() {
  2672. $time = time();
  2673. $q = "SELECT uid FROM " . TB_PREFIX . "deleting where timestamp < $time";
  2674. $result = mysql_query($q, $this->connection);
  2675. return $this->mysql_fetch_all($result);
  2676. }
  2677. function countUser() {
  2678. $q = "SELECT count(id) FROM " . TB_PREFIX . "users where id > 5";
  2679. $result = mysql_query($q, $this->connection);
  2680. $row = mysql_fetch_row($result);
  2681. return $row[0];
  2682. }
  2683. function countAlli() {
  2684. $q = "SELECT count(id) FROM " . TB_PREFIX . "alidata where id != 0";
  2685. $result = mysql_query($q, $this->connection);
  2686. $row = mysql_fetch_row($result);
  2687. return $row[0];
  2688. }
  2689. /***************************
  2690. Function to process MYSQLi->fetch_all (Only exist in MYSQL)
  2691. References: Result
  2692. ***************************/
  2693. function mysql_fetch_all($result) {
  2694. $all = array();
  2695. if($result) {
  2696. while($row = mysql_fetch_assoc($result)) {
  2697. $all[] = $row;
  2698. }
  2699. return $all;
  2700. }
  2701. }
  2702. function query_return($q) {
  2703. $result = mysql_query($q, $this->connection);
  2704. return $this->mysql_fetch_all($result);
  2705. }
  2706. /***************************
  2707. Function to do free query
  2708. References: Query
  2709. ***************************/
  2710. function query($query) {
  2711. return mysql_query($query, $this->connection);
  2712. }
  2713. function RemoveXSS($val) {
  2714. return htmlspecialchars($val, ENT_QUOTES);
  2715. }
  2716. //MARKET FIXES
  2717. function getWoodAvailable($wref) {
  2718. $q = "SELECT wood FROM " . TB_PREFIX . "vdata WHERE wref = $wref";
  2719. $result = mysql_query($q, $this->connection) or die(mysql_error());
  2720. $dbarray = mysql_fetch_array($result);
  2721. return $dbarray['wood'];
  2722. }
  2723. function getClayAvailable($wref) {
  2724. $q = "SELECT clay FROM " . TB_PREFIX . "vdata WHERE wref = $wref";
  2725. $result = mysql_query($q, $this->connection) or die(mysql_error());
  2726. $dbarray = mysql_fetch_array($result);
  2727. return $dbarray['clay'];
  2728. }
  2729. function getIronAvailable($wref) {
  2730. $q = "SELECT iron FROM " . TB_PREFIX . "vdata WHERE wref = $wref";
  2731. $result = mysql_query($q, $this->connection) or die(mysql_error());
  2732. $dbarray = mysql_fetch_array($result);
  2733. return $dbarray['iron'];
  2734. }
  2735. function getCropAvailable($wref) {
  2736. $q = "SELECT crop FROM " . TB_PREFIX . "vdata WHERE wref = $wref";
  2737. $result = mysql_query($q, $this->connection) or die(mysql_error());
  2738. $dbarray = mysql_fetch_array($result);
  2739. return $dbarray['crop'];
  2740. }
  2741. function Getowner($vid) {
  2742. $s = "SELECT owner FROM " . TB_PREFIX . "vdata where wref = $vid";
  2743. $result1 = mysql_query($s, $this->connection);
  2744. $row1 = mysql_fetch_row($result1);
  2745. return $row1[0];
  2746. }
  2747. public function debug($time, $uid, $debug_info) {
  2748. $q = "INSERT INTO " . TB_PREFIX . "debug_info (time,uid,debug_info) VALUES ($time,$uid,$debug_info)";
  2749. if(mysql_query($q, $this->connection)) {
  2750. return mysql_insert_id($this->connection);
  2751. } else {
  2752. return false;
  2753. }
  2754. }
  2755. function populateOasisdata() {
  2756. $q2 = "SELECT * FROM " . TB_PREFIX . "wdata where oasistype != 0";
  2757. $result2 = mysql_query($q2, $this->connection);
  2758. while($row = mysql_fetch_array($result2)) {
  2759. $wid = $row['id'];
  2760. $basearray = $this->getOMInfo($wid);
  2761. if($basearray['oasistype'] < 4) {
  2762. $high = 1;
  2763. } else if ($basearray['oasistype'] < 10){
  2764. $high = 2;
  2765. }else {
  2766. $high = 0;
  2767. }
  2768. //We switch type of oasis and instert record with apropriate infomation.
  2769. $q = "INSERT into " . TB_PREFIX . "odata VALUES ('" . $basearray['id'] . "'," . $basearray['oasistype'] . ",0,800,800,800,800,800,800," . time() . "," . time() . ",100,2,'Unoccupied Oasis',".$high.")";
  2770. $result = mysql_query($q, $this->connection);
  2771. }
  2772. }
  2773. public function getAvailableExpansionTraining() {
  2774. global $building, $session, $technology, $village;
  2775. $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";
  2776. $result = mysql_query($q, $this->connection);
  2777. $row = mysql_fetch_row($result);
  2778. $maxslots = $row[0];
  2779. $residence = $building->getTypeLevel(25);
  2780. $palace = $building->getTypeLevel(26);
  2781. if($residence > 0) {
  2782. $maxslots -= (3 - floor($residence / 10));
  2783. }
  2784. if($palace > 0) {
  2785. $maxslots -= (3 - floor(($palace - 5) / 5));
  2786. }
  2787. $q = "SELECT (u10+u20+u30) FROM " . TB_PREFIX . "units WHERE vref = $village->wid";
  2788. $result = mysql_query($q, $this->connection);
  2789. $row = mysql_fetch_row($result);
  2790. $settlers = $row[0];
  2791. $q = "SELECT (u9+u19+u29) FROM " . TB_PREFIX . "units WHERE vref = $village->wid";
  2792. $result = mysql_query($q, $this->connection);
  2793. $row = mysql_fetch_row($result);
  2794. $chiefs = $row[0];
  2795. $settlers += 3 * count($this->getMovement(5, $village->wid, 0));
  2796. $current_movement = $this->getMovement(3, $village->wid, 0);
  2797. if(!empty($current_movement)) {
  2798. foreach($current_movement as $build) {
  2799. $settlers += $build['t10'];
  2800. $chiefs += $build['t9'];
  2801. }
  2802. }
  2803. $current_movement = $this->getMovement(3, $village->wid, 1);
  2804. if(!empty($current_movement)) {
  2805. foreach($current_movement as $build) {
  2806. $settlers += $build['t10'];
  2807. $chiefs += $build['t9'];
  2808. }
  2809. }
  2810. $current_movement = $this->getMovement(4, $village->wid, 0);
  2811. if(!empty($current_movement)) {
  2812. foreach($current_movement as $build) {
  2813. $settlers += $build['t10'];
  2814. $chiefs += $build['t9'];
  2815. }
  2816. }
  2817. $current_movement = $this->getMovement(4, $village->wid, 1);
  2818. if(!empty($current_movement)) {
  2819. foreach($current_movement as $build) {
  2820. $settlers += $build['t10'];
  2821. $chiefs += $build['t9'];
  2822. }
  2823. }
  2824. $q = "SELECT (u10+u20+u30) FROM " . TB_PREFIX . "enforcement WHERE `from` = $village->wid";
  2825. $result = mysql_query($q, $this->connection);
  2826. $row = mysql_fetch_row($result);
  2827. if(!empty($row)) {
  2828. foreach($row as $reinf) {
  2829. $settlers += $reinf[0];
  2830. }
  2831. }
  2832. $q = "SELECT (u9+u19+u29) FROM " . TB_PREFIX . "enforcement WHERE `from` = $village->wid";
  2833. $result = mysql_query($q, $this->connection);
  2834. $row = mysql_fetch_row($result);
  2835. if(!empty($row)) {
  2836. foreach($row as $reinf) {
  2837. $chiefs += $reinf[0];
  2838. }
  2839. }
  2840. $trainlist = $technology->getTrainingList(4);
  2841. if(!empty($trainlist)) {
  2842. foreach($trainlist as $train) {
  2843. if($train['unit'] % 10 == 0) {
  2844. $settlers += $train['amt'];
  2845. }
  2846. if($train['unit'] % 10 == 9) {
  2847. $chiefs += $train['amt'];
  2848. }
  2849. }
  2850. }
  2851. // trapped settlers/chiefs calculation required
  2852. $settlerslots = $maxslots * 3 - $settlers - $chiefs * 3;
  2853. $chiefslots = $maxslots - $chiefs - floor(($settlers + 2) / 3);
  2854. if(!$technology->getTech(($session->tribe - 1) * 10 + 9)) {
  2855. $chiefslots = 0;
  2856. }
  2857. $slots = array("chiefs" => $chiefslots, "settlers" => $settlerslots);
  2858. return $slots;
  2859. }
  2860. function addArtefact($vref, $owner, $type, $size, $name, $desc, $effect, $img) {
  2861. $q = "INSERT INTO `" . TB_PREFIX . "artefacts` (`vref`, `owner`, `type`, `size`, `conquered`, `name`, `desc`, `effect`, `img`, `active`) VALUES ('$vref', '$owner', '$type', '$size', '" . time() . "', '$name', '$desc', '$effect', '$img', '0')";
  2862. return mysql_query($q, $this->connection);
  2863. }
  2864. function getOwnArtefactInfo($vref) {
  2865. $q = "SELECT * FROM " . TB_PREFIX . "artefacts WHERE vref = $vref";
  2866. $result = mysql_query($q, $this->connection);
  2867. return mysql_fetch_array($result);
  2868. }
  2869. function getOwnArtefactInfo2($vref) {
  2870. $q = "SELECT * FROM " . TB_PREFIX . "artefacts WHERE vref = $vref";
  2871. $result = mysql_query($q, $this->connection);
  2872. return $this->mysql_fetch_all($result);
  2873. }
  2874. function getOwnArtefactInfo3($uid) {
  2875. $q = "SELECT * FROM " . TB_PREFIX . "artefacts WHERE owner = $uid";
  2876. $result = mysql_query($q, $this->connection);
  2877. return $this->mysql_fetch_all($result);
  2878. }
  2879. function getOwnArtefactInfoByType($vref, $type) {
  2880. $q = "SELECT * FROM " . TB_PREFIX . "artefacts WHERE vref = $vref AND type = $type order by size";
  2881. $result = mysql_query($q, $this->connection);
  2882. return mysql_fetch_array($result);
  2883. }
  2884. function getOwnArtefactInfoByType2($vref, $type) {
  2885. $q = "SELECT * FROM " . TB_PREFIX . "artefacts WHERE vref = $vref AND type = $type";
  2886. $result = mysql_query($q, $this->connection);
  2887. return $this->mysql_fetch_all($result);
  2888. }
  2889. function getOwnUniqueArtefactInfo($id, $type, $size) {
  2890. $q = "SELECT * FROM " . TB_PREFIX . "artefacts WHERE owner = $id AND type = $type AND size=$size";
  2891. $result = mysql_query($q, $this->connection);
  2892. return mysql_fetch_array($result);
  2893. }
  2894. function getOwnUniqueArtefactInfo2($id, $type, $size, $mode) {
  2895. if(!$mode){
  2896. $q = "SELECT * FROM " . TB_PREFIX . "artefacts WHERE owner = $id AND active = 1 AND type = $type AND size=$size";
  2897. }else{
  2898. $q = "SELECT * FROM " . TB_PREFIX . "artefacts WHERE vref = $id AND active = 1 AND type = $type AND size=$size";
  2899. }
  2900. $result = mysql_query($q, $this->connection);
  2901. return $this->mysql_fetch_all($result);
  2902. }
  2903. function getFoolArtefactInfo($type,$vid,$uid) {
  2904. $q = "SELECT * FROM " . TB_PREFIX . "artefacts WHERE vref = $vid AND type = 8 AND kind = $type OR owner = $uid AND size > 1 AND active = 1 AND type = 8 AND kind = $type";
  2905. $result = mysql_query($q, $this->connection);
  2906. return $this->mysql_fetch_all($result);
  2907. }
  2908. function claimArtefact($vref, $ovref, $id) {
  2909. $time = time();
  2910. $q = "UPDATE " . TB_PREFIX . "artefacts SET vref = $vref, owner = $id, conquered = $time, active = 1 WHERE vref = $ovref";
  2911. return mysql_query($q, $this->connection);
  2912. }
  2913. public function canClaimArtifact($from,$vref,$size,$type) {
  2914. //fix by Ronix
  2915. global $session, $form;
  2916. $size1 = $size2 = $size3 = 0;
  2917. $artifact = $this->getOwnArtefactInfo($from);
  2918. if (!empty($artifact)) {
  2919. $form->addError("error","Treasury is full. Your hero could not claim the artefact");
  2920. return false;
  2921. }
  2922. $uid=$session->uid;
  2923. $q="SELECT Count(size) AS totals,
  2924. SUM(IF(size = '1',1,0)) small,
  2925. SUM(IF(size = '2',1,0)) great,
  2926. SUM(IF(size = '3',1,0)) `unique`
  2927. FROM ".TB_PREFIX."artefacts WHERE owner = ".$uid;
  2928. $result = mysql_query($q, $this->connection);
  2929. $artifact= $this->mysql_fetch_all($result);
  2930. if($artifact['totals'] < 3 || $type==11) {
  2931. $DefenderFields = $this->getResourceLevel($vref);
  2932. $defcanclaim = TRUE;
  2933. for($i=19;$i<=38;$i++) {
  2934. if($DefenderFields['f'.$i.'t'] == 27) {
  2935. $defTresuaryLevel = $DefenderFields['f'.$i];
  2936. if($defTresuaryLevel > 0) {
  2937. $defcanclaim = FALSE;
  2938. $form->addError("error","Treasury has not been destroyed. Your hero could not claim the artefact");
  2939. return false;
  2940. } else {
  2941. $defcanclaim = TRUE;
  2942. }
  2943. }
  2944. }
  2945. $AttackerFields = $this->getResourceLevel($from,2);
  2946. for($i=19;$i<=38;$i++) {
  2947. if($AttackerFields['f'.$i.'t'] == 27) {
  2948. $attTresuaryLevel = $AttackerFields['f'.$i];
  2949. if ($attTresuaryLevel >= 10) {
  2950. $villageartifact = TRUE;
  2951. } else {
  2952. $villageartifact = FALSE;
  2953. }
  2954. if ($attTresuaryLevel >= 20){
  2955. $accountartifact = TRUE;
  2956. } else {
  2957. $accountartifact = FALSE;
  2958. }
  2959. }
  2960. }
  2961. if (($artifact['great']>0 || $artifact['unique']>0) && $size>1) {
  2962. $form->addError("error","Max num. of great/unique artefacts. Your hero could not claim the artefact");
  2963. return FALSE;
  2964. }
  2965. if (($size == 1 && ($villageartifact || $accountartifact)) || (($size == 2 || $size == 3)&& $accountartifact)) {
  2966. return true;
  2967. /*
  2968. if($this->getVillageField($from,"capital")==1 && $type==11) {
  2969. $form->addError("error","Ancient Construction Plan cannot kept in capital village");
  2970. return FALSE;
  2971. }else{
  2972. return TRUE;
  2973. }
  2974. */
  2975. } else {
  2976. $form->addError("error","Your level treasury is low. Your hero could not claim the artefact");
  2977. return FALSE;
  2978. }
  2979. } else {
  2980. $form->addError("error","Max num. of artefacts. Your hero could not claim the artefact");
  2981. return FALSE;
  2982. }
  2983. }
  2984. function getArtefactDetails($id) {
  2985. $q = "SELECT * FROM " . TB_PREFIX . "artefacts WHERE id = " . $id . "";
  2986. $result = mysql_query($q, $this->connection);
  2987. return mysql_fetch_array($result);
  2988. }
  2989. function getMovementById($id){
  2990. $q = "SELECT * FROM ".TB_PREFIX."movement WHERE moveid = ".$id."";
  2991. $result = mysql_query($q);
  2992. $array = $this->mysql_fetch_all($result);
  2993. return $array;
  2994. }
  2995. function getLinks($id){
  2996. $q = 'SELECT * FROM `' . TB_PREFIX . 'links` WHERE `userid` = ' . $id . ' ORDER BY `pos` ASC';
  2997. return mysql_query($q, $this->connection);
  2998. }
  2999. function removeLinks($id,$uid){
  3000. $q = "DELETE FROM " . TB_PREFIX . "links WHERE `id` = ".$id." and `userid` = ".$uid."";
  3001. return mysql_query($q, $this->connection);
  3002. }
  3003. function getVilFarmlist($wref){
  3004. $q = 'SELECT * FROM ' . TB_PREFIX . 'farmlist WHERE wref = ' . $wref . ' ORDER BY wref ASC';
  3005. $result = mysql_query($q, $this->connection);
  3006. $dbarray = mysql_fetch_array($result);
  3007. if($dbarray['id']!=0) {
  3008. return true;
  3009. } else {
  3010. return false;
  3011. }
  3012. }
  3013. function getRaidList($id) {
  3014. $q = "SELECT * FROM " . TB_PREFIX . "raidlist WHERE id = ".$id."";
  3015. $result = mysql_query($q, $this->connection);
  3016. return mysql_fetch_array($result);
  3017. }
  3018. function delFarmList($id, $owner) {
  3019. $q = "DELETE FROM " . TB_PREFIX . "farmlist where id = $id and owner = $owner";
  3020. return mysql_query($q, $this->connection);
  3021. }
  3022. function delSlotFarm($id) {
  3023. $q = "DELETE FROM " . TB_PREFIX . "raidlist where id = $id";
  3024. return mysql_query($q, $this->connection);
  3025. }
  3026. function createFarmList($wref, $owner, $name) {
  3027. $q = "INSERT INTO " . TB_PREFIX . "farmlist (`wref`, `owner`, `name`) VALUES ('$wref', '$owner', '$name')";
  3028. return mysql_query($q, $this->connection);
  3029. }
  3030. function addSlotFarm($lid, $towref, $x, $y, $distance, $t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10) {
  3031. $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')";
  3032. return mysql_query($q, $this->connection);
  3033. }
  3034. function editSlotFarm($eid, $lid, $wref, $x, $y, $dist, $t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10) {
  3035. $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";
  3036. return mysql_query($q, $this->connection);
  3037. }
  3038. function getArrayMemberVillage($uid){
  3039. $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';
  3040. $result = mysql_query($q, $this->connection);
  3041. $array = $this->mysql_fetch_all($result);
  3042. return $array;
  3043. }
  3044. function addPassword($uid, $npw, $cpw){
  3045. $q = "REPLACE INTO `" . TB_PREFIX . "password`(uid, npw, cpw) VALUES ($uid, '$npw', '$cpw')";
  3046. mysql_query($q, $this->connection) or die(mysql_error());
  3047. }
  3048. function resetPassword($uid, $cpw){
  3049. $q = "SELECT npw FROM `" . TB_PREFIX . "password` WHERE uid = $uid AND cpw = '$cpw' AND used = 0";
  3050. $result = mysql_query($q, $this->connection) or die(mysql_error());
  3051. $dbarray = mysql_fetch_array($result);
  3052. if(!empty($dbarray)) {
  3053. if(!$this->updateUserField($uid, 'password', md5($dbarray['npw']), 1)) return false;
  3054. $q = "UPDATE `" . TB_PREFIX . "password` SET used = 1 WHERE uid = $uid AND cpw = '$cpw' AND used = 0";
  3055. mysql_query($q, $this->connection) or die(mysql_error());
  3056. return true;
  3057. }
  3058. return false;
  3059. }
  3060. function getCropProdstarv($wref) {
  3061. global $bid4,$bid8,$bid9,$sesion,$technology;
  3062. $basecrop = $grainmill = $bakery = 0;
  3063. $owner = $this->getVrefField($wref, 'owner');
  3064. $bonus = $this->getUserField($owner, 'b4', 0);
  3065. $buildarray = $this->getResourceLevel($wref);
  3066. $cropholder = array();
  3067. for($i=1;$i<=38;$i++) {
  3068. if($buildarray['f'.$i.'t'] == 4) {
  3069. array_push($cropholder,'f'.$i);
  3070. }
  3071. if($buildarray['f'.$i.'t'] == 8) {
  3072. $grainmill = $buildarray['f'.$i];
  3073. }
  3074. if($buildarray['f'.$i.'t'] == 9) {
  3075. $bakery = $buildarray['f'.$i];
  3076. }
  3077. }
  3078. $q = "SELECT type FROM `" . TB_PREFIX . "odata` WHERE conqured = $wref";
  3079. $oasis = $this->query_return($q);
  3080. foreach($oasis as $oa){
  3081. switch($oa['type']) {
  3082. case 1:
  3083. case 2:
  3084. $wood += 1;
  3085. break;
  3086. case 3:
  3087. $wood += 1;
  3088. $cropo += 1;
  3089. break;
  3090. case 4:
  3091. case 5:
  3092. $clay += 1;
  3093. break;
  3094. case 6:
  3095. $clay += 1;
  3096. $cropo += 1;
  3097. break;
  3098. case 7:
  3099. case 8:
  3100. $iron += 1;
  3101. break;
  3102. case 9:
  3103. $iron += 1;
  3104. $cropo += 1;
  3105. break;
  3106. case 10:
  3107. case 11:
  3108. $cropo += 1;
  3109. break;
  3110. case 12:
  3111. $cropo += 2;
  3112. break;
  3113. }
  3114. }
  3115. for($i=0;$i<=count($cropholder)-1;$i++) { $basecrop+= $bid4[$buildarray[$cropholder[$i]]]['prod']; }
  3116. $crop = $basecrop + $basecrop * 0.25 * $cropo;
  3117. if($grainmill >= 1 || $bakery >= 1) {
  3118. $crop += $basecrop /100 * ($bid8[$grainmill]['attri'] + $bid9[$bakery]['attri']);
  3119. }
  3120. if($bonus > time()) {
  3121. $crop *= 1.25;
  3122. }
  3123. $crop *= SPEED;
  3124. return $crop;
  3125. }
  3126. //general statistics
  3127. function addGeneralAttack($casualties) {
  3128. $time = time();
  3129. $q = "INSERT INTO " . TB_PREFIX . "general values (0,'$casualties','$time',1)";
  3130. return mysql_query($q, $this->connection) or die(mysql_error());
  3131. }
  3132. function getAttackByDate($time) {
  3133. $q = "SELECT * FROM " . TB_PREFIX . "general where shown = 1";
  3134. $result = $this->query_return($q);
  3135. $attack = 0;
  3136. foreach($result as $general){
  3137. if(date("j. M",$time) == date("j. M",$general['time'])){
  3138. $attack += 1;
  3139. }
  3140. }
  3141. return $attack;
  3142. }
  3143. function getAttackCasualties($time) {
  3144. $q = "SELECT * FROM " . TB_PREFIX . "general where shown = 1";
  3145. $result = $this->query_return($q);
  3146. $casualties = 0;
  3147. foreach($result as $general){
  3148. if(date("j. M",$time) == date("j. M",$general['time'])){
  3149. $casualties += $general['casualties'];
  3150. }
  3151. }
  3152. return $casualties;
  3153. }
  3154. //end general statistics
  3155. function addFriend($uid, $column, $friend) {
  3156. $q = "UPDATE " . TB_PREFIX . "users SET $column = $friend WHERE id = $uid";
  3157. return mysql_query($q, $this->connection);
  3158. }
  3159. function deleteFriend($uid, $column) {
  3160. $q = "UPDATE " . TB_PREFIX . "users SET $column = 0 WHERE id = $uid";
  3161. return mysql_query($q, $this->connection);
  3162. }
  3163. function checkFriends($uid) {
  3164. $user = $this->getUserArray($uid, 1);
  3165. for($i=0;$i<=19;$i++) {
  3166. if($user['friend'.$i] == 0 && $user['friend'.$i.'wait'] == 0){
  3167. for($j=$i+1;$j<=19;$j++) {
  3168. $k = $j-1;
  3169. if($user['friend'.$j] != 0){
  3170. $friend = $this->getUserField($uid, "friend".$j, 0);
  3171. $this->addFriend($uid,"friend".$k,$friend);
  3172. $this->deleteFriend($uid,"friend".$j);
  3173. }
  3174. if($user['friend'.$j.'wait'] == 0){
  3175. $friendwait = $this->getUserField($uid, "friend".$j."wait", 0);
  3176. $this->addFriend($sessionuid,"friend".$k."wait",$friendwait);
  3177. $this->deleteFriend($uid,"friend".$j."wait");
  3178. }
  3179. }
  3180. }
  3181. }
  3182. }
  3183. function setVillageEvasion($vid) {
  3184. $village = $this->getVillage($vid);
  3185. if($village['evasion'] == 0){
  3186. $q = "UPDATE " . TB_PREFIX . "vdata SET evasion = 1 WHERE wref = $vid";
  3187. }else{
  3188. $q = "UPDATE " . TB_PREFIX . "vdata SET evasion = 0 WHERE wref = $vid";
  3189. }
  3190. return mysql_query($q, $this->connection);
  3191. }
  3192. function addPrisoners($wid,$from,$t1,$t2,$t3,$t4,$t5,$t6,$t7,$t8,$t9,$t10,$t11) {
  3193. $q = "INSERT INTO " . TB_PREFIX . "prisoners values (0,$wid,$from,$t1,$t2,$t3,$t4,$t5,$t6,$t7,$t8,$t9,$t10,$t11)";
  3194. mysql_query($q, $this->connection);
  3195. return mysql_insert_id($this->connection);
  3196. }
  3197. function updatePrisoners($wid,$from,$t1,$t2,$t3,$t4,$t5,$t6,$t7,$t8,$t9,$t10,$t11) {
  3198. $q = "UPDATE " . TB_PREFIX . "prisoners set t1 = t1 + $t1, t2 = t2 + $t2, t3 = t3 + $t3, t4 = t4 + $t4, t5 = t5 + $t5, t6 = t6 + $t6, t7 = t7 + $t7, t8 = t8 + $t8, t9 = t9 + $t9, t10 = t10 + $t10, t11 = t11 + $t11 where wref = $wid and ".TB_PREFIX."prisoners.from = $from";
  3199. return mysql_query($q, $this->connection) or die(mysql_error());
  3200. }
  3201. function getPrisoners($wid,$mode=0) {
  3202. if(!$mode) {
  3203. $q = "SELECT * FROM " . TB_PREFIX . "prisoners where wref = $wid";
  3204. }else {
  3205. $q = "SELECT * FROM " . TB_PREFIX . "prisoners where `from` = $wid";
  3206. }
  3207. $result = mysql_query($q, $this->connection);
  3208. return $this->mysql_fetch_all($result);
  3209. }
  3210. function getPrisoners2($wid,$from) {
  3211. $q = "SELECT * FROM " . TB_PREFIX . "prisoners where wref = $wid and " . TB_PREFIX . "prisoners.from = $from";
  3212. $result = mysql_query($q, $this->connection);
  3213. return $this->mysql_fetch_all($result);
  3214. }
  3215. function getPrisonersByID($id) {
  3216. $q = "SELECT * FROM " . TB_PREFIX . "prisoners where id = $id";
  3217. $result = mysql_query($q, $this->connection);
  3218. return mysql_fetch_array($result);
  3219. }
  3220. function getPrisoners3($from) {
  3221. $q = "SELECT * FROM " . TB_PREFIX . "prisoners where " . TB_PREFIX . "prisoners.from = $from";
  3222. $result = mysql_query($q, $this->connection);
  3223. return $this->mysql_fetch_all($result);
  3224. }
  3225. function deletePrisoners($id) {
  3226. $q = "DELETE from " . TB_PREFIX . "prisoners where id = '$id'";
  3227. mysql_query($q, $this->connection);
  3228. }
  3229. /*****************************************
  3230. Function to vacation mode - by advocaite
  3231. References:
  3232. *****************************************/
  3233. function setvacmode($uid,$days){
  3234. $days1 =60*60*24*$days;
  3235. $time =time()+$days1;
  3236. $q ="UPDATE ".TB_PREFIX."users SET vac_mode = '1' , vac_time=".$time." WHERE id=".$uid."";
  3237. $result =mysql_query($q,$this->connection);
  3238. }
  3239. function removevacationmode($uid){
  3240. $q ="UPDATE ".TB_PREFIX."users SET vac_mode = '0' , vac_time='0' WHERE id=".$uid."";
  3241. $result =mysql_query($q,$this->connection);
  3242. }
  3243. function getvacmodexy($wref){
  3244. $q = "SELECT id,oasistype,occupied FROM " . TB_PREFIX . "wdata where id = $wref";
  3245. $result = mysql_query($q, $this->connection);
  3246. $dbarray = mysql_fetch_array($result);
  3247. if($dbarray['occupied'] != 0 && $dbarray['oasistype'] == 0) {
  3248. $q1 = "SELECT owner FROM " . TB_PREFIX . "vdata where wref = ".$dbarray['id']."";
  3249. $result1 = mysql_query($q1, $this->connection);
  3250. $dbarray1 = mysql_fetch_array($result1);
  3251. if($dbarray1['owner'] != 0){
  3252. $q2 = "SELECT vac_mode,vac_time FROM " . TB_PREFIX . "users where id = ".$dbarray1['owner']."";
  3253. $result2 = mysql_query($q2, $this->connection);
  3254. $dbarray2 = mysql_fetch_array($result2);
  3255. if($dbarray2['vac_mode'] ==1){
  3256. return true;
  3257. }else{
  3258. return false;
  3259. }
  3260. }
  3261. } else {
  3262. return false;
  3263. }
  3264. }
  3265. /*****************************************
  3266. Function to vacation mode - by advocaite
  3267. References:
  3268. *****************************************/
  3269. /***************************
  3270. Function to get Hero Dead
  3271. Made by: Shadow and brainiacX
  3272. ***************************/
  3273. function getHeroDead($id) {
  3274. $q = "SELECT dead FROM " . TB_PREFIX . "hero WHERE `uid` = $id";
  3275. $result = mysql_query($q, $this->connection);
  3276. $notend= mysql_fetch_array($result);
  3277. return $notend['dead'];
  3278. }
  3279. /***************************
  3280. Function to get Hero In Revive
  3281. Made by: Shadow
  3282. ***************************/
  3283. function getHeroInRevive($id) {
  3284. $q = "SELECT inrevive FROM " . TB_PREFIX . "hero WHERE `uid` = $id";
  3285. $result = mysql_query($q, $this->connection);
  3286. $notend= mysql_fetch_array($result);
  3287. return $notend['inrevive'];
  3288. }
  3289. /***************************
  3290. Function to get Hero In Train
  3291. Made by: Shadow
  3292. ***************************/
  3293. function getHeroInTraining($id) {
  3294. $q = "SELECT intraining FROM " . TB_PREFIX . "hero WHERE `uid` = $id";
  3295. $result = mysql_query($q, $this->connection);
  3296. $notend= mysql_fetch_array($result);
  3297. return $notend['intraining'];
  3298. }
  3299. /***************************
  3300. Function to check Hero Not in Village
  3301. Made by: Shadow and brainiacX
  3302. ***************************/
  3303. function HeroNotInVil($id) {
  3304. $heronum=0;
  3305. $outgoingarray = $this->getMovement(3, $id, 0);
  3306. if(!empty($outgoingarray)) {
  3307. foreach($outgoingarray as $out) {
  3308. $heronum += $out['t11'];
  3309. }
  3310. }
  3311. $returningarray = $this->getMovement(4, $id, 1);
  3312. if(!empty($returningarray)) {
  3313. foreach($returningarray as $ret) {
  3314. if($ret['attack_type'] != 1) {
  3315. $heronum += $ret['t11'];
  3316. }
  3317. }
  3318. }
  3319. return $heronum;
  3320. }
  3321. /***************************
  3322. Function to Kill hero if not found
  3323. Made by: Shadow and brainiacX
  3324. ***************************/
  3325. function KillMyHero($id) {
  3326. $q = "UPDATE " . TB_PREFIX . "hero set dead = 1 where uid = ".$id;
  3327. return mysql_query($q, $this->connection);
  3328. }
  3329. /***************************
  3330. Function checkAttack
  3331. Made by: Shadow
  3332. ***************************/
  3333. function checkAttack($wref, $toWref){
  3334. $q = "SELECT * FROM " . TB_PREFIX . "movement, " . TB_PREFIX . "attacks where " . TB_PREFIX . "movement.from = $wref and " . TB_PREFIX . "movement.to = $toWref and " . TB_PREFIX . "movement.ref = " . TB_PREFIX . "attacks.id and " . TB_PREFIX . "movement.proc = 0 and " . TB_PREFIX . "movement.sort_type = 3 and (" . TB_PREFIX . "attacks.attack_type = 3 or " . TB_PREFIX . "attacks.attack_type = 4) ORDER BY endtime ASC";
  3335. $result = mysql_query($q, $this->connection);
  3336. if(mysql_num_rows($result)) {
  3337. return true;
  3338. } else {
  3339. return false;
  3340. }
  3341. }
  3342. /***************************
  3343. Function checkEnforce
  3344. Made by: Shadow
  3345. ***************************/
  3346. function checkEnforce($wref, $toWref) {
  3347. $q = "SELECT * FROM " . TB_PREFIX . "movement, " . TB_PREFIX . "attacks where " . TB_PREFIX . "movement.from = $wref and " . TB_PREFIX . "movement.to = $toWref and " . TB_PREFIX . "movement.ref = " . TB_PREFIX . "attacks.id and " . TB_PREFIX . "movement.proc = 0 and " . TB_PREFIX . "movement.sort_type = 3 and " . TB_PREFIX . "attacks.attack_type = 2 ORDER BY endtime ASC";
  3348. $result = mysql_query($q, $this->connection);
  3349. if(mysql_num_rows($result)) {
  3350. return true;
  3351. }else{
  3352. return false;
  3353. }
  3354. }
  3355. /***************************
  3356. Function checkScout
  3357. Made by: yi12345
  3358. ***************************/
  3359. function checkScout($wref, $toWref) {
  3360. $q = "SELECT * FROM " . TB_PREFIX . "movement, " . TB_PREFIX . "attacks where " . TB_PREFIX . "movement.from = $wref and " . TB_PREFIX . "movement.to = $toWref and " . TB_PREFIX . "movement.ref = " . TB_PREFIX . "attacks.id and " . TB_PREFIX . "movement.proc = 0 and " . TB_PREFIX . "movement.sort_type = 3 and " . TB_PREFIX . "attacks.attack_type = 1 ORDER BY endtime ASC";
  3361. $result = mysql_query($q, $this->connection);
  3362. if(mysql_num_rows($result)) {
  3363. return true;
  3364. }else{
  3365. return false;
  3366. }
  3367. }
  3368. };
  3369. $database = new MYSQL_DB;
  3370. ?>