
#!/usr/bin/perl
use DBI;
use Net::OICQ;
use Net::OICQ::ServerEvent;
use Net::OICQ::Event;
use IO::Select;
my $DBUser="root";
my $DBPasswd="";
my $DBTable="qq";
my $DBHost="localhost";
my $UserID=-1;
my $QQNumber=-1;
my $QQPasswd="";
my $CurStatus=0;
my $dbh = DBI->connect("DBI:mysql:$DBTable:$DBHost",$DBUser,$DBPasswd)
or die "Couldn't connect to database: " . DBI->errstr;
my $select_user_sql="select UserID,QQNumber,QQPasswd,CurStatus,ComandStatus from user";
while(1){
$sth = $dbh->prepare($select_user_sql);
$sth->execute();
while (@data = $sth->fetchrow_array()) {
$UserID=$data[0];
if ($QQ{$UserID}{'Status'} != 1 ) {
$QQ{$UserID}{'QQNumber'}=$data[1];
$QQ{$UserID}{'QQPasswd'}=$data[2];
$QQ{$UserID}{'CurStatus'}=$data[3];
$QQ{$UserID}{'ComandStatus'}=$data[4];
print "QQNumber:".$QQ{$UserID}{'QQNumber'}."\n";
print "QQPasswd:".$QQ{$UserID}{'QQPasswd'};
$result=fork();
if($result == 0) {
print "i am child\n";
print "process qq:".$QQ{$UserID}{'QQNumber'}."\n";
$QQ{$UserID}{'Sockect'}=Net::OICQ->new;
$QQ{$UserID}{'Sockect'}->add_handler('recv_mesg',\&qq_recv_mesg);
$QQ{$UserID}{'Sockect'}->add_handler('group_search',\&qq_group_search);
$QQ{$UserID}{'Sockect'}->add_handler('on_login',\&qq_login);
$QQ{$UserID}{'Sockect'}->add_handler('usr_info',\&qq_user_info);
$QQ{$UserID}{'Sockect'}->login($QQ{$UserID}{'QQNumber'}, $QQ{$UserID}{'QQPasswd'}) or die "Failed to login.\n";
#??3??и▓??
my $select=IO::Select->new();
$select->add(\*STDIN);
my $con=1;
my $f=1;
while(1){
$QQ{$UserID}{'Sockect'}->do_one_loop();
foreach ($select->can_read(0.1)){
my $input=<>;
unless($input){next;}
process_kb($input,$QQ{$UserID}{'Sockect'});
}
} #end while(1)
} else {
#????3им
print "i am parent\n";
$QQ{$UserID}{'Status'} = 1;
}
}
}
sleep(5);
}
sub process_kb{
my($input)=@_;
chomp($input);
unless($input){print "please input command:\n";return;}
my ($a,$b,$c)=split(",",$input);
#unless($a){print "please input command\n";return;}
print "command:$a\n";
unless($b){
$QQ{$UserID}{'Sockect'}->push_command($a,[]);
}
else{
unless($c){
print "arg1:$b";
$QQ{$UserID}{'Sockect'}->push_command($a,[$b]);
}
else{print " arg2:$c\n";
$QQ{$UserID}{'Sockect'}->push_command($a,[$b,$c])}
}
}
sub qq_recv_mesg{
my($get)=@_;
if($$get{type} eq "buddy"){
print "$$get{srcid}:$$get{mesg}\n";
unless($f){$f=1;return;}
$QQ{$UserID}{'Sockect'}->push_command("send_msg",[$$get{srcid},"╬╥╒¤╘┌╩╣╙├QQ╣╥╗·│╠╨Єгм╔╘║є╘┘┴к╧╡╬╥"]);
$f=0;
}
elsif($$get{type} eq "group"){
print "$$get{srcid}:$$get{mesg}\n";
$QQ{$UserID}{'Sockect'}->push_command("send_group_msg",[$$get{srcid},"?aи║??и▓?б┬ии?б┴??бе???бфбъ?$con"]);
$con++;
}
}
sub qq_login{
#foreach (1...100){
#$qq->push_command("send_msg",[258279649,"hi,test$_"]);
# $qq->push_command("send_group_msg",[209454195,"test$_"]);
# }
}
sub qq_group_search{
}
sub user_info{
}