DirectConnect

amp_god 13.01.04 19:09

Yhdistää & authaa itsensä DC hubille...

 Tekstiversio  Arvo: 2 (4 ääntä)  Äänestä: +  -
[code]
<?php
## Config ##
$host = "127.0.0.1";
$port = "411";
$username = "nickname";
$password = "salasana";
$email = "osoite@netissa.com"; # Sähköposti..
$sharesize = "0"; # "jaon" koko...
$debug = FALSE# Jos haluaa nähdä Liikenteen scriptin ja serverin välillä niin muuta FALSE -> TRUE
############
function lock2key($_LOCK) {

   $lockLength = strlen ($_LOCK);

   $h = ord($_LOCK{0}) ^ ord( $_LOCK{ $lockLength - 1} ) ^ ord( $_LOCK{ $lockLength - 2} ) ^ 5;

   #echo $h . "<br>";

    while ($h > 255) {$h = $h - 256;}

    $h = (($h<<4) & 240) | (($h>>4) & 15);

   $a = $h;

   if ($a == '126' or // '~'
       $a == '124' or // '|'
       $a == '96' or  // '`'
       $a == '36' or  // '$'
       $a == '5' or   // '^E'
       $a == '0')     // NUL
   {
     $LockToKey = "/%DCN";

     if ($a < 100)
       $LockToKey .="0";
     if ($a < 10)
       $LockToKey .="0";
      $LockToKey .= $a; // As a string integer
     $LockToKey .= "%/";
   } else {
     $LockToKey = chr ($a)// No transformation.
   }

   for ($j = 1; $j < strlen($_LOCK); $j++) {
      $h = ord($_LOCK{$j}) ^ ord($_LOCK{$j-1});

   while ($h > 255) {$h = $h - 256;}

      $h = (($h<<4) & 240) | (($h>>4) & 15);

      #echo $j . " - " . ($h*16) . "<br>";

     $a = $h;

   if ($a == '126' or // '~'
       $a == '124' or // '|'
       $a == '96' or  // '`'
       $a == '36' or  // '$'
       $a == '5' or   // '^E'
       $a == '0')     // NUL
   {
     $LockToKey .= "/%DCN";

     if ($a < 100)
       $LockToKey .="0";
     if ($a < 10)
       $LockToKey .="0";
      $LockToKey .= $a; // As a string integer
     $LockToKey .= "%/";
   } else {
     $LockToKey .= chr ($a)// No transformation.
   }
   }

   return $LockToKey;
}
function haerivi ($conn) {
  while($data != "\n") {
    $data = fread($conn,1);
    $out .= "$data";
  }
  return($out);
}
function haerivi_dc ($conn) {
  global $debug;
  while($data != "|") {
    $data = fread($conn,1);
    if($data != "|") { $out .= "$data"; }
  }
  if($debug) { print("Received: $out\n"); }
  return($out);
}
function kirjoita_dc ($conn, $text) {
  global $debug;
  $text = "$text|";
  fwrite($conn,$text);
  if($debug) { print("Sent    : $text\n"); }
}
function keskustele_dc($conn, $text) {
  kirjoita_dc($conn, $text);
  $first = " ";
  while($first != "$") {
    $row = haerivi_dc($conn);
    $first = $row[0];
  }
  return $row;
}
function hae_pyynto_dc($conn) {
  $first = " ";
  while($first != "$") {
    $row = haerivi_dc($conn);
    $first = $row[0];
  }
  return $row;
}
$authed = FALSE;
set_time_limit(600);
print("Connecting..............");
$connection = fsockopen($host, $port, $errno, $errstr);
if($connection) {
  print("OK\nAuthing.................");
  while($connection && !$authed) {
    $rivi = hae_pyynto_dc($connection);
    $rivi_p = explode(" ", $rivi);
    if($rivi_p[0] == "\$Lock") {
      ### Lock2Key ###
      $key = lock2key($rivi_p[1]);
      kirjoita_dc($connection, "\$Key $key");
      kirjoita_dc($connection, "\$ValidateNick $username");
      ###############
    }
    if($rivi_p[0] == "\$GetPass") {
      kirjoita_dc($connection, "\$MyPass $password");
    }
    if($rivi_p[0] == "\$Hello") { $authed = TRUE; }
    if($rivi_p[0] == "\$BadPass") { print("Password Failure.."); }
    if($rivi_p[0] == "\$ValidateDenide") { print("Nick validation failed.. nick in use??.."); }
  }
  if($authed) {
    $users = 0; $opers = 0;
    kirjoita_dc($connection, "\$GetNickList");
    $users = sizeof(explode("\$\$", hae_pyynto_dc($connection))); $users--; $users--;
    $opers = sizeof(explode("\$\$", hae_pyynto_dc($connection))); $opers--;
    print("OK, $users users and $opers Operators\n"); }
    kirjoita_dc($connection, '$MyINFO $ALL ' . "$username" . ' $ $7$' . "$email" . '$' . "$sharesize" . '$');
}
  if(!$authed) { print("FAILED\n"); }
}
?>
[/code]
Yhteys jätetetään tahallaan auki... saat lähetettyä vaikka kommenttia DC keskustelukanavalle tyylillä kirjoita_dc($connection, "<$username> Kommentti");
Sulku tapahtuu lopuksi : fclose($connection);

Miggolo 12:31 18.1.04 
Hieno Skripta!
Juuri tälläistä suunnittelin tarvitsevani. Hyvät pohjat kehittää eteenpäin. Vähän on kyllä buginen mutta ei se mitään....
Mistä muuten ton LockToKey:n muodostus syteemin löysit?
amp_god 23:43 19.1.04 
Miggolo, googlella lock2key ;)
amp_god 23:04 31.1.04 
Päivitetty $MyINFO... + oikea tyyli omille viesteille.. (Testattu ja toimii)
OzKu1 18:13 1.4.04 
öö mitä tällä ees tekee?
tomtom 23:06 15.6.04 
Saisko vähän selvennystä että miten tämä toimii käytännössä?
netteri 03:48 11.6.06 
ihan vaan vinkiksi että jos vaihtas ton myinfo rivin ja getuserlistin paikkaa
Arochian 21:13 29.10.06 
luokkatyylisenä tästä saisi aika hyvän.. taidankin alkaa kehittään :p