#!/bin/bash -f ###################################################################### # Artemis packet logger, (C) 2015-2020 Nosey Nick Waterman, # https://noseynick.org/artemis/ # All wrong righted, all rights reserved. Licensed under thev GNU # Affero General Public License v3.0 https://www.gnu.org/licenses/agpl.txt # with Commons Clause https://commonsclause.com/ v1.0 ###################################################################### cd "${0%/*}" || exit # approx "dirname" - to find ./parser.pl ./mainscreen.pl ./discord.sh [[ -f ./mainscreen.pl ]] || nebula mainscreen.pl mkdir -vp captures export TZ=UTC MAIN="main fight comms" SHIP='' LOOP='' DISCORD='' HEARTBEAT='' PING='' while true; do case "$1" in "") echo "USAGE: $0 [notes]"; exit 1 ;; [1-8]) SHIP="$1"; shift ;; # and try again -q|--quiet) MAIN='' shift ;; # and try again -l|--loop) LOOP=1; shift ;; # and try again -d|--disco*) DISCORD=$1; shift ;; # and try again -h|--heart*) HEARTBEAT=heartbeat; shift ;; # and try again -p|--ping) PING=ping; shift ;; # and try again -u|--up*) UPLOAD=1; shift ;; # and try again -*) echo "USAGE: $0 [notes]"; exit 1 ;; *:*) PORT="${1##*:}" HOST="${1%%:*}"; shift; break ;; *) PORT=2010 HOST="$1"; shift; break ;; esac; done NOTE="" if [[ "$1" ]]; then NOTE=$(echo ".$*" | tr ' ' .) fi if [[ "$DISCORD" ]]; then MID=$( SERVER="$HOST" case "$HOST" in 127.*) SERVER="Nebula server" ;; *) [[ "$DO_NOT_ANNOUNCE_IP" ]] && SERVER="the server" ;; esac echo "Did someone say fetch? I will fetch stats and scores from $SERVER." \ "Let <@372579141922324480> know if this causes any problems" \ | ./discord.sh --send ) fi if [[ -f ~/.artemis ]]; then sed -i -e '/^ip=/ d' ~/.artemis echo "ip=$HOST" >> ~/.artemis fi FIRST=1 while [[ "$FIRST$LOOP" ]]; do # loop at least once FIRST= DST="captures/artemis-$(date '+%Y-%m-%d.%H%M')$NOTE.01s"; NN=01 while [[ -f "$DST" ]] || [[ -f "$DST.xz" ]] ; do NN="$((${NN#0}+1))"; [[ "$NN" -lt 10 ]] && NN="0$NN" DST="captures/artemis-$(date '+%Y-%m-%d.%H%M')$NOTE.${NN}s" done echo "mainscreen.pl $SHIP $MAIN $HEARTBEAT $PING $DST.running | nc $HOST $PORT > $DST" if [[ "$MID" ]]; then trap 'rm -vf $DST.running; ./discord.sh --delete $MID' EXIT else trap 'rm -vf $DST.running' EXIT fi echo "PID $$" > "$DST.running" ###################################################################### # run the "please send me mainscreen (of ship $SHIP)" program, # send the command to the server, log the s2c packets. # Also parse them (at MUCH reduced verbosity) to stderr, # pretty-print the "Game Results" (GameOverReason/GameOverStats), # optionally send to discord: # shellcheck disable=SC2086 # deliberate word splitting: ./mainscreen.pl $SHIP $MAIN $HEARTBEAT $PING $DST.running \ | nc -w 10 "$HOST" "$PORT" \ | tee "$DST" \ | ./parser.pl --noobj --nosss --nodmx --nointel --times $DISCORD --quit "$DST.running" # was PROBABLY deleted by mainscreen.pl but if not... rm -f "$DST.running" [[ "$MID" ]] && ./discord.sh --delete "$MID" ; MID='' if [[ -s "$DST" ]] && [[ "$UPLOAD" ]]; then xz -9v "$DST" \ && wget -t3 -T3 -qO- --post-file "$DST.xz" \ "$NEBULA/logs.cgi/${DST#*/}.xz" & elif [[ -s "$DST" ]]; then xz -9v "$DST" & else echo "### Zero size capture - exiting" rm -vf "$DST" exit 0 fi done