Guest User

Untitled

a guest
Oct 18th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 47.41 KB | None | 0 0
  1. <?php
  2.  
  3. class MYSQL_DB {
  4.  
  5. var $connection;
  6.  
  7. function MYSQL_DB() {
  8.  
  9. $this->connection = mysql_connect(SQL_SERVER, SQL_USER, SQL_PASS) or die(mysql_error());
  10. mysql_select_db(SQL_DB, $this->connection) or die(mysql_error());
  11. }
  12.  
  13. function register($username,$password,$email,$tribe,$locate,$act) {
  14. $time = time();
  15. $time += PROTECTION;
  16. $q = "INSERT INTO ".TB_PREFIX."users (username,password,access,email,timestamp,tribe,location,act,protect) VALUES ('$username', '$password', ".USER.", '$email',$time, $tribe, $locate, '$act', $time)";
  17. if(mysql_query($q,$this->connection)) {
  18. return mysql_insert_id($this->connection);
  19. }
  20. else {
  21. return false;
  22. }
  23. }
  24.  
  25. function unreg($username) {
  26. $q = "DELETE from ".TB_PREFIX."users where username = '$username'";
  27. return mysql_query($q,$this->connection);
  28. }
  29.  
  30. function checkExist($ref,$mode) {
  31.  
  32. if(!$mode) {
  33. $q = "SELECT username FROM ".TB_PREFIX."users where username = '$ref' LIMIT 1";
  34. }
  35. else {
  36. $q = "SELECT email FROM ".TB_PREFIX."users where email = '$ref' LIMIT 1";
  37. }
  38. $result = mysql_query($q, $this->connection);
  39. if(mysql_num_rows($result)) {
  40. return true;
  41. }
  42. else {
  43. return false;
  44. }
  45. }
  46.  
  47. function updateUserField($ref,$field,$value,$switch) {
  48. if(!$switch) {
  49. $q = "UPDATE ".TB_PREFIX."users set $field = '$value' where username = '$ref'";
  50. }
  51. else {
  52. $q = "UPDATE ".TB_PREFIX."users set $field = '$value' where id = '$ref'";
  53. }
  54. return mysql_query($q, $this->connection);
  55. }
  56.  
  57. function getSitee($uid) {
  58. $q = "SELECT id from ".TB_PREFIX."users where sit1 = $uid or sit2 = $uid";
  59. $result = mysql_query($q,$this->connection);
  60. return $this->mysql_fetch_all($result);
  61. }
  62.  
  63. function removeMeSit($uid,$uid2) {
  64. $q = "UPDATE ".TB_PREFIX."users set sit1 = 0 where id = $uid and sit1 = $uid2";
  65. mysql_query($q,$this->connection);
  66. $q2 = "UPDATE ".TB_PREFIX."users set sit2 = 0 where id = $uid and sit2 = $uid2";
  67. mysql_query($q2,$this->connection);
  68. }
  69.  
  70. function getUserField($ref,$field,$mode) {
  71. if(!$mode) {
  72. $q = "SELECT $field FROM ".TB_PREFIX."users where id = '$ref'";
  73. }
  74. else {
  75. $q = "SELECT $field FROM ".TB_PREFIX."users where username = '$ref'";
  76. }
  77. $result = mysql_query($q, $this->connection) or die(mysql_error());
  78. $dbarray = mysql_fetch_array($result);
  79. return $dbarray[$field];
  80. }
  81.  
  82. function login($username,$password) {
  83. $q = "SELECT password,sessid FROM ".TB_PREFIX."users where username = '$username' and access != ".BANNED;
  84. $result = mysql_query($q, $this->connection);
  85. $dbarray = mysql_fetch_array($result);
  86. if($dbarray['password'] == md5($password)) {
  87. return true;
  88. }
  89. else {
  90. return false;
  91. }
  92. }
  93.  
  94. function sitterLogin($username,$password) {
  95. $q = "SELECT sit1,sit2 FROM ".TB_PREFIX."users where username = '$username' and access != ".BANNED;
  96. $result = mysql_query($q, $this->connection);
  97. $dbarray = mysql_fetch_array($result);
  98. if($dbarray['sit1'] != 0) {
  99. $q2 = "SELECT password FROM ".TB_PREFIX."users where id = ".$dbarray['sit1']." and access != ".BANNED;
  100. $result2 = mysql_query($q2, $this->connection);
  101. $dbarray2 = mysql_fetch_array($result2);
  102. }
  103. else if($dbarray['sit2'] != 0) {
  104. $q3 = "SELECT password FROM ".TB_PREFIX."users where id = ".$dbarray['sit2']." and access != ".BANNED;
  105. $result3 = mysql_query($q3, $this->connection);
  106. $dbarray3 = mysql_fetch_array($result3);
  107. }
  108. if($dbarray['sit1'] != 0 || $dbarray['sit2'] != 0) {
  109. if($dbarray2['password'] == md5($password) || $dbarray3['password'] == md5($password)) {
  110. return true;
  111. }
  112. else {
  113. return false;
  114. }
  115. } else {
  116. return false;
  117. }
  118. }
  119.  
  120. function setDeleting($uid,$mode) {
  121. $time = time() + 72*3600;
  122. if(!$mode) {
  123. $q = "INSERT into ".TB_PREFIX."deleting values ($uid,$time)";
  124. }
  125. else {
  126. $q = "DELETE FROM ".TB_PREFIX."deleting where uid = $uid";
  127. }
  128. mysql_query($q, $this->connection);
  129. }
  130.  
  131. function isDeleting($uid) {
  132. $q = "SELECT timestamp from ".TB_PREFIX."deleting where uid = $uid";
  133. $result = mysql_query($q,$this->connection);
  134. $dbarray = mysql_fetch_array($result);
  135. return $dbarray['timestamp'];
  136. }
  137.  
  138. function modifyGold($username,$amt,$mode) {
  139. if(!$mode) {
  140. $q = "UPDATE ".TB_PREFIX."users set gold = gold - $amt where username = $username";
  141. }
  142. else {
  143. $q = "UPDATE ".TB_PREFIX."users set gold = gold + $amt where username = $username";
  144. }
  145. return mysql_query($q,$this->connection);
  146. }
  147.  
  148. /*****************************************
  149. Function to retrieve user array via Username or ID
  150. Mode 0: Search by Username
  151. Mode 1: Search by ID
  152. References: Alliance ID
  153. *****************************************/
  154.  
  155. function getUserArray($ref,$mode) {
  156. if(!$mode) {
  157. $q = "SELECT * FROM ".TB_PREFIX."users where username = '$ref'";
  158. }
  159. else {
  160. $q = "SELECT * FROM ".TB_PREFIX."users where id = $ref";
  161. }
  162. $result = mysql_query($q, $this->connection);
  163. return mysql_fetch_array($result);
  164. }
  165.  
  166. function activeModify($username,$mode) {
  167. $time = time();
  168. if(!$mode) {
  169. $q = "INSERT into ".TB_PREFIX."active VALUES ('$username',$time)";
  170. }
  171. else {
  172. $q = "DELETE FROM ".TB_PREFIX."active where username = '$username'";
  173. }
  174. return mysql_query($q, $this->connection);
  175. }
  176.  
  177. function addActiveUser($username,$time) {
  178. $q = "REPLACE into ".TB_PREFIX."active values ('$username',$time)";
  179. if(mysql_query($q, $this->connection)) {
  180. return true;
  181. }
  182. else {
  183. return false;
  184. }
  185. }
  186.  
  187. function updateActiveUser($username,$time) {
  188. $q = "REPLACE into ".TB_PREFIX."active values ('$username',$time)";
  189. $q2 = "UPDATE ".TB_PREFIX."users set timestamp = $time where username = '$username'";
  190. $exec1 = mysql_query($q, $this->connection);
  191. $exec2 = mysql_query($q2, $this->connection);
  192. if($exec1 && $exec2) {
  193. return true;
  194. }
  195. else {
  196. return false;
  197. }
  198. }
  199.  
  200. function checkactiveSession($username,$sessid) {
  201. $q = "SELECT username FROM ".TB_PREFIX."users where username = '$username' and sessid = '$sessid' LIMIT 1";
  202. $result = mysql_query($q, $this->connection);
  203. if(mysql_num_rows($result) != 0) {
  204. return true;
  205. }
  206. else {
  207. return false;
  208. }
  209. }
  210.  
  211. function submitProfile($uid,$gender,$location,$birthday,$des1,$des2) {
  212. $q = "UPDATE ".TB_PREFIX."users set gender = $gender, location = '$location', birthday = '$birthday', desc1 = '$des1', desc2 = '$des2' where id = $uid";
  213. return mysql_query($q,$this->connection);
  214. }
  215.  
  216. function gpack($uid,$gpack) {
  217. $q = "UPDATE ".TB_PREFIX."users set gpack = '$gpack' where id = $uid";
  218. return mysql_query($q,$this->connection);
  219. }
  220.  
  221. function UpdateOnline($mode, $name="", $time="")
  222. {
  223. global $session;
  224. if ($mode == "login")
  225. {
  226. $q = "INSERT IGNORE INTO ".TB_PREFIX."online (name, time) VALUES ('$name', ".time().")";
  227. return mysql_query ($q,$this->connection);
  228. }
  229. else
  230. {
  231. $q = "DELETE FROM ".TB_PREFIX."online WHERE name ='".$session->username."'";
  232. return mysql_query ($q,$this->connection);
  233. }
  234. }
  235.  
  236. function generateBase($sector) {
  237. switch($sector) {
  238. case 1:
  239. $q = "Select * from ".TB_PREFIX."wdata where fieldtype = 3 and x < 0 and y > 0 and occupied = 0 LIMIT 200";
  240. break;
  241. case 2:
  242. $q = "Select * from ".TB_PREFIX."wdata where fieldtype = 3 and x > 0 and y > 0 and occupied = 0 LIMIT 200";
  243. break;
  244. case 3:
  245. $q = "Select * from ".TB_PREFIX."wdata where fieldtype = 3 and x < 0 and y < 0 and occupied = 0 LIMIT 200";
  246. break;
  247. case 4:
  248. $q = "Select * from ".TB_PREFIX."wdata where fieldtype = 3 and x > 0 and y < 0 and occupied = 0 LIMIT 200";
  249. break;
  250. }
  251. $result = mysql_query($q, $this->connection);
  252. $num_rows = mysql_num_rows($result);
  253. $result = $this->mysql_fetch_all($result);
  254. $base = rand(0, ($num_rows-1));
  255. return $result[$base]['id'];
  256. }
  257.  
  258. function setFieldTaken($id) {
  259. $q = "UPDATE ".TB_PREFIX."wdata set occupied = 1 where id = $id";
  260. return mysql_query($q, $this->connection);
  261. }
  262.  
  263. function addVillage($wid,$uid,$username,$capital) {
  264. $total = count($this->getVillagesID($uid));
  265. if ($total >= 1) {
  266. $vname = $username."\'s village ".($total+1);
  267. }
  268. else {
  269. $vname = $username."\'s village";
  270. }
  271. $time = time();
  272. $q = "INSERT into ".TB_PREFIX."vdata (wref, owner, name, capital, pop, cp, celebration, wood, clay, iron, maxstore, crop, maxcrop, lastupdate, created) values
  273. ($wid, $uid, '$vname', $capital, 2, 1, 0, 750, 750, 750, 800, 750, 800, $time, $time)";
  274. return mysql_query($q, $this->connection) or die(mysql_error());
  275. }
  276.  
  277. function addResourceFields($vid,$type) {
  278. switch($type) {
  279. case 1:
  280. $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)";
  281. break;
  282. case 2:
  283. $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)";
  284. break;
  285. case 3:
  286. $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)";
  287. break;
  288. case 4:
  289. $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)";
  290. break;
  291. case 5:
  292. $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)";
  293. break;
  294. case 6:
  295. $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)";
  296. break;
  297. case 7:
  298. $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)";
  299. break;
  300. case 8:
  301. $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)";
  302. break;
  303. case 9:
  304. $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)";
  305. break;
  306. case 10:
  307. $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)";
  308. break;
  309. case 11:
  310. $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,4,4,3,1,4,4,2,4,4,1,15)";
  311. break;
  312. case 12:
  313. $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,1,2,1,1,15)";
  314. break;
  315. }
  316. return mysql_query($q, $this->connection);
  317. }
  318.  
  319. /***************************
  320. Function to retrieve type of village via ID
  321. References: Village ID
  322. ***************************/
  323. function getVillageType($wref) {
  324. $q = "SELECT id, fieldtype FROM ".TB_PREFIX."wdata where id = $wref";
  325. $result = mysql_query($q, $this->connection);
  326. $dbarray = mysql_fetch_array($result);
  327. return $dbarray['fieldtype'];
  328. }
  329.  
  330. /*****************************************
  331. Function to retrieve if is ocuped via ID
  332. References: Village ID
  333. *****************************************/
  334. function getVillageState($wref) {
  335. $q = "SELECT occupied FROM ".TB_PREFIX."wdata where id = $wref";
  336. $result = mysql_query($q, $this->connection);
  337. $dbarray = mysql_fetch_array($result);
  338. return $dbarray['occupied'];
  339. }
  340.  
  341. function getProfileVillages($uid) {
  342. $q = "SELECT capital,wref,name,pop,created from ".TB_PREFIX."vdata where owner = $uid order by pop desc";
  343. $result = mysql_query($q,$this->connection);
  344. return $this->mysql_fetch_all($result);
  345. }
  346.  
  347. function getVillagesID($uid) {
  348. $q = "SELECT wref from ".TB_PREFIX."vdata where owner = $uid order by capital DESC";
  349. $result = mysql_query($q, $this->connection);
  350. $array = $this->mysql_fetch_all($result);
  351. $newarray = array();
  352. for($i=0;$i<count($array);$i++) {
  353. array_push($newarray,$array[$i]['wref']);
  354. }
  355. return $newarray;
  356. }
  357.  
  358. function getVillage($vid) {
  359. $q = "SELECT * FROM ".TB_PREFIX."vdata where wref = $vid";
  360. $result = mysql_query($q, $this->connection);
  361. return mysql_fetch_array($result);
  362. }
  363.  
  364. function getMInfo($id) {
  365. $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";
  366. $result = mysql_query($q, $this->connection);
  367. return mysql_fetch_array($result);
  368. }
  369.  
  370. function getOasis($vid) {
  371. $q = "SELECT * FROM ".TB_PREFIX."odata where conqured = $vid";
  372. $result = mysql_query($q, $this->connection);
  373. return $this->mysql_fetch_all($result);
  374. }
  375.  
  376. function getOasisInfo($wid) {
  377. $q = "SELECT * FROM ".TB_PREFIX."odata where wref = $wid";
  378. $result = mysql_query($q, $this->connection);
  379. return mysql_fetch_assoc($result);
  380. }
  381.  
  382. function getVillageField($ref,$field) {
  383. $q = "SELECT $field FROM ".TB_PREFIX."vdata where wref = $ref";
  384. $result = mysql_query($q, $this->connection);
  385. $dbarray = mysql_fetch_array($result);
  386. return $dbarray[$field];
  387. }
  388.  
  389. function setVillageField($ref,$field,$value) {
  390. $q = "UPDATE ".TB_PREFIX."vdata set $field = '$value' where wref = $ref";
  391. return mysql_query($q,$this->connection);
  392. }
  393.  
  394. function getResourceLevel($vid) {
  395. $q = "SELECT * from ".TB_PREFIX."fdata where vref = $vid";
  396. $result = mysql_query($q, $this->connection);
  397. return mysql_fetch_assoc($result);
  398. }
  399.  
  400. function getCoor($wref) {
  401. $q = "SELECT x,y FROM ".TB_PREFIX."wdata where id = $wref";
  402. $result = mysql_query($q, $this->connection);
  403. return mysql_fetch_array($result);
  404. }
  405.  
  406. function CheckForum($id) {
  407. $q = "SELECT * from ".TB_PREFIX."forum_cat where alliance = '$id'";
  408. $result = mysql_query($q, $this->connection);
  409. if(mysql_num_rows($result)) {
  410. return true;
  411. }
  412. else {
  413. return false;
  414. }
  415. }
  416.  
  417. function CountCat($id) {
  418. $q = "SELECT count(id) FROM ".TB_PREFIX."forum_topic where cat = '$id'";
  419. $result = mysql_query($q,$this->connection);
  420. $row = mysql_fetch_row($result);
  421. return $row[0];
  422. }
  423.  
  424. function LastTopic($id) {
  425. $q = "SELECT * from ".TB_PREFIX."forum_topic where cat = '$id' order by post_date";
  426. $result = mysql_query($q,$this->connection);
  427. return $this->mysql_fetch_all($result);
  428. }
  429.  
  430. function CheckLastTopic($id) {
  431. $q = "SELECT * from ".TB_PREFIX."forum_topic where cat = '$id'";
  432. $result = mysql_query($q, $this->connection);
  433. if(mysql_num_rows($result)) {
  434. return true;
  435. }
  436. else {
  437. return false;
  438. }
  439. }
  440.  
  441. function CheckLastPost($id) {
  442. $q = "SELECT * from ".TB_PREFIX."forum_post where topic = '$id'";
  443. $result = mysql_query($q, $this->connection);
  444. if(mysql_num_rows($result)) {
  445. return true;
  446. }
  447. else {
  448. return false;
  449. }
  450. }
  451.  
  452. function LastPost($id) {
  453. $q = "SELECT * from ".TB_PREFIX."forum_post where topic = '$id'";
  454. $result = mysql_query($q,$this->connection);
  455. return $this->mysql_fetch_all($result);
  456. }
  457.  
  458. function CountTopic($id) {
  459. $q = "SELECT count(id) FROM ".TB_PREFIX."forum_post where owner = '$id'";
  460. $result = mysql_query($q,$this->connection);
  461. $row = mysql_fetch_row($result);
  462.  
  463. $qs = "SELECT count(id) FROM ".TB_PREFIX."forum_topic where owner = '$id'";
  464. $results = mysql_query($qs,$this->connection);
  465. $rows = mysql_fetch_row($results);
  466. return $row[0]+$rows[0];
  467. }
  468.  
  469. function CountPost($id) {
  470. $q = "SELECT count(id) FROM ".TB_PREFIX."forum_post where topic = '$id'";
  471. $result = mysql_query($q,$this->connection);
  472. $row = mysql_fetch_row($result);
  473. return $row[0];
  474. }
  475.  
  476. function ForumCat($id) {
  477. $q = "SELECT * from ".TB_PREFIX."forum_cat where alliance = '$id' ORDER BY id";
  478. $result = mysql_query($q,$this->connection);
  479. return $this->mysql_fetch_all($result);
  480. }
  481.  
  482. function ForumCatEdit($id) {
  483. $q = "SELECT * from ".TB_PREFIX."forum_cat where id = '$id'";
  484. $result = mysql_query($q,$this->connection);
  485. return $this->mysql_fetch_all($result);
  486. }
  487.  
  488. function ForumCatName($id) {
  489. $q = "SELECT forum_name from ".TB_PREFIX."forum_cat where id = $id";
  490. $result = mysql_query($q, $this->connection);
  491. $dbarray = mysql_fetch_array($result);
  492. return $dbarray['forum_name'];
  493. }
  494.  
  495. function CheckCatTopic($id) {
  496. $q = "SELECT * from ".TB_PREFIX."forum_topic where cat = '$id'";
  497. $result = mysql_query($q, $this->connection);
  498. if(mysql_num_rows($result)) {
  499. return true;
  500. }
  501. else {
  502. return false;
  503. }
  504. }
  505.  
  506. function CheckResultEdit($alli) {
  507. $q = "SELECT * from ".TB_PREFIX."forum_edit where alliance = '$alli'";
  508. $result = mysql_query($q, $this->connection);
  509. if(mysql_num_rows($result)) {
  510. return true;
  511. }
  512. else {
  513. return false;
  514. }
  515. }
  516.  
  517. function CheckCloseTopic($id) {
  518. $q = "SELECT close from ".TB_PREFIX."forum_topic where id = '$id'";
  519. $result = mysql_query($q, $this->connection);
  520. $dbarray = mysql_fetch_array($result);
  521. return $dbarray['close'];
  522. }
  523.  
  524. function CheckEditRes($alli) {
  525. $q = "SELECT result from ".TB_PREFIX."forum_edit where alliance = '$alli'";
  526. $result = mysql_query($q, $this->connection);
  527. $dbarray = mysql_fetch_array($result);
  528. return $dbarray['result'];
  529. }
  530.  
  531. function CreatResultEdit($alli,$result) {
  532. $q = "INSERT into ".TB_PREFIX."forum_edit values (0,'$alli','$result')";
  533. mysql_query($q,$this->connection);
  534. return mysql_insert_id($this->connection);
  535. }
  536.  
  537. function UpdateResultEdit($alli,$result) {
  538. $date = time();
  539. $q = "UPDATE ".TB_PREFIX."forum_edit set result = '$result' where alliance = '$alli'";
  540. return mysql_query($q, $this->connection);
  541. }
  542.  
  543. function UpdateEditTopic($id,$title,$cat) {
  544. $q = "UPDATE ".TB_PREFIX."forum_topic set title = '$title', cat = '$cat' where id = $id";
  545. return mysql_query($q, $this->connection);
  546. }
  547.  
  548. function UpdateEditForum($id,$name,$des) {
  549. $q = "UPDATE ".TB_PREFIX."forum_cat set forum_name = '$name', forum_des = '$des' where id = $id";
  550. return mysql_query($q, $this->connection);
  551. }
  552.  
  553. function StickTopic($id,$mode) {
  554. $q = "UPDATE ".TB_PREFIX."forum_topic set stick = '$mode' where id = '$id'";
  555. return mysql_query($q, $this->connection);
  556. }
  557.  
  558. function ForumCatTopic($id) {
  559. $q = "SELECT * from ".TB_PREFIX."forum_topic where cat = '$id' AND stick = '' ORDER BY post_date desc";
  560. $result = mysql_query($q,$this->connection);
  561. return $this->mysql_fetch_all($result);
  562. }
  563.  
  564. function ForumCatTopicStick($id) {
  565. $q = "SELECT * from ".TB_PREFIX."forum_topic where cat = '$id' AND stick = '1' ORDER BY post_date desc";
  566. $result = mysql_query($q,$this->connection);
  567. return $this->mysql_fetch_all($result);
  568. }
  569.  
  570. function ShowTopic($id) {
  571. $q = "SELECT * from ".TB_PREFIX."forum_topic where id = '$id'";
  572. $result = mysql_query($q,$this->connection);
  573. return $this->mysql_fetch_all($result);
  574. }
  575.  
  576. function ShowPost($id) {
  577. $q = "SELECT * from ".TB_PREFIX."forum_post where topic = '$id'";
  578. $result = mysql_query($q,$this->connection);
  579. return $this->mysql_fetch_all($result);
  580. }
  581.  
  582. function ShowPostEdit($id) {
  583. $q = "SELECT * from ".TB_PREFIX."forum_post where id = '$id'";
  584. $result = mysql_query($q,$this->connection);
  585. return $this->mysql_fetch_all($result);
  586. }
  587.  
  588. function CreatForum($owner,$alli,$name,$des,$area) {
  589. $q = "INSERT into ".TB_PREFIX."forum_cat values (0,'$owner','$alli','$name','$des','$area')";
  590. mysql_query($q,$this->connection);
  591. return mysql_insert_id($this->connection);
  592. }
  593.  
  594. function CreatTopic($title,$post,$cat,$owner,$alli,$ends) {
  595. $date = time();
  596. $q = "INSERT into ".TB_PREFIX."forum_topic values (0,'$title','$post','$date','$date','$cat','$owner','$alli','$ends','','')";
  597. mysql_query($q,$this->connection);
  598. return mysql_insert_id($this->connection);
  599. }
  600.  
  601. function CreatPost($post,$tids,$owner) {
  602. $date = time();
  603. $q = "INSERT into ".TB_PREFIX."forum_post values (0,'$post','$tids','$owner','$date')";
  604. mysql_query($q,$this->connection);
  605. return mysql_insert_id($this->connection);
  606. }
  607.  
  608. function UpdatePostDate($id) {
  609. $date = time();
  610. $q = "UPDATE ".TB_PREFIX."forum_topic set post_date = '$date' where id = $id";
  611. return mysql_query($q, $this->connection);
  612. }
  613.  
  614. function EditUpdateTopic($id,$post) {
  615. $q = "UPDATE ".TB_PREFIX."forum_topic set post = '$post' where id = $id";
  616. return mysql_query($q, $this->connection);
  617. }
  618.  
  619. function EditUpdatePost($id,$post) {
  620. $q = "UPDATE ".TB_PREFIX."forum_post set post = '$post' where id = $id";
  621. return mysql_query($q, $this->connection);
  622. }
  623.  
  624. function LockTopic($id,$mode) {
  625. $q = "UPDATE ".TB_PREFIX."forum_topic set close = '$mode' where id = '$id'";
  626. return mysql_query($q, $this->connection);
  627. }
  628.  
  629. function DeleteCat($id) {
  630. $qs = "DELETE from ".TB_PREFIX."forum_cat where id = '$id'";
  631. $q = "DELETE from ".TB_PREFIX."forum_topic where cat = '$id'";
  632. mysql_query($qs,$this->connection);
  633. return mysql_query($q,$this->connection);
  634. }
  635.  
  636. function DeleteTopic($id) {
  637. $qs = "DELETE from ".TB_PREFIX."forum_topic where id = '$id'";
  638. $q = "DELETE from ".TB_PREFIX."forum_post where topic = '$id'";
  639. mysql_query($qs,$this->connection);
  640. return mysql_query($q,$this->connection);
  641. }
  642.  
  643. function DeletePost($id) {
  644. $q = "DELETE from ".TB_PREFIX."forum_post where id = '$id'";
  645. return mysql_query($q,$this->connection);
  646. }
  647.  
  648. function getAllianceName($id) {
  649. $q = "SELECT tag from ".TB_PREFIX."alidata where id = $id";
  650. $result = mysql_query($q, $this->connection);
  651. $dbarray = mysql_fetch_array($result);
  652. return $dbarray['tag'];
  653. }
  654.  
  655. function getAlliance($id) {
  656. $q = "SELECT * from ".TB_PREFIX."alidata where id = $id";
  657. $result = mysql_query($q, $this->connection);
  658. return mysql_fetch_assoc($result);
  659. }
  660.  
  661. function setAlliName($aid,$name,$tag) {
  662. $q = "UPDATE ".TB_PREFIX."alidata set name = '$name', tag = '$tag' where id = $aid";
  663. return mysql_query($q, $this->connection);
  664. }
  665.  
  666. function isAllianceOwner($id) {
  667. $q = "SELECT * from ".TB_PREFIX."alidata where leader = '$id'";
  668. $result = mysql_query($q, $this->connection);
  669. if(mysql_num_rows($result)) {
  670. return true;
  671. }
  672. else {
  673. return false;
  674. }
  675. }
  676.  
  677. function aExist($ref,$type) {
  678. $q = "SELECT $type FROM ".TB_PREFIX."alidata where $type = '$ref'";
  679. $result = mysql_query($q, $this->connection);
  680. if(mysql_num_rows($result)) {
  681. return true;
  682. }
  683. else {
  684. return false;
  685. }
  686. }
  687.  
  688. function modifyPoints($aid,$points,$amt) {
  689. $q = "UPDATE ".TB_PREFIX."users set $points = $points + $amt where id = $aid";
  690. return mysql_query($q,$this->connection);
  691. }
  692.  
  693. /*****************************************
  694. Function to create an alliance
  695. References:
  696. *****************************************/
  697. function createAlliance($tag,$name,$uid,$max) {
  698. $q = "INSERT into ".TB_PREFIX."alidata values (0,'$name','$tag',$uid,0,0,0,'','',$max)";
  699. mysql_query($q,$this->connection);
  700. return mysql_insert_id($this->connection);
  701. }
  702.  
  703. /*****************************************
  704. Function to insert an alliance new
  705. References:
  706. *****************************************/
  707. function insertAlliNotice($aid,$notice) {
  708. $time = time();
  709. $q = "INSERT into ".TB_PREFIX."ali_log values (0,'$aid','$notice',$time)";
  710. mysql_query($q,$this->connection);
  711. return mysql_insert_id($this->connection);
  712. }
  713.  
  714. /*****************************************
  715. Function to read all alliance news
  716. References:
  717. *****************************************/
  718. function readAlliNotice($aid) {
  719. $q = "SELECT * from ".TB_PREFIX."ali_log where aid = $aid ORDER BY date DESC";
  720. $result = mysql_query($q,$this->connection);
  721. return $this->mysql_fetch_all($result);
  722. }
  723.  
  724. /*****************************************
  725. Function to create alliance permissions
  726. References: ID, notice, description
  727. *****************************************/
  728. function createAlliPermissions($uid,$aid,$rank,$opt1,$opt2,$opt3,$opt4,$opt5,$opt6,$opt7,$opt8) {
  729.  
  730. $q = "INSERT into ".TB_PREFIX."ali_permission values(0,'$uid','$aid','$rank','$opt1','$opt2','$opt3','$opt4','$opt5','$opt6','$opt7','$opt8')";
  731. mysql_query($q,$this->connection);
  732. return mysql_insert_id($this->connection);
  733. }
  734.  
  735. /*****************************************
  736. Function to update alliance permissions
  737. References:
  738. *****************************************/
  739. function deleteAlliPermissions($uid) {
  740. $q = "DELETE from ".TB_PREFIX."ali_permission where uid = '$uid'";
  741. return mysql_query($q,$this->connection);
  742. }
  743. /*****************************************
  744. Function to update alliance permissions
  745. References:
  746. *****************************************/
  747. function updateAlliPermissions($uid,$aid,$rank,$opt1,$opt2,$opt3,$opt4,$opt5,$opt6,$opt7) {
  748.  
  749. $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";
  750. return mysql_query($q,$this->connection);
  751. }
  752.  
  753. /*****************************************
  754. Function to read alliance permissions
  755. References: ID, notice, description
  756. *****************************************/
  757. function getAlliPermissions($uid, $aid) {
  758. $q = "SELECT * FROM ".TB_PREFIX."ali_permission where uid = $uid && alliance = $aid";
  759. $result = mysql_query($q,$this->connection);
  760. return mysql_fetch_assoc($result);
  761. }
  762.  
  763. /*****************************************
  764. Function to update an alliance description and notice
  765. References: ID, notice, description
  766. *****************************************/
  767. function submitAlliProfile($aid,$notice,$desc) {
  768.  
  769. $q = "UPDATE ".TB_PREFIX."alidata SET `notice` = '$notice', `desc` = '$desc' where id = $aid";
  770. return mysql_query($q,$this->connection);
  771. }
  772.  
  773. function getUserAlliance($id) {
  774. $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";
  775. $result = mysql_query($q, $this->connection);
  776. $dbarray = mysql_fetch_array($result);
  777. if($dbarray['tag'] == "") {
  778. return "-";
  779. }
  780. else {
  781. return $dbarray['tag'];
  782. }
  783. }
  784.  
  785. function modifyResource($vid,$wood,$clay,$iron,$crop,$mode) {
  786. if(!$mode) {
  787. $q = "UPDATE ".TB_PREFIX."vdata set wood = wood - $wood, clay = clay - $clay, iron = iron - $iron, crop = crop - $crop where wref = $vid";
  788. }
  789. else {
  790. $q = "UPDATE ".TB_PREFIX."vdata set wood = wood + $wood, clay = clay + $clay, iron = iron + $iron, crop = crop + $crop where wref = $vid";
  791. }
  792. return mysql_query($q, $this->connection);
  793. }
  794.  
  795. function getFieldLevel($vid,$field) {
  796. $q = "SELECT f".$field." from ".TB_PREFIX."fdata where vref = $vid";
  797. $result = mysql_query($q,$this->connection);
  798. return mysql_result($result,0);
  799. }
  800.  
  801. function getVSumField($uid,$field) {
  802. $q = "SELECT sum(".$field.") FROM ".TB_PREFIX."vdata where owner = $uid";
  803. $result = mysql_query($q, $this->connection);
  804. $row = mysql_fetch_row($result);
  805. return $row[0];
  806. }
  807.  
  808. function updateVillage($vid) {
  809. $time = time();
  810. $q = "UPDATE ".TB_PREFIX."vdata set lastupdate = $time where wref = $vid";
  811. return mysql_query($q, $this->connection);
  812. }
  813.  
  814.  
  815. function setVillageName($vid,$name) {
  816. $q = "UPDATE ".TB_PREFIX."vdata set name = '$name' where wref = $vid";
  817. return mysql_query($q, $this->connection);
  818. }
  819.  
  820. function modifyPop($vid,$pop,$mode) {
  821. if(!$mode) {
  822. $q = "UPDATE ".TB_PREFIX."vdata set pop = pop + $pop where wref = $vid";
  823. }
  824. else {
  825. $q = "UPDATE ".TB_PREFIX."vdata set pop = pop - $pop where wref = $vid";
  826. }
  827. return mysql_query($q, $this->connection);
  828. }
  829.  
  830.  
  831. function addCP($ref,$cp) {
  832. $q = "UPDATE ".TB_PREFIX."vdata set cp = cp + $cp where wref = $ref";
  833. return mysql_query($q, $this->connection);
  834. }
  835.  
  836. function addCel($ref,$cel,$type) {
  837. $q = "UPDATE ".TB_PREFIX."vdata set celebration = $cel, type= $type where wref = $ref";
  838. return mysql_query($q, $this->connection);
  839. }
  840. function getCel() {
  841. $time = time();
  842. $q = "SELECT * FROM ".TB_PREFIX."vdata where celebration < $time AND celebration != 0";
  843. $result = mysql_query($q, $this->connection);
  844. return $this->mysql_fetch_all($result);
  845. }
  846.  
  847. function clearCel($ref) {
  848. $q = "UPDATE ".TB_PREFIX."vdata set celebration = 0, type = 0 where wref = $ref";
  849. return mysql_query($q, $this->connection);
  850. }
  851. function setCelCp($user,$cp) {
  852. $q = "UPDATE ".TB_PREFIX."users set cp = cp + $cp where id = $user";
  853. return mysql_query($q, $this->connection);
  854. }
  855.  
  856.  
  857. function getInvitation($uid) {
  858. $q = "SELECT * FROM ".TB_PREFIX."ali_invite where uid = $uid";
  859. $result = mysql_query($q, $this->connection);
  860. return $this->mysql_fetch_all($result);
  861. }
  862.  
  863. function getAliInvitations($aid) {
  864. $q = "SELECT * FROM ".TB_PREFIX."ali_invite where alliance = $aid && accept = 0";
  865. $result = mysql_query($q, $this->connection);
  866. return $this->mysql_fetch_all($result);
  867. }
  868.  
  869. function sendInvitation($uid, $alli, $sender) {
  870. $time = time();
  871. $q = "INSERT INTO ".TB_PREFIX."ali_invite values (0,$uid,$alli,$sender,$time,0)";
  872. return mysql_query($q,$this->connection) or die(mysql_error());
  873. }
  874.  
  875. function removeInvitation($id) {
  876. $q = "DELETE FROM ".TB_PREFIX."ali_invite where id = $id";
  877. return mysql_query($q,$this->connection);
  878. }
  879.  
  880. function sendMessage($client,$owner,$topic,$message,$send) {
  881. $time = time();
  882. $q = "INSERT INTO ".TB_PREFIX."mdata values (0,$client,$owner,'$topic',\"$message\",0,0,$send,$time)";
  883. return mysql_query($q, $this->connection);
  884. }
  885.  
  886. function setArchived($id) {
  887. $q = "UPDATE ".TB_PREFIX."mdata set archived = 1 where id = $id";
  888. return mysql_query($q, $this->connection);
  889. }
  890.  
  891. function setNorm($id) {
  892. $q = "UPDATE ".TB_PREFIX."mdata set archived = 0 where id = $id";
  893. return mysql_query($q, $this->connection);
  894. }
  895.  
  896. /***************************
  897. Function to get messages
  898. Mode 1: Get inbox
  899. Mode 2: Get sent
  900. Mode 3: Get message
  901. Mode 4: Set viewed
  902. Mode 5: Remove message
  903. Mode 6: Retrieve archive
  904. References: User ID/Message ID, Mode
  905. ***************************/
  906. function getMessage($id,$mode) {
  907. switch($mode) {
  908. case 1:
  909. $q = "SELECT * FROM ".TB_PREFIX."mdata WHERE target = $id and send = 0 and archived = 0 ORDER BY time DESC";
  910. break;
  911. case 2:
  912. $q = "SELECT * FROM ".TB_PREFIX."mdata WHERE owner = $id and send = 1 and archived = 0 ORDER BY time DESC";
  913. break;
  914. case 3:
  915. $q = "SELECT * FROM ".TB_PREFIX."mdata where id = $id";
  916. break;
  917. case 4:
  918. $q = "UPDATE ".TB_PREFIX."mdata set viewed = 1 where id = $id";
  919. break;
  920. case 5:
  921. $q = "DELETE FROM ".TB_PREFIX."mdata where id = $id";
  922. break;
  923. case 6:
  924. $q = "SELECT * FROM ".TB_PREFIX."mdata where target = $id and send = 0 and archived = 1";
  925. break;
  926. }
  927. if($mode <= 3 || $mode == 6) {
  928. $result = mysql_query($q, $this->connection);
  929. return $this->mysql_fetch_all($result);
  930. }
  931. else {
  932. return mysql_query($q, $this->connection);
  933. }
  934. }
  935.  
  936. function unarchiveNotice($id) {
  937. $q = "UPDATE ".TB_PREFIX."ndata set ntype = archive, archive = 0 where id = $id";
  938. return mysql_query($q,$this->connection);
  939. }
  940.  
  941. function archiveNotice($id) {
  942. $q = "update ".TB_PREFIX."ndata set archive = ntype, ntype = 9 where id = $id";
  943. return mysql_query($q,$this->connection);
  944. }
  945.  
  946. function removeNotice($id) {
  947. $q = "DELETE FROM ".TB_PREFIX."ndata where id = $id";
  948. return mysql_query($q,$this->connection);
  949. }
  950.  
  951. function noticeViewed($id) {
  952. $q = "UPDATE ".TB_PREFIX."ndata set viewed = 1 where id = $id";
  953. return mysql_query($q,$this->connection);
  954. }
  955.  
  956. function addNotice($uid,$type,$topic,$data) {
  957. $time = time();
  958. $q = "INSERT INTO ".TB_PREFIX."ndata (id, uid, topic, ntype, data, time, viewed) values (0,'$uid','$topic',$type,'$data',$time,0)";
  959. return mysql_query($q,$this->connection) or die(mysql_error());
  960. }
  961.  
  962. function getNotice($uid) {
  963. $q = "SELECT * FROM ".TB_PREFIX."ndata where uid = $uid ORDER BY time DESC";
  964. $result = mysql_query($q, $this->connection);
  965. return $this->mysql_fetch_all($result);
  966. }
  967.  
  968. function addBuilding($wid,$field,$type,$loop,$time) {
  969. $q = "INSERT into ".TB_PREFIX."bdata values (0,$wid,$field,$type,$loop,$time)";
  970. return mysql_query($q,$this->connection);
  971. }
  972.  
  973. function removeBuilding($d) {
  974. $q = "DELETE FROM ".TB_PREFIX."bdata where id = $d";
  975. return mysql_query($q,$this->connection);
  976. }
  977.  
  978. function getJobs($wid) {
  979. $q = "SELECT * FROM ".TB_PREFIX."bdata where wid = $wid order by ID ASC";
  980. $result = mysql_query($q,$this->connection);
  981. return $this->mysql_fetch_all($result);
  982. }
  983.  
  984. function getVillageByName($name) {
  985. $name = mysql_real_escape_string($name,$this->connection);
  986. $q = "SELECT wref FROM ".TB_PREFIX."vdata where name = '$name' limit 1";
  987. $result = mysql_query($q,$this->connection);
  988. $dbarray = mysql_fetch_array($result);
  989. return $dbarray['wref'];
  990. }
  991.  
  992. /***************************
  993. Function to set accept flag on market
  994. References: id
  995. ***************************/
  996. function setMarketAcc($id) {
  997. $q = "UPDATE ".TB_PREFIX."market set accept = 1 where id = $id";
  998. return mysql_query($q,$this->connection);
  999. }
  1000.  
  1001. /***************************
  1002. Function to send resource to other village
  1003. Mode 0: Send
  1004. Mode 1: Cancel
  1005. References: Wood/ID, Clay, Iron, Crop, Mode
  1006. ***************************/
  1007. function sendResource($ref,$clay,$iron,$crop,$merchant,$mode) {
  1008. if(!$mode) {
  1009. $q = "INSERT INTO ".TB_PREFIX."send values (0,$ref,$clay,$iron,$crop,$merchant)";
  1010. mysql_query($q, $this->connection);
  1011. return mysql_insert_id($this->connection);
  1012. }
  1013. else {
  1014. $q = "DELETE FROM ".TB_PREFIX."send where id = $ref";
  1015. return mysql_query($q, $this->connection);
  1016. }
  1017. }
  1018.  
  1019. /***************************
  1020. Function to add market offer
  1021. Mode 0: Add
  1022. Mode 1: Cancel
  1023. References: Village, Give, Amt, Want, Amt, Time, Alliance, Mode
  1024. ***************************/
  1025. function addMarket($vid,$gtype,$gamt,$wtype,$wamt,$time,$alliance,$merchant,$mode) {
  1026. if(!$mode) {
  1027. $q = "INSERT INTO ".TB_PREFIX."market values (0,$vid,$gtype,$gamt,$wtype,$wamt,0,$time,$alliance,$merchant)";
  1028. mysql_query($q, $this->connection);
  1029. return mysql_insert_id($this->connection);
  1030. }
  1031. else {
  1032. $q = "DELETE FROM ".TB_PREFIX."market where id = $gtype and vref = $vid";
  1033. return mysql_query($q, $this->connection);
  1034. }
  1035. }
  1036.  
  1037. /***************************
  1038. Function to get market offer
  1039. References: Village, Mode
  1040. ***************************/
  1041. function getMarket($vid,$mode) {
  1042. $alliance = $this->getUserField($this->getVillageField($vid,"owner"),"alliance",0);
  1043. if(!$mode) {
  1044. $q = "SELECT * FROM ".TB_PREFIX."market where vref = $vid and accept = 0";
  1045. }
  1046. else {
  1047. $q = "SELECT * FROM ".TB_PREFIX."market where vref != $vid and alliance = $alliance or vref != $vid and alliance = 0 and accept = 0";
  1048. }
  1049. $result = mysql_query($q, $this->connection);
  1050. return $this->mysql_fetch_all($result);
  1051. }
  1052.  
  1053. /***************************
  1054. Function to get market offer
  1055. References: ID
  1056. ***************************/
  1057. function getMarketInfo($id) {
  1058. $q = "SELECT * FROM ".TB_PREFIX."market where id = $id";
  1059. $result = mysql_query($q, $this->connection);
  1060. return mysql_fetch_assoc($result);
  1061. }
  1062.  
  1063. function setMovementProc($moveid) {
  1064. $q = "UPDATE ".TB_PREFIX."movement set proc = 1 where moveid = $moveid";
  1065. return mysql_query($q,$this->connection);
  1066. }
  1067.  
  1068. /***************************
  1069. Function to retrieve used merchant
  1070. References: Village
  1071. ***************************/
  1072. function totalMerchantUsed($vid) {
  1073. $time = time();
  1074. $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";
  1075. $result = mysql_query($q, $this->connection);
  1076. $row = mysql_fetch_row($result);
  1077. $q2 = "SELECT sum(ref) from ".TB_PREFIX."movement where sort_type = 2 and ".TB_PREFIX."movement.to = $vid and proc = 0";
  1078. $result2 = mysql_query($q2, $this->connection);
  1079. $row2 = mysql_fetch_row($result2);
  1080. $q3 = "SELECT sum(merchant) from ".TB_PREFIX."market where vref = $vid and accept = 0";
  1081. $result3 = mysql_query($q3, $this->connection);
  1082. $row3 = mysql_fetch_row($result3);
  1083. return $row[0]+$row2[0]+$row3[0];
  1084. }
  1085.  
  1086. /***************************
  1087. Function to retrieve movement of village
  1088. Type 0: Send Resource
  1089. Type 1: Send Merchant
  1090. Type 2: Return Resource
  1091. Type 3: Attack
  1092. Type 4: Return
  1093. Type 5: Settler
  1094. Type 6: Bounty
  1095. Mode 0: Send/Out
  1096. Mode 1: Recieve/In
  1097. References: Type, Village, Mode
  1098. ***************************/
  1099. function getMovement($type,$village,$mode) {
  1100. $time = time();
  1101. if(!$mode) {
  1102. $where = "from";
  1103. }
  1104. else {
  1105. $where = "to";
  1106. }
  1107. switch($type) {
  1108. case 0: $q = "SELECT * FROM ".TB_PREFIX."movement, ".TB_PREFIX."send where ".TB_PREFIX."movement.".$where." = $village and ".TB_PREFIX."movement.ref = ".TB_PREFIX."send.id and ".TB_PREFIX."movement.proc = 0 and ".TB_PREFIX."movement.sort_type = 0"; break;
  1109. case 2: $q = "SELECT * FROM ".TB_PREFIX."movement where ".TB_PREFIX."movement.".$where." = $village and proc = 0 and sort_type = 2"; break;
  1110. case 3: $q = "SELECT * FROM ".TB_PREFIX."movement, ".TB_PREFIX."attacks where ".TB_PREFIX."movement.".$where." = $village and ".TB_PREFIX."movement.ref = ".TB_PREFIX."attacks.id and ".TB_PREFIX."movement.proc = 0 and ".TB_PREFIX."movement.sort_type = 3 ORDER BY endtime DESC"; break;
  1111. case 4: $q = "SELECT * FROM ".TB_PREFIX."movement, ".TB_PREFIX."attacks where ".TB_PREFIX."movement.".$where." = $village and ".TB_PREFIX."movement.ref = ".TB_PREFIX."attacks.id and ".TB_PREFIX."movement.proc = 0 and ".TB_PREFIX."movement.sort_type = 4 ORDER BY endtime DESC"; break;
  1112. case 5: $q = "SELECT * FROM ".TB_PREFIX."movement where ".TB_PREFIX."movement.".$where." = $village and sort_type = 5 and proc = 0"; break;
  1113. }
  1114. $result = mysql_query($q, $this->connection);
  1115. $array = $this->mysql_fetch_all($result);
  1116. return $array;
  1117. }
  1118.  
  1119. function addMovement($type,$from,$to,$ref,$endtime) {
  1120. $q = "INSERT INTO ".TB_PREFIX."movement values (0,$type,$from,$to,$ref,$endtime,0)";
  1121. return mysql_query($q, $this->connection);
  1122. }
  1123.  
  1124. function addAttack($vid,$t1,$t2,$t3,$t4,$t5,$t6,$t7,$t8,$t9,$t10,$t11,$type) {
  1125. $q = "INSERT INTO ".TB_PREFIX."attacks values (0,$vid,$t1,$t2,$t3,$t4,$t5,$t6,$t7,$t8,$t9,$t10,$t11,$type)";
  1126. mysql_query($q, $this->connection);
  1127. return mysql_insert_id($this->connection);
  1128. }
  1129.  
  1130. function modifyAttack($aid,$unit,$amt) {
  1131. $unit = 't'.$unit;
  1132. $q = "UPDATE ".TB_PREFIX."attacks set $unit = $unit - $amt where id = $aid";
  1133. return mysql_query($q,$this->connection);
  1134. }
  1135.  
  1136. function getRanking() {
  1137. if(INCLUDE_ADMIN) {
  1138. $q = "SELECT id,username,alliance,ap,dp FROM ".TB_PREFIX."users where access != ".BANNED;
  1139. }
  1140. else {
  1141. $q = "SELECT id,username,alliance,ap,dp FROM ".TB_PREFIX."users where access = ".USER;
  1142. }
  1143. $result = mysql_query($q, $this->connection);
  1144. return $this->mysql_fetch_all($result);
  1145. }
  1146.  
  1147. function getVRanking() {
  1148. $q = "SELECT wref,name,owner,pop FROM ".TB_PREFIX."vdata where wref != ''";
  1149. $result = mysql_query($q, $this->connection);
  1150. return $this->mysql_fetch_all($result);
  1151. }
  1152.  
  1153. function getARanking() {
  1154. $q = "SELECT id,name,tag FROM ".TB_PREFIX."alidata where id != ''";
  1155. $result = mysql_query($q, $this->connection);
  1156. return $this->mysql_fetch_all($result);
  1157. }
  1158.  
  1159. function getHeroRanking() {
  1160. $q = "SELECT * FROM ".TB_PREFIX."hero";
  1161. $result = mysql_query($q, $this->connection);
  1162. return $this->mysql_fetch_all($result);
  1163. }
  1164.  
  1165. function getAllMember($aid) {
  1166. $q = "SELECT * FROM ".TB_PREFIX."users left JOIN ".TB_PREFIX."vdata ON ".TB_PREFIX."vdata.owner = ".TB_PREFIX."users.id where ".TB_PREFIX."users.alliance = '$aid' order by ".TB_PREFIX."vdata.pop desc";
  1167. $result = mysql_query($q, $this->connection);
  1168. return array_unique($this->mysql_fetch_all($result));
  1169. }
  1170.  
  1171. function addUnits($vid) {
  1172. $q = "INSERT into ".TB_PREFIX."units (vref) values ($vid)";
  1173. return mysql_query($q, $this->connection);
  1174. }
  1175.  
  1176. function getUnit($vid) {
  1177. $q = "SELECT * from ".TB_PREFIX."units where vref = $vid";
  1178. $result = mysql_query($q,$this->connection);
  1179. return mysql_fetch_assoc($result);
  1180. }
  1181.  
  1182. function addTech($vid) {
  1183. $q = "INSERT into ".TB_PREFIX."tdata (vref) values ($vid)";
  1184. return mysql_query($q, $this->connection);
  1185. }
  1186.  
  1187. function addABTech($vid) {
  1188. $q = "INSERT into ".TB_PREFIX."abdata (vref) values ($vid)";
  1189. return mysql_query($q, $this->connection);
  1190. }
  1191.  
  1192. function getABTech($vid) {
  1193. $q = "SELECT * FROM ".TB_PREFIX."abdata where vref = $vid";
  1194. $result = mysql_query($q,$this->connection);
  1195. return mysql_fetch_assoc($result);
  1196. }
  1197.  
  1198. function addResearch($vid,$tech,$time) {
  1199. $q = "INSERT into ".TB_PREFIX."research values (0,$vid,'$tech',$time)";
  1200. return mysql_query($q,$this->connection);
  1201. }
  1202.  
  1203. function getResearching($vid) {
  1204. $q = "SELECT * FRom ".TB_PREFIX."research where vref = $vid";
  1205. $result = mysql_query($q,$this->connection);
  1206. return $this->mysql_fetch_all($result);
  1207. }
  1208.  
  1209. function getTech($vid) {
  1210. $q = "SELECT * from ".TB_PREFIX."tdata where vref = $vid";
  1211. $result = mysql_query($q, $this->connection);
  1212. return mysql_fetch_assoc($result);
  1213. }
  1214.  
  1215. function getTraining($vid) {
  1216. $q = "SELECT * FROM ".TB_PREFIX."training where vref = $vid";
  1217. $result = mysql_query($q,$this->connection);
  1218. return $this->mysql_fetch_all($result);
  1219. }
  1220.  
  1221. function trainUnit($vid,$unit,$amt,$pop,$each,$time,$mode) {
  1222. global $village, $building, $session;
  1223. if(!$mode) {
  1224. if($unit == 10 OR $unit == 20 OR $unit == 30) {
  1225. $query = mysql_query('SELECT * FROM `' . TB_PREFIX . 'units` WHERE `vref` = ' . $village->wid);
  1226. $data = mysql_fetch_assoc($query);
  1227. if($building->getTypeLevel(25) == 0 AND $building->getTypeLevel(26) > 0) {
  1228. $max_settlers = ($building->getTypeLevel(26) * 3) / 10;
  1229. if($building->getTypeLevel(26) == 15) {
  1230. $max_settlers += 1;
  1231. } elseif($building->getTypeLevel(26) == 20) {
  1232. $max_settlers += 3;
  1233. }
  1234. } elseif($building->getTypeLevel(25) > 0 AND $building->getTypeLevel(26) == 0) {
  1235. $max_settlers = ($building->getTypeLevel(25) * 3) / 10;
  1236. }
  1237. $query2 = mysql_query('SELECT * FROM `' . TB_PREFIX . 'vdata` WHERE `wref` = ' . $village->wid);
  1238. $data2 = mysql_fetch_assoc($query2);
  1239. $exp_c = 0;
  1240.  
  1241. if($data2['exp1'] != 0) ++$exp_c;
  1242. if($data2['exp2'] != 0) ++$exp_c;
  1243. $can_settle = 2-$exp_c;
  1244.  
  1245. if($can_settle == 0) {
  1246. $unit = 0;
  1247. } else {
  1248. if($amt > ($max_settlers - $data['u' . $session->tribe . '0'])) {
  1249. $amt = $max_settlers - $data['u' . $session->tribe . '0'];
  1250. }
  1251. }
  1252. }
  1253. $q = "INSERT INTO ".TB_PREFIX."training values (0,$vid,$unit,$amt,$pop,$time,1,$time)";
  1254. } else {
  1255. $q = "DELETe FROM ".TB_PREFIX."training where id = $vid";
  1256. }
  1257. return mysql_query($q,$this->connection);
  1258. }
  1259.  
  1260. function updateTraining($id,$trained) {
  1261. $time = time();
  1262. $q = "UPDATE ".TB_PREFIX."training set amt = amt - $trained, timestamp = $time where id = $id";
  1263. return mysql_query($q,$this->connection);
  1264. }
  1265.  
  1266. function modifyUnit($vref,$unit,$amt,$mode) {
  1267. if($unit == 230) { $unit = 30; }
  1268. if($unit == 231) { $unit = 31; }
  1269. if($unit == 120) { $unit = 20; }
  1270. if($unit == 121) { $unit = 21; }
  1271. $unit = 'u'.$unit;
  1272. if(!$mode) {
  1273. $q = "UPDATE ".TB_PREFIX."units set $unit = $unit - $amt where vref = $vref";
  1274. }
  1275. else {
  1276. $q = "UPDATE ".TB_PREFIX."units set $unit = $unit + $amt where vref = $vref";
  1277. }
  1278. return mysql_query($q,$this->connection);
  1279. }
  1280.  
  1281. function getEnforce($vid,$mode) {
  1282. if($mode) {
  1283. $q = "SELECT * from ".TB_PREFIX."enforcement where vref = $vid";
  1284. }
  1285. else {
  1286. $q = "SELECT * from ".TB_PREFIX."enforcement where from = $vid";
  1287. }
  1288. $result = mysql_query($q,$this->connection);
  1289. return $this->mysql_fetch_all($result);
  1290. }
  1291.  
  1292. function addEnforce($t1,$t2,$t3,$t4,$t5,$t6,$t7,$t8,$t9,$t10,$from,$to) {
  1293. $q = "INSERT INTO ".TB_PREFIX."enforcement values (0,$t1,$t2,$t3,$t4,$t5,$t6,$t7,$t8,$t9,$t10,$from,$to)";
  1294. mysql_query($q, $this->connection);
  1295. return mysql_insert_id($this->connection);
  1296. }
  1297.  
  1298. function getEnforceArray($id) {
  1299. $q = "SELECT * from ".TB_PREFIX."enforcement where id = $id";
  1300. $result = mysql_query($q, $this->connection);
  1301. return mysql_fetch_assoc($result);
  1302. }
  1303.  
  1304. function modifyCommence($id) {
  1305. $time = time();
  1306. $q = "UPDATE ".TB_PREFIX."training set commence = $time";
  1307. return mysql_query($q,$this->connection);
  1308. }
  1309.  
  1310. function getTrainingList() {
  1311. $q = "SELECT * FROM ".TB_PREFIX."training where vref != ''";
  1312. $result = mysql_query($q,$this->connection);
  1313. return $this->mysql_fetch_all($result);
  1314. }
  1315.  
  1316. function getNeedDelete() {
  1317. $time = time();
  1318. $q = "SELECT uid FROM ".TB_PREFIX."deleting where timestamp < $time";
  1319. $result = mysql_query($q,$this->connection);
  1320. return $this->mysql_fetch_all($result);
  1321. }
  1322.  
  1323. function countUser() {
  1324. $q = "SELECT count(id) FROM ".TB_PREFIX."users where id != 0";
  1325. $result = mysql_query($q,$this->connection);
  1326. $row = mysql_fetch_row($result);
  1327. return $row[0];
  1328. }
  1329.  
  1330. function countAlli() {
  1331. $q = "SELECT count(id) FROM ".TB_PREFIX."alidata where id != 0";
  1332. $result = mysql_query($q,$this->connection);
  1333. $row = mysql_fetch_row($result);
  1334. return $row[0];
  1335. }
  1336.  
  1337. /***************************
  1338. Function to process MYSQLi->fetch_all (Only exist in MYSQL)
  1339. References: Result
  1340. ***************************/
  1341. function mysql_fetch_all($result) {
  1342. $all = array();
  1343. if($result) {
  1344. while ($row = mysql_fetch_assoc($result)){ $all[] = $row; }
  1345. return $all;
  1346. }
  1347. }
  1348.  
  1349. function query_return($q) {
  1350. $result = mysql_query($q, $this->connection);
  1351. return $this->mysql_fetch_all($result);
  1352. }
  1353.  
  1354. /***************************
  1355. Function to do free query
  1356. References: Query
  1357. ***************************/
  1358. function query($query) {
  1359. return mysql_query($query, $this->connection);
  1360. }
  1361.  
  1362. function RemoveXSS($val)
  1363. {
  1364. return htmlspecialchars($val, ENT_QUOTES);
  1365. }
  1366.  
  1367.  
  1368.  
  1369.  
  1370.  
  1371. };
  1372.  
  1373. $database = new MYSQL_DB;
  1374. ?>
Add Comment
Please, Sign In to add comment