[17] | 1 | #!/bin/bash
|
---|
| 2 |
|
---|
| 3 | . /usr/local/lib/7dtd/common.sh
|
---|
[67] | 4 | . /usr/local/lib/7dtd/playerlog.sh
|
---|
[17] | 5 |
|
---|
| 6 | if [ $(isValidInstance $1) -eq 0 ]; then
|
---|
| 7 | echo "No instance given or not a valid instance!"
|
---|
| 8 | return
|
---|
| 9 | fi
|
---|
| 10 |
|
---|
| 11 | INSTANCE=$1
|
---|
[67] | 12 | LOG=$(getInstancePath $INSTANCE)/logs/$(date '+%Y-%m-%d_%H-%M-%S')_output.log
|
---|
| 13 | CHATLOG=$(getInstancePath $INSTANCE)/logs/$(date '+%Y-%m-%d_%H-%M-%S')_chat.log
|
---|
[17] | 14 |
|
---|
| 15 | timestamp() {
|
---|
| 16 | date '+%Y.%m.%d %H:%M:%S'
|
---|
| 17 | }
|
---|
| 18 |
|
---|
| 19 | handleConnect() {
|
---|
| 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 |
|
---|
| 36 | handleDisconnect() {
|
---|
[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] | 44 | handleChat() {
|
---|
| 45 | echo "$(timestamp): $1" >> $CHATLOG
|
---|
| 46 |
|
---|
| 47 | for H in $(getHooksFor chat); do
|
---|
[63] | 48 | $H $INSTANCE "$1"
|
---|
[62] | 49 | done
|
---|
| 50 | }
|
---|
| 51 |
|
---|
[67] | 52 | if [ ! -d "$(getInstancePath $INSTANCE)/logs" ]; then
|
---|
| 53 | mkdir "$(getInstancePath $INSTANCE)/logs"
|
---|
| 54 | fi
|
---|
| 55 |
|
---|
| 56 | setAllPlayersOffline
|
---|
| 57 |
|
---|
[17] | 58 | echo >> $LOG
|
---|
| 59 | echo >> $LOG
|
---|
| 60 | echo "Starting instance $INSTANCE at $(timestamp)" >> $LOG
|
---|
| 61 | echo >> $LOG
|
---|
| 62 |
|
---|
[18] | 63 | sleep 5
|
---|
| 64 |
|
---|
[17] | 65 | NOBUF="stdbuf -e0 -o0"
|
---|
| 66 |
|
---|
[69] | 67 | $NOBUF tail -n 5000 -F $(getInstancePath $INSTANCE)/logs/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] | 72 | while 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
|
---|
| 98 | done
|
---|