commands.rb
rbmud-0.2/lib/commands.rb · 1.1 KB
From the archive RbMUD-0.2.tar.bz2
Download the archive « Back to the archive contents
#!/usr/bin/env ruby
# $Revision: 1.11 $
# $Date: 2003/12/04 22:18:34 $
# $Author: jefus $
class Commands
attr_accessor :list
def initialize
@list = []
# i like this
# access 0 = player
# access 1 = builder type admin
# access 2 = full admin
Dir.chdir("commands")
Dir["*.rb"].each {|entry| @list << Command.new(entry[0..entry.size-4]) }
end
def include?(name)
@list.each {|command| return true if command.name == name }
return false
end
def [](name)
return find(name)
end
def find(name)
@list.each {|command| return command if command.name == name }
return nil
end
end
class Command
attr_accessor :name, :access
def initialize(name)
@name = name
@access = 0
begin
file = File.open("#{name}.rb")
file.each {|line|
if line =~ /#\s*access (\d)/
@access = $1.to_i
end
}
file.close
load("#{name}.rb")
rescue
Logger.log("Error loading command '#{@name}': #{$!}")
Logger.log($@)
#else
#Logger.log("Loaded command '#{@name}' at access level #{@access}.")
end
end
end
Logger.log("Command code initialized.")