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

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

v.23

  • Property svn:executable set to *
File size: 2.4 KB
RevLine 
[17]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
[62]12CHATLOG=$(getInstancePath $INSTANCE)/chat.log
[17]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,")
[62]21 #nickname=$(echo "$playerline" | sed -r 's/^.* id=[0-9]*, ([^,]*), pos=.*$/\1/')
[17]22 steamid=$(echo "$playerline" | sed -r 's/^.*, health=[0-9]*, ([0-9]*)$/\1/')
23
24 if [ -z "$steamid" ]; then
25 return
26 fi
27
[63]28 logPlayerConnect $INSTANCE "$2" "$steamid" "$3"
[17]29
30 for H in $(getHooksFor playerConnect); do
[63]31 $H $INSTANCE "$1" "$2" "$3" "$steamid"
[17]32 done
33}
34
35handleDisconnect() {
[63]36 logPlayerDisconnect $INSTANCE "$2"
[17]37
38 for H in $(getHooksFor playerDisconnect); do
[63]39 $H $INSTANCE "$1" "$2" "$NICKNAME" "$STEAMID"
[17]40 done
41}
42
[62]43handleChat() {
44 echo "$(timestamp): $1" >> $CHATLOG
45
46 for H in $(getHooksFor chat); do
[63]47 $H $INSTANCE "$1"
[62]48 done
49}
50
[17]51echo >> $LOG
52echo >> $LOG
53echo "Starting instance $INSTANCE at $(timestamp)" >> $LOG
54echo >> $LOG
55
[18]56sleep 5
57
[17]58NOBUF="stdbuf -e0 -o0"
59
[35]60$NOBUF tail -n 5000 -F $(getInstancePath $INSTANCE)/output_log.txt |
[17]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
[57]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]*\)$')
[17]72 sleep 1
[57]73 handleConnect "$playerId" "$entityId" "$playerName"
[17]74 unset entityId playerId playerName unknown
[62]75 else
[17]76 if [ -n "$(echo "$line" | grep '^Removing player with id ')" ]; then
[57]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"
[17]80 unset playerId entityId
[62]81 else
82 if [ -n "$(echo "$line" | grep -E '^GMSG: .+')" ]; then
83 msg=$(expr "$line" : 'GMSG: \(.*\)$')
84 handleChat "$msg"
85 unset msg
[17]86 fi
[62]87 fi
88 fi
[17]89 fi
90done
Note: See TracBrowser for help on using the repository browser.