Beispiel #1
0
int CWorldLogin::ModifyLoginFlag(T_VECTOR_OBJECT* p)
{
    //printf("modify login flag !\n");
	if(p->size() != 1)
	{
		return -1;
	}

	uint8_t flag = VOBJECT_GET_U8((*p)[0]);
	if(flag == 1)
	{   
        //printf("open service success!\n");
		m_bCanLogin = true;
	}
	else
	{
        //printf("open service failure!\n");
		m_bCanLogin = false;
	}

	//记录日志
	LogInfo("CWorldLogin::ModifyLoginFlag", "input=%d;flag=%d", flag, m_bCanLogin);

	return 0;
}
Beispiel #2
0
    int CWorldMgrD::CreateBaseFromDbByName(T_VECTOR_OBJECT* p)
    {
        if(p->size() < 3)
        {
            return -1;
        }

        uint8_t createFlag = VOBJECT_GET_U8((*p)[0]);
        const char* pszEntityType = VOBJECT_GET_STR((*p)[1]);
        const char* pszKey = VOBJECT_GET_STR((*p)[2]);

        uint16_t nBaseappId;
        if(p->size() > 3)
        {
            //指定了baseapp
            nBaseappId = VOBJECT_GET_U16((*p)[3]);
        }
        else
        {
            //未指定baseapp,选择一个
            nBaseappId = ChooseABaseApp(pszEntityType);
        }

#ifdef __TEST_LOGIN
        CEpollServer* s = this->GetServer();
        CMailBox* mb = s->GetServerMailbox(nBaseappId);

        if (mb)
        {
            TENTITYID nOtherEntityId = 0;

            CPluto* u = new CPluto;
            (*u).Encode(MSGID_BASEAPP_LOOKUP_ENTITY_CALLBACK);
            (*u) << (uint64_t)0 << this->GetNextEntityId()<< createFlag << pszKey << nOtherEntityId;
            (*u) << this->GetDefParser().GetTypeId(pszEntityType);

            TDBID dbid2 = 0;

            (*u).ReplaceField(PLUTO_FILED_BEGIN_POS, dbid2);
            (*u) << EndPluto;

            u->SetMailbox(mb);

            LogDebug("CWorldMgrD::CreateBaseFromDbByName", "u.GenLen()=%d", u.GetLen());

            mb->PushPluto(u);
        }

#else
        CMailBox* mb = GetServerMailbox(SERVER_DBMGR);
        if(mb)
        {
            mb->RpcCall(GetRpcUtil(), MSGID_DBMGR_CREATEBASE_FROM_NAME, nBaseappId, createFlag, pszEntityType, pszKey);
        }
#endif
        return 0;
    }
Beispiel #3
0
// DbMgr 验证后的回调。 通过后通知baseapp 创建角色对象
int CWorldLogin::SelectAccountCallback(T_VECTOR_OBJECT* p)
{
    if(p->size() != 3)
    {
        return -1;
    }

    int32_t fd = VOBJECT_GET_I32((*p)[0]);
    const char* pszAccount = VOBJECT_GET_STR((*p)[1]);
    uint8_t nRet = VOBJECT_GET_U8((*p)[2]);

    //printf("select account call back vector objects: fd: %d account: %s ret: %d\n",fd, pszAccount, nRet );
    LogInfo("CWorldLogin::select_account_callback", "account=%s;fd=%d;ret=%d\n", pszAccount, fd, nRet);

	CMailBox* mb = GetServer()->GetClientMailbox(fd);
    CPluto* pu = new CPluto;
    if(nRet == 0)
    {
        m_fd2accounts.erase(fd);    //验证失败,删除对应关系
		m_accounts2fd.erase(pszAccount);

        //账号错误
        (*pu).Encode(MSGID_CLIENT_LOGIN_RESP) << (uint8_t)ENUM_LOGIN_RET_ACCOUNT_PASSWD_NOMATCH << EndPluto;
    }
    else
    {
        //账号校验通过
		if(mb)
		{
            //printf("set the client to authorize!\n");
			mb->SetAuthz(MAILBOX_CLIENT_AUTHZ);
		}
        uint32_t tp = 0x11111111;
        (*pu).Encode(MSGID_CLIENT_LOGIN_RESP) << (uint8_t)ENUM_LOGIN_SUCCESS << tp << EndPluto;

        /*
        //创建account
        CMailBox* mb2 = GetServerMailbox(SERVER_BASEAPPMGR);
        if(mb2)
        {
            //标记1表示如果数据库中不存在,也要创建一个entity
            mb2->RpcCall(GetRpcUtil(), MSGID_BASEAPPMGR_CREATEBASE_FROM_NAME_ANYWHERE, (uint8_t)1, "Account", pszAccount);
        }
        */
    }

	if(mb != NULL)
	{
		mb->PushPluto(pu);
        //printf("select account login call back success!\n");
	}

    return 0;
}
Beispiel #4
0
    //根据dbid查找entity
    int CWorldDbmgr::LookupEntityByDbId(T_VECTOR_OBJECT* p, CDbOper& db)
    {
        if(p->size() != 4)
        {
            return -1;
        }

        uint8_t nServerId = VOBJECT_GET_U8((*p)[0]);
        const char* szEntityName = VOBJECT_GET_STR((*p)[1]);
        TDBID dbid = VOBJECT_GET_U64((*p)[2]);
        int32_t ref = VOBJECT_GET_I32((*p)[3]);

        CPluto* u = new CPluto;
        string strErr;
        if(db.LookupEntityByDbId(szEntityName, dbid, ref, *u, strErr) != 0)
        {
            delete u;
            //cout << strErr << endl;
            LogWarning("LookupEntityByDbId_err", "%s", strErr.c_str());
            return -2;
        }

        //通知db结果
        CEpollServer* s = this->GetServer();
        CMailBox* mb = s->GetServerMailbox(nServerId);
        if(mb)
        {
#ifdef _WIN32
            mb->RpcCall(*u);
#else
            u->SetMailbox(mb);

            LogDebug("CWorldDbmgr::LookupEntityByDbId", "u.GenLen()=%d", u->GetLen());

            g_pluto_sendlist.PushPluto(u);
#endif
        }
        else
        {
            LogWarning("CWorldDbmgr::LookupEntityByDbId", "u.GenLen()=%d", u->GetLen());
            delete u;
        }

        return 0;
    }
Beispiel #5
0
    int CWorldDbmgr::LookupEntityByName(T_VECTOR_OBJECT* p, CDbOper& db)
    {
        if(p->size() != 4)
        {
            return -1;
        }

        uint16_t nBaseappId = VOBJECT_GET_U16((*p)[0]);
        uint8_t nCreateFlag = VOBJECT_GET_U8((*p)[1]);
        const char* pszEntityName = VOBJECT_GET_STR((*p)[2]);
        const char* pszKey = VOBJECT_GET_STR((*p)[3]);

        const string& strKey(pszKey);
        //先查找该key相关的entity是否已经创建出来了
        SEntityLookup* pLookup = LookupEntityInfo(strKey, pszEntityName);
        if(pLookup != NULL)
        {
            //LogInfo("CWorldDbmgr::LookEntityByName", "entity exists;key=%s;eid=%d;baseapp=%d", \
            //        pszKey, pLookup->eid, pLookup->sid);

            CMailBox* mb = GetServerMailbox(pLookup->sid);
            if(mb)
            {
                CPluto* u = new CPluto;
                u->Encode(MSGID_BASEAPP_ENTITY_MULTILOGIN);
                (*u) << pLookup->eid << EndPluto;
                u->SetMailbox(mb);

                //LogDebug("CWorldDbmgr::LookupEntityByName", "u.GenLen()=%d", u->GetLen());

                g_pluto_sendlist.PushPluto(u);
            }

            return 0;
        }

        TENTITYID new_eid = MyGetNextEntityId();
        CPluto* u = new CPluto;
        string strErr;
        if(db.LookupEntityByName(nCreateFlag, pszEntityName, strKey, new_eid, *u, nBaseappId, strErr) != 0)
        {
            delete u;
            //cout << strErr << endl;
            LogWarning("LookEntityByName_err", "%s", strErr.c_str());
            return -2;
        }

        //add for lookup
        CreateNewEntityToLookup(strKey, pszEntityName, new_eid, nBaseappId);

        //通知db结果
        CEpollServer* s = this->GetServer();
        CMailBox* mb = s->GetServerMailbox(nBaseappId);
        if(mb)
        {
#ifdef _WIN32
            mb->RpcCall(*u);
#else
            u->SetMailbox(mb);

            LogDebug("CWorldDbmgr::LookupEntityByName", "u.GenLen()=%d", u->GetLen());

            g_pluto_sendlist.PushPluto(u);
#endif
        }
        else
        {
            LogWarning("CWorldDbmgr::LookupEntityByName", "u.GenLen()=%d", u->GetLen());
            delete u;
        }

        return 0;
    }