hxp
4 天以前 388823edfe6308cba6f76ca6dc4f20022c5cb2be
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/usr/bin/python
# -*- coding: GBK -*-
#
# @todo: 
#
# @author: Alee
# @date 2018-1-3 ÏÂÎç05:52:47
# @version 1.0
#
# @note: 
#
#---------------------------------------------------------------------
 
import ConfigParser
import logging
 
class AppConfig():
    def __init__(self, filePath):
        self.config = ConfigParser.ConfigParser()
        self.config.read(filePath)
        
    def SetSection(self, sectionName ):
        self.sectionName = sectionName
        
    def GetValue(self, key):
        return self.config.get(self.sectionName,key) 
    
    def GetIntValue(self, 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")
        
        self.TJGLimitCnt = config.GetIntValue( "TJGLimitCnt")
        
        
    def GetTJGLimitCnt(self):
        return self.TJGLimitCnt
        
    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
    return __gGameConfig
 
if __name__ == '__main__':
    FilePath = "..\Configuration\Config.ini" 
    SectionName = "GameConfig"
 
    ReadConfig( FilePath )
    config = GetConfig()
    print config