Question

PHP AOL Instant Messenger (AIM) bot

Asked by: dirtywerm

I'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.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2003-01-09 at 20:34:23ID20450773
Tags

aim

,

toc

,

werm

Topic

PHP Scripting Language

Participating Experts
9
Points
100
Comments
15

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

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.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

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.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

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.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Flash Instant Messenger?
    Hello Everyone, Could someone please provide a link to a tutorial on creating an Instant Messenger with Flash. Or, if someone has a fla they would be willing to share for free that would be even better! Thanks, --SL
  2. How to: intranet instant messenging server and clients
    How do I setup an internal Instant Messenging server for our intranet? Can I use MSN Messenger free in this enviroment? and does it need Exchange server or somethign to run it? Should I use a different instant messenger, I'm not concerned about security as it will only be o...
  3. VBA / Instant Messenger
    Hi, Does anyone know of a way to send messages on Instant Messenger using vba in Excel. I do not need to receive any messages, I just need to send an alert to a user every once in a while. Thanks in Advance, mit
  4. Messenger
    My boss asked me today if there is any kind of messenger out there that we could use at work just for the people on the network. I was going to suggest msn messenger but she doesnt want it to be on the internet. Most of them you have to make an email address for and sign up a...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

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.

Join the Community

Answers

 

by: dirtywermPosted on 2003-01-09 at 20:35:34ID: 7699385

<?
define("MAX_PACKLENGTH",65535);
define("SFLAP_TYPE_SIGNON",1);
define("SFLAP_TYPE_DATA",2);
define("SFLAP_TYPE_ERROR",3);
define("SFLAP_TYPE_SIGNOFF",4);
define("SFLAP_TYPE_KEEPALIVE",5);
define("SFLAP_MAX_LENGTH",1024);
define("SFLAP_SUCCESS",0);
define("SFLAP_ERR_UNKNOWN",1);
define("SFLAP_ERR_ARGS",2);
define("SFLAP_ERR_LENGTH",3);
define("SFLAP_ERR_READ",4);
define("SFLAP_ERR_SEND",5);
define("SFLAP_FLAP_VERSION",1);
define("SFLAP_TLV_TAG",1);
define("SFLAP_HEADER_LEN",6);


$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/nsequenceNumber/ndataLength", $header);

      $packet = fread($socket, $headerArray['dataLength']);

      if($headerArray['frameType'] == SFLAP_TYPE_SIGNON)
            $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($screenName), 1, 1, strlen($screenName), $screenName);

      $result = sendFlap(SFLAP_TYPE_SIGNON, $data);

      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:]]+","",strtolower($screenName));
}

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'], 0, 6) == "ERROR:")
      {
            $where = strpos( $result['data'], ":");
            die($ERROR_MSGS[chop(substr($result['data'], $where+1))] . "<br>\n");
      }

      $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();

?>

 

by: VGRPosted on 2003-01-09 at 23:53:24ID: 7700133

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

 

by: dirtywermPosted on 2003-01-10 at 01:27:41ID: 7700482

I've gone a lot off of the program MIA a C++ aol instant messanger.  I think I do everything that they do.  But MIA can send messages.  So there has got to be something i'm missing.

 

by: dirtywermPosted on 2003-01-10 at 08:52:13ID: 7702820

i've also asked this question

http://www.experts-exchange.com/Programming/Q_20450778.html

if you can help me I will give you credit for both questions.

 

by: rbmattPosted on 2003-07-04 at 11:12:22ID: 8857906

I've looked this code up and down.. I don't know what's wrong.
The only possible thing I see is that the toc_init_done should be null terminated, but it doesnt look to be. I tried doing that, but it didnt work.

Let me know if you figure it out.

 

by: EzranRC5Posted on 2003-08-24 at 15:35:45ID: 9213228

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.

 

by: 01xPosted on 2003-09-25 at 15:27:01ID: 9432140

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;
}

 

by: Peppe316Posted on 2003-10-19 at 00:02:51ID: 9578365

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['data']))
      {
            $nick = explode(':',$result['data']);
            $nick = normalize($nick[1]);
            if(ereg('quit', $result['data']) && $nick = 'YOUR NICKNAME')
            {
                  sendFlap(SFLAP_TYPE_DATA,'toc_send_im ' . $nick . 'Good bye');
                  //couldn't get toc_signoff to do anything so I closed the socket
                  fclose($socket);
                  exit;
            }
            if(ereg('hello',$result['data']))
            {
                  $nick = explode(':',$result['data']);
                  $nick = normalize($nick[1]);
                  sendFlap(SFLAP_TYPE_DATA,'toc_send_im ' . $nick . ' "Hello!"');
            }
            else
            {
                  $nick = explode(':',$result['data']);
                  $nick = normalize($nick[1]);
                  sendFlap(SFLAP_TYPE_DATA,'toc_send_im ' . $nick . ' "I don\'t understand you!"');
            }
      }
}

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.

 

by: MasterStanF2kPosted on 2004-02-16 at 18:31:23ID: 10378387

any final version of this script?

 

by: codecraigPosted on 2004-02-21 at 23:01:42ID: 10424290

doesnt look like it

 

by: MasterStanF2kPosted on 2004-02-22 at 07:12:54ID: 10425650

:(

 

by: mattjp88Posted on 2004-08-04 at 13:01:16ID: 11720176

Peppe316,
I am trying to make a bot and I tried the asker's code with your code added on at the end.  It doesn't work.  The username never signs on.  Could you post your working code?

Thanks,
Matt

 

by: qwertqPosted on 2005-03-14 at 14:41:36ID: 13539878

was anyone able to get a working version of this?

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...