//停止所有服务器 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; }
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; }
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; }
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; }
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; }
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; }
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; }