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

	// Make sure this is legit request
	if (!array_key_exists($_POST["index"], $SERVERS))
	{
		die(json_encode(["result" => RESULT_FAILED, "return" => INVALID_PERMS]));
	}

	$serverKey = $_POST["index"];
	$tid = $_POST["tid"];
	$puid = $_POST["uid"];
	$option = $_POST["option"];
	$steamID = $steamprofile['steamid'];

	$server = $SERVERS[$serverKey];
	$schema = $server["database_schema"];

	$query = mysqli_query($exile_db, "SELECT id, owner_uid, moderators, build_rights, (SELECT name FROM $schema.account WHERE uid = '$puid') AS pname FROM $schema.territory WHERE id = $tid");

	if (!$query) { die(json_encode(["result" => RESULT_FAILED, "return" => FAILED_QUERY])); }

	$row = mysqli_fetch_assoc($query);

	// Make sure we are the owner
	if ($row["owner_uid"] !== $steamID) { die(json_encode(["result" => RESULT_FAILED, "return" => INVALID_PERMS])); }

	// Make sure we aren't trying to add ourselves
	if ($puid === $steamID) { die(json_encode(["result" => RESULT_FAILED, "return" => PROMOTE_DEMOTE_SELF])); }

	// "1" == add, "0" == remove
	if ($option === "1")
	{
		// Make sure they are in the build_rights
		if (strpos($row["build_rights"], $puid) === false) { die(json_encode(["result" => RESULT_FAILED, "return" => NOT_IN_BUILD_RIGHTS])); }

		// Make sure they aren't in the moderator array
		if (strpos($row["moderators"], $puid) !== false) { die(json_encode(["result" => RESULT_FAILED, "return" => NOT_IN_MODERATORS])); }

		// Get the flag id, we will have to use this in ArmA in order to get the flag object
		$id = $row["id"];

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

		die(json_encode(["result" => RESULT_SUCCESS, "return" => ["name" => $row["pname"], "uid" => $puid]]));
	}
	else
	{
		// Make sure they are in the build_rights
		if (strpos($row["build_rights"], $puid) === false) { die(json_encode(["result" => RESULT_FAILED, "return" => NOT_IN_BUILD_RIGHTS])); }

		// Make sure they are in the moderator array
		if (strpos($row["moderators"], $puid) === false) { die(json_encode(["result" => RESULT_FAILED, "return" => NOT_IN_MODERATORS])); }

		// Get the flag id, we will have to use this in ArmA in order to get the flag object
		$id = $row["id"];

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

		die(json_encode(["result" => RESULT_SUCCESS, "return" => ["name" => $row["pname"], "uid" => $puid]]));
	}

?>
All opinions represented herein are my own
- © 2024 - 2026 itsthedevman
- build 4294fb2