Guest User

Untitled

a guest
Jul 16th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.69 KB | None | 0 0
  1. <?php
  2.  
  3. // First off, we need to make sure we're connected to the database!
  4. include ('mysql_connect.php');
  5.  
  6. // Let's set an error for the links here.
  7. $error = "<div class=\"error\">You followed a bad link. Please go back and try again.</div>\n";
  8.  
  9. // This is the text output array.
  10. // MAKE SURE THE URL VARIABLES ARE WHAT ARE IN THE DATABASE!
  11. // Make sure this is completely accurate!
  12. $buildElements = array(
  13. 'command' => 'Command Center',
  14. 'star' => 'Star Dock',
  15. 'library' => 'Library',
  16. 'barracks' => 'Barracks',
  17. );
  18.  
  19. // Here are the levels that they can go up by.
  20. // Make sure this is completely accurate!
  21. $upgradeLevels = array(
  22. 'command' => 2,
  23. 'star' => 2,
  24. 'library' => 2,
  25. 'barracks' => 2,
  26. );
  27.  
  28.  
  29. // UPGRADE AMOUNTS!
  30.  
  31. // This is the required amount of ORE needed to UPGRADE!
  32. // Make sure this is completely accurate!
  33. $oreUpgradeAmounts = array(
  34. 'command' => 900,
  35. 'star' => 500,
  36. 'library' => 750,
  37. 'barracks' => 800,
  38. );
  39.  
  40. // This is the required amount of CREDITS needed to UPGRADE!
  41. // Make sure this is completely accurate!
  42. $creditUpgradeAmounts = array(
  43. 'command' => 2500,
  44. 'star' => 1000,
  45. 'library' => 1250,
  46. 'barracks' => 1500,
  47. );
  48.  
  49. // This is the amount of STATUS POINTS added for UPGRADING!
  50. // Make sure this is completely accurate!
  51. $statusUpgradeAmounts = array(
  52. 'command' => 2250,
  53. 'star' => 750,
  54. 'library' => 1000,
  55. 'barracks' => 1250,
  56. );
  57.  
  58.  
  59. // BUILD AMOUNTS!
  60.  
  61. // This is the required amount of ORE needed to BUILD!
  62. // Make sure this is completely accurate!
  63. $oreBuildAmounts = array(
  64. 'command' => 1800,
  65. 'star' => 1000,
  66. 'library' => 1200,
  67. 'barracks' => 1400,
  68. );
  69.  
  70. // This is the required amount of CREDITS needed to BUILD!
  71. // Make sure this is completely accurate!
  72. $creditBuildAmounts = array(
  73. 'command' => 2500,
  74. 'star' => 1250,
  75. 'library' => 1500,
  76. 'barracks' => 2000,
  77. );
  78.  
  79. // This is the amount of STATUS POINTS added for BUILDING!
  80. // Make sure this is completely accurate!
  81. $statusBuildAmounts = array(
  82. 'command' => 1500,
  83. 'star' => 800,
  84. 'library' => 1000,
  85. 'barracks' => 1400,
  86. );
  87.  
  88. // So what we do first is that they actually have an action set
  89. if (isset($_GET['a'])){
  90. $action = $_GET['a'];
  91.  
  92. // Now what building do they want to upgrade?
  93. if (isset($_GET['u']) && isset($_GET['l'])){
  94. $upgrade = $_GET['u'];
  95. $level = $_GET['l'];
  96. } else if (isset($_GET['s'])){
  97. $structure = $_GET['s'];
  98. }
  99.  
  100. // So if the action is that they want to upgrade, and the upgraded
  101. // building is set, and the target level is there, then let's do it!
  102. if ($action == "upgrade" && isset($upgrade, $level)){
  103. // Notice the custom action?
  104. upgrade($upgrade, $level);
  105.  
  106. // So if it's a building... let's do it!
  107. } else if ($action == "build" && isset($structure)){
  108. build($structure);
  109. } else {
  110. $message .= "<div class=\"error\">Unknown action or incomplete URL. Please go back and try again.</div>\n";
  111. }
  112. } else {
  113.  
  114. // Alright, so they didn't have something set right, let's tell them they made a boo boo.
  115. $message .= $error;
  116. }
  117.  
  118. // So the function is that they want to upgrade.
  119. function upgrade($upgrade, $level)
  120. {
  121. global $message, $content, $upgrade, $level, $buildElements, $oreUpgradeAmounts, $creditUpgradeAmounts, $statusUpgradeAmounts, $upgradeLevels;
  122.  
  123. // Let's see if the building exsists!
  124. if(isset($buildElements[$_REQUEST['u']])){
  125. $upgradeText = $buildElements[$_REQUEST['u']];
  126. } else {
  127. $message .= "<div class=\"error\">No such building exsists. Please go back and try again</div>\n";
  128. return(0);
  129. }
  130.  
  131. // Now we want to get the maximum level for the building in question.
  132. $upgradeLevel = $upgradeLevels[$_REQUEST['u']];
  133.  
  134. // Now let's get the requred Ore, Credit and Status amounts and dump them into variables!
  135. $oreAmount = $oreUpgradeAmounts[$_REQUEST['u']];
  136. $creditAmount = $creditUpgradeAmounts[$_REQUEST['u']];
  137. $statusAmount = $statusUpgradeAmounts[$_REQUEST['u']];
  138.  
  139. // Let's get the username from the session data
  140. $username = $_SESSION['user_name'];
  141.  
  142. // Now we need to send a request to the server to get the user's amounts
  143. $query = mysql_query("SELECT * FROM `user` WHERE `user_name` = '". $username ."'");
  144. if (!$query) {
  145. $message .= "<div class=\"error\">MySQL error:<br />". mysql_error() ."</div>\n";
  146. return(0);
  147. }
  148. $result = mysql_fetch_assoc($query);
  149.  
  150. // So let's make the ammounts into variables
  151. $credits = $result['credits'];
  152. $ore = $result['ore'];
  153.  
  154. // Now we need to get the structures that are there
  155. $query = mysql_query("SELECT * FROM `structures` WHERE `structure_built_from` ='". $username ."'");
  156. if (!$query) {
  157. $message .= "<div class=\"error\">MySQL error:<br />". mysql_error() ."</div>\n";
  158. return(0);
  159. }
  160. $result = mysql_fetch_assoc($query);
  161.  
  162. // Credit Check
  163. if($credits <= $creditAmount)
  164. {
  165. $message .= "<div class=\"error\">You don't have enough Credits to upgrade your " .$upgradeText. ".</div>\n";
  166. return(0);
  167. }
  168.  
  169. // Ore Check
  170. if($ore <= $oreAmount)
  171. {
  172. $message .= "<div class=\"error\">You don't have enough Ore to upgrade your " .$upgradeText. ".</div>\n";
  173. return(0);
  174. }
  175.  
  176.  
  177. // Because only one set of results gets added into a variable, we hope that they've already built it!!
  178.  
  179. $query = mysql_query("SELECT * FROM `structures` WHERE `structure_built_from` ='". $username ."' && `structure_name` = '".$upgradeText."'");
  180. if (!$query) {
  181. $message .= "<div class=\"error\">MySQL error:<br />". mysql_error() ."</div>\n";
  182. return(0);
  183. }
  184. $result = mysql_fetch_assoc($query);
  185.  
  186. // Now sort the data we got. That there was a name of the unit and what level it is.
  187. $structure_name = $result['structure_name'];
  188. $structure_level = $result['structure_level'];
  189.  
  190. // Structure Exsistance Check
  191. if($structure_name != $upgradeText)
  192. {
  193. $message .= "<div class=\"error\">You haven't built the " .$upgradeText. " yet!</div>\n";
  194. return(0);
  195. }
  196.  
  197. // Structure Level Check
  198. if($structure_level >= $level)
  199. {
  200. $message .= "<div class=\"error\">You've already upgraded your " .$upgradeText. " to level " .$structure_level. ".</div>\n";
  201. return(0);
  202. }
  203.  
  204. // Make sure they don't want to go over the level that's allowed!
  205. if ($level > $upgradeLevel){
  206. $message .= "<div class=\"error\">You can't upgrade any higher than level " .$upgradeLevel. " for the " .$upgradeText. "!</div>\n";
  207. return(0);
  208. }
  209.  
  210. // Now this is where the magic starts!
  211. mysql_query("UPDATE `user` SET `credits` = `credits` - " .$creditAmount. ", `ore` = `ore` - " .$oreAmount. " WHERE `user_name` = '". $username ."' LIMIT 1");
  212. mysql_query("UPDATE `structures` SET `structure_level` = `structure_level` + 1, `status` = `status` + " .$statusAmount. " WHERE `structure_built_from` = '". $username ."' && `structure_name` = '" .$upgradeText. "' LIMIT 1");
  213.  
  214. // Let them know it worked.
  215. $message .= "<div class=\"confirm\">You successfully upgraded your " . $upgradeText . " to level " . $level . "!</div>\n";
  216.  
  217. // That's all done, so let's end it here!
  218. return(0);
  219. }
  220.  
  221.  
  222. // Ok, they wish to build something.
  223. function build($structure)
  224. {
  225. global $message, $content, $upgrade, $level, $buildElements, $oreBuildAmounts, $creditBuildAmounts, $statusBuildAmounts;
  226.  
  227. // Let's see if the building exsists!
  228. if(isset($buildElements[$_REQUEST['s']])){
  229. $buildText = $buildElements[$_REQUEST['s']];
  230. } else {
  231. $message .= "<div class=\"error\">No such building exsists. Please go back and try again</div>\n";
  232. return(0);
  233. }
  234.  
  235. // Now let's get the requred Ore, Credit and Status amounts and dump them into variables!
  236. $oreAmount = $oreBuildAmounts[$_REQUEST['s']];
  237. $creditAmount = $creditBuildAmounts[$_REQUEST['s']];
  238. $statusAmount = $statusBuildAmounts[$_REQUEST['s']];
  239.  
  240. // Let's get the username from the session data
  241. $username = $_SESSION['user_name'];
  242.  
  243. // Now we need to send a request to the server to get the user's amounts
  244. $query = mysql_query("SELECT * FROM `user` WHERE `user_name` = '". $username ."'");
  245. if (!$query) {
  246. $message .= "<div class=\"error\">MySQL error:<br />". mysql_error() ."</div>\n";
  247. return(0);
  248. }
  249. $result = mysql_fetch_assoc( $query );
  250.  
  251. // So let's make the ammounts into variables
  252. $credits = $result['credits'];
  253. $ore = $result['ore'];
  254. $date = date("j/M/Y g:i:s A");
  255.  
  256.  
  257. // Credit Check
  258. if($credits <= $creditAmount)
  259. {
  260. $message .= "<div class=\"error\">You don't have enough Credits to build a " .$buildText. ".</div>\n";
  261. return(0);
  262. }
  263.  
  264. // Ore Check
  265. if($ore <= $oreAmount)
  266. {
  267. $message .= "<div class=\"error\">You don't have enough Ore to build a " .$buildText. ".</div>\n";
  268. return(0);
  269. }
  270.  
  271. // Now we need to get the structures that are there
  272. $query = mysql_query("SELECT * FROM `structures` WHERE `structure_built_from` = '". $username ."' && `structure_name` = '".$buildText."'");
  273. if (!$query) {
  274. $message .= "<div class=\"error\">MySQL error:<br />". mysql_error() ."</div>\n";
  275. return(0);
  276. }
  277. $result = mysql_fetch_assoc($query);
  278.  
  279. // And again, make them into variables
  280. $structure_name = $result['structure_name'];
  281.  
  282. // Structure Exsistance Check
  283. if($structure_name == $buildText)
  284. {
  285. $message .= "<div class=\"error\">You've already built the " .$buildText. "!</div>\n";
  286. return(0);
  287. }
  288.  
  289. // Now this is where the magic starts!
  290. mysql_query("INSERT INTO `structures` (`structure_name`, `structure_level`, `structure_built_from`, `date`, `status`) VALUES ( '".$buildText."', '1', '".$username."', '".$date."', '".$statusAmount."')") && mysql_query("UPDATE `user` SET `credits` = `credits` - ".$creditAmount.", `ore` = `ore` - ".$oreAmount." WHERE `user_name` = '".$username."' LIMIT 1");
  291.  
  292. // Let them know it worked.
  293. $message .= "<div class=\"confirm\">You successfully built a " . $buildText . "!</div>\n";
  294.  
  295. // That's all done, so let's end it here!
  296. return(0);
  297. }
Add Comment
Please, Sign In to add comment