2 # modules.pl: pseudo-Module handler
4 # Version: v0.2 (20000629)
8 if (&IsParam("useStrict")) { use strict; }
14 eval "use IO::Socket";
16 &ERROR("no IO::Socket?");
19 &showProc(" (IO::Socket)");
23 "countdown" => "Countdown.pl",
24 "allowDNS" => "DNS.pl",
25 "debian" => "Debian.pl",
26 "debianExtra" => "DebianExtra.pl",
28 "dumpvars" => "DumpVars.pl",
29 "factoids" => "Factoids.pl",
30 "freshmeat" => "Freshmeat.pl",
31 "kernel" => "Kernel.pl",
32 "ircdcc" => "UserDCC.pl",
33 "perlMath" => "Math.pl",
34 "quote" => "Quote.pl",
35 "rootwarn" => "RootWarn.pl",
36 "search" => "Search.pl",
37 "slashdot" => "Slashdot3.pl",
38 "topic" => "Topic.pl",
39 "units" => "Units.pl",
40 "uptime" => "Uptime.pl",
41 "userinfo" => "UserInfo.pl",
42 "wwwsearch" => "W3Search.pl",
43 "whatis" => "WhatIs.pl",
44 "wingate" => "Wingate.pl",
45 "insult" => "insult.pl",
46 "nickometer" => "nickometer.pl",
48 @myModulesLoadNow = ('topic', 'uptime',);
49 @myModulesReloadNot = ('IRC/Irc.pl','IRC/Schedulers.pl');
52 if (!opendir(DIR, $bot_src_dir)) {
53 &ERROR("can't open source directory $bot_src_dir: $!");
57 &status("Loading CORE modules...");
59 while (defined(my $file = readdir DIR)) {
60 next unless $file =~ /\.pl$/;
61 next unless $file =~ /^[A-Z]/;
62 my $mod = "$bot_src_dir/$file";
63 ### TODO: use eval and exit gracefully?
65 $moduleAge{$mod} = (stat $mod)[9];
66 &showProc(" ($file)") if (&IsParam("DEBUG"));
72 &status("Loading DB modules...");
74 if ($param{'DBType'} =~ /^mysql$/i) {
77 &ERROR("libdbd-mysql-perl is not installed!");
80 &showProc(" (DBI // mysql)");
82 &status(" using MySQL support.");
83 require "$bot_src_dir/db_mysql.pl";
85 } elsif ($param{'DBType'} =~ /^pgsql$/i) {
88 &ERROR("libpgperl is not installed!");
91 &showProc(" (Pg // postgreSQLl)");
93 &status(" using PostgreSQL support.");
94 require "$bot_src_dir/db_pgsql.pl";
95 } elsif ($param{'DBType'} =~ /^dbm$/i) {
97 &status(" using Berkeley DBM 1.85/2.0 support.");
98 require "$bot_src_dir/db_dbm.pl";
101 &status("DB support DISABLED.");
106 sub loadFactoidsModules {
107 &status("Loading Factoids modules...");
109 if (!&IsParam("factoids")) {
110 &status("Factoid support DISABLED.");
114 if (!opendir(DIR, "$bot_src_dir/Factoids")) {
115 &ERROR("can't open source directory Factoids: $!");
119 while (defined(my $file = readdir DIR)) {
120 next unless $file =~ /\.pl$/;
121 next unless $file =~ /^[A-Z]/;
122 my $mod = "$bot_src_dir/Factoids/$file";
123 ### TODO: use eval and exit gracefully?
125 $moduleAge{$mod} = (stat $mod)[9];
126 &showProc(" ($file)") if (&IsParam("DEBUG"));
132 &status("Loading IRC modules...");
133 if (&whatInterface() =~ /IRC/) {
136 &ERROR("libnet-irc-perl is not installed!");
139 &showProc(" (Net::IRC)");
141 &status("IRC support DISABLED.");
145 if (!opendir(DIR, "$bot_src_dir/IRC")) {
146 &ERROR("can't open source directory Factoids: $!");
150 while (defined(my $file = readdir DIR)) {
151 next unless $file =~ /\.pl$/;
152 next unless $file =~ /^[A-Z]/;
153 my $mod = "$bot_src_dir/IRC/$file";
154 ### TODO: use eval and exit gracefully?
156 $moduleAge{$mod} = (stat $mod)[9];
157 &showProc(" ($file)") if (&IsParam("DEBUG"));
162 sub loadMyModulesNow {
166 &status("Loading MyModules...");
167 foreach (@myModulesLoadNow) {
170 if (!exists $param{$_}) {
171 &DEBUG("myModule: $myModules{$_} not loaded.");
174 &loadMyModule($myModules{$_});
178 &status("Modules: Loaded/Total [$loaded/$total]");
181 ### rename to modulesReload?
183 ## my @check = map { $myModules{$_} } keys %myModules;
184 ## push(@check, map { substr($_,2) } keys %moduleAge);
185 my @check = map { substr($_,2) } keys %moduleAge;
187 &DEBUG("rM: moduleAge must be in src/BLAH format?");
188 foreach (keys %moduleAge) {
189 &DEBUG("rM: moduleAge{$_} => '...'.");
194 my $file = (grep /\/$mod/, keys %INC)[0];
196 if (!defined $file) {
197 &DEBUG("rM: mod '$mod' was not found in \%INC.");
202 &DEBUG("rM: file '$file' does not exist?");
206 my $age = (stat $file)[9];
207 next if ($age == $moduleAge{$file});
209 if (grep /$mod/, @myModulesReloadNot) {
210 &DEBUG("rM: SHOULD NOT RELOAD $mod!!!");
214 &DEBUG("rM: (loading) => '$mod' or ($_).");
216 eval "require \"$file\"";
218 &DEBUG("rM: failure: @$");
220 &DEBUG("rM: good! (reloaded)");
227 ### OPTIONAL MODULES.
230 local %perlModulesLoaded = ();
231 local %perlModulesMissing = ();
234 return 0 if (exists $perlModulesMissing{$_[0]});
235 return 1 if (exists $perlModulesLoaded{$_[0]});
239 &WARN("Module: $_[0] is not installed!");
240 $perlModulesMissing{$_[0]} = 1;
243 $perlModulesLoaded{$_[0]} = 1;
244 &status("Module: Loaded $_[0] ...");
245 &showProc(" ($_[0])");
253 &WARN("loadMyModule: module is NULL.");
257 my ($modulebase, $modulefile);
258 if (exists $myModules{$tmp}) {
259 ($modulename, $modulebase) = ($tmp, $myModules{$tmp});
263 my $modulefile = "$bot_src_dir/Modules/$modulebase";
265 return 1 if (grep /$modulefile/, keys %INC);
267 if (! -f $modulefile) {
268 &ERROR("lMM: module ($modulebase) does not exist.");
269 if ($$ == $bot_pid) { # parent.
270 &shutdown() if (defined $shm and defined $dbh);
272 &delForked($modulename);
278 eval "require \"$modulefile\"";
280 &ERROR("cannot load my module: $modulebase");
281 if ($bot_pid == $$) { # parent.
282 &shutdown() if (defined $shm and defined $dbh);
284 &delForked($modulebase);
289 $moduleAge{$modulefile} = (stat $modulefile)[9];
290 &DEBUG("lMM: setting moduleAge{$modulefile} = time();");
292 &status("myModule: Loaded $modulebase ...");
293 &showProc(" ($modulebase)");
298 ### this chews 3megs on potato, 300 kB on slink.
300 ###eval "require 'sys/syscall.ph'";
302 # &WARN("sys/syscall.ph has not been installed//generated. gettimeofday
303 #will use time() instead");
306 #&showProc(" (syscall)");