home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.madoka.org
/
2014.12.ftp.madoka.org.tar
/
ftp.madoka.org
/
pub
/
plum
/
2.x
/
plum2_15_2.lzh
/
module
/
ctcp
/
dcc
/
gate.plm
< prev
next >
Wrap
Text File
|
1997-12-22
|
7KB
|
224 lines
# <!-- -*- perl -*-
# $Id: gate.plm,v 2.3 1997/12/23 00:14:41 hasegawa Exp $
# copyright (c)1997 pupu_j <hasegawa@agusa.nuie.nagoya-u.ac.jp>
package ctcp_dcc_gate;
$READSIZE = 4096;
$REPLYSIZE = 4;
$CLIENTINFO = 'DCC';
$SOCKADDR = 'S n N x8';
$_ = 'ctcp_dcc_gate';
sub main_loop {
foreach $dccclientno (&'array($dccclientlist)) {
&dcc_client($dccclientno) if vec($'rout, $dccclientno, 1);
}
foreach $dccserverno (&'array($dccserverlist)) {
&dcc_server($dccserverno) if vec($'rout, $dccserverno, 1);
}
foreach $dcclistenno (&'array($dcclistenlist)) {
&dcc_accept($dcclistenno) if vec($'rout, $dcclistenno, 1);
}
}
sub cpss_dcc {
local($serverno, $prefix, $cmd, $msg) = @_;
local($userno, $regex, @params);
$userno = $'userno[$serverno];
foreach $not (&'property($userno, 'not')) {
$regex = &'regex($not);
return ($prefix, $cmd, $msg) if $prefix =~ /$regex/i;
}
foreach $user (&'property($userno, 'user')) {
$regex = &'regex($user);
next unless $prefix =~ /$regex/i;
@params = &server_gate($serverno, $prefix, split(/\s+/, $msg));
if (@params) {
return ($prefix, $cmd, join(' ', @params));
} else {
return ();
}
}
return ($prefix, $cmd, $msg)
}
sub cpsp_dcc {
local($serverno, $prefix, $cmd, $msg) = @_;
local($userno, $regex, @params);
$userno = $'userno[$serverno];
foreach $not (&'property($userno, 'not')) {
$regex = &'regex($not);
return ($prefix, $cmd, $msg) if $prefix =~ /$regex/i;
}
foreach $user (&'property($userno, 'user')) {
$regex = &'regex($user);
if ($prefix =~ /$regex/i) {
@params = &client_gate($serverno, $prefix, split(/\s+/, $msg));
if (@params) {
return ($prefix, $cmd, join(' ', @params));
} else {
return ();
}
}
}
return ($prefix, $cmd, $msg);
}
sub dcc_client {
local($dccclientno) = @_;
local($input, $output, $tmp);
$input = $'socket[$dccclientno];
$tmp = '';
if (sysread($input, $tmp, $REPLYSIZE)) {
$output = $'socket[$dccpeer[$dccclientno]];
print $output $tmp if fileno($output);
} else {
&'close($dccclientno);
$dccclientlist = &'remove($dccclientlist, $dccclientno);
}
}
sub dcc_server {
local($dccserverno) = @_;
local($input, $output, $tmp);
$input = $'socket[$dccserverno];
$tmp = '';
if (sysread($input, $tmp, $READSIZE)) {
$output = $'socket[$dccpeer[$dccserverno]];
print $output $tmp if fileno($output);
} else {
&'close($dccserverno);
$dccserverlist = &'remove($dccserverlist, $dccserverno);
}
}
sub dcc_accept {
local($dcclistenno) = @_;
local($dccclientno, $dccserverno);
if ($dccclientno = &'accept($dcclistenno)) {
$dccserverno = $dccpeer[$dcclistenno];
$dccpeer[$dccclientno] = $dccserverno;
$dccpeer[$dccserverno] = $dccclientno;
vec($'rin, $dcclistenno, 1) = 0;
$dcclistenlist = &'remove($dcclistenlist, $dcclistenno);
$dccclientlist = &'add($dccclientlist, $dccclientno);
$dccserverlist = &'add($dccserverlist, $dccserverno);
}
&'close($dcclistenno);
}
sub server_gate {
local($serverno, $prefix, @params) = @_;
local($dccsereverno, $dcclistenno, $host, $port);
if ($params[0] eq 'SEND') {
if ($dcclistenno = &'listen(0, 1)) {
if (!($dccserverno = &'connect($params[2], $params[3]))) {
&'close($dcclistenno);
return @params;
}
$dcclistenlist = &'add($dcclistenlist, $dcclistenno);
$dccpeer[$dcclistenno] = $dccserverno;
$params[3] = (unpack($SOCKADDR, getsockname($'socket[$dcclistenno])))[1];
foreach $cno (&'array($'clientlist)) {
next unless $'avail[$cno];
next unless $'userno[$cno] == $'userno[$serverno];
$params[2] = (unpack($SOCKADDR, getsockname($'socket[$cno])))[2];
&'c_print($cno, $prefix, 'PRIVMSG', $'nick[$cno], "\cA" . join(' ', 'DCC', @params) . "\cA");
}
return ();
}
} elsif ($params[0] eq 'CANCEL') {
$host = (unpack($SOCKADDR, getsockname($'socket[$serverno])))[2];
if ($host == $params[2]) {
foreach $lno (&'array($dcclistenlist)) {
$port = (unpack($SOCKADDR, getsockname($'socket[$lno])))[1];
next unless $port == $params[3];
&'close($lno);
$dcclistenlist = &'remove($dcclistenlist, $lno);
&'close($dccpeer[$lno]);
return ();
}
}
}
return @params;
}
sub client_gate {
local($serverno, $prefix, @params) = @_;
local($dccsereverno, $dcclistenno, $host, $port);
if ($params[0] eq 'SEND') {
if ($dcclistenno = &'listen(0, 1)) {
if (!($dccserverno = &'connect($params[2], $params[3]))) {
&'close($dcclistenno);
return @params;
}
$dcclistenlist = &'add($dcclistenlist, $dcclistenno);
$dccpeer[$dcclistenno] = $dccserverno;
$params[2] = (unpack($SOCKADDR, getsockname($'socket[$dccserverno])))[2];
$params[3] = (unpack($SOCKADDR, getsockname($'socket[$dcclistenno])))[1];
return @params;
}
} elsif ($params[0] eq 'CANCEL') {
foreach $lno (&'array($dcclistenlist)) {
$port = (unpack($SOCKADDR, getsockname($'socket[$lno])))[1];
next unless $port == $params[3];
foreach $cno (&'array($'clientlist)) {
next unless $'avail[$cno];
next unless $'userno[$cno] == $'userno[$serverno];
$host = (unpack($SOCKADDR, getsockname($'socket[$cno])))[2];
next unless $host == $params[2];
&'close($lno);
$dcclistenlist = &'remove($dcclistenlist, $lno);
&'close($dccpeer[$lno]);
return ();
}
}
}
return @params;
}
__END__
--><!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<HTML><HEAD><TITLE> ctcp/dcc.gate.plm </TITLE></HEAD><BODY>
$B%*%s%i%$%s%I%-%e%a%s%H(B
<HR><H3> $BL>A0(B </H3>
ctcp/dcc/gate.plm - CTCP DCC SEND$B$KH?1~$7$FE>Aw$NCf7Q$r9T$&(B
<HR><H3> $B@bL@(B </H3>
CTCP DCC SNED$B$,Aw$i$l$F$-$?$H$-!"(B
$BAw$j85$H%/%i%$%"%s%H$N4V$N%U%!%$%k$NAw<u?.$NCf7Q$r9T$$$^$9!#(B
<HR><H3> $B%W%m%Q%F%#(B </H3>
<DL>
<DT> ctcp.dcc.gate.not* $B%f!<%6%^%9%/(B
<DD> $B%U%!%$%k$rAw?.$7$F$-$??M$,$3$3$G;XDj$5$l$?$b$N$K%^%C%A$7$?$i!"(B
$BE>Aw$NCf7Q$O$7$^$;$s!#(B
<DT> ctcp.dcc.gate.user* $B%f!<%6%^%9%/(B
<DD> $B%U%!%$%k$rAw?.$7$F$-$??M$,$3$3$G;XDj$5$l$?$b$N$K%^%C%A$7$?$i!"(B
$BE>Aw$NCf7Q$r$7$^$9!#(B
</DL>
<HR><H3> $B@_DjNc(B </H3>
<PRE>
+ ctcp/dcc/gate.plm
ctcp.dcc.gate.not: *!*@*.nagoya-u.ac.jp
ctcp.dcc.gate.user: *!*@*
</PRE>
$B%U%!%$%k$rAw$C$F$-$??M$,!V(B*!*@*.nagoya-u.ac.jp$B!W$K%^%C%A$7$J$1$l$P!"(B
$BE>Aw$NCf7Q$r9T$$$^$9!#(B
</BODY></HTML>