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

/GameEngine/Database/db_MYSQL.php

http://traviant4.codeplex.com
PHP | 3174 lines | 2752 code | 258 blank | 164 comment | 239 complexity | e62bb7b17c1eb923737ba01e347014dd MD5 | raw file

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

  1. <?php
  2. class MYSQL_DB {
  3. var $connection;
  4. function MYSQL_DB() {
  5. $this->connection = mysql_connect(SQL_SERVER, SQL_USER, SQL_PASS) or die(mysql_error());
  6. mysql_select_db(SQL_DB, $this->connection) or die(mysql_error());
  7. }
  8. function register($username, $password, $email, $tribe, $locate, $act) {
  9. $time = time();
  10. $timep = ($time + PROTECTION);
  11. $rand = rand(8900, 9000);
  12. $q = "INSERT INTO " . TB_PREFIX . "users (username,password,access,email,timestamp,tribe,location,act,protect,clp,cp) VALUES ('$username', '$password', " . USER . ", '$email', $time, $tribe, $locate, '$act', $timep, '$rand', 1)";
  13. if(mysql_query($q, $this->connection)) {
  14. return mysql_insert_id($this->connection);
  15. } else {
  16. return false;
  17. }
  18. }
  19. function activate($username, $password, $email, $tribe, $locate, $act, $act2) {
  20. $time = time();
  21. $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')";
  22. if(mysql_query($q, $this->connection)) {
  23. return mysql_insert_id($this->connection);
  24. } else {
  25. return false;
  26. }
  27. }
  28. function unreg($username) {
  29. $q = "DELETE from " . TB_PREFIX . "activate where username = '$username'";
  30. return mysql_query($q, $this->connection);
  31. }
  32. function deleteReinf($id) {
  33. $q = "DELETE from " . TB_PREFIX . "enforcement where id = '$id'";
  34. mysql_query($q, $this->connection);
  35. }
  36. function updateResource($vid, $what, $number) {
  37. $q = "UPDATE " . TB_PREFIX . "vdata set " . $what . "=" . $number . " where wref = $vid";
  38. $result = mysql_query($q, $this->connection);
  39. return mysql_query($q, $this->connection);
  40. }
  41. function checkExist($ref, $mode) {
  42. if(!$mode) {
  43. $q = "SELECT username FROM " . TB_PREFIX . "users where username = '$ref' LIMIT 1";
  44. } else {
  45. $q = "SELECT email FROM " . TB_PREFIX . "users where email = '$ref' LIMIT 1";
  46. }
  47. $result = mysql_query($q, $this->connection);
  48. if(mysql_num_rows($result)) {
  49. return true;
  50. } else {
  51. return false;
  52. }
  53. }
  54. function checkExist_activate($ref, $mode) {
  55. if(!$mode) {
  56. $q = "SELECT username FROM " . TB_PREFIX . "activate where username = '$ref' LIMIT 1";
  57. } else {
  58. $q = "SELECT email FROM " . TB_PREFIX . "activate where email = '$ref' LIMIT 1";
  59. }
  60. $result = mysql_query($q, $this->connection);
  61. if(mysql_num_rows($result)) {
  62. return true;
  63. } else {
  64. return false;
  65. }
  66. }
  67. function updateUserField($ref, $field, $value, $mode) {
  68. if(!$mode) {
  69. $q = "UPDATE " . TB_PREFIX . "users set $field = '$value' where username = '$ref'";
  70. } elseif($mode==1) {
  71. $q = "UPDATE " . TB_PREFIX . "users set $field = '$value' where id = '$ref'";
  72. } elseif($mode==2) {
  73. $q = "UPDATE " . TB_PREFIX . "users set $field = $field + '$value' where id = '$ref'";
  74. }
  75. return mysql_query($q, $this->connection);
  76. }
  77. function getSitee($uid) {
  78. $q = "SELECT id from " . TB_PREFIX . "users where sit1 = $uid or sit2 = $uid";
  79. $result = mysql_query($q, $this->connection);
  80. return $this->mysql_fetch_all($result);
  81. }
  82. function getSitee1($uid) {
  83. $q = "SELECT * from " . TB_PREFIX . "users where sit1 = $uid";
  84. $result = mysql_query($q, $this->connection);
  85. $dbarray = mysql_fetch_array($result);
  86. return $dbarray;
  87. }
  88. function getSitee2($uid) {
  89. $q = "SELECT * from " . TB_PREFIX . "users where sit2 = $uid";
  90. $result = mysql_query($q, $this->connection);
  91. $dbarray = mysql_fetch_array($result);
  92. return $dbarray;
  93. }
  94. function removeMeSit($uid, $uid2) {
  95. $q = "UPDATE " . TB_PREFIX . "users set sit1 = 0 where id = $uid and sit1 = $uid2";
  96. mysql_query($q, $this->connection);
  97. $q2 = "UPDATE " . TB_PREFIX . "users set sit2 = 0 where id = $uid and sit2 = $uid2";
  98. mysql_query($q2, $this->connection);
  99. }
  100. function getUserField($ref, $field, $mode) {
  101. if(!$mode) {
  102. $q = "SELECT $field FROM " . TB_PREFIX . "users where id = '$ref'";
  103. } else {
  104. $q = "SELECT $field FROM " . TB_PREFIX . "users where username = '$ref'";
  105. }
  106. $result = mysql_query($q, $this->connection) or die(mysql_error());
  107. $dbarray = mysql_fetch_array($result);
  108. return $dbarray[$field];
  109. }
  110. function getActivateField($ref, $field, $mode) {
  111. if(!$mode) {
  112. $q = "SELECT $field FROM " . TB_PREFIX . "activate where id = '$ref'";
  113. } else {
  114. $q = "SELECT $field FROM " . TB_PREFIX . "activate where username = '$ref'";
  115. }
  116. $result = mysql_query($q, $this->connection) or die(mysql_error());
  117. $dbarray = mysql_fetch_array($result);
  118. return $dbarray[$field];
  119. }
  120. function login($username, $password) {
  121. $q = "SELECT password,sessid FROM " . TB_PREFIX . "users where username = '$username'";
  122. $result = mysql_query($q, $this->connection);
  123. $dbarray = mysql_fetch_array($result);
  124. if($dbarray['password'] == md5($password)) {
  125. return true;
  126. } else {
  127. return false;
  128. }
  129. }
  130. function checkActivate($act) {
  131. $q = "SELECT * FROM " . TB_PREFIX . "activate where act = '$act'";
  132. $result = mysql_query($q, $this->connection);
  133. $dbarray = mysql_fetch_array($result);
  134. return $dbarray;
  135. }
  136. function sitterLogin($username, $password) {
  137. $q = "SELECT sit1,sit2 FROM " . TB_PREFIX . "users where username = '$username' and access != " . BANNED;
  138. $result = mysql_query($q, $this->connection);
  139. $dbarray = mysql_fetch_array($result);
  140. if($dbarray['sit1'] != 0) {
  141. $q2 = "SELECT password FROM " . TB_PREFIX . "users where id = " . $dbarray['sit1'] . " and access != " . BANNED;
  142. $result2 = mysql_query($q2, $this->connection);
  143. $pw_sit1 = mysql_fetch_array($result2);
  144. }
  145. elseif($dbarray['sit2'] != 0) {
  146. $q3 = "SELECT password FROM " . TB_PREFIX . "users where id = " . $dbarray['sit2'] . " and access != " . BANNED;
  147. $result3 = mysql_query($q3, $this->connection);
  148. $pw_sit2 = mysql_fetch_array($result3);
  149. }
  150. if($dbarray['sit1'] != 0 || $dbarray['sit2'] != 0) {
  151. if($pw_sit1['password'] == md5($password) || $pw_sit2['password'] == md5($password)) {
  152. return true;
  153. } else {
  154. return false;
  155. }
  156. } else {
  157. return false;
  158. }
  159. }
  160. function setDeleting($uid, $mode) {
  161. $time = time() + 72 * 3600;
  162. if(!$mode) {
  163. $q = "INSERT into " . TB_PREFIX . "deleting values ($uid,$time)";
  164. } else {
  165. $q = "DELETE FROM " . TB_PREFIX . "deleting where uid = $uid";
  166. }
  167. mysql_query($q, $this->connection);
  168. }
  169. function isDeleting($uid) {
  170. $q = "SELECT timestamp from " . TB_PREFIX . "deleting where uid = $uid";
  171. $result = mysql_query($q, $this->connection);
  172. $dbarray = mysql_fetch_array($result);
  173. return $dbarray['timestamp'];
  174. }
  175. function modifyGold($userid, $amt, $mode) {
  176. if(!$mode) {
  177. $q = "UPDATE " . TB_PREFIX . "users set gold = gold - $amt where id = $userid";
  178. } else {
  179. $q = "UPDATE " . TB_PREFIX . "users set gold = gold + $amt where id = $userid";
  180. }
  181. return mysql_query($q, $this->connection);
  182. }
  183. /*****************************************
  184. Function to retrieve user array via Username or ID
  185. Mode 0: Search by Username
  186. Mode 1: Search by ID
  187. References: Alliance ID
  188. *****************************************/
  189. function getUserArray($ref, $mode) {
  190. if(!$mode) {
  191. $q = "SELECT * FROM " . TB_PREFIX . "users where username = '$ref'";
  192. } else {
  193. $q = "SELECT * FROM " . TB_PREFIX . "users where id = $ref";
  194. }
  195. $result = mysql_query($q, $this->connection);
  196. return mysql_fetch_array($result);
  197. }
  198. function getUserWithEmail($email) {
  199. $q = "SELECT * FROM " . TB_PREFIX . "users where email = '$email'";
  200. $result = mysql_query($q, $this->connection);
  201. return mysql_fetch_array($result);
  202. }
  203. function activeModify($username, $mode) {
  204. $time = time();
  205. if(!$mode) {
  206. $q = "INSERT into " . TB_PREFIX . "active VALUES ('$username',$time)";
  207. } else {
  208. $q = "DELETE FROM " . TB_PREFIX . "active where username = '$username'";
  209. }
  210. return mysql_query($q, $this->connection);
  211. }
  212. function addActiveUser($username, $time) {
  213. $q = "REPLACE into " . TB_PREFIX . "active values ('$username',$time)";
  214. if(mysql_query($q, $this->connection)) {
  215. return true;
  216. } else {
  217. return false;
  218. }
  219. }
  220. function updateActiveUser($username, $time) {
  221. $q = "REPLACE into " . TB_PREFIX . "active (`username`, `timestamp`) values ('$username',$time)";
  222. $q2 = "UPDATE " . TB_PREFIX . "users set timestamp = $time where username = '$username'";
  223. $exec1 = mysql_query($q, $this->connection);
  224. $exec2 = mysql_query($q2, $this->connection);
  225. if($exec1 && $exec2) {
  226. return true;
  227. } else {
  228. return false;
  229. }
  230. }
  231. function checkSitter($username){
  232. $q = "SELECT * FROM ".TB_PREFIX."online WHERE name = '".$username."'";
  233. $result = mysql_query($q, $this->connection);
  234. $dbarray = mysql_fetch_array($result);
  235. return $dbarray['sitter'];
  236. }
  237. public function canConquerOasis($vref,$wref) {
  238. $AttackerFields = $this->getResourceLevel($vref);
  239. for($i=19;$i<=38;$i++) {
  240. if($AttackerFields['f'.$i.'t'] == 37) { $HeroMansionLevel = $AttackerFields['f'.$i]; }
  241. }
  242. if($this->VillageOasisCount($vref) < floor(($HeroMansionLevel-5)/5)) {
  243. $OasisInfo = $this->getOasisInfo($wref);
  244. $troopcount = $this->countOasisTroops($wref);
  245. if($OasisInfo['conqured'] == 0 || $OasisInfo['conqured'] != 0 && $OasisInfo['loyalty'] < 99 / min(3,(4-$this->VillageOasisCount($OasisInfo['conqured']))) && $troopcount == 0) {
  246. $CoordsVillage = $this->getCoor($vref);
  247. $CoordsOasis = $this->getCoor($wref);
  248. if(abs($CoordsOasis['x']-$CoordsVillage['x'])<=3 && abs($CoordsOasis['y']-$CoordsVillage['y'])<=3) {
  249. return True;
  250. } else {
  251. return False;
  252. }
  253. } else {
  254. return False;
  255. }
  256. } else {
  257. return False;
  258. }
  259. }
  260. public function conquerOasis($vref,$wref) {
  261. $vinfo = $this->getVillage($vref);
  262. $uid = $vinfo['owner'];
  263. $q = "UPDATE `".TB_PREFIX."odata` SET conqured=$vref,loyalty=100,lastupdated=".time().",owner=$uid,name='Occupied Oasis' WHERE wref=$wref";
  264. return mysql_query($q, $this->connection);
  265. }
  266. public function modifyOasisLoyalty($wref) {
  267. if($this->isVillageOases($wref) != 0) {
  268. $OasisInfo = $this->getOasisInfo($wref);
  269. if($OasisInfo['conqured'] != 0) {
  270. $LoyaltyAmendment = floor(100 / min(3,(4-$this->VillageOasisCount($OasisInfo['conqured']))));
  271. $q = "UPDATE `".TB_PREFIX."odata` SET loyalty=loyalty-$LoyaltyAmendment WHERE wref=$wref";
  272. return mysql_query($q, $this->connection);
  273. }
  274. }
  275. }
  276. function checkactiveSession($username, $sessid) {
  277. $user = $this->getUserArray($username, 0);
  278. $sessidarray = explode("+", $user['sessid']);
  279. if(in_array($sessid, $sessidarray)) {
  280. return true;
  281. } else {
  282. return false;
  283. }
  284. }
  285. function submitProfile($uid, $gender, $location, $birthday, $des1, $des2) {
  286. $q = "UPDATE " . TB_PREFIX . "users set gender = $gender, location = '$location', birthday = '$birthday', desc1 = '$des1', desc2 = '$des2' where id = $uid";
  287. return mysql_query($q, $this->connection);
  288. }
  289. function gpack($uid, $gpack) {
  290. $q = "UPDATE " . TB_PREFIX . "users set gpack = '$gpack' where id = $uid";
  291. return mysql_query($q, $this->connection);
  292. }
  293. function UpdateOnline($mode, $name = "", $sit = 0) {
  294. global $session;
  295. if($mode == "login") {
  296. $q = "INSERT IGNORE INTO " . TB_PREFIX . "online (name, time, sitter) VALUES ('$name', ".time().", ".$sit.")";
  297. return mysql_query($q, $this->connection);
  298. } else {
  299. $q = "DELETE FROM " . TB_PREFIX . "online WHERE name ='" . $session->username . "'";
  300. return mysql_query($q, $this->connection);
  301. }
  302. }
  303. //Choice placement where sector
  304. function generateBase($sector){
  305. $sector = ($sector == 0) ? rand(1, 4) : $sector;
  306. // (-/-) SW
  307. if($sector == 1){
  308. $x_a = (WORLD_MAX - (WORLD_MAX*2));
  309. $x_b = 0;
  310. $y_a = (WORLD_MAX - (WORLD_MAX*2));
  311. $y_b = 0;
  312. $order = "ORDER BY y DESC,x DESC";
  313. $mmm = rand(-1, -20);
  314. $x_y = "AND x < -4 AND y < $mmm";
  315. }
  316. // (+/-) SE
  317. elseif($sector == 2){
  318. $x_a = (WORLD_MAX - (WORLD_MAX*2));
  319. $x_b = 0;
  320. $y_a = 0;
  321. $y_b = WORLD_MAX;
  322. $order = "ORDER BY y ASC,x DESC";
  323. $mmm = rand(1, 20);
  324. $x_y = "AND x < -4 AND y > $mmm";
  325. }
  326. // (+/+) NE
  327. elseif($sector == 3){
  328. $x_a = 0;
  329. $x_b = WORLD_MAX;
  330. $y_a = 0;
  331. $y_b = WORLD_MAX;
  332. $order = "ORDER BY y,x ASC";
  333. $mmm = rand(1, 20);
  334. $x_y = "AND x > 4 AND y > $mmm";
  335. }
  336. // (-/+) NW
  337. elseif($sector == 4){
  338. $x_a = 0;
  339. $x_b = WORLD_MAX;
  340. $y_a = (WORLD_MAX - (WORLD_MAX*2));
  341. $y_b = 0;
  342. $order = "ORDER BY y DESC, x ASC";
  343. $mmm = rand(-1, -20);
  344. $x_y = "AND x > 4 AND y < $mmm";
  345. }
  346. $q = "SELECT * FROM ".TB_PREFIX."wdata where fieldtype = 3 and occupied = 0 $x_y and (x BETWEEN $x_a AND $x_b) and (y BETWEEN $y_a AND $y_b) $order LIMIT 20";
  347. $result = mysql_query($q, $this->connection);
  348. $dbarray = mysql_fetch_array($result);
  349. return $dbarray['id'];
  350. }
  351. function setFieldTaken($id) {
  352. $q = "UPDATE " . TB_PREFIX . "wdata set occupied = 1 where id = $id";
  353. return mysql_query($q, $this->connection);
  354. }
  355. function addVillage($wid, $uid, $username, $capital) {
  356. $total = count($this->getVillagesID($uid));
  357. if($total >= 1) {
  358. $vname = "????? ????";
  359. } else {
  360. $vname = "????? ".$username;
  361. }
  362. $time = time();
  363. $q = "INSERT into " . TB_PREFIX . "vdata (wref, owner, name, capital, pop, cp, celebration, wood, clay, iron, maxstore, crop, maxcrop, lastupdate, created) values
  364. ('$wid', '$uid', '$vname', '$capital', 2, 1, 0, 780, 780, 780, 800, 780, 800, '$time', '$time')";
  365. return mysql_query($q, $this->connection) or die(mysql_error());
  366. }
  367. function addResourceFields($vid, $type) {
  368. switch($type) {
  369. case 1:
  370. $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)";
  371. break;
  372. case 2:
  373. $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)";
  374. break;
  375. case 3:
  376. $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)";
  377. break;
  378. case 4:
  379. $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)";
  380. break;
  381. case 5:
  382. $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)";
  383. break;
  384. case 6:
  385. $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)";
  386. break;
  387. case 7:
  388. $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)";
  389. break;
  390. case 8:
  391. $q = "INSERT into " . TB_PREFIX . "fdata (vref,f1t,f2t,f3t,f4t,f5t,f6t,f7t,f8t,f9t,f10t,f11t,f12t,f13t,f14t,f15t,f16t,f17t,f18t,f26,f26t) values($vid,3,4,4,1,2,2,3,4,4,3,3,4,4,1,4,2,1,2,1,15)";
  392. break;
  393. case 9:
  394. $q = "INSERT into " . TB_PREFIX . "fdata (vref,f1t,f2t,f3t,f4t,f5t,f6t,f7t,f8t,f9t,f10t,f11t,f12t,f13t,f14t,f15t,f16t,f17t,f18t,f26,f26t) values($vid,3,4,4,1,1,2,3,4,4,3,3,4,4,1,4,2,1,2,1,15)";
  395. break;
  396. case 10:
  397. $q = "INSERT into " . TB_PREFIX . "fdata (vref,f1t,f2t,f3t,f4t,f5t,f6t,f7t,f8t,f9t,f10t,f11t,f12t,f13t,f14t,f15t,f16t,f17t,f18t,f26,f26t) values($vid,3,4,1,2,2,2,3,4,4,3,3,4,4,1,4,2,1,2,1,15)";
  398. break;
  399. case 11:
  400. $q = "INSERT into " . TB_PREFIX . "fdata (vref,f1t,f2t,f3t,f4t,f5t,f6t,f7t,f8t,f9t,f10t,f11t,f12t,f13t,f14t,f15t,f16t,f17t,f18t,f26,f26t) values($vid,3,1,1,3,1,4,4,3,3,2,2,3,1,4,4,2,4,4,1,15)";
  401. break;
  402. case 12:
  403. $q = "INSERT into " . TB_PREFIX . "fdata (vref,f1t,f2t,f3t,f4t,f5t,f6t,f7t,f8t,f9t,f10t,f11t,f12t,f13t,f14t,f15t,f16t,f17t,f18t,f26,f26t) values($vid,1,4,1,1,2,2,3,4,4,3,3,4,4,1,4,2,1,2,1,15)";
  404. break;
  405. }
  406. return mysql_query($q, $this->connection);
  407. }
  408. function isVillageOases($wref) {
  409. $q = "SELECT id, oasistype FROM " . TB_PREFIX . "wdata where id = $wref";
  410. $result = mysql_query($q, $this->connection);
  411. $dbarray = mysql_fetch_array($result);
  412. return $dbarray['oasistype'];
  413. }
  414. public function VillageOasisCount($vref) {
  415. $q = "SELECT count(*) FROM ".TB_PREFIX."odata WHERE conqured=$vref";
  416. $result = mysql_query($q, $this->connection);
  417. $row = mysql_fetch_row($result);
  418. return $row[0];
  419. }
  420. function populateOasis() {
  421. $q = "SELECT * FROM " . TB_PREFIX . "wdata where oasistype != 0";
  422. $result = mysql_query($q, $this->connection);
  423. while($row = mysql_fetch_array($result)) {
  424. $wid = $row['id'];
  425. $this->addUnits($wid);
  426. }
  427. }
  428. /***************************
  429. Function to retrieve type of village via ID
  430. References: Village ID
  431. ***************************/
  432. function getVillageType($wref) {
  433. $q = "SELECT id, fieldtype FROM " . TB_PREFIX . "wdata where id = $wref";
  434. $result = mysql_query($q, $this->connection);
  435. $dbarray = mysql_fetch_array($result);
  436. return $dbarray['fieldtype'];
  437. }
  438. function getVillageData($wref) {
  439. $q = "SELECT * FROM " . TB_PREFIX . "wdata where id = $wref";
  440. $result = mysql_query($q, $this->connection);
  441. return $this->mysql_fetch_all($result);
  442. }
  443. function getVillageType2($wref) {
  444. $q = "SELECT * FROM " . TB_PREFIX . "wdata where id = $wref";
  445. $result = mysql_query($q, $this->connection);
  446. $dbarray = mysql_fetch_array($result);
  447. return $dbarray['oasistype'];
  448. }
  449. function getVilWref($x, $y) {
  450. $q = "SELECT * FROM " . TB_PREFIX . "wdata where x = $x AND y = $y";
  451. $result = mysql_query($q, $this->connection);
  452. $dbarray = mysql_fetch_array($result);
  453. return $dbarray['id'];
  454. }
  455. function checkVilExist($wref) {
  456. $q = "SELECT * FROM " . TB_PREFIX . "vdata where wref = '$wref'";
  457. $result = mysql_query($q, $this->connection);
  458. if(mysql_num_rows($result)) {
  459. return true;
  460. } else {
  461. return false;
  462. }
  463. }
  464. function oasischecker($x, $y) {
  465. $q = "SELECT * FROM " . TB_PREFIX . "wdata where x = $x AND y = $y";
  466. $result = mysql_query($q, $this->connection);
  467. return $this->mysql_fetch_all($result);
  468. }
  469. /*****************************************
  470. Function to retrieve if is ocuped via ID
  471. References: Village ID
  472. *****************************************/
  473. function getVillageState($wref) {
  474. $q = "SELECT oasistype,occupied FROM " . TB_PREFIX . "wdata where id = $wref";
  475. $result = mysql_query($q, $this->connection);
  476. $dbarray = mysql_fetch_array($result);
  477. if($dbarray['occupied'] != 0 || $dbarray['oasistype'] != 0) {
  478. return true;
  479. } else {
  480. return false;
  481. }
  482. }
  483. function getProfileVillages($uid) {
  484. $q = "SELECT * from " . TB_PREFIX . "vdata where owner = $uid order by pop desc";
  485. $result = mysql_query($q, $this->connection);
  486. return $this->mysql_fetch_all($result);
  487. }
  488. function getProfileMedal($uid) {
  489. $q = "SELECT id,categorie,plaats,week,img,points from " . TB_PREFIX . "medal where userid = $uid order by id desc";
  490. $result = mysql_query($q, $this->connection);
  491. return $this->mysql_fetch_all($result);
  492. }
  493. function getProfileMedalAlly($uid) {
  494. $q = "SELECT id,categorie,plaats,week,img,points from " . TB_PREFIX . "allimedal where allyid = $uid order by id desc";
  495. $result = mysql_query($q, $this->connection);
  496. return $this->mysql_fetch_all($result);
  497. }
  498. function getVillageID($uid) {
  499. $q = "SELECT wref FROM " . TB_PREFIX . "vdata WHERE owner = $uid";
  500. $result = mysql_query($q, $this->connection);
  501. $dbarray = mysql_fetch_array($result);
  502. return $dbarray['wref'];
  503. }
  504. function getVillagesID($uid) {
  505. $q = "SELECT wref from " . TB_PREFIX . "vdata where owner = $uid order by capital DESC";
  506. $result = mysql_query($q, $this->connection);
  507. $array = $this->mysql_fetch_all($result);
  508. $newarray = array();
  509. for($i = 0; $i < count($array); $i++) {
  510. array_push($newarray, $array[$i]['wref']);
  511. }
  512. return $newarray;
  513. }
  514. function getVillage($vid) {
  515. $q = "SELECT * FROM " . TB_PREFIX . "vdata where wref = $vid";
  516. $result = mysql_query($q, $this->connection);
  517. return mysql_fetch_array($result);
  518. }
  519. function getOasisV($vid) {
  520. $q = "SELECT * FROM " . TB_PREFIX . "odata where wref = $vid";
  521. $result = mysql_query($q, $this->connection);
  522. return mysql_fetch_array($result);
  523. }
  524. function getAInfo($id) {
  525. $q = "SELECT * FROM " . TB_PREFIX . "wdata where id = $id";
  526. $result = mysql_query($q, $this->connection);
  527. return mysql_fetch_array($result);
  528. }
  529. function getMInfo($id) {
  530. $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";
  531. $result = mysql_query($q, $this->connection);
  532. return mysql_fetch_array($result);
  533. }
  534. function getOMInfo($id) {
  535. $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";
  536. $result = mysql_query($q, $this->connection);
  537. return mysql_fetch_array($result);
  538. }
  539. function getOasis($vid) {
  540. $q = "SELECT * FROM " . TB_PREFIX . "odata where conqured = $vid";
  541. $result = mysql_query($q, $this->connection);
  542. return $this->mysql_fetch_all($result);
  543. }
  544. function getOasisInfo($wid) {
  545. $q = "SELECT * FROM " . TB_PREFIX . "odata where wref = $wid";
  546. $result = mysql_query($q, $this->connection);
  547. return mysql_fetch_assoc($result);
  548. }
  549. function getVillageField($ref, $field) {
  550. $q = "SELECT $field FROM " . TB_PREFIX . "vdata where wref = $ref";
  551. $result = mysql_query($q, $this->connection);
  552. $dbarray = mysql_fetch_array($result);
  553. return $dbarray[$field];
  554. }
  555. function getOasisField($ref, $field) {
  556. $q = "SELECT $field FROM " . TB_PREFIX . "odata where wref = $ref";
  557. $result = mysql_query($q, $this->connection);
  558. $dbarray = mysql_fetch_array($result);
  559. return $dbarray[$field];
  560. }
  561. function setVillageField($ref, $field, $value) {
  562. $q = "UPDATE " . TB_PREFIX . "vdata set $field = '$value' where wref = $ref";
  563. return mysql_query($q, $this->connection);
  564. }
  565. function setVillageLevel($ref, $field, $value) {
  566. $q = "UPDATE " . TB_PREFIX . "fdata set " . $field . " = '" . $value . "' where vref = " . $ref . "";
  567. return mysql_query($q, $this->connection);
  568. }
  569. function getResourceLevel($vid) {
  570. $q = "SELECT * from " . TB_PREFIX . "fdata where vref = $vid";
  571. $result = mysql_query($q, $this->connection);
  572. return mysql_fetch_assoc($result);
  573. }
  574. function getAdminLog() {
  575. $q = "SELECT id,user,log,time from " . TB_PREFIX . "admin_log where id != 0 ORDER BY id DESC";
  576. $result = mysql_query($q, $this->connection);
  577. return $this->mysql_fetch_all($result);
  578. }
  579. function delAdminLog($id) {
  580. $q = "DELETE FROM " . TB_PREFIX . "admin_log where id = $id";
  581. return mysql_query($q, $this->connection);
  582. }
  583. function getCoor($wref) {
  584. $q = "SELECT x,y FROM " . TB_PREFIX . "wdata where id = $wref";
  585. $result = mysql_query($q, $this->connection);
  586. return mysql_fetch_array($result);
  587. }
  588. function CheckForum($id) {
  589. $q = "SELECT * from " . TB_PREFIX . "forum_cat where alliance = '$id'";
  590. $result = mysql_query($q, $this->connection);
  591. if(mysql_num_rows($result)) {
  592. return true;
  593. } else {
  594. return false;
  595. }
  596. }
  597. function CountCat($id) {
  598. $q = "SELECT count(id) FROM " . TB_PREFIX . "forum_topic where cat = '$id'";
  599. $result = mysql_query($q, $this->connection);
  600. $row = mysql_fetch_row($result);
  601. return $row[0];
  602. }
  603. function LastTopic($id) {
  604. $q = "SELECT * from " . TB_PREFIX . "forum_topic where cat = '$id' order by post_date";
  605. $result = mysql_query($q, $this->connection);
  606. return $this->mysql_fetch_all($result);
  607. }
  608. function CheckLastTopic($id) {
  609. $q = "SELECT * from " . TB_PREFIX . "forum_topic where cat = '$id'";
  610. $result = mysql_query($q, $this->connection);
  611. if(mysql_num_rows($result)) {
  612. return true;
  613. } else {
  614. return false;
  615. }
  616. }
  617. function CheckLastPost($id) {
  618. $q = "SELECT * from " . TB_PREFIX . "forum_post where topic = '$id'";
  619. $result = mysql_query($q, $this->connection);
  620. if(mysql_num_rows($result)) {
  621. return true;
  622. } else {
  623. return false;
  624. }
  625. }
  626. function LastPost($id) {
  627. $q = "SELECT * from " . TB_PREFIX . "forum_post where topic = '$id'";
  628. $result = mysql_query($q, $this->connection);
  629. return $this->mysql_fetch_all($result);
  630. }
  631. function CountTopic($id) {
  632. $q = "SELECT count(id) FROM " . TB_PREFIX . "forum_post where owner = '$id'";
  633. $result = mysql_query($q, $this->connection);
  634. $row = mysql_fetch_row($result);
  635. $qs = "SELECT count(id) FROM " . TB_PREFIX . "forum_topic where owner = '$id'";
  636. $results = mysql_query($qs, $this->connection);
  637. $rows = mysql_fetch_row($results);
  638. return $row[0] + $rows[0];
  639. }
  640. function CountPost($id) {
  641. $q = "SELECT count(id) FROM " . TB_PREFIX . "forum_post where topic = '$id'";
  642. $result = mysql_query($q, $this->connection);
  643. $row = mysql_fetch_row($result);
  644. return $row[0];
  645. }
  646. function ForumCat($id) {
  647. $q = "SELECT * from " . TB_PREFIX . "forum_cat where alliance = '$id' ORDER BY id";
  648. $result = mysql_query($q, $this->connection);
  649. return $this->mysql_fetch_all($result);
  650. }
  651. function ForumCatEdit($id) {
  652. $q = "SELECT * from " . TB_PREFIX . "forum_cat where id = '$id'";
  653. $result = mysql_query($q, $this->connection);
  654. return $this->mysql_fetch_all($result);
  655. }
  656. function ForumCatName($id) {
  657. $q = "SELECT forum_name from " . TB_PREFIX . "forum_cat where id = $id";
  658. $result = mysql_query($q, $this->connection);
  659. $dbarray = mysql_fetch_array($result);
  660. return $dbarray['forum_name'];
  661. }
  662. function CheckCatTopic($id) {
  663. $q = "SELECT * from " . TB_PREFIX . "forum_topic where cat = '$id'";
  664. $result = mysql_query($q, $this->connection);
  665. if(mysql_num_rows($result)) {
  666. return true;
  667. } else {
  668. return false;
  669. }
  670. }
  671. function CheckResultEdit($alli) {
  672. $q = "SELECT * from " . TB_PREFIX . "forum_edit where alliance = '$alli'";
  673. $result = mysql_query($q, $this->connection);
  674. if(mysql_num_rows($result)) {
  675. return true;
  676. } else {
  677. return false;
  678. }
  679. }
  680. function CheckCloseTopic($id) {
  681. $q = "SELECT close from " . TB_PREFIX . "forum_topic where id = '$id'";
  682. $result = mysql_query($q, $this->connection);
  683. $dbarray = mysql_fetch_array($result);
  684. return $dbarray['close'];
  685. }
  686. function CheckEditRes($alli) {
  687. $q = "SELECT result from " . TB_PREFIX . "forum_edit where alliance = '$alli'";
  688. $result = mysql_query($q, $this->connection);
  689. $dbarray = mysql_fetch_array($result);
  690. return $dbarray['result'];
  691. }
  692. function CreatResultEdit($alli, $result) {
  693. $q = "INSERT into " . TB_PREFIX . "forum_edit values (0,'$alli','$result')";
  694. mysql_query($q, $this->connection);
  695. return mysql_insert_id($this->connection);
  696. }
  697. function UpdateResultEdit($alli, $result) {
  698. $date = time();
  699. $q = "UPDATE " . TB_PREFIX . "forum_edit set result = '$result' where alliance = '$alli'";
  700. return mysql_query($q, $this->connection);
  701. }
  702. function UpdateEditTopic($id, $title, $cat) {
  703. $q = "UPDATE " . TB_PREFIX . "forum_topic set title = '$title', cat = '$cat' where id = $id";
  704. return mysql_query($q, $this->connection);
  705. }
  706. function UpdateEditForum($id, $name, $des) {
  707. $q = "UPDATE " . TB_PREFIX . "forum_cat set forum_name = '$name', forum_des = '$des' where id = $id";
  708. return mysql_query($q, $this->connection);
  709. }
  710. function StickTopic($id, $mode) {
  711. $q = "UPDATE " . TB_PREFIX . "forum_topic set stick = '$mode' where id = '$id'";
  712. return mysql_query($q, $this->connection);
  713. }
  714. function ForumCatTopic($id) {
  715. $q = "SELECT * from " . TB_PREFIX . "forum_topic where cat = '$id' AND stick = '' ORDER BY post_date desc";
  716. $result = mysql_query($q, $this->connection);
  717. return $this->mysql_fetch_all($result);
  718. }
  719. function ForumCatTopicStick($id) {
  720. $q = "SELECT * from " . TB_PREFIX . "forum_topic where cat = '$id' AND stick = '1' ORDER BY post_date desc";
  721. $result = mysql_query($q, $this->connection);
  722. return $this->mysql_fetch_all($result);
  723. }
  724. function ShowTopic($id) {
  725. $q = "SELECT * from " . TB_PREFIX . "forum_topic where id = '$id'";
  726. $result = mysql_query($q, $this->connection);
  727. return $this->mysql_fetch_all($result);
  728. }
  729. function ShowPost($id) {
  730. $q = "SELECT * from " . TB_PREFIX . "forum_post where topic = '$id'";
  731. $result = mysql_query($q, $this->connection);
  732. return $this->mysql_fetch_all($result);
  733. }
  734. function ShowPostEdit($id) {
  735. $q = "SELECT * from " . TB_PREFIX . "forum_post where id = '$id'";
  736. $result = mysql_query($q, $this->connection);
  737. return $this->mysql_fetch_all($result);
  738. }
  739. function CreatForum($owner, $alli, $name, $des, $area) {
  740. $q = "INSERT into " . TB_PREFIX . "forum_cat values (0,'$owner','$alli','$name','$des','$area')";
  741. mysql_query($q, $this->connection);
  742. return mysql_insert_id($this->connection);
  743. }
  744. function CreatTopic($title, $post, $cat, $owner, $alli, $ends) {
  745. $date = time();
  746. $q = "INSERT into " . TB_PREFIX . "forum_topic values (0,'$title','$post','$date','$date','$cat','$owner','$alli','$ends','','')";
  747. mysql_query($q, $this->connection);
  748. return mysql_insert_id($this->connection);
  749. }
  750. function CreatPost($post, $tids, $owner) {
  751. $date = time();
  752. $q = "INSERT into " . TB_PREFIX . "forum_post values (0,'$post','$tids','$owner','$date')";
  753. mysql_query($q, $this->connection);
  754. return mysql_insert_id($this->connection);
  755. }
  756. function UpdatePostDate($id) {
  757. $date = time();
  758. $q = "UPDATE " . TB_PREFIX . "forum_topic set post_date = '$date' where id = $id";
  759. return mysql_query($q, $this->connection);
  760. }
  761. function EditUpdateTopic($id, $post) {
  762. $q = "UPDATE " . TB_PREFIX . "forum_topic set post = '$post' where id = $id";
  763. return mysql_query($q, $this->connection);
  764. }
  765. function EditUpdatePost($id, $post) {
  766. $q = "UPDATE " . TB_PREFIX . "forum_post set post = '$post' where id = $id";
  767. return mysql_query($q, $this->connection);
  768. }
  769. function LockTopic($id, $mode) {
  770. $q = "UPDATE " . TB_PREFIX . "forum_topic set close = '$mode' where id = '$id'";
  771. return mysql_query($q, $this->connection);
  772. }
  773. function DeleteCat($id) {
  774. $qs = "DELETE from " . TB_PREFIX . "forum_cat where id = '$id'";
  775. $q = "DELETE from " . TB_PREFIX . "forum_topic where cat = '$id'";
  776. mysql_query($qs, $this->connection);
  777. return mysql_query($q, $this->connection);
  778. }
  779. function DeleteTopic($id) {
  780. $qs = "DELETE from " . TB_PREFIX . "forum_topic where id = '$id'";
  781. // $q = "DELETE from ".TB_PREFIX."forum_post where topic = '$id'";//
  782. return mysql_query($qs, $this->connection); //
  783. // mysql_query($q,$this->connection);
  784. }
  785. function DeletePost($id) {
  786. $q = "DELETE from " . TB_PREFIX . "forum_post where id = '$id'";
  787. return mysql_query($q, $this->connection);
  788. }
  789. function getAllianceName($id) {
  790. $q = "SELECT tag from " . TB_PREFIX . "alidata where id = $id";
  791. $result = mysql_query($q, $this->connection);
  792. $dbarray = mysql_fetch_array($result);
  793. return $dbarray['tag'];
  794. }
  795. function getAlliancePermission($ref, $field, $mode) {
  796. if(!$mode) {
  797. $q = "SELECT $field FROM " . TB_PREFIX . "ali_permission where uid = '$ref'";
  798. } else {
  799. $q = "SELECT $field FROM " . TB_PREFIX . "ali_permission where username = '$ref'";
  800. }
  801. $result = mysql_query($q, $this->connection) or die(mysql_error());
  802. $dbarray = mysql_fetch_array($result);
  803. return $dbarray[$field];
  804. }
  805. function getAlliance($id) {
  806. $q = "SELECT * from " . TB_PREFIX . "alidata where id = $id";
  807. $result = mysql_query($q, $this->connection);
  808. return mysql_fetch_assoc($result);
  809. }
  810. function setAlliName($aid, $name, $tag) {
  811. $q = "UPDATE " . TB_PREFIX . "alidata set name = '$name', tag = '$tag' where id = $aid";
  812. return mysql_query($q, $this->connection);
  813. }
  814. function isAllianceOwner($id) {
  815. $q = "SELECT * from " . TB_PREFIX . "alidata where leader = '$id'";
  816. $result = mysql_query($q, $this->connection);
  817. if(mysql_num_rows($result)) {
  818. return true;
  819. } else {
  820. return false;
  821. }
  822. }
  823. function aExist($ref, $type) {
  824. $q = "SELECT $type FROM " . TB_PREFIX . "alidata where $type = '$ref'";
  825. $result = mysql_query($q, $this->connection);
  826. if(mysql_num_rows($result)) {
  827. return true;
  828. } else {
  829. return false;
  830. }
  831. }
  832. function modifyPoints($aid, $points, $amt) {
  833. $q = "UPDATE " . TB_PREFIX . "users set $points = $points + $amt where id = $aid";
  834. return mysql_query($q, $this->connection);
  835. }
  836. function modifyPointsAlly($aid, $points, $amt) {
  837. $q = "UPDATE " . TB_PREFIX . "alidata set $points = $points + $amt where id = $aid";
  838. return mysql_query($q, $this->connection);
  839. }
  840. /*****************************************
  841. Function to create an alliance
  842. References:
  843. *****************************************/
  844. function createAlliance($tag, $name, $uid, $max) {
  845. $q = "INSERT into " . TB_PREFIX . "alidata values (0,'$name','$tag',$uid,0,0,0,'','',$max,'','','','','','','','')";
  846. mysql_query($q, $this->connection);
  847. return mysql_insert_id($this->connection);
  848. }
  849. /*****************************************
  850. Function to insert an alliance new
  851. References:
  852. *****************************************/
  853. function insertAlliNotice($aid, $notice) {
  854. $time = time();
  855. $q = "INSERT into " . TB_PREFIX . "ali_log values (0,'$aid','$notice',$time)";
  856. mysql_query($q, $this->connection);
  857. return mysql_insert_id($this->connection);
  858. }
  859. /*****************************************
  860. Function to delete alliance if empty
  861. References:
  862. *****************************************/
  863. function deleteAlliance($aid) {
  864. $result = mysql_query("SELECT * FROM " . TB_PREFIX . "users where alliance = $aid");
  865. $num_rows = mysql_num_rows($result);
  866. if($num_rows == 0) {
  867. $q = "DELETE FROM " . TB_PREFIX . "alidata WHERE id = $aid";
  868. }
  869. mysql_query($q, $this->connection);
  870. return mysql_insert_id($this->connection);
  871. }
  872. /*****************************************
  873. Function to read all alliance news
  874. References:
  875. *****************************************/
  876. function readAlliNotice($aid) {
  877. $q = "SELECT * from " . TB_PREFIX . "ali_log where aid = $aid ORDER BY date DESC";
  878. $result = mysql_query($q, $this->connection);
  879. return $this->mysql_fetch_all($result);
  880. }
  881. /*****************************************
  882. Function to create alliance permissions
  883. References: ID, notice, description
  884. *****************************************/
  885. function createAlliPermissions($uid, $aid, $rank, $opt1, $opt2, $opt3, $opt4, $opt5, $opt6, $opt7, $opt8) {
  886. $q = "INSERT into " . TB_PREFIX . "ali_permission values(0,'$uid','$aid','$rank','$opt1','$opt2','$opt3','$opt4','$opt5','$opt6','$opt7','$opt8')";
  887. mysql_query($q, $this->connection);
  888. return mysql_insert_id($this->connection);
  889. }
  890. /*****************************************
  891. Function to update alliance permissions
  892. References:
  893. *****************************************/
  894. function deleteAlliPermissions($uid) {
  895. $q = "DELETE from " . TB_PREFIX . "ali_permission where uid = '$uid'";
  896. return mysql_query($q, $this->connection);
  897. }
  898. /*****************************************
  899. Function to update alliance permissions
  900. References:
  901. *****************************************/
  902. function updateAlliPermissions($uid, $aid, $rank, $opt1, $opt2, $opt3, $opt4, $opt5, $opt6, $opt7) {
  903. $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";
  904. return mysql_query($q, $this->connection);
  905. }
  906. /*****************************************
  907. Function to read alliance permissions
  908. References: ID, notice, description
  909. *****************************************/
  910. function getAlliPermissions($uid, $aid) {
  911. $q = "SELECT * FROM " . TB_PREFIX . "ali_permission where uid = $uid && alliance = $aid";
  912. $result = mysql_query($q, $this->connection);
  913. return mysql_fetch_assoc($result);
  914. }
  915. /*****************************************
  916. Function to update an alliance description and notice
  917. References: ID, notice, description
  918. *****************************************/
  919. function submitAlliProfile($aid, $notice, $desc) {
  920. $q = "UPDATE " . TB_PREFIX . "alidata SET `notice` = '$notice', `desc` = '$desc' where id = $aid";
  921. return mysql_query($q, $this->connection);
  922. }
  923. function diplomacyInviteAdd($alli1, $alli2, $type) {
  924. $q = "INSERT INTO " . TB_PREFIX . "diplomacy (alli1,alli2,type,accepted) VALUES ($alli1,$alli2," . (int)intval($type) . ",0)";
  925. return mysql_query($q, $this->connection);
  926. }
  927. function diplomacyOwnOffers($session_alliance) {
  928. $q = "SELECT * FROM " . TB_PREFIX . "diplomacy WHERE alli1 = $session_alliance AND accepted = 0";
  929. $result = mysql_query($q, $this->connection);
  930. return $this->mysql_fetch_all($result);
  931. }
  932. function getAllianceID($name) {
  933. $q = "SELECT id FROM " . TB_PREFIX . "alidata WHERE tag ='" . $this->RemoveXSS($name) . "'";
  934. $result = mysql_query($q, $this->connection);
  935. $dbarray = mysql_fetch_array($result);
  936. return $dbarray['id'];
  937. }
  938. function getDiplomacy($aid) {
  939. $q = "SELECT * FROM " . TB_PREFIX . "diplomacy WHERE id = $aid";
  940. $result = mysql_query($q, $this->connection);
  941. return $this->mysql_fetch_all($result);
  942. }
  943. function diplomacyCancelOffer($id) {
  944. $q = "DELETE FROM " . TB_PREFIX . "diplomacy WHERE id = $id";
  945. return mysql_query($q, $this->connection);
  946. }
  947. function diplomacyInviteAccept($id, $session_alliance) {
  948. $q = "UPDATE " . TB_PREFIX . "diplomacy SET accepted = 1 WHERE id = $id AND alli2 = $session_alliance";
  949. return mysql_query($q, $this->connection);
  950. }
  951. function diplomacyInviteDenied($id, $session_alliance) {
  952. $q = "DELETE FROM " . TB_PREFIX . "diplomacy WHERE id = $id AND alli2 = $session_alliance";
  953. return mysql_query($q, $this->connection);
  954. }
  955. function diplomacyInviteCheck($session_alliance) {
  956. $q = "SELECT * FROM " . TB_PREFIX . "diplomacy WHERE alli2 = $session_alliance AND accepted = 0";
  957. $result = mysql_query($q, $this->connection);
  958. return $this->mysql_fetch_all($result);
  959. }
  960. function diplomacyExistingRelationships($session_alliance) {
  961. $q = "SELECT * FROM " . TB_PREFIX . "diplomacy WHERE alli2 = $session_alliance AND accepted = 1";
  962. $result = mysql_query($q, $this->connection);
  963. return $this->mysql_fetch_all($result);
  964. }
  965. function diplomacyExistingRelationships2($session_alliance) {
  966. $q = "SELECT * FROM " . TB_PREFIX . "diplomacy WHERE alli1 = $session_alliance AND accepted = 1";
  967. $result = mysql_query($q, $this->connection);
  968. return $this->mysql_fetch_all($result);
  969. }
  970. function diplomacyCancelExistingRelationship($id, $session_alliance) {
  971. $q = "DELETE FROM " . TB_PREFIX . "diplomacy WHERE id = $id AND alli2 = $session_alliance";
  972. return mysql_query($q, $this->connection);
  973. }
  974. function getUserAlliance($id) {
  975. $q = "SELECT " . TB_PREFIX . "alidata.tag from " . TB_PREFIX . "users join " . TB_PREFIX . "alidata where " . TB_PREFIX . "users.alliance = " . TB_PREFIX . "alidata.id and " . TB_PREFIX . "users.id = $id";
  976. $result = mysql_query($q, $this->connection);
  977. $dbarray = mysql_fetch_array($result);
  978. if($dbarray['tag'] == "") {
  979. return "-";
  980. } else {
  981. return $dbarray['tag'];
  982. }
  983. }
  984. function modifyResource($vid, $wood, $clay, $iron, $crop, $mode) {
  985. if(!$mode) {
  986. $q = "UPDATE " . TB_PREFIX . "vdata set wood = wood - $wood, clay = clay - $clay, iron = iron - $iron, crop = crop - $crop where wref = $vid";
  987. } else {
  988. $q = "UPDATE " . TB_PREFIX . "vdata set wood = wood + $wood, clay = clay + $clay, iron = iron + $iron, crop = crop + $crop where wref = $vid";
  989. }
  990. return mysql_query($q, $this->connection);
  991. }
  992. function modifyOasisResource($vid, $wood, $clay, $iron, $crop, $mode) {
  993. if(!$mode) {
  994. $q = "UPDATE " . TB_PREFIX . "odata set wood = wood - $wood, clay = clay - $clay, iron = iron - $iron, crop = crop - $crop where wref = $vid";
  995. } else {
  996. $q = "UPDATE " . TB_PREFIX . "odata set wood = wood + $wood, clay = clay + $clay, iron = iron + $iron, crop = crop + $crop where wref = $vid";
  997. }
  998. return mysql_query($q, $this->connection);
  999. }
  1000. function getFieldLevel($vid, $field) {
  1001. $q = "SELECT f" . $field . " from " . TB_PREFIX . "fdata where vref = $vid";
  1002. $result = mysql_query($q, $this->connection);
  1003. return mysql_result($result, 0);
  1004. }
  1005. function getFieldType($vid, $field) {
  1006. $q = "SELECT f" . $field . "t from " . TB_PREFIX . "fdata where vref = $vid";
  1007. $result = mysql_query($q, $this->connection);
  1008. return mysql_result($result, 0);
  1009. }
  1010. function getVSumField($uid, $field) {
  1011. $q = "SELECT sum(" . $field . ") FROM " . TB_PREFIX . "vdata where owner = $uid";
  1012. $result = mysql_query($q, $this->connection);
  1013. $row = mysql_fetch_row($result);
  1014. return $row[0];
  1015. }
  1016. function updateVillage($vid) {
  1017. $time = time();
  1018. $q = "UPDATE " . TB_PREFIX . "vdata set lastupdate = $time where wref = $vid";
  1019. return mysql_query($q, $this->connection);
  1020. }
  1021. function updateOasis($vid) {
  1022. $time = time();
  1023. $q = "UPDATE " . TB_PREFIX . "odata set lastupdated = $time where wref = $vid";
  1024. return mysql_query($q, $this->connection);
  1025. }
  1026. function setVillageName($vid, $name) {
  1027. $q = "UPDATE " . TB_PREFIX . "vdata set name = '$name' where wref = $vid";
  1028. return mysql_query($q, $this->connection);
  1029. }

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