Ignore:
Timestamp:
Jul 10, 2014, 9:59:02 PM (10 years ago)
Author:
alloc
Message:

v25: Fixes #22, #23. Also adds new serverconfig options

File:
1 edited

Legend:

Unmodified
Added
Removed
  • scripts/usr/local/lib/7dtd/playerlog.sh

    r63 r67  
    11#!/bin/bash
     2
     3PLAYERSXML=$(getInstancePath $1)/players.xml
     4PLAYERSLOG=$(getInstancePath $1)/logs/$(date '+%Y-%m-%d_%H-%M-%S')_players.log
    25
    36timestamp() {
     
    69
    710# Create empty player list if not existing
    8 # Params:
    9 #   1: Instance name
    1011createPlayerList() {
    11         PLAYERLIST=$(getInstancePath $1)/players.xml
    12         if [ ! -f $PLAYERLIST ]; then
    13                 echo "<Players/>" > $PLAYERLIST
     12        if [ ! -f $PLAYERSXML ]; then
     13                echo "<Players/>" > $PLAYERSXML
    1414        fi
    1515}
    1616
    1717# Set all players for an instance to offline (on startup/shutdown)
    18 # Params:
    19 #   1: Instance name
    2018setAllPlayersOffline() {
    21         PLAYERLIST=$(getInstancePath $1)/players.xml
    22         createPlayerList "$1"
     19        createPlayerList
    2320        $XMLSTARLET ed -L \
    2421                -u "/Players/Player/@online" -v "false" \
    25                 $PLAYERLIST
     22                $PLAYERSXML
    2623}
    2724
     
    3330#   4: Nick name
    3431logPlayerConnect() {
    35         PLAYERLOG=$(getInstancePath $1)/players.log
    36         PLAYERLIST=$(getInstancePath $1)/players.xml
    3732        ENTITYID="$2"
    3833        STEAMID="$3"
    3934        NICKNAME="$4"
    4035
    41         echo "$(timestamp) +++ $ENTITYID $NICKNAME $STEAMID" >> $PLAYERLOG
     36        echo "$(timestamp) +++ $ENTITYID $NICKNAME $STEAMID" >> $PLAYERSLOG
    4237
    43         createPlayerList "$1"
     38        createPlayerList
    4439       
    4540        XPATHBASE="/Players/Player[@steamid='$STEAMID']"
    4641
    47         if [ -z $($XMLSTARLET sel -t -v "$XPATHBASE/@steamid" $PLAYERLIST) ]; then
     42        if [ -z $($XMLSTARLET sel -t -v "$XPATHBASE/@steamid" $PLAYERSXML) ]; then
    4843                $XMLSTARLET ed -L \
    4944                        -s "/Players" -t elem -n "Player" -v "" \
     
    5550                        -i "$XPATHBASE" -t attr -n "online" -v "true" \
    5651                        -i "$XPATHBASE" -t attr -n "entityid" -v "$ENTITYID" \
    57                         $PLAYERLIST
     52                        $PLAYERSXML
    5853        else
    59                 LOGINS=$($XMLSTARLET sel -t -v "$XPATHBASE/@logins" $PLAYERLIST)
     54                LOGINS=$($XMLSTARLET sel -t -v "$XPATHBASE/@logins" $PLAYERSXML)
    6055                (( LOGINS++ ))
    6156                $XMLSTARLET ed -L \
     
    6459                        -u "$XPATHBASE/@entityid" -v "$ENTITYID" \
    6560                        -u "$XPATHBASE/@logins" -v "$LOGINS" \
    66                         $PLAYERLIST
     61                        $PLAYERSXML
    6762        fi
    6863}
     
    7368#   2: Entity ID
    7469logPlayerDisconnect() {
    75         PLAYERLOG=$(getInstancePath $1)/players.log
    76         PLAYERLIST=$(getInstancePath $1)/players.xml
    7770        ENTITYID="$2"
    7871
    79         createPlayerList "$1"
     72        createPlayerList
    8073
    8174        XPATHBASE="/Players/Player[@entityid='$ENTITYID'][@online='true']"
    8275
    83         if [ -f $PLAYERLIST ]; then
    84                 if [ ! -z $($XMLSTARLET sel -t -v "$XPATHBASE/@steamid" $PLAYERLIST) ]; then
    85                         NICKNAME=$($XMLSTARLET sel -t -v "$XPATHBASE/@nick" $PLAYERLIST)
    86                         STEAMID=$($XMLSTARLET sel -t -v "$XPATHBASE/@steamid" $PLAYERLIST)
    87                         LOGINTIME=$($XMLSTARLET sel -t -v "$XPATHBASE/@lastlogin" $PLAYERLIST)
    88                         PLAYTIME=$($XMLSTARLET sel -t -v "$XPATHBASE/@playtime" $PLAYERLIST)
     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)
    8982                        NOW=$(date '+%s')
    9083                        PLAYTIME=$(( PLAYTIME + NOW - LOGINTIME ))
     
    9285                                -u "$XPATHBASE/@playtime" -v "$PLAYTIME" \
    9386                                -u "$XPATHBASE/@online" -v "false" \
    94                                 $PLAYERLIST
     87                                $PLAYERSXML
    9588                fi
    9689        fi
    9790
    98         echo "$(timestamp) --- $ENTITYID $NICKNAME $STEAMID" >> $PLAYERLOG
     91        echo "$(timestamp) --- $ENTITYID $NICKNAME $STEAMID" >> $PLAYERSLOG
    9992}
    10093
Note: See TracChangeset for help on using the changeset viewer.