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
#!/usr/bin/python
# -*- coding: GBK -*-
#-------------------------------------------------------------------------------
#
##@package PyMongoDataServer.GM.GMShell
#
# @todo:dbÖ´ÐÐGMÃüÁî
# @author hxp
# @date 2025-03-04
# @version 1.0
#
# ÏêϸÃèÊö: dbÖ´ÐÐGMÃüÁî
#
#-------------------------------------------------------------------------------
#"""Version = 2025-03-04 16:30"""
#-------------------------------------------------------------------------------
 
 
from DBCommon import GlobalFunctions
from Common import mylog
import Commands
import os
 
## µ¼ÈëGMÈ«²¿ÃüÁî
#  @param importDir Â·¾¶Ãû
#  @return None
#  @remarks º¯ÊýÏêϸ˵Ã÷.
def ImportCommandAll(importDir):
    curPath = GlobalFunctions.getAppPath()
    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 ['pyc', 'py']:
                continue
            
            fileName = fileName.replace("\\",".")
            __import__(fileName)
 
ImportCommandAll("GM\\Commands")
 
## º¯Êýµ÷ÓÃ
#  @param curCallObj ÊµÀý£¨¿ÉÄÜÊÇij¸öÎļþÃû£© 
#  @param callName ÊµÀýµÄij¸öÊôÐÔ
#  @return ÊôÐÔ
def ParseNameGetObj(curCallObj, callName):
    callList = callName.split(".")
    if len(callList) <= 1:
        return None
    
    for curCallName in callList:
        if hasattr(curCallObj, curCallName) != True:
            #ÎÞ´ËÊôÐÔ
            return None
        
        curCallObj = getattr(curCallObj, curCallName)
        
    return curCallObj
 
## Íⲿµ÷ÓõĻñÈ¡ÊôÐÔ£¬ÇÒÊÇ¿ÉÒÔcallµÄ
#  @param curCallObj ÊµÀý£¨¿ÉÄÜÊÇij¸öÎļþÃû£© 
#  @param callName ÊµÀýµÄij¸öÊôÐÔ
#  @return ¿ÉÒÔcallµÄÊôÐÔ
#  @remarks º¯ÊýÏêϸ˵Ã÷.
def GetExecFunc(curCallObj, callName):
    curCallObj = ParseNameGetObj(curCallObj, callName)
    
    if curCallObj == None:
        return None
        
    if callable(curCallObj) != True:
        #²»¿Éµ÷ÓÃ
        return None
    
    return curCallObj   
 
def ClientGMCommand(msgData):
    mylog.debug('¿ç·þDBÊÕµ½×Ó·þGMÃüÁî: %s' % msgData)
    cmdMsgList = msgData.get("cmdMsgList", [])
    if not cmdMsgList:
        return []
    dbAnswerList = []
    cmdName = cmdMsgList[0]
    callName = "%s.%s"%(cmdName, "OnCrossDBExec")
    callFunc = GetExecFunc(Commands, callName)
    if callFunc != None:
        callFunc(cmdMsgList[1:], dbAnswerList)
    return dbAnswerList
 
def DBGMCommand(cmdMsg):
    mylog.debug('DBÊÕµ½GameServerµÄGMÃüÁî: %s' % cmdMsg)
    if not cmdMsg:
        return []
    dbAnswerList = []
    try:
        cmdMsgList = eval(cmdMsg)
        cmdName = cmdMsgList[0]
        callName = "%s.%s"%(cmdName, "OnDBExec")
        callFunc = GetExecFunc(Commands, callName)
        if callFunc != None:
            callFunc(cmdMsgList[1:], dbAnswerList)
    except:
        pass
    return dbAnswerList