コード例 #1
0
ファイル: entity_base.cpp プロジェクト: Joinhack/fragement
    //将base/cell共有属性打包
    bool CEntityBase::PickleCellPropsToPluto(CPluto& u1)
    {
        CPluto u;
        const SEntityDef* pDef = this->GetEntityDef();
        if(pDef)
        {
            map<string, _SEntityDefProperties*>::const_iterator iter = pDef->m_properties.begin();
            for(; iter != pDef->m_properties.end(); ++iter)
            {
                _SEntityDefProperties* p = iter->second;
                if(IsCellFlag(p->m_nFlags) && IsBaseFlag(p->m_nFlags))
                {
                    const string& strEntityName = iter->first;
                    map<string, VOBJECT*>::const_iterator iter2 = m_data.find(strEntityName);
                    if(iter2 == m_data.end())
                    {

                        //todo warning...
                        continue;
                    }

                    u << (uint16_t)(pDef->m_propertiesMap.GetIntByStr(iter2->first));
                    u.FillPluto(*(iter2->second));
                }
                else if (IsCellFlag(p->m_nFlags))
                {
                    //如果该属性只有cell才有,则到cellData上查找
                    const string& strEntityName = iter->first;
                    map<string, VOBJECT*>::iterator iter3 = m_cellData.find(strEntityName);

                    if (iter3 != m_cellData.end())
                    {
                        u << (uint16_t)(pDef->m_propertiesMap.GetIntByStr(iter3->first));
                        u.FillPluto(*(iter3->second));
                        m_cellData.erase(iter3);

                        LogDebug("CEntityBase::PickleCellPropsToPluto cellData", "strEntityName=%s", strEntityName.c_str());
                    }
                }
                
            }
            //print_hex_pluto(u);
        }

        charArrayDummy ad;
        ad.m_l = u.GetLen();
        ad.m_s = (char*)u.GetBuff();
        u1 << ad;
        ad.m_l = 0;

        return pDef != NULL;
    }
コード例 #2
0
ファイル: entity.cpp プロジェクト: terwxqian/Mars_server
    bool CEntityParent::PickleToPluto(CPluto& u) const
    {
        const SEntityDef* pDef = this->GetEntityDef();
        if(pDef)
        {
            //u << m_mymb << m_dbid;   //不需要包含mb和dbid,这两个字段要分离出去
            u << m_etype;              //必须包含entity_type,以便接包时查询def数据
            map<string, _SEntityDefProperties*>::const_iterator iter = pDef->m_properties.begin();
            for(; iter != pDef->m_properties.end(); ++iter)
            {
                _SEntityDefProperties* p = iter->second;
                if(!p->m_bSaveDb)
                {
                    //不需要存盘
                    continue;
                }

                const string& strEntityName = iter->first;
                map<string, VOBJECT*>::const_iterator iter2 = m_data.find(strEntityName);
                if(iter2 == m_data.end())
                {
                    //todo warning...
                    continue;
                }

                //u << iter2->first.c_str();
                u << (uint16_t)(pDef->m_propertiesMap.GetIntByStr(iter2->first));
                u.FillPluto(*(iter2->second));
            }
            //print_hex_pluto(u);
        }

        return pDef != NULL;
    }
コード例 #3
0
ファイル: entity.cpp プロジェクト: terwxqian/Mars_server
    //同步带client标记的属性给客户端
    void CEntityParent::SyncClientProp(int32_t nPropId, const VOBJECT& v)
    {
        //获得当前entity的client fd
        static const string strClient = "client";

        map<string, VOBJECT*>::iterator iter = m_data.find(strClient);
        if(iter != m_data.end())
        {
            //当前已经有client了
            world* pWorld = GetWorld();

            lua_State* L = pWorld->GetLuaState();
            ClearLuaStack(L);

            CLuaCallback& cb = pWorld->GetLuaTables();
            int ref = (int)(iter->second->vv.i32);

            //LogDebug("CEntityParent::SyncClientProp", "m_id=%d;ref=%d", m_id, ref);


            cb.GetObj(L, ref);

            if(lua_istable(L, -1))
            {
                lua_rawgeti(L, -1, g_nMailBoxServerIdKey);

                int fd = (int)lua_tointeger(L, -1);
                CMailBox* mb = pWorld->GetServer()->GetClientMailbox(fd);
                if(mb)
                {
                    //LogDebug("CEntityParent::SyncClientProp", "m_id=%d;nPropId=%d;", m_id, nPropId);

                    CPluto* u =  new CPluto;
                    (*u).Encode(MSGID_CLIENT_AVATAR_ATTRI_SYNC) << (uint16_t)nPropId;
                    u->FillPluto(v);
                    (*u) << EndPluto;

                    mb->PushPluto(u);
                }
            }

            ClearLuaStack(L);
        }
    }
コード例 #4
0
ファイル: entity_base.cpp プロジェクト: Joinhack/fragement
    //同步带cell标记的属性
    void CEntityBase::SyncBaseAndCellProp(int32_t nPropId, const VOBJECT& v)
    {
        int nCellId = GetCellServerId();
        if(nCellId > 0)
        {
            CMailBox* mb = GetWorld()->GetServerMailbox(nCellId);
            if(mb)
            {
                CPluto* u =  new CPluto;
                (*u).Encode(MSGID_CELLAPP_ENTITY_ATTRI_SYNC) << m_id << m_etype << (uint16_t)nPropId;
                u->FillPluto(v);
                (*u) << EndPluto;

                //LogDebug("CEntityBase::SyncBaseAndCellProp", "u->GetLen()=%d;", u->GetLen());

                mb->PushPluto(u);
            }
        }
    }
コード例 #5
0
ファイル: entity_base.cpp プロジェクト: Joinhack/fragement
    bool CEntityBase::PickleClientToPluto(CPluto& u)
    {
        //类似于CEntityParent::pickle_to_pluto,打包所有需要存盘的字段
        //打包所有待client标记的字段
        const SEntityDef* pDef = this->GetEntityDef();
        if(pDef)
        {
            u << m_etype << m_id << m_dbid;              //必须包含entity_type,以便接包时查询def数据
            LogDebug("CEntityBase::PickleClientToPluto", "m_etype=%d;m_id=%d;m_dbid=%d", m_etype, m_id, m_dbid);
            map<string, _SEntityDefProperties*>::const_iterator iter = pDef->m_properties.begin();
            for(; iter != pDef->m_properties.end(); ++iter)
            {
                _SEntityDefProperties* p = iter->second;
                if(IsClientFlag(p->m_nFlags))
                {
                    const string& strEntityName = iter->first;
                    map<string, VOBJECT*>::const_iterator iter2 = m_data.find(strEntityName);
                    if(iter2 == m_data.end())
                    {
                        //todo warning...
                        continue;
                    }

                    //u << iter2->first.c_str();
                    uint16_t attr_id = (uint16_t)(pDef->m_propertiesMap.GetIntByStr(iter2->first));
                    u << attr_id;

                    //LogDebug("CEntityBase::PickleClientToPluto", "attr_id=%d;first=%s", attr_id, iter2->first.c_str());

                    u.FillPluto(*(iter2->second));
                }
            }
            //print_hex_pluto(u);
        }

        return pDef != NULL;
    }