mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2026-08-15 13:04:36 +00:00
tools: harden task3 session debug scripts
This commit is contained in:
parent
0519eac4a8
commit
e0752d8d98
3 changed files with 78 additions and 14 deletions
|
|
@ -44,11 +44,47 @@ FILE_INPUT=false
|
||||||
|
|
||||||
while [[ $# -gt 0 ]]; do
|
while [[ $# -gt 0 ]]; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-v|--version) VERSION="$2"; shift 2 ;;
|
-v|--version)
|
||||||
-m|--mode) MODE="$2"; shift 2 ;;
|
if [[ $# -lt 2 ]]; then
|
||||||
-p|--port) PORT="$2"; PORT_SET_BY_USER=true; shift 2 ;;
|
echo "$1 requires a value" >&2
|
||||||
--session) SESSION="$2"; shift 2 ;;
|
exit 1
|
||||||
--username) USERNAME="$2"; shift 2 ;;
|
fi
|
||||||
|
VERSION="$2"
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
-m|--mode)
|
||||||
|
if [[ $# -lt 2 ]]; then
|
||||||
|
echo "$1 requires a value" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
MODE="$2"
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
-p|--port)
|
||||||
|
if [[ $# -lt 2 ]]; then
|
||||||
|
echo "$1 requires a value" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
PORT="$2"
|
||||||
|
PORT_SET_BY_USER=true
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
--session)
|
||||||
|
if [[ $# -lt 2 ]]; then
|
||||||
|
echo "--session requires a value" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
SESSION="$2"
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
--username)
|
||||||
|
if [[ $# -lt 2 ]]; then
|
||||||
|
echo "--username requires a value" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
USERNAME="$2"
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
--no-build) DO_BUILD=false; shift ;;
|
--no-build) DO_BUILD=false; shift ;;
|
||||||
--debug-on) DEBUG_ON=true; shift ;;
|
--debug-on) DEBUG_ON=true; shift ;;
|
||||||
--file-input) FILE_INPUT=true; shift ;;
|
--file-input) FILE_INPUT=true; shift ;;
|
||||||
|
|
@ -183,7 +219,7 @@ if [[ "$MODE" == "tui" ]]; then
|
||||||
# TUI mode: needs a real tty - no pipes or redirects allowed
|
# TUI mode: needs a real tty - no pipes or redirects allowed
|
||||||
tmux kill-session -t "$MCC_TMUX_SESSION" 2>/dev/null || true
|
tmux kill-session -t "$MCC_TMUX_SESSION" 2>/dev/null || true
|
||||||
tmux new-session -d -s "$MCC_TMUX_SESSION" -x 160 -y 50 \
|
tmux new-session -d -s "$MCC_TMUX_SESSION" -x 160 -y 50 \
|
||||||
"cd '$REPO_ROOT' && dotnet run --project MinecraftClient -c Release --no-build -- ${MCC_ARGS[*]}; echo '=== MCC EXITED ==='; sleep 600"
|
"cd '$REPO_ROOT' && dotnet run --project MinecraftClient -c Release --no-build -- $MCC_ARGS_CMD; echo '=== MCC EXITED ==='; sleep 600"
|
||||||
echo ""
|
echo ""
|
||||||
echo " TUI mode started in tmux session '$MCC_TMUX_SESSION'"
|
echo " TUI mode started in tmux session '$MCC_TMUX_SESSION'"
|
||||||
echo " (TUI mode uses a real terminal; log file is not available, use MCC's /debug command)"
|
echo " (TUI mode uses a real terminal; log file is not available, use MCC's /debug command)"
|
||||||
|
|
@ -243,7 +279,7 @@ else
|
||||||
# Interactive classic mode: run in tmux (no pipe - ConsoleInteractive also needs tty)
|
# Interactive classic mode: run in tmux (no pipe - ConsoleInteractive also needs tty)
|
||||||
tmux kill-session -t "$MCC_TMUX_SESSION" 2>/dev/null || true
|
tmux kill-session -t "$MCC_TMUX_SESSION" 2>/dev/null || true
|
||||||
tmux new-session -d -s "$MCC_TMUX_SESSION" -x 160 -y 50 \
|
tmux new-session -d -s "$MCC_TMUX_SESSION" -x 160 -y 50 \
|
||||||
"cd '$REPO_ROOT' && dotnet run --project MinecraftClient -c Release --no-build -- ${MCC_ARGS[*]}; echo '=== MCC EXITED ==='; sleep 600"
|
"cd '$REPO_ROOT' && dotnet run --project MinecraftClient -c Release --no-build -- $MCC_ARGS_CMD; echo '=== MCC EXITED ==='; sleep 600"
|
||||||
echo ""
|
echo ""
|
||||||
echo " Classic mode started in tmux session '$MCC_TMUX_SESSION'"
|
echo " Classic mode started in tmux session '$MCC_TMUX_SESSION'"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
|
||||||
|
|
@ -210,7 +210,7 @@ mcc-kill() {
|
||||||
done
|
done
|
||||||
|
|
||||||
session="$(_mcc_resolve_session "$session")"
|
session="$(_mcc_resolve_session "$session")"
|
||||||
local pid_file meta_file tmux_session pid
|
local pid_file meta_file tmux_session pid pid_comm pid_args
|
||||||
local killed=false
|
local killed=false
|
||||||
pid_file="$(_mcc_session_pid_file "$session")"
|
pid_file="$(_mcc_session_pid_file "$session")"
|
||||||
meta_file="$(_mcc_session_meta_file "$session")"
|
meta_file="$(_mcc_session_meta_file "$session")"
|
||||||
|
|
@ -219,9 +219,15 @@ mcc-kill() {
|
||||||
if [[ -f "$pid_file" ]]; then
|
if [[ -f "$pid_file" ]]; then
|
||||||
pid="$(tr -cd '0-9' < "$pid_file")"
|
pid="$(tr -cd '0-9' < "$pid_file")"
|
||||||
if [[ -n "$pid" ]] && kill -0 "$pid" 2>/dev/null; then
|
if [[ -n "$pid" ]] && kill -0 "$pid" 2>/dev/null; then
|
||||||
|
pid_comm="$(ps -p "$pid" -o comm= 2>/dev/null | tr -d '[:space:]')"
|
||||||
|
pid_args="$(ps -p "$pid" -o args= 2>/dev/null || true)"
|
||||||
|
if [[ "$pid_comm" == "MinecraftClient" ]] || { [[ "$pid_comm" == "dotnet" ]] && [[ "$pid_args" == *"MinecraftClient"* ]]; }; then
|
||||||
kill "$pid" 2>/dev/null || true
|
kill "$pid" 2>/dev/null || true
|
||||||
echo "Killed MCC PID $pid for session '$session'"
|
echo "Killed MCC PID $pid for session '$session'"
|
||||||
killed=true
|
killed=true
|
||||||
|
else
|
||||||
|
echo "Refusing to kill PID $pid for session '$session': unexpected process '$pid_comm'"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
echo "No live MCC PID found for session '$session' (pid file: $pid_file)"
|
echo "No live MCC PID found for session '$session' (pid file: $pid_file)"
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
|
|
@ -18,9 +18,31 @@ SERVER_ONLY=false
|
||||||
|
|
||||||
while [[ $# -gt 0 ]]; do
|
while [[ $# -gt 0 ]]; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
--session) SESSION="$2"; shift 2 ;;
|
--session)
|
||||||
--server) SERVER_VER="$2"; shift 2 ;;
|
if [[ $# -lt 2 ]]; then
|
||||||
--server-only) SERVER_ONLY=true; SERVER_VER="$2"; shift 2 ;;
|
echo "--session requires a value" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
SESSION="$2"
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
--server)
|
||||||
|
if [[ $# -lt 2 ]]; then
|
||||||
|
echo "--server requires a value" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
SERVER_VER="$2"
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
--server-only)
|
||||||
|
if [[ $# -lt 2 ]]; then
|
||||||
|
echo "--server-only requires a value" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
SERVER_ONLY=true
|
||||||
|
SERVER_VER="$2"
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
-h|--help)
|
-h|--help)
|
||||||
echo "Usage: tools/mcc-log-tail.sh [--session NAME] [--server VER] [--server-only VER]"
|
echo "Usage: tools/mcc-log-tail.sh [--session NAME] [--server VER] [--server-only VER]"
|
||||||
exit 0 ;;
|
exit 0 ;;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue