| 1 | #================== | ||
| 2 | # NOTE: this is a work in progress. don't expect it to do | ||
| 3 | # anything useful yet. I just put it in CVS so others could | ||
| 4 | # see a more complex example of Net::ICQ usage. | ||
| 5 | #================== | ||
| 6 | |||
| 7 | #!/usr/bin/perl | ||
| 8 | |||
| 9 | use strict; | ||
| 10 | use Net::ICQ; | ||
| 11 | use Data::Dumper; | ||
| 12 | |||
| 13 | |||
| 14 | my ( | ||
| 15 | $icq, | ||
| 16 | $ready | ||
| 17 | ); | ||
| 18 | |||
| 19 | |||
| 20 | $ready = 0; | ||
| 21 | |||
| 22 | $icq = Net::ICQ->new($ARGV[0], $ARGV[1]) | ||
| 23 | or print ("Please specify a UIN and password on the command line\n"), exit; | ||
| 24 | |||
| 25 | $icq->{_debug} = 1; | ||
| 26 | |||
| 27 | # register dump_event as the handler for ALL (!) events | ||
| 28 | foreach (values(%Net::ICQ::srv_codes)) { | ||
| 29 | $icq->add_handler($_, \&dump_event); | ||
| 30 | } | ||
| 31 | |||
| 32 | $icq->add_handler('SRV_X2', \&handle_x2); | ||
| 33 | $icq->add_handler('SRV_LOGIN_REPLY', \&handle_login_reply); | ||
| 34 | |||
| 35 | # register a SIGINT handler, so ctrl-c will trigger a clean shutdown | ||
| 36 | $SIG{INT} = \&disconnect; | ||
| 37 | |||
| 38 | |||
| 39 | $icq->connect(); | ||
| 40 | print "connecting...\n"; | ||
| 41 | while (!$ready) { | ||
| 42 | $icq->do_one_loop; | ||
| 43 | } | ||
| 44 | print "ready\n"; | ||
| 45 | |||
| 46 | print "looping (ctrl-c to exit)\n"; | ||
| 47 | $icq->start; | ||
| 48 | |||
| 49 | |||
| 50 | |||
| 51 | |||
| 52 | |||
| 53 | # dump event contents | ||
| 54 | sub dump_event { | ||
| 55 | my ($icq, $event) = @_; | ||
| 56 | |||
| 57 | print Dumper($event); | ||
| 58 | } | ||
| 59 | |||
| 60 | |||
| 61 | # send CMD_ACK_MESSAGES on X2 from server to keep it from sending us | ||
| 62 | # any received offline msgs on next login | ||
| 63 | sub handle_x2 { | ||
| 64 | my ($icq, $event) = @_; | ||
| 65 | |||
| 66 | print (":X2\n"); | ||
| 67 | $icq->send_event('CMD_ACK_MESSAGES'); | ||
| 68 | } | ||
| 69 | |||
| 70 | |||
| 71 | # set ready to 1 to signal we can send events now | ||
| 72 | sub handle_login_reply { | ||
| 73 | my ($icq, $event) = @_; | ||
| 74 | |||
| 75 | print (":LOGIN_REPLY\n"); | ||
| 76 | $ready = 1; | ||
| 77 | } | ||
| 78 | |||
| 79 | |||
| 80 | sub disconnect { | ||
| 81 | $icq->disconnect(); | ||
| 82 | exit(); | ||
| 83 | } |