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.
252 lines
5.0 KiB
252 lines
5.0 KiB
#!/bin/bash |
|
# provide remote control for demo_player |
|
name=${0##*/} |
|
log=/opt/uatv/tmp/uatv_log |
|
|
|
info () { printf '%s: %s: %s\n' "$name" "$$" "$1" | logger ; } |
|
warn () { info "$1"; printf '%s: %s\n' "$name" "$1" >&2; } |
|
quit () { warn "$1"; exit 1; } |
|
info "$(date) $*" |
|
|
|
inwee=/opt/uatv/bin/inwee |
|
tmp=/opt/uatv/tmp/ |
|
html=/var/www/htdocs/ultronoarena.com/info/ |
|
url=https://ultronoarena.com/info |
|
help=https://ultronoarena.com/info/bot_help.txt |
|
|
|
extracter=/opt/uatv/extracter |
|
exdir=/opt/uatv/ |
|
series_gen=/opt/uatv/utils/series_gen |
|
|
|
save=/opt/uatv/output/favorite_games.txt |
|
out=/opt/uatv/ua/demo_selection |
|
livefile=/opt/uatv/livefile |
|
requestfile=/opt/uatv/requestfile |
|
demo_selection=/opt/uatv/ua/demo_selection |
|
demofile=/opt/uatv/demofile |
|
demoloc=/opt/uatv/demos |
|
maplist='^uamap[1-9]$|^uamap1[1-9]$|^uamap[37]b$|^uamap4_orig$' |
|
|
|
instances=$(pgrep remote_controler | wc -l) |
|
|
|
ball_script=/opt/uatv/utils/ball_adder |
|
demo_player=/opt/uatv/demo_player |
|
match_render=/opt/uatv/match_render |
|
stat_chatter=/opt/uatv/utils/stat_chatter |
|
pids=/opt/uatv/pids |
|
|
|
export DISPLAY=:0.0 |
|
|
|
if ((instances<7)); then |
|
info "instances: $(printf '%s\n' "$((instances-1))/7" )" |
|
else |
|
quit "too many instances" |
|
fi |
|
|
|
parser () { |
|
while (($#)); do |
|
case $1 in |
|
!ua) |
|
shift # it's the trigger |
|
;; |
|
--buffer) |
|
buffer=$2 |
|
shift 2 |
|
;; |
|
resume|play|unpause) |
|
resume_demo |
|
;; |
|
stats) |
|
$stat_chatter "$buffer" |
|
exit |
|
;; |
|
stop) |
|
stop_show |
|
;; |
|
help) |
|
bot_help |
|
;; |
|
score) |
|
disp_score |
|
;; |
|
next) |
|
next_game |
|
;; |
|
map) |
|
map_thinger "$2" |
|
;; |
|
live) |
|
its_live |
|
;; |
|
note) |
|
shift |
|
flavor_savor "$@" |
|
;; |
|
extract) |
|
extract "$@" |
|
;; |
|
demo) |
|
demo "$2" |
|
;; |
|
bo*) |
|
info "series_gen called" |
|
printf '%s\n' "$($series_gen "$@")"| $inwee -b "$buffer" |
|
exit |
|
;; |
|
np) |
|
current_demo |
|
;; |
|
start) |
|
start_show |
|
;; |
|
ball) |
|
info "ball called" |
|
"$ball_script" |
|
exit |
|
;; |
|
*) |
|
warn "warning: unknown option (ignored): $1" |
|
shift |
|
;; |
|
esac |
|
done |
|
} |
|
start_show () { |
|
if test -f "$pids"; then |
|
printf '%s\n' "we've already started" | $inwee -b "$buffer" |
|
exit |
|
fi |
|
|
|
"$demo_player" & |
|
printf '%s\n' "$!" >> "$pids" |
|
|
|
"$match_render" & |
|
printf '%s\n' "$!" >> "$pids" |
|
|
|
printf '%s\n' "starting show" | $inwee -b "$buffer" |
|
|
|
exit |
|
} |
|
stop_show () { |
|
#TODO |
|
#anyone can stop the recording of the spheres |
|
if test -f "$livefile"; then |
|
printf '%s\n' "there is no stopping the spheres" |
|
exit |
|
fi |
|
|
|
cat "$pids" | xargs kill |
|
rm "$pids" |
|
printf '%s\n' "stopping show" | $inwee -b "$buffer" |
|
exit |
|
} |
|
|
|
current_demo () { |
|
if ! test -f "$pids"; then |
|
printf '%s\n' "offline" | $inwee -b "$buffer" |
|
exit |
|
fi |
|
|
|
read -r var < "$demo_selection" |
|
info "var is $var" |
|
printf '%s\n' "now playing:" "$var" | $inwee -b "$buffer" |
|
var=${var##*demos\/} |
|
var=${var%%\/*} |
|
info "var is $var" |
|
extract "--date" "$var" |
|
exit |
|
} |
|
|
|
demo () { |
|
info "specific demo requested" |
|
if test -f "$demoloc/$1"; then |
|
printf '%s\n' "demo $demoloc/$1" > "$demo_selection" |
|
# printf '%s\n' "OK" | $inwee -b "$buffer" |
|
touch "$demofile" |
|
next_game |
|
else |
|
printf '%s\n' "sorry i cannot find that demo. please try again." | $inwee -b "$buffer" |
|
fi |
|
exit |
|
} |
|
bot_help () { |
|
info "bot help requested yeye" |
|
printf '%s\n' "$help" | $inwee -b "$buffer" |
|
exit |
|
} |
|
extract () { |
|
info "extracter called" |
|
info "extractor functions \$* is $*" |
|
|
|
out="$tmp/$(date +%Y-%m-%d)" |
|
mkdir "$out" |
|
for ((i=0;i<99;i++)); do |
|
test ! -f "$out/$i.txt" && break |
|
done |
|
cd "$exdir" || quit "failed to cd $exdir" |
|
info "passing $* to extracter" |
|
$extracter "$@" > "$out/$i.txt" |
|
scp -r "$out" www:"$html" |
|
printf '%s\n' "$url/$(date +%Y-%m-%d)/$i.txt" | $inwee -b "$buffer" |
|
exit |
|
} |
|
flavor_savor () { |
|
info "game noted" |
|
printf '%s\n' "game noted" |
|
# are we saving a live game or a demo? |
|
if [[ $(wc -l "$out" | awk '{print $1}') == 4 ]]; then |
|
info "live game saved" |
|
var=$(awk 'NR==3 { print $2}' "$out") |
|
else |
|
info "demo saved" |
|
var=$(awk '{print $2}' "$out") |
|
fi |
|
map=$(strings "$var" | head -n1 ) |
|
printf '%s\n' "***" "$map" "!ua demo ${var##*demos/}" "$*" >> "$save" |
|
quit |
|
} |
|
its_live () { |
|
info "its_live called" |
|
touch "$livefile" |
|
next_game |
|
} |
|
map_thinger () { |
|
info "map_thinger gets $1" |
|
if test -n "$1"; then |
|
if [[ "$1" =~ $maplist ]]; then |
|
printf '%s\n' "$1" > "$requestfile" |
|
next_game |
|
else |
|
printf '%s\n' "!ua map failed to parse a good map" | $inwee -b "$buffer" |
|
fi |
|
fi |
|
quit "map thinger failed to parse a good map" |
|
} |
|
next_game () { |
|
if ! test -f "$pids"; then |
|
start_show |
|
fi |
|
wineserver -k |
|
quit "exiting brutal next_game function" |
|
} |
|
stop_demo () { |
|
xdotool search --name "ultrono arena" key s |
|
printf '%s\n' "demo stopped" | $inwee -b "$buffer" |
|
quit "exiting stop_demo function" |
|
} |
|
resume_demo () { |
|
xdotool search --name "ultrono arena" key r |
|
printf '%s\n' "demo resumed" | $inwee -b "$buffer" |
|
quit "exiting stop_demo function" |
|
} |
|
disp_score () { |
|
xdotool search --name "ultrono arena" keydown Tab |
|
# printf '%s\n' "beep" | $inwee -b "$buffer" |
|
sleep 10 |
|
xdotool search --name "ultrono arena" keyup Tab |
|
quit "exiting display_score function" |
|
} |
|
|
|
parser "$@" |
|
|
|
|
|
|