Search
Categories
Documents
Net::YMSG - Interface to the Yahoo! Messenger IM protocol (Displayed) README
|
Net::YMSG - Interface to the Yahoo! Messenger IM protocol
Net::YMSG - Interface to the Yahoo! Messenger IM protocol
use Net::YMSG;
my $yahoo = Net::YMSG->new(
id => 'your_yahoo_id',
password => 'your_password',
);
$yahoo->login or die "Can't login Yahoo!Messenger";
$yahoo->send('recipient_yahoo_id', 'Hello World!');
Net::YMSG is a client class for connecting with the Yahoo! Messenger server, and transmitting and receiving a message.
Since implement of a protocol is the result of analyzing and investigating a packet, it has an inadequate place. However, it is working as expected usually.
This section documents method of the Net::YMSG class.
It should be called with following arguments (items with default value are optional):
id => yahoo id
password => password
pre_login_url => url which refers to setting information.
(default http://msg.edit.yahoo.com/config/)
hostname => server hostname
(default 'scs.yahoo.com)
Returns a blessed instantiation of Net::YMSG.
Note: If you plan to connect with Yahoo!India (yahoo.co.in), it sets up as follows.
my $yahoo_japan = Net::YMSG->new(
pre_login_url => 'http://edit.my.yahoo.co.in/config/',
hostname => 'cs.yahoo.co.in',
);
Since it connects with Yahoo!(yahoo.com), this procedure is unnecessary in almost all countries.
This method gets or sets the present Yahoo Id.
This method gets or sets the present password.
Call this after new() to logon the Yahoo!Messenger service.
This method send an Instant-Message $message to the user specified by $yahoo_id.
=cut
sub send
{
my $self = shift;
my $recipient = shift;
my $message = join '', @_;
my $server = $self->handle;
my $event = $self->create('SendMessage');
$event->from($self->id);
$event->to($recipient);
$event->body($message);
$event->option(1515563606); # in Buddy list then 1515563606 else 1515563605
$server->send($event->to_raw_string, 0);
}
This method send a Message $message to the given $chatroom.
This method sets the status messages for the current user. 'Status message' is set by $status_message. 'Busy icon' is set by the numerical value of $busy.
The $busy should be called with following arguments:
0 - I'm Available
1 - Busy
2 - Sleep
This method reads the message from a server socket and returns a corresponding Event object.
The Event object which will be returned is as follows:
Net::YMSG::InvalidLogin - Invalid Login
Net::YMSG::Login - Succeeded in Login.
Net::YMSG::GoesOnline - Buddy has logged in.
Net::YMSG::ReceiveMessage - Message was received.
Net::YMSG::ChangeState - Buddy has change status.
Net::YMSG::GoesOffline - Buddy logged out.
Net::YMSG::NewFriendAlert - New Friend Alert.
Net::YMSG::ChatRoomLogon - Log in chat room
Net::YMSG::ChatRoomReceive- Log in chat room
Net::YMSG::ChatRoomLogoff - Log in chat room
Net::YMSG::UnImplementEvent - Un-implemented event was received.
All event objects have the following attributes:
- $event->from
-
Yahoo id which invoked the event.
- $event->to
-
Yahoo id which should receive an event.
- $event->body
-
The contents of an event. The message and state which were transmitted.
- $event->code
-
The event number on Yahoo Messenger Protocol.
This method returns a raw server socket. When connection has already ended, the socket is returned, and when not connecting, it connects newly.
This method sets the Event handler for a specific Yahoo!Messenger server event. $event_handler is the sub class of Net::YMSG::EventHandler.
Note: The event which can be overwritten should look at the method signature of the Net::YMSG::EventHandler manpage.
This method adds the file handle (event sauce) to supervise. The file handle to add is specified by $file_handle. The code reference to the processing to perform is specified by $code_ref.
C<$flag> eq 'r' - set when the file handle to add is an object for read.
C<$flag> eq 'w' - set when the file handle to add is an object for write.
By adding another handle (for example, STDIN), processing can be performed based on those inputs. Usually, the server socket of 'Yahoo!Messenger server' is set as a candidate for surveillance.
ex:
# The input of STDIN is transmitted to 'EXAMPLE_YAHOO_ID'.
$yahoo->add_event_source(\*STDIN, sub {
my $message = scalar <STDIN>;
chomp $message;
$yahoo->send('EXAMPLE_YAHOO_ID', $message);
}, 'r');
If you're writing a fairly simple application that doesn't need to interface with other event-loop-based libraries, you can just call start() to begin communicating with the server.
This method logs you in $roomname. You need to provide the $id along with Roomname.
Check out http://www.cse.iitb.ac.in/varunk/YahooProtocol.php for the list of RoomIDs corresponding
to the Room you wish to join.[This is a comprehensive list and might not list all available rooms
at that moment; Follow instructions to get the roomid of the room you wish to join]
This method logs you off any chat rooms you are currently logged into.
All offline messages would be displayed on login by declaring the Event_handler of ReceiveMessage as following :
my $first=0;
sub ReceiveMessage
{
my $self = shift;
my $event = shift;
my @from = split(``\x80'',$event->from);
my @body = split(``\x80'',$event->body);
my $i;
if($first==0 && $#from >= 1) {
# offline messages
print ``Your Offline messages :\n[They have been saved in the file \'offline\' in the current directory]\n'';
open(OFFLINE,``>>offline'') || printf ``Error opening file offline'';
for($i=0;$i<=$#from;$i++) {
print OFFLINE ``[''.$from[$i].``]: ''.$body[$i].``\n'';
}
close(OFFLINE);
}
$first=1;
for($i=0;$i<=$#from;$i++) {
if ($body[$i] ne ``'') {
$body[$i] =~ s{</?(?:font|FACE).+?>}{}g;
if( ! defined $nametonum{``$from[$i]''} ) {
$nametonum{``$from[$i]''} = $count;
$numtoname{``$count''}=$from[$i];
$count++;
}
my $message = sprintf "[%s(%s)] %s \n", $from[$i],$nametonum{"$from[$i]"},$body[$i];
print $message;
}
}
}
#!perl
use Net::YMSG;
use strict;
my $yahoo = Net::YMSG->new;
$yahoo->id('yahoo_id');
$yahoo->password('password');
$yahoo->login or die "Can't login Yahoo!Messenger";
$yahoo->send('recipient_yahoo_id', 'Hello World!');
__END__
#!perl
use Net::YMSG;
use strict;
use constant IN_BUSY => 1;
my $yahoo = Net::YMSG->new(
id => 'yahoo_id',
password => 'password',
);
$yahoo->login or die "Can't login Yahoo!Messenger";;
$yahoo->change_state(IN_BUSY, q{I'm very busy now!});
sleep 5;
__END__
#!perl
use Net::YMSG;
use strict;
my $yahoo = Net::YMSG->new(
id => 'yahoo_id',
password => 'password',
);
$yahoo->login or die "Can't login Yahoo!Messenger";;
$yahoo->invisible();
__END__
#!perl
use Net::YMSG;
use strict;
my $yahoo = Net::YMSG->new(
id => 'yahoo_id',
password => 'password',
);
$yahoo->set_event_handler(new ToStdoutEventHandler);
$yahoo->login or die "Can't login Yahoo!Messenger";
$yahoo->start;
package ToStdoutEventHandler;
use base 'Net::YMSG::EventHandler';
use strict;
sub ChangeState {}
sub GoesOffline {}
sub GoesOnline {}
sub UnImplementEvent {}
sub ReceiveMessage
{
my $self = shift;
my $event = shift;
printf "%s: %s\n", $event->from, $event->body;
}
__END__
#!perl
use Net::YMSG;
use strict;
my $yahoo = Net::YMSG->new(
pre_login_url => 'http://edit.my.yahoo.co.in/config/',
hostname => 'cs.yahoo.co.in',
);
$yahoo->id('yahoo_id');
$yahoo->password('password');
$yahoo->login or die "Can't login Yahoo!Messenger";
$yahoo->send('recipient_yahoo_id', 'Namaste!');
__END__
my $chatroom=``Linux, FreeBSD, Solaris:1'';
my $chatroomcode=``1600326591'';
my $message= ``Hi Room!'';
#!perl
use Net::YMSG;
use strict;
my $yahoo = Net::YMSG->new(
id => 'yahoo_id',
password => 'password',
);
$yahoo->login or die "Can't login Yahoo!Messenger";;
# Join chat room C<$chatroom>
my $msg = $yahoo->pre_join();
my $msg=$yahoo->join_room($chatroom,$chatroomcode);
| # Send message to chatroom |
| | $yahoo->chatsend($chatroom,$message);
| |
|
# Log off chatroom
$yahoo->logoffchat();
__END__
Please refer to the use agreement of Yahoo! about use of the Yahoo!Messenger service.
=cut
Information
|
This site is currently in testing, it is not yet operating using the full database. Until it is officially launched you may wish to visit Help-Site Computer Manuals. After launch, this site (HelpSpy) will replace Help-Site. Information about the spider which is currently trawling the Internet looking for links to add to this directory can be found here. |
|