//根据server_id获取服务器绑定端口 uint16_t world::GetServerPort(uint16_t sid) { list<CMailBox*>& mbs = m_mbMgr.GetMailboxs(); list<CMailBox*>::iterator iter = mbs.begin(); for(; iter != mbs.end(); ++iter) { CMailBox* pmb = *iter; if(pmb->GetMailboxId() == sid) { return pmb->GetServerPort(); } } return 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; }
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; }