Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- set_time_limit(0);
- declare(ticks=1);
- class XatBot {
- private $roomID = "31149180";
- private $botName = "ChatAiutoBOT";
- private $avatar = "http://i56.tinypic.com/slmvxg.jpg";
- var $botID = "";
- var $homePage = 'http://xat.com/Aiuto';
- var $access = array('Davide');
- var $k = "";
- var $status= "";
- var $allowAccess = array('723517','356566558','303826285');
- var $BotOwner = array('723517');
- var $userID = "";
- var $joinmsg = "";
- var $regName = "ChatAiutoBOT";
- var $regPassword = "passworddelbot";
- var $regInfo = array();
- var $loggedIn = true;
- private $maxKicks = 3;
- var $banTime = 3000;
- var $spam = array("time"=>10, "limit"=>6);
- var $filterWords = true;
- var $allowByRank;
- var $automember = false;
- private $autowelcome = "";
- var $autokicknull = false;
- var $commands = array();
- var $censor = array("");
- var $gamesAllowed = false;
- var $gameRunning = false;
- var $gameVar = array();
- var $debug = false;
- var $soc = null;
- var $packet = array();
- var $users = array();
- var $auser = array();
- var $doneReached = false;
- private $autokick = array("");
- var $members = array();
- var $handler = array();
- function login() {
- $this->loggedIn = false;
- if($this->regName==''||$this->regPassword=='') return;
- $postData = "Locked=NC&Login=Login&NameEmail=$this->regName&Pin=0&Protected=NC&UserId=0&cp=&k2=0&mode=0&password=$this->regPassword";
- $res = $this->post_request('http://xat.com/web_gear/chat/register.php', $postData, 'http://xat.com/web_gear/chat/register.php');
- if($res['status']!='ok') return;
- $res = $res['content'];
- $this->regInfo['pw'] = $this->getBetween(strtolower($res),strtolower($this->regName)."&pw=",'"');
- if($this->regInfo['pw']=='') return;
- if($this->soc!=null) socket_close($this->soc);
- $this->connect("174.36.242.27","10000");
- $this->send('<v n="'.$this->regName.'" p="'.$this->regInfo['pw'].'" />');
- $this->read();
- print_r($this->packet['v']);
- $this->regInfo = $this->packet['v'];
- $this->userID = $this->packet['v']['i'];
- $this->regName = $this->packet['v']['n'];
- if(count($this->regInfo)>4) $this->loggedIn = true;
- return true;
- }
- function run() {
- if($this->login()!=true){
- $this->k = "1970311945";
- $this->userID = "363095521";
- $this->loggedIn = false;
- }
- $this->connect("174.36.242.26","10000");
- $this->join($this->roomID);
- while($this->read()!="DIED");
- }
- function connect($ip, $port) {
- $this->soc = socket_create(AF_INET,SOCK_STREAM,SOL_TCP);
- if(!$this->soc) die(socket_strerror(socket_last_error($this->soc)));
- if(!socket_connect($this->soc,$ip,$port)) die("Impossibile connettersi.");
- }
- function join($roomID) {
- $this->send('<y m="1" />');
- while(substr_count($this->read(),'<y')<=0);
- if($this->loggedIn) {
- $p = "";
- if(!empty($this->regInfo['n']))
- $this->regInfo['N'] = $this->regInfo['n'];
- unset($this->regInfo['n']);
- $p .= 'q="1" ';
- $p .= 'y="'.$this->packet['y']['i'].'" ';
- $p .= 'k="'.$this->regInfo['k1'].'" ';
- $p .= 'k3="'.$this->regInfo['k3'].'" ';
- if(isset($this->regInfo['d1'])) $p .= 'd1="'.$this->regInfo['d1'].'" ';
- $p .= 'z="12" p="0" ';
- $p .= 'c="'.$this->roomID.'" ';
- $p .= 'f="0" ';
- $p .= 'u="'.$this->regInfo['i'].'" ';
- $p .= 'm0="671088640" ';
- $p .= 'm2="32" ';
- $p .= 'd0="'.$this->regInfo['d0'].'" ';
- if(isset($this->regInfo['d2'])) $p .= 'd2="'.$this->regInfo['d2'].'" ';
- $p .= 'd3="'.$this->regInfo['d3'].'" ';
- if(isset($this->regInfo['d4'])) $p .= 'd4="'.$this->regInfo['d4'].'" ';
- if(isset($this->regInfo['d5'])) $p .= 'd5="'.$this->regInfo['d5'].'" ';
- if(isset($this->regInfo['d6'])) $p .= 'd6="'.$this->regInfo['d6'].'" ';
- if(isset($this->regInfo['d7'])) $p .= 'd7="'.$this->regInfo['d7'].'" ';
- if(isset($this->regInfo['d8'])) $p .= 'd8="'.$this->regInfo['d8'].'" ';
- if(isset($this->regInfo['dO'])) $p .= 'dO="'.$this->regInfo['dO'].'" ';
- if(isset($this->regInfo['dx'])) $p .= 'dx="'.$this->regInfo['dx'].'" ';
- $p .= 'dt="'.$this->regInfo['dt'].'" ';
- $p .= 'N="'.$this->regName.'" ';
- $p .= 'n="'.$this->botName.'##'.$this->status.'" ';
- $p .= 'a="'.$this->avatar.'" ';
- $p .= 'h="'.$this->homePage.'" ';
- $p .= 'v="0" ';
- $p = trim($p);
- $this->send('<j2 '.$p.' />');
- $this->sendMessage("$this->joinmsg");
- } else {
- $this->send('<j2 q="1" y="'.$this->packet['y']['i'].'" k="'.$this->k.'" k3="0" z="12" p="0" c="'.$roomID.'" f="0" u="'.$this->userID.'" d0="0" n="'.$this->botName.'" a="'.trim($this->avatar).'" h="$this->homePage" v="0" />');
- }
- $this->time = time();
- }
- function send($message) {
- if($this->debug)echo "->>\t $message\n";
- socket_write($this->soc, $message."\0", strlen($message)+1);
- }
- function read($parse=true) {
- $res = rtrim(socket_read($this->soc, 4096));
- if($this->debug)echo "<<-\t $res\n";
- if(!$res) {
- return "DIED";
- echo $res." then DIED\n";
- }
- $this->lastPacket = $res;
- if($res{strlen($res)-1}!='>') { $res.=$this->read(false);}
- if($parse)$this->parse($res);
- return $res;
- }
- function save($state=1) {
- $save;
- foreach($this as $k=>$v) {
- if($k!='soc' && $k != 'users')
- $save[$k]=$v;
- }
- }
- function loadFromDB($content) {
- $content = unserialize($content);
- foreach($content as $k=>$v) {
- if($k!='debug'&&$k!='roomID'&&$k!='sql')
- $this->$k = $v;
- }
- }
- function load() {
- try {
- $content = unserialize(file_get_contents("XatBot.".$this->roomID));
- foreach($content as $k=>$v) {
- if($k!='debug'&&$k!='roomID')
- $this->$k = $v;
- }
- } catch(Exception $e) {
- }
- }
- function write2file($fn,$content,$mode='w') {
- if(!file_exists($fn)&&stristr($mode,'w')==false) return;
- $fp = fopen($fn,$mode);
- fwrite($fp,$content);
- fclose($fp);
- }
- function get($url, $includeHeader=false) {
- $urlp = parse_url($url);
- $fp = fsockopen($urlp['host'],80);
- $path = explode('/',$url,4);
- $path = ((count($path)>=4)?$path[3]:"");
- $req = "GET /$path HTTP/1.1\r\n";
- $req .= "Host: $urlp[host]\r\n";
- $req .= "Connessione: Chiusa\r\n\r\n";
- fputs($fp, $req);
- $res = "";
- while(!feof($fp)) $res .= fgets($fp, 4096);
- fclose($fp);
- if($includeHeader) return $res;
- $res = explode("\r\n\r\n",$res,2);
- return $res[1];
- }
- function post_request($url, $data, $referer='') {
- $url = parse_url($url);
- $host = $url['host'];
- $path = $url['path'];
- $fp = fsockopen($host, 80, $errno, $errstr, 30);
- if ($fp){
- fputs($fp, "POST $path HTTP/1.1\r\n");
- fputs($fp, "Host: $host\r\n");
- if ($referer != '')
- fputs($fp, "Referer: $referer\r\n");
- fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
- fputs($fp, "Content-length: ". strlen($data) ."\r\n");
- fputs($fp, "Connessione: Chiusa\r\n\r\n");
- fputs($fp, $data);
- $res = '';
- while(!feof($fp)) {
- $res .= fgets($fp, 128);
- }
- }
- else {
- return array(
- 'status' => 'err',
- 'error' => "$errstr ($errno)"
- );
- }
- fclose($fp);
- $res = explode("\r\n\r\n", $res, 2);
- $header = isset($res[0]) ? $res[0] : '';
- $content = isset($res[1]) ? $res[1] : '';
- return array(
- 'status' => 'ok',
- 'header' => $header,
- 'content' => $content
- );
- }
- function censor($message) {
- $badwords = $this->censor;
- $message = @ereg_replace('[^A-Za-z0-9 ]','',strtolower(' '.$message.' '));
- foreach($badwords as $bad) {
- $bad = trim($bad);
- if(strpos($message.' ', $bad.' ')!==false) {
- if(strlen($bad)>=2) {
- return true;
- }
- }
- }
- }
- function parse($packet) {
- if(substr_count($packet,'>')>1) $packet = explode('/>',$packet);
- foreach((Array)$packet as $p) {
- $p = trim($p);
- if(strlen($p)<5) return;
- $type = trim(strtolower(substr($p,1,strpos($p.' ',' '))));
- $p = trim(str_replace("<$type",'',str_replace('/>','',$p)));
- parse_str(str_replace('"','',str_replace('" ','&',str_replace('="','=',str_replace('&','__38',$p)))),$this->packet[$type]);
- foreach($this->packet[$type] as $k=>$v) {
- $this->packet[$type][$k] = str_replace('__38','&',$v);
- }
- $this->handler['type'] = $type;
- $this->handler['msg'] = $p;
- $this->handle();
- }
- }
- function handle() {
- $type = $this->handler['type'];
- $msg = $this->handler['msg'];
- switch($type) {
- case 'a':
- if(strtolower($this->regName)==$this->regName&&$this->loggedIn == true) {
- if($this->packet['a']['b']!=$this->userID) return;
- if(!isset($this->packet['a']['c'])&&empty($this->packet['a']['c'])) {
- $value = $this->packet['a']['x'] + ($this->packet['a']['s']*13);
- if($value >= 1000) {
- $this->sendPrivateChat("",$this->packet['a']['u']);
- } else {
- $this->sendPrivateChat("",$this->packet['a']['u']);
- $this->send('<a b="'.$this->packet['a']['u'].'" s="'.$this->packet['a']['s'].'" x="'.$this->packet['a']['x'].'" k="T" m="" p="'.$this->regPassword.'" />');
- }
- } else {
- socket_close($this->soc);
- return;
- }
- }
- break;
- case 'q':
- $this->connect($this->packet['q']['d'], $this->packet['q']['p']);
- $this->join($this->roomID);
- break;
- case 'z':
- $data['id'] = $this->parseU($this->packet['z']['u']);
- $this->send('<z d="'.$data['id'].'" u="'.$this->userID.'" t="/ab" />');
- break;
- case 'o':
- $this->users[$this->packet['o']['u']]['name'] = $this->packet['o']['n'];
- break;
- case 'u':
- if(in_array($this->packet['u']['u'],$this->autokick)) {$this->kick("(bye)",$this->packet['u']['u'],true);return;}//Auto-Kick
- if((!isset($this->packet['u']['q'])||empty($this->packet['u']['q']))&&$this->packet['u']['n']==''){
- }
- $this->users[$this->packet['u']['u']]['name'] = trim($this->packet['u']['n']);
- $this->users[$this->packet['u']['u']]['rank'] = ((empty($this->packet['u']['f']))?0:$this->packet['u']['f']);
- $this->users[$this->packet['u']['u']]['regName'] = ((!isset($this->packet['u']['N']))?-1:$this->packet['u']['N']);
- $this->users[$this->packet['u']['u']]['messages'] = 0;
- $this->users[$this->packet['u']['u']]['time'] = 3600;
- if(!isset($this->users[$this->packet['u']['u']]['kicks'])) $this->users[$this->packet['u']['u']]['kicks']=0;
- if(!isset($this->packet['u']['f'])||empty($this->packet['u']['f'])||$this->f2rank($this->packet['u']['f']) == 0) {
- if(!empty($this->packet['u']['n']))
- if($this->automember){
- $this->member($this->packet['u']['u']);
- return;
- }
- }
- if($this->autowelcome!=''&&!isset($this->packet['u']['s']))$this->sendPrivateMessage($this->autowelcome,$this->packet['u']['u']);
- if($this->filterWords) {
- $nome = $this->packet['u']['n'];
- $smile = substr_count($nome,":)")+substr_count($nome,":d")+substr_count($nome,";)")+substr_count($nome,":o")+substr_count($nome,":p")+substr_count($nome,":@")+substr_count($nome,":s")+substr_count($nome,":$")+substr_count($nome,":(")+substr_count($nome,"|-)");
- $nome = str_replace(':)','',$nome);
- $nome = str_replace(':d','',$nome);
- $nome = str_replace(';)','',$nome);
- $nome = str_replace(':o','',$nome);
- $nome = str_replace(':p','',$nome);
- $nome = str_replace(':@','',$nome);
- $nome = str_replace(':s','',$nome);
- $nome = str_replace(':$','',$nome);
- $nome = str_replace(':(','',$nome);
- $nome = str_replace('|-)','',$nome);
- $nome = str_replace(strstr ($nome,'(glow'),'',$nome);
- $nome = str_replace(strstr ($nome,'(hat'),'',$nome);
- $smile = $smile + (substr_count($nome,")")+substr_count($nome,"("))/2;
- if($smile > 6) ($this->kick("Massimo 6 smile nel nick", $this->packet['u']['u'],false,true));
- }
- break;
- case 'p':
- if(isset($this->packet['p']['d'])) {
- if($this->packet['p']['t']{0}=='!') {
- $info = explode(' ',trim($this->packet['p']['t']),2);
- switch(strtolower($info[0])) {
- case '!mioid':
- $this->sendPrivateChat("Il tuo id è: ".($this->parseU($this->packet['p']['u'])), $this->packet['p']['u']);
- break;
- }
- }
- }
- break;
- case 'm':
- if(isset($this->packet['m']['s'])) return;
- //Filter words
- if($this->filterWords) {
- if($this->censor($this->packet['m']['t'])) {
- $this->kick("a", $this->packet['m']['u'],false,true);
- return;
- }
- if(substr_count($this->packet['m']['t'],":)")+substr_count($this->packet['m']['t'],":d")+substr_count($this->packet['m']['t'],";)")+substr_count($this->packet['m']['t'],":o")+substr_count($this->packet['m']['t'],":p")+substr_count($this->packet['m']['t'],":@")+substr_count($this->packet['m']['t'],":s")+substr_count($this->packet['m']['t'],":$")+substr_count($this->packet['m']['t'],":(")+substr_count($this->packet['m']['t'],"|-)")+(int)(substr_count($this->packet['m']['t'],"(")+substr_count($this->packet['m']['t'],")")/2) > 3) ($this->kick("No flood, massimo 3 smile", $this->packet['m']['u'],false,true));
- }
- if((isset($this->packet['m']['u']))&&in_array($this->parseU($this->packet['m']['u']),$this->autokick)) {$this->kick("(bye)",$this->packet['u']['u'],true);return;}
- if($this->packet['m']['t']{0}=='!') {
- $info = explode(' ',trim($this->packet['m']['t']),2);
- $info[1] = @trim($info[1]);
- switch(strtolower($info[0])) {
- //////////////////////////////////////////////// INIZIO COMANDI PER GLI AIUTI ///////////////////////////////////////////////////////
- case '!mioid':
- $this->sendMessage("Il tuo ID è: ".($this->parseU($this->packet['m']['u'])));
- break;
- case '!creachat':
- $this->sendMessage("Per creare una chat clicca sulla parola blu CREACHAT e segui questa guida: http://xat-aiuto.com/come-creare-una-chat-su-xat/");
- break;
- case '!prezzi':
- $this->sendMessage("Puoi trovare i prezzi aggiornati di trade qui: xat.mx");
- break;
- case '!playlist':
- $this->sendMessage("Per inserire una playlist nella tua chat segui questa guida: http://xat-aiuto.com/come-inserire-una-playlist-nella-tua-chat/");
- break;
- case '!radio':
- $this->sendMessage("Per aggiungere una radio nella tua chat segui questa guida: http://xat-aiuto.com/come-aggiungere-una-radio/");
- break;
- case '!interno':
- $this->sendMessage("Per inserire uno sfondo interno nella tua chat, segui questa guida: http://xat-aiuto.com/come-cambiare-lo-sfondo-interno-di-una-chat/");
- break;
- case '!esterno':
- $this->sendMessage("Per inserire uno sfondo esterno nella tua chat, segui questa guida: http://xat-aiuto.com/come-cambiare-lo-sfondo-esterno-di-una-chat/");
- break;
- case '!registrazione':
- $this->sendMessage("Per registrarti su xat clicca sulla parola REGISTER e segui questa guida: http://xat-aiuto.com/come-registrarsi-su-xat/");
- break;
- case '!promote':
- $this->sendMessage("Per mettere in promote la tua chat clicca sulla parola blu promote e segui questa guida: http://xat-aiuto.com/promuovere-la-tua-chat/");
- break;
- case '!trade':
- $this->sendMessage("Per scambiare xats, days e powers puoi usare le chat apposite: xat.com/Baratto / xat.com/Trade / xat.com/Cambio");
- break;
- case '!stamp':
- $this->sendMessage("Per fare uno stamp(screenshot)alla chat puoi seguire questa guida: http://xat-aiuto.com/come-fare-uno-stamp-della-chat/");
- break;
- case '!forumfree':
- $this->sendMessage("Per inserire la tua chat su forumfree/forumcommunity od un fan club segui questa guida: http://xat-aiuto.com/integrare-una-chat-di-xat-su-forumfree/");
- break;
- case '!supporto':
- $this->sendMessage("Puoi contattare il supporto andando su xat.com/support");
- break;
- case '!sondaggio':
- $this->sendMessage("Per insrire un sondaggio nella tua chat segui questa guida: http://xat-aiuto.com/aggiungere-un-sondaggio-alla-chat/");
- break;
- case '!lostpsw':
- $this->sendMessage("Per recuperare la password del tuo account su xat segui questa guida: http://xat-aiuto.com/recuperare-la-password-dimenticata/");
- break;
- case '!buy':
- $this->sendMessage("Puoi comprare xats e days cliccando sulla parola BUY e seguendo questa guida: http://xat-aiuto.com/come-comprare-xats-e-days-con-postepay/");
- break;
- case '!regole':
- $this->sendMessage("Puoi trovare le regole della chat andando su: http://xat.com/Aiuto?p=1 oppure direttamente su: http://util.xat.com/wiki/index.php/Chat_Aiuto");
- break;
- case '!reset':
- $this->sendMessage("Se vuoi resettare la tua chat segui questa guida: http://xat-aiuto.com/come-resettare-una-chat/");
- break;
- case '!nuovoid':
- $this->sendMessage("Per ottenere un nuovo segui questa guida: http://xat-aiuto.com/come-ottenere-un-nuovo-id-su-xat/");
- break;
- case '!effavatar':
- $this->sendMessage("Per aggiungere effetti al tuo avatar segui questa guida: http://xat-aiuto.com/come-aggiungere-effetti-allavatar/");
- break;
- case '!avatar':
- $this->sendMessage("Per cambiare avatar(immagine)su xat, clicca su HOST , carica l'immagine dal tuo computer, prendi l'unico link che la pagina ti offre e copialo nel campo Picture.");
- break;
- case '!eliminaccount':
- $this->sendMessage("Per eliminare il tuo account segui questa guida: http://xat-aiuto.com/come-eliminare-un-account/");
- break;
- case '!lockedout':
- $this->sendMessage("Se il tuo account è bloccato, segui questa guida per fartelo sbloccare http://xat-aiuto.com/come-sbloccare-un-account-bloccato/");
- break;
- case '!effavatar':
- $this->sendMessage("Per aggiungere effetti al tuo avatar segui questa guida: http://xat-aiuto.com/come-aggiungere-effetti-allavatar/");
- break;
- case '!xatspace':
- $this->sendMessage("Per modificare il tuo profilo vai qui: http://xat.com/web_gear/chat/editprofile.php , inserisci il tuo nome utente e la password e inizia a modificare lo xatspace.");
- break;
- case '!comandi':
- $this->sendMessage("I comandi del BOT li trovate su: http://xat-aiuto.com/comandi-bot/");
- break;
- case '!phishing':
- $this->sendMessage("Per informazioni sul phishing, http://util.xat.com/wiki/index.php/PhishingIT");
- break;
- case '!animate':
- $this->sendMessage("Per convertire la vostra immagine da GIF a PNG andate qui: http://util.xat.com/web_gear/chat/ConvertAnimation.php");
- break;
- case '!cell':
- $this->sendMessage("Per usare xat con il tuo cellulare, visita m.xat.com");
- break;
- case '!imgswf':
- $this->sendMessage("Le chat di xat ora hanno delle restrizioni riguardanti le immagini e i file flash(swf). Vedi: tinyurl.com/x-timages2");
- break;
- case '!sms':
- $this->sendMessage("Per comprare xats e days con il vostro cellulare in Italia seguite questa guida: http://xat-aiuto.com/comprare-xats-e-days-con-il-cellulare/");
- break;
- case '!android':
- $this->sendMessage("È possibile utilizzare xat sul tuo cellulare Android. Per più informazioni: http://util.xat.com/wiki/index.php/AndroidIT");
- break;
- //////////////////////////////////////////////// FINE COMANDI PER GLI AIUTI ///////////////////////////////////////////////////////
- //////////////////////////////////////////////// INIZIO ALTRI COMANDI ///////////////////////////////////////////////////////
- case '!dire':
- if(!$this->isAllowed($this->packet['m']['u'],6)) return;
- if($info[1]{0}=='/') $this->sendMessage("No.");
- if($info[1]{0}=='$') $this->sendMessage("No.");
- else $this->sendMessage($info[1]);
- break;
- case '!status':
- if(!$this->isAllowed($this->packet['m']['u'])) return;
- $this->status = ((trim($info[1])!='')?$info[1]:$this->status);
- socket_close($this->soc);
- $this->connect("174.36.242.26","10024");
- $this->join($this->roomID);
- $this->save();
- if(empty($info[1])) $this->status = '';
- break;
- case '!nome':
- if(!$this->isAllowed($this->packet['m']['u'],6)) return;
- $this->botName = ((trim($info[1])!='')?$info[1]:$this->botName);
- socket_close($this->soc);
- $this->connect("174.36.242.26","10024");
- $this->join($this->roomID);
- $this->save();
- break;
- case '!8ball':
- if(!$this->isAllowed($this->packet['m']['u'],6)) return;
- $risposta[] = "Potrebbe essere.";
- $risposta[] = "Forse.";
- $risposta[] = "No.";
- $risposta[] = "Non ne sono sicuro.";
- $risposta[] = "Sì.";
- $risposta[] = "Nemmeno tra 100 anni.";
- $risposta[] = "Non penso.";
- $this->sendMessage($risposta[array_rand($risposta)]);
- break;
- case '!off':
- if(!$this->isAllowed($this->packet['m']['u'],6)) return;
- socket_close($this->soc);
- break;
- //////////////////////////////////////////////// FINE ALTRI COMANDI ///////////////////////////////////////////////////////
- if(array_key_exists(substr(strtolower($info[0]),1),$this->commands)) {
- $msg = $this->commands[substr(strtolower($info[0]),1)];
- $msg = str_replace('[input]',$info[1],$msg);
- $this->sendMessage($msg);
- }
- }
- }
- break;
- }
- }
- function parseU($id) {
- if(substr_count($id,'_')>=1) $id = substr($id,0,strpos($id,'_'));
- return $id;
- }
- function inStr($needle, $haystack) {
- $needlechars = strlen($needle);
- for ($i = 0; $i < strlen($haystack); $i++) if (substr($haystack, $i, $needlechars) == $needle) return true;
- return false;
- }
- function getBetween($content,$start,$end){
- $r = explode($start, $content);
- if (isset($r[1])){
- $r = explode($end, $r[1]);
- return $r[0];
- }
- return '';
- }
- function member($id) {
- if(!isset($this->members[$id])||$this->members[$id]<(time()-5)) {
- $this->send('<c u="'.$id.'" t="/e" />');
- $this->members[$id] = time();
- }
- }
- function kick($message, $id, $silent=false, $log=false) {
- if($log) {
- if(!empty($this->users[$id]['kicks']) ) $this->users[$id]['kicks']++;
- else $this->users[$id]['kicks'] = 1;
- }
- if($silent)$this->send('<c u="'.$id.'" t="/k" />');
- else $this->send('<c p="'.$message." ".$this->users[$id]['kicks'].'/'.$this->maxKicks.'" u="'.$id.'" t="/k" />');
- }
- function ban($message, $id, $time) {
- if(empty($time)) $time = banTime;
- $this->send('<c p="'.ereg_replace('[^A-Za-z0-9.! ]','',$message).'" u="'.$this->parseU($id).'" t="/g'.$time.'" />');
- }
- function unban($id) {
- $this->send('<c u="'.$this->parseU($id).'" t="/u" />');
- }
- function restart() {
- socket_close($this->soc);
- $this->soc = null;
- $this->save();
- sleep(1);
- if($this->botID == 1)
- shell_exec("php XatBot.db.class.php4 $this->botID -null >> log1.txt 2>>err1.txt &");
- else
- shell_exec("php XatBot.db.class.php4 $this->botID -null > /dev/null 2>/dev/null &");
- shell_exec('kill -9 '.getmypid());
- }
- function sendPrivateChat($message, $id) {
- if(empty($message))return;
- $this->send('<p u="'.$id.'" t="'.$message.'" s="2" d="'.$this->userID.'" />');
- }
- function sendPrivateMessage($message,$id) {
- $id = $this->parseU($id);
- if(empty($message))return;
- $this->send('<p u="'.$id.'" t="'.$message.'" />');
- }
- function sendMessage($message) {
- if(empty($message))return;
- $this->send('<m t="'.$message.'" u="'.$this->userID.'" />');
- }
- function query_str($params, $out = array()) {
- if (!is_array($params) || count($params) == 0) return false;
- $fga = func_get_args();
- $akey = ( !isset($fga[1]) ) ? false : $fga[1];
- foreach ($params as $key => $val) {
- if ( is_array($val) ) {
- query_str($val,$key, $out);
- continue;
- }
- $thekey = ( !$akey ) ? $key : $akey . '['.$key.']';
- $out[] = $thekey."=".$val;
- }
- return implode("&",$out);
- }
- function isValidURL($url){return $this->inStr('http://',$url);}
- function f2rank($f) {
- $f = $this->parseU($f);
- if($f==-1) return 0;
- if((16 & $f)) return -1;
- if((1 & $f)&&(2 & $f)) return 1;
- if((4 & $f)) return 3;
- if((32 & $f)&&(1 & $f)&&!(2 & $f)) return 5;
- if(!(1 & $f)&&!(2 & $f)) return 0;
- if((16 & $f)) return -1;
- if((2 & $f)&&!(1 & $f)) return 2;
- }
- function sec2hms($sec, $padHours = false) {
- $hms = "";
- $hours = intval(intval($sec) / 3600);
- $hms .= ($padHours) ? str_pad($hours, 2, "0", STR_PAD_LEFT) . ':' : $hours . ':';
- $minutes = intval(($sec / 60) % 60);
- $hms .= str_pad($minutes, 2, "0", STR_PAD_LEFT) . ':';
- $seconds = intval($sec % 60);
- $hms .= str_pad($seconds, 2, "0", STR_PAD_LEFT);
- return $hms;
- }
- function isAllowed($id,$min) {
- $id = $this->parseU($id);
- if (in_array($id,$this->allowAccess)) return true;
- if($this->allowByRank)if($this->f2rank($this->users[$id]['rank'])>=$min) return true;
- }
- function botOwner($id) {
- $id = $this->parseU($id);
- if (in_array($id,$this->BotOwner)) return true;
- }
- function checkMinRank($id,$min) {
- $id = $this->parseU($id);
- if (in_array($id,$this->allowAccess)) return true;
- if($this->f2rank($this->users[$id]['rank'])>=$min) return true;
- return in_array(strtolower($this->users[$id]['regName']),$this->access);
- }
- }
- $bot = new XatBot();
- while(true) {
- try {
- $bot->run();
- } catch(exception $e) {
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement