[17] | 1 | #!/bin/bash
|
---|
| 2 |
|
---|
| 3 | . /usr/local/lib/7dtd/common.sh
|
---|
[67] | 4 | . /usr/local/lib/7dtd/playerlog.sh
|
---|
[17] | 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
|
---|
[219] | 12 | LOG=$2
|
---|
| 13 | #LOG=$(getInstancePath $INSTANCE)/logs/$(date '+%Y-%m-%d_%H-%M-%S')_output_log.txt
|
---|
[67] | 14 | CHATLOG=$(getInstancePath $INSTANCE)/logs/$(date '+%Y-%m-%d_%H-%M-%S')_chat.log
|
---|
[87] | 15 | COMMANDLOG=$(getInstancePath $INSTANCE)/logs/$(date '+%Y-%m-%d_%H-%M-%S')_commandExecution.log
|
---|
[17] | 16 |
|
---|
| 17 | timestamp() {
|
---|
| 18 | date '+%Y.%m.%d %H:%M:%S'
|
---|
| 19 | }
|
---|
| 20 |
|
---|
| 21 | handleConnect() {
|
---|
[234] | 22 | local entityId="$1"
|
---|
| 23 | local name="$2"
|
---|
| 24 | local steamId="$3"
|
---|
| 25 | local ip="$4"
|
---|
[17] | 26 |
|
---|
[87] | 27 | logPlayerConnect $INSTANCE "$entityId" "$name" "$steamId" "$ip"
|
---|
[17] | 28 |
|
---|
| 29 | for H in $(getHooksFor playerConnect); do
|
---|
[234] | 30 | $H $INSTANCE "$entityId" "$name" "$steamId" "$ip"
|
---|
[17] | 31 | done
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | handleDisconnect() {
|
---|
[234] | 35 | local playerId="$1"
|
---|
[87] | 36 | local entityId="$2"
|
---|
[17] | 37 |
|
---|
[87] | 38 | logPlayerDisconnect $INSTANCE "$entityId"
|
---|
| 39 |
|
---|
[17] | 40 | for H in $(getHooksFor playerDisconnect); do
|
---|
[234] | 41 | $H $INSTANCE "$playerId" "$entityId" "$NICKNAME" "$STEAMID"
|
---|
[17] | 42 | done
|
---|
| 43 | }
|
---|
| 44 |
|
---|
[62] | 45 | handleChat() {
|
---|
| 46 | echo "$(timestamp): $1" >> $CHATLOG
|
---|
| 47 |
|
---|
| 48 | for H in $(getHooksFor chat); do
|
---|
[63] | 49 | $H $INSTANCE "$1"
|
---|
[62] | 50 | done
|
---|
| 51 | }
|
---|
| 52 |
|
---|
[87] | 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 |
|
---|
[67] | 76 | if [ ! -d "$(getInstancePath $INSTANCE)/logs" ]; then
|
---|
| 77 | mkdir "$(getInstancePath $INSTANCE)/logs"
|
---|
| 78 | fi
|
---|
| 79 |
|
---|
| 80 | setAllPlayersOffline
|
---|
| 81 |
|
---|
[219] | 82 | rm $(getInstancePath $INSTANCE)/logs/current_output_log.txt
|
---|
[87] | 83 | rm $(getInstancePath $INSTANCE)/logs/current_chat.log
|
---|
| 84 | rm $(getInstancePath $INSTANCE)/logs/current_commandExecution.log
|
---|
[219] | 85 | ln -s $LOG $(getInstancePath $INSTANCE)/logs/current_output_log.txt
|
---|
[87] | 86 | ln -s $CHATLOG $(getInstancePath $INSTANCE)/logs/current_chat.log
|
---|
| 87 | ln -s $COMMANDLOG $(getInstancePath $INSTANCE)/logs/current_commandExecution.log
|
---|
| 88 |
|
---|
[18] | 89 | sleep 5
|
---|
| 90 |
|
---|
[17] | 91 | NOBUF="stdbuf -e0 -o0"
|
---|
| 92 |
|
---|
[220] | 93 | $NOBUF tail -n 5000 -F $LOG |
|
---|
[17] | 94 | $NOBUF tr '\\' '/' |
|
---|
| 95 | $NOBUF tr -d '\r' |
|
---|
| 96 | $NOBUF grep -v "^(Filename: " |
|
---|
[219] | 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/' |
|
---|
[17] | 98 | while read line ; do
|
---|
| 99 | if [ -n "$line" ]; then
|
---|
[234] | 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.]*$
|
---|
[87] | 102 | if [ -n "$(echo "$line" | grep '^Player connected,')" ]; then
|
---|
[234] | 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.]*\)$')
|
---|
[17] | 107 | sleep 1
|
---|
[234] | 108 | handleConnect "$entityId" "$playerName" "$steamId" "$ip"
|
---|
| 109 | unset entityId playerName steamId ip
|
---|
[62] | 110 | else
|
---|
[234] | 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='.*'$")
|
---|
[57] | 115 | handleDisconnect "$playerId" "$entityId"
|
---|
[17] | 116 | unset playerId entityId
|
---|
[62] | 117 | else
|
---|
[87] | 118 | #GMSG: .*$
|
---|
[62] | 119 | if [ -n "$(echo "$line" | grep -E '^GMSG: .+')" ]; then
|
---|
| 120 | msg=$(expr "$line" : 'GMSG: \(.*\)$')
|
---|
| 121 | handleChat "$msg"
|
---|
| 122 | unset msg
|
---|
[87] | 123 | else
|
---|
[234] | 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 \(.*\)$")
|
---|
[87] | 128 | handleRemoteCommand "$cmd" "$nick"
|
---|
| 129 | unset cmd nick
|
---|
| 130 | else
|
---|
[234] | 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 \(.*\)$")
|
---|
[87] | 135 | handleTelnetCommand "$cmd" "$ip"
|
---|
| 136 | unset cmd ip
|
---|
[17] | 137 | fi
|
---|
[62] | 138 | fi
|
---|
| 139 | fi
|
---|
[87] | 140 | fi
|
---|
| 141 | fi
|
---|
[17] | 142 | fi
|
---|
| 143 | done
|
---|