#!/bin/bash ########################################################################################## # Paths for logs and crash dumps ########################################################################################## export LOGS_PATH="/tmp/ac/logs" export CRASHES_PATH="/tmp/ac/crashes" mkdir -p "$LOGS_PATH" "$CRASHES_PATH" ########################################################################################## # Tmux sessions ########################################################################################## AUTHSERVER_SESSION="auth-session" WORLDSERVER_SESSION="world-session" # Timestamps for log files TIMESTAMP=$(date +"%Y%m%d_%H%M%S") AUTH_LOG="$LOGS_PATH/authserver_$TIMESTAMP.log" WORLD_LOG="$LOGS_PATH/worldserver_$TIMESTAMP.log" WORLD_CRASH_LOG="$CRASHES_PATH/worldserver_gdb_$TIMESTAMP.log" ########################################################################################## # Determine ROOT_DIR based on script location ########################################################################################## ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" # Paths to binaries AUTH_BIN="$ROOT_DIR/_server/azerothcore/env/dist/bin/authserver" WORLD_BIN="$ROOT_DIR/_server/azerothcore/env/dist/bin/worldserver" ########################################################################################## # Check debug toggle ########################################################################################## DEBUG_MODE=0 if [[ "$1" == "debug" ]]; then DEBUG_MODE=1 fi ########################################################################################## # Helper to start a tmux session ########################################################################################## start_tmux_session() { local session_name=$1 local command=$2 local log_file=$3 # Create session if it doesn't exist if tmux has-session -t "$session_name" 2>/dev/null; then echo "Tmux session '$session_name' already exists." else if tmux new-session -d -s "$session_name"; then echo "Created tmux session: $session_name" else echo "Error creating tmux session: $session_name" return 1 fi fi # Export environment variables inside tmux tmux send-keys -t "$session_name" "export LOGS_PATH=$LOGS_PATH; export CRASHES_PATH=$CRASHES_PATH" C-m # Run the command and pipe output to a new log file tmux send-keys -t "$session_name" "$command | tee $log_file" C-m echo "Running '$command' in $session_name, logging to $log_file" echo } ########################################################################################## # Prepare commands ########################################################################################## # Authserver binary (normal mode) AUTH_CMD="$AUTH_BIN" # Worldserver binary if [[ $DEBUG_MODE -eq 1 ]]; then echo "DEBUG MODE: Running worldserver under GDB" WORLD_CMD="gdb -ex 'set logging file $WORLD_CRASH_LOG' \ -ex 'set logging enabled on' \ -ex 'run' \ -ex 'bt full' \ -ex 'quit' \ --args $WORLD_BIN" else WORLD_CMD="$WORLD_BIN" fi ########################################################################################## # Start servers ########################################################################################## start_tmux_session "$AUTHSERVER_SESSION" "$AUTH_CMD" "$AUTH_LOG" start_tmux_session "$WORLDSERVER_SESSION" "$WORLD_CMD" "$WORLD_LOG" ########################################################################################## # Optional: show menu if exists ########################################################################################## if [[ -f "${ROOT_DIR}/script/menu.sh" ]]; then source "${ROOT_DIR}/script/menu.sh" fi