+sub chanSet {
+ my($cmd, $chan, $what, $val) = @_;
+
+ if ($cmd eq "+chan") {
+ if (exists $chanconf{$chan}) {
+ &pSReply("chan $chan already exists.");
+ return;
+ }
+ $chanconf{$chan}{_time_added} = time();
+ $chanconf{$what}{autojoin} = 1;
+
+ &pSReply("Joining $chan...");
+ &joinchan($chan);
+
+ return;
+ }
+
+ if (!exists $chanconf{$chan}) {
+ &pSReply("no such channel $chan");
+ return;
+ }
+
+ my $update = 0;
+
+ ### ".chanset +blah"
+ ### ".chanset +blah 10" -- error.
+ if (defined $what and $what =~ s/^([+-])(\S+)/$2/) {
+ my $state = ($1 eq "+") ? 1 : 0;
+ my $was = $chanconf{$chan}{$what};
+
+ if ($state) { # add/set.
+ if (defined $was and $was eq "1") {
+ &pSReply("setting $what for $chan already 1.");
+ return;
+ }
+
+ $was = ($was) ? "; was '$was'" : "";
+ $val = 1;
+
+ } else { # delete/unset.
+ if (!defined $was) {
+ &pSReply("setting $what for $chan is not set.");
+ return;
+ }
+
+ if ($was eq "0") {
+ &pSReply("setting $what for $chan already 0.");
+ return;
+ }
+
+ $was = ($was) ? "; was '$was'" : "";
+ $val = 0;
+ }
+
+ if ($val eq "0") {
+ &pSReply("Unsetting $what for $chan$was.");
+ delete $chanconf{$chan}{$what};
+ } else {
+ &pSReply("Setting $what for $chan to '$val'$was.");
+ $chanconf{$chan}{$what} = $val;
+ }
+
+ $update++;
+
+ ### ".chanset blah testing"
+ } elsif (defined $val) {
+ my $was = $chanconf{$chan}{$what};
+ if (defined $was and $was eq $val) {
+ &pSReply("setting $what for $chan already '$val'.");
+ return;
+ }
+ $was = ($was) ? "; was '$was'" : "";
+ &pSReply("Setting $what for $chan to '$val'$was.");
+
+ $chanconf{$chan}{$what} = $val;
+
+ $update++;
+
+ ### ".chanset"
+ ### ".chanset blah"
+ } else { # read only.
+ if (!defined $what) {
+ &WARN("chanset/DC: what == undefine.");
+ return;
+ }
+
+ 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;
+}
+
+sub rehashConfVars {
+ # this is an attempt to fix where an option is loaded but the module
+ # has not loaded. it also can be used for other things.
+
+ foreach (keys %{ $cache{confvars} }) {
+ my $i = $cache{confvars}{$_};
+ &DEBUG("rehashConfVars: _ => $_");
+
+ if (/^news$/ and $i) {
+ &loadMyModule("news");
+ delete $cache{confvars}{$_};
+ }
+
+ if (/^uptime$/ and $i) {
+ &loadMyModule("uptime");
+ delete $cache{confvars}{$_};
+ }
+
+ if (/^rootwarn$/i and $i) {
+ &loadMyModule($_);
+ delete $cache{confvars}{$_};
+ }
+ }
+
+ &DEBUG("end of rehashConfVars");
+
+ delete $cache{confvars};
+}
+