source: scripts/usr/local/lib/7dtd/monitor-log.sh@ 482

Last change on this file since 482 was 482, checked in by alloc, 12 months ago

Scripts

  • Property svn:executable set to *
File size: 8.2 KB
RevLine 
[17]1#!/bin/bash
2
[258]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
[17]18. /usr/local/lib/7dtd/common.sh
[67]19. /usr/local/lib/7dtd/playerlog.sh
[17]20
21if [ $(isValidInstance $1) -eq 0 ]; then
22 echo "No instance given or not a valid instance!"
23 return
24fi
25
26INSTANCE=$1
[240]27LOGTIMESTAMP=$2
28LOG=$(getInstancePath $INSTANCE)/logs/${LOGTIMESTAMP}_output_log.txt
29CHATLOG=$(getInstancePath $INSTANCE)/logs/${LOGTIMESTAMP}_chat.log
30COMMANDLOG=$(getInstancePath $INSTANCE)/logs/${LOGTIMESTAMP}_commandExecution.log
[17]31
32timestamp() {
33 date '+%Y.%m.%d %H:%M:%S'
34}
35
36handleConnect() {
[234]37 local entityId="$1"
38 local name="$2"
[482]39 local platformId="$3"
40 local crossId="$4"
41 local ip="$5"
42 local ownerId="$6"
[17]43
[482]44 logPlayerConnect $INSTANCE "$entityId" "$name" "$platformId" "$crossId" "$ip" "$ownerId"
[17]45
[259]46 for H in $(getHooksFor playerConnect $INSTANCE); do
[482]47 $H $INSTANCE "$entityId" "$name" "$platformId" "$ip" "$ownerId" "$crossId"
[17]48 done
49}
50
51handleDisconnect() {
[482]52 local entityId="$1"
[17]53
[87]54 logPlayerDisconnect $INSTANCE "$entityId"
55
[259]56 for H in $(getHooksFor playerDisconnect $INSTANCE); do
[482]57 $H $INSTANCE "$entityId" "$NICKNAME" "$PLATFORMID" "$IP" "$OWNERID" "$CROSSID"
[17]58 done
59}
60
[308]61handlePlayerSpawnedInWorld() {
62 local entityId="$1"
[482]63 local platformId="$2"
64 local crossId="$3"
65 local ownerId="$4"
66 local playerName="$5"
67 local reason="$6"
68 local position="$7"
[308]69
70 for H in $(getHooksFor playerSpawned $INSTANCE); do
[482]71 $H $INSTANCE "$entityId" "$platformId" "$ownerId" "$playerName" "$reason" "$position" "$crossId"
[308]72 done
73}
74
[62]75handleChat() {
[344]76 echo "$(timestamp): $1: $2 (SteamID $3, EntityID $4, Target $5)" >> $CHATLOG
[62]77
[259]78 for H in $(getHooksFor chat $INSTANCE); do
[344]79 $H $INSTANCE "$1" "$2" "$3" "$4" "$5"
[275]80 done
81}
82
83handleGmsg() {
84 echo "$(timestamp): GMSG: $1" >> $CHATLOG
85
86 for H in $(getHooksFor gmsg $INSTANCE); do
[63]87 $H $INSTANCE "$1"
[62]88 done
89}
90
[87]91handleRemoteCommand() {
92 local cmd="$1"
93 local name="$2"
94
95 echo "$(timestamp): Player \"$name\" executed \"$cmd\"" >> $COMMANDLOG
96
[259]97 for H in $(getHooksFor remoteCommand $INSTANCE); do
[87]98 $H $INSTANCE "$cmd" "$name"
99 done
100}
101
102handleTelnetCommand() {
103 local cmd="$1"
104 local ip="$2"
105
106 echo "$(timestamp): Telnet from \"$ip\" executed \"$cmd\"" >> $COMMANDLOG
107
[259]108 for H in $(getHooksFor telnetCommand $INSTANCE); do
[87]109 $H $INSTANCE "$cmd" "$ip"
110 done
111}
112
113
[67]114if [ ! -d "$(getInstancePath $INSTANCE)/logs" ]; then
115 mkdir "$(getInstancePath $INSTANCE)/logs"
116fi
117
118setAllPlayersOffline
119
[219]120rm $(getInstancePath $INSTANCE)/logs/current_output_log.txt
[87]121rm $(getInstancePath $INSTANCE)/logs/current_chat.log
122rm $(getInstancePath $INSTANCE)/logs/current_commandExecution.log
[219]123ln -s $LOG $(getInstancePath $INSTANCE)/logs/current_output_log.txt
[87]124ln -s $CHATLOG $(getInstancePath $INSTANCE)/logs/current_chat.log
125ln -s $COMMANDLOG $(getInstancePath $INSTANCE)/logs/current_commandExecution.log
126
[18]127sleep 5
128
[17]129NOBUF="stdbuf -e0 -o0"
130
[220]131$NOBUF tail -n 5000 -F $LOG |
[17]132$NOBUF tr '\\' '/' |
133$NOBUF tr -d '\r' |
134$NOBUF grep -v "^(Filename: " |
[219]135$NOBUF sed -r 's/^[0-9]+-[0-9]+-[0-9]+T[0-9]+:[0-9]+:[0-9]+ [0-9]+[.,][0-9]+ [A-Z]+ (.*)$/\1/' |
[17]136while read line ; do
137 if [ -n "$line" ]; then
[482]138 #Player connected, entityid=1278, name=termo2, pltfmid=Steam_76561197997439820, crossid=EOS_eab...421, steamOwner=Steam_76561197997439820, ip=178.203.27.140
[298]139 #Player connected, entityid=[0-9]*, name=.*, steamid=[0-9]*, steamOwner=[0-9]*, ip=[a-fA-F:0-9.]*$
[87]140 if [ -n "$(echo "$line" | grep '^Player connected,')" ]; then
[482]141 entityId=$(expr "$line" : 'Player connected, entityid=\([0-9]*\), name=.*, pltfmid=.*, crossid=.*, steamOwner=.*, ip=[a-fA-F:0-9.]*$')
142 playerName=$(expr "$line" : 'Player connected, entityid=[0-9]*, name=\(.*\), pltfmid=.*, crossid=.*, steamOwner=.*, ip=[a-fA-F:0-9.]*$')
143 platformId=$(expr "$line" : 'Player connected, entityid=[0-9]*, name=.*, pltfmid=\(.*\), crossid=.*, steamOwner=.*, ip=[a-fA-F:0-9.]*$')
144 crossId=$(expr "$line" : 'Player connected, entityid=[0-9]*, name=.*, pltfmid=.*, crossid=\(.*\), steamOwner=.*, ip=[a-fA-F:0-9.]*$')
145 steamOwner=$(expr "$line" : 'Player connected, entityid=[0-9]*, name=.*, pltfmid=.*, crossid=.*, steamOwner=\(.*\), ip=[a-fA-F:0-9.]*$')
146 ip=$(expr "$line" : 'Player connected, entityid=[0-9]*, name=.*, pltfmid=.*, crossid=.*, steamOwner=.*, ip=\([a-fA-F:0-9.]*\)$')
[17]147 sleep 1
[482]148 handleConnect "$entityId" "$playerName" "$platformId" "$crossId" "$ip" "$steamOwner"
149 unset entityId playerName platformId crossId steamOwner ip
[234]150 #Player disconnected: EntityID=[0-9]*, PlayerID='[0-9]*', OwnerID='[0-9]*', PlayerName='.*'$
[308]151 elif [ -n "$(echo "$line" | grep '^Player disconnected: ')" ]; then
[482]152 entityId=$(expr "$line" : "Player disconnected: EntityID=\(.*\), PltfmId='.*$")
153 handleDisconnect "$entityId"
154 unset entityId
155 #PlayerSpawnedInWorld (reason: .*, position: .*, .*, .*): EntityID=.*, PltfmId='.*', CrossId='.*', OwnerID='.*', PlayerName='.*', ClientNumber='.*'
[308]156 elif [ -n "$(echo "$line" | grep '^PlayerSpawnedInWorld ')" ]; then
[482]157 reason=$(expr "$line" : "PlayerSpawnedInWorld (reason: \(.*\), position: .*, .*, .*): EntityID=.*, PltfmId='.*', CrossId='.*', OwnerID='.*', PlayerName='.*', ClientNumber='.*'$")
158 position=$(expr "$line" : "PlayerSpawnedInWorld (reason: .*, position: \(.*, .*, .*\)): EntityID=.*, PltfmId='.*', CrossId='.*', OwnerID='.*', PlayerName='.*', ClientNumber='.*'$")
159 entityId=$(expr "$line" : "PlayerSpawnedInWorld (reason: .*, position: .*, .*, .*): EntityID=\(.*\), PltfmId='.*', CrossId='.*', OwnerID='.*', PlayerName='.*', ClientNumber='.*'$")
160 platformId=$(expr "$line" : "PlayerSpawnedInWorld (reason: .*, position: .*, .*, .*): EntityID=.*, PltfmId='\(.*\)', CrossId='.*', OwnerID='.*', PlayerName='.*', ClientNumber='.*'$")
161 crossId=$(expr "$line" : "PlayerSpawnedInWorld (reason: .*, position: .*, .*, .*): EntityID=.*, PltfmId='.*', CrossId='\(.*\)', OwnerID='.*', PlayerName='.*', ClientNumber='.*'$")
162 ownerId=$(expr "$line" : "PlayerSpawnedInWorld (reason: .*, position: .*, .*, .*): EntityID=.*, PltfmId='.*', CrossId='.*', OwnerID='\(.*\)', PlayerName='.*', ClientNumber='.*'$")
163 playerName=$(expr "$line" : "PlayerSpawnedInWorld (reason: .*, position: .*, .*, .*): EntityID=.*, PltfmId='.*', CrossId='.*', OwnerID='.*', PlayerName='\(.*\)', ClientNumber='.*'$")
164 handlePlayerSpawnedInWorld "$entityId" "$platformId" "$crossId" "$ownerId" "$playerName" "$reason" "$position"
165 unset reason position entityId platformId crossId ownerId playerName
[87]166 #GMSG: .*$
[308]167 elif [ -n "$(echo "$line" | grep -E '^GMSG: .+')" ]; then
[62]168 msg=$(expr "$line" : 'GMSG: \(.*\)$')
[275]169 handleGmsg "$msg"
[62]170 unset msg
[344]171 #Chat (from '<steamid>', entity id '<entityid>', to '<targettype>'): '<senderchatname>': <msg>
172 elif [ -n "$(echo "$line" | grep -E '^Chat .+')" ]; then
[482]173 steamId=$(expr "$line" : "Chat (from '\(.*\)', entity id '.*', to '.*'): '.*': .*$")
174 entityId=$(expr "$line" : "Chat (from '.*', entity id '\(.*\)', to '.*'): '.*': .*$")
175 targetType=$(expr "$line" : "Chat (from '.*', entity id '.*', to '\(.*\)'): '.*': .*$")
176 name=$(expr "$line" : "Chat (from '.*', entity id '.*', to '.*'): '\(.*\)': .*$")
177 msg=$(expr "$line" : "Chat (from '.*', entity id '.*', to '.*'): '.*': \(.*\)$")
[344]178 handleChat "$name" "$msg" "$steamId" "$entityId" "$targetType"
179 unset name msg steamId entityId targetType
[234]180 #Executing command ".*" from client ".*"$
[308]181 elif [ -n "$(echo "$line" | grep '^Executing command '.*' from client')" ]; then
[234]182 cmd=$(expr "$line" : "Executing command '\(.*\)' from client .*$")
183 nick=$(expr "$line" : "Executing command '.*' from client \(.*\)$")
[87]184 handleRemoteCommand "$cmd" "$nick"
185 unset cmd nick
[234]186 #Executing command ".*" by Telnet from .*$
[308]187 elif [ -n "$(echo "$line" | grep '^Executing command '.*' by Telnet from ')" ]; then
[234]188 cmd=$(expr "$line" : "Executing command '\(.*\)' by Telnet from .*$")
189 ip=$(expr "$line" : "Executing command '.*' by Telnet from \(.*\)$")
[87]190 handleTelnetCommand "$cmd" "$ip"
191 unset cmd ip
[17]192 fi
193 fi
194done
Note: See TracBrowser for help on using the repository browser.