示例#1
0
//检查一个rpc调用是否合法
bool CWorldCrossserver::CSCheckClientRpc(CPluto& u)
{
	CMailBox* mb = u.GetMailbox();
	if(!mb)
	{
		//如果没有mb,是从本进程发来的包
		return true;
	}
	if(mb->IsDelete())
	{
		//已标记del的mb,其所有的包不再处理
		return false;
	}
	uint8_t authz = mb->GetAuthz();
	if(authz == MAILBOX_CLIENT_TRUSTED)
	{
		return true;
	}
	else if(authz == MAILBOX_CLIENT_UNAUTHZ)
	{
		//检查客户端地址是否可以信任
		//return CheckTrustedMailbox(mb);
		return u.GetMsgId() == MSGID_CROSSSERVER_CHECK_MD5;
	}
	else if(authz == MAILBOX_CLIENT_AUTHZ)
	{
		//return CheckTrustedMailbox(mb);
		return true;
	}
	else
	{
		return false;
	}
}
示例#2
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;
}
示例#3
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;
}
示例#4
0
    //停止所有服务器
    int CWorldMgrD::ShutdownAllServers(T_VECTOR_OBJECT* p, CPluto& u)
    {
        if(m_bShutdown)
        {
            return 0;
        }

        m_bShutdown = true;         //设置正在停止之中标记

        //步骤1:通知loginapp/baseapp/cellapp退出
        vector<CMailBox*>& mbs = GetServer()->GetAllServerMbs();
        vector<CMailBox*>::iterator iter = mbs.begin();
        for(; iter != mbs.end(); ++iter)
        {
            CMailBox* basemb = *iter;
            if(basemb && basemb->GetServerMbType() != SERVER_DBMGR)
            {
                LogDebug("CWorldMgrD::ShutdownAllServers", "basemb->GetServerMbType()=%d;basemb->GetServerName()=%s;basemb->GetServerPort()=%d", 
                                                            basemb->GetServerMbType(), basemb->GetServerName().c_str(), basemb->GetServerPort());
                basemb->RpcCall(GetRpcUtil(), MSGID_ALLAPP_SHUTDOWN_SERVER, (uint8_t)1);
            }
        }

        //步骤2:确认其他服务器退出之后,再通知dbmgr退出
        //在另外一个方法里实现

        CMailBox* mb = u.GetMailbox();
        if(mb != NULL)
        {
            mb->RpcCall(GetRpcUtil(), MSGID_BASEAPPMGR_SHUTDOWN_SERVERS_CALLBACK, (uint8_t)1);
        }

        return 0;
    }
示例#5
0
int CDbMgrServer::HandleSendPluto()
{
    enum { SEND_COUNT = 1000, };
    CPluto* u;
    int i = 0;
	while (!g_pluto_sendlist.Empty())
    {
		u = g_pluto_sendlist.PopPluto();
        CMailBox* mb = u->GetMailbox();
        if(mb)
        {
            LogDebug("CDbMgrServer::HandleSendPluto", "u.GenLen()=%d", u->GetLen());
            mb->PushPluto(u);
        }
        //每次只发送一定条数,主要用在loadAllAvatar处
        if(++i > SEND_COUNT)
        {
            break;
        }
    }

    CEpollServer::HandleSendPluto();

	return 0;
}
示例#6
0
bool CWorldCrossclient::CcCheckClientRpc(CPluto& u)
{
    CMailBox* mb = u.GetMailbox();
    if(mb && mb->GetMailboxId() == EXTERN_MAILBOX_ID)
    {
        //如果消息来自跨服连接
        return true;
    }

    return CheckClientRpc(u);
}
示例#7
0
//检查一个rpc调用是否合法
bool world::CheckClientRpc(CPluto& u)
{
    CMailBox* mb = u.GetMailbox();
	if(!mb)
	{
		//如果没有mb,是从本进程发来的包
		return true;
	}
    uint8_t authz = mb->GetAuthz();
    //printf("authz status: %d\n", authz);
    pluto_msgid_t msg_id = u.GetMsgId();
    if(authz == MAILBOX_CLIENT_TRUSTED)
    {
        printf("authz status: %d MAILBOX_CLIENT_TRUSTED:%d\n", authz,MAILBOX_CLIENT_TRUSTED);
        return true;
    }
    else if(authz == MAILBOX_CLIENT_AUTHZ)
    {
        
        //pluto_msgid_t msg_id = u.GetMsgId();
        printf("authz status: %d MAILBOX_CLIENT_AUTHZ:%d msg_id: %d\n", authz,MAILBOX_CLIENT_AUTHZ, msg_id);
        return msg_id == MSGID_BASEAPP_CLIENT_RPCALL || msg_id == MSGID_BASEAPP_CLIENT_MOVE_REQ;
    }
    else if(authz == MAILBOX_CLIENT_UNAUTHZ)
    {
                
        printf("authz status: %d MAILBOX_CLIENT_UNAUTHZ:%d msg_id: %d\n", authz, MAILBOX_CLIENT_UNAUTHZ, msg_id);
        return msg_id == MSGID_LOGINAPP_LOGIN || msg_id == MSGID_BASEAPP_CLIENT_LOGIN || \
               msg_id == MSGID_LOGINAPP_MODIFY_LOGIN_FLAG || msg_id == MSGID_LOGINAPP_SELECT_ACCOUNT_CALLBACK;
    
    }
    else
    {
        //printf("authz status: %d error: %d\n", authz, -1);
        return false;
    }
}
示例#8
0
//in parent class , this method has a pure virtual access limited
int CWorldLogin::FromRpcCall(CPluto& u)
{
    //printf("CWorldLogin::from_rpc_call\n");
    //printf("handle pluto in FromRpcCall()! : start!\n");
	pluto_msgid_t msg_id = u.GetMsgId();
    //printf("message id : %d\n", msg_id);
	if(!CheckClientRpc(u))
	{
		LogWarning("FromRpcCall", "invalid rpcall error.unknown msgid:%d\n", msg_id);
		return -1;
	}

	T_VECTOR_OBJECT* p = m_rpc.Decode(u);
	if(p == NULL)
	{
		LogWarning("FromRpcCall", "rpc decode error.unknown msgid:%d\n", msg_id);
		return -1;
	}

	if(u.GetDecodeErrIdx() > 0)
	{
		ClearTListObject(p);
		LogWarning("FromRpcCall", "rpc decode error.msgid:%d;pluto err idx=%d\n", msg_id, u.GetDecodeErrIdx());
		return -2;
	}
    printf("MSGID_LOGINAPP_MODIFY_LOGIN_FLAG:%d\n", MSGID_LOGINAPP_MODIFY_LOGIN_FLAG);
    int nRet = -1;
    switch(msg_id)
    {
        case MSGID_LOGINAPP_LOGIN:
        {
            AddClientFdToVObjectList(u.GetMailbox()->GetFd(), p);
            nRet = AccountLogin(p);
            break;
        }
        case MSGID_LOGINAPP_SELECT_ACCOUNT_CALLBACK:
        {
            nRet = SelectAccountCallback(p);
            break;
        }
        case MSGID_LOGINAPP_NOTIFY_CLIENT_TO_ATTACH:
        {
            nRet = NotifyClientToAttach(p);
            break;
        }
	    case MSGID_LOGINAPP_MODIFY_LOGIN_FLAG:  
		{
			nRet = ModifyLoginFlag(p);
			break;
		}
	    case MSGID_ALLAPP_SHUTDOWN_SERVER://103
		{
			nRet = ShutdownServer(p);
			break;
		}
        default:
        {
            LogWarning("CWorldLogin::from_rpc_call", "unknown msgid:%d\n", msg_id);
            break;
        }
    }

	if(nRet != 0)
	{
		LogWarning("from_rpc_call", "rpc error.msg_id=%d;ret=%d\n", msg_id, nRet);
	}

    ClearTListObject(p);
    //printf("handle pluto in FromRpcCall()! : end!\n");
    return 0;
}
示例#9
0
	int CWorldOther::FromRpcCall(CPluto& u, CDbOper& db)
	{
		//printf("CWorldOther::from_rpc_call\n");
		//print_hex_pluto(u);

		pluto_msgid_t msg_id = -1;
		T_VECTOR_OBJECT* p = NULL;

		//这一段要加锁(2012/02/15改为不加锁)
		{
			//CMutexGuard _g(m_rpcMutex);

			msg_id = u.GetMsgId();
			if(!CheckClientRpc(u))
			{
				LogWarning("from_rpc_call", "invalid rpcall error.unknown msgid:%d\n", msg_id);
				return -1;
			}

			p = m_rpc.Decode(u);
			if(p == NULL)
			{
				LogWarning("from_rpc_call", "rpc Decode error.unknown msgid:%d\n", msg_id);
				return -1;
			}

			if(u.GetDecodeErrIdx() > 0)
			{
				ClearTListObject(p);
				//PrintHexPluto(u);
				LogWarning("from_rpc_call", "rpc Decode error.msgid:%d;pluto err idx=%d\n", msg_id, u.GetDecodeErrIdx());
				return -2;
			}
		}

        //这一段不用加锁
        int nRet = -1;
        switch(msg_id)
        {
            case MSGID_LOG_INSERT:
            {
                nRet = InsertDB(p, db);
                break;
            }
            case MSGID_OTHER_HTTP_REQ:
            {
                nRet = ReqUrl(p);
                break;
            }
            case MSGID_ALLAPP_SHUTDOWN_SERVER:
            {
                nRet = ShutdownServer(p);
                break;
            }
            case MSGID_OTHER_ADD_GLOBALBASE:
            {
                nRet = RegisterGlobally(p);
                break;
            }
            case MSGID_OTHER_YUNYING_API:
            {
                nRet = SupportApi(p, u.GetMailbox(), db);
                break;
            }
            case MSGID_OTHER_CLIENT_RESPONSE:
            {
                nRet = Response2Browser(p);
				PrintHexPluto(u);
                break;
            }
            //case MSGID_OTHER_LOGIN_VERIFY:
            //{
            //    //todo:verify
            //    nRet = SdkServerVerify(p, u);
            //    break;
            //}
// 			case MSGID_OTHER_PLAT_API:
// 			{
// 				nRet = PlatApi(p, u.GetMailbox(), db);
// 				break;
// 			}
            default:
            {
                LogWarning("from_rpc_call", "rpc unkown msg_id = %d\n", msg_id, nRet);
                break;
            }
        }

		if(nRet != 0)
		{
			LogWarning("from_rpc_call", "rpc error.msg_id=%d;ret=%d\n", msg_id, nRet);
		}

		ClearTListObject(p);

		return 0;
	}
示例#10
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;


	}