diff --git a/README.md b/README.md index 3c0c376..875a259 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ https://github.com/thetredev/steamcmd/assets/6085219/b7b807c0-3459-4522-89ed-343 # Table of Contents - [Differences to official images](#differences-to-official-images) - [tmux session socket](#tmux-session-socket) + - [console input socket](#console-input-socket) - [Base image](#base-image) - [SSH server](#ssh-server) - [HLDS image](#hlds-image) @@ -60,6 +61,27 @@ tmux -S /tmp/steamcmd/tmux.sock send-keys "bot_kick" "Enter" Unfortunately there's no way currently to provide a shorthand for `send-keys` yet. +### console input socket + +To get around the `tmux` session syntax noise, I decided to create a Unix domain socket as well. + +To type something in the SteamCMD game server console directly, you can use `netcat-openbsd` / `openbsd-netcat` like this: +``` +echo "my server command" | nc -UN /tmp/steamcmd/console.sock +``` + +To expose the socket, just bind-mount the path (using `cs2` as an example): +```yaml +services: + cs2: + ... + volumes: + - /tmp/steamcmd:/tmp/steamcmd + ... +``` + +This socket makes it possible to forward console inputs from a web API or secure TCP socket for example. + ### Base image - Based on the official [`SteamRT v3 "(Sniper)"` image](https://gitlab.steamos.cloud/steamrt/sniper/platform) with all necessary dependencies and basic tools preinstalled - For legacy game servers (Source 1, non-CS 2 and HLDS) SteamRT v2 "Soldier" is used instead diff --git a/image/base/Dockerfile b/image/base/Dockerfile index 46616c2..5d27216 100644 --- a/image/base/Dockerfile +++ b/image/base/Dockerfile @@ -18,7 +18,8 @@ ENV STEAMCMD_SH="${STEAMCMD_INSTALL_DIR}/steamcmd.sh" ## SteamCMD socket paths ENV STEAMCMD_SERVER_SOCKET_PATH="/tmp/steamcmd" ENV STEAMCMD_SERVER_TMUX_SOCKET="${STEAMCMD_SERVER_SOCKET_PATH}/tmux.sock" \ - STEAMCMD_SERVER_LOGS_SOCKET="${STEAMCMD_SERVER_SOCKET_PATH}/logs.sock" + STEAMCMD_SERVER_LOGS_SOCKET="${STEAMCMD_SERVER_SOCKET_PATH}/logs.sock" \ + STEAMCMD_SERVER_CONSOLE_SOCKET="${STEAMCMD_SERVER_SOCKET_PATH}/console.sock" ## System ENV TIME_ZONE=UTC \ LANG=en_US.UTF-8 \ @@ -44,6 +45,8 @@ RUN apt-get update && \ vim \ nano \ bash-completion \ + # tools needed for managing unix domain sockets + netcat-openbsd \ && \ # Remve preinstalled SSHD configs rm -f /etc/ssh/sshd_config.d/* \ diff --git a/image/base/usr/local/lib/steamcmd/server-common.sh b/image/base/usr/local/lib/steamcmd/server-common.sh index 2ed3928..5126a0f 100755 --- a/image/base/usr/local/lib/steamcmd/server-common.sh +++ b/image/base/usr/local/lib/steamcmd/server-common.sh @@ -112,6 +112,8 @@ _run_post() { echo ${MESSAGE_STEAMCMD_SERVER_WAITING} until healthy; do :; done + + _input_socket echo ${MESSAGE_STEAMCMD_SERVER_HEALTHY} } @@ -123,3 +125,14 @@ _logs_fifo() { ${TMUX_CMD} pipe-pane -O -t ${STEAMCMD_SERVER_SESSION_NAME} 'cat > ${STEAMCMD_SERVER_LOGS_SOCKET}' while :; do cat ${STEAMCMD_SERVER_LOGS_SOCKET}; done & } + + +_input_socket() { + rm -rf ${STEAMCMD_SERVER_CONSOLE_SOCKET} + nc -lkU ${STEAMCMD_SERVER_CONSOLE_SOCKET} & + + while :; do + input_string=$(nc -Ul ${STEAMCMD_SERVER_CONSOLE_SOCKET} < /dev/null) + ${TMUX_CMD} send-keys -t ${STEAMCMD_SERVER_SESSION_NAME} "${input_string}" "Enter" + done & +}