Created
April 4, 2016 16:48
-
-
Save mollyporph/8310dd7f3c1c15f5e438fa67b66989c0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
PATHTOLOG="/root/factorio/factorio-current.log" | |
OLDPLAYERCOUNT=0 | |
PLAYERCOUNT=0 | |
NUMBEROFLINESOLD=0 | |
while :; do | |
#get the current nuber of log entries | |
NUMBEROFLINES=$(wc -l /root/factorio/factorio-current.log | grep -o "[0-9]\+") | |
ABSOLUTELINES=$((NUMBEROFLINES-NUMBEROFLINESOLD)) | |
#only look at new lines | |
TAILEDLOG=$(tail -$ABSOLUTELINES $PATHTOLOG) | |
#grab Joins PlayerJoinGame | |
JOINSGAME=$(echo $TAILEDLOG | grep "MultiplayerManager changing state from(InGameSendingMap) to(InGame)" | wc -l | grep -o "[0-9]\+") | |
#grab peer leaving | |
QUITS=$(echo $TAILEDLOG | grep "PlayerLeaveGame" | wc -l | grep -o "[0-9]\+") | |
#grab peer timeout | |
DROPOUTS=$(echo $TAILEDLOG | grep "is not responding, dropping" | wc -l | grep -o "[0-9]\+") | |
BOOT=$(echo $TAILEDLOG | grep "MultiplayerManager changing state from(CreatingGame) to(InGame)" | wc -l | grep -o "[0-9]\+") | |
QUITS=$((QUITS+DROPOUTS)) | |
echo "QUITS: "$QUITS | |
JOINS=$((JOINSGAME)) | |
echo "JOINS: "$JOINS | |
echo "JOINSGAME:"$JOINSGAME | |
PLAYERCOUNT=$((PLAYERCOUNT+JOINS)) | |
PLAYERCOUNT=$((PLAYERCOUNT-QUITS)) | |
if [ $BOOT -eq 1 ] | |
then | |
WID=$(xdotool search Factorio 2>/dev/null) | |
xdotool windowactivate --sync $WID | |
xdotool key Escape | |
xdotool key shift+space | |
fi | |
if [ $PLAYERCOUNT -eq 1 -a $OLDPLAYERCOUNT -eq 0 ] | |
then | |
echo "detected players, unpausing" | |
WID=$(xdotool search Factorio 2>/dev/null) | |
xdotool windowactivate --sync $WID | |
xdotool key shift+space | |
fi | |
if [ $PLAYERCOUNT -eq 0 -a $OLDPLAYERCOUNT -eq 1 ] | |
then | |
echo "0 players, pausing" | |
WID=$(xdotool search Factorio 2>/dev/null) | |
xdotool windowactivate --sync $WID | |
xdotool key shift+space | |
fi | |
#REMOVE the following line if you don't want to see current players. | |
echo $PLAYERCOUNT | |
OLDPLAYERCOUNT=$PLAYERCOUNT | |
NUMBEROFLINESOLD=$NUMBEROFLINES | |
#change to number of seconds between player count update [default: 1 sec] | |
sleep 1 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment