#!/bin/bash
if [ -L $0 ]; then
        LEGENDS_DIR="$(dirname $(readlink $0))"
else
        LEGENDS_DIR="$(dirname $0)"
fi
cd $LEGENDS_DIR
export LD_LIBRARY_PATH=./

#check if URL is allowed.  prevents malicious URL abuse
isAllowed ()
{
  [ $# -eq 1 ] || return $FAILURE

  case $1 in
  *[!0-9\.\:]*|"") exit -1 ;;
               *) return;;
  esac
}

### handle protocol to connect translation, removes all other args
if [[ "$1" == "legends://"* ]]; then
	#chances are this came from a web site, so validate the url.
	#url can only contain numbers, period and :
	
	isAllowed "${1:10}"
	LD_PRELOAD=./libaoss.so ./lspawn.bin 28000 ./legends.bin -connect IP:${1:10}
else
	LD_PRELOAD=./libaoss.so ./lspawn.bin 28000 ./legends.bin $* &
fi


