source: scripts/usr/local/lib/7dtd/monitor-log.sh@ 64

Last change on this file since 64 was 64, checked in by alloc, 10 years ago

v.23

  • Property svn:executable set to *
File size: 2.4 KB
Line 
1#!/bin/bash
2
3. /usr/local/lib/7dtd/common.sh
4
5if [ $(isValidInstance $1) -eq 0 ]; then
6 echo "No instance given or not a valid instance!"
7 return
8fi
9
10INSTANCE=$1
11LOG=$(getInstancePath $INSTANCE)/output.log
12CHATLOG=$(getInstancePath $INSTANCE)/chat.log
13
14timestamp() {
15 date '+%Y.%m.%d %H:%M:%S'
16}
17
18handleConnect() {
19 tel=$(telnetCommand $INSTANCE lp)
20 playerline=$(echo "$tel" | tr -d '\r' | grep "id=$2,")
21 #nickname=$(echo "$playerline" | sed -r 's/^.* id=[0-9]*, ([^,]*), pos=.*$/\1/')
22 steamid=$(echo "$playerline" | sed -r 's/^.*, health=[0-9]*, ([0-9]*)$/\1/')
23
24 if [ -z "$steamid" ]; then
25 return
26 fi
27
28 logPlayerConnect $INSTANCE "$2" "$steamid" "$3"
29
30 for H in $(getHooksFor playerConnect); do
31 $H $INSTANCE "$1" "$2" "$3" "$steamid"
32 done
33}
34
35handleDisconnect() {
36 logPlayerDisconnect $INSTANCE "$2"
37
38 for H in $(getHooksFor playerDisconnect); do
39 $H $INSTANCE "$1" "$2" "$NICKNAME" "$STEAMID"
40 done
41}
42
43handleChat() {
44 echo "$(timestamp): $1" >> $CHATLOG
45
46 for H in $(getHooksFor chat); do
47 $H $INSTANCE "$1"
48 done
49}
50
51echo >> $LOG
52echo >> $LOG
53echo "Starting instance $INSTANCE at $(timestamp)" >> $LOG
54echo >> $LOG
55
56sleep 5
57
58NOBUF="stdbuf -e0 -o0"
59
60$NOBUF tail -n 5000 -F $(getInstancePath $INSTANCE)/output_log.txt |
61$NOBUF tr '\\' '/' |
62$NOBUF tr -d '\r' |
63$NOBUF grep -v "^(Filename: " |
64while read line ; do
65 if [ -n "$line" ]; then
66 echo "$(timestamp): $line" >> $LOG
67 if [ -n "$(echo "$line" | grep '^RequestToSpawnPlayer:')" ]; then
68 entityId=$(expr "$line" : 'RequestToSpawnPlayer: \([0-9]*\), [0-9]*, .*, [0-9]*$')
69 playerId=$(expr "$line" : 'RequestToSpawnPlayer: [0-9]*, \([0-9]*\), .*, [0-9]*$')
70 playerName=$(expr "$line" : 'RequestToSpawnPlayer: [0-9]*, [0-9]*, \(.*\), [0-9]*$')
71 unknown=$(expr "$line" : 'RequestToSpawnPlayer: [0-9]*, [0-9]*, .*, \([0-9]*\)$')
72 sleep 1
73 handleConnect "$playerId" "$entityId" "$playerName"
74 unset entityId playerId playerName unknown
75 else
76 if [ -n "$(echo "$line" | grep '^Removing player with id ')" ]; then
77 playerId=$(expr "$line" : 'Removing player with id clientId=\([0-9]*\), entityId=[0-9]*$')
78 entityId=$(expr "$line" : 'Removing player with id clientId=[0-9]*, entityId=\([0-9]*\)$')
79 handleDisconnect "$playerId" "$entityId"
80 unset playerId entityId
81 else
82 if [ -n "$(echo "$line" | grep -E '^GMSG: .+')" ]; then
83 msg=$(expr "$line" : 'GMSG: \(.*\)$')
84 handleChat "$msg"
85 unset msg
86 fi
87 fi
88 fi
89 fi
90done
Note: See TracBrowser for help on using the repository browser.