Skip to content

Instantly share code, notes, and snippets.

@oberhamsi
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oberhamsi/10415802 to your computer and use it in GitHub Desktop.
Save oberhamsi/10415802 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Reads the player position via telnet and writes it to tracks.csv. Can be
# sourced or executed.
# The tracks.csv file can be display in the map viewer https://github.com/nicolas-f/7DTD-leaflet/
. /usr/local/lib/7dtd/common.sh
# @@ this should be a per instance config, not per server
SDTD_TRACKS_PATH=/path/to/tracks.csv
writeTracks() {
if [ $(isValidInstance $1) -eq 0 ]; then
echo "No instance given or not a valid instance!"
return
fi
if [ ! -w $2 ]; then
echo "Tracks.csv output file does not exist or is not writeable"
return
fi
# player name and position from telnet lp
regex="(, )([^,]+), pos=\(([0-9\.]*), ([0-9\.]*), ([0-9\.]*)\)"
if [ $(isRunning $1) -eq 1 ]; then
lines=$(telnetCommand $1 lp)
while read -r line; do
[[ $line =~ $regex ]]
if [[ ${BASH_REMATCH[0]} ]]; then
csvLine="${BASH_REMATCH[2]},${BASH_REMATCH[5]},${BASH_REMATCH[3]}"
echo "$csvLine" >> $2
fi
done <<< "$lines"
else
echo "Instance $1 not running"
return
fi
}
if [[ $_ != $0 ]]; then
instance=${1}
tracksFile=${2:-$SDTD_TRACKS_PATH}
writeTracks $instance $tracksFile
exit 1
fi
@tschaerni
Copy link

It doesn't parse the Positions correctly. And there is a Problem with Telnet, the script doesn't make a clean exit.

Cheers

@oberhamsi
Copy link
Author

@tschaerni it's now working for randomgen. the telnet problem is due to the buggy 7dtd telnet server. it works with with alloc's native server tools.

the positions are now written to a tracks.csv file to be rendered with the map viewer https://github.com/nicolas-f/7DTD-leaflet

@scetron
Copy link

scetron commented Jan 18, 2015

Is there any help? it looks like the script needs two args, the 7dtd server manager instance, but I am not sure what the $tracksFile is for...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment