require './common.rb' require './module.rb' require './server.rb' require 'yaml' module Vrobot4 private # Loads a bot from its configuration +botinfo+. # @param botinfo [Hash] arbitrary bot information # ["type"] The type by name of the bot. # @return [Vrobot4::Server] the loaded bot def self.load_bot botinfo type = botinfo["type"] serv = Server::get_server_type(type).new botinfo for mod in botinfo["modules"] do serv.load_mod mod end serv 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 |server| threads << Thread.new do server.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 |botinfo| bots << load_bot(botinfo) 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