]> git.donarmstrong.com Git - infobot.git/blob - blootbot/src/Files.pl
userlist display now verbosity>1
[infobot.git] / blootbot / src / Files.pl
1 #
2 # Files.pl: Open and close, read and probably write files.
3 #   Author: dms
4 #  Version: v0.2 (2000502)
5 #  Created: 19991221
6 #
7
8 if (&IsParam("useStrict")) { use strict; }
9
10 # File: Language support.
11 sub loadLang {
12     my ($file) = @_;
13     my $langCount = 0;
14     my $replyName;
15
16     if (!open(FILE, $file)) {
17         &ERROR("FAILED loadLang ($file): $!");
18         exit 0;
19     }
20
21     undef %lang;                # for rehash.
22
23     while (<FILE>) {
24         chop;
25         if ($_ eq "" || /^#/) {
26             undef $replyName;
27             next;
28         }
29
30         if (!/^\s/) {
31             $replyName = $_;
32             next;
33         }
34
35         s/^[\s\t]+//g;
36         if (!$replyName) {
37             &status("loadLang: bad line ('$_')");
38             next;
39         }
40
41         $lang{$replyName}{$_} = 1;
42         $langCount++;
43     }
44     close FILE;
45
46     $file =~ s/^.*\///;
47     &status("Loaded lang $file ($langCount items)");
48 }
49
50 # File: Ignore list.
51 sub loadIgnore {
52     my ($file)  = @_;
53     %ignoreList = ();
54
55     if (!open(FILE, $file)) {
56         &ERROR("FAILED loadIgnore ($file): $!");
57         return;
58     }
59
60     my $count = 0;
61     while (<FILE>) {
62         chomp;
63         next if /^\s*\#/;
64         next unless /\S/;
65
66         if (/^(\S+)[\t\s]+(\S+)([\t\s]+.*)?$/) {
67             $ignoreList{$2} = 1;
68             $count++;
69         }
70     }
71     close FILE;
72
73     $file =~ s/^.*\///;
74     &status("Loaded ignore $file ($count masks)");
75 }
76
77 # File: Irc Servers list.
78 sub loadIRCServers {
79     my ($file) = @_;
80     @ircServers = ();
81     %ircPort = ();
82
83     if (!open(FILE, $file)) {
84         &ERROR("FAILED loadIRCServers ($file): $!");
85         exit 0;
86     }
87
88     while (<FILE>) {
89         chop;
90         next if /^\s*$/;
91         next if /^[\#\[ ]/;
92
93         if (/^(\S+)(:(\d+))?$/) {
94             push(@ircServers,$1);
95             $ircPort{$1} = ($3 || 6667);
96         } else {
97             &status("loadIRCServers: invalid line => '$_'.");
98         }
99     }
100     close FILE;
101
102     $file =~ s/^.*\///;
103     &status("Loaded ircServers $file (". scalar(@ircServers) ." servers)");
104 }
105
106 # File: User List.
107 sub loadUsers {
108     my ($file) = @_;
109     %userList = ();     # clear it.
110
111     if (!open(FILE, $file)) {
112         &ERROR("FAILED loadUsers ($file): $!");
113         exit 0;
114     }
115
116     my $userName;
117
118     while (<FILE>) {
119         next if /^\s*$/;
120         next if /^#/;
121
122         if (/^UserEntry\s+(.+?)\s/) {
123             $userName = $1;
124             if (/\s*\{\s*/) {
125                 while (<FILE>) {
126                     if (/^\s*(\w+)\s+(.+);$/) {
127                         my ($opt,$val) = ($1,$2);
128
129                         $opt =~ tr/A-Z/a-z/;
130                         $val =~ s/\"//g;
131                         $val =~ s/\+// if ($opt =~ /^flags$/i);
132
133                         if ($opt =~ /^mask$/i) {
134                             $userList{$userName}{$opt}{$val} = 1;
135                         } else {
136                             $userList{$userName}{$opt} = $val;
137                         }
138                     } elsif (/^\s*\}\s*$/) {
139                         last;
140                     }
141                 }
142             } else {
143                 &status("parse error: User Entry $userName without right brace");
144             }
145         }
146     }
147     close FILE;
148
149     return unless (&IsParam("VERBOSITY"));
150
151     $file =~ s/^.*\///;
152     &status("Loaded userlist $file (". scalar(keys %userList) ." users)");
153     foreach $userName (keys %userList) {
154         last if ($param{VERBOSITY} < 2);
155
156         &status("  $userName:");
157         &status("    flags: +$userList{$userName}{'flags'}");
158
159         foreach (keys %{$userList{$userName}{'mask'}}) {
160             &status("    hostmask: $_");
161         }
162     }
163 }
164
165 1;