def init__xml_config(self): settings = import_module("settings") xml = get_module_attr("kbe.xml.Xml") data = dict() data_default = dict() for name in reversed(self.apps): d = get_module_attr("%s.__kbengine_xml__" % name, dict()) d_default = get_module_attr("%s.__kbengine_xml_default__" % name, dict()) data = config.update_recursive(data, d) data_default = config.update_recursive(data_default, d_default) default = config.get_default_with_telnet(deepcopy(data_default), settings.Global.telnetOnePassword) data = config.update_recursive(data, default) data = config.update_recursive(data, config.get_default_data()) db = self.get_mongodb() collection = db.kbengine_xml try: d = collection.find({}, dict(_id=False)).next() except StopIteration: collection.save(deepcopy(data_default)) d = dict() data = config.update_recursive(data, d) data = config.final(data, lambda x: x) self.xml_config = data s = xml.dict2xml(data) self.write(s, self.RES_SERVER_DIR, "kbengine.xml")
def handle(entity_base, entity_cell): parent = entity_base.parent() volatile = entity_base.volatile() properties = entity_base.properties() implements = entity_base.implements() base = entity_base.base() cell = Cell() client = entity_base.client() if entity_cell: assert parent == entity_cell.parent() volatile = entity_cell.volatile() properties += entity_cell.properties() assert implements == entity_cell.implements() cell = entity_cell.cell() client += entity_cell.client() for n in reversed(self.apps): h = get_module_attr("%s.plugins.auto_generate.entity_define" % n) if h: h(self, entity_base, entity_cell, parent, volatile, implements, properties, base, cell, client) s = Entity( parent=parent.str(), volatile=volatile.str(), implements=implements.str(), properties=properties.str(), base=base.str(), cell=cell.str(), client=client.str() ).str() self.write(s, entity_base.def_file_path())
def init__third_package(self): install = [] for name in self.apps: install.extend( list(get_module_attr("%s.__third_package__" % name) or [])) self.clear(self.THIRD_PACKAGE_DIR) os.system("pip3 install -t %s %s" % (self.THIRD_PACKAGE_DIR, " ".join(set(install))))
def get_mongodb(self): settings = import_module("settings") client = get_module_attr("pymongo.MongoClient") db_name = "goodmo__%s" % self.uid if "uri" in settings.Global.kbengine_xml_mongodb: c = dict(host=settings.Global.kbengine_xml_mongodb["uri"]) else: c = dict(authSource=db_name, **settings.Global.kbengine_xml_mongodb) return client(**c)[db_name]
def open_async(self): assert self.app not in ("base", "cell") settings = get_module("settings") AsyncHttp = get_module_attr("common.asyncHttp.AsyncHttp") asyncio_loop = get_module_attr("common.asyncio.asyncio_loop") def onAsyncHttpTick(timerID): AsyncHttp.run_frame() def onAsyncioTick(timerID): asyncio_loop.run_frame() gameTimeInterval = settings.Global.gameTimeInterval if self.app == "bots": gameTimeInterval *= 2 if settings.Global.enableAsyncHttp: KBEngine.addTimer(gameTimeInterval, gameTimeInterval, onAsyncHttpTick) if settings.Global.enableAsyncio: KBEngine.addTimer(gameTimeInterval, gameTimeInterval, onAsyncioTick)
def completed(plugins, name): for app in plugins.app_component.values(): plugins.load_all_module("inner_command_common.%s" % app) c = get_module_attr("inner_command_utils.c") doc = c.get_doc() info = c.get_app_info() collect = {} for k, v in doc.items(): d = collect.setdefault(info[k], {}) d[k] = v for appname, d in collect.items(): plugins.write(json.dumps(d, sort_keys=True), plugins.PLUGINS_PROXY_COMMON_DIR, appname, "inner_command.json")
def init__shell(self): settings = import_module("settings") bc = settings.BaseApp.equalizationBaseappAmount + len(settings.BaseApp.multi["baseappIndependence"].dict) base = dict( machine=1, logger=1, interfaces=1, dbmgr=1, baseappmgr=1, cellappmgr=1, loginapp=1, baseapp=bc ) bots = dict(bots=1) shell_maker.set_origin_cid(self.xml_config["originCid"]) self.write(shell_maker.apps_shell(base, True, True), self.SHELL_DIR, "start_server.cmd") self.write(shell_maker.apps_shell(base, True, False), self.SHELL_DIR, "start_server.sh") self.write(shell_maker.apps_shell(bots, False, True), self.SHELL_DIR, "start_bots.cmd") self.write(shell_maker.apps_shell(bots, False, False), self.SHELL_DIR, "start_bots.sh") telnet = dict( bots=1, logger=1, interfaces=1, dbmgr=1, loginapp=1, baseapp=bc, cellapp=1 ) internal_ip_address = get_module_attr("kbe.utils.internal_ip_address") for app, count in telnet.items(): data = dict( ip=internal_ip_address(), port=self.xml_config[app]["telnet_service"]["port"], password=self.xml_config[app]["telnet_service"]["password"] ) port = data["port"] for i in range(count): data["port"] = port + i self.write(shell_maker.app_telnet_shell(data, True), self.TELNET_DIR, "%s%s.%s" % (app, "" if i == 0 else i, "cmd")) self.write(shell_maker.app_telnet_shell(data, False), self.TELNET_DIR, "%s%s.%s" % (app, "" if i == 0 else i, "sh"))
def reqGetInnerCommands(self): if self.canExecuteInnerCommand(): self.client.onInnerCommands(python_client(get_module_attr("inner_command_utils.c").doc))
def run_plugins(self, method): for name in reversed(self.apps): entry = get_module_attr("%s.plugins.auto_generate.%s" % (name, method)) if entry: entry(self, name)
def init__entity(self): self.init_entity("base") self.switch_to_cell() self.init_entity("cell") self.switch_to_base() self.init_entity("base") def handle(entity_base, entity_cell): parent = entity_base.parent() volatile = entity_base.volatile() properties = entity_base.properties() implements = entity_base.implements() base = entity_base.base() cell = Cell() client = entity_base.client() if entity_cell: assert parent == entity_cell.parent() volatile = entity_cell.volatile() properties += entity_cell.properties() assert implements == entity_cell.implements() cell = entity_cell.cell() client += entity_cell.client() for n in reversed(self.apps): h = get_module_attr("%s.plugins.auto_generate.entity_define" % n) if h: h(self, entity_base, entity_cell, parent, volatile, implements, properties, base, cell, client) s = Entity( parent=parent.str(), volatile=volatile.str(), implements=implements.str(), properties=properties.str(), base=base.str(), cell=cell.str(), client=client.str() ).str() self.write(s, entity_base.def_file_path()) for k, v in self.entities[ObjectOfBase].items(): for k2, v2 in v.items(): v2c = self.entities[ObjectOfCell].get(k, {}).get(k2) print(v2.entity) handle(v2, v2c) entities = Entities() for k, v in self.entities[EntityOfBase].items(): for k2, v2 in v.items(): v2c = self.entities[EntityOfCell].get(k, {}).get(k2) print(v2.entity) handle(v2, v2c) has_client = issubclass(v2.entity, KBEngine.Proxy) or (v2c and hasattr(v2c.entity, "client")) info = dict( key=("A" if v2.entity_name == "Equalization" else "") + ("B" if v2.plugin else "A") + ( "A" if has_client else "B") + v2.entity_name, name=v2.entity_name, hasCell=bool(v2c), hasBase=True, hasClient=has_client ) entities.append(info) self.write(entities.str(), self.HOME_DIR, "entities.xml") for k in self.m_entity_plugins["base"].keys(): import_list = [] content_list = [] for name in reversed(self.apps): handler = get_module_attr("%s.plugins.auto_generate.entity_base_content" % name) if handler: content = handler(self, k) if content is not None: if content[0] is not None: import_list.append(content[0]) if content[1] is not None: content_list.append(content[1]) if not content_list: content_list.append(" pass\n") self.write( self.template_proxy_str % dict(app="base", cls_name=k, plugin_name=self.m_entity_plugins["base"][k], import_content=("\n".join(import_list) + "\n") if import_list else "", content="\n".join(content_list)), self.PLUGINS_PROXY_BASE_DIR, k + ".py") for k in self.m_entity_plugins["cell"].keys(): import_list = [] content_list = [] for name in reversed(self.apps): handler = get_module_attr("%s.plugins.entity.cell_content" % name) if handler: content = handler(self, k) if content is not None: if content[0] is not None: import_list.append(content[0]) if content[1] is not None: content_list.append(content[1]) if not content_list: content_list.append(" pass\n") self.write( self.template_proxy_str % dict(app="cell", cls_name=k, plugin_name=self.m_entity_plugins["cell"][k], import_content=("\n".join(import_list) + "\n") if import_list else "", content="\n".join(content_list)), self.PLUGINS_PROXY_CELL_DIR, k + ".py") Type.finish_dict_type() self.write(Type.str(), self.DEF_DIR, 'types.xml')