1. ASHOOT-x86 - 06 Сентября, 2008 - 00:13:48 - перейти к сообщению
Всем привет! Скачал я клас для работы с icq и решил написать простого бота, который бы сам пробывал еще и еще раз подключаться к icq. Вот код
Все бы ничего, бот пашет если запустить скрипт при наличии или отсутствии подключения к интернету. Бот висит,тоесть работает как мне хотелось бы. Но если не закрывать программу и выполнить переподключение к инету, то бот заново не пробует подключиться, так как метод is_connected() продолжает возващать true (даже при отсутствии подключения к интернету). Что делать? Может в классе какая-то ошибка или я что-то не понимаю? // Заранее благодарен за помощь!(Добавление)
PHP:
скопировать код в буфер обмена
скопировать код в буфер обмена
- <?PHP
- class BasICQ {
- function BasICQ() {
- $this->method=false;
- }
- function sockets($method) {
- $this->method=$method;
- }
- function connect($uin,$pass) {
- if ($this->method) {
- if ($this->socket<0||$this->socket===false) return false;
- if ($result<0||$result===false) return false;
- } else {
- if ($errno!==0) return false;
- }
- $this->getpacket();
- $this->uin=$uin;
- $this->body.=$this->setoption('UIN',$uin);
- $hash="";
- $this->body.=$this->setoption('DATA',$hash);
- $this->body.=$this->setoption('CLIENT','HFICQ');
- $this->body.=$this->setoption('CLIENT_ID',266,2);
- $this->body.=$this->setoption('CLI_MAJOR_VER',20,2);
- $this->body.=$this->setoption('CLI_MINOR_VER',34,2);
- $this->body.=$this->setoption('CLI_LESSER_VER',0,2);
- $this->body.=$this->setoption('CLI_BUILD_NUMBER',2321,2);
- $this->body.=$this->setoption('DISTRIB_NUMBER',1085,4);
- $this->body.=$this->setoption('CLIENT_LNG','ru');
- $this->body.=$this->setoption('CLIENT_COUNTRY','ru');
- $this->channel=1;
- $pack=$this->prepare();
- if ($this->method) socket_write($this->socket,$pack,strlen($pack)); else fwrite($this->socket,$pack);
- $this->getpacket();
- while($this->body!='') {
- $this->type=$arr[1];
- $this->size=$arr[2];
- if($key) $this->info[$key]=$info;
- }
- $this->body=0x0000;
- $pack=$this->prepare();
- if ($this->method) socket_write($this->socket,$pack,strlen($pack)); else fwrite($this->socket,$pack);
- $this->socket=false;
- if ($this->method) {
- if ($this->socket<0||$this->socket===false) $res=false;
- if ($result<0||$result===false) $res=false; else $res=true;
- } else {
- if ($errno!==0) $res=false; else $res=true;
- }
- if (!$res) {
- $this->error=isset($this->info['DISCONECT_REASON'])?$this->info['DISCONECT_REASON']:'Невозможно сменить север';
- return false;
- }
- } else {
- $this->error=isset($this->info['DISCONECT_REASON'])?$this->info['DISCONECT_REASON']:'Превышен лимит подключений';
- return false;
- }
- $this->getpacket();
- $this->body.=$this->setoption('COOKIE',$this->info['COOKIE']);
- $pack=$this->prepare();
- if ($this->method) $wr=socket_write($this->socket,$pack,strlen($pack)); else $wr=fwrite($this->socket,$pack);
- if (!$wr) {
- $this->error='Соединение закрыто';
- return false;
- }
- $this->getpacket();
- $this->request_id++;
- $pack=$this->prepare();
- if ($this->method) $wr=socket_write($this->socket,$pack,strlen($pack)); else $wr=fwrite($this->socket,$pack);
- if (!$wr) {
- $this->error='Соединение закрыто';
- return false;
- }
- return true;
- }
- function is_connected() {
- if ($this->socket) return true; else return false;
- }
- function send_message($uin,$message) {
- $this->request_id++;
- $this->body.=$this->setoption('RECONECT_HERE',$data);
- $this->body.=$this->setoption('CLIENT','');
- $pack=$this->prepare();
- if ($this->method) $wr=socket_write($this->socket,$pack,strlen($pack)); else $wr=fwrite($this->socket,$pack);
- if (!$wr) {
- $this->error='Не могу отправить сообщение, сервер закрыл соединение';
- return false;
- }
- if (!$this->makeinfo()) {
- $this->request_id++;
- $this->body.=$this->setoption('DATA', $data);
- $this->body.=$this->setoption('CLIENT','');
- $this->body.=$this->setoption('COOKIE','');
- $pack=$this->prepare();
- if ($this->method) $wr=socket_write($this->socket,$pack,strlen($pack)); else $wr=fwrite($this->socket,$pack);
- if (!$wr) {
- $this->error='Соединение закрыто';
- return false;
- }
- $this->makeinfo();
- return false;
- }
- return true;
- }
- function read_message() {
- while($this->getpacket()) {
- $body=$this->body;
- if ($msg['family']==4&&$msg['subtype']==7) {
- $channel=$msg['channel'];
- for ($i=0;$i<=$msg['TLVnumber'];$i++) {
- $this->type=$arr[1];
- $this->size=$arr[2];
- if ($channel==1&&$this->type==2) {
- if ($frg['id']==1&&$frg['version']==1) {
- }
- }
- $message=false;
- }
- }
- }
- } else $message=false;
- }
- return false;
- }
- function disconnect() {
- $this->socket=false;
- }
- var $types=array('UIN'=>1,'DATA'=>2,'CLIENT'=>3,'ERROR_URL'=>4,'RECONECT_HERE'=>5,'COOKIE'=>6,'SNAC_VERSION'=>7,'ERROR_SUBCODE'=>8,'DISCONECT_REASON'=>9,'RECONECT_HOST'=>10,'URL'=>11,'DEBUG_DATA'=>12,'SERVICE'=>13,'CLIENT_COUNTRY'=>14,'CLIENT_LNG'=>15,'SCRIPT'=>16,'USER_EMAIL'=>17,'OLD_PASSWORD'=>18,'REG_STATUS'=>19,'DISTRIB_NUMBER'=>20,'PERSONAL_TEXT'=>21,'CLIENT_ID'=>22,'CLI_MAJOR_VER'=>23,'CLI_MINOR_VER'=>24,'CLI_LESSER_VER'=>25,'CLI_BUILD_NUMBER'=>26);
- var $socet,$channel,$sequence,$body,$uin,$type,$size,$error;
- function getpacket() {
- if ($this->method) {
- if ($header) {
- $this->channel=$header['channel2'];
- return true;
- } else return false;
- }
- } else {
- if($this->socket) {
- if ($header) {
- $this->channel=$header['channel2'];
- return true;
- } else return false;
- }
- }
- }
- function makeinfo() {
- $this->getpacket();
- while ($array['int']!=$this->request_id) {
- $this->getpacket();
- }
- $this->error='Неизвестный ответ сервера';
- if ($array['int1']==4) {
- switch ($array['int2']) {
- case 1: $this->error='Error to sent message'; return false; break;
- case 12: return true; break;
- }
- }
- $this->error='Неизвестный ответ сервера';
- return false;
- }
- function setoption($type,$val,$len=false) {
- switch ($len) {
- case 1: $format='c'; break;
- case 2: $format='n'; break;
- case 4: $format='N'; break;
- default: $format='a*'; break;
- }
- }
- function prepare() {
- $this->sequence++;
- return $out;
- }
- }
- ?>