- # +chan.
- if ($message =~ /^(chanset|\+chan)(\s+(.*?))?$/) {
- my $cmd = $1;
- my $args = $3;
- my $no_chan = 0;
-
- if (!defined $args) {
- &help($cmd);
- return;
- }
-
- my $chan;
- if ($args =~ s/^($mask{chan})\s*//) {
- $chan = $1;
- } else {
- $chan = "_default";
- $no_chan = 1;
- }
-
- my($what,$val) = split /[\s\t]+/, $args, 2;
-
- ### TODO: "cannot set values without +m".
- return unless (&hasFlag("m"));
-
- if ($cmd eq "+chan") {
- &DEBUG("setting _time_added...");
- $chanconf{$chan}{_time_added} = time();
-
- &pSReply("Joining $chan...");
- &joinchan($chan);
-
- return;
- }
-
- if (!exists $chanconf{$chan}) {
- &pSReply("no such channel $chan");
- return;
- }
-
- my $update = 0;
- ### TODO: $what can be undefined. fix it!
- if ($what =~ s/^\+(\S+)/$1/) {
- my $was = $chanconf{$chan}{$1};
- if ($was eq "1") {
- &pSReply("setting $what for $chan already 1.");
- return;
- }
-
- $was = ($was) ? "; was '$was'" : "";
- &pSReply("Setting $what for $chan to '1'$was.");
-
- $chanconf{$chan}{$what} = 1;
-
- $update++;
- } elsif ($what =~ s/^\-(\S+)/$1/) {
- my $was = $chanconf{$chan}{$1};
- # hrm...
- if (!defined $was) {
- &pSReply("setting $1 for $chan is not set.");
- return;
- }
-
- if ($was eq "0") {
- &pSReply("setting $1 for $chan already 0.");
- return;
- }
-
- $was = ($was) ? "; was '$was'" : "";
- &pSReply("Setting $what for $chan to '0'$was.");
-
- $chanconf{$chan}{$what} = 0;
-
- $update++;
- } elsif (defined $val) {
- my $was = $chanconf{$chan}{$what};
- if ($was eq $val) {
- &pSReply("setting $1 for $chan already '$val'.");
- return;
- }
- $was = ($was) ? "; was '$was'" : "";
- &pSReply("Setting $what for $chan to '$val'$was.");
-
- $chanconf{$chan}{$what} = $val;
-
- $update++;
- } elsif (defined $what) {
- if (exists $chanconf{$chan}{$what}) {
- &pSReply("$what for $chan is '$chanconf{$chan}{$what}'");
- } else {
- &pSReply("$what for $chan is not set.'");
- }
- }
-
- if ($update) {
- $utime_chanfile = time();
- $ucount_chanfile++;
- return;
- }
-
- if ($cmd eq "chanset" and !defined $what) {
- &DEBUG("showing channel conf.");
-
- foreach $chan ($chan, "_default") {
- &pSReply("chan: $chan");
- ### TODO: merge 2 or 3 per line.
- my @items;
- my $str = "";
- foreach (sort keys %{ $chanconf{$chan} }) {
- my $newstr = join(', ', @items);
- if (length $newstr > 60) {
- &pSReply(" $str");
- @items = ();
- }
- $str = $newstr;
- push(@items, "$_ => $chanconf{$chan}{$_}");
- }
- }
-
- return;
- }
-
- return;
+ if ( $message =~ /^(chanunset|chandel)(\s+(.*))?$/ ) {
+ return unless ( &hasFlag('n') );
+ my $cmd = $1;
+ my $args = $3;
+ my $no_chan = 0;
+
+ if ( !defined $args ) {
+ &help($cmd);
+ return;
+ }
+
+ my ($chan);
+ my $delete = 0;
+ if ( $args =~ s/^(\-)?($mask{chan})\s*// ) {
+ $chan = $2;
+ $delete = ($1) ? 1 : 0;
+ }
+ else {
+ &VERB( "no chan arg; setting to default.", 2 );
+ $chan = '_default';
+ $no_chan = 1;
+ }
+
+ if ( !exists $chanconf{$chan} ) {
+ &performStrictReply("no such channel $chan");
+ return;
+ }
+
+ if ( $args ne '' ) {
+
+ if ( !&getChanConf( $args, $chan ) ) {
+ &performStrictReply("$args does not exist for $chan");
+ return;
+ }
+
+ my @chans = &ChanConfList($args);
+ &DEBUG( "scalar chans => " . scalar(@chans) );
+ if ( scalar @chans == 1 and $chans[0] eq '_default' and !$no_chan )
+ {
+ &performStrictReply(
+"ok, $args was set only for _default; unsetting for _defaul but setting for other chans."
+ );
+
+ my $val = $chanconf{$_}{_default};
+ foreach ( keys %chanconf ) {
+ $chanconf{$_}{$args} = $val;
+ }
+ delete $chanconf{_default}{$args};
+ $cache{confvars}{$args} = 0;
+ &rehashConfVars();
+
+ return;
+ }
+
+ if ( $no_chan and !exists( $chanconf{_default}{$args} ) ) {
+ &performStrictReply(
+"ok, $args for _default does not exist, removing from all chans."
+ );
+
+ foreach ( keys %chanconf ) {
+ next unless ( exists $chanconf{$_}{$args} );
+ &DEBUG("delete chanconf{$_}{$args};");
+ delete $chanconf{$_}{$args};
+ }
+ $cache{confvars}{$args} = 0;
+ &rehashConfVars();
+
+ return;
+ }
+
+ &performStrictReply(
+"Unsetting channel ($chan) option $args. (was $chanconf{$chan}{$args})"
+ );
+ delete $chanconf{$chan}{$args};
+
+ return;
+ }
+
+ if ($delete) {
+ &performStrictReply("Deleting channel $chan for sure!");
+ $utime_chanfile = time();
+ $ucount_chanfile++;
+
+ &part($chan);
+ &performStrictReply("Leaving $chan...");
+
+ delete $chanconf{$chan};
+ }
+ else {
+ &performStrictReply("Prefix channel with '-' to delete for sure.");
+ }
+
+ return;