<?php
|
include_once "/Common/Logging.php";
|
include_once "/Account/User.php";
|
include_once "/db/DBOper.php";
|
include_once "/Common/ServerOPS.php";
|
include_once "/Common/CommFunc.php";
|
include_once "/language/lang.php";
|
include_once "/Account/userlogcomm.php";
|
|
\Logging\CreateLogging("serverops.serverstatemgr.php");
|
|
\Logging\LogInfo("_POST:" . print_r($_POST, true));
|
$alertMsg = "";
|
$Permission = \User\Permission::P_OPSServerStateMgr;
|
$channel = $_SESSION['spid'];
|
$user = new \User\User($_SESSION['UserAccount']);
|
if (!$user->HavePermission($Permission)) {
|
exit;
|
}
|
$UserAccount = $_SESSION['UserAccount'];
|
|
$all = "all";
|
$Statue = \ServerOPS\ServerStatue::Open; // 开放状态固定只针对已开放的
|
$RunningStatus = $all;
|
$Recommend = array_key_exists("Recommend", $_POST) ? $_POST["Recommend"] : $all;
|
|
// 搜索条件组合 {"Channel":"sohagame", "$or":[{"ServerID":{"$gte":1, "$lte":10}}, {"ServerID":{"$gte":80, "$lte":90}}]}
|
$find = array("Channel" => $channel);
|
if ($Statue != $all) {
|
$find["Statue"] = intval($Statue);
|
}
|
if ($RunningStatus != $all) {
|
$find["RunningStatus"] = intval($RunningStatus);
|
}
|
if ($Recommend != $all) {
|
$find["Recommend"] = intval($Recommend);
|
}
|
$serverIDCondArray = array();
|
$serverIDCondIn = array();
|
$serverIDCondFind = array();
|
$serverIDCondNumMax = 20;
|
for ($i = 1; $i < $serverIDCondNumMax + 1; $i++) {
|
if (!array_key_exists("ServerIDGTE" . $i, $_POST)) {
|
continue;
|
}
|
$eValue = intval($_POST["ServerIDE" . $i]);
|
$gteValue = intval($_POST["ServerIDGTE" . $i]);
|
$lteValue = intval($_POST["ServerIDLTE" . $i]);
|
// echo $i, " : ", $gteValue, $lteValue, "<br/>";
|
if ($eValue <= 0 && $gteValue <= 0 && $lteValue <= 0) {
|
continue;
|
}
|
if ($gteValue > 0 && $lteValue > 0 && $gteValue > $lteValue) {
|
continue;
|
}
|
$cond = array();
|
if ($eValue > 0) {
|
array_push($serverIDCondIn, $eValue);
|
}
|
if ($gteValue > 0) {
|
$cond['$gte'] = $gteValue;
|
}
|
if ($lteValue > 0) {
|
$cond['$lte'] = $lteValue;
|
}
|
array_push($serverIDCondArray, array($eValue, $gteValue, $lteValue));
|
array_push($serverIDCondFind, array("ServerID" => $cond));
|
}
|
if (count($serverIDCondIn) > 0) {
|
array_push($serverIDCondFind, array("ServerID" => array('$in' => $serverIDCondIn)));
|
}
|
if (count($serverIDCondFind) > 0) {
|
$find['$or'] = $serverIDCondFind;
|
}
|
\Logging\LogInfo("find:" . json_encode($find));
|
|
$isSearch = true;
|
if (array_key_exists("submitsearch", $_POST)) {
|
}
|
// 设置状态
|
elseif (array_key_exists("updSelect", $_POST) && $_POST["updSelect"] != "") {
|
$set = array();
|
$updSelect = $_POST["updSelect"];
|
if (substr($updSelect, 0, 9) == "Recommend") {
|
$set["Recommend"] = intval(substr($updSelect, 9));
|
}
|
// echo "set: ", json_encode($set), "<br/>";
|
if (count($set) > 0) {
|
if (!\DBOper\Update("GameServers", $find, $set, false, false, true)) {
|
$alertMsg = \Lang\gettext("批量更新服务器失败");
|
\Logging\LogError($alertMsg . " find=" . json_encode($find) . " set=" . json_encode($set));
|
} else {
|
$alertMsg = \Lang\gettext("批量更新服务器成功");
|
\Logging\LogInfo($alertMsg . " find=" . json_encode($find) . " set=" . json_encode($set));
|
\ServerOPS\RefreshServerListIni($channel);
|
$logPost = $_POST;
|
$logPost["serverIDCondArray"] = $serverIDCondArray;
|
AddSuccessLog($channel, $UserAccount, $Permission, $logPost, $set);
|
}
|
echo "<script>alert('" . $alertMsg . "')</script>";
|
}
|
} else {
|
$isSearch = false;
|
}
|
|
$pageLimit = 50; # 默认仅展示最近服务器数
|
if ($isSearch) {
|
$pageLimit = 0; # 搜索的直接显示全部,暂不做分页
|
}
|
|
\DBOper\Find("GameServers", $find, $serverList, null, array("JsonBranch" => 1, "ServerID" => -1), $pageLimit);
|
$totalCount = count($serverList);
|
if (!$isSearch && $totalCount == $pageLimit) {
|
$totalCount = \DBOper\Count("GameServers", $find);
|
}
|
|
// echo "_POST: ", print_r($_POST, true), "<br/>";
|
// echo "find: ", json_encode($find), "<br/>";
|
|
//显示表格字段配置 key-参数名,value-说明
|
$tableArray = array(
|
"ServerID" => array(\Lang\gettext("区服"), "10%", "center"),
|
"ServerName" => array(\Lang\gettext("名称"), "15%", "center"),
|
"StartDate" => array(\Lang\gettext("开服时间"), "15%", "center"),
|
"Statue" => array(\Lang\gettext("开放状态"), "10%", "center"),
|
"RunningStatus" => array(\Lang\gettext("运行状态"), "10%", "center"),
|
"Recommend" => array(\Lang\gettext("推荐"), "10%", "center"),
|
"MainServerID" => array(\Lang\gettext("所属主服"), "10%", "center"),
|
);
|
|
?>
|
|
<html>
|
|
<head>
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
<title><?php echo \Lang\gettext("服务器状态管理"); ?></title>
|
<link rel="stylesheet" type="text/css" href="/css/table.css">
|
<link rel="stylesheet" type="text/css" href="/css/button.css">
|
<link rel="gettext" type="application/x-po" href="../language/<?php echo \Lang\getLang(); ?>/LC_MESSAGES/<?php echo \Lang\getjspodomain(); ?>.po" />
|
</head>
|
|
<body>
|
<center>
|
<p><b><?php echo \Lang\gettext("服务器状态管理"); ?></b></P>
|
</center>
|
|
<form id="serverstatemgr" action="serverstatemgr.php" method="post">
|
<?php echo \Lang\gettext("推荐状态"); ?>:
|
<select name="Recommend" id="Recommend">
|
<?php
|
foreach (array($all => \Lang\gettext("全部"), "1" => \Lang\gettext("是"), "0" => \Lang\gettext("否")) as $key => $value) {
|
echo "<option value=\"" . $key . "\"";
|
if ($Recommend == $key . "") {
|
echo " selected";
|
}
|
echo ">" . $value . "</option>";
|
}
|
?>
|
</select>
|
<input type="button" value="<?php echo \Lang\gettext("添加服务器ID条件"); ?>" onclick="AddServerIDCondition('', '', '')" />
|
<input type="button" value="<?php echo \Lang\gettext("重置条件"); ?>" onclick="ResetCondition()" />
|
<input type="submit" name="submitsearch" value="<?php echo \Lang\gettext("搜索"); ?>" class="button green medium" />
|
|
|
<?php
|
echo "<select name=\"updSelect\" onchange=\"CheckUpdMulti(this)\">";
|
echo "<option value=\"\">" . \Lang\gettext("全部设置为") . "</option>";
|
echo "<optgroup label=\"" . \Lang\gettext("推荐状态") . "\">";
|
foreach (array("1" => \Lang\gettext("是"), "0" => \Lang\gettext("否")) as $key => $value) {
|
echo "<option value=\"Recommend" . $key . "\">" . $value . "</option>";
|
}
|
echo "</optgroup>";
|
echo "</select>";
|
?>
|
<input type="button" value="刷新选服列表" onclick="window.location.href='refreshServerJson.php'" />
|
<div id="ServerIDCondition"></div>
|
<hr />
|
<table width="60%">
|
<?php
|
if ($serverList) {
|
if ($isSearch) {
|
echo "<caption>" . \Lang\gettext("符合条件服务器总数") . ": " . count($serverList) . "</caption>";
|
} else {
|
echo "<caption>" . \Lang\gettext("服务器数") . ": " . count($serverList) . "/" . $totalCount . "</caption>";
|
}
|
echo "<thead><tr>";
|
foreach ($tableArray as $value) {
|
echo "<th width=\"" . $value[1] . "\">" . $value[0] . "</td>";
|
}
|
echo "</tr></thead>";
|
} else {
|
echo \Lang\gettext("无满足条件服务器"), "<br/>";
|
}
|
|
foreach ($serverList as $serverInfo) {
|
echo "<tr class='trc'>";
|
$ServerID = $serverInfo["ServerID"];
|
$ServerName = $serverInfo["ServerName"];
|
foreach ($tableArray as $key => $value) {
|
$tdContent = $serverInfo[$key];
|
if ($key == "ServerID") {
|
$tdContent = "s" . $tdContent;
|
} else if ($key == "Statue") {
|
$statue = $tdContent;
|
$statueName = \ServerOPS\ServerStatue::$StatueName[$statue];
|
if ($statue != \ServerOPS\ServerStatue::Open) {
|
$tdContent = "<font color='red'>" . $statueName . "</font>";
|
} else {
|
$tdContent = $statueName;
|
}
|
} else if ($key == "RunningStatus") {
|
$runningStatus = $tdContent;
|
$runningStatusName = \ServerOPS\ServerRunningStatus::$RunningStatusName[$runningStatus];
|
if ($runningStatus == \ServerOPS\ServerRunningStatus::PreOpen || $runningStatus == \ServerOPS\ServerRunningStatus::Upkeep) {
|
$tdContent = "<font color='red'>" . $runningStatusName . "</font>";
|
} else {
|
$tdContent = $runningStatusName;
|
}
|
} else if ($key == "Recommend") {
|
$tdContent = $tdContent == 1 ? \Lang\gettext("是") : \Lang\gettext("否");
|
} elseif ($key == "JsonBranch") {
|
$tdContent = \ServerOPS\GetCommonServerlistJsonFileName($channel, $tdContent);
|
}
|
echo "<td align='" . $value[2] . "' style=\"display:table-cell; vertical-align:middle\">" . $tdContent . "</td>";
|
}
|
echo "</tr>";
|
}
|
?>
|
</table>
|
</form>
|
|
<script type='text/javascript' src="/js/common.js"></script>
|
<script type="text/javascript">
|
var serverIDCondNum = 0; // 服务器ID条件编号
|
|
window.onload = function() {
|
var serverIDCondList = JSON.parse('<?php echo json_encode($serverIDCondArray); ?>');
|
for (let index = 0; index < serverIDCondList.length; index++) {
|
const cond = serverIDCondList[index];
|
const eValue = cond[0] > 0 ? cond[0] : "";
|
const gteValue = cond[1] > 0 ? cond[1] : "";
|
const lteValue = cond[2] > 0 ? cond[2] : "";
|
AddServerIDCondition(eValue, gteValue, lteValue);
|
}
|
}
|
|
function AddServerIDCondition(eValue, gteValue, lteValue) {
|
var numMax = parseInt("<?php echo $serverIDCondNumMax ?>");
|
if (serverIDCondNum >= numMax) {
|
alert("<?php echo \Lang\gettext("服务器ID条件超过最大个数"); ?>: " + numMax);
|
return;
|
}
|
serverIDCondNum += 1;
|
var serverIDCondition = "<div id=\"ServerIDCond" + serverIDCondNum + "\">" +
|
"<?php echo \Lang\gettext("服务器ID条件"); ?>" + (serverIDCondNum < 10 ? " " + serverIDCondNum : serverIDCondNum) + " => " +
|
" <?php echo \Lang\gettext("等于"); ?>: " + "<input type=\"number\" name=\"ServerIDE" + serverIDCondNum + "\"" +
|
" id=\"ServerIDE" + serverIDCondNum + "\" value=\"" + eValue + "\" min=\"0\" style=\"width: 60px\" />" +
|
" <?php echo \Lang\gettext("大于等于"); ?>: " + "<input type=\"number\" name=\"ServerIDGTE" + serverIDCondNum + "\"" +
|
" id=\"ServerIDGTE" + serverIDCondNum + "\" value=\"" + gteValue + "\" min=\"0\" style=\"width: 60px\" />" +
|
" <?php echo \Lang\gettext("小于等于"); ?>: " + "<input type=\"number\" name=\"ServerIDLTE" + serverIDCondNum + "\"" +
|
" id=\"ServerIDLTE" + serverIDCondNum + "\" value=\"" + lteValue + "\" min=\"0\" style=\"width: 60px\" />" +
|
" <a href=\"javascript:DelServerIDCondition(" + serverIDCondNum + ")\"><?php echo \Lang\gettext("删除"); ?></a>";
|
"</div>";
|
document.getElementById("ServerIDCondition").insertAdjacentHTML("beforeEnd", serverIDCondition);
|
}
|
|
function DelServerIDCondition(delNum) {
|
document.getElementById("ServerIDCondition").removeChild(document.getElementById("ServerIDCond" + delNum));
|
}
|
|
function ResetCondition() {
|
set_select_checked("Recommend", '<?php echo $all; ?>');
|
document.getElementById("ServerIDCondition").innerHTML = "";
|
serverIDCondNum = 0;
|
}
|
|
function set_select_checked(selectId, checkValue) {
|
var select = document.getElementById(selectId);
|
for (var i = 0; i < select.options.length; i++) {
|
if (select.options[i].value == checkValue) {
|
select.options[i].selected = true;
|
break;
|
}
|
}
|
}
|
|
function CheckUpdMulti(obj) {
|
var setStr = "";
|
if (obj.name == "updSelect") {
|
var value = obj.value;
|
if (!value) {
|
return false;
|
}
|
if (value.substr(0, 9) == "Recommend") {
|
setStr = "<?php echo \Lang\gettext("推荐状态"); ?>:" + obj.options[obj.selectedIndex].text;
|
} else {
|
alert("无效设置项!");
|
return false;
|
}
|
} else {
|
alert("未知批量更新操作控件: " + obj.name + " type:" + obj.type);
|
return false;
|
}
|
|
var br = getbr();
|
let gteValue, lteValue;
|
var serverCondStr = "";
|
var numMax = parseInt("<?php echo $serverIDCondNumMax ?>");
|
for (let index = 1; index < numMax + 1; index++) {
|
if (!document.getElementById("ServerIDGTE" + index)) {
|
continue;
|
}
|
eValue = parseInt(document.getElementById("ServerIDE" + index).value);
|
gteValue = parseInt(document.getElementById("ServerIDGTE" + index).value);
|
lteValue = parseInt(document.getElementById("ServerIDLTE" + index).value);
|
eValue = (isNaN(eValue) || eValue < 0) ? 0 : eValue;
|
gteValue = (isNaN(gteValue) || gteValue < 0) ? 0 : gteValue;
|
lteValue = (isNaN(lteValue) || lteValue < 0) ? 0 : lteValue;
|
if (eValue <= 0 && gteValue <= 0 && lteValue <= 0) {
|
continue;
|
}
|
if (gteValue > 0 && lteValue > 0 && gteValue > lteValue) {
|
// alert("服务器ID“大于等于值”不能小于“小于等于值”!");
|
continue;
|
}
|
if (serverCondStr != "") {
|
// serverCondStr += "或";
|
}
|
serverCondStr += "ServerID ";
|
if (eValue > 0) {
|
serverCondStr += eValue;
|
}
|
if (gteValue > 0 || lteValue > 0) {
|
if (eValue > 0) {
|
serverCondStr += " , ";
|
}
|
if (gteValue > 0 && lteValue > 0) {
|
serverCondStr += gteValue + " ~ " + lteValue;
|
} else if (gteValue > 0) {
|
serverCondStr += ">=" + gteValue;
|
} else {
|
serverCondStr += "<=" + lteValue;
|
}
|
}
|
serverCondStr += br;
|
}
|
|
var RecommendSelect = document.getElementById("Recommend");
|
|
var confimStr = ""
|
confimStr += "<?php echo \Lang\gettext("推荐状态"); ?>: " + RecommendSelect.options[RecommendSelect.selectedIndex].text + br;
|
confimStr += serverCondStr;
|
confimStr += br + "<?php echo \Lang\gettext("确定将以上条件服务器设置为"); ?> => " + setStr + "?";
|
|
if (!window.confirm(confimStr)) {
|
return false;
|
}
|
if (obj.type != "submit") {
|
var form = document.getElementById("serverstatemgr");
|
form.submit();
|
}
|
return true;
|
}
|
</script>
|
</body>
|
|
</html>
|