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

Last change on this file since 223 was 220, checked in by alloc, 10 years ago

scripts 72

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