ref_servermonitor.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. /*
  3. *
  4. * OGP - Open Game Panel
  5. * Copyright (C) 2008 - 2018 The OGP Development Team
  6. *
  7. * http://www.opengamepanel.org/
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. *
  23. */
  24. require_once('modules/gamemanager/home_handling_functions.php');
  25. require_once("modules/config_games/server_config_parser.php");
  26. require_once('includes/lib_remote.php');
  27. function exec_ogp_module()
  28. {
  29. global $db;
  30. $home_id = $_REQUEST['home_id'];
  31. $mod_id = $_REQUEST['mod_id'];
  32. // Is admin ??
  33. $isAdmin = $db->isAdmin( $_SESSION['user_id'] );
  34. if( $isAdmin )
  35. $server_home = $db->getGameHome($home_id);
  36. else
  37. $server_home = $db->getUserGameHome($_SESSION['user_id'],$home_id);
  38. if ( !$server_home )
  39. return;
  40. $port = $_REQUEST['port'];
  41. $ip = $_REQUEST['ip'];
  42. $server_home['ip'] = $ip;
  43. $server_home['port'] = $port;
  44. $stats_players = 0;
  45. $stats_maxplayers = 0;
  46. $server_xml = read_server_config(SERVER_CONFIG_LOCATION."/".$server_home['home_cfg_file']);
  47. $xml_installer = $server_xml->installer;
  48. $mod_name = $server_home['mods'][$mod_id]['mod_name'];
  49. $mod_key = $server_home['mods'][$mod_id]['mod_key'];
  50. if (strtolower($mod_name) == "none")
  51. $mod = $mod_key;
  52. else
  53. $mod = $mod_name;
  54. if ($server_xml->protocol == "gameq")
  55. $query_name = $server_xml->gameq_query_name;
  56. elseif ($server_xml->protocol == "lgsl")
  57. $query_name = $server_xml->lgsl_query_name;
  58. else
  59. $query_name = $mod; // If query name does not exist use mod key instead.
  60. // Check if the screen running the server is running.
  61. if ($server_xml->protocol == "gameq")
  62. {
  63. require('protocol/GameQ/functions.php');
  64. require_once('protocol/GameQ/GameQMonitor.php');
  65. }
  66. else if ($server_xml->protocol == "lgsl")
  67. {
  68. require('protocol/lgsl/functions.php');
  69. require_once('protocol/lgsl/LGSLMonitor.php');
  70. }
  71. else if ($server_xml->protocol == "teamspeak3")
  72. {
  73. require_once('protocol/TeamSpeak3/TS3Monitor.php');
  74. }
  75. else
  76. {
  77. // This is here because some servers are not supported by LGSL/GameQ or
  78. // because we do not have proper support for them yet.
  79. // With properly supported games this should not needed.
  80. // (In a perfect world no one would need an insurance.)
  81. $status = "online";
  82. $map = $status;
  83. $maplocation = get_map_path($query_name,$mod,$map);
  84. @$notifications .= get_lang("query_protocol_not_supported");
  85. }
  86. $map_image_upload = '<br><button class="upload-image" id="'.$home_id.'" data-map="'.$map.'" data-mod_id="'.$mod_id.'" onClick="uploadMapImg(this);" >'. get_lang("upload_map_image") .'</button>';
  87. @$map_icon = "<img class='mapicon' src='$maplocation'/>";
  88. @$currentmap = $map;
  89. //Properties for Specific Status
  90. if($status == "half" || $status == "online")
  91. {
  92. if($status == "online")
  93. {
  94. $onlineT = "<div class='map-icon' >";
  95. $onlineT .= "$map_icon";
  96. if($isAdmin)
  97. $onlineT .= "$map_image_upload";
  98. $onlineT .= "</div>";
  99. $onlineT .= "<div class='server-info' >";
  100. @$onlineT .= get_lang("hostname") .": <marquee class='hostname'>" . htmlentities($name) . "</marquee><br />";
  101. @$onlineT .= get_lang("current_map") . ": " . ((isset($mapRaw) && !empty($mapRaw)) ? htmlentities($mapRaw) : $currentmap);
  102. $onlineT .= "</div>";
  103. }
  104. else if($status == "half")
  105. {
  106. @$notifications .= get_lang("failed_querying_server");
  107. }
  108. $remote_server_id = $server_home['remote_server_id'];
  109. $rserver = $db->getRemoteServerById($remote_server_id);
  110. $remote = new OGPRemoteLibrary($rserver['agent_ip'], $rserver['agent_port'], $rserver['encryption_key'], $rserver['timeout']);
  111. $startup_file_exists = $remote->rfile_exists( "startups/".$ip."-".$port ) === 1;
  112. $SrvCtrl = "<table class='srvctrl'><tr><td style='border:0;text-align:center;background:transparent'><a href='?m=gamemanager&amp;p=restart&amp;home_id=".
  113. $home_id."&amp;mod_id=".$mod_id."&amp;ip=".$ip."&amp;port=".$port.
  114. "'><img src='" . check_theme_image("images/restart.png") . "' width='64' border='0' alt='". get_lang("restart_server") ."' /><br><b>". get_lang("restart_server") .
  115. "</b></a></td><td style='border:0;text-align:center;background:transparent'><a href='?m=gamemanager&amp;p=stop&amp;home_id=".
  116. $home_id."&amp;mod_id=".$mod_id."&amp;ip=".$ip."&amp;port=".$port."'><img src='" . check_theme_image("images/stop.png") . "' width='64' border='0' alt='".
  117. get_lang("stop_server") ."' /><br><b>". get_lang("stop_server") .
  118. "</b></a></td></tr></table>";
  119. }
  120. //Echo them all
  121. echo "<div class='monitor-1'>".@$onlineT.@$halfT.@$offlineT."</div>";
  122. if( $server_xml->protocol != "teamspeak3" OR ($startup_file_exists and $server_xml->protocol == "teamspeak3") )
  123. echo "<div class='monitor-2 bloc'>".@$SrvCtrl."</div>";
  124. if(isset($player_list))
  125. echo "<div class='monitor-3'>".@$player_list."</div>";
  126. if(isset($notifications))
  127. echo "<div class='monitor-3 bloc'>".@$notifications."</div>";
  128. }
  129. ?>