X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=lib%2Frbot%2Fircbot.rb;h=8b827f15fb59484c88c54df7e0523cd88a51638a;hb=b955d424d89655a04ba5f06d3cfee482ae33e713;hp=a1713c2d4a0ecc320d74600cb24a99928ef6c404;hpb=85ee9672fce67d95bf8310af331a576f3492b863;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/lib/rbot/ircbot.rb b/lib/rbot/ircbot.rb index a1713c2d..8b827f15 100644 --- a/lib/rbot/ircbot.rb +++ b/lib/rbot/ircbot.rb @@ -1,3 +1,4 @@ +# encoding: UTF-8 #-- vim:sw=2:et #++ # @@ -59,13 +60,16 @@ def rawlog(level, message=nil, who_pos=1) when String str = message else - str = message.pretty_inspect + str = message.pretty_inspect rescue '?' end qmsg = Array.new str.each_line { |l| qmsg.push [level, l.chomp, who] who = ' ' * who.size } + if level == Logger::Severity::ERROR or level == Logger::Severity::FATAL and not $daemonize + $stderr.puts str + end $log_queue.push qmsg end @@ -143,13 +147,13 @@ end require 'rbot/load-gettext' require 'rbot/config' -require 'rbot/config-compat' require 'rbot/irc' require 'rbot/rfc2812' require 'rbot/ircsocket' require 'rbot/botuser' require 'rbot/timer' +require 'rbot/registry' require 'rbot/plugins' require 'rbot/message' require 'rbot/language' @@ -185,11 +189,6 @@ class Bot # TODO multiserver attr_reader :socket - # bot's object registry, plugins get an interface to this for persistant - # storage (hash interface tied to a db file, plugins use Accessors to store - # and restore objects in their own namespaces.) - attr_reader :registry - # bot's plugins. This is an instance of class Plugins attr_reader :plugins @@ -197,6 +196,12 @@ class Bot # proxies etc as defined by the bot configuration/environment attr_accessor :httputil + # mechanize agent factory + attr_accessor :agent + + # loads and opens new registry databases, used by the plugins + attr_accessor :registry_factory + # server we are connected to # TODO multiserver def server @@ -287,7 +292,7 @@ class Bot :desc => "The CA file used to verify the SSL connection.", :wizard => true) Config.register Config::StringValue.new('server.ssl_ca_path', - :default => '', :requires_restart => true, + :default => default_ssl_ca_path, :requires_restart => true, :desc => "Alternativly a directory that includes CA PEM files used to verify the SSL connection.", :wizard => true) Config.register Config::StringValue.new('server.password', @@ -430,11 +435,11 @@ class Bot }, :desc => "Percentage of IRC penalty to consider when sending messages to prevent being disconnected for excess flood. Set to 0 to disable penalty control.") Config.register Config::StringValue.new('core.db', - :default => "bdb", - :wizard => true, :default => "bdb", - :validate => Proc.new { |v| ["bdb", "tc"].include? v }, + :default => default_db, + :wizard => true, + :validate => Proc.new { |v| Registry::formats.include? v }, :requires_restart => true, - :desc => "DB adaptor to use for storing settings and plugin data. Options are: bdb (Berkeley DB, stable adaptor, but troublesome to install and unmaintained), tc (Tokyo Cabinet, new adaptor, fast and furious, but may be not available and contain bugs)") + :desc => "DB adaptor to use for storing the plugin data/registries. Options: " + Registry::formats.join(', ')) @argv = params[:argv] @run_dir = params[:run_dir] || Dir.pwd @@ -471,12 +476,6 @@ class Bot repopulate_botclass_directory - registry_dir = File.join(@botclass, 'registry') - Dir.mkdir(registry_dir) unless File.exist?(registry_dir) - unless FileTest.directory? registry_dir - error "registry storage location #{registry_dir} is not a directory" - exit 2 - end save_dir = File.join(@botclass, 'safe_save') Dir.mkdir(save_dir) unless File.exist?(save_dir) unless FileTest.directory? save_dir @@ -504,14 +503,8 @@ class Bot $daemonize = true end - case @config["core.db"] - when "bdb" - require 'rbot/registry/bdb' - when "tc" - require 'rbot/registry/tc' - else - raise _("Unknown DB adaptor: %s") % @config["core.db"] - end + @registry_factory = Registry.new @config['core.db'] + @registry_factory.migrate_registry_folder(path) @logfile = @config['log.file'] if @logfile.class!=String || @logfile.empty? @@ -580,8 +573,6 @@ class Bot pf << "#{$$}\n" end - @registry = Registry.new self - @timer = Timer.new @save_mutex = Mutex.new if @config['core.save_every'] > 0 @@ -832,6 +823,21 @@ class Bot end end + def default_ssl_ca_path + file = default_ssl_ca_file + File.dirname file if file + end + + # Determine if tokyocabinet is installed, if it is use it as a default. + def default_db + begin + require 'tokyocabinet' + return 'tc' + rescue LoadError + return 'dbm' + end + end + def repopulate_botclass_directory template_dir = File.join Config::datadir, 'templates' if FileTest.directory? @botclass @@ -1025,11 +1031,6 @@ class Bot rescue SystemExit log_session_end exit 0 - rescue DBFatal => e - fatal "fatal db error: #{e.pretty_inspect}" - DBTree.stats - log_session_end - exit 2 rescue Exception => e error e will_wait = true @@ -1108,13 +1109,6 @@ class Bot log "Killed by server, extra delay multiplier #{oldtf} -> #{too_fast}" end retry - rescue DBFatal => e - fatal "fatal db error: #{e.pretty_inspect}" - DBTree.stats - # Why restart? DB problems are serious stuff ... - # restart("Oops, we seem to have registry problems ...") - log_session_end - exit 2 rescue Exception => e error "non-net exception: #{e.pretty_inspect}" quit_msg = e.to_s @@ -1150,6 +1144,12 @@ class Bot where = ds[:dest] filtered = ds[:text] + if defined? WebServiceUser and where.instance_of? WebServiceUser + debug 'sendmsg to web service!' + where.response << filtered + return + end + # For starters, set up appropriate queue channels and rings mchan = opts[:queue_channel] mring = opts[:queue_ring] @@ -1358,8 +1358,6 @@ class Bot # @timer.stop # debug "Closing registries" # @registry.close - debug "\t\tcleaning up the db environment ..." - DBTree.cleanup_env log "rbot quit (#{message})" end end @@ -1401,7 +1399,6 @@ class Bot def save @save_mutex.synchronize do @plugins.save - DBTree.cleanup_logs end end