Thursday, June 04, 2026 12:04:14 AM
> upgradeTerritory.php
<?php
	/*
		Bryan
		Exile Server Manager
	*/
	session_start();
	require 'updateServers.php';
	require 'steamauth/userInfo.php';

	// Get some variables
	$serverKey = $_POST["index"];
	$tid = $_POST["tid"];
	$type = $_POST["type"];
	$server = $SERVERS[$serverKey];
	$schema = $server["database_schema"];
	$steamID = $steamprofile['steamid'];

	if ($type === "info")
	{
		$oldT = mysqli_fetch_assoc(mysqli_query($exile_db, "SELECT radius, level, flag_stolen, (SELECT locker FROM $schema.account WHERE uid = '$steamID') AS locker FROM $schema.territory WHERE id = '$tid'"));

		$currentLevel = $oldT["level"];
		$nextLevel = $currentLevel + 1;

		$newT = mysqli_fetch_assoc(mysqli_query($esm_db, "SELECT price, radius, objects, (SELECT objects FROM territory WHERE level = $currentLevel) AS current_max FROM territory WHERE level = $nextLevel"));

		if ($newT["price"] === null)
		{
			die(json_encode(["result" => RESULT_FAILED, "return" => TERRITORY_HIGHEST_LEVEL]));
		}

		if ($oldT["flag_stolen"] === "1")
		{
			die(json_encode(["result" => RESULT_FAILED, "return" => FLAG_STOLEN]));
		}


		die(json_encode(
		[
			"result" => RESULT_SUCCESS,
			"return" =>
			[
				"old_radius" => $oldT["radius"],
				"old_max" => $newT["current_max"],
				"player_money" => $oldT["locker"],
				"new_price" => $newT["price"],
				"new_radius" => $newT["radius"],
				"new_max" => $newT["objects"]
			]
		]));

	}
	elseif ($type === "confirm")
	{
		$query = mysqli_fetch_assoc(mysqli_query($exile_db, "SELECT level, flag_stolen, (SELECT locker FROM $schema.account WHERE uid = '$steamID') AS locker, (SELECT COUNT(*) FROM $schema.construction c WHERE c.territory_id = $tid) AS object_count FROM $schema.territory WHERE id = '$tid'"));

		$level = $query["level"] + 1;

		$newT = mysqli_fetch_assoc(mysqli_query($esm_db, "SELECT price, objects, radius, (SELECT price FROM territory WHERE level = $level + 1) AS next_price FROM territory WHERE level = $level"));

		// Flag stolen
		if ($query["flag_stolen"] === "1")
		{
			die(json_encode(["result" => RESULT_FAILED, "return" => FLAG_STOLEN]));
		}

		$newPrice = $newT["price"];

		// Highest Level (double check)
		if ($newPrice === null)
		{
			die(json_encode(["result" => RESULT_FAILED, "return" => TERRITORY_HIGHEST_LEVEL]));
		}

		$remainingMoney = intval($query["locker"]) - intval($newPrice);

		// Not enough money
		if ($remainingMoney < 0)
		{
			die(json_encode(["result" => RESULT_FAILED, "return" => POOR_PLAYER]));
		}

		// Send the request to the server
		if (!mysqli_query($esm_db, "INSERT INTO requests (recipient_key, function, parameter) VALUES ('$serverKey', 'ExileServerManager_system_territory_upgradeTerritory', '[$tid,$steamID]')"))
		{
		  die(json_encode(["result" => RESULT_FAILED, "return" => FAILED_QUERY]));
		}

		die(json_encode(["result" => RESULT_SUCCESS, "return" =>
		[
			"object_count" => $query["object_count"],
			"max_objects" => $newT["objects"],
			"radius" => $newT["radius"],
			"price" => $newT["next_price"]
		]
		]));
	}
?>
All opinions represented herein are my own
- © 2024 - 2026 itsthedevman
- build 4294fb2