diff --git a/.env b/.env index d00050e..91b8555 100644 --- a/.env +++ b/.env @@ -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 diff --git a/Justfile b/Justfile index 0e9941f..8384ffb 100644 --- a/Justfile +++ b/Justfile @@ -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 \ No newline at end of file +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 \ No newline at end of file diff --git a/css/css.dockerfile b/css/css.dockerfile deleted file mode 100644 index 1a3e712..0000000 --- a/css/css.dockerfile +++ /dev/null @@ -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 \ No newline at end of file diff --git a/cssds/cssds.dockerfile b/cssds/cssds.dockerfile new file mode 100644 index 0000000..ff3d6d3 --- /dev/null +++ b/cssds/cssds.dockerfile @@ -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"] \ No newline at end of file diff --git a/css/etc/cfg/mapcycle.txt b/cssds/etc/cfg/mapcycle.txt similarity index 100% rename from css/etc/cfg/mapcycle.txt rename to cssds/etc/cfg/mapcycle.txt diff --git a/css/etc/cfg/mapcycle_default.txt b/cssds/etc/cfg/mapcycle_default.txt similarity index 100% rename from css/etc/cfg/mapcycle_default.txt rename to cssds/etc/cfg/mapcycle_default.txt diff --git a/css/etc/cfg/server.cfg b/cssds/etc/cfg/server.cfg similarity index 99% rename from css/etc/cfg/server.cfg rename to cssds/etc/cfg/server.cfg index 92f151e..730adc8 100644 --- a/css/etc/cfg/server.cfg +++ b/cssds/etc/cfg/server.cfg @@ -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 diff --git a/cssds/etc/cfg/sourcemod/sm_warmode_off.cfg b/cssds/etc/cfg/sourcemod/sm_warmode_off.cfg new file mode 100644 index 0000000..278c925 --- /dev/null +++ b/cssds/etc/cfg/sourcemod/sm_warmode_off.cfg @@ -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 diff --git a/cssds/etc/cfg/sourcemod/sm_warmode_on.cfg b/cssds/etc/cfg/sourcemod/sm_warmode_on.cfg new file mode 100644 index 0000000..56340cd --- /dev/null +++ b/cssds/etc/cfg/sourcemod/sm_warmode_on.cfg @@ -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 diff --git a/cssds/etc/cfg/sourcemod/sourcemod.cfg b/cssds/etc/cfg/sourcemod/sourcemod.cfg new file mode 100644 index 0000000..9ed0ccc --- /dev/null +++ b/cssds/etc/cfg/sourcemod/sourcemod.cfg @@ -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 @. 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 diff --git a/cssds/etc/cp_tf2_libs.sh b/cssds/etc/cp_tf2_libs.sh new file mode 100644 index 0000000..71e24cf --- /dev/null +++ b/cssds/etc/cp_tf2_libs.sh @@ -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 +} + +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 <