#!/bin/bash

[ -f "$1" ] || {
	echo "Syntax: $0 <IP log file>";
	exit 1;
};

cat "$1" | sed -e 's/\r//' | while read lf_addr lf_evt lf_hasname lf_name; do
	lf_addr_addr="`echo "${lf_addr}" | cut -d: -f1`"
	lf_addr_port="`echo "${lf_addr}" | cut -d: -f2`"
	printf "%18s %8s " "${lf_addr_addr}" "${lf_addr_port}"
	case "${lf_evt}" in
		RVR)
			echo "Unknown protocol version";
			;;
		R00)
			echo "Rejected - too many connections from host";
			;;
		R01)
			echo "Rejected - userinfo string length exceeded"
			;;
		R02)
			echo "Rejected - empty userinfo"
			;;
		R03)
			echo "Rejected - end-of-message-in-string exploit"
			;;
		R04)
			echo "Rejected - attempted to spoof IP address"
			;;
		R05)
			echo "Rejected - remote connect in attract loop"
			;;
		R06)
			echo "Rejected - bad challenge"
			;;
		R07)
			echo "Rejected - no challenge"
			;;
		R08)
			echo "Rejected - already connected"
			;;
		R09)
			echo "Rejected - trying to reconnect too soon"
			;;
		R10)
			echo "Rejected - server full"
			;;
		GRJ)
			echo "Rejected by game"
			;;
		RCN)
			echo "Client reconnecting"
			;;
		NCN)
			echo "Client establishing new connection"
			;;
		UUS)
			echo "Player ${lf_name} connected";
			;;
		DCN)
			echo "Player ${lf_name} disconnected"
			;;
	esac
done
