oagenerate.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. /*
  3. * Copyright (C) 2012 Leah Rowe <info@minifree.org>
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the
  7. * "Software"), to deal in the Software without restriction, including
  8. * without limitation the rights to use, copy, modify, merge, publish,
  9. * distribute, sublicense, and/or sell copies of the Software, and to
  10. * permit persons to whom the Software is furnished to do so, subject to
  11. * the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included
  14. * in all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  17. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  18. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  19. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  20. * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  21. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  22. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. */
  24. /*
  25. * This finds all servers in the database, and generates
  26. * links to oadisplay.php using parameters, e.g.
  27. - oadisplay.php?server=x&server=y
  28. * For servers currently listed as offline, it will still generate a link,
  29. * but the anchor text will have Offline in parenthesis.
  30. */
  31. include "oaprotected/common.php";
  32. function getOnline()
  33. {
  34. $output = "";
  35. $sqlServers = inject("SELECT * FROM servers WHERE serverdown = '0'");
  36. $sqlServersNrows = mysql_numrows($sqlServers);
  37. $sqlQStat = inject("SELECT * FROM qstat");
  38. $sqlQStatNrows = mysql_numrows($sqlQStat);
  39. $qstatListURL = array($sqlQStatNrows);
  40. for ($i = 0; $i < $sqlQStatNrows; $i++) {
  41. $qstatListURL[$i] = mysql_result($sqlQStat, $i, "listurl");
  42. }
  43. for ($i = 0; $i < $sqlServersNrows; $i++)
  44. {
  45. $sqlServersIPAddr = mysql_result($sqlServers, $i, "ipaddr");
  46. $sqlServersPortNum = mysql_result($sqlServers, $i, "portnum");
  47. $numplayers = "";
  48. $sv_hostname = "";
  49. for ($j = 0; $j < count($qstatListURL); $j++)
  50. {
  51. $content = curlGetPage($qstatListURL[$j].
  52. (strpos($qstatListURL[$j],"?")!==false?"&":"?")
  53. ."server=$sqlServersIPAddr:$sqlServersPortNum&xml=1");
  54. $qstat = new SimpleXMLElement($content);
  55. // check if server is listed here (if not then it is
  56. // offline, but may be on another master server)
  57. $server_status = $qstat->server[0]['status'];
  58. if ($server_status != "UP") {
  59. continue;
  60. }
  61. $numplayers = $qstat->server[0]->numplayers;
  62. foreach($qstat->server[0]->rules->rule as $rule) {
  63. switch((string) $rule['name']) {
  64. case 'sv_hostname':
  65. $sv_hostname = $rule;
  66. break;
  67. default:
  68. continue;
  69. }
  70. }
  71. }
  72. $output .= "<li class='oachecker_li'>$sv_hostname<br/>Player ".
  73. "Count: $numplayers<br/><a class='oachecker_a' href".
  74. "='?ipaddr=$sqlServersIPAddr&portnum".
  75. "=$sqlServersPortNum'>$sqlServersIPAddr:".
  76. "$sqlServersPortNum</a></li>";
  77. }
  78. $output = "<ul class='oachecker_ul'>$output</ul>";
  79. return $output;
  80. }
  81. function getOffline()
  82. {
  83. $output = "";
  84. $sqlServers = inject("SELECT * FROM servers WHERE serverdown = '1'");
  85. $sqlServersNrows = mysql_numrows($sqlServers);
  86. for ($i = 0; $i < $sqlServersNrows; $i++) {
  87. $sqlServersIPAddr = mysql_result($sqlServers, $i, "ipaddr");
  88. $sqlServersPortNum = mysql_result($sqlServers, $i, "portnum");
  89. $output .= "<li class='oachecker_li'><a class='oachecker_a' h".
  90. "ref='?ipaddr=$sqlServersIPAddr&portnum=".
  91. "$sqlServersPortNum'>$sqlServersIPAddr:".
  92. "$sqlServersPortNum</a></li>";
  93. }
  94. $output = "<ul class='oachecker_ul'>$output</ul>";
  95. return $output;
  96. }
  97. ?>