1 | #!/bin/bash
|
---|
2 |
|
---|
3 | . /usr/local/lib/7dtd/common.sh
|
---|
4 | . /usr/local/lib/7dtd/playerlog.sh
|
---|
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)/logs/$(date '+%Y-%m-%d_%H-%M-%S')_output.log
|
---|
13 | CHATLOG=$(getInstancePath $INSTANCE)/logs/$(date '+%Y-%m-%d_%H-%M-%S')_chat.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" "$3"
|
---|
30 |
|
---|
31 | for H in $(getHooksFor playerConnect); do
|
---|
32 | $H $INSTANCE "$1" "$2" "$3" "$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 | handleChat() {
|
---|
45 | echo "$(timestamp): $1" >> $CHATLOG
|
---|
46 |
|
---|
47 | for H in $(getHooksFor chat); do
|
---|
48 | $H $INSTANCE "$1"
|
---|
49 | done
|
---|
50 | }
|
---|
51 |
|
---|
52 | if [ ! -d "$(getInstancePath $INSTANCE)/logs" ]; then
|
---|
53 | mkdir "$(getInstancePath $INSTANCE)/logs"
|
---|
54 | fi
|
---|
55 |
|
---|
56 | setAllPlayersOffline
|
---|
57 |
|
---|
58 | echo >> $LOG
|
---|
59 | echo >> $LOG
|
---|
60 | echo "Starting instance $INSTANCE at $(timestamp)" >> $LOG
|
---|
61 | echo >> $LOG
|
---|
62 |
|
---|
63 | sleep 5
|
---|
64 |
|
---|
65 | NOBUF="stdbuf -e0 -o0"
|
---|
66 |
|
---|
67 | $NOBUF tail -n 5000 -F $(getInstancePath $INSTANCE)/logs/output_log.txt |
|
---|
68 | $NOBUF tr '\\' '/' |
|
---|
69 | $NOBUF tr -d '\r' |
|
---|
70 | $NOBUF grep -v "^(Filename: " |
|
---|
71 | $NOBUF sed -r 's/^[0-9]+[.,][0-9]+ (.*)$/\1/' |
|
---|
72 | while read line ; do
|
---|
73 | if [ -n "$line" ]; then
|
---|
74 | echo "$(timestamp): $line" >> $LOG
|
---|
75 | if [ -n "$(echo "$line" | grep '^RequestToSpawnPlayer:')" ]; then
|
---|
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]*\)$')
|
---|
80 | sleep 1
|
---|
81 | handleConnect "$playerId" "$entityId" "$playerName"
|
---|
82 | unset entityId playerId playerName unknown
|
---|
83 | else
|
---|
84 | if [ -n "$(echo "$line" | grep '^Removing player with id ')" ]; then
|
---|
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"
|
---|
88 | unset playerId entityId
|
---|
89 | else
|
---|
90 | if [ -n "$(echo "$line" | grep -E '^GMSG: .+')" ]; then
|
---|
91 | msg=$(expr "$line" : 'GMSG: \(.*\)$')
|
---|
92 | handleChat "$msg"
|
---|
93 | unset msg
|
---|
94 | fi
|
---|
95 | fi
|
---|
96 | fi
|
---|
97 | fi
|
---|
98 | done
|
---|