void CClientMgr::SendMsg(int32 clientid, Msg *pMsg) { if (clientid > 0) { CClient *cl = FindClientByClientID(clientid); if (cl) { cl->SendMsg(pMsg); } } else { std::list<CClient*>::iterator _Iter = m_ClientList.begin(); for (; _Iter != m_ClientList.end(); ++_Iter) (*_Iter)->SendMsg(pMsg); } }
void CClient::OnMsgTransmit(unsigned short wMsgId, const char *pMsg) { if (m_strAccount.length() == 0) { LOGDebug("account is empty."); return; } SEsp8266Info *pEspInfo = CEsp8266Mgr::getMe().Find(m_strAccount); if (nullptr == pEspInfo) { LOGDebug("nullptr == pEspInfo[m_strAccount:" + m_strAccount + "]"); return; } CClient *pSendClient = nullptr; CClient *pToClient = nullptr; if (this == pEspInfo->pClientApp) { pSendClient = pEspInfo->pClientApp; pToClient = pEspInfo->pClientEsp; } else if (this == pEspInfo->pClientEsp) { pSendClient = pEspInfo->pClientEsp; pToClient = pEspInfo->pClientApp; } else { LOGDebug("OnMsgTransmit error.[m_strAccount:" + m_strAccount + "]"); return; } if (nullptr == pToClient) { LOGDebug("nullptr == pToClient.[m_strAccount:" + m_strAccount + "]"); return; } pToClient->SendMsg(wMsgId, pMsg); LOGDebug("Account[" + m_strAccount + "] transmit message[msgid:" + wMsgId + "]."); }
void CClientMgr::SendMsg(int32 clientid, google::protobuf::Message &pMsg, int32 maintype, int32 subtype) { if (clientid > 0) { CClient *cl = FindClientByClientID(clientid); if (cl) { MessagePack pk; pk.Pack(&pMsg, maintype, subtype); cl->SendMsg(&pk); } } else { MessagePack pk; pk.Pack(&pMsg, maintype, subtype); std::list<CClient*>::iterator _Iter = m_ClientList.begin(); for (; _Iter != m_ClientList.end(); ++_Iter) (*_Iter)->SendMsg(&pk); } }