UltronoArena TV https://ultronoarena.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

129 lines
3.2 KiB

#!/bin/bash
# play ultrono arena demos
name=${0##*/}
info () { printf '%s: %s: %s\n' "$name" "$$" "$1" | logger; }
warn () { info "$1"; printf '%s: %s\n' "$name" "$1" >&2; }
quit () { warn "$1"; exit 1; }
autoexec=/opt/uatv/ua/autoexec.cfg # file for game settings
DISPLAY=:0.0 # Xvfb display
demofile=/opt/uatv/demofile # temporary file set by remote_controller (rc)
demos=/opt/uatv/demos # location of demos
game=/opt/uatv/ua/ua.exe # game binary
game_dir=/opt/uatv/ua # bin dir
livefile=/opt/uatv/livefile # temp file set by rc
out=/opt/uatv/ua/demo_selection # file loaded by game autoexec
requestfile=/opt/uatv/requestfile # temp file contains map requests from chat set by rc
# initial setup of xvfb.
# confirm aloop module, game
init () {
export DISPLAY=:0.0
Xvfb :0 -screen 0 448x336x24 &
pid0=$!
test "$(find /lib/modules/"$(uname -r)" -type f -name 'snd-aloop.ko')" || quit "snd-aloop gone"
test "$(lsmod | grep -c snd_aloop)" -gt 3 || quit "snd_aloop module check failed"
test -f "$HOME/.asoundrc" || quit "asoundrc not found"
test -f "$game" || quit "game not found at $game"
test -f "$autoexec" || quit "autoexec not found at $autoexec"
cd "$game_dir" || quit "cd game dir $game_dir failed"
}
# look for updates from the remote controller
# live game preparation
checker () {
demo=
live=
request=
test -f "$requestfile" && read -r request < "$requestfile" && rm "$requestfile"
test -f "$demofile" && ((++demo)) && rm "$demofile"
test -f "$livefile" && ((++live)) && rm "$livefile"
if test -n "$live"; then
dfile="$demos/$(date -I)"
mkdir "$dfile"
for ((i=0;i<99;i++)); do
test ! -f "$dfile/$i" && touch "$dfile/$i" && break
done
fi
}
# select a demo
selecter () {
check=
maps='uamap[1-9]|uamap1[1-9]'
if test -z "$request"; then
until [[ "$check" =~ $maps ]]; do
selection=$(find "$demos" -type f -size +2500k ! -path '*other*' | sort -R | head -n1)
check=$(strings "$selection" | head -n1)
done
else
until [[ "$check" == "$request" ]]; do
selection=$(find "$demos" -type f -size +2500k ! -path '*other*' | sort -R | head -n1)
check=$(strings "$selection" | head -n1)
done
fi
# try and filter some old maps out
fract='uamap[458]'
if [[ "$check" =~ $fract ]]; then
if ! [[ "$selection" =~ 202? ]]; then
return 1
fi
fi
printf '%s\n' "demo $selection" > "$out"
info "playing $selection"
info "map: $check"
}
pover () {
# change point of view
while true; do
var=${RANDOM: -1:1}
sleep 10
if [[ "$var" =~ ^[0-3] ]]; then
xdotool search --name "ultrono arena" click 1
fi
done &
pid1=$!
}
# start
init
pover
# cleanup when killed
trap ' info "killing xvfb ${pid0} and pover ${pid1}";
kill -1 "${pid0}";
kill -1 "${pid1}"' 0
while true; do
# ingest rc updates
checker
# if not live and without a specific request
# select a demo
if test -z "$live"; then
if test -z "$demo"; then
time=11m
selecter
until [[ "$?" != 1 ]]; do
selecter
done
fi
# else write commands for dav1d_tv
else
info "live stream called"
info "recording $dfile/$i"
time=31m
cat > "$out" << EOF
name dav1d_tv
connect broodwar
spec
record $dfile/$i
EOF
fi
# launch game
timeout "$time" nice -n 14 wine "$game" client
done