die();
}

$sql_getships = "SELECT * FROM $table[ships]";
$rec_getships = mysql_query($sql_getships) or die(mysql_error());

if (!isset($do)) { $act = secureData($_GET['do']); }
if (!isset($do)) { $act = secureData($_POST['do']); }
if ($do == 'move') {
	$amount = secureData($_POST['amount']);
	$ship_id = secureData($_POST['ship_id']);
	$from = secureData($_POST['from']);
	$to = secureData($_POST['to']);

	$error = 0;
	if ($amount > getShipsOnFleet($playerdata[id], $ship_id, $from)) { $error = 1; }
	if ($from == $to) { $error = 2; }

	if ($error == 0) {
		moveShips($playerdata['id'], $ship_id, $amount, $from, $to);
	}

	switch($error) {
		case 0:
			$msg = "Succesfully moved ships.";
			break;
		case 1:
			$msg = "You don't have that amount of ships to move from fleet $from to $to";
			break;
		case 2:
			$msg = "You can't move ships to the same fleet.";
Exemplo n.º 2
0
function moveShips($player_id, $ship_id, $amount, $from, $to) {
	global $table;
	$from_current_amount = getShipsOnFleet($player_id, $ship_id, $from);
	$to_current_amount = getShipsOnFleet($player_id, $ship_id, $to);
	$from_new_amount = $from_current_amount - $amount;
	$to_new_amount = $to_current_amount + $amount;
	$sql_updfleet = "UPDATE $table[fleet] SET `$from` = '$from_new_amount', `$to` = '$to_new_amount' WHERE `player_id` = '$player_id' AND `ship_id` = '$ship_id'";
	mysql_query($sql_updfleet);
}