hxp
2024-11-15 789490b7d362160f7fca4580df6176498e1eb271
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
#!/usr/bin/python
# -*- coding: GBK -*-
#---------------------------------------------------------------------
#
#---------------------------------------------------------------------
##@package ReadCaptchaImage
# @todo: ¼ÓÔØÍ¼ÐÎÑéÖ¤Âë
#
# @author: panwei
# @date 2011-05-31 21:30
# @version 1.5
#
# @note: 
# @change: "2011-06-05 01:20" Alee ÐÞ¸ÄΪ¶àÎļþ¶ÁÈ¡£¬²»´æÄÚ´æÖÐ
# @change: "2011-06-07 11:10" Alee ·µ»ØÖµÍ³Ò»
# @change: "2011-06-17 11:00" Alee Ìí¼ÓÖØ¶Á¹¦ÄÜ
# @change: "2011-06-23 13:40" Alee Ëæ»úÉú³ÉÑéÖ¤ÂëÖØÔØ
# @change: "2011-07-11 18:00" Alee ÐÞ¸´È«¾Ö²ÎÊý´«²ÎÎÞ·¨±ä¸üµÄÎÊÌâ
#---------------------------------------------------------------------
"""Version = 2011-07-11 18:00"""
#---------------------------------------------------------------------
import ChConfig
import GameWorld
import os
import random
import ShareDefine
import ReadChConfig
#---------------------------------------------------------------------
#È«¾Ö±äÁ¿
g_captchaImageTexDict = {}
g_captchaImageJpegDict = {}
 
#Ëæ»úÑéÖ¤Â뿪¹Ø
Def_Random_Captcha_Open = 1
#---------------------------------------------------------------------
#È«¾Ö³£Á¿
Def_FilePath = ChConfig.GetAppPath() + "\\" + "CaptchaImage\\"
 
#---------------------------------------------------------------------
##»ñÈ¡ÑéÖ¤Âë
# @param ÎÞ²ÎÊý
# @return ÑéÖ¤Âë´ð°¸, ÑéÖ¤ÂëÄÚÈÝ
# @remarks 
def GetCaptchaImage():
    global g_captchaImageTexDict
    global g_captchaImageJpegDict
    
    #¼ì²éËæ»úÑéÖ¤Â뿪¹Ø
    if ReadChConfig.GetEvalChConfig("Random_Captcha_Open") == Def_Random_Captcha_Open:
        captchaName, captchaStream, g_captchaImageJpegDict = \
        GetCaptchaImageByExt(ShareDefine.Def_Notify_WorldKey_ReloadJpegCaptcha, 
                             'jpegCaptchaPath.txt', g_captchaImageJpegDict)
        
        #³É¹¦·µ»Ø
        if captchaName != 0:
            return captchaName, captchaStream
    
    
    #Ëæ»úʧ°ÜÔò¶ÁÈ¡¹Ì¶¨tex
    captchaName, captchaStream, g_captchaImageTexDict = \
    GetCaptchaImageByExt(ShareDefine.Def_Notify_WorldKey_ReloadTexCaptcha, 
                         'texCaptchaPath.txt', g_captchaImageTexDict)
 
    return captchaName, captchaStream
 
