Jump to content

_TocLib, a library for TOC Protocol


Falcone88
 Share

Recommended Posts

Hello,

This is my first publicly posted bit of code, and I hope you will all enjoy it :whistle: _TocLib is a library that allows for easy communication over the TOC (Talk to Oscar) protocol. This is the protocol which third-party clients can use to connect to OSCAR-based instant message servers, such as AIM and ICQ. Links to full documentation of this protocol can be found in the _TocLib.au3 file. I have implemented a function to send an IM, as I expect that to be the most useful command for most people. I have not yet added things like communication in chat rooms, but they would be extremely easy to add. I may do them eventually, but for now I thought I'd share the lib as it is :P

The library does not stop there, however. While you can make your own while loop and check for input from the server manually, I have included a set of functions which allow for an event-driven interface. You can use _TocRegisterFunc to set a function that will be called when the given TOC server command is received, then _TocInitLoop() to start an Adlib-based loop to check for input and parse accordingly.

When I clean it up a bit more and update the functions (if there is interest) I may release myCommands version 4, a program I developed which uses AIM's ability to send and receive text messages to control a computer via cell phone. I used to use BSFLite (a text-based AIM client), pipe the output using STDOUT and write to it with ControlSendPlus() (this was version 2/3). Using this library, however, it's much smaller and I believe it will be much less finicky :D

Here is a quick demo on how to use the basic functions:

Global $myUser = "" ; Define these
Global $myPass = "" ; And then run this
Global $targetUser = "" ; to test :)

Global $doQuit = false

$login = _TocLogin( $myUser, $myPass);, "localhost")
if not $login Then
    if @error == $TOC_ERROR Then
        _DebugPrint( "TOC Error: code " & $login )
    Else
        _DebugPrint( "_TocLogin @error = " & @error )
    EndIf
Else
    _DebugPrint( "Logged in successfully" )
EndIf

_TocRegisterFunc( $TOC_CMD_IMRECV, "HandleRecv" )
_TocInitLoop()

_TocSendIM($targetUser, "This is a test")
_TocSendIM($targetUser, "haha auto response", true)

Do
    Sleep( 50 ) ; Hang out so the loop can recieve messages
Until $doQuit

Func HandleRecv($packet)
    _DebugPrint("Recieved message: " & $packet)
    $msg = _TocParseIm( $packet )
    
    MsgBox(0,"_TocLib Test", "("&$msg[0]&") said: " & $msg[3], 2)   
    
    if StringInStr($msg[3], "good bye") Then $doQuit = true     
EndFunc

Enjoy!

Questions? Comments?

EDIT: Updated file. Added _TocIsRegistered() and the ability to catch any command with one register statement. Could be useful....

Also, here's a list of the current functions included in the au3:

_TocLogin
        _TocFinalizeLogin
        _TocSendIM
        _TocSetAway
        _TocParseIm
        _TocParseConfig <- doesn't do anything yet
        _TocCleanup
        
        _TocRegisterFunc
        _TocIsRegistered
        _TocInitLoop
        _TocStopLoop
        _TocDoLoop
        
        _TocRoastPass
        _TocNormalizeName
        _TocNormalizeString
        _TocMakeSigninCode
        _TocMakeFlapPacket
        _TocDecodeFlap
        _TocSendFlap
        _TocSendRaw 
        _TocWaitFlap    
        _TocGetFlap
        
        _BinaryNumber
        _BinaryNumberDecode

_TocLib.au3

(Previous downloads: 51)

Edited by Falcone88

My Code:- _TocLib - UDF for TOC protocol (The simplified one used by 3rd party AIM/ICQ clients)

Link to comment
Share on other sites

  • 3 weeks later...

Well, in trying to use this to make an AIM client, I've discovered a flaw in the FLAP header (Arr! It's back to haunt me!)

For packets greater than 255 characters, _TocMakeFlapPacket() and _TocDecodeFlap() don't work correctly... I'll keep looking into it, but any help would be amazing. The offending code is here, if you don't want to DL the lib:

EDIT: Fixed :whistle:

Edited by Falcone88

My Code:- _TocLib - UDF for TOC protocol (The simplified one used by 3rd party AIM/ICQ clients)

Link to comment
Share on other sites

A few questions.

Is it possible to extract the exzact text thats said? For example:

test

Instead of

2007-04-03 04:17:00 : <HTML><BODY><FONT FACE="Arial" SIZE=2 COLOR=#000000>test</FONT></BODY></HTML>

Also, is it possible to log the user that IM's you as well?

Link to comment
Share on other sites

A few questions.

Is it possible to extract the exzact text thats said? For example:

Instead of

Also, is it possible to log the user that IM's you as well?

to 1.:

You need just a bit of thinking and the String* commands:

