From d0991e7d226aa24fa2713ac750138cb0e549800e Mon Sep 17 00:00:00 2001 From: Sergey Shorokhov Date: Tue, 23 Apr 2024 21:59:46 +0300 Subject: [PATCH 1/2] add script `build.sh` --- .vscode/.gitignore | 1 + .vscode/build.sh | 117 +++++++++++++++++++++++++++++++++++++++++++++ .vscode/tasks.json | 48 +++++++++++++++++++ 3 files changed, 166 insertions(+) create mode 100644 .vscode/.gitignore create mode 100644 .vscode/build.sh create mode 100644 .vscode/tasks.json diff --git a/.vscode/.gitignore b/.vscode/.gitignore new file mode 100644 index 0000000..c07a74d --- /dev/null +++ b/.vscode/.gitignore @@ -0,0 +1 @@ +build.sh \ No newline at end of file diff --git a/.vscode/build.sh b/.vscode/build.sh new file mode 100644 index 0000000..99c9779 --- /dev/null +++ b/.vscode/build.sh @@ -0,0 +1,117 @@ +#!/bin/bash + +# Define color codes +RED="\e[31m" +ORANGE="\e[33m" +GREEN="\e[32m" +WHITE_BG="\e[47m" +RESET="\e[0m" + +# Function to print colored messages +print_color() { + local color="$1" + local message="$2" + echo -e "${color}${message}${RESET}" +} + + +# Define directories +srcDir="$1" + +# Check if directory is not empty +if [ -z "$srcDir" ]; then + print_color $RED "❌ Error: Argument 1 not provided" + exit 1 +fi + +# Check if directory does not exist +if [ ! -d "$srcDir" ]; then + print_color $RED "❌ Error: Directory '$srcDir' not found" + exit 1 +fi + +# Make amxxpc happy to find amxxpc32.so nearly +export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$srcDir/scripting + +destinationDir="$2" + +# Check if directory is not empty +if [ -z "$destinationDir" ]; then + print_color $RED "❌ Error: Argument 2 not provided" + exit 1 +fi + +# Check if directory does not exist +if [ ! -d "$destinationDir" ]; then + print_color $RED "❌ Error: Directory '$destinationDir' not found" + exit 1 +fi + +scriptingDir="$destinationDir/scripting" + + + +# Function to compile a .sma file +compile_sma() { + local smaFile="$1" + local outputPluginDir="$2" + + pluginName=$(basename "${smaFile%.sma}") + relativeDir=$(dirname "${smaFile#$srcDir}") + outputPlugin="$outputPluginDir/${pluginName}.amxx" + + # Create the output plugin directory if it doesn't exist + mkdir -p "$outputPluginDir" + + # Print the name of the .sma file with white background + # print_color $WHITE_BG " - Compiling: $(basename $smaFile)" + + # Get the last modification time of the output plugin file + lastModTime=$(stat -c %Y "$smaFile" 2>/dev/null) + now=$(date +%s) + diff=$((now-lastModTime)) + + # Check if the file exists and its last modification time is within the last minute + + # Compile the .sma file and capture its output, excluding the lines with version and copyright info + compile_output=$("$scriptingDir/amxxpc" \ + "$smaFile" \ + -i"$srcDir/scripting" \ + -i"$srcDir/scripting/include" \ + -i"$srcDir/scripting/ReDeathmatch" \ + -o"$outputPlugin" 2>&1 | grep -vE "AMX Mod X Compiler|Copyright|Could not locate output file") + + # Check if there are any errors or warnings in the compile output + if echo "$compile_output" | grep -qi "error"; then + error_lines=$(echo "$compile_output" | grep -i "error" | sed 's/.*scripting\///') + warning_lines=$(echo "$compile_output" | grep -i "warning" | sed 's/.*scripting\///') + print_color $RED "❌ $error_lines" + if [ -n "$warning_lines" ]; then + print_color $ORANGE "⚠️ $warning_lines" + fi + elif echo "$compile_output" | grep -qi "warning"; then + warning_lines=$(echo "$compile_output" | grep -i "warning" | sed 's/.*scripting\///') + print_color $ORANGE "⚠️ $warning_lines" + else + print_color $GREEN " ✅ Compiled: $(basename $smaFile)" + fi + +} + +# Find and compile all .sma files in the source directory and its subdirectories +find $srcDir -name "*.sma" -type f | while read smaFile; do + relativeDir=$(dirname "${smaFile#$srcDir/scripting}") + outputPluginDir="$destinationDir/plugins$relativeDir" + compile_sma "$smaFile" "$outputPluginDir" +done + +needCopyOther=$3 +if [ "$needCopyOther" ]; then + echo "" + + # Copy directories without confirmation with green messages + print_color $GREEN " - Copying configs..." + cp -an $srcDir/configs/* $destinationDir/configs/ + print_color $GREEN " - Copying data..." + cp -an $srcDir/data/* $destinationDir/data/ +fi \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..b172a24 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,48 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "Build AMX Mod X Plugins", + "type": "shell", + "command": "bash", + "args": [ + ".vscode/build.sh", + // sourceDir + "$PWD/cstrike/addons/amxmodx", + // outputDir + "D:/Dev/HLDS_Server/cstrike/addons/amxmodx", + // copy `data` and `configs` ? + "1" + ], + "group": { + "kind": "build", + "isDefault": false + } + } + ], + "presentation": { + "echo": false, + "reveal": "always", + "focus": false, + "panel": "dedicated", + "showReuseMessage": false, + "clear": true + }, + "problemMatcher": { + "fileLocation": "autoDetect", + "owner": "problem", + "pattern": { + // Group 1 - filename (absolute path for filename) + // Group 2 - beginning line + // Group 3 - ending line (optional) + // Group 4 - error | warning (severity) + // Group 5 - message + "regexp": "(.+?)\\((\\d+)(?:\\s--\\s(\\d+))?\\)\\s:\\s(warning|error)\\s\\d+:\\s(.*)", + "file": 1, + "line": 2, + "column": 3, + "severity": 4, + "message": 5 + } + } +} \ No newline at end of file From 8b42b1d8bc57c44946febb87796c150b569b3afc Mon Sep 17 00:00:00 2001 From: Sergey Shorokhov Date: Tue, 23 Apr 2024 22:18:41 +0300 Subject: [PATCH 2/2] add Dockerfile and build tasks --- .vscode/tasks.json | 41 +++++++++++++++++++++++++++++++- Dockerfile | 58 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 Dockerfile diff --git a/.vscode/tasks.json b/.vscode/tasks.json index b172a24..68ca57f 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -18,6 +18,33 @@ "kind": "build", "isDefault": false } + }, + { + "label": "Build ReDeathmatch Image", + "type": "docker-build", + "dockerBuild": { + "context": "${workspaceFolder}/", + "tag": "redeathmatch:${input:mod}", + "buildArgs": { + "MOD": "${input:mod}" + } + }, + "group": { + "kind": "build", + "isDefault": false + } + }, + { + "type": "shell", + "label": "Run HLDS container", + "command": "docker run --rm -ti -p 26900-27020:26900-27020/udp redeathmatch:${input:mod} ./hlds_run -game ${input:mod} +maxplayers 32 -bots +ip 0.0.0.0 -port 27016 +map de_dust2", + "dependsOn": [ + "Build ReDeathmatch Image" + ], + "group": { + "kind": "build", + "isDefault": false + } } ], "presentation": { @@ -44,5 +71,17 @@ "severity": 4, "message": 5 } - } + }, + "inputs": [ + { + "type": "pickString", + "id": "mod", + "default": "cstrike", + "description": "Select mod.", + "options": [ + "cstrike", + "czero" + ] + } + ] } \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..bb8b7a8 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,58 @@ +# syntax=docker/dockerfile:1 + +ARG MOD="cstrike" + +FROM debian:trixie-slim AS build_stage + +# Install required packages +RUN set -x \ + && apt-get update \ + && apt-get install -y --no-install-recommends --no-install-suggests \ + ca-certificates=20240203 \ + curl=8.5.0-2 \ + libarchive-tools=3.7.2-1 \ + lib32stdc++6=14-20240201-3 \ + && rm -rf /var/lib/apt/lists/* + +WORKDIR /usr/local/bin/ +ADD --chmod=755 https://raw.githubusercontent.com/hldsdocker/rehlds/master/utils/GetGithubReleaseUrl.sh GetGithubReleaseUrl + +WORKDIR /root/hlds/cstrike + +# Install Metamod-R +RUN releaseLink="https://github.com/theAsmodai/metamod-r/releases/download/1.3.0.149/metamod-bin-1.3.0.149.zip" \ + && curl -sSL ${releaseLink} | bsdtar -xf - --exclude='*.dll' --exclude='*.pdb' addons/* + +# Install AMXModX 1.9.0 +ARG AMXModX_URL="https://www.amxmodx.org/amxxdrop/1.9/amxmodx-1.9.0-git5294-base-linux.tar.gz" +RUN curl -sSL ${AMXModX_URL} | bsdtar -xf - addons/ \ + && echo "linux addons/amxmodx/dlls/amxmodx_mm_i386.so" > addons/metamod/plugins.ini + +# Install ReAPI +RUN releaseLink="https://github.com/s1lentq/reapi/releases/download/5.24.0.300/reapi-bin-5.24.0.300.zip" \ + && curl -sSL ${releaseLink} | bsdtar -xf - --exclude='*.dll' --exclude='*.pdb' addons/ + +COPY cstrike . + +SHELL ["/bin/bash", "-c"] + +WORKDIR /usr/local/bin/ +COPY --chmod=755 .vscode/build.sh BuildAMXXPlugins + +WORKDIR /root/hlds/cstrike/addons/amxmodx/ +RUN BuildAMXXPlugins . . + + +WORKDIR /root/hlds/cstrike/ +ARG YaPB_URL="https://github.com/yapb/yapb/releases/download/4.4.957/yapb-4.4.957-linux.tar.xz" +RUN curl -sSL ${YaPB_URL} | bsdtar -xf - addons/ \ + && echo "linux addons/yapb/bin/yapb.so" >> addons/metamod/plugins.ini + + +ARG MOD +FROM hldsdocker/rehlds-${MOD}:regamedll AS run_stage + +COPY --chown=${APPUSER}:${APPUSER} --chmod=755 --from=build_stage /root/hlds/cstrike ${MOD} + +# Activate Metamod-R +RUN sed -i 's/gamedll_linux ".*"/gamedll_linux "addons\/metamod\/metamod_i386.so"/' ${MOD}/liblist.gam