换位置

This commit is contained in:
lwt
2026-06-09 14:01:20 +08:00
parent 6d86678e11
commit 0b34f2e3d0
53 changed files with 1762 additions and 603 deletions
+74
View File
@@ -340,6 +340,80 @@ def _argv_to_shell_line(args: List[str]) -> str:
return shlex.join(args)
def rpc_clear_server_on_center_and_login(
center_node: str,
login_node: str,
server_id: Union[int, str],
cookie: str,
erl_path: Optional[str] = None,
timeout: int = 45,
) -> Tuple[int, str, str, str]:
"""Notify center/login nodes to clear a game server.
Returns:
(returncode, stdout, stderr, full_command_line)
"""
clean_center_node = str(center_node or "").strip().strip("'\"")
clean_login_node = str(login_node or "").strip().strip("'\"")
if not clean_center_node:
raise ValueError("center_node is empty")
if not clean_login_node:
raise ValueError("login_node is empty")
try:
sid = int(str(server_id).strip())
except (TypeError, ValueError) as exc:
raise ValueError(f"invalid server_id: {server_id!r}") from exc
cookie_arg = (cookie or "").strip() or "ddxq2-node"
if any(c in cookie_arg for c in " \t\r\n'\""):
raise ValueError("cookie cannot contain whitespace or quotes")
erl = get_erl_cmd(erl_path)
local_ip = get_local_ip()
ping_node = f"clear_{os.getpid()}_{time.time_ns() % 100000000}"
center_atom = _erl_quoted_atom(clean_center_node)
login_atom = _erl_quoted_atom(clean_login_node)
eval_code = (
f"CenterNode = {center_atom}, "
f"LoginNode = {login_atom}, "
f"ServerId = {sid}, "
"CenterResult = rpc:call(CenterNode, center_node_gs_lib, clear_server, [ServerId]), "
"LoginResult = rpc:call(LoginNode, login_server_app, clear_server, [ServerId]), "
"io:format(\"CENTER: ~p~nLOGIN: ~p~n\", [CenterResult, LoginResult]), "
"case {CenterResult, LoginResult} of "
"{{badrpc, _}, _} -> erlang:halt(2, [{flush, true}]); "
"{_, {badrpc, _}} -> erlang:halt(3, [{flush, true}]); "
"_ -> erlang:halt(0, [{flush, true}]) "
"end."
)
args = [
erl,
"-noshell",
"-name", f"{ping_node}@{local_ip}",
"-setcookie", cookie_arg,
"-eval", eval_code,
]
cmd_line = _argv_to_shell_line(args)
try:
_ensure_epmd_daemon(erl_path)
result = subprocess.run(
args,
capture_output=True,
text=True,
encoding="utf-8",
errors="replace",
timeout=timeout,
creationflags=getattr(subprocess, "CREATE_NO_WINDOW", 0) if IS_WINDOWS else 0,
)
return result.returncode, (result.stdout or ""), (result.stderr or ""), cmd_line
except subprocess.TimeoutExpired:
return -1, "", f"RPC timeout after {timeout}s", cmd_line
except Exception as e:
return -1, "", str(e), cmd_line
def rpc_role_gs_trace_network(
server_name: str,
cookie: str,