Location: PHPKode > scripts > Socketeer > socketeer/fsControl.php
<?php 
/***************************************************************************
 * Fleetsave control, works on the GET parameters set in request
 * supply PHPSESSID and the object is persistent between requests
 * we're looking for -= create =- and -= action =- and -= cp =-,
 * where action parameter takes either save, save or farm as arguments
 *
 * Adapt host and login informations to your needs
 **************************************************************************/



require_once "socketeer.php"; 
require_once "fields.php"; 
session_start();
 printForm();
if(isset($_GET['unlock'])) $_SESSION['mutex'] = 0;
header("Content-Type: text/html; charset=iso-8859-1");
// ini_set("display_errors", "Off");
// SET CREDENTIALS
$host = 
$name =
$pass =
//$name =
//$pass =
if(isset($_GET['create'] ) && $_GET['create'] == true)
{
	session_unset();
	$conn = new Socketeer($host, $name, $pass);
	$conn->login();
	$_SESSION['relogin'] = 0;
	$_SESSION['failed_farms'] = 0;
	$_SESSION['id'] = $conn->sessionid;
	echo "Logged in and Socketeer created! \n";

} else {
	$fp=fopen("dumps/object.dump", "r") or die("Must create new obj");
	$serial = null;
	while(!feof($fp))
		$serial.=fread($fp, 4096);
	$conn = unserialize($serial);
	if(!$conn)
		die("Invalid SESSID @".$_SERVER['SERVER_NAME']);
	if($conn->sessionid == "") {
		// FIXME Compare create vs login... hmm
		//header("Location: ".$_SERVER['PHP_SELF']."?action=login"); 
		//echo "Ogame session does not exists, login in!\n";
	}
}
if(isset($_GET['login']) && $_GET['login'] == 'true')
{
	// FIXME Compare create vs login... 
	$conn->resetCookies();
	$conn->login();
	echo "after relogin: cookies are ".$conn->getCookies();
	$_SESSION['relogin'] = 0;
	$_SESSION['id'] = $conn->sessionid;
}
if(isset($_GET['test']) )
{
	$arr = $conn->findSuitable(split(":", $conn->getCoordsByCP($_GET['test'])));
	//	$arr = $conn->findSuitable($conn->getCoordsByCP($conn->attackStar['CP'][0]));
	var_dump($arr);
}
doGet($conn);
/* Allways refresh data */
$conn->overview();
/* SCAN i.e. check for attacks */
if(isset($_GET['action']) && $_GET['action'] == 'scan')
{
//	$conn->outputCoords();
	//	
	for($i = 0; $i < count ($conn->attackStar['CP']); $i++)
	{
		/* Output for CLI script :) */
		$sleep = $conn->attackStar['STAR'][0] - $conn->servertime - 4;
		echo $sleep;
		echo "<meta http-equiv='refresh' content='$sleep;URL=http://localhost/devel/Socketeer/fsControl.php?action=save&cp=".$conn->attackStar['CP'][0]."'>";
	}
	if($_SESSION['forfarm']++ > 5) {
		echo "<meta http-equiv='refresh' content='20;URL=http://localhost/devel/Socketeer/fsControl.php?action=farm'>";
		$_SESSION['forfarm'] = 0;
	} else {
		echo "<meta http-equiv='refresh' content='1090;URL=http://localhost/devel/Socketeer/fsControl.php?action=scan'>";
	}

/* FLEETSAVE, we're evading! */
} else if(isset($_GET['action']) && $_GET['action'] == 'save') {
	if(isset($_GET['cp']) && $_GET['cp'] != "") {
		$conn->attackStar['CP'][0] = $_GET['cp'];
	}
	if($conn->attackStar['CP'][0] == "")
		die("No data to issue fleesave with");
	$conn->fleet1($conn->attackStar['CP'][0]);	// Collect (res, available fleet etc)
	if( $conn->fleet2('save') )				// Create form (speed, maxships etc)
	{
		$conn->fleet3('save'); 			// Issue the form!
		$conn->returning_fleet = $conn->attackStar['CP'][0];
		if($_SESSION['relogin'] >= 3)
		{
			fwrite(fopen("dumps/object.dump", "w"), serialize($conn));
			header("Location: ".$_SERVER['PHP_SELF']."?login=true&action=save");
		}

		sleep(20);
		
		$conn->order_return($conn->returning_fleet);
		echo "Fleet should now return<br>";
	} else {
	/*	if($_SESSION['relogin'] >= 3) {
			fwrite(fopen("dumps/object.dump", "w"), serialize($conn));
			header("Location: ".$_SERVER['PHP_SELF']."?login=true&action=save");
		}
	 */	echo "Nothing but fleet resis and solarsats.. Abandoning mine\n";
	}
		
// RETURN if we've sent out a fleetsave (can only handle one at a time
} else if(isset($_GET['action']) && $_GET['action'] == 'return') {
	if(isset($_GET['cp']) && $_GET['cp'] != "")
		$conn->returning_fleet = $_GET['cp'];
	$conn->order_return($conn->returning_fleet);
	
// FARM loops getFarm if.  fields, and issues attack
} else if(isset($_GET['action']) && $_GET['action'] == 'farm') {
	$slots = 12 - 1;
	foreach($conn->farmPlanets['RETURNS'] as $time)
		if($time - $conn->servertime > 0)
			$slots--;

	for($i = 0; $i < $slots; $i++)
	{
		$conn->overview(); // get current ressources
		$conn->fleet1($conn->getMain(true)); // get fleet, fleet1(CP = main) 
//		$conn->fleet1($conn->getPlanetCPByName('Koloni'));
		if( $conn->fleet2('farm') ) { // set query, hence farm
			if($conn->fleet3('farm') == false ) { // assault the enemy!
				echo "Target: ".join(":" ,$conn->farmCoords)."<br>";
				echo "Got : <br>".$conn->outputContents($conn->content);

				echo "Flaw!!";
				break;
			}
		}
	}
	echo "<meta http-equiv='refresh' content='1390;URL=http://localhost/devel/Socketeer/fsControl.php?action=scan'>";
}

if($_SESSION['relogin'] > 3)
{
	//header("Location: ".$_SERVER['PHP_SELF']."?login=true&action=save");
	//$conn->login();
	//$_SESSION['relogin'] = 0;
	//echo "Logged in @ $host. New Socketeerobject is available! \n";
}
fwrite(fopen("dumps/object.dump", "w"), serialize($conn));
echo "SerializzzzZzZ...\n";


function doGet($obj)
{
	if( isset($_GET['debug']) && $_GET['debug'] == true ) {
		var_dump($obj);
	} 
	if( isset($_GET['setcookie']) && $_GET['setcookie'] == true ) {
		$obj->setCookiesFromFF();
	}
	if( isset($_GET['session']) && $_GET['session'] != "" 
	 && !isset($_GET['create']) ) {
		$obj->sessionid = $_GET['session'];
		$_SESSION['id'] = $_GET['session'];
	} 
	if( isset($_GET['session']) && $_GET['session'] != "" 
	 && isset($_GET['create']) ) {
		if( isset($_GET['setcookie']) )
		{
			$obj->sessionid = $_GET['session'];
			$_SESSION['id'] = $_GET['session'];
		}
	} 
	if( isset($_GET['scanfarm']) && $_GET['scanfarm'] == true ) {
		/* Clear arrays */
		for($i = 0; $i < sizeof($obj->farmPlanets['COORDS']); $i++)
		{
			array_pop($obj->farmPlanets['COORDS']);
			array_pop($obj->farmPlanets['RETURNS']);
			array_pop($obj->farmPlanets['SCANNED']);
		}
		/* Refresh it */
		$obj->scanForFarms(array(1, 259, 8));
	} 
	// elseif( isset($_GET['spioreport']) ) {
	// action = 6, ship210 = 8,
	// on timeout/10 scans - cp/pst messages into galayplugin.xpi
	//} elseif( isset($_GET['']) ) {
}
function printForm()
{

?>
<html>
<body>
<div>
<form>
<hr>
<table align=center border=1 >
<tr>
<td>Action : </td>
<td><select name=action>
	<option id=scan value=scan>Scan for attack</option>
	<option id=farm value=farm>Farm...</option>
	<option id=login value=login>Relogin</option>
	<option id=save value=save>Fleetsave</option>
</select></td>
<td>SessionID:</td>
<td><input type=text size=20 name=session value="<?php if(!isset($_GET['create']) && !isset($_GET['setcookie'])) echo $_SESSION['id']; ?>" /></td>
<td>PlanetCP:</td>
<td><input type=text size=10 name=cp /></td>
</tr></table>
<hr>
<table align=center >
<tr>
<td><input type=checkbox name=scanfarm /></td>
<td><input type=checkbox name=debug /></td>
<td><input type=checkbox name=create /></td>
<td><input type=checkbox name=setcookie /></td>
<td colspan=2><input type=submit value=Refresh /></td>
</tr>
<tr>
<td>Scan for farms</td>
<td>Debug</td>
<td>Create</td>
<td>ffCookie</td>
</tr>
</table>
<hr>
</form></div>
<?php
}
?>
Return current item: Socketeer