Example #1
0
int CWorldCrossserver::OnCrossClientResp(CPluto& u)
{
	CHECK_AND_GET_RPC_FIELD(u, nSeq, uint32_t);

	//检查流水号对应的外系统连接是否还在
	map<uint32_t, _SCrossClientInfo*>::iterator iter1 = m_InRpc.find(nSeq);
	if(iter1 == m_InRpc.end())
	{
		LogWarning("CWorldCrossserver::OnCrossClientResp", "notfound_seq=%d", nSeq);
		return -1;
	}

	_SCrossClientInfo* pInfo = iter1 ->second;
	CMailBox* mb = GetServer()->GetClientMailbox(pInfo->fd);
	if(mb == NULL)
	{
		//外系统已经断开连接了
		LogWarning("CWorldCrossserver::OnCrossClientResp", "notfoundclient_seq=%d", nSeq);
		return -2;
	}

	CPluto* u2 = new CPluto;
	u2->Encode(MSGID_CROSSCLIENT_RESP) << pInfo->sid << pInfo->etype << pInfo->eid;
	//转发包内容
	u2->FillBuff(u.GetBuff()+u.GetLen(), u.GetMaxLen()-u.GetLen());
	u2->endPluto();
	mb->PushPluto(u2);

	//删除数据,即每个流水号只能被回调一次
	delete pInfo;
	m_InRpc.erase(iter1);
	m_lsFreeRpcSeq.push_back(nSeq); //流水号重用

	return 0;
}
Example #2
0
//来自跨服的广播
int CWorldCrossclient::OnCrossClientBroadcast(CPluto& u)
{
    //printf("CWorldCrossclient::OnCrossClientBroadcast \n");

    if(m_nBcBaseappId == 0)
    {
        //挑一个baseapp来处理,挑完之后不会再变了
        vector<CMailBox*>& mbs = GetServer()->GetAllServerMbs();
        vector<CMailBox*>::iterator iter1 = mbs.begin();
        for(; iter1 != mbs.end(); ++iter1)
        {
            CMailBox* mb2 = *iter1;
            if(mb2 && mb2->GetServerMbType() == SERVER_BASEAPP)
            {
                m_nBcBaseappId = mb2->GetMailboxId();
                break;
            }
        }
    }

    CMailBox* mb = GetServerMailbox(m_nBcBaseappId);
    if(mb)
    {
        CPluto* u2 = new CPluto(u.GetBuff(), u.GetMaxLen());
        u2->ReplaceField<uint16_t>(6, MSGID_BASEAPP_CROSSCLIENT_BROADCAST);
        mb->PushPluto(u2);
    }

    return 0;
}
Example #3
0
//来自原始服的跨服调用
int CWorldCrossserver::OnCrossServerRpc(CPluto& u)
{
	//printf("CWorldCrossserver::OnCrossServerRpc 111\n");

	CHECK_AND_GET_RPC_FIELD(u, uSrcServerId, uint16_t);
	CHECK_AND_GET_RPC_FIELD(u, etype, TENTITYTYPE);
	CHECK_AND_GET_RPC_FIELD(u, eid, TENTITYID);
	CHECK_AND_GET_RPC_FIELD(u, strGlobal, string);
	//CHECK_AND_GET_RPC_FIELD(u, strFuncId, uint16_t);

	uint32_t nSeq = GetNextRpcSeq(u, uSrcServerId, etype, eid);
	if(nSeq == 0)
	{
		return -1;
	}

	//printf("CWorldCrossserver::OnCrossServerRpc 222, %d - %d - %d - %s - seq =%d \n", uSrcServerId, etype, eid, strGlobal.c_str(), nSeq);

	map<string, CEntityMailbox*>::iterator iter1 = m_globalBases.find(strGlobal);
	if(iter1 == m_globalBases.end())
	{
		return -2;
	}

	CEntityMailbox* emb = iter1->second;
	CMailBox* mb = GetServerMailbox(emb->m_nServerMailboxId);
	if(mb)
	{
		CPluto* u2 = new CPluto;
		u2->Encode(MSGID_BASEAPP_ENTITY_RPC) << (*emb);
		u2->FillBuff(u.GetBuff()+u.GetLen(), 2);        //msg_id
		u2->FillField(nSeq);                            //填充流水号字段
		u2->FillBuff(u.GetBuff()+u.GetLen()+2, u.GetMaxLen()-u.GetLen()-2);//copy其他字段
		u2->endPluto();
		mb->PushPluto(u2);

		return 0;
	}

	return -2;
}
Example #4
0
//来自跨服的回调
int CWorldCrossclient::OnCrossClientResp(CPluto& u)
{
    //printf("CWorldCrossclient::onCrossClientResp\n");

    CHECK_AND_GET_RPC_FIELD(u, sid, uint16_t);

    CMailBox* mb = GetServerMailbox(sid);
    //printf("CWorldCrossclient::onCrossClientResp 222, sid=%d;mb=%x\n", sid, mb);
    if(mb)
    {
        //发回给发起调用的那个entity
        CPluto* u2 = new CPluto;
        u2->Encode(MSGID_BASEAPP_ENTITY_RPC) << sid;
        u2->FillBuff(u.GetBuff()+u.GetLen(), u.GetMaxLen()-u.GetLen());
        u2->endPluto();

        mb->PushPluto(u2);
    }

    return 0;
}
Example #5
0
//转发跨服调用
int CWorldCrossclient::OnCrossServerRpc(CPluto& u)
{
    //跨服服务名
    CHECK_AND_GET_RPC_FIELD(u, strService, string);

    //检查对应的跨服服务器是否已连接
    CMailBox* pmb = ((CCrossclientServer*)GetServer())->GetExternMailbox(strService);
    if(pmb == NULL)
    {
    	//外系统当前不可用,记录日志;返回错误消息也无用
    	LogWarning("CWorldCrossclient::OnCrossServerRpc", "extern error,%s\n", strService.c_str());
    	return 0;
    }

    CPluto* u2 = new CPluto;
    u2->Encode(MSGID_CROSSSERVER_RPC);
    //转发包内容
    u2->FillBuff(u.GetBuff()+u.GetLen(), u.GetMaxLen()-u.GetLen());
    u2->endPluto();
    pmb->PushPluto(u2);

    return 0;
}
Example #6
0
	int CWorldOther::SdkServerVerify(T_VECTOR_OBJECT* p, CPluto& u)
	{
#if 0
        //注释掉老代码
		if (p->size() != 4)
		{
			return -1;
		}
		string& url = VOBJECT_GET_SSTR((*p)[0]);
		int32_t nFd = VOBJECT_GET_I32((*p)[1]);
		string& strAccount = VOBJECT_GET_SSTR((*p)[2]);
		string& strPlatId = VOBJECT_GET_SSTR((*p)[3]);
		CMailBox* pmb = u.GetMailbox();
		if (NULL == pmb)
		{
			return -1;
		}

		CPluto* duplicate = new CPluto(u.GetBuff(), u.GetMaxLen());
		duplicate->SetMailbox(pmb);
		int ret = threadpool_add_job(g_threadpool, ThreadJob_SdkServerVerify, (void*)(duplicate));

		if (ret != 0)
		{
			//直接返回服务器繁忙,请稍后再试
			//printf("服务器繁忙,请稍后再试!\n");
			//std::cout << "服务器繁忙,请稍后再试!" << endl;
			LogWarning("CWorldOther::SdkServerVerify", "threadpool list is full.");
			CPluto* u2 = new CPluto;
			u2->Encode(MSGID_LOGINAPP_LOGIN_VERIFY_CALLBACK);
			(*u2)<< int32_t(-2) << nFd << strAccount << strPlatId << EndPluto;
			g_pluto_sendlist.PushPluto(u2);
			//不适合多线程发送
			//pmb->RpcCall(GetRpcUtil(), MSGID_LOGINAPP_LOGIN_VERIFY_CALLBACK, -2, nFd, strAccount, strPlatId);
		}

		return 0;
#endif

        if (p->size() != 4)
        {
            return -1;
        }
        string& url = VOBJECT_GET_SSTR((*p)[0]);
        int32_t nFd = VOBJECT_GET_I32((*p)[1]);
        string& strAccount = VOBJECT_GET_SSTR((*p)[2]);
        string& strPlatId = VOBJECT_GET_SSTR((*p)[3]);
        CMailBox* pmb = u.GetMailbox();

        pluto_msgid_t msg_id = u.GetMsgId();;

        string resp = "";
        int ret = GetUrl_new(url.c_str(), resp);
        if (ret != CURLE_OK)
        {
            LogWarning("CWorldOther::SdkServerVerify", "%s ret = %d", strAccount.c_str(), ret);
            //todo:faild.
            SyncRpcCall(g_pluto_sendlist, SERVER_LOGINAPP, MSGID_LOGINAPP_LOGIN_VERIFY_CALLBACK, ret, nFd, strAccount, strPlatId);            
            return 0;
        }
        Trim(resp);
        cJSON* json = cJSON_Parse(resp.c_str());
        cJSON* childJs = cJSON_GetObjectItem(json, "code");
        int rst = cJSON_GetObjectItem(json, "code")->valueint;

        if (rst == 1)
        {
            //succeed.
            if (strAccount.c_str() != cJSON_GetObjectItem(json, "msg")->valuestring)
            {
                ret = 0;
            }
            else
            {
                LogWarning("CWorldOther::SdkServerVerify", "strAccount[%s] msg[%s]", 
                    strAccount.c_str(), cJSON_GetObjectItem(json, "msg")->valuestring);
                ret = 1;
                //pmb->RpcCall(GetRpcUtil(), MSGID_LOGINAPP_LOGIN_VERIFY_CALLBACK, int32_t(1), nFd, strAccount, strPlatId);
            }
        }
        else
        {
            //failed.
            LogWarning("CWorldOther::SdkServerVerify", "strAccount[%s] rst[%d]", 
                strAccount.c_str(), rst);
            ret = -1;
            //pmb->RpcCall(GetRpcUtil(), MSGID_LOGINAPP_LOGIN_VERIFY_CALLBACK, -1, nFd, strAccount, strPlatId);
        }
        SyncRpcCall(g_pluto_sendlist, SERVER_LOGINAPP, MSGID_LOGINAPP_LOGIN_VERIFY_CALLBACK, ret, nFd, strAccount, strPlatId);
        return 0;


	}