CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Tracking if AIMBot is offline

 



kladizkov
Novice

Jun 3, 2009, 10:38 AM

Post #1 of 12 (1161 views)
Tracking if AIMBot is offline Can't Post

Hi,

I'm writing an AIM bot using Net::OSCAR. When net connection is lost it goes offline. I need to find a way to periodically check if its online or not. But, I don't find a method in Net::OSCAR to check this. Anyone have any idea how to check if the connected bot is online or not?

Please help!


scrpnsanctuary
Novice

Jun 8, 2009, 11:37 AM

Post #2 of 12 (1148 views)
Re: [kladizkov] Tracking if AIMBot is offline [In reply to] Can't Post

I would suggest using Net::Ping to check if you can ping the server.

http://search.cpan.org/~smpeters/Net-Ping-2.35/lib/Net/Ping.pm


Edit: I may be confused. Do you want the bot to check for a connection so it can sign back in when it comes back up OR do you want a different script that will check AIM to see if your bot is listed as on line?
----------
The vastness of what we know is only surpassed by the vastness of what we don't.

(This post was edited by scrpnsanctuary on Jun 8, 2009, 11:39 AM)


kladizkov
Novice

Jun 8, 2009, 11:40 AM

Post #3 of 12 (1143 views)
Re: [scrpnsanctuary] Tracking if AIMBot is offline [In reply to] Can't Post

what I plan to do is to send an IM to itself and check if it can receive it.. but haven't implemented it yet


scrpnsanctuary
Novice

Jun 8, 2009, 11:42 AM

Post #4 of 12 (1142 views)
Re: [kladizkov] Tracking if AIMBot is offline [In reply to] Can't Post

Oh, okay. You want to make sure AIM lists your bot as online.

What you're planning sounds good to me. I am unfamiliar with that module though, so someone who knows it might have a better solution.
----------
The vastness of what we know is only surpassed by the vastness of what we don't.


kladizkov
Novice

Jun 8, 2009, 11:44 AM

Post #5 of 12 (1140 views)
Re: [scrpnsanctuary] Tracking if AIMBot is offline [In reply to] Can't Post


Quote
You want to make sure AIM lists your bot as online.


Exactly!!!


scrpnsanctuary
Novice

Jun 8, 2009, 12:04 PM

Post #6 of 12 (1138 views)
Re: [kladizkov] Tracking if AIMBot is offline [In reply to] Can't Post

Well, I have one suggestion.

Since the module supports callbacks and there is one for signon_done, you can use that.


This is a lame one, just to demonstrate:

Code
use Net::OSCAR qw(:standard); 
$i_am_signed_in = 0;

### Define sub for callback
sub i_am_in
{
$i_am_signed_in = 1;
}

### New object
$oscar = Net::OSCAR->new();

### Set callback to our sub
$oscar->set_callback_signon_done(\&i_am_in);

### Sign on
$oscar->signon($screenname, $password);

$time_signin = time(); ### Get current time
while(!$i_am_signed_in && (time() - $time_signin < 10) )
{
### Sleep for 1 second intervals while I am not connected, for the next 10 seconds
sleep(1);

### do_one_loop processes incomming events (like the sign on one)
$oscar->do_one_loop();
}

unless($i_am_signed_in) {die 'Could not sign in.';}

### Rest of program ###




It may actually be easier just to try to send yourself an IM, though, lol.


-- EDIT :: This, of course, only works for checking that you are actually signed on when you initiate the sign on. The module does provide good return information when you make a call, so I highly suggest capturing and checking that info for detecting random disconnects.

I noticed that by default Net::OSCAR will not not stealth when you sign in, you have to pass it extra flags if you want to do that. If you are worried about your bot being signed on in invisible mode, I don't think you need to be.
----------
The vastness of what we know is only surpassed by the vastness of what we don't.

(This post was edited by scrpnsanctuary on Jun 8, 2009, 12:20 PM)


kladizkov
Novice

Jun 8, 2009, 12:40 PM

Post #7 of 12 (1130 views)
Re: [scrpnsanctuary] Tracking if AIMBot is offline [In reply to] Can't Post

this one only checks if the bot got logged in... the problem is that sometimes the bot gets logged out... this is where my problems begins... there is no function or callback to check if the bot is online or not...


scrpnsanctuary
Novice

Jun 8, 2009, 12:50 PM

Post #8 of 12 (1128 views)
Re: [kladizkov] Tracking if AIMBot is offline [In reply to] Can't Post

To do it right, you will have to set up a callback for
$oscar->set_callback_error();

This gets called when any error is encountered. Your callback sub will have to look through the info returned and figure out if you've disconnected.
----------
The vastness of what we know is only surpassed by the vastness of what we don't.


kladizkov
Novice

Jun 8, 2009, 1:00 PM

Post #9 of 12 (1126 views)
Re: [scrpnsanctuary] Tracking if AIMBot is offline [In reply to] Can't Post

it didn't work for me...


scrpnsanctuary
Novice

Jun 8, 2009, 1:54 PM

Post #10 of 12 (1124 views)
Re: [kladizkov] Tracking if AIMBot is offline [In reply to] Can't Post

You need to provide more information and at least some of your code if you wish for other people to help you troubleshoot.

Only stating it didn't work discourages people from assisting you, since it gives the impression you have put little to no work into it and want other people to do all the work for you.

So, are you receiving an error when you try to run your script? If so, what does it say? Please also post a copy of your error handling subroutine. I'll do what I can to assist you.
----------
The vastness of what we know is only surpassed by the vastness of what we don't.

(This post was edited by scrpnsanctuary on Jun 8, 2009, 1:56 PM)


kladizkov
Novice

Jun 9, 2009, 5:17 AM

Post #11 of 12 (1115 views)
Re: [scrpnsanctuary] Tracking if AIMBot is offline [In reply to] Can't Post


Code
sub error 
{
my ($oscar, $connection, $error, $description, $fatal) = @_;
die ("Error: " . $connection->{description} . "\n");
}

$oscar->set_callback_error(\&error);


This is my error handler. But, this one doesn't get called when connection drops.

The issue can be recreated by creating a sample program and switching off your LAN interface ( may ifdown eth0 or pull out the cable ) while running it. The bot goes offline after some time but error callback function won't get called.


scrpnsanctuary
Novice

Jun 9, 2009, 7:39 AM

Post #12 of 12 (1111 views)
Re: [kladizkov] Tracking if AIMBot is offline [In reply to] Can't Post

Yeah, after re-reading the module info it seems to me that that error sub only gets called on certain error events. Disconnecting or loosing connection is not one of them.

I assume your bot is sending and receiving IMs when it will disconnect, and it looks like there is no callback to the error sub when sending an IM fails.

So, it looks like detecting failures to send IMs is the best way to know if you have been disconnected. Fortunately there are several things you can do.

I think, based on what the module says, that the best way to do it is to catch the request IDs generated by send_im() and use the im_ok() callback to verify that your messages are being sent.

Example for callback:

Code
### Create hash to hold im request ids 
%im_request_ids = ();

sub im_sent_ok
{
my($oscar, $to, $request_id) = @_;

if($im_request_ids{$request_id})
{
### Message was sent by me, and the time is logged there.

### Blank out the time, so the ID doesn't get checked
$im_request_ids{$request_id} = 0;

### Attempt to undefine it. Not sure if this is appropriate or will work (double check)
### If it does work, it will keep the size of the hash down
undef $im_request_ids{$request_id};
}
else
{
### Doesn't look like I sent a message with that request id, error
}

}

$oscar->set_callback_im_ok(\&im_sent_ok);



When you send an IM, here's how my example would catch the request id:

Code
### Send IM and catch the request ID 
$request_id = send_im($to, $message);

### If the message was too long to send, $request_id will be zero
unless($request_id > 0)
{
### Split up message, resend
}

### Use the request ID as a key in the hash, log the time the IM was sent
$im_request_ids{$request_id} = time();



In your main do() or while() loop, you'd want to check periodically that %im_request_ids doesn't have anything too old

Code
### Check every 30 seconds 
if ( int(time()/30) == (time()/30) )
{
foreach $key (keys %im_request_ids)
{
### If the time logged is > 0, and it's been over 120 seconds since the message was sent
if( ($im_request_ids{$key} > 0) && (time() - $im_request_ids{$key} > 120) )
{
### IM failed to send, error. Probably disconnected.
}
}
}



My example is not really good. Hopefully it helps you though.
----------
The vastness of what we know is only surpassed by the vastness of what we don't.

(This post was edited by scrpnsanctuary on Jun 9, 2009, 7:47 AM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives