Example #1
0
	def load_triggers(self):
		groups = loadXML.load_xml_triggers(self.path + '/triggers/')
		for group in groups:
			self.trigger_groups[self.cname].append(group)
Example #2
0
def reload_triggers(line, time, backrefs):
	core.triggers = {}
	core.trigger_groups = []
	core.trigger_groups_active = []
	loadXML.load_xml_triggers()
	core.echo("Triggers Reloaded")
Example #3
0
File: core.py Project: AKJ/sage
def bootstrap():
	global config
	sys.stdout.write("\nAvalon SAGE %s\n" % VERSION)
	sys.stdout.write("(c) 2010-2011 Matt Davis, Paul Shahid, Todd Wilson, (C) 2013 Andrew Johnson\nAll rights reserved, all wrongs revenged.\n\n")

	if debug_mode:
		sys.stdout.write("            >>> DEBUGGING MODE <<<\n\n")


	# Load Config
	config = ConfigParser.ConfigParser()
	if os.path.isfile(config_file) is False:
		sys.exit('Error: Unable to locate your configuration file (%s)' % config_file)
	config.read(config_file)

	# Pull config out of file and into dictionary "options"
	options = {
		# general
		'class': config_get('general', 'class'),
		'name': config_get('general', 'name'),
		'unknown_affliction_ticks': config_getint('general', 'unknown_affliction_ticks'),
		# connection
		'host':	config_get('connection', 'host'),
		'port':	config_getint('connection', 'port'),
		'listen_on': config_getint('connection', 'listen_on'),
		# display
		'newline_on_ga': config_getboolean('display', 'newline_on_ga'),
		#logging
		'logging_enabled': config_getboolean('logging', 'logging_enabled'),
		# healing
		'health_sip_percentage': config_getint('healing', 'health_sip_percentage'),
		'mana_sip_percentage': config_getint('healing', 'mana_sip_percentage'),
		'eat_lestagii': config_getboolean('healing', 'eat_lestagii'),
		'basic_lestagii_health_percentage': config_getint('healing', 'basic_lestagii_health_percentage'),
		'combat_lestagii_health_percentage': config_getint('healing', 'combat_lestagii_health_percentage'),
		'basic_lestagii_mana_percentage': config_getint('healing', 'basic_lestagii_mana_percentage'),
		'combat_lestagii_mana_percentage': config_getint('healing', 'combat_lestagii_mana_percentage'),
		'herb_balance_delay': config_getfloat('healing', 'herb_balance_delay'),
		# pipes
		'elm': config_get_optional('pipes', 'elm'),
		'artyelm': config_get_optional('pipes', 'artyelm'),
		'malloran': config_get_optional('pipes', 'malloran'),
		'artymalloran': config_get_optional('pipes', 'artymalloran'),
		'valerian': config_get_optional('pipes', 'valerian'),
		'artyvalerian': config_get_optional('pipes', 'artyvalerian'),
		'min_elm': config_getint('pipes', 'min_elm'),
		'min_valerian': config_getint('pipes', 'min_valerian'),
		'min_malloran': config_getint('pipes', 'min_malloran'),
		# antiillusion
		'focus_on_impatience_mana_threshold': config_getint('antiillusion', 'focus_on_impatience_mana_threshold'),
	}

	config_modules = config.items('modules')
	config_herbsout = config.items('herbsout')
	default_sections = ['connection', 'general', 'display', 'logging', 'healing', 'pipes', 'herbsout', 'antiillusion', 'modules']
	classdefssections = [x for x in config.sections() if x not in default_sections]
	classdeflist = [config.items(section) for section in classdefssections]
	classdefs = []
	for x in classdeflist:
		for y in x:
			classdefs.append(y)

	del default_sections, classdefssections, classdeflist
	config = options
	options['herbsout'] = {}
	for herb in config_herbsout:
		options['herbsout'][herb[0]] = int(herb[1])

	player.name = config['name']
	player.lestagii_health_percentage = config['basic_lestagii_health_percentage']
	player.lestagii_mana_percentage = config['combat_lestagii_mana_percentage']
	player.combat_class = config['class']
	if config['artyelm'] == None:
		player.elm_pipe = config['elm']
		player.arty_elm = False
	else:
		player.elm_pipe = config['artyelm']
		player.arty_elm = True

	if config['artymalloran'] == None:
		player.malloran_pipe = config['malloran']
		player.arty_malloran = False
	else:
		player.malloran_pipe = config['artymalloran']
		player.arty_malloran = True

	if config['artyvalerian'] == None:
		player.valerian_pipe = config['valerian']
		player.arty_valerian = False
	else:
		player.valerian_pipe = config['artyvalerian']
		player.arty_valerian = True

	_reset_deflist()

	for option in classdefs:
		if option[0] == 'simultaneity':
			player.simultaneity = utils.str_to_bool(option[1])
			continue
		elif option[0] == 'purity_necklace':
			continue # need to actually make that...

		flags = option[1]

		try:
			player.basic[option[0]] = utils.str_to_bool(flags[0])
			player.keepup_basic[option[0]] = utils.str_to_bool(flags[1])
			player.combat[option[0]] = utils.str_to_bool(flags[2])
			player.keepup_combat[option[0]] = utils.str_to_bool(flags[3])
			player.starburst[option[0]] = utils.str_to_bool(flags[4])
			player.keepup_starburst[option[0]] = utils.str_to_bool(flags[5])
		except:
			sys.exit('Invalid configuration for "' + option[0] + '".')

	path = sys.path[0]

	sys.stdout.write("> Loading configuration (%s)\n" % config_file)
	sys.stdout.write("> Loading Triggers\n")
	loadXML.load_xml_triggers(path + '/triggers/')

	sys.stdout.write("> Registering Trigger Dispatch Functions\n")
	Triggers.trigger_dispatch = loadDispatch.load_dir(path + '/inc/trigger_dispatch/')

	sys.stdout.write("> Loading Aliases\n")
	loadXML.load_xml_aliases(path + '/aliases/')

	sys.stdout.write("> Registering Alias Dispatch Functions\n")
	Aliases.alias_dispatch = loadDispatch.load_dir(path + '/inc/alias_dispatch/')

	""" Load modules from config and bootstrap them """
	sys.stdout.write("> Loading Modules\n")
	for cm in config_modules:
		if cm[1] == 'enabled':
			module = cm[0]
			load_module(module, True)

	"""
	Check all functions called by triggers/aliases and make sure
	they have dispatch functions available to them.
	"""
	error = False
	for group in triggers:
		for trigger in triggers[group]:
			functions = triggers[group][trigger].function
			for function in functions:
				if " " in function:
					function = function.split(" ")
					if function[0] == 'pfunction':
						function = function[1]
					else:
						function = function[0]

				if function not in Triggers.trigger_dispatch:
					sys.stdout.write("Error: trigger '%s::%s' calls unavailable trigger dispatch function '%s'\n" % (group, trigger, function))
					error = True
	if error:
		sys.exit()

	for group in aliases:
		for alias in aliases[group]:
			functions = aliases[group][alias].function
			for function in functions:
				if " " in function:
					function = function.split(" ")[0]

				if function not in Aliases.alias_dispatch:
					sys.stdout.write("Error: alias '%s::%s' calls unavailable alias dispatch function '%s'\n" % (group, alias, function))
					error = True

	if error:
		sys.exit()

	"""
	Ensure we don't have duplicates in triggers and aliases.
	This is the quick and dirty way...could massively optmize this.
	"""
	check_dict = {}
	for group in trigger_groups:
		check_dict[group] = check_dict.get(group, 0) + 1

	for item in check_dict:
		if check_dict[item] > 1:
			error = True
			sys.stdout.write("Error: duplicate trigger group: " + item + "\n")

	check_dict = {}
	for group in alias_groups:
		check_dict[group] = check_dict.get(group, 0) + 1

	for item in check_dict:
		if check_dict[item] > 1:
			error = True
			sys.stdout.write("Error: duplicate alias group: " + item + "\n")

	trigger_list = []
	for group in triggers:
		for trigger in triggers[group]:
			trigger_list.append(trigger)

	check_dict = {}
	for trigger in trigger_list:
		check_dict[trigger] = check_dict.get(trigger, 0) + 1

	for item in check_dict:
		if check_dict[item] > 1:
			error = True
			sys.stdout.write("Error: duplicate trigger: " + item + "\n")

	alias_list = []
	for group in aliases:
		for alias in aliases[group]:
			alias_list.append(alias)

	check_dict = {}
	for alias in alias_list:
		check_dict[alias] = check_dict.get(alias, 0) + 1

	for item in check_dict:
		if check_dict[item] > 1:
			error = True
			sys.stdout.write("Error: duplicate alias: " + item + "\n")

	if error:
		sys.exit()

	if player.combat_class == 'monk':
		enable_trigger_group('monk_balances')

	sys.stdout.write("> Initializing Twisted\n")

	import telnetProxy

	factory = telnetProxy.Factory()
	factory.protocol = telnetProxy.TelnetServer
	reactor.listenTCP(config['listen_on'], factory)

	if console_enabled:
		reactor.callWhenRunning(interact, stopReactor=True)

	reactor.addSystemEventTrigger("before", "shutdown", shutdown)
	reactor.run()