PageRenderTime 55ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/GameEngine/db_MYSQL.php

https://bitbucket.org/Dzoki/travianx
PHP | 2277 lines | 1804 code | 266 blank | 207 comment | 269 complexity | 67a2c7e919d7aef4cd73b08d1dac7edc 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. return mysql_fetch_array($result);
  685. }
  686. function CheckForum($id) {
  687. $q = "SELECT * from " . TB_PREFIX . "forum_cat where alliance = '$id'";
  688. $result = mysql_query($q, $this->connection);
  689. if(mysql_num_rows($result)) {
  690. return true;
  691. } else {
  692. return false;
  693. }
  694. }
  695. function CountCat($id) {
  696. $q = "SELECT count(id) FROM " . TB_PREFIX . "forum_topic where cat = '$id'";
  697. $result = mysql_query($q, $this->connection);
  698. $row = mysql_fetch_row($result);
  699. return $row[0];
  700. }
  701. function LastTopic($id) {
  702. $q = "SELECT * from " . TB_PREFIX . "forum_topic where cat = '$id' order by post_date";
  703. $result = mysql_query($q, $this->connection);
  704. return $this->mysql_fetch_all($result);
  705. }
  706. function CheckLastTopic($id) {
  707. $q = "SELECT * from " . TB_PREFIX . "forum_topic where cat = '$id'";
  708. $result = mysql_query($q, $this->connection);
  709. if(mysql_num_rows($result)) {
  710. return true;
  711. } else {
  712. return false;
  713. }
  714. }
  715. function CheckLastPost($id) {
  716. $q = "SELECT * from " . TB_PREFIX . "forum_post where topic = '$id'";
  717. $result = mysql_query($q, $this->connection);
  718. if(mysql_num_rows($result)) {
  719. return true;
  720. } else {
  721. return false;
  722. }
  723. }
  724. function LastPost($id) {
  725. $q = "SELECT * from " . TB_PREFIX . "forum_post where topic = '$id'";
  726. $result = mysql_query($q, $this->connection);
  727. return $this->mysql_fetch_all($result);
  728. }
  729. function CountTopic($id) {
  730. $q = "SELECT count(id) FROM " . TB_PREFIX . "forum_post where owner = '$id'";
  731. $result = mysql_query($q, $this->connection);
  732. $row = mysql_fetch_row($result);
  733. $qs = "SELECT count(id) FROM " . TB_PREFIX . "forum_topic where owner = '$id'";
  734. $results = mysql_query($qs, $this->connection);
  735. $rows = mysql_fetch_row($results);
  736. return $row[0] + $rows[0];
  737. }
  738. function CountPost($id) {
  739. $q = "SELECT count(id) FROM " . TB_PREFIX . "forum_post where topic = '$id'";
  740. $result = mysql_query($q, $this->connection);
  741. $row = mysql_fetch_row($result);
  742. return $row[0];
  743. }
  744. function ForumCat($id) {
  745. $q = "SELECT * from " . TB_PREFIX . "forum_cat where alliance = '$id' ORDER BY id";
  746. $result = mysql_query($q, $this->connection);
  747. return $this->mysql_fetch_all($result);
  748. }
  749. function ForumCatEdit($id) {
  750. $q = "SELECT * from " . TB_PREFIX . "forum_cat where id = '$id'";
  751. $result = mysql_query($q, $this->connection);
  752. return $this->mysql_fetch_all($result);
  753. }
  754. function ForumCatName($id) {
  755. $q = "SELECT forum_name from " . TB_PREFIX . "forum_cat where id = $id";
  756. $result = mysql_query($q, $this->connection);
  757. $dbarray = mysql_fetch_array($result);
  758. return $dbarray['forum_name'];
  759. }
  760. function CheckCatTopic($id) {
  761. $q = "SELECT * from " . TB_PREFIX . "forum_topic where cat = '$id'";
  762. $result = mysql_query($q, $this->connection);
  763. if(mysql_num_rows($result)) {
  764. return true;
  765. } else {
  766. return false;
  767. }
  768. }
  769. function CheckResultEdit($alli) {
  770. $q = "SELECT * from " . TB_PREFIX . "forum_edit where alliance = '$alli'";
  771. $result = mysql_query($q, $this->connection);
  772. if(mysql_num_rows($result)) {
  773. return true;
  774. } else {
  775. return false;
  776. }
  777. }
  778. function CheckCloseTopic($id) {
  779. $q = "SELECT close from " . TB_PREFIX . "forum_topic where id = '$id'";
  780. $result = mysql_query($q, $this->connection);
  781. $dbarray = mysql_fetch_array($result);
  782. return $dbarray['close'];
  783. }
  784. function CheckEditRes($alli) {
  785. $q = "SELECT result from " . TB_PREFIX . "forum_edit where alliance = '$alli'";
  786. $result = mysql_query($q, $this->connection);
  787. $dbarray = mysql_fetch_array($result);
  788. return $dbarray['result'];
  789. }
  790. function CreatResultEdit($alli, $result) {
  791. $q = "INSERT into " . TB_PREFIX . "forum_edit values (0,'$alli','$result')";
  792. mysql_query($q, $this->connection);
  793. return mysql_insert_id($this->connection);
  794. }
  795. function UpdateResultEdit($alli, $result) {
  796. $date = time();
  797. $q = "UPDATE " . TB_PREFIX . "forum_edit set result = '$result' where alliance = '$alli'";
  798. return mysql_query($q, $this->connection);
  799. }
  800. function UpdateEditTopic($id, $title, $cat) {
  801. $q = "UPDATE " . TB_PREFIX . "forum_topic set title = '$title', cat = '$cat' where id = $id";
  802. return mysql_query($q, $this->connection);
  803. }
  804. function UpdateEditForum($id, $name, $des) {
  805. $q = "UPDATE " . TB_PREFIX . "forum_cat set forum_name = '$name', forum_des = '$des' where id = $id";
  806. return mysql_query($q, $this->connection);
  807. }
  808. function StickTopic($id, $mode) {
  809. $q = "UPDATE " . TB_PREFIX . "forum_topic set stick = '$mode' where id = '$id'";
  810. return mysql_query($q, $this->connection);
  811. }
  812. function ForumCatTopic($id) {
  813. $q = "SELECT * from " . TB_PREFIX . "forum_topic where cat = '$id' AND stick = '' ORDER BY post_date desc";
  814. $result = mysql_query($q, $this->connection);
  815. return $this->mysql_fetch_all($result);
  816. }
  817. function ForumCatTopicStick($id) {
  818. $q = "SELECT * from " . TB_PREFIX . "forum_topic where cat = '$id' AND stick = '1' ORDER BY post_date desc";
  819. $result = mysql_query($q, $this->connection);
  820. return $this->mysql_fetch_all($result);
  821. }
  822. function ShowTopic($id) {
  823. $q = "SELECT * from " . TB_PREFIX . "forum_topic where id = '$id'";
  824. $result = mysql_query($q, $this->connection);
  825. return $this->mysql_fetch_all($result);
  826. }
  827. function ShowPost($id) {
  828. $q = "SELECT * from " . TB_PREFIX . "forum_post where topic = '$id'";
  829. $result = mysql_query($q, $this->connection);
  830. return $this->mysql_fetch_all($result);
  831. }
  832. function ShowPostEdit($id) {
  833. $q = "SELECT * from " . TB_PREFIX . "forum_post where id = '$id'";
  834. $result = mysql_query($q, $this->connection);
  835. return $this->mysql_fetch_all($result);
  836. }
  837. function CreatForum($owner, $alli, $name, $des, $area) {
  838. $q = "INSERT into " . TB_PREFIX . "forum_cat values (0,'$owner','$alli','$name','$des','$area')";
  839. mysql_query($q, $this->connection);
  840. return mysql_insert_id($this->connection);
  841. }
  842. function CreatTopic($title, $post, $cat, $owner, $alli, $ends) {
  843. $date = time();
  844. $q = "INSERT into " . TB_PREFIX . "forum_topic values (0,'$title','$post','$date','$date','$cat','$owner','$alli','$ends','','')";
  845. mysql_query($q, $this->connection);
  846. return mysql_insert_id($this->connection);
  847. }
  848. function CreatPost($post, $tids, $owner) {
  849. $date = time();
  850. $q = "INSERT into " . TB_PREFIX . "forum_post values (0,'$post','$tids','$owner','$date')";
  851. mysql_query($q, $this->connection);
  852. return mysql_insert_id($this->connection);
  853. }
  854. function UpdatePostDate($id) {
  855. $date = time();
  856. $q = "UPDATE " . TB_PREFIX . "forum_topic set post_date = '$date' where id = $id";
  857. return mysql_query($q, $this->connection);
  858. }
  859. function EditUpdateTopic($id, $post) {
  860. $q = "UPDATE " . TB_PREFIX . "forum_topic set post = '$post' where id = $id";
  861. return mysql_query($q, $this->connection);
  862. }
  863. function EditUpdatePost($id, $post) {
  864. $q = "UPDATE " . TB_PREFIX . "forum_post set post = '$post' where id = $id";
  865. return mysql_query($q, $this->connection);
  866. }
  867. function LockTopic($id, $mode) {
  868. $q = "UPDATE " . TB_PREFIX . "forum_topic set close = '$mode' where id = '$id'";
  869. return mysql_query($q, $this->connection);
  870. }
  871. function DeleteCat($id) {
  872. $qs = "DELETE from " . TB_PREFIX . "forum_cat where id = '$id'";
  873. $q = "DELETE from " . TB_PREFIX . "forum_topic where cat = '$id'";
  874. mysql_query($qs, $this->connection);
  875. return mysql_query($q, $this->connection);
  876. }
  877. function DeleteTopic($id) {
  878. $qs = "DELETE from " . TB_PREFIX . "forum_topic where id = '$id'";
  879. // $q = "DELETE from ".TB_PREFIX."forum_post where topic = '$id'";//
  880. return mysql_query($qs, $this->connection); //
  881. // mysql_query($q,$this->connection);
  882. }
  883. function DeletePost($id) {
  884. $q = "DELETE from " . TB_PREFIX . "forum_post where id = '$id'";
  885. return mysql_query($q, $this->connection);
  886. }
  887. function getAllianceName($id) {
  888. $q = "SELECT tag from " . TB_PREFIX . "alidata where id = $id";
  889. $result = mysql_query($q, $this->connection);
  890. $dbarray = mysql_fetch_array($result);
  891. return $dbarray['tag'];
  892. }
  893. function getAlliancePermission($ref, $field, $mode) {
  894. if(!$mode) {
  895. $q = "SELECT $field FROM " . TB_PREFIX . "ali_permission where uid = '$ref'";
  896. } else {
  897. $q = "SELECT $field FROM " . TB_PREFIX . "ali_permission where username = '$ref'";
  898. }
  899. $result = mysql_query($q, $this->connection) or die(mysql_error());
  900. $dbarray = mysql_fetch_array($result);
  901. return $dbarray[$field];
  902. }
  903. function getAlliance($id) {
  904. $q = "SELECT * from " . TB_PREFIX . "alidata where id = $id";
  905. $result = mysql_query($q, $this->connection);
  906. return mysql_fetch_assoc($result);
  907. }
  908. function setAlliName($aid, $name, $tag) {
  909. $q = "UPDATE " . TB_PREFIX . "alidata set name = '$name', tag = '$tag' where id = $aid";
  910. return mysql_query($q, $this->connection);
  911. }
  912. function isAllianceOwner($id) {
  913. $q = "SELECT * from " . TB_PREFIX . "alidata where leader = '$id'";
  914. $result = mysql_query($q, $this->connection);
  915. if(mysql_num_rows($result)) {
  916. return true;
  917. } else {
  918. return false;
  919. }
  920. }
  921. function aExist($ref, $type) {
  922. $q = "SELECT $type FROM " . TB_PREFIX . "alidata where $type = '$ref'";
  923. $result = mysql_query($q, $this->connection);
  924. if(mysql_num_rows($result)) {
  925. return true;
  926. } else {
  927. return false;
  928. }
  929. }
  930. function modifyPoints($aid, $points, $amt) {
  931. $q = "UPDATE " . TB_PREFIX . "users set $points = $points + $amt where id = $aid";
  932. return mysql_query($q, $this->connection);
  933. }
  934. function modifyPointsAlly($aid, $points, $amt) {
  935. $q = "UPDATE " . TB_PREFIX . "alidata set $points = $points + $amt where id = $aid";
  936. return mysql_query($q, $this->connection);
  937. }
  938. /*****************************************
  939. Function to create an alliance
  940. References:
  941. *****************************************/
  942. function createAlliance($tag, $name, $uid, $max) {
  943. $q = "INSERT into " . TB_PREFIX . "alidata values (0,'$name','$tag',$uid,0,0,0,'','',$max,'','','','','','','','')";
  944. mysql_query($q, $this->connection);
  945. return mysql_insert_id($this->connection);
  946. }
  947. /*****************************************
  948. Function to insert an alliance new
  949. References:
  950. *****************************************/
  951. function insertAlliNotice($aid, $notice) {
  952. $time = time();
  953. $q = "INSERT into " . TB_PREFIX . "ali_log values (0,'$aid','$notice',$time)";
  954. mysql_query($q, $this->connection);
  955. return mysql_insert_id($this->connection);
  956. }
  957. /*****************************************
  958. Function to delete alliance if empty
  959. References:
  960. *****************************************/
  961. function deleteAlliance($aid) {
  962. $result = mysql_query("SELECT * FROM " . TB_PREFIX . "users where alliance = $aid");
  963. $num_rows = mysql_num_rows($result);
  964. if($num_rows == 0) {
  965. $q = "DELETE FROM " . TB_PREFIX . "alidata WHERE id = $aid";
  966. }
  967. mysql_query($q, $this->connection);
  968. return mysql_insert_id($this->connection);
  969. }
  970. /*****************************************
  971. Function to read all alliance news
  972. References:
  973. *****************************************/
  974. function readAlliNotice($aid) {
  975. $q = "SELECT * from " . TB_PREFIX . "ali_log where aid = $aid ORDER BY date DESC";
  976. $result = mysql_query($q, $this->connection);
  977. return $this->mysql_fetch_all($result);
  978. }
  979. /*****************************************
  980. Function to create alliance permissions
  981. References: ID, notice, description
  982. *****************************************/
  983. function createAlliPermissions($uid, $aid, $rank, $opt1, $opt2, $opt3, $opt4, $opt5, $opt6, $opt7, $opt8) {
  984. $q = "INSERT into " . TB_PREFIX . "ali_permission values(0,'$uid','$aid','$rank','$opt1','$opt2','$opt3','$opt4','$opt5','$opt6','$opt7','$opt8')";
  985. mysql_query($q, $this->connection);
  986. return mysql_insert_id($this->connection);
  987. }
  988. /*****************************************
  989. Function to update alliance permissions
  990. References:
  991. *****************************************/
  992. function deleteAlliPermissions($uid) {
  993. $q = "DELETE from " . TB_PREFIX . "ali_permission where uid = '$uid'";
  994. return mysql_query($q, $this->connection);
  995. }
  996. /*****************************************
  997. Function to update alliance permissions
  998. References:
  999. *****************************************/
  1000. function updateAlliPermissions($uid, $aid, $rank, $opt1, $opt2, $opt3, $opt4, $opt5, $opt6, $opt7) {
  1001. $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";
  1002. return mysql_query($q, $this->connection);
  1003. }
  1004. /*****************************************
  1005. Function to read alliance permissions
  1006. References: ID, notice, description
  1007. *****************************************/
  1008. function getAlliPermissions($uid, $aid) {
  1009. $q = "SELECT * FROM " . TB_PREFIX . "ali_permission where uid = $uid && alliance = $aid";
  1010. $result = mysql_query($q, $this->connection);
  1011. return mysql_fetch_assoc($result);
  1012. }
  1013. /*****************************************
  1014. Function to update an alliance description and notice
  1015. References: ID, notice, description
  1016. *****************************************/
  1017. function submitAlliProfile($aid, $notice, $desc) {
  1018. $q = "UPDATE " . TB_PREFIX . "alidata SET `notice` = '$notice', `desc` = '$desc' where id = $aid";
  1019. return mysql_query($q, $this->connection);
  1020. }
  1021. function diplomacyInviteAdd($alli1, $alli2, $type) {
  1022. $q = "INSERT INTO " . TB_PREFIX . "diplomacy (alli1,alli2,type,accepted) VALUES ($alli1,$alli2," . (int)intval($type) . ",0)";

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