##¸ù¾ÝÖ¸¶¨µÄÎļþ»ñÈ¡ÑéÖ¤Âë
# @param reloadKey ÖضÁ×Öµä
# @param fileName Ö¸¶¨Îļþ
# @param gameDict ´æ´¢ÑéÖ¤Âë·¾¶
# @return ÑéÖ¤Âë´ð°¸, ÑéÖ¤ÂëÄÚÈÝ
def GetCaptchaImageByExt(reloadKey, fileName, gameDict):
    if GameWorld.GetGameWorld().GetGameWorldDictByKey(reloadKey):
        #ÖØ¶Á
        gameDict = {}
        #¹Ø±Õ×Öµä
        GameWorld.GetGameWorld().SetGameWorldDict(reloadKey, 0)
   
    if len(gameDict) == 0:
        #ÖØÐ¼ÓÔØÑéÖ¤Âë
        gameDict = ReloadCaptchaImageDict(fileName, gameDict)
    
    if len(gameDict) != 0:
        #Ëæ»ú¸øÒ»¸ö
        captchaInfo = random.choice(gameDict.items())
        
        if len(captchaInfo) != 2:
            GameWorld.ErrLog('Ëæ»ú³öÒ»¸ö´íÎóµÄͼÐÎÑéÖ¤Âë %s'%str(captchaInfo))
            return 0, '', gameDict
        
        fileName, fileStream = GetParseCaptchaInfo(captchaInfo)
        
        return fileName, fileStream, gameDict
    
    GameWorld.ErrLog('GetCaptchaImage Error, Def_FilePath = %s%s'%(Def_FilePath, fileName))
    return 0, '', gameDict
 
 
##ÖØÐ¼ÓÔØÑéÖ¤Âë
# @param ÎÞ²ÎÊý
# @return ×Öµä
def ReloadCaptchaImageDict(fileName, gameDict):
    filePath = Def_FilePath + fileName
    if not os.path.isfile(filePath):
        return
    
    fileIns = open(filePath, 'r')
    
    for imageStr in fileIns.readlines():
        imageInfo = imageStr.split()
        
        if len(imageInfo) != 2:
            continue
        
        gameDict.update({imageInfo[0].strip():imageInfo[1].strip()})
    
    GameWorld.Log('ReloadCaptchaImage %s'%fileName)
        
    return gameDict
 
##»ñµÃÎļþÃûºÍ¶þ½øÖÆÎļþÁ÷
# @param captchaInfo È¡µ½µÄ×Öµä¶Ô
# @return ÎļþÃûºÍ¶þ½øÖÆÎļþÁ÷
def GetParseCaptchaInfo(captchaInfo):
    fileName = captchaInfo[0].split('_')[-1]
    
    openfilePath = Def_FilePath + captchaInfo[1]
    try:
        openfile = open(openfilePath, 'rb')
    except:
        GameWorld.ErrLog('Ëæ»ú³öÒ»¸ö´íÎóµÄͼÐÎÑéÖ¤Âë·¾¶ %s'%str(openfilePath))
        return 0, ''
    
    return fileName, openfile.read()
 
###ÖØÐÂÉèÖÃͼÐÎÑéÖ¤Âë
## @param ÎÞ
## @return ÎÞ
#def ReSetCaptcha():
#    #¿ª¹âÑéÖ¤
#    if ReadChConfig.GetEvalChConfig("Random_Captcha_Open") != Def_Random_Captcha_Open:
#        return
#    
#    curHour = GameWorld.GetCurrentTime().hour
#    
#    #ͼƬºÍÎļþÉú³ÉÖ»Ò»¸öµØÍ¼´¦Àí£¨¾©³Ç£©
#    if GameWorld.GetMap().GetMapID() == ChConfig.Def_MapID_JingCheng \
#    and GameWorld.GetGameWorld().GetCopyMapID() == 0:
#
#        if curHour == 3:
#            #5µãÖØÐÂÉú³ÉͼƬ
#            os.system("start %s"%(Def_FilePath + "VerificationCodePic\\Start.bat"))
#            
#        elif curHour == 4:
#            #6µãÖØÐÂÉú³ÉÎļþ¼Ç¼
#            os.system("start %s"%(Def_FilePath + "jpeg.bat"))
#            
#    if curHour == 5:
#        #7µãÖØ¶ÁÎļþ¼ÓÔØÖÁÓÎÏ·ÖÐ
#        GameWorld.GetGameWorld().SetGameWorldDict(ShareDefine.Def_Notify_WorldKey_ReloadJpegCaptcha, 1)
#    
#    return