<?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'];
$esm = mysqli_fetch_assoc(mysqli_query($esm_db, "SELECT territory_life_time, price_per_object FROM servers WHERE server_key = '$serverKey'"));
$ttl = $esm["territory_life_time"];
$ppo = $esm["price_per_object"];
$query = mysqli_fetch_assoc(mysqli_query($exile_db, "
SELECT
DATE_ADD(last_paid_at, INTERVAL $ttl DAY) AS current_due_date,
DATE_ADD(NOW(), INTERVAL $ttl DAY) AS next_due_date,
(SELECT locker FROM $schema.account WHERE uid = '$steamID') as locker,
(SELECT COUNT(*) FROM $schema.construction WHERE territory_id ='$tid') as current_object_count
FROM
$schema.territory
WHERE
id = '$tid'"));
if ($type === "info")
{
die(json_encode([ "result" => RESULT_SUCCESS,
"return" =>
[
"current_due_date" => $query["current_due_date"],
"current_locker_amount" => $query["locker"],
"current_objects" => $query["current_object_count"],
"next_due_date" => $query["next_due_date"],
"price_per_object" => $ppo
]
]));
}
elseif ($type === "confirm")
{
// Locker check
if (intval($query["locker"]) < (intval($query["current_object_count"]) * intval($ppo)))
{
die(json_encode(["result" => RESULT_FAILED, "return" => POOR_PLAYER]));
}
// Eh, let the arma server handle the rest...
if (!mysqli_query($esm_db, "INSERT INTO requests (recipient_key, function, parameter) VALUES ('$serverKey', 'ExileServerManager_system_territory_payTerritory', '[$tid,$steamID]')"))
{
die(json_encode(["result" => RESULT_FAILED, "return" => FAILED_QUERY]));
}
// Send back just the due date so we can update
die(json_encode(["result" => RESULT_SUCCESS, "return" => ["next_due_date" => $query["next_due_date"]]]));
}
?>