1 | #!/bin/bash
|
---|
2 |
|
---|
3 | # Copyright 2016 Christian 'Alloc' Illy
|
---|
4 | #
|
---|
5 | # Licensed under the Apache License, Version 2.0 (the "License");
|
---|
6 | # you may not use this file except in compliance with the License.
|
---|
7 | # You may obtain a copy of the License at
|
---|
8 | #
|
---|
9 | # http://www.apache.org/licenses/LICENSE-2.0
|
---|
10 | #
|
---|
11 | # Unless required by applicable law or agreed to in writing, software
|
---|
12 | # distributed under the License is distributed on an "AS IS" BASIS,
|
---|
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
14 | # See the License for the specific language governing permissions and
|
---|
15 | # limitations under the License.
|
---|
16 |
|
---|
17 |
|
---|
18 | . /usr/local/lib/7dtd/common.sh
|
---|
19 | . /usr/local/lib/7dtd/playerlog.sh
|
---|
20 |
|
---|
21 | if [ $(isValidInstance $1) -eq 0 ]; then
|
---|
22 | echo "No instance given or not a valid instance!"
|
---|
23 | return
|
---|
24 | fi
|
---|
25 |
|
---|
26 | INSTANCE=$1
|
---|
27 | LOGTIMESTAMP=$2
|
---|
28 | LOG=$(getInstancePath $INSTANCE)/logs/${LOGTIMESTAMP}_output_log.txt
|
---|
29 | CHATLOG=$(getInstancePath $INSTANCE)/logs/${LOGTIMESTAMP}_chat.log
|
---|
30 | COMMANDLOG=$(getInstancePath $INSTANCE)/logs/${LOGTIMESTAMP}_commandExecution.log
|
---|
31 |
|
---|
32 | timestamp() {
|
---|
33 | date '+%Y.%m.%d %H:%M:%S'
|
---|
34 | }
|
---|
35 |
|
---|
36 | handleConnect() {
|
---|
37 | local entityId="$1"
|
---|
38 | local name="$2"
|
---|
39 | local platformId="$3"
|
---|
40 | local crossId="$4"
|
---|
41 | local ip="$5"
|
---|
42 | local ownerId="$6"
|
---|
43 |
|
---|
44 | logPlayerConnect $INSTANCE "$entityId" "$name" "$platformId" "$crossId" "$ip" "$ownerId"
|
---|
45 |
|
---|
46 | for H in $(getHooksFor playerConnect $INSTANCE); do
|
---|
47 | $H $INSTANCE "$entityId" "$name" "$platformId" "$ip" "$ownerId" "$crossId"
|
---|
48 | done
|
---|
49 | }
|
---|
50 |
|
---|
51 | handleDisconnect() {
|
---|
52 | local entityId="$1"
|
---|
53 |
|
---|
54 | logPlayerDisconnect $INSTANCE "$entityId"
|
---|
55 |
|
---|
56 | for H in $(getHooksFor playerDisconnect $INSTANCE); do
|
---|
57 | $H $INSTANCE "$entityId" "$NICKNAME" "$PLATFORMID" "$IP" "$OWNERID" "$CROSSID"
|
---|
58 | done
|
---|
59 | }
|
---|
60 |
|
---|
61 | handlePlayerSpawnedInWorld() {
|
---|
62 | local entityId="$1"
|
---|
63 | local platformId="$2"
|
---|
64 | local crossId="$3"
|
---|
65 | local ownerId="$4"
|
---|
66 | local playerName="$5"
|
---|
67 | local reason="$6"
|
---|
68 | local position="$7"
|
---|
69 |
|
---|
70 | for H in $(getHooksFor playerSpawned $INSTANCE); do
|
---|
71 | $H $INSTANCE "$entityId" "$platformId" "$ownerId" "$playerName" "$reason" "$position" "$crossId"
|
---|
72 | done
|
---|
73 | }
|
---|
74 |
|
---|
75 | handleChat() {
|
---|
76 | echo "$(timestamp): $1: $2 (SteamID $3, EntityID $4, Target $5)" >> $CHATLOG
|
---|
77 |
|
---|
78 | for H in $(getHooksFor chat $INSTANCE); do
|
---|
79 | $H $INSTANCE "$1" "$2" "$3" "$4" "$5"
|
---|
80 | done
|
---|
81 | }
|
---|
82 |
|
---|
83 | handleGmsg() {
|
---|
84 | echo "$(timestamp): GMSG: $1" >> $CHATLOG
|
---|
85 |
|
---|
86 | for H in $(getHooksFor gmsg $INSTANCE); do
|
---|
87 | $H $INSTANCE "$1"
|
---|
88 | done
|
---|
89 | }
|
---|
90 |
|
---|
91 | handleRemoteCommand() {
|
---|
92 | local cmd="$1"
|
---|
93 | local name="$2"
|
---|
94 | local clientInfo="$3"
|
---|
95 |
|
---|
96 | echo "$(timestamp): Player \"$name\" executed \"$cmd\" (client $clientInfo)" >> $COMMANDLOG
|
---|
97 |
|
---|
98 | for H in $(getHooksFor remoteCommand $INSTANCE); do
|
---|
99 | $H $INSTANCE "$cmd" "$name"
|
---|
100 | done
|
---|
101 | }
|
---|
102 |
|
---|
103 | handleRemoteCommandDenied() {
|
---|
104 | local cmd="$1"
|
---|
105 | local name="$2"
|
---|
106 | local clientInfo="$3"
|
---|
107 |
|
---|
108 | echo "$(timestamp): Denied \"$name\" to exec command \"$cmd\" (client $clientInfo)" >> $COMMANDLOG
|
---|
109 |
|
---|
110 | for H in $(getHooksFor remoteCommandDenied $INSTANCE); do
|
---|
111 | $H $INSTANCE "$cmd" "$name"
|
---|
112 | done
|
---|
113 | }
|
---|
114 |
|
---|
115 | handleTelnetCommand() {
|
---|
116 | local cmd="$1"
|
---|
117 | local ip="$2"
|
---|
118 |
|
---|
119 | echo "$(timestamp): Telnet from \"$ip\" executed \"$cmd\"" >> $COMMANDLOG
|
---|
120 |
|
---|
121 | for H in $(getHooksFor telnetCommand $INSTANCE); do
|
---|
122 | $H $INSTANCE "$cmd" "$ip"
|
---|
123 | done
|
---|
124 | }
|
---|
125 |
|
---|
126 |
|
---|
127 | if [ ! -d "$(getInstancePath $INSTANCE)/logs" ]; then
|
---|
128 | mkdir "$(getInstancePath $INSTANCE)/logs"
|
---|
129 | fi
|
---|
130 |
|
---|
131 | setAllPlayersOffline
|
---|
132 |
|
---|
133 | rm $(getInstancePath $INSTANCE)/logs/current_output_log.txt
|
---|
134 | rm $(getInstancePath $INSTANCE)/logs/current_chat.log
|
---|
135 | rm $(getInstancePath $INSTANCE)/logs/current_commandExecution.log
|
---|
136 | ln -s $LOG $(getInstancePath $INSTANCE)/logs/current_output_log.txt
|
---|
137 | ln -s $CHATLOG $(getInstancePath $INSTANCE)/logs/current_chat.log
|
---|
138 | ln -s $COMMANDLOG $(getInstancePath $INSTANCE)/logs/current_commandExecution.log
|
---|
139 |
|
---|
140 | sleep 5
|
---|
141 |
|
---|
142 | NOBUF="stdbuf -e0 -o0"
|
---|
143 |
|
---|
144 | $NOBUF tail -n 5000 -F $LOG |
|
---|
145 | $NOBUF tr '\\' '/' |
|
---|
146 | $NOBUF tr -d '\r' |
|
---|
147 | $NOBUF grep -v "^(Filename: " |
|
---|
148 | $NOBUF sed -r 's/^[0-9]+-[0-9]+-[0-9]+T[0-9]+:[0-9]+:[0-9]+ [0-9]+[.,][0-9]+ [A-Z]+ (.*)$/\1/' |
|
---|
149 | while read line ; do
|
---|
150 | if [ -n "$line" ]; then
|
---|
151 | #Player connected, entityid=1278, name=termo2, pltfmid=Steam_76561197997439820, crossid=EOS_eab...421, steamOwner=Steam_76561197997439820, ip=178.203.27.140
|
---|
152 | #Player connected, entityid=[0-9]*, name=.*, steamid=[0-9]*, steamOwner=[0-9]*, ip=[a-fA-F:0-9.]*$
|
---|
153 | if [ -n "$(echo "$line" | grep '^Player connected,')" ]; then
|
---|
154 | entityId=$(expr "$line" : 'Player connected, entityid=\([0-9]*\), name=.*, pltfmid=.*, crossid=.*, steamOwner=.*, ip=[a-fA-F:0-9.]*$')
|
---|
155 | playerName=$(expr "$line" : 'Player connected, entityid=[0-9]*, name=\(.*\), pltfmid=.*, crossid=.*, steamOwner=.*, ip=[a-fA-F:0-9.]*$')
|
---|
156 | platformId=$(expr "$line" : 'Player connected, entityid=[0-9]*, name=.*, pltfmid=\(.*\), crossid=.*, steamOwner=.*, ip=[a-fA-F:0-9.]*$')
|
---|
157 | crossId=$(expr "$line" : 'Player connected, entityid=[0-9]*, name=.*, pltfmid=.*, crossid=\(.*\), steamOwner=.*, ip=[a-fA-F:0-9.]*$')
|
---|
158 | steamOwner=$(expr "$line" : 'Player connected, entityid=[0-9]*, name=.*, pltfmid=.*, crossid=.*, steamOwner=\(.*\), ip=[a-fA-F:0-9.]*$')
|
---|
159 | ip=$(expr "$line" : 'Player connected, entityid=[0-9]*, name=.*, pltfmid=.*, crossid=.*, steamOwner=.*, ip=\([a-fA-F:0-9.]*\)$')
|
---|
160 | sleep 1
|
---|
161 | handleConnect "$entityId" "$playerName" "$platformId" "$crossId" "$ip" "$steamOwner"
|
---|
162 | unset entityId playerName platformId crossId steamOwner ip
|
---|
163 | #Player disconnected: EntityID=[0-9]*, PlayerID='[0-9]*', OwnerID='[0-9]*', PlayerName='.*'$
|
---|
164 | elif [ -n "$(echo "$line" | grep '^Player disconnected: ')" ]; then
|
---|
165 | entityId=$(expr "$line" : "Player disconnected: EntityID=\(.*\), PltfmId='.*$")
|
---|
166 | handleDisconnect "$entityId"
|
---|
167 | unset entityId
|
---|
168 | #PlayerSpawnedInWorld (reason: .*, position: .*, .*, .*): EntityID=.*, PltfmId='.*', CrossId='.*', OwnerID='.*', PlayerName='.*', ClientNumber='.*'
|
---|
169 | elif [ -n "$(echo "$line" | grep '^PlayerSpawnedInWorld ')" ]; then
|
---|
170 | reason=$(expr "$line" : "PlayerSpawnedInWorld (reason: \(.*\), position: .*, .*, .*): EntityID=.*, PltfmId='.*', CrossId='.*', OwnerID='.*', PlayerName='.*', ClientNumber='.*'$")
|
---|
171 | position=$(expr "$line" : "PlayerSpawnedInWorld (reason: .*, position: \(.*, .*, .*\)): EntityID=.*, PltfmId='.*', CrossId='.*', OwnerID='.*', PlayerName='.*', ClientNumber='.*'$")
|
---|
172 | entityId=$(expr "$line" : "PlayerSpawnedInWorld (reason: .*, position: .*, .*, .*): EntityID=\(.*\), PltfmId='.*', CrossId='.*', OwnerID='.*', PlayerName='.*', ClientNumber='.*'$")
|
---|
173 | platformId=$(expr "$line" : "PlayerSpawnedInWorld (reason: .*, position: .*, .*, .*): EntityID=.*, PltfmId='\(.*\)', CrossId='.*', OwnerID='.*', PlayerName='.*', ClientNumber='.*'$")
|
---|
174 | crossId=$(expr "$line" : "PlayerSpawnedInWorld (reason: .*, position: .*, .*, .*): EntityID=.*, PltfmId='.*', CrossId='\(.*\)', OwnerID='.*', PlayerName='.*', ClientNumber='.*'$")
|
---|
175 | ownerId=$(expr "$line" : "PlayerSpawnedInWorld (reason: .*, position: .*, .*, .*): EntityID=.*, PltfmId='.*', CrossId='.*', OwnerID='\(.*\)', PlayerName='.*', ClientNumber='.*'$")
|
---|
176 | playerName=$(expr "$line" : "PlayerSpawnedInWorld (reason: .*, position: .*, .*, .*): EntityID=.*, PltfmId='.*', CrossId='.*', OwnerID='.*', PlayerName='\(.*\)', ClientNumber='.*'$")
|
---|
177 | handlePlayerSpawnedInWorld "$entityId" "$platformId" "$crossId" "$ownerId" "$playerName" "$reason" "$position"
|
---|
178 | unset reason position entityId platformId crossId ownerId playerName
|
---|
179 | #GMSG: .*$
|
---|
180 | elif [ -n "$(echo "$line" | grep -E '^GMSG: .+')" ]; then
|
---|
181 | msg=$(expr "$line" : 'GMSG: \(.*\)$')
|
---|
182 | handleGmsg "$msg"
|
---|
183 | unset msg
|
---|
184 | #Chat (from '<steamid>', entity id '<entityid>', to '<targettype>'): '<senderchatname>': <msg>
|
---|
185 | elif [ -n "$(echo "$line" | grep -E '^Chat .+')" ]; then
|
---|
186 | steamId=$(expr "$line" : "Chat (from '\(.*\)', entity id '.*', to '.*'): '.*': .*$")
|
---|
187 | entityId=$(expr "$line" : "Chat (from '.*', entity id '\(.*\)', to '.*'): '.*': .*$")
|
---|
188 | targetType=$(expr "$line" : "Chat (from '.*', entity id '.*', to '\(.*\)'): '.*': .*$")
|
---|
189 | name=$(expr "$line" : "Chat (from '.*', entity id '.*', to '.*'): '\(.*\)': .*$")
|
---|
190 | msg=$(expr "$line" : "Chat (from '.*', entity id '.*', to '.*'): '.*': \(.*\)$")
|
---|
191 | handleChat "$name" "$msg" "$steamId" "$entityId" "$targetType"
|
---|
192 | unset name msg steamId entityId targetType
|
---|
193 | #Executing command ".*" from client ".*"$
|
---|
194 | elif [ -n "$(echo "$line" | grep '^Executing command '.*' from client')" ]; then
|
---|
195 | cmd=$(expr "$line" : "Executing command '\(.*\)' from client EntityID=.*, PltfmId='.*', CrossId='.*', OwnerID='.*', PlayerName='.*', ClientNumber='.*'$")
|
---|
196 | clientInfo=$(expr "$line" : "Executing command '.*' from client \(.*\)$")
|
---|
197 | playerName=$(expr "$line" : "Executing command '.*' from client EntityID=.*, PltfmId='.*', CrossId='.*', OwnerID='.*', PlayerName='\(.*\)', ClientNumber='.*'$")
|
---|
198 | handleRemoteCommand "$cmd" "$playerName" "$clientInfo"
|
---|
199 | unset cmd playerName clientInfo
|
---|
200 | #Denying command ".*" from client ".*"$
|
---|
201 | elif [ -n "$(echo "$line" | grep '^Denying command '.*' from client')" ]; then
|
---|
202 | cmd=$(expr "$line" : "Denying command '\(.*\)' from client EntityID=.*, PltfmId='.*', CrossId='.*', OwnerID='.*', PlayerName='.*', ClientNumber='.*'$")
|
---|
203 | clientInfo=$(expr "$line" : "Denying command '.*' from client \(.*\)$")
|
---|
204 | playerName=$(expr "$line" : "Denying command '.*' from client EntityID=.*, PltfmId='.*', CrossId='.*', OwnerID='.*', PlayerName='\(.*\)', ClientNumber='.*'$")
|
---|
205 | handleRemoteCommandDenied "$cmd" "$playerName" "$clientInfo"
|
---|
206 | unset cmd playerName clientInfo
|
---|
207 | #Executing command ".*" by Telnet from .*$
|
---|
208 | elif [ -n "$(echo "$line" | grep '^Executing command '.*' by Telnet from ')" ]; then
|
---|
209 | cmd=$(expr "$line" : "Executing command '\(.*\)' by Telnet from .*$")
|
---|
210 | ip=$(expr "$line" : "Executing command '.*' by Telnet from \(.*\)$")
|
---|
211 | handleTelnetCommand "$cmd" "$ip"
|
---|
212 | unset cmd ip
|
---|
213 | fi
|
---|
214 | fi
|
---|
215 | done
|
---|