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

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

Version 16: Fixes #17

  • Property svn:executable set to *
File size: 2.1 KB
Line 
1#!/bin/bash
2
3. /usr/local/lib/7dtd/common.sh
4checkRootLoadConf
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)/output.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 $nickname
29
30 for H in $(getHooksFor playerConnect); do
31 $H $INSTANCE $1 $2 $nickname $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
43echo >> $LOG
44echo >> $LOG
45echo "Starting instance $INSTANCE at $(timestamp)" >> $LOG
46echo >> $LOG
47
48sleep 5
49
50NOBUF="stdbuf -e0 -o0"
51
52$NOBUF tail -n 5000 -F $(getInstancePath $INSTANCE)/output_log.txt |
53$NOBUF tr '\\' '/' |
54$NOBUF tr -d '\r' |
55$NOBUF grep -v "^(Filename: " |
56while read line ; do
57 if [ -n "$line" ]; then
58 echo "$(timestamp): $line" >> $LOG
59 if [ -n "$(echo "$line" | grep '^RequestToSpawnPlayer:')" ]; then
60 entityId=$(expr "$line" : 'RequestToSpawnPlayer: \([0-9]*\), [0-9]*, .*, [0-9]*$')
61 playerId=$(expr "$line" : 'RequestToSpawnPlayer: [0-9]*, \([0-9]*\), .*, [0-9]*$')
62 playerName=$(expr "$line" : 'RequestToSpawnPlayer: [0-9]*, [0-9]*, \(.*\), [0-9]*$')
63 unknown=$(expr "$line" : 'RequestToSpawnPlayer: [0-9]*, [0-9]*, .*, \([0-9]*\)$')
64 sleep 1
65 handleConnect "$playerId" "$entityId" "$playerName"
66 unset entityId playerId playerName unknown
67 fi
68 if [ -n "$(echo "$line" | grep '^Removing player with id ')" ]; then
69 playerId=$(expr "$line" : 'Removing player with id clientId=\([0-9]*\), entityId=[0-9]*$')
70 entityId=$(expr "$line" : 'Removing player with id clientId=[0-9]*, entityId=\([0-9]*\)$')
71 handleDisconnect "$playerId" "$entityId"
72 unset playerId entityId
73 fi
74 fi
75done
Note: See TracBrowser for help on using the repository browser.