PageRenderTime 66ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/GameEngine/Database/db_MYSQL.php

https://bitbucket.org/Dzoki/travianx
PHP | 2618 lines | 2089 code | 303 blank | 226 comment | 295 complexity | 8bdb73ca4ba48784814262d7f12d10f6 MD5 | raw file
  1. <?php
  2. /** --------------------------------------------------- **\
  3. * | ********* DO NOT REMOVE THIS COPYRIGHT NOTICE ********* |
  4. * +---------------------------------------------------------+
  5. * | Credits: All the developers including the leaders: |
  6. * | Advocaite & Dzoki & Donnchadh |
  7. * | |
  8. * | Copyright: TravianX Project All rights reserved |
  9. * \** --------------------------------------------------- **/
  10. class MYSQL_DB {
  11. var $connection;
  12. function MYSQL_DB() {
  13. $this->connection = mysql_connect(SQL_SERVER, SQL_USER, SQL_PASS) or die(mysql_error());
  14. mysql_select_db(SQL_DB, $this->connection) or die(mysql_error());
  15. }
  16. function register($username, $password, $email, $tribe, $locate, $act) {
  17. $time = time();
  18. $timep = (time() + PROTECTION);
  19. $q = "INSERT INTO " . TB_PREFIX . "users (username,password,access,email,timestamp,tribe,location,act,protect) VALUES ('$username', '$password', " . USER . ", '$email', $time, $tribe, $locate, '$act', $timep)";
  20. if(mysql_query($q, $this->connection)) {
  21. return mysql_insert_id($this->connection);
  22. } else {
  23. return false;
  24. }
  25. }
  26. function activate($username, $password, $email, $tribe, $locate, $act, $act2) {
  27. $time = time();
  28. $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')";
  29. if(mysql_query($q, $this->connection)) {
  30. return mysql_insert_id($this->connection);
  31. } else {
  32. return false;
  33. }
  34. }
  35. function unreg($username) {
  36. $q = "DELETE from " . TB_PREFIX . "activate where username = '$username'";
  37. return mysql_query($q, $this->connection);
  38. }
  39. function deleteReinf($id) {
  40. $q = "DELETE from " . TB_PREFIX . "enforcement where id = '$id'";
  41. mysql_query($q, $this->connection);
  42. }
  43. function updateResource($vid, $what, $number) {
  44. $q = "UPDATE " . TB_PREFIX . "vdata set " . $what . "=" . $number . " where wref = $vid";
  45. $result = mysql_query($q, $this->connection);
  46. return mysql_query($q, $this->connection);
  47. }
  48. function checkExist($ref, $mode) {
  49. if(!$mode) {
  50. $q = "SELECT username FROM " . TB_PREFIX . "users where username = '$ref' LIMIT 1";
  51. } else {
  52. $q = "SELECT email FROM " . TB_PREFIX . "users where email = '$ref' LIMIT 1";
  53. }
  54. $result = mysql_query($q, $this->connection);
  55. if(mysql_num_rows($result)) {
  56. return true;
  57. } else {
  58. return false;
  59. }
  60. }
  61. function checkExist_activate($ref, $mode) {
  62. if(!$mode) {
  63. $q = "SELECT username FROM " . TB_PREFIX . "activate where username = '$ref' LIMIT 1";
  64. } else {
  65. $q = "SELECT email FROM " . TB_PREFIX . "activate where email = '$ref' LIMIT 1";
  66. }
  67. $result = mysql_query($q, $this->connection);
  68. if(mysql_num_rows($result)) {
  69. return true;
  70. } else {
  71. return false;
  72. }
  73. }
  74. public function hasBeginnerProtection($vid) {
  75. $q = "SELECT u.protect FROM ".TB_PREFIX."users u,".TB_PREFIX."vdata v WHERE u.id=v.owner AND v.wref=".$vid;
  76. $result = mysql_query($q, $this->connection);
  77. $dbarray = mysql_fetch_array($result);
  78. if(!empty($dbarray)) {
  79. if(time()<$dbarray[0]) {
  80. return true;
  81. } else {
  82. return false;
  83. }
  84. } else {
  85. return false;
  86. }
  87. }
  88. function updateUserField($ref, $field, $value, $switch) {
  89. if(!$switch) {
  90. $q = "UPDATE " . TB_PREFIX . "users set $field = '$value' where username = '$ref'";
  91. } else {
  92. $q = "UPDATE " . TB_PREFIX . "users set $field = '$value' where id = '$ref'";
  93. }
  94. return mysql_query($q, $this->connection);
  95. }
  96. function getSitee($uid) {
  97. $q = "SELECT id from " . TB_PREFIX . "users where sit1 = $uid or sit2 = $uid";
  98. $result = mysql_query($q, $this->connection);
  99. return $this->mysql_fetch_all($result);
  100. }
  101. function removeMeSit($uid, $uid2) {
  102. $q = "UPDATE " . TB_PREFIX . "users set sit1 = 0 where id = $uid and sit1 = $uid2";
  103. mysql_query($q, $this->connection);
  104. $q2 = "UPDATE " . TB_PREFIX . "users set sit2 = 0 where id = $uid and sit2 = $uid2";
  105. mysql_query($q2, $this->connection);
  106. }
  107. function getUserField($ref, $field, $mode) {
  108. if(!$mode) {
  109. $q = "SELECT $field FROM " . TB_PREFIX . "users where id = '$ref'";
  110. } else {
  111. $q = "SELECT $field FROM " . TB_PREFIX . "users where username = '$ref'";
  112. }
  113. $result = mysql_query($q, $this->connection) or die(mysql_error());
  114. $dbarray = mysql_fetch_array($result);
  115. return $dbarray[$field];
  116. }
  117. function getActivateField($ref, $field, $mode) {
  118. if(!$mode) {
  119. $q = "SELECT $field FROM " . TB_PREFIX . "activate where id = '$ref'";
  120. } else {
  121. $q = "SELECT $field FROM " . TB_PREFIX . "activate where username = '$ref'";
  122. }
  123. $result = mysql_query($q, $this->connection) or die(mysql_error());
  124. $dbarray = mysql_fetch_array($result);
  125. return $dbarray[$field];
  126. }
  127. function login($username, $password) {
  128. $q = "SELECT password,sessid FROM " . TB_PREFIX . "users where username = '$username' and access != " . BANNED;
  129. $result = mysql_query($q, $this->connection);
  130. $dbarray = mysql_fetch_array($result);
  131. if($dbarray['password'] == md5($password)) {
  132. return true;
  133. } else {
  134. return false;
  135. }
  136. }
  137. function checkActivate($act) {
  138. $q = "SELECT * FROM " . TB_PREFIX . "activate where act = '$act'";
  139. $result = mysql_query($q, $this->connection);
  140. $dbarray = mysql_fetch_array($result);
  141. return $dbarray;
  142. }
  143. function sitterLogin($username, $password) {
  144. $q = "SELECT sit1,sit2 FROM " . TB_PREFIX . "users where username = '$username' and access != " . BANNED;
  145. $result = mysql_query($q, $this->connection);
  146. $dbarray = mysql_fetch_array($result);
  147. if($dbarray['sit1'] != 0) {
  148. $q2 = "SELECT password FROM " . TB_PREFIX . "users where id = " . $dbarray['sit1'] . " and access != " . BANNED;
  149. $result2 = mysql_query($q2, $this->connection);
  150. $dbarray2 = mysql_fetch_array($result2);
  151. } else
  152. if($dbarray['sit2'] != 0) {
  153. $q3 = "SELECT password FROM " . TB_PREFIX . "users where id = " . $dbarray['sit2'] . " and access != " . BANNED;
  154. $result3 = mysql_query($q3, $this->connection);
  155. $dbarray3 = mysql_fetch_array($result3);
  156. }
  157. if($dbarray['sit1'] != 0 || $dbarray['sit2'] != 0) {
  158. if($dbarray2['password'] == md5($password) || $dbarray3['password'] == md5($password)) {
  159. return true;
  160. } else {
  161. return false;
  162. }
  163. } else {
  164. return false;
  165. }
  166. }
  167. function setDeleting($uid, $mode) {
  168. $time = time() + 72 * 3600;
  169. if(!$mode) {
  170. $q = "INSERT into " . TB_PREFIX . "deleting values ($uid,$time)";
  171. } else {
  172. $q = "DELETE FROM " . TB_PREFIX . "deleting where uid = $uid";
  173. }
  174. mysql_query($q, $this->connection);
  175. }
  176. function isDeleting($uid) {
  177. $q = "SELECT timestamp from " . TB_PREFIX . "deleting where uid = $uid";
  178. $result = mysql_query($q, $this->connection);
  179. $dbarray = mysql_fetch_array($result);
  180. return $dbarray['timestamp'];
  181. }
  182. function modifyGold($userid, $amt, $mode) {
  183. if(!$mode) {
  184. $q = "UPDATE " . TB_PREFIX . "users set gold = gold - $amt where id = $userid";
  185. } else {
  186. $q = "UPDATE " . TB_PREFIX . "users set gold = gold + $amt where id = $userid";
  187. }
  188. return mysql_query($q, $this->connection);
  189. }
  190. /*****************************************
  191. Function to retrieve user array via Username or ID
  192. Mode 0: Search by Username
  193. Mode 1: Search by ID
  194. References: Alliance ID
  195. *****************************************/
  196. function getUserArray($ref, $mode) {
  197. if(!$mode) {
  198. $q = "SELECT * FROM " . TB_PREFIX . "users where username = '$ref'";
  199. } else {
  200. $q = "SELECT * FROM " . TB_PREFIX . "users where id = $ref";
  201. }
  202. $result = mysql_query($q, $this->connection);
  203. return mysql_fetch_array($result);
  204. }
  205. function activeModify($username, $mode) {
  206. $time = time();
  207. if(!$mode) {
  208. $q = "INSERT into " . TB_PREFIX . "active VALUES ('$username',$time)";
  209. } else {
  210. $q = "DELETE FROM " . TB_PREFIX . "active where username = '$username'";
  211. }
  212. return mysql_query($q, $this->connection);
  213. }
  214. function addActiveUser($username, $time) {
  215. $q = "REPLACE into " . TB_PREFIX . "active values ('$username',$time)";
  216. if(mysql_query($q, $this->connection)) {
  217. return true;
  218. } else {
  219. return false;
  220. }
  221. }
  222. function updateActiveUser($username, $time) {
  223. $q = "REPLACE into " . TB_PREFIX . "active values ('$username',$time)";
  224. $q2 = "UPDATE " . TB_PREFIX . "users set timestamp = $time where username = '$username'";
  225. $exec1 = mysql_query($q, $this->connection);
  226. $exec2 = mysql_query($q2, $this->connection);
  227. if($exec1 && $exec2) {
  228. return true;
  229. } else {
  230. return false;
  231. }
  232. }
  233. function checkactiveSession($username, $sessid) {
  234. $q = "SELECT username FROM " . TB_PREFIX . "users where username = '$username' and sessid = '$sessid' LIMIT 1";
  235. $result = mysql_query($q, $this->connection);
  236. if(mysql_num_rows($result) != 0) {
  237. return true;
  238. } else {
  239. return false;
  240. }
  241. }
  242. function submitProfile($uid, $gender, $location, $birthday, $des1, $des2) {
  243. $q = "UPDATE " . TB_PREFIX . "users set gender = $gender, location = '$location', birthday = '$birthday', desc1 = '$des1', desc2 = '$des2' where id = $uid";
  244. return mysql_query($q, $this->connection);
  245. }
  246. function gpack($uid, $gpack) {
  247. $q = "UPDATE " . TB_PREFIX . "users set gpack = '$gpack' where id = $uid";
  248. return mysql_query($q, $this->connection);
  249. }
  250. function UpdateOnline($mode, $name = "", $time = "") {
  251. global $session;
  252. if($mode == "login") {
  253. $q = "INSERT IGNORE INTO " . TB_PREFIX . "online (name, time) VALUES ('$name', " . time() . ")";
  254. return mysql_query($q, $this->connection);
  255. } else {
  256. $q = "DELETE FROM " . TB_PREFIX . "online WHERE name ='" . $session->username . "'";
  257. return mysql_query($q, $this->connection);
  258. }
  259. }
  260. function generateBase($sector) {
  261. $qeinde = "9999";
  262. $sector = rand(1, 4);
  263. $query = "select * from " . TB_PREFIX . "wdata where fieldtype = 3 and occupied = 0";
  264. $result = mysql_query($query, $this->connection);
  265. for($i = 0; $row = mysql_fetch_assoc($result); $i++) {
  266. $oke = '1';
  267. $x = $row['x'];
  268. $y = $row['y'];
  269. if($x[0] == "-") {
  270. $x = ($x * -1);
  271. if($sector == '2' or $sector == '4') {
  272. $oke = '0';
  273. }
  274. } else {
  275. if($sector == '1' or $sector == '3') {
  276. $oke = '0';
  277. }
  278. }
  279. if($y[0] == "-") {
  280. $y = ($y * -1);
  281. if($sector == '1' or $sector == '2') {
  282. $oke = '0';
  283. }
  284. } else {
  285. if($sector == '3' or $sector == '4') {
  286. $oke = '0';
  287. }
  288. }
  289. $afstand = sqrt(pow($x, 2) + pow($y, 2));
  290. if($oke == '1') {
  291. if($qeinde > $afstand) {
  292. $rand = rand(1, 10);
  293. if($rand == '3') {
  294. $qeinde = $afstand;
  295. $qid = $row['id'];
  296. }
  297. }
  298. }
  299. }
  300. if(isset($qid)) {
  301. return $qid;
  302. } else {
  303. $query = "select * from " . TB_PREFIX . "wdata where fieldtype = 3 and occupied = 0 LIMIT 0,1";
  304. $result = mysql_query($query, $this->connection);
  305. $row = mysql_fetch_array($result);
  306. return $row['id'];
  307. }
  308. }
  309. function setFieldTaken($id) {
  310. $q = "UPDATE " . TB_PREFIX . "wdata set occupied = 1 where id = $id";
  311. return mysql_query($q, $this->connection);
  312. }
  313. function addVillage($wid, $uid, $username, $capital) {
  314. $total = count($this->getVillagesID($uid));
  315. if($total >= 1) {
  316. $vname = $username . "\'s village " . ($total + 1);
  317. } else {
  318. $vname = $username . "\'s village";
  319. }
  320. $time = time();
  321. $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')";
  322. return mysql_query($q, $this->connection) or die(mysql_error());
  323. }
  324. function addResourceFields($vid, $type) {
  325. switch($type) {
  326. case 1:
  327. $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)";
  328. break;
  329. case 2:
  330. $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)";
  331. break;
  332. case 3:
  333. $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)";
  334. break;
  335. case 4:
  336. $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)";
  337. break;
  338. case 5:
  339. $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)";
  340. break;
  341. case 6:
  342. $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)";
  343. break;
  344. case 7:
  345. $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)";
  346. break;
  347. case 8:
  348. $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)";
  349. break;
  350. case 9:
  351. $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)";
  352. break;
  353. case 10:
  354. $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)";
  355. break;
  356. case 11:
  357. $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)";
  358. break;
  359. case 12:
  360. $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)";
  361. break;
  362. }
  363. return mysql_query($q, $this->connection);
  364. }
  365. function isVillageOases($wref) {
  366. $q = "SELECT id, oasistype FROM " . TB_PREFIX . "wdata where id = $wref";
  367. $result = mysql_query($q, $this->connection);
  368. $dbarray = mysql_fetch_array($result);
  369. return $dbarray['oasistype'];
  370. }
  371. public function VillageOasisCount($vref) {
  372. $q = "SELECT count(*) FROM `".TB_PREFIX."odata` WHERE conqured=$vref";
  373. $result = mysql_query($q, $this->connection);
  374. $row = mysql_fetch_row($result);
  375. return $row[0];
  376. }
  377. public function countOasisTroops($vref){
  378. //count oasis troops: $troops_o
  379. $troops_o=0;
  380. $o_unit2=mysql_query("select * from ".TB_PREFIX."units where `vref`='".$vref."'");
  381. $o_unit=mysql_fetch_array($o_unit2);
  382. for ($i=1;$i<51;$i++)
  383. {
  384. $troops_o+=$o_unit[$i];
  385. }
  386. $troops_o+=$o_unit['hero'];
  387. $o_unit2=mysql_query("select * from ".TB_PREFIX."enforcement where `vref`='".$vref."'");
  388. while ($o_unit=@mysql_fetch_array($o_unit2))
  389. {
  390. for ($i=1;$i<51;$i++)
  391. {
  392. $troops_o+=$o_unit[$i];
  393. }
  394. $troops_o+=$o_unit['hero'];
  395. }
  396. return $troops_o;
  397. }
  398. public function canConquerOasis($vref,$wref) {
  399. $AttackerFields = $this->getResourceLevel($vref);
  400. for($i=19;$i<=38;$i++) {
  401. if($AttackerFields['f'.$i.'t'] == 37) { $HeroMansionLevel = $AttackerFields['f'.$i]; }
  402. }
  403. if($this->VillageOasisCount($vref) < floor(($HeroMansionLevel-5)/5)) {
  404. $OasisInfo = $this->getOasisInfo($wref);
  405. $troopcount = $this->countOasisTroops($wref);
  406. if($OasisInfo['conqured'] == 0 || $OasisInfo['conqured'] != 0 && $OasisInfo['loyalty'] < 99 / min(3,(4-$this->VillageOasisCount($OasisInfo['conqured']))) && $troopcount == 0) {
  407. $CoordsVillage = $this->getCoor($vref);
  408. $CoordsOasis = $this->getCoor($wref);
  409. if(abs($CoordsOasis['x']-$CoordsVillage['x'])<=3 && abs($CoordsOasis['y']-$CoordsVillage['y'])<=3) {
  410. return True;
  411. } else {
  412. return False;
  413. }
  414. } else {
  415. return False;
  416. }
  417. } else {
  418. return False;
  419. }
  420. }
  421. public function conquerOasis($vref,$wref) {
  422. $vinfo = $this->getVillage($vref);
  423. $uid = $vinfo['owner'];
  424. $q = "UPDATE `".TB_PREFIX."odata` SET conqured=$vref,loyalty=100,lastupdated=".time().",owner=$uid,name='Occupied Oasis' WHERE wref=$wref";
  425. return mysql_query($q, $this->connection);
  426. }
  427. public function modifyOasisLoyalty($wref) {
  428. if($this->isVillageOases($wref) != 0) {
  429. $OasisInfo = $this->getOasisInfo($wref);
  430. if($OasisInfo['conqured'] != 0) {
  431. $LoyaltyAmendment = floor(100 / min(3,(4-$this->VillageOasisCount($OasisInfo['conqured']))));
  432. $q = "UPDATE `".TB_PREFIX."odata` SET loyalty=loyalty-$LoyaltyAmendment WHERE wref=$wref";
  433. return mysql_query($q, $this->connection);
  434. }
  435. }
  436. }
  437. function populateOasis() {
  438. $q = "SELECT * FROM " . TB_PREFIX . "wdata where oasistype != 0";
  439. $result = mysql_query($q, $this->connection);
  440. while($row = mysql_fetch_array($result)) {
  441. $wid = $row['id'];
  442. $this->addUnits($wid);
  443. }
  444. }
  445. function populateOasisUnitsLow() {
  446. $q2 = "SELECT * FROM " . TB_PREFIX . "wdata where oasistype != 0";
  447. $result2 = mysql_query($q2, $this->connection);
  448. while($row = mysql_fetch_array($result2)) {
  449. $wid = $row['id'];
  450. $basearray = $this->getMInfo($wid);
  451. //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
  452. switch($basearray['oasistype']) {
  453. case 1:
  454. case 2:
  455. //+25% lumber per hour
  456. $q = "UPDATE " . TB_PREFIX . "units SET u36 = u36 + '".rand(0,20)."', u37 = u37 + '".rand(0,10)."' WHERE vref = '" . $wid . "' AND u36 <= '2' AND u37 <= '2'";
  457. $result = mysql_query($q, $this->connection);
  458. break;
  459. case 3:
  460. //+25% lumber and +25% crop per hour
  461. $q = "UPDATE " . TB_PREFIX . "units SET u36 = u36 + '".rand(0,20)."', u37 = u37 + '".rand(0,10)."', u38 = u38 + '".rand(0,10)."' WHERE vref = '" . $wid . "' AND u36 <= '2' AND u37 <= '2' AND u38 <='2'";
  462. $result = mysql_query($q, $this->connection);
  463. break;
  464. case 4:
  465. case 5:
  466. //+25% clay per hour
  467. $q = "UPDATE " . TB_PREFIX . "units SET u36 = u36 + '".rand(0,20)."', u37 = u37 + '".rand(0,10)."' WHERE vref = '" . $wid . "' AND u36 <= '2' AND u37 <= '2'";
  468. $result = mysql_query($q, $this->connection);
  469. break;
  470. case 6:
  471. //+25% clay and +25% crop per hour
  472. $q = "UPDATE " . TB_PREFIX . "units SET u36 = u36 + '".rand(0,20)."', u37 = u37 + '".rand(0,10)."', u38 = u38 + '".rand(0,10)."' WHERE vref = '" . $wid . "' AND u36 <= '2' AND u37 <= '2' AND u38 <='2'";
  473. $result = mysql_query($q, $this->connection);
  474. break;
  475. case 7:
  476. case 8:
  477. //+25% iron per hour
  478. $q = "UPDATE " . TB_PREFIX . "units SET u31 = u31 + '".rand(0,20)."', u32 = u32 + '".rand(0,10)."', u34 = u34 + '".rand(0,10)."' WHERE vref = '" . $wid . "' AND u31 <= '2' AND u32 <= '2'";
  479. $result = mysql_query($q, $this->connection);
  480. break;
  481. case 9:
  482. //+25% iron and +25% crop
  483. $q = "UPDATE " . TB_PREFIX . "units SET u31 = u31 + '".rand(0,20)."', u32 = u32 + '".rand(0,10)."', u34 = u34 + '".rand(0,10)."' WHERE vref = '" . $wid . "' AND u31 <= '2' AND u32 <= '2' AND u34 <='2'";
  484. $result = mysql_query($q, $this->connection);
  485. break;
  486. case 10:
  487. case 11:
  488. //+25% crop per hour
  489. $q = "UPDATE " . TB_PREFIX . "units SET u33 = u33 + '".rand(0,20)."', u37 = u37 + '".rand(0,10)."', u38 = u38 + '".rand(0,10)."' WHERE vref = '" . $wid . "' AND u33 <= '2' AND u37 <= '2' AND u38 <='2'";
  490. $result = mysql_query($q, $this->connection);
  491. break;
  492. case 12:
  493. //+50% crop per hour
  494. $q = "UPDATE " . TB_PREFIX . "units SET u33 = u33 + '".rand(0,20)."', u37 = u37 + '".rand(0,10)."', u38 = u38 + '".rand(0,10)."', u39 = u39 + '".rand(0,10)."' WHERE vref = '" . $wid . "' AND u33 <= '2' AND u37 <= '2' AND u38 <='2'AND u38 <='2'";
  495. $result = mysql_query($q, $this->connection);
  496. break;
  497. }
  498. }
  499. }
  500. function populateOasisUnitsHigh() {
  501. $q2 = "SELECT * FROM " . TB_PREFIX . "wdata where oasistype != 0";
  502. $result2 = mysql_query($q2, $this->connection);
  503. while($row = mysql_fetch_array($result2)) {
  504. $wid = $row['id'];
  505. $basearray = $this->getMInfo($wid);
  506. //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
  507. switch($basearray['oasistype']) {
  508. case 1:
  509. case 2:
  510. //+25% lumber per hour
  511. $q = "UPDATE " . TB_PREFIX . "units SET u36 = u36 + '".rand(15,40)."', u37 = u37 + '".rand(10,20)."' WHERE vref = '" . $wid . "' AND u36 <= '2' AND u37 <= '2'";
  512. $result = mysql_query($q, $this->connection);
  513. break;
  514. case 3:
  515. //+25% lumber and +25% crop per hour
  516. $q = "UPDATE " . TB_PREFIX . "units SET u36 = u36 + '".rand(15,40)."', u37 = u37 + '".rand(10,20)."', u38 = u38 + '".rand(10,20)."' WHERE vref = '" . $wid . "' AND u36 <= '2' AND u37 <= '2' AND u38 <='2'";
  517. $result = mysql_query($q, $this->connection);
  518. break;
  519. case 4:
  520. case 5:
  521. //+25% clay per hour
  522. $q = "UPDATE " . TB_PREFIX . "units SET u36 = u36 + '".rand(15,40)."', u37 = u37 + '".rand(10,20)."' WHERE vref = '" . $wid . "' AND u36 <= '2' AND u37 <= '2'";
  523. $result = mysql_query($q, $this->connection);
  524. break;
  525. case 6:
  526. //+25% clay and +25% crop per hour
  527. $q = "UPDATE " . TB_PREFIX . "units SET u36 = u36 + '".rand(15,40)."', u37 = u37 + '".rand(10,20)."', u38 = u38 + '".rand(10,20)."' WHERE vref = '" . $wid . "' AND u36 <= '2' AND u37 <= '2' AND u38 <='2'";
  528. $result = mysql_query($q, $this->connection);
  529. break;
  530. case 7:
  531. case 8:
  532. //+25% iron per hour
  533. $q = "UPDATE " . TB_PREFIX . "units SET u31 = u31 + '".rand(15,40)."', u32 = u32 + '".rand(10,20)."', u34 = u34 + '".rand(10,20)."' WHERE vref = '" . $wid . "' AND u31 <= '2' AND u32 <= '2'";
  534. $result = mysql_query($q, $this->connection);
  535. break;
  536. case 9:
  537. //+25% iron and +25% crop
  538. $q = "UPDATE " . TB_PREFIX . "units SET u31 = u31 + '".rand(15,40)."', u32 = u32 + '".rand(10,20)."', u34 = u34 + '".rand(10,20)."' WHERE vref = '" . $wid . "' AND u31 <= '2' AND u32 <= '2' AND u34 <='2'";
  539. $result = mysql_query($q, $this->connection);
  540. break;
  541. case 10:
  542. case 11:
  543. //+25% crop per hour
  544. $q = "UPDATE " . TB_PREFIX . "units SET u33 = u33 + '".rand(0,20)."', u37 = u37 + '".rand(0,10)."', u38 = u38 + '".rand(0,10)."' WHERE vref = '" . $wid . "' AND u33 <= '2' AND u37 <= '2' AND u38 <='2'";
  545. $result = mysql_query($q, $this->connection);
  546. break;
  547. case 12:
  548. //+50% crop per hour
  549. $q = "UPDATE " . TB_PREFIX . "units SET u33 = u33 + '".rand(0,20)."', u37 = u37 + '".rand(0,10)."', u38 = u38 + '".rand(0,10)."', u39 = u39 + '".rand(0,10)."' WHERE vref = '" . $wid . "' AND u33 <= '2' AND u37 <= '2' AND u38 <='2'AND u38 <='2'";
  550. $result = mysql_query($q, $this->connection);
  551. break;
  552. }
  553. }
  554. }
  555. /***************************
  556. Function to retrieve type of village via ID
  557. References: Village ID
  558. ***************************/
  559. function getVillageType($wref) {
  560. $q = "SELECT id, fieldtype FROM " . TB_PREFIX . "wdata where id = $wref";
  561. $result = mysql_query($q, $this->connection);
  562. $dbarray = mysql_fetch_array($result);
  563. return $dbarray['fieldtype'];
  564. }
  565. /*****************************************
  566. Function to retrieve if is ocuped via ID
  567. References: Village ID
  568. *****************************************/
  569. function getVillageState($wref) {
  570. $q = "SELECT oasistype,occupied FROM " . TB_PREFIX . "wdata where id = $wref";
  571. $result = mysql_query($q, $this->connection);
  572. $dbarray = mysql_fetch_array($result);
  573. if($dbarray['occupied'] != 0 || $dbarray['oasistype'] != 0) {
  574. return true;
  575. } else {
  576. return false;
  577. }
  578. }
  579. function getProfileVillages($uid) {
  580. $q = "SELECT capital,wref,name,pop,created from " . TB_PREFIX . "vdata where owner = $uid order by pop desc";
  581. $result = mysql_query($q, $this->connection);
  582. return $this->mysql_fetch_all($result);
  583. }
  584. function getProfileMedal($uid) {
  585. $q = "SELECT id,categorie,plaats,week,img,points from " . TB_PREFIX . "medal where userid = $uid order by id desc";
  586. $result = mysql_query($q, $this->connection);
  587. return $this->mysql_fetch_all($result);
  588. }
  589. function getProfileMedalAlly($uid) {
  590. $q = "SELECT id,categorie,plaats,week,img,points from " . TB_PREFIX . "allimedal where allyid = $uid order by id desc";
  591. $result = mysql_query($q, $this->connection);
  592. return $this->mysql_fetch_all($result);
  593. }
  594. function getVillageID($uid) {
  595. $q = "SELECT wref FROM " . TB_PREFIX . "vdata WHERE owner = $uid";
  596. $result = mysql_query($q, $this->connection);
  597. $dbarray = mysql_fetch_array($result);
  598. return $dbarray['wref'];
  599. }
  600. function getVillagesID($uid) {
  601. $q = "SELECT wref from " . TB_PREFIX . "vdata where owner = $uid order by capital DESC,pop DESC";
  602. $result = mysql_query($q, $this->connection);
  603. $array = $this->mysql_fetch_all($result);
  604. $newarray = array();
  605. for($i = 0; $i < count($array); $i++) {
  606. array_push($newarray, $array[$i]['wref']);
  607. }
  608. return $newarray;
  609. }
  610. function getVillage($vid) {
  611. $q = "SELECT * FROM " . TB_PREFIX . "vdata where wref = $vid";
  612. $result = mysql_query($q, $this->connection);
  613. return mysql_fetch_array($result);
  614. }
  615. public function getVillageBattleData($vid) {
  616. $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;
  617. $result = mysql_query($q, $this->connection);
  618. return mysql_fetch_array($result);
  619. }
  620. public function getPopulation($uid) {
  621. $q = "SELECT sum(pop) AS pop FROM ".TB_PREFIX."vdata WHERE owner=".$uid;
  622. $result = mysql_query($q, $this->connection);
  623. $dbarray = mysql_fetch_array($result);
  624. return $dbarray['pop'];
  625. }
  626. function getOasisV($vid) {
  627. $q = "SELECT * FROM " . TB_PREFIX . "odata where wref = $vid";
  628. $result = mysql_query($q, $this->connection);
  629. return mysql_fetch_array($result);
  630. }
  631. function getMInfo($id) {
  632. $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";
  633. $result = mysql_query($q, $this->connection);
  634. return mysql_fetch_array($result);
  635. }
  636. function getOMInfo($id) {
  637. $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";
  638. $result = mysql_query($q, $this->connection);
  639. return mysql_fetch_array($result);
  640. }
  641. function getOasis($vid) {
  642. $q = "SELECT * FROM " . TB_PREFIX . "odata where conqured = $vid";
  643. $result = mysql_query($q, $this->connection);
  644. return $this->mysql_fetch_all($result);
  645. }
  646. function getOasisInfo($wid) {
  647. $q = "SELECT * FROM " . TB_PREFIX . "odata where wref = $wid";
  648. $result = mysql_query($q, $this->connection);
  649. return mysql_fetch_assoc($result);
  650. }
  651. function getVillageField($ref, $field) {
  652. $q = "SELECT $field FROM " . TB_PREFIX . "vdata where wref = $ref";
  653. $result = mysql_query($q, $this->connection);
  654. $dbarray = mysql_fetch_array($result);
  655. return $dbarray[$field];
  656. }
  657. function getOasisField($ref, $field) {
  658. $q = "SELECT $field FROM " . TB_PREFIX . "odata where wref = $ref";
  659. $result = mysql_query($q, $this->connection);
  660. $dbarray = mysql_fetch_array($result);
  661. return $dbarray[$field];
  662. }
  663. function setVillageField($ref, $field, $value) {
  664. $q = "UPDATE " . TB_PREFIX . "vdata set $field = '$value' where wref = $ref";
  665. return mysql_query($q, $this->connection);
  666. }
  667. function setVillageLevel($ref, $field, $value) {
  668. $q = "UPDATE " . TB_PREFIX . "fdata set " . $field . " = '" . $value . "' where vref = " . $ref . "";
  669. return mysql_query($q, $this->connection);
  670. }
  671. function getResourceLevel($vid) {
  672. $q = "SELECT * from " . TB_PREFIX . "fdata where vref = $vid";
  673. $result = mysql_query($q, $this->connection);
  674. return mysql_fetch_assoc($result);
  675. }
  676. function getAdminLog() {
  677. $q = "SELECT id,user,log,time from " . TB_PREFIX . "admin_log where id != 0 ORDER BY id ASC";
  678. $result = mysql_query($q, $this->connection);
  679. return $this->mysql_fetch_all($result);
  680. }
  681. function getCoor($wref) {
  682. $q = "SELECT x,y FROM " . TB_PREFIX . "wdata where id = $wref";
  683. $result = mysql_query($q, $this->connection);
  684. if ($result){$fetcharray=mysql_fetch_array($result);}
  685. return $fetcharray;
  686. }
  687. function CheckForum($id) {
  688. $q = "SELECT * from " . TB_PREFIX . "forum_cat where alliance = '$id'";
  689. $result = mysql_query($q, $this->connection);
  690. if(mysql_num_rows($result)) {
  691. return true;
  692. } else {
  693. return false;
  694. }
  695. }
  696. function CountCat($id) {
  697. $q = "SELECT count(id) FROM " . TB_PREFIX . "forum_topic where cat = '$id'";
  698. $result = mysql_query($q, $this->connection);
  699. $row = mysql_fetch_row($result);
  700. return $row[0];
  701. }
  702. function LastTopic($id) {
  703. $q = "SELECT * from " . TB_PREFIX . "forum_topic where cat = '$id' order by post_date";
  704. $result = mysql_query($q, $this->connection);
  705. return $this->mysql_fetch_all($result);
  706. }
  707. function CheckLastTopic($id) {
  708. $q = "SELECT * from " . TB_PREFIX . "forum_topic where cat = '$id'";
  709. $result = mysql_query($q, $this->connection);
  710. if(mysql_num_rows($result)) {
  711. return true;
  712. } else {
  713. return false;
  714. }
  715. }
  716. function CheckLastPost($id) {
  717. $q = "SELECT * from " . TB_PREFIX . "forum_post where topic = '$id'";
  718. $result = mysql_query($q, $this->connection);
  719. if(mysql_num_rows($result)) {
  720. return true;
  721. } else {
  722. return false;
  723. }
  724. }
  725. function LastPost($id) {
  726. $q = "SELECT * from " . TB_PREFIX . "forum_post where topic = '$id'";
  727. $result = mysql_query($q, $this->connection);
  728. return $this->mysql_fetch_all($result);
  729. }
  730. function CountTopic($id) {
  731. $q = "SELECT count(id) FROM " . TB_PREFIX . "forum_post where owner = '$id'";
  732. $result = mysql_query($q, $this->connection);
  733. $row = mysql_fetch_row($result);
  734. $qs = "SELECT count(id) FROM " . TB_PREFIX . "forum_topic where owner = '$id'";
  735. $results = mysql_query($qs, $this->connection);
  736. $rows = mysql_fetch_row($results);
  737. return $row[0] + $rows[0];
  738. }
  739. function CountPost($id) {
  740. $q = "SELECT count(id) FROM " . TB_PREFIX . "forum_post where topic = '$id'";
  741. $result = mysql_query($q, $this->connection);
  742. $row = mysql_fetch_row($result);
  743. return $row[0];
  744. }
  745. function ForumCat($id) {
  746. $q = "SELECT * from " . TB_PREFIX . "forum_cat where alliance = '$id' ORDER BY id";
  747. $result = mysql_query($q, $this->connection);
  748. return $this->mysql_fetch_all($result);
  749. }
  750. function ForumCatEdit($id) {
  751. $q = "SELECT * from " . TB_PREFIX . "forum_cat where id = '$id'";
  752. $result = mysql_query($q, $this->connection);
  753. return $this->mysql_fetch_all($result);
  754. }
  755. function ForumCatName($id) {
  756. $q = "SELECT forum_name from " . TB_PREFIX . "forum_cat where id = $id";
  757. $result = mysql_query($q, $this->connection);
  758. $dbarray = mysql_fetch_array($result);
  759. return $dbarray['forum_name'];
  760. }
  761. function CheckCatTopic($id) {
  762. $q = "SELECT * from " . TB_PREFIX . "forum_topic where cat = '$id'";
  763. $result = mysql_query($q, $this->connection);
  764. if(mysql_num_rows($result)) {
  765. return true;
  766. } else {
  767. return false;
  768. }
  769. }
  770. function CheckResultEdit($alli) {
  771. $q = "SELECT * from " . TB_PREFIX . "forum_edit where alliance = '$alli'";
  772. $result = mysql_query($q, $this->connection);
  773. if(mysql_num_rows($result)) {
  774. return true;
  775. } else {
  776. return false;
  777. }
  778. }
  779. function CheckCloseTopic($id) {
  780. $q = "SELECT close from " . TB_PREFIX . "forum_topic where id = '$id'";
  781. $result = mysql_query($q, $this->connection);
  782. $dbarray = mysql_fetch_array($result);
  783. return $dbarray['close'];
  784. }
  785. function CheckEditRes($alli) {
  786. $q = "SELECT result from " . TB_PREFIX . "forum_edit where alliance = '$alli'";
  787. $result = mysql_query($q, $this->connection);
  788. $dbarray = mysql_fetch_array($result);
  789. return $dbarray['result'];
  790. }
  791. function CreatResultEdit($alli, $result) {
  792. $q = "INSERT into " . TB_PREFIX . "forum_edit values (0,'$alli','$result')";
  793. mysql_query($q, $this->connection);
  794. return mysql_insert_id($this->connection);
  795. }
  796. function UpdateResultEdit($alli, $result) {
  797. $date = time();
  798. $q = "UPDATE " . TB_PREFIX . "forum_edit set result = '$result' where alliance = '$alli'";
  799. return mysql_query($q, $this->connection);
  800. }
  801. function UpdateEditTopic($id, $title, $cat) {
  802. $q = "UPDATE " . TB_PREFIX . "forum_topic set title = '$title', cat = '$cat' where id = $id";
  803. return mysql_query($q, $this->connection);
  804. }
  805. function UpdateEditForum($id, $name, $des) {
  806. $q = "UPDATE " . TB_PREFIX . "forum_cat set forum_name = '$name', forum_des = '$des' where id = $id";
  807. return mysql_query($q, $this->connection);
  808. }
  809. function StickTopic($id, $mode) {
  810. $q = "UPDATE " . TB_PREFIX . "forum_topic set stick = '$mode' where id = '$id'";
  811. return mysql_query($q, $this->connection);
  812. }
  813. function ForumCatTopic($id) {
  814. $q = "SELECT * from " . TB_PREFIX . "forum_topic where cat = '$id' AND stick = '' ORDER BY post_date desc";
  815. $result = mysql_query($q, $this->connection);
  816. return $this->mysql_fetch_all($result);
  817. }
  818. function ForumCatTopicStick($id) {
  819. $q = "SELECT * from " . TB_PREFIX . "forum_topic where cat = '$id' AND stick = '1' ORDER BY post_date desc";
  820. $result = mysql_query($q, $this->connection);
  821. return $this->mysql_fetch_all($result);
  822. }
  823. function ShowTopic($id) {
  824. $q = "SELECT * from " . TB_PREFIX . "forum_topic where id = '$id'";
  825. $result = mysql_query($q, $this->connection);
  826. return $this->mysql_fetch_all($result);
  827. }
  828. function ShowPost($id) {
  829. $q = "SELECT * from " . TB_PREFIX . "forum_post where topic = '$id'";
  830. $result = mysql_query($q, $this->connection);
  831. return $this->mysql_fetch_all($result);
  832. }
  833. function ShowPostEdit($id) {
  834. $q = "SELECT * from " . TB_PREFIX . "forum_post where id = '$id'";
  835. $result = mysql_query($q, $this->connection);
  836. return $this->mysql_fetch_all($result);
  837. }
  838. function CreatForum($owner, $alli, $name, $des, $area) {
  839. $q = "INSERT into " . TB_PREFIX . "forum_cat values (0,'$owner','$alli','$name','$des','$area')";
  840. mysql_query($q, $this->connection);
  841. return mysql_insert_id($this->connection);
  842. }
  843. function CreatTopic($title, $post, $cat, $owner, $alli, $ends) {
  844. $date = time();
  845. $q = "INSERT into " . TB_PREFIX . "forum_topic values (0,'$title','$post','$date','$date','$cat','$owner','$alli','$ends','','')";
  846. mysql_query($q, $this->connection);
  847. return mysql_insert_id($this->connection);
  848. }
  849. function CreatPost($post, $tids, $owner) {
  850. $date = time();
  851. $q = "INSERT into " . TB_PREFIX . "forum_post values (0,'$post','$tids','$owner','$date')";
  852. mysql_query($q, $this->connection);
  853. return mysql_insert_id($this->connection);
  854. }
  855. function UpdatePostDate($id) {
  856. $date = time();
  857. $q = "UPDATE " . TB_PREFIX . "forum_topic set post_date = '$date' where id = $id";
  858. return mysql_query($q, $this->connection);
  859. }
  860. function EditUpdateTopic($id, $post) {
  861. $q = "UPDATE " . TB_PREFIX . "forum_topic set post = '$post' where id = $id";
  862. return mysql_query($q, $this->connection);
  863. }
  864. function EditUpdatePost($id, $post) {
  865. $q = "UPDATE " . TB_PREFIX . "forum_post set post = '$post' where id = $id";
  866. return mysql_query($q, $this->connection);
  867. }
  868. function LockTopic($id, $mode) {
  869. $q = "UPDATE " . TB_PREFIX . "forum_topic set close = '$mode' where id = '$id'";
  870. return mysql_query($q, $this->connection);
  871. }
  872. function DeleteCat($id) {
  873. $qs = "DELETE from " . TB_PREFIX . "forum_cat where id = '$id'";
  874. $q = "DELETE from " . TB_PREFIX . "forum_topic where cat = '$id'";
  875. mysql_query($qs, $this->connection);
  876. return mysql_query($q, $this->connection);
  877. }
  878. function DeleteTopic($id) {
  879. $qs = "DELETE from " . TB_PREFIX . "forum_topic where id = '$id'";
  880. // $q = "DELETE from ".TB_PREFIX."forum_post where topic = '$id'";//
  881. return mysql_query($qs, $this->connection); //
  882. // mysql_query($q,$this->connection);
  883. }
  884. function DeletePost($id) {
  885. $q = "DELETE from " . TB_PREFIX . "forum_post where id = '$id'";
  886. return mysql_query($q, $this->connection);
  887. }
  888. function getAllianceName($id) {
  889. $q = "SELECT tag from " . TB_PREFIX . "alidata where id = $id";
  890. $result = mysql_query($q, $this->connection);
  891. $dbarray = mysql_fetch_array($result);
  892. return $dbarray['tag'];
  893. }
  894. function getAlliancePermission($ref, $field, $mode) {
  895. if(!$mode) {
  896. $q = "SELECT $field FROM " . TB_PREFIX . "ali_permission where uid = '$ref'";
  897. } else {
  898. $q = "SELECT $field FROM " . TB_PREFIX . "ali_permission where username = '$ref'";
  899. }
  900. $result = mysql_query($q, $this->connection) or die(mysql_error());
  901. $dbarray = mysql_fetch_array($result);
  902. return $dbarray[$field];
  903. }
  904. function getAlliance($id) {
  905. $q = "SELECT * from " . TB_PREFIX . "alidata where id = $id";
  906. $result = mysql_query($q, $this->connection);
  907. return mysql_fetch_assoc($result);
  908. }
  909. function setAlliName($aid, $name, $tag) {
  910. $q = "UPDATE " . TB_PREFIX . "alidata set name = '$name', tag = '$tag' where id = $aid";
  911. return mysql_query($q, $this->connection);
  912. }
  913. function isAllianceOwner($id) {
  914. $q = "SELECT * from " . TB_PREFIX . "alidata where leader = '$id'";
  915. $result = mysql_query($q, $this->connection);
  916. if(mysql_num_rows($result)) {
  917. return true;
  918. } else {
  919. return false;
  920. }
  921. }
  922. function aExist($ref, $type) {
  923. $q = "SELECT $type FROM " . TB_PREFIX . "alidata where $type = '$ref'";
  924. $result = mysql_query($q, $this->connection);
  925. if(mysql_num_rows($result)) {
  926. return true;
  927. } else {
  928. return false;
  929. }
  930. }
  931. function modifyPoints($aid, $points, $amt) {
  932. $q = "UPDATE " . TB_PREFIX . "users set $points = $points + $amt where id = $aid";
  933. return mysql_query($q, $this->connection);
  934. }
  935. function modifyPointsAlly($aid, $points, $amt) {
  936. $q = "UPDATE " . TB_PREFIX . "alidata set $points = $points + $amt where id = $aid";
  937. return mysql_query($q, $this->connection);
  938. }
  939. /*****************************************
  940. Function to create an alliance
  941. References:
  942. *****************************************/
  943. function createAlliance($tag, $name, $uid, $max) {
  944. $q = "INSERT into " . TB_PREFIX . "alidata values (0,'$name','$tag',$uid,0,0,0,'','',$max,'','','','','','','','')";
  945. mysql_query($q, $this->connection);
  946. return mysql_insert_id($this->connection);
  947. }
  948. /*****************************************
  949. Function to insert an alliance new
  950. References:
  951. *****************************************/
  952. function insertAlliNotice($aid, $notice) {
  953. $time = time();
  954. $q = "INSERT into " . TB_PREFIX . "ali_log values (0,'$aid','$notice',$time)";
  955. mysql_query($q, $this->connection);
  956. return mysql_insert_id($this->connection);
  957. }
  958. /*****************************************
  959. Function to delete alliance if empty
  960. References:
  961. *****************************************/
  962. function deleteAlliance($aid) {
  963. $result = mysql_query("SELECT * FROM " . TB_PREFIX . "users where alliance = $aid");
  964. $num_rows = mysql_num_rows($result);
  965. if($num_rows == 0) {
  966. $q = "DELETE FROM " . TB_PREFIX . "alidata WHERE id = $aid";
  967. }
  968. mysql_query($q, $this->connection);
  969. return mysql_insert_id($this->connection);
  970. }
  971. /*****************************************
  972. Function to read all alliance news
  973. References:
  974. *****************************************/
  975. function readAlliNotice($aid) {
  976. $q = "SELECT * from " . TB_PREFIX . "ali_log where aid = $aid ORDER BY date DESC";
  977. $result = mysql_query($q, $this->connection);
  978. return $this->mysql_fetch_all($result);
  979. }
  980. /*****************************************
  981. Function to create alliance permissions
  982. References: ID, notice, description
  983. *****************************************/
  984. function createAlliPermissions($uid, $aid, $rank, $opt1, $opt2, $opt3, $opt4, $opt5, $opt6, $opt7, $opt8) {
  985. $q = "INSERT into " . TB_PREFIX . "ali_permission values(0,'$uid','$aid','$rank','$opt1','$opt2','$opt3','$opt4','$opt5','$opt6','$opt7','$opt8')";
  986. mysql_query($q, $this->connection);
  987. return mysql_insert_id($this->connection);
  988. }
  989. /*****************************************
  990. Function to update alliance permissions
  991. References:
  992. *****************************************/
  993. function deleteAlliPermissions($uid) {
  994. $q = "DELETE from " . TB_PREFIX . "ali_permission where uid = '$uid'";
  995. return mysql_query($q, $this->connection);
  996. }
  997. /*****************************************
  998. Function to update alliance permissions
  999. References:
  1000. *****************************************/
  1001. function updateAlliPermissions($uid, $aid, $rank, $opt1, $opt2, $opt3, $opt4, $opt5, $opt6, $opt7) {
  1002. $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";
  1003. return mysql_query($q, $this->connection);
  1004. }
  1005. /*****************************************
  1006. Function to read alliance permissions
  1007. References: ID, notice, description
  1008. *****************************************/
  1009. function getAlliPermissions($uid, $aid) {
  1010. $q = "SELECT * FROM " . TB_PREFIX . "ali_permission where uid = $uid && alliance = $aid";
  1011. $result = mysql_query($q, $this->connection);
  1012. return mysql_fetch_assoc($result);
  1013. }
  1014. /*****************************************
  1015. Function to update an alliance description and notice
  1016. References: ID, notice, description
  1017. *****************************************/
  1018. function submitAlliProfile($aid, $notice, $desc) {
  1019. $q = "UPDATE " . TB_PREFIX . "alidata SET `notice` = '$notice', `desc` = '$desc' where id = $aid";
  1020. return mysql_query($q, $this->connection);
  1021. }
  1022. function diplomacyInviteAdd($alli1, $alli2, $type) {
  1023. $q = "INSERT INTO " . TB_PREFIX . "diplomacy (alli1,alli2,type,accepted) VALUES ($alli1,$alli2," . (int)intval($type) . ",0)";
  1024. return mysql_query($q, $this->connection);
  1025. }
  1026. function diplomacyOwnOffers($session_alliance) {
  1027. $q = "SELECT * FROM " . TB_PREFIX . "diplomacy WHERE alli1 = $session_alliance AND accepted = 0";
  1028. $result = mysql_query($q, $this->connection);
  1029. return $this->mysql_fetch_all($result);
  1030. }
  1031. function getAllianceID($name) {
  1032. $q = "SELECT id FROM " . TB_PREFIX . "alidata WHERE tag ='" . $this->RemoveXSS($name) . "'";
  1033. $result = mysql_query($q, $this->connection);
  1034. $dbarray = mysql_fetch_array($result);
  1035. return $dbarray['id'];
  1036. }
  1037. function getDiplomacy($aid) {
  1038. $q = "SELECT * FROM " . TB_PREFIX . "diplomacy WHERE id = $aid";
  1039. $result = mysql_query($q, $this->connection);
  1040. return $this->mysql_fetch_all($result);
  1041. }
  1042. function diplomacyCancelOffer($id) {
  1043. $q = "DELETE FROM " . TB_PREFIX . "diplomacy WHERE id = $id";
  1044. return mysql_query($q, $this->connection);
  1045. }
  1046. function diplomacyInviteAccept($id, $session_alliance) {
  1047. $q = "UPDATE " . TB_PREFIX . "diplomacy SET accepted = 1 WHERE id = $id AND alli2 = $session_alliance";
  1048. return mysql_query($q, $this->connection);
  1049. }
  1050. function diplomacyInviteDenied($id, $session_alliance) {
  1051. $q = "DELETE FROM " . TB_PREFIX . "diplomacy WHERE id = $id AND alli2 = $session_alliance";
  1052. return mysql_query($q, $this->connection);
  1053. }
  1054. function diplomacyInviteCheck($session_alliance) {
  1055. $q = "SELECT * FROM " . TB_PREFIX . "diplomacy WHERE alli2 = $session_alliance AND accepted = 0";
  1056. $result = mysql_query($q, $this->connection);
  1057. return $this->mysql_fetch_all($result);
  1058. }
  1059. function getAllianceDipProfile($aid, $type){
  1060. $q = "SELECT * FROM ".TB_PREFIX."diplomacy WHERE alli1 = '$aid' AND type = '$type' AND accepted = '1'";
  1061. $result = mysql_query($q, $this->connection);
  1062. if(mysql_num_rows($result) == 0){
  1063. $q2 = "SELECT * FROM ".TB_PREFIX."diplomacy WHERE alli2 = '$aid' AND type = '$type' AND accepted = '1'";
  1064. $result2 = mysql_query($q2, $this->connection);
  1065. while($row = mysql_fetch_array($result2)){
  1066. $alliance = $this->getAlliance($row['alli1']);
  1067. $text = "";
  1068. $text .= "<a href=allianz.php?aid=".$alliance['id'].">".$alliance['tag']."</a><br> ";
  1069. }
  1070. }else{
  1071. while($row = mysql_fetch_array($result)){
  1072. $alliance = $this->getAlliance($row['alli2']);
  1073. $text = "";
  1074. $text .= "<a href=allianz.php?aid=".$alliance['id'].">".$alliance['tag']."</a><br> ";
  1075. }
  1076. }
  1077. if(strlen($text) == 0){
  1078. $text = "-<br>";
  1079. }
  1080. return $text;
  1081. }
  1082. function getAllianceAlly($aid, $type){
  1083. $q = "SELECT * FROM ".TB_PREFIX."diplomacy WHERE (alli1 = '$aid' or alli2 = '$aid') AND (type = '$type' AND accepted = '1')";
  1084. $result = mysql_query($q, $this->connection);
  1085. return $this->mysql_fetch_all($result);
  1086. }
  1087. function diplomacyExistingRelationships($session_alliance) {
  1088. $q = "SELECT * FROM " . TB_PREFIX . "diplomacy WHERE alli2 = $session_alliance AND accepted = 1";
  1089. $result = mysql_query($q, $this->connection);
  1090. return $this->mysql_fetch_all($result);
  1091. }
  1092. function diplomacyExistingRelationships2($session_alliance) {
  1093. $q = "SELECT * FROM " . TB_PREFIX . "diplomacy WHERE alli1 = $session_alliance AND accepted = 1";
  1094. $result = mysql_query($q, $this->connection);
  1095. return $this->mysql_fetch_all($result);
  1096. }
  1097. function diplomacyCancelExistingRelationship($id, $session_alliance) {
  1098. $q = "DELETE FROM " . TB_PREFIX . "diplomacy WHERE id = $id AND alli2 = $session_alliance";
  1099. return mysql_query($q, $this->connection);
  1100. }
  1101. function getUserAlliance($id) {
  1102. $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";
  1103. $result = mysql_query($q, $this->connection);
  1104. $dbarray = mysql_fetch_array($result);
  1105. if($dbarray['tag'] == "") {
  1106. return "-";
  1107. } else {
  1108. return $dbarray['tag'];
  1109. }
  1110. }
  1111. function modifyResource($vid, $wood, $clay, $iron, $crop, $mode) {
  1112. if(!$mode) {
  1113. $q = "UPDATE " . TB_PREFIX . "vdata set wood = wood - $wood, clay = clay - $clay, iron = iron - $iron, crop = crop - $crop where wref = $vid";
  1114. } else {
  1115. $q = "UPDATE " . TB_PREFIX . "vdata set wood = wood + $wood, clay = clay + $clay, iron = iron + $iron, crop = crop + $crop where wref = $vid";
  1116. }
  1117. // echo $q;
  1118. return mysql_query($q, $this->connection);
  1119. }
  1120. function modifyOasisResource($vid, $wood, $clay, $iron, $crop, $mode) {
  1121. if(!$mode) {
  1122. $q = "UPDATE " . TB_PREFIX . "odata set wood = wood - $wood, clay = clay - $clay, iron = iron - $iron, crop = crop - $crop where wref = $vid";
  1123. } else {
  1124. $q = "UPDATE " . TB_PREFIX . "odata set wood = wood + $wood, clay = clay + $clay, iron = iron + $iron, crop = crop + $crop where wref = $vid";
  1125. }
  1126. // echo $q;
  1127. return mysql_query($q, $this->connection);
  1128. }
  1129. function getFieldLevel($vid, $field) {
  1130. $q = "SELECT f" . $field . " from " . TB_PREFIX . "fdata where vref = $vid";
  1131. $result = mysql_query($q, $this->connection);
  1132. return mysql_result($result, 0);
  1133. }
  1134. function getFieldType($vid, $field) {
  1135. $q = "SELECT f" . $field . "t from " . TB_PREFIX . "fdata where vref = $vid";
  1136. $result = mysql_query($q, $this->connection);
  1137. return mysql_result($result, 0);
  1138. }
  1139. function getVSumField($uid, $field) {
  1140. $q = "SELECT sum(" . $field . ") FROM " . TB_PREFIX . "vdata where owner = $uid";
  1141. $result = mysql_query($q, $this->connection);
  1142. $row = mysql_fetch_row($result);
  1143. return $row[0];
  1144. }
  1145. function updateVillage($vid) {
  1146. $time = time();
  1147. $q = "UPDATE " . TB_PREFIX . "vdata set lastupdate = $time where wref = $vid";
  1148. return mysql_query($q, $this->connection);
  1149. }
  1150. function updateOasis($vid) {
  1151. $time = time();
  1152. $q = "UPDATE " . TB_PREFIX . "odata set lastupdated = $time where wref = $vid";
  1153. return mysql_query($q, $this->connection);
  1154. }
  1155. function setVillageName($vid, $name) {
  1156. $q = "UPDATE " . TB_PREFIX . "vdata set name = '$name' where wref = $vid";
  1157. return mysql_query($q, $this->connection);
  1158. }
  1159. function modifyPop($vid, $pop, $mode) {
  1160. if(!$mode) {
  1161. $q = "UPDATE " . TB_PREFIX . "vdata set pop = pop + $pop where wref = $vid";
  1162. } else {
  1163. $q = "UPDATE " . TB_PREFIX . "vdata set pop = pop - $pop where wref = $vid";
  1164. }
  1165. return mysql_query($q, $this->connection);
  1166. }
  1167. function addCP($ref, $cp) {
  1168. $q = "UPDATE " . TB_PREFIX . "vdata set cp = cp + $cp where wref = $ref";
  1169. return mysql_query($q, $this->connection);
  1170. }
  1171. function addCel($ref, $cel, $type) {
  1172. $q = "UPDATE " . TB_PREFIX . "vdata set celebration = $cel, type= $type where wref = $ref";
  1173. return mysql_query($q, $this->connection);
  1174. }
  1175. function getCel() {
  1176. $time = time();
  1177. $q = "SELECT * FROM " . TB_PREFIX . "vdata where celebration < $time AND celebration != 0";
  1178. $result = mysql_query($q, $this->connection);
  1179. return $this->mysql_fetch_all($result);
  1180. }
  1181. function clearCel($ref) {
  1182. $q = "UPDATE " . TB_PREFIX . "vdata set celebration = 0, type = 0 where wref = $ref";
  1183. return mysql_query($q, $this->connection);
  1184. }
  1185. function setCelCp($user, $cp) {
  1186. $q = "UPDATE " . TB_PREFIX . "users set cp = cp + $cp where id = $user";
  1187. return mysql_query($q, $this->connection);
  1188. }
  1189. function clearExpansionSlot($id) {
  1190. for($i = 1; $i <= 3; $i++) {
  1191. $q = "UPDATE " . TB_PREFIX . "vdata SET exp" . $i . "=0 WHERE exp" . $i . "=" . $id;
  1192. mysql_query($q, $this->connection);
  1193. }
  1194. }
  1195. function getInvitation($uid) {
  1196. $q = "SELECT * FROM " . TB_PREFIX . "ali_invite where uid = $uid";
  1197. $result = mysql_query($q, $this->connection);
  1198. return $this->mysql_fetch_all($result);
  1199. }
  1200. function getAliInvitations($aid) {
  1201. $q = "SELECT * FROM " . TB_PREFIX . "ali_invite where alliance = $aid && accept = 0";
  1202. $result = mysql_query($q, $this->connection);
  1203. return $this->mysql_fetch_all($result);
  1204. }
  1205. function sendInvitation($uid, $alli, $sender) {
  1206. $time = time();
  1207. $q = "INSERT INTO " . TB_PREFIX . "ali_invite values (0,$uid,$alli,$sender,$time,0)";
  1208. return mysql_query($q, $this->connection) or die(mysql_error());
  1209. }
  1210. function removeInvitation($id) {
  1211. $q = "DELETE FROM " . TB_PREFIX . "ali_invite where id = $id";
  1212. return mysql_query($q, $this->connection);
  1213. }
  1214. function sendMessage($client, $owner, $topic, $message, $send) {
  1215. $time = time();
  1216. $q = "INSERT INTO " . TB_PREFIX . "mdata values (0,$client,$owner,'$topic',\"$message\",0,0,$send,$time)";
  1217. return mysql_query($q, $this->connection);
  1218. }
  1219. function setArchived($id) {
  1220. $q = "UPDATE " . TB_PREFIX . "mdata set archived = 1 where id = $id";
  1221. return mysql_query($q, $this->connection);
  1222. }
  1223. function setNorm($id) {
  1224. $q = "UPDATE " . TB_PREFIX . "mdata set archived = 0 where id = $id";
  1225. return mysql_query($q, $this->connection);
  1226. }
  1227. /***************************
  1228. Function to get messages
  1229. Mode 1: Get inbox
  1230. Mode 2: Get sent
  1231. Mode 3: Get message
  1232. Mode 4: Set viewed
  1233. Mode 5: Remove message
  1234. Mode 6: Retrieve archive
  1235. References: User ID/Message ID, Mode
  1236. ***************************/
  1237. function getMessage($id, $mode) {
  1238. global $session;
  1239. switch($mode) {
  1240. case 1:
  1241. $q = "SELECT * FROM " . TB_PREFIX . "mdata WHERE target = $id and send = 0 and archived = 0 ORDER BY time DESC";
  1242. break;
  1243. case 2:
  1244. // removed send no longer needed as we dont send 2 messages any more just 1
  1245. $q = "SELECT * FROM " . TB_PREFIX . "mdata WHERE owner = $id ORDER BY time DESC";
  1246. break;
  1247. case 3:
  1248. $q = "SELECT * FROM " . TB_PREFIX . "mdata where id = $id";
  1249. break;
  1250. case 4:
  1251. $q = "UPDATE " . TB_PREFIX . "mdata set viewed = 1 where id = $id AND target = $session->uid";
  1252. break;
  1253. case 5:
  1254. $q = "DELETE FROM " . TB_PREFIX . "mdata where id = $id";
  1255. break;
  1256. case 6:
  1257. $q = "SELECT * FROM " . TB_PREFIX . "mdata where target = $id and send = 0 and archived = 1";
  1258. break;
  1259. }
  1260. if($mode <= 3 || $mode == 6) {
  1261. $result = mysql_query($q, $this->connection);
  1262. return $this->mysql_fetch_all($result);
  1263. } else {
  1264. return mysql_query($q, $this->connection);
  1265. }
  1266. }
  1267. function unarchiveNotice($id) {
  1268. $q = "UPDATE " . TB_PREFIX . "ndata set ntype = archive, archive = 0 where id = $id";
  1269. return mysql_query($q, $this->connection);
  1270. }
  1271. function archiveNotice($id) {
  1272. $q = "update " . TB_PREFIX . "ndata set archive = ntype, ntype = 9 where id = $id";
  1273. return mysql_query($q, $this->connection);
  1274. }
  1275. function removeNotice($id) {
  1276. $q = "DELETE FROM " . TB_PREFIX . "ndata where id = $id";
  1277. return mysql_query($q, $this->connection);
  1278. }
  1279. function noticeViewed($id) {
  1280. $q = "UPDATE " . TB_PREFIX . "ndata set viewed = 1 where id = $id";
  1281. return mysql_query($q, $this->connection);
  1282. }
  1283. function addNotice($uid, $type, $topic, $data, $time = 0) {
  1284. if($time == 0) {
  1285. $time = time();
  1286. }
  1287. $q = "INSERT INTO " . TB_PREFIX . "ndata (id, uid, topic, ntype, data, time, viewed) values (0,'$uid','$topic',$type,'$data',$time,0)";
  1288. return mysql_query($q, $this->connection) or die(mysql_error());
  1289. }
  1290. function getNotice($uid) {
  1291. $q = "SELECT * FROM " . TB_PREFIX . "ndata where uid = $uid ORDER BY time DESC";
  1292. $result = mysql_query($q, $this->connection);
  1293. return $this->mysql_fetch_all($result);
  1294. }
  1295. function addBuilding($wid, $field, $type, $loop, $time) {
  1296. $x = "UPDATE " . TB_PREFIX . "fdata SET f" . $field . "t=" . $type . " WHERE vref=" . $wid;
  1297. mysql_query($x, $this->connection) or die(mysql_error());
  1298. $q = "INSERT into " . TB_PREFIX . "bdata values (0,$wid,$field,$type,$loop,$time)";
  1299. return mysql_query($q, $this->connection);
  1300. }
  1301. function removeBuilding($d) {
  1302. global $building;
  1303. $jobLoopconID = -1;
  1304. $SameBuildCount = 0;
  1305. $jobs = $building->buildArray;
  1306. for($i = 0; $i < sizeof($jobs); $i++) {
  1307. if($jobs[$i]['id'] == $d) {
  1308. $jobDeleted = $i;
  1309. }
  1310. if($jobs[$i]['loopcon'] == 1) {
  1311. $jobLoopconID = $i;
  1312. }
  1313. }
  1314. if(count($jobs) > 1 && ($jobs[0]['field'] == $jobs[1]['field'])) {
  1315. $SameBuildCount = 1;
  1316. }
  1317. if(count($jobs) > 2 && ($jobs[0]['field'] == $jobs[2]['field'])) {
  1318. $SameBuildCount = 2;
  1319. }
  1320. if(count($jobs) > 2 && ($jobs[1]['field'] == $jobs[2]['field'])) {
  1321. $SameBuildCount = 3;
  1322. }
  1323. if($SameBuildCount > 0) {
  1324. if($d == $jobs[floor($SameBuildCount / 3)]['id'] || $d == $jobs[floor($SameBuildCount / 2) + 1]['id']) {
  1325. $q = "UPDATE " . TB_PREFIX . "bdata SET loopcon=0,timestamp=" . $jobs[floor($SameBuildCount / 3)]['timestamp'] . " WHERE ID=" . $jobs[floor($SameBuildCount / 3)]['id'] . " OR ID=" . $jobs[floor($SameBuildCount / 2) + 1]['id'];
  1326. mysql_query($q, $this->connection);
  1327. }
  1328. } else {
  1329. if($jobs[$jobDeleted]['field'] >= 19) {
  1330. $x = "SELECT f" . $jobs[$jobDeleted]['field'] . " FROM " . TB_PREFIX . "fdata WHERE vref=" . $jobs[$jobDeleted]['wid'];
  1331. $result = mysql_query($x, $this->connection) or die(mysql_error());
  1332. $fieldlevel = mysql_fetch_row($result);
  1333. if($fieldlevel[0] == 0) {
  1334. $x = "UPDATE " . TB_PREFIX . "fdata SET f" . $jobs[$jobDeleted]['field'] . "t=0 WHERE vref=" . $jobs[$jobDeleted]['wid'];
  1335. mysql_query($x, $this->connection) or die(mysql_error());
  1336. }
  1337. }
  1338. if(($jobLoopconID >= 0) && ($jobs[$jobDeleted]['loopcon'] != 1)) {
  1339. if(($jobs[$jobLoopconID]['field'] <= 18 && $jobs[$jobDeleted]['field'] <= 18) || ($jobs[$jobLoopconID]['field'] >= 19 && $jobs[$jobDeleted]['field'] >= 19)) {
  1340. $uprequire = $building->resourceRequired($jobs[$jobLoopconID]['field'], $jobs[$jobLoopconID]['type']);
  1341. $x = "UPDATE " . TB_PREFIX . "bdata SET loopcon=0,timestamp=" . (time() + $uprequire['time']) . " WHERE wid=" . $jobs[$jobDeleted]['wid'] . " AND loopcon=1";
  1342. mysql_query($x, $this->connection) or die(mysql_error());
  1343. }
  1344. }
  1345. }
  1346. $q = "DELETE FROM " . TB_PREFIX . "bdata where id = $d";
  1347. return mysql_query($q, $this->connection);
  1348. }
  1349. function addDemolition($wid, $field) {
  1350. global $building, $village;
  1351. $q = "DELETE FROM ".TB_PREFIX."bdata WHERE field=$field AND wid=$wid";
  1352. mysql_query($q, $this->connection);
  1353. $uprequire = $building->resourceRequired($field,$village->resarray['f'.$field.'t'],0);
  1354. $q = "INSERT INTO ".TB_PREFIX."demolition VALUES (".$wid.",".$field.",".($this->getFieldLevel($wid,$field)-1).",".(time()+floor($uprequire['time']/2)).")";
  1355. return mysql_query($q, $this->connection);
  1356. }
  1357. function getDemolition($wid = 0) {
  1358. if($wid) {
  1359. $q = "SELECT * FROM " . TB_PREFIX . "demolition WHERE vref=" . $wid;
  1360. } else {
  1361. $q = "SELECT * FROM " . TB_PREFIX . "demolition WHERE timetofinish<=" . time();
  1362. }
  1363. $result = mysql_query($q, $this->connection);
  1364. if(!empty($result)) {
  1365. return $this->mysql_fetch_all($result);
  1366. } else {
  1367. return NULL;
  1368. }
  1369. }
  1370. function finishDemolition($wid) {
  1371. $q = "UPDATE " . TB_PREFIX . "demolition SET timetofinish=" . time() . " WHERE vref=" . $wid;
  1372. return mysql_query($q, $this->connection);
  1373. }
  1374. function delDemolition($wid) {
  1375. $q = "DELETE FROM " . TB_PREFIX . "demolition WHERE vref=" . $wid;
  1376. return mysql_query($q, $this->connection);
  1377. }
  1378. function getJobs($wid) {
  1379. $q = "SELECT * FROM " . TB_PREFIX . "bdata where wid = $wid order by timestamp ASC";
  1380. $result = mysql_query($q, $this->connection);
  1381. return $this->mysql_fetch_all($result);
  1382. }
  1383. function getVillageByName($name) {
  1384. $name = mysql_real_escape_string($name, $this->connection);
  1385. $q = "SELECT wref FROM " . TB_PREFIX . "vdata where name = '$name' limit 1";
  1386. $result = mysql_query($q, $this->connection);
  1387. $dbarray = mysql_fetch_array($result);
  1388. return $dbarray['wref'];
  1389. }
  1390. /***************************
  1391. Function to set accept flag on market
  1392. References: id
  1393. ***************************/
  1394. function setMarketAcc($id) {
  1395. $q = "UPDATE " . TB_PREFIX . "market set accept = 1 where id = $id";
  1396. return mysql_query($q, $this->connection);
  1397. }
  1398. /***************************
  1399. Function to send resource to other village
  1400. Mode 0: Send
  1401. Mode 1: Cancel
  1402. References: Wood/ID, Clay, Iron, Crop, Mode
  1403. ***************************/
  1404. function sendResource($ref, $clay, $iron, $crop, $merchant, $mode) {
  1405. if(!$mode) {
  1406. $q = "INSERT INTO " . TB_PREFIX . "send values (0,$ref,$clay,$iron,$crop,$merchant)";
  1407. mysql_query($q, $this->connection);
  1408. return mysql_insert_id($this->connection);
  1409. } else {
  1410. $q = "DELETE FROM " . TB_PREFIX . "send where id = $ref";
  1411. return mysql_query($q, $this->connection);
  1412. }
  1413. }
  1414. /***************************
  1415. Function to get resources back if you delete offer
  1416. References: VillageRef (vref)
  1417. Made by: Dzoki
  1418. ***************************/
  1419. function getResourcesBack($vref, $gtype, $gamt) {
  1420. //Xtype (1) = wood, (2) = clay, (3) = iron, (4) = crop
  1421. if($gtype == 1) {
  1422. $q = "UPDATE " . TB_PREFIX . "vdata SET `wood` = `wood` + '$gamt' WHERE wref = $vref";
  1423. return mysql_query($q, $this->connection);
  1424. } else
  1425. if($gtype == 2) {
  1426. $q = "UPDATE " . TB_PREFIX . "vdata SET `clay` = `clay` + '$gamt' WHERE wref = $vref";
  1427. return mysql_query($q, $this->connection);
  1428. } else
  1429. if($gtype == 3) {
  1430. $q = "UPDATE " . TB_PREFIX . "vdata SET `iron` = `iron` + '$gamt' WHERE wref = $vref";
  1431. return mysql_query($q, $this->connection);
  1432. } else
  1433. if($gtype == 4) {
  1434. $q = "UPDATE " . TB_PREFIX . "vdata SET `crop` = `crop` + '$gamt' WHERE wref = $vref";
  1435. return mysql_query($q, $this->connection);
  1436. }
  1437. }
  1438. /***************************
  1439. Function to get info about offered resources
  1440. References: VillageRef (vref)
  1441. Made by: Dzoki
  1442. ***************************/
  1443. function getMarketField($vref, $field) {
  1444. $q = "SELECT $field FROM " . TB_PREFIX . "market where vref = '$vref'";
  1445. $result = mysql_query($q, $this->connection) or die(mysql_error());
  1446. $dbarray = mysql_fetch_array($result);
  1447. return $dbarray[$field];
  1448. }
  1449. function removeAcceptedOffer($id) {
  1450. $q = "DELETE FROM " . TB_PREFIX . "market where id = $id";
  1451. $result = mysql_query($q, $this->connection);
  1452. return mysql_fetch_assoc($result);
  1453. }
  1454. /***************************
  1455. Function to add market offer
  1456. Mode 0: Add
  1457. Mode 1: Cancel
  1458. References: Village, Give, Amt, Want, Amt, Time, Alliance, Mode
  1459. ***************************/
  1460. function addMarket($vid, $gtype, $gamt, $wtype, $wamt, $time, $alliance, $merchant, $mode) {
  1461. if(!$mode) {
  1462. $q = "INSERT INTO " . TB_PREFIX . "market values (0,$vid,$gtype,$gamt,$wtype,$wamt,0,$time,$alliance,$merchant)";
  1463. mysql_query($q, $this->connection);
  1464. return mysql_insert_id($this->connection);
  1465. } else {
  1466. $q = "DELETE FROM " . TB_PREFIX . "market where id = $gtype and vref = $vid";
  1467. return mysql_query($q, $this->connection);
  1468. }
  1469. }
  1470. /***************************
  1471. Function to get market offer
  1472. References: Village, Mode
  1473. ***************************/
  1474. function getMarket($vid, $mode) {
  1475. $alliance = $this->getUserField($this->getVillageField($vid, "owner"), "alliance", 0);
  1476. if(!$mode) {
  1477. $q = "SELECT * FROM " . TB_PREFIX . "market where vref = $vid and accept = 0";
  1478. } else {
  1479. $q = "SELECT * FROM " . TB_PREFIX . "market where vref != $vid and alliance = $alliance or vref != $vid and alliance = 0 and accept = 0";
  1480. }
  1481. $result = mysql_query($q, $this->connection);
  1482. return $this->mysql_fetch_all($result);
  1483. }
  1484. /***************************
  1485. Function to get market offer
  1486. References: ID
  1487. ***************************/
  1488. function getMarketInfo($id) {
  1489. $q = "SELECT * FROM " . TB_PREFIX . "market where id = $id";
  1490. $result = mysql_query($q, $this->connection);
  1491. return mysql_fetch_assoc($result);
  1492. }
  1493. function setMovementProc($moveid) {
  1494. $q = "UPDATE " . TB_PREFIX . "movement set proc = 1 where moveid = $moveid";
  1495. return mysql_query($q, $this->connection);
  1496. }
  1497. /***************************
  1498. Function to retrieve used merchant
  1499. References: Village
  1500. ***************************/
  1501. function totalMerchantUsed($vid) {
  1502. $time = time();
  1503. $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";
  1504. $result = mysql_query($q, $this->connection);
  1505. $row = mysql_fetch_row($result);
  1506. $q2 = "SELECT sum(ref) from " . TB_PREFIX . "movement where sort_type = 2 and " . TB_PREFIX . "movement.to = $vid and proc = 0";
  1507. $result2 = mysql_query($q2, $this->connection);
  1508. $row2 = mysql_fetch_row($result2);
  1509. $q3 = "SELECT sum(merchant) from " . TB_PREFIX . "market where vref = $vid and accept = 0";
  1510. $result3 = mysql_query($q3, $this->connection);
  1511. $row3 = mysql_fetch_row($result3);
  1512. return $row[0] + $row2[0] + $row3[0];
  1513. }
  1514. /***************************
  1515. Function to retrieve movement of village
  1516. Type 0: Send Resource
  1517. Type 1: Send Merchant
  1518. Type 2: Return Resource
  1519. Type 3: Attack
  1520. Type 4: Return
  1521. Type 5: Settler
  1522. Type 6: Bounty Type 7: Reinf.
  1523. Mode 0: Send/Out
  1524. Mode 1: Recieve/In
  1525. References: Type, Village, Mode
  1526. ***************************/
  1527. function getMovement($type, $village, $mode) {
  1528. $time = time();
  1529. if(!$mode) {
  1530. $where = "from";
  1531. } else {
  1532. $where = "to";
  1533. }
  1534. switch($type) {
  1535. case 0:
  1536. $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";
  1537. break;
  1538. case 2:
  1539. $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";
  1540. break;
  1541. case 3:
  1542. $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";
  1543. break;
  1544. case 4:
  1545. $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";
  1546. break;
  1547. case 5:
  1548. $q = "SELECT * FROM " . TB_PREFIX . "movement where " . TB_PREFIX . "movement." . $where . " = $village and sort_type = 5 and proc = 0 ORDER BY endtime ASC";
  1549. break;
  1550. case 6:
  1551. $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";
  1552. break;
  1553. case 34:
  1554. $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";
  1555. break;
  1556. case 99:
  1557. $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";
  1558. break;
  1559. }
  1560. $result = mysql_query($q, $this->connection);
  1561. $array = $this->mysql_fetch_all($result);
  1562. return $array;
  1563. }
  1564. //=================== Fixed By Salmon+ =========================
  1565. function getMovementById($id){
  1566. $q="SELECT * FROM ".TB_PREFIX."movement where moveid = ".$id;
  1567. $result=mysql_query($q);
  1568. $array=$this->mysql_fetch_all($result);
  1569. return $array;
  1570. }
  1571. function getResourceOneField($village,$id) {
  1572. $q = "SELECT * FROM ".TB_PREFIX."movement, ".TB_PREFIX."send where ".TB_PREFIX."movement.ref = ".TB_PREFIX."send.id and ".TB_PREFIX."movement.proc = 0 and sort_type = 6 and " . TB_PREFIX . "movement.moveid = $id";
  1573. //echo$q;
  1574. // $q = "SELECT * FROM " . TB_PREFIX . "movement, " . TB_PREFIX . "send where " . TB_PREFIX . "movement.to = $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";
  1575. // echo$q;
  1576. $result = mysql_query($q, $this->connection);
  1577. $array = $this->mysql_fetch_all($result);
  1578. return $array;
  1579. }
  1580. //array(1) { [0]=> array(1) { ["owner"]=> string(1) "6" } } ||array(1) { [0]=> array(1) { ["owner"]=> string(1) "6" } } ||array(1) { [0]=> array(1) { ["owner"]=> string(1) "6" } } ||array(1) { [0]=> array(1) { ["owner"]=> string(1) "6" } } ||
  1581. function checkMyVillages($wref,$uid) {
  1582. global $session;
  1583. $q = "SELECT owner from " . TB_PREFIX . "vdata where wref = $wref";
  1584. $result = mysql_query($q, $this->connection);
  1585. $data=$this->mysql_fetch_all($result);
  1586. //var_dump($data);echo"||>>$uid<<";
  1587. if ($data[0]['owner']==$uid){
  1588. return true;
  1589. }else{
  1590. return false;
  1591. }
  1592. }
  1593. function checkMyData ($wref){
  1594. $checkOasis=$this->checkMyOasis($wref);
  1595. $checkVillage=$this->checkMyVillage($wref);
  1596. if ($checkOasis>0 || $checkVillage>0){
  1597. $check=1;
  1598. }else{
  1599. $check=0;
  1600. }
  1601. return $check;
  1602. }
  1603. function checkMyOasis($villageid) {
  1604. global $session;
  1605. $q="SELECT * FROM " . TB_PREFIX . "odata WHERE wref=".$villageid." AND owner=".$session->uid;
  1606. $result = mysql_query($q);
  1607. if (mysql_num_rows($result)>0){
  1608. $check=1;
  1609. }else{
  1610. $check=0;
  1611. }
  1612. return $check;
  1613. }
  1614. function getTotalBounty($units,$att_tribe) {
  1615. //var_dump($units);
  1616. $start = ($att_tribe-1)*10+1;
  1617. $end = ($att_tribe*10);
  1618. $max_bounty = 0;
  1619. $countunit=0;
  1620. for($i=$start;$i<=$end;$i++) {
  1621. // echo$i;
  1622. global ${'u'.$i};
  1623. // echo $units['t'.(($i-$start)+1)]."||".${'u'.$i}['cap'];
  1624. $countunit++;
  1625. $max_bounty += $units['t'.$countunit]*${'u'.$i}['cap'];
  1626. }
  1627. return $max_bounty;
  1628. }
  1629. function getReportOfVillage ($uid,$myvillage,$dataarray) {
  1630. // var_dump($dataarray);
  1631. $villageid=$dataarray;
  1632. if ($myvillage == 1){
  1633. $q = "SELECT * FROM " . TB_PREFIX . "ndata where uid = $uid AND (ntype = 4 OR ntype = 0) AND data LIKE '%$villageid%' ORDER BY time DESC";
  1634. }else{
  1635. $q = "SELECT * FROM " . TB_PREFIX . "ndata where uid = $uid AND ntype != 4 AND data LIKE '%$villageid%' ORDER BY time DESC";
  1636. }
  1637. //$q = "SELECT * FROM " . TB_PREFIX . "ndata where data LIKE '%$villageid%' ORDER BY time DESC";
  1638. $result = mysql_query($q, $this->connection);
  1639. return $this->mysql_fetch_all($result);
  1640. }
  1641. function checkMyVillage ($villageid){
  1642. global $session;
  1643. $q="SELECT * FROM " . TB_PREFIX . "vdata WHERE wref=".$villageid." AND owner=".$session->uid;
  1644. $result = mysql_query($q);
  1645. if (mysql_num_rows($result)>0){
  1646. $check=1;
  1647. }else{
  1648. $check=0;
  1649. }
  1650. return $check;
  1651. }
  1652. function modifyHeroAttack($aid, $unit, $amt) {
  1653. $q = "UPDATE " . TB_PREFIX . "hero set $unit = $unit - $amt where id = $aid";
  1654. return mysql_query($q, $this->connection);
  1655. }
  1656. /*
  1657. function heroLvlUp($hero_info,$hero_levels,$uid){
  1658. // $datareturn=array();
  1659. if ($hero_info['experience'] > $hero_levels[$hero_info['level']+1]) {
  1660. mysql_query("UPDATE ".TB_PREFIX."hero SET `level` = `level` + 1 where `uid`='".$uid."'");
  1661. mysql_query("UPDATE ".TB_PREFIX."hero SET `points` = `points` + 5 where `uid`='".$uid."'");
  1662. // $hero = mysql_query("SELECT * FROM " . TB_PREFIX . "hero WHERE `uid` = " . $uid . "");
  1663. // $hero_info = mysql_fetch_array($hero);
  1664. $datareturn=true;
  1665. // $datareturn[1]=$hero_info;
  1666. } else {
  1667. $datareturn=false;
  1668. // $datareturn[1]=false;
  1669. }
  1670. return $datareturn;
  1671. }
  1672. function heroMultiLvlUp($hero_info,$hero_levels,$uid){
  1673. $i=0;
  1674. while ($i<1){
  1675. if (($this->heroLvlUp($hero_info,$hero_levels,$uid)==true){
  1676. }else{
  1677. $i=1;
  1678. }
  1679. }
  1680. }*/
  1681. //============================================================================================
  1682. function addA2b($ckey, $timestamp, $to, $t1, $t2, $t3, $t4, $t5, $t6, $t7, $t8, $t9, $t10, $t11, $type) {
  1683. $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')";
  1684. mysql_query($q, $this->connection);
  1685. return mysql_insert_id($this->connection);
  1686. }
  1687. function getA2b($ckey, $check) {
  1688. $q = "SELECT * from " . TB_PREFIX . "a2b where ckey = '" . $ckey . "' AND time_check = '" . $check . "'";
  1689. $result = mysql_query($q, $this->connection);
  1690. if($result) {
  1691. return mysql_fetch_assoc($result);
  1692. } else {
  1693. return false;
  1694. }
  1695. }
  1696. function addMovement($type, $from, $to, $ref, $endtime) {
  1697. $q = "INSERT INTO " . TB_PREFIX . "movement values (0,$type,$from,$to,$ref,".time().",$endtime,0)";
  1698. return mysql_query($q, $this->connection);
  1699. }
  1700. 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) {
  1701. $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)";
  1702. mysql_query($q, $this->connection);
  1703. return mysql_insert_id($this->connection);
  1704. }
  1705. function modifyAttack($aid, $unit, $amt) {
  1706. $unit = 't' . $unit;
  1707. $q = "UPDATE " . TB_PREFIX . "attacks set $unit = $unit - $amt where id = $aid";
  1708. return mysql_query($q, $this->connection);
  1709. }
  1710. function getRanking() {
  1711. $q = "SELECT id,username,alliance,ap,apall,dp,dpall,access FROM " . TB_PREFIX . "users WHERE tribe<=3 AND access<" . (INCLUDE_ADMIN ? "10" : "8");
  1712. $result = mysql_query($q, $this->connection);
  1713. return $this->mysql_fetch_all($result);
  1714. }
  1715. function getVRanking() {
  1716. $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");
  1717. $result = mysql_query($q, $this->connection);
  1718. return $this->mysql_fetch_all($result);
  1719. }
  1720. function getARanking() {
  1721. $q = "SELECT id,name,tag FROM " . TB_PREFIX . "alidata where id != ''";
  1722. $result = mysql_query($q, $this->connection);
  1723. return $this->mysql_fetch_all($result);
  1724. }
  1725. function getHeroRanking() {
  1726. $q = "SELECT * FROM " . TB_PREFIX . "hero WHERE dead = 0";
  1727. $result = mysql_query($q, $this->connection);
  1728. return $this->mysql_fetch_all($result);
  1729. }
  1730. function getAllMember($aid) {
  1731. $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";
  1732. $result = mysql_query($q, $this->connection);
  1733. return $this->mysql_fetch_all($result);
  1734. }
  1735. function addUnits($vid) {
  1736. $q = "INSERT into " . TB_PREFIX . "units (vref) values ($vid)";
  1737. return mysql_query($q, $this->connection);
  1738. }
  1739. function getUnit($vid) {
  1740. $q = "SELECT * from " . TB_PREFIX . "units where vref = $vid";
  1741. $result = mysql_query($q, $this->connection);
  1742. if (!empty($result)) {
  1743. return mysql_fetch_assoc($result);
  1744. } else {
  1745. return NULL;
  1746. }
  1747. }
  1748. function getHero($uid=0,$all=0) {
  1749. if ($all) {
  1750. $q = "SELECT * FROM ".TB_PREFIX."hero WHERE uid=$uid";
  1751. } elseif (!$uid) {
  1752. $q = "SELECT * FROM ".TB_PREFIX."hero";
  1753. } else {
  1754. $q = "SELECT * FROM ".TB_PREFIX."hero WHERE dead=0 AND uid=$uid LIMIT 1";
  1755. }
  1756. $result = mysql_query($q, $this->connection);
  1757. if (!empty($result)) {
  1758. return $this->mysql_fetch_all($result);
  1759. } else {
  1760. return NULL;
  1761. }
  1762. }
  1763. function getHeroField($uid,$field){
  1764. $q = "SELECT * FROM ".TB_PREFIX."hero WHERE uid = $uid";
  1765. $result = mysql_query($q,$this->connection);
  1766. return $this->mysql_fetch_all($result);
  1767. }
  1768. function modifyHero($column,$value,$heroid,$mode=0) {
  1769. if(!$mode) {
  1770. $q = "UPDATE `".TB_PREFIX."hero` SET $column = $value WHERE heroid = $heroid";
  1771. } elseif($mode=1) {
  1772. $q = "UPDATE `".TB_PREFIX."hero` SET $column = $column + $value WHERE heroid = $heroid";
  1773. } else {
  1774. $q = "UPDATE `".TB_PREFIX."hero` SET $column = $column - $value WHERE heroid = $heroid";
  1775. }
  1776. return mysql_query($q, $this->connection);
  1777. }
  1778. function modifyHeroXp($column,$value,$heroid) {
  1779. $q = "UPDATE ".TB_PREFIX."hero SET $column = $column + $value WHERE uid=$heroid";
  1780. return mysql_query($q, $this->connection);
  1781. }
  1782. function addTech($vid) {
  1783. $q = "INSERT into " . TB_PREFIX . "tdata (vref) values ($vid)";
  1784. return mysql_query($q, $this->connection);
  1785. }
  1786. function addABTech($vid) {
  1787. $q = "INSERT into " . TB_PREFIX . "abdata (vref) values ($vid)";
  1788. return mysql_query($q, $this->connection);
  1789. }
  1790. function getABTech($vid) {
  1791. $q = "SELECT * FROM " . TB_PREFIX . "abdata where vref = $vid";
  1792. $result = mysql_query($q, $this->connection);
  1793. return mysql_fetch_assoc($result);
  1794. }
  1795. function addResearch($vid, $tech, $time) {
  1796. $q = "INSERT into " . TB_PREFIX . "research values (0,$vid,'$tech',$time)";
  1797. return mysql_query($q, $this->connection);
  1798. }
  1799. function getResearching($vid) {
  1800. $q = "SELECT * FROM " . TB_PREFIX . "research where vref = $vid";
  1801. $result = mysql_query($q, $this->connection);
  1802. return $this->mysql_fetch_all($result);
  1803. }
  1804. function checkIfResearched($vref, $unit) {
  1805. $q = "SELECT $unit FROM " . TB_PREFIX . "tdata WHERE vref = $vref";
  1806. $result = mysql_query($q, $this->connection) or die(mysql_error());
  1807. $dbarray = mysql_fetch_array($result);
  1808. return $dbarray[$unit];
  1809. }
  1810. function getTech($vid) {
  1811. $q = "SELECT * from " . TB_PREFIX . "tdata where vref = $vid";
  1812. $result = mysql_query($q, $this->connection);
  1813. return mysql_fetch_assoc($result);
  1814. }
  1815. function getTraining($vid) {
  1816. $q = "SELECT * FROM " . TB_PREFIX . "training where vref = $vid ORDER BY id";
  1817. $result = mysql_query($q, $this->connection);
  1818. return $this->mysql_fetch_all($result);
  1819. }
  1820. function countTraining($vid) {
  1821. $q = "SELECT * FROM " . TB_PREFIX . "training WHERE vref = $vid";
  1822. $result = mysql_query($q, $this->connection);
  1823. $row = mysql_fetch_row($result);
  1824. return $row[0];
  1825. }
  1826. function trainUnit($vid, $unit, $amt, $pop, $each, $time, $mode) {
  1827. global $village, $building, $session, $technology;
  1828. if(!$mode) {
  1829. $barracks = array(1, 2, 3, 11, 12, 13, 14, 21, 22, 31, 32, 33, 34, 41, 42, 43, 44);
  1830. $stables = array(4, 5, 6, 15, 16, 23, 24, 25, 26, 35, 36, 45, 46);
  1831. $workshop = array(7, 8, 17, 18, 27, 28, 37, 38, 47, 48);
  1832. $residence = array(9, 10, 19, 20, 29, 30, 39, 40, 49, 50);
  1833. if(in_array($unit, $barracks)) {
  1834. $queued = $technology->getTrainingList(1);
  1835. } elseif(in_array($unit, $stables)) {
  1836. $queued = $technology->getTrainingList(2);
  1837. } elseif(in_array($unit, $workshop)) {
  1838. $queued = $technology->getTrainingList(3);
  1839. } elseif(in_array($unit, $residence)) {
  1840. $queued = $technology->getTrainingList(4);
  1841. }
  1842. if(count($queued) > 0) {
  1843. $time = $queued[count($queued) - 1]['commence'] + $queued[count($queued) - 1]['eachtime'] * $queued[count($queued) - 1]['amt'];
  1844. }
  1845. $now = time();
  1846. $q = "INSERT INTO " . TB_PREFIX . "training values (0,$vid,$unit,$amt,$pop,$now,$each,$time)";
  1847. } else {
  1848. $q = "DELETE FROM " . TB_PREFIX . "training where id = $vid";
  1849. }
  1850. return mysql_query($q, $this->connection);
  1851. }
  1852. function updateTraining($id, $trained) {
  1853. $time = time();
  1854. $q = "UPDATE " . TB_PREFIX . "training set amt = amt - $trained, timestamp = $time where id = $id";
  1855. return mysql_query($q, $this->connection);
  1856. }
  1857. function modifyUnit($vref, $unit, $amt, $mode) {
  1858. if($unit == 230) {
  1859. $unit = 30;
  1860. }
  1861. if($unit == 231) {
  1862. $unit = 31;
  1863. }
  1864. if($unit == 120) {
  1865. $unit = 20;
  1866. }
  1867. if($unit == 121) {
  1868. $unit = 21;
  1869. }
  1870. if ($unit =="hero"){
  1871. $unit = 'hero';
  1872. } else {$unit = 'u' . $unit;}
  1873. if(!$mode) {
  1874. $q = "UPDATE " . TB_PREFIX . "units set $unit = $unit - $amt where vref = $vref";
  1875. } else {
  1876. $q = "UPDATE " . TB_PREFIX . "units set $unit = $unit + $amt where vref = $vref";
  1877. }
  1878. return mysql_query($q, $this->connection);
  1879. }
  1880. function getEnforce($vid, $from) {
  1881. $q = "SELECT * from " . TB_PREFIX . "enforcement where `from` = $from and vref = $vid";
  1882. $result = mysql_query($q, $this->connection);
  1883. return mysql_fetch_assoc($result);
  1884. }
  1885. function addEnforce($data) {
  1886. $q = "INSERT into " . TB_PREFIX . "enforcement (vref,`from`) values (" . $data['to'] . "," . $data['from'] . ")";
  1887. mysql_query($q, $this->connection);
  1888. $id = mysql_insert_id($this->connection);
  1889. $owntribe = $this->getUserField($this->getVillageField($data['from'], "owner"), "tribe", 0);
  1890. if (!$owntribe){$owntribe=4;}
  1891. $start = ($owntribe - 1) * 10 + 1;
  1892. $end = ($owntribe * 10);
  1893. //add unit
  1894. $j = '1';
  1895. //var_dump($data);
  1896. for($i = $start; $i <= $end; $i++) {
  1897. // echo '$this-modifyEnforce('.$id.', '.$i.', '.$data['t' . $j . ''].', 1)';
  1898. $this->modifyEnforce($id, $i, $data['t' . $j . ''], 1);
  1899. $j++;
  1900. }
  1901. $this->modifyEnforce($id,'hero',$data['t11'],1);
  1902. return mysql_insert_id($this->connection);
  1903. }
  1904. function modifyEnforce($id, $unit, $amt, $mode) {
  1905. if($unit != 'hero') { $unit = 'u' . $unit; }
  1906. if(!$mode) {
  1907. $q = "UPDATE " . TB_PREFIX . "enforcement set $unit = $unit - $amt where id = $id";
  1908. } else {
  1909. $q = "UPDATE " . TB_PREFIX . "enforcement set $unit = $unit + $amt where id = $id";
  1910. }
  1911. mysql_query($q, $this->connection);
  1912. }
  1913. function getEnforceArray($id, $mode) {
  1914. if(!$mode) {
  1915. $q = "SELECT * from " . TB_PREFIX . "enforcement where id = $id";
  1916. } else {
  1917. $q = "SELECT * from " . TB_PREFIX . "enforcement where `from` = $id";
  1918. }
  1919. $result = mysql_query($q, $this->connection);
  1920. return mysql_fetch_assoc($result);
  1921. }
  1922. function getNatureArray($vid) {
  1923. $q = "SELECT u31,u32,u33,u34,u35,u36,u37,u38,u39,u40 from " . TB_PREFIX . "units where vref = $vid";
  1924. $result = mysql_query($q, $this->connection);
  1925. return mysql_fetch_assoc($result);
  1926. }
  1927. function getEnforceVillage($id, $mode) {
  1928. if(!$mode) {
  1929. $q = "SELECT * from " . TB_PREFIX . "enforcement where vref = $id";
  1930. } else {
  1931. $q = "SELECT * from " . TB_PREFIX . "enforcement where `from` = $id";
  1932. }
  1933. $result = mysql_query($q, $this->connection);
  1934. return $this->mysql_fetch_all($result);
  1935. }
  1936. function getVillageMovement($id) {
  1937. $vinfo = $this->getVillage($id);
  1938. $vtribe = $this->getUserField($vinfo['owner'], "tribe", 0);
  1939. $movingunits = array();
  1940. $outgoingarray = $this->getMovement(3, $id, 0);
  1941. if(!empty($outgoingarray)) {
  1942. foreach($outgoingarray as $out) {
  1943. for($i = 1; $i <= 10; $i++) {
  1944. $movingunits['u' . (($vtribe - 1) * 10 + $i)] += $out['t' . $i];
  1945. }
  1946. $movingunits['hero'] += $out['t11'];
  1947. }
  1948. }
  1949. $returningarray = $this->getMovement(4, $id, 1);
  1950. if(!empty($returningarray)) {
  1951. foreach($returningarray as $ret) {
  1952. if($ret['attack_type'] != 1) {
  1953. for($i = 1; $i <= 10; $i++) {
  1954. $movingunits['u' . (($vtribe - 1) * 10 + $i)] += $ret['t' . $i];
  1955. }
  1956. $movingunits['hero'] += $ret['t11'];
  1957. }
  1958. }
  1959. }
  1960. $settlerarray = $this->getMovement(5, $id, 0);
  1961. if(!empty($settlerarray)) {
  1962. $movingunits['u' . ($vtribe * 10)] += 3 * count($settlerarray);
  1963. }
  1964. return $movingunits;
  1965. }
  1966. ################# -START- ##################
  1967. ## WORLD WONDER STATISTICS FUNCTIONS! ##
  1968. ############################################
  1969. /***************************
  1970. Function to get all World Wonders
  1971. Made by: Dzoki
  1972. ***************************/
  1973. function getWW() {
  1974. $q = "SELECT * FROM " . TB_PREFIX . "fdata WHERE f99t = 40";
  1975. $result = mysql_query($q, $this->connection);
  1976. if(mysql_num_rows($result)) {
  1977. return true;
  1978. } else {
  1979. return false;
  1980. }
  1981. }
  1982. /***************************
  1983. Function to get world wonder level!
  1984. Made by: Dzoki
  1985. ***************************/
  1986. function getWWLevel($vref) {
  1987. $q = "SELECT f99 FROM " . TB_PREFIX . "fdata WHERE vref = $vref";
  1988. $result = mysql_query($q, $this->connection) or die(mysql_error());
  1989. $dbarray = mysql_fetch_array($result);
  1990. return $dbarray['f99'];
  1991. }
  1992. /***************************
  1993. Function to get world wonder owner ID!
  1994. Made by: Dzoki
  1995. ***************************/
  1996. function getWWOwnerID($vref) {
  1997. $q = "SELECT owner FROM " . TB_PREFIX . "vdata WHERE wref = $vref";
  1998. $result = mysql_query($q, $this->connection) or die(mysql_error());
  1999. $dbarray = mysql_fetch_array($result);
  2000. return $dbarray['owner'];
  2001. }
  2002. /***************************
  2003. Function to get user alliance name!
  2004. Made by: Dzoki
  2005. ***************************/
  2006. function getUserAllianceID($id) {
  2007. $q = "SELECT alliance FROM " . TB_PREFIX . "users where id = $id";
  2008. $result = mysql_query($q, $this->connection) or die(mysql_error());
  2009. $dbarray = mysql_fetch_array($result);
  2010. return $dbarray['alliance'];
  2011. }
  2012. /***************************
  2013. Function to get WW name
  2014. Made by: Dzoki
  2015. ***************************/
  2016. function getWWName($vref) {
  2017. $q = "SELECT wwname FROM " . TB_PREFIX . "fdata WHERE vref = $vref";
  2018. $result = mysql_query($q, $this->connection) or die(mysql_error());
  2019. $dbarray = mysql_fetch_array($result);
  2020. return $dbarray['wwname'];
  2021. }
  2022. /***************************
  2023. Function to change WW name
  2024. Made by: Dzoki
  2025. ***************************/
  2026. function submitWWname($vref, $name) {
  2027. $q = "UPDATE " . TB_PREFIX . "fdata SET `wwname` = '$name' WHERE " . TB_PREFIX . "fdata.`vref` = $vref";
  2028. return mysql_query($q, $this->connection);
  2029. }
  2030. //medal functions
  2031. function addclimberpop($user, $cp) {
  2032. $q = "UPDATE " . TB_PREFIX . "users set Rc = Rc + '$cp' where id = $user";
  2033. return mysql_query($q, $this->connection);
  2034. }
  2035. function addclimberrankpop($user, $cp) {
  2036. $q = "UPDATE " . TB_PREFIX . "users set clp = clp + '$cp' where id = $user";
  2037. return mysql_query($q, $this->connection);
  2038. }
  2039. function removeclimberrankpop($user, $cp) {
  2040. $q = "UPDATE " . TB_PREFIX . "users set clp = clp - '$cp'' where id = $user";
  2041. return mysql_query($q, $this->connection);
  2042. }
  2043. function updateoldrank($user, $cp) {
  2044. $q = "UPDATE " . TB_PREFIX . "users set oldrank = '$cp' where id = $user";
  2045. return mysql_query($q, $this->connection);
  2046. }
  2047. function removeclimberpop($user, $cp) {
  2048. $q = "UPDATE " . TB_PREFIX . "users set Rc = Rc - '$cp' where id = $user";
  2049. return mysql_query($q, $this->connection);
  2050. }
  2051. // ALLIANCE MEDAL FUNCTIONS
  2052. function addclimberpopAlly($user, $cp) {
  2053. $q = "UPDATE " . TB_PREFIX . "alidata set Rc = Rc + '$cp' where id = $user";
  2054. return mysql_query($q, $this->connection);
  2055. }
  2056. function addclimberrankpopAlly($user, $cp) {
  2057. $q = "UPDATE " . TB_PREFIX . "alidata set clp = clp + '$cp' where id = $user";
  2058. return mysql_query($q, $this->connection);
  2059. }
  2060. function removeclimberrankpopAlly($user, $cp) {
  2061. $q = "UPDATE " . TB_PREFIX . "alidata set clp = clp - '$cp'' where id = $user";
  2062. return mysql_query($q, $this->connection);
  2063. }
  2064. function updateoldrankAlly($user, $cp) {
  2065. $q = "UPDATE " . TB_PREFIX . "alidata set oldrank = '$cp' where id = $user";
  2066. return mysql_query($q, $this->connection);
  2067. }
  2068. function removeclimberpopAlly($user, $cp) {
  2069. $q = "UPDATE " . TB_PREFIX . "alidata set Rc = Rc - '$cp' where id = $user";
  2070. return mysql_query($q, $this->connection);
  2071. }
  2072. function modifyCommence($id) {
  2073. $time = time();
  2074. $q = "UPDATE " . TB_PREFIX . "training set commence = $time WHERE id=$id";
  2075. return mysql_query($q, $this->connection);
  2076. }
  2077. function getTrainingList() {
  2078. $q = "SELECT * FROM " . TB_PREFIX . "training where vref != ''";
  2079. $result = mysql_query($q, $this->connection);
  2080. return $this->mysql_fetch_all($result);
  2081. }
  2082. function getNeedDelete() {
  2083. $time = time();
  2084. $q = "SELECT uid FROM " . TB_PREFIX . "deleting where timestamp < $time";
  2085. $result = mysql_query($q, $this->connection);
  2086. return $this->mysql_fetch_all($result);
  2087. }
  2088. function countUser() {
  2089. $q = "SELECT count(id) FROM " . TB_PREFIX . "users where id != 0";
  2090. $result = mysql_query($q, $this->connection);
  2091. $row = mysql_fetch_row($result);
  2092. return $row[0];
  2093. }
  2094. function countAlli() {
  2095. $q = "SELECT count(id) FROM " . TB_PREFIX . "alidata where id != 0";
  2096. $result = mysql_query($q, $this->connection);
  2097. $row = mysql_fetch_row($result);
  2098. return $row[0];
  2099. }
  2100. /***************************
  2101. Function to process MYSQLi->fetch_all (Only exist in MYSQL)
  2102. References: Result
  2103. ***************************/
  2104. function mysql_fetch_all($result) {
  2105. $all = array();
  2106. if($result) {
  2107. while($row = mysql_fetch_assoc($result)) {
  2108. $all[] = $row;
  2109. }
  2110. return $all;
  2111. }
  2112. }
  2113. function query_return($q) {
  2114. $result = mysql_query($q, $this->connection);
  2115. return $this->mysql_fetch_all($result);
  2116. }
  2117. /***************************
  2118. Function to do free query
  2119. References: Query
  2120. ***************************/
  2121. function query($query) {
  2122. return mysql_query($query, $this->connection);
  2123. }
  2124. function RemoveXSS($val) {
  2125. return htmlspecialchars($val, ENT_QUOTES);
  2126. }
  2127. //MARKET FIXES
  2128. function getWoodAvailable($wref) {
  2129. $q = "SELECT wood FROM " . TB_PREFIX . "vdata WHERE wref = $wref";
  2130. $result = mysql_query($q, $this->connection) or die(mysql_error());
  2131. $dbarray = mysql_fetch_array($result);
  2132. return $dbarray['wood'];
  2133. }
  2134. function getClayAvailable($wref) {
  2135. $q = "SELECT clay FROM " . TB_PREFIX . "vdata WHERE wref = $wref";
  2136. $result = mysql_query($q, $this->connection) or die(mysql_error());
  2137. $dbarray = mysql_fetch_array($result);
  2138. return $dbarray['clay'];
  2139. }
  2140. function getIronAvailable($wref) {
  2141. $q = "SELECT iron FROM " . TB_PREFIX . "vdata WHERE wref = $wref";
  2142. $result = mysql_query($q, $this->connection) or die(mysql_error());
  2143. $dbarray = mysql_fetch_array($result);
  2144. return $dbarray['iron'];
  2145. }
  2146. function getCropAvailable($wref) {
  2147. $q = "SELECT crop FROM " . TB_PREFIX . "vdata WHERE wref = $wref";
  2148. $result = mysql_query($q, $this->connection) or die(mysql_error());
  2149. $dbarray = mysql_fetch_array($result);
  2150. return $dbarray['crop'];
  2151. }
  2152. function Getowner($vid) {
  2153. $s = "SELECT owner FROM " . TB_PREFIX . "vdata where wref = $vid";
  2154. $result1 = mysql_query($s, $this->connection);
  2155. $row1 = mysql_fetch_row($result1);
  2156. return $row1[0];
  2157. }
  2158. public function debug($time, $uid, $debug_info) {
  2159. $q = "INSERT INTO " . TB_PREFIX . "debug_info (time,uid,debug_info) VALUES ($time,$uid,$debug_info)";
  2160. if(mysql_query($q, $this->connection)) {
  2161. return mysql_insert_id($this->connection);
  2162. } else {
  2163. return false;
  2164. }
  2165. }
  2166. function populateOasisdata() {
  2167. $q2 = "SELECT * FROM " . TB_PREFIX . "wdata where oasistype != 0";
  2168. $result2 = mysql_query($q2, $this->connection);
  2169. while($row = mysql_fetch_array($result2)) {
  2170. $wid = $row['id'];
  2171. $basearray = $this->getOMInfo($wid);
  2172. //We switch type of oasis and instert record with apropriate infomation.
  2173. $q = "INSERT into " . TB_PREFIX . "odata VALUES ('" . $basearray['id'] . "'," . $basearray['oasistype'] . ",0,400,400,400,400,400,400," . time() . ",100,2,'Unoccupied Oasis')";
  2174. $result = mysql_query($q, $this->connection);
  2175. }
  2176. }
  2177. public function getAvailableExpansionTraining() {
  2178. global $building, $session, $technology, $village;
  2179. $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";
  2180. $result = mysql_query($q, $this->connection);
  2181. $row = mysql_fetch_row($result);
  2182. $maxslots = $row[0];
  2183. $residence = $building->getTypeLevel(25);
  2184. $palace = $building->getTypeLevel(26);
  2185. if($residence > 0) {
  2186. $maxslots -= (3 - floor($residence / 10));
  2187. }
  2188. if($palace > 0) {
  2189. $maxslots -= (3 - floor(($palace - 5) / 5));
  2190. }
  2191. $q = "SELECT (u10+u20+u30) FROM " . TB_PREFIX . "units WHERE vref = $village->wid";
  2192. $result = mysql_query($q, $this->connection);
  2193. $row = mysql_fetch_row($result);
  2194. $settlers = $row[0];
  2195. $q = "SELECT (u9+u19+u29) FROM " . TB_PREFIX . "units WHERE vref = $village->wid";
  2196. $result = mysql_query($q, $this->connection);
  2197. $row = mysql_fetch_row($result);
  2198. $chiefs = $row[0];
  2199. $settlers += 3 * count($this->getMovement(5, $village->wid, 0));
  2200. $current_movement = $this->getMovement(3, $village->wid, 0);
  2201. if(!empty($current_movement)) {
  2202. foreach($current_movement as $build) {
  2203. $settlers += $build['t10'];
  2204. $chiefs += $build['t9'];
  2205. }
  2206. }
  2207. $current_movement = $this->getMovement(3, $village->wid, 1);
  2208. if(!empty($current_movement)) {
  2209. foreach($current_movement as $build) {
  2210. $settlers += $build['t10'];
  2211. $chiefs += $build['t9'];
  2212. }
  2213. }
  2214. $current_movement = $this->getMovement(4, $village->wid, 0);
  2215. if(!empty($current_movement)) {
  2216. foreach($current_movement as $build) {
  2217. $settlers += $build['t10'];
  2218. $chiefs += $build['t9'];
  2219. }
  2220. }
  2221. $current_movement = $this->getMovement(4, $village->wid, 1);
  2222. if(!empty($current_movement)) {
  2223. foreach($current_movement as $build) {
  2224. $settlers += $build['t10'];
  2225. $chiefs += $build['t9'];
  2226. }
  2227. }
  2228. $q = "SELECT (u10+u20+u30) FROM " . TB_PREFIX . "enforcement WHERE `from` = $village->wid";
  2229. $result = mysql_query($q, $this->connection);
  2230. $row = mysql_fetch_row($result);
  2231. if(!empty($row)) {
  2232. foreach($row as $reinf) {
  2233. $settlers += $reinf[0];
  2234. }
  2235. }
  2236. $q = "SELECT (u9+u19+u29) FROM " . TB_PREFIX . "enforcement WHERE `from` = $village->wid";
  2237. $result = mysql_query($q, $this->connection);
  2238. $row = mysql_fetch_row($result);
  2239. if(!empty($row)) {
  2240. foreach($row as $reinf) {
  2241. $chiefs += $reinf[0];
  2242. }
  2243. }
  2244. $trainlist = $technology->getTrainingList(4);
  2245. if(!empty($trainlist)) {
  2246. foreach($trainlist as $train) {
  2247. if($train['unit'] % 10 == 0) {
  2248. $settlers += $train['amt'];
  2249. }
  2250. if($train['unit'] % 10 == 9) {
  2251. $chiefs += $train['amt'];
  2252. }
  2253. }
  2254. }
  2255. // trapped settlers/chiefs calculation required
  2256. $settlerslots = $maxslots * 3 - $settlers - $chiefs * 3;
  2257. $chiefslots = $maxslots - $chiefs - floor(($settlers + 2) / 3);
  2258. if(!$technology->getTech(($session->tribe - 1) * 10 + 9)) {
  2259. $chiefslots = 0;
  2260. }
  2261. $slots = array("chiefs" => $chiefslots, "settlers" => $settlerslots);
  2262. return $slots;
  2263. }
  2264. function addArtefact($vref, $owner, $type, $size, $name, $desc, $effect, $img) {
  2265. $q = "INSERT INTO `" . TB_PREFIX . "artefacts` (`vref`, `owner`, `type`, `size`, `conquered`, `name`, `desc`, `effect`, `img`) VALUES ('$vref', '$owner', '$type', '$size', '" . time() . "', '$name', '$desc', '$effect', '$img')";
  2266. return mysql_query($q, $this->connection);
  2267. }
  2268. function getOwnArtefactInfo($vref) {
  2269. $q = "SELECT * FROM " . TB_PREFIX . "artefacts WHERE vref = $vref";
  2270. $result = mysql_query($q, $this->connection);
  2271. return mysql_fetch_array($result);
  2272. }
  2273. function getOwnArtefactInfoByType($vref, $type) {
  2274. $q = "SELECT * FROM " . TB_PREFIX . "artefacts WHERE vref = $vref AND type = $type";
  2275. $result = mysql_query($q, $this->connection);
  2276. return mysql_fetch_array($result);
  2277. }
  2278. function getOwnUniqueArtefactInfo($id, $type, $size) {
  2279. $q = "SELECT * FROM " . TB_PREFIX . "artefacts WHERE owner = $id AND type = $type AND size=$size";
  2280. $result = mysql_query($q, $this->connection);
  2281. return mysql_fetch_array($result);
  2282. }
  2283. function getArtefactInfo() {
  2284. $q = "SELECT * FROM " . TB_PREFIX . "artefacts WHERE id > 0";
  2285. $result = mysql_query($q, $this->connection);
  2286. return mysql_fetch_array($result);
  2287. }
  2288. function claimArtefact($vref, $ovref, $id) {
  2289. $time = time();
  2290. $q = "UPDATE " . TB_PREFIX . "artefacts SET vref = $vref, owner = $id WHERE vref = $ovref";
  2291. $result = mysql_query($q, $this->connection);
  2292. return mysql_fetch_array($result);
  2293. }
  2294. function getArtefactDetails($id) {
  2295. $q = "SELECT * FROM " . TB_PREFIX . "artefacts WHERE id = " . $id . "";
  2296. $result = mysql_query($q, $this->connection);
  2297. return mysql_fetch_array($result);
  2298. }
  2299. function getLinks($id){
  2300. $q = 'SELECT * FROM `' . TB_PREFIX . 'links` WHERE `userid` = ' . $id . ' ORDER BY `pos` ASC';
  2301. return mysql_query($q, $this->connection);
  2302. }
  2303. function getArrayMemberVillage($uid){
  2304. $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';
  2305. $result = mysql_query($q, $this->connection);
  2306. $array = $this->mysql_fetch_all($result);
  2307. return $array;
  2308. }
  2309. }
  2310. ;
  2311. $database = new MYSQL_DB;
  2312. ?>