本文整理汇总了C++中CMsgConn::SetKey方法的典型用法代码示例。如果您正苦于以下问题:C++ CMsgConn::SetKey方法的具体用法?C++ CMsgConn::SetKey怎么用?C++ CMsgConn::SetKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CMsgConn
的用法示例。
在下文中一共展示了CMsgConn::SetKey方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _HandleValidateResponse
void CDBServConn::_HandleValidateResponse(CImPdu* pPdu)
{
IM::Server::IMValidateRsp msg;
CHECK_PB_PARSE_MSG(msg.ParseFromArray(pPdu->GetBodyData(), pPdu->GetBodyLength()));
string login_name = msg.user_name();
uint32_t result = msg.result_code();
string result_string = msg.result_string();
CDbAttachData attach_data((uchar_t*)msg.attach_data().c_str(), msg.attach_data().length());
struct timeval now;
gettimeofday(&now, NULL);
uint32_t rand_num = rand();
string strKey = int2string(now.tv_usec % 10000) + int2string(now.tv_sec) + int2string(rand_num);
strKey += strKey;
uint32_t nKeyLen = strKey.length();
if (nKeyLen < 32) {
for (uint32_t i=nKeyLen; i<32; i++)
strKey += '0';
}
else
{
strKey = strKey.substr(0, 32);
}
log("HandleValidateResp, user_name=%s, result=%d, key=%s", login_name.c_str(), result, strKey.c_str());
CImUser* pImUser = CImUserManager::GetInstance()->GetImUserByLoginName(login_name);
CMsgConn* pMsgConn = NULL;
if (!pImUser) {
log("ImUser for user_name=%s not exist", login_name.c_str());
return;
} else {
pMsgConn = pImUser->GetUnValidateMsgConn(attach_data.GetHandle());
if (!pMsgConn || pMsgConn->IsOpen()) {
log("no such conn is validated, user_name=%s", login_name.c_str());
return;
}
log("_HandleValidateResponse, user=%s(%p) conn=%p", login_name.c_str(), pImUser, pMsgConn);
}
if (result != 0) {
result = IM::BaseDefine::REFUSE_REASON_DB_VALIDATE_FAILED;
}
log("_HandleValidateResponse, login_user=%s key=%s %p ", login_name.c_str(), strKey.c_str(), pMsgConn);
total_users++;
switch(pMsgConn->GetClientType())
{
case IM::BaseDefine::CLIENT_TYPE_WINDOWS:
case IM::BaseDefine::CLIENT_TYPE_MAC:
pc_total_users++;
break;
case IM::BaseDefine::CLIENT_TYPE_ANDROID:
android_total_users++;
break;
case IM::BaseDefine::CLIENT_TYPE_IOS:
ios_total_users++;
break;
case IM::BaseDefine::CLIENT_TYPE_WEB:
web_total_users++;
break;
}
if (result == 0)
{
IM::BaseDefine::UserInfo user_info = msg.user_info();
uint32_t user_id = user_info.user_id();
CImUser* pUser = CImUserManager::GetInstance()->GetImUserById(user_id);
if (pUser)
{
log("_HandleValidateResponse, get user %u(%p) key=%s %p", user_id, pUser, strKey.c_str(), pMsgConn);
pUser->AddUnValidateMsgConn(pMsgConn);
pImUser->DelUnValidateMsgConn(pMsgConn);
if (pImUser->IsMsgConnEmpty())
{
CImUserManager::GetInstance()->RemoveImUserByLoginName(login_name);
delete pImUser;
}
}
else
{
pUser = pImUser;
log("_HandleValidateResponse, use login user %u(%p) key=%s %p", user_id, pUser, strKey.c_str(), pMsgConn);
}
pUser->SetUserId(user_id);
pUser->SetNickName(user_info.user_nick_name());
pUser->SetValidated();
CImUserManager::GetInstance()->AddImUserById(user_id, pUser);
log("user_name: %s, uid: %d(%p)", login_name.c_str(), user_id, pMsgConn);
pMsgConn->SetKey(strKey);
pMsgConn->SetUserId(user_id);
pMsgConn->SetOpen();
pMsgConn->SendUserStatusUpdate(IM::BaseDefine::USER_STATUS_ONLINE);
CRouteServConn* pRouteConn = get_route_serv_conn();
if (pRouteConn) {
IM::Server::IMServerKickUser msg2;
msg2.set_user_id(user_id);
msg2.set_client_type((::IM::BaseDefine::ClientType)pMsgConn->GetClientType());
msg2.set_reason(1);
//.........这里部分代码省略.........