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

Last change on this file since 22 was 20, checked in by alloc, 11 years ago

Version 5. Fixes #9, #11

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