예제 #1
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;
    }
예제 #2
0
    int CWorldMgrD::init(const char* pszEtcFile)
    {
        LogInfo("CWorldMgrD::init()", "");

        int nWorldInit = world::init(pszEtcFile);
        if(nWorldInit != 0)
        {
            return nWorldInit;
        }

        //将所有的
        list<CMailBox*>& mbs = m_mbMgr.GetMailboxs();
        list<CMailBox*>::iterator iter = mbs.begin();
        for(; iter != mbs.end(); ++iter)
        {
            CMailBox* p = *iter;
            if(p->GetServerMbType() == SERVER_BASEAPP)
            {
                m_baseBalance.AddNewId(p->GetMailboxId());
            }
            else if(p->GetServerMbType() == SERVER_CELLAPP)
            {
                m_cellBalance.AddNewId(p->GetMailboxId());
            }
        }

        return 0;
    }
예제 #3
0
    int CWorldDbmgr::init(const char* pszEtcFile)
    {
        LogDebug("CWorldDbmgr::init()", "a=%d", 1);

        int nWorldInit = world::init(pszEtcFile);
        if(nWorldInit != 0)
        {
            return nWorldInit;
        }

        try
        {
            GetDefParser().init(m_cfg->GetValue("init", "def_path").c_str());
            GetDefParser().ReadDbCfg(m_cfg);
        }
        catch(const CException& e)
        {
            LogDebug("CWorldDbmgr::init().error", "%s", e.GetMsg().c_str());
            return -1;
        }

        ////需要一个空的lua环境来保存LUA_TABLE类型的数据
        /*
        m_L = lua_open();
        if(m_L==NULL)
        {
          return -1;
        }
        luaL_newmetatable(m_L, "G_LUATABLES");
        lua_setglobal(m_L, "G_LUATABLES");
        */
        //将所有的
        list<CMailBox*>& mbs = m_mbMgr.GetMailboxs();
        list<CMailBox*>::iterator iter = mbs.begin();
        for(; iter != mbs.end(); ++iter)
        {
            CMailBox* p = *iter;
            if(p->GetServerMbType() == SERVER_BASEAPP)
            {
                m_baseBalance.AddNewId(p->GetMailboxId());
            }
            //else if(p->GetServerMbType() == SERVER_CELLAPP)
            //{
            //  m_cellBalance.addNewId(p->GetMailboxId());
            //}
        }

        return 0;
    }
예제 #4
0
    //其他服务器进程退出后的回调方法
    int CWorldMgrD::OnServerShutdown(T_VECTOR_OBJECT* p)
    {
        if(p->size() != 1)
        {
            return -1;
        }

        //标记这个进程已经退出
        uint16_t nServerId = VOBJECT_GET_U16((*p)[0]);
        m_setShutdown.set(nServerId);

        LogDebug("CWorldMgrD::OnServerShutdown", "nServerId=%d", nServerId);

        //检查是否除dbmgr之外的进程都已经退出
        bool bQuitAll = true;
        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)
            {
                if(!m_setShutdown.test(basemb->GetMailboxId()))
                {
                    bQuitAll = false;
                    break;
                }
            }
        }

        if(bQuitAll)
        {
            //通知dbmgr退出
            RpcCall(SERVER_DBMGR, MSGID_DBMGR_SHUTDOWN_SERVER, (uint8_t)1);

            //cwmd退出
            GetServer()->Shutdown();
        }

        return 0;
    }
예제 #5
0
int CWorldCrossserver::init(const char* pszEtcFile)
{
	LogInfo("CWorldCrossserver::init()", "");

	int nWorldInit = world::init(pszEtcFile);
	if(nWorldInit != 0)
	{
		return nWorldInit;
	}

	//将所有的
	list<CMailBox*>& mbs = m_mbMgr.GetMailboxs();
	list<CMailBox*>::iterator iter = mbs.begin();
	for(; iter != mbs.end(); ++iter)
	{
		CMailBox* p = *iter;
		if(p->GetServerMbType() == SERVER_BASEAPP)
		{
			m_baseBalance.AddNewId(p->GetMailboxId());
		}
	}

	//计算def文件的md5
	{
		try
		{
			const string& strDefPath = GetCfgReader()->GetValue("init", "def_path");
			m_strDefMd5.assign(GetDefParser().CalcMd5OfAll(strDefPath.c_str()));
			LogInfo("CalcMd5OfAll", "md5=%s", m_strDefMd5.c_str());
		}
		catch(const CException& ex)
		{
			LogError("CWorldCrossserver::init.error", "Failed_to_calc_def_md5");
			return -10;
		}        
	}    

	return 0;
}
예제 #6
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;
    }
예제 #7
0
int BroadcastClientRpc(lua_State* L)
{

    const char* pszEntity = luaL_checkstring(L, 1);
    const char* pszFunc = luaL_checkstring(L, 2);

    world* the_world = GetWorld();
    if (!the_world)
    {
        return 0;
    }

    const SEntityDef* pDef = the_world->GetDefParser().GetEntityDefByName(pszEntity);
    if (!pDef)
    {
        return 0;
    }

    map<string, _SEntityDefMethods*>::const_iterator iter11 = \
        pDef->m_clientMethods.find(pszFunc);
    if(iter11 == pDef->m_clientMethods.end())
    {
        return 0;
    }

    //把pszEntity和pszFunc从堆栈中移除掉
    lua_remove(L, 1);
    lua_remove(L, 1);


    const _SEntityDefMethods* pMethods = iter11->second;
    const list<VTYPE>& args = pMethods->m_argsType;
    int nArgCount = lua_gettop(L);
    if(nArgCount != (int)args.size())
    {
        return 0;
    }

    uint16_t nFuncId = (uint16_t)pDef->m_clientMethodsMap.GetIntByStr(pszFunc);

    CPluto* u = new CPluto;
    u->Encode(MSGID_BASEAPP_BROADCAST_CLIENT_PRC);

    (*u) << the_world->GetDefParser().GetTypeId(pszEntity) << nFuncId;

    //打包rpc的所有参数为一个string
    int idx = 0;
    list<VTYPE>::const_iterator iter = args.begin();
    for(; iter != args.end(); ++iter)
    {
        ++idx;
        VTYPE vt = *iter;
        u->FillPlutoFromLua(vt, L, idx);
    }

    (*u) << EndPluto;

    the_world->GetServer()->AddLocalRpcPluto(u);

    vector<CMailBox*>& mbs = the_world->GetServer()->GetAllServerMbs();
    vector<CMailBox*>::iterator iter2 = mbs.begin();
    for(; iter2 != mbs.end(); ++iter2)
    {
        CMailBox* basemb = *iter2;
        if(basemb && basemb->GetServerMbType() == SERVER_BASEAPP)
        {
            //发给每个其他baseapp的mb的pluto都是发给本地进程的那个pluto的拷贝
            CPluto* u2 = new CPluto(u->GetBuff(), u->GetLen());
            basemb->PushPluto(u2);
        }
    }

    return 0;
}