Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Feb 9th, 2010 | Syntax: None | Size: 17.08 KB | Hits: 19 | Expires: Never
Copy text to clipboard
  1. <?php
  2. /*Mod Under Construction
  3. All Rights Reserver
  4. Immortal Thug .inc
  5. Gang Turf Modification
  6. */
  7.     require_once(DIRNAME(__FILE__) . '/globals.php');
  8.  
  9.         $_GET['action'] = isset($_GET['action']) && is_string($_GET['action']) ? strtolower(trim($_GET['action'])) : false;
  10.        $_GET['ID'] = isset($_GET['ID']) && is_numeric($_GET['ID']) ? abs(@intval($_GET['ID'])) : false;
  11.       $_GET['amount'] = isset($_GET['amount']) && is_numeric($_GET['amount']) ? abs(@intval($_GET['amount'])) : false;
  12.          $_POST['turf'] = abs((int) $_POST['turf']);
  13.         $_POST['crew'] = abs((int) $_POST['crew']);
  14.  
  15.     $cityturf = sprintf("SELECT
  16.                           `cityTURF`,`turfPRICE`
  17.                              FROM `cities`
  18.                                WHERE (`cityid` = %u)", $ir['location']);
  19.      $city = $db->query($cityturf);
  20.       $city = $db->fetch_row($city);
  21.  
  22.    $president = sprintf("SELECT
  23.                            `gangPRESIDENT`,`gangVICEPRES`,`gangMONEY`
  24.                                 FROM `gangs`
  25.                                    WHERE (`gangID`=%u)", $ir['gang']);
  26.     $gangstuff = $db->query($president);
  27.    $pres = $db->fetch_row($gangstuff);
  28.  
  29. switch($_GET['action']) {
  30. case "index":index();break;
  31. case 'buyturf': buyturf(); break;
  32. case 'buyturfs': buyturfs(); break;
  33. case 'sellturf': sellturf(); break;
  34. case 'sellturfs': sellturfs(); break;
  35. case 'owned': owned(); break;
  36. case 'turfbattle': turfbattle(); break;
  37. case 'blockfight': blockfight(); break;
  38. case 'blockfights': blockfights(); break;
  39. case 'market': market(); break;
  40. case 'markets': markets(); break;
  41. default:index();break;
  42. }
  43.  
  44.     function index() {
  45.    global $ir,$pres;
  46.  
  47. if($ir['userid'] === $pres['gangPRESIDENT'] || $ir['userid'] === $pres['gangVICEPRES'])
  48. {
  49. echo "<center><strong><h2>Gang Turf Center</h2></strong></center><br />
  50. <br>
  51.   <center><table width='80%' class='table'><tr><th>Turf Management</th><th>Turf Info</th></tr>
  52.   <tr><td><a href='turf.php?action=buyturf'><strong>Purchase Turf</strong></a></td>
  53.       <td><a href='turf.php?action=owned'><strong>Turf Owned</strong></a></td></tr>
  54.   <tr><td><a href='turf.php?action=sellturf'><strong>Sell Turf</strong></a></td>
  55.       <td><a href='turf.php?action=turfbattle'><strong>Turf Battles</strong></a></td></tr>
  56.   <tr><td><a href='turf.php?action=blockfight'><strong>Battle for Turf</strong></a></td>
  57.       <td><a href='pimp.php'><strong>Pimp Turf</strong></a></td></tr>
  58.   <tr><td><a href='turf.php?action=market'><strong>Market Turf</strong></a></td>    
  59. </table></center>";
  60. }
  61.   else
  62. {
  63. echo "<center><strong><h2>Gang Turf Center</h2></strong></center><br />
  64. <br>
  65. <center><table width='40%' class='table'><tr><th>Turf Info</th></tr>
  66. <tr> <td><a href='turf.php?action=owned'><center><strong>Turf Owned</strong></center></a></td></tr>
  67. <tr> <td><a href='turf.php'?action=turfbattle'><strong>Turf Battles</strong></a></td></tr>
  68. </table></center>";
  69. }
  70. }
  71.   function buyturf() {
  72.    global $userid,$city,$pres,$h;
  73.  
  74.      if($userid != $pres['gangPRESIDENT'] && $userid != $pres['gangVICEPRES'])
  75.   {
  76. echo "Only the leader of your gang can purchase or negotiate for turf towards your clicks progress.  Please discuss this with your leaders.<br />
  77.     <a href='turf.php'> Back</a>";
  78.   $h->endpage();
  79.      exit;
  80.   }
  81.       if($c['cityTURF'] === 0)
  82.     {
  83. echo "There is currently no turf up for grabs in this city.  Your only option at this moment is to await further construction in your area, or battle an opposing gang for their turf.<br /><a href='turf.php'><strong>Back</strong>";
  84.     $h->endpage();
  85.   exit;
  86.     }
  87.      else
  88.  {
  89. echo "There is currently ".number_format($city['cityTURF'])." blocks of turf available for you to purchase.<br />
  90.   <br />
  91.     <form action='turf.php?action=buyturfs' method='post'>
  92.       Amount of Turf: <input type='text' name='turf' />
  93.      <input type='submit' />
  94.     </form>";
  95.  }
  96. }
  97.   function buyturfs() {
  98.  global $db,$ir,$city,$h,$pres;
  99.  
  100. $first = sprintf("SELECT
  101.                  `gangID`
  102.                  FROM `turf`
  103.                WHERE (`gangID`=%u)", $ir['gang']);
  104.    $second = $db->query($first);
  105.  if(!$db->num_rows($second))
  106.   {
  107.  $amount = $_POST['turf']*$city['turfPRICE'];
  108.   $tax = 5;
  109.  if($amount > $pres['gangMONEY'])
  110.   {
  111. echo "You currently do not have the funds to make this transaction.<br /><a href='turf.php'><strong>Back</strong></a>";
  112.   $h->endpage();
  113.  exit;
  114. }
  115. echo "You successfully purchased ".number_format($_POST['turf'])." for your gang at the price of ".number_format($amount)."<br />
  116.       <a href='turf.php'><strong>Back</strong></a>";
  117.   $query1 = sprintf("UPDATE `gangs` SET `gangMONEY`=`gangMONEY`-%u WHERE (`gangID` = %d)", $amount, $ir['gang']);
  118.   $query2 = sprintf("UPDATE `cities` SET `cityTURF`=`cityTURF`-%u WHERE (`cityid`=%u)", $_POST['turf'], $ir['location']);
  119.   $query3 = sprintf("INSERT INTO `turf` VALUES('',%u,%u,%d,%u)", $ir['gang'], $_POST['turf'], $ir['location'], $tax);
  120.   $db->query($query1);
  121.   $db->query($query2);
  122.   $db->query($query3);
  123. }
  124. else
  125. {
  126. $amount = $_POST['turf']*$city['turfPRICE'];
  127. $tax = 5;
  128. if($amount > $pres['gangMONEY'])
  129. {
  130. echo "You currently do not have the funds to make this transaction.<br /><a href='turf.php'><strong>Back</strong></a>";
  131. $h->endpage();
  132. exit;
  133. }
  134. echo "You successfully purchased ".number_format($_POST['turf'])." for your gang at the price of ".number_format($amount)."<br />
  135. <a href='turf.php'><strong>Back</strong></a>";
  136.    $query4 = sprintf("UPDATE `gangs` SET `gangMONEY`=`gangMONEY`-%u WHERE (`gangID` = %d)", $amount, $ir['gang']);
  137.    $query5 = sprintf("UPDATE `cities` SET `cityTURF`=`cityTURF`-%u WHERE (`cityid`=%u)", $_POST['turf'], $ir['location']);
  138.    $query6 = sprintf("UPDATE `turf` SET `amount` = `amount`+%u WHERE (`gangID`=%u)", $_POST['turf'], $ir['gang']);
  139.    $db->query($query4);
  140.    $db->query($query5);
  141.    $db->query($query6);
  142. }
  143. }
  144. function sellturf() {
  145.  global $userid,$city,$db,$pres,$h,$ir;
  146.  
  147. $tehgang = $db->query("SELECT t.`amount`,g.`gangID` FROM `turf` t LEFT JOIN `gangs` g ON t.`gangID`=g.`gangID` WHERE g.`gangID`={$ir['gang']}");
  148. if(!$db->num_rows($tehgang))
  149. {
  150. echo "You do not own any turf on this block";
  151. exit;
  152. endpage();
  153. }
  154. $turfy = $db->fetch_row($tehgang);
  155.  
  156. if($userid != $pres['gangPRESIDENT'] && $userid != $pres['gangVICEPRES'])
  157. {
  158. echo "Only the leader or co-leader of your gang can purchase or negotiate for turf towards your clicks progress.  Please discuss this with your leaders.<br />
  159. <a href='turf.php'> Back</a>";
  160. $h->endpage();
  161. exit;
  162. }
  163.  
  164. else
  165. {
  166. echo "There is currently ".number_format($turfy['amount'])." blocks of turf that you own in this city.  You may sell as much or as little as you see fit.  Keep in mind you can only sell turf for the city you are currently in.<br />
  167. <br />
  168. <form action='turf.php?action=sellturfs' method='post'>
  169. Amount of Turf: <input type='text' name='turf' />
  170. <input type='submit' />
  171. </form>";
  172. }
  173. }
  174. function sellturfs() {
  175.    global $db,$ir,$city,$userid,$turf,$h;
  176.  
  177. $tehgang = $db->query("SELECT t.`amount`,g.`gangID` FROM `turf` t LEFT JOIN `gangs` g ON t.`gangID`=g.`gangID` WHERE g.`gangID`={$ir['gang']}");
  178. if(!$db->num_rows($tehgang))
  179. {
  180. echo "You do not own any turf";
  181. $h->endpage();
  182. exit;
  183. }
  184.  
  185. if($_POST['turf'] > $turfy['amount'])
  186. {
  187. echo "You do not have this much turf to sell!<br /><a href='turf.php'><strong>Back</strong></a>";
  188. $h->endpage();
  189. exit;
  190. }
  191. if($_POST['turf'])
  192. {
  193. $amount = $city['turfPRICE']*$_POST['turf'];
  194. $tax = 5;
  195. echo "You successfully sold ".number_format($_POST['turf'])." block(s) back to the community at a price of ".number_format($amount)."<br /><a href='turf.php'><strong>Back</strong></a>";
  196.   $query5 = sprintf("UPDATE `gangs` SET `gangMONEY`=`gangMONEY`+%u WHERE (`gangID` = %d)", $amount, $ir['gang']);
  197.  $query6 = sprintf("UPDATE `cities` SET `cityTURF`=`cityTURF`+%u WHERE (`cityid`=%u)", $_POST['turf'], $ir['location']);
  198.     $query7 = sprintf("UPDATE `turf` SET `amount`=`amount`-%u WHERE `gangID`=%u AND (`city`=%u)", $_POST['turf'], $ir['gang'], $ir['location']);
  199.   $db->query($query5);
  200.  $db->query($query6);
  201.   $db->query($query7);
  202.  }
  203. }
  204.  
  205.  function owned() {
  206. global $ir,$db,$city,$h,$pres;
  207.  
  208. echo "<h2>Turf Owned</h2><br><br>
  209. Here you can see a list of all the turf owned and in which cities.  This will help know which cities you could get killed in, which cities you can get taxxed in and more.<br />
  210.  <a href='turf.php'><strong>Back</strong></a>
  211. <br />
  212.   <hr /><u>Turf Listings</u><br />
  213. <table cellspacing=1 class='table' width='70%'><tr><th>Crew Name</th><th>Turf Owned</th><th>City</th><th>Leader</th></tr>";
  214.  
  215. $gangs2 =  sprintf("SELECT
  216.                    t.`gangID`,t.`amount`,t.`city`,g.`gangID`,g.`gangNAME`,g.`gangPRESIDENT`,m.`username`,c.`cityname`
  217.                    FROM `turf` t
  218.                    LEFT JOIN `gangs` g
  219.                    ON t.`gangID`=g.`gangID`
  220.                    LEFT JOIN `myplayers` m  
  221.                    ON g.`gangPRESIDENT`=m.`userid`
  222.                    LEFT JOIN `cities` c
  223.                    ON c.`cityid`=t.`city`
  224.                    ORDER BY t.`gangID` ASC;");
  225.           $gangs = $db->query($gangs2);
  226.           while($crew=$db->fetch_row($gangs))
  227. {
  228. echo sprintf("<tr><td><a href='gangs.php?action=view&ID=%u'>%s</a></td><td>", $crew['gangID'], $crew['gangNAME']);
  229.  
  230. echo sprintf("%u Blocks</td><td>%s</td>
  231. <td><a href='viewuser.php?u=%u'>%s</a></td></tr>", $crew['amount'], $crew['cityname'], $crew['gangPRESIDENT'], $crew['username']);
  232. }
  233. echo "</table>";
  234.  
  235. }
  236. function turfbattle() {
  237. global $ir,$db,$city,$h,$pres;
  238.  
  239. echo "<h2>Current Battles Over Turf</h2>";
  240. echo "<a href='turf.php'><strong>Back</strong></a><br />
  241.  
  242. <table width=80% cellspacing=1 class='table'>";
  243. $query = "SELECT
  244.                 t.`ID`,t.`attacker`,t.`defender`,g1.`gangNAME`
  245.                  AS `start`, g2.`gangNAME`
  246.                   AS `protect`
  247.                    FROM `turfwars` t  
  248.                     LEFT JOIN `gangs` g1
  249.                      ON t.`attacker`=g1.`gangID`
  250.                       LEFT JOIN `gangs` g2
  251.                        ON t.`defender`=g2.`gangID`
  252.                         WHERE g1.`gangNAME` != ''
  253.                          AND g2.`gangNAME` != ''";
  254.           $query2 = $db->query($query);
  255.  
  256. if($db->num_rows($query2) > 0)
  257. {
  258. while($r=$db->fetch_row($query2))
  259. {
  260. echo "<tr><th>Attacker</th><th><strong>Vs</strong></th><th>Defender</th></tr><tr> <td width=45%><a href='gangs.php?action=view&ID=".$r['attacker']."'><center>".$r['start']."</center></a></td> <td width=10%><center><strong>vs.</strong></center></td> <td width=45%><a href='gangs.php?action=view&ID=".$r['defender']."'><center>".$r['protect']."</center></a></td> </tr>";
  261. }
  262. }
  263. else
  264. {
  265. echo "</table>There are currently no battles over turf at this point in time.";
  266. }
  267. echo "</table>";
  268.  
  269. $h->endpage();
  270. }
  271.  
  272. function blockfight()
  273. {
  274.  global $db,$ir,$h,$userid,$pres;
  275.  
  276.  
  277. if($ir['gang'] = 0)
  278. {
  279. echo "You are not in a gang";
  280. $h->endpage();
  281. exit;
  282. }
  283.  
  284. if($pres['gangPRESIDENT'] != $ir['userid'] AND $pres['gangVICEPRES'] != $ir['userid'])
  285. {
  286. echo "Only the President or Vice President of your crew can declare a turf battle.<br /><a href='turf.php'><strong>Back</strong></a>";
  287. $h->endpage();
  288. exit;
  289. }
  290.  
  291.  
  292. echo "In this section you can select gangs from a drop down list of who currently owns turf.  You can then battle them for their turf.  Currently the first gang to get 500 kills in the battle will have the option to claim the turf.  Be sure once you close in on 500 kills you check back and claim your turf, or the opposing gang can re-claim their turf if they hit 500 kills. <br />
  293. <br />
  294. <form action='turf.php?action=blockfights' method='post'>
  295. Choose who's turf you wish to fight over..<br />
  296. <input type='hidden' name='subm' value='submit' />
  297. Crew: <select name='crew' type='dropdown'>";
  298.     $query1 = sprintf("SELECT
  299.               g.`gangID`,g.`gangNAME`,t.`amount`
  300.                FROM `gangs` g
  301.                 LEFT JOIN `turf` t  
  302.                  ON g.`gangID`=t.`gangID`
  303.                   WHERE g.gangID != %u
  304.                    AND t.`amount` > 0", $ir['gang']);
  305.     $query = $db->query($query1);
  306. while($r=$db->fetch_row($query))
  307. {
  308. echo sprintf("<option value='%u'>%s</option>\n", $r['gangID'], $r['gangNAME']);
  309. }
  310. echo "</select><br />
  311. <input type='submit' value='Declare' /></form>";
  312. }
  313.  
  314. function blockfights() {
  315.  global $db,$ir,$userid,$h;
  316. $select = sprintf("SELECT `attacker`,`defender` FROM `turfwars`");
  317. $base = $db->query($select);
  318. $attackers = $db->fetch_row($base);
  319. if($ir['gang'] === $attackers['attacker'] || $ir['gang'] === $attackers['defender'])
  320. {
  321. echo "Your crew is currently already at war over a block of turf.  You should think twice before even attempting at spreading your army out so thinly.  Finish the first battle then start on gaining more turf.<br /><a href='turf.php'><strong>Back</strong></a>";
  322. $h->endpage();
  323. exit;
  324. }
  325. if(isset($_POST['subm']))
  326. {
  327. $query = sprintf("INSERT INTO `turfwars` VALUES('',%u,%u,0,0)", $ir['gang'], $_POST['crew']);
  328. $db->query($query);
  329.            $gangs = sprintf("SELECT
  330.                             `gangNAME`
  331.                             FROM `gangs`
  332.                                WHERE (`gangID`=%u)", $_POST['crew']);
  333. $tthem = $db->query($gangs);
  334. $them = $db->fetch_row($tthem);
  335. $turf = str_replace("'","''","<a href='gangs.php?action=view&ID={$ir['gang']}'>".strip_tags($turf['gangNAME'])."</a> declared war on <a href='gangs.php?action=view&ID={$_POST['crew']}'>".strip_tags($them['gangNAME'])."</a>");
  336. $insertion = sprintf("INSERT INTO gangevents VALUES('',%u,unix_timestamp(),'%s')", $ir['gang'],'$turf');
  337. $db->query($insertion);
  338. echo "You have declared war!";
  339. }
  340. }
  341. function market()
  342. {
  343. global $ir,$db,$h;
  344.  
  345.  
  346. $thug = sprintf("SELECT t.`ID`,t.`amount`,t.`city`,c.`cityname` FROM `turf` t LEFT JOIN `cities` c ON t.`city`=c.`cityid` WHERE `gangID`=%u ORDER BY `ID` ASC", $ir['gang']);
  347. $thug2 = $db->query($thug);
  348.  
  349. if(!$db->num_rows($thug2))
  350. {
  351. echo 'You do not currently own turf in this city to place on the market.<br /><a href="turf.php"><strong>Back</strong></a>';
  352. $h->endpage();
  353. exit;
  354. }
  355.  
  356. $thug3 = sprintf("SELECT `gangPRESIDENT`,`gangVICEPRES` FROM `gangs` WHERE `gangID`=%u", $ir['gang']);
  357. $thug4 = $db->query($thug3);
  358. $thugs = $db->fetch_row($thug4);
  359. if($thugs['gangPRESIDENT'] != $ir['userid'] || $thugs['gangVICEPRES'] != $ir['userid'])
  360. {
  361. echo 'Only the gang president or gang vicepresident can add Turf to the Market.<br /><a href ="turf.php"><strong>Back</strong></a>';
  362. $h->endpage();
  363. exit;
  364. }
  365.  
  366. echo 'Select a portion of Turf owned from the list below to set for sale on the market. <br />Note**<br />If you are not in the appropriate city in which you own the turf you will not see it nor be able to market it.  You MUST be in the city owned.<br />';
  367. echo '<table width=80% class=table><tr><th>ID</th><th>Amount</th><th>Sell</th></tr>';
  368. while($t=$db->fetch_row($thug2))
  369. {
  370. $market = "<a href='turf.php?action=markets&ID=".$t['ID']."'><strong>Add to Market</strong></a>";
  371.                
  372.                echo '<tr><td>'.$t['cityname'].'</td>
  373.                           <td>'.$t['amount'].'</td>
  374.                           <td>'.$market.'</td></tr>';
  375. }
  376. echo '</table>';
  377.  
  378. }
  379.  
  380. function markets()
  381. {
  382. global $ir,$userid,$db,$h;
  383.  
  384. $mehquery = sprintf("SELECT `gangPRESIDENT`,`gangVICEPRES` FROM `gangs` WHERE `gangID`=%u", $ir['gang']);
  385. $mequery = $db->query($mehquery);
  386. $hello = $db->fetch_row($mequery);
  387.  
  388. if($hello['gangPRESIDENT'] != $ir['userid'] || $hello['gangVICEPRES'] != $ir['userid'])
  389. {
  390. echo "Only the Leaders of your crew can market owned turf.<br /><a href='turf.php'><strong>Back</strong></a>";
  391. $h->endpage();
  392. exit;
  393. }
  394.  
  395. if(empty($_POST['amount']))
  396. {
  397. echo "<form action='turf.php?action=markets&ID=".$_GET['ID']."' method='post'>";
  398. echo "<table class='table' width='50%' style='text-align:center;'>";
  399. echo "<tr>";
  400. echo "<td>Price</td>";
  401. echo "<td><input type='text' name='amount' /></td>";
  402. echo "</tr>";
  403. echo "<tr>";
  404. echo "<td colspan='2'><input type='submit' value='Submit' /></td>";
  405. echo "</tr>";
  406.  
  407. echo "</table>";
  408. echo "</form>";
  409. }
  410.  
  411. else
  412. {
  413.  
  414. $thugquery = sprintf("SELECT
  415.                      `ID`,`amount`
  416.                        FROM `turf`
  417.                          WHERE (`gangID`=%u)
  418.                           AND (`city`=%u)", $ir['gang'], $ir['location']);
  419.      $thug = $db->query($thugquery);
  420.    $tt = $db->fetch_row($thug);
  421.  
  422.     if(!$db->num_rows($thug))
  423.   {
  424.       echo "Why are you here again?<br /><a href='turf.php'><strong>Back</strong></a>";
  425.     $h->endpage();
  426.    exit;
  427.    }
  428.  echo "Turf Added to Market.<br /><a href='turf.php'><strong>Back</strong></a>";
  429.  
  430. if($tt['amount'] > 1)
  431. {
  432. $query5 = sprintf("UPDATE `turf` SET `amount`=`amount`-1 WHERE `gangID`=%u", $ir['gang']);
  433. $query6 = sprintf("INSERT INTO `turfmarket` VALUES('',%u,%u,%u)", $_POST['amount'], $ir['gang'], $ir['location']);
  434. $db->query($query5);
  435. $db->query($query6);
  436. }
  437. else if($tt['amount'] == 1)
  438. {
  439. $query9 = sprintf("DELETE FROM `turf` WHERE `ID`=%u", $_GET['ID']);
  440. $thu = sprintf("INSERT INTO `turfmarket` VALUES('',%u,%u,%u)", $_POST['amount'], $ir['gang'], $ir['location']);
  441. $db->query($query9);
  442. $db->query($thu);
  443. }
  444. }
  445. }
  446. //Crons
  447. //
  448. //$db->query("DELETE FROM turfwars WHERE attackerkills > 500 || defenderkills > 500");
  449. //
  450. ?>