Friday, June 20, 2008

Drawball code

Looks like a lot of people are showing up here looking for the Drawball information I posted last year. Here's some crummy Perl code that might help you get started. All it does is connect to the server every second and check how much ink you've got, as an integer value.


#!/usr/bin/perl

use IO::Socket::Inet;
use LWP::Simple;
use strict;

$/ = "\x00";
my $sock = IO::Socket::INET->new('70.84.35.114:8007') or die "Could not connect\n";
handshake();

while($sock) {
if(my $ink = getink()) {
printf "ink: %08x\n", $ink;
}
sleep 1;
}

sub getink {
print $sock "i\x00";
my $i = <$sock>;
my $numink = undef;
if($i =~ /^i(\x01.{3})\x00/) {
$numink = unpack "N", $1;
}
return $numink;
}

sub handshake {
my ($seed) = (get "http://www.drawball.com") =~ /l=(.{7})/;
print $sock "$seed\x00";
my $chal = <$sock>;
my $resp = decode($seed, $chal);
print $sock "$resp\x00";
print $sock "\x65\x00\x69\x00\x62\x01\x01\x01\x01\x07\x00";
}

sub decode {
my @k1 = split //, shift;
my @k2 = split //, shift;

my $out;
my $k2c = 0;
for(0 .. @k1-1) {
my $tmp = ord($k2[$k2c]) - 65;
my $c = ord($k1[$_]) - $tmp;
my $out .= chr($c);
my $k2c += 2;
}
return $out;
}

Monday, June 2, 2008