PageRenderTime 30ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/ext_scripts/lgsl/lgsl_files/lgsl_feed.php

http://lansuite.googlecode.com/
PHP | 162 lines | 94 code | 41 blank | 27 comment | 34 complexity | 879fb8cc60ede8050e6dd6ce2f254c8b MD5 | raw file
Possible License(s): LGPL-3.0, AGPL-1.0, LGPL-2.1
  1. <?php
  2. /*----------------------------------------------------------------------------------------------------------\
  3. | |
  4. | [ LIVE GAME SERVER LIST ] [ Š RICHARD PERRY FROM GREYCUBE.COM ] |
  5. | |
  6. | Released under the terms and conditions of the GNU General Public License Version 3 (http://gnu.org) |
  7. | |
  8. \-----------------------------------------------------------------------------------------------------------*/
  9. //------------------------------------------------------------------------------------------------------------+
  10. require "lgsl_class.php";
  11. //------------------------------------------------------------------------------------------------------------+
  12. $type = isset($_GET['type']) ? lgsl_string_html($_GET['type']) : "";
  13. $ip = isset($_GET['ip']) ? lgsl_string_html($_GET['ip']) : "";
  14. $c_port = isset($_GET['c_port']) ? intval($_GET['c_port']) : 0;
  15. $q_port = isset($_GET['q_port']) ? intval($_GET['q_port']) : 0;
  16. $s_port = isset($_GET['s_port']) ? intval($_GET['s_port']) : 0;
  17. $request = isset($_GET['request']) ? lgsl_string_html($_GET['request']) : "";
  18. $version = isset($_GET['version']) ? lgsl_string_html($_GET['version']) : "";
  19. $xml = isset($_GET['xml']) ? intval($_GET['xml']) : 0;
  20. $format = isset($_GET['format']) ? intval($_GET['format']) : 0;
  21. //------------------------------------------------------------------------------------------------------------+
  22. // VALIDATE REQUEST
  23. if (!$type || !$ip || !$c_port || !$q_port || !$request)
  24. {
  25. exit("LGSL FEED PROBLEM: INCOMPLETE REQUEST");
  26. }
  27. if ($q_port > 99999 || $q_port < 1024)
  28. {
  29. exit("LGSL FEED PROBLEM: INVALID QUERY PORT: '{$q_port}'");
  30. }
  31. if (preg_match("/[^0-9a-z\.\-\[\]\:]/i", $ip))
  32. {
  33. exit("LGSL FEED PROBLEM: INVALID IP OR HOSTNAME: '{$ip}'");
  34. }
  35. if (preg_match("/[^a-z]/", $request))
  36. {
  37. exit("LGSL FEED PROBLEM: INVALID REQUEST: '{$request}'");
  38. }
  39. if ($type == "test")
  40. {
  41. exit("LGSL FEED PROBLEM: TYPE 'test' IS NOT ALLOWED");
  42. }
  43. $lgsl_protocol_list = lgsl_protocol_list();
  44. if (!isset($lgsl_protocol_list[$type]))
  45. {
  46. exit("LGSL FEED PROBLEM: ".($type ? "UNKNOWN TYPE '{$type}'" : "MISSING TYPE")." FOR {$ip} : {$c_port} : {$q_port} : {$s_port}");
  47. }
  48. //------------------------------------------------------------------------------------------------------------+
  49. // FILTER HOSTNAME AND IP FORMATS THAT PHP ACCEPTS BUT ARE NOT WANTED
  50. if (preg_match("/(\[[0-9a-z\:]+\])/iU", $ip, $match)) { $ip = $match[1]; }
  51. elseif (preg_match("/([0-9a-z\.\-]+)/i", $ip, $match)) { $ip = $match[1]; }
  52. //------------------------------------------------------------------------------------------------------------+
  53. // CHECK PUBLIC FEED SETTING AND EITHER ADD [a] REQUEST OR ENSURE [a] IS REMOVED
  54. $request = $lgsl_config['public_feed'] ? $request."a" : str_replace("a", "", $request);
  55. //------------------------------------------------------------------------------------------------------------+
  56. // QUERY SERVER
  57. $server = lgsl_query_cached($type, $ip, $c_port, $q_port, $s_port, $request);
  58. //------------------------------------------------------------------------------------------------------------+
  59. // ADD THE FEED PROVIDER
  60. if ($server['e']) { $server['e']['_feed_'] = "http://{$_SERVER['HTTP_HOST']}"; }
  61. //------------------------------------------------------------------------------------------------------------+
  62. // FEED USAGE LOGGING - 'logs' FOLDER MUST BE MANUALLY CREATED AND SET AS WRITABLE
  63. if (is_dir("logs") && is_writable("logs"))
  64. {
  65. // $file_path = "logs/log_feed.html";
  66. $file_path = "logs/log_feed_{$_SERVER['REMOTE_ADDR']}.html";
  67. if (filesize($file_path) > 1234567) { unlink($file_path); }
  68. $file_handle = fopen($file_path, "a");
  69. $file_string = "
  70. [ ".date("Y/m/d H:i:s")." ] {$type}:{$ip}:{$c_port}:{$q_port}:{$s_port}:{$request}
  71. [ <a href='http://".lgsl_string_html($_SERVER['REMOTE_ADDR']) ."'>".lgsl_string_html($_SERVER['REMOTE_ADDR']) ."</a> ]
  72. [ <a href='" .lgsl_string_html($_SERVER['HTTP_REFERER'])."'>".lgsl_string_html($_SERVER['HTTP_REFERER'])."</a> ]
  73. ".($version ? " [ {$version} ] " : "")."
  74. ".($xml ? " [ XML ] " : "")."
  75. <br />";
  76. fwrite($file_handle, $file_string);
  77. fclose($file_handle);
  78. }
  79. //------------------------------------------------------------------------------------------------------------+
  80. // SERIALIZED OUTPUT
  81. if (!$xml)
  82. {
  83. if ($format == 0) { exit("_SLGSLF_".serialize($server)."_SLGSLF_"); } // LEGACY SYSTEM ( 5.6 AND OLDER )
  84. if (($format == 3 || $format == 4) && function_exists("json_encode"))
  85. {
  86. if ($format == 4 && function_exists("gzcompress")) { exit("_F4_".base64_encode(gzcompress(json_encode($server)))."_F4_"); }
  87. else { exit("_F3_".base64_encode( json_encode($server)). "_F3_"); }
  88. }
  89. else
  90. {
  91. if ($format == 2 && function_exists("gzcompress")) { exit("_F2_".base64_encode(gzcompress(serialize($server)))."_F2_"); }
  92. else { exit("_F1_".base64_encode( serialize($server)). "_F1_"); }
  93. }
  94. }
  95. //------------------------------------------------------------------------------------------------------------+
  96. // XML OUTPUT
  97. header("content-type: text/xml");
  98. echo "<?xml version='1.0' encoding='UTF-8' ?>\r\n<server>\r\n";
  99. foreach ($server as $a => $b)
  100. {
  101. echo "<".lgsl_string_html($a, TRUE).">";
  102. foreach ($b as $c => $d)
  103. {
  104. if (is_array($d))
  105. {
  106. echo "<player>\r\n";
  107. foreach ($d as $e => $f)
  108. {
  109. echo "<".lgsl_string_html($e, TRUE).">".lgsl_string_html($f, TRUE)."</".lgsl_string_html($e, TRUE).">\r\n";
  110. }
  111. echo "</player>\r\n";
  112. }
  113. else
  114. {
  115. echo "<".lgsl_string_html($c, TRUE).">".lgsl_string_html($d, TRUE)."</".lgsl_string_html($c, TRUE).">\r\n";
  116. }
  117. }
  118. echo "</".lgsl_string_html($a, TRUE).">\r\n";
  119. }
  120. echo "</server>\r\n";
  121. //------------------------------------------------------------------------------------------------------------+