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

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

  // Query the database and return some results
  $result = mysqli_query($exile_db, "SELECT a.locker, a.score, a.name, p.money, p.damage, p.hunger, p.thirst FROM $schema.player p INNER JOIN $schema.account a ON a.uid = p.account_uid WHERE p.account_uid = '$steamID'");

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

  // Get all of the results, dump them into an array
  $p_array = mysqli_fetch_assoc($result);

  // Time for the territories
  $result = mysqli_query($exile_db,
    "SELECT
      t.owner_uid,
      t.name,
      t.build_rights,
      t.moderators
    FROM
      $schema.territory t
    WHERE
      t.deleted_at IS NULL
      AND
      (t.owner_uid = '$steamID' OR t.build_rights LIKE '%$steamID%' OR t.moderators LIKE '%$steamID%')");

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

  // Array time!
  $t_array = mysqli_fetch_all($result, MYSQLI_ASSOC);

  /*
    Time to replace all the UIDs with names.
    So this is a bit interesting because my PHP coding is so bad. xD
    ArmA arrays are like javascript arrays in format style
    ["UID","UID","UID"]
    However, in order to store them in the database, they must be stored in a TEXT field, which is string.
  */
  foreach($t_array as $k => $v)
  {
    // Get the UID
    $ownerUID = $t_array[$k]["owner_uid"];

    // Replace the UID with the name of the player based in the account table
    $t_array[$k]["owner_uid"] = ["uid" => $ownerUID, "name" => mysqli_fetch_assoc(mysqli_query($exile_db, "SELECT name FROM $schema.account WHERE uid = '$ownerUID'"))['name']];

    // Process these arrays to make it so they can be converted into a PHP array. Basically strip "["UID","UID","UID"]" to "UID,UID,UID,UID"
    $t_array[$k]["build_rights"] = explode(",", str_replace(["[", "]", "\""], "", $t_array[$k]["build_rights"]));
    $t_array[$k]["moderators"] = explode(",", str_replace(["[", "]", "\""], "", $t_array[$k]["moderators"]));

    // Loop through the build_rights array
    for ($i = 0; $i < count($t_array[$k]["build_rights"]); $i++)
    {
      // Get the UID
      $modUID = $t_array[$k]["build_rights"][$i];

      // Get the name and replace
      $t_array[$k]["build_rights"][$i] = ["uid" => $modUID, "name" => mysqli_fetch_assoc(mysqli_query($exile_db, "SELECT name FROM $schema.account WHERE uid = '$modUID'"))['name']];
    }

    // Loop through the moderators/members
    for ($i = 0; $i < count($t_array[$k]["moderators"]); $i++)
    {
      // UID
      $memUID = $t_array[$k]["moderators"][$i];

      // To name
      $t_array[$k]["moderators"][$i] = ["uid" => $memUID, "name" => mysqli_fetch_assoc(mysqli_query($exile_db, "SELECT name FROM $schema.account WHERE uid = '$memUID'"))['name']];
    }
  }

  // Return it!
  echo json_encode(["result" => RESULT_SUCCESS, "return" => ['player' => $p_array, 'territory' => $t_array]]);
?>
All opinions represented herein are my own
- © 2024 - 2026 itsthedevman
- build 4294fb2