Exemple #1
0
def getArg(cfg, arg):
    result = []
    keys = utils.getObjSortedKeys(arg)
    for argname in keys:
        if argname.startswith("_"):
            print("Invalid Arg -> ", argname)
            continue

        argtype = arg[argname]
        tp = None
        canNil = False
        desc = "no-desc"
        if type(argtype) is list:
            if len(argtype) == 2:
                tp, desc = argtype[0], argtype[1]
            elif len(argtype) == 3:
                tp, desc, canNil = argtype[0], argtype[1], argtype[2]
            else:
                print("Invalid Arg Config -> ", arg)
        else:
            tp = argtype

        if tp not in cfg["done_types"]:
            #load new type
            typename = handleTmp(cfg, tp)
            if not typename in BASIC_TYPES:
                if not typename in cfg['done_types']:
                    readType(cfg, typename)  #recursive fetch type
            tp = typename

        result.append([cfg['done_types'][tp]['id'], argname, desc, canNil])
    return result
Exemple #2
0
def analysesType(cfg):
    keys = utils.getObjSortedKeys(cfg['types'])
    for k in keys:
        v = cfg['types'][k]
        if k in cfg['done_types']:
            continue
        readType(cfg, k)
Exemple #3
0
def analysesServer(cfg):
    keys = utils.getObjSortedKeys(cfg['entities'])
    for ename in keys:
        ecfg = cfg['entities'][ename]
        if ecfg['Abstract']: continue

        sname = ecfg['Server']
        if sname == "bf_proxy":
            cfg['done_proxies']['LoginProxy'] = ename
            cfg['done_proxies']['LoginProxyServer'] = sname
        elif sname == "bb_proxy":
            cfg['done_proxies']['ClientProxy'] = ename
            cfg['done_proxies']['ClientProxyServer'] = sname
Exemple #4
0
def readObject(cfg, k, v):
    objCfg = {"ctype": "object", "fields": {}}
    if 'indexs' in v:
        objCfg['indexs'] = v['indexs']
    for key in utils.getObjSortedKeys(v['fields']):
        ktype = v['fields'][key]
        typename = handleTmp(cfg, ktype)
        if not typename in BASIC_TYPES:
            if not typename in cfg['types']:
                print("readObject :: You can'nt go here!")
                return
            elif not typename in cfg['done_types']:
                readType(cfg, typename)  #recursive fetch type
        objCfg['fields'][key] = typename
    addDoneType(cfg, k, objCfg)
Exemple #5
0
def writeScript(cfg, ccPath):
    utils.make_sure_path(ccPath)

    keys = utils.getObjSortedKeys(cfg['done_entities'])
    for ename in keys:
        ecfg = cfg['done_entities'][ename]
        if ecfg['etype'] != 0:
            continue

        rlpath = cfg["entities"][ename]['path']
        if rlpath:
            rlpath += "/"
        epath = ccPath + "/" + rlpath
        if not os.path.exists(epath):
            os.makedirs(epath)
        method = epath + ename + ".lua"
        userCode = {
            "__private": [],
            "__require": [],
            "__global": [],
            "__property": [],
            "____old": {}
        }
        if os.path.exists(method):
            with codecs.open(method, "r", "utf-8") as f:
                #print("   ----> Load %s "%(method))
                userCode = utils.importUserCode(f, AUTO_LUA_COMMENT)

        try:
            with codecs.open(method + ".tmp", "w", "utf-8") as f:
                exportLuaEntity(cfg, ename, ecfg, userCode, f)
            with codecs.open(method + ".tmp", "r", "utf-8") as f:
                with codecs.open(method, "w", "utf-8") as fw:
                    fw.write(f.read())
        except (Exception) as e:
            import traceback
            print("Failed export lua -> ", method, e.args)
            traceback.print_exc()
        finally:
            os.remove(method + ".tmp")

    #print()
