Tuesday, 17 December 2013

My code - "You only get one pixel" bot

One of the interesting experiments at the Ludum Dare Game Competition 28th iteration was Folis''s You only get one pixel. It's a simple 100x100 canvas in which each "player" contributes one pixel to form an image.

However, seeing that the only thing keeping me from spamming it was an stupid cookie, I couldn't resist but to write a bot. I choose of course C++ and Allegro, to the dismay of iostream, who ironically thought I should use Perl to this task. Unfortunately I have no knowledge of Perl.

Below is the form code inside You only get one pixel's code:

<form action="scripts/draw.php" method="post">
<label for="color">Color:</label> <input class="color" name="color" readonly="readonly" type="text" /><br />
<label for="col">Coord (x, y):</label> <input class="col" name="col" readonly="readonly" type="text" /> <input class="row" name="row" readonly="readonly" type="text" /><br />
<input class="submit" type="submit" value="Draw!" />
</form>

It's was a matter of creating a program to translate the pixels in a bitmap image to a series of curl commands that would use this form to write the pixels in the page.

I had some problems with my program generating white pixels which aren't visible in most browser's backgrounds and also with the non-intuitive coordinate system that starts at 1,1 instead of 0,0.

Here's my final code:

#include <allegro.h>
#include <cstdlib>
#include <iostream>

int main(int argc, char **argv)
{
 allegro_init();
 set_color_depth(32);
 if(argc < 2) return 1;
 BITMAP *bmp = load_bitmap(argv[1], 0);
 for(int x = 0; x < 100; x++)
 {
  for(int y = 0; y < 100; y++)
  {
   if(getpixel(bmp, x, y) == 0xFF0000)
   {
    std::cout
    << "curl -d \"color=FFFFFF&col="
    << (x + 1)
    << "&row="
    << (y + 1)
    << "\" http://www.pixelspade.at/games/you-only-get-one-pixel/scripts/draw.php\n";
   }
   if(getpixel(bmp, x, y) == 0)
   {
    std::cout
    << "curl -d \"color=000000&col="
    << (x + 1)
    << "&row="
    << (y + 1)
    << "\" http://www.pixelspade.at/games/you-only-get-one-pixel/scripts/draw.php\n";
   }
  }
 }
 return 0;
}

Below you can see the results of my beloved bot, where lies clearly spelled "drnick", my nickname in the Ludum Dare community, along with some earlier efforts by iostream.




Update: Folis
and iostream added security features to the game's code. I in turn updated my code to use proxylists and randomized user agents, defeating their security measures. However I did this as an mere exercise and will abstain from using it or publishing the code.

The spamming incident was reported by Folis on his Twitter.

No comments:

Post a Comment