home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.madoka.org
/
2014.12.ftp.madoka.org.tar
/
ftp.madoka.org
/
pub
/
plum
/
1.x
/
plum10b8.lzh
/
plum10b8
/
dccget.plm
< prev
next >
Wrap
Text File
|
1997-06-25
|
3KB
|
93 lines
package dccget;
$DCCREADSIZE = 4096;
$DCCDIR = '~/tmp';
$_ = 'dccget';
sub main_loop {
local($socket, $length, $size, $tmp);
foreach $dccserverno (&'array($dccserverlist || $;)) {
next unless vec($'rout, $dccserverno, 1);
if ($size[$dccserverno] - $done[$dccserverno] < $DCCREADSIZE) {
$size = $size[$dccserverno] - $done[$dccserverno];
} else {
$size = $DCCREADSIZE;
}
$tmp = '';
$socket = "'$'socket[$dccserverno]";
if ($length = sysread($socket, $tmp, $size)) {
if (open(FILE, ">>$file[$dccserverno]")) {
select((select(FILE), $| = 1)[0]);
print FILE $tmp;
close(FILE);
}
$done[$dccserverno] += $length;
if (int(($done[$dccserverno] - $length) / $DCCREADSIZE) != int($done[$dccserverno] / $DCCREADSIZE)) {
print $socket pack('N', int($done[$dccserverno] / $DCCREADSIZE) * $DCCREADSIZE);
}
if ($done[$dccserverno] == $size[$dccserverno]) {
print $socket pack('N', int($done[$dccserverno]));
&dcc_close($dccserverno);
}
} else {
&dcc_close($dccserverno);
}
}
}
sub xss_dcc {
local($serverno, $prefix, $cmd, @params) = @_;
local($nick) = (&'prefix($prefix))[0];
local($dccserverno, $dir, $dirmode, $filemode, $name, $ext);
$dir = &'expand(&'property($'userno[$serverno], 'dccdir') || $DCCDIR);
$dir .= '/' if substr($dir, -1, 1) ne '/';
$dirmode = oct(&'property($'userno[$serverno], 'dirmode') || 0);
mkdir($dir, ($dirmode || (umask ^ 0777)) | 0200) unless -d $dir;
if ($params[0] eq 'SEND') {
$name = "$dir$params[1]";
if (-f $name) {
$ext = '0';
while (-f "$name.$ext") {
$ext++;
}
$name = "$name.$ext";
}
if (open(FILE, ">$name")) {
close(FILE);
$filemode = oct(&'property($'userno[$serverno], 'filemode') || 0);
chmod(($filemode || (umask ^ 0666)) | 0200, $name);
if ($dccserverno = &'connect($params[2], $params[3])) {
vec($'rin, $dccserverno, 1) = 1;
$file[$dccserverno] = $name;
$size[$dccserverno] = $params[4];
$done[$dccserverno] = 0;
$userno[$dccserverno] = $'userno[$serverno];
$nick[$dccserverno] = $nick;
$dccserverlist = &'add($dccserverlist || $;, $dccserverno);
foreach $clientno (&'array($'clientlist)) {
next unless $'avail[$clientno];
next unless $'userno[$clientno] == $'userno[$serverno];
&'c_print($clientno, '', 'NOTICE', $'nick[$clientno], "*** DCC SEND request from $nick: $params[1] ($params[4] bytes)");
&'c_print($clientno, '', 'NOTICE', $'nick[$clientno], "*** DCC getting file $name ($params[4] bytes) from $nick");
}
return ();
}
}
}
return ($prefix, $cmd, @params);
}
sub dcc_close {
local($dccserverno) = @_;
foreach $clientno (&'array($'clientlist)) {
next unless $'avail[$clientno];
next unless $'userno[$clientno] == $userno[$dccserverno];
&'c_print($clientno, '', 'NOTICE', $'nick[$clientno], "*** DCC got file $file[$dccserverno] ($size[$dccserverno] bytes) from $nick[$dccserverno]");
}
&'close($dccserverno);
vec($'rin, $dccserverno, 1) = 0;
$dccserverlist = &'remove($dccserverlist, $dccserverno);
}