+ module Auth
+
+ # We extend the BotUser class to handle remote logins
+ #
+ class BotUser
+
+ # A rather simple method to handle remote logins. Nothing special, just a
+ # password check.
+ #
+ def remote_login(password)
+ if password == @password
+ debug "remote login for #{self.inspect} succeeded"
+ return true
+ else
+ return false
+ end
+ end
+ end
+
+ # We extend the AuthManagerClass to handle remote logins
+ #
+ class AuthManagerClass
+
+ MAX_SESSION_ID = 2**128 - 1
+
+ # Creates a session id when the given password matches the given
+ # botusername
+ #
+ def remote_login(botusername, pwd)
+ @remote_users = Hash.new unless defined? @remote_users
+ n = BotUser.sanitize_username(botusername)
+ k = n.to_sym
+ raise "No such BotUser #{n}" unless include?(k)
+ bu = @allbotusers[k]
+ if bu.remote_login(pwd)
+ raise "ran out of session ids!" if @remote_users.length == MAX_SESSION_ID
+ session_id = rand(MAX_SESSION_ID)
+ while @remote_users.has_key?(session_id)
+ session_id = rand(MAX_SESSION_ID)
+ end
+ @remote_users[session_id] = bu
+ return session_id
+ end
+ return false
+ end
+
+ # Returns the botuser associated with the given session id
+ def remote_user(session_id)
+ return everyone unless session_id
+ return nil unless defined? @remote_users
+ if @remote_users.has_key?(session_id)
+ return @remote_users[session_id]
+ else
+ return nil
+ end
+ end
+ end
+
+ end
+
+
+ # A RemoteMessage is similar to a BasicUserMessage