home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.madoka.org
/
2014.12.ftp.madoka.org.tar
/
ftp.madoka.org
/
pub
/
plum
/
2.x
/
plum2_28_2.lzh
/
module
/
ctcp
/
dcc
/
get.plm
< prev
next >
Wrap
Text File
|
1998-10-15
|
6KB
|
226 lines
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"><!-- $_ if 0; # -*- perl -*-
# $Id: get.plm,v 2.26 1998/08/27 02:47:24 hasegawa Exp $
# copyright (c)1997-1998 pupu_j <hasegawa@agusa.nuie.nagoya-u.ac.jp>
package ctcp_dcc_get;
$READSIZE = 4096;
$DIRECTORY = '.';
$MODE = umask() ^ 0666;
$CLIENTINFO = 'DCC';
$TIMEOUT = 3600;
$_ = 'ctcp_dcc_get';
sub main_loop {
local($userno) = @_;
local($socket, $length, $size, $tmp);
foreach $sno (&'array($dccserverlist)) {
if (vec($'rout, $sno, 1)) {
if ($size[$sno] - $done[$sno] < $READSIZE) {
$size = $size[$sno] - $done[$sno];
} else {
$size = $READSIZE;
}
$tmp = '';
$socket = $'socket[$sno];
if ($length = sysread($socket, $tmp, $size)) {
if (open(FILE, ">>$file[$sno]")) {
select((select(FILE), $| = 1)[0]);
print FILE $tmp;
close(FILE);
}
$done[$sno] += $length;
print $socket pack('N', $done[$sno]);
if ($done[$sno] >= $size[$sno]) {
&dcc_close($sno);
}
} else {
&dcc_close($sno);
}
vec($'rout, $sno, 1) = 0;
} elsif (time() - $'access[$sno] > $TIMEOUT) {
&'close($sno);
$dccserverlist = &'remove($dccserverlist, $sno);
}
}
}
sub cpss_dcc {
local($serverno, $prefix, $cmd, @params) = @_;
local($userno, $regex);
$userno = $'userno[$serverno];
if (&checkmask($userno, $prefix, $params[0])) {
($cmd, $params[1]) = &dcc_open($serverno, $cmd, $params[1]);
return ($prefix, $cmd, @params);
}
return ($prefix, $cmd, @params);
}
sub dcc_open {
local($serverno, $cmd, $msg) = @_;
local($userno, $nick, $dir, $name, $mode, @params, $sno);
$userno = $'userno[$serverno];
$nick = &'prefix($prefix);
@params = split(/\s+/, $msg);
if ("\L$params[0]\E" eq 'send') {
$dir = &'expand(&'property($userno, 'directory') || $DIRECTORY);
$name = &newfile($dir, $params[1]);
if (open(FILE, ">$name")) {
close(FILE);
$mode = &'property($userno, 'mode');
if (defined($mode)) {
$mode = oct($mode) | 0200;
} else {
$mode = $MODE | 0200;
}
chmod($mode, $name);
if ($sno = &'connect($params[2], $params[3])) {
$file[$sno] = $name;
$size[$sno] = $params[4];
$done[$sno] = 0;
$nick[$sno] = $nick;
$server[$sno] = $serverno;
$userno[$sno] = $userno;
$dccserverlist = &'add($dccserverlist, $sno);
foreach $cno (&'array($'clientlist)) {
next unless $'avail[$cno];
next unless $'server[$cno] == $serverno;
&'c_print($cno, '', 'NOTICE', $'nick[$cno], "*** DCC SEND request from $nick: $params[1] ($params[4] bytes)");
&'c_print($cno, '', 'NOTICE', $'nick[$cno], "*** DCC getting file $name ($params[4] bytes) from $nick");
}
return ();
}
}
}
return ($prefix, $cmd, $msg);
}
sub dcc_close {
local($sno) = @_;
foreach $cno (&'array($'clientlist)) {
next unless $'avail[$cno];
next unless $'server[$cno] == $server[$sno];
&'c_print($cno, '', 'NOTICE', $'nick[$cno], "*** DCC got file $file[$sno] ($size[$sno] bytes) from $nick[$sno]");
}
&'close($sno);
$dccserverlist = &'remove($dccserverlist, $sno);
}
sub newfile {
local($dir, $file) = @_;
local($name, $ext);
$file =~ s/^.*[\\\/]([^\\\/]+)$/$1/;
$name = "$dir/$file";
if (-e $name) {
$ext = '';
if (rindex($file, '.') > 0) {
$ext = substr($file, rindex($file, '.'));
$file = substr($file, 0, rindex($file, '.'));
}
$num = 1;
$name = "$dir/$file-$num$ext";
while (-e $name) {
$num++;
$name = "$dir/$file-$num$ext";
}
}
return $name;
}
sub checkmask {
local($userno, $prefix, $chan) = @_;
local($user, $chlist, $list);
foreach $mask (&'property($userno, 'mask')) {
($user, $chlist) = split(/\s+/, $mask);
$list = '';
foreach $vchan (split(/\,/, $chlist || '')) {
$list = &'add($list, &'real($vchan));
}
if ($chan =~ /^[\#\&\+]/) {
next unless (!$list || &'exist($list, $chan));
} else {
next unless (!$list || &'exist($list, '*'));
}
if ($user =~ /^\-/) {
$regex = &'regex(substr($user, 1));
return 0 if $prefix =~ /$regex/i;
}
if ($user =~ /^\+/) {
$regex = &'regex(substr($user, 1));
} else {
$regex = &'regex($user);
}
return 1 if $prefix =~ /$regex/i;
}
return 0;
}
__END__
--><HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-2022-JP">
<LINK REV="made" HREF="mailto:hasegawa@agusa.nuie.nagoya-u.ac.jp">
<TITLE>ctcp/dcc.get.plm</TITLE></HEAD><BODY>
$B%*%s%i%$%s%I%-%e%a%s%H(B
<HR><H3>$BL>A0(B</H3>
ctcp/dcc/get.plm - DCC SEND$B$KH?1~$7$FAw$i$l$F$-$?%U%!%$%k$r<u$1<h$k(B
<HR><H3>$B@bL@(B</H3>
DCC SEND$B%j%/%(%9%H$,Aw$i$l$F$-$?$H$-!"(B
$B$=$l$KH?1~$7$FAw$i$l$F$-$?%U%!%$%k$r<+F0E*$K<u?.$7$^$9!#(B
<HR><H3>$B%W%m%Q%F%#(B</H3>
<DL>
<DT> ctcp.dcc.get.directory $B%G%#%l%/%H%j(B
</DT>
<DD> $B<u?.$7$?%U%!%$%k$rCV$/%G%#%l%/%H%j$r;XDj$7$^$9(B
$B%G%#%l%/%H%j$,B8:_$7$J$$$H$-$d!"(B
$B%G%#%l%/%H%j$K=q$-9~$_$,$G$-$J$$$H$-$O%U%!%$%k$r<u?.$7$^$;$s!#(B
$B%G%U%)%k%H$G$O%+%l%s%H%G%#%l%/%H%j$G$9!#(B
</DD>
<DT> ctcp.dcc.get.mask* $B%f!<%6%^%9%/(B [($B%A%c%s%M%kL>(B)]
</DT>
<DD> $B%U%!%$%k$rAw?.$7$F$-$??M$,$3$3$G;XDj$5$l$?$b$N$K%^%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