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 |
|
---|
48 | sleep 5
|
---|
49 |
|
---|
50 | NOBUF="stdbuf -e0 -o0"
|
---|
51 |
|
---|
52 | $NOBUF tail -n 5000 -F $(getInstancePath $INSTANCE)/output_log.txt |
|
---|
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
|
---|
60 | read entityId playerId playerName unknown <<< "$(echo $line | sed -r 's/^RequestToSpawnPlayer: (.*), (.*), (.*), (.*)$/\1 \2 \3 \4/')"
|
---|
61 | sleep 1
|
---|
62 | handleConnect $playerId $entityId $playerName
|
---|
63 | unset entityId playerId playerName unknown
|
---|
64 | fi
|
---|
65 | if [ -n "$(echo "$line" | grep '^Removing player with id ')" ]; then
|
---|
66 | read playerId entityId <<< "$(echo $line | sed -r 's/^Removing player with id clientId=(.*), entityId=(.*)$/\1 \2/')"
|
---|
67 | handleDisconnect $playerId $entityId
|
---|
68 | unset playerId entityId
|
---|
69 | fi
|
---|
70 | fi
|
---|
71 | done
|
---|