All pastes #76598 Raw Edit

Miscellany

public text v1 · immutable
·published 2006-07-01 21:10 UTC
rendered paste body
<?php

//---------------------------------------------------------------------------
// This file is for general use functions and database calls
// I have used this to help seperate up the code
//---------------------------------------------------------------------------

//**************************************************************************************
//FUNCTION LIST
//authuser()
//getuseruesers($accountname)
//getuserresources($accountname)
//getnetworth($accountname)
//getempire($empire)
//ticksrunning()
//userreadiness($accountname)
//getuserresearch($accountname)
//getuserresearchp($accountname)

function authuser()
{
global $username;

//if no username found then end session and login again
if ( $_SESSION['username'] == '' )
{
 header( 'Location: logout.php' );
 exit;
}
else
{
//pickup username
$username = $_SESSION['username'];
}
}
//picks up the information from the users database using a username
function getuserusers($accountname)
{
global $username,$faction,$id,$empire;
$username = $accountname;
$query = ("SELECT * FROM users WHERE username='$username'");
$result = mysql_query($query);
$fdata = mysql_fetch_array($result);
$faction = $fdata['faction'];
$id = $fdata['id'];
$empire = $fdata['empire'];
}
//picks up the information from the resources database using a username
function getuserresources($accountname)
{
global $roids,$energy,$mineral,$silicon,$crystal,$pop;
$username = $accountname;
$query1 = ("SELECT * FROM resources WHERE username='$username'");
$result1 = mysql_query($query1);
$fdata1 = mysql_fetch_array($result1);
$roids = $fdata1['roids'];
$energy = $fdata1['energy'];
$mineral = $fdata1['mineral'];
$silicon = $fdata1['silicon'];
$crystal = $fdata1['crystal'];
$pop = $fdata1['population'];
}
//picks up the information from the score table using username
function getnetworth($accountname)
{
global $nw;
$username = $accountname;
$query2 = ("SELECT * FROM scores WHERE username='$username'");
$result2 = mysql_query($query2);
$fdata2 = mysql_fetch_array($result2);
$nw = $fdata2['networth'];
$roidnw = $fdata2['roids'];
}
//pick up the information from the empire table using username
function getempire($empire)
{
global $lmsg,$user1,$user2,$user3;
$query3 = ("SELECT * FROM empire WHERE id='$empire'");
$result3 = mysql_query($query3);
$fdata3 = mysql_fetch_array($result3);
$lmsg = $fdata3['lmsg'];
$user1 = $fdata3['user1'];
$user2 = $fdata3['user2'];
$user3 = $fdata3['user3'];
}

function ticksrunning()
{
global $currenttick,$tickrunning,$ticktime;
$query4=mysql_query("SELECT * FROM tick ORDER BY id DESC LIMIT 1");
while($row=mysql_fetch_assoc($query4))
{
$currenttick = $row['tick'];
$tickrunning =$row['active'];
}
if ($currenttick == 1)
{
$ticktime = "Time Frozen";
}
elseif ($tickrunning == 0)
{
$ticktime = "Time Frozen";
}
else
{
$ticktime = $currenttick;
}
}



function userreadiness($accountname)
{
global $fr,$pr,$or;
$username = $accountname;
$query10 = ("SELECT * FROM readiness WHERE username='$username'");
$result10 = mysql_query($query10);
$fdata10 = mysql_fetch_array($result10);
$fr = $fdata10['fr'];
$or = $fdata10['pr'];
$pr = $fdata10['ar'];
}
function getuserresearch($accountname)
{
global $energyr,$milir,$consr,$scansr,$opsr;
$username = $accountname;
//collect data from research db
$query = ("SELECT * FROM research WHERE username='$username'");
$result = mysql_query($query);
$fdata = mysql_fetch_array($result);
//get the values from the array
$energyr =$fdata['energyr'];
$milir = $fdata['milir'];
$consr = $fdata['consr'];
$scansr =$fdata['scansr'];
$opsr =$fdata['opsr'];
}
function getuserresearchp($accountname)
{
global $energyp,$milip,$consp,$scansp,$opsp;
$username = $accountname;
//collect data from research db
$query = ("SELECT * FROM researchp WHERE username='$username'");
$result = mysql_query($query);
$fdata = mysql_fetch_array($result);
//get the values from the array
$energyp =$fdata['energyp'];
$milip = $fdata['milip'];
$consp = $fdata['consp'];
$scansp =$fdata['scansp'];
$opsp =$fdata['opsp'];
}
function buildingscost($pcons)
{
global $solarecost,$solarmcost,$solarscost;
//cost of the solar buildings

$query = ("SELECT * FROM buildings WHERE username='$username'");
$result = mysql_query($query);
$fdata = mysql_fetch_array($result);
//get the values from the array
$total =$fdata['total'];

$solarecost = round((50 / (1 + $pcons / 100) * (1+($total/100-1)^2) );
$solarmcost = round(20 / (1 + $pcons / 100) * (1+($total/100-1)^2) );

$solarscost = round(10 / (1 + $pcons / 100) * (1+($total/100-1)^2) );

//cost of the mineral buildings
global $minecost,$minccost,$minscost;
$minecost = round(20 / (1 + $pcons / 100) * (1+($total/100-1)^2) );

$minccost = round(15 / (1 + $pcons / 100) * (1+($total/100-1)^2) );

$minscost = round(20 / (1 + $pcons / 100) * (1+($total/100-1)^2) );

//cost of the silicon buildings
global $silecost,$silmcost,$silccost;
$silecost = round(20 / (1 + $pcons / 100) * (1+($total/100-1)^2) );

$silmcost = round(30 / (1 + $pcons / 100) * (1+($total/100-1)^2) );

$silccost = round(10 / (1 + $pcons / 100) * (1+($total/100-1)^2) );

//cost of the crystal buildings
global $crystecost,$crystmcost,$crystscost;
$crystecost = round(50 / (1 + $pcons / 100) * (1+($total/100-1)^2) );

$crystmcost = round(20 / (1 + $pcons / 100) * (1+($total/100-1)^2) );

$crystscost = round(20 / (1 + $pcons / 100) * (1+($total/100-1)^2) );

//cost of the research centre buildings
global $rcecost,$rcmcost,$rcscost,$rcccost;
$rcecost = round(30 / (1 + $pcons / 100) * (1+($total/100-1)^2) );

$rcmcost = round(30 / (1 + $pcons / 100) * (1+($total/100-1)^2) );

$rcscost = round(30 / (1 + $pcons / 100) * (1+($total/100-1)^2) );

$rcccost = round(30 / (1 + $pcons / 100) * (1+($total/100-1)^2) );

}

function buildsolars($solars,$username)
{
if ($solars < 1)
{
echo "You must enter a whole number";
}
else
{

$buildfinish = $currenttick + 4;
$sinsert = "INSERT INTO buildtick (username,sc,mp,sr,cp,rc,tick,built) VALUES('$username','$solars','0','0','0','0','$buildfinish','n')";
mysql_query($sinsert) or die(mysql_error());
?>
<link href="css.css" rel="stylesheet" type="text/css" />
<br><? echo "You Started To Build ";
echo $solars;
echo " Solar Collectors";
?>
<br />
<?
}
}

function buildmins($mins,$username)
{
if ($mins < 1)
{
echo "You must enter a whole number";
}
else
{
$buildfinish = $currenttick + 6;
$sinsert = "INSERT INTO buildtick (username,sc,mp,sr,cp,rc,tick,built) VALUES('$username','0','$mins','0','0','0','$buildfinish','n')";
mysql_query($sinsert) or die(mysql_error());
?><br><? echo "You Started To Build ";
echo $mins;
echo " Mineral Plants";
?>
<br />
<?
}}
function buildsils($sils,$username)
{
if ($sils < 1)
{
echo "You must enter a whole number";
}
else
{
$buildfinish = $currenttick + 3;
$sinsert = "INSERT INTO buildtick (username,sc,mp,sr,cp,rc,tick,built) VALUES('$username','0','0','$sils','0','0','$buildfinish','n')";
mysql_query($sinsert) or die(mysql_error());
?><br><? echo "You Started To Build ";
echo $sils;
echo " Silicon Refinements";
?>
<br />
<?
}}

function buildcrysts($crysts,$username)
{
if ($crysts < 1)
{
echo "You must enter a whole number";
}
else
{
$buildfinish = $currenttick + 5;
$sinsert = "INSERT INTO buildtick (username,sc,mp,sr,cp,rc,tick,built) VALUES('$username','0','0','0','$crysts','0','$buildfinish','n')";
mysql_query($sinsert) or die(mysql_error());
?><br><? echo "You Started To Build ";
echo $crysts;
echo " Crystal Laboratorys";
?>
<br />
<?
}}

function buildrcs($rcs,$username)
{
if ($rcs < 1)
{
echo "You must enter a whole number";
}
else
{
$buildfinish = $currenttick + 4;
$sinsert = "INSERT INTO buildtick (username,sc,mp,sr,cp,rc,tick,built) VALUES('$username','0','0','0','0','$rcs','$buildfinish','n')";
mysql_query($sinsert) or die(mysql_error());
?><br><?
echo "You Started To Build ";
echo $rcs;
echo " Research Centres";
?>
<br />
<?
}}	

function getscans($accountname)
{
$username = $accountname;
global $roidscans;
$query10 = ("SELECT * FROM scans WHERE username='$username'");
$result10 = mysql_query($query10);
$fdata10 = mysql_fetch_array($result10);
$roidscans = $fdata10['roidscans'];
$miliscans = $fdata10['miliscans'];
$playerscans = $fdata10['playerscans'];
$enhancers = $fdata10['scanenhancers'];
}

function whatisbfleet($accountname)
{
$username = $accountname;
global $bfighters,$bcruisers,$broiders;
$query10 = ("SELECT * FROM basefleet WHERE username='$username'");
$result10 = mysql_query($query10);
$fdata10 = mysql_fetch_array($result10);
$bcruisers = $fdata10['cruiser'];
$bfighters = $fdata10['fighter'];
$broiders = $fdata10['roider'];
}

function whatisofleet($accountname)
{
$username = $accountname;
global $ofighters,$ocruisers,$oroiders,$odestination,$oeta,$oarrived,$otick;
$query10 = ("SELECT * FROM fleetone WHERE username='$username'");
$result10 = mysql_query($query10);
$fdata10 = mysql_fetch_array($result10);
$ocruisers = $fdata10['cruiser'];
$ofighters = $fdata10['fighter'];
$oroiders = $fdata10['roider'];
$odestination = $fdata10['destination'];
$oeta = $fdata10['eta'];
$oarrived = $fdata10['arrived'];
$otick = $fdata10['tick'];
}

function howmanyplayers()
{
$username = $accountname;
global $playermax;
$query10 = ("SELECT * FROM users ORDER BY id Desc LIMIT 1");
$result10 = mysql_query($query10);
$fdata10 = mysql_fetch_array($result10);
$playermax = $fdata10['id'];
}

function minplayers()
{
$username = $accountname;
global $playermin;
$query10 = ("SELECT * FROM users ORDER BY id Asc LIMIT 1");
$result10 = mysql_query($query10);
$fdata10 = mysql_fetch_array($result10);
$playermin = $fdata10['id'];
}
?>