| 1 | #!/bin/bash
|
|---|
| 2 |
|
|---|
| 3 | . /usr/local/lib/7dtd/common.sh
|
|---|
| 4 |
|
|---|
| 5 | if [ $(isValidInstance $1) -eq 0 ]; then
|
|---|
| 6 | echo "No instance given or not a valid instance!"
|
|---|
| 7 | return
|
|---|
| 8 | fi
|
|---|
| 9 |
|
|---|
| 10 | INSTANCE=$1
|
|---|
| 11 | LOG=$(getInstancePath $INSTANCE)/output.log
|
|---|
| 12 | CHATLOG=$(getInstancePath $INSTANCE)/chat.log
|
|---|
| 13 |
|
|---|
| 14 | timestamp() {
|
|---|
| 15 | date '+%Y.%m.%d %H:%M:%S'
|
|---|
| 16 | }
|
|---|
| 17 |
|
|---|
| 18 | handleConnect() {
|
|---|
| 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" "$3"
|
|---|
| 29 |
|
|---|
| 30 | for H in $(getHooksFor playerConnect); do
|
|---|
| 31 | $H $INSTANCE "$1" "$2" "$3" "$steamid"
|
|---|
| 32 | done
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 | handleDisconnect() {
|
|---|
| 36 | logPlayerDisconnect $INSTANCE "$2"
|
|---|
| 37 |
|
|---|
| 38 | for H in $(getHooksFor playerDisconnect); do
|
|---|
| 39 | $H $INSTANCE "$1" "$2" "$NICKNAME" "$STEAMID"
|
|---|
| 40 | done
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
| 43 | handleChat() {
|
|---|
| 44 | echo "$(timestamp): $1" >> $CHATLOG
|
|---|
| 45 |
|
|---|
| 46 | for H in $(getHooksFor chat); do
|
|---|
| 47 | $H $INSTANCE "$1"
|
|---|
| 48 | done
|
|---|
| 49 | }
|
|---|
| 50 |
|
|---|
| 51 | echo >> $LOG
|
|---|
| 52 | echo >> $LOG
|
|---|
| 53 | echo "Starting instance $INSTANCE at $(timestamp)" >> $LOG
|
|---|
| 54 | echo >> $LOG
|
|---|
| 55 |
|
|---|
| 56 | sleep 5
|
|---|
| 57 |
|
|---|
| 58 | NOBUF="stdbuf -e0 -o0"
|
|---|
| 59 |
|
|---|
| 60 | $NOBUF tail -n 5000 -F $(getInstancePath $INSTANCE)/output_log.txt |
|
|---|
| 61 | $NOBUF tr '\\' '/' |
|
|---|
| 62 | $NOBUF tr -d '\r' |
|
|---|
| 63 | $NOBUF grep -v "^(Filename: " |
|
|---|
| 64 | while read line ; do
|
|---|
| 65 | if [ -n "$line" ]; then
|
|---|
| 66 | echo "$(timestamp): $line" >> $LOG
|
|---|
| 67 | if [ -n "$(echo "$line" | grep '^RequestToSpawnPlayer:')" ]; then
|
|---|
| 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]*\)$')
|
|---|
| 72 | sleep 1
|
|---|
| 73 | handleConnect "$playerId" "$entityId" "$playerName"
|
|---|
| 74 | unset entityId playerId playerName unknown
|
|---|
| 75 | else
|
|---|
| 76 | if [ -n "$(echo "$line" | grep '^Removing player with id ')" ]; then
|
|---|
| 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"
|
|---|
| 80 | unset playerId entityId
|
|---|
| 81 | else
|
|---|
| 82 | if [ -n "$(echo "$line" | grep -E '^GMSG: .+')" ]; then
|
|---|
| 83 | msg=$(expr "$line" : 'GMSG: \(.*\)$')
|
|---|
| 84 | handleChat "$msg"
|
|---|
| 85 | unset msg
|
|---|
| 86 | fi
|
|---|
| 87 | fi
|
|---|
| 88 | fi
|
|---|
| 89 | fi
|
|---|
| 90 | done
|
|---|