Beispiel #1
0
void CLoginConn::_HandleUserCntUpdate(CImPdu* pPdu)
{
    map<uint32_t, msg_serv_info_t*>::iterator it = g_msg_serv_info.find(m_handle);
    if (it == g_msg_serv_info.end())
    {
        //error log or alertmsg
        log("socket %d not found.", m_handle);
        return;
    }

    IM::Server::IMUserCntUpdate msg;
    if (!pPdu->Decode(msg))
    {
        //decode fail
        log("decode fail.");
        return;
    }

    msg_serv_info_t* pMsgServInfo = it->second;
    //@zergl: 每个用户上线、下线都来个通知信息~ 这思路…打脸啪啪啪~~~
    uint32_t incr_num = (msg.user_action() == USER_CNT_INC) ? 1 : -1;
    pMsgServInfo->cur_conn_cnt += incr_num;
    g_total_online_user_cnt += incr_num;

    log("%s:%d, cur_cnt=%u, total_cnt=%u ", pMsgServInfo->hostname.c_str(),
        pMsgServInfo->port, pMsgServInfo->cur_conn_cnt, g_total_online_user_cnt);
}
Beispiel #2
0
void CLoginConn::_HandleUserCntUpdate(CImPdu* pPdu)
{
	log("enter[%s]", __FUNCTION__);

	map<uint32_t, msg_serv_info_t*>::iterator it = g_msg_serv_info.find(m_handle);
	if (it != g_msg_serv_info.end()) {
		msg_serv_info_t* pMsgServInfo = it->second;
        IM::Server::IMUserCntUpdate msg;
        msg.ParseFromArray(pPdu->GetBodyData(), pPdu->GetBodyLength());

		uint32_t action = msg.user_action();
		//每当有一个客户连接上来,则pMsgServInfo里面的用户数+1,总并发数也加1
		if (action == USER_CNT_INC) {
			pMsgServInfo->cur_conn_cnt++;
			g_total_online_user_cnt++;
		} else {
			pMsgServInfo->cur_conn_cnt--;
			g_total_online_user_cnt--;
		}

		log("%s:%d, cur_cnt=%u, total_cnt=%u ", pMsgServInfo->hostname.c_str(),
            pMsgServInfo->port, pMsgServInfo->cur_conn_cnt, g_total_online_user_cnt);
	}
	log("leave[%s]", __FUNCTION__);

}