From 74c92a5ffaba07ba32b2297fe7f72d43549f621a Mon Sep 17 00:00:00 2001 From: dms Date: Thu, 13 Nov 2003 08:22:17 +0000 Subject: [PATCH] - upgraded user flags to attributes. write support disabled for now. git-svn-id: https://svn.code.sf.net/p/infobot/code/trunk@885 c11ca15a-4712-0410-83d8-924469b57eb5 --- blootbot/src/DynaConfig.pl | 170 ++++++++++++++++++++++++------------- 1 file changed, 111 insertions(+), 59 deletions(-) diff --git a/blootbot/src/DynaConfig.pl b/blootbot/src/DynaConfig.pl index 5d9a1bc..c425cec 100644 --- a/blootbot/src/DynaConfig.pl +++ b/blootbot/src/DynaConfig.pl @@ -9,7 +9,7 @@ use strict; use vars qw(%chanconf %cache %bans %channels %nuh %users %ignore - %talkWho %dcc %mask); + %talkWho %dcc %mask %flag2attr); use vars qw($utime_userfile $ucount_userfile $utime_chanfile $who $ucount_chanfile $userHandle $chan $msgType $talkchannel $ident $bot_state_dir $talkWho $flag_quit $wtime_userfile @@ -47,7 +47,7 @@ sub readUserFile { undef %ignore; # reset. my $ver = ; - if ($ver !~ /^#v1/) { + if ($ver !~ /^#v[12]/) { &ERROR("old or invalid user file found."); &closeLog(); exit 1; # correct? @@ -61,7 +61,7 @@ sub readUserFile { next if /^$/; next if /^#/; - if (/^--(\S+)[\s\t]+(.*)$/) { # user: middle entry. + if (/^--(\S+)[\s\t]+(.*)$/) { # user: body my ($what,$val) = ($1,$2); if (!defined $val or $val eq "") { @@ -74,22 +74,29 @@ sub readUserFile { next; } - # nice little hack. - if ($what eq "HOSTS") { + # hack for attribute support. + if ($what =~ /^attr$/) { + foreach (split / /, $val) { + $users{$nick}{$what}{$_} = 1; + } + next; + } + + if ($what =~ /^HOSTS$/) { $users{$nick}{$what}{$val} = 1; } else { $users{$nick}{$what} = $val; } - } elsif (/^(\S+)$/) { # user: start entry. + } elsif (/^(\S+)$/) { # user: start. $nick = $1; - } elsif (/^::(\S+) ignore$/) { # ignore: start entry. + } elsif (/^::(\S+) ignore$/) { # ignore: start. $chan = $1; $type = "ignore"; } elsif (/^- (\S+):\+(\d+):\+(\d+):(\S+):(.*)$/ and $type eq "ignore") { - ### ignore: middle entry. + ### ignore: body. my $mask = $1; my(@array) = ($2,$3,$4,$5); ### DEBUG purposes only! @@ -99,12 +106,12 @@ sub readUserFile { } $ignore{$chan}{$mask} = \@array; - } elsif (/^::(\S+) bans$/) { # bans: start entry. + } elsif (/^::(\S+) bans$/) { # bans: start. $chan = $1; $type = "bans"; } elsif (/^- (\S+):\+(\d+):\+(\d+):(\d+):(\S+):(.*)$/ and $type eq "bans") { - ### bans: middle entry. + ### bans: body. # $btime, $atime, $count, $whoby, $reason. my(@array) = ($2,$3,$4,$5,$6); $bans{$chan}{$1} = \@array; @@ -152,16 +159,47 @@ sub writeUserFile { print OUT "$user\n"; foreach (sort keys %{ $users{$user} }) { + # todo: rename what to key? my $what = $_; - my $val = $users{$user}{$_}; + my $val = $users{$user}{$what}; + + if (ref($val) eq "SCALAR") { + print OUT "--$what\t\t$val\n"; + next; + } + + next unless (ref($val) eq "HASH"); - if (ref($val) eq "HASH") { - foreach (sort keys %{ $users{$user}{$_} }) { + if ($what ne "attr") { + foreach (sort keys %{ $users{$user}{$what} }) { print OUT "--$what\t\t$_\n"; } + next; + } + + # disabled until confirmed to work flawlessly. + next if (1); + + # attr support. + my $str = "--$what\t\t"; + my @attr = sort keys %{ $users{$user}{$what} }; + # some fucking weird code ;) does it work? + # any room for improvement? + while (@attr) { + my $attr = shift(@attr); + my $_str = $str." ".$attr; + my $print = 0; + + if (length $str < 60 && length $_str > 60) { + $print++; + } else { + $str = $_str; + $print++ if (!@attr); + } - } else { - print OUT "--$_\t\t$val\n"; + next unless ($print); + print OUT "$str\n"; + $str = "--$what\t\t"; } } print OUT "\n"; @@ -405,15 +443,27 @@ sub writeChanFile { ##### USER COMMANDS. ##### -# todo: support multiple flags. +# todo: support multiple flags, eg: "+o-m" sub IsFlag { my $flags = shift; my ($ret, $f, $o) = ""; &verifyUser($who, $nuh); + # userfile v2 support: + if ($users{$userHandle}{attr}) { + # todo: fix for multiple flags/attr + my $attr = $flag2attr{$flags}; + if (!$attr) { + &WARN("IsFlag: !flag2attr{$flags}"); + return 0; + } + return 1 if ($users{$userHandle}{attr}{$attr}); + return 0; + } + foreach $f (split //, $users{$userHandle}{FLAGS}) { - foreach $o ( split //, $flags ) { + foreach $o (split //, $flags) { next unless ($f eq $o); $ret = $f; @@ -496,13 +546,13 @@ sub ckpasswd { sub hasFlag { my ($flag) = @_; - if (&IsFlag($flag) eq $flag) { - return 1; - } else { + if (&IsFlag($flag) ne $flag) { &status("DCC CHAT: <$who> $message -- not enough flags."); &pSReply("error: you do not have enough flags for that. ($flag required)"); return 0; } + + return 1; } # expire is time in minutes @@ -567,11 +617,9 @@ sub ignoreDel { } sub userAdd { - my($nick,$mask) = @_; + my($nick,$mask) = @_; - if (exists $users{$nick}) { - return 0; - } + return 0 if (exists $users{$nick}); $utime_userfile = time(); $ucount_userfile++; @@ -581,7 +629,7 @@ sub userAdd { $users{$nick}{HOSTS}{$mask} = 1; } - $users{$nick}{FLAGS} ||= $users{_default}{FLAGS}; + $users{$nick}{FLAGS} ||= $users{_default}{FLAGS}; return 1; } @@ -589,9 +637,7 @@ sub userAdd { sub userDel { my($nick) = @_; - if (!exists $users{$nick}) { - return 0; - } + return 0 if (!exists $users{$nick}); $utime_userfile = time(); $ucount_userfile++; @@ -603,17 +649,12 @@ sub userDel { sub banAdd { my($mask,$chan,$expire,$reason) = @_; - $chan ||= "*"; $expire ||= 0; - - if ($expire > 0) { - $expire = $expire*60 + time(); - } + $expire = $expire*60 + time() if ($expire > 0); my $exist = 1; - $exist++ if (exists $bans{$chan}{$mask} or - exists $bans{'*'}{$mask}); + $exist++ if (exists $bans{$chan}{$mask} or exists $bans{'*'}{$mask}); $bans{$chan}{$mask} = [$expire, time(), 0, $who, $reason]; my @chans = ($chan eq "*") ? keys %channels : $chan; @@ -825,31 +866,42 @@ sub rehashConfVars { delete $cache{confvars}; } -# registered flags... not used yet. -my @regFlagsChan = ( - "autojoin", - "limitcheckInterval", - "limitcheckPlus", - "allowConv", - "allowDNS", -### TODO: finish off this list. -); +sub convertUserFileVer2 { + foreach (keys %users) { + my $handle = $_; + my $flags = $users{$handle}{FLAGS}; + if (!$flags) { + &WARN("cUFV2: handle $handle has no flags!"); + next; + } + + my $fail = 0; + foreach (split //, $flags) { + my $flag = $_; + my $attr = $flag2attr{$flag}; + if (!$attr) { + &DEBUG("cUFV2: handle=$handle: flag=$flag does not exist."); + $fail++; + next; + } + $users{$handle}{attr}{$attr} = 1; + } + + next if ($fail); + delete $users{$handle}{FLAGS}; + } +} -my @regFlagsUser = ( - "m", # modify factoid. (includes renaming) - "r", # remove factoid. - "t", # teach/add factoid. - "a", # ask/request factoid. - "n", # bot owner - # can "reload" - "o", # master of bot (automatic +amrt) - # can search on factoid strings shorter than 2 chars - # can tell bot to join new channels - # can [un]lock factoids - "O", # dynamic ops (as on channel). (automatic +o) - "A", # bot administration over /msg - # default is only via DCC CHAT - "T", # add topics. +# support more than one attribute? +%flag2attr = ( + m => "modify_factoid", + r => "delete_factoid", + t => "add_factoid", + a => "ask_factoid", + n => "bot_owner", + o => "bot_master", + A => "admin_over_msg", + T => "topic" ); 1; -- 2.39.2