Share Pastebin
Guest
Public paste!

opb0t

By: a guest | Mar 18th, 2010 | Syntax: C++ | Size: 0.97 KB | Hits: 89 | Expires: Never
Copy text to clipboard
  1. /* opb0t */
  2.  
  3. #include "Socket.h"
  4. #include "SocketError.h"
  5. #include <iostream>
  6. #include <string>
  7.  
  8. using namespace std;
  9.  
  10. const string server = "irc.tddirc.net";
  11. const string port = "6667";
  12.  
  13. int main ()
  14. {
  15.   try
  16.   {
  17.     Socket sock(server,port);
  18.     if ( !sock.get_address() ) throw SocketException ( "Could not find irc server." );
  19.     if ( !sock.connect() ) throw SocketException ( "Could not connect to irc server." );
  20.  
  21.     string reply;
  22.  
  23.     sock >> reply;
  24.     sock >> reply;
  25.     sock << "USER test test test test :test\r\n";
  26.     sock << "NICK opb0t\r\n";
  27.     sock << "JOIN  #hackerthreads\r\n";
  28.     sock >> reply;
  29.  
  30.     string::size_type loc = reply.find( "PING :", 0 );
  31.     if( loc != string::npos ){
  32.       string pong = "PONG :" + reply.substr(6,-1);
  33.       sock << pong;
  34.       }
  35.  
  36.     while (true){
  37.       sock >> reply;
  38.     }    
  39.   }
  40.   catch ( SocketException& e )
  41.   {
  42.     cout << "Exception was caught:" << e.description() << "\n";
  43.   }
  44.   return 0;
  45. }