Author Topic: HowTo: Set up a Linux Crysis Wars dedicated server  (Read 26826 times)

0 Members and 1 Guest are viewing this topic.

Offline HAARP

  • Living Legend
  • *******
  • Posts: 2340
  • l33tp0intz: +212/-1
  • I regret nothing
    • Clan Jade Wolf
Re: HowTo: Set up a Linux Crysis Wars dedicated server
« Reply #75 on: February 27, 2016, 01:55:44 PM »
Hoo boy, that script is pretty outdated
Any chance re-posting the updated script here again?  ::)

Here you go:
Code: [Select]
# cwdedsvr v0.10.2 by haarp
# Released under the GNU General Public License version 3 or later

# Run the Windows Crysis Wars dedicated server (+ mod) with Wine on Xvfb, requiring no X server
# The Crysis Wars server console will be available through ncurses on the controlling terminal

# Requirements (debian pkg): Xvfb (xvfb), GLX (libgl1-mesa-glx),
# Wine (wine1.3): (also works on Debian),
# Screen (screen) is also recommended

# Howto (verified to work with Wine 1.3.36 and 1.4 on Debian 6 (squeeze) 64-bit):
# - Remove the '.wine' directory in your user's home, if it exists already
# - Create the directories '.wine' and '.wine/drive_c' in your user's home
# - Place a working Crysis Wars installation somewhere below drive_c, e.g. 'drive_c/CrysisWars'
# - For MWLL: Make sure th 'MWLL' folder under 'Mods/' is uppercase
# - Put this script into a file, adjust the paths (see PATHS below) and make it executable
# - Think of a short name for the server (avoid spaces!)
# - The server's root dir will be 'servername' below SERVERS_DIR (see PATHS below), create it
# - Put server.cfg, levelrotation.xml, etc. in it. Logs and stuff will also end up in there
# - You can also put a 'common.cfg' into this dir, which will be executed before server.cfg
# - Run this script without arguments for usage information

# - Useful info for server configuration:

if [[ ! $WINEPREFIX ]]; then WINEPREFIX="$HOME/.wine"; fi

### PATHS AND SETTINGS (avoid very long paths!) --------------------------------------------------------------
DRIVE_C="$WINEPREFIX/drive_c" # Wine's C: drive. WINEPREFIX is $HOME/.wine/ unless set otherwise
WARS_DIR="CrysisWars" # Crysis Wars install dir, relative to DRIVE_C
SERVERS_DIR="CrysisWars/servers" # Container for root dirs of all servers, relative to DRIVE_C
MOD="MWLL" # The mod, empty quotes for no mod (case-sensitive!)
EXECFILE="$HOME/mwll/" # Optional script to exec between server restarts (e.g. map installs)
# $1=full-servers_dir | $2=servername | $3=full-wars_dir | $4=modname
### RUNTIME PATHS (leave these be!) --------------------------------------------------------------------------
pidfile="$DRIVE_C/$SERVERS_DIR/$server/" # Contains $wine_pid; file exists -> server running
wsfile="$DRIVE_C/$SERVERS_DIR/$server/" # Contains $wineserver_pid
autofile="$DRIVE_C/$SERVERS_DIR/$server/.automode" # File exists -> Auto-mode enabled
### ----------------------------------------------------------------------------------------------------------

startserver() {
if [[ "$MOD" = "" ]]; then modarg=""
else modarg="-mod $MOD"

#Spawn wineserver manually so we can get its PID (it will exit on its own after Wine quits)
wineserver -f -p0 &>/dev/null &
echo $! > "$wsfile"

#Background thread that waits until *our* Crysis spawns, then records PID and sets terminal title
until pgrep -u $USER -l -f "CrysisWarsDedicatedServer.exe" | grep -v wineconsole | grep -q "\-root C:/$SERVERS_DIR/$server "; do sleep 0.1; done
pgrep -u $USER -l -f "CrysisWarsDedicatedServer.exe" | grep -v wineconsole | grep "\-root C:/$SERVERS_DIR/$server " | awk '{print $1}' >"$pidfile"
echo -en "\e]2;cwdedsvr: $server\007"
} &

