]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - lib/rbot/core/remote.rb
[auth] randomized default password
[user/henk/code/ruby/rbot.git] / lib / rbot / core / remote.rb
index 43d883dd8796d5303a614e952cb0fce02c3b05e9..d8d43533da3e5ab01e784b91e93b46485b2b5f45 100644 (file)
@@ -4,18 +4,16 @@
 # :title: Remote service provider for rbot
 #
 # Author:: Giuseppe Bilotta (giuseppe.bilotta@gmail.com)
-# Copyright:: Copyright (c) 2006 Giuseppe Bilotta
-# License:: GPLv2
 #
 # From an idea by halorgium <rbot@spork.in>.
 #
 # TODO find a way to manage session id (logging out, manually and/or
 # automatically)
-#
 
 require 'drb/drb'
 
 module ::Irc
+class Bot
 
   module Auth
 
@@ -36,9 +34,9 @@ module ::Irc
       end
     end
 
-    # We extend the AuthManagerClass to handle remote logins
+    # We extend the ManagerClass to handle remote logins
     #
-    class AuthManagerClass
+    class ManagerClass
 
       MAX_SESSION_ID = 2**128 - 1
 
@@ -138,7 +136,7 @@ module ::Irc
       raise "Botmodule #{botmodule.name} tried to unmap #{tmpl.inspect} that was handled by #{tmpl.botmodule}" unless tmpl.botmodule == botmodule.name
       debug "Unmapping #{tmpl.inspect}"
       @templates[handle] = nil
-      @templates.clear unless @templates.nitems > 0
+      @templates.clear unless @templates.compact.size > 0
     end
 
     # We redefine the handle() method from MessageMapper, taking into account
@@ -149,7 +147,7 @@ module ::Irc
     #
     # Presently, the hash returned on success has only one key, :return, whose
     # value is the actual return value of the successfull dispatch.
-    # 
+    #
     # TODO this same kind of mechanism could actually be used in MessageMapper
     # itself to be able to handle the case of multiple plugins having the same
     # 'first word' ...
@@ -162,19 +160,19 @@ module ::Irc
         # Skip this element if it was unmapped
         next unless tmpl
         botmodule = @parent.plugins[tmpl.botmodule]
-        options, failure = tmpl.recognize(m)
-        if options.nil?
-          failures << [tmpl, failure]
+        options = tmpl.recognize(m)
+        if options.kind_of? Failure
+          failures << options
         else
           action = tmpl.options[:action]
           unless botmodule.respond_to?(action)
-            failures << [tmpl, "#{botmodule} does not respond to action #{action}"]
+            failures << NoActionFailure.new(tmpl, m)
             next
           end
           auth = tmpl.options[:full_auth_path]
           debug "checking auth for #{auth}"
           # We check for private permission
-          if m.bot.auth.allow?(auth, m.source, '?')
+          if m.bot.auth.permit?(m.source, auth, '?')
             debug "template match found and auth'd: #{action.inspect} #{options.inspect}"
             return :return => botmodule.send(action, m, options)
           end
@@ -184,8 +182,8 @@ module ::Irc
           return false
         end
       end
-      failures.each {|f, r|
-        debug "#{f.inspect} => #{r}"
+      failures.each {|r|
+        debug "#{r.template.inspect} => #{r}"
       }
       debug "no handler found"
       return false
@@ -193,9 +191,7 @@ module ::Irc
 
   end
 
-  class IrcBot
-
-    # The Irc::IrcBot::RemoteObject class represents and object that will take care
+    # The Irc::Bot::RemoteObject class represents and object that will take care
     # of interfacing with remote clients
     #
     # Example client session:
@@ -261,8 +257,6 @@ module ::Irc
       end
     end
 
-  end
-
   module Plugins
 
     # We create a new Ruby module that can be included by BotModules that want to
@@ -310,25 +304,26 @@ module ::Irc
   end
 
 end
+end
 
 class RemoteModule < CoreBotModule
 
   include RemoteCoreBotModule
 
-  BotConfig.register BotConfigBooleanValue.new('remote.autostart',
-    :default => true,
+  Config.register Config::BooleanValue.new('remote.autostart',
+    :default => false,
     :requires_rescan => true,
     :desc => "Whether the remote service provider should be started automatically")
 
-  BotConfig.register BotConfigIntegerValue.new('remote.port',
+  Config.register Config::IntegerValue.new('remote.port',
     :default => 7268, # that's 'rbot'
     :requires_rescan => true,
     :desc => "Port on which the remote interface will be presented")
 
-  BotConfig.register BotConfigStringValue.new('remote.host',
-    :default => '',
+  Config.register Config::StringValue.new('remote.host',
+    :default => '127.0.0.1',
     :requires_rescan => true,
-    :desc => "Port on which the remote interface will be presented")
+    :desc => "Host on which the remote interface will be presented")
 
   def initialize
     super