summaryrefslogtreecommitdiffstats
path: root/scripts/offer-sync.sh
blob: a1d3f141ba76f195b49e4b5557d29caae101f0f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/sh

PATH=/usr/bin:/bin:/usr/sbin:/sbin

if [ -z $1 ]; then
        echo "usage: $0 network_interface"
        echo "example: $0 eth0"
        exit 1
fi
IFACE="$1"

IP="`ifconfig $IFACE | grep 'inet addr'| awk '{print $2}'|cut -f2 -d:`"

if [ -z $APPROOT ]; then
    NC="../src/netcat -c"
    BC="../src/broadcaster"
else
    NC="$APPROOT/bin/netcat -c"
    BC="$APPROOT/bin/broadcaster"
fi

ready=false

rm -f /tmp/listener.replies
touch /tmp/listener.replies

echo "broadcasting sync signals"

# background listener
(while [ true ]; do
    answer=`echo | $NC -u -l -p 3331`;
    echo $answer >> /tmp/listener.replies
    done) &

# send broadcast signals
for b in 1 2 3 4 5; do
    echo -n "$b: `date +%X` "
    $BC 255.255.255.255 3332 $IP
    sleep 2
done

echo "harvesting replies"
cat /tmp/listener.replies | sort | uniq > /tmp/listeners

echo "sending acks"
c=1
for l in `cat /tmp/listeners`; do
    echo "$c: $l"
    echo "$c" | $NC -u $l 3333
done

echo "waiting for players to get ready"
sleep 20
echo "syncstart!"
$BC 255.255.255.255 3336 s