コード例 #1
0
ファイル: world_client.cpp プロジェクト: Joinhack/fragement
    bool avatar_cell_rpc(const char* cmd)
    {
        list<string> ls;
        SplitString(cmd, '|', ls);

        if(ls.empty())
        {
            printf("error rpc, empty string. \n");
            return false;
        }

        //远程方法名
        CDefParser& defp = GetWorld()->GetDefParser();
        const SEntityDef* pDef = defp.GetEntityDefByName("Avatar");
        string strFunc = ls.front();
        ls.pop_front();
        uint16_t nFunc = (uint16_t)pDef->m_cellMethodsMap.GetIntByStr(strFunc);		

        CPluto u;
        u.Encode(MSGID_BASEAPP_CLIENT_RPC2CELL_VIA_BASE) << nFunc;

        //其他参数
        map<string, _SEntityDefMethods*>::const_iterator iter11 = pDef->m_cellMethods.find(strFunc);		
        if(iter11 != pDef->m_cellMethods.end())
        {
            _SEntityDefMethods* pmethod = iter11->second;
            list<VTYPE>::const_iterator iter = pmethod->m_argsType.begin();
            for(; iter != pmethod->m_argsType.end(); ++iter)
            {
                if(ls.empty())
                {
                    printf("error rpc, less params, %s \n", cmd);
                    return false;
                }

                const string& sv = ls.front();
                u.FillPlutoFromStr(*iter, sv.c_str(), (unsigned long)sv.size());
                ls.pop_front();
            }
        }

        u << EndPluto;

        //发送
        printf("send cell cmd: %s \n", cmd);
        //print_hex_pluto(u);
        write_some(u.GetBuff(), u.GetLen());

        //收取回应包
        //async_read_some();
        //CPluto* u2 = read_pluto();
        //delete u2;

        return true;
    }
コード例 #2
0
ファイル: world_client.cpp プロジェクト: Joinhack/fragement
    bool random_cell_rpc()
    {
        //远程方法名
        CDefParser& defp = GetWorld()->GetDefParser();
        const SEntityDef* pDef = defp.GetEntityDefByName("Avatar");

        int nMaxFuncId = (int)pDef->m_cellMethods.size();
        int nFunc = rand() % nMaxFuncId;
        const string& strFunc = pDef->m_cellMethodsMap.GetStrByInt(nFunc);

        ostringstream oss;
        oss << strFunc;
        CPluto u;
        u.Encode(MSGID_BASEAPP_CLIENT_RPC2CELL_VIA_BASE) << nFunc;

        //其他参数
        map<string, _SEntityDefMethods*>::const_iterator iter11 = pDef->m_cellMethods.find(strFunc);		
        if(iter11 != pDef->m_cellMethods.end())
        {
            _SEntityDefMethods* pmethod = iter11->second;
            list<VTYPE>::const_iterator iter = pmethod->m_argsType.begin();
            for(; iter != pmethod->m_argsType.end(); ++iter)
            {
                VTYPE vt = *iter;
                string sv;
                switch(vt)
                {
                case V_STR:
                    sv.assign("abcd");
                    break;
                case V_INT8:
                case V_UINT8:
                case V_INT16:
                case V_UINT16:
                case V_INT32:
                case V_UINT32:
                case V_INT64:
                case V_UINT64:
                case V_FLOAT32:
                case V_FLOAT64:
                    sv.assign("14");
                    break;
                case V_BLOB:
                    sv.assign("{}");
                    break;
                default:
                    sv.assign("");
                    break;
                }

                oss << "|" << sv;
                u.FillPlutoFromStr(*iter, sv.c_str(), (unsigned long)sv.size());
            }
        }

        u << EndPluto;

        //发送
        printf("send cell_cmd: %d %s \n", nFunc,  oss.str().c_str());
        //print_hex_pluto(u);
        write_some(u.GetBuff(), u.GetLen());

        //收取回应包
        //async_read_some();
        //CPluto* u2 = read_pluto();
        //delete u2;

        return true;
    }