PageRenderTime 58ms CodeModel.GetById 17ms 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

Large files files are truncated, but you can click here to view the full 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,$alliā€¦

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