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
/
send.plm
< prev
Wrap
Text File
|
1998-10-15
|
5KB
|
158 lines
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"><!-- $_ if 0; # -*- perl -*-
# $Id: send.plm,v 2.4 1998/07/31 12:39:13 hasegawa Exp $
# copyright (c)1998 pupu_j <hasegawa@agusa.nuie.nagoya-u.ac.jp>
package ctcp_dcc_send;
$READSIZE = 4096;
$WRITESIZE = 4;
$SOCKADDR = 'S n N x8';
$TIMEOUT = 3600;
$_ = 'ctcp_dcc_send';
sub main_loop {
local($userno) = @_;
local($socket, $length, $size, $tmp, $cno);
foreach $cno (&'array($dccclientlist)) {
if (vec($'rout, $cno, 1)) {
&dcc_client($cno);
vec($'rout, $cno, 1) = 0;
} elsif (time() - $'access[$cno] > $TIMEOUT) {
&'close($cno);
$dccclientlist = &'remove($dccclientlist, $cno);
&'c_print($client[$cno], '', 'NOTICE', $'nick[$client[$cno]], "*** DCC sent file $file[$cno] ($done[$cno]/$size[$cno] bytes) to $nick[$cno]");
}
}
foreach $lno (&'array($dcclistenlist)) {
if (vec($'rout, $lno, 1)) {
&dcc_listen($lno);
vec($'rout, $lno, 1) = 0;
} elsif (time() - $'access[$lno] > $TIMEOUT) {
&'close($lno);
$dcclistenlist = &'remove($dcclistenlist, $lno);
}
}
}
sub cs_send {
local($clientno, $prefix, $cmd, @params) = @_;
local($sno, $lno, $name, $size, $addr, $port, $file);
$sno = $'server[$clientno];
if ($params[1]) {
$file = &'expand($params[1]);
$size = (stat($file))[7];
if ($size) {
foreach $nick (split(/\,/, $params[0])) {
next unless $lno = &'listen(0, 1);
$name = $file;
$name =~ s/^.*[\\\/]([^\\\/]+)$/$1/;
$dcclistenlist = &'add($dcclistenlist, $lno);
$addr = (unpack($SOCKADDR, getsockname($'socket[$sno])))[2];
$port = (unpack($SOCKADDR, getsockname($'socket[$lno])))[1];
$file[$lno] = $file;
$size[$lno] = $size;
$nick[$lno] = $nick;
$client[$lno] = $clientno;
&'s_print($sno, $prefix, 'PRIVMSG', $nick, "\cA" . join(' ', 'DCC', 'SEND', $name, $addr, $port, $size) . "\cA");
&'c_print($clientno, '', 'NOTICE', $'nick[$clientno], "*** DCC SEND request file $file ($size bytes) to $nick");
}
}
}
return ();
}
sub dcc_client {
local($cno) = @_;
local($tmp, $socket, $length);
$tmp = '';
$socket = $'socket[$cno];
if ($length = sysread($socket, $tmp, $WRITESIZE)) {
if (unpack('N', $tmp) == $done[$cno]) {
if ($done[$cno] == $size[$cno]) {
&'close($cno);
$dccclientlist = &'remove($dccclientlist, $cno);
&'c_print($client[$cno], '', 'NOTICE', $'nick[$client[$cno]], "*** DCC sent file $file[$cno] ($size[$cno] bytes) to $nick[$cno]");
} else {
&dcc_send($cno);
}
}
} else {
&'close($cno);
$dccclientlist = &'remove($dccclientlist, $cno);
&'c_print($client[$cno], '', 'NOTICE', $'nick[$client[$cno]], "*** DCC sent file $file[$cno] ($size[$cno] bytes) to $nick[$cno]");
}
}
sub dcc_listen {
local($cno) = @_;
if ($cno = &'accept($lno)) {
$dccclientlist = &'add($dccclientlist, $cno);
$file[$cno] = $file[$lno];
$size[$cno] = $size[$lno];
$nick[$cno] = $nick[$lno];
$done[$cno] = 0;
$client[$cno] = $client[$lno];
&'c_print($client[$cno], '', 'NOTICE', $'nick[$client[$cno]], "*** DCC sending file $file[$cno] ($size[$cno] bytes) to $nick[$cno]");
&dcc_send($cno);
}
$dcclistenlist = &'remove($dcclistenlist, $lno);
&'close($lno);
}
sub dcc_send {
local($cno) = @_;
local($size, $tmp, $socket);
if ($size[$cno] - $done[$cno] < $READSIZE) {
$size = $size[$cno] - $done[$cno];
} else {
$size = $READSIZE;
}
if (open(FILE, $file[$cno])) {
$tmp = '';
seek(FILE, $done[$cno], 0);
if (read(FILE, $tmp, $size)) {
$socket = $'socket[$cno];
print $socket $tmp;
$done[$cno] += $size;
}
close(FILE);
}
}
__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/send.plm</TITLE></HEAD><BODY>
$B%*%s%i%$%s%I%-%e%a%s%H(B
<HR><H3>$BL>A0(B</H3>
ctcp/dcc/send.plm - DCC SEND$B$G%U%!%$%k$rAw?.$9$k(B
<HR><H3>$B@bL@(B</H3>
$B$3$N%b%8%e!<%k$rF~$l$k$H!"(BSEND$B$H$$$&%3%^%s%I$,;H$($k$h$&$K$J$j!"(B
$B$3$N%3%^%s%I$r;H$C$F(BDCC$B$G%U%!%$%k$rAw?.$9$k$3$H$,$G$-$k$h$&$K$J$j$^$9!#(B
SEND$B%3%^%s%I$N%Q%i%a!<%?$O%K%C%/%M!<%`$H%U%!%$%kL>$G!"(B
$B0J2<$N$h$&$K;HMQ$7$^$9!#(B
<PRE>
/SEND nick filename
</PRE>
<HR><H3>$B%W%m%Q%F%#(B</H3>
<HR><H3>$B@_DjNc(B</H3>
<PRE>
+ ctcp/dcc/send.plm
</PRE>
</BODY></HTML>