beautiful code ;-)
if it is logging in successfully, why wouldn't it be shown as "logged in" ? ;-)
it is apparently not a FW issue concerning ports
I don't know. It's more a AOL IM problem I guess
Main Topics
Browse All TopicsI'm working on making a AOL Instant Messenger bot in PHP using TOC. I can get it to log in and everything, but it never shows up as being online and I can't send any messages. If anyone can help me with this I would really appreciate it. I'll post the code below in a comment. I can give out more points if this is difficult to fix.
Thanks
WERM
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
i've also asked this question
http://www.experts-exchang
if you can help me I will give you credit for both questions.
I was wanting to write a PHP client for the same thing... I stumbled across this and thought it would be a good start for working on mine -- but I figured I'd just write almost everything from scratch to avoid whatever bug was causing you problems.
My code is completely different, as it's object oriented, but I was having the same trouble.
I found out that the TOC servers don't seem to acknowledge your existence unless you send permit/deny or add_buddy type command before the toc_init_done. For whatever reason, I don't know. So I just started making it always do a toc_add_buddy before the toc_init_done, and it always adds itself to it's own list.
Now it has no trouble signing on.
Maybe 7 months late, but at least it's an answer.
The toc_add_buddy deal isn't your problem at all. You aren't properly terminating all your strings, fix it by adding a check in sendFlap
function sendFlap($frameType, $data)
{
global $socket, $clientSequenceNumber;
if( strlen($data) > SFLAP_MAX_LENGTH)
{
$data = substr($data, 0, (SFLAP_MAX_LENGTH-2) );
$data .= '"';
}
+ $data = rtrim($data);
+ $data .= "\0";
$header = pack("aCnn", '*', $frameType, $clientSequenceNumber, strlen($data));
$packet = $header . $data;
if(fwrite($socket, $packet) == FALSE)
die("Unable to send the packet.<BR>\n");
$clientSequenceNumber++;
return $packet;
}
I've started playing around with your code. The reason it doesn't show up online or allow you to send messages is becuase after logging in php is finished with the code and closes closes the socket(s).
A very quick 'n dirty hack is to add the following to the end of the code.
$x=false;
while($x==false)
{
sleep(3); // this is just to pause the reading for 3 secs...can be less
$result = readFlap(); //grab the data
if(ereg('^IM_IN',$result['
{
$nick = explode(':',$result['data'
$nick = normalize($nick[1]);
if(ereg('quit', $result['data']) && $nick = 'YOUR NICKNAME')
{
sendFlap(SFLAP_TYPE_DATA,'
//couldn't get toc_signoff to do anything so I closed the socket
fclose($socket);
exit;
}
if(ereg('hello',$result['d
{
$nick = explode(':',$result['data'
$nick = normalize($nick[1]);
sendFlap(SFLAP_TYPE_DATA,'
}
else
{
$nick = explode(':',$result['data'
$nick = normalize($nick[1]);
sendFlap(SFLAP_TYPE_DATA,'
}
}
}
Now when you start the bot and say "hello" it will say "Hello!", if you say "quit" it will say "Good Bye" and quit. If you say anything else it will tell you it doesn't understand. I guess you could add a check to see if you are still connected (set $x=false) but I figured if you get disconnected or something the script will terminate anyway (atleast when used as CLI)
Hope this helps.
Business Accounts
Answer for Membership
by: dirtywermPosted on 2003-01-09 at 20:35:34ID: 7699385
<? 535); ,1); ); 3); ",4); VE",5); 1024); ,1); ; 3); ; ; ",1); 6);
quenceNumb er/ndataLe ngth", $header);
);
'] == SFLAP_TYPE_SIGNON)
Name), 1, 1, strlen($screenName), $screenName);
, $data);
+","",strt olower($sc reenName)) ;
)
0, 6) == "ERROR:") r($result[ 'data'], $where+1))] . "<br>\n");
define("MAX_PACKLENGTH",65
define("SFLAP_TYPE_SIGNON"
define("SFLAP_TYPE_DATA",2
define("SFLAP_TYPE_ERROR",
define("SFLAP_TYPE_SIGNOFF
define("SFLAP_TYPE_KEEPALI
define("SFLAP_MAX_LENGTH",
define("SFLAP_SUCCESS",0);
define("SFLAP_ERR_UNKNOWN"
define("SFLAP_ERR_ARGS",2)
define("SFLAP_ERR_LENGTH",
define("SFLAP_ERR_READ",4)
define("SFLAP_ERR_SEND",5)
define("SFLAP_FLAP_VERSION
define("SFLAP_TLV_TAG",1);
define("SFLAP_HEADER_LEN",
$ERROR_MSGS = array ( 0 => 'Success',
1 => 'AOLIM Error: Unknown Error',
2 => 'AOLIM Error: Incorrect Arguments',
3 => 'AOLIM Error: Exceeded Max Packet Length (1024)',
4 => 'AOLIM Error: Reading from server',
5 => 'AOLIM Error: Sending to server',
6 => 'AOLIM Error: Login timeout',
901 => 'General Error: $ERR_ARG not currently available',
902 => 'General Error: Warning of $ERR_ARG not currently available',
903 => 'General Error: A message has been dropped, you are exceeding the server speed limit',
950 => 'Chat Error: Chat in $ERR_ARG is unavailable',
960 => 'IM and Info Error: You are sending messages too fast to $ERR_ARG',
961 => 'IM and Info Error: You missed an IM from $ERR_ARG because it was too big',
962 => 'IM and Info Error: You missed an IM from $ERR_ARG because it was sent too fast',
970 => 'Dir Error: Failure',
971 => 'Dir Error: Too many matches',
972 => 'Dir Error: Need more qualifiers',
973 => 'Dir Error: Dir service temporarily unavailble',
974 => 'Dir Error: Email lookup restricted',
975 => 'Dir Error: Keyword ignored',
976 => 'Dir Error: No keywords',
977 => 'Dir Error: Language not supported',
978 => 'Dir Error: Country not supported',
979 => 'Dir Error: Failure unknown $ERR_ARG',
980 => 'Auth Error: Incorrect nickname or password',
981 => 'Auth Error: The service is temporarily unavailable',
982 => 'Auth Error: Your warning level is too high to sign on',
983 => 'Auth Error: You have been connecting and disconnecting too frequently. Wait 10 minutes and try again. If you continue to try, you will need to wait even longer.',
989 => 'Auth Error: An unknown signon error has occurred $ERR_ARG' );
$socket = null;
$clientSequenceNumber = 0;
$screenName="screenName";
$password = "password";
$tocHost = "toc.oscar.aol.com";
$tocPort = 5190;
$authHost = "login.oscar.aol.com";
$authPort = 5159;
function RoastPassword($password)
{
$roastString = 'Tic/Toc';
$roastedPassword = '0x';
for ($i = 0; $i < strlen($password); $i++)
$roastedPassword .= bin2hex($password[$i] ^ $roastString[($i % 7)]);
return $roastedPassword;
}
function readFlap()
{
global $socket;
$header = fread($socket, SFLAP_HEADER_LEN);
if(strlen($header) < SFLAP_HEADER_LEN)
return(0);
$headerArray = unpack ("aasterisk/CframeType/nse
$packet = fread($socket, $headerArray['dataLength']
if($headerArray['frameType
$packetArray = unpack("Ndata", $packet);
else
$packetArray = unpack("a*data", $packet);
$data = array_merge($headerArray, $packetArray);
return $data;
}
function sendRaw($data)
{
global $socket;
if(fwrite($socket, $data) == FALSE)
return 0;
return 1;
}
function sendFlap($frameType, $data)
{
global $socket, $clientSequenceNumber;
if( strlen($data) > SFLAP_MAX_LENGTH)
{
$data = substr($data, 0, (SFLAP_MAX_LENGTH-2) );
$data .= '"';
}
$header = pack("aCnn", '*', $frameType, $clientSequenceNumber, strlen($data));
$packet = $header . $data;
if(fwrite($socket, $packet) == FALSE)
die("Unable to send the packet.<BR>\n");
$clientSequenceNumber++;
return $packet;
}
function sendTocFlapSignon()
{
global $screenName;
$data = pack("Nnna".strlen($screen
$result = sendFlap(SFLAP_TYPE_SIGNON
return $result;
}
function tocSignon()
{
global $screenName, $password;
global $authHost, $authPort;
$roastedPassword = RoastPassword($password);
$tocSignon = 'toc_signon ' . $authHost . ' ' . $authPort . ' ' . $screenName . ' ' . $roastedPassword . ' "english" "AOLIM:\$Version 1.1\$"';
$tocSignon .= "\0";
$result = sendFlap(SFLAP_TYPE_DATA, $tocSignon);
return $result;
}
function normalize($screenName)
{
return eregi_replace("[[:space:]]
}
function signOn()
{
global $screenName, $roastedPassword, $socket, $clientSequenceNumber, $ERROR_MSGS;
global $tocHost, $tocPort;
echo "Signing on using $screenName<BR>\n";
if( !($socket = fsockopen($tocHost, $tocPort, $errorno, $errorstr, 30)) )
die("$errorstr ($errorno)");
echo "Connected to the sever<BR>\n";
if( !sendRaw("FLAPON\r\n\r\n")
die("Error sending the FLAPON packet.");
echo "FLAPON packet sent<BR>\n";
if( !( $result = readFlap() ) )
die("No response from server.<BR>\n");
if($result['asterisk'] != '*' && $result['frameType'] != 1 && $result['dataLength'] != 4 && $result['data'] != 1)
die("Invalid FLAP SIGNON response from the server.<BR>\n");
sendTocFlapSignon();
echo "SIGN_ON packet sent<BR>\n";
tocSignon();
echo "toc_signon packet sent<BR>\nWaiting for reply...<BR>\n";
$result = readFlap();
if($result['asterisk'] != '*' && $result['frameType'] != 2 )
die("Invalid response from server.<BR>\n");
if($result['data'] == "SIGN_ON:TOC1.0")
echo "toc_signon success SIGN_ON <br>";
else if(substr($result['data'],
{
$where = strpos( $result['data'], ":");
die($ERROR_MSGS[chop(subst
}
$result = readFlap(); // NICK
echo $result['data'] . "<BR>\n";
$result = readFlap(); // NICK
echo $result['data'] . "<BR>\n";
$result = readFlap(); // Buddies
echo $result['data'] . "<BR>\n";
sendFlap(SFLAP_TYPE_DATA, "toc_add_permit");
sendFlap(SFLAP_TYPE_DATA, "toc_add_deny");
$tocAddBuddy = "toc_add_buddy " . $screenName;
sendFlap(SFLAP_TYPE_DATA, $tocAddBuddy);
sendFlap(SFLAP_TYPE_DATA, "toc_init_done");
echo "sent toc_init_done<BR>\n";
/*
$done = 0;
while(!$done)
{
$result = readFlap();
if($result)
{
echo $result['asterisk'] . " - ";
echo $result['frameType'] . " - ";
echo $result['sequenceNumber'] . " - ";
echo $result['dataLength'] . "\n";
}
}
*/
}
signOn();
?>