60 lines
1.2 KiB
Ruby
60 lines
1.2 KiB
Ruby
require './common.rb'
|
|
require './module.rb'
|
|
require './server.rb'
|
|
|
|
require 'yaml'
|
|
|
|
module Vrobot4
|
|
private
|
|
def self.loadBot botinfo
|
|
type = botinfo["type"]
|
|
serv = Server::get_server_type(type).new(botinfo)
|
|
|
|
if botinfo.key? "modules" then for mod in botinfo["modules"] do
|
|
serv.load_mod mod
|
|
end end
|
|
|
|
serv
|
|
end
|
|
|
|
def self.runBots bots
|
|
thrds = []
|
|
bots.each {|serv| thrds << Thread.new {serv.connect}}
|
|
thrds.each {|th| th.join}
|
|
end
|
|
|
|
public
|
|
# Runs the program.
|
|
# @param cfg [IO] configuration file to load
|
|
def self.main cfg
|
|
log :INFO, "vrobot version", Version
|
|
|
|
begin
|
|
cfg = YAML.load cfg.read
|
|
rescue
|
|
log :ERROR, "error reading bot config:", $!
|
|
return
|
|
end
|
|
|
|
Vrobot4.debug = cfg["debug"] if cfg.key? "debug"
|
|
cfg["loadmods"].each {|mod| load mod, true}
|
|
|
|
begin
|
|
bots = []
|
|
cfg["bots"].each {|botinfo| bots << loadBot(botinfo)}
|
|
log :DEBUGV, "bots:", bots.to_s
|
|
rescue
|
|
log :ERROR, "error loading bot config:",
|
|
$!.to_s + ?\n + $!.backtrace.first(3).join(?\n)
|
|
return
|
|
end
|
|
|
|
runBots bots
|
|
end
|
|
end
|
|
|
|
Thread.abort_on_exception = true
|
|
Vrobot4.main open(ARGV[0])
|
|
|
|
## EOF
|