#!/bin/bash ###################################################################### # Artemis Nebula Artemis script, (C) 2015-2020 Nosey Nick Waterman, # https://noseynick.org/artemis/nebula/ # All wrong righted, all rights reserved. Licensed under thev GNU # Affero General Public License v3.0 https://www.gnu.org/licenses/agpl.txt # with Commons Clause https://commonsclause.com/ v1.0 ###################################################################### # shellcheck disable=SC1090 # don't parse when shellchecking: . ~/bin/conf.sh [[ "$DISPLAY" ]] || export DISPLAY=:20 cd || exit 9 if [[ "$EE_VER" ]]; then banner Run EE pkill EmptyEpsilon ; sleep 2 ; pkill -9 EmptyEpsilon ; sleep 2 # shellcheck disable=SC2086 # deliberate word splitting of $EE_OPTS /usr/local/bin/EmptyEpsilon ${EE_PROXY:+proxy=$EE_PROXY} ${EE_OPTS} >> ~/logs/EE.log 2>&1 & [[ "$RUNTEST" ]] && nebula "$RUNTEST" bash exit 0 elif cd 0.* || cd 0-*; then banner Artemis Cosmos PRE-RELEASE pkill -f Artemis3-x64-release.exe; pkill wineserver64; pkill winedbg sleep 2 pkill -f -9 Artemis3-x64-release.exe; pkill -9 wineserver64; pkill -9 winedbg pulseaudio --start # winetricks arch=64 win10 sound=pulse d3dx9 d3dcompiler_47 winetricks arch=64 win7 sound=pulse d3dx9 d3dcompiler_47 rm -rfv ~/.cache # -- bit tight on space? # nebula https://aka.ms/vs/17/release/vc_redist.x64.exe wine /passive # x-terminal-emulator -e wine Artemis3-x64-release.exe & wine Artemis3-x64-release.exe & RUNNING='' for X in {40..1}; do date "+#### %F %T : Waiting $X secs for cosmos..." sleep 1 # Test for window AND move it to avoid "off the left of the screen" bug: if xdotool search --name Engine windowmove 0 -5; then RUNNING=yes; break fi done if [[ "$RUNNING" ]]; then banner "Nebula Cosmos server is ready! *start game $IP ${NAME:-[Mod]} [level]" else banner Cosmos failed to start properly fi exit 0 fi banner Artemis mods and config cd 2.* || exit 9 pkill Artemis.exe ; pkill wineserver32 sleep 2 pkill -9 Artemis.exe ; pkill -9 wineserver32 [[ "$MISSIONS" ]] && nebula missions bash echo "$MISSIONS" | grep -q 'nginecho' && crontab - <<__EOF__ # m h dom mon dow command */30 * * * * ~/bin/missions > ~/logs/missions.log 2>&1 $(crontab -l | grep -Ev '^# m |missions') __EOF__ grep -q ^gameWindowMode= artemis.ini || cat >> artemis.ini <<__INI__ ; Added for NoseyNick "Nebula": gameWindowWidth=${NEB_WIDTH:-1280} gameWindowHeight=${NEB_HEIGHT:-700} gameWindowMode=2 __INI__ PORT=2010 if [[ "$HERMES" ]]; then PORT=2011 # for Artemis itself. Hermes will listen on regular 2010 sed -i~ -e '/networkPort/ d' artemis.ini echo networkPort=$PORT >> artemis.ini [[ "$HERMES_STARTUP" ]] || HERMES_STARTUP=dummy # 0-byte file nebula https://github.com/StarryWisdom/hermes-bin/raw/master/hermes nebula "$HERMES" "ln -fs" ~/bin/hermes_connect.lua # probably the ship names nebula "$HERMES_STARTUP" "ln -fs" ~/bin/hermes_startup.lua # probably 0 bytes ( cd ~/bin && hermes >> ~/logs/hermes.log 2>&1) & # will die PDQ if port already in use. # Check with a comms client by sending: /hermes version fi # to dismiss requests for Mono and .net and stuff: WINEDLLOVERRIDES="mscoree,mshtml=" wineboot -u # OLD WAY: # DISPLAY=DUMMY wine regedit '/?' >/dev/null # sleep 7 # Seems to reduce liklihood that Artemis.exe will crash on first run? :-/ ###################################################################### # Some TCP tuning: # See also https://pracucci.com/linux-tcp-rto-min-max-and-tcp-retries2.html sudo sysctl -f - <<__TUNING__ net.ipv4.tcp_fin_timeout=5 # restart quicker after server crash net.ipv4.tcp_retries1 = 2 # fewer retries net.ipv4.tcp_retries2 = 4 # fewer retries - just over 10sec net.ipv4.tcp_keepalive_time=5 # probe conns after N secs of idle net.ipv4.tcp_keepalive_intvl=3 # probe dead conns every N secs net.ipv4.tcp_keepalive_probes=3 # ... and kill them after N tries net.ipv4.tcp_tw_reuse=1 # to re-use conns in TIMEWAIT __TUNING__ ###################################################################### # Check port is free SS=netstat [[ -x /usr/bin/ss ]] && SS=/usr/bin/ss for X in {20..1}; do date "+#### %F %T : Checking TCP port $PORT is free ($X)..." $SS -apn 2>&1 | grep "^tcp.*:$PORT" || break sleep 5 done ###################################################################### # ++++++++++++++++++ Consider DxWnd? https://sourceforge.net/projects/dxwnd/ # https://artemis.forumchitchat.com/post/windows-10-performance-fix-increase-frame-rate-4x-10103464?highlight=fps # ACTUALLY RUN ARTEMIS: # ++++++ devnull until Thom fixes Simulation::Tick-NNN Player::Tick-NNN spam: wine Artemis.exe >/dev/null & cd || exit RUNNING='' for X in {40..1}; do date "+#### %F %T : Waiting $X secs for server..." sleep 1 if $SS -apn 2>&1 | grep 0.0.0.0:$PORT; then RUNNING=yes; break; fi timeout 1 click-SERVER done ###################################################################### # IF we are running... if [[ "$RUNNING" ]]; then sleep 2 # to give GUI time to catch up timeout 1 click-FPS timeout 1 click-game-solo sleep 1 if [[ "$SHIPS" ]]; then # shellcheck disable=SC2086 # deliberately word splitting: nebula $SHIPS perl | nc -q2 127.1 2010 | parser.pl sleep 1 | nc -q2 127.1 2010 | parser.pl fi banner "Nebula Server is ready! *start game $IP ${NAME:-[Mod]} [level]" # If we have an IP, and a channel/token/script for discord: if [[ "$IP" ]] && [[ -x ~/bin/discord.sh ]]; then echo "Nebula Server is ready! *start game $IP ${NAME:-[Mod]} [level]" \ | discord.sh --send DISC_ARG=--discord fi BLINK=0 nebula logger.sh bash --loop --heartbeat --up $DISC_ARG \ 127.0.0.1 Nebula "$NAME" \ >> logs/logger.log 2>&1 & [[ "$RUNTEST" ]] && nebula "$RUNTEST" bash else banner Artemis failed to start properly fi # ++++++++++ AUTO SHUTDOWN on empty? # ++++++++++ Puppy / comms accept commands to customise, shutdown, etc?