File: op.mpi

package info (click to toggle)
madoka 4.2.3-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 960 kB
  • ctags: 45
  • sloc: perl: 1,006; makefile: 45; sh: 4
file content (127 lines) | stat: -rw-r--r-- 3,534 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# madoka 4.2 op
#
# op.mpi
#    Copyright(c)1998- cookie / The madoka project
#

&list_add($plugin_list, 'op');
&list_add($per_sec, 'set_modes');
&list_add($per_min, 'op_firstloop');
1;

sub check_modes {
  my $chan = $_[0];
  my @modes = &read_modes;
  my $from2 = "$from!$where";
  $from2 =~ s/![~\^\+\-\=]/!/;
  my($chanr, $chanv, $chan_m, $com, $l, $t);
  foreach (@modes) {
    next unless ($_ && /^[^\#]/);
    if (/^\[(.+)\]\s*$/) {
      ($chanr, $chanv) = &alias_chan($1);
      next if !&check_chan($chanr) && $chanr ne 'all';
      if ($chan =~ /^\Q$chanr\E$/i || $chanr =~ /^all$/i) {
	$chan_m = $chanr;
      } else {
	undef $chan_m;
	next;
      }
    } elsif (/^([\+\-][o|b|v])=(.+)$/ && $chan_m) {
      $com = $1;
      $l = $2;
      $l =~ s/\\/\\\\/g;
      $l =~ s/\./\\\./g;
      $l =~ s/\@/\\\@/g;
      $l =~ s/\?/./g;
      $l =~ s/\*/.*/g;
      $l =~ s/\[/\\\[/g;
      $l =~ s/\]/\\\]/g;
      foreach (split(/\s+/, $l)) {
        next unless $from2 =~ /^$_$/i;
        if (/^\^/) {
          s/^\^//;
          last if $from2 =~ /^$_$/i;
          next;
        }
        if ($com eq '+b' || $com eq '-b') {
          &send('sv', "MODE $chan $com :*!$where\n");
	} else {
          $t = time;
          push(@naruto, "$chan $com $from $t");
	  &mes("[check_modes] op_add $chan : $com : $from : $t", 'D');
        }
	last;
      }
    }
  }
}
sub op_nick {
  my($from, $nick) = @_;
  my($chan, $mode, $i, $n, $t);
  for ($i = 0; $i <= $#naruto; $i++) {
    ($chan, $mode, $n, $t) = split(/ /,shift(@naruto));
    if ($from =~ /^\Q$n\E$/i) {
      push (@naruto, "$chan $mode $nick $t");
      &mes("[op_nick] op_change: $chan $mode $n -> $nick $t", 'D');
    } else {
      push (@naruto, "$chan $mode $n $t");
    }
  }
}
sub op_firstloop {
  return if ++$op_loop < 2 || !vec($at_state, 7, 1) || !vec($sv_state, 1, 1);
  undef $op_loop;
  &list_del($per_min, 'op_firstloop');
  &list_add($per_min, 'op_restore');
}
sub op_restore {
  return if !vec($at_state, 7, 1) || !vec($sv_state, 1, 1);
  foreach (split(/$;/, $chl)) {
    next unless $_;
    next unless &list_exist($chl_opnone, $_) || &list_exist($chl_oponly, $_);
    if (&list_exist($chl_opnone, $_)) {
      if ($ls_mem{$_} !~ /\@/ || 
	  ($ls_mem{$_} =~ /^$;[\+\@]?$us_nick$;$/ &&
	   !&list_exist($chl_autojoin, $_))) {
	$chnum{$_} = ($ls_mem{$_} =~ s/$;/$;/g)
	    if &list_exist($chl_autojoin, $_);
	&send('sv', "PART $_ \n");
      }
    } elsif (&list_exist($chl_oponly, $_)) {
      if ($ls_mem{$_} =~ /^$;\+?$us_nick$;$/) {
	&send('sv', "PART $_ \n");
	&send('sv', "JOIN $_ $at_key{$_} \n");
	&send('sv', "MODE $_ $at_mode{$_} \n") if $at_mode{$_};
      }
    }
  }
  foreach (keys(%chnum)) {
    next if --$chnum{$_} > 0;
    &send('sv', "JOIN $_ $at_key{$_} \n");
    &send('sv', "MODE $_ $at_mode{$_} \n") if $at_mode{$_};
    delete $chnum{$_};
  }
}
sub set_modes {
  return unless @naruto;
  my($chan, $com, $nick, $t) = split(/ /, shift(@naruto));
  my $tm = ($at_op_rand == 1) ? int(rand($at_op_tm)) + 1 : $at_op_tm;
  if (time - $t > $tm) {
    &send('sv', "MODE $chan $com :$nick\n")
	if &list_exist($ls_mem{$chan}, $nick, "\+$nick") &&
	    &list_exist($ls_mem{$chan}, "\@$us_nick");
  } else {
    push(@naruto, "$chan $com $nick $t");
  }
}
sub read_modes {
  $mdk_modes = &search_file('madoka.modes') unless $mdk_modes;
  my @modes = ();
  if (open(MODES, "$mdk_modes")) {
    @modes = <MODES>;
    close(MODES);
  } elsif (-e $mdk_modes) {
    &mes("[ERROR] modes: cannot open $mdk_modes\n", 'L');
  }
  return @modes;
}