def _excute(): appConfig = ConfigManager.Singleton() serverInfo = appConfig["Server"]["Info"] accServerConfig = appConfig["Server"]["Interface"]["AccServer2"] address = (accServerConfig["Address"]["ip"], int(accServerConfig["Address"]["port"])) magiccode = int(accServerConfig["MagicCode"], 16) seqCount = 0 while True: sock = None while True: AccServerConnection2._status = False try: Log.Write("try Acc Server 2 connection to %s:%s"%address) sock = gevent.socket.create_connection(address) except l_socket.error, e: Log.Write("%s" % str(e)) gevent.sleep(2) continue AccServerConnection2._sock = sock AccServerConnection2._reconnectEvent.clear() Log.Write("Acc Server 2 connection to %s:%s" % address) ServerSocketManager.NewConnection(sock.fileno()) taskData = TaskData(sock) taskData.setType(0) shake_acc = shaketoacc_pb2.ShakeToAcc() shake_acc.id = int(serverInfo["ID"]) shake_acc.code = int(serverInfo["Code"], 16) shake_acc.port = 0 taskData.setData(shake_acc.SerializePartialToString()) shake_acc.Clear() ServerSocketManager.SendToConnection(sock.fileno(), taskData) try: sockread = gevent.spawn(ServerSocketRead, sock, AccServerConnection2._reconnectEvent) sockwrite = gevent.spawn(ServerSocketWrite, sock, AccServerConnection2._reconnectEvent) # AccServerConnection2._reconnectEvent.wait(300) AccServerConnection2._reconnectEvent.wait() if not sockread.ready() or not sockread.successful(): sockread.kill() if not sockwrite.ready() or not sockwrite.successful(): sockwrite.kill() finally: AccServerConnection2._sock = None ServerSocketManager.DelConnection(sock.fileno()) sock.close() Log.Write("del Server connection to %s:%s" % address)
def Init(): session = DBEngine.NewSession() try: resourceVersions = session.query(t_section_resource).\ filter(t_section_resource.status == "excute").\ order_by(t_section_resource.id.desc()).all() if resourceVersions is None: Log.Write("[Error]GameResource Error: No GameResource Excute") return False appConfig = ConfigManager.Singleton() GameResourceManager._resource_dict = {} for resourceVersion in resourceVersions: version = resourceVersion.id needrestart = resourceVersion.needrestart versionFiles = session.query(t_section_resource_files).filter(t_section_resource_files.r_id == version).all() if versionFiles is None: continue versionFilesData = [] for versionFile in versionFiles: versionFileData = { "version": version, "id": versionFile.id, "url": versionFile.url, "filepath": versionFile.filepath, "platform": versionFile.platform, "length": versionFile.length, "needrestart": needrestart, "url2": versionFile.url2, "url3": versionFile.url3, } versionFilesData.append(versionFileData) GameResourceManager._resource_dict[version] = versionFilesData # Log.Write("GameResourceManager", GameResourceManager._resource_dict) return True except NoResultFound, nf: Log.Write("[Error]Database Error: %s" % str(nf)) return False
def Init(fixtag=None): Log.LOG_FILE_TIME = datetime.now() if fixtag: Log.LOG_FIXTAG = fixtag appConfig = ConfigManager.Singleton() logConfig = appConfig["Server"]["Log"] if logConfig["print"] == "true": Log.LOG_PRINT = True else: Log.LOG_PRINT = False Log.LOG_PATH = logConfig["path"] if Log.LOG_FIXTAG: Log.LOG_FILE = Log.LOG_PATH + "/" + Log.LOG_FILE_TIME.strftime( "%F") + Log.LOG_FIXTAG + ".log" else: Log.LOG_FILE = Log.LOG_PATH + "/" + Log.LOG_FILE_TIME.strftime( "%F") + ".log" Log.FileLog = open(Log.LOG_FILE, "a+")
def _init(): configmanager = ConfigManager.Singleton() dbconfig = configmanager["Server"]["DataBase"]["DB1"] Log.Write(dbconfig) unix_socket = None if dbconfig["echo"] == "true": bEngineEcho = True else: bEngineEcho = False if "unix_socket" in dbconfig and dbconfig["unix_socket"]: unix_socket = dbconfig["unix_socket"] if unix_socket: conn_str = "mysql://%s:%s@/%s?%s" % ( dbconfig["user"], dbconfig["password"], dbconfig["db"], dbconfig["param"]) DBEngine._engine = create_engine( conn_str, echo=bEngineEcho, pool_size=100, max_overflow=100, pool_recycle=10 * 60, connect_args={'unix_socket': '%s' % (unix_socket, )}) else: conn_str = "mysql://%s:%s@%s:%s/%s?%s" % ( dbconfig["user"], dbconfig["password"], dbconfig["host"], dbconfig["port"], dbconfig["db"], dbconfig["param"]) DBEngine._engine = create_engine(conn_str, echo=bEngineEcho, pool_size=100, max_overflow=100, pool_recycle=10 * 60) Log.Write("conn_str", conn_str) # DBEngine._engine = create_engine(conn_str, echo=bEngineEcho, # pool_size=100, max_overflow=100, pool_recycle=10 * 60, connect_args={'unix_socket': '/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock'}) try: DBEngine._engine.connect() except OperationalError, e: Log.Write(e) return False
def Update(section, changeFiles): """ 更新分区配置 :param section: 分区号 :param changeFiles: 配置文件 """ Log.Write("GameConfigManager.Update") appConfig = ConfigManager.Singleton() gameconfig_root = appConfig["Server"]["Configure"]["root"] GameConfigManager._section = section if not GameConfigManager._dict.has_key(section): GameConfigManager._dict[section] = {} configDir = gameconfig_root + os.sep + str(GameConfigManager._section) Log.Write("configDir", configDir) try: os.mkdir(configDir) except: pass for changeFile in changeFiles: configFilePath = configDir + os.sep + changeFile.ctype + ".json" Log.Write("target", changeFile.url, changeFile.urls[:]) Log.Write("config", configFilePath) # f = codecs.open(configFilePath, "w", "utf-8") # f.write(changeFile.content) # f.close() if GameConfigManager.HttpDownloadFile( [changeFile.url] + changeFile.urls[:], configFilePath): t_section_config.UpdateVersion(section, changeFile.ctype, changeFile.version) if not GameConfigManager._version.has_key(section): GameConfigManager._version[section] = {} GameConfigManager._version[section][ changeFile.ctype] = changeFile.version try: with file(configFilePath, 'r') as f: GameConfigManager._dict[section][ changeFile.ctype] = json.loads(f, encoding='utf-8') except IOError, e: Log.Write( "[Error]GameConfig Error: %s cant read" % (configDir + os.sep + changeFile.ctype + ".json")) return False
def Init(): Log.Write("GameConfigManager.Init 1", GameConfigManager._section) # 分区数 GameConfigManager._ktv = t_ktv.LoadAllToDict() if GameConfigManager._ktv: if GameConfigManager._ktv.has_key("section"): # 分区 GameConfigManager._section = int( GameConfigManager._ktv["section"].value) Log.Write("GameConfigManager.Init 2", GameConfigManager._section) appConfig = ConfigManager.Singleton() gameconfig_root = appConfig["Server"]["Configure"]["root"] configFiles = t_section_config.All( GameConfigManager._section) # 获取分区下面的配置表 for configFile in configFiles: if not GameConfigManager._version.has_key(configFile.section): GameConfigManager._version[configFile.section] = { } # 版本的分区 if not GameConfigManager._dict.has_key(configFile.section): GameConfigManager._dict[configFile.section] = {} Log.Write(configFile.ctype, configFile.section) # 配置名, 分区 GameConfigManager._version[configFile.section][ configFile.ctype] = configFile.version Log.Write(gameconfig_root, os.sep, str(configFile.section), os.sep, configFile.ctype, ".json") # xxxx/3/activity.json configFilePath = gameconfig_root + os.sep + str( configFile.section) + os.sep + configFile.ctype + ".json" Log.Write(configFilePath) try: with file(configFilePath, 'r') as f: GameConfigManager._dict[configFile.section][ configFile.ctype] = json.loads(f, encoding='utf-8') except IOError, e: Log.Write("[Error]GameConfig Error: %s cant read" % configFilePath) return False GameConfigManager.ProcessExt()
def Init(): session = DBEngine.NewSession() try: config_files = session.query(t_section_config, t_section_config_files). \ filter(t_section_config.excute == t_section_config_files.id).all() if config_files is None: Log.Write("[Error]GameConfig Error: No GameConfig Data") return False GameConfigManager._config_dict = {} appConfig = ConfigManager.Singleton() for config_file in config_files: section = config_file[0].section config_file_info = { "section": section, "ctype": config_file[0].ctype, "version": config_file[0].version, "excute": config_file[0].excute, "url": config_file[1].url, "filepath": config_file[1].filepath, "url2": config_file[1].url2, "url3": config_file[1].url3 } # Log.Write(section, config_file_info) if not GameConfigManager._config_dict.has_key(section): GameConfigManager._config_dict[section] = {} GameConfigManager._config_dict[section][ config_file[0].ctype] = config_file_info # for k, v in GameConfigManager._config_dict.items(): # Log.Write("section", k) return True except NoResultFound, nf: Log.Write("[Error]Database Error: %s" % str(nf)) return False
def UpdateVersion(version): session = DBEngine.NewSession() try: versionFilesData = [] targetVersion = session.query(t_section_resource).filter(t_section_resource.id == version).\ filter(t_section_resource.status == "excute").first() if targetVersion: appConfig = ConfigManager.Singleton() # GameResourceManager._resource_dict = {} needrestart = targetVersion.needrestart versionFiles = session.query(t_section_resource_files). \ filter(t_section_resource_files.r_id == version).all() if versionFiles: for versionFile in versionFiles: versionFileData = { "version": version, "id": versionFile.id, "url": versionFile.url, "filepath": versionFile.filepath, "platform": versionFile.platform, "length": versionFile.length, "needrestart": needrestart, "url2": versionFile.url2, "url3": versionFile.url3, } versionFilesData.append(versionFileData) if not versionFilesData: if GameResourceManager._resource_dict.has_key(version): del GameResourceManager._resource_dict[version] else: GameResourceManager._resource_dict[version] = versionFilesData # Log.Write("GameResourceManager", GameResourceManager._resource_dict) return True except NoResultFound, nf: Log.Write("[Error]Database Error: %s" % str(nf)) return False
from Source.Config.ConfigManager import ConfigManager from Source.Log.Write import Log from Source.DataBase.Common.DBEngine import DBEngine from Source.GameData import SystemParams from Source.GameConfig.GameConfigManager2 import GameConfigManager from Source.GameResource.GameResourceManager2 import GameResourceManager if __name__ == '__main__': # 1.读取运行配置 config_file = "config.xml" if len(sys.argv) > 1: config_file = sys.argv[1] # 1.读取运行配置 ConfigManager.Create(config_file) appConfig = ConfigManager.Singleton() Log.Init() Log.Write(ConfigManager.Singleton()) # 2.初始化环境 if not DBEngine.Init(): Log.Write("[Error]Database Init Error") exit(1) SystemParams.Init() # 重新获取更新白名单|更新版本号|前端的更新版本等信息 # 3.预加载配置数据 if not GameConfigManager.Init(): Log.Write("[Error]GameConfig Init Error") exit(1) if not GameResourceManager.Init():