[17] | 1 | #!/bin/bash
|
---|
| 2 |
|
---|
| 3 | . /usr/local/lib/7dtd/common.sh
|
---|
| 4 | checkRootLoadConf
|
---|
| 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
|
---|
| 12 | LOG=$(getInstancePath $INSTANCE)/output.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 $nickname
|
---|
| 29 |
|
---|
| 30 | for H in $(getHooksFor playerConnect); do
|
---|
| 31 | $H $INSTANCE $1 $2 $nickname $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 | echo >> $LOG
|
---|
| 44 | echo >> $LOG
|
---|
| 45 | echo "Starting instance $INSTANCE at $(timestamp)" >> $LOG
|
---|
| 46 | echo >> $LOG
|
---|
| 47 |
|
---|
[18] | 48 | sleep 5
|
---|
| 49 |
|
---|
[17] | 50 | NOBUF="stdbuf -e0 -o0"
|
---|
| 51 |
|
---|
[35] | 52 | $NOBUF tail -n 5000 -F $(getInstancePath $INSTANCE)/output_log.txt |
|
---|
[17] | 53 | $NOBUF tr '\\' '/' |
|
---|
| 54 | $NOBUF tr -d '\r' |
|
---|
| 55 | $NOBUF grep -v "^(Filename: " |
|
---|
| 56 | while read line ; do
|
---|
| 57 | if [ -n "$line" ]; then
|
---|
| 58 | echo "$(timestamp): $line" >> $LOG
|
---|
| 59 | if [ -n "$(echo "$line" | grep '^RequestToSpawnPlayer:')" ]; then
|
---|
[57] | 60 | entityId=$(expr "$line" : 'RequestToSpawnPlayer: \([0-9]*\), [0-9]*, .*, [0-9]*$')
|
---|
| 61 | playerId=$(expr "$line" : 'RequestToSpawnPlayer: [0-9]*, \([0-9]*\), .*, [0-9]*$')
|
---|
| 62 | playerName=$(expr "$line" : 'RequestToSpawnPlayer: [0-9]*, [0-9]*, \(.*\), [0-9]*$')
|
---|
| 63 | unknown=$(expr "$line" : 'RequestToSpawnPlayer: [0-9]*, [0-9]*, .*, \([0-9]*\)$')
|
---|
[17] | 64 | sleep 1
|
---|
[57] | 65 | handleConnect "$playerId" "$entityId" "$playerName"
|
---|
[17] | 66 | unset entityId playerId playerName unknown
|
---|
| 67 | fi
|
---|
| 68 | if [ -n "$(echo "$line" | grep '^Removing player with id ')" ]; then
|
---|
[57] | 69 | playerId=$(expr "$line" : 'Removing player with id clientId=\([0-9]*\), entityId=[0-9]*$')
|
---|
| 70 | entityId=$(expr "$line" : 'Removing player with id clientId=[0-9]*, entityId=\([0-9]*\)$')
|
---|
| 71 | handleDisconnect "$playerId" "$entityId"
|
---|
[17] | 72 | unset playerId entityId
|
---|
| 73 | fi
|
---|
| 74 | fi
|
---|
| 75 | done
|
---|