From c0e38b3d008c2aa07c7cd03a0ce74edbaf05f8e5 Mon Sep 17 00:00:00 2001 From: epoch Date: Tue, 14 Apr 2020 11:49:04 +0000 Subject: added a bunch of the hackvr-server scripts --- share/hackvr/examples/hackvrd/hackvr-subsystem | 5 ++ share/hackvr/examples/hackvrd/hackvrd.sh | 112 +++++++++++++++++++++++++ share/hackvr/examples/hackvrd/ident | 16 ++++ share/hackvr/examples/hackvrd/list_to_cubes.sh | 33 ++++++++ share/hackvr/examples/hackvrd/multi.sh | 10 +++ share/hackvr/examples/hackvrd/radio.sh | 70 ++++++++++++++++ 6 files changed, 246 insertions(+) create mode 100755 share/hackvr/examples/hackvrd/hackvr-subsystem create mode 100755 share/hackvr/examples/hackvrd/hackvrd.sh create mode 100755 share/hackvr/examples/hackvrd/ident create mode 100755 share/hackvr/examples/hackvrd/list_to_cubes.sh create mode 100755 share/hackvr/examples/hackvrd/multi.sh create mode 100755 share/hackvr/examples/hackvrd/radio.sh diff --git a/share/hackvr/examples/hackvrd/hackvr-subsystem b/share/hackvr/examples/hackvrd/hackvr-subsystem new file mode 100755 index 0000000..ad99b84 --- /dev/null +++ b/share/hackvr/examples/hackvrd/hackvr-subsystem @@ -0,0 +1,5 @@ +#!/bin/bash +if [ "$1" ];then + derp="$USER action $1" +fi +cat <(echo $derp) /dev/stdin | ncat 127.0.0.1 1337 diff --git a/share/hackvr/examples/hackvrd/hackvrd.sh b/share/hackvr/examples/hackvrd/hackvrd.sh new file mode 100755 index 0000000..39054a3 --- /dev/null +++ b/share/hackvr/examples/hackvrd/hackvrd.sh @@ -0,0 +1,112 @@ +#!/usr/bin/env bash + +OUR_HOST=$(/usr/local/libexec/sockip | head -n1) +THEIR_HOST=$(/usr/local/libexec/peerip | head -n1) +OUR_PORT=$(/usr/local/libexec/sockip | tail -n1) +THEIR_PORT=$(/usr/local/libexec/peerip | tail -n1) + +log=/var/log/log.hackvr + +# some hackvr scripts use USER for commanding the player +if USER=$(ident $OUR_HOST $THEIR_HOST 113 $THEIR_PORT $OUR_PORT);then + export USER +else + printf "%s does not have an ident daemon running.\n" "$THEIR_HOST" >> $log + exit 1 +fi + +if [ ! "$USER" ];then + exit 1 +fi +printf "%s@%s connected to hackvr\n" "$USER" "$THEIR_HOST" >> $log + +last_pong=$(date +%s) +wat=true + +while true;do + while read -t 10 group action target args;do + printf "hackvr line: %s\n" "$group $action $target" >> $log + if [ "$group" = "$USER" -a "$action" = "pong" ];then + printf '%s@%s ponged on hackvr\n' $USER $THEIR_HOST >> $log + last_pong="$(date +%s)" + fi + if [ "$group" = "$USER" -a "$action" = "quit" ];then + break + fi + if [ "$action" = "action" ];then + if [ "$target" = "/links" ];then + printf "%s deleteallexcept %s\n" "$USER" "$USER" + off=-10 + for link in gopher://thebackupbox.net/;do + off=$[$off + 10] + printf '<%s> addshape 4 3 0 0 0 0 8 0 8 0 0\n' "$link" + printf '%s' "$link" | makelabel.sh "<$link>" 8 0 0 + printf '<%s> move 0 %d 0\n' "$link" "$off" + done + target=/ + fi + if [ $target = "/radio" ];then + printf "$USER deleteallexcept $USER\n" + ./radio.sh + target=/ + fi + if [ $target = "/ttt" ];then + printf "$USER deleteallexcept $USER\n" + cd /usr/local/src/hackvr/share/hackvr/examples/tictactoe + ./game.sh 2>/dev/null + target=/ + fi + if grep "^/dun" <<< "$target" 2>&1 >/dev/null;then + printf "$USER deleteallexcept $USER\n" + export seed="$(printf "%s\n" "$target" | cut -d/ -f3)" + cd /usr/local/src/hackvr/share/hackvr/examples/dungen + ./dunexplore.sh 2>/dev/null + target=/ + fi + if [ $target = "/multi" ];then + /var/hackvr/multi.sh + target=/ + fi + if [ $target = "/map" ];then + printf "$USER deleteallexcept $USER\n" + cd /usr/local/src/hackvr/share/hackvr/examples/anonet_map + ./map 2>/dev/null + printf '/ addshape 4 3 0 0 0 0 8 0 8 0 0\n' + while read group action target args;do + if [ "$action" = "action" ];then + if [ "$target" = "/" ];then + break + fi + fi + done + target=/ + fi + if [ $target = "/" ];then + printf "%s deleteallexcept %s\n" "$USER" "$USER" + cd /usr/local/src/hackvr/share/hackvr/examples/hackvrd + off=-10 + for name in ttt dun map multi links radio;do + off=$[$off + 10] + printf '/%s addshape 4 3 0 0 0 0 8 0 8 0 0\n' "$name" + printf '/%s' "$name" | makelabel.sh "/$name" 8 0 0 + printf '/%s move 0 %d 0\n' $name $off + done + fi + else + if $wat;then + wat=false + printf '/ addshape 4 3 0 0 0 0 8 0 8 0 0\n' + printf 'welcome' | makelabel.sh / 8 0 0 + fi + fi + done + #printf "pinging... %s@%s\n" "$USER" "$THEIR_HOST" >> /var/log/hackvr.all + #printf "%s ping %s\n" "$USER" "thebackupbox.net" + #if [ $[$(date +%s) - $last_pong] -gt 30 ];then #they probably pinged out. + # printf '# you pinged out. gotta respond to those, dude.\n' + # printf "%s@%s pinged out from hackvr\n" "$USER" "$THEIR_HOST" >> /var/log/hackvr.all + # exit 1 + #fi +done + +printf "%s@%s disconnected from hackvr\n" "$USER" "$THEIR_HOST" >> $log diff --git a/share/hackvr/examples/hackvrd/ident b/share/hackvr/examples/hackvrd/ident new file mode 100755 index 0000000..f4e7599 --- /dev/null +++ b/share/hackvr/examples/hackvrd/ident @@ -0,0 +1,16 @@ +#!/bin/sh +if [ $# -lt 4 ];then + echo usage: ident.sh our-host their-host 113 their-port our-port + exit 1 +fi +REMOTE_PORT="$4" +SERVER_PORT="$5" +IDENT_PORT="$3" +REMOTE_ADDR="$2" +SERVER_ADDR="$1" +username="$(printf "%s, %s\r\n" "$REMOTE_PORT" "$SERVER_PORT" | (ncat -s "$SERVER_ADDR" "$REMOTE_ADDR" "$IDENT_PORT" 2>/dev/null || echo 'ERROR:ERROR:ERROR:ERROR') | tr -d '\r' | cut -d: -f4)" +if [ "$username" ];then + printf "%s\n" "$username" +else + exit 1 +fi diff --git a/share/hackvr/examples/hackvrd/list_to_cubes.sh b/share/hackvr/examples/hackvrd/list_to_cubes.sh new file mode 100755 index 0000000..0dfca06 --- /dev/null +++ b/share/hackvr/examples/hackvrd/list_to_cubes.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash +# blank lines deleteallexcept epoch +# expected input format: +# +# line1 +# line2 +# line3 +# +# line1 +# line2 +j=1 +r=200 +while read -r line;do + if [ "_$line" != '_' ];then +# ../tools/obj2hackvr.pl "$line" ../meshes/cube.obj + #turn line into hex to prevent stupid shit + hexline="$(printf "%s" "$line" | xxd -p | tr -d '\n')" + printf "%s addshape 18 3 8 %d %d 0 %d %d 0 %d %d\n" "$hexline" "$j" "$r" "$[$j+8]" "$r" "$j" "$r" + cd .. + printf "%s\n" "$line" | tee /dev/stderr | makelabel.sh "$hexline" 15 $j $r + cd filebrowser + #printf "%s move 0 %d %d 0 0 0 0 0 0\n" "$hexline" "$i" "$r" + printf "%s rotate 0 %d 0\n" "$hexline" "$[i * 3]" + #somehow printf '%s\n' "$line" | ./testfont.sh and make its output belong to same group as $line.. sed? + i=$[i+10] + j=$[j+4] + else + cat camera.pos + printf "USER deleteallexcept USER\n" #deleteallexcept doesn't have gr deletions yet I think. + j=0 + i=0 + fi +done diff --git a/share/hackvr/examples/hackvrd/multi.sh b/share/hackvr/examples/hackvrd/multi.sh new file mode 100755 index 0000000..525f981 --- /dev/null +++ b/share/hackvr/examples/hackvrd/multi.sh @@ -0,0 +1,10 @@ +#!/bin/bash +printf 'user: %s joined multi\n' "$USER" >> /var/log/hackvr.all +cat /var/cache/hackvr/world_history <(echo 'root export *') \ + | egrep -v '^#|^[^ ][^ ]* *quit' \ + | grep -v 'move [a-z]' \ + | /usr/local/bin/hackvr_headless 2>/dev/null \ + | sed 's/^root_//g' +tail -f -n0 /var/cache/hackvr/world_history \ + | grep --line-buffered -v '^'"$USER"' ' & +tee -a /var/cache/hackvr/world_history >/dev/null diff --git a/share/hackvr/examples/hackvrd/radio.sh b/share/hackvr/examples/hackvrd/radio.sh new file mode 100755 index 0000000..e3f915f --- /dev/null +++ b/share/hackvr/examples/hackvrd/radio.sh @@ -0,0 +1,70 @@ +#!/usr/bin/env bash +log=/var/log/log.hackvr + +button="-2 2 1 2 2 1 2 -2 1 -2 -2 1" + +printf " addshape 6 4 -2 6 0 2 6 0 2 2 0 -2 2 0\n" +printf " +name=radio_play +printf "%s addshape 4 4 %s\n" "$name" "$button" +printf "radio_play addshape 4 3 -1 1 0 1 0 0 -1 -1 0\n" +printf "radio_play move -10 0 0\n" +# || +name=radio_pause +printf "%s addshape 4 4 %s\n" "$name" "$button" +printf "radio_pause addshape 4 4 -1 1 0 -.5 1 0 -.5 -1 0 -1 -1 0\n" +printf "radio_pause addshape 4 4 .5 1 0 1 1 0 1 -1 0 .5 -1 0\n" +printf "radio_pause move -6 0 0\n" + +# [] +name=radio_stop +printf "%s addshape 4 4 %s\n" "$name" "$button" +printf "radio_stop addshape 4 4 -1 1 0 1 1 0 1 -1 0 -1 -1 0\n" +printf "radio_stop move -2 0 0\n" + +# |>| +name=radio_next +printf "%s addshape 4 4 %s\n" "$name" "$button" +printf "radio_next addshape 4 3 -1 1 0 .75 0 0 -1 -1 0\n" +printf "radio_next addshape 4 4 .75 1 0 1 1 0 1 -1 0 .75 -1 0\n" +printf "radio_next move 2 0 0\n" + +# |<| +name=radio_prev +printf "%s addshape 4 4 %s\n" "$name" "$button" +printf "radio_prev addshape 4 3 -.75 0 0 1 1 0 1 -1 0\n" +printf "radio_prev addshape 4 4 -1 1 0 -.75 1 0 -.75 -1 0 -1 -1 0\n" +printf "radio_prev move 6 0 0\n" + +printf "exit addshape 4 4 -2 -5 0 2 -5 0 2 -9 0 -2 -9 0\n" + +# a "listen" link to the http stream +# so anyone using hackvr_uri can open it from inside hackvr. :) + + while read group action target args;do + printf "hackvr line: %s\n" "$group $action $target" >> $log + if [ "$group" = "$USER" -a "$action" = "quit" ];then + break + fi + if [ "$action" = "action" ];then + if [ $target = "radio_pause" ];then + mpc --host=21.41.41.4 --port=61666 pause 2>&1 >/dev/null 2>&1 + fi + if [ $target = "radio_play" ];then + mpc --host=21.41.41.4 --port=61666 play 2>&1 >/dev/null 2>&1 + fi + if [ $target = "radio_prev" ];then + mpc --host=21.41.41.4 --port=61666 prev 2>&1 >/dev/null 2>&1 + fi + if [ $target = "radio_next" ];then + mpc --host=21.41.41.4 --port=61666 next 2>&1 >/dev/null 2>&1 + fi + if [ $target = "radio_stop" ];then + mpc --host=21.41.41.4 --port=61666 stop 2>&1 >/dev/null 2>&1 + fi + if [ $target = "exit" ];then + break; + fi + fi + done -- cgit v1.2.3