-
Notifications
You must be signed in to change notification settings - Fork 0
/
Channel.pm
1219 lines (1126 loc) · 34.5 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
#####################################################################
# Channel.pm #
# Created: Tue Sep 15 12:56:51 1998 by jay.kominek@colorado.edu #
# Revised: Wed Jun 5 12:59:27 2002 by jay.kominek@colorado.edu #
# Copyright 1998 Jay F. Kominek (jay.kominek@colorado.edu) #
# #
# Consult the file 'LICENSE' for the complete terms under which you #
# may use this file. #
# #
#####################################################################
# channel package - juno ircd #
#####################################################################
package Channel;
use Utils;
use User;
use Server;
use strict;
use UNIVERSAL qw(isa);
use Tie::IRCUniqueHash;
#####################
# CLASS CONSTRUCTOR #
#####################
# Expects to get the proper name of the channel as the first
# argument.
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
my $this = { };
$this->{'name'} = shift;
my %tmp = ();
$this->{'bans'} = \%tmp;
tie my %mutetmp, 'Tie::IRCUniqueHash';
$this->{'mutes'} = \%mutetmp;
$this->{'creation'} = shift || time();
tie my %usertmp, 'Tie::IRCUniqueHash';
$this->{'users'} = \%usertmp;
tie my %opstmp, 'Tie::IRCUniqueHash';
$this->{'ops'} = \%opstmp;
tie my %halfopstmp, 'Tie::IRCUniqueHash';
$this->{'halfops'} = \%halfopstmp;
tie my %ownerstmp, 'Tie::IRCUniqueHash';
$this->{'owners'} = \%ownerstmp;
tie my %adminstmp, 'Tie::IRCUniqueHash';
$this->{'admins'} = \%adminstmp;
tie my %voicetmp,'Tie::IRCUniqueHash';
$this->{'voice'} = \%voicetmp;
tie my %jointimetmp,'Tie::IRCUniqueHash';
$this->{'jointime'} = \%jointimetmp;
bless($this, $class);
return $this;
}
#####################################################################
# DATA ACCESSING SUBROUTINES
############################
sub users {
my $this = shift;
return values(%{$this->{'users'}});
}
sub bans {
my $this = shift;
return keys(%{$this->{'bans'}});
}
sub mutes {
my $this = shift;
return keys(%{$this->{'mutes'}});
}
# Sends the user /names output
sub names {
my $this = shift;
my $user = shift;
my @lists;
my($index,$count) = (0,0);
foreach(sort
{ $this->{'jointime'}->{$b} <=> $this->{'jointime'}->{$a} }
keys %{$this->{'users'}}) {
if($count>60) { $index++; $count = 0; }
my $nick = $this->{'users'}->{$_}->nick;
if($this->isowner($this->{'users'}->{$_})) {
$nick = "~".$nick;
} elsif($this->isadmin($this->{'users'}->{$_})) {
$nick = "&".$nick;
} elsif($this->isop($this->{'users'}->{$_})) {
$nick = "@".$nick;
} elsif($this->ishalfop($this->{'users'}->{$_})) {
$nick = "%".$nick;
} elsif($this->hasvoice($this->{'users'}->{$_})) {
$nick = "+".$nick;
}
push(@{$lists[$index]},$nick);
}
foreach(0..$index) {
$user->senddata(":".$user->server->{name}." 353 ".$user->nick." = ".$this->{name}." :".join(' ',@{$lists[$_]})."\r\n");
}
}
sub isvalidchannelmode {
my $mode = shift;
if($mode =~ /\W/) { return 0; }
if(grep {/$mode/} ("b","i","k",
"l","m","n",
"o","s","t",
"v","a","q",
"h","Z","L",
"A","O" )) {
return 1;
} else {
return 0;
}
}
# These functions manipulate binary modes on the channel.
# ismode returns 0 or 1 depending on whether or not the requested
# mode is set on the channel now.
sub ismode {
my $this = shift;
my $mode = shift;
if($this->{modes}->{$mode}==1) {
return 1;
} else {
return 0;
}
}
# do the dirty work for setmode and unsetmode
sub frobmode {
my($this,$user,$mode,$val)=@_;
if(!isvalidchannelmode($mode)) {
$user->senddata(":".$user->server->{name}." 501 ".$user->nick." :Unknown mode flag \2$mode\2\r\n");
return 0;
}
if($this->{'modes'}->{$mode}!=$val) {
$this->{'modes'}->{$mode}=$val;
return 1;
} else {
return 0;
}
}
# setmode attempts to set the given mode to true. If the mode
# is not already set, then it sets it. returns 1 if a mode
# change was effected, 0 if the mode was already set.
sub setmode {
frobmode(@_,1);
}
# unsetmode does the opposite of setmode.
sub unsetmode {
frobmode(@_,0);
}
sub setlink {
my $this = shift;
my $user = shift;
my $channel = shift;
my $link = Utils::lookup($channel);
if (isa($link,"Channel")) {
unless ($link->{name} =~ /^\&/ && $this->{name} !~ /^\&/) {
if ($link->isop($user)) {
if (lc($this->{name}) eq lc($channel)) {
$user->sendreply("609 $$this{name} $channel :You can't link a channel to itself");
}
else {
if (defined($this->{'link'}) && lc($this->{'link'}) eq lc($channel)) {
$user->sendreply("609 $$this{name} $channel :Target is already linked");
}
else {
$this->setmode($user,"L");
$this->{'link'} = $channel;
return $channel;
}
}
}
else {
$user->sendreply("609 $$this{name} $channel :You must be op in a channel to link it");
return 0;
}
} else {
$user->sendreply("609 $$this{name} $channel :Cannot link global channel to local channel");
return 0;
}
} else {
$user->sendreply("403 $$this{name} $channel :No such channel");
return 0;
}
}
sub unsetlink {
my $this = shift;
my $user = shift;
my $link = $this->{link};
delete($this->{link});
undef($this->{link});
$this->unsetmode($user, "L");
return $link;
}
# These functions manipulate or view the ban list for $this channel
# bans are stored as a hash, keyed on the mask. The value for that
# hash{key} is a an array, the first item of which contains the name
# of the person who set the ban, and the second item containing the
# time the ban was set.
# XXX since when can a hash value be an array?
# setban takes a mask, and if it is not already present, adds it to
# the list of bans on the channel.
sub setban {
# we actually *check* if a mask is somewhat valid, unlike before.
my $this = shift;
my $user = shift;
my $mask = shift;
my $full = $user->nick."!".$user->username."\@".$user->host;
if ($mask =~ m/\@/) {
if ($mask =~ m/\!/) {
$mask = $mask; # cool story bro.
}
else {
$mask = "*!".$mask;
}
}
else {
if ($mask =~ m/\!/) {
$mask = $mask."@*";
}
else {
$mask = $mask."!*@*";
}
}
if(!defined($this->{'bans'}->{$mask})) {
$mask = lc($mask); # this is easier... since capitalization doesn't matter with masks.
$this->{'bans'}->{$mask} = [$full,time()];
return $mask;
} else {
return 0; # already set
}
}
sub setmute {
# we have mute! Added on july 1st, 2010
# we actually *check* if a mask is somewhat valid, unlike before.
my $this = shift;
my $user = shift;
my $mask = shift;
my $full = $user->nick."!".$user->username."\@".$user->host;
if ($mask =~ m/\@/) {
if ($mask =~ m/\!/) {
$mask = $mask; # cool story bro.
}
else {
$mask = "*!".$mask;
}
}
else {
if ($mask =~ m/\!/) {
$mask = $mask."@*";
}
else {
$mask = $mask."!*@*";
}
}
if(!defined($this->{'mutes'}->{$mask})) {
$mask = lc($mask); # this is easier... since capitalization doesn't matter with masks.
$this->{'mutes'}->{$mask} = [$full,time()];
return $mask;
} else {
return 0; # already set
}
}
# Removes a ban mask from the current
sub unsetban {
my $this = shift;
my $user = shift;
my $mask = shift;
my $mask = lc($mask);
if(defined($this->{bans}->{$mask})) {
delete($this->{bans}->{$mask});
return $mask;
} else {
return 0;
}
}
sub unsetmute {
my $this = shift;
my $user = shift;
my $mask = shift;
my $mask = lc($mask);
if(defined($this->{mutes}->{$mask})) {
delete($this->{mutes}->{$mask});
return $mask;
} else {
return 0;
}
}
# Takes a User object and returns true if that user
# is an op on this channel.
sub isop {
my $this = shift;
my $user = shift;
if(defined($this->{ops}->{$user->nick()})) {
return 1;
} else {
return 0;
}
}
sub ishalfop {
# as of may 2010, we have halfop support :)
my $this = shift;
my $user = shift;
if(defined($this->{halfops}->{$user->nick()})) {
return 1;
} else {
return 0;
}
}
sub isadmin {
# admin added may 2010
my $this = shift;
my $user = shift;
if(defined($this->{admins}->{$user->nick()})) {
return 1;
} else {
return 0;
}
}
sub isowner {
# what good is halfop without owner and admin as well? we now have all 5 prefixes :D
my $this = shift;
my $user = shift;
if(defined($this->{owners}->{$user->nick()})) {
return 1;
} else {
return 0;
}
}
sub setop {
# the setowner, setadmin, setop, sethalfop, and setvoice subroutines were changed entirely.
# I tested several times to make sure halfops can't give op, ops can't give admin, etc
# i think it's all good :)
my $this = shift;
my $user = shift;
my $target = shift;
my $ret = Utils::lookupuser($target,1);
if ((ref($ret) && isa($ret,"User"))) {
if (defined($this->{'users'}->{$ret->nick()})) {
if ($this->isop($user) || $user->ismode('O')) {
if (!defined($this->{ops}->{$ret->nick()})) {
$this->{ops}->{$ret->nick()} = $user;
return $ret->nick;
}
else {
return 0;
}
}
else {
$user->sendreply("482 $$this{name} :You're not a channel operator.");
# technically, non ops/halfops can't set modes at all, so this isn't necessary
# but we might as well check here too
return 0;
}
}
else {
$user->sendnumeric($user->server,441,$target,$this->{name},"They aren't on the channel");
return 0;
}
}
else {
$user->sendnumeric($user->server,401,$target,"No such nick");
return 0;
}
}
sub unsetop {
my $this = shift;
my $user = shift;
my $target = shift;
my $ret = Utils::lookupuser($target,1);
if(!(ref($ret) && isa($ret,"User"))) {
$user->sendnumeric($user->server,401,$target,"No such nick");
return 0;
}
if(!defined($this->{'users'}->{$ret->nick()})) {
$user->sendnumeric($user->server,441,$target,$this->{name},
"They aren't on the channel");
return 0;
}
if(!$this->isop($user) && !$user->ismode('O')) {
$user->sendreply("482 $$this{name} :You're not a channel operator.");
return 0;
}
if(defined($this->{ops}->{$ret->nick()})) {
delete($this->{ops}->{$ret->nick()});
return $ret->nick;
} else {
return 0;
}
}
sub sethalfop {
# the setowner, setadmin, setop, sethalfop, and setvoice subroutines were changed entirely.
# I tested several times to make sure halfops can't give op, ops can't give admin, etc
# i think it's all good :)
my $this = shift;
my $user = shift;
my $target = shift;
my $ret = Utils::lookupuser($target,1);
if ((ref($ret) && isa($ret,"User"))) {
if (defined($this->{'users'}->{$ret->nick()})) {
if ($this->isop($user) || $user->ismode('O')) {
if (!defined($this->{halfops}->{$ret->nick()})) {
$this->{halfops}->{$ret->nick()} = $user;
return $ret->nick;
}
else {
return 0;
}
}
else {
$user->sendreply("482 $$this{name} :You're not a channel operator.");
return 0;
}
}
else {
$user->sendnumeric($user->server,441,$target,$this->{name},"They aren't on the channel");
return 0;
}
}
else {
$user->sendnumeric($user->server,401,$target,"No such nick");
return 0;
}
}
sub unsethalfop {
my $this = shift;
my $user = shift;
my $target = shift;
my $ret = Utils::lookupuser($target,1);
if(!(ref($ret) && isa($ret,"User"))) {
$user->sendnumeric($user->server,401,$target,"No such nick");
return 0;
}
if(!defined($this->{'users'}->{$ret->nick()})) {
$user->sendnumeric($user->server,441,$target,$this->{name},
"They aren't on the channel");
return 0;
}
if(!$this->isop($user) && !$user->ismode('O')) {
$user->sendreply("482 $$this{name} :You're not a channel operator.");
return 0;
}
if(defined($this->{halfops}->{$ret->nick()})) {
delete($this->{halfops}->{$ret->nick()});
return $ret->nick;
} else {
return 0;
}
}
sub setadmin {
# the setowner, setadmin, setop, sethalfop, and setvoice subroutines were changed entirely.
# I tested several times to make sure halfops can't give op, ops can't give admin, etc
# i think it's all good :)
my $this = shift;
my $user = shift;
my $target = shift;
my $ret = Utils::lookupuser($target,1);
if ((ref($ret) && isa($ret,"User"))) {
if (defined($this->{'users'}->{$ret->nick()})) {
if ($this->isowner($user) || $user->ismode('O')) {
if (!defined($this->{admins}->{$ret->nick()})) {
$this->{admins}->{$ret->nick()} = $user;
return $ret->nick;
}
else {
return 0;
}
}
else {
$user->sendreply("482 $$this{name} :You're not a channel owner.");
return 0;
}
}
else {
$user->sendnumeric($user->server,441,$target,$this->{name},"They aren't on the channel");
return 0;
}
}
else {
$user->sendnumeric($user->server,401,$target,"No such nick");
return 0;
}
}
sub unsetadmin {
my $this = shift;
my $user = shift;
my $target = shift;
my $ret = Utils::lookupuser($target,1);
if(!(ref($ret) && isa($ret,"User"))) {
$user->sendnumeric($user->server,401,$target,"No such nick");
return 0;
}
if(!defined($this->{'users'}->{$ret->nick()})) {
$user->sendnumeric($user->server,441,$target,$this->{name},
"They aren't on the channel");
return 0;
}
if(!$this->isowner($user) && !$user->ismode('O') && lc($user->nick) ne lc($target)) {
$user->sendreply("482 $$this{name} :You're not a channel owner.");
return 0;
}
if(defined($this->{admins}->{$ret->nick()})) {
delete($this->{admins}->{$ret->nick()});
return $ret->nick;
} else {
return 0;
}
}
sub setowner {
# the setowner, setadmin, setop, sethalfop, and setvoice subroutines were changed entirely.
# I tested several times to make sure halfops can't give op, ops can't give admin, etc
# i think it's all good :)
my $this = shift;
my $user = shift;
my $target = shift;
my $ret = Utils::lookupuser($target,1);
if ((ref($ret) && isa($ret,"User"))) {
if (defined($this->{'users'}->{$ret->nick()})) {
if ($this->isowner($user) || $user->ismode('O')) {
if (!defined($this->{owners}->{$ret->nick()})) {
$this->{owners}->{$ret->nick()} = $user;
return $ret->nick;
}
else {
return 0;
}
}
else {
$user->sendreply("482 $$this{name} :You're not a channel owner.");
return 0;
}
}
else {
$user->sendnumeric($user->server,441,$target,$this->{name},"They aren't on the channel");
return 0;
}
}
else {
$user->sendnumeric($user->server,401,$target,"No such nick");
return 0;
}
}
sub firstjoin {
# this subroutine replaces force_join, as we can't set op without a user unless defined by the server (here)
# and it was checking for op, when there was nothing to check. "you're not channel operator" when we were joining
# and this subroutine is the exact same without the op check
my $this = shift;
my $user = shift;
my $server = shift;
$this->{'ops'}->{$user->nick()} = $user;
$this->{'users'}->{$user->nick()} = $user;
$this->{'jointime'}->{$user->nick()} = time;
$user->{'channels'}->{$this->{name}} = $this;
$this->setmode($user,"n");
$this->setmode($user,"t");
User::multisend(":$$user{nick}!$$user{user}\@$$user{host} JOIN>:$$this{name}",
values(%{$this->{'users'}}));
User::multisend(":".$user->server->name." MODE>$$this{name} +nt $$user{nick}",
values(%{$this->{'users'}}));
foreach my $iserver ($Utils::thisserver->children) {
if($iserver ne $server) {
$iserver->join($user,$this);
}
}
return $user->nick;
}
sub unsetowner {
my $this = shift;
my $user = shift;
my $target = shift;
my $ret = Utils::lookupuser($target,1);
if(!(ref($ret) && isa($ret,"User"))) {
$user->sendnumeric($user->server,401,$target,"No such nick");
return 0;
}
if(!defined($this->{'users'}->{$ret->nick()})) {
$user->sendnumeric($user->server,441,$target,$this->{name},
"They aren't on the channel");
return 0;
}
if(!$this->isowner($user) && !$user->ismode('O')) {
$user->sendreply("482 $$this{name} :You're not a channel owner.");
return 0;
}
if(defined($this->{owners}->{$ret->nick()})) {
delete($this->{owners}->{$ret->nick()});
return $ret->nick;
} else {
return 0;
}
}
# Takes a User object and tells you if it has a voice on
# this channel.
sub hasvoice {
my $this = shift;
my $user = shift;
if(defined($this->{voice}->{$user->nick()})) {
return 1;
} else {
return 0;
}
}
sub setvoice {
my $this = shift;
my $user = shift;
my $target = shift;
my $ret = Utils::lookupuser($target,1);
if ((ref($ret) && isa($ret,"User"))) {
if (defined($this->{'users'}->{$ret->nick()})) {
if ($this->isop($user) || $this->ishalfop($user) || $user->ismode('O')) {
if (!defined($this->{voice}->{$ret->nick()})) {
$this->{voice}->{$ret->nick()} = $user;
return $ret->nick;
}
else {
return 0;
}
}
else {
$user->sendreply("482 $$this{name} :You're not a channel operator.");
return 0;
}
}
else {
$user->sendnumeric($user->server,441,$target,$this->{name},"They aren't on the channel");
return 0;
}
}
else {
$user->sendnumeric($user->server,401,$target,"No such nick");
return 0;
}
}
sub unsetvoice {
my $this = shift;
my $user = shift;
my $target = shift;
my $ret = Utils::lookupuser($target,1);
if(!(ref($ret) && isa($ret,"User"))) {
$user->sendnumeric($user->server,401,$target,"No such nick");
return 0;
}
if(!defined($this->{'users'}->{$ret->nick()})) {
$user->sendnumeric($user->server,441,$target,$this->{name},
"They aren't on the channel");
return 0;
}
if(defined($this->{voice}->{$ret->nick()})) {
delete($this->{voice}->{$ret->nick()});
return $ret->nick;
} else {
return 0;
}
}
#####################################################################
# DATA MANIPULATING SUBROUTINES
###############################
# handle a MODE command from a user - can be mode check or mode change
sub mode {
my($this,$user,$modestr,@arguments)=@_;
my @modebytes = split(//,$modestr);
my(@accomplishedset,@accomplishedunset,@accomplishedargs);
my $state = 1;
my $arg;
# if it's a mode check, send the nf0z
if(!defined($modestr)) {
my(@modes,@args);
foreach(keys(%{$this->{'modes'}})) {
next if(!$this->{'modes'}->{$_}); # don't show unset modes
if($_ eq "k") {
if($user->onchan($this)) {
push(@args, $this->{'key'});
}
} elsif($_ eq "l") {
push(@args, $this->{'limit'});
} elsif($_ eq "L") {
push(@args, $this->{'link'});
}
push(@modes, $_);
}
$user->sendnumeric($user->server,324,($this->{name},"+".join('',@modes),@args),undef);
$user->sendnumeric($user->server,329,($this->{name},$this->{'creation'}),undef);
return;
} elsif($modestr eq 'b' or ($modestr eq '+b' and $#arguments == -1)) {
foreach(keys(%{$this->{'bans'}})) {
my @bandata = @{$this->{'bans'}->{$_}};
$user->sendnumeric($user->server,367,($this->{name},$_,@bandata),undef);
}
$user->sendnumeric($user->server,368,($this->{name}),"End of channel ban list");
return;
} elsif($modestr eq 'Z' or ($modestr eq '+Z' and $#arguments == -1)) {
foreach(keys(%{$this->{'mutes'}})) {
my @mutedata = @{$this->{'mutes'}->{$_}};
$user->sendnumeric($user->server,367,($this->{name},$_,@mutedata),undef);
}
$user->sendnumeric($user->server,368,($this->{name}),"End of channel mute list");
return;
}
if(!$this->isop($user) && !$user->ismode('O') && !$this->ishalfop($user)) {
$user->sendreply("482 $$this{name} :You're not a channel operator.");
return;
}
foreach(@modebytes) {
if($_ eq "+") {
$state = 1;
} elsif($_ eq "-") {
$state = 0;
} else {
if($_=~/[bZoahqvlkLA]/ &&!($_ eq 'l' && !$state)) {
if ($_ eq "L" && !$state && $this->ismode("L")) { $this->unsetlink($user); push(@accomplishedunset, $_); }
$arg=shift(@arguments);
next if(!defined($arg));
} else {
push(@accomplishedset,$_) if($state && $this->setmode($user,$_));
push(@accomplishedunset,$_) if(!$state && $this->unsetmode($user,$_));
next;
}
if($_ eq "b") {
$arg=$this->setban($user,$arg) if($state);
$arg=$this->unsetban($user,$arg) if(!$state);
} elsif($_ eq "Z") {
$arg=$this->setmute($user,$arg) if($state);
$arg=$this->unsetmute($user,$arg) if(!$state);
} elsif($_ eq "q") {
$arg=$this->setowner($user,$arg) if($state);
$arg=$this->unsetowner($user,$arg) if(!$state);
} elsif($_ eq "a") {
$arg=$this->setadmin($user,$arg) if($state);
$arg=$this->unsetadmin($user,$arg) if(!$state);
} elsif($_ eq "o") {
$arg=$this->setop($user,$arg) if($state);
$arg=$this->unsetop($user,$arg) if(!$state);
} elsif($_ eq "h") {
$arg=$this->sethalfop($user,$arg) if($state);
$arg=$this->unsethalfop($user,$arg) if(!$state);
} elsif($_ eq "v") {
$arg=$this->setvoice($user,$arg) if($state);
$arg=$this->unsetvoice($user,$arg) if(!$state);
} elsif($_ eq "L") {
$arg=$this->setlink($user, $arg) if($state);
$arg=$this->unsetlink($user, $arg) if(!$state);
} elsif($_ eq "l") {
if($arg =~ /\D/) {
$user->sendreply("467 $$this{name} :Channel limit value \2$arg\2 is nonnumeric");
next;
} else {
$this->setmode($user,'l');
$this->{'limit'} = $arg;
}
} elsif($_ eq "k") {
if($state) {
if($this->ismode('k')) {
$user->sendreply("467 $$this{name} :Channel key already set");
undef $arg;
} else {
$this->setmode($user,'k');
$this->{'key'} = $arg;
}
} else {
if($arg ne $this->{key} || !($this->unsetmode($user, "k"))) {
undef $arg;
}
}
}
if($arg) {
push(@accomplishedset,$_) if($state);
push(@accomplishedunset,$_) if(!$state);
push(@accomplishedargs,$arg);
}
}
}
if($#accomplishedset>=0 || $#accomplishedunset>=0) {
my $changestr;
if($#accomplishedset>=0) {
$changestr = "+".join('',@accomplishedset);
}
if($#accomplishedunset>=0) {
$changestr .= "-".join('',@accomplishedunset);
}
if($#accomplishedargs>=0) {
$changestr .= join(' ','',@accomplishedargs);
}
User::multisend(":$$user{nick}!$$user{user}\@$$user{host}".
" MODE>$$this{name} $changestr",
values(%{$this->{'users'}}));
foreach my $server ($user->server->children) {
$server->mode($user,$this,$changestr);
}
}
}
sub topic {
my $this = shift;
my $user = shift;
my $topic = shift;
if(defined($user) && defined($topic)) {
unless($this->ismode('t') && (!($this->isop($user) ||
$user->ismode('S') || $this->ishalfop($user)))) {
$this->{'topic'} = $topic;
$this->{topicsetter} = $user->nick;
$this->{topicsettime} = time();
foreach(keys(%{$this->{'users'}})) {
if($this->{'users'}->{$_}->islocal()) {
$this->{'users'}->{$_}->senddata(":".$user->nick."!".$user->username."\@".$user->host." TOPIC ".$this->{name}." :$topic\r\n");
}
}
} else {
$user->senddata(":".$user->server->{name}." 482 ".$user->nick." ".$this->{name}." :You're not a channel operator\r\n");
}
} else {
if($this->{'topic'}) {
return ($this->{'topic'},$this->{topicsetter},$this->{topicsettime});
} else {
return undef;
}
}
}
# Called when a local user wants to try and join the channel
# (This one does checking and stuff)
sub join {
my $this = shift;
my $user = shift;
my @keys = @_;
my $hasinvitation = 0;
my($fu,$bar) = ($user->nick,$this->{name});
if(defined($this->{hasinvitation}->{$user})) {
$hasinvitation = 1;
delete($this->{hasinvitation}->{$user});
}
# Test to see if the user needs an invitation [and doesn't have
# it/isn't godlike]
if($this->ismode('i') && (!$hasinvitation) && !$user->ismode('S')) {
Connection::sendreply($user, "473 $this->{name} :Cannot join channel (+i)");
return;
}
# If the user is invited, [or godlike] then they can bypass the key,
# limit, and bans
unless($hasinvitation || $user->ismode('S')) {
# Test to see if the user knows the channel key
if($this->ismode('k')) {
unless(grep {$_ eq $this->{key}} @keys) {
Connection::sendreply($user, "475 $this->{name} :Cannot join channel. Requires keyword. (+k)");
return;
}
}
# Test to see if the channel is over the current population limit.
unless($hasinvitation || $user->ismode('O')) {
if(($this->ismode('l')) &&
((1+scalar keys(%{$this->{'users'}}))>$this->{limit})) {
Connection::sendreply($user, "471 $this->{name} :Cannot join channel. Population limit reached. (+l)");
if ($this->ismode('L')) {
my $link = Utils::lookup($this->{link});
if ($link->ismode("L") && $link->ismode("l")) {
if (1+scalar keys(%{$link->{'users'}})>$link->{limit}) {
Connection::sendreply($user, "NOTICE $user->{nick} $this->{name} :Multiple links - you're not going anywhere.");
}
else {
$user->handle_join("JOIN ".$this->{link},$this->{link});
Connection::sendreply($user, "NOTICE $user->{nick} $this->{name} :Forwarding channel");
}
}
else {
$user->handle_join("JOIN ".$this->{link},$this->{link});
Connection::sendreply($user, "NOTICE $user->{nick} $this->{name} :Forwarding channel");
}
}
return;
}
}
# Test for bans, here
my @banmasks = keys(%{$this->{bans}});
my(@banregexps, $mask);
$mask = $user->nick."!".$user->username."\@".$user->host;
foreach(@banmasks) {
my $regexp = $_;
$regexp =~ s/\./\\\./g;
$regexp =~ s/\?/\./g;
$regexp =~ s/\*/\.\*/g;
$regexp = "^".$regexp."\$";
push(@banregexps,$regexp);
}
if(grep {$mask =~ /$_/} @banregexps) {
$user->sendnumeric($user->server,474,$this->{name},"Cannot join channel You're banned. (+b)");
return;
}
}
#do the actual join
if(0==scalar keys(%{$this->{'users'}})) {
$this->firstjoin($user,$user->server);
}
else {
$this->force_join($user,$user->server);
}
$user->sendnumeric($user->server,332,$this->{'name'},$this->{'topic'}) if defined $this->{'topic'};
$user->sendnumeric($user->server,333,$this->{'name'},$this->{'topicsetter'},$this->{'topicsettime'},undef) if defined $this->{'topicsetter'};
if(defined($this->{'topic'})) {
$this->topic($user);
}
$this->names($user);
$user->sendnumeric($user->server,366,$this->{name},"End of /NAMES list.");
}
# Called by (servers) to forcibly add a user, does no checking.
sub force_join {
my $this = shift;
my $user = shift;
my $server = shift; # the server that is telling us about the
# user connecting has to tell us what it is
# so that when we propogate the join on,
# we don't tell it.
Utils::channels()->{$this->{name}} = $this;
$this->{'users'}->{$user->nick()} = $user;
$this->{'jointime'}->{$user->nick()} = time;
$user->{'channels'}->{$this->{name}} = $this;
User::multisend(":$$user{nick}!$$user{user}\@$$user{host} JOIN>:$$this{name}",
values(%{$this->{'users'}}));
foreach my $iserver ($Utils::thisserver->children) {
if($iserver ne $server) {
$iserver->join($user,$this);
}
}
}
# This one is called when a user leaves
sub part {
my($this,$user,$server)=@_;
my @foo;
foreach my $iserver ($Utils::thisserver->children) {
if($iserver ne $server) {
$iserver->part($user,$this);
}
}
@foo=$this->notifyofquit($user);
User::multisend(":$$user{nick}!$$user{user}\@$$user{host} PART>$$this{name}",
@foo,$user);
}
sub kick {
my($this,$user,$target,$excuse)=@_;
my @foo;
my $sap = Utils::lookupuser($target,1);
if(!$this->isop($user) && !$this->ishalfop($user) && !$user->ismode('O')) {