[17] | 1 | #!/bin/bash
|
---|
| 2 | # Version 4
|
---|
| 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 |
|
---|
| 49 | NOBUF="stdbuf -e0 -o0"
|
---|
| 50 |
|
---|
| 51 | $NOBUF tail -n 5000 -F $SDTD_BASE/engine/7DaysToDie_Data/output_log.txt |
|
---|
| 52 | $NOBUF tr '\\' '/' |
|
---|
| 53 | $NOBUF tr -d '\r' |
|
---|
| 54 | $NOBUF grep -v "^(Filename: " |
|
---|
| 55 | while read line ; do
|
---|
| 56 | if [ -n "$line" ]; then
|
---|
| 57 | echo "$(timestamp): $line" >> $LOG
|
---|
| 58 | if [ -n "$(echo "$line" | grep '^RequestToSpawnPlayer:')" ]; then
|
---|
| 59 | read entityId playerId playerName unknown <<< "$(echo $line | sed -r 's/^RequestToSpawnPlayer: (.*), (.*), (.*), (.*)$/\1 \2 \3 \4/')"
|
---|
| 60 | sleep 1
|
---|
| 61 | handleConnect $playerId $entityId $playerName
|
---|
| 62 | unset entityId playerId playerName unknown
|
---|
| 63 | fi
|
---|
| 64 | if [ -n "$(echo "$line" | grep '^Removing player with id ')" ]; then
|
---|
| 65 | read playerId entityId <<< "$(echo $line | sed -r 's/^Removing player with id clientId=(.*), entityId=(.*)$/\1 \2/')"
|
---|
| 66 | handleDisconnect $playerId $entityId
|
---|
| 67 | unset playerId entityId
|
---|
| 68 | fi
|
---|
| 69 | fi
|
---|
| 70 | done
|
---|