PageRenderTime 59ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/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

Large files files are truncated, but you can click here to view the full 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. ******…

Large files files are truncated, but you can click here to view the full file