59 lines
1.5 KiB
Bash
Executable File
59 lines
1.5 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
help_text="
|
|
submit.sh - submit an slbr solution to be verified
|
|
usage: ./submit <challenge number> <solution>
|
|
for example: ./submit 3 \"this is the solution for challenge 3\"
|
|
"
|
|
|
|
challenge_no="$1"
|
|
submitted_solution="$2"
|
|
|
|
[ -z "$submitted_solution" ] && echo "$help_text" && exit
|
|
|
|
echo "Submitting \"$submitted_solution\" as the solution to challenge #$challenge_no..."
|
|
|
|
my_ip="$(ip addr | grep 'scope global eth0' | cut -f6 -d ' ')"
|
|
|
|
scoreboard="$(nc -q0 -d {{ HOST_IP }} {{ INFO_PORT }})"
|
|
prev_score="$(
|
|
echo "$scoreboard" \
|
|
| grep "$my_ip"
|
|
)"
|
|
max_score="$(echo "$scoreboard" | head -n1)"
|
|
current_score=""
|
|
|
|
echo "SOLUTION $challenge_no $submitted_solution" \
|
|
| nc -q0 {{ HOST_IP }} {{ SLBR_PORT }}
|
|
|
|
# give the server ample time to process the request
|
|
echo "Verifying..."
|
|
sleep 5
|
|
|
|
# we need to request the scoreboard twice here for the score to properly update
|
|
nc -q0 -d {{ HOST_IP }} {{ INFO_PORT }} > /dev/null
|
|
current_score="$(
|
|
nc -q0 -d {{ HOST_IP }} {{ INFO_PORT }} \
|
|
| grep "$my_ip"
|
|
)"
|
|
|
|
if [ "$prev_score" != "$current_score" ]
|
|
then
|
|
echo "w00t! You got the right answer!!!"
|
|
num_correct="$(
|
|
echo $current_score \
|
|
| grep -oE '[0-9],' \
|
|
| wc -l
|
|
)"
|
|
echo "$num_correct correct answers so far"
|
|
if [ "$num_correct" = "$max_score" ]
|
|
then
|
|
printf "\e[0;92]"
|
|
echo "Hey! thats all $max_score! that means YOU WIN!"
|
|
echo "!!!!!!!CONGRATULATIONS!!!!!!!"
|
|
printf "\e[0;91m THIS CONTAINER WILL NOW SELF DESTRUCT\e[0m\n"
|
|
fi
|
|
else
|
|
echo "|X_x| Your answer was rejected!!!."
|
|
fi
|