当前位置: 首页>>代码示例>>C++>>正文


C++ TcpSessionPtr::setUserParam方法代码示例

本文整理汇总了C++中TcpSessionPtr::setUserParam方法的典型用法代码示例。如果您正苦于以下问题:C++ TcpSessionPtr::setUserParam方法的具体用法?C++ TcpSessionPtr::setUserParam怎么用?C++ TcpSessionPtr::setUserParam使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TcpSessionPtr的用法示例。


在下文中一共展示了TcpSessionPtr::setUserParam方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: msg_onAttachLogicReq

void NetMgr::msg_onAttachLogicReq(TcpSessionPtr session, ReadStream & rs)
{
    if (std::get<TupleParamNumber>(session->getUserParam(UPARAM_SESSION_STATUS)) != SSTATUS_UNKNOW)
    {
        return;
    }
    
    AttachLogicAck ack;
    ack.retCode = EC_SUCCESS;
    AttachLogicReq req;
    rs >> req;
    LOGD("enter msg_loginReq token=" << req.token << ", uID=" << req.uID);
    do 
    {
        auto info = getUserInfo(req.uID);
        if (!info)
        {
            ack.retCode = EC_TARGET_NOT_EXIST;
            break;
        }
        if (info->token.token != req.token)
        {
            ack.retCode = EC_PERMISSION_DENIED;
            break;
        }
        if (info->token.expire < time(NULL))
        {
            ack.retCode = EC_REQUEST_EXPIRE;
            break;
        }

        if (info->sID != InvalidSessionID)
        {
            event_onLogout(info);
            SessionManager::getRef().kickSession(info->sID);
            _mapSession.erase(info->sID);
        }

        info->sID = session->getSessionID();
        session->setUserParam(UPARAM_USER_ID, info->base.uID);
        session->setUserParam(UPARAM_SESSION_STATUS, SSTATUS_LOGINED);
        session->setUserParam(UPARAM_LAST_ACTIVE_TIME, time(NULL));
        session->setUserParam(UPARAM_LOGIN_TIME, time(NULL));
        _mapSession.insert(std::make_pair(session->getSessionID(), info));

        sendMessage(session, ack);
        session->setUserParam(UPARAM_LAST_ACTIVE_TIME, time(NULL));

        event_onLogin(info);
        
        return;
    } while (0);
    
    sendMessage(session, ack);
}
开发者ID:roger912,项目名称:breeze,代码行数:55,代码来源:netMgr.cpp

示例2: msg_onHeartbeatEcho

void NetMgr::msg_onHeartbeatEcho(TcpSessionPtr session, ReadStream & rs)
{
    auto status = session->getUserParamNumber(UPARAM_SESSION_STATUS);
    if (status != SSTATUS_UNKNOW && status != SSTATUS_PLAT_LOGINING)
    {
        session->setUserParam(UPARAM_LAST_ACTIVE_TIME, time(NULL));
    }
}
开发者ID:roger912,项目名称:breeze,代码行数:8,代码来源:netMgr.cpp

示例3: msg_onSelectUserReq

void NetMgr::msg_onSelectUserReq(TcpSessionPtr session, ReadStream & rs)
{
    if (session->getUserParamNumber(UPARAM_SESSION_STATUS) != SSTATUS_PLAT_LOGINED)
    {
        LOGE("NetMgr::msg_onSelectUserReq. status error. session id=" << session->getSessionID() << ", status = " << session->getUserParamNumber(UPARAM_SESSION_STATUS));
        session->close();
        return;
    }

    auto founder = _mapAccounts.find(session->getUserParamString(UPARAM_ACCOUNT));
    if (founder == _mapAccounts.end())
    {
        LOGW("Login::msg_onSelectUserReq session have no account info. sID=" << session->getSessionID());
        return;
    }

    SelectUserReq req;
    rs >> req;

    auto base = founder->second.find(req.uID);
    if (base == founder->second.end())
    {
        LOGW("Login::msg_onSelectUserReq session have no user info. sID=" << session->getSessionID());
        return;
    }


    MD5Data data;
    data.append(base->second.account);
    data.append(base->second.nickName);
    data.append(toString(rand()));

    //模拟通知logic刷新token
    auto ptr = getUserInfo(req.uID);
    if (!ptr)
    {
        return;
    }
    ptr->token.uID = req.uID;
    ptr->token.token = data.genMD5();
    ptr->token.expire = (unsigned int)time(NULL) + 600;

    //模拟断开连接
    session->setUserParam(UPARAM_SESSION_STATUS, SSTATUS_UNKNOW);


    SelectUserAck ack;
    ack.retCode = EC_SUCCESS;
    ack.uID = req.uID;
    ack.token = data.genMD5();
    ack.ip = ServerConfig::getRef().getConfigListen(LogicServer)._wip;
    ack.port = ServerConfig::getRef().getConfigListen(LogicServer)._wport;

    sendMessage(session, ack);
}
开发者ID:roger912,项目名称:breeze,代码行数:55,代码来源:netMgr.cpp

示例4: msg_onLinkServerReq

void NetManager::msg_onLinkServerReq(TcpSessionPtr session, ProtoID pID, ReadStream & rs)
{
	LinkServerReq req;
	rs >> req;
	LOGD("enter msg_loginReq token=" << req.token << ", uID=" << req.uID);
	LinkServerAck ack;
	ack.retCode = EC_SUCCESS;

    auto inner = UserManager::getRef().getInnerUserInfo(req.uID);
    if (inner)
    {
		if (inner->token.token == req.token)
		{
			if (inner->token.tokenExpire > time(NULL))
			{
				ack.retCode = EC_SUCCESS;
				if (inner->sID != InvalidSeesionID)
				{
					UserManager::getRef().userLogout(inner);
				}

				inner->loginTime = time(NULL);
				inner->sID = session->getSessionID();

				session->setUserParam(inner->userInfo.uID);
				session->setUserLParam(SS_LOGINED);
				session->setUserRParam(time(NULL));
				WriteStream ws(ID_LinkServerAck);
				ws << ack;
				session->doSend(ws.getStream(), ws.getStreamLen());

				UserManager::getRef().userLogin(inner);
				return;
			}
			else
			{
				ack.retCode = EC_TOKEN_EXPIRE;
			}
		}
		else
		{
			ack.retCode = EC_INVALIDE_USER;
		}
		
    }
	else
	{
		ack.retCode = EC_INVALIDE_USER;
	}
    
	WriteStream ws(ID_LinkServerAck);
	ws << ack;
	session->doSend(ws.getStream(), ws.getStreamLen());
}
开发者ID:heber,项目名称:breeze,代码行数:54,代码来源:netManager.cpp

示例5: msg_onPlatAuthReq

void NetMgr::msg_onPlatAuthReq(TcpSessionPtr session, ReadStream & rs)
{
    if (session->getUserParamNumber(UPARAM_SESSION_STATUS) != SSTATUS_UNKNOW)
    {
        LOGE("NetMgr::msg_onPlatAuthReq. status error .session id=" << session->getSessionID() << ", status = " << session->getUserParamNumber(UPARAM_SESSION_STATUS));
        session->close();
        return;
    }
    PlatAuthReq req;
    rs >> req;
    session->setUserParam(UPARAM_ACCOUNT, req.account);

    session->setUserParam(UPARAM_SESSION_STATUS, SSTATUS_PLAT_LOGINING);
    //goto plat auth
    //....
    //plat auth success.
    session->setUserParam(UPARAM_SESSION_STATUS, SSTATUS_PLAT_LOGINED);

    session->setUserParam(UPARAM_SESSION_STATUS, SSTATUS_PLAT_LOADING);
    zsummer::mysql::DBQuery q(" select `uID`,`account`,`nickName`,`iconID`,`diamond`,`hisotryDiamond`,`giftDiamond`,`joinTime` from `tb_BaseInfo` where `account` = ? ");
    q << req.account;
    DBMgr::getRef().infoAsyncQuery(q.popSQL(), std::bind(&NetMgr::db_onFetchUsers, this, _1, session));
}
开发者ID:roger912,项目名称:breeze,代码行数:23,代码来源:netMgr.cpp

示例6: db_onCreateUser

