• [手游新项目历程]第10天-角色登陆流程


    管理容器
    //References :
    typedef std::map<std::string, int> clientMapT;
    clientMapT clientMap;	
    LogicalConnection* ClientFactoryImpl::AddLogicalConnection( LogicalConnection* pClient )
    {
        std::string key(pClient->getKey());
        ScopedLock csLock(cs);
        //
        LogicalConnection* pRet = pClient;
    
        clientMapT::iterator it = clientMap.find(key);
        if(it!=clientMap.end())
        {
            pRet =  it->second;
        }
        else
        {
            clientMap[key] = pClient;
            nClientsCount++;
        }
    
        pRet->IncrementUsage();
        return pRet;
    }
    
    LogicalConnection* ClientFactoryImpl::FindLogicalConnection( const char* _key )
    {
        std::string key(_key);
        //
        ScopedLock csLock(cs);
    
        clientMapT::iterator it = clientMap.find(key);
        if(it==clientMap.end())
            return NULL;
    
        LogicalConnection* pClient = it->second;
    
        pClient->IncrementUsage();
        return pClient;
    }
    
    	LogicalConnection* pRecipient = FindClient(request.GetArg1().c_str());
    	if (pRecipient)
    	{
    		WebsocketDataMessage response(Routedcommunication);
    		response.SetArguments(request.GetEncodedData());
    		pRecipient->PushPacket(&response);
    		ReturnClient(pRecipient);
    	}
    	
    	std::map<Tint32, LogicalConnection*>	m_PlayerConnectionIdMap;	//错误的方式
    	如果自己存一个连接的指针取出来发送回报错,
    	
    	std::map<Tint32, CLIENT_KEY>			m_PlayerConnectionIdMap;	//正确的方式	
    	LogicalConnection* pRecipient = FindClient(CLIENT_KEY);
    	只能存一个key的容器,通过key去自带的容器取连接来发送包


    角色登陆流程
    
    GAME_MSG_LOGIN_REQ					=		1001,					//登陆
    
    client发送登陆包 -> webServer 产生链接ConIdid写进包->gate 
    
    Tint32 NetGate::OnRecvHandle( t_ConnID ConnectionId,tagNetMsg *pMsg ) 消息派发
    
    Tint32 NetClient::OnAcceptHandle( t_ConnID ConnectionId )
    
    void GatePlayerMgr::AddPlayerConnIdMap( t_ConnID nConnId, GatePlayer* pGatePlayer )
    
    TBool NetDBCache::PlayerRetLogin( t_ConnID ConnectionId,tagNetMsg &Msg )
    
    void NetWorld::SendToWholeWorld(Tint32 msgID,char *buff, unsigned int buffLen , ePlayerFilter eFilter, Tint64 nFilterValue)
    {
    	Debug_Assert(buffLen < enMaxMsgDataBufferSize, );
    	tagNetMsg msgToSend;
    	memcpy(msgToSend.buff, buff, buffLen);
    	msgToSend.BuffLen = buffLen;
    	msgToSend.MsgID = msgID;
    	SendToWholeWorld(msgToSend, eFilter, nFilterValue);
    }
    
    void NetWorld::SendToWholeWorld( tagNetMsg& msg,ePlayerFilter eFilter /*= ePlayerFilter_All*/, Tint64 nFilterValue /*= -1*/ )
    {
    	tagNetMsg MsgToSend;
    	Stream stream(MsgToSend.buff, sizeof(MsgToSend.buff));
    	stream.Write(eFilter);
    	stream.Write(nFilterValue);
    	stream.Write(msg);
    	MsgToSend.MsgID = GAME_SERVER_MSG_BROCAST_WHOLE_WORLD;
    	MsgToSend.BuffLen = stream.GetPos();
    	SendSingle(MsgToSend.MsgID, MsgToSend.BuffLen, MsgToSend);
    }
    
    struct MsgLoginReq
    {
    	void Serialize(Stream& stream) 
    	{
    		unsigned short nLen = (unsigned short)m_Account.GetRealStrLen();
    		stream.Write(nLen);
    		stream.WriteBuffer(m_Account.GetName(),nLen);
    
    		stream.Write(m_SerVerId);
    
    		nLen = (unsigned short)m_Platform.GetRealStrLen();
     		stream.Write(nLen);
     		stream.WriteBuffer(m_Platform.GetName(),nLen);
    	}
    
    	bool DeSerialize(Stream& stream)
    	{
    		unsigned short nLen = 0;
    
    		//玩家账号
    		if (!stream.Read(nLen))
    			return false;
    		if(nLen >= MAX_ACCOUNT_LEN)
    			return false;
    		if (!stream.ReadBuffer(m_Account.GetName(), nLen))
    			return false;
    		//服务器id
    		if (!stream.Read(m_SerVerId))
    			return false;
    		//平台标识
     		if (!stream.Read(nLen))
     			return false;
     		if(nLen >= MAX_PLATFORM_LEN)
     			return false;
     		if (!stream.ReadBuffer(m_Platform.GetName(), nLen))
     			return false;
    		return true;
    	}
    
    	CommonAccountName m_Account;
    	CommonString<255> m_Token;
    	Tint32 m_SerVerId;
    	CommonPlatform m_Platform;
    };
    
    TBool NetGate::PlayerLoginResService
    DB_MSG_ACCOUNT_LOGIN,								//登录
    DB_MSG_ACCOUNT_LOGIN_RET,							//登录返回
    GAME_MSG_LOGIN_RES
    void NetGate::SendToClientWithClientConnId
    GAME_SERVER_MSG_DBCACHE_TO_GATE ,					//从DBCACHE发给GATE
    TBool NetDBCache::PlayerRetLogin( t_ConnID ConnectionId,tagNetMsg &Msg )
    
  • 相关阅读:
    git 查看当前所在分支
    【XSS技巧拓展】————19、利用反射型XSS二次注入绕过CSP form-action限制
    【XSS技巧拓展】————18、一个URL跳转引发的一系列“惨案”
    【XSS技巧拓展】————17、XSS without HTML: Client-Side Template Injection with AngularJS
    【XSS技巧拓展】————16、Electron hack跨平台 XSS
    【XSS技巧拓展】————15、Chrome 是怎么过滤反射型 XSS 的呢?
    【XSS技巧拓展】————14、XSS攻击另类玩法
    【XSS技巧拓展】————13、CRLF Injection and Bypass Tencent WAF
    【XSS技巧拓展】————12、The 7 Main XSS Cases Everyone Should Know
    【XSS技巧拓展】————11、Advanced JavaScript Injections
  • 原文地址:https://www.cnblogs.com/byfei/p/14104300.html
Copyright © 2020-2023  润新知