So I wrote this little script to update the maps/map cycle all my servers at once.
I run 9 severs now. Adding a map/managing the playlist has become a huge hassle.
I have my Configs per server in kf2server/KFGame/Config/
So for example, for my second normar server, there is a folder kf2server/KFGame/Config/ConfigNormal2
What this script does is the following:
It supports 2 maplists. It can be configured which maplist it installs on what server.
It replaces the parts between:
GameMapCycles=(Maps=(...))
and the parts between:
[KF-Default KFMapSummary]\
MapName=KF-Default
ScreenshotPathName=UI_MapPreview_TEX.UI_MapPreview_Placeholder
...
[Survival KFGameInfoSummary]
It does require perl to do the replaces:
The maplist.txt is just the map per line:
I run 9 severs now. Adding a map/managing the playlist has become a huge hassle.
I have my Configs per server in kf2server/KFGame/Config/
So for example, for my second normar server, there is a folder kf2server/KFGame/Config/ConfigNormal2
What this script does is the following:
- Scans my map upload folder for new maps
- Copies the maps to BrewedPC/Maps
- Generates the KFMapSummary for every map
- Reads the map cycle from maplist.txt/maplist with defaults.txt
- Updates every PCServer-KFGame.ini in every folder it finds
It supports 2 maplists. It can be configured which maplist it installs on what server.
It replaces the parts between:
GameMapCycles=(Maps=(...))
and the parts between:
[KF-Default KFMapSummary]\
MapName=KF-Default
ScreenshotPathName=UI_MapPreview_TEX.UI_MapPreview_Placeholder
...
[Survival KFGameInfoSummary]
It does require perl to do the replaces:
Code:
#!/bin/bash
# Update all Killing Floor 2 servers with new maps
# Variables
UploadFolder="/home/ragequit/public_html/kf2/"
InstallFolder="/home/steam/steamcmdwin/kf2server/"
MapListFolder="/home/steam/"
# Config folders in this array get maplist.txt, the rest gets maplist with defaults.txt
declare -a NoDefaultsArr=(ConfigNormal2 ConfigHard2 ConfigHard4 ConfigSuicidal1)
# Config folders in this array are ignored
declare -a IgnoredArr=(ConfigSpecial)
# Everything between these 2 strings will be replaced with the map cycle
ConfigCycleReplaceStart="GameMapCycles=\(Maps=\("
ConfigCycleReplaceEnd="\)\)"
# Everything between these 2 strings will be replaced with the map list
ConfigMapReplaceStart="\[KF-Default KFMapSummary\]\r\nMapName=KF-Default\r\nScreenshotPathName=UI_MapPreview_TEX.UI_MapPreview_Placeholder"
ConfigMapReplaceEnd="\[Survival KFGameInfoSummary\]"
# Functions
array_contains() {
local array="$1[@]"
local seeking=$2
local in=1
for element in "${!array}"; do
if [[ $element == $seeking ]]; then
in=0
break
fi
done
return $in
}
#Actual script
echo "Step 1: Copy new maps from $UploadFolder to $InstallFolder"
rsync -v -a "$UploadFolder" "$InstallFolder"KFGame/BrewedPC/Maps/
#chown -R steam:steam "$InstallFolder"KFGame/BrewedPC/Maps/
shopt -s nullglob
echo "Step 2: Find all server configs to be updated..."
dirArray=()
while IFS= read -r -d $'\0'; do
echo Found `basename "$REPLY"`
dirArray+=("$REPLY")
done < <(find "$InstallFolder"KFGame/Config/ -maxdepth 1 -mindepth 1 -type d -name 'Config*' -print0)
echo "Step 3: Loading maplist.txt"
MapList=""
while IFS='' read -r line || [[ -n $line ]]; do
#echo "Adding to Map Cycle: $line"
MapList="${MapList}\"${line}\","
done < "$MapListFolder"maplist.txt
MapList=${MapList%?}
echo "New maplist for servers without defaults: $MapList"
echo "Step 4: Loading maplist with defaults.txt"
MapListDefaults=""
while IFS='' read -r line || [[ -n $line ]]; do
#echo "Adding to Map Cycle for defaults: $line"
MapListDefaults="${MapListDefaults}\"${line}\","
done < "${MapListFolder}maplist with defaults.txt"
MapListDefaults=${MapListDefaults%?}
echo "New maplist for servers with defaults: $MapListDefaults"
echo "Step 5: Adding all maps to the web interface..."
MapSummary="\r\n\r\n"
for file in "$InstallFolder"KFGame/BrewedPC/Maps/*.kfm
do
filename=${file##*/}
mapname=${filename%.*}
echo "Processing map: $mapname, filename: $filename"
MapSummary="${MapSummary}[${mapname} KFMapSummary]\r\n"
MapSummary="${MapSummary}MapName=${mapname}\r\n"
MapSummary="${MapSummary}ScreenshotPathName=UI_MapPreview_TEX.UI_MapPreview_Placeholder\r\n\r\n"
done
echo "Step 6: Actually updating the config files"
MapCycle=$MapListDefaults
for i in "${dirArray[@]}"
do
foldername=`basename "$i"`
if array_contains IgnoredArr $foldername
then
echo "Ignoring $foldername"
continue
fi
if array_contains NoDefaultsArr $foldername
then
MapCycle=$MapList
fi
echo "Updating ${i}/PCServer-KFGame.ini"
#cycle
perl -0777 -pi -e "s/${ConfigCycleReplaceStart}.*?(${ConfigCycleReplaceEnd})/${ConfigCycleReplaceStart}${MapCycle}${ConfigCycleReplaceEnd}/g" "${i}/PCServer-KFGame.ini"
#summary
perl -0777 -pi -e "s/${ConfigMapReplaceStart}.*?(${ConfigMapReplaceEnd})/${ConfigMapReplaceStart}${MapSummary}${ConfigMapReplaceEnd}/gs" "${i}/PCServer-KFGame.ini"
MapCycle=$MapListDefaults
done
echo "Done!"
The maplist.txt is just the map per line:
Code:
KF-londonbetathree
KF-Defence_Thyself_v3_beta
KF-DarkZone
KF-ZedIsland_FinalBeta
KF-BioticsLabUK_B2
KF-Subterrane-v2
KF-Complexity-B4
KF-HotelZed_BetaV4-2
KF-ScrakesOnAPlane-v1-0
KF-Antize-RE2-V7
KF-BloodBank
KF-PoliceStation
KF-ZedIsland_FinalBeta
KF-HorzineDistrict
KF-PoliceStation
KF-RatsManorV2-1
Last edited:
Upvote
0