Esempio n. 1
0
 def loadConfigs(self):
     print("Loading configs......")
     _G.setGlobalVarTo_Global("AppConfig", AppConfig)
     _G.setGlobalVarTo_Global("ClientConfig", ClientConfig())
     # 设置客户端配置的全局变量
     print("Loaded configs!")
     pass
Esempio n. 2
0
def _loadRsaDecode_():
    # 加载rsa密钥编解码方法
    _G.setGlobalVarTo_Global("EncodeStr", encodeStr)
    _G.setGlobalVarTo_Global("DecodeStr", decodeStr)
    # 更新main.js的公钥和首页地址
    publicKey = getPublicKey()
    publicKey = publicKey.replace("\n", "")
    mainJSFile, content = os.path.join(CURRENT_PATH, "assets", "static", "js",
                                       "main.js"), ""
    with open(mainJSFile, "r", encoding="utf-8") as f:
        isPking = False
        for line in f.readlines():
            # 更新HOME_URL
            if re.search("var HOME_URL.*=.*\".*\"", line):
                line = re.sub("\".*\";?", f"\"{HOME_URL}\";", line)
            # 更新PUBLIC_KEY
            if re.search("var PUBLIC_KEY.*\".*\"", line):
                line = re.sub("\".*\";?", f"\"{publicKey}\";", line)
            elif re.search("var PUBLIC_KEY.*\".*", line):
                line = re.sub("\".*;?", f"\"{publicKey}\";", line)
                isPking = True
            else:
                if isPking:
                    if re.search("\";?", line):
                        isPking = False
                    continue
            content += line
    with open(mainJSFile, "w", encoding="utf-8") as f:
        f.write(content)
Esempio n. 3
0
 def loadGClass(self):
     _G.setGlobalVarTo_Global("BaseScene", BaseScene)
     # 设置基础场景的全局变量
     _G.setGlobalVarTo_Global("BaseView", BaseView)
     # 设置基础视图的全局变量
     self.loadLogger()
     # 加载日志类变量
     pass
Esempio n. 4
0
    def loadDependPath(self):
        def getDependPath(path):
            dependPath = os.path.abspath(
                os.path.join(self.__mainPath, "..", path))
            if os.path.exists(dependPath):
                return dependPath
            return os.path.abspath(os.path.join(self.__projectPath, path))

        _G.setGlobalVarTo_Global("GetDependPath", getDependPath)
Esempio n. 5
0
def _loadReleaseToken_():
    tokenFilePath = os.path.join(CURRENT_PATH, "release_token.json")
    # 设置获取发布Token的全局方法
    global lastReleaseTokenTime
    global releaseToken
    releaseToken = ""
    # 初始化

    # 更新Token
    def updateToken():
        # 更新时间
        global lastReleaseTokenTime
        lastReleaseTokenTime = datetime.datetime.now()
        # 生成Token
        global releaseToken
        randCode = random_util.randomMulti(32)
        # 32位随机码
        releaseToken = hashlib.md5("|".join([
            datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S.%f%z"),
            randCode
        ]).encode("utf-8")).hexdigest()
        _G._GG("Log").i("======== New Release Token ========", releaseToken)
        base_util.sendMsgToAllMgrs(
            f"JDreamHeart New Release Token: {releaseToken}.")
        # 保存到文件中
        with open(tokenFilePath, "w") as f:
            f.write(
                json.dumps({
                    "token": releaseToken,
                    "timestamp": lastReleaseTokenTime.timestamp(),
                }))

    # 获取Token
    def getToken():
        global lastReleaseTokenTime
        delta = datetime.datetime.now() - lastReleaseTokenTime
        if delta.days >= 10:
            updateToken()
            # 距离上次请求超过10天,更新Token
        global releaseToken
        return releaseToken

    # 设置获取Token的全局变量
    _G.setGlobalVarTo_Global("GetReleaseToken", getToken)
    # 检测更新当前Token
    if os.path.exists(tokenFilePath):
        with open(tokenFilePath, "r") as f:
            info = json.loads(f.read())
            if "token" in info and "timestamp" in info:
                releaseToken = info["token"]
                lastReleaseTokenTime = datetime.datetime.fromtimestamp(
                    info["timestamp"])
        pass
    # 判断是否更新Token
    if not releaseToken:
        updateToken()
Esempio n. 6
0
    def loadUniqueIdFunc(self):
        global uniqueId
        uniqueId = 0

        def getUniqueId():
            global uniqueId
            uniqueId += 1
            return uniqueId

        _G.setGlobalVarTo_Global("getUniqueId", getUniqueId)
