hxp
2021-02-20 71a5b8c236d7538053a3a893adccaa0d59798521
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
#!/usr/bin/python
# -*- coding: GBK -*-
#
##@package E:/GameSVN/U3DGame/ProjectSServer/ServerPython/CoreServerGroup/GameServer/Script/GM/GMShell.py
# @todo: 
#
# @author: Alee
# @date 2017-9-8 ÉÏÎç11:28:31
# @version 1.0
#
# @note: 
#
#---------------------------------------------------------------------
# @change: "2017-04-26 16:30" hxp ×ª»¯±àÂë¸ñʽ´¦Àíµ¥ÒýºÅ
#---------------------------------------------------------------------
#"""Version = 2017-04-26 16:30"""
#---------------------------------------------------------------------
import ChConfig
import GameWorld
import Commands
import IPY_GameServer
import CrossRealmMsg
import PyGameData
import traceback
import GMCommon
import ShareDefine
import os
#---------------------------------------------------------------------
g_broadCastList = []
 
## µ¼ÈëGMÈ«²¿ÃüÁî
#  @param importDir Â·¾¶Ãû
#  @return None
#  @remarks º¯ÊýÏêϸ˵Ã÷.
def ImportCommandAll(importDir):
    curPath = ChConfig.GetAppPath() + "Script\\GM"
    for root, dirs, files in os.walk("%s\\%s"%(curPath, importDir)):
        for file in files:
            fileName = os.path.join(root, file)
            fileName = fileName.replace(curPath, "")
            fileName = fileName[1:len(fileName)]
            if fileName.find("__init__") >= 0:
                continue
            
            curFileList = fileName.split(".")
            fileName = curFileList[0]
            ext = curFileList[1]
            if ext not in ChConfig.TYPE_Load_Module_Ext:
                continue
            
            fileName = fileName.replace("\\",".")
            __import__(fileName)
 
ImportCommandAll("Commands")
 
## Ö´ÐÐGMÃüÁî
#  @param index Íæ¼ÒË÷Òý
#  @param tick µ±Ç°Ê±¼ä
#  @return None
#  @remarks º¯ÊýÏêϸ˵Ã÷.
def MapServer_RecvGMCMD(index,tick):
    GameWorld.GetPsycoFunc(__Func_MapServer_RecvGMCMD)(index, tick)
    return
 
## Ö´ÐÐGMÃüÁî
#  @param index Íæ¼ÒË÷Òý
#  @param tick µ±Ç°Ê±¼ä
#  @return None
#  @remarks º¯ÊýÏêϸ˵Ã÷.
def __Func_MapServer_RecvGMCMD(index, tick):
    try:
        gmCmd = IPY_GameServer.IPY_GGMCmd()
        inputStr = gmCmd.GetMsg()
        alist = inputStr.split()
        if len(alist) == 0:
            return 
        
        curPlayer = GameWorld.GetPlayerManager().GetPlayerByIndex(index)
        
        callFunName = alist[0]
        # ÌØÊâµÄÃüÁî²»ÑéÖ¤GMµÈ¼¶£¬ÔÚMapServerÒÑÑéÖ¤Õ˺Å
        if callFunName.startswith("@"):
            callFunName = "GMS_%s" % (callFunName[1:].capitalize())
            
        #ÅжÏÍæ¼ÒÊÇ·ñΪGM
        elif curPlayer.GetGMLevel() == 0:
            GameWorld.Log("###ʹÓÃGMÃüÁî = %s´íÎó,Íæ¼Ò²»ÊÇGM"%(callFunName), curPlayer.GetPlayerID())
            return
        
        #°ÑÊ£Óà²ÎÊýת»»ÎªÕûÐÍ
        for i in range(0, len(alist)):
            if i == 0:
                continue
            value = GameWorld.ToIntDef(alist[i], None)
            if value == None:
                #GameWorld.DebugAnswer(curPlayer, "²ÎÊý´íÎó, ²ÎÊý%s±ØÐëΪ´¿Êý×Ö!" % (i + 1))
                continue
            alist[i] = value
            
        #·Ç¿ç·þ·þÎñÆ÷ÏÂʹÓÿç·þGMÃüÁÔò·¢Ë͵½¿ç·þ
        if not GameWorld.IsCrossServer():
            callFunc = GameWorld.GetExecFunc(Commands, "%s.%s"%(callFunName, "OnGetMergeParam"))
            if callFunc != None:
                extendParamList = callFunc(curPlayer)
                CrossRealmMsg.SendMsgToCrossServer(ShareDefine.ClientServerMsg_GMCMD, alist + extendParamList)
                
        callFunc = GameWorld.GetExecFunc(Commands, "%s.%s"%(callFunName, "OnExec"))
        if callFunc == None:
            #ûÓдËÃüÁî
            GameWorld.Log("###ʹÓÃGMÃüÁî = %s, Ã»ÓиÃÃüÁî!" % callFunName, curPlayer.GetPlayerID())
            GameWorld.DebugAnswer(curPlayer, 'no cmd !!!')
            return
        
        callFunc(curPlayer, alist[1:])
        
    except BaseException:
        GameWorld.DebugAnswer(curPlayer, "Ö´ÐÐGMÃüÁî´íÎó, Çë²é¿´GameServerÈÕÖ¾!")
        errorMsg = str(traceback.format_exc())
        GameWorld.ErrLog('GMÃüÁî´íÎó - > %s'%(errorMsg) , curPlayer.GetPlayerID())
        #=======================================================================
        # if GameWorld.GetGameWorld().GetDebugLevel():
        #    raise BaseException(errorMsg)
        #=======================================================================
        return
