Thread bot connections in a separate function
parent
7f0f02a997
commit
9a7512c7c3
|
@ -6,11 +6,8 @@ require 'yaml'
|
|||
|
||||
module Vrobot4
|
||||
def self.loadServer servinfo
|
||||
name = servinfo["name"]
|
||||
type = servinfo["type"]
|
||||
|
||||
log :INFO, "loadServer: loading configuration for", name
|
||||
|
||||
serv = Server::get_server_type(type).new(servinfo)
|
||||
|
||||
servinfo.has_key?("modules") && servinfo["modules"].each \
|
||||
|
@ -21,9 +18,16 @@ module Vrobot4
|
|||
|
||||
def self.loadBot botinfo
|
||||
servers = []
|
||||
log :INFO, "loadBot: loading configuration for", botinfo["name"]
|
||||
botinfo["servers"].each {|servinfo| servers << loadServer(servinfo)}
|
||||
servers
|
||||
{:info => botinfo, :servs => servers}
|
||||
end
|
||||
|
||||
def self.runBots bots
|
||||
thrds = []
|
||||
bots.each do |bot|
|
||||
bot[:servs].each {|serv| thrds << Thread.new {serv.connect}}
|
||||
end
|
||||
thrds.each {|th| th.join}
|
||||
end
|
||||
|
||||
def self.main cfgname
|
||||
|
@ -36,18 +40,15 @@ module Vrobot4
|
|||
|
||||
Vrobot4.debug = cfg["debug"] if cfg.has_key? "debug"
|
||||
|
||||
cfg["loadmods"].each {|mod| load mod, true}
|
||||
|
||||
begin
|
||||
bots = []
|
||||
thrds = []
|
||||
cfg["loadmods"].each {|mod| load mod, true}
|
||||
cfg["bots"] .each {|botinfo| bots << loadBot(botinfo)}
|
||||
log :DEBUG, "bots:", bots.to_s
|
||||
bots.each do |servs|
|
||||
servs.each {|serv| thrds << Thread.new {serv.connect}}
|
||||
end
|
||||
thrds.each {|th| th.join}
|
||||
bots = []
|
||||
cfg["bots"].each {|botinfo| bots << loadBot(botinfo)}
|
||||
log :DEBUGV, "bots:", bots.to_s
|
||||
runBots bots
|
||||
rescue
|
||||
log :ERROR, "error loading bot configuration:", $!
|
||||
log :ERROR, "error loading bot config:", $!
|
||||
exit
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue