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

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

v.27: Fixed output log

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