#!/usr/bin/python # -*- coding: GBK -*- #------------------------------------------------------------------------------- # #------------------------------------------------------------------------------- # ##@package OnServerCMD # ÅäÖÃÎļþ¶ÁÈ¡ # # @author wdb # @date 2012-10-23 # @version 1.3 # # @note # # @change: "2012-11-27 11:11" xrc Ôö¼Óº«¹ú·À³ÁÃÔ¿ª¹Ø # @change: "2012-11-30 09:42" xrc È¥³ýº«¹ú·À³ÁÃÔ¿ª¹Ø£¬ÒÑÒÆÖÁGameServer # @change: "2012-12-03 10:00" wdb ÐÞ¸ÄÖØ¶ÁÅäÖà #--------------------------------------------------------------------- """Version = 2012-12-03 10:00""" #--------------------------------------------------------------------- import traceback import ConfigParser import os import GameWorld import ChConfig import ReadChConfig import ShareDefine #--------------------------------------------------------------------- #ÅäÖÃÏî ConfigSet ={ "VIPClubOn":[0, "config"], # vip¹ó±ö¾ãÀÖ²¿ÉêÇëÊÇ·ñ¿ªÆô "IsMergeWarServe":[0, "config"], # ±¾·þÊÇ·ñʱ¿ç·þ·þÎñÆ÷ } ## ¶ÁÈ¡Åä±í # @param None # @return def ReadConfig(): global g_config try: #self_module = __import__(__name__) g_config = {} configFile = ConfigParser.ConfigParser() #¶ÁÈ¡Êý¾Ý¿âÅäÖÃÎļþconfig.ini configPath = os.path.join(ChConfig.MapServerPath, 'config.ini') if os.path.isfile(configPath): configFile.read(configPath) # »ñµÃÅäÖÃÖµ for key, value in ConfigSet.items(): value = ReadCongfigValue(configFile, value[1], key, value[0]) if value == None: return False g_config[key] = value except: GameWorld.ErrLog('%s'%traceback.format_exc()) return False return True ## »ñµÃÅäÖÃÖµ # @param config ÅäÖÃÎļþ # @param secname ¶ÎÂäÃû # @param keyname ¼üÃû # @param defvalue ĬÈÏÖµ # @return def ReadCongfigValue(config, secname, keyname, defvalue): try: if config.has_option(secname, keyname): value = config.get(secname, keyname) if type(defvalue) == bool: value = type(defvalue)(int(value)) else: value = type(defvalue)(value) else: return defvalue except: msg = 'config secname = %s, keyname = %s, defvalue = %s\n%s'%(secname, keyname, defvalue, traceback.format_exc()) GameWorld.ErrLog(msg) return None return value # ÅäÖÃ×Öµä g_config = None ## ³õʼ»¯ÅäÖà # @param None # @return def GetConfig(): global g_config #ÊÇ·ñÖØ¶ÁËùÓеÄÅäÖñí if GameWorld.GetGameWorld().GetGameWorldDictByKey(ShareDefine.Def_Notify_WorldKey_ReloadConfig): ReadChConfig.ClearAllConfig() elif g_config != None: return g_config if not ReadConfig(): GameWorld.ErrLog("Init config failed.") return g_config ## ɾ³ýÅäÖà # @param None # @return def ClearConfig(): global g_config g_config = None return