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=$2
|
---|
13 | #LOG=$(getInstancePath $INSTANCE)/logs/$(date '+%Y-%m-%d_%H-%M-%S')_output_log.txt
|
---|
14 | CHATLOG=$(getInstancePath $INSTANCE)/logs/$(date '+%Y-%m-%d_%H-%M-%S')_chat.log
|
---|
15 | COMMANDLOG=$(getInstancePath $INSTANCE)/logs/$(date '+%Y-%m-%d_%H-%M-%S')_commandExecution.log
|
---|
16 |
|
---|
17 | timestamp() {
|
---|
18 | date '+%Y.%m.%d %H:%M:%S'
|
---|
19 | }
|
---|
20 |
|
---|
21 | handleConnect() {
|
---|
22 | local entityId="$1"
|
---|
23 | local name="$2"
|
---|
24 | local steamId="$3"
|
---|
25 | local ip="$4"
|
---|
26 |
|
---|
27 | logPlayerConnect $INSTANCE "$entityId" "$name" "$steamId" "$ip"
|
---|
28 |
|
---|
29 | for H in $(getHooksFor playerConnect); do
|
---|
30 | $H $INSTANCE "$entityId" "$name" "$steamId" "$ip"
|
---|
31 | done
|
---|
32 | }
|
---|
33 |
|
---|
34 | handleDisconnect() {
|
---|
35 | local playerId="$1"
|
---|
36 | local entityId="$2"
|
---|
37 |
|
---|
38 | logPlayerDisconnect $INSTANCE "$entityId"
|
---|
39 |
|
---|
40 | for H in $(getHooksFor playerDisconnect); do
|
---|
41 | $H $INSTANCE "$playerId" "$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 | rm $(getInstancePath $INSTANCE)/logs/current_output_log.txt
|
---|
83 | rm $(getInstancePath $INSTANCE)/logs/current_chat.log
|
---|
84 | rm $(getInstancePath $INSTANCE)/logs/current_commandExecution.log
|
---|
85 | ln -s $LOG $(getInstancePath $INSTANCE)/logs/current_output_log.txt
|
---|
86 | ln -s $CHATLOG $(getInstancePath $INSTANCE)/logs/current_chat.log
|
---|
87 | ln -s $COMMANDLOG $(getInstancePath $INSTANCE)/logs/current_commandExecution.log
|
---|
88 |
|
---|
89 | sleep 5
|
---|
90 |
|
---|
91 | NOBUF="stdbuf -e0 -o0"
|
---|
92 |
|
---|
93 | $NOBUF tail -n 5000 -F $LOG |
|
---|
94 | $NOBUF tr '\\' '/' |
|
---|
95 | $NOBUF tr -d '\r' |
|
---|
96 | $NOBUF grep -v "^(Filename: " |
|
---|
97 | $NOBUF sed -r 's/^[0-9]+-[0-9]+-[0-9]+T[0-9]+:[0-9]+:[0-9]+ [0-9]+[.,][0-9]+ [A-Z]+ (.*)$/\1/' |
|
---|
98 | while read line ; do
|
---|
99 | if [ -n "$line" ]; then
|
---|
100 | #Player connected, entityid=1278, name=termo2, steamid=76561197997439820, ip=178.203.27.140
|
---|
101 | #Player connected, entityid=[0-9]*, name=.*, steamid=[0-9]*, ip=[0-9.]*$
|
---|
102 | if [ -n "$(echo "$line" | grep '^Player connected,')" ]; then
|
---|
103 | entityId=$(expr "$line" : 'Player connected, entityid=\([0-9]*\), name=.*, steamid=[0-9]*, ip=[0-9.]*$')
|
---|
104 | playerName=$(expr "$line" : 'Player connected, entityid=[0-9]*, name=\(.*\), steamid=[0-9]*, ip=[0-9.]*$')
|
---|
105 | steamId=$(expr "$line" : 'Player connected, entityid=[0-9]*, name=.*, steamid=\([0-9]*\), ip=[0-9.]*$')
|
---|
106 | ip=$(expr "$line" : 'Player connected, entityid=[0-9]*, name=.*, steamid=[0-9]*, ip=\([0-9.]*\)$')
|
---|
107 | sleep 1
|
---|
108 | handleConnect "$entityId" "$playerName" "$steamId" "$ip"
|
---|
109 | unset entityId playerName steamId ip
|
---|
110 | else
|
---|
111 | #Player disconnected: EntityID=[0-9]*, PlayerID='[0-9]*', OwnerID='[0-9]*', PlayerName='.*'$
|
---|
112 | if [ -n "$(echo "$line" | grep '^Player disconnected: ')" ]; then
|
---|
113 | playerId=$(expr "$line" : "Player disconnected: EntityID=[0-9]*, PlayerID='\([0-9]*\)', OwnerID='[0-9]*', PlayerName='.*'$")
|
---|
114 | entityId=$(expr "$line" : "Player disconnected: EntityID=\([0-9]*\), PlayerID='[0-9]*', OwnerID='[0-9]*', PlayerName='.*'$")
|
---|
115 | handleDisconnect "$playerId" "$entityId"
|
---|
116 | unset playerId entityId
|
---|
117 | else
|
---|
118 | #GMSG: .*$
|
---|
119 | if [ -n "$(echo "$line" | grep -E '^GMSG: .+')" ]; then
|
---|
120 | msg=$(expr "$line" : 'GMSG: \(.*\)$')
|
---|
121 | handleChat "$msg"
|
---|
122 | unset msg
|
---|
123 | else
|
---|
124 | #Executing command ".*" from client ".*"$
|
---|
125 | if [ -n "$(echo "$line" | grep '^Executing command '.*' from client')" ]; then
|
---|
126 | cmd=$(expr "$line" : "Executing command '\(.*\)' from client .*$")
|
---|
127 | nick=$(expr "$line" : "Executing command '.*' from client \(.*\)$")
|
---|
128 | handleRemoteCommand "$cmd" "$nick"
|
---|
129 | unset cmd nick
|
---|
130 | else
|
---|
131 | #Executing command ".*" by Telnet from .*$
|
---|
132 | if [ -n "$(echo "$line" | grep '^Executing command '.*' by Telnet from ')" ]; then
|
---|
133 | cmd=$(expr "$line" : "Executing command '\(.*\)' by Telnet from .*$")
|
---|
134 | ip=$(expr "$line" : "Executing command '.*' by Telnet from \(.*\)$")
|
---|
135 | handleTelnetCommand "$cmd" "$ip"
|
---|
136 | unset cmd ip
|
---|
137 | fi
|
---|
138 | fi
|
---|
139 | fi
|
---|
140 | fi
|
---|
141 | fi
|
---|
142 | fi
|
---|
143 | done
|
---|