[17] | 1 | #!/bin/bash
|
---|
[20] | 2 | # Version 5
|
---|
[17] | 3 |
|
---|
| 4 | . /usr/local/lib/7dtd/common.sh
|
---|
| 5 | checkRootLoadConf
|
---|
| 6 |
|
---|
| 7 | if [ $(isValidInstance $1) -eq 0 ]; then
|
---|
| 8 | echo "No instance given or not a valid instance!"
|
---|
| 9 | return
|
---|
| 10 | fi
|
---|
| 11 |
|
---|
| 12 | INSTANCE=$1
|
---|
| 13 | LOG=$(getInstancePath $INSTANCE)/output.log
|
---|
| 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,")
|
---|
| 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 |
|
---|
| 36 | handleDisconnect() {
|
---|
| 37 | logPlayerDisconnect $INSTANCE $2
|
---|
| 38 |
|
---|
| 39 | for H in $(getHooksFor playerDisconnect); do
|
---|
| 40 | $H $INSTANCE $1 $2 $NICKNAME $STEAMID
|
---|
| 41 | done
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | echo >> $LOG
|
---|
| 45 | echo >> $LOG
|
---|
| 46 | echo "Starting instance $INSTANCE at $(timestamp)" >> $LOG
|
---|
| 47 | echo >> $LOG
|
---|
| 48 |
|
---|
[18] | 49 | sleep 5
|
---|
| 50 |
|
---|
[17] | 51 | NOBUF="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: " |
|
---|
| 57 | while 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
|
---|
| 72 | done
|
---|