#!/usr/bin/perl -w--#-.
#!/usr/bin/perl -w
#-------------------------------------------------------
# ad184 Robot
#
# Copyright (c) 2003 Zezy. All rights reserved.
# Version: 0.6.0
# Update: 2003-05-14
#-------------------------------------------------------
use LWP::UserAgent;
$ENV{HOME} = "e:\\perl\\test\\";
my $login_name = '33;
my $login_pass = 44444;
my $quesss = '砍伐何种';
my $ansss = '柏';
my $quesrr = '选择本地制盐方';
my $ansrr = '矿盐式';
my $fight_target1 = '265';
my $fight_target2 = '6264';
my $fight_type1 = '2';#'2';
my $fight_type2 = '2';
my $cur_fight = '1';
#my @war = ($target1, $target2, $type1, $type2);
my $cur_deliver_map = '2';#'1','2', '3' , '4'
my $cur_deliver_path = 'deliver_path'.$cur_deliver_map;
my $url_prefix = 'http://www.ad184.com/';
my $question_base_file_path = 'e:\\perl\\test\\question_base.txt';
my $session_id = 'session';
my $fight_error = 1;
my $water_error = 0;
my $wood_error = 0;
my $salt_error = 1;
my $farm_error = 0;
our %ques_wood;
our %ques_water;
our %ques_salt;
our @deliver_path1 = (102,101,100,99,98,79,60,61,62,63,64,45,26,27,28,29,30,31,32,33,34,53,72,71,90,109,108,107,106);
our @deliver_path2 = (96,97,98,99,100,101,82,83,84,103,104,105,106,107,108,109,128,147,166,167,168,149,130,111,92,73);
our @deliver_path3 = (58,77,96,97,98,99,118,137,136,155,174,193,194,195,196,197,198,199,200,201,202,203,184,165,164,145,126,127,128,129,130,149,168,187);
our @deliver_path4 = (21,40,59,78,79,80,61,42,23,24,25,26,27,46,65,66,67,48,29,30,31,32,33,34,35,54,73,72,91,110,129,148,167,186,205,206,207,188,169);
our %deliver_paths = ( path1 => \@deliver_path1,
path2 => \@deliver_path2,
path3 => \@deliver_path3,
path4 => \@deliver_path4, );
my $need_debug = 0;
my $need_logger = 0;
my $need_info = 0;
my $ua = LWP::UserAgent->new;
$ua->cookie_jar({});
$ua->agent('Mozilla/4.0 (compatible; MSIE 6.0; Windws NT 5.1)');
#init();
chdir;
if (($need_debug) && !(-e "debug")) {
die "make dir \'debug\' failure!" unless(mkdir("debug"));
}
if (($need_debug) && !(-e "log")) {
die "make dir \'log\' failure!" unless(mkdir("log"));
}
if (($need_debug) && !(-e "info")) {
die "make dir \'info\' failure!" unless(mkdir("info"));
}
$session_id = &login($login_name, $login_pass);
&info ('Session_id='.$session_id);
&load_question_base($question_base_file_path);
&print_question_base(*ques_wood);
&print_question_base(*ques_water);
&print_question_base(*ques_salt);
$fight_error = 0 if ($fight_target1 eq $fight_target2);
while (1) {
&m_wood(*ques_wood) unless($wood_error);
&m_water(*ques_water) unless($water_error);
&m_farm() unless($farm_error);
&info("sleep 10 seconds");
sleep(10);
}
sub m_fight {
指令
}
sub m_deliver {
指令
}
sub m_farm {
[color=red] my $post_url = $url_prefix.'food.php?submit=1';
my $url = $url_prefix.'food.php';
my $res = $ua->post($url); [/color]
if ($res->is_success) {
if ($res->content =~ /你必须(休息.*秒)/) {
info("种田时间未到,请".$1);
} elsif ($res->content =~ /请登陆先|重新登陆|未登陆|先登陆|不能登陆|不能开多个/) {
info("重新登陆le....");
$session_id = &login($login_name, $login_pass);
info('Session_id='.$session_id);
return;
} elsif ($res->content =~ /^\s*$/) {
info("空内容。。。");
} else {
info("开始种田了。。。");
]);
if ($res->is_success) {
$res->content =~ /(共有荒地.*(农业值增加了!)?)'\);/;
info("种田结束:".$1);
} else {
print $res->content;
info("Mission_Farm_Retrun_Error: " . $res->status_line);
}
}# end if "再休息"
} else {
info("Mission_Farm_Error: " . $res->status_line);
}
}
sub m_water {
指令}
sub m_wood {
指令}
sub login {
my ($name, $pass) = @_;
my $res = $ua->post($url_prefix.'login_club.php', [loginname => $name, loginpass => $pass]);
if ($res->is_success) {
debugg($res->as_string);
die '老大,用户名搞错了!'."\n" if ($res->content =~ /用户名不存在/);
die '大哥,你密码输错咯。。。'."\n" if ($res->content =~ /密码错误/);
die 'IP满了'."\n" if ($res->content =~ /相同IP只能登陆 \d* 名会员/);
$res->as_string =~ /(PHPSESSID=\w+);.* path=\/\sX/;
return $1;
} else {
$res = $ua->post($url_prefix.'login_club.php', [loginname => $name, loginpass => $pass]);
if ($res->is_success) {
$res->as_string =~ /(PHPSESSID=\w+);.* path=\/\sX/;
return $1;
} else {
info("Login_Error: " . $res->status_line);
}
}
}
sub print_question_base {
local(*hash_name) = @_;
while (($ques, $ans) = each(%hash_name)){
debugg("question:".$ques."\n"."answer:".$ans."\n");
#print "question:".$ques."\n"."answer:".$ans."\n";
}
}
sub load_question_base {
my $ques_hash_name = 'ques_salt';
my $ques = 'ques';
my $ans = "ans";
my @m_ans = ();
my $multi_ans = 0;
my ($filename) = @_;
die 'Error: open file '.$filename.' failure!'."\n" unless(open(QUESBASE, $filename));
while (my $line = <QUESBASE>) {
if ($line =~ /^category=(.*)\s*$/) {
if ($ques ne 'ques') {
#print "hash_name:".$ques_hash_name."ques:".$ques."ans:".$ans."\n";
$$ques_hash_name{$ques} = $ans;
$ques = 'ques';
}
$multi_ans = 0;
$ques_hash_name = 'ques_salt' if ($line =~ /制盐题/);
$ques_hash_name = 'ques_wood' if ($line =~ /砍树题/);
$ques_hash_name = 'ques_water' if ($line =~ /治水题/);
#debugg($ques_hash_name);
} elsif ($line =~ /^q:(.*)\s*$/) {
if ($ques ne 'ques') {
#print "hash_name:".$ques_hash_name."ques:".$ques."ans:".$ans."\n";
$$ques_hash_name{$ques} = $ans;
}
$multi_ans = 0;
$ques = $1;
#debugg("ques:".$ques);
} elsif ($line =~ /^a:(.*)\s*$/) {
if ($multi_ans) {
$ans .= '$zezy$'.$1;
} else {
$ans = $1;
}
$multi_ans ++;
#debugg("ans:".$ans);
} else {
#debugg($line);
next;
}
}
# record the last question.
$$ques_hash_name{$ques} = $ans if ($ques ne 'ques');
close(QUESBASE);
}
sub debugg {
return unless($need_debug);
print "打开DEBUGG日志文件出错!\n" unless (open(DEBUGFILE, ">>e:\\perl\\test\\debug\\".$login_name.".txt"));
foreach $msg (@_) {
#print 'DEBUG: '.$msg."\n";
print DEBUGFILE ('DEBUG '.&getNowTime().' '.'STARTING**************************************'."\n");
print DEBUGFILE ($msg."\n");
print DEBUGFILE ('DEBUG '.&getNowTime().' '.'ENDED*****************************************'."\n");
}
close(DEBUGFILE);
}
sub logger {
return unless($need_logger);
print "打开日志文件出错!\n" unless (open(LOGFILE, ">>e:\\perl\\test\\log\\".$login_name.".txt"));
foreach $msg (@_) {
print LOGFILE ('LOG '.&getNowTime().' '.$msg."\n");
}
close(LOGFILE);
&debugg(@_) if ($need_debug);
}
sub info {
foreach $msg (@_) {
print 'INFO '.&getNowTime().' '.$msg."\n";
}
return unless($need_info);
print "打开信息日志出错!\n" unless (open(INFOFILE, ">>e:\\perl\\test\\info\\".$login_name.".txt"));
foreach $msg (@_) {
print INFOFILE ('INFO '.&getNowTime().' '.$msg."\n");
}
close(INFOFILE);
&debugg(@_) if ($need_debug);
}
sub getNowTime {
my @tm = localtime;
($tm[5]+1900).'-'.($tm[4]+1).'-'.$tm[3].' '.$tm[2].':'.$tm[1].':'.$tm[0];
}