home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.madoka.org
/
2014.12.ftp.madoka.org.tar
/
ftp.madoka.org
/
pub
/
plum
/
2.x
/
plum2_32_1.lzh
/
module
/
ctcp
/
dcc
/
gate.plm
< prev
next >
Wrap
Text File
|
1999-02-20
|
12KB
|
435 lines
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"><!-- $_ if 0; # -*- perl -*-
# $Id: gate.plm,v 2.39 1999/02/09 22:24:50 hasegawa Exp $
# copyright (c)1997-1999 Yoshinori Hasegawa <hasegawa@madoka.org>
package ctcp_dcc_gate;
$RECVSIZE = 65536;
$CLIENTINFO = 'DCC';
$TIMEOUT = 3600;
$_ = 'ctcp_dcc_gate';
sub main_loop {
local($userno) = @_;
local($timeout);
$timeout = &'property($userno, 'timeout') || $TIMEOUT;
foreach $cno (&'array($dccclientlist)) {
next unless $userno[$cno] == $userno;
if (vec($'rout, $cno, 1)) {
&dcc_client($cno);
vec($'rout, $cno, 1) = 0;
} elsif (time() - $'access[$cno] > $timeout) {
&'close($cno);
$dccclientlist = &'remove($dccclientlist, $cno);
&'close($peer[$cno]);
$dccserverlist = &'remove($dccserverlist, $peer[$cno]);
}
}
foreach $sno (&'array($dccserverlist)) {
next unless $userno[$sno] == $userno;
if (vec($'rout, $sno, 1)) {
&dcc_server($sno);
vec($'rout, $sno, 1) = 0;
} elsif (time() - $'access[$sno] > $timeout) {
&'close($sno);
$dccserverlist = &'remove($dccserverlist, $sno);
&'close($peer[$sno]);
$dccclientlist = &'remove($dccclientlist, $peer[$sno]);
}
}
foreach $lno (&'array($dcclistenlist)) {
next unless $userno[$lno] == $userno;
if (vec($'rout, $lno, 1)) {
&dcc_accept($lno);
vec($'rout, $lno, 1) = 0;
} elsif (time() - $'access[$lno] > $timeout) {
&'close($lno);
$dcclistenlist = &'remove($dcclistenlist, $lno);
}
}
}
sub module_disable {
local($userno) = @_;
foreach $cno (&'array($dccclientlist)) {
next unless $userno[$cno] == $userno;
&'close($cno);
$dccclientlist = &'remove($dccclientlist, $cno);
}
foreach $sno (&'array($dccserverlist)) {
next unless $userno[$sno] == $userno;
&'close($sno);
$dccserverlist = &'remove($dccserverlist, $sno);
}
foreach $lno (&'array($dcclistenlist)) {
next unless $userno[$lno] == $userno;
&'close($lno);
$dcclistenlist = &'remove($dcclistenlist, $lno);
}
foreach $sno (&'array($'serverlist)) {
next unless $'avail[$sno];
next unless $'userno[$sno] == $userno;
&delete_address($sno);
}
}
sub server_close {
local($serverno) = @_;
&delete_address($serverno);
}
sub ss_join {
local($serverno, $prefix, $cmd, @params) = @_;
local($nick);
$nick = &'prefix($prefix);
$address{$serverno, $nick} = $prefix;
return ($prefix, $cmd, @params);
}
sub ss_kick {
local($serverno, $prefix, $cmd, @params) = @_;
local($nick);
$nick = &'prefix($prefix);
$address{$serverno, $nick} = $prefix;
return ($prefix, $cmd, @params);
}
sub ss_mode {
local($serverno, $prefix, $cmd, @params) = @_;
local($nick);
$nick = &'prefix($prefix);
$address{$serverno, $nick} = $prefix;
return ($prefix, $cmd, @params);
}
sub ss_nick {
local($serverno, $prefix, $cmd, @params) = @_;
local($nick, $user);
$nick = &'prefix($prefix);
$user = $params[0] . '!' . join('@', (&'prefix($prefix))[1, 2]);
delete $address{$serverno, $nick};
$address{$serverno, $params[0]} = $user;
return ($prefix, $cmd, @params);
}
sub ss_notice {
local($serverno, $prefix, $cmd, @params) = @_;
local($nick);
$nick = &'prefix($prefix);
$address{$serverno, $nick} = $prefix;
return ($prefix, $cmd, @params);
}
sub ss_part {
local($serverno, $prefix, $cmd, @params) = @_;
local($nick);
$nick = &'prefix($prefix);
$address{$serverno, $nick} = $prefix;
return ($prefix, $cmd, @params);
}
sub ss_privmsg {
local($serverno, $prefix, $cmd, @params) = @_;
local($nick);
$nick = &'prefix($prefix);
$address{$serverno, $nick} = $prefix;
return ($prefix, $cmd, @params);
}
sub ss_quit {
local($serverno, $prefix, $cmd, @params) = @_;
local($nick);
$nick = &'prefix($prefix);
delete $address{$serverno, $nick};
return ($prefix, $cmd, @params);
}
sub ss_topic {
local($serverno, $prefix, $cmd, @params) = @_;
local($nick);
$nick = &'prefix($prefix);
$address{$serverno, $nick} = $prefix;
return ($prefix, $cmd, @params);
}
sub ss_302 {
local($serverno, $prefix, $cmd, @params) = @_;
local($nick, $user);
if ($params[1]) {
($nick, $user) = split(/\*?\=[\+\-]/, $params[1]);
$address{$serverno, $nick} = $nick . '!' . $user;
}
return ($prefix, $cmd, @params);
}
sub ss_311 {
local($serverno, $prefix, $cmd, @params) = @_;
local($user);
$address{$serverno, $params[1]} = $params[1] . '!' . $params[2] . '@' . $params[3];
return ($prefix, $cmd, @params);
}
sub ss_352 {
local($serverno, $prefix, $cmd, @params) = @_;
local($nick, $user);
$address{$serverno, $params[5]} = $params[5] . '!' . $params[2] . '@' . $params[3];
return ($prefix, $cmd, @params);
}
sub cpss_dcc {
local($serverno, $prefix, $cmd, @params) = @_;
local($userno, $regex, @msg);
$userno = $'userno[$serverno];
if (&check_mask($userno, $prefix, $params[0])) {
@msg = &server_gate($serverno, $prefix, split(/\s+/, $params[1]));
if (@msg) {
$params[1] = join(' ', @msg);
return ($prefix, $cmd, @params);
} else {
return ();
}
}
return ($prefix, $cmd, @params);
}
sub cpcs_dcc {
local($clientno, $prefix, $cmd, @params) = @_;
local($userno, $regex, @msg, $user, $info, $nick);
$userno = $'userno[$clientno];
$user = $address{$'server[$clientno], $params[0]};
if (!$user) {
foreach $known (&'property($userno, 'known')) {
($info, $nick) = split(/\s+/, $known);
if (!$nick || &'exist(&'list(split(/\,/, $nick)), $params[0])) {
$user = $info;
last;
}
}
if (!$user) {
$user = &'user($clientno);
}
}
if (&check_mask($userno, $user, $params[0])) {
@msg = &client_gate($clientno, $user, split(/\s+/, $params[1]));
if (@msg) {
$params[1] = join(' ', @msg);
return ($prefix, $cmd, @params);
} else {
return ();
}
}
return ($prefix, $cmd, @params);
}
sub delete_address {
local($sno) = @_;
local($no, $nick);
foreach $key (keys(%address)) {
($no, $nick) = split(/$;/, $key, 2);
next unless $no == $sno;
delete $address{$key};
}
}
sub dcc_client {
local($clientno) = @_;
local($socket, $tmp, $recv);
$tmp = '';
$recv = &'property($userno[$clientno], 'recvsize') || $RECVSIZE;
if (sysread($'socket[$clientno], $tmp, $recv)) {
$socket = $'socket[$peer[$clientno]];
print $socket $tmp if fileno($socket);
} else {
&'close($clientno);
$dccclientlist = &'remove($dccclientlist, $clientno);
&'close($peer[$clientno]);
$dccserverlist = &'remove($dccserverlist, $peer[$clientno]);
}
}
sub dcc_server {
local($serverno) = @_;
local($socket, $tmp, $recv);
$tmp = '';
$recv = &'property($userno[$serverno], 'recvsize') || $RECVSIZE;
if (sysread($'socket[$serverno], $tmp, $recv)) {
$socket = $'socket[$peer[$serverno]];
print $socket $tmp if fileno($socket);
} else {
&'close($serverno);
$dccserverlist = &'remove($dccserverlist, $serverno);
&'close($peer[$serverno]);
$dccclientlist = &'remove($dccclientlist, $peer[$serverno]);
}
}
sub dcc_accept {
local($listenno) = @_;
local($cno, $sno, @params);
if ($cno = &'accept($listenno)) {
$userno[$cno] = $userno[$listenno];
@params = &'array($request[$listenno]);
if ($sno = &'connect($params[2], $params[3])) {
$userno[$sno] = $userno[$listenno];
$peer[$cno] = $sno;
$peer[$sno] = $cno;
$dccclientlist = &'add($dccclientlist, $cno);
$dccserverlist = &'add($dccserverlist, $sno);
} else {
&'close($cno);
}
}
&'close($listenno);
$dcclistenlist = &'remove($dcclistenlist, $listenno);
}
sub server_gate {
local($serverno, $prefix, @params) = @_;
local($lno, $host, $port);
if ("\L$params[0]\E" eq 'send' || "\L$params[0]\E" eq 'chat') {
$lno = &'listen(0, 1) || return @params;
$userno[$lno] = $'userno[$serverno];
$request[$lno] = &'list(@params);
$dcclistenlist = &'add($dcclistenlist, $lno);
$params[3] = (&'sockname($lno))[0];
foreach $cno (&'array($'clientlist)) {
next unless $'avail[$cno];
next unless $'server[$cno] == $serverno;
$params[2] = (&'sockname($cno))[1];
&'c_print($cno, $prefix, 'PRIVMSG', $'nick[$cno], "\cA" . join(' ', 'DCC', @params) . "\cA");
}
return ();
} elsif ("\L$params[0]\E" eq 'cancel') {
$host = (&'sockname($serverno))[1];
if ($host == $params[2]) {
foreach $lno (&'array($dcclistenlist)) {
$port = (&'sockname($lno))[0];
next unless $port == $params[3];
&'close($lno);
$dcclistenlist = &'remove($dcclistenlist, $lno);
&'close($peer[$lno]);
return ();
}
}
}
return @params;
}
sub client_gate {
local($clientno, $prefix, @params) = @_;
local($lno, $host, $port, $sno);
$sno = $'server[$clientno];
if ("\L$params[0]\E" eq 'send' || "\L$params[0]\E" eq 'chat') {
$lno = &'listen(0, 1) || return @params;
$userno[$lno] = $'userno[$clientno];
$request[$lno] = &'list(@params);
$dcclistenlist = &'add($dcclistenlist, $lno);
$params[2] = (&'sockname($sno))[1];
$params[3] = (&'sockname($lno))[0];
} elsif ("\L$params[0]\E" eq 'cancel') {
foreach $lno (&'array($dcclistenlist)) {
$port = (&'sockname($lno))[0];
next unless $port == $params[3];
foreach $cno (&'array($'clientlist)) {
next unless $'avail[$cno];
next unless $'server[$cno] == $sno;
$host = (&'sockname($cno))[1];
next unless $host == $params[2];
&'close($lno);
$dcclistenlist = &'remove($dcclistenlist, $lno);
&'close($peer[$lno]);
return ();
}
}
}
return @params;
}
sub check_mask {
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 (&'channel($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@madoka.org">
<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.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%^%C%A$7$?$i!"(B
$B%U%!%$%k$NE>Aw$rCf7Q$7$^$9!#(B
</DD>
<DT> ctcp.dcc.gate.known $B%f!<%6>pJs(B ($B%K%C%/%M!<%`(B)
</DT>
<DD> DCC$B$rAw$kAj<j$N%f!<%6>pJs$,$o$+$i$J$$$?$a$K!"E>Aw$r(B
$BCf7Q$7$F$$$$$+$I$&$+H=CG$G$-$J$$$H$-!"$3$3$G;XDj%f!<%6>pJs$r(B
$B;2>H$7$FH=CG$7$^$9!#$3$3$G$bH=CG$G$-$J$+$C$?>l9g$OBe$o$j$K<+J,$N(B
$B%f!<%6>pJs$r;2>H$7$^$9!#(B
</DD>
</DL>
<HR><H3>$B@_DjNc(B</H3>
<PRE>
+ ctcp/dcc/gate.plm
ctcp.dcc.gate.mask: -*!*@*.nagoya-u.ac.jp
ctcp.dcc.gate.mask: *!*@*
ctcp.dcc.gate.known: plum!plum@agusa.nuie.nagoya-u.ac.jp plum,plum_d
ctcp.dcc.gate.known: unknown!unknown@unknown.jp
</PRE>
$B%U%!%$%k$rAw$C$F$-$??M!"$b$7$/$OAw$m$&$H$7$??M$,(B
$B!V(B*!*@*.nagoya-u.ac.jp$B!W$K%^%C%A$7$J$1$l$P!"E>Aw$NCf7Q$r9T$$$^$9!#(B
$B$^$?!"%U%!%$%k$rAw$m$&$H$7$??M$N%f!<%6>pJs$,$o$+$i$J$$$H$-!"(B
$B$=$N?M$N%K%C%/%M!<%`$,!V(Bplum$B!W$+!V(Bplum_d$B!W$J$i$P!"%f!<%6>pJs$H$7$F!"(B
$B!V(Bplum!plum@agusa.nuie.nagoya-u.ac.jp$B!W$r;HMQ$7$^$9!#(B
$B$=$l0J30$N%K%C%/%M!<%`$N?M$KBP$7$F$O!V(Bunknown!unknown@unknown.jp$B!W$r(B
$B;HMQ$7$^$9!#(B
</BODY></HTML>