
scrpnsanctuary
Novice
Jun 9, 2009, 7:39 AM
Post #12 of 12
(849 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:
### 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:
### 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
### 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)
|