You followed a bad link. Please go back and try again.\n";
// This is the text output array.
// MAKE SURE THE URL VARIABLES ARE WHAT ARE IN THE DATABASE!
// Make sure this is completely accurate!
$buildElements = array(
'command' => 'Command Center',
'star' => 'Star Dock',
'library' => 'Library',
'barracks' => 'Barracks',
);
// Here are the levels that they can go up by.
// Make sure this is completely accurate!
$upgradeLevels = array(
'command' => 2,
'star' => 2,
'library' => 2,
'barracks' => 2,
);
// UPGRADE AMOUNTS!
// This is the required amount of ORE needed to UPGRADE!
// Make sure this is completely accurate!
$oreUpgradeAmounts = array(
'command' => 900,
'star' => 500,
'library' => 750,
'barracks' => 800,
);
// This is the required amount of CREDITS needed to UPGRADE!
// Make sure this is completely accurate!
$creditUpgradeAmounts = array(
'command' => 2500,
'star' => 1000,
'library' => 1250,
'barracks' => 1500,
);
// This is the amount of STATUS POINTS added for UPGRADING!
// Make sure this is completely accurate!
$statusUpgradeAmounts = array(
'command' => 2250,
'star' => 750,
'library' => 1000,
'barracks' => 1250,
);
// BUILD AMOUNTS!
// This is the required amount of ORE needed to BUILD!
// Make sure this is completely accurate!
$oreBuildAmounts = array(
'command' => 1800,
'star' => 1000,
'library' => 1200,
'barracks' => 1400,
);
// This is the required amount of CREDITS needed to BUILD!
// Make sure this is completely accurate!
$creditBuildAmounts = array(
'command' => 2500,
'star' => 1250,
'library' => 1500,
'barracks' => 2000,
);
// This is the amount of STATUS POINTS added for BUILDING!
// Make sure this is completely accurate!
$statusBuildAmounts = array(
'command' => 1500,
'star' => 800,
'library' => 1000,
'barracks' => 1400,
);
// So what we do first is that they actually have an action set
if (isset($_GET['a'])){
$action = $_GET['a'];
// Now what building do they want to upgrade?
if (isset($_GET['u']) && isset($_GET['l'])){
$upgrade = $_GET['u'];
$level = $_GET['l'];
} else if (isset($_GET['s'])){
$structure = $_GET['s'];
}
// So if the action is that they want to upgrade, and the upgraded
// building is set, and the target level is there, then let's do it!
if ($action == "upgrade" && isset($upgrade, $level)){
// Notice the custom action?
upgrade($upgrade, $level);
// So if it's a building... let's do it!
} else if ($action == "build" && isset($structure)){
build($structure);
} else {
$message .= "
Unknown action or incomplete URL. Please go back and try again.
\n";
}
} else {
// Alright, so they didn't have something set right, let's tell them they made a boo boo.
$message .= $error;
}
// So the function is that they want to upgrade.
function upgrade($upgrade, $level)
{
global $message, $content, $upgrade, $level, $buildElements, $oreUpgradeAmounts, $creditUpgradeAmounts, $statusUpgradeAmounts, $upgradeLevels;
// Let's see if the building exsists!
if(isset($buildElements[$_REQUEST['u']])){
$upgradeText = $buildElements[$_REQUEST['u']];
} else {
$message .= "No such building exsists. Please go back and try again
\n";
return(0);
}
// Now we want to get the maximum level for the building in question.
$upgradeLevel = $upgradeLevels[$_REQUEST['u']];
// Now let's get the requred Ore, Credit and Status amounts and dump them into variables!
$oreAmount = $oreUpgradeAmounts[$_REQUEST['u']];
$creditAmount = $creditUpgradeAmounts[$_REQUEST['u']];
$statusAmount = $statusUpgradeAmounts[$_REQUEST['u']];
// Let's get the username from the session data
$username = $_SESSION['user_name'];
// Now we need to send a request to the server to get the user's amounts
$query = mysql_query("SELECT * FROM `user` WHERE `user_name` = '". $username ."'");
if (!$query) {
$message .= "MySQL error:
". mysql_error() ."
\n";
return(0);
}
$result = mysql_fetch_assoc($query);
// So let's make the ammounts into variables
$credits = $result['credits'];
$ore = $result['ore'];
// Now we need to get the structures that are there
$query = mysql_query("SELECT * FROM `structures` WHERE `structure_built_from` ='". $username ."'");
if (!$query) {
$message .= "MySQL error:
". mysql_error() ."
\n";
return(0);
}
$result = mysql_fetch_assoc($query);
// Credit Check
if($credits <= $creditAmount)
{
$message .= "You don't have enough Credits to upgrade your " .$upgradeText. ".
\n";
return(0);
}
// Ore Check
if($ore <= $oreAmount)
{
$message .= "You don't have enough Ore to upgrade your " .$upgradeText. ".
\n";
return(0);
}
// Because only one set of results gets added into a variable, we hope that they've already built it!!
$query = mysql_query("SELECT * FROM `structures` WHERE `structure_built_from` ='". $username ."' && `structure_name` = '".$upgradeText."'");
if (!$query) {
$message .= "MySQL error:
". mysql_error() ."
\n";
return(0);
}
$result = mysql_fetch_assoc($query);
// Now sort the data we got. That there was a name of the unit and what level it is.
$structure_name = $result['structure_name'];
$structure_level = $result['structure_level'];
// Structure Exsistance Check
if($structure_name != $upgradeText)
{
$message .= "You haven't built the " .$upgradeText. " yet!
\n";
return(0);
}
// Structure Level Check
if($structure_level >= $level)
{
$message .= "You've already upgraded your " .$upgradeText. " to level " .$structure_level. ".
\n";
return(0);
}
// Make sure they don't want to go over the level that's allowed!
if ($level > $upgradeLevel){
$message .= "You can't upgrade any higher than level " .$upgradeLevel. " for the " .$upgradeText. "!
\n";
return(0);
}
// Now this is where the magic starts!
mysql_query("UPDATE `user` SET `credits` = `credits` - " .$creditAmount. ", `ore` = `ore` - " .$oreAmount. " WHERE `user_name` = '". $username ."' LIMIT 1");
mysql_query("UPDATE `structures` SET `structure_level` = `structure_level` + 1, `status` = `status` + " .$statusAmount. " WHERE `structure_built_from` = '". $username ."' && `structure_name` = '" .$upgradeText. "' LIMIT 1");
// Let them know it worked.
$message .= "You successfully upgraded your " . $upgradeText . " to level " . $level . "!
\n";
// That's all done, so let's end it here!
return(0);
}
// Ok, they wish to build something.
function build($structure)
{
global $message, $content, $upgrade, $level, $buildElements, $oreBuildAmounts, $creditBuildAmounts, $statusBuildAmounts;
// Let's see if the building exsists!
if(isset($buildElements[$_REQUEST['s']])){
$buildText = $buildElements[$_REQUEST['s']];
} else {
$message .= "No such building exsists. Please go back and try again
\n";
return(0);
}
// Now let's get the requred Ore, Credit and Status amounts and dump them into variables!
$oreAmount = $oreBuildAmounts[$_REQUEST['s']];
$creditAmount = $creditBuildAmounts[$_REQUEST['s']];
$statusAmount = $statusBuildAmounts[$_REQUEST['s']];
// Let's get the username from the session data
$username = $_SESSION['user_name'];
// Now we need to send a request to the server to get the user's amounts
$query = mysql_query("SELECT * FROM `user` WHERE `user_name` = '". $username ."'");
if (!$query) {
$message .= "MySQL error:
". mysql_error() ."
\n";
return(0);
}
$result = mysql_fetch_assoc( $query );
// So let's make the ammounts into variables
$credits = $result['credits'];
$ore = $result['ore'];
$date = date("j/M/Y g:i:s A");
// Credit Check
if($credits <= $creditAmount)
{
$message .= "You don't have enough Credits to build a " .$buildText. ".
\n";
return(0);
}
// Ore Check
if($ore <= $oreAmount)
{
$message .= "You don't have enough Ore to build a " .$buildText. ".
\n";
return(0);
}
// Now we need to get the structures that are there
$query = mysql_query("SELECT * FROM `structures` WHERE `structure_built_from` = '". $username ."' && `structure_name` = '".$buildText."'");
if (!$query) {
$message .= "MySQL error:
". mysql_error() ."
\n";
return(0);
}
$result = mysql_fetch_assoc($query);
// And again, make them into variables
$structure_name = $result['structure_name'];
// Structure Exsistance Check
if($structure_name == $buildText)
{
$message .= "You've already built the " .$buildText. "!
\n";
return(0);
}
// Now this is where the magic starts!
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");
// Let them know it worked.
$message .= "You successfully built a " . $buildText . "!
\n";
// That's all done, so let's end it here!
return(0);
}