#---------------------------------------------------------------------
#===============================================================================
#DBGMCommon    
#    int      GetCmdIndex()   #ÐòÁкÅ
#    int      GetPostTime()   #Ìύʱ¼ä
#    char *      GetGMAcc()   #GMÕʺÅ
#    int      GetCMDLen()     #GMÃüÁ¶È
#    char *      GetCMD()     #»ñȡִÐеÄGMÃüÁî
#===============================================================================
## Ö´ÐÐÊý¾Ý¿âÖеÄGMÃüÁî
#  @param dBGMCommon
#  @return None
#  @remarks º¯ÊýÏêϸ˵Ã÷.
def DoLogic_DBGMCommon(dBGMCommon):
#    callList = dBGMCommon.GetCMD()
#    callList = callList.split()
#    #cmd²ÎÊýË÷Òý
#    cmdIndex = dBGMCommon.GetCmdIndex()
#    
#    try:
#        callName = callList[0]
#    except BaseException:
#        GameWorld.Log( '###¶ÁÈ¡Êý¾Ý¿âGMÃüÁîʧ°Ü,¸ñʽ´íÎó = %s'%(callList) )
#        GMCommon.Send_DataServer_GMCommandResult( cmdIndex, ChConfig.Def_GMTool_Fail )
#        return
#        
#    callFunc = GameWorld.GetExecFunc(Commands, "%s.%s"%(callName, "OnExec"))
#    if not callFunc:
#        GameWorld.Log( '###¶ÁÈ¡Êý¾Ý¿âGMÃüÁîÒì³££¬ÎÞ´ËGMÃüÁî = %s'%(callName) )
#        GMCommon.Send_DataServer_GMCommandResult( cmdIndex, ChConfig.Def_GMTool_Fail )
#        return
#    
#    del callList[0]
#    
#    sameList = [ cmdIndex , dBGMCommon.GetGMAcc() ]
#    callList = sameList + callList
#    
#    #²ÎÊý0:cmdIndex,²ÎÊý1:GMAcc,²ÎÊý2..:GMÃüÁîÐèÒªµÄ²ÎÊý
#    try:
#        callFunc(None, callList)
#    except BaseException , e:
#        GameWorld.Log( '###¶ÁÈ¡Êý¾Ý¿âGMÃüÁî´íÎó, = %s , %s'%(e , callList) )
#        GMCommon.Send_DataServer_GMCommandResult( cmdIndex, ChConfig.Def_GMTool_Fail )
#    
    return
 
 
## Ö´ÐÐGM¹¤¾ßÃüÁî
#  @param index Íæ¼ÒË÷Òý
#  @param tick µ±Ç°Ê±¼ä
#  @return None
#  @remarks º¯ÊýÏêϸ˵Ã÷.
def GMTool_RecvCMD(index, tick):
 
    gmToolCMD = IPY_GameServer.IPY_GGMToolCommand()
    cmd = gmToolCMD.GetCmd()
    orderId = gmToolCMD.GetOrderId()
    
    try:
        # »ñµÃgmÃüÁîÐÅÏ¢
        gmCmdDict = eval(cmd)          
        gmType = gmCmdDict.get(GMCommon.Def_GMKey_Type, '')  
 
        if gmType == None:                        
            GMCommon.GMCommandResult(orderId, gmCmdDict, GMCommon.Def_GMCmdNone)
            return 
        
        callFunc = GameWorld.GetExecFunc(Commands, "%s.%s"%(gmType, "OnExec"))
        if callFunc == None:
            #gmÃüÁî²»¿ÉʹÓÃ
 
            GMCommon.GMCommandResult(orderId, gmCmdDict, GMCommon.Def_GMCmdNone)
            return 
 
        # ×ª»»±àÂë¸ñʽ
        cmdDict = ChangeEncodIng(gmCmdDict) 
        if cmdDict == {}:
            GMCommon.GMCommandResult(orderId, gmCmdDict, GMCommon.Def_EncodeFail)
            return
        
        callFunc(orderId, cmdDict)
        
    except BaseException:
        GMCommon.GMCommandResult(orderId, gmCmdDict, GMCommon.Def_GMGSEntranceFail)
        GameWorld.RaiseException('GMÃüÁî´íÎó\r\n%s'%(traceback.format_exc()))
        return 
 
    return 
 
