#!/usr/bin/perl
use DBI;
use CGI qw/escape/;
use String::CRC32;
use strict;
my $query = new CGI;
my $dbh = DBI->connect("DBI:mysql:database=wuukiee_play;host=localhost", "mcc", "kQ89Ef2f49Gvc2FQq");
unless ($dbh) { print $query->redirect("mysql.gif"); return; }
my $sth;
# $sth = $dbh->prepare(qq[update usruser set hits=hits+1, last=now() where name="$name"]); $sth->execute(); $sth->finish();
my $pickb;
if (int($query->param('a'))) {
$pickb = "where id=" . int($query->param('a'));
} else {
$pickb = "order by rand() limit 1";
}
$sth = $dbh->prepare(qq[select id, content, music, bcolor, tcolor, vcolor from mprsee $pickb;]); $sth->execute();
my @permidl = qw(a b c d);
my @permid;
my ($mid, $content, $music, $mbcolor, $mtcolor, $mvcolor) = $sth->fetchrow_array;
$mid = int($mid);
my @bcolor = unpack "CCC", pack "H6", $mbcolor;
my @vcolor = unpack "CCC", pack "H6", $mvcolor;
push(@permid, $mid);
$sth->finish;
my $pickt;
$pickt = join(" or ", map { int($_) ? ("id=" . int($_)) : () } ($query->param('b'), $query->param('c'), $query->param('d')));
$pickt = "where $pickt" if ($pickt);
$pickt = "order by rand() limit 3" unless ($pickt);
$sth = $dbh->prepare(qq[select id, content, minsize from mpread $pickt;]); $sth->execute();
my $readers;
my $blocks;
for my $i (1..4) {
my ($id, $content, $mins, $size, $xsize, $hsize, $psize, $psize2, @colorl);
$psize = 10 + int(rand(80)); my $psize2 = 10 + int(rand(80));
my ($lrsize, $udsize) = (10,20);
my @result = $sth->fetchrow_array;
if (@result) {
($id, $content, $mins) = @result;
$readers .= " or (mpruser.id=mprlink.user and mprlink.thing=$id and mprlink.isread=1)";
$size = $mins?$mins:150+int(rand(100))*2; $hsize=$size/2+20;
$xsize = 20;
push(@permid, $id);
} else {
$size = 60; $hsize=30; $xsize = 0;
($lrsize,$udsize) = (0,0);
}
if (@result || 4 >= $i) {
for(0..2) {
$colorl[$_] = $bcolor[$_] + rand($vcolor[$_]) * (rand()>0.5?-1:1);
$colorl[$_] = 255 if ($colorl[$_] > 255);
$colorl[$_] = 0 if ($colorl[$_] < 0);
}
my $color = sprintf("%02x%02x%02x", @colorl);
my $sum = sprintf("%8X",crc32($content));
$sum =~ tr/A-F/a-f/;
$content =~ s/$/
/mg;
$content =~ s/ /\ \ /sg;
$blocks .= <
EOF
if (4 > $i) {
$blocks .= <File ${sum}\\\\\\\\
X
$content
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
EOF
} else {
my $z = int(rand(1000000000));
$blocks .= <
EOF
}
}
}
$sth->finish;
my $contrib;
$sth = $dbh->prepare(qq[select distinct mpruser.name,mpruser.url from (mprlink,mpruser) where (mpruser.id=mprlink.user and mprlink.thing=$mid and mprlink.isread=0) $readers;]); $sth->execute();
while (my @result = $sth->fetchrow_array) {
my ($name, $url) = @result;
$contrib .= "$name\n $url\n";
}
my $link;
for (0..(@permid-1)) {
$permid[$_] = $permidl[$_] . '=' . $permid[$_];
}
$link = "http://themostpowerfulrobotever.com/?" . join("&",@permid);
print <
THE MOST POWERFUL ROBOT EVER
$content
$blocks
$music