Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use warnings;
- my $sname="DMS-Trace-Nick"; # origin was "DMS-Nick-Trace"
- my $version="2.1.0"; # origin was "1.6.0"
- Xchat::register($sname, $version, "DMS");
- Xchat::print "\n\n\00312.:: DMS-Trace-Nick ::.\003\n";
- Xchat::print "\00312::: Version $version :::\003\n";
- Xchat::print "\00312::: © DMS '05 :::\003\n\n";
- Xchat::print "\00312::: /emptydb /insertchan #channel until all chan covered then /startautoadd :::\003\n\n";
- my $outputType=0; #0=Join Message, 1=Notice, 2=Server Notice
- #my $lessOut=0;
- my $autoAdd=0; # must be set to 1 to start and/or continue updating db
- my $minMEE=50;
- my $hostmasks=Xchat::get_info("xchatdir");
- my $firsttime="true";
- my $channels;
- $hostmasks="$hostmasks/hostmasks.db";
- my $fh;
- Xchat::hook_print('Join', 'joinHandler',{help_text => 'handles nickchanges'});
- Xchat::hook_server('NICK','nickHandler',{help_text => 'handles joins'});
- Xchat::hook_command('NickTrace','nicktraceHandler',{help_text => 'check for aliases for given nick'});
- Xchat::hook_command('NickTrace_add','nicktraceAddHandler',{help_text => 'usage: /NickTrace_add NICK IDENT HOST/IP'});
- Xchat::hook_command('startautoadd','startautoadd',{help_text => 'usage: /startautoadd'});
- Xchat::hook_command('stopautoadd','stopautoadd',{help_text => 'usage: /stopautoadd'});
- Xchat::hook_command('emptydb', \&emptydb, { help_text => 'create an empty db if autoadd = 0' });
- Xchat::hook_command('insertchan','insertchan', { help_text => 'usage /insertchan #channel' });
- sub readFile{
- $path=shift(@_);
- #if (open(DB, "<","$path")==undef){Xchat::print("file not found: $path");return "";}
- if (!open(DB, "<","$path")){Xchat::print("file not found: $path");return "";}
- @stats=stat(DB);
- my $data;
- read (DB,$data,$stats[7]);
- close (DB);
- return $data;
- }
- sub startautoadd{
- $autoAdd = 1;
- Xchat::printf("Auto-Add STARTED");
- }
- sub stopautoadd{
- $autoAdd = 0;
- Xchat::printf("Auto-Add STOPPED");
- }
- sub emptydb {
- if ($autoAdd==1) {
- Xchat::print("Nicktrace DB not erased do /stopautoadd first");
- } else {
- open ($fh, '>:encoding(UTF-8)', $hostmasks);
- close $fh;
- $firsttime = "true";
- $channels = "";
- Xchat::print("Nicktrace DB erased - cleaned - emptied :-)");
- }
- }
- sub insertchan {
- my $who_hook;
- my $end_hook;
- my $channel = $_[0][1];
- return EAT_XCHAT unless $channel;
- if ($autoAdd==1) {
- Xchat::print("Nicktrace DB not erased do /stopautoadd first");
- } else {
- if ($firsttime eq "true") {
- $channels = $channel;
- } else {
- $channels = $channels . ", " . $channel;
- }
- $who_hook = hook_server('352', sub {
- my($chan1,$ident1, $hostmask1, $server1, $nick1 )=(split " ", $_[1][3]);
- $db=readFile($hostmasks);
- open(DB, ">$hostmasks");
- foreach $line(split "\n", $db){
- my($n,$i, $h)=(split "=", $line);
- print DB "$n=$i=$h\n" if (($n ne $nick1)||($i ne $ident1)||($h ne $hostmask1));
- }
- print DB "$nick1=$ident1=$hostmask1\n";
- close(DB);
- }); # LIGNE 89 QUI DONNE l'ERREUR:
- # Error in command callback Undefined subroutine &Xchat::Script::tracenick::hook_server called at (eval 16) line 89.
- $end_hook = hook_server('315', sub {
- if ($firsttime eq "true") {
- Xchat::print("Nicktrace DB populated with users on channel: $channels");
- } else {
- Xchat::print("Nicktrace DB populated with users on channels: $channels");
- }
- $firsttime = "nottrue";
- unhook($who_hook);
- unhook($end_hook);
- });
- # now send the /who
- command("who $channel");
- return EAT_XCHAT;
- }}
- sub nicktraceHandler{
- $nick=$_[0][1];
- if (!$nick){Xchat::print("you have to give nick as argument");return Xchat::EAT_ALL;}
- my $data=Xchat::user_info("$nick");
- if (!$data){
- Xchat::print("invalid user");
- return Xchat::EAT_ALL;
- }
- $host=$data->{"host"};
- @parts=split("@",$host);
- $akas=checkAlias($nick,$parts[0],$parts[1]);
- Xchat::printf("$nick$akas");
- return Xchat::EAT_ALL;
- }
- sub checkAlias{
- $nick=shift(@_);
- $ident=shift(@_);
- $hostmask=shift(@_);
- $aliases="";
- foreach $line (split "\n", readFile($hostmasks)){
- my($n, $i, $h)=(split "=", $line);
- if ($h eq $hostmask){
- if ($n ne $nick){
- $aliases="$aliases aka. $n" if (index($aliases,"aka. $n")==-1);
- }
- }
- }
- return $aliases;
- }
- sub addAlias{
- $nick=shift(@_);
- $ident=shift(@_);
- $hostmask=shift(@_);
- $db=readFile($hostmasks);
- open(DB, ">$hostmasks");
- foreach $line(split "\n", $db){
- my($n,$i, $h)=(split "=", $line);
- print DB "$n=$i=$h\n" if (($n ne $nick)||($i ne $ident)||($h ne $hostmask));
- }
- print DB "$nick=$ident=$hostmask\n";
- close(DB);
- }
- sub nicktraceAddHandler{addAlias($_[0][1],$_[0][2],$_[0][3]);Xchat::print("Added to hostmask.db");return Xchat::EAT_ALL;}
- sub joinHandler{
- $mask=$_[0][2];
- $nick=$_[0][0];
- $chan=$_[0][1];
- if (index($nick,"\002\002")==0){return Xchat::EAT_NONE;}
- @parts2=split("@",$mask);
- $ident=$parts2[0];
- $hostmask=$parts2[1];
- # Xchat::print("Ray: $nick | $chan | $ident | $hostmask ");
- $alias=checkAlias($nick,$ident,$hostmask);
- &addAlias($nick,$ident,$hostmask)if ($autoAdd==1);
- if ($outputType==0){
- my @ret=();
- push(@ret,"\002\002$nick$alias");push(@ret,$chan);push(@ret,"$mask");
- $rVal=Xchat::emit_print('Join',@ret);
- if ($rVal!=1){ #emit_print fails (why ever)
- Xchat::print("emit_print failed (returned $rVal)");
- Xchat::print("\002$nick$alias\002 ($mask) has joined $chan");
- }
- return Xchat::EAT_ALL;
- }
- if ($outputType==1){ #notice
- my @ret=();
- push(@ret,"nickTrace");push(@ret,"\002\002$nick$alias");
- Xchat::set_context("(notices)");
- $rVal=Xchat::emit_print('Notice',@ret);
- if ($rVal!=1){ #emit_print fails (why ever)
- Xchat::print("emit_print failed (returned $rVal)");
- #Xchat::print("\002$nick$alias\002 ($mask) has joined $chan");
- }
- }
- if ($outputType==2){ #server notice
- my @ret=();
- push(@ret,"\002\002$nick$alias");push(@ret,"nickTrace");
- Xchat::set_context("(snotices)");
- $rVal=Xchat::emit_print('Server Notice',@ret);
- if ($rVal!=1){ #emit_print fails (why ever)
- Xchat::print("emit_print failed (returned $rVal)");
- #Xchat::print("\002$nick$alias\002 ($mask) has joined $chan");
- }
- }
- return Xchat::EAT_NONE;
- }
- sub nickHandler{
- $mask=$_[0][0];
- $nick=substr($_[0][2],1);
- @parts1=split("!",$mask);
- @parts2=split("@",$parts1[1]);
- $ident=$parts2[0];
- $hostmask=$parts2[1];
- if ($autoAdd==1) {
- addAlias($nick,$ident,$hostmask);
- }
- return Xchat::EAT_NONE;
- }
- sub mee{
- my $mask1=uc(shift(@_));my $mask2=uc(shift(@_));my $maxLen; my $minLen;
- if (length($mask1)>length($mask2)){$maxLen=length($mask1);$minLen=length($mask2);}
- else {$maxLen=length($mask2);$minLen=length($mask1);}
- for ($i=1;$i<=$minLen;$i++){return int(($i-1)*100/$maxLen) if (substr($mask1,length($mask1)-$i) ne substr($mask2,length($mask2)-$i));}
- return 100;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement