#!/usr/bin/perl # # ibProBattle Bot # (c) Mindfuck 2007 # www.mindfucked.org # # This Bot automates the Invision Power Board -Board Game ibP-Battle # # Features & HowTo: rtfm! # ####################### use strict; use warnings; use WWW::Mechanize; use HTML::TokeParser; use HTTP::Cookies; use Term::ANSIColor; use Config::IniFiles; ############################## CONFIG ######################################### my $configfile = 'battlebot.ini'; tie my %hash, 'Config::IniFiles', (-file => $configfile ); my %config = %{ $hash{config} }; my @friends = (10202,7222); ################# NO NEED TO EDIT BELOW THIS LINE ############################# my $agent = WWW::Mechanize->new(); $agent->cookie_jar(HTTP::Cookies->new); my $count = '1'; our $stop = '0'; my $version = "0.2b"; sub gettime{ return sprintf "%s:%s:%s ", (localtime)[2,1,0]; } sub randomizer { my $seconds = shift; my $rand_number = int(rand($config{spread})); my $twisted = ($seconds + $rand_number); return $twisted; } sub timer { my $minutes = shift; my $seconds = ($minutes * 60); my $magic = randomizer($seconds); print gettime(), "Sleeping for $minutes minutes\n"; sleep($magic); } sub id2nick { my $id = shift; $agent->get("http://$config{url}/index.php?showuser=$id"); my $nick = $agent->content =~ m/(.+) - Profil ansehen<\/title>/; my $dood = $1; return $dood; } sub logmein { CONNECT: if ($config{DEBUG} == '1') { print("DEBUG: Accessing $config{url}\n");} $agent->get("http://$config{url}/index.php?act=Login&CODE=00"); $agent->success or (sleep(600) and (goto CONNECT)); $agent->form_name('LOGIN') or goto SLEEP; $agent->field('UserName',$config{username}); $agent->field('PassWord',$config{password}); if ($config{DEBUG} == '1') { print("DEBUG: Logging in...\n");} $agent->submit(); print("Send User\/Pass to $config{url}\n"); } sub getinfo { my $input = shift; $agent->get("http://$config{url}/index.php?act=atkshop"); my $infopage = $agent->content; my $money = $infopage =~ m/Euro:<\/strong> (\d+(?:,\d+)?)/; my $s_potions = $infopage =~ m/.+>War Pills \((\d+)\)</; if ($input eq "money") { return $money; } elsif ($input eq "s_potions") { return $s_potions; } } sub attack { $agent->get("http://$config{url}/index.php?act=atkshop&do=target"); my @targetsite = $agent->content; if ($config{DEBUG} == '1') { print("DEBUG: Parsing Victims...\n");} my @targets; foreach (@targetsite) { push @targets, $_ =~ m/act=attack&m=(\d+)/gs; } if ($config{DEBUG} == '1') { print ("DEBUG: Found Target: @targets\n");} if ($config{DEBUG} == '1') { print("DEBUG: Attacking...\n");} foreach (@targets) { my $target = $_; $agent->get("http://$config{url}/index.php?act=attack&m=$target"); if ($config{DEBUG} == '1') { print("DEBUG: Choosing best Weapon...\n");} my @weaponlist = $agent->content =~ m/.+&w=(\d)/; my @weapons = sort(@weaponlist); if ((defined $weapons[0]) and ($stop == '0') and ($target != @friends)) { if ($config{DEBUG} == '1') { print("DEBUG: Attack \#$count\n");} $agent->get("http://$config{url}/index.php?act=attack&m=$target&w=$weapons[0]"); print gettime(), "\#$count $config{username} Attacked Target id ", id2nick($target), " with Weapon $weapons[0]\n"; $count++; healcheck(); } else { print gettime(), "Cant attack ", id2nick($_), " \(Id: $_\), moving on to next Victim\n"; } if ($count == $config{max_attacks}) { print gettime(), "Attacked $config{max_attacks} Targets, stopping...\n"; healcheck(); goto SLEEP; } } if ($config{DEBUG} == '1') { print("DEBUG: Attack finished\n");} } sub gethp { my $input = shift; $agent->get("http://$config{url}/index.php?act=atkshop&do=target"); my @hpmaxhp = $agent->content =~ m/.+<strong>Hp: <\/strong> (\d+)\/(\d+)/; my $hp = $hpmaxhp[0]; my $maxhp = $hpmaxhp[1]; my $prozente = $hp * 100 / $maxhp; if ($input eq "hp") { return $hp; } elsif ($input eq "maxhp") { return $maxhp; } elsif ($input eq "prozente") { return $prozente; } } sub healcheck { if ($config{DEBUG} == 1) { print gettime(), "DEBUG: Checking if we need a Potion\n"; } if (gethp(prozente) == 0) { if ($config{DEBUG} == '1') { print("DEBUG: Im Dead!\n");} my $deathsleep = ($config{deathtimer} * 60); print gettime(), "!!!YOU ARE DEAD!!!\n"; print gettime(), "Sleeping for $config{deathtimer} minutes\n"; sleep($deathsleep); goto START; } elsif (gethp(prozente) < 25) { if ($config{DEBUG} == 1) { print("DEBUG: Health below 25%, trying to use middle potion.\n");} heal("25"); } elsif (gethp(prozente) < 55) { if ($config{DEBUG} == 1) { print("DEBUG: Health below 55%, trying to use small potion.\n");} heal("50"); } } sub heal { my $pro = shift; print color("green"), "Money:", getinfo(money), "\nSmall Potions:", getinfo(s_potions), "\n", color("reset"); if ($pro == '50') { print("Got 50 percent\n"); if (getinfo(s_potions) > 1) { print gettime(), "Using small Potion\n"; $agent->get("http://$config{url}/index.php?act=atkshop&do=use&item=1"); } elsif ((getinfo(s_potions) == 0) and (getinfo(money) > 125)) { print gettime(), "Buying small Potion\n"; $agent->get("http://$config{url}/index.php?act=atkshop&do=buy&item=1"); print gettime(), "Using small Potion\n"; $agent->get("http://$config{url}/index.php?act=atkshop&do=use&item=1"); } elsif ((getinfo(s_potions) == 0) and (getinfo(money) < 125)) { print gettime(), "No Money, No Potions, sleeping...\n"; goto SLEEP; } } elsif ($pro == '25') { print("Got 25 percent\n"); if (getinfo(s_potions) > 1) { print gettime(), "Using small Potion\n"; $agent->get("http://$config{url}/index.php?act=atkshop&do=use&item=1"); } elsif ((getinfo(s_potions) == 0) and (getinfo(money) > 125)) { print gettime(), "Buying small Potion\n"; $agent->get("http://$config{url}/index.php?act=atkshop&do=buy&item=1"); print gettime(), "Using small Potion\n"; $agent->get("http://$config{url}/index.php?act=atkshop&do=use&item=1"); } elsif ((getinfo(s_potions) == 0) and (getinfo(money) < 125)) { print gettime(), "No Money, No Potions, sleeping...\n"; goto SLEEP; } } } sub healthwatch { logmein(); WATCHER: if ($config{watchlog} == '1') { print gettime(), "Checking if we need a Potion\n"; } healcheck(); sleep($config{watchdelay}); goto WATCHER; } sub info { print color("orange"), "Health: ", gethp(hp),"\/",gethp(maxhp),"\n", color("reset"); } main { system("clear"); if ($config{DEBUG} == '1') { print gettime(), "DEBUGGING STARTED\n\n";} print color("yellow"), "Mindfucks ipB Battle Bot version $version\n", color("reset"); if ($config{healthwatcher} == '1') { if(! defined(my $pid= fork())){ die "Error on Fork\n";} elsif($pid==0){ healthwatch(); } else{ START: logmein(); info(); healcheck(); attack(); if ($config{DEBUG} == '1') { print gettime(), "DEBUGGING ENDED\n";} SLEEP: timer($config{delay}); goto START; } } else { START: logmein(); info(); healcheck(); attack(); if ($config{DEBUG} == '1') { print("DEBUGGING ENDED\n");} SLEEP: timer($config{delay}); goto START; } }