Leser: 24
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
#!/usr/bin/perl use strict; use warnings; use WWW::Mechanize; use Net::XMPP; sub getxmpp { my $mech = WWW::Mechanize->new( cookie_jar => {} ); $mech->agent_alias( 'Windows IE 6' ); $mech->add_header('Content-Type' => 'application/x-www-form-urlencoded; charset=UTF-8' ); $mech->add_header('X-Requested-With' => 'XMLHttpRequest' ); my ( $self, $event ) = @_; my $nick = shift; my $loginpost = $mech->post( 'http://www.quakelive.com/user/login', { u => 'email@domain.com', p => 'meinpass', r => '0', } ); $mech->get("http://www.quakelive.com/user/load"); my $site = $mech->content(); if($site =~/".+XAID":"(.+)","STATUS/){ return $1; } else { print "fail"; } } sub xmppconnect { my $connection = Net::XMPP::Client->new(); my $xmpp = getxmpp(); $connection->Connect( hostname => 'xmpp.quakelive.com') or die "Cannot connect ($!)\n"; my @result = $connection->AuthSend( "username" => 'qlstats', "password" => $xmpp, "resource" => 'quakelive'); if ($result[0] ne "ok") { die "Ident/Auth with server failed: $result[0] - $result[1]\n"; } # $connection->PresenceSend(); my $message = Net::XMPP::Message->new(); $message->SetMessage( "to" => 'Mindfoo\@xmpp.quakelive.com', "type" => "chat", "body" => "testmsg from script"); $connection->Send($message) or die "Cant send msg!\n"; sleep(2); $connection->Disconnect(); } xmppconnect();
2009-04-04T08:00:05 format_cPruef doch erst mal ob dir die Funktion getxmpp() ueberhaupt einen Wert zurueck gibt.
--A.
2009-04-04T12:42:38 neposNaja, dann schau doch mal in das Modul, in dem der Fehler gemeldet wird und schau dir an, was an der entsprechenden Stelle steht...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
sub getxmpp { my $mech = WWW::Mechanize->new( cookie_jar => {} ); $mech->agent_alias( 'Windows IE 6' ); $mech->add_header('Content-Type' => 'application/x-www-form-urlencoded; charset=UTF-8' ); $mech->add_header('X-Requested-With' => 'XMLHttpRequest' ); my ( $self, $event ) = @_; my $nick = shift; my $loginpost = $mech->post( 'http://www.quakelive.com/user/login', { u => 'user@mail.com', p => 'passwort', r => '0', } ); $mech->get("http://www.quakelive.com/user/load"); my $site = $mech->content(); if($site =~/USERNAME":"(.+)","XAID":"(.+)","STATUS/){ push(@xmppdata,("$1","$2")); } else { print "Fail!\n$site"; exit; } } sub xmppconnect { use constant USER => $xmppdata[0]; use constant PASS => $xmppdata[1]; my $connection = Net::XMPP::Client->new(); $connection->Connect( hostname => 'xmpp.quakelive.com') or die "Cannot connect ($!)\n"; my @result = $connection->AuthSend( "username" => USER, "password" => PASS, "ressource" => 'quakelive'); if (!defined($result[0])) { print "Authed with XMPP server as user $xmppdata[0] with password $xmppdata[1]\n"; } else { die "Ident/Auth with server failed: $result[0] - $result[1]\n"; } $connection->PresenceSend(); my $message = Net::XMPP::Message->new(); $message->SetMessage( "to" => 'Mindfoo\@xmpp.quakelive.com', "type" => "chat", "body" => "testmsg from script"); $connection->Send($message) or die "Cant send msg!\n"; sleep(1); $connection->Disconnect(); }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
diff -u ?.1
--- a.1 2009-04-04 20:45:21.415888190 +0200
+++ b.1 2009-04-04 20:46:01.200703520 +0200
@@ -9,16 +9,17 @@
my $loginpost = $mech->post(
'http://www.quakelive.com/user/login',
{
- u => 'email@domain.com',
- p => 'meinpass',
+ u => 'user@mail.com',
+ p => 'passwort',
r => '0',
}
);
$mech->get("http://www.quakelive.com/user/load");
my $site = $mech->content();
- if($site =~/".+XAID":"(.+)","STATUS/){
- return $1;
+ if($site =~/USERNAME":"(.+)","XAID":"(.+)","STATUS/){
+ push(@xmppdata,("$1","$2"));
} else {
- print "fail";
+ print "Fail!\n$site";
+ exit;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
diff -u ?.2
--- a.2 2009-04-04 20:45:33.828027839 +0200
+++ b.2 2009-04-04 20:47:03.097072730 +0200
@@ -1,21 +1,22 @@
sub xmppconnect {
+ use constant USER => $xmppdata[0];
+ use constant PASS => $xmppdata[1];
my $connection = Net::XMPP::Client->new();
- my $xmpp = getxmpp();
$connection->Connect( hostname => 'xmpp.quakelive.com') or die "Cannot connect ($!)\n";
- my @result = $connection->AuthSend( "username" => 'qlstats', "password" => $xmpp, "resource" => 'quakelive');
- if ($result[0] ne "ok") {
+ my @result = $connection->AuthSend( "username" => USER, "password" => PASS, "ressource" => 'quakelive');
+ if (!defined($result[0])) {
+ print "Authed with XMPP server as user $xmppdata[0] with password $xmppdata[1]\n";
+ } else {
die "Ident/Auth with server failed: $result[0] - $result[1]\n";
}
-
-# $connection->PresenceSend();
-
+ $connection->PresenceSend();
my $message = Net::XMPP::Message->new();
$message->SetMessage(
"to" => 'Mindfoo\@xmpp.quakelive.com',
"type" => "chat",
"body" => "testmsg from script");
$connection->Send($message) or die "Cant send msg!\n";
- sleep(2);
+ sleep(1);
$connection->Disconnect();
}