Hi everyone, I'm new here aswell to php
I have this script I'm working on, trying to understand it, it worked out so far until I get to the commands pack, unpack and the part where it is written to disk and then read from disk:
pack part:
$peer_ip = pack("C", $peer_ip[0], $peer_ip[1], $peer_ip[2], $peer_ip[3]);
$peer_port = pack("n", (int)$_GET['port']);
$handle = fopen($info_hash, "rb+");
flock($handle, LOCK_EX);
$peer_num = intval(filesize($info_hash) / 7);
$data = fread($handle, $peer_num 7);
$peer = array();
$updated = false;
for($i=0;$i<$peer_num;$i++)
{
if($peer_ip . $peer_port == substr($data, $i 7 + 1, 6))
{
$updated = true;
if($_GET['event'] == 'stopped')
{
$peer_num--;
}
else
{
$peer[$i] = $time . $peer_ip . $peer_port;
}
}
else
{
$peer[$i] = substr($data, $i * 7, 7);
}
}
if($updated == false)
{
$peer[] = $time . $peer_ip . $peer_port;
$peer_num++;
}
rewind($handle);
ftruncate($handle, 0);
fwrite($handle, join('', $peer), $peer_num * 7);
flock($handle, LOCK_UN);
fclose($handle);
unpack part:
$handle = fopen($info_hash, "rb+");
$x = fread($handle, filesize($info_hash));
$ip = unpack("C", substr($x, $j 7 + 1, 4));
$ip = $ip[1] . '.' . $ip[2] . '.' . $ip[3] . '.' . $ip[4];
$port = join('', unpack("n", substr($x, $j 7 + 5, 2)));
$t_peer_seed = join('', unpack("C", substr($x, $j * 7, 1)));
the script I pasted here does not work! I only pasted the parts wich matter in this question!
first I dont understand where they get this numer 7, it pops out all the time
what I would like to ad extra info to the $data array? say I wanted to add uploaded wich ist in bytes so it would be al long string right?
could anyone who is good at php explane exactly what is done at each ommand? this way I can understand the code and I can modify it. (ofcource only if you are in the mood for it, it is a lot of work, thanks 🙂)
thanks in advance for any help on this,
Shai-Hulud