Example #1
0
std::string Settings::GetDefaultRegistryPath()
{
    std::string s("Software\\");
    std::wstring vendor = Settings::GetCompanyName();
    if ( !vendor.empty() )
        s += WideToAnsi(vendor) + "\\";
    s += WideToAnsi(Settings::GetAppName());
    s += "\\WinSparkle";

    return s;
}
std::wstring ApplicationPathParer::GetApplicationPathOrigin( const std::wstring& appName )
{
	std::map<std::string, boost::any> users
		= boost::any_cast<std::map<std::string, boost::any> >(m_dict["User"]);

	if ( users.end() == users.find(WideToAnsi(appName)) )
		return L"";

	std::map<std::string, boost::any> appDict
		= boost::any_cast<std::map<std::string, boost::any> >(users[WideToAnsi(appName)]);

	std::wstring result = AnsiToWide( boost::any_cast<std::string>(appDict["Container"]) );

	return result;
}
Example #3
0
void UpdateChecker::Run()
{
    // no initialization to do, so signal readiness immediately
    SignalReady();

    try
    {
#ifdef _DEBUG
		const std::string url = "https://s3.amazonaws.com/qvivo_releases/v2/win32/testing/appcast.xml";
#else
        const std::string url = Settings::GetAppcastURL();
#endif
        if ( url.empty() )
            throw std::runtime_error("Appcast URL not specified.");

        StringDownloadSink appcast_xml;
        DownloadFile(url, &appcast_xml, GetAppcastDownloadFlags());

        Appcast appcast;
        appcast.Load(appcast_xml.data);

        Settings::WriteConfigValue("LastCheckTime", time(NULL));

        const std::string currentVersion =
                WideToAnsi(Settings::GetAppVersion());

		std::string currentBuild = currentVersion.substr(currentVersion.find(":") + 1);
		std::string appcastBuild = appcast.Build.substr(appcast.Build.find(":") + 1);

		std::string currentProductionVersion = currentVersion.substr(0, currentVersion.find(","));
		std::string appcastProductionVersion = appcast.Build.substr(0, appcast.Build.find(","));

        // Check if our version is out of date.
        if ( CompareVersions(currentProductionVersion, appcastProductionVersion) >= 0 )
        {
            // The same or newer version is already installed.

			if(m_showUI)
				UI::NotifyNoUpdates();
            return;
        }

        // Check if the user opted to ignore this particular version.
        std::string toSkip;
        if ( Settings::ReadConfigValue("SkipThisVersion", toSkip) &&
             toSkip == appcast.Version )
        {
			if(m_showUI)
				UI::NotifyNoUpdates();
            return;
        }

        UI::NotifyUpdateAvailable(appcast);
    }
    catch ( ... )
    {
        UI::NotifyUpdateError();
        throw;
    }
}
Example #4
0
void UpdateChecker::Run()
{
    // no initialization to do, so signal readiness immediately
    SignalReady();

    try
    {
        const std::string url = Settings::GetAppcastURL();
        if ( url.empty() )
            throw std::runtime_error("Appcast URL not specified.");
        CheckForInsecureURL(url, "appcast feed");

        StringDownloadSink appcast_xml;
        DownloadFile(url, &appcast_xml, GetAppcastDownloadFlags());

        Appcast appcast = Appcast::Load(appcast_xml.data);
        if (!appcast.ReleaseNotesURL.empty())
            CheckForInsecureURL(appcast.ReleaseNotesURL, "release notes");
        if (!appcast.DownloadURL.empty())
            CheckForInsecureURL(appcast.DownloadURL, "update file");

        Settings::WriteConfigValue("LastCheckTime", time(NULL));

        const std::string currentVersion =
                WideToAnsi(Settings::GetAppBuildVersion());

        // Check if our version is out of date.
        if ( !appcast.IsValid() || CompareVersions(currentVersion, appcast.Version) >= 0 )
        {
            // The same or newer version is already installed.
            UI::NotifyNoUpdates(ShouldAutomaticallyInstall());
            return;
        }

        // Check if the user opted to ignore this particular version.
        if ( ShouldSkipUpdate(appcast) )
        {
            UI::NotifyNoUpdates(ShouldAutomaticallyInstall());
            return;
        }

        UI::NotifyUpdateAvailable(appcast, ShouldAutomaticallyInstall());
    }
    catch ( ... )
    {
        UI::NotifyUpdateError();
        throw;
    }
}
std::wstring ApplicationPathParer::GetApplicationPath( const std::wstring& appName )
{
	std::map<std::string, boost::any> users
		= boost::any_cast<std::map<std::string, boost::any> >(m_dict["User"]);

	if ( users.end() == users.find(WideToAnsi(appName)) )
		return L"";

	std::map<std::string, boost::any> appDict
		= boost::any_cast<std::map<std::string, boost::any> >(users[WideToAnsi(appName)]);

	std::wstring result = AnsiToWide( boost::any_cast<std::string>(appDict["Container"]) );
	
	std::wstring::size_type pos = result.find(L'/');

	while ( pos != std::wstring::npos )
	{
		result = result.replace(pos, 1, L"\\");
		++pos;
		pos = result.find(L'/', pos);
	}

	return result;
}
void CSpriteFontTextRenderer::DrawText(DirectX::SpriteBatch& spriteBatch, int x, int y, LPCWSTR text, DirectX::XMVECTOR color)
{
    std::wstring ws = text;
    std::string s = WideToAnsi(ws);
    float fxPos = (float)x;
    for (int i = 0; i < s.length(); i++)
    {
        CHAR c = s[i];
        RECT r = _glyphtionary[c];
        r.right = r.left + r.right;
        r.bottom = r.top + r.bottom;
        spriteBatch.Draw(_sprite, DirectX::XMFLOAT2(fxPos, (float)y), &r, color, 0, DirectX::XMFLOAT2(0, 0), 1.0);
        fxPos += r.right - r.left;
    }
}
int CSpriteFontTextRenderer::MeasureText(LPCWSTR text)
{
    std::wstring ws = text;
    std::string s = WideToAnsi(ws);
    int width = 0;
    for (int i = 0; i < s.length(); i++)
    {
        CHAR c = s[i];
        RECT r = _glyphtionary[c];
        r.right = r.left + r.right;
        r.bottom = r.top + r.bottom;
        width += r.right - r.left;
    }

    return width;
}
Example #8
0
void UpdateChecker::Run()
{
    // no initialization to do, so signal readiness immediately
    SignalReady();

    try
    {
        const std::string url = Settings::GetAppcastURL();
        if ( url.empty() )
            throw std::runtime_error("Appcast URL not specified.");

        StringDownloadSink appcast_xml;
        DownloadFile(url, &appcast_xml, GetAppcastDownloadFlags());

        Appcast appcast;
        appcast.Load(appcast_xml.data);

        Settings::WriteConfigValue("LastCheckTime", time(NULL));

        const std::string currentVersion =
                WideToAnsi(Settings::GetAppVersion());

        // Check if our version is out of date.
        if ( CompareVersions(currentVersion, appcast.Version) >= 0 )
        {
            // The same or newer version is already installed.
            UI::NotifyNoUpdates();
            return;
        }

        // Check if the user opted to ignore this particular version.
        std::string toSkip;
        if ( Settings::ReadConfigValue("SkipThisVersion", toSkip) &&
             toSkip == appcast.Version )
        {
            UI::NotifyNoUpdates();
            return;
        }

        UI::NotifyUpdateAvailable(appcast);
    }
    catch ( ... )
    {
        UI::NotifyUpdateError();
        throw;
    }
}
Example #9
0
std::wstring IOSWeixinParser::GetTableNameFromUserName(const std::wstring& userName)
{
	std::string md5Src = WideToAnsi(userName);
	unsigned char hash[16] = {0};
	MD5_CTX c = {0};
	MD5_Init(&c);
	MD5_Update(&c, md5Src.c_str(), strlen(md5Src.c_str()));
	MD5_Final(hash, &c);

	char hex[1024] = {0};
	for ( int i = 0; i < 16; ++i )
		sprintf(hex+2*i, "%.2x", hash[i]);

	char table[1024] = {0};
	sprintf(table, "Chat_%s", hex);

	return AnsiToWide(table);
}
Example #10
0
void UserActionDlg::onTrUserActionItemClicked(QTreeWidgetItem* item, int column)
{

	std::wstring text = item->text(0).toStdWString();

	std::map<std::wstring, int> indexMap;

	//indexMap[L"用户文件行为"] = 0;
	indexMap[L"全部操作"] = 0;
	indexMap[L"新建文件"] = 0;
	indexMap[L"删除文件"] = 0;
	indexMap[L"拷贝文件"] = 0;
	indexMap[L"移动文件"] = 0;
	indexMap[L"新建目录"] = 0;
	indexMap[L"删除目录"] = 0;
	//indexMap[L"用户敏感行为"] = 1;
	indexMap[L"键盘记录"] = 1;
	indexMap[L"密码窗口感知"] = 2;
	indexMap[L"剪切板监控"] = 3;
	//indexMap[L"进程行为"] = 4;
	indexMap[L"文件访问"] = 4;
	indexMap[L"执行轨迹"] = 5;
	//indexMap[L"通讯行为"] = 6;
	indexMap[L"短信记录"] = 6;
	indexMap[L"通话记录"] = 7;
	indexMap[L"通讯录"] = 8;

	strcpy(opType, WideToAnsi(text).c_str());

	if ( indexMap.end() != indexMap.find(text) )
	{
		int index = indexMap[text];
		ui.stkUserAction->setCurrentIndex(index);
		ui.lbUserAction->setText(item->parent()->text(0) + " - " + item->text(0));

		if ( index == 0 )
			RefreshUserFOIData();

		if ( index == 1 && !m_queryKeyboardInfoFinished
			&& NULL == m_waitKeyboardInfoDlg )
		{
			m_waitKeyboardInfoDlg = new WaitDlg(ui.tbKeyboardRecord);
			m_waitKeyboardInfoDlg->show();
			RefreshIMEData();
		}

		if ( index == 2 && 0 == ui.tbPasswordRecord->rowCount() )
			RefreshPWIData();

		if ( index == 3 && 0 == ui.tbClipboardData->rowCount() )
			RefreshCBDData();

		if ( index == 4 && 0 == ui.tbFileAccessRecord->rowCount() )
			RefreshFOIData();

		if ( index == 5 && 0 == ui.tbCommandRecord->rowCount() )
			RefreshPEIData();

		if ( index == 6 && 0 == ui.tbMessageInfo->rowCount() )
			RefreshSMSData();

		if ( index == 7 && 0 == ui.tbCallInfo->rowCount() )
			RefreshCALData();

		if ( index == 8 && 0 == ui.tbAddressBook->rowCount() )
			RefreshCONTACTData();
	}
}
HRESULT CLucid3DRenderer::AddMesh(GraphicsDevicePtr graphicsDevice, std::wstring& contentPath, IModelContentPtr pModelContent, MeshInfo meshInfo)
{
    HRESULT hr = S_OK;
    CStringW diffuseTextureName;
    Lucid3DRenderBufferDesc renderDesc;
    ModelContentBufferDescription vertexBuffer;
    ModelContentBufferDescription indexBuffer;
    ModelContentMaterialDescription material;
    InputStreamPtr spStream;
    TexturePtr tex;
    std::string contentPathA = WideToAnsi(contentPath);

    std::string diffuseTexturePath;
    std::string specularTexturePath;
    std::string normalTexturePath;
    
    // Get vertex and index buffer descriptions for target mesh
    hr = pModelContent->GetVertexBuffer(meshInfo.vertexBufferId, vertexBuffer);
    GOTO_EXIT_IF_FAILED_MESSAGE(hr, "Failed to get vertex buffer");

    hr = pModelContent->GetIndexBuffer(meshInfo.indexBufferId, indexBuffer);
    GOTO_EXIT_IF_FAILED_MESSAGE(hr, "Failed to get index buffer");

    hr = pModelContent->GetMaterial(meshInfo.materialId, material);
    GOTO_EXIT_IF_FAILED_MESSAGE(hr, "Failed to get material");

    VertexElement elements[] =
    {
        VertexElement(0, VertexChannelType::Float3, VertexChannelSemantic::Position, false),
        VertexElement(0, VertexChannelType::Float3, VertexChannelSemantic::Normal, false),
        VertexElement(0, VertexChannelType::Float3, VertexChannelSemantic::Tangent, false),
        VertexElement(0, VertexChannelType::Float3, VertexChannelSemantic::BiTangent, false),
        VertexElement(0, VertexChannelType::Float2, VertexChannelSemantic::TexCoord0, false),
    };

    hr = graphicsDevice->CreateVertexBuffer((uint)vertexBuffer.stride, vertexBuffer.numElements, elements, _countof(elements),  ResourceAccess::Read, ResourceAccess::Write, vertexBuffer.pBuffer.get()->ptr, &renderDesc.m_vertexBuffer);
    GOTO_EXIT_IF_FAILED_MESSAGE(hr, "Failed to create vertex buffer");

    hr = graphicsDevice->CreateIndexBuffer((uint)indexBuffer.stride, (uint)indexBuffer.numElements, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST, ResourceAccess::Read, ResourceAccess::Write, indexBuffer.pBuffer.get()->ptr, &renderDesc.m_indexBuffer);
    GOTO_EXIT_IF_FAILED_MESSAGE(hr, "Failed to create index buffer");

    hr = Renderer::CreateMaterial(std::to_string((uint64)meshInfo.materialId).c_str(), &renderDesc.m_material);
    GOTO_EXIT_IF_FAILED_MESSAGE(hr, "Failed to create the material");

    diffuseTexturePath = (contentPathA + material.info.diffuse + ".tc").c_str();

    hr = IO::ReadExistingFile(diffuseTexturePath.c_str(), &spStream);
    if (FAILED(hr))
    {
        DEBUG_PRINT("Failed to load diffuse texture file '%s', hr = 0x%lx",diffuseTexturePath.c_str(), hr);
        goto Exit;
    }

    hr = Graphics::CreateTextureFromStream(graphicsDevice, spStream, false, ResourceAccess::Read, ResourceAccess::None, &tex);
    if (FAILED(hr))
    {
        DEBUG_PRINT("Failed to create texture from diffuse texture file '%s', hr = 0x%lx",diffuseTexturePath.c_str(), hr);
        goto Exit;
    }
    
    renderDesc.m_material->SetTexture(TextureUsage::Diffuse, tex);

    if (material.info.normal.size() != 0)
    {
        normalTexturePath = (contentPathA + material.info.normal + ".tc").c_str();

        hr = IO::ReadExistingFile(normalTexturePath.c_str(), &spStream);
        if (FAILED(hr))
        {
            DEBUG_PRINT("Failed to load normal texture file '%s', hr = 0x%lx",normalTexturePath.c_str(), hr);
            goto Exit;
        }

        hr = Graphics::CreateTextureFromStream(graphicsDevice, spStream, false, ResourceAccess::Read, ResourceAccess::None, &tex);
        if (FAILED(hr))
        {
            DEBUG_PRINT("Failed to create texture from normal texture file '%s', hr = 0x%lx",normalTexturePath.c_str(), hr);
            goto Exit;
        }
    
        renderDesc.m_material->SetTexture(TextureUsage::Normal, tex);
    }

    renderDesc.m_material->SetSpecularPower(120.0f);

    // Add the buffers to the render collection
    m_buffers.push_back(renderDesc);

Exit:

    return hr;
}
HRESULT CLucid3DRenderer::AddContent(GraphicsDevicePtr graphicsDevice, std::wstring& contentPath, ISpriteFontContentPtr pSpriteFontContent)
{
    Clear();

    HRESULT hr = S_OK;
    std::string spriteFontName;
    std::wstring spriteFontNameW;
    Lucid3DRenderBufferDesc renderDesc;
    InputStreamPtr spStream;
    TexturePtr tex;

    BYTE* pData = nullptr;
    DWORD cbData = 0;

    pSpriteFontContent->GetSpriteFontName(spriteFontNameW);
    spriteFontName = WideToAnsi(spriteFontNameW);

    XMProjSpaceVertex vertices[] = 
    {
        { XMFLOAT2(-1, 1), XMFLOAT2(0, 0) },
        { XMFLOAT2(1, 1), XMFLOAT2(1, 0) },
        { XMFLOAT2(1, -1), XMFLOAT2(1, 1) },
        { XMFLOAT2(-1, -1), XMFLOAT2(0, 1) },
    };

    uint32 indices[] = { 0, 1, 2, 0, 2, 3 };

    VertexElement layout[] =
    {
        VertexElement(0, VertexChannelType::Float2, VertexChannelSemantic::Position, false),
        VertexElement(0, VertexChannelType::Float2, VertexChannelSemantic::TexCoord0, false),
    };

    hr = graphicsDevice->CreateVertexBuffer(sizeof(XMProjSpaceVertex), _countof(vertices), layout, _countof(layout), ResourceAccess::Read, ResourceAccess::None, vertices, &renderDesc.m_vertexBuffer);
    GOTO_EXIT_IF_FAILED_MESSAGE(hr, "Failed to create vertex buffer");

    hr = graphicsDevice->CreateIndexBuffer(sizeof(indices[0]), _countof(indices), D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST, ResourceAccess::Read, ResourceAccess::None, indices, &renderDesc.m_indexBuffer);
    GOTO_EXIT_IF_FAILED_MESSAGE(hr, "Failed to create index buffer");

    hr = Renderer::CreateMaterial(spriteFontName.c_str(), &renderDesc.m_material);
    GOTO_EXIT_IF_FAILED_MESSAGE(hr, "Failed to create the material");

    // Get a stream to the DDS data stored in the spritefont content
    hr = pSpriteFontContent->GetTextureData(&pData, &cbData);
    GOTO_EXIT_IF_FAILED_MESSAGE(hr, "Failed to get texture data from spritefont content");

    hr = IO::CreateInputStreamOnBuffer(pData, cbData, &spStream);
    GOTO_EXIT_IF_FAILED_MESSAGE(hr, "Failed to get create lucid memory stream for texture data from spritefont content");

    hr = Graphics::CreateTextureFromStream(graphicsDevice, spStream, false, ResourceAccess::Read, ResourceAccess::None, &tex);
    if (FAILED(hr))
    {
        DEBUG_PRINT("Failed to create texture from spritefont texture data, hr = 0x%lx", hr);
        goto Exit;
    }

    renderDesc.m_material->SetTexture(TextureUsage::Diffuse, tex);

    // Add the buffers to the render collection
    m_buffers.push_back(renderDesc);

Exit:

    SAFE_DELETE_ARRAY(pData);

    return hr;
}
HRESULT CLucid3DRenderer::AddContent(GraphicsDevicePtr graphicsDevice, std::wstring& contentPath, ITextureContentPtr pTextureContent)
{
    Clear();

    HRESULT hr = S_OK;
    std::string textureName;
    std::wstring textureNameW;
    Lucid3DRenderBufferDesc renderDesc;
    InputStreamPtr spStream;
    TexturePtr tex;
    WCHAR szTempPath[MAX_PATH] = {0};
    WCHAR szTempFile[MAX_PATH] = {0};

    pTextureContent->GetTextureName(textureNameW);
    textureName = WideToAnsi(textureNameW);

    XMProjSpaceVertex vertices[] = 
    {
        { XMFLOAT2(-1, 1), XMFLOAT2(0, 0) },
        { XMFLOAT2(1, 1), XMFLOAT2(1, 0) },
        { XMFLOAT2(1, -1), XMFLOAT2(1, 1) },
        { XMFLOAT2(-1, -1), XMFLOAT2(0, 1) },
    };

    uint32 indices[] = { 0, 1, 2, 0, 2, 3 };

    VertexElement layout[] =
    {
        VertexElement(0, VertexChannelType::Float2, VertexChannelSemantic::Position, false),
        VertexElement(0, VertexChannelType::Float2, VertexChannelSemantic::TexCoord0, false),
    };

    hr = graphicsDevice->CreateVertexBuffer(sizeof(XMProjSpaceVertex), _countof(vertices), layout, _countof(layout), ResourceAccess::Read, ResourceAccess::None, vertices, &renderDesc.m_vertexBuffer);
    GOTO_EXIT_IF_FAILED_MESSAGE(hr, "Failed to create vertex buffer");

    hr = graphicsDevice->CreateIndexBuffer(sizeof(indices[0]), _countof(indices), D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST, ResourceAccess::Read, ResourceAccess::None, indices, &renderDesc.m_indexBuffer);
    GOTO_EXIT_IF_FAILED_MESSAGE(hr, "Failed to create index buffer");

    hr = Renderer::CreateMaterial(textureName.c_str(), &renderDesc.m_material);
    GOTO_EXIT_IF_FAILED_MESSAGE(hr, "Failed to create the material");

    // HACK: HACK: Coop, I'm not familiar enough with this to do the 'right' way of loading the .tc
    // so I'm hacking it up good :) you can fix this later if you want
    GetTempPath(ARRAYSIZE(szTempPath), szTempPath);
    GetTempFileName(szTempPath, L"", 0, szTempFile);
    pTextureContent->SaveToFile(szTempFile);

    hr = IO::ReadExistingFile(WideToAnsi(std::wstring(szTempFile)).c_str(), &spStream);
    if (FAILED(hr))
    {
        DEBUG_PRINT("Failed to load diffuse texture file '%s', hr = 0x%lx",szTempFile, hr);
        goto Exit;
    }

    hr = Graphics::CreateTextureFromStream(graphicsDevice, spStream, false, ResourceAccess::Read, ResourceAccess::None, &tex);
    if (FAILED(hr))
    {
        DEBUG_PRINT("Failed to create texture from diffuse texture file '%s', hr = 0x%lx", szTempFile, hr);
        goto Exit;
    }

    renderDesc.m_material->SetTexture(TextureUsage::Diffuse, tex);

    // Add the buffers to the render collection
    m_buffers.push_back(renderDesc);

Exit:

    return hr;
}
Example #14
0
//======================================================================================
// MessageHandler()
//
// Handles messages from DirectPlay.
//======================================================================================
HRESULT CDarkPeer::MessageHandler(void* pContext, DWORD messageType, void* pMessage)
{
	switch (messageType)
	{
	case DPN_MSGID_CREATE_PLAYER:
		{
			HandleCreatePlayerMsg((DPNMSG_CREATE_PLAYER*)pMessage);
			break;
		}

      case DPN_MSGID_DESTROY_PLAYER:
		{
			// Translate DPlay8's destroy player message to DPlay4
			PDPNMSG_DESTROY_PLAYER pDestroyPlayer = (PDPNMSG_DESTROY_PLAYER) pMessage;
			DPNID dpnidPlayer = pDestroyPlayer->dpnidPlayer;
			DPMSG_DESTROYPLAYERORGROUP* pDP4DestroyPlayer = new DPMSG_DESTROYPLAYERORGROUP;

			if (dpnidPlayer != m_dpnidLocal && g_pNetMan)
			{
#if (GAME == GAME_THIEF)
#if 1
				DPN_PLAYER_INFO* pPeerInfo = GetPeerInfo(pDestroyPlayer->dpnidPlayer);
				if (pPeerInfo)
				{
					char playerName[kMaxPlayerName];
					WideToAnsi(playerName, pPeerInfo->pwszName, sizeof(playerName));
					const char* str = "%s has left the game.";
					MessageMgr::Get()->AddLineFormat(true, str, playerName);
					ConPrintF(str, playerName);

					SAFE_DELETE_ARRAY(pPeerInfo);
				}
#else
				const char* playerName = Players.NameFromDPNID(pDestroyPlayer->dpnidPlayer);
				const char* msg = "%s has left the game.";
				MessageMgr::Get()->AddLineFormat(true, msg, playerName);
				ConPrintF(msg, playerName);
#endif
#endif
				ZeroMemory(pDP4DestroyPlayer, sizeof(DPMSG_DESTROYPLAYERORGROUP));
				pDP4DestroyPlayer->lpLocalData = m_DP4PlayerData[dpnidPlayer];
				pDP4DestroyPlayer->dpId = dpnidPlayer;
				pDP4DestroyPlayer->dwType = DPSYS_DESTROYPLAYERORGROUP;
				pDP4DestroyPlayer->dwPlayerType = DPPLAYERTYPE_PLAYER;

				// send Thief the destroy player notification in the form it expects from DPlay 4
				NetMessage* pMsg = new NetMessage;
				pMsg->m_pMsgData = (BYTE*)pDP4DestroyPlayer;
				pMsg->m_size = sizeof(DPMSG_DESTROYPLAYERORGROUP);
				pMsg->m_dpnidSender = DPID_SYSMSG;

				m_DarkQueue.Push(pMsg);
				// find the player's index and destroy the player data
			}
			break;
		}

		case DPN_MSGID_INDICATE_CONNECT:
			{
				if (g_Net == STATE_Host)
				{
#ifndef _RELEASE
					if (Client.MissionStarted() && !Cfg.GetBool("AllowJoinsInProgress"))
#else
					if (Client.MissionStarted())
#endif
						return DPNERR_HOSTREJECTEDCONNECTION;
				}
				break;
			}

		case DPN_MSGID_CONNECT_COMPLETE:
			{
				PDPNMSG_CONNECT_COMPLETE pConnComplete = (PDPNMSG_CONNECT_COMPLETE)pMessage;

				if (pConnComplete->hResultCode == DPN_OK)
				{
#if (GAME == GAME_THIEF || GAME == GAME_DROMED)
					m_dpnidLocal = (pConnComplete->dpnidLocal);

					ConPrintF("Connected to session.");
					_SFX_Play_Raw(1, 0, "pickloot.wav");
#endif

					SetEvent(m_ConnectedEvent);
				}
				break;
			}

		case DPN_MSGID_ENUM_HOSTS_RESPONSE:
			{
				m_csEnumResponse.Lock();

				DPNMSG_ENUM_HOSTS_RESPONSE* pResponse = (DPNMSG_ENUM_HOSTS_RESPONSE*)pMessage;

				OnEnumerationResponse(pResponse);

				m_csEnumResponse.Unlock();
				break;
			}

      case DPN_MSGID_RECEIVE:
			{
				PDPNMSG_RECEIVE pRecvData = (PDPNMSG_RECEIVE)pMessage;
				Packet* packet = (Packet*)pRecvData->pReceiveData;

				csReceive.Lock();

				// this may not be a good idea... some original packets are very close to these numbers
				if (packet->type > NewPacketStart && packet->type < NewPacketEnd)
				{
					HandleNewPacket(pRecvData->pReceiveData, pRecvData->dwReceiveDataSize, pRecvData->dpnidSender);
					csReceive.Unlock();
					return DPN_OK;
				}

				NetMessage* pMsg = new NetMessage;

				pMsg->m_pMsgData = pRecvData->pReceiveData;
				pMsg->m_size = pRecvData->dwReceiveDataSize;
				pMsg->m_bufferHandle = pRecvData->hBufferHandle; // Save buffer handle so we can return it to DirectPlay with ReturnBuffer() later
				pMsg->m_dpnidSender = pRecvData->dpnidSender;

				m_DarkQueue.Push(pMsg);

				csReceive.Unlock();

				return DPNSUCCESS_PENDING;
			}

		case DPN_MSGID_TERMINATE_SESSION:
			{
				// Translate DPlay8's terminate session message to DPlay4
				PDPNMSG_TERMINATE_SESSION pTerminateSession = (PDPNMSG_TERMINATE_SESSION)pMessage;
				DPMSG_SESSIONLOST* pDP4SessLost = new DPMSG_SESSIONLOST;
				NetMessage* pMsg = new NetMessage;

				ZeroMemory(pDP4SessLost, sizeof(DPMSG_SESSIONLOST));
				pDP4SessLost->dwType = DPSYS_SESSIONLOST;

				pMsg->m_pMsgData = (BYTE*)pDP4SessLost;
				pMsg->m_size = sizeof(DPMSG_SESSIONLOST);
				pMsg->m_dpnidSender = DPID_SYSMSG;

				m_DarkQueue.Push(pMsg);

#if (GAME == GAME_THIEF || GAME == GAME_DROMED)
				if (pTerminateSession->pvTerminateData)
				{
					SDestroyReason* pMsg = (SDestroyReason*)pTerminateSession->pvTerminateData;

					switch (pMsg->reason)
					{
						case DReason_CrcFailed:
							Client.StartEndGameTimer(EndGameTime, ER_KickedCrc); break;
						default:
						case DReason_Kicked:
							Client.StartEndGameTimer(EndGameTime, ER_Kicked); break;
					}
				}
				else
					Client.StartEndGameTimer(EndGameTime, ER_HostLeft);
#endif
				break;
			}
	}

	return DPN_OK;
}
Example #15
0
//======================================================================================
// HandleCreatePlayerMsg()
//
// Handles create player system message from DPlay.
//======================================================================================
void CDarkPeer::HandleCreatePlayerMsg(DPNMSG_CREATE_PLAYER* pCreatePlayer)
{
	csReceive.Lock(); // Block packet receives while we're handling this

	// Translate DPlay8's create player message to DPlay4
	char playerName[kMaxPlayerName] = "";
	DPMSG_CREATEPLAYERORGROUP* pDP4CreatePlayer = new DPMSG_CREATEPLAYERORGROUP;

	// Retrieve the peer info and set the host and local DPNIDs
	DPN_PLAYER_INFO* pdpPlayerInfo = GetPeerInfo(pCreatePlayer->dpnidPlayer);

	//Log.Print("Connection from DPNID: %08x", pCreatePlayer->dpnidPlayer);

	if (pdpPlayerInfo)
	{
		if (pdpPlayerInfo->dwPlayerFlags == DPNPLAYER_HOST)
		{
			m_dpnidHost = pCreatePlayer->dpnidPlayer;

			if (Debug.IsFlagSet(DEBUG_NET))
				ConPrintF("Set host DPNID to %x.", m_dpnidHost);
		}
		else if (pdpPlayerInfo->dwPlayerFlags == DPNPLAYER_LOCAL)
			m_dpnidLocal = pCreatePlayer->dpnidPlayer;

		char playerName[kMaxPlayerName];
		WideToAnsi(playerName, pdpPlayerInfo->pwszName, kMaxPlayerName);

		// Display the connection message if this isn't the local player
		if (!(pdpPlayerInfo->dwPlayerFlags & DPNPLAYER_LOCAL))
		{
			ConPrintF("%s connected.", playerName);
			MessageMgr::Get()->AddLineFormat(false, "%s connected.", playerName);
		}

		SAFE_DELETE_ARRAY(pdpPlayerInfo);
	}
	else
		ConPrintF("Failed to get peer info for DPNID %x.", pCreatePlayer->dpnidPlayer);

	if (g_pNetMan->AmDefaultHost() && !IsStagingMode())
	{
		if (Client.MissionStarted())
		{
			IPtr<IQuestData> pQuest = _AppGetAggregated(IID_IQuestData);

			CNetMsg_StartMission msg;
			msg.difficulty = pQuest->Get("Difficulty");
			msg.missionID = _GetMissionData()->missNumber;

			Send(pCreatePlayer->dpnidPlayer, (void*)&msg, sizeof(CNetMsg_StartMission), NULL, DPNSEND_GUARANTEED | DPNSEND_NOLOOPBACK);
		}
	}

	if (g_Net == STATE_Client && m_bReceivedExistingPlayers || g_Net == STATE_Host)
	{
		if (pCreatePlayer->pvPlayerContext == this)
		{
			if (Debug.IsFlagSet(DEBUG_NET))
				ConPrintF("Creating local host. (%x)", pCreatePlayer->dpnidPlayer);
			m_dpnidLocal = (pCreatePlayer->dpnidPlayer);

			csReceive.Unlock();
			return;// DPN_OK;
		}

		// send Thief the new player notification in the form it expects from DPlay 4
		ZeroMemory(pDP4CreatePlayer, sizeof(DPMSG_CREATEPLAYERORGROUP));

		pDP4CreatePlayer->dwType = DPSYS_CREATEPLAYERORGROUP;
		pDP4CreatePlayer->dwPlayerType = DPPLAYERTYPE_PLAYER;
		pDP4CreatePlayer->dpId = pCreatePlayer->dpnidPlayer;

		NetMessage* pMsg = new NetMessage;
		pMsg->m_pMsgData = (BYTE*)pDP4CreatePlayer;
		pMsg->m_size = sizeof(DPMSG_CREATEPLAYERORGROUP);
		pMsg->m_dpnidSender = DPID_SYSMSG;

		m_DarkQueue.Push(pMsg);

#ifdef _THIEFBUILD
		_SFX_Play_Raw(1, 0, "pickloot.wav");
#endif

	}			

	csReceive.Unlock();
}