Exemple #6
0
def write(cfg, scPath):
    keys = utils.getObjSortedKeys(cfg['done_entities'])
    for ename in keys:
        ecfg = cfg['done_entities'][ename]
        rlpath = cfg["entities"][ename]['path']
        if rlpath:
            rlpath += "/"
        epath = scPath + "/" + rlpath
        utils.make_sure_path(epath)

        method = epath + ename + "Method.js"
        userCode = {
            "__private": [],
            "__require": [],
            "__global": [],
            "__property": [],
            "__public": [],
            "____old": {}
        }
        if os.path.exists(method):
            with codecs.open(method, "r", "utf-8") as f:
                #print("   ----> Load %s "%(method))
                userCode = utils.importUserCode(f, AUTO_JS_COMMENT)

        #print("   ----> Write %s "%(method))
        try:
            with codecs.open(method + ".tmp", "w", "utf-8") as f:
                exportJsEntityMethod(cfg, ename, ecfg, userCode, f)
            with codecs.open(method + ".tmp", "r", "utf-8") as f:
                with codecs.open(method, "w", "utf-8") as fw:
                    fw.write(f.read())
        except (Exception) as e:
            import traceback
            print("Failed export method -> ", method, e.args)
            traceback.print_exc()
        finally:
            os.remove(method + ".tmp")
Exemple #7
0
def analysesEntities(cfg):
    keys = utils.getObjSortedKeys(cfg['entities'])
    for ename in keys:
        analysesEntity(cfg, ename)
Exemple #8
0
def analysesEntity(cfg, ename):
    global REQ_METHOD_INDEX
    global PUSH_METHOD_INDEX
    ecfg = cfg['entities'][ename]
    cfg['done_entities'][ename] = {
        "handlers": [],
        "pushes": [],
        "remotes": [],
        "properties": {},
        # "impProperties":{},
        # "impHandlers":{},
        # "impRemotes":{},
        # "impPushes":{},
        "implements": ecfg['Implements'],
        "path": ecfg['path'].replace("\\", "/"),
        "abstract": ecfg['Abstract'],
        "etype": -1,
        "server": ecfg['Server'] if 'Server' in ecfg else ''
    }

    if 'Type' in ecfg:
        if ecfg['Type'] == 'single':
            cfg['done_entities'][ename]['etype'] = 1
        elif ecfg['Type'] == 'proxy':
            cfg['done_entities'][ename]['etype'] = 0
        elif ecfg['Type'] == 'simple':
            cfg['done_entities'][ename]['etype'] = 2
        else:
            print("Invalid Config to Entity Type -> ", ename, ecfg['Type'])

    decfg = cfg['done_entities'][ename]
    for imp, prior in ecfg['Implements'].items():
        if imp not in cfg['entities']:
            print("Invalid implements entity -> ", imp)
            continue
        if imp not in cfg['done_entities']:
            analysesEntity(cfg, imp)
        imecfg = cfg['done_entities'][imp]
        #decfg['impProperties'][imp] = list(imecfg['properties'].keys())
        #decfg['impProperties'].update(imecfg['impProperties'])
        #decfg['impHandlers'][imp] = imecfg['handlers']
        #decfg['impHandlers'].update(imecfg['impHandlers'])
        #decfg['impPushes'][imp] = imecfg['pushes']
        #decfg['impPushes'].update(imecfg['impPushes'])
        #decfg['impRemotes'][imp] = imecfg['remotes']
        #decfg['impRemotes'].update(imecfg['impRemotes'])
        imecfg['etype'] = decfg['etype']
        imecfg['server'] = decfg['server']

    if "Handlers" in ecfg:
        keys = utils.getObjSortedKeys(ecfg['Handlers'])
        h = cfg['done_methods']['handler']
        for mname in keys:
            if mname.startswith("_"):
                print("Invalid Methods -> ", mname)
                continue

            mcfg = ecfg['Handlers'][mname]
            h[mname] = {
                "id": REQ_METHOD_INDEX,
                "req": getArg(cfg, mcfg['req'])
            }
            if 'unbinded' in mcfg:
                h[mname]['unbinded'] = mcfg['unbinded']
            if 'resp' in mcfg:
                h[mname]['resp'] = getArg(cfg, mcfg['resp'])
            if 'resend' in mcfg:
                h[mname]['resend'] = mcfg['resend']
            else:
                h[mname]['resend'] = 0

            cfg['done_entities'][ename]['handlers'].append(mname)
            cfg['done_methods']['handlerIds'][REQ_METHOD_INDEX] = [
                ename, mname
            ]
            REQ_METHOD_INDEX += 1

    if "Pushes" in ecfg:
        keys = utils.getObjSortedKeys(ecfg['Pushes'])
        h = cfg['done_methods']['push']
        for mname in keys:
            if mname.startswith("_"):
                print("Invalid Methods -> ", mname)
                continue
            mcfg = ecfg['Pushes'][mname]
            h[mname] = {
                "id": PUSH_METHOD_INDEX,
                "req": getArg(cfg, mcfg['req'])
            }
            cfg['done_entities'][ename]['pushes'].append(mname)
            cfg['done_methods']['pushIds'][PUSH_METHOD_INDEX] = [ename, mname]
            PUSH_METHOD_INDEX += 1

    if "Remotes" in ecfg:
        keys = utils.getObjSortedKeys(ecfg['Remotes'])
        h = cfg['done_methods']['remote']
        for mname in keys:
            if mname.startswith("_"):
                print("Invalid Methods -> ", mname)
                continue
            mcfg = ecfg['Remotes'][mname]
            h[mname] = {
                "req": getArg(cfg, mcfg['req']),
            }
            if 'resp' in mcfg:
                h[mname]['resp'] = getArg(cfg, mcfg['resp'])
            cfg['done_entities'][ename]['remotes'].append(mname)

    if "Properties" in ecfg:
        keys = utils.getObjSortedKeys(ecfg['Properties'])
        h = cfg['done_entities'][ename]['properties']
        for pname in keys:
            if pname.startswith("_"):
                print("Invalid Property -> ", pname)
                continue
            if pname.lower() == ename.lower() + "id":
                print("Critical Error -> property can not be set as ", pname)
                exit(1)
            elif "_" in pname:
                print("Critical Error -> property can not be set as ", pname)
                exit(1)
            pcfg = ecfg['Properties'][pname]
            tp = pcfg['type']
            if type(tp) is "str":
                if tp not in cfg["done_types"]:
                    #load new type
                    typename = handleTmp(cfg, tp)
                    if not typename in BASIC_TYPES:
                        if not typename in cfg['done_types']:
                            readType(cfg, typename)  #recursive fetch type
                    tp = typename
            else:
                #load new type
                typename = handleTmp(cfg, tp)
                if not typename in BASIC_TYPES:
                    if not typename in cfg['done_types']:
                        readType(cfg, typename)  #recursive fetch type
                tp = typename

            h[pname] = {
                "type": cfg["done_types"][tp]['id'],
                "persistent":
                pcfg['persistent'] if 'persistent' in pcfg else True,
                #"autoSyncClient":pcfg['autoSyncClient'] if 'autoSyncClient' in pcfg else False,
                #"flag":pcfg['flag'] if 'flag' in pcfg else "all",
                "index": pcfg['index'] > 0 if 'index' in pcfg else False,
                "unique": pcfg['unique'] > 0 if 'unique' in pcfg else False,
            }

            if 'default' in pcfg:
                h[pname]["default"] = pcfg['default']

            if h[pname]['index']:
                if cfg["done_types"][tp]['ctype'] != 'basic' and cfg[
                        "done_types"][tp]['ctype'] != 'enum':
                    print(
                        "Invalid Index Settings, only simple type can be set into index !",
                        tp)
                    h[pname]['index'] = False