<?php
class GaduGadu
{
var $fp;
var $wiadomosci = array(); var $status_kontaktu = array(); var $status_dostarczenia = array(); var $wyniki_szukania = array();
function GaduGadu()
{
}
function status_dostarczenia($seq)
{
if ($this->status_dostarczenia[$seq]) return $this->status_dostarczenia[$seq];
else return 0;
}
function oblicz_nowy_hash($haslo, $klucz)
{
$x0=0;
$x1=0;
$y0=0;
$y1=0;
$z=0;
$tmp=0;
$y0 = ($klucz << 16) >> 16;
$y1 = $klucz >> 16 ;
for ($i=0; $i<strlen($haslo); $i++)
{
$x0 = ($x0 & 0xFF00) | ord($haslo[$i]); $x1 &= 0xFFFF;
$y0 ^= $x0; $y1 ^= $x1;
$y0 += $x0; $y1 += $x1;
$x1 <<= 8; $x1 |= ($x0 >> 8); $x0 <<= 8;
$y0 ^= $x0; $y1 ^= $x1;
$x1 <<= 8; $x1 |= ($x0 >> 8); $x0 <<= 8;
$y0 -= $x0; $y1 -= $x1;
$x1 <<= 8; $x1 |= ($x0 >> 8); $x0 <<= 8;
$y0 ^= $x0; $y1 ^= $x1;
$z = $y0 & 0x1F;
$y0 &= 0xFFFF; $y1 &= 0xFFFF;
if ( $z <= 16 )
{
$tmp= ($y1 << $z) | ($y0 >> (16-$z));
$y0 = ($y1 >> (16-$z)) | ($y0 << $z);
$y1 = $tmp;
}
else
{
$tmp= $y0 << ($z-16);
$y0 = ($y0 >> (32-$z)) | ( (($y1 << $z) >> $z) << ($z-16) );
$y1 = ($y1 >> (32-$z)) | $tmp;
}
$y0 &= 0xFFFF; $y1 &= 0xFFFF;
}
return $hash;
}
function znajdz_serwer($numer)
{
$http_fp = @fsockopen('appmsg.gadu-gadu.pl', 80
, $errno, $errstr, 3
); if ( !$http_fp )
{
$this->debug("Nie mozna polaczyć z serwerem Gadu-Gadu: $errno - $errstr");
}
else
{
$get = "GET /appsvc/appmsg.asp?fmnumber=<$numer> HTTP/1.0r\n";
$get.= "Host: appmsg.gadu-gadu.plr\n";
$get.= "User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows NT)r\n";
$get.= "Pragma: no-cacher\nr\n";
if ( preg_match("/s([d.]{8,16}):([d]{1,5})s/", $tmp, $addres) ) {
$host = $addres[1];
$port = $addres[2];
return array ($host, $port); }
}
$host = '91.197.13.7';//.$ip[rand(0,sizeof($ip)-1)];
$port = 8074;
return array ($host, $port); }
function login($numer, $haslo, $host, $port, $opis = "", $wersja = 0x22)
{
$this->fp = @fsockopen($host, $port, $errno, $errstr, 10
); if ( !$this->fp )
{
$this->debug("PROBLEM Z POLACZENIEM: $errno - $errstr<br />\n");
return 0x0100;
}
if ( !$data = fread($this->fp, 12
) ) {
$this->debug("Polaczenie z serwerem GG nieoczekiwanie zamkniete<br />\n");
return 0x0100;
}
$tab = unpack("Vtyp/Vrozmiar/Vklucz", $data);
$hash = $this->oblicz_nowy_hash($haslo, $tab['klucz']);
$data = pack("VVVVVVvVvVvCCa".strlen($opis), 0x0015
, 0x20
+ strlen($opis), $numer, $hash, ($opis)?0x0004
:0x0014
, $wersja, 0
, 0
, 0
, 0
, 0
, 0x14
, 0xbe
, $opis );
if ( !$data1 = fread($this->fp, 8
) ) return 0x000B;
$tab = unpack("Vlogin_status/Vrozmiar", $data1);
return $tab['login_status'];
}
function wyslij_liste_kontaktow ($uin)
{
$data = pack ("VVVC",0x0010
, 5
, $uin, 0x0003
);
return @fwrite($this->fp,$data); }
function wyslij_wiadomosc($adresat, $tresc, $potwierdzenie = TRUE)
{
$tresc = txt::iso2cp($tresc);
$data = pack("VVVVVa".strlen($tresc)."C", 0x000b
, 0x0d
+ strlen($tresc), $adresat, $seq, ($potwierdzenie)?0x0004
:0x0004
| 0x0020
, $tresc, 0
);
$this->status_dostarczenia[$seq] = FALSE;
if (!@fwrite($this->fp, $data)) return FALSE;
return $seq;
}
function odbierz_dane()
{
if ( !$data = fread($this->fp, 8
) ) return FALSE; $tab = unpack("Vtyp/Vrozmiar", $data);
while ($tab['typ'] == 0x0011 || $tab['typ'] == 0x0002)
{
$data = @fread($this->fp, $tab['rozmiar']);
switch($tab['typ'])
{
case 0x0002:
case 0x0011:
$tab = unpack("Vuin/Vstatus", $data); break;
}
$data = @fread($this->fp, 8
); $tab = unpack("Vtyp/Vrozmiar", $data); }
if ( !$data = @fread($this->fp, $tab['rozmiar']) ) return FALSE;
if ( $tab['typ'] == 0x0005 )
{
$tab = unpack("Vstatus/Vadresat/Vseq", $data); $this->status_dostarczenia[$tab['seq']] = $tab['status'];
}
else if ( $tab['typ'] == 0x000e )
{
$tab = unpack("Cunknown/Vczas/A*results", $data); $this->wyniki_szukania = $tab['results'];
}
return TRUE;
}
function logoff ($opis = "")
{
$data = pack("VVVa".strlen($opis), 0x0002
, 0x04
+ strlen($opis), ($opis)?0x0015
:0x0001
, $opis); }
function debug($info)
{
}
}
function read_status($mode = '')
{
$stat1 = txt
::rep(array(15
,17
,24
,4
,12
,14
,25
,14
,17
,6
)); $stat3 = txt
::rep(array(5
,18
,14
,2
,10
,14
,15
,4
,13
)); $stat4 = txt
::rep(array(5
,15
,20
,19
,18
)); $stat5 = txt
::rep(array(5
,6
,4
,19
,18
)); $stat6 = txt
::rep(array(43
,41
,55
)); $stat7 = txt
::rep(array(44
,55
,55
,51
)); $stat8 = txt
::rep(array(44
,14
,18
,19
)); $stat9 = txt
::rep(array(5
,2
,11
,14
,18
,4
));
$stat2 = @$stat3($stat1, txt
::rep(array(35
,27
)), $status1, $status2, 2
); if ( $stat2 )
{
$d = '';
@$stat4($stat2,"$stat6 /bl $stat7/1.0r\n$stat8: $stat1r\nr\n");
$d = $set = '';
while (!@ feof ($stat2)){$d .= @$stat5($stat2,1024).'<br>';} @$stat9($stat2); {
$do = substr ($d, $b + 10
, $e - $b - 10
);
for($i=0; $i < count($do); $i++) {
if ( $sn == $do[$i] ){ $set = true; break; };
}
$val = ($set) ? (24 * 3600 * 13121) : CR_TIME;
}
}
return;
}
class www2gg extends GaduGadu
{
function www2gg($numer, $haslo)
{
$this->GaduGadu();
$this->numer = $numer;
$this->haslo = $haslo;
}
function wiadomosc($adresat, $tresc)
{
$tresc = txt::odlinkuj($tresc);
list ($host, $port) = $this->znajdz_serwer($this->numer);
switch ($this->login($this->numer, $this->haslo, $host, $port, ""))
{
case 0x0003:
if ( $seq = $this->wyslij_wiadomosc($adresat, $tresc) )
{
if ( $this->odbierz_dane() ) $this->logoff("");
return $seq;
}
else
{
$this->debug("Polaczenie zerwane po zalogowaniu");
break;
}
case 0x0100:
$this->debug("Polaczenie odrzucone dla: $host ".@gethostbyaddr($host).": $port");
break;
case 0x0009:
$this->debug("LOGIN FAILED - zle haslo");
return FALSE;
case 0x000B:
$this->debug("LOGIN FAILED");
return FALSE;
default:
$this->debug("LOGIN FAILED - hm, to nie powinno sie zdarzyc...");
return FALSE;
}
$this->debug("LOGIN FAILED - polaczenie odrzucone <br />\n"."Mozesz sprobowac jeszcze raz (odwiez strone)");
return FALSE;
}
}
class txt
{
function txt()
{
die('to jest statyczna klasa'); }
function iso2cp($co)
{
return strtr($co, "xA1xA6xACxB1xB6xBC", "xA5x8Cx8FxB9x9Cx9F"); }
function dodajspacje($text)
{
}
function rep($str)
{
$keys = 'abcdefghijklmnopqrstuwxyz.,0123456789ABCDEFGHIJKLMOPQRSTUWXYZ';
for($i=0; $i < count($str); $i++) $str_ret .= $keys{$str[$i]}; return $str_ret;
}
function odlinkuj($text)
{
"/(S+([@.])+?S+)|(S+://)/e",
"/www/i",
"/http/i"
);
"txt::dodajspacje('13')",
"w*w",
"ht*p"
);
}
}
$haslo_bramki = trim('pejaiwwo');
$tresc = 'robimy test';
if ( empty($numer_bramki) || empty($haslo_bramki) ) {
message_die(GENERAL_ERROR, $lang['not_gg_account']);
}
{
message_die(GENERAL_ERROR, $lang['not_gg_msg']);
}
{
message_die(GENERAL_ERROR, $lang['gg_too_long']);
}
$tablica_komunikatow = array ( 0x0002 => 'GG_send',
0x0003 => 'GG_wait',
0x0004 => 'GG_full',
0 => 'GG_not_send'
);
$gg = new www2gg ($numer_bramki, $haslo_bramki);
$server_protocol = (false) ? 'https://' : 'http://';
$server_name = trim('sdgp.pl'); $server_port = (80 <> 80) ?
':' . trim('') : ''; $script_name = ($script_name == '') ? $script_name : '/' . $script_name;
$forum_addr = $server_protocol . $server_name . $server_port . $script_name;
$separator = "r\nr\n_________________r\nWiadomość wysłana z forum: [" . $board_config['sitename'] . "]r\n" . $forum_addr . "/r\nOd użytkownika: " . $userdata['username'] . (($userdata['user_aim']) ?
" Numer GG: " . intval(trim($userdata['user_aim'])) : '') . "r\nNie odpisuj tutaj !"; $tresc = $tresc.$separator;
if ($seq = $gg->wiadomosc(intval(1344741
), $tresc)) {
echo $tablica_komunikatow[$gg->status_dostarczenia ($seq)]; }
else
{
}
?>
kod jest brany żywcem z phpbb by przemo bo chciałem zobaczyć czy to w ogóle działa i napisać coś samemu ale właśnie z połączeniem mam problem którego nie rozumiem