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 moduleReloadAll?
182 sub reloadAllModules {
183 &status("Modules: reloading all.");
184 foreach (map { substr($_,2) } keys %moduleAge) {
187 &status("Modules: reloading done.");
190 ### rename to modulesReload?
193 my $file = (grep /\/$mod/, keys %INC)[0];
195 if (!defined $file) {
196 &DEBUG("rM: mod '$mod' was not found in \%INC.");
201 &DEBUG("rM: file '$file' does not exist?");
205 my $age = (stat $file)[9];
206 return if ($age == $moduleAge{$file});
208 if (grep /$mod/, @myModulesReloadNot) {
209 &DEBUG("rM: SHOULD NOT RELOAD $mod!!!");
213 &status("Module: Loading $mod...");
215 eval "require \"$file\""; # require or use?
217 &DEBUG("rM: failure: @$");
219 my $basename = $file;
220 $basename =~ s/^.*\///;
221 &status("Modules: reloaded $basename");
222 $moduleAge{$file} = $age;
227 ### OPTIONAL MODULES.
230 local %perlModulesLoaded = ();
231 local %perlModulesMissing = ();
234 return 0 if (exists $perlModulesMissing{$_[0]});
235 return 1 if (exists $perlModulesLoaded{$_[0]});
237 &DEBUG("lPM: _ => '$_[0]'.");
238 &reloadModule($_[0]);
242 &WARN("Module: $_[0] is not installed!");
243 $perlModulesMissing{$_[0]} = 1;
246 $perlModulesLoaded{$_[0]} = 1;
247 &status("Module: Loaded $_[0] ...");
248 &showProc(" ($_[0])");
256 &WARN("loadMyModule: module is NULL.");
260 my ($modulebase, $modulefile);
261 if (exists $myModules{$tmp}) {
262 ($modulename, $modulebase) = ($tmp, $myModules{$tmp});
265 if ($tmp = grep /^$modulebase$/, keys %myModules) {
266 &DEBUG("lMM: lame hack, file => name => $tmp.");
270 my $modulefile = "$bot_src_dir/Modules/$modulebase";
272 return 1 if (grep /$modulefile/, keys %INC);
274 if (! -f $modulefile) {
275 &ERROR("lMM: module ($modulebase) does not exist.");
276 if ($$ == $bot_pid) { # parent.
277 &shutdown() if (defined $shm and defined $dbh);
279 &delForked($modulename);
285 eval "require \"$modulefile\"";
287 &ERROR("cannot load my module: $modulebase");
288 if ($bot_pid == $$) { # parent.
289 &shutdown() if (defined $shm and defined $dbh);
291 &delForked($modulename);
296 $moduleAge{$modulefile} = (stat $modulefile)[9];
298 &status("myModule: Loaded $modulebase ...");
299 &showProc(" ($modulebase)");
304 ### this chews 3megs on potato, 300 kB on slink.
306 ###eval "require 'sys/syscall.ph'";
308 # &WARN("sys/syscall.ph has not been installed//generated. gettimeofday
309 #will use time() instead");
312 #&showProc(" (syscall)");