hxp
2025-06-04 f4a514d5ac952110da846636ecbb9de951eaf3d2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
<?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>
        &nbsp;&nbsp;<input type="button" value="<?php echo \Lang\gettext("添加服务器ID条件"); ?>" onclick="AddServerIDCondition('', '', '')" />
        &nbsp;&nbsp;<input type="button" value="<?php echo \Lang\gettext("重置条件"); ?>" onclick="ResetCondition()" />
        &nbsp;&nbsp;<input type="submit" name="submitsearch" value="<?php echo \Lang\gettext("搜索"); ?>" class="button green medium" />
        &nbsp;&nbsp; | &nbsp;&nbsp;
        <?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>";
        ?>
        &nbsp;&nbsp;<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 ? "&nbsp;&nbsp;" + serverIDCondNum : serverIDCondNum) + " => " +
                "&nbsp;&nbsp;<?php echo \Lang\gettext("等于"); ?>: " + "<input type=\"number\" name=\"ServerIDE" + serverIDCondNum + "\"" +
                " id=\"ServerIDE" + serverIDCondNum + "\" value=\"" + eValue + "\" min=\"0\" style=\"width: 60px\" />" +
                "&nbsp;&nbsp;<?php echo \Lang\gettext("大于等于"); ?>: " + "<input type=\"number\" name=\"ServerIDGTE" + serverIDCondNum + "\"" +
                " id=\"ServerIDGTE" + serverIDCondNum + "\" value=\"" + gteValue + "\" min=\"0\" style=\"width: 60px\" />" +
                "&nbsp;&nbsp;<?php echo \Lang\gettext("小于等于"); ?>: " + "<input type=\"number\" name=\"ServerIDLTE" + serverIDCondNum + "\"" +
                " id=\"ServerIDLTE" + serverIDCondNum + "\" value=\"" + lteValue + "\" min=\"0\" style=\"width: 60px\" />" +
                "&nbsp;&nbsp;<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>