[[[file]]][[[name]]]installer[[[read]]] $v ) {
if( stristr($v,'curl')!="" )
$got_curl = true;
if( stristr($v,'bz2')!="" )
$got_bz2 = true;
}
if( $win_env ) {
// check for dlls on path
$paths = explode( ";", getenv("path") );
foreach( $paths as $pathx ) {
$filepath = trim($pathx);
if( $filepath[strlen($filepath)-1]!="/" )
$filepath .= "/";
$filename = $filepath."libeay32.dll";
if( file_exists($filename) )
$got_eay = true;
$filename = $filepath."ssleay32.dll";
if( file_exists($filename) )
$got_ssl = true;
}
$koi_site = "http://www.hot.ee/bond4u/ao/";
if( !$got_eay && !file_exists('libeay32.dll') ) {
$text = "Trying to get 'libeay32.dll' from Koi's site...";
echo( $text."\n" );
send( $admin, $text, "", "tell" );
$curly = fileget($koi_site."libeay32.bz2");
if( $curly ) {
$f = fopen("libeay32.dll","wb+");
$curly = bzdecompress($curly);
$ff = fwrite($f,$curly);
fclose($f);
}
}
if( !$got_ssl && !file_exists('ssleay32.dll') ) {
$text = "Trying to get 'ssleay32.dll' from Koi's site...";
echo( $text."\n" );
send( $admin, $text, "", "tell" );
$curly = fileget($koi_site."ssleay32.bz2");
if( $curly ) {
$f = fopen("ssleay32.dll","wb+");
$curly = bzdecompress($curly);
$ff = fwrite($f,$curly);
fclose($f);
}
}
if( !$got_curl && !file_exists('php_curl.dll') ) {
$text = "Trying to get 'php_curl.dll' from Koi's site...";
echo( $text."\n" );
send( $admin, $text, "", "tell" );
$curly = fileget($koi_site."php_curl.bz2");
if( $curly ) {
$f = fopen("php_curl.dll","wb+");
$curly = bzdecompress($curly);
$ff = fwrite($f,$curly);
fclose($f);
}
}
if( !$got_curl && file_exists('php_curl.dll') ) {
if( !dl('php_curl.dll') ) {
$text = "Unable to load CURL extension.";
echo( $text."\n" );
send( $admin, $text, "", "tell" );
} else
$got_curl = true; // loaded ok
}
}
if( $got_curl ) {
// rename existing files, add "datetime" to filename
$ext = ".".date( "YmdHis");
if( !function_exists('retire') ) {
function retire( $fn, $fe ) {
if( file_exists($fn) ) {
rename($fn,$fn.$fe);
return array( $fn, $fn.$fe );
}
return false;
}
}
$mods = array();
$rval = retire( 'pluginmain/loop.php', $ext );
if( is_array($rval) )
$mods[] = $rval;
$rval = retire( 'pluginmain/functions.php', $ext );
if( is_array($rval) )
$mods[] = $rval;
retire( 'pluginmain/aim.class.php', $ext );
retire( 'pluginmain/msn.class.php', $ext );
if( $win_env ) {
$content = file('php.ini');
$load_curl = false;
foreach( $content as $v ) {
if( stristr( $v, "php_curl.dll" ) != "" )
$load_curl = true;
}
if( $load_curl == false ) {
$rval = retire( 'php.ini', $ext );
if( is_array($rval ) )
$mods[] = $rval;
$content[] = "extension=php_curl.dll";
$f = fopen('php.ini',"w+");
$ff = fwrite($f,implode("\r\n",$content));
fclose($f);
}
}
// move pluginmain files
rename( 'plugins/aim.class.php', 'pluginmain/aim.class.php' );
rename( 'plugins/msn.class.php', 'pluginmain/msn.class.php' );
rename( 'plugins/functions.php', 'pluginmain/functions.php' );
rename( 'plugins/loop.php', 'pluginmain/loop.php' );
// turn pluginloop on
if( !file_exists( 'pluginloop' ) ) {
$f = fopen( 'pluginloop', "w+" );
fwrite($f,"loop");
fclose($f);
$text = "Pluginloop is ON now";
echo( $text."\n" );
send( $admin, $text, "", "tell" );
}
// message about old files
if( count($mods)>0 ) {
$text = "";
foreach( $mods as $v ) {
if( $text!="" )
$text .= ", ";
$text .= $v[0]." -> ".$v[1];
}
$text = "Some files were renamed: ".$text;
echo( $text."\n" );
send( $admin, $text, "", "tell" );
}
// done
sleep(1);
$text = dynamic("AIM & MSN plugins installed: do ".
"'/tell (bot) (syntax)aim setup' and/or ".
"'/tell (bot) (syntax)msn setup'");
echo( $text."\n" );
send( $admin, $text, "", "tell" );
$text = "Restart is required";
echo( $text."\n" );
send( $admin, $text, "", "tell" );
} else {
$text = "Installation not completed, no CURL";
if( $win_env == false ) {
$text .= "\nSorry, no precompiled binaries for non-windows environment";
}
echo( $text."\n" );
send( $admin, $text, "", "tell" );
}
?>[[[file]]][[[name]]]aim.class.php[[[read]]]'Success',
901 =>"\$errarg not currently available.",
902 =>"Warning of \$errarg not currently available.",
903 =>'A message has been dropped, you are exceeding the server speed limit.',
911 =>'Error validating input',
912 =>'Invalid account',
913 =>'Error encountered while processing request',
914 =>'Service unavailable',
950 =>"Chat in \$errarg is unavailable.",
960 =>"You are sending message too fast to \$errarg.",
961 =>"You missed an im from \$errarg because it was too big.",
962 =>"You missed an im from \$errarg because it was sent too fast.",
970 =>'Failure',
971 =>'Too many matches',
972 =>'Need more qualifiers',
973 =>'Dir service temporarily unavailable',
974 =>'Email lookup restricted',
975 =>'Keyword Ignored',
976 =>'No Keywords',
977 =>'Language not supported',
978 =>'Country not supported',
979 =>"Failure unknown \$errarg.",
980 =>'Incorrect nickname or password.',
981 =>'The service is temporarily unavailable.',
982 =>'Your warning level is currently too high to sign on.',
983 =>'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 =>"An unknown signon error has occurred \$errarg."
);
var $cfg_file = "aim.config";
var $msgs_out = array();
//Constructor
function Aim() { //, $silent=false)
//Constructor assignment
$this->screenname=""; //$this->normalize($sn);
$this->password=""; //$password;
$this->myRoastedPass=""; //$this->roast_pass($password);
$this->mySeqNum=1;
$this->myConnection=0;
$this->myWarnLevel=0;
$this->myAuthCode=$this->make_code();
$this->buddymode=4; //$pdmode;
// if($this->debug){
// error_reporting(E_ALL);
// } //else
//error_reporting(E_ALL);
$this->load();
$this->sEcho("PHPTOCLIB v0.4 Object Created");
}
function load() {
$contents = @file( $this->cfg_file );
if( $contents != "" ) {
$this->screenname = $contents[2];
$this->password = $contents[3];
$this->displayname = $contents[4];
$contents = explode( '"', $this->screenname );
$this->screenname = $contents[1];
$contents = explode( '"', $this->password );
$this->password = $contents[1];
$contents = explode( '"', $this->displayname );
$this->displayname = $contents[1];
}
}
function store() {
$contents = "\r\n";
$contents .= "\r\n";
$contents .= '$screenname = "'.$this->screenname."\";\r\n";
$contents .= '$password = "'.$this->password."\";\r\n";
$contents .= '$displayname = "'.$this->displayname."\";\r\n";
$contents .= "\r\n";
$contents .= "";
$rval = fopen( $this->cfg_file, "w+" );
$cnt = fwrite( $rval, $contents );
$cnt = fclose( $rval );
}
function roast_pass($password) {
$roaststring = 'Tic/Toc';
$roasted_password = '0x';
for ($i = 0; $i < strlen($password); $i++)
$roasted_password .= bin2hex($password[$i] ^ $roaststring[($i % 7)]);
return $roasted_password;
}
function make_code() {
$sn=base_convert(bin2hex($this->screenname[0]),16,10) - 96;
$pw=base_convert(bin2hex($this->password[0]),16,10) - 96;
$a= $sn * 7696 + 738816;
$b= $sn * 746512;
$c= $pw * $a;
return $c-$a+$b+71665152;
}
//Public function designed to set the sql information
/* function sql_connect($host,$username,$password,$database) {
@$this->mySQLHandle=mysql_connect($host,$username,$password) or die("Could not connect to the database. The host may not exist, or the supplied username and password were incorrect");
@mysql_select_db($database) or die("Error selecting database. It is possible it does not exist, or you may bot have permission to access it");
$this->sql_user=$username;
$this->sql_pass=$password;
$this->sql_server=$host;
$this->sql_db=$database;
$this->sEcho("Connected to MySQL Database: " . $this->sql_db . " by " . $this->sql_user . "@" . $this->sql_server);
}
*/
function _put( $data ) {
fwrite( $this->myConnection, $data );
if( $this->debug )
$this->sEcho( "<<< $data" );
return true;
}
function _get() {
if( $data = @fgets( $this->myConnection, 4096 ) ) {
if( $this->debug )
$this->sEcho( ">>> $data" );
return $data;
} else {
return false;
}
}
function sflap_read() {
if( !$this->sflap_read_in_progress ) {
$this->header = $this->header_data = "";
$this->packet = $this->packet_data = "";
$this->sflap_read_in_progress = true;
if( strlen($this->packet_next) > 0 ) {
$this->header = $this->packet_next; $this->packet_next = "";
}
}
$data = $this->_get();
if( strlen($this->header) < SFLAP_HEADER_LEN ) {
$this->header .= $data;
$data = "";
if( strlen($this->header) < SFLAP_HEADER_LEN ) {
$this->myLastReceived="";
return ""; // need more data
}
}
if( $this->header_data == "" ) {
$this->packet = substr($this->header,SFLAP_HEADER_LEN);
$this->header = substr($this->header,0,SFLAP_HEADER_LEN);
$this->header_data=unpack("aast/Ctype/nseq/ndlen", $this->header);
}
$this->packet .= $data;
if( strlen($this->packet) < $this->header_data['dlen'] ) {
if( strlen($this->packet) < $this->header_data['dlen'] ) {
$this->myLastReceived="";
return ""; // need more data
}
}
if( strlen($this->packet) >= $this->header_data['dlen'] ) {
// got part of next packet
$this->packet_next = substr($this->packet,$this->header_data['dlen']);
$this->packet = substr($this->packet,0,$this->header_data['dlen']);
}
if($this->header_data['type']==SFLAP_TYPE_SIGNON) {
$this->packet_data=unpack("Ndecoded",$this->packet);
} else if($this->header_data['type']==SFLAP_TYPE_KEEPALIVE) {
$this->myLastReceived='';
$this->sflap_read_in_progress = false;
return ""; // need to receive signon
} else if(strlen($this->packet)>0) {
$this->packet_data=unpack("a*decoded",$this->packet);
}
$data=array_merge($this->header_data,$this->packet_data);
$this->myLastReceived=$data;
$this->sflap_read_in_progress = false;
return $data;
}
function sflap_send($sflap_type,$sflap_data,$no_null,$formatted) {
$packet="";
if(strlen($sflap_data)>=MAX_PACKLENGTH)
$sflap_data=substr($sflap_data,0,MAX_PACKLENGTH);
if($formatted) {
$len=strlen($sflap_len);
$sflap_header=pack("aCnn",'*',$sflap_type,$this->mySeqNum,$len);
$packet=$sflap_header . $sflap_data;
} else {
if(!$no_null) {
$sflap_data=str_replace("\0","",$sflap_data);
$sflap_data.="\0";
}
$data=pack("a*",$sflap_data);
$len=strlen($sflap_data);
$header=pack("aCnn","*",$sflap_type,$this->mySeqNum,$len);
$packet=$header . $data;
}
$sent = $this->_put( $packet );
$this->mySeqNum++;
sleep(ceil($this->myWarnLevel/10));
}
//Escape the thing that TOC doesn't like,that would be
//",',$,{,},[,]
function encode_data($data) {
$data=str_replace('"','\"',$data);
$data=str_replace('$','\$',$data);
$data=str_replace("'","\'",$data);
$data=str_replace('{','\{',$data);
$data=str_replace('}','\}',$data);
$data=str_replace('[','\[',$data);
$data=str_replace(']','\]',$data);
return $data;
}
function decode($data) {
$data=str_replace('\"','"',$data);
$data=str_replace('\$','$',$data);
$data=str_replace("\'","'",$data);
$data=str_replace('\{','{',$data);
$data=str_replace('\}','}',$data);
$data=str_replace('\[','[',$data);
$data=str_replace('\]',']',$data);
$data=str_replace('"','"',$data);
$data=str_replace('&','&',$data);
return $data;
}
//"normalize" the nickname, that means no spaces and all lowercase
function normalize($nick) {
$nick=str_replace(" ","",$nick);
$nick=strtolower($nick);
return $nick;
}
function set_my_info() {
//Sets internal values bvase on the update buddy command
$this->sEcho("Setting my warning level ...");
$this->sflap_send(SFLAP_TYPE_DATA,"toc_get_status " . $this->normalize($this->screenname),0,0);
//The rest of this will now be handled by the other functions. It is assumed
//that we may have other data queued in the socket, do we should just add this
//message to the queue instead of trying to set it in here
}
function connect() {
if( $this->screenname == "" || $this->password == "" )
return false;
if( !$this->connected ) {
$this->myConnection=@fsockopen($this->myServer,$this->myPort,$errno,$errstr,2);
if( $this->debug )
$this->secho( "connected with error ".$errstr." (".$errno.")\n" );
if( !$this->myConnection ) {
$this->connected = false;
} else {
stream_set_timeout( $this->myConnection, 0, $this->usleep );
$this->connected = true;
}
}
}
function init() {
if( !$this->authed ) {
if( !$this->init1 ) {
$this->mySeqNum=(time() % 65536); //Select an arbitrary starting point for
//sequence numbers
//Send the flapon packet
$this->_put("FLAPON\r\n\n\0"); //send the initial handshake
$this->init1 = true;
} else if( !$this->init2 ) {
$this->sflap_read(); //Make sure the server responds with what we expect
if( $this->myLastReceived ) {
$this->init2 = true;
}
} else if( !$this->init3 ) {
//send the FLAP SIGNON packet back with what it needs
//There are 2 parts to the signon packet. They are sent in succession, there
//is no indication if either packet was correctly sent
$signon_packet=pack("Nnna".strlen($this->screenname),1,1,strlen($this->screenname),$this->screenname);
$this->sflap_send(SFLAP_TYPE_SIGNON,$signon_packet,1,0);
$this->myRoastedPass=$this->roast_pass($this->password);
$this->myAuthCode=$this->make_code();
$signon_packet_part2='toc2_signon login.oscar.aol.com 29999 ' . $this->screenname . ' ' . $this->myRoastedPass . ' english-US "TIC:TOC2:REVISION" 160 ' . $this->myAuthCode;
$this->sflap_send(SFLAP_TYPE_DATA,$signon_packet_part2,0,0);
$this->init3 = true;
} else if( !$this->init4 ) {
$this->sflap_read();
if( $this->myLastReceived ) {
// $this->sEcho("Received Sign on packet, beginning initilization...");
$message=$this->getLastReveived();
if(strstr($message,"ERROR:")) {
$this->onError($message);
// $this->secho("Fatal signon error");
} else {
$this->init4 = true;
}
}
} else {
//The information sent before the config2 command is utterly useless to us
//So we will just skim through them until we reach it
//UPDATED 4/12/03: Now this will use the receive function and send the
//received messaged to the assigned handlers. This is where the signon
//method has no more use
$this->authed = true;
}
}
}
function parse_buddy_change($message) {
//This will update buddy info when I get around to it
//TODO: SQL buddy storage
}
function send_im($to,$message,$auto=false) {
if($auto)
$auto="auto";
else
$auto="";
$to=$this->normalize($to);
$message=$this->encode_data($message);
$command='toc2_send_im "' . $to . '" "' . $message . '" ' . $auto;
$this->sflap_send(SFLAP_TYPE_DATA,$command,0,0);
$cleanedmessage = str_replace("
", " ", $this->decode($message));
$cleanedmessage = strip_tags($cleanedmessage);
// if( $this->debug )
// $this->sEcho("TO - " . $to . " : " . $cleanedmessage);
}
function get_buddy_list() {
//THis better be the right message
$message=$this->myLastReceived['decoded'];
if(strpos($message,"CONFIG2:")===false) {
if( $this->debug )
$this->sEcho("get_buddy_list cannot be called at this time");
return false;
}
$people=explode("\n",trim($message,"\n"));
//The first 3 elements of the array are who knows what, element 3 should be
//a letter followed by a person
for($i=1;$imyPermitList[]=$name;
break;
case 'd':
$this->myBlockedList[]=$name;
break;
case 'b':
$this->myBuddyList[]=$name;
break;
case 'done':
break;
default:
//
}
}
}
function add_permit($buddy) {
$this->sflap_send(SFLAP_TYPE_DATA,"toc2_add_permit " . $this->normalize($buddy),0,0);
$this->myPermitList[]=$this->normalize($buddy);
return 1;
}
function block_buddy($buddy) {
$this->sflap_send(SFLAP_TYPE_DATA,"toc2_add_deny " . $this->normalize($buddy),0,0);
$this->myBlockedList[]=$this->normalize($buddy);
return 1;
}
function getMessage() {
$in = $this->read_from_aim();
$cmd = $this->msg_type($in);
$in = $this->msg_parse($cmd);
$out = $in;
$out['type'] = $cmd['type'];
if($out['type'] == AIM_TYPE_WARN){
$this->setWarning($out['warnlevel']);
}
if($out['type'] == AIM_TYPE_MSG){
// if( $this->debug )
// $this->sEcho("" . $out['from'] . ": " . strip_tags($out['message']));
$out['cleanmessage'] = strip_tags($out['message']);
}
return $out;
}
function getLastReveived() {
if(@$instuff=$this->myLastReceived['decoded']){
return $this->myLastReceived['decoded'];
} else {
return;
}
}
function getBuddies() {
return $this->myBuddyList;
}
function getPermit() {
return $this->myPermitList;
}
function getBlocked() {
return $this->myBlockedList;
}
function read_from_aim() {
$this->sflap_read();
$returnme= $this->getLastReveived();
return $returnme;
}
function setWarning($warnlevel) {
$this->myWarnLevel=$warnlevel;
}
function warn_user($to,$anon=false) {
if(!$anon)
$anon='"norm"';
else
$anon='"anon"';
$this->sflap_send(SFLAP_TYPE_DATA,"toc_evil " . $this->normalize($to) . " $anon",0,0);
}
function update_profile($profiledata, $poweredby=false) {
if($poweredby==false){
$this->myProfile = $profiledata;
} else {
$this->myProfile = $profiledata . "
Powered by phpTOCLib
http://sourceforge.net/projects/phptoclib";
}
$this->sflap_send(SFLAP_TYPE_DATA,"toc_set_info \"" . $this->encode_data($this->myProfile) . "\"",0,0);
$this->set_my_info();
if( $this->debug )
$this->sEcho("Profile has been updated...");
}
//Added 4/29/04 by Jeremy:
//Various chat related methods
function join_chat($chatid) {
$this->sflap_send(SFLAP_TYPE_DATA,"toc_chat_accept " . $chatid,0,0);
}
function leave_chat($chatid) {
$this->sflap_send(SFLAP_TYPE_DATA,"toc_chat_leave " . $chatid,0,0);
}
function chat_say($chatid,$message) {
$this->sflap_send(SFLAP_TYPE_DATA,"toc_chat_send " . $chatid . " \"" . $this->encode_data($message) . "\"",0,0);
}
function chat_invite($chatid,$who,$message) {
$this->sflap_send(SFLAP_TYPE_DATA,"toc_chat_invite " . $chatid . " \"" . $this->encode_data($message) . "\" " . $who,0,0);
}
function join_new_chat($name,$exchange) {
//Creates a new chat
$this->sflap_send(SFLAP_TYPE_DATA,"toc_chat_join " . $exchange . " \"" . $name . "\"",0,0);
}
function recieve() {
//This function will be used to get the incoming data
//and it will be used to call the event handlers
//First step:Get the data sitting in the socket
$message=$this->read_from_aim();
if(strlen($message) <= 0) {
return;
}
//Second step: Get the command from the server
@list($cmd,$rest)=explode(":",$message);
//Third step, take the command, test the type, and pass it off
//to the correct internal handler. The internal handler will
//do what needs to be done on the class internals to allow
//it to work, then proceed to pass it off to the user created handle
//if there is one
switch($cmd) {
case 'SIGN_ON':
$this->onSignOn($message);
break;
case 'CONFIG2':
$this->onConfig($message);
break;
case 'ERROR':
$this->onError($message);
break;
case 'NICK':
$this->onNick($message);
break;
case 'IM_IN2':
// echo("Calling onImIn()");
$this->onImIn($message);
break;
case 'UPDATE_BUDDY2':
$this->onUpdateBuddy($message);
break;
case 'EVILED':
$this->onWarn($message);
break;
case 'CHAT_JOIN':
$this->onChatJoin($message);
break;
case 'CHAT_IN':
$this->onChatJoin($message);
break;
case 'CHAT_UPDATE_BUDDY':
$this->onChatUpdate($message);
break;
case 'CHAT_INVITE':
$this->onChatInvite($message);
break;
case 'CHAT_LEFT':
$this->onChatLeft($message);
break;
case 'GOTO_URL':
$this->onGotoURL($message);
break;
case 'DIR_STATUS':
$this->onDirStatus($message);
break;
case 'ADMIN_NICK_STATUS':
$this->onAdminNick($message);
break;
case 'ADMIN_PASSWD_STATUS':
$this->onAdminPasswd($message);
break;
case 'PAUSE':
$this->onPause($message);
break;
case 'RVOUS_PROPOSE':
$this->onRvous($message);
break;
default:
if( $this->debug )
$this->sEcho("Fell through :(");
$this->CatchAll($message);
break;
}
//Now get out of this function becuase the handlers should take care
//of everything
}
function send() {
if( count($this->msgs_out) > 0 ) {
foreach( $this->msgs_out as $msgk => $msg ) {
$this->send_im( $msg['person'], $msg['text'] );
break;
}
unset($this->msgs_out[$msgk]);
}
return true;
}
//The next block of code is all the event handlers needed by the class
//Some are left blank and only call the users handler because the class
//either does not support the command, or cannot do anything with it
function onSignOn($message) {
$this->signonrcv=true;
$function=$this->onSignOnf . "(\$message);";
eval($function);
}
function onConfig($message) {
if(strpos($message,"CONFIG2:")===false) {
$this->sEcho("get_buddy_list cannot be called at this time");
return false;
}
$people=explode("\n",trim($message,"\n"));
//The first 3 elements of the array are who knows what, element 3 should be
//a letter followed by a person
for($i=1;$imyPermitList[]=$name;
break;
case 'd':
$this->myBlockedList[]=$name;
break;
case 'b':
$this->myBuddyList[]=$name;
break;
case 'done':
break;
default:
}
}
//We only get the config message once, so now we should send our pd mode
$this->sflap_send(SFLAP_TYPE_DATA,"toc2_set_pdmode " . $this->buddymode,0,0);
//Adds yourself to the permit list
//This is to fix an odd behavior if you have nobody on your list
//the server won't send the config command... so this takes care of it
$this->sflap_send(SFLAP_TYPE_DATA,"toc2_add_permit " . $this->normalize($this->screenname),0,0);
//Now we allow the user to send a list, update anything they want, etc
$function=$this->onConfigf . "(\$message);";
eval($function);
//Now that we have taken care of what the user wants, send the init_done message
$this->sflap_send(SFLAP_TYPE_DATA,"toc_init_done",0,0);
}
function onError($message) {
// global $ERRORS;
@list($cmd,$errornum,$errarg)=explode(":",$message);
eval("\$errorstring=\"\$this->ERRORS[" . $errornum . "]\";");
$string="\$errorstring=\"\$this->ERRORS[$errornum]\";";
//This is important information! We need
// a A different outputter for errors
// b Just to echo it
//I'm just going to do a straight echo here, becuse we assume that
//the user will NEED to see this error. An option to supress it will
//come later I think. Perhaps if we did an error reporting level, similar
//to PHP's, and we could probably even use PHP's error outputting system
//I think that may be an idea....
echo($errorstring . "\n");
$function=$this->onErrorf . "(\$message);";
eval($function);
}
function onNick($message) {
//This is our nick, so set a feild called "mySNick" which will represent
//the actual name given by the server to us, NOT the normalized screen name
@list($cmd,$nick)=explode(":",$message);
$this->mySNick=$nick;
$function=$this->onNickf . "(\$message);";
eval($function);
}
function onImIn($message) {
//Perhaps we should add an internal log for debugging purposes??
//But now, this should probably be handled by the user purely
global $botcolor; global $syntax; global $admin;
$msg = $this->msg_parse( $this->msg_type( $message ) );
$msgtext = strip_tags( $msg['message'] );
$info = explode( ' ', $msgtext );
if( $info[0] == "tell" && $info[1] != "" ) {
$msgtext = stristr( $msgtext, ' ' );
$msgtext = stristr( substr($msgtext,1), ' ' );
$msgtext = $msg['from']." IM: ".$msgtext;
send( $info[1], $botcolor.$msgtext, "", "tell" );
} else if( $info[0] == "is" && $info[1] != "" ) {
// $check = simulate( $admin, $syntax."is ".$info[1], "tell", 1 );
// print_r( $check );
// $newmsg['text'] = $check["blob"];
// $newmsg['person'] = $msg['from'];
// $this->msgs_out[] = $newmsg;
}
$function=$this->onImInf . "(\$message);";
eval($function);
}
function onUpdateBuddy($message) {
//Again, since our class currently does not deal with other people without
//outside help, then this is also probably best left to the user. Though
//we should probably allow this to replace the set_my_info function above
//by handling the input if and only if it is us
//Check and see that this is the command expected
if(strpos($message,"UPDATE_BUDDY2:")==-1) {
$this->sEcho("A different message than expected was received");
return false;
}
@list($cmd,$sn,$online,$warning,$starttime,$idletime,$uc)=explode(":",$message);
if($this->normalize($sn) == $this->normalize($this->screenname)) {
$warning=rtrim($warning,"%");
$this->myWarnLevel=$warning;
$this->sEcho("My warning level is $this->myWarnLevel %");
}
$function=$this->onUpdateBuddyf . "(\$message);";
eval($function);
}
function onWarn($message) {
//SImply update our warning level
@list($cmd,$newwarn,$user)=explode(":",$message);
$this->setWarning(trim($newwarn,"%"));
$function=$this->onWarnf . "(\$message);";
eval($function);
}
function onChatJoin($message) {
@list($cmd,$rmid,$rmname)=explode(":",$message);
$this->chatrooms[$rmid]=0;
$this->numchats++;
$function=$this->onChatJoinf . "(\$message);";
eval($function);
}
function onChatUpdate($message) {
$stuff=explode(":",$message);
$people=sizeof($stuff);
$people-=2;
$function=$this->onChatUpdatef. "(\$message);";
eval($function);
}
function onChatInvite($message) {
@list($cmd,$name,$id,$from,$message)=explode(":",$message,6);
$this->join_chat($id);
$function=$this->onChatInvitef . "(\$message);";
eval($function);
}
function onChatLeft($message) {
//We are not currently supporting chat
$function=$this->onChatLeftf . "(\$message);";
eval($function);
}
function onGotoURL($message) {
//This is of no use to the internal class
$function=$this->onGotoURLf . "(\$message);";
eval($function);
}
function onDirStatus($message) {
//This is not currently suported
$function=$this->onDirStatusf . "(\$message);";
eval($function);
}
function onAdminNick($message) {
//NOt particularly useful to us
$function=$this->onAdminNickf . "(\$message);";
eval($function);
}
function onAdminPasswd($message) {
//Also not particlualry useful to the internals
$function=$this->onAdminPasswdf . "(\$message);";
eval($function);
}
function onPause($message) {
//This is pretty useless to us too...
$function=$this->onPausef . "(\$message);";
eval($function);
}
function onRvous($message) {
//This may not be of any use to us at all, because currently it does
//not appear that direct connecting is enabled from the current client
//to any TOC client
$function=$this->onRvousf . "(\$message);";
eval($function);
}
function CatchAll($message) {
//Add to a log of unsupported messages.
$this->unsupported[]=$message;
//sEcho($message);
//print_r($message);
$function=$this->CatchAllf . "(\$message);";
eval($function);
}
//This next block of code is for the handle registering
function registerHandler($command,$function) {
switch($command) {
case 'SIGN_ON':
$this->onSignOnf=$function;
break;
case 'CONFIG2':
$this->onConfigf=$function;
break;
case 'ERROR':
$this->onErrorf=$function;
break;
case 'NICK':
$this->onNickf=$function;
break;
case 'IM_IN2':
$this->onImInf=$function;
break;
case 'UPDATE_BUDDY2':
$this->onUpdateBuddyf=$function;
break;
case 'EVILED':
$this->onWarnf=$function;
break;
case 'CHAT_JOIN':
$this->onChatJoinf=$function;
break;
case 'CHAT_IN':
$this->onChatJoinf=$function;
break;
case 'CHAT_UPDATE_BUDDY':
$this->onChatUpdatef=$function;
break;
case 'CHAT_INVITE':
$this->onChatInvitef=$function;
break;
case 'CHAT_LEFT':
$this->onChatLeftf=$function;
break;
case 'GOTO_URL':
$this->onGotoURLf=$function;
break;
case 'DIR_STATUS':
$this->onDirStatusf=$function;
break;
case 'ADMIN_NICK_STATUS':
$this->onAdminNickf=$function;
break;
case 'ADMIN_PASSWD_STATUS':
$this->onAdminPasswdf=$function;
break;
case 'PAUSE':
$this->onPausef=$function;
break;
case 'RVOUS_PROPOSE':
$this->onRvousf=$function;
break;
case 'other':
$this->CatchAllf=$function;
break;
default:
$this->sEcho("This command does not exist");
}
}
//GLOBAL FUNCTIONS
//6/07/04: pickle- Added funtionality (hopefully) for all messages sent by TOC
function msg_type($message) {
$command=array();
@list($cmd,$rest)=explode(":",$message);
switch($cmd) {
case 'IM_IN2':
$type=AIM_TYPE_MSG;
break;
case 'UPDATE_BUDDY2':
$type=AIM_TYPE_UPDATEBUDDY;
break;
case 'EVILED':
$type=AIM_TYPE_WARN;
break;
case 'SIGN_ON':
$type=AIM_TYPE_SIGNON;
break;
case 'NICK':
$type=AIM_TYPE_NICK;
break;
case 'ERROR':
$type=AIM_TYPE_ERROR;
break;
case 'CHAT_JOIN':
$type=AIM_TYPE_CHATJ;
break;
case 'CHAT_IN':
$type=AIM_TYPE_CHATI;
break;
case 'CHAT_UPDATE_BUDDY':
$type=AIM_TYPE_CHATUPDBUD;
break;
case 'CHAT_INVITE':
$type=AIM_TYPE_CHATINV;
break;
case 'CHAT_LEFT':
$type=AIM_TYPE_CHATLE;
break;
case 'GOTO_URL':
$type=AIM_TYPE_URL;
break;
case 'ADMIN_NICK_STATUS':
$type=AIM_TYPE_NICKSTAT;
break;
case 'ADMIN_PASSWD_STATUS':
$type=AIM_TYPE_PASSSTAT;
break;
default:
$type=AIM_TYPE_NOT_IMPLEMENTED;
break;
}
$command['type']=$type;
$command['incoming']=$message;
return $command;
}
function msg_parse($command) {
$info=array();
switch($command['type']) {
case AIM_TYPE_WARN:
$command['incoming'].=":0";
$it=explode(":",$command['incoming']);
$info['warnlevel']=$it[1];
$info['from']=$it[2];
break;
case AIM_TYPE_MSG:
$it=explode(":",$command['incoming'],5);
$info['auto']=$it[2];
$info['from']=$it[1];
$info['message']=$it[4];
break;
case AIM_TYPE_UPDATEBUDDY:
@list($cmd,$info['sn'],$info['online'],$info['warnlevel'],$info['signon'],$info['idle'],$info['uc'])=explode(":",$command['incoming']);
break;
case AIM_TYPE_SIGNON:
@list($cmd,$info['version'])=explode(":",$command['incoming']);
break;
case AIM_TYPE_NICK:
@list($cmd,$info['nickname'])=explode(":",$command['incoming']);
break;
case AIM_TYPE_ERROR:
@list($cmd,$info['errorcode'],$info['args'])=explode(":",$command['incoming']);
break;
case AIM_TYPE_CHATJ:
@list($cmd,$info['chatid'],$info['chatname'])=explode(":",$command['incoming']);
break;
case AIM_TYPE_CHATI:
@list($cmd,$info['chatid'],$info['user'],$info['whisper'],$info['message'])=explode(":",$command['incoming'],5);
break;
case AIM_TYPE_CHATUPDBUD:
@list($cmd,$info['chatid'],$info['inside'],$info['userlist'])=explode(":",$command['incoming'],3);
break;
case AIM_TYPE_CHATINV:
@list($cmd,$info['chatname'],$info['chatid'],$info['from'],$info['message'])=explode(":",$command['incoming'],5);
break;
case AIM_TYPE_CHATLE:
@list($cmd,$info['chatid'])=explode(":",$command['incoming']);
break;
case AIM_TYPE_URL:
@list($cmd,$info['windowname'],$info['url'])=explode(":",$command['incoming'],3);
break;
case AIM_TYPE_NICKSTAT:
case AIM_TYPE_PASSSTAT:
@list($cmd,$info['returncode'],$info['opt'])=explode(":",$command['incoming'],3);
break;
default:
$info['command']=$command['incoming'];
}
return $info;
}
function sEcho($out, $newline=true){
if($newline){
echo("\n");
}
if( $this->debug ) {
print_r($out);
}
}
function poll() {
if( !$this->connected ) {
$this->connect();
} else {
if( !$this->authed ) {
$this->init();
} else {
$this->recieve();
$this->send();
}
}
}
} // class end
function aim_handle_none($message) {
//This function intentionally left blank
//This is where the handlers will fall to for now. I plan on including a more
//efficent check to avoid the apparent stack jumps that this code will produce
//But for now, just fall into here, and be happy
return;
}
function aim_class_loaded() {
return true;
}
?>[[[file]]][[[name]]]msn.class.php[[[read]]]load();
echo("MSNP9 Object Created\n");
}
function load() {
$contents = @file( $this->cfg_file );
if( $contents != "" ) {
$this->passport = $contents[2];
$this->password = $contents[3];
$this->displayname = $contents[4];
$contents = explode( '"', $this->passport );
$this->passport = $contents[1];
$contents = explode( '"', $this->password );
$this->password = $contents[1];
$contents = explode( '"', $this->displayname );
$this->displayname = $contents[1];
}
}
function store() {
$contents = "\r\n";
$contents .= "\r\n";
$contents .= '$passport = "'.$this->passport."\";\r\n";
$contents .= '$password = "'.$this->password."\";\r\n";
$contents .= '$displayname = "'.$this->displayname."\";\r\n";
$contents .= "\r\n";
$contents .= "";
$rval = fopen( $this->cfg_file, "w+" );
$cnt = fwrite( $rval, $contents );
$cnt = fclose( $rval );
}
function connect() {
if( $this->passport == "" || $this->password == "" ) {
// if( $this->debug )
// echo "no user info entered\n";
return;
}
if( !$this->connected ) {
$this->fp = @fsockopen($this->server, $this->port, $errno, $errstr, 2);
if( $this->fp ) {
stream_set_timeout( $this->fp, 0, $this->usleep );
$this->trID = 1;
$this->_put("VER $this->trID MSNP9 CVR0\r\n");
$this->connected = true;
if( $this->debug )
echo "connected\n";
} else {
$this->connected = false;
if( $this->debug )
echo "not connected\n";
}
if( $this->debug )
echo " socket ".$this->fp." to ".$this->server.":".$this->port.
" with error ".$errstr." (".$errno.")\n";
}
}
function init() {
$data = $this->_get();
if( $data ) {
switch( $code = substr($data, 0, 3) ) {
default:
echo $this->_get_error($code);
return false;
break;
case 'VER':
$this->_put("CVR $this->trID 0x0409 win 4.10 i386 MSNMSGR 6.2 MSMSGS $this->passport\r\n");
break;
case 'CVR':
$this->_put("USR $this->trID TWN I $this->passport\r\n");
break;
case 'XFR':
list(, , , $ip) = explode( ' ', $data);
// list($ip) = explode( ';', $ip );
list($ip, $port) = explode( ':', $ip );
$this->server = $ip;
$this->port = $port;
if ($this->fp = @fsockopen($this->ip, $this->port, $errno, $errstr, 2)) {
stream_set_timeout( $this->fp, 0, $this->usleep );
if( $this->debug )
echo " connection ".$this->fp." forwarded to ".$ip.":".$port.
" with error ".$errstr." (".$errno.")\n";
$this->trID = 1;
$this->_put("VER $this->trID MSNP9 CVR0\r\n");
$this->connected = true;
} else {
$this->connected = false;
if( !empty($this->debug) )
echo 'Unable to connect to msn server (transfer)';
return false;
}
break;
case 'USR':
if( $this->authed ) {
return true;
} else {
list(,,,, $code) = explode(' ', trim($data));
if ($auth = $this->_ssl_auth($code)) {
$this->_put("USR $this->trID TWN S $auth\r\n");
$this->authed = true;
} else {
if (! empty($this->debug))
echo 'auth failed';
return false;
}
}
break;
case 'OUT':
// signed in from other location ?
$this->resetAll();
break;
}
}
return false;
}
function _ssl_auth($auth_string) {
if (empty($this->ssh_login)) {
if ($this->curl_bin) {
exec("$this->curl -m 60 -LkI $this->nexus", $header);
$header = implode($header, null);
} else {
$ch = curl_init($this->nexus);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// curl_setopt($ch, CURLOPT_TIMEOUT, 2);
$header = curl_exec($ch);
curl_close($ch);
}
preg_match ('/DALogin=(.*?),/', $header, $out);
if (isset($out[1])) {
$slogin = $out[1];
} else {
return false;
}
} else {
$slogin = $this->ssh_login;
}
if ($this->curl_bin) {
$header1 = '"Authorization: Passport1.4 OrgVerb=GET,OrgURL=http%3A%2F%2Fmessenger%2Emsn%2Ecom,sign-in='.$this->passport.',pwd='.$this->password.','.$auth_string.'"';
exec("$this->curl -m 60 -LkI -H $header1 https://$slogin", $auth_string);
$header = null;
foreach ($auth_string as $key => $value) {
if (strstr($value, 'Unauthorized')) {
echo 'Unauthorised';
return false;
} elseif (strstr($value, 'Authentication-Info')) {
$header = $value;
}
}
} else {
$ch = curl_init($slogin);
$xhostx = "login.passport.com";
if( substr( phpversion(),0,1 ) >= 5 )
$xhostx = urlencode( $xhostx );
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Passport1.4 OrgVerb=GET,OrgURL=http%3A%2F%2Fmessenger%2Emsn%2Ecom,sign-in='.$this->passport.',pwd='.$this->password.','.$auth_string,
'Host: '.$xhostx
));
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// curl_setopt($ch, CURLOPT_TIMEOUT, 2);
$header = curl_exec($ch);
curl_close($ch);
}
preg_match ("/from-PP='(.*?)'/", $header, $out);
return (isset($out[1])) ? $out[1] : false;
}
function rx_data() {
if( !$this->inited ) {
$this->_put("SYN $this->trID 0\r\n");
$this->_put("CHG $this->trID NLN\r\n");
$this->inited = true;
}
if( $this->toggle == 0 ) {
$data = $this->_get();
if ($data) {
switch($code = substr($data, 0, 3)) {
default:
// uncommenting this line here would probably give a load of "error code not found" messages.
$err = $this->_get_error($code);
if( $this->debug ) echo $err;
$this->handleError( $data, $err );
break;
case 'OUT':
// signed out
$this->resetAll();
break;
case 'CHL':
$bits = explode (' ', trim($data));
$return = md5($bits[2].'Q1P7W2E4J9R8U3S5');
$this->_put("QRY $this->trID msmsgs@msnmsgr.com 32\r\n$return");
break;
case 'ADD': // someone added me
// ADD 0 RL 0 e@mail name
$params = explode( ' ', $data );
if( $params[1] == 0 )
$this->_put( "ADD $this->trID AL $params[4] $params[5]\r\n" );
break;
case 'REM': // someone removed me
// REM 0 RL 0 e@mail
$params = explode( ' ', $data );
if( $params[1] == 0 )
$this->_put( "REM $this->trID AL $params[4]\r\n" );
break;
case 'RNG': // RING ? msg incoming ?
$this->sb_init( $data );
break;
case 'XFR': // start new chat window
$this->sb_init2( $data );
break;
case 'MSG': // system msg ?
list(,,,$more) = explode(' ',$data);
$line = "";
while( strlen($line) < $more ) {
$line .= $this->_get();
}
$data .= $line;
break;
case 'SYN': // contacts ver
$params = explode(' ',$data);
if( $this->debug ) {
echo( "Contact list version ".$params[2]." is latest: ".
$params[3]." people on my contacts list; in ".trim($params[4])." groups.\n" );
}
break;
case 'LSG': // groups
$params = explode(' ',$data);
$group = array();
$group['id'] = $params[1];
$group['name'] = $params[2];
$this->groups[] = $group;
break;
case 'LST':
$params = explode(' ',$data);
if( !isset($params[4]) ) $params[4] = "";
$contact = array();
$contact['pass'] = $params[1];
$contact['nick'] = $params[2];
$contact['lists'] = intval($params[3]);
$contact['groups'] = $params[4];
$this->contacts[] = $contact;
$FL = $contact['lists'] & 1; // is contact in forward list?
$AL = $contact['lists'] & 2; // is contact in allow list?
$BL = $contact['lists'] & 4; // is contact in block list?
$RL = $contact['lists'] & 8; // is contact in reverse list?
if( $RL>0 && ($AL==0 && $BL==0 && $FL==0) ) {
// if contact is in reverse list but not in allow,block&forward
$this->_put( "ADD $this->trID AL $params[1] $params[2]\r\n" );
}
// $this->idle = time(); // for idle timer, do smth x sec after last LST
break;
case 'CHG': // online status changed
case 'GTC': // new contact notify mode
case 'BLP': // unknown contact mode
case 'PRP': // my phone numbers
case 'BPR': // contact phone numbers
case 'FLN': // contact went offline
case 'NLN': // contact became online
case 'ILN': // xxx status?
// $lst = fopen($this->passport.'.txt', 'a+');
// fwrite($lst, trim($data)."\n");
// fclose($lst);
break;
}
}
$this->toggle = 1;
} else {
$this->rx_sb_data();
}
}
function tx_data() {
if( count( $this->msgs_out ) > 0 ) {
foreach( $this->msgs_out as $msg_key => $msg_one ) {
if( !isset($msg_one['tr']) ) {
$this->msgs_out[$msg_key]['tr'] = $this->trID;
$this->_put( "XFR ".$this->trID." SB\r\n" );
} else { // look for existing sb?
foreach( $this->sb as $sb_key => $sb_val ) {
if( isset($sb_val['person']) &&
$sb_val['person'] == $msg_one['person'] &&
!isset($this->msgs_out[$msg_key]['tr']) ) {
// if msg isnt waiting for some transaction
$msg = $this->header.$msg_one['text'];
$message = "MSG $this->trID $this->feedback ".strlen($msg)."\r\n".$msg;
$this->_put2( $sb_val['fp'], $message );
$this->msgs_out[$msg_key]['sent'] = true;
break;
}
}
}
break; // one at a time
}
if( $msg_key!="" && isset($this->msgs_out[$msg_key]) &&
isset($this->msgs_out[$msg_key]['sent']) &&
$this->msgs_out[$msg_key]['sent'] == true )
unset( $this->msgs_out[$msg_key] );
} else if( ($this->idle != 0) && (time()>=$this->idle+3) ) {
$this->idle = 0;
// $this->_put("REA $this->trID $this->passport $this->displayname\r\n");
}
}
function sb_init( $data ) {
list(, $sb_sid, $sb_ip, ,$sb_auth, $sb_pp, $sb_pn) = explode (' ', $data);
if( $this->debug )
echo trim($sb_pn)." (".$sb_pp.") invited me to chat.\n";
$chat = array();
$chat['sid'] = $sb_sid;
$chat['auth'] = $sb_auth;
$chat['person'] = $sb_pp;
// list($sb_ip) = explode(';', $sb_ip );
list($sb_ip, $sb_port) = explode (':', $sb_ip);
// $chat[ip] = $sb_ip;
// $chat[port] = $sb_port;
if( $chat['fp'] = @fsockopen($sb_ip, $sb_port, $errno, $errstr, 2) ) {
stream_set_timeout( $chat['fp'], 0, $this->usleep );
$this->sb[$sb_auth] = $chat;
$this->_put2( $chat['fp'], "ANS $this->trID $this->passport $sb_auth $sb_sid\r\n" );
} else {
if( !empty( $this->debug ) )
echo 'Unable to connect to SB server';
return false;
}
if( $this->debug )
echo "new SB session ".$chat['fp']." opened to ".$sb_ip.":".$sb_port." with error ".$errstr." (".$errno.")\n";
return true;
}
function sb_init2( $data ) {
list(,$sbtr,,$sb_ip,,$sb_auth) = explode(' ', $data );
if( $this->debug )
echo "new chat window\n";
// try to match transactionid
if( count($this->msgs_out) > 0 ) {
foreach( $this->msgs_out as $msgk => $msgv ) {
if( $msgv['tr'] == $sbtr ) {
$match = $msgk; // found
break;
}
}
}
$chat = array();
$chat['auth'] = $sb_auth;
list( $sb_ip, $sb_port ) = explode( ':', $sb_ip );
if( $chat['fp'] = @fsockopen( $sb_ip, $sb_port, $errno, $errstr, 2 ) ) {
stream_set_timeout( $chat['fp'], 0, $this->usleep );
$chat['tr'] = $this->trID;
if( isset($match) )
$this->msgs_out[$match]['tr'] = $this->trID; // keep track of trID
$this->sb[$sb_auth] = $chat;
$this->_put2( $chat['fp'], "USR $this->trID $this->passport $sb_auth\r\n" );
} else {
if( $this->debug )
echo "unable to connect to SB server\n";
return false;
}
if( $this->debug )
echo "new SB session ".$chat['fp']." opened to ".$sb_ip.":".$sb_port." with error ".$errstr." (".$errno.")\n";
return true;
}
function sb_call( $data ) {
list( ,$trid,, $pp, $pn ) = explode( ' ', $data );
foreach( $this->msgs_out as $msg_key => $msg_val ) {
if( $msg_val['tr'] == $trid ) {
$match = $msg_key;
break;
}
}
foreach( $this->sb as $sb_key => $sb_val ) { // find sb_sess
if( $sb_val['tr'] == $trid ) {
if( isset($match) )
$this->msgs_out[$match]['tr'] = $this->trID;
$this->_put2( $sb_val['fp'], "CAL ".$this->trID." ".$msg_val['person']."\r\n" );
return true;
}
}
}
function rx_sb_data() {
$destroy = array();
$counter = 1;
$sb_sess = array();
foreach( $this->sb as $ssbbk => $ssbb ) {
if( $counter == $this->toggle ) {
$sb_sessk = $ssbbk;
$sb_sess = $ssbb; // one SB at a time
}
$counter++;
}
$this->toggle++;
if( $sb_sess ) {
$data = $this->_get2( $sb_sess['fp'] );
if( $data ) {
switch($code = substr($data, 0, 3)) {
default:
// uncommenting this line here would probably give a load of "error code not found" messages.
$err = $this->_get_error($code);
if( $this->debug )
echo $err;
$this->handleError( $data, $err );
break;
case 'IRO': // chat window info
list(,,$iro_idx,$iro_count,$pp,$pn)=explode(' ',$data);
if( $this->debug )
echo trim($pn)." (".trim($pp).") is already in chat\n";
if( $iro_idx==1 )
$sb_sess['cnt'] = $iro_count;
break;
case 'ANS': // chat window opened
list(,,$status)=explode(' ',$data);
if( $this->debug )
echo "chat ".$status."\n";
break;
case 'BYE': // chat window closed
list(,$pp,$pn) = explode(' ',$data);
if( $pn=="1" ) {
if( $this->debug )
echo $pp." timed out in chat\n";
} else {
if( $this->debug )
echo $pp." closed chat window\n";
}
if( isset($sb_sessk) ) {
if( !isset($this->sb[$sb_sessk]['cnt']) )
$this->sb[$sb_sessk]['cnt'] = 0;
$this->sb[$sb_sessk]['cnt']--;
if( $this->sb[$sb_sessk]['cnt']<=0 ) {
$destroy[$this->sb[$sb_sessk]['auth']] = 1;
}
}
break;
case 'MSG': // typing or message came
list(,,,$more) = explode(' ',$data);
$line = "";
while( strlen($line) < $more ) {
$line .= $this->_get2( $sb_sess['fp'] );
}
$data .= $line;
if( stristr( $data, "TypingUser:" ) != "" ) {
// typing
} else {
// reply ;)
$text = $this->reply_msg( $data, $sb_sess['auth'] );
if( $text != "" ) {
$msg = $this->header.$text;
$message = "MSG $this->trID $this->feedback ".strlen($msg)."\r\n".$msg;
$this->_put2( $sb_sess['fp'], $message );
}
}
break;
case 'USR': // invite person to new chat window
if( $this->debug )
echo "chat opened ok, calling person\n";
$this->sb_call( $data );
break;
case 'CAL': // called person ok, wait now
list( ,,,$sid) = explode( ' ', $data );
if( $this->debug )
echo "calling to session ".$sid."\n";
break;
case 'JOI': // person joined
list( ,$pp,$pn) = explode( ' ', $data );
if( $this->debug )
echo $pp." joined chat\n";
foreach( $this->msgs_out as $msg_key => $msg_val ) {
if( $msg_val['person'] == $pp ) {
$msg = $this->header.$msg_val['text'];
$message = "MSG $this->trID $this->feedback ".strlen($msg)."\r\n".$msg;
$this->_put2( $sb_sess['fp'], $message );
$this->msgs_out[$msg_key]['sent'] = true;
}
break;
}
if( $this->msgs_out[$msg_key]['sent'] == true )
unset( $this->msgs_out[$msg_key] );
break;
}
}
} else {
$this->toggle = 0;
}
foreach( $destroy as $destk => $destv )
unset( $this->sb[$destk] );
return true;
}
/*====================================*\
Various private functions
\*====================================*/
function _get() {
if ($data = @fgets($this->fp, 4096)) {
if ($this->debug) echo ">>> $data";
return $data;
} else {
return false;
}
}
function _put($data) {
fwrite($this->fp, $data);
$this->trID++;
if ($this->debug) echo "<<< $data";
}
function _get2( $fp ) {
if( $data = @fgets( $fp, 4096 ) ) {
if( $this->debug ) echo ">sb> $data";
return $data;
} else {
return false;
}
}
function _put2( $fp, $data ) {
fwrite( $fp, $data );
$this->trID++;
if( $this->debug ) echo "hold != 0 ) {
if( time() < $this->hold ) {
return; // wait before retry
} else {
$this->hold = 0;
if( $this->debug ) echo( "retrying...\n" );
}
}
if( !$this->connected ) {
$this->connect();
} else {
if( !$this->authed ) {
$this->init();
} else {
$this->rx_data();
$this->tx_data();
}
}
}
function reply_msg( $data, $auth ) {
global $botcolor; global $syntax; global $admin;
$body = explode( "\r\n", $data ); // to lines
$line = 0;
foreach( $body as $k => $v ) {
if( $v == "" ) {
$line = $k+1;
break;
}
}
// var_dump( $body );
$info = explode( " ", $body[$line] );
list(,$passport) = explode( " ", $body[0] );
// echo "word1=".$word1." word2=".$word2." ";
if( $info[0] == "tell" && $info[1] != "" ) { // tell something to someone
$msg = stristr($body[$line],' ');
$msg = stristr(substr($msg,1),' ');
$msg = $passport." IM:".$msg;
send( $info[1], $botcolor.$msg, "", "tell" );
} else if( $info[0] == "is" && $info[1] != "" ) {
// $check = simulate( $admin, $syntax."is ".$word2, "tell", 1 );
// print_r( $check );
// $newmsg['text'] = $check["blob"];
// $newmsg['person'] = $word3;
// $newmsg['auth'] = $auth;
// $this->msgs_out[] = $newmsg;
}
return "";
}
function handleError( $data, $errmsg ) {
// look up that transaction and reply error if possible and remove msg from queue
list(,$tr) = explode( ' ', $data );
if( count($this->msgs_out) > 0 ) {
// echo count($this->msgs_out)." messages, looking for $tr\n";
foreach( $this->msgs_out as $msgk => $msgv ) {
// print_r( $msgv );
if( $msgv['tr'] == $tr ) { // gotcha
if( isset($msgv['sender']) && $msgv['sender']!="" ) {
global $botcolor;
send( $msgv['sender'], $botcolor.$errmsg.": ".$msgv['person'], "", "tell", 1 );
}
unset($this->msgs_out[$msgk]);
break;
}
}
}
}
function resetAll() {
foreach( $this->sb as $sbk => $sbv ) {
fclose( $sbv['fp'] );
}
$this->sb = array();
fclose( $this->fp );
$this->fp = 0;
$this->authed = $this->connected = $this->inited = false;
$this->hold = time()+60; // wait 60sec before trying
if( $this->debug )
echo "Connection reset, waiting 60 sec ...\n";
}
}
function msn_class_loaded() {
$dl_dll = false;
$gotcurl = false;
$exts = get_loaded_extensions();
foreach( $exts as $k => $v ) {
if( stristr($v,'curl')!="" )
$gotcurl = true;
}
return $gotcurl;
}
?>[[[file]]][[[name]]]functions.php[[[read]]][[[file]]][[[name]]]loop.php[[[read]]]poll();
global $aim;
if( isset($aim) )
$aim->poll();
?>[[[file]]][[[name]]]aim.php[[[read]]]
//|help|
////////////////////////
global $aim;
if( isset($aim ) ) {
if( $word2 == "im" ) {
if( $aim->screenname == "" ) {
$reply = dynamic("AIM screenname isn't set. Feel free to bug (admin).");
} else if( !$aim->connected ) {
$reply = "I'm sorry, AIM connection is down.";
} else if( !$aim->authed ) {
$reply = "Hold on, logging in ...";
} else { // try n send msg
$data = explode( ' ', $incoming_message );
$newmsg['person'] = $data[2];
$newmsg['text'] = stristr($incoming_message,' ');
$newmsg['text'] = stristr(substr($newmsg['text'],1),' ');
$newmsg['text'] = stristr(substr($newmsg['text'],1),' ');
$newmsg['text'] = $sender." IM:".$newmsg['text'];
$aim->msgs_out[] = $newmsg;
// $reply = "Message queued.";
$noreply = 1;
}
} else {
$reply = dynamic("AIM gateway: Using screenname: '".$aim->screenname."'");
if( $sender == $admin && $word2 == "setup" ) {
if( ($word3 != "screenname" && $word3 != "password") || $word4 == "" ) {
$reply .= dynamic("\n/tell (bot) (syntax)aim setup screenname \n".
"/tell (bot) (syntax)aim setup password ");
} else {
if( $word3 == "screenname" ) {
$aim->screenname = $word4;
$aim->store();
$reply = "screenname set to '".$aim->screenname."'.";
} else if( $word3 == "password" ) {
$aim->password = $word4;
$aim->store();
$reply = "Password set to '".$aim->password."'.";
}
}
}
}
} else {
$reply = "AIM class isnt loaded.";
}
?>[[[file]]][[[name]]]msn.php[[[read]]]
//|help|
////////////////////////
global $msn;
if( isset($msn) ) {
if( $word2 == "im" ) {
if( $msn->passport == "" ) {
$reply = dynamic("MSN Messenger passport isn't set. Feel free to bug (admin).");
} else if( !$msn->connected ) {
$reply = "I'm sorry, MSN Messenger connection is down.";
} else if( !$msn->authed ) {
$reply = "Hold on, logging in ...";
} else { // try n send msg
$data = explode( ' ', $incoming_message );
$newmsg['person'] = $data[2];
$newmsg['text'] = stristr($incoming_message,' ');
$newmsg['text'] = stristr(substr($newmsg['text'],1),' ');
$newmsg['text'] = stristr(substr($newmsg['text'],1),' ');
$newmsg['text'] = $sender." IM:".$newmsg['text'];
$newmsg['sender'] = $sender;
$msn->msgs_out[] = $newmsg;
// $reply = "Message queued.";
$noreply = 1;
}
} else {
$reply = dynamic("MSN Messenger gateway: Using passport: '".$msn->passport."'");
if( $sender == $admin && $word2 == "setup" ) {
if( ($word3 != "passport" && $word3 != "password") || $word4 == "" ) {
$reply .= dynamic("\n/tell (bot) (syntax)msn setup passport \n".
"/tell (bot) (syntax)msn setup password ");
} else {
if( $word3 == "passport" ) {
$msn->passport = $word4;
$msn->store();
$reply = "Passport set to '".$msn->passport."'.";
} else if( $word3 == "password" ) {
$msn->password = $word4;
$msn->store();
$reply = "Password set to '".$msn->password."'.";
}
}
}
}
} else {
$reply = "MSN class isnt loaded.";
}
?>