summaryrefslogtreecommitdiffstats
path: root/god
diff options
context:
space:
mode:
Diffstat (limited to 'god')
-rwxr-xr-xgod/Reaktor/index37
-rwxr-xr-xgod/Reaktor/lib/listener.py50
-rwxr-xr-xgod/licht115
3 files changed, 193 insertions, 9 deletions
diff --git a/god/Reaktor/index b/god/Reaktor/index
new file mode 100755
index 00000000..a2e6fe61
--- /dev/null
+++ b/god/Reaktor/index
@@ -0,0 +1,37 @@
+#! /bin/sh
+#
+# //god/Reaktor - listen to UDP events and forward them to IRC
+#
+# export host passwd printto to configure jsb-udp
+#
+set -euf
+cd $(readlink -f $(dirname $0))
+
+listener=$(readlink -f lib/listener.py)
+
+jsb_version=0.7.1.2
+distdir=jsb-$jsb_version.tar.gz
+
+host=${host-91.206.142.247}
+passwd=${passwd-h4x0r}
+printto=${printto-#shackspace}
+
+if ! test -x tmp/jsb-$jsb_version; then
+ mkdir -p tmp
+ cd tmp
+ curl -f http://jsonbot.googlecode.com/files/jsb-$jsb_version.tar.gz | tar zx
+ cd jsb-$jsb_version
+ bin/jsb-udp -s </dev/null
+ cd ../..
+fi
+cd tmp/jsb-$jsb_version
+
+# TODO only if it is not already configured properly
+sed -i '
+ s/^host *=.*/host="'$host'"/
+ s/^passwd *=.*/passwd="'$passwd'"/
+ s/^printto *=.*/printto="'$printto'"/
+' config/udp-send
+
+# TODO output modules: stderr, jsb-udp, remount-ro, ...
+PYTHONUNBUFFERED=y $listener | tee /dev/stderr | bin/jsb-udp
diff --git a/god/Reaktor/lib/listener.py b/god/Reaktor/lib/listener.py
new file mode 100755
index 00000000..9708d9bc
--- /dev/null
+++ b/god/Reaktor/lib/listener.py
@@ -0,0 +1,50 @@
+#! /usr/bin/env python2
+# coding=UTF-8
+
+location = 'shackspace'
+host = '0.0.0.0'
+port = 2342
+
+map = {
+ 'shackspace': {
+ 'device': {
+ 0: 'Licht0, Zickenzone; Fenster',
+ 1: 'Licht1, Sofaecke; Fenster',
+ 2: 'Licht2, Zickenzone; Ghetto',
+ 3: 'Licht3, Sofaecke; Ghetto',
+ 4: 'Licht4, Richtung Getränkelager',
+ 5: 'Licht5, Porschekonsole',
+ 6: 'Licht6, Tomatenecke',
+ 7: 'Licht7, Ghetto',
+ 10: 'Hauptschalter'
+ },
+ 'state': {
+ 0: 'aus',
+ 1: 'an',
+ 2: 'aus in T-10s'
+ },
+ '->': 'ist'
+ }
+}
+
+import socket
+from string import join
+from struct import unpack
+
+# create udp socket
+mysocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+
+# allow send/recieve from broacast address
+mysocket.setsockopt(socket.SOL_SOCKET,socket.SO_BROADCAST,1)
+
+# allow the socket to be re-used
+mysocket.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
+mysocket.bind((host, port))
+
+map = map[location]
+
+while True:
+ did, sid = unpack('BB', mysocket.recv(2))
+ device, state = map['device'][did], map['state'][sid]
+ arrow = map['->']
+ print join([device, arrow, state], ' ')
diff --git a/god/licht b/god/licht
index 8ece3510..cbff9ad0 100755
--- a/god/licht
+++ b/god/licht
@@ -1,20 +1,117 @@
#!/bin/bash
-case "$1" in
- (--help) echo "Toggle the lights";;
- (*)
- LAMPE=`echo $1 | sed -n '/^[1-2]*[0-9]*[0-9]$/p' | xargs echo "obase=16;" | bc`
- TOGGLE=`echo $2 | sed -n '/^[0-1]/p'`
+#
+#SYNOPSIS
+# //god/licht [options] [0/1]
+#OPTIONS
+# all - toggles all lights
+# links - toggles all lights on the left hand side while looking towards the Auditorium
+# rechts - toggles all lights on the right hand side while looking towards the Auditorium
+# kuschel - toggles the lights in the pwnie corner
+# software - toggles the software corner
+# tische - toggles the lights on the window side of the long table
+# porsche - toggles the lights on the window side where the porsche cockpit is
+# ghetto - toggles the lights in the hallway
+# 0-7 - toggles individual lights
+
+toggle() {
+ LAMPE=`echo "$1" | sed -n '/^[1-2]*[0-9]*[0-9]$/p' | xargs echo "obase=16;" | bc`
+ TOGGLE=`echo "$2" | sed -n '/^[0-1]/p'`
if ! [ "$LAMPE" -a "$TOGGLE" ];then
echo "you are made of stupid"
exit 1
fi
- STRING="\xA5\x5A\x$LAMPE\x$TOGGLE"
+ STRING="\\xA5\\x5A\\x$LAMPE\\x$TOGGLE"
if [ $# != 2 ]
then
- echo -ne "Usage: licht <lampe> <0/1>"
+ echo "Usage: licht <lampe> <0/1>"
else
echo "Toggle light $LAMPE ($TOGGLE)"
- echo -ne "$STRING" | nc -u -w1 licht.shack 1337
+ printf "$STRING" | nc -u -w1 licht.shack 1337
fi
- ;;
+}
+
+toggle_all() {
+ for i in `seq 0 7`
+ do
+ printf "\\xA5\\x5A\\x$i\\x$TOGGLE" | nc -u -w1 licht.shack 1337 &
+ done
+ wait
+}
+
+kuschel(){
+ for i in 0 2
+ do
+ printf "\\xA5\\x5A\\x$i\\x$TOGGLE" | nc -u -w1 licht.shack 1337 &
+ done
+ wait
+}
+
+software(){
+ for i in 1 3
+ do
+ printf "\\xA5\\x5A\\x$i\\x$TOGGLE" | nc -u -w1 licht.shack 1337 &
+ done
+ wait
+}
+
+tische(){
+ for i in 4 6
+ do
+ printf "\\xA5\\x5A\\x$i\\x$TOGGLE" | nc -u -w1 licht.shack 1337 &
+ done
+ wait
+}
+
+ghetto(){
+ printf "\\xA5\\x5A\\x7\\x$TOGGLE" | nc -u -w1 licht.shack 1337
+}
+
+porsche(){
+ printf "\\xA5\\x5A\\x5\\x$TOGGLE" | nc -u -w1 licht.shack 1337
+}
+
+case "$1" in
+ --help)
+ echo "Toggle the lights"
+ echo "Usage: lich <lampe> <0/1>"
+ ;;
+ all)
+ TOGGLE=$2
+ toggle_all
+ ;;
+ kuschel)
+ TOGGLE=$2
+ kuschel
+ ;;
+ software)
+ TOGGLE=$2
+ software
+ ;;
+ links)
+ TOGGLE=$2
+ kuschel
+ software
+ ;;
+ rechts)
+ TOGGLE=$2
+ tische
+ porsche
+ ghetto
+ ;;
+ tische)
+ TOGGLE=$2
+ tische
+ ;;
+ porsche)
+ TOGGLE=$2
+ porsche
+ ;;
+ ghetto)
+ TOGGLE=$2
+ ghetto
+ ;;
+ *)
+ toggle "$@"
+ ;;
esac
+