<?php class xatbot{public $username;public $password;public $key;public $owners;public $chat;private $k1;private $k2;private $k3;private $d0;private $d1;private $d2;private $d3;private $dt;private $xatpwd;private $socket;private $ip;private $port;public function xatbot(){$socket=@socket_create(AF_INET,SOCK_STREAM,SOL_TCP);if($socket<0){trigger_error("Could not create socket. Is the socket extension enabled? Error code:".socket_strerror($socket))}}public function login($username=$this->username,$password=$this->password){if($username==null||$password==null){trigger_error("Username and password field cannot be empty",E_USER_WARNING)}else{$this->username=$username;$this->password=$password;$c=curl_init()or trigger_error("cURL not installed. It must be installed for this to run",E_USER_WARNING);$url="http://xat.com/web_gear/chat/register.php";if(empty($this->key)){$this->key="0"}$fields=array("k2"=>"0","UserId"=>"0","mode"=>"0","Pin"=>$this->key,"cp"=>"","NameEmail"=>urlencode($username),"password"=>urlencode($password),"Protected"=>"NC","Locked"=>"NC","Login"=>"Login");foreach($fields as $k=>$v){$fields_string.=$k."=".$v."&"}rtrim($fields_string,"&");curl_setopt($c,CURLOPT_URL,$url);curl_setopt($c,CURLOPT_POST,count($fields));curl_setopt($c,CURLOPT_POSTFIELDS,$fields_string);curl_setopt($c,CURLOPT_RETURNTRANSFER,1);curl_setopt($c,CURLOPT_HTTPHEADER,array("X-Forwared-For:".$_SERVER['REMOTE_ADDR']));$result=curl_exec($c);curl_close($c);if(stripos($result,'<div id="LoginResult">Please wait..</div>')===false){$error=stribet($result,'<p style="color:#FF0000"><strong>**','**</strong>');return array(false,$error)}$this->username=stribet($result,"&em=","&pw");$this->xatpwd=stribet($result,"&pw=","\"");return array(true,$this->username,$this->xatpwd)}}public function connectToChat($username=$this->username,$chat=$this->chat,$password=$this->xatpwd){}public function parseXML($xmlStr){$xml="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";$xml.="<root>\n";$xml.=$xmlStr;$xml.="\n</root>"}public function groupToId($group){$url="http://xat.com/".$group;$params=array('http'=>array('method'=>'HEAD','ignore_errors'=>true));$context=stream_context_create($params);$fp=fopen($url,'rb',false,$context);$result=stream_get_contents($fp);if($result===false){trigger_error("Could not connect to xat",E_USER_WARNING);return false}else if(strstr($http_response_header[0],'302')){echo"success=0&error=Group+does+not+exist&groupid=0"}else{return stribet(file_get_contents($url),"&id=","&md")}}public function connect(){}public function stribet($inputstr,$delimiterLeft,$delimiterRight){$posLeft=stripos($inputstr,$delimiterLeft)+strlen($delimiterLeft);$posRight=stripos($inputstr,$delimiterRight,$posLeft);return substr($inputstr,$posLeft,$posRight-$posLeft)}}?>
