This feature has been comitted into SVN now !
There is no need to install it yourself and if you want to use this, then read this post.
[/EDIT]
Its usefull to me, i guess it would be usefull for others aswell.
You need plugins.txt in your control folder.
I don't know what you guys think but maybe it won't be bad to put the plugin config in here aswell.
Since there are hooks even before config.txt is loaded.
Improve it if you can.
plugins.txt:
Code: Select all
# 0 : do not automatically load plugins
# 1 : automatically load all plugins
# 2 : selectively load plugins
autoLoad 2
loadPlugins macro, dKore
Code: Select all
Index: functions.pl
===================================================================
--- functions.pl (revision 6428)
+++ functions.pl (working copy)
@@ -107,7 +107,32 @@
}
sub loadPlugins {
+ no encoding 'utf8';
+ Settings::addControlFile('plugins.txt', loader => [\&parseConfigFile, \%plugins]);
+ use encoding 'utf8';
eval {
+ my $progressHandler = sub {
+ my ($filename) = @_;
+ message TF("Loading %s...\n", $filename);
+ };
+ Settings::loadAll($progressHandler);
+ };
+ if (my $e = caught('UTF8MalformedException')) {
+ $interface->errorDialog(TF(
+ "The file %s must be valid UTF-8 encoded, which it is \n" .
+ "currently not. To solve this prolem, please use Notepad\n" .
+ "to save that file as valid UTF-8.",
+ $e->textfile));
+ exit 1;
+ } elsif (my $e = caught('FileNotFoundException')) {
+ $interface->errorDialog(TF( "Unable to load the file %s. \n" .
+ "It should be located in %s. \n",
+ $e->filename, Settings::getControlFolders));
+ exit 1;
+ } elsif ($@) {
+ die $@;
+ }
+ eval {
Plugins::loadAll();
};
if (my $e = caught('Plugin::LoadException')) {
Index: Globals.pm
===================================================================
--- Globals.pm (revision 6428)
+++ Globals.pm (working copy)
@@ -26,7 +26,7 @@
# Do not use any other Kore modules here. It will create circular dependancies.
our %EXPORT_TAGS = (
- config => [qw(%arrowcraft_items %avoid @chatResponses %cities_lut %config %consoleColors %directions_lut %equipTypes_lut %equipSlot_rlut %equipSlot_lut %haircolors @headgears_lut %items_control %items_lut %itemSlotCount_lut %itemsDesc_lut %itemTypes_lut %jobs_lut %maps_lut %masterServers %monsters_lut %npcs_lut %packetDescriptions %portals_lut %responses %sex_lut %shop %skillsDesc_lut %skillsLooks %skillsArea %skillsEncore %skillsSP_lut %spells_lut %emotions_lut %timeout $char %mon_control %priority %routeWeights %pickupitems %rpackets %itemSlots_lut %skillsStatus %portals_los %skillsState %skillsAilments %elements_lut)],
+ config => [qw(%arrowcraft_items %avoid @chatResponses %cities_lut %config %consoleColors %directions_lut %equipTypes_lut %equipSlot_rlut %equipSlot_lut %haircolors @headgears_lut %items_control %items_lut %itemSlotCount_lut %itemsDesc_lut %itemTypes_lut %jobs_lut %maps_lut %masterServers %monsters_lut %npcs_lut %packetDescriptions %plugins %portals_lut %responses %sex_lut %shop %skillsDesc_lut %skillsLooks %skillsArea %skillsEncore %skillsSP_lut %spells_lut %emotions_lut %timeout $char %mon_control %priority %routeWeights %pickupitems %rpackets %itemSlots_lut %skillsStatus %portals_los %skillsState %skillsAilments %elements_lut)],
ai => [qw(@ai_seq @ai_seq_args %ai_v $AI $AI_forcedOff %targetTimeout)],
state => [qw($accountID $cardMergeIndex @cardMergeItemsID $charID @chars @chars_old %cart @friendsID %friends %incomingFriend %field $field %homunculus $itemsList @itemsID %items $monstersList @monstersID %monsters @npcsID %npcs $npcsList @playersID %players @portalsID @portalsID_old %portals %portals_old $portalsList @storeList $currentChatRoom @currentChatRoomUsers @chatRoomsID %createdChatRoom %chatRooms @skillsID %storage @storageID @arrowCraftID %guild %incomingGuild @spellsID %spells @unknownPlayers @unknownNPCs $statChanged $skillChanged $useArrowCraft %currentDeal %incomingDeal %outgoingDeal @identifyID @partyUsersID %incomingParty @petsID %pets @venderItemList $venderID @venderListsID @articles $articles %venderLists %monsters_old @monstersID_old %npcs_old %items_old %players_old @playersID_old @servers $sessionID $sessionID2 $accountSex $accountSex2 $map_ip $map_port $KoreStartTime $secureLoginKey $initSync $lastConfChangeTime $petsList $playersList $portalsList @playerNameCacheIDs %playerNameCache %pet $pvp @cashList)],
network => [qw($remote_socket $net $messageSender $charServer $conState $conState_tries $encryptVal $ipc $bus $lastPacketTime $masterServer $lastswitch $packetParser $bytesSent $bytesReceived $incomingMessages $outgoingClientMessages $enc_val1 $enc_val2)],
@@ -103,6 +103,7 @@
our %monsters_lut;
our %npcs_lut;
our %packetDescriptions;
+our %plugins;
our %portals_los;
our %portals_lut;
our %priority;
Index: Plugins.pm
===================================================================
--- Plugins.pm (revision 6428)
+++ Plugins.pm (working copy)
@@ -34,7 +34,7 @@
use Modules 'register';
use Globals;
use Utils qw(stringToQuark quarkToString);
-use Utils::DataStructures qw(binAdd);
+use Utils::DataStructures qw(binAdd existsInList);
use Utils::ObjectList;
use Utils::Exceptions;
use Log qw(message);
@@ -71,6 +71,12 @@
##
# void Plugins::loadAll()
#
+# autoLoad
+# 0 : do not automatically load plugins
+# 1 : automatically load all plugins
+# 2 : selectively load plugins
+# loadPlugins pluginname1, pluginname2, ...
+#
# Loads all plugins from the plugins folder, and all plugins that are one subfolder below
# the plugins folder. Plugins must have the .pl extension.
#
@@ -78,41 +84,51 @@
# Throws Plugin::DeniedException if the plugin system refused to load a plugin. This can
# happen, for example, if it detects that a plugin is incompatible.
sub loadAll {
- my (@plugins, @subdirs);
+ message TF("autoLoad is %s\n", $plugins{'autoLoad'});
+ if ($plugins{'autoLoad'}) {
+ my (@plugins, @subdirs, @files);
- my @pluginsFolders;
- @pluginsFolders = Settings::getPluginsFolders() if (defined &Settings::getPluginsFolders);
- foreach my $dir (@pluginsFolders) {
- my @items;
+ my @pluginsFolders;
+ @pluginsFolders = Settings::getPluginsFolders() if (defined &Settings::getPluginsFolders);
+ foreach my $dir (@pluginsFolders) {
+ my @items;
- next if (!opendir(DIR, $dir));
- @items = readdir DIR;
- closedir DIR;
+ next if (!opendir(DIR, $dir));
+ @items = readdir DIR;
+ closedir DIR;
- foreach my $file (@items) {
- push @plugins, "$dir/$file" if (-f "$dir/$file" && $file =~ /\.(pl|lp)$/);
+ foreach my $file (@items) {
+ push @plugins, "$dir/$file" if (-f "$dir/$file" && $file =~ /\.(pl|lp)$/);
+ push @files, "$file" if ($file =~ /\.(pl|lp)$/);
+ }
+ foreach my $subdir (@items) {
+ push @subdirs, "$dir/$subdir" if (-d "$dir/$subdir" && $subdir !~ /^(\.|CVS$)/i);
+ }
}
- foreach my $subdir (@items) {
- push @subdirs, "$dir/$subdir" if (-d "$dir/$subdir" && $subdir !~ /^(\.|CVS$)/i);
+
+ foreach my $plugin (@plugins) {
+ my $file = substr(shift(@files), 0, - 3);
+ next if (!existsInList($plugins{loadPlugins}, $file) && ($plugins{autoLoad} == 2));
+ load($plugin);
}
- }
- foreach my $plugin (@plugins) {
- load($plugin);
- }
+ foreach my $dir (@subdirs) {
+ next unless (opendir(DIR, $dir));
+ @plugins = grep { -f "$dir/$_" && /\.(pl|lp)$/ } readdir(DIR);
+ foreach my $file (@plugins) {
+ push @files, "$file" if ($file =~ /\.(pl|lp)$/);
+ }
+ closedir(DIR);
- foreach my $dir (@subdirs) {
- next unless (opendir(DIR, $dir));
- @plugins = grep { -f "$dir/$_" && /\.(pl|lp)$/ } readdir(DIR);
- closedir(DIR);
-
- foreach my $plugin (@plugins) {
- load("$dir/$plugin");
+ foreach my $plugin (@plugins) {
+ my $file = substr(shift(@files), 0, - 3);
+ next if (!existsInList($plugins{loadPlugins}, $file) && ($plugins{autoLoad} == 2));
+ load("$dir/$plugin");
+ }
}
}
}
-
##
# void Plugins::load(String file)
# file: The filename of a plugin.