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 | COMMANDLOG=$(getInstancePath $INSTANCE)/logs/$(date '+%Y-%m-%d_%H-%M-%S')_commandExecution.log
|
---|
15 |
|
---|
16 | timestamp() {
|
---|
17 | date '+%Y.%m.%d %H:%M:%S'
|
---|
18 | }
|
---|
19 |
|
---|
20 | handleConnect() {
|
---|
21 | local clientId="$1"
|
---|
22 | local entityId="$2"
|
---|
23 | local name="$3"
|
---|
24 | local steamId="$4"
|
---|
25 | local ip="$5"
|
---|
26 |
|
---|
27 | logPlayerConnect $INSTANCE "$entityId" "$name" "$steamId" "$ip"
|
---|
28 |
|
---|
29 | for H in $(getHooksFor playerConnect); do
|
---|
30 | $H $INSTANCE "$clientId" "$entityId" "$name" "$steamId" "$ip"
|
---|
31 | done
|
---|
32 | }
|
---|
33 |
|
---|
34 | handleDisconnect() {
|
---|
35 | local clientId="$1"
|
---|
36 | local entityId="$2"
|
---|
37 |
|
---|
38 | logPlayerDisconnect $INSTANCE "$entityId"
|
---|
39 |
|
---|
40 | for H in $(getHooksFor playerDisconnect); do
|
---|
41 | $H $INSTANCE "$clientId" "$entityId" "$NICKNAME" "$STEAMID"
|
---|
42 | done
|
---|
43 | }
|
---|
44 |
|
---|
45 | handleChat() {
|
---|
46 | echo "$(timestamp): $1" >> $CHATLOG
|
---|
47 |
|
---|
48 | for H in $(getHooksFor chat); do
|
---|
49 | $H $INSTANCE "$1"
|
---|
50 | done
|
---|
51 | }
|
---|
52 |
|
---|
53 | handleRemoteCommand() {
|
---|
54 | local cmd="$1"
|
---|
55 | local name="$2"
|
---|
56 |
|
---|
57 | echo "$(timestamp): Player \"$name\" executed \"$cmd\"" >> $COMMANDLOG
|
---|
58 |
|
---|
59 | for H in $(getHooksFor remoteCommand); do
|
---|
60 | $H $INSTANCE "$cmd" "$name"
|
---|
61 | done
|
---|
62 | }
|
---|
63 |
|
---|
64 | handleTelnetCommand() {
|
---|
65 | local cmd="$1"
|
---|
66 | local ip="$2"
|
---|
67 |
|
---|
68 | echo "$(timestamp): Telnet from \"$ip\" executed \"$cmd\"" >> $COMMANDLOG
|
---|
69 |
|
---|
70 | for H in $(getHooksFor telnetCommand); do
|
---|
71 | $H $INSTANCE "$cmd" "$ip"
|
---|
72 | done
|
---|
73 | }
|
---|
74 |
|
---|
75 |
|
---|
76 | if [ ! -d "$(getInstancePath $INSTANCE)/logs" ]; then
|
---|
77 | mkdir "$(getInstancePath $INSTANCE)/logs"
|
---|
78 | fi
|
---|
79 |
|
---|
80 | setAllPlayersOffline
|
---|
81 |
|
---|
82 | echo >> $LOG
|
---|
83 | echo >> $LOG
|
---|
84 | echo "Starting instance $INSTANCE at $(timestamp)" >> $LOG
|
---|
85 | echo >> $LOG
|
---|
86 |
|
---|
87 | rm $(getInstancePath $INSTANCE)/logs/current_output.log
|
---|
88 | rm $(getInstancePath $INSTANCE)/logs/current_chat.log
|
---|
89 | rm $(getInstancePath $INSTANCE)/logs/current_commandExecution.log
|
---|
90 | ln -s $LOG $(getInstancePath $INSTANCE)/logs/current_output.log
|
---|
91 | ln -s $CHATLOG $(getInstancePath $INSTANCE)/logs/current_chat.log
|
---|
92 | ln -s $COMMANDLOG $(getInstancePath $INSTANCE)/logs/current_commandExecution.log
|
---|
93 |
|
---|
94 | sleep 5
|
---|
95 |
|
---|
96 | NOBUF="stdbuf -e0 -o0"
|
---|
97 |
|
---|
98 | $NOBUF tail -n 5000 -F $(getInstancePath $INSTANCE)/logs/output_log.txt |
|
---|
99 | $NOBUF tr '\\' '/' |
|
---|
100 | $NOBUF tr -d '\r' |
|
---|
101 | $NOBUF grep -v "^(Filename: " |
|
---|
102 | $NOBUF sed -r 's/^[0-9]+[.,][0-9]+ (.*)$/\1/' |
|
---|
103 | while read line ; do
|
---|
104 | if [ -n "$line" ]; then
|
---|
105 | echo "$(timestamp): $line" >> $LOG
|
---|
106 | #Player connected, clientid=[0-9]*, entityid=[0-9]*, name=.*, steamid=[0-9]*, ip=[0-9.]*$
|
---|
107 | if [ -n "$(echo "$line" | grep '^Player connected,')" ]; then
|
---|
108 | clientId=$(expr "$line" : 'Player connected, clientid=\([0-9]*\), entityid=[0-9]*, name=.*, steamid=[0-9]*, ip=[0-9.]*$')
|
---|
109 | entityId=$(expr "$line" : 'Player connected, clientid=[0-9]*, entityid=\([0-9]*\), name=.*, steamid=[0-9]*, ip=[0-9.]*$')
|
---|
110 | playerName=$(expr "$line" : 'Player connected, clientid=[0-9]*, entityid=[0-9]*, name=\(.*\), steamid=[0-9]*, ip=[0-9.]*$')
|
---|
111 | steamId=$(expr "$line" : 'Player connected, clientid=[0-9]*, entityid=[0-9]*, name=.*, steamid=\([0-9]*\), ip=[0-9.]*$')
|
---|
112 | ip=$(expr "$line" : 'Player connected, clientid=[0-9]*, entityid=[0-9]*, name=.*, steamid=[0-9]*, ip=\([0-9.]*\)$')
|
---|
113 | sleep 1
|
---|
114 | handleConnect "$clientId" "$entityId" "$playerName" "$steamId" "$ip"
|
---|
115 | unset clientId entityId playerName steamId ip
|
---|
116 | else
|
---|
117 | #Removing player with id clientId=[0-9]*, entityId=[0-9]*$
|
---|
118 | if [ -n "$(echo "$line" | grep '^Removing player with id ')" ]; then
|
---|
119 | playerId=$(expr "$line" : 'Removing player with id clientId=\([0-9]*\), entityId=[0-9]*$')
|
---|
120 | entityId=$(expr "$line" : 'Removing player with id clientId=[0-9]*, entityId=\([0-9]*\)$')
|
---|
121 | handleDisconnect "$playerId" "$entityId"
|
---|
122 | unset playerId entityId
|
---|
123 | else
|
---|
124 | #GMSG: .*$
|
---|
125 | if [ -n "$(echo "$line" | grep -E '^GMSG: .+')" ]; then
|
---|
126 | msg=$(expr "$line" : 'GMSG: \(.*\)$')
|
---|
127 | handleChat "$msg"
|
---|
128 | unset msg
|
---|
129 | else
|
---|
130 | #Executed command ".*" from player ".*"$
|
---|
131 | if [ -n "$(echo "$line" | grep '^Executed command ')" ]; then
|
---|
132 | cmd=$(expr "$line" : 'Executed command "\(.*\)" from player ".*"$')
|
---|
133 | nick=$(expr "$line" : 'Executed command ".*" from player "\(.*\)"$')
|
---|
134 | handleRemoteCommand "$cmd" "$nick"
|
---|
135 | unset cmd nick
|
---|
136 | else
|
---|
137 | #Telnet executed ".*" from: .*$
|
---|
138 | if [ -n "$(echo "$line" | grep '^Telnet executed ')" ]; then
|
---|
139 | cmd=$(expr "$line" : 'Telnet executed "\(.*\)" from: .*$')
|
---|
140 | ip=$(expr "$line" : 'Telnet executed ".*" from: \(.*\)$')
|
---|
141 | handleTelnetCommand "$cmd" "$ip"
|
---|
142 | unset cmd ip
|
---|
143 | fi
|
---|
144 | fi
|
---|
145 | fi
|
---|
146 | fi
|
---|
147 | fi
|
---|
148 | fi
|
---|
149 | done
|
---|