Esempio n. 7
0
 def loadLogger(self):
     cliConf = _G._GG("ClientConfig").Config()
     # 服务配置
     path = cliConf.Get("log", "path", "").replace("\\", "/")
     name = cliConf.Get("log", "name", "pytoolsip-client")
     curTimeStr = time.strftime("%Y_%m_%d", time.localtime())
     logger = Logger("Common",
                     isLogFile=True,
                     logFileName=os.path.join(
                         self.__projectPath, path,
                         name + ("_%s.log" % curTimeStr)),
                     maxBytes=int(cliConf.Get("log", "maxBytes")),
                     backupCount=int(cliConf.Get("log", "backupCount")))
     _G.setGlobalVarTo_Global("Log", logger)
     # 设置日志类的全局变量
     return logger
Esempio n. 8
0
 def loadPaths(self):
     _G.setGlobalVarTo_Global("g_ProjectPath", self.__projectPath + "/")
     _G.setGlobalVarTo_Global("g_DataPath", self.__projectPath + "/data/")
     if not os.path.exists(_G._GG("g_DataPath")):
         os.makedirs(_G._GG("g_DataPath"))
         # 若工程数据文件不存在,则需创建该目录
     _G.setGlobalVarTo_Global("g_AssetsPath", self.__mainPath + "/")
     _G.setGlobalVarTo_Global("g_CommonPath", self.__mainPath + "/common/")
     pass
Esempio n. 9
0
 def loadPaths(self):
     _G.setGlobalVarTo_Global(
         "g_ProjectPath",
         os.path.abspath(os.path.join(CURRENT_PATH, "..")) + "/")
     _G.setGlobalVarTo_Global("g_BinPath",
                              _G._GG("g_ProjectPath") + "bin/")
     _G.setGlobalVarTo_Global("g_LibPath",
                              _G._GG("g_ProjectPath") + "lib/")
     _G.setGlobalVarTo_Global("g_SrcPath", CURRENT_PATH + "/")
     pass
Esempio n. 10
0
def _loadLogger_():
    # Logger参数
    path = "log"
    name = "pytoolsip-website"
    curTimeStr = time.strftime("%Y_%m_%d", time.localtime())
    maxBytes = 102400000
    backupCount = 10
    # 保存Logger到全局变量中
    logger = Logger("Common",
                    level=logLevel,
                    isLogFile=True,
                    logFileName=os.path.join(CURRENT_PATH, path,
                                             name + ("_%s.log" % curTimeStr)),
                    maxBytes=maxBytes,
                    backupCount=backupCount)
    _G.setGlobalVarTo_Global("Log", logger)
    # 设置日志类的全局变量
    return logger
Esempio n. 11
0
 def loadLogger(self):
     srvConf = _G._GG("ServerConfig").Config()
     # 服务配置
     path = srvConf.Get("log", "path", "").replace("\\", "/")
     if len(path) > 0 and path[-1] != "/":
         path += "/"
     name = srvConf.Get("log", "name", "PyToolsIP")
     curTimeStr = time.strftime("%Y_%m_%d", time.localtime())
     logger = Logger("Common",
                     isLogFile=True,
                     logFileName="".join([
                         _G._GG("g_ProjectPath"), path, name,
                         "_%s.log" % curTimeStr
                     ]),
                     maxBytes=int(srvConf.Get("log", "maxBytes")),
                     backupCount=int(srvConf.Get("log", "backupCount")))
     _G.setGlobalVarTo_Global("Log", logger)
     # 设置日志类的全局变量
     return logger
Esempio n. 12
0
 def loadObjects(self):
     _G.setGlobalVarTo_Global("BaseBehavior", BaseBehavior)
     # 设置组件基础类变量(未实例化)
     _G.setGlobalVarTo_Global("BehaviorManager", BehaviorManager())
     # 设置组件管理器的全局变量
     _G.setGlobalVarTo_Global("DBCManager", DBCManager())
     # 设置数据库连接管理器的全局变量
     pass
Esempio n. 13
0
 def loadMainServer(self):
     srvConf = _G._GG("ServerConfig").Config()
     # 服务配置
     grpcServer = grpc.server(
         futures.ThreadPoolExecutor(
             max_workers=int(srvConf.Get("server", "max_workers"))))
     # 最多有多少work并行执行任务
     commonServer = require(CURRENT_PATH, "server", "CommonServer")()
     # 获取服务器对象
     common_pb2_grpc.add_CommonServicer_to_server(commonServer, grpcServer)
     # 添加函数方法和服务器,服务器端会进行反序列化。
     print(":".join(
         [srvConf.Get("server", "host"),
          srvConf.Get("server", "port")]))
     grpcServer.add_insecure_port(":".join(
         [srvConf.Get("server", "host"),
          srvConf.Get("server", "port")]))
     # 建立服务器和端口
     # 设置注册及注销方法
     grpcServer.registerMethod = commonServer.registerMethod
     grpcServer.unregisterMethod = commonServer.unregisterMethod
     # 设置服务器对象到全局
     _G.setGlobalVarTo_Global("MainServer", grpcServer)
     return grpcServer
Esempio n. 14
0
 def loadConfigs(self):
     print("Loading game configs......")
     _G.setGlobalVarTo_Global("GameConfig", GameConfig())
     # 设置配置的全局变量
     print("Loaded game configs!")
     pass
Esempio n. 15
0
def _loadPath_():
    _G.setGlobalVarTo_Global("ProjectPath", CURRENT_PATH)
Esempio n. 16
0
def _loadConsumerMgr_():
    _G.setGlobalVarTo_Global("ConsumerMgr", ConsumerMgr())
Esempio n. 17
0
def _loadPaths_():
    _G.setGlobalVarTo_Global("ProjectPath", CURRENT_PATH + "/")
    pass
Esempio n. 18
0
 def loadObjects(self):
     _G.setGlobalVarTo_Global("BaseBehavior", BaseBehavior)
     # 设置组件基础类变量(未实例化)
     _G.setGlobalVarTo_Global("BehaviorManager", BehaviorManager())
     # 设置组件管理器的全局变量
     _G.setGlobalVarTo_Global("EventDispatcher", EventDispatcher())
     # 设置事件分发器的全局变量
     _G.setGlobalVarTo_Global("EVENT_ID", EVENT_ID)
     # 设置事件枚举Id的全局变量
     _G.setGlobalVarTo_Global("CacheManager", CacheManager())
     # 设置缓存管理器的全局变量
     _G.setGlobalVarTo_Global("SceneManager", SceneManager())
     # 设置场景管理器的全局变量
     _G.setGlobalVarTo_Global("TimerManager", TimerManager())
     # 设置定时器管理器的全局变量
     pass
Esempio n. 19
0
 def loadConfigs(self):
     print("Loading configs......")
     _G.setGlobalVarTo_Global("ServerConfig", ServerConfig())
     # 设置服务配置的全局变量
     print("Loaded configs!")
     pass
Esempio n. 20
0
 def loadFuncs(self):
     # 加载rsa密钥解码方法
     _G.setGlobalVarTo_Global("DecodeStr", rsaCore.decodeStr)
     _G.setGlobalVarTo_Global("GetPublicKey", rsaCore.getPublicKey)
Esempio n. 21
0
 def loadPyPath(self):
     _G.setGlobalVarTo_Global("g_PythonPath",
                              _G._GG("GetDependPath")("include/python"))
Esempio n. 22
0
 def updatePyPath(self, path):
     _G.setGlobalVarTo_Global("g_PythonPath", path, isCover=True)
Esempio n. 23
0
 def loadObjects(self):
     _G.setGlobalVarTo_Global("BaseBehavior", BaseBehavior)
     # 设置组件基础类变量(未实例化)
     _G.setGlobalVarTo_Global("WindowObject", GlobalWindowObject())
     # 设置窗口类的全局变量
     _G.setGlobalVarTo_Global("BehaviorManager", BehaviorManager())
     # 设置组件管理器的全局变量
     _G.setGlobalVarTo_Global("EventDispatcher", EventDispatcher())
     # 设置事件分发器的全局变量
     _G.setGlobalVarTo_Global("EVENT_ID", EVENT_ID)
     # 设置事件枚举Id的全局变量
     _G.setGlobalVarTo_Global("HotKeyManager", HotKeyManager())
     # 设置热键管理器的全局变量
     _G.setGlobalVarTo_Global("TimerManager", TimerManager())
     # 设置定时器管理器的全局变量
     _G.setGlobalVarTo_Global("CacheManager", CacheManager())
     # 设置缓存管理器的全局变量
     pass
Esempio n. 24
0
 def loadCommonClient(self):
     _G.setGlobalVarTo_Global("CommonClient", CommonClient())
     # 设置客户端->服务端连接的全局变量
     pass