Console work + modem.c

This commit is contained in:
Neale Pickett 2012-05-29 22:45:20 -06:00
parent 57cb1a4cdc
commit fb03774655
3 changed files with 107 additions and 21 deletions

View File

@ -8,6 +8,7 @@ if ! [ -f $BASE/salt ]; then
dd if=/dev/urandom count=1 | md5sum - > $BASE/salt dd if=/dev/urandom count=1 | md5sum - > $BASE/salt
fi fi
clear clear
printf '\017'
read salt < $BASE/salt read salt < $BASE/salt
esc () { esc () {
@ -64,28 +65,52 @@ elif ! [ -d $BASE/$hash ]; then
fini fini
fi fi
clear
read -r name < $BASE/$hash/.name read -r name < $BASE/$hash/.name
printf "%s answer: " "$name"
read -r answer
echo
match=$(awk -v ans="$answer" '(substr($0, length($1)+2) == ans) { print substr(FILENAME, 6, length(FILENAME)-17) " " $1; }' /opt/*/answers.txt) printf 'Welcome back, %s.\n' "$name"
if [ -z "$match" ]; then
echo "That is not a correct answer."
fini
fi
cat=${match% *} while true; do
points=${match#* } printf "p2> "
fn=$BASE/$hash/$cat.$points read -r answer
if [ -f $fn ]; then
echo "You've already received points for this answer."
else
> $fn
echo "You get $points more points in the $cat category."
# run puzzles.cgi
# update scoreboard
fi
fini case "$answer" in
\?|help)
cat <<EOD
 Help
----------------------------------------------------------
Type "quit" to leave the p2 shell.
Any other string is checked as an answer. If the answer
is correct, you are awarded points and the scoreboard will
update within 10 seconds. Check the puzzles overview to
see if your answer unlocked a new puzzle.
EOD
continue
;;
quit)
break
;;
esac
match=$(awk -v ans="$answer" '(substr($0, length($1)+2) == ans) { print substr(FILENAME, 6, length(FILENAME)-17) " " $1; }' /opt/*/answers.txt)
if [ -z "$match" ]; then
echo 'That is not a correct answer. Type "help" for help.'
continue
fi
cat=${match% *}
points=${match#* }
fn=$BASE/$hash/$cat.$points
if [ -f $fn ]; then
echo "You've already received points for this answer."
else
> $fn
echo "You get $points more points in the $cat category."
# run puzzles.cgi
# update scoreboard
fi
done

1
packages/p2/src/Makefile Normal file
View File

@ -0,0 +1 @@
modem:

60
packages/p2/src/modem.c Normal file
View File

@ -0,0 +1,60 @@
#include <unistd.h>
#include <stdlib.h>
#define NOISE_PROB 300
#define NOISE_BITS 16
int badbits = 0;
char
line_noise(char c)
{
int i = 7;
while (badbits && (i >= 0)) {
c = c ^ ((rand() % 2) << i);
badbits -= 1;
i -= 1;
}
if (rand() % NOISE_PROB == 0) {
badbits = rand() % NOISE_BITS;
}
return c;
}
int
main(int argc, char *argv[])
{
char c;
ssize_t ret;
int baud = 0;
useconds_t usec;
if (argv[1]) {
baud = atoi(argv[1]);
}
if (! baud) {
baud = 1200;
}
srandom(getpid());
/*
N81 uses 1 stop bit, and 1 parity bit. That works out to
exactly 10 bits per byte.
*/
usec = 10000000 / baud;
while (1) {
ret = read(0, &c, 1);
if (ret != 1) {
break;
}
c = line_noise(c);
write(1, &c, 1);
usleep(usec);
}
return 0;
}