Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Commit

Permalink
image/base: Create console input socket
Browse files Browse the repository at this point in the history
This socket forwards any input to the server console directly.

Usage from outside:
  echo "my server command" | nc -UN /tmp/steamcmd/console.sock

The OpenBSD version of netcat is required for that to work (I believe).

Signed-off-by: Timo Reichl <[email protected]>
  • Loading branch information
thetredev committed Dec 23, 2023
1 parent 235209f commit fd08dfe
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion image/base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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/* \
Expand Down
13 changes: 13 additions & 0 deletions image/base/usr/local/lib/steamcmd/server-common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ _run_post() {

echo ${MESSAGE_STEAMCMD_SERVER_WAITING}
until healthy; do :; done

_input_socket
echo ${MESSAGE_STEAMCMD_SERVER_HEALTHY}
}

Expand All @@ -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 &
}

0 comments on commit fd08dfe

Please sign in to comment.