void NetMgr::db_onCreateUser(DBResultPtr result, TcpSessionPtr session, const BaseInfo & info)
{
    session->setUserParam(UPARAM_SESSION_STATUS, SSTATUS_PLAT_LOGINED);
    CreateUserAck ack;
    ack.retCode = EC_SUCCESS;
    if (result->getErrorCode() != QEC_SUCCESS)
    {
        ack.retCode = EC_DB_ERROR;
        _mapAccounts[info.account].erase(info.uID);
    }
    else
    {
        //!模拟 通知logic服务器添加新的用户
        createUser(info);
        ack.users.push_back(info);
        //end
    }
    sendMessage(session, ack);
}
开发者ID:roger912,项目名称:breeze,代码行数:19,代码来源:netMgr.cpp

示例7: db_onFetchUsers

void NetMgr::db_onFetchUsers(DBResultPtr result, TcpSessionPtr session)
{
    //loading guard over.
    session->setUserParam(UPARAM_SESSION_STATUS, SSTATUS_PLAT_LOGINED);

    PlatAuthAck ack;
    ack.retCode = EC_DB_ERROR;
    if (result->getErrorCode() != QEC_SUCCESS)
    {
        LOGE("Login::db_onFetchUsers have db error. error=" << result->getLastError() << ", sql=" << result->sqlString());
    }
    else
    {
        ack.retCode = EC_SUCCESS;
        try
        {
            BaseInfo info;
            while (result->haveRow())
            {
                *result >> info.uID;
                *result >> info.account;
                *result >> info.nickName;
                *result >> info.iconID;
                *result >> info.diamond;
                *result >> info.hisotryDiamond;
                *result >> info.giftDiamond;
                *result >> info.joinTime;
                ack.users.push_back(info);
                _mapAccounts[session->getUserParamString(UPARAM_ACCOUNT)][info.uID] = info;
            }

        }
        catch (std::runtime_error e)
        {
            ack.retCode = EC_DB_ERROR;
            LOGE("Login::db_onFetchUsers catch one exception. e=" << e.what() << ", sql=" << result->sqlString());
        }
    }
    sendMessage(session, ack);
}
开发者ID:roger912,项目名称:breeze,代码行数:40,代码来源:netMgr.cpp

示例8: msg_onCreateUserReq

void NetMgr::msg_onCreateUserReq(TcpSessionPtr session, ReadStream & rs)
{
    if (session->getUserParamNumber(UPARAM_SESSION_STATUS) != SSTATUS_PLAT_LOGINED)
    {
        LOGE("NetMgr::msg_onCreateUserReq. status error. session id=" << session->getSessionID() << ", status = " << session->getUserParamNumber(UPARAM_SESSION_STATUS));
        session->close();
        return;
    }

    auto founder = _mapAccounts.find(session->getUserParamString(UPARAM_ACCOUNT));
    if (founder != _mapAccounts.end() && founder->second.size() > MAX_ACCOUNT_USERS)
    {
        LOGW("Login::msg_onCreateUserReq  too many users. sID=" << session->getSessionID());
        return;
    }

    

    CreateUserReq req;
    rs >> req;
    session->setUserParam(UPARAM_SESSION_STATUS, SSTATUS_PLAT_CREATING);
    BaseInfo info;
    info.uID = _genID.genNewObjID();
    if (info.uID >= _genID.getMaxObjID() || info.uID < _genID.getMinObjID())
    {
        LOGE("gen UserID over the max user ID. cur ID=" << info.uID);
        return;
    }
    info.account = session->getUserParamString(UPARAM_ACCOUNT);
    info.nickName = req.nickName;
    info.iconID = req.iconID;
    info.joinTime = (ui32)time(NULL);
    _mapAccounts[session->getUserParamString(UPARAM_ACCOUNT)][info.uID] = info;

    std::string sql = BaseInfo_INSERT(info);
    DBMgr::getRef().infoAsyncQuery(sql, std::bind(&NetMgr::db_onCreateUser, this, _1, session, info));
}
开发者ID:roger912,项目名称:breeze,代码行数:37,代码来源:netMgr.cpp

示例9: event_onLinked

void NetMgr::event_onLinked(TcpSessionPtr session)
{
    session->setUserParam(UPARAM_SESSION_STATUS, SSTATUS_UNKNOW);
    LOGD("NetMgr::event_onLinked. SessionID=" << session->getSessionID() << ", remoteIP=" << session->getRemoteIP() << ", remotePort=" << session->getRemotePort());
}
开发者ID:roger912,项目名称:breeze,代码行数:5,代码来源:netMgr.cpp


注:本文中的TcpSessionPtr::setUserParam方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。