void CBaseObj::SendRefMsg(Msg &pMsg) { assert(m_GateIDMax < gateinfo_count); for (int i = m_GateIDMin; i <= m_GateIDMax; ++i) { gateinfo[i]->Reset(); } static bool bNeeSendMsg = false; static msgtail tail; std::unordered_map<uint32, CBaseObj *> *playerlist = GetAoiList(); std::unordered_map<uint32, CBaseObj *>::iterator iter = playerlist->begin(); for (; iter != playerlist->end(); ++iter) { if (iter->second->IsPlayer()) { CPlayer * p = (CPlayer *)iter->second; if (FuncUti::isValidCret(p)) { int32 gateid = p->GetGateID(); if (gateid >= 0 && gateid < gateinfo_count) { if (gateid > m_GateIDMax) { m_GateIDMax = gateid; } else if (gateid < m_GateIDMin) { m_GateIDMin = gateid; } if (gateinfo[gateid]->gate == nullptr) { gateinfo[gateid]->gate = p->GetGateInfo(); } gateinfo[gateid]->nClientId[gateinfo[gateid]->nCount] = p->GetClientID(); gateinfo[gateid]->nCount += 1; } } } } static bool bIsPlayer = false; bIsPlayer = IsPlayer(); if (bNeeSendMsg || bIsPlayer) { if (bIsPlayer) { CPlayer *p = (CPlayer *)this; int32 gateid = p->GetGateID(); if (gateid >= 0 && gateid < gateinfo_count) { if (gateid > m_GateIDMax) { m_GateIDMax = gateid; } else if (gateid < m_GateIDMin) { m_GateIDMin = gateid; } if (gateinfo[gateid]->gate == nullptr) { gateinfo[gateid]->gate = p->GetGateInfo(); } gateinfo[gateid]->nClientId[gateinfo[gateid]->nCount] = p->GetClientID(); gateinfo[gateid]->nCount += 1; } } bNeeSendMsg = false; MessagePack pkmain; pkmain.PushInt32(pMsg.GetLength()); pkmain.PushBlock(&pMsg, pMsg.GetLength()); int32 pkmainlen = pkmain.GetLength(); for (int i = m_GateIDMin; i < m_GateIDMax; ++i) { if (gateinfo[i]->nCount > 0) { tail.id = 0; for (int j = 0; j < gateinfo[i]->nCount; ++j) { pkmain.PushInt32(gateinfo[i]->nClientId[j]); --tail.id; } GameGatewayMgr.SendMsg(gateinfo[i]->gate, pkmain, &tail, sizeof(tail)); pkmain.SetLength(pkmainlen); pkmain.m_index = pkmainlen - (int32)sizeof(Msg); } } } }