## ×ª»»±àÂë¸ñʽ
# @param gmCmdDict: gmÃüÁîÊý¾Ý
# @return None 
def ChangeEncodIng(gmCmdDict):
    cmdDict = {}
    
    coding = gmCmdDict.get('coding', '')
    if coding == '':
        return cmdDict
    
    for key, value in gmCmdDict.items():
        
        if not isinstance(value, str):
            continue
        
        # Ôö¼Óu
        try:
            value = value.replace("\r\n", "`r")
            value = value.replace("\'", "\\'")
            translateStr = eval("u'%s'"%value)
            translateStr = translateStr.encode(coding)
        except:
            GameWorld.Log('translateStr error! srcStr = %s '%repr(value))
            return {}
        
        cmdDict[key] = translateStr
        
    return cmdDict
 
## ÊÕµ½×Ó·þÎñÆ÷·¢Ë͵ÄGMÃüÁî
def ClientServerMsg_GMCMD(cmdMsgList, tick):
    if len(cmdMsgList) == 0:
        return 
    
    callName = "%s.%s" % (cmdMsgList[0], "OnMergeServerExec")
    callFunc = GameWorld.GetExecFunc(Commands, callName)
    if callFunc == None:
        GameWorld.ErrLog("ÕÒ²»µ½´ËGMÃüÁî´¦Àíº¯Êý%s" % callName)
        return
    
    GameWorld.Log("Ö´ÐÐ×Ó·þÇëÇóµÄGMÃüÁ%s" % str(cmdMsgList))
    #Ö»½«Êµ¼Ê²ÎÊý´«Èë
    callFunc(cmdMsgList[1:], tick)
    return
 
def AddOfflinePlayerGMTInfo(orderId, queryType, playerFind, gmCmdDict):
    # Íæ¼Ò²»ÔÚÏߣ¬ÏȼǼ£¬µÈÍæ¼ÒÉÏÏߺó´¦Àí£¬¿ª¹Ø·þºóÎÞЧ
    key = (queryType, playerFind)
    ctgInfoList = PyGameData.g_gmtOfflinePlayerInfo.get(key, [])
    ctgInfoList.append(gmCmdDict)
    PyGameData.g_gmtOfflinePlayerInfo[key] = ctgInfoList
    GameWorld.Log("ÀëÏßÍæ¼ÒÌí¼ÓGMT: g_gmtOfflinePlayerInfo=%s" % str(PyGameData.g_gmtOfflinePlayerInfo))
    GMCommon.GMCommandResult(orderId, gmCmdDict, GMCommon.Def_Success, "Player is off line.")
    return
 
def OnPlayerLogin(curPlayer):
    gmtList = []
    nameKey = (ChConfig.queryType_sqtPlayerByName, curPlayer.GetName())
    if nameKey in PyGameData.g_gmtOfflinePlayerInfo:
        gmtList += PyGameData.g_gmtOfflinePlayerInfo.pop(nameKey)
        
    accIDKey = (ChConfig.queryType_sqtPlayerByAccID, curPlayer.GetAccID())
    if accIDKey in PyGameData.g_gmtOfflinePlayerInfo:
        gmtList += PyGameData.g_gmtOfflinePlayerInfo.pop(accIDKey)
        
    if not gmtList:
        return
    
    tagMapID = curPlayer.GetRealMapID()
    GameWorld.Log("ÀëÏßÍæ¼ÒÉÏÏßGMT: tagMapID=%s, %s" % (tagMapID, gmtList), curPlayer.GetPlayerID())
    if not tagMapID:
        return
    
    for gmCmdDict in gmtList:
        pack_type = gmCmdDict.get("pack_type")
        if not pack_type:
            continue
        
        callFunc = GameWorld.GetExecFunc(Commands, "%s.%s"%(pack_type, "OnOfflineCTGInfo"))
        if callFunc:
            GameWorld.Log("Íæ¼ÒÉÏÏßÖ´ÐÐGMT: %s, tagMapID=%s, %s" % (pack_type, tagMapID, gmCmdDict), curPlayer.GetPlayerID())
            callFunc(curPlayer, tagMapID, gmCmdDict)
            
    return