示例#1
0
BOOL ClientEngine::ProcessData()
{
	if(m_nDataLen < sizeof(TransferHeader))
	{
		return FALSE;
	}

	TransferHeader *pHeader = (TransferHeader *)m_DataBuffer;
	if(pHeader->dwSize <= m_nDataLen)
	{
		memcpy(m_ReadBuffer.GetData(), m_DataBuffer, pHeader->dwSize);

		m_ReadBuffer.SetDataLenth(pHeader->dwSize);

		m_nDataLen -= pHeader->dwSize;

		if(m_nDataLen > 0)
		{
			memmove(m_DataBuffer, m_DataBuffer+pHeader->dwSize, m_nDataLen);
		}

		CBufferHelper BufferReader(FALSE, &m_ReadBuffer);
		if(!BufferReader.BeginRead())
		{
			return FALSE;
		}

		CommandHeader *pCommandHeader = BufferReader.GetCommandHeader();
		if(pCommandHeader == NULL)
		{
			return FALSE;
		}

		OnCommandHandle(pCommandHeader->wCommandID, 0, &BufferReader);
	}

	return TRUE;
}
示例#2
0
 inline BufferReader SubReader(uint64_t pos, uint64_t size) const
 {
   return BufferReader(*this, pos, size);
 }
示例#3
0
BOOL ServiceBase::OnDataHandle(IDataBuffer *pDataBuffer , CConnection *pConnection)
{
    CBufferHelper BufferReader(FALSE, pDataBuffer);
    if(!BufferReader.BeginRead())
    {
        ASSERT_FAIELD;
        return FALSE;
    }

    CommandHeader *pCommandHeader = BufferReader.GetCommandHeader();
    if(pCommandHeader == NULL)
    {
        ASSERT_FAIELD;
        return FALSE;
    }

    if(pCommandHeader->wCommandID == CMD_CONNECT_NOTIFY)
    {
        StConnectNotify ConnectNotify;

        BufferReader.Read(ConnectNotify);

        if(ConnectNotify.btConType == TYPE_SVR_CENTER)
        {
            CLog::GetInstancePtr()->AddLog("收到身份验证包:来自-[中心]-服务器【%lld】, 服务器类型:%d",  ConnectNotify.u64ConnID, ConnectNotify.btConType);
        }
        else if(ConnectNotify.btConType == TYPE_SVR_GAME)
        {
            CLog::GetInstancePtr()->AddLog("收到身份验证包:来自-[游戏]-服务器【%lld】, 服务器类型:%d",  ConnectNotify.u64ConnID, ConnectNotify.btConType);
        }
        else if(ConnectNotify.btConType == TYPE_SVR_PROXY)
        {
            CLog::GetInstancePtr()->AddLog("收到身份验证包:来自-[代理]-服务器【%lld】, 服务器类型:%d",  ConnectNotify.u64ConnID, ConnectNotify.btConType);
        }
        else if(ConnectNotify.btConType == TYPE_SVR_LOGIN)
        {
            CLog::GetInstancePtr()->AddLog("收到身份验证包:来自-[登录]-服务器【%lld】, 服务器类型:%d",  ConnectNotify.u64ConnID, ConnectNotify.btConType);
        }
        else if(ConnectNotify.btConType == TYPE_SVR_DATABASE)
        {
            CLog::GetInstancePtr()->AddLog("收到身份验证包:来自-[数据库]-服务器【%lld】, 服务器类型:%d",  ConnectNotify.u64ConnID, ConnectNotify.btConType);
        }
        else if(ConnectNotify.btConType == TYPE_CLT_PLAYER)
        {
            CLog::GetInstancePtr()->AddLog("收到身份验证包:来自-[客户端]-【%lld】, 服务器类型:%d",  ConnectNotify.u64ConnID, ConnectNotify.btConType);
        }
        else if(ConnectNotify.btConType == TYPE_SVR_STATISTICS)
        {
            CLog::GetInstancePtr()->AddLog("收到身份验证包:来自-[统计]-服务器【%lld】, 服务器类型:%d",  ConnectNotify.u64ConnID, ConnectNotify.btConType);
        }
        else if(ConnectNotify.btConType == TYPE_SVR_WORLDSVR)
        {
            CLog::GetInstancePtr()->AddLog("收到身份验证包:来自-[世界]-服务器【%lld】, 服务器类型:%d",  ConnectNotify.u64ConnID, ConnectNotify.btConType);
        }

        if(pConnection->GetConnectionID() != 0)
        {
            ASSERT_FAIELD;
            pConnection->Close(TRUE);
            CConnectionMgr::GetInstancePtr()->DeleteConnection(pConnection);

            return FALSE;
        }

        pConnection->SetConnectionType(ConnectNotify.btConType);

        CConnectionMgr::GetInstancePtr()->SetConnectionID(pConnection, ConnectNotify.u64ConnID);

        if(!BufferReader.BeginRead())
        {
            ASSERT_FAIELD;
            pConnection->Close(TRUE);
            CConnectionMgr::GetInstancePtr()->DeleteConnection(pConnection);
            return FALSE;
        }
    }

    if(pConnection->GetConnectionID() == 0)
    {
        ASSERT_FAIELD;
        pConnection->Close(FALSE);
        CConnectionMgr::GetInstancePtr()->DeleteConnection(pConnection);
        return FALSE;
    }

    OnCommandHandle(pCommandHeader->wCommandID, pConnection->GetConnectionID(), &BufferReader);

    return TRUE;
}