$Input = '2007-04-03 04:17:00 : <HTML><BODY><FONT FACE="Arial" SIZE=2 COLOR=#000000>test</FONT></BODY></HTML>'
$Output = StringReplace(StringTrimLeft($Input,StringInStr($Input,">",1,3)),"</FONT></BODY></HTML>","")

to 2.

What do you mean?

You could write an Ini-File saving the User but I haven't worked with this yet, so I can't say where the User is saved.

#

Link to comment
Share on other sites

Thanks for the first solution, I didn't even think of that.

to 2.

What do you mean?

You could write an Ini-File saving the User but I haven't worked with this yet, so I can't say where the User is saved.

#

When I log the users it just gives me the message, and I'm unable to find out who sent it to me.

Link to comment
Share on other sites

You're using the _TocParseIM() function, right? The first index of the array that returns is the username of the person who sent it.... Am I misunderstanding the question?

My Code:- _TocLib - UDF for TOC protocol (The simplified one used by 3rd party AIM/ICQ clients)

Link to comment
Share on other sites

Well, even without suggestions I finally figured out the proper format for those numbers in the FLAP header. As far as I know, everything works perfectly :shocked: I removed the old file and uploaded the updated one. See first post.

Development on my AIM client can now continue. Stay tuned :(

Any more questions/comments? I'm surprised more people aren't interested... you can use this and AIM's cell-phone communication abilities to do some interesting things. I also have a program I made to take advantage of that which I'm updating to use this new udf...

My Code:- _TocLib - UDF for TOC protocol (The simplified one used by 3rd party AIM/ICQ clients)

Link to comment
Share on other sites

Hello !

Any more questions/comments? I'm surprised more people aren't interested...

We need time to think about all the tremendous new abilities your UDF will provide.

And it's been nice to make an UDF, truely the best way to share this awesome function.

Just a question. Can an ID be shared by more than one script at a time ?

I have a grid computing project that may come back faster than expected.

Apzo.

Link to comment
Share on other sites

Can an ID be shared by more than one script at a time ?

What do you mean by ID? Do you mean can more than one script use the same AIM functionality? If so, then at the moment the answer is no. I haven't figured out a way to open a previously open tcp connection from a separate program, but I haven't really looked into it much. If someone else has an idea, I'd be thrilled :shocked:

My Code:- _TocLib - UDF for TOC protocol (The simplified one used by 3rd party AIM/ICQ clients)

Link to comment
Share on other sites

What do you mean by ID? Do you mean can more than one script use the same AIM functionality? If so, then at the moment the answer is no. I haven't figured out a way to open a previously open tcp connection from a separate program, but I haven't really looked into it much. If someone else has an idea, I'd be thrilled :shocked:

if you are looking into loggin into the same AIM with two scripts, yea, you can do that.

same port? doubtful

Link to comment
Share on other sites

Another brief but important update. Sending IMs with quotes in them broke previously, but they work now :shocked: If there are other characters that need to be caught, let me know

EDIT: I went ahead and took into account a few other characters, just in case. The [] characters were causing problems, so I'm guessing that <> and a few others will too... Again, if you see more, let me know

Edited by Falcone88

My Code:- _TocLib - UDF for TOC protocol (The simplified one used by 3rd party AIM/ICQ clients)

Link to comment
Share on other sites

I have made a small example client with this library:

CODE
#include <GUIConstants.au3>
#include <GUIEdit.au3>
#include <TOC.au3>
#include <Misc.au3>

Global $myUser = ""
Global $myPass = ""
Global $targetUser = ""

Global $doQuit = false

$login = _TocLogin( $myUser, $myPass)
if not $login Then
    if @error == $TOC_ERROR Then
        _DebugPrint( "TOC Error: code " & $login )
    Else
        _DebugPrint( "_TocLogin @error = " & @error )
    EndIf
Else
    _DebugPrint( "Logged in successfully" )
EndIf

_TocRegisterFunc( $TOC_CMD_IMRECV, "HandleRecv" )
_TocInitLoop()

;~ _TocSendIM($targetUser, "This is a test")
;~ _TocSendIM($targetUser, "haha auto response", true)

$GUI = GUICreate("AIM TOC", 299, 353)
$Input = GUICtrlCreateInput("", 0, 306, 299, 21)
$History = GUICtrlCreateEdit("", 0, 0, 299, 305, BitOR($WS_VSCROLL, $ES_READONLY, $ES_AUTOVSCROLL))
$Button = GUICtrlCreateButton ("Send", 5, 330, 289, Default, $BS_DEFPUSHBUTTON)
GUISetState(@SW_SHOW)

Do
    $guimsg = GUIGetMsg ()
    Switch $guimsg
        Case $Button
            If GUICtrlRead ($Input) <> "" Then
                _TocSendIM ($targetUser, GUICtrlRead($Input))
                GUICtrlSetData ($History, GUICtrlRead($History)&@CRLF&"You: "&GUICtrlRead($Input)&@CRLF)
                _GUICtrlEditLineScroll ($History, 0, _GUICtrlEditGetLineCount($History))
                
                GUICtrlSetData ($Input, "")
            EndIf
        Case $GUI_EVENT_CLOSE
            $doQuit = True
    EndSwitch
Until $doQuit

Func HandleRecv($packet)
    _DebugPrint("Recieved message: " & $packet)
    $msg = _TocParseIm( $packet )
   
;~     MsgBox(0,"_TocLib Test", "("&$msg[0]&") said: " & $msg[3], 2)

;~  _ArrayDisplay ($msg, "message")
   
;~     if StringInStr($msg[3], "goodbye") Then $doQuit = true
    $from = $msg[0]
    $message = _StringStripHtml ($msg[3])
;~  MsgBox (0, "", $msg[3])
;~  MsgBox (0, "", $message)
    GUICtrlSetData ($History, GUICtrlRead($History)&@CRLF&$from&": "&$message&@CRLF)
    _GUICtrlEditLineScroll ($History, 0, _GUICtrlEditGetLineCount($History))
    
EndFunc

Func _StringStripHtml ($s)
    Return StringRegExpReplace ($s, "<[^<>]+>", "")
EndFunc

Func _StringNum($sStr1, $sStr2)
    For $i = 1 to StringLen($sStr1)
        If not StringInStr($sStr1, $sStr2, 1, $i) Then ExitLoop
    Next
    Return $i
EndFunc
Edited by theguy0000

The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Link to comment
Share on other sites

Uploaded version 2.2.0.0 with a few more changes:

_TocNormalizeString was renamed to _TocNormalizeName. _TocNormalizeString is a new function that properly parses any strings. So, you can now use HTML properly!

I think there were a few minor fixes, but I forget now....

My AIM client is close to being done, but there's a weird bug where its CPU usage goes ridiculous after a while, and I'm working on fixing that.... I may post it and ask for help, though. We'll see!

Edited by Falcone88

My Code:- _TocLib - UDF for TOC protocol (The simplified one used by 3rd party AIM/ICQ clients)

Link to comment
Share on other sites

  • 1 month later...

Okay, so apparently TOC doesn't support the +(phonenumber) format of SNs, so you can't use this to text your cell, like I thought you could. It still works for receiving... but whatever.

In other news, my AIM client has a huge memory leak somewhere (If you leave it alone for half a day it starts using 100% of the CPU...) so that project is on hold. I've narrowed it down to the buddy update handling function, but I'm too lazy to find exactly what at the moment. I was surprised to find that the GUI update functions weren't the cause... Maybe the arrays....

Anyway, I'm more interested in cell phone interaction, so I've started to (very slowly) implement the Oscar protocol, which I know for a fact works with cell phones. It's going fairly well so far... I can connect to the auth server and retrieve BOS login info... Now I've slowed down at the extremely excessive protocol negotiation, partly due to SNAC packets, I think. Also, my laziness in hardcoding the _BinaryNumberDecode function is coming back to haunt me.... It shouldn't be too hard of a fix, I'm just too tired to really think atm :rolleyes:

So wish me luck with Oscar! If/when I ever get it done, I'll hopefully make a config for my myCommands script and release what will be v5.

Maybe someday I'll try to fix the leak in my AIM client....

My Code:- _TocLib - UDF for TOC protocol (The simplified one used by 3rd party AIM/ICQ clients)

Link to comment
Share on other sites

Just a quick update on _OscarLib:

I've finally fixed _BinaryNumberDecode! When I get back from Europe I'll update _TocLib with it. _BinaryNumber probably needs fixing, but that's another thinking thing.

Anyway, got to the next step in signon for Oscar, thanks to that fix. Should be relatively easy to get the rest working... it'll just take a while. There are 14+ steps for protocol management in Oscar! Jeez!

My Code:- _TocLib - UDF for TOC protocol (The simplified one used by 3rd party AIM/ICQ clients)

Link to comment
Share on other sites

  • 3 weeks later...

Updated to use the new Binary functions and such. That was a pain!

Got logging in with Oscar to work! now just have to figure out why I can't send IMs....

See first post for updated _TocLib.au3

My Code:- _TocLib - UDF for TOC protocol (The simplified one used by 3rd party AIM/ICQ clients)

Link to comment
Share on other sites

  • 2 weeks later...

Updated to use the new Binary functions and such. That was a pain!

Got logging in with Oscar to work! now just have to figure out why I can't send IMs....

See first post for updated _TocLib.au3

getting im's to cell phones (ie, sms) would be wonderful!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...