Пример #1
0
//获取一个流水号
uint32_t CWorldCrossserver::GetNextRpcSeq(CPluto& u, uint16_t sid, TENTITYTYPE etype, TENTITYID eid)
{
	CMailBox* mb = u.GetMailbox();
	if(mb == NULL)
	{
		return 0;
	}
	int fd = mb->GetFd();

	int nSeq;
	if(m_lsFreeRpcSeq.empty())
	{
		//没有空闲流水号了
		++m_nCrossRpcSeq;
		nSeq = m_nCrossRpcSeq;
	}
	else
	{
		nSeq = m_lsFreeRpcSeq.front();
		m_lsFreeRpcSeq.pop_front();
	}

	_SCrossClientInfo* pInfo = new _SCrossClientInfo(fd, sid, etype, eid);
	m_InRpc.insert(make_pair(nSeq, pInfo));

	return nSeq;
}
Пример #2
0
//检查所有服的所有def文件的md5是否匹配
int CWorldCrossserver::CheckMd5(CPluto& u)
{
	CMailBox* pmb = u.GetMailbox();
	if(pmb == NULL)
	{
		return -1;
	}

	if(((CCrossserverServer*)GetServer())->IsTrustedIp(pmb->GetServerName()))
	{
		//来自受信任的客户端,校验md5是否匹配
		CHECK_AND_GET_RPC_FIELD(u, strMd5, string);

		if(m_strDefMd5 == strMd5)
		{
			//设置信任标记
			pmb->SetAuthz(MAILBOX_CLIENT_TRUSTED);
			LogInfo("CheckMd5", "ip=%s", pmb->GetServerName().c_str());

			return 0;
		}
		else
		{
			LogWarning("CheckMd5.err1", "md5_mismatch;self=%s;other=%s", m_strDefMd5.c_str(), strMd5.c_str());
			return -2;
		}
	}

	//来自不受信任的客户端,断开连接
	GetServer()->CloseFdFromServer(pmb->GetFd());
	LogInfo("CheckMd5.err2", "err_ip=%s", pmb->GetServerName().c_str());    
	return -3;
}
Пример #3
0
//发到base的来自client的entity rpc调用
T_VECTOR_OBJECT* CRpcUtil::DecodeBaseClientRpc(CPluto& u)
{
    CMailBox* mb = u.GetMailbox();
    if(mb == NULL)
    {
        return NULL;
    }
    int fd = mb->GetFd();
    //CWorldBase& the_world = GetWorldbase();
    CWorldBase *pstCWorldBase = dynamic_cast<CWorldBase *>(GetWorld());
    if (pstCWorldBase==NULL)
    {
        LogError("CRpcUtil::DecodeBaseClientRpc", "pstCWorldBase is null.");
        return NULL;
    }
    //CEntityBase* pBase = the_world.GetEntityByFd(fd);
    CEntityBase* pBase = pstCWorldBase->GetEntityByFd(fd);
    if(pBase == NULL)
    {
        return NULL;
    }

#ifdef __PLUTO_ORDER
    //校验rpc包的顺序
    uint16_t PlutoOrder = sz_to_uint16((unsigned char*)u.GetRecvBuff() + MSGLEN_HEAD);
    uint16_t EntityPlutoOrder = pBase->GetPlutoOrder();
    //LogDebug("CRpcUtil::DecodeBaseClientRpc", "PlutoOrder=%d;EntityPlutoOrder=%d", PlutoOrder, EntityPlutoOrder);
#endif

    //const SEntityDef* pDef = the_world.GetDefParser().GetEntityDefByType(pBase->GetEntityType());
    const SEntityDef* pDef = pstCWorldBase->GetDefParser().GetEntityDefByType(pBase->GetEntityType());
    if(pDef == NULL)
    {
        return NULL;
    }

    T_VECTOR_OBJECT* ll = new T_VECTOR_OBJECT;

    VOBJECT* v = new VOBJECT;
    v->vt = V_ENTITY_POINTER;
    v->vv.p = pBase;
    ll->push_back(v);

    uint16_t nFuncId = 0;
    u >> nFuncId;
    if(u.GetDecodeErrIdx() > 0)
    {
        return ll;
    }

    const string& strFunc = pDef->m_baseMethodsMap.GetStrByInt(nFuncId);
    map<string, _SEntityDefMethods*>::const_iterator iter11 = pDef->m_baseMethods.find(strFunc);
    if(iter11 != pDef->m_baseMethods.end())
    {
        _SEntityDefMethods* pMethods = iter11->second;
        if(pMethods->m_bExposed)
        {
            v = new VOBJECT;
            v->vt = V_STR;
            v->vv.s = new string(strFunc);
            ll->push_back(v);

            list<VTYPE>& refs = pMethods->m_argsType;
            list<VTYPE>::const_iterator iter2 = refs.begin();
            for(; iter2 != refs.end(); ++iter2)
            {
                VOBJECT* v = new VOBJECT;
                u.FillVObject(*iter2, *v);
                ll->push_back(v);

                if(u.GetDecodeErrIdx() > 0)
                {
                    return ll;
                }
            }
            return ll;
        }
        //else 该方法不能由客户端调用
    }

    ClearTListObject(ll);

    return NULL;
}