Changeset 67 for scripts/usr/local/lib/7dtd/playerlog.sh
- Timestamp:
- Jul 10, 2014, 9:59:02 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
scripts/usr/local/lib/7dtd/playerlog.sh
r63 r67 1 1 #!/bin/bash 2 3 PLAYERSXML=$(getInstancePath $1)/players.xml 4 PLAYERSLOG=$(getInstancePath $1)/logs/$(date '+%Y-%m-%d_%H-%M-%S')_players.log 2 5 3 6 timestamp() { … … 6 9 7 10 # Create empty player list if not existing 8 # Params:9 # 1: Instance name10 11 createPlayerList() { 11 PLAYERLIST=$(getInstancePath $1)/players.xml 12 if [ ! -f $PLAYERLIST ]; then 13 echo "<Players/>" > $PLAYERLIST 12 if [ ! -f $PLAYERSXML ]; then 13 echo "<Players/>" > $PLAYERSXML 14 14 fi 15 15 } 16 16 17 17 # Set all players for an instance to offline (on startup/shutdown) 18 # Params:19 # 1: Instance name20 18 setAllPlayersOffline() { 21 PLAYERLIST=$(getInstancePath $1)/players.xml 22 createPlayerList "$1" 19 createPlayerList 23 20 $XMLSTARLET ed -L \ 24 21 -u "/Players/Player/@online" -v "false" \ 25 $PLAYER LIST22 $PLAYERSXML 26 23 } 27 24 … … 33 30 # 4: Nick name 34 31 logPlayerConnect() { 35 PLAYERLOG=$(getInstancePath $1)/players.log36 PLAYERLIST=$(getInstancePath $1)/players.xml37 32 ENTITYID="$2" 38 33 STEAMID="$3" 39 34 NICKNAME="$4" 40 35 41 echo "$(timestamp) +++ $ENTITYID $NICKNAME $STEAMID" >> $PLAYER LOG36 echo "$(timestamp) +++ $ENTITYID $NICKNAME $STEAMID" >> $PLAYERSLOG 42 37 43 createPlayerList "$1"38 createPlayerList 44 39 45 40 XPATHBASE="/Players/Player[@steamid='$STEAMID']" 46 41 47 if [ -z $($XMLSTARLET sel -t -v "$XPATHBASE/@steamid" $PLAYER LIST) ]; then42 if [ -z $($XMLSTARLET sel -t -v "$XPATHBASE/@steamid" $PLAYERSXML) ]; then 48 43 $XMLSTARLET ed -L \ 49 44 -s "/Players" -t elem -n "Player" -v "" \ … … 55 50 -i "$XPATHBASE" -t attr -n "online" -v "true" \ 56 51 -i "$XPATHBASE" -t attr -n "entityid" -v "$ENTITYID" \ 57 $PLAYER LIST52 $PLAYERSXML 58 53 else 59 LOGINS=$($XMLSTARLET sel -t -v "$XPATHBASE/@logins" $PLAYER LIST)54 LOGINS=$($XMLSTARLET sel -t -v "$XPATHBASE/@logins" $PLAYERSXML) 60 55 (( LOGINS++ )) 61 56 $XMLSTARLET ed -L \ … … 64 59 -u "$XPATHBASE/@entityid" -v "$ENTITYID" \ 65 60 -u "$XPATHBASE/@logins" -v "$LOGINS" \ 66 $PLAYER LIST61 $PLAYERSXML 67 62 fi 68 63 } … … 73 68 # 2: Entity ID 74 69 logPlayerDisconnect() { 75 PLAYERLOG=$(getInstancePath $1)/players.log76 PLAYERLIST=$(getInstancePath $1)/players.xml77 70 ENTITYID="$2" 78 71 79 createPlayerList "$1"72 createPlayerList 80 73 81 74 XPATHBASE="/Players/Player[@entityid='$ENTITYID'][@online='true']" 82 75 83 if [ -f $PLAYER LIST]; then84 if [ ! -z $($XMLSTARLET sel -t -v "$XPATHBASE/@steamid" $PLAYER LIST) ]; then85 NICKNAME=$($XMLSTARLET sel -t -v "$XPATHBASE/@nick" $PLAYER LIST)86 STEAMID=$($XMLSTARLET sel -t -v "$XPATHBASE/@steamid" $PLAYER LIST)87 LOGINTIME=$($XMLSTARLET sel -t -v "$XPATHBASE/@lastlogin" $PLAYER LIST)88 PLAYTIME=$($XMLSTARLET sel -t -v "$XPATHBASE/@playtime" $PLAYER LIST)76 if [ -f $PLAYERSXML ]; then 77 if [ ! -z $($XMLSTARLET sel -t -v "$XPATHBASE/@steamid" $PLAYERSXML) ]; then 78 NICKNAME=$($XMLSTARLET sel -t -v "$XPATHBASE/@nick" $PLAYERSXML) 79 STEAMID=$($XMLSTARLET sel -t -v "$XPATHBASE/@steamid" $PLAYERSXML) 80 LOGINTIME=$($XMLSTARLET sel -t -v "$XPATHBASE/@lastlogin" $PLAYERSXML) 81 PLAYTIME=$($XMLSTARLET sel -t -v "$XPATHBASE/@playtime" $PLAYERSXML) 89 82 NOW=$(date '+%s') 90 83 PLAYTIME=$(( PLAYTIME + NOW - LOGINTIME )) … … 92 85 -u "$XPATHBASE/@playtime" -v "$PLAYTIME" \ 93 86 -u "$XPATHBASE/@online" -v "false" \ 94 $PLAYER LIST87 $PLAYERSXML 95 88 fi 96 89 fi 97 90 98 echo "$(timestamp) --- $ENTITYID $NICKNAME $STEAMID" >> $PLAYER LOG91 echo "$(timestamp) --- $ENTITYID $NICKNAME $STEAMID" >> $PLAYERSLOG 99 92 } 100 93
Note:
See TracChangeset
for help on using the changeset viewer.