-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonitor_log
executable file
·69 lines (59 loc) · 1.94 KB
/
monitor_log
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
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
minecraft_dir=../
curr_user=`tail -n1 $minecraft_dir/white-list.txt`
fd="$minecraft_dir/command_input"
db='/tmp/chaincraft.db'
spectator="endofdays442"
function cycle_user() {
local nextUser=$(sqlite3 "$db" "select * from users limit 1")
if test -z "$nextUser"; then return; fi
local userName=$(echo "$nextUser" | cut -d'|' -f3)
local userEmail=$(echo "$nextUser" | cut -d'|' -f2)
echo "Emailing $userName at $userEmail to come play."
echo "whitelist add $userName" > $fd
sqlite3 "$db" "delete from users where handle=\"$userName\""
sendmail -fnoreply@linode.jmatthews.us "$userEmail" << __ENDEMAIL__
Your turn to play! Connect to linode.jmatthews.us:25565 to play chaincraft.
__ENDEMAIL__
}
function process_line() {
local user_end=0
if echo $1 | grep -i "joined the game"
then
local newUser=$(echo $1 | cut -d: -f4 | cut -d' ' -f2 | tr '[:upper:]' '[:lower:]')
if [ "$newUser" == "$spectator" ]; then return; fi
curr_user=$newUser
echo "Setting $newUser as the current user."
echo "tp $spectator $curr_user" > $fd
return
fi
# Detect if user has disconnected
if echo $1 | grep -i "$curr_user left the game"
then
echo "$curr_user left, cycling to next in queue."
local user_end=1
fi
#Detect if the user died
while read text
do
if echo $1 | grep -i "$curr_user $text"
then
echo "$curr_user died, cycling to next in queue."
local user_end=1
break
fi
done < death_messages
if [ $user_end -eq 1 ]
then
#Remove them from the whitelist
echo "Removing $curr_user from the whitelist and kicking."
echo "whitelist remove $curr_user" > $fd
echo "kick $curr_user Your turn is over. Thanks for playing" > $fd
cycle_user
fi
}
cycle_user
tail -n0 -f $minecraft_dir/logs/latest.log | while read l
do
process_line "$l"
done