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

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

v25: Fixes #22, #23. Also adds new serverconfig options

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