echo "Launching Wine..."
if [[ $debug ]]; then
DISPLAY=":$xdisplay" WINEDEBUG="err-winediag" WINEDLLOVERRIDES="mshtml=" wine "$DRIVE_C/$WARS_DIR/Bin32/CrysisWarsDedicatedServer.exe" $modarg -root "C:/$SERVERS_DIR/$server" +exec common.cfg +exec server.cfg
DISPLAY=":$xdisplay" WINEDEBUG="-all" WINEDLLOVERRIDES="mshtml=" wineconsole --backend="curses" "$DRIVE_C/$WARS_DIR/Bin32/CrysisWarsDedicatedServer.exe" $modarg -root "C:/$SERVERS_DIR/$server" +exec common.cfg +exec server.cfg
echo "Wine has quit."

rm "$pidfile" &>/dev/null
rm "$wsfile" &>/dev/null

startxvfb() {
xdisplay=10 #Count up from 10 until unused display is found
while [[ -e /tmp/.X$xdisplay-lock ]]; do

xvfbout="$(mktemp --suffix ".xvfb")"
Xvfb :$xdisplay -screen 0 1x1x24 -nolisten tcp &>"$xvfbout" &

sleep 1

if [[ ! -e /tmp/.X$xdisplay-lock ]]; then
tail -n3 "$xvfbout"
rm "$xvfbout"
echo "Xvfb failed to start. Aborting!"
exit 1

echo "Xvfb started on DISPLAY=:$xdisplay."
rm "$xvfbout"
stopxvfb() {
echo "Stopping Xvfb..."
#Even with the trap in place, Ctrl+C will immediately kill Xvfb...
kill $xvfb_pid &>/dev/null

checkrun() {
#Path sanity checks
if [[ ! -f "$DRIVE_C/$WARS_DIR/Bin32/CrysisWarsDedicatedServer.exe" ]]; then
echo "WARS_DIR wrong or bad Crysis install (see the PATHS section in this script). Aborting!"; exit 1
elif [[ ! "$MOD" = "" && ! -f "$DRIVE_C/$WARS_DIR/Mods/$MOD/info.xml" ]]; then
echo "Mod '$MOD' not found (case-sensitive). Aborting!"; exit 1
elif [[ ! -d "$DRIVE_C/$SERVERS_DIR/$server" || ! -w "$DRIVE_C/$SERVERS_DIR/$server" ]]; then
echo "Server dir wrong or bad server name (see the PATHS section in this script). Aborting!"; exit 1

#Abort if server running already, silently remove pidfiles if exists but not running
if [[ -e "$pidfile" ]]; then
if kill -0 $(cat "$pidfile") &>/dev/null; then
echo "Server already running. Aborting!"
exit 1
rm "$pidfile" &>/dev/null
rm "$wsfile" &>/dev/null

#Silently remove $autofile if exists
if [[ -e "$autofile" ]]; then rm "$autofile"; fi

echo "Preliminary checks completed."
sleep 3

usage() {
echo "Usage: $(basename "$0") servername {auto|single|restart|stop|status} [debug]"
echo "------"
echo "'auto': Auto-mode; restart the server in the event of a crash."
echo "'single': No Auto-mode; terminate when server shuts down. Great for testing!"
echo "'restart': Quit the current server, let auto-mode restart if active."
echo "'stop': Quit the current server, disable auto-mode."
echo "'status': Display the current server status."
echo "'debug': (optional) Display Wine log instead of the server console."
echo "------"
echo "Suggestion: Run with screen to keep the server running when you log out. e.g."
echo "'screen -S gregsbox $(basename "$0") gregsbox auto'"
echo "(detach with Ctrl+a, d  re-attach with 'screen -r gregsbox')"

status() {
if kill -0 $(cat "$pidfile" 2>/dev/null) &>/dev/null; then
crysis_pid=$(cat "$pidfile")
crysis_mem=$[ $(ps -o rss -p $crysis_pid | tail -n1) /1024 ]

wineserver_pid=$(cat "$wsfile")
wineserver_mem=$[ $(ps -o rss -p $wineserver_pid | tail -n1) /1024 ]

echo "Running! RAM usage (MB):"
echo "Crysis: $crysis_mem"
echo "Wineserver: $wineserver_mem"
exit 0
echo "Not running!"
exit 1

if [[ $# -lt 2 || $# -gt 3 ]]; then usage; fi
if [[ $# = 3 && ! "$3" = "debug" ]]; then usage; fi
if [[ "$3" = "debug" ]]; then debug=1; fi

case "$2" in
trap 'rm "$autofile" &>/dev/null; kill $(cat "$pidfile" 2>/dev/null) &>/dev/null; break' SIGHUP SIGINT SIGTERM
touch "$autofile"
while [[ -f "$autofile" ]]; do

[[ -x "$EXECFILE" ]] && "$EXECFILE" "$DRIVE_C/$SERVERS_DIR" "$server" "$DRIVE_C/$WARS_DIR" "$MOD"

test -f "$autofile" || break

echo -n "Press Ctrl+C to exit now! Restarting in "
for i in {5..1}; do echo -n "${i}.."; sleep 1; done; echo ""

trap 'kill $(cat "$pidfile" 2>/dev/null) &>/dev/null' SIGHUP SIGINT SIGTERM

if [[ -e "$pidfile" ]]; then
echo "Terminating server."
kill $(cat "$pidfile")
else echo "Server not running."

if [[ -e "$autofile" ]]; then
echo "Disabling auto-mode."
rm "$autofile"
if [[ -e "$pidfile" ]]; then
echo "Terminating server."
kill $(cat "$pidfile")
else echo "Server not running."


exit 0

# ChangeLog:
# 0.10.2:
# -Better EXECFILE handling
# 0.10.1:
# -Better WINEPREFIX handling
# 0.10.0:
# -Added support for optional common.cfg
# -Now records wineserver_pid to ensure correct memory usage display
# 0.9.3:
# -Disabled Xvfb listening on TCP port (wasn't needed, improves security)
# 0.9.2:
# -Modified script so each server spawns its own Xvfb
# 0.9.1:
# -Added EXECFILE capability
# 0.9:
# -Turned the servername into a commandline argument
# 0.8.4:
# -Small tweaks
# -Reverted port and rcon to reside inside server.cfg again
# 0.8.2:
# -$pidfile now points to the actual CrysisWarsDedicatedServer.exe PID
# 0.8:
# -Can run several servers on one machine now
# 0.7.1:
# -Long command line no longer runs the risk of getting truncated by Wine
# -Requirement for xprop removed again
# 0.7:
# -Major overhaul of documentation comments
# -More checks
# -Defeated the Gecko dialog once and for all
# -Running without mod (vanilla) now possible
# 0.6.2:
# -Minor tweaks
# -Mod selection now possible via variable
# 0.6.1:
# -Script now checks whether Xvfb started correctly and displays its output if not
# -Automatically find free X display starting at :10 instead of hardcoding :90
# -Added 'debug' command line option to show Wine log instead of server console
# 0.6:
# -Crysis server console is now available on the controlling terminal
# -Revised the entire script for increased durability
# -Added a ton of explanations and infos
# -Added and clarified usage (command-line options)
# -Put paths into variables for easier customization
# -Extracted port and RCON settings into variables
# -Removed dependency on xvfb-run and at the same time slightly improved performance
# -Will no longer kill all instances of Xvfb, only the one it spawned itself
# -Will no longer kill all instances of Wine, only CrysisWarsDedicatedServer.exe

# TODO: Handle other Wineapps already running on same WINEPREFIX (wineserver wont start)
# (documentation issue?)
# TODO: Check if a server already running in current prefix, then abort
# (we can't have different Xvfb but same wineserver!)
# BUG: Resize wineconsole ncurses window with controlling terminal (Wine bug 30193)
# BUG: wineserver leaks a lot of memory (Wine bug 30415)
# BUG: Server console cursor disappears when running inside screen
# BUG: Using HTTP RCon can sometimes lag or even hang the server. Wine bug?
# LIMIT: Wine truncates very long command lines. I would write the cmd into a file
#  and execute it with cmd /c, but that seems to crash the server after mapload (?!)

ignore these other shitty knockoffs
« Last Edit: February 27, 2016, 02:01:21 PM by HAARP »
don't bother sending me PMs, I probably won't be reading them in time.

Offline Starch1ld

  • Lance Captain
  • ***
  • Posts: 688
  • l33tp0intz: +47/-25
  • hi
Re: HowTo: Set up a Linux Crysis Wars dedicated server
« Reply #76 on: March 01, 2016, 06:15:51 PM »
oh wow, now you can start multiple servers from the same script. Not bad, sir.  ::)

and thanks, btw
« Last Edit: March 01, 2016, 06:47:29 PM by Star Wraith »

Offline cest73

  • Star Captain
  • ***
  • Posts: 763
  • l33tp0intz: +22/-19
  • there are links in my signature -->
    • MW:LL game status online (kudos: Spooky)
Re: HowTo: Set up a Linux Crysis Wars dedicated server
« Reply #77 on: March 06, 2016, 06:41:19 PM »
kind thanks  ;D