Changeset 767

Show
Ignore:
Timestamp:
09/17/02 12:46:50
Author:
miyagawa
Message:

0.02

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • POE-Component-YahooMessenger/trunk/Changes

    r764 r767  
    11Revision history for Perl extension POE::Component::YahooMessenger 
     2 
     30.02  Tue Sep 17 12:45:54 JST 2002 
     4        * Fixed logon goes_online events 
     5        - Added null message handling in receive_message 
    26 
    370.01  Wed Sep 11 21:24:31 2002 
  • POE-Component-YahooMessenger/trunk/MANIFEST

    r764 r767  
    22MANIFEST                        This list of files 
    33Makefile.PL 
     4README 
    45lib/POE/Component/YahooMessenger.pm 
    56lib/POE/Component/YahooMessenger/Constants.pm 
  • POE-Component-YahooMessenger/trunk/lib/POE/Component/YahooMessenger.pm

    r764 r767  
    33use strict; 
    44use vars qw($VERSION); 
    5 $VERSION = 0.01
     5$VERSION = 0.02
    66 
    77use POE qw(Wheel::SocketFactory Wheel::ReadWrite Driver::SysRW 
    8            Filter::Stream Filter::YahooMessengerPacket); 
    9 use Socket;                    # for constants 
     8           Filter::YahooMessengerPacket Component::YahooMessenger::Constants); 
     9use Socket; 
    1010use Net::YahooMessenger::CRAM; 
    11 use POE::Component::YahooMessenger::Constants; 
    1211 
    1312sub spawn { 
     
    3938            goes_offline        => \&goes_offline, 
    4039            change_status       => \&_handle_common, 
    41             receive_message     => \&_handle_common
     40            receive_message     => \&receive_message
    4241            new_friend_alert    => \&_handle_common, 
    4342            toggle_typing       => \&_handle_common, 
     
    188187sub goes_online { 
    189188    my($kernel, $heap, $event) = @_[KERNEL, HEAP, ARG0]; 
    190     $heap->{online}->{$event->id} = 1; 
     189    my $number = $event->number_of_online_buddies; 
     190    $number = 1 unless defined $number; 
     191    for my $num (0..$number-1) { 
     192        $heap->{online}->{$event->buddy_id($num)} = 1; 
     193        my $goes_online = POE::Component::YahooMessenger::Event->new( 
     194            'goes_online', 0, { 
     195                buddy_id => $event->buddy_id($num), 
     196                status_code => $event->status_code($num), 
     197                status_message => $event->status_message($num), 
     198                busy_code => $event->busy_code($num), 
     199            }, 
     200        ); 
     201        $kernel->yield(notify => $goes_online->name, $goes_online); 
     202    } 
     203
     204 
     205sub goes_offline { 
     206    my($kernel, $heap, $event) = @_[KERNEL, HEAP, ARG0]; 
     207    delete $heap->{online}->{$event->buddy_id}; 
    191208    $kernel->yield(notify => $event->name, $event); 
    192209} 
    193210 
    194 sub goes_offline { 
    195     my($kernel, $heap, $event) = @_[KERNEL, HEAP, ARG0]; 
    196     delete $heap->{online}->{$event->id}; 
    197     $kernel->yield(notify => $event->name, $event); 
     211sub receive_message { 
     212    my($kernel, $heap, $event) = @_[KERNEL, HEAP, ARG0]; 
     213    my $code = $event->status_code; 
     214    unless (defined $code && $code == 99) { 
     215        $kernel->yield(notify => $event->name, $event);  
     216    } 
    198217} 
    199218 
    200219sub send_message { 
    201220    my($kernel, $heap, $args) = @_[KERNEL, HEAP, ARG0]; 
     221    my $option = _is_buddy($heap, $args->{to}) 
     222        ? $Options->{to_buddies} : $Options->{to_non_buddies}; 
    202223    $heap->{sock}->put( 
    203224        POE::Component::YahooMessenger::Event->new( 
    204             'send_message', 1515563606, { 
     225            'send_message', $option, { 
    205226                from => $heap->{id}, 
    206227                to   => $args->{to}, 
     
    209230        ), 
    210231    ); 
     232} 
     233 
     234sub _is_buddy { 
     235    my($heap, $buddy_id) = @_; 
     236    my %buddies = map $_ => 1, map @$_, values %{$heap->{buddies}}; 
     237    return $buddies{$buddy_id}; 
    211238} 
    212239 
  • POE-Component-YahooMessenger/trunk/lib/POE/Component/YahooMessenger/Constants.pm

    r764 r767  
    77    require Exporter; 
    88    @ISA    = qw(Exporter); 
    9     @EXPORT = qw($MessageHeader $BodySeparater 
     9    @EXPORT = qw($Default $MessageHeader $BodySeparater $Options 
    1010                 $ReceiveEventCodes $ReceiveEventNames 
    1111                 $SendEventCodes $SendEventNames 
    12                  $BodyCodes $BodyNames $Default); 
     12                 $BodyCodes $BodyNames); 
    1313} 
    1414 
     
    1818    hostanme      => 'scs.yahoo.com', 
    1919    port          => 5050, 
     20}; 
     21 
     22$Options = { 
     23    to_buddies => 1515563606, 
     24    to_non_buddies => 1515563605, 
    2025}; 
    2126 
  • POE-Component-YahooMessenger/trunk/lib/POE/Component/YahooMessenger/Event.pm

    r764 r767  
    88        my $wantkey = shift; 
    99        return sub { 
    10             my $self = shift
     10            my($self, $number) = @_
    1111            my @values; 
    1212            my @params = $self->params; 
     
    1414                push @values, $value if $key eq $BodyNames->{$wantkey}; 
    1515            } 
    16             return wantarray ? @values : $values[0]; 
     16            return defined $number ? $values[$number] : $values[0]; 
    1717        }; 
    1818    }