#!/bin/bash
CONTAINER="mc_forge_server"
SESSION="mc_console"

# Install tmux if not installed
if ! command -v tmux &> /dev/null; then
    echo "Installing tmux..."
    sudo apt update && sudo apt install -y tmux
fi

# Clean up old session
tmux kill-session -t $SESSION 2>/dev/null

# Create top window: Live logs
tmux new-session -d -s $SESSION "docker logs -f --tail 100 $CONTAINER"

# Create bottom window: Interactive command prompt via rcon-cli
tmux split-window -v -l 3 -t $SESSION "while true; do read -e -p 'MC> ' cmd; [ -n \"\$cmd\" ] && docker exec -i $CONTAINER rcon-cli \"\$cmd\"; done"

# Open the split console
tmux attach -t $SESSION
