X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=lib%2Frbot%2Fircbot.rb;h=18b9e1d4ac35ff2e05e5b47d226e6a6e9b26b1f7;hb=53cfadbb9f2b25efe4c22b2fd02f8bc33b5e9d2d;hp=108d0b1d04ac85a7d7a8f8f64742168d8b99550a;hpb=c4d629ad86aae3b8bb4669650df57875252bea92;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/lib/rbot/ircbot.rb b/lib/rbot/ircbot.rb index 108d0b1d..18b9e1d4 100644 --- a/lib/rbot/ircbot.rb +++ b/lib/rbot/ircbot.rb @@ -1,3 +1,4 @@ +# encoding: UTF-8 #-- vim:sw=2:et #++ # @@ -59,15 +60,14 @@ 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 } - # Also output (fatal) errors to STDERR: - if level == Logger::Severity::ERROR or level == Logger::Severity::FATAL + if level == Logger::Severity::ERROR or level == Logger::Severity::FATAL and not $daemonize $stderr.puts str end $log_queue.push qmsg @@ -147,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' @@ -189,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 @@ -201,6 +196,14 @@ 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 + + attr_accessor :webservice + # server we are connected to # TODO multiserver def server @@ -291,7 +294,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', @@ -434,11 +437,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, :store_default => true, + :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 @@ -475,12 +478,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 @@ -508,14 +505,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? @@ -584,8 +575,6 @@ class Bot pf << "#{$$}\n" end - @registry = Registry.new self - @timer = Timer.new @save_mutex = Mutex.new if @config['core.save_every'] > 0 @@ -836,6 +825,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 @@ -1029,11 +1033,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 @@ -1112,13 +1111,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 @@ -1154,6 +1146,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] @@ -1362,8 +1360,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 @@ -1405,7 +1401,6 @@ class Bot def save @save_mutex.synchronize do @plugins.save - DBTree.cleanup_logs end end