This commit is contained in:
Nathan Rashleigh 2025-07-31 18:13:22 +10:00
parent c1c0cd56b2
commit b0d23c1dac
16 changed files with 485 additions and 110 deletions

15
.env
View File

@ -1,18 +1,9 @@
STEAMAPPID=232330
STEAMAPP=css
SRCDS_TOKEN=C02633B3395EA6BEF7D8DFBA440ABB7F
SRCDS_RCONPW="changeme"
SRCDS_PW="changeme"
SRCDS_PORT=27015
SRCDS_TV_PORT=27020
SRCDS_IP="0.0.0.0"
SRCDS_FPSMAX=300
SRCDS_TICKRATE=66
SRCDS_MAXPLAYERS=32
SRCDS_REGION=3
SRCDS_RCONPW="hahahahhaha"
SRCDS_PW="hahahahhaha"
SRCDS_STARTMAP="ctf_2fort"
SRCDS_HOSTNAME="megastructure surf"
SRCDS_WORKSHOP_AUTHKEY=""
SRCDS_CFG="server.cfg"
SRCDS_MAPCYCLE="mapcycle_default.txt"
SRCDS_SECURED=0

View File

@ -2,10 +2,16 @@ build-css:
docker build -f css/css.dockerfile css/ -t megastructure/css
up:
docker compose -f surf.yaml up
docker compose -f surf.yaml up --remove-orphans
down:
docker compose -f surf.yaml down -v --remove-orphans
srcds-sh:
docker compose -f surf.yaml run -it srcds bash
build:
docker compose -f surf.yaml build
cssds-run:
docker compose -f surf.yaml run -it cssds bash
cssds-exec:
docker compose -f surf.yaml exec -it cssds bash

View File

@ -1,81 +0,0 @@
###########################################################
# Dockerfile that builds a CSS Gameserver
###########################################################
FROM cm2network/steamcmd:root AS build_stage
LABEL maintainer="ntr@megastructure.games"
ENV STEAMAPPID 232330
ENV STEAMAPP css
ENV STEAMAPPDIR "${HOMEDIR}/${STEAMAPP}-dedicated"
COPY "etc/entry_x64.sh" "${HOMEDIR}/entry_x64.sh"
COPY "etc/cfg" "${STEAMAPPDIR}/${STEAMAPP}/cfg/"
RUN set -x \
# Install, update & upgrade packages
&& apt-get update \
&& apt-get install -y --no-install-recommends --no-install-suggests \
wget=1.21.3-1+deb12u1 \
ca-certificates=20230311 \
zlib1g=1:1.2.13.dfsg-1 \
libncurses5=6.4-4 \
libbz2-1.0=1.0.8-5+b1 \
libtinfo5=6.4-4 \
libcurl3-gnutls=7.88.1-10+deb12u5 \
&& mkdir -p "${STEAMAPPDIR}" \
# Create autoupdate config
&& { \
echo '@ShutdownOnFailedCommand 1'; \
echo '@NoPromptForPassword 1'; \
echo 'force_install_dir '"${STEAMAPPDIR}"''; \
echo 'login anonymous'; \
echo 'app_update '"${STEAMAPPID}"''; \
echo 'quit'; \
} > "${HOMEDIR}/${STEAMAPP}_update.txt" \
&& chmod +x "${HOMEDIR}/entry_x64.sh" \
&& chown -R "${USER}:${USER}" "${HOMEDIR}/entry_x64.sh" "${STEAMAPPDIR}" "${HOMEDIR}/${STEAMAPP}_update.txt" \
# Clean up
&& rm -rf /var/lib/apt/lists/*
FROM build_stage AS bookworm-base
ENV SRCDS_FPSMAX=300 \
SRCDS_TICKRATE=66 \
SRCDS_PORT=27015 \
SRCDS_TV_PORT=27020 \
SRCDS_NET_PUBLIC_ADDRESS="0" \
SRCDS_IP="0" \
SRCDS_MAXPLAYERS=16 \
SRCDS_TOKEN=0 \
SRCDS_RCONPW="changeme" \
SRCDS_PW="changeme" \
SRCDS_STARTMAP="de_dust2" \
SRCDS_REGION=3 \
SRCDS_HOSTNAME="New \"${STEAMAPP}\" Server" \
SRCDS_WORKSHOP_START_MAP=0 \
SRCDS_HOST_WORKSHOP_COLLECTION=0 \
SRCDS_WORKSHOP_AUTHKEY="" \
SRCDS_CFG="server.cfg" \
SRCDS_MAPCYCLE="mapcycle.txt" \
SRCDS_SECURED=1
# Switch to user
USER ${USER}
WORKDIR ${HOMEDIR}
CMD ["bash", "entry_x64.sh"]
# Expose ports
EXPOSE 27015/tcp \
27015/udp \
27020/udp
FROM bookworm-base AS bookworm-metamod
ENV METAMOD_VERSION 1.12
FROM bookworm-metamod AS bookworm-sourcemod
ENV SOURCEMOD_VERSION 1.12

32
cssds/cssds.dockerfile Normal file
View File

@ -0,0 +1,32 @@
FROM cm2network/steamcmd:root AS build
LABEL maintainer="ntr@megastructure.games"
EXPOSE 27015/tcp \
27015/udp \
27020/udp
USER root
RUN apt-get update
RUN apt-get install -y wget
ENV CSSDS="/home/steam/cssds"
ENV TF2DS="/home/steam/tf2ds"
ENV STEAMCMD="/home/steam/steamcmd"
ENV ETC="/home/steam/etc"
# ensure gamedirs exist and have been chowned to steam
# before they potentially get setup as docker volumes
# which would otherwise cause them to be owned by root
RUN mkdir -p "$CSSDS" "$TF2DS" "$STEAMCMD" "$ETC"
RUN chown -R steam:steam /home/steam
FROM build AS steam
USER steam
WORKDIR /home/steam
ENV METAMOD_VERSION 1.12
ENV SOURCEMOD_VERSION 1.12
COPY etc /home/steam/etc
CMD ["bash", "./etc/run.sh"]

View File

@ -1,7 +1,7 @@
// General Settings //
// Hostname for server.
hostname "{{SERVER_HOSTNAME}}"
hostname "New "css" Server"
// Overrides the max players reported to prospective clients
sv_visiblemaxplayers 24

View File

@ -0,0 +1,4 @@
//This file re-enables a server from "war mode" by unlocking plugin loading
//and refreshing the plugins list.
sm plugins load_unlock
sm plugins refresh

View File

@ -0,0 +1,10 @@
//This file unloads all plugins, re-loads a few "safe" ones, and then prevents
//any more plugins from being loaded.
sm plugins unload_all
sm plugins load_unlock
sm plugins load basebans.smx
sm plugins load basecommands.smx
sm plugins load admin-flatfile.smx
sm plugins load adminhelp.smx
sm plugins load adminmenu.smx
sm plugins load_lock

View File

@ -0,0 +1,138 @@
// SourceMod Configuration File
// This file is automatically executed by SourceMod every mapchange.
// Specifies how admin activity should be relayed to users. Add up the values
// below to get the functionality you want.
// 1: Show admin activity to non-admins anonymously.
// 2: If 1 is specified, admin names will be shown.
// 4: Show admin activity to admins anonymously.
// 8: If 4 is specified, admin names will be shown.
// 16: Always show admin names to root users.
// --
// Default: 13 (1+4+8)
sm_show_activity 13
// Specifies whether menu sounds are enabled for menus created by SourceMod.
// Menu sounds can be further configured in addons/sourcemod/configs/core.cfg.
// --
// Default: 1
sm_menu_sounds 1
// Specifies how long of a delay, in seconds, should be used in between votes
// that are "public" or can be spammed. Whether or not this delay is obeyed
// is dependent on the menu/command.
// --
// Default: 30
sm_vote_delay 30
// Default datetime formatting rules when displaying to clients.
// For full options, see: http://www.opengroup.org/onlinepubs/007908799/xsh/strftime.html
// --
// Default: %m/%d/%Y - %H:%M:%S
// 12 hour format: %m/%d/%Y - %I:%M:%S %p
sm_datetime_format "%m/%d/%Y - %H:%M:%S"
// Sets how SourceMod should check immunity levels when administrators target
// each other.
// 0: Ignore immunity levels (except for specific group immunities).
// 1: Protect from admins of lower access only.
// 2: Protect from admins of equal to or lower access.
// 3: Same as 2, except admins with no immunity can affect each other.
// --
// Default: 1
sm_immunity_mode 1
// Sets how many seconds SourceMod should adjust time values for incorrect
// server clocks. This can be positive or negative and will affect every
// system time in SourceMod, including logging stamps.
// --
// Default: 0
sm_time_adjustment 0
// Specifies the amount of time that is allowed between chat messages. This
// includes the say and say_team commands. If a client sends a message faster
// than this time, they receive a flood token. When the client has accumulated
// 3 or more tokens, a warning message is shown instead of the chat message.
// --
// Requires: antiflood.smx
// Default: 0.75
sm_flood_time 0.75
// Specifies how the reserved slots plugin operates. Valid values are:
// 0 : Public slots are used in preference to reserved slots. Reserved slots are freed before public slots.
// 1 : If someone with reserve access joins into a reserved slot, the player with the highest latency and
// no reserved slot access (spectator players are selected first) is kicked to make room. Thus, the reserved
// slots always remains free. The only situation where the reserved slot(s) can become properly occupied is
// if the server is full with reserve slot access clients.
// 2 : The same as sm_reserve_type 1 except once a certain number of admins have been reached, the reserve slot
// stops kicking people and anyone can join to fill the server. You can use this to simulate having a large
// number of reserved slots with sm_reserve_type 0 but with only need to have 1 slot unavailable when there are
// less admins connected.
// --
// Requires: reservedslots.smx
// Default: 0
sm_reserve_type 0
// Specifies the number of reserved player slots. Users with the reservation
// admin flag set will be able to join the server when there are no public slots
// remaining. If someone does not have this flag, they will be kicked.
// (Public slots are defined as: maxplayers - number of reserved slots)
// --
// Requires: reservedslots.smx
// Default: 0
sm_reserved_slots 0
// Specifies whether or not reserved slots will be hidden (subtracted from max
// slot count). Valid values are 0 (Visible) or 1 (Hidden).
// --
// Requires: reservedslots.smx
// Default: 0
sm_hide_slots 0
// Specifies whether or not non-admins can send messages to admins using
// say_team @<message>. Valid values are 0 (Disabled) or 1 (Enabled)
// --
// Requires: basechat.smx
// Default: 1
sm_chat_mode 1
// Specifies whether or not "timeleft" will automatically be triggered every
// x seconds. Valid values are 0 (Disabled) to 1800 seconds.
// --
// Requires: basetriggers.smx
// Default: 0
sm_timeleft_interval 0
// Specifies whether or not chat triggers are broadcast to the server or just
// the player who requested the info trigger. Valid values are 0 (Disabled) or
// 1 (Enabled)
// --
// Requires: basetriggers.smx
// Default: 0
sm_trigger_show 0
// Specifies whether or not to display vote progress to clients in the
// "hint" box (near the bottom of the screen in most games).
// Valid values are 0 (Disabled) or 1 (Enabled).
// --
// Default: 0
sm_vote_progress_hintbox 0
// Specifies whether or not to display vote progress to clients in the
// chat area. Valid values are 0 (Disabled) or 1 (Enabled).
// --
// Default: 0
sm_vote_progress_chat 0
// Specifies whether or not to display vote progress in the server console.
// Valid values are 0 (Disabled) or 1 (Enabled).
// --
// Default: 0
sm_vote_progress_console 0
// Specifies whether or not to display vote progress to clients in the
// client console. Valid values are 0 (Disabled) or 1 (Enabled).
// --
// Default: 0
sm_vote_progress_client_console 0

164
cssds/etc/cp_tf2_libs.sh Normal file
View File

@ -0,0 +1,164 @@
#!/usr/bin/bash
set -o nounset
set -o errtrace
set -o pipefail
set -e
IFS=$'\n\t'
ME="$(basename "${0}")"
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
export SCRIPT_DIR=${SCRIPT_DIR%/*}
usage() {
cat <<HEREDOC
██████╗ ██╗ ██╗██████╗ ███████╗██████╗ ███████╗
██╔════╝ ██║ ██║██╔══██╗██╔════╝██╔══██╗██╔════╝
███████╗ ███████║██████╔╝███████╗██║ ██║███████╗
██╔═══██╗╚════██║██╔══██╗╚════██║██║ ██║╚════██║
╚██████╔╝ ██║██████╔╝███████║██████╔╝███████║
╚═════╝ ╚═╝╚═════╝ ╚══════╝╚═════╝ ╚══════╝
Quick installation of 64-bit Source Dedicated Server
Requirements: libncurses5 libncurses5:i386 lib32z1
Usage:
./${ME} <css/dods/hl2dm/hldm>
HEREDOC
}
if [ $# -ne 1 ]; then
usage
exit 1
else
case "$1" in
css|dods|hl2dm|hldm)
GAMESERVER=$1
;;
*)
usage
exit 1
;;
esac
fi
STEAMCMDBIN="/usr/games/steamcmd"
TF2DIR="$HOME/tf2-serverfiles"
DSDIR=""
prepare() {
DSDIR="$HOME/$GAMESERVER-serverfiles"
# Check if steamcmd installed and/or accessible
if command -v steamcmd >/dev/null 2&>1; then
STEAMCMDBIN=$(command -v steamcmd)
elif result=$(find "$HOME" -type f -name 'steamcmd' 2>/dev/null | head -n 1) && [ -n "$result" ]; then
STEAMCMDBIN="$result"
else
echo "SteamCMD not found. Please install following this guide: https://developer.valvesoftware.com/wiki/SteamCMD#Linux"
exit 1
fi
echo "SteamCMD found at $STEAMCMDBIN. Continuing..."
}
fetch_server_files() {
echo "Starting installation of $GAMESERVER dedicated server!"
# Update steamcmd-scripts to correct home dir
echo "Confirm steamcmd scripts are correct..."
for _steamcmdscriptfile in $SCRIPT_DIR/steamcmd-scripts/*; do
sed -i "s#/home/server/#/home/${USER}/#g" "$_steamcmdscriptfile"
done
if [ -d "$DSDIR" ]; then
echo "$DSDIR already contains files. Exiting..."
exit 1;
fi
echo "Starting to download server files using steamcmd"
# Fetch required game server and tf2 server files
"$STEAMCMDBIN" +runscript "$HOME/steamcmd-scripts/update_${GAMESERVER}_ds.txt" && \
echo "$DSDIR successfully downloaded!"
if [ -d "$TF2DIR" ]; then
echo "$TF2DIR already contains files. Validating..."
fi
"$STEAMCMDBIN" +runscript "$HOME/steamcmd-scripts/update_tf2_ds.txt" && \
echo "$TF2DIR successfully downloaded!"
}
copy_64bit() {
echo "Copying libsteam_api.so..."
cp -a "$TF2DIR/bin/linux64/libsteam_api.so" \
"$DSDIR/bin/linux64/."
echo "Copying srcds binaries..."
cp -a "$HOME/tf2-serverfiles/srcds_linux64" "$HOME/tf2-serverfiles/srcds_run_64" \
"$DSDIR/."
}
remove_tf2() {
echo "Removing $TF2DIR..."
[ -f "$DSDIR/srcds_linux64" ] && rm -r "$HOME/tf2-serverfiles" || \
# You should never see this message
echo "$DSDIR is missing 64-bit binaries. Cannot remove tf2-serverfiles"
}
symlink_binaries() {
cd "$DSDIR/bin/linux64"
for file in *_srv.so; do
echo "Symlinking \"$file\" to \"${file/_srv/}"
ln -s "$file" "${file/_srv/}"
done
}
steamclient_binary() {
echo "Looking for steamclient.so and symlinking it..."
local _steamclient64bit=$(find "$HOME" -type f -name 'steamclient.so' | grep "linux64" | head -n 1)
if [ ! -n $_steamclient64bit ]; then
echo "Could not locate 64-bit steamclient.so binary. Exiting..."
exit 1
fi
mkdir -p "$HOME/.steam/sdk64/" # srcds_linux64 looks for steamclient.so in this directory
ln -sf "$_steamclient64bit" "$HOME/.steam/sdk64/steamclient.so"
ln -sf "$_steamclient64bit" "$DSDIR/bin/linux64/steamclient.so"
}
main() {
prepare
fetch_server_files
copy_64bit
remove_tf2
symlink_binaries
steamclient_binary
SRCDSGAME=""
case "$GAMESERVER" in
css) SRCDSGAME="cstrike"; SRCDSMAP="de_dust2";;
dods) SRCDSGAME="dod"; SRCDSMAP="dod_anzio";;
hl2dm) SRCDSGAME="hl2mp"; SRCDSMAP="dm_lockdown";;
hldm) SRCDSGAME="hl1mp"; SRCDSMAP="crossfire";;
*) ;;
esac
cat <<SUCESSMSG
# --------------------------------------------------- #
Successfully installed $GAMESERVER dedicated server
to $DSDIR!
Confirm the server starts and runs without issue:
$ cd $DSDIR
$ ./srcds_run_64 -game $SRCDSGAME +map $SRCDSMAP -debug
# --------------------------------------------------- #
SUCESSMSG
}
main "$@"

7
css/etc/entry_x64.sh → cssds/etc/entry_x64.sh Normal file → Executable file
View File

@ -2,13 +2,6 @@
set -eux
mkdir -p "${STEAMAPPDIR}" || true
bash "${STEAMCMDDIR}/steamcmd.sh" +force_install_dir "${STEAMAPPDIR}" \
+login anonymous \
+app_update "${STEAMAPPID}" \
+quit
# Are we in a metamod container and is the metamod folder missing?
if [ ! -z "$METAMOD_VERSION" ] && [ ! -d "${STEAMAPPDIR}/${STEAMAPP}/addons/metamod" ]; then
LATESTMM=$(wget -qO- https://mms.alliedmods.net/mmsdrop/"${METAMOD_VERSION}"/mmsource-latest-linux)

93
cssds/etc/run.sh Normal file
View File

@ -0,0 +1,93 @@
#! /bin/bash
set -uxe
update_cssds() {
cd $STEAMCMD
./steamcmd.sh +runscript "$HOME/etc/update_cssds.txt"
echo "--------------------------------------------------------------"
echo "CSS DS is up to date"
echo "--------------------------------------------------------------"
}
update_tf2ds() {
cd $STEAMCMD
./steamcmd.sh +runscript "$HOME/etc/update_tf2ds.txt"
echo "--------------------------------------------------------------"
echo "TF2 DS is up to date"
echo "--------------------------------------------------------------"
}
install_metamod() {
# is the metamod folder missing?
if [ ! -d "$CSSDS/addons/metamod" ]; then
LATESTMM=$(wget -qO- https://mms.alliedmods.net/mmsdrop/"${METAMOD_VERSION}"/mmsource-latest-linux)
wget -qO- https://mms.alliedmods.net/mmsdrop/"${METAMOD_VERSION}"/"${LATESTMM}" | tar xvzf - -C "$CSSDS"
echo "--------------------------------------------------------------"
echo "Installed MetaMod $METAMOD_VERSION"
echo "--------------------------------------------------------------"
fi
}
install_sourcemod() {
# Are we in a sourcemod container and is the sourcemod folder missing?
if [ ! -d "$CSSDS/addons/sourcemod" ]; then
LATESTSM=$(wget -qO- https://sm.alliedmods.net/smdrop/"${SOURCEMOD_VERSION}"/sourcemod-latest-linux)
wget -qO- https://sm.alliedmods.net/smdrop/"${SOURCEMOD_VERSION}"/"${LATESTSM}" | tar xvzf - -C "$CSSDS"
echo "--------------------------------------------------------------"
echo "Installed SourceMod $SOURCEMOD_VERSION"
echo "--------------------------------------------------------------"
fi
}
copy_64bit() {
cp -a "$TF2DS/bin/linux64/libsteam_api.so" \
"$CSSDS/bin/linux64/."
cp -a "$TF2DS/srcds_linux64" "$TF2DS/srcds_run_64" \
"$CSSDS/."
}
symlink_binaries() {
cd "$CSSDS/bin/linux64"
for file in *_srv.so; do
echo "Symlinking \"$file\" to \"${file/_srv/}"
ln -s "$file" "${file/_srv/}"
done
}
steamclient_binary() {
echo "Looking for steamclient.so and symlinking it..."
local _steamclient64bit=$(find "$HOME" -type f -name 'steamclient.so' | grep "linux64" | head -n 1)
if [ ! -n $_steamclient64bit ]; then
echo "Could not locate 64-bit steamclient.so binary. Exiting..."
exit 1
fi
mkdir -p "$HOME/.steam/sdk64/" # srcds_linux64 looks for steamclient.so in this directory
ln -nfs "$_steamclient64bit" "$HOME/.steam/sdk64/steamclient.so"
ln -nfs "$_steamclient64bit" "$CSSDS/bin/linux64/steamclient.so"
}
run_cssds() {
echo "ready to run"
cd "$CSSDS"
./srcds_run_64 -game cstrike +map de_dust2 -debug
}
main() {
update_cssds
update_tf2ds
copy_64bit
symlink_binaries
steamclient_binary
install_metamod
install_sourcemod
run_cssds
}
main

View File

@ -0,0 +1,6 @@
@ShutdownOnFailedCommand 1
@NoPromptForPassword 1
force_install_dir /home/steam/cssds
login anonymous
app_update 232330 validate
quit

View File

@ -0,0 +1,6 @@
@ShutdownOnFailedCommand 1
@NoPromptForPassword 1
force_install_dir /home/steam/tf2ds
login anonymous
app_update 232250 validate
quit

View File

@ -1,8 +1,21 @@
services:
srcds:
image: megastructure/css:latest
volumes:
- ./css/etc/entry_x64.sh:/home/steam/entry_x64.sh
- ./css/etc/cfg:/home/steam/css-dedicated/css/cfg
- ./data/css-dir:/home/steam/css-dedicated
cssds:
image: megastructure/cssds
build:
dockerfile: cssds.dockerfile
context: ./cssds
env_file:
- .env
# command: sleep 5000000
volumes:
- ./cssds/etc:/home/steam/etc
- cssds:/home/steam/cssds
- tf2ds:/home/steam/tf2ds
volumes:
tf2ds:
cssds: