require './common.rb' require './module.rb' require './server.rb' require './robots.rb' require 'yaml' module Vrobot4 private # Loads a bot from its configuration +info+. # @param info [Hash] arbitrary bot information # ["type"] The type by name of the bot. # @return [Vrobot4::Robots::Bot] the loaded bot def self.load_bot info type = info["type"] Robots::get_bot_type(type).new info end # Runs all bots in +bots+ in separate threads. # @param bots [Array] all bots to run # @return [void] def self.run_bots bots threads = [] bots.each do |bot| threads << Thread.new do bot.connect end end threads.each do |thread| thread.join end end public # Runs the program. # @param cfg [IO] configuration file to read # @return [void] def self.main cfg Thread.abort_on_exception = true log :INFO, "vrobot version #{Version}" begin cfg = YAML.load cfg.read rescue log :ERROR, "error reading bot config: #{$!}" return end Vrobot4.set_debug(cfg["debug"] || 0) cfg["load"].each do |mod| load mod, true end begin bots = [] cfg["bots"].each do |info| bots << load_bot(info) end log :DEBUGV, "bots: #{bots.to_s}" rescue err = $!.to_s + ?\n + $!.backtrace.first(3).join(?\n) log :ERROR, "error loading bot config: #{err}" return end run_bots bots end end Vrobot4.main open ARGV[0] ## EOF