-
Notifications
You must be signed in to change notification settings - Fork 0
/
channel.pm
1128 lines (884 loc) · 28.4 KB
/
channel.pm
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/perl -w
# Copyright (c) 2011, Mitchell Cooper
package channel;
use warnings;
use strict;
use feature qw/say switch/;
use utils qw/conf hostmatch snotice cut_to_limit/;
our %channels;
# create a new channel
sub new {
my ($this, $user, $name) = @_;
# create the channel object
bless my $channel = {
name => $name,
time => time,
first => time,
creator => $user->nick,
owners => {
# they get owner on join
$user->{'id'} => time
},
ops => {
# they get op on join
$user->{'id'} => time
}
}, $this;
$channels{lc $name} = $channel;
# do the actual user join
$channel->dojoin($user);
# set auto modes
$channel->automodes($user);
snotice('channel '.$name.' created by '.$user->fullhost);
return $channel
}
# the actual join of a user
sub dojoin {
my ($channel, $user, $key) = @_;
my @users = keys %{$channel->{'users'}};
# check for bans without exceptions
if ($channel->banned($user)) {
# can't join; banned
$user->numeric(474, $channel->name);
return
}
# check if the channel is invite-only
if ($channel->ismode('i')
# and if they don't have an invite exception
&& !hostmatch($user->fullcloak, keys %{$channel->{'invexes'}})
# and if they have not been invited
&& !$channel->{'invites'}->{$user->{'id'}}) {
# can't join; not invited.
$user->numeric(473, $channel->name);
return
}
# check if the channel has a user count limit set
if ($channel->ismode('l')
# and if the limit is reached
&& $#users+1 >= $channel->{'mode'}->{'l'}->{'params'}) {
# can't join; channel full
$user->numeric(471, $channel->name);
return
}
# check if the user has the proper key
my $letmein = $channel->ismode('k');
if (defined $letmein &&
(not defined $key or $letmein->{params} ne $key)) {
$user->numeric(475, $channel->name);
return
}
# delete their invitation, if any
delete $channel->{'invites'}->{$user->{'id'}};
# add them to the user list
$channel->{'users'}->{$user->{'id'}} = time;
# relay their join to channel users
$channel->allsend(':%s JOIN :%s', 0, $user->fullcloak, $channel->name);
# send the topic and NAMES numerics
$channel->showtopic($user, 1);
$channel->names($user);
# set any status that applies to this user's mask (mode A)
$channel->doauto($user);
# success
return 1
}
# check if a user's displayed or actual mask matches any channel bans
# and if there are no exceptions
sub banned {
my ($channel, $user) = @_;
return 1 if (
(hostmatch($user->fullcloak, keys %{$channel->{'bans'}})
|| hostmatch($user->fullhost, keys %{$channel->{'bans'}}))
and (
!hostmatch($user->fullcloak, keys %{$channel->{'exempts'}})
&& !hostmatch($user->fullhost, keys %{$channel->{'exempts'}})
)
);
# not banned
return
}
# send to all users of a channel, with an optional exception
sub allsend {
my ($channel, $data, $exception) = (shift, shift, shift);
foreach (keys %{$channel->{'users'}}) {
my $usr = user::lookupbyid($_);
$usr->send(sprintf $data, @_) unless $usr == $exception
}
return 1
}
# send to users with operator status and above, with an optional exception
sub opsend {
my ($channel, $data, $exception) = (shift, shift, shift);
foreach (keys %{$channel->{'users'}}) {
my $usr = user::lookupbyid($_);
next unless $channel->basicstatus($usr, 1);
$usr->send(sprintf $data, @_) unless $exception == $usr
}
return 1
}
# remove user from channel
sub remove {
my $channel = shift;
my $id = shift->{'id'};
# delete their data
delete $channel->{$_}->{$id} foreach qw/users owners admins ops halfops voices invites/;
# check if the channel is now empty
$channel->check;
return 1
}
# fail WHO command
# (who knows why this is here and not in userhandlers.pm?)
sub who {
my $channel = shift;
my $user = shift;
foreach (keys %{$channel->{'users'}}) {
my $u = user::lookupbyid($_);
my $flags = (defined $u->{'away'} ? 'G' : 'H').
($u->ismode('o') ? '*' : q..).
(defined $channel->{'owners'}->{$_} ? '~' : q..).
(defined $channel->{'admins'}->{$_} ? '&' : q..).
(defined $channel->{'ops'}->{$_} ? '@' : q..).
(defined $channel->{'halfops'}->{$_} ? '%': q..).
(defined $channel->{'voices'}->{$_} ? '+' : q..);
# this is ugly, but I could care less.
$user->sendservj(352,
$user->nick,
$channel->name,
$u->{'ident'},
$u->{'cloak'},
(conf qw/server name/),
$u->nick,
$flags,
':0',
$u->{'gecos'}
);
}
return 1
}
# check if a channel is empty
sub check {
my $channel = shift;
if (!scalar keys %{$channel->{'users'}}) {
# it's empty, so delete its data
delete $channels{lc $channel->name};
snotice('dead channel: '.$channel->name);
return
}
# it still exists
return 1
}
# check if a user has status(es) (by name)
sub has {
my ($channel, $user, @status) = @_;
foreach (@status) {
# say yes, they have this
return 1 if $channel->{$_.'s'}->{$user->{'id'}}
}
# no matches
return
}
# NAMES comamnd
# (why is this here and not in userhandlers.pm?)
sub names {
my ($channel, $user) = @_;
my @users = ();
# find the users
foreach (keys %{$channel->{'users'}}) {
my $u = user::lookupbyid($_);
next if ($u->ismode('i') and !$user->ison($channel));
push @users, ($channel->prefix($u) ? $channel->prefix($u).$u->nick : $u->nick);
}
# send the info
$user->numeric(353, $channel->name, (join q. ., @users)) unless $#users < 0;
$user->numeric(366, $channel->name);
return 1
}
# fetch a user's prefix
sub prefix {
my ($channel, $user) = @_;
if ($channel->has($user, 'owner')) {
return '~'
}
if ($channel->has($user, 'admin')) {
return '&'
}
if ($channel->has($user, 'op')) {
return '@'
}
if ($channel->has($user, 'halfop')) {
return '%'
}
if ($channel->has($user, 'voice')) {
return '+'
}
# they don't have any special status
return
}
# check if a channel exists (by name)
sub chanexists {
my $name = lc shift;
# found it
return $channels{$name} if exists $channels{$name};
# no match
return
}
# does this user have halfop or greater?
# (halfop doesn't count if a third argument is true
sub basicstatus {
my ($channel, $user) = (shift, shift);
my $halfop = $channel->has($user, 'halfop');
# no halfops allowed!
$halfop = 0 if shift;
# nope
return if (!$channel->has($user, 'owner') && !$channel->has($user, 'admin') && !$channel->has($user, 'op') && !$halfop);
# yep
return 1
}
# do an actual mode set
# note: the mode handler is handlemode()
# this actually sets the mode
sub setmode {
my ($channel, $mode, $parameter) = @_;
# set the mode
$channel->{'mode'}->{$mode} = {
time => time,
params => (
# if there's a parameter, set it
defined $parameter ?
$parameter
# otherwise use undef I guess..
: undef
)
};
return 1
}
# check if a channel is a mode, returning it's value if so
sub ismode {
my ($channel, $mode) = @_;
# found it
return $channel->{'mode'}->{$mode} if exists $channel->{'mode'}->{$mode};
# it's not
return
}
# delete mode(s)
sub unsetmode {
my $channel = shift;
delete $channel->{'mode'}->{$_} foreach split //, shift;
return 1
}
# fetch the channel's name
sub name {
return shift->{'name'}
}
# main mode handler for channels
sub handlemode {
my ($channel, $user) = (shift, shift);
if (!defined $_[0] || !length $_[0]) {
# no string, so sending them a mode numeric
$channel->showmodes($user);
return
}
my @mode_string = split /\s+/, shift;
my $modes = shift @mode_string;
# modes without parameters
my @normal_modes = qw/n t m i z/;
# modes with a nickname as a parameter
my @status_modes = qw/q a o h v/;
# modes that require a mask
my @mask_modes = qw/b e I Z A/;
# modes with a parameter
my @parameter_modes = qw/l k/;
# some modes such as l do not need a parameter to unset but do to set.
# these must also be in @parameter_modes.
my @no_unset = qw/l/;
# some modes (such as mask lists) do not require operator status.
# qaohv are not here because they handle it in handlestatus().
# these modes require op
my @needs_op = qw/n t m i z l/;
# if $success is false by the end of this mode string, a numeric is sent
# reading that the user must have half-operator or above
my $success = 1;
# returns the next parameter or false if no parameters are left
my $parameter = sub {
if (my $result = shift @mode_string) {
return $result
}
return
};
my @finished_parameters = ();
my $finished_string = '+';
my ($state, $cstate, $ok, $i) = (1, 1, 1, 0);
# handle each mode individually
foreach my $mode (split //, $modes) {
$ok = 1;
# if the mode limit is reached
last if $i > conf qw/limit chanmodes/;
$i++;
# if they need op and don't have it, give up
if ($mode ~~ @needs_op && !$channel->basicstatus($user)) {
$success = 0;
next
}
# setting or unsetting?
$state = 1, next if $mode eq '+';
$state = 0, next if $mode eq '-';
# normal modes without parameters
if ($mode ~~ @normal_modes) {
if ($state) {
$channel->setmode($mode)
}
else {
$channel->unsetmode($mode)
}
}
# modes with a parameter
elsif ($mode ~~ @parameter_modes) {
# if it's a mode like l that doesn't need a parameter on unset,
# just unset it
if (!$state && $mode ~~ @no_unset) {
$channel->unsetmode($mode)
}
# it needs a parameter for both unset and set
# or this a set not an unset.
else {
if (defined (my $par = $parameter->())) {
if (my $cool_it_worked = $channel->handleparmode($user, $mode, $state, $par)) {
push @finished_parameters, $cool_it_worked
}
else {
$ok = 0
}
}
# we need a parameter.
else {
$ok = 0
}
}
}
# modes with masks as their parameters
elsif ($mode ~~ @mask_modes) {
my $par = $parameter->();
if (defined $par) {
my $result = $channel->handlemaskmode($user, $state, $mode, $par);
if (defined $result) {
# worked!
push @finished_parameters, $result
}
# uh-oh? handlemaskmode() said no
else {
$ok = 0
}
}
# no parameter, so send the list and continue
else {
$channel->sendmasklist($user, $mode);
next
}
}
# modes q, a, o, h, and v
elsif ($mode ~~ @status_modes) {
my $target_nick = $parameter->() or next;
# are they allowed to set this?
if (my $nickname = $channel->handlestatus($user, $state, $mode, $target_nick)) {
# handlestatus returns the user's nickname in proper case
push @finished_parameters, $nickname
}
# handlestatus() returned false :(
else {
$ok = 0
}
}
# unknown mode
else {
$user->numeric(472, $mode);
next
}
# $ok is set to false if there was an error or something, and it's not added to the final string
if ($ok) {
if ($cstate != $state) {
$finished_string .= ($state ? '+' : '-');
$cstate = $state
}
$finished_string .= $mode
}
}
# show them a "requires half-operator" numeric if some mode(s) failed
$user->numeric(482, $channel->name, 'half-operator') unless $success;
$finished_string =~ s/\+-/-/g;
$channel->allsend(':%s MODE %s %s %s', 0, $user->fullcloak, $channel->name, $finished_string, (join q. ., @finished_parameters))
# this is what we started with
unless $finished_string eq '+';
# success
return 1
}
# send channel modes
sub showmodes {
my ($channel, $user) = @_;
my (@modes, @parameters);
while (my ($mode, $ref) = each %{$channel->{'mode'}}) {
push @modes, $mode;
if (defined $ref->{'params'}) {
push @parameters, $ref->{'params'}
}
}
$user->numeric(324, $channel->name, (join q.., @modes), (join q.., @parameters));
$user->numeric(329, $channel->name, $channel->{'first'});
}
# handle modes q, a, o, h, and v
sub handlestatus {
my ($channel, $user, $state, $mode, $tuser) = @_;
my (@needs, $modename, $longname);
# define mode names and their requirements
given ($mode) {
when ('q') {
$modename = 'owners';
@needs = 'owner';
$longname = 'owner'
}
when ('a') {
$modename = 'admins';
@needs = qw/owner admin/;
$longname = 'administrator'
}
when ('o') {
$modename = 'ops';
@needs = qw/owner admin op/;
$longname = 'operator'
}
when ('h') {
$modename = 'halfops';
@needs = qw/owner admin op/;
$longname = 'operator'
}
when ('v') {
$modename = 'voices';
@needs = qw/owner admin op halfop/;
$longname = 'half-operator'
}
}
# check if the user has what they need to set this mode
if (!$channel->has($user, @needs)) {
# they don't.
$user->numeric(482, $channel->name, $longname);
return
}
my $target = user::nickexists($tuser);
# make sure the user exists
if (!$target) {
# they don't.
$user->numeric(401, $tuser);
return
}
# are they on the channel?
if (!$target->ison($channel)) {
# no, they aren't.
$user->numeric(441, $target->nick, $channel->name);
return
}
if ($state) {
# give them the status
$channel->{$modename}->{$target->{'id'}} = time
}
else {
# remove their status
delete $channel->{$modename}->{$target->{'id'}}
}
# success!
# by the way, this returns the nickname to properly relay mode changes in handlemode()
return $target->nick
}
# send topic numerics
sub showtopic {
# $halt it used on channel join
# because if no topic is set when you join, these numerics aren't sent at all
my ($channel, $user, $halt) = @_;
if ($channel->{'topic'}) {
$user->numeric(332, $channel->name, $channel->{'topic'}->{'topic'});
$user->numeric(333, $channel->name, $channel->{'topic'}->{'setby'}, $channel->{'topic'}->{'time'});
return 1
}
# send "no topic is set"
$user->numeric(331, $channel->name) unless $halt;
return
}
# set the topic
sub settopic {
my ($channel, $user, $topic) = @_;
my $success = 0;
# see if they can set it
if ($channel->ismode('t')) {
$success = 1 if $channel->basicstatus($user)
}
# if it's not +t, anyone can
else {
$success = 1
}
# they can
if ($success) {
$channel->{'topic'} = {
topic => $topic,
time => time,
setby => (
(conf qw/main fullmasktopic/)
? $user->fullcloak
: $user->nick
)
};
$channel->allsend(':%s TOPIC %s :%s', 0, $user->fullcloak, $channel->name, $topic);
return 1
}
# they can't.
else {
$user->numeric(482, $channel->name, 'half-operator')
}
return
}
# check if a user can speak with the status they have
sub canspeakwithstatus {
my ($channel, $user) = @_;
# they don't have what they need
return
if (!$channel->has($user, 'owner')
&& !$channel->has($user, 'admin')
&& !$channel->has($user, 'op')
&& !$channel->has($user, 'halfop')
&& !$channel->has($user, 'voice'));
# they can speak
return 1
}
# send a PRIVMSG or NOTICE
# I am too lazy to make this prettier. it works the way it is.
# since it's so messy, I commented it line-by-line
sub privmsgnotice {
my ($channel, $user, $type, $msg) = @_;
# you must be in the channel if n is set.
if (($channel->ismode('n') && !$user->ison($channel))
# you have to have voice or such to speak in a moderated room
|| ($channel->ismode('m') && !$channel->canspeakwithstatus($user))
# is this user banned?
|| ((hostmatch($user->fullcloak, keys %{$channel->{'bans'}}) || hostmatch($user->fullhost, keys %{$channel->{'bans'}})
# is he muted?
|| hostmatch($user->fullcloak, keys %{$channel->{'mutes'}}) || hostmatch($user->fullhost, keys %{$channel->{'mutes'}}))
# does he have the required status he needs to speak here?
&& !$channel->canspeakwithstatus($user)
# and doesn't have an exception?
&& !hostmatch($user->fullcloak, keys %{$channel->{'exempts'}}))) {
# show the ops if z is set
if ($channel->ismode('z')) {
# z doesn't work unless you're in the channel.
# it doesn't allow you to override n
if (!$user->ison($channel)) {
$user->numeric(404, $channel->name);
return
}
# okay, they're on the channel, so let's send it to the ops
$channel->opsend(':'.$user->fullcloak.q( ).(join q. ., $type, $channel->name, ':'.$msg), $user);
return 1
}
# otherwise give them an error
else {
$user->numeric(404, $channel->name);
return
}
}
# cool, he can send it
$channel->allsend(':%s %s %s :%s', $user, $user->fullcloak, $type, $channel->name, $msg);
return 1
}
# handle modes such as b
sub handlemaskmode {
my ($channel, $user, $state, $mode, $mask) = @_;
# this user can't even set modes... why is he trying to do this in the first place?
$user->numeric(482, $channel->name, 'half-operator'), return unless $channel->basicstatus($user);
# A doesn't check masks because it's the odd one out
if ($mode ne 'A') {
# make an idiot's excuse for a mask somewhat acceptable
if ($mask =~ m/\@/) {
if ($mask !~ m/\!/) {
$mask = '*!'.$mask
}
}
else {
if ($mask =~ m/\!/) {
$mask = $mask.'@*'
}
else {
$mask = $mask.'!*@*'
}
}
}
# handle an auto-access mask
else {
my @m = split ':', $mask, 2;
if ($#m) {
# now we can do more than 1 setting in 1 mode :D
my $finished_modes = q..;
my %done;
foreach my $status_mode (split //, $m[0]) {
# make sure it's a legal mode first
# and it's not already been used
if ($status_mode =~ m/(q|a|o|h|v)/ && !$done{$status_mode}) {
$done{$status_mode} = 1;
$finished_modes .= $status_mode
}
}
# put in form of modes:mask
$mask = $finished_modes.q(:).$m[1]
}
# no mode type provided
else {
# we'll assume they meant o
$mask = 'o:'.$mask
}
}
# get the name of the mode
my $modename;
given ($mode) {
when ('b') {
$modename = 'bans'
}
when ('Z') {
$modename = 'mutes'
}
when ('I') {
$modename = 'invexes'
}
when ('A') {
$modename = 'autoops';
return unless $channel->canAmode($user, (split ':', $mask)[0])
}
when ('e') {
$modename = 'exempts'
}
}
# cool, do the change
if ($state) {
# set the mode
my $from = $user->fullcloak;
# if it's a server, remove anything but the server name
$from = (split '!', $from)[0] if $user->nick =~ m/\./;
$channel->{$modename}->{lc $mask} = [$from, time, $mask]
}
else {
# delete the mode
delete $channel->{$modename}->{lc $mask}
}
# success
return $mask
}
sub sendmasklist {
my ($channel, $user, $modes) = @_;
MODES: foreach (split //, $modes) {
# ignore non-mask modes
next unless $_ =~ m/^(b|Z|e|I|A)$/;
my @list;
# set the numerics, mode names, requirements, etc.
given ($_) {
when ('b') {
@list = (367, 368, 'bans', 0)
}
when ('Z') {
@list = (728, 729, 'mutes', 0)
}
when ('e') {
@list = (348, 349, 'exempts', 1)
}
when ('A') {
@list = (388, 389, 'autoops', 1)
}
when ('I') {
@list = (346, 347, 'invexes', 1)
}
}
# if they need op (mode e, for example), check for it
if ($list[3] && !$channel->basicstatus($user)) {
# sux4u
$user->numeric(482, $channel->name, 'half-operator');
next MODES
}
# send the list
foreach (keys %{$channel->{$list[2]}}) {
$user->numeric($list[0],
$channel->name,
$channel->{$list[2]}->{$_}->[2],
$channel->{$list[2]}->{$_}->[0],
$channel->{$list[2]}->{$_}->[1]
);
}
$user->numeric($list[1], $channel->name)
}
return 1
}
sub kick {
# kick a user if possible
# this is an ugly subroutine
# but not everyone can be beautiful, studies conclude.
my ($channel, $user, $target, $reason) = @_;
return unless $channel->basicstatus($user);
return if ($channel->has($target, 'owner') && !$channel->has($user, 'owner'));
return if ($channel->has($target, 'admin') && !$channel->has($user, 'owner') && !$channel->has($user, 'admin'));
return if ($channel->has($target, 'op') && !$channel->has($user, 'owner') && !$channel->has($user, 'admin') && !$channel->has($user, 'op'));
return if ($channel->has($target, 'halfop') && !$channel->has($user, 'owner') && !$channel->has($user, 'admin') && !$channel->has($user, 'op'));
# they can, so do it
$channel->allsend(':%s KICK %s %s :%s', 0, $user->fullcloak, $channel->name, $target->nick, $reason);
$channel->remove($target);
return 1
}
sub list {
# information for a channel shown in LIST command
my ($channel, $user) = @_;
# send the name, number of users, and topic.
$user->numeric(322,
$channel->name,
scalar keys %{$channel->{'users'}},
$channel->{'topic'}
? $channel->{'topic'}->{'topic'}
: q..
);
return 1
}
# handle a mode with a single parameter
sub handleparmode {
my ($channel, $user, $mode, $state, $parameter) = @_;
given ($mode) {
# channel limit
when ('l') {
# -l does not required a parameter, so this is not the right place to handle it.
return unless $state;
# make sure the amount is valid
if ($parameter !~ m/[^0-9]/ && $parameter != 0) {
# don't allow limits that are gigantic
$parameter = 9001 if int $parameter > 9000;
$channel->setmode('l', $parameter);
return $parameter
}
# invalid amount
return
}
# channel key
when ('k') {
# if setting, go ahead and set it
if ($state) {
$parameter = cut_to_limit('chankey', $parameter);
$parameter =~ s/,//;
$channel->setmode('k', $parameter);
return $parameter
}
return unless $channel->ismode('k');
# if they are unsetting it and the parameter is right
my $m = $channel->ismode('k');
if ($parameter eq $m->{params}) {
$channel->unsetmode('k');
return $parameter
}
}
# unknown mode ?
}
return
}
# apply automatic status (A mode)
sub doauto {
my ($channel, $user) = @_;
my (@modes, @parameters, %done);
foreach (keys %{$channel->{'autoops'}}) {
my ($mode, $mask) = split ':', $_, 2;
foreach my $status_mode (split //, $mode) {
# we've already set this mode
next if $done{$status_mode};