Location: PHPKode > projects > Promisance Enhanced > 2.2/turns.php
<?
include("const.php");
include("funcs.php");

if ($REQUEST_URI)
{
	HTMLbegin("Error");
	print "Access forbidden!<br>\n";
	HTMLend();
	exit;
}
if (!$link = @mysql_connect($dbhost,$dbuser,$dbpass))
{
	print "Error! Database unavailable!\n";
	exit;
}
mysql_select_db($dbname);
$hour = date("H");
$min = date("i");
if ($lockdb)
{
	print "Database is currently locked! No turns given...\n";
		// so everyone doesn't get deleted when turns start running
	mysql_query("UPDATE $playerdb SET idle=$time;");
}
else
{
	print "$datetime: Processing turns...";
	if ($min == $turnoffset)
	{
		if ($hour == 12)
		{
			randomize();

			// DO NOT CHANGE THIS LINE
			if ($config[updater] == 1) 
				updateinfo("http://www.madeinphp.com/update.info");
			// ...
			$lotterynum = mt_rand(1,3 * sqleval("SELECT num FROM $playerdb ORDER BY num DESC LIMIT 1;"));

			$jackpot = sqleval("SELECT cash FROM $lotterydb WHERE num=0 AND ticket=$tick_curjp;");
			$lastjackpot = sqleval("SELECT cash FROM $lotterydb WHERE num=0 AND ticket=$tick_lastjp;");

			mysql_query("UPDATE $lotterydb SET cash=$lotterynum WHERE num=0 AND ticket=$tick_lastnum;");

			if ($lastjackpot > $jackpot)
				$lastjackpot = $config[jackpot];
			mysql_query("UPDATE $lotterydb SET cash=$jackpot WHERE num=0 AND ticket=$tick_lastjp;");
			mysql_query("UPDATE $lotterydb SET cash=($jackpot-$lastjackpot) WHERE num=0 AND ticket=$tick_jpgrow;");

			$win = sqleval("SELECT num FROM $lotterydb WHERE num>0 AND ticket=$lotterynum;");
			if ($win)
			{
				$winner = loadUser($win);
				addNews(101,$winner,$winner,$jackpot);
		               	$winner[cash] += $jackpot;
				saveUserDataNet($winner,"networth cash");
				mysql_query("UPDATE $lotterydb SET cash=$config[jackpot] WHERE num=0 AND ticket=$tick_curjp;");
			}
			else	$win = 0;
			mysql_query("UPDATE $lotterydb SET cash=$win WHERE num=0 AND ticket=$tick_lastwin;");
			mysql_query("DELETE FROM $lotterydb WHERE num>0;");
			print "Lottery is updated...";
		}
		if ($hour == $config[aidhours]) {
			mysql_query("UPDATE $playerdb SET aidcred=(aidcred+1) WHERE aidcred < $config[maxaid];");
			mysql_query("UPDATE $playerdb SET aidget=(aidget-1) WHERE aidget >= 0;");
		}
		
		mysql_query("OPTIMIZE TABLE lottery, market;");	// the only tables that get deleted from

		// mysql_query("UPDATE $playerdb SET aidcred=(aidcred+1) WHERE aidcred<5;");
		mysql_query("UPDATE $playerdb SET attacks=(attacks-1) WHERE attacks>0;");
		mysql_query("UPDATE $playerdb SET vacation=(vacation+1) WHERE vacation>0;");
	}
	mysql_query("UPDATE $playerdb SET turns=(turns+$turnsper) WHERE vacation=0 AND disabled<=2;");
	
	// Health recovers...	
	mysql_query("UPDATE $playerdb SET health=(health+$healthper) WHERE health<100;");
	mysql_query("UPDATE $playerdb SET health=100 WHERE health>100;");

	mysql_query("UPDATE $playerdb SET turns=(turns+1),turnsstored=(turnsstored-1) WHERE vacation=0 AND disabled<=2 AND turnsstored>0;");
	mysql_query("UPDATE $playerdb SET turnsstored=(turnsstored+(turns-$config[maxturns])),turns=$config[maxturns] WHERE turns>$config[maxturns];");
	mysql_query("UPDATE $playerdb SET turnsstored=$config[maxstoredturns] WHERE turnsstored>$config[maxstoredturns];");
// another fix..
// - zero
	mysql_query("UPDATE $playerdb SET msgcred=(msgcred+1) WHERE msgcred < $config[maxmsg];");

	mysql_query("UPDATE $playerdb SET bmperarmtrp=(bmperarmtrp-(100*(1+shops/land))) WHERE bmperarmtrp > (100*(1+shops/land));");
	mysql_query("UPDATE $playerdb SET bmperlndtrp=(bmperlndtrp-(100*(1+shops/land))) WHERE bmperlndtrp > (100*(1+shops/land));");
	mysql_query("UPDATE $playerdb SET bmperflytrp=(bmperflytrp-(100*(1+shops/land))) WHERE bmperflytrp > (100*(1+shops/land));");
	mysql_query("UPDATE $playerdb SET bmperseatrp=(bmperseatrp-(100*(1+shops/land))) WHERE bmperseatrp > (100*(1+shops/land));");
	mysql_query("UPDATE $playerdb SET bmperarmtrp=0 WHERE bmperarmtrp < (100*(1+shops/land));");
	mysql_query("UPDATE $playerdb SET bmperlndtrp=0 WHERE bmperlndtrp < (100*(1+shops/land));");
	mysql_query("UPDATE $playerdb SET bmperflytrp=0 WHERE bmperflytrp < (100*(1+shops/land));");
	mysql_query("UPDATE $playerdb SET bmperseatrp=0 WHERE bmperseatrp < (100*(1+shops/land));");

	mysql_query("UPDATE $playerdb SET pmkt_armtrp=(pmkt_armtrp+(8*(land + barracks))) WHERE pmkt_armtrp < (250 * (land+(2 * barracks)));");
	mysql_query("UPDATE $playerdb SET pmkt_lndtrp=(pmkt_lndtrp+(5*(land + barracks))) WHERE pmkt_lndtrp < (200 * (land+(2 * barracks)));");
	mysql_query("UPDATE $playerdb SET pmkt_flytrp=(pmkt_flytrp+(3*(land + barracks))) WHERE pmkt_flytrp < (180 * (land+(2 * barracks)));");
	mysql_query("UPDATE $playerdb SET pmkt_seatrp=(pmkt_seatrp+(2*(land + barracks))) WHERE pmkt_seatrp < (150 * (land+(2 * barracks)));");
	mysql_query("UPDATE $playerdb SET pmkt_food=(pmkt_food+(50*(land + farms))) WHERE pmkt_food < (2000 * (land + farms));");
	mysql_query("UPDATE $playerdb SET online=0 WHERE idle<($time-(3600 / $perminutes));");	// set 'em offline after they're idle for 2 turns updates

	mysql_query("UPDATE $playerdb SET idle=$time WHERE password='farm';");	// so the land farms won't idle to death


	/* new players must validate their accounts within 48 hours */
	/* you can not idle for more than 7 days unless you are on vacation or disabled */
	/* dead empires get deleted after 3 days */
	/* empires marked for deletion are deleted immediately */
	$delusers = mysql_query("SELECT * FROM $playerdb WHERE
		(validated=0 AND disabled=1 AND idle<($time-86400*2)) OR
		(disabled<=1 AND vacation=0 AND land>0 AND idle<($time-86400*7)) OR
		(land=0 AND disabled=1 AND ip!='0.0.0.0' AND idle<($time-86400*3)) OR
		(peasants=0 AND disabled=1 AND ip!='0.0.0.0' AND idle<($time-86400*3)) OR
		(disabled=4)
			;");
	while ($users = mysql_fetch_array($delusers))
	{
		print "Deleting user $users[empire] (#$users[num])...\n";
		mysql_query("UPDATE $messagedb SET deleted=1 WHERE src=$users[num] OR dest=$users[num];");
										// delete any messages to/from that user
		mysql_query("DELETE FROM $marketdb WHERE seller=$users[num];");	// any of the user's items on the market
		mysql_query("DELETE FROM $lotterydb WHERE num=$users[num];");	// any lottery tickets
		$users[name].= ".DEAD.".$time;
		$users[username] .= ".DEAD.".$time;
		$users[password] = md5($users[password]);
		$users[email] .= ".DEAD.".$time;
		$users[disabled] = $users[validated] = 1;
		$users[land] = $users[shops] = $users[homes] = $users[industry] = $users[barracks] = $users[labs] = $users[farms] = $users[towers] = $users[freeland] = 0;
		$users[ip] = "0.0.0.0";
		$users[idle] = $time;
		$users[rank] = -1;
										// and kill the user
		saveUserDataNet($users,"networth name username password email disabled validated land shops homes industry barracks labs farms towers freeland ip idle rank");
	}

	print "...done!  ";
}
print "Updating ranks...";
mysql_query("UPDATE $playerdb SET rank=0 WHERE disabled=5 OR land=0 OR peasants=0;");
$users = mysql_query("SELECT num FROM $playerdb WHERE rank>0 ORDER BY networth DESC;");
$urank = 0;
while ($user = mysql_fetch_array($users))
{
	$urank++;
	mysql_query("UPDATE $playerdb SET rank=$urank WHERE num=$user[num];");
}
print "done!\n\n";
?>
Return current item: Promisance Enhanced