Ejemplo n.º 1
0
    int CWorldMgrD::CreateCellInNewSpace(T_VECTOR_OBJECT* p)
    {
        if(p->size() != 4)
        {
            return -1;
        }

        CEntityMailbox& emb = VOBJECT_GET_EMB((*p)[0]);
        uint16_t etype = VOBJECT_GET_U16((*p)[1]);
#ifdef __USE_MSGPACK
        charArrayDummy *d = (charArrayDummy*)VOBJECT_GET_BLOB((*p)[2]);
#else
        const char* pszParams = VOBJECT_GET_STR((*p)[2]);
#endif
        charArrayDummy& props = *((charArrayDummy*)((*p)[3]->vv.p));

        uint16_t nCellappId = ChooseACellApp(etype);
        CMailBox* mb = GetServerMailbox(nCellappId);
        if(mb)
        {
#ifdef __USE_MSGPACK
            mb->RpcCall(GetRpcUtil(), MSGID_CELLAPP_CREATE_CELL_IN_NEW_SPACE, emb, etype, *d, props);
#else
            mb->RpcCall(GetRpcUtil(), MSGID_CELLAPP_CREATE_CELL_IN_NEW_SPACE, emb, etype, pszParams, props);
#endif
        }

        return 0;
    }
Ejemplo n.º 2
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;
    }
Ejemplo n.º 3
0
int CWorldLogin::NotifyClientToAttach(T_VECTOR_OBJECT* p)
{
    if(p->size() != 3)
    {
        return -1;
    }

    const char* pszAccount = VOBJECT_GET_STR((*p)[0]);
    uint16_t baseapp_id = VOBJECT_GET_U16((*p)[1]);
    const char* pszKey = VOBJECT_GET_STR((*p)[2]);

    map<string, int>::const_iterator iter = m_accounts2fd.find(pszAccount);
    if(iter == m_accounts2fd.end())
    {
        LogWarning("NotifyClientToAttach", "Account '%s' hasn't client", pszAccount);
        return -2;
    }

    LogDebug("NotifyClientToAttach", "account=%s;fd=%d", pszAccount, iter->second);
    CMailBox* mb = GetServer()->GetClientMailbox(iter->second);
    if(mb != NULL)
    {
        CMailBox* smb = GetServer()->GetServerMailbox(baseapp_id);
        if(smb == NULL)
        {
            LogWarning("NotifyClientToAttach", "error baseapp_id:%d", baseapp_id);
            return -3;
        }

        mb->RpcCall(GetRpcUtil(), MSGID_CLIENT_NOTIFY_ATTACH_BASEAPP, smb->GetServerName().c_str(), smb->GetServerPort(), pszKey);
    }

    return 0;
}
Ejemplo n.º 4
0
    int CWorldDbmgr::SelectAccount(T_VECTOR_OBJECT* p, CDbOper& db)
    {
#if __PLAT_PLUG_IN || __PLAT_PLUG_IN_NEW
		if(p->size() != 3)
#else
		if(p->size() != 4)
#endif
        {
            return -1;
        }

        uint16_t nServerId = VOBJECT_GET_U16((*p)[0]);
        int32_t nFd = VOBJECT_GET_I32((*p)[1]);
        const char* s1 = VOBJECT_GET_STR((*p)[2]);
#if __PLAT_PLUG_IN || __PLAT_PLUG_IN_NEW

#else
        const char* s2 = VOBJECT_GET_STR((*p)[3]);
#endif

        CPluto* u = new CPluto;
        string strErr;
#if __PLAT_PLUG_IN || __PLAT_PLUG_IN_NEW
		if(db.SelectAccount(nFd, s1, *u, strErr) != 0)
#else
        if(db.SelectAccount(nFd, s1, s2, *u, strErr) != 0)
#endif
        {
            delete u;
            //cout << strErr << endl;
            LogWarning("SelectAccount_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::SelectAccount", "u.GenLen()=%d", u->GetLen());

            g_pluto_sendlist.PushPluto(u);
#endif
        }
        else
        {
            delete u;
            LogWarning("SelectAccount_err", "no mb!");
            return -3;
        }

        return 0;
    }
Ejemplo n.º 5
0
    int CEntityParent::lWriteToDB(lua_State* L)
    {
        //first param is userdata

        world& the_world = *GetWorld();
        int32_t ref = 0;
        if(m_dbid == 0)
        {
            luaL_checkany(L, 2);   //callable object
            CLuaCallback& cb = the_world.GetCallback();
            lua_pushvalue(L, 2);
            ref = (int32_t)cb.Ref(L);
        }
        else
        {
            //没有设置脏数据标记,返回
            if(!m_bIsMysqlDirty)
            {
                LogDebug("CEntityParent::lWriteToDB", "not_dirty;etype=%d;id=%d;dbid=%d", m_etype, m_id, m_dbid);
                return 0;
            }
        }

        CMailBox* mb = the_world.GetServerMailbox(SERVER_DBMGR);
        if(mb)
        {
            if(m_dbid == 0)
            {
                mb->RpcCall(the_world.GetRpcUtil(), MSGID_DBMGR_INSERT_ENTITY, m_mymb, ref, *this);
            }
            else
            {
                mb->RpcCall(the_world.GetRpcUtil(), MSGID_DBMGR_UPDATE_ENTITY, m_mymb, m_dbid, *this);
            }
        }

        //清理脏数据标记,设置上次存盘时间
        m_nTimestamp = time(NULL);
        m_bIsDirty = false;
        m_bIsMysqlDirty = false;

        LogInfo("CEntityParent::lWriteToDB", "etype=%d;id=%d;dbid=%d;ref=%d", m_etype, m_id, m_dbid, ref);

        return 0;
    }
Ejemplo n.º 6
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;
    }
Ejemplo n.º 7
0
    int CWorldDbmgr::InsertDB(T_VECTOR_OBJECT* p, CDbOper& db)
    {
        if(p->size() != 3)
        {
            return -1;
        }

        CEntityMailbox& emb = VOBJECT_GET_EMB((*p)[0]);
        int32_t ref = VOBJECT_GET_I32((*p)[1]);
        SEntityPropFromPluto* p2 = (SEntityPropFromPluto*)((*p)[2]->vv.p);

        const string& strEntityName = GetDefParser().GetTypeName(p2->etype);

        //string strSql;
        //db.make_insert_sql(strEntityName, p2->data, strSql);
        //cout << strSql << endl;

        //string strSql2;
        //db.make_create_sql(strEntityName, strSql2);
        //cout << strSql2 << endl;

        //LogWarning("insert to db", "emb ref strEntityName = %s", strEntityName.c_str());

        string strErr;
        TDBID newid = db.InsertEntity(strEntityName, p2->data, strErr);
        if(newid == 0)
        {
            LogWarning("InsertDB_err", "newid=0;err=%s", strErr.c_str());
            //cout << strErr << endl;
            //return -2;
        }

        //通知db结果
        CEpollServer* s = this->GetServer();
        CMailBox* mb = s->GetServerMailbox(emb.m_nServerMailboxId);
        if(mb)
        {
#ifdef _WIN32
            mb->RpcCall(GetRpcUtil(), MSGID_BASEAPP_INSERT_ENTITY_CALLBACK, emb, newid, ref, strErr.c_str());
#else
            CRpcUtil& rpc = GetRpcUtil();
            CPluto* u = new CPluto;
            rpc.Encode(*u, MSGID_BASEAPP_INSERT_ENTITY_CALLBACK, emb, newid, ref, strErr.c_str());
            u->SetMailbox(mb);

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

            g_pluto_sendlist.PushPluto(u);
#endif
        }

        return 0;
    }
Ejemplo n.º 8
0
int LoadEntitiesOfType(lua_State* L)
{
    const char* pszEntity = luaL_checkstring(L, 1);
    uint16_t nBaseappId = GetWorld()->GetMailboxId();

    world* the_world = GetWorld();
    CMailBox* mb = the_world->GetServerMailbox(SERVER_DBMGR);
    if(mb)
    {
        mb->RpcCall(the_world->GetRpcUtil(), MSGID_DBMGR_LOAD_ENTITIES_OF_TYPE, pszEntity, nBaseappId);
    }

    return 0;
}
Ejemplo n.º 9
0
int LoadAllAvatars(lua_State* L)
{
    const static char szEntity[] = "Avatar";
    const static char szIndex[] = "account_name";

    world* the_world = GetWorld();
    CMailBox* mb = the_world->GetServerMailbox(SERVER_DBMGR);
    if(mb)
    {
        mb->RpcCall(the_world->GetRpcUtil(), MSGID_DBMGR_LOAD_ALL_AVATAR, szEntity, szIndex);
    }

    return 0;
}
Ejemplo n.º 10
0
	int CWorldDbmgr::TableExcute(T_VECTOR_OBJECT* p, CDbOper& db)
	{
		if (p->size() != 3)
		{
			LogError("CWorldDbmgr::TableInsert", "p->size()=%d", p->size());
			return -1;
		}

		uint16_t nBaseappId = VOBJECT_GET_U16((*p)[0]);
		const string& strSql = VOBJECT_GET_SSTR((*p)[1]);
		uint32_t ref = VOBJECT_GET_U32((*p)[2]);

		//LogDebug("CWorldDbmgr::TableExcute", "nBaseappId=%d;ref=%d;strSql=%s",
		//	nBaseappId, ref,  strSql.c_str());

		string strErr;
		uint8_t ret = db.TableExcute(strSql, strErr);

		if(ret != 0)
		{
			LogWarning("ExcuteDB_err", "ret=%d;err=%s", ret, strErr.c_str());
		}
		//ref == 0 无返回
		if (ref == 0)
		{
			return 0;
		}
		
		//通知db结果
		CEpollServer* s = this->GetServer();
		CMailBox* mb = s->GetServerMailbox(nBaseappId);
		if(mb)
		{
#ifdef _WIN32
			mb->RpcCall(GetRpcUtil(), MSGID_BASEAPP_TABLE_EXCUTE_CALLBACK, ref, ret );
#else
			CRpcUtil& rpc = GetRpcUtil();
			CPluto* u = new CPluto;
			rpc.Encode(*u, MSGID_BASEAPP_TABLE_EXCUTE_CALLBACK, ref, ret);
			u->SetMailbox(mb);

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

			g_pluto_sendlist.PushPluto(u);
#endif
		}
		return 0;
	}
Ejemplo n.º 11
0
    int CEntityBase::lNotifyClientMultiLogin(lua_State* L)
    {
        //first param is userdata
        const char* pszAccount = luaL_checkstring(L, 2);

        LogDebug("CEntityBase::lNotifyClientMultiLogin", "id=%d;Account=%s", m_id, pszAccount);

        CWorldBase& worldbase = GetWorldbase();
        CMailBox* mb = worldbase.GetServerMailbox(SERVER_LOGINAPP);
        if(mb)
        {
            mb->RpcCall(worldbase.GetRpcUtil(), MSGID_LOGINAPP_NOTIFY_CLIENT_MULTILOGIN, pszAccount);
        }

        return 0;
    }
Ejemplo n.º 12
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;
    }
Ejemplo n.º 13
0
    int CEntityBase::lNotifyClientToAttach(lua_State* L)
    {
        //first param is userdata
        const char* pszAccount = luaL_checkstring(L, 2);

        //测试数据日志
        LogDebug("CEntityBase::lNotifyClientToAttach", "id=%d;Account=%s", m_id, pszAccount);
        //only Account can invoke, and control with scripts
        CWorldBase& worldbase = GetWorldbase();
        CMailBox* mb = worldbase.GetServerMailbox(SERVER_LOGINAPP);
        if(mb)
        {
            const string& key = worldbase.MakeClientLoginKey(pszAccount, m_id);
            mb->RpcCall(worldbase.GetRpcUtil(), MSGID_LOGINAPP_NOTIFY_CLIENT_TO_ATTACH, pszAccount,
                        m_mymb.m_nServerMailboxId, key.c_str());
        }

        return 0;
    }
Ejemplo n.º 14
0
    int CEntityBase::lRegisterGlobally(lua_State* L)
    {
        //first param is userdata
        const char* szName = luaL_checkstring(L, 2);
        //printf("CEntityBase::lregisterGlobally(),%d,%s\n", SERVER_BASEAPPMGR, szName);
        luaL_checkany(L, 3);   //callable object

        world& the_world = *GetWorld();
        CLuaCallback& cb = the_world.GetCallback();
        lua_pushvalue(L, 3);
        int ref = cb.Ref(L);

        CMailBox* mb = the_world.GetServerMailbox(SERVER_BASEAPPMGR);
        if(mb)
        {
            mb->RpcCall(the_world.GetRpcUtil(), MSGID_BASEAPPMGR_REGISTERGLOBALLY, m_mymb, szName, (int32_t)ref);
        }

        return 0;
    }
Ejemplo n.º 15
0
    //通知db销毁account
    int CEntityBase::lNotifyDbDestroyAccountCache(lua_State* L)
    {
        //first param userdata
        const char* pszAccountName = luaL_checkstring(L, 2);
        static const string strEntityType = "Account";
        world& the_world = *GetWorld();
        /*
        luaL_checkany(L, 3);   //callable object

        CLuaCallback& cb = the_world.GetCallback();
        lua_pushvalue(L, 3);
        int ref = cb.Ref(L);
        */
        CMailBox* mb = the_world.GetServerMailbox(SERVER_DBMGR);
        if(mb)
        {
            mb->RpcCall(the_world.GetRpcUtil(), MSGID_DBMGR_DEL_ACCOUNT_CACHE, pszAccountName, strEntityType);
        }
        return 0;
    }
Ejemplo n.º 16
0
//发起创建,此时无数据无法真正创建
int CreateEntityFromDbId(lua_State* L)
{
    const char* szEntityType = luaL_checkstring(L, 1);
    TDBID dbid = (TDBID)luaL_checknumber(L, 2);
    luaL_checkany(L, 3);                        //callback

    CWorldBase& worldbase = GetWorldbase();
    CMailBox* mb = worldbase.GetServerMailbox(SERVER_DBMGR);
    if(mb && dbid > 0)
    {
        CLuaCallback& cb = worldbase.GetCallback();
        //lua_pushvalue(L, 3);
        int32_t ref = (int32_t)cb.Ref(L);

        //LogInfo("[create entity from db id]", "[entity type=%s][dbid =%d][ref =%d]",szEntityType, dbid, ref);

        mb->RpcCall(worldbase.GetRpcUtil(), MSGID_DBMGR_SELECT_ENTITY, \
                    worldbase.GetServer()->GetMailboxId(), szEntityType, dbid, ref);
    }
    return 0;
}
Ejemplo n.º 17
0
int lGetArrayFromDb(lua_State* L)
{
    int n = lua_gettop(L);
    if( n != 3 )
    {
        LogError("lGetArrayFromDb", "Parameters number from lua not enough");
        lua_pushnumber(L, 0);
        return 1;
    }
    if( LUA_TSTRING != lua_type(L, 1) && LUA_TNUMBER != lua_type(L, 2) )
    {
        LogError("Parameters type from lua erroe", "%d", -1);
        lua_pushnumber(L, 0);
        return 1;
    }
    luaL_checkany(L, 3);

    CLuaCallback& cb = GetWorld()->GetCallback();
    lua_pushvalue(L, 3);
    int32_t ref = (int32_t)cb.Ref(L);

    lua_pop(L, 1);

    const char* itemName = lua_tostring(L, 1);
    const TDBID dbid = lua_tonumber(L, 2);
    uint16_t nBaseappId = GetWorld()->GetMailboxId();

    CMailBox* mb = GetWorldbase().GetServerMailbox(SERVER_DBMGR);
    if(mb)
    {
        //cout<<"get arary from db"<<endl;
        //cout<<"ref ="<<ref<<endl;
        mb->RpcCall(GetWorldbase().GetRpcUtil(), MSGID_DBMGR_LOADING_ITEMS, itemName, dbid, nBaseappId, ref);
    }
    else
    {
        cb.Unref(L, ref);
    }
    return 0;
}
Ejemplo n.º 18
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;
    }
Ejemplo n.º 19
0
    int CWorldMgrD::RegisterGlobally(T_VECTOR_OBJECT* p)
    {

        //printf("rrrr,%d\n", p->size());
        if(p->size() != 3)
        {
            return -1;
        }

        CEntityMailbox& emb = VOBJECT_GET_EMB((*p)[0]);
        const char* szName = VOBJECT_GET_STR((*p)[1]);
        int32_t ref = VOBJECT_GET_I32((*p)[2]);

        //printf("rrrr2222, %s, %d \n", szName, ref);

        bool bRet = false;
        map<string, CEntityMailbox*>::iterator iter = m_globalBases.lower_bound(szName);
        if(iter != m_globalBases.end() && iter->first.compare(szName) == 0)
        {
            //existed!
        }
        else
        {
            //add new
            bRet = true;
            CEntityMailbox* pe = new CEntityMailbox;
            pe->m_nServerMailboxId = emb.m_nServerMailboxId;
            pe->m_nEntityType = emb.m_nEntityType;
            pe->m_nEntityId = emb.m_nEntityId;
            m_globalBases.insert(iter, make_pair(szName, pe));
        }

        //如果注册成功,同步给所有的baseapp
        CEpollServer* s = this->GetServer();
        if(bRet)
        {
            vector<CMailBox*>& mbs = s->GetAllServerMbs();
            vector<CMailBox*>::iterator iter = mbs.begin();
            for(; iter != mbs.end(); ++iter)
            {
                CMailBox* basemb = *iter;
                if(basemb && basemb->GetServerMbType() == SERVER_BASEAPP)
                {
                    basemb->RpcCall(GetRpcUtil(),MSGID_BASEAPP_ADD_GLOBALBASE, szName, emb);
                }
                if (basemb && basemb->GetServerMbType() == SERVER_LOG)
                {
                    LogDebug("mogo::CWorldMgrD::RegisterGlobally", "szName=%s;", szName);
                    //通知logapp,哪一个base进程拥有哪一个globalbase
                    basemb->RpcCall(GetRpcUtil(), MSGID_OTHER_ADD_GLOBALBASE, szName, emb);
                }
            }
        }

        //通知注册结果
        CMailBox* mb = s->GetServerMailbox(emb.m_nServerMailboxId);
        if(mb)
        {
            mb->RpcCall(GetRpcUtil(), MSGID_BASEAPP_REGISTERGLOBALLY_CALLBACK, emb, (uint8_t)bRet, ref);
        }

        return 0;
    }
Ejemplo n.º 20
0
void* ThreadJob_SdkServerVerify(void* arg)
{
	CPluto& u = *((CPluto*)arg);
	pluto_msgid_t msg_id = u.GetMsgId();;
	T_VECTOR_OBJECT* p = NULL;

	CMailBox* pmb = u.GetMailbox();
	if(!pmb)
	{
		//如果没有mb,是从本进程发来的包
		delete &u;
		return (void*)-1;
	}
	uint8_t authz = pmb->GetAuthz();
	if(authz != MAILBOX_CLIENT_TRUSTED)
	{
		LogWarning("ThreadJob_SdkServerVerify", "invalid rpcall error.unknown msgid:%d\n", msg_id);
		delete &u;
		return (void*)-1;
	}

	p = g_worldOther.GetRpcUtil().Decode(u);
	if(p == NULL)
	{
		LogWarning("ThreadJob_SdkServerVerify", "rpc Decode error.unknown msgid:%d\n", msg_id);
		delete &u;
		return (void*)-2;
	}

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

	if (p->size() != 4)
	{
		delete &u;
		return (void*)-4;
	}
	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();

	string resp = "";
	int ret = GetUrl(url.c_str(), resp);
	if (ret != CURLE_OK)
	{
		LogWarning("CWorldOther::SdkServerVerify", "%s ret = %d", strAccount.c_str(), ret);
		//todo:faild.
		pmb->RpcCall(g_worldOther.GetRpcUtil(), MSGID_LOGINAPP_LOGIN_VERIFY_CALLBACK, ret, nFd, strAccount, strPlatId);
		delete &u;
		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);
	}
	pmb->RpcCall(g_worldOther.GetRpcUtil(), MSGID_LOGINAPP_LOGIN_VERIFY_CALLBACK, ret, nFd, strAccount, strPlatId);
	delete &u;
	return (void*)0;
}