Advertisement
tjone270

aliases.php Quake Alias API (JSON)

Jul 17th, 2016
603
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.91 KB | None | 0 0
  1. <?php
  2.   header("Content-Type: text/plain");
  3.  
  4.   if (isset($_GET["steam_id"])) {
  5.     $steam_id = $_GET["steam_id"];
  6.   } else {
  7.     die(json_encode(array("steam_id" => "PARAMETER NOT SPECIFIED")));
  8.   }
  9.  
  10.   $database = new Redis();
  11.   $database->connect("127.0.0.1", 6379);
  12.   $database->select(0);
  13.  
  14.   if (strlen($steam_id) != 17) {
  15.     die(json_encode(array($steam_id => "PARAMETER INVALID (NOT 17 DIGITS LONG)")));
  16.   } elseif (!ctype_digit($steam_id)) {
  17.     die(json_encode(array($steam_id => "PARAMETER INVALID (NOT OF TYPE INT)")));
  18.   }
  19.  
  20.   try {
  21.     $aliases = $database->lRange("minqlx:players:" . $steam_id, 0, -1);
  22.   } catch (Exception $e) {
  23.     die(json_encode(array($steam_id => "DB ERROR")));
  24.   }
  25.  
  26.   if (empty($aliases)) {
  27.     die(json_encode(array($steam_id => "ABSENT")));
  28.   }
  29.  
  30.   print_r(json_encode(array($steam_id => "PRESENT")) . "\n");
  31.   print_r(json_encode($aliases));
  32.  
  33.   $database->close();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement