Skip to content

Instantly share code, notes, and snippets.

@Rcomian
Last active May 31, 2022 11:51
Show Gist options
  • Save Rcomian/da5506197822431f84356cc3b2a5cf5f to your computer and use it in GitHub Desktop.
Save Rcomian/da5506197822431f84356cc3b2a5cf5f to your computer and use it in GitHub Desktop.
CC2 Dedicated Server ==================== This script will help with running CC2 as a dedicated server on linux using the installed steam proton runtime. **Dependencies** * XMLStarlet: [http://xmlstar.sourceforge.net/docs.php]() * `optional` for auto editing the xml files **Usage** `./run-server.sh proton` Lists the available proton versions, al…

CC2 Dedicated Server

This script will help with running CC2 as a dedicated server on linux using the installed steam proton runtime.

For official documentation on server_config.xml and additional getting started information, visit: https://geometa.co.uk/wiki/carrier_command_2/view/dedicated_servers

Dependencies

Configuration

The script starts by defining the following variables. You should make sure they are appropriate for your system and point to your actual steam locations:

  • STEAMLOCAL
  • STEAMAPPS
  • PROTON_VERSION

Usage

./run-server.sh proton

Lists the available proton versions, also showing the current version being used.

./run-server.sh init

This will:

  • make a copy of the proton prefix for the server
    • this is so the main game can be run from steam while the server is running
  • create the steam_appid.txt file so that the server can identify the game id
  • setup a basic server_config.xml
  • if xmlstarlet is installed:
    • set the data path (rom_0) correctly using the proton path mapping
    • name the server after your Steam displayname
    • add the current steam users as admins
    • add the currently enabled game mods to the list of server mods

./run-server.sh mods

List the mods available

./run-server.sh addmod <MOD NAME>

Adds the current mod to the list of server mods, using the correct path for proton.

./run-server.sh run

Actually runs the server using proton. A separate window is not opened for this.

#!/bin/env bash
# BASE Config
STEAMLOCAL="${HOME}/.local/share/Steam"
STEAMAPPS="${STEAMLOCAL}/steamapps"
PROTON_VERSION="Proton - Experimental"
GAME_NAME="Carrier Command 2"
GAME_ID="1489630"
GAME_EXE="dedicated_server.exe"
declare -a PROTON_LOCATIONS=("${STEAMAPPS}/common" "${STEAMLOCAL}/compatibilitytools.d")
# See if we can handle XML
XMLSTARLET=`which xml 2>/dev/null`
if [ ! -f "${XMLSTARLET}" ]; then
echo "xmlstarlet not installed, please install this for handling mods"
XMLSTARLET=""
fi
# Find the exe to run
CC2_INSTALL="${STEAMLOCAL}/steamapps/common/${GAME_NAME}"
GAME_PATH="${CC2_INSTALL}/${GAME_EXE}"
if [ ! -f "${GAME_PATH}" ]; then
echo "Cannot find server executable, please check that ${GAME_NAME} is installed and that the STEAMLOCAL variable is correct"
echo "STEAMLOCAL: ${STEAMLOCAL}"
echo "Expected Game Path: ${GAME_PATH}"
exit 1
fi
# Find the version of proton we're running
PROTON=""
for val in "${PROTON_LOCATIONS[@]}"; do
PROTONTEST="${val}/${PROTON_VERSION}/proton"
if [ -f "${PROTONTEST}" ]; then
PROTON="${PROTONTEST}"
fi
done
if [ ! -f "${PROTON}" ]; then
echo "Unable to find proton version: ${PROTON_VERSION}"
echo "Please check the PROTON_VERSION variable and ensure that version is installed in steam"
exit 1
fi
export STEAM_COMPAT_CLIENT_INSTALL_PATH="${STEAMLOCAL}"
export STEAM_COMPAT_DATA_PATH="${STEAMAPPS}/compatdata/${GAME_ID}-srv"
export WINEPREFIX="${STEAM_COMPAT_DATA_PATH}/pfx"
if [ "$1" = "mods" ]; then
if [ "${XMLSTARLET}" != "" ]; then
echo "Available mods:"
echo
for val in `ls ${STEAMAPPS}/workshop/content/${GAME_ID}`; do
MOD_PATH="${STEAMAPPS}/workshop/content/${GAME_ID}/${val}"
MOD_NAME=`xml sel -t -v "/data/@name" "${MOD_PATH}/mod.xml"`
echo "${MOD_NAME}"
done
fi
exit 0
fi
if [ "$1" = "addmod" ]; then
if [ "${XMLSTARLET}" != "" ]; then
WANTED_MOD_NAME=$2
MOD_COMPATPATH=""
echo "Adding mod ${MOD_NAME}"
for val in `ls ${STEAMAPPS}/workshop/content/${GAME_ID}`; do
MOD_PATH="${STEAMAPPS}/workshop/content/${GAME_ID}/${val}"
MOD_NAME=`xml sel -t -v "/data/@name" "${MOD_PATH}/mod.xml"`
if [ "${MOD_NAME}" = "${WANTED_MOD_NAME}" ]; then
MOD_COMPATPATH=`"${PROTON}" getcompatpath "${MOD_PATH}" 2>/dev/null`
echo "${MOD_NAME}: ${MOD_COMPATPATH}"
xml ed \
-s "/data/active_mod_folders" -t elem -n mod\
-a "/data/active_mod_folders/mod[last()]" -t attr -n name -v "${MOD_NAME}"\
-a "/data/active_mod_folders/mod[last()]" -t attr -n value -v "${MOD_COMPATPATH}"\
server_config.xml >tmp.xml
mv -f tmp.xml server_config.xml
fi
done
if [ "${MOD_COMPATPATH}" = "" ]; then
echo "Could not find mod: ${WANTED_MOD_NAME}"
fi
fi
exit 0
fi
if [ "$1" = "proton" ]; then
if [ "${XMLSTARLET}" != "" ]; then
echo "Current proton: ${PROTON_VERSION}"
echo
for val in "${PROTON_LOCATIONS[@]}"; do
ls "${val}" | grep "Proton" | xargs -i{} echo "{}"
done
fi
exit 0
fi
if [ "$1" = "init" ]; then
# Create our own prefix so that we can run the normal game through steam at the same time as our server
rm -rf "${STEAM_COMPAT_DATA_PATH}"
mkdir -p "${STEAM_COMPAT_DATA_PATH}/pfx"
#cp -ra "${ORIG_STEAM_COMPAT_DATA_PATH}" "${STEAM_COMPAT_DATA_PATH}"
TEMPLATE="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\
<data port=\"25565\" max_players=\"4\" server_name=\"\" password=\"\" island_count=\"16\" team_count_ai=\"1\" team_count_human=\"1\" base_difficulty=\"1\" loadout_type=\"0\" blueprints=\"0\" game_data_path=\"\">\n\
<permissions>\n\
</permissions>\n\
<active_mod_folders>\n\
</active_mod_folders>\n\
</data>\n\
"
echo -e ${TEMPLATE} >server_config.xml
echo -e ${GAME_ID} >steam_appid.txt
if [ "${XMLSTARLET}" != "" ]; then
PERSONA=`grep -m1 PersonaName ${STEAMLOCAL}/config/loginusers.vdf | awk -e '{print $2}'`
eval PERSONA=${PERSONA}
SERVER_NAME="${PERSONA}-CC2"
echo "Server Name: ${SERVER_NAME}"
GAME_DATA_PATH="${STEAMAPPS}/common/${GAME_NAME}/rom_0"
GAME_DATA_COMPATPATH=`"${PROTON}" getcompatpath "${GAME_DATA_PATH}" 2>/dev/null`
echo "Setting data path: ${GAME_DATA_COMPATPATH}"
xml ed \
-u "/data/@game_data_path" -v "${GAME_DATA_COMPATPATH}"\
-u "/data/@server_name" -v "${SERVER_NAME}"\
server_config.xml >tmp.xml
mv -f tmp.xml server_config.xml
for STEAMID in `grep SteamID ${STEAMLOCAL}/config/config.vdf | awk -e '{print $2}'`; do
eval STEAMID=${STEAMID}
echo "Adding ADMIN ${STEAMID}"
xml ed \
-s "/data/permissions" -t elem -n peer\
-a "/data/permissions/peer[last()]" -t attr -n steam_id -v "${STEAMID}"\
-a "/data/permissions/peer[last()]" -t attr -n is_banned -v "false"\
-a "/data/permissions/peer[last()]" -t attr -n is_admin -v "true"\
server_config.xml >tmp.xml
mv -f tmp.xml server_config.xml
done
xml sel -t -v "/data/active_mod_folders/path/@value" "${WINEPREFIX}/drive_c/users/steamuser/AppData/Roaming/Carrier Command 2/mods.xml"
for ACTIVEMOD in `xml sel -t -v "/data/active_mod_folders/path/@value" "${WINEPREFIX}/drive_c/users/steamuser/AppData/Roaming/Carrier Command 2/mods.xml"`; do
echo "Adding mod from game config: ${ACTIVEMOD}"
xml ed \
-s "/data/active_mod_folders" -t elem -n mod\
-a "/data/active_mod_folders/mod[last()]" -t attr -n value -v "${ACTIVEMOD}"\
server_config.xml >tmp.xml
mv -f tmp.xml server_config.xml
done
fi
exit 0
fi
if [ "$1" = "run" ]; then
"${PROTON}" runinprefix "${GAME_PATH}"
exit 0
fi
echo "Available commands: proton, init, mods, addmod, run"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment