| | |
| | | import logging
|
| | |
|
| | | class AppConfig():
|
| | | def __init__(self, filePath):
|
| | | def __init__(self, filePath, sectionName):
|
| | | self.config = ConfigParser.ConfigParser()
|
| | | self.config.read(filePath)
|
| | | self.sectionName = sectionName
|
| | |
|
| | | def SetSection(self, sectionName ):
|
| | | def SetSection(self, sectionName):
|
| | | self.sectionName = sectionName
|
| | |
|
| | | def GetValue(self, key):
|
| | | return self.config.get(self.sectionName,key) |
| | | return self.config.get(self.sectionName, key) |
| | |
|
| | | def GetIntValue(self, key):
|
| | | return self.config.getint(self.sectionName,key) |
| | | return self.config.getint(self.sectionName, key) |
| | |
|
| | | class GameConfig():
|
| | | def __init__(self, filePath):
|
| | | config = AppConfig( filePath )
|
| | | logging.debug( "Config file:%s", filePath )
|
| | | config.SetSection( "ServerConfig" )
|
| | | self.ip = config.GetValue( "IP" )
|
| | | self.port = config.GetIntValue( "Port" )
|
| | | |
| | | config.SetSection( "VersionConfig" )
|
| | | self.ClientVersion = config.GetValue( "ClientVersion" )
|
| | | self.VersionNO = config.GetIntValue( "VERSION_NO" )
|
| | | self.StartCnt = config.GetIntValue( "PACK_START_COUNT" )
|
| | | self.KeyName = config.GetValue( "Key" )
|
| | | keylen = len(self.KeyName)-1
|
| | | self.KeyName = self.KeyName[1:keylen]
|
| | | self.SendKeyDictPath = config.GetValue( "SendKeyDictFile" )
|
| | | |
| | | config.SetSection( "MapDataConfig" )
|
| | | self.MapFilePath = config.GetValue( "MapFilePath" )
|
| | | self.MapPostFix = config.GetValue( "MapPostFix" )
|
| | | |
| | | |
| | | config.SetSection( "ThreadNumberControl" )
|
| | | self.IOThreadNum = config.GetIntValue( "IOWorkerThreadNum" )
|
| | | self.AIThreadNum = config.GetIntValue( "AIWorkerThreadNum" )
|
| | | |
| | | config.SetSection( "RunningParams" )
|
| | | self.UsePsyco = config.GetIntValue( "UsePsyco" )
|
| | | self.AISleepPeriod = config.GetIntValue( "AISleepPeriod" )
|
| | | self.PlayerOffTime = config.GetIntValue( "PlayerOffTime")
|
| | | self.ProcessFindTJGTime = config.GetIntValue( "ProcessFindTJGTime")
|
| | | self.ServerDBConfigPath = config.GetValue( "ServerDBConfigPath")
|
| | | self.StartRunTime = config.GetIntValue( "StartRunTime")
|
| | | |
| | | def GetIOThreadNum(self):
|
| | | return self.IOThreadNum
|
| | | |
| | | def GetAIThreadNum(self):
|
| | | return self.AIThreadNum
|
| | | |
| | | def GetServerIP(self):
|
| | | return self.ip
|
| | | |
| | | def GetServerPort(self):
|
| | | return self.port
|
| | | |
| | | def GetClientVersion(self):
|
| | | return self.ClientVersion
|
| | | |
| | | def GetVersionNo(self):
|
| | | return self.VersionNO
|
| | | |
| | | def GetPackStartCount(self):
|
| | | return self.StartCnt
|
| | | |
| | | def GetKeyString(self):
|
| | | return self.KeyName
|
| | | |
| | | def GetSendKeyDictFilePath(self):
|
| | | return self.SendKeyDictPath
|
| | | |
| | | def GetMapFilePath(self):
|
| | | return self.MapFilePath
|
| | | |
| | | def GetMapFilePostFix(self):
|
| | | return self.MapPostFix
|
| | | |
| | | def GetUsePsyco(self):
|
| | | return self.UsePsyco
|
| | | |
| | | def GetAISleepPeriod(self):
|
| | | return self.AISleepPeriod
|
| | | |
| | | # 玩家下线时长
|
| | | def GetPlayerOffTime(self):
|
| | | return self.PlayerOffTime
|
| | | |
| | | # 从数据库查询脱机挂玩家的间隔
|
| | | def GetProcessFindTJGTime(self):
|
| | | return self.ProcessFindTJGTime
|
| | |
|
| | | def GetServerDBConfigPath(self):
|
| | | return self.ServerDBConfigPath
|
| | |
|
| | | def GetStartRunTime(self):
|
| | | return self.StartRunTime
|
| | | |
| | | def __str__(self):
|
| | | return "ClientVersion:[%s]\n" \
|
| | | "KeyString:[%s]\n" \
|
| | | "MapFilePath:[%s]\n" \
|
| | | "MapFilePostFix:[%s]\n" \
|
| | | "PackStartCount:[%u]\n" \
|
| | | "SendKeyDictFile:[%s]\n" \
|
| | | "ServerIP:[%s]\n" \
|
| | | "ServerPort:[%u]\n" \
|
| | | "VersionNO:[%u]\n" \
|
| | | "IOThreadNum:[%u]\n" \
|
| | | "AIThreadNum:[%u]\n" \
|
| | | "UsePsyco:[%u]\n" \
|
| | | "AISleepPeriod:[%u]\n" \
|
| | | % \
|
| | | ( \
|
| | | self.GetClientVersion(),\
|
| | | self.GetKeyString(), \
|
| | | self.GetMapFilePath(), \
|
| | | self.GetMapFilePostFix(), \
|
| | | self.GetPackStartCount(), \
|
| | | self.GetSendKeyDictFilePath(), \
|
| | | self.GetServerIP(), \
|
| | | self.GetServerPort(), \
|
| | | self.GetVersionNo(), \
|
| | | self.GetIOThreadNum(), \
|
| | | self.GetAIThreadNum(), \
|
| | | self.GetUsePsyco(), \
|
| | | self.GetAISleepPeriod(), \
|
| | | )
|
| | | |
| | | __gGameConfig = None
|
| | |
|
| | | def ReadConfig( filename ):
|
| | | global __gGameConfig
|
| | | if not __gGameConfig:
|
| | | __gGameConfig = GameConfig( filename )
|
| | | |
| | |
|
| | |
|
| | | def GetConfig():
|
| | | global __gGameConfig
|
| | | if not __gGameConfig:
|
| | | FilePath = ".\Config.ini"
|
| | | SectionName = "GeTuiConfig"
|
| | | __gGameConfig = AppConfig (FilePath, SectionName)
|
| | | return __gGameConfig
|
| | |
|
| | | if __name__ == '__main__':
|
| | | FilePath = "..\Configuration\Config.ini" |
| | | SectionName = "GameConfig"
|
| | |
|
| | | ReadConfig( FilePath )
|
| | | config = GetConfig()
|
| | | print config
|