Example #1
0
// +-----------------------------------------------------------
bool f3::LogControl::getAppLogData(QMap<QString, QtMsgType> &mAppLogData) const
{
	// Try to lock the shared memory
	if(!m_pSharedMemory->lock())
		return false;

	// Read the map from the shared memory
	QBuffer oBuffer;
	QDataStream oStream(&oBuffer);

	oBuffer.setData((char *) m_pSharedMemory->constData(), m_pSharedMemory->size());
	oBuffer.open(QBuffer::ReadOnly);
	
	QMap<QString, int> mApps;
	oStream >> mApps;

	// Unlock the shared memory before returning
	m_pSharedMemory->unlock();

	mAppLogData.clear();
	QMap<QString, int>::iterator it;
	for(it = mApps.begin(); it != mApps.end(); ++it)
		mAppLogData.insert(it.key(), (QtMsgType) (it.value() - 1));

	return true;
}
int NFCDataBaseModule::QueryAccountRoleList(const std::string& strAccount, NFIValueList& value)
{
    char szExec[MAX_PATH] = { 0 };
    sprintf(szExec, "SELECT RoleList FROM %s	 WHERE Account = '%s'", mstrAccountTableName.c_str(), strAccount.c_str());

    otl_long_string strInfo;
    otl_stream oStream(1, szExec, motlConnect);

    while (!oStream.eof())
    {
        oStream >> strInfo;
    }

    if (strInfo.len() > 0)
    {
        stringstream strStream;
        strStream << strInfo.v;

        string strProperty = strStream.str();
        value.Split(strProperty.c_str(), ";");

        return value.GetCount();
    }

    return 0;
}
Example #3
0
void ChatServerSessionManager::OnChatServerInfo(ChatServerSession* pChatServerSession)
{
	stCHAT_MANAGER_NOTIFY_CHAT_INFO oCHAT_MANAGER_NOTIFY_CHAT_INFO;
	for (unsigned int i = 0; i < CHAT_SERVER_NUM; ++i)
	{
		if (pChatServerSession == m_oChatServerSessions + i)
		{
			// 同一个连接
			for (unsigned int j = 0; j < ChatConstant::g_dwHashGen; ++j)
			{
				if (j % CHAT_SERVER_NUM == i)
				{
					m_mapSessionIpPort[j] = pChatServerSession;
				}
			}
			oCHAT_MANAGER_NOTIFY_CHAT_INFO.dwHashIndex = i;
		}
		else
		{
			if (m_oChatServerSessions[i].m_dwChatPort && m_oChatServerSessions[i].m_dwChatServerPort)
			{
				stCHAT_MANAGER_NOTIFY_CHAT_INFO::stRemoteChatInfo oInfo;
				oInfo.dwIp = m_oChatServerSessions[i].GetRemoteIP();
				oInfo.dwPort = m_oChatServerSessions[i].m_dwChatServerPort;
				oInfo.dwHashIndex = i;
				oCHAT_MANAGER_NOTIFY_CHAT_INFO.vecRemoteInfo.push_back(oInfo);
			}
		}
	}
	CNetStream oStream(ENetStreamType_Write, g_pChatServerSessionBuf, g_dwChatServerSessionBuffLen);
	oStream.WriteInt(Protocol::CHAT_MANAGER_NOTIFY_CHAT_INFO);
	oCHAT_MANAGER_NOTIFY_CHAT_INFO.Write(oStream);
	pChatServerSession->Send(g_pChatServerSessionBuf, g_dwChatServerSessionBuffLen - oStream.GetDataLength());
}
Example #4
0
// +-----------------------------------------------------------
bool f3::LogControl::getLogLevel(const QString &sAppName, QtMsgType &eLevel) const
{
	// Try to lock the shared memory
	if(!m_pSharedMemory->lock())
		return false;

	// Read the map from the shared memory
	QBuffer oBuffer;
	QDataStream oStream(&oBuffer);

	oBuffer.setData((char *) m_pSharedMemory->constData(), m_pSharedMemory->size());
	oBuffer.open(QBuffer::ReadOnly);
	
	QMap<QString, int> mApps;
	oStream >> mApps;

	// Unlock the shared memory before returning
	m_pSharedMemory->unlock();

	// Return the stored value for the application name (if found on the table)
	int iLevel = mApps[sAppName];
	if(iLevel != 0)
	{
		eLevel = (QtMsgType) (iLevel - 1);
		return true;
	}
	else
		return false;
}
Example #5
0
void ChatServerSession::OnChatLoginSignGM(const char* pBuf, UINT32 dwLen)
{
	CNetStream oStream(pBuf, dwLen);
	stCHAT_SEND_CHAT_MANAGER_LOGIN_SIGN_GM oCHAT_SEND_CHAT_MANAGER_LOGIN_SIGN_GM;
	oCHAT_SEND_CHAT_MANAGER_LOGIN_SIGN_GM.Read(oStream);

	ChatServerManager::Instance()->GetGMSessionManager().GetGMSession().OnLoginSign(m_szChatIp, m_dwChatPort, m_dwWebSocketChatPort,oCHAT_SEND_CHAT_MANAGER_LOGIN_SIGN_GM.szPlayerId, oCHAT_SEND_CHAT_MANAGER_LOGIN_SIGN_GM.szSign);
}
Example #6
0
void CRdbTableAccess::ReInsert(char* sRedo, uint32 nSize)
{
	CMemoryStream oStream(sRedo, nSize);
	oStream.SetLocalCode(true);
	if(!m_oInsertAttr.Read(oStream))
		return;
	m_pTable->Insert(&m_oInsertAttr);
}
Example #7
0
void CRdbTableAccess::ReDelete(char* sRedo, uint32 nSize)
{
	uint32 nCount;
	CMemoryStream oStream(sRedo, nSize);
	oStream.SetLocalCode(true);
	if(!m_oIdxAttr.Read(oStream))
		return;
	m_pTable->Delete(&m_oIdxAttr, nCount);
}
Example #8
0
void CNetDDESvrApp::OnDDEDestroyConversation(CNetDDESvrSocket& oConnection, CNetDDEPacket& oReqPacket)
{
	ASSERT(oReqPacket.DataType() == CNetDDEPacket::DDE_DESTROY_CONVERSATION);

	HCONV  hConv;
	uint32 nConvID;

	// Decode message.
	CMemStream oStream(oReqPacket.Buffer());

	oStream.Open();
	oStream.Seek(sizeof(CNetDDEPacket::Header));

	oStream.Read(&hConv, sizeof(hConv));
	oStream >> nConvID;

	oStream.Close();

	if (App.m_bTraceConvs)
		App.Trace(TXT("DDE_DESTROY_CONVERSATION: 0x%p [#%u]"), hConv, nConvID);

	// Locate the conversation.
	CDDECltConv* pConv = m_pDDEClient->FindConversation(hConv);

	if (pConv != NULL)
	{
		CNetDDEConv* pNetConv = oConnection.FindNetConv(pConv, nConvID);

		ASSERT(pNetConv != NULL);

		try
		{
			// Not final reference?
			if (pNetConv->m_pSvrConv->RefCount() != 1)
			{
				// Destroy NetDDE conversations' links.
				for (size_t i = 0; i < pNetConv->m_aoLinks.Size(); ++i)
					pConv->DestroyLink(pNetConv->m_aoLinks[i]);
			}

			// Purge link cache, if last reference.
			if (pNetConv->m_pSvrConv->RefCount() == 1)
				m_oLinkCache.Purge(pConv);

			// Call DDE to terminate the conversation.
			m_pDDEClient->DestroyConversation(pConv);
		}
		catch (CDDEException& e)
		{
			App.Trace(TXT("DDE_ERROR: %s"), e.twhat());
		}

		// Detach from the connection.
		oConnection.m_aoNetConvs.Delete(oConnection.m_aoNetConvs.Find(pNetConv));
	}
}
Example #9
0
void ChatServerSession::ChatLoginByGM(std::string szPlayerId)
{
	stCHAT_MANAGER_NOTIFY_CHAT_LOGIN_GM oCHAT_MANAGER_NOTIFY_CHAT_LOGIN_GM;
	oCHAT_MANAGER_NOTIFY_CHAT_LOGIN_GM.szPlayerId = szPlayerId;

	CNetStream oStream(ENetStreamType_Write, g_pChatServerSessionBuf, g_dwChatServerSessionBuffLen);
	oStream.WriteInt(Protocol::CHAT_MANAGER_NOTIFY_CHAT_LOGIN_GM);
	oCHAT_MANAGER_NOTIFY_CHAT_LOGIN_GM.Write(oStream);
	Send(g_pChatServerSessionBuf, g_dwChatServerSessionBuffLen - oStream.GetDataLength());
}
Example #10
0
void CNetDDESvrApp::OnDDEStopAdvise(CNetDDESvrSocket& oConnection, CNetDDEPacket& oReqPacket)
{
	ASSERT(oReqPacket.DataType() == CNetDDEPacket::DDE_STOP_ADVISE);

	HCONV	 hConv;
	uint32   nConvID;
	CString  strItem;
	uint32   nFormat;

	// Decode message.
	CMemStream oStream(oReqPacket.Buffer());

	oStream.Open();
	oStream.Seek(sizeof(CNetDDEPacket::Header));

	oStream.Read(&hConv, sizeof(hConv));
	oStream >> nConvID;
	oStream >> strItem;
	oStream >> nFormat;

	oStream.Close();

	if (App.m_bTraceAdvises)
		App.Trace(TXT("DDE_STOP_ADVISE: %s %s"), strItem, CClipboard::FormatName(nFormat));

	// Locate the conversation.
	CDDECltConv* pConv = m_pDDEClient->FindConversation(hConv);

	if (pConv != NULL)
	{
		// Locate the link. (May not exist, if async advised).
		CDDELink* pLink = pConv->FindLink(strItem, nFormat);

		if (pLink != NULL)
		{
			CNetDDEConv* pNetConv = oConnection.FindNetConv(pConv, nConvID);

			ASSERT(pNetConv != NULL);

			try
			{
				// Call DDE to destroy the link.
				pConv->DestroyLink(pLink);
			}
			catch (CDDEException& e)
			{
				App.Trace(TXT("DDE_ERROR: %s"), e.twhat());
			}

			// Detach from the connection.
			pNetConv->m_aoLinks.Remove(pNetConv->m_aoLinks.Find(pLink));
		}
	}
}
Example #11
0
//----------------------------------------------------------------------------------------------------
vector<string>& GBUserPrefs::SplitString( const string& strInput, char chDelimiter, vector<string>& oOutput )
{
    stringstream oStream( strInput );
    string strCurrent;

    while( getline( oStream, strCurrent, chDelimiter ) )
    {
        oOutput.push_back( ( strCurrent ) );
    }

    return oOutput;
}
Example #12
0
void ChatServerSession::OnChatServerInfo(const char* pBuf, UINT32 dwLen)
{
	CNetStream oStream(pBuf, dwLen);
	stCHAT_SEND_CHAT_MANAGER_INFO oCHAT_SEND_CHAT_MANAGER_INFO;
	oCHAT_SEND_CHAT_MANAGER_INFO.Read(oStream);
	m_dwWebSocketChatPort = oCHAT_SEND_CHAT_MANAGER_INFO.m_dwWebSocketChatPort;
	m_dwChatPort = oCHAT_SEND_CHAT_MANAGER_INFO.m_dwChatPort;
	m_dwChatServerPort = oCHAT_SEND_CHAT_MANAGER_INFO.m_dwChatServerPort;
	m_szChatIp = oCHAT_SEND_CHAT_MANAGER_INFO.m_szChatIp;

	ChatServerManager::Instance()->GetChatServerSessionManager().OnChatServerInfo(this);
}
Example #13
0
// +-----------------------------------------------------------
bool f3::LogControl::setLogLevel(const QString &sAppName, const QtMsgType eLevel)
{
	// Try to lock the shared memory
	if(!m_pSharedMemory->lock())
		return false;

	// First Read the map from the shared memory
	QBuffer oBuffer;
	QDataStream oStream(&oBuffer);

	oBuffer.setData((char *) m_pSharedMemory->constData(), m_pSharedMemory->size());
	oBuffer.open(QBuffer::ReadOnly);

	QMap<QString, int> mApps;
	oStream >> mApps;

	// Then update the value in the map with the new log level (if needed)
	int iLevel = mApps[sAppName];
	int iNewLevel = ((int) eLevel) + 1;

	// And save the map data to the shared memory
	if(iLevel == 0 || iLevel != iNewLevel)
	{
		mApps[sAppName] = iNewLevel;

		QBuffer oNewBuffer;
		oNewBuffer.open(QBuffer::ReadWrite);
		QDataStream oNewStream(&oNewBuffer);

		oNewStream << mApps;

		int iSize = oNewBuffer.size();
		if(iSize < SHARED_MEMORY_SIZE)
		{
			char *sDataTo = (char *) m_pSharedMemory->data();
			const char *sDataFrom = oNewBuffer.data().data();
			memset(sDataTo, '\0', SHARED_MEMORY_SIZE);
			memcpy(sDataTo, sDataFrom, iSize);
		}
		else // Oops! Not enough space in the shared memory
		{
			// Unlock the shared memory before returning failure
			m_pSharedMemory->unlock();
			return false;
		}
	}

	// Unlock the shared memory before returning
	m_pSharedMemory->unlock();
	return true;
}
Example #14
0
void ChatServerSessionManager::BroadcastMsg(const Protocol::EChatType& eChatType, const std::string& szContent)
{
	stCHAT_MANAGER_NOTIFY_CHAT_BROADCAST oCHAT_MANAGER_NOTIFY_CHAT_BROADCAST;

	oCHAT_MANAGER_NOTIFY_CHAT_BROADCAST.eChatType = eChatType;
	oCHAT_MANAGER_NOTIFY_CHAT_BROADCAST.szContent = szContent;
	CNetStream oStream(ENetStreamType_Write, g_pChatServerSessionBuf, g_dwChatServerSessionBuffLen);
	oStream.WriteInt(Protocol::CHAT_MANAGER_NOTIFY_CHAT_BROADCAST);
	oCHAT_MANAGER_NOTIFY_CHAT_BROADCAST.Write(oStream);
	for (int i = 0; i < CHAT_SERVER_NUM; ++i)
	{
		m_oChatServerSessions[i].Send(g_pChatServerSessionBuf, g_dwChatServerSessionBuffLen - oStream.GetDataLength());
	}
}
Example #15
0
void ChatServerSession::OnChatLoginSign(const char* pBuf, UINT32 dwLen)
{
	CNetStream oStream(pBuf, dwLen);
	stCHAT_SEND_CHAT_MANAGER_LOGIN_SIGN oCHAT_SEND_CHAT_MANAGER_LOGIN_SIGN;
	oCHAT_SEND_CHAT_MANAGER_LOGIN_SIGN.Read(oStream);

	GameSession* pSession = ChatServerManager::Instance()->GetGameSessionManager().GetGameSession(oCHAT_SEND_CHAT_MANAGER_LOGIN_SIGN.szServerId);
	if (!pSession)
	{
		LogExe(LogLv_Critical, "error");
		return;
	}
	pSession->OnLoginSign(m_szChatIp, m_dwChatPort, m_dwWebSocketChatPort, oCHAT_SEND_CHAT_MANAGER_LOGIN_SIGN.szPlayerId, oCHAT_SEND_CHAT_MANAGER_LOGIN_SIGN.szSign);
}
int NFCDataBaseModule::HasAccount(const std::string& strAccount)
{
    char szExec[MAX_PATH] = { 0 };
    sprintf(szExec, "select count(*) from %s where Account = '%s'", mstrAccountTableName.c_str(), strAccount.c_str());

    int nCount = 0;
    otl_stream oStream(1, szExec, motlConnect);

    while (!oStream.eof())
    {
        oStream >> nCount;
        return nCount;
    }

    return 0;
}
Example #17
0
void ChatServerSession::OnRecv(const char* pBuf, UINT32 dwLen)
{
	CNetStream oStream(pBuf, dwLen);
	Protocol::EChatProtocol eProrocol;
	oStream.ReadInt((int&)eProrocol);
	const char* pData = pBuf + sizeof(UINT32);
	dwLen -= sizeof(UINT32);

	switch (eProrocol)
	{
		case Protocol::CHAT_NOTIFY_CHAT_MANAGER_INFO:				OnChatServerInfo(pData, dwLen);	break;
		case Protocol::CHAT_NOTIFY_CHAT_MANAGER_LOGIN_SIGN:		OnChatLoginSign(pData, dwLen); break;
		case Protocol::CHAT_NOTIFY_CHAT_MANAGER_LOGIN_SIGN_GM:	OnChatLoginSignGM(pData, dwLen); break;
		default:	Assert(0);	break;
	}
}
Example #18
0
void CRdbTableAccess::ReUpdate(char* sRedo, uint32 nSize)
{
	uint32 nMaxRollBackRecordQuantity;
	CMemoryStream oStream(sRedo, nSize);
	oStream.SetLocalCode(true);
	if(!oStream.Read(nMaxRollBackRecordQuantity))
		return;
	if(!m_oIdxAttr.Read(oStream))
		return;
	if(!m_oSetAttr.Read(oStream))
		return;
	uint32 nCount;
	m_oRollBack.SetRecordSetSize(nMaxRollBackRecordQuantity);
	m_oRollBack.PreAlloc();
	m_pTable->Update(&m_oIdxAttr, &m_oSetAttr, m_oRollBack, nCount);
}
int NFCDataBaseModule::ConfirmAccountInfo(const std::string& strAccount, const std::string& strPassword)
{

    char szExec[MAX_PATH] = { 0 };
    sprintf(szExec, "SELECT Count(*) FROM %s	 WHERE Account = '%s' and Password = '******'", mstrAccountTableName.c_str(), strAccount.c_str(), strPassword.c_str());

    int nCount = 0;
    otl_stream oStream(1, szExec, motlConnect);

    while (!oStream.eof())
    {
        oStream >> nCount;
        return nCount;
    }

    return 0;
}
Example #20
0
//==============================================================================
void SynthAudioProcessor::getStateInformation (MemoryBlock& destData)
{
    // You should use this method to store your parameters in the memory block.
    // You could do that either as raw data, or use the XML or ValueTree classes
    // as intermediaries to make it easy to save and load complex data.
	MemoryOutputStream oStream(destData, true);
	oStream.writeFloat(*oscP);
	oStream.writeFloat(*detP);
	oStream.writeFloat(*ampP);
	oStream.writeFloat(*freqP);
	oStream.writeFloat(*qP);
	oStream.writeFloat(*envP);
	oStream.writeFloat(*speedP);

	//MemoryOutputStream(destData, true).writeFloat(*speedP);

}
Example #21
0
void SState::Save()
{
    std::string sFilename = GetConfigFilename();
    std::ofstream oStream( sFilename.c_str(), std::ios_base::out | std::ios_base::trunc );
    if ( oStream.rdstate() & std::ios::failbit )
    {
        debug( "Unable to open config file: %s\n", sFilename.c_str() );
        return;
    }

    oStream << GetConfigHeader() << '\n';

//	oStream << "=" << m_ << '\n';

    oStream << "NUMPLAYERS=" << m_iNumPlayers << '\n';
    oStream << "TEAMMODE=" << m_enTeamMode << '\n';
    oStream << "TEAMSIZE=" << m_iTeamSize << '\n';
    oStream << "TEAMMULTISELECT=" << m_bTeamMultiselect << '\n';

    oStream << "ROUNDLENGTH=" << m_iRoundLength << '\n';
    oStream << "HITPOINTS=" << m_iHitPoints << '\n';
    oStream << "GAMESPEED=" << m_iGameSpeed << '\n';

    oStream << "FULLSCREEN=" << m_bFullscreen << '\n';
    oStream << "CHANNELS=" << m_iChannels << '\n';
    oStream << "MIXINGRATE=" << m_iMixingRate << '\n';
    oStream << "MIXINGBITS=" << m_iMixingBits << '\n';
    oStream << "MUSICVOLUME=" << m_iMusicVolume << '\n';
    oStream << "SOUNDVOLUME=" << m_iSoundVolume << '\n';
    oStream << "LANGUAGE=" << m_acLanguage << '\n';

    oStream << "LATESTSERVER=" << m_acLatestServer << '\n';
    oStream << "SERVER=" << m_bServer << '\n';
    oStream << "NICK=" << m_acNick << '\n';

    for ( int i=0; i<MAXPLAYERS; ++i )
    {
        for ( int j=0; j<9; ++j )
        {
            oStream << "PLAYER" <<i<< "KEY" <<j<< '=' << m_aiPlayerKeys[i][j] << '\n';
        }
    }

    oStream.flush();
    oStream.close();
}
Example #22
0
// +-----------------------------------------------------------
bool f3::LogControl::removeAppEntry(const QString &sAppName)
{
	// Try to lock the shared memory
	if(!m_pSharedMemory->lock())
		return false;

	// First Read the map from the shared memory
	QBuffer oBuffer;
	QDataStream oStream(&oBuffer);

	oBuffer.setData((char *) m_pSharedMemory->constData(), m_pSharedMemory->size());
	oBuffer.open(QBuffer::ReadOnly);

	QMap<QString, int> mApps;
	oStream >> mApps;

	// Then remove the entry in the map with the app name
	mApps.remove(sAppName);

	// Save the map data to the shared memory
	QBuffer oNewBuffer;
	oNewBuffer.open(QBuffer::ReadWrite);
	QDataStream oNewStream(&oNewBuffer);

	oNewStream << mApps;

	int iSize = oNewBuffer.size();
	if(iSize < SHARED_MEMORY_SIZE)
	{
		char *sDataTo = (char *) m_pSharedMemory->data();
		const char *sDataFrom = oNewBuffer.data().data();
		memset(sDataTo, '\0', SHARED_MEMORY_SIZE);
		memcpy(sDataTo, sDataFrom, iSize);
	}
	else // Oops! Not enough space in the shared memory
	{
		// Unlock the shared memory before returning failure
		m_pSharedMemory->unlock();
		return false;
	}

	// Unlock the shared memory before returning
	m_pSharedMemory->unlock();
	return true;
}
Example #23
0
void CNetDDESvrApp::OnNetDDEClientDisconnect(CNetDDESvrSocket& /*oConnection*/, CNetDDEPacket& oReqPacket)
{
	ASSERT(oReqPacket.DataType() == CNetDDEPacket::NETDDE_CLIENT_DISCONNECT);

	CString strService;
	CString strComputer;

	// Decode request message.
	CMemStream oStream(oReqPacket.Buffer());

	oStream.Open();
	oStream.Seek(sizeof(CNetDDEPacket::Header));

	oStream >> strService;
	oStream >> strComputer;

	oStream.Close();

	if (App.m_bTraceNetConns)
		App.Trace(TXT("NETDDE_CLIENT_DISCONNECT: %s %s"), strService, strComputer);
}
Example #24
0
//理论上这里收到消息之后,要弄个hashmap做消息映射。采用这种switch办法很难看,还导致这个类处理太多无关的事情。
void Summoners::receiveMessage()
{
    QDataStream oStream(Socket->readAll());
    oStream.setByteOrder(QDataStream::LittleEndian);
    qint32 msgID;
    while (!oStream.atEnd())
    {
        oStream >> msgID;

        ui.edit_display_msg->append(QString::number(msgID));

        switch (msgID)
        {
        case SC_HEART:
            //can not receive this message.
            break;
        case SC_Login:
            msg_login(oStream);
            break;
        case SC_RoleInfo:
            msg_RoleInfo(oStream);
            break;
        //case SC_updateRole:	msg_updateRole(oStream);break;
        case SC_FightStart:
            msg_FightStart(oStream);
            break;
        case SC_FightFinish:
            msg_FightFinish(oStream);
            break;
        case SC_Action:
            msg_Action(oStream);
            break;

        default:
            break;
        }
    }
}
Example #25
0
QString LogMessage::toString() const
{
	QString str;
	QTextStream oStream(&str, QIODevice::WriteOnly);

	oStream << m_timestamp.toString("yyyy-MM-dd HH:mm:ss.zzz ") << m_app << ": ";

	switch(m_level)
	{
		case LogMessage::Error:
			oStream << "E: ";
			break;
		case LogMessage::Warning:
			oStream << "W: ";
			break;
		case LogMessage::Info:
			oStream << "N: ";
			break;
		case LogMessage::StateMachine:
			oStream << "S: ";
			break;
		case LogMessage::SoapIn:
			oStream << "I: ";
			break;
		case LogMessage::SoapOut:
			oStream << "O: ";
			break;
		case LogMessage::Debug:
			oStream << "D: ";
			break;
		default:
			break;
	}

	oStream << m_msg;
	return str;
}
Example #26
0
void CNetDDESvrApp::OnDDEPoke(CNetDDESvrSocket& oConnection, CNetDDEPacket& oReqPacket)
{
	ASSERT(oReqPacket.DataType() == CNetDDEPacket::DDE_POKE);

	bool     bResult = false;

	HCONV	 hConv;
	uint32   nConvID;
	CString  strItem;
	uint32   nFormat;
	CBuffer  oData;

	// Decode message.
	CMemStream oStream(oReqPacket.Buffer());

	oStream.Open();
	oStream.Seek(sizeof(CNetDDEPacket::Header));

	oStream.Read(&hConv, sizeof(hConv));
	oStream >> nConvID;
	oStream >> strItem;
	oStream >> nFormat;
	oStream >> oData;

	oStream.Close();

	if (App.m_bTraceRequests)
	{
		CString strData;

		if (nFormat == CF_TEXT)
			strData = oData.ToString(ANSI_TEXT);
		else if (nFormat == CF_UNICODETEXT)
			strData = oData.ToString(UNICODE_TEXT);
		else
			strData = CClipboard::FormatName(nFormat);

		App.Trace(TXT("DDE_POKE: %s %s [%s]"), strItem, CClipboard::FormatName(nFormat), strData);
	}

	try
	{
		// Locate the conversation.
		CDDECltConv* pConv = m_pDDEClient->FindConversation(hConv);

		if (pConv != NULL)
		{
			// Call DDE to do the poke.
			pConv->Poke(strItem, nFormat, oData.Buffer(), oData.Size());

			bResult = true;
		}
	}
	catch (CDDEException& e)
	{
		App.Trace(TXT("DDE_ERROR: %s"), e.twhat());
	}

	// Create response message.
	CBuffer    oRspBuffer;
	CMemStream oRspStream(oRspBuffer);

	oRspStream.Create();

	oRspStream << bResult;

	oRspStream.Close();

	// Send response message.
	CNetDDEPacket oRspPacket(CNetDDEPacket::DDE_POKE, oReqPacket.PacketID(), oRspBuffer);

	oConnection.SendPacket(oRspPacket);

	// Update stats.
	++m_nPktsSent;
}
Example #27
0
void CSVDocument::load(const std::string& oFile, bool bWithHeader /* = true */, int *errorRow /* = NULL */, int *errorCol /* = NULL */)
{
	std::ifstream oStream(oFile.c_str(), std::ios::in) ;
	if (!oStream.is_open())
	{
		printf("打开文件失败: %s\n", oFile.c_str());
		return;
	}
	std::vector<std::string> stringList;
	char sBuff[1024];
	while (!oStream.eof())
	{
		memset(sBuff, 0, sizeof(sBuff));
		oStream.getline(sBuff, sizeof(sBuff));
		if (sBuff[0] != '\0')
		{
			int len = (int)strlen(sBuff);
			if (sBuff[len - 1] == '\r')
				sBuff[len - 1] = '\0';
			stringList.push_back(sBuff);
		}
	}
	//首先清空现有数据
	clearColumnObject();
	//文档为空,没有数据则退出
	if (stringList.size() <= 0)
		return;

	//从第1行分析列名称表,分隔符是","
	parseColumns(stringList[1], ',');

	//循环读取数据并添加到每个列对象
	const int rowCount = (int)stringList.size();
	m_dwRowNum = 0;
	int hadErrCol = 0;
	int nStartRow = bWithHeader ? 1 : 0;
	for (int i = nStartRow; i < rowCount; ++i)
	{
		if (parseRow(stringList[i], ',', &hadErrCol))
		{
			m_dwRowNum++;
		}
		if (hadErrCol != 0)
		{
			if (errorRow && errorCol)
			{
				*errorCol = hadErrCol;
				*errorRow = i;
				return;
			}
			else assert(false);
		}
	}
#ifdef _DEBUG
	for (size_t i = 0; i < m_dwColNum; ++i)
	{
		if ((int)m_dwRowNum != m_ColumnList[i]->size())
		{
			if (errorCol)
			{
				*errorCol = (int)i;
				return;
			}
			else
			{
				assert(false);
			}
		}
	}
#endif
}
Example #28
0
void CNetDDESvrApp::OnDisconnect(CDDECltConv* pConv)
{
	HCONV      hConv = pConv->Handle();
	CBuffer    oBuffer;
	CMemStream oStream(oBuffer);

	oStream.Create();
	oStream.Write(&hConv, sizeof(hConv));
	oStream.Close();

	CNetDDEPacket oPacket(CNetDDEPacket::DDE_DISCONNECT, oBuffer);

	// For all NetDDEClients...
	for (size_t i = 0; i < m_aoConnections.Size(); ++i)
	{
		CNetDDESvrSocket* pConnection = m_aoConnections[i];
		bool              bNotifyConn = true;

		// Clean-up all client conversations...
		for (int j = static_cast<int>(pConnection->m_aoNetConvs.Size())-1; j >= 0; --j)
		{
			CNetDDEConv* pNetConv = pConnection->m_aoNetConvs[j];

			if (pNetConv->m_pSvrConv == pConv)
			{
				try
				{
					// Only send once per client.
					if (bNotifyConn)
					{
						bNotifyConn = false;

						if (App.m_bTraceConvs)
							App.Trace(TXT("DDE_DISCONNECT: %s, %s"), pConv->Service(), pConv->Topic());

						// Send disconnect message.
						pConnection->SendPacket(oPacket);

						// Update stats.
						++m_nPktsSent;
					}
				}
				catch (CSocketException& e)
				{
					App.Trace(TXT("SOCKET_ERROR: %s"), e.twhat());
				}

				pConnection->m_aoNetConvs.Delete(j);
			}
		}
	}

	// Purge link cache.
	m_oLinkCache.Purge(pConv);

	uint nRefCount = pConv->RefCount();

	// Free conversation.
	while (nRefCount--)
		m_pDDEClient->DestroyConversation(pConv);
}
Example #29
0
int main(int argc, char * argv[])
#endif
{
	C7ZipLibrary lib;

	if (!lib.Initialize()) {
		wprintf(L"initialize fail!\n");
		return 1;
	}

	WStringArray exts;

	if (!lib.GetSupportedExts(exts)) {
		wprintf(L"get supported exts fail\n");
		return 1;
	}

	size_t size = exts.size();

	for(size_t i = 0; i < size; i++) {
		wstring ext = exts[i];

		for(size_t j = 0; j < ext.size(); j++) {
			wprintf(L"%c", (char)(ext[j] &0xFF));
		}

		wprintf(L"\n");
	}

	C7ZipArchive * pArchive = NULL;

	TestInStream stream("Test7Zip.zip");
	TestOutStream oStream("TestResult.txt");
        if (lib.OpenArchive(&stream, &pArchive, true)) {
		unsigned int numItems = 0;

		pArchive->GetItemCount(&numItems);

		wprintf(L"%d\n", numItems);

		for(unsigned int i = 0;i < numItems;i++) {
			C7ZipArchiveItem * pArchiveItem = NULL;

			if (pArchive->GetItemInfo(i, &pArchiveItem)) {
				wprintf(L"%d,%ls,%d\n", pArchiveItem->GetArchiveIndex(),
						pArchiveItem->GetFullPath().c_str(),
						pArchiveItem->IsDir());

				wprintf(L"get all properties\n");
				for(lib7zip::PropertyIndexEnum index = lib7zip::kpidPackSize;
					index <= lib7zip::kpidIsDir;
					index = (lib7zip::PropertyIndexEnum)(index + 1)) {
					wstring strVal = L"";
					unsigned __int64 val = 0;
					bool bVal = false;

					bool result = pArchiveItem->GetUInt64Property(index, val);

					wprintf(L"\n\nGetProperty:%d %ls\n", (int)index, 
							index_names[(int)index]);

					wprintf(L"UInt64 result:%ls val=%ld\n", 
							result ? L"true" : L"false",
							val);

					result = pArchiveItem->GetBoolProperty(index, bVal);

					wprintf(L"Bool result:%ls val=%ls\n", 
							result ? L"true" : L"false",
							bVal ? L"true" : L"false");

					result = pArchiveItem->GetStringProperty(index, strVal);

					wprintf(L"String result:%ls val=%ls\n", 
							result ? L"true" : L"false",
							strVal.c_str());				

					result = pArchiveItem->GetFileTimeProperty(index, val);

					wprintf(L"FileTime result:%ls val=%ld\n", 
							result ? L"true" : L"false",
							val);				
				}

				//set archive password or item password
				pArchive->SetArchivePassword(L"test");
				if (i==0) {
					//Or set password for each archive item
					//pArchiveItem->SetArchiveItemPassword(L"test");
					pArchive->Extract(pArchiveItem, &oStream);
				}
			} //if
		}//for
	}
	else {
		wprintf(L"open archive Test7Zip.zip fail\n");
	}

	if (pArchive != NULL)
		delete pArchive;

	return 0;
}
Example #30
0
void CNetDDESvrApp::OnAdvise(CDDELink* pLink, const CDDEData* pData)
{
	ASSERT(pData != NULL);

	// Ignore Advise, if during an Advise Start.
	if (pLink == NULL)
		return;

	CDDEConv* pConv = pLink->Conversation();
	CBuffer   oData = pData->GetBuffer();

	// Find the links' value in the cache.
	CLinkValue* pValue = m_oLinkCache.Find(pConv, pLink);

	// Discard duplicate updates.
	if ((App.m_bDiscardDups) && (pValue != NULL)
	 && (pValue->m_oLastValue == oData))
	{
		if (App.m_bTraceUpdates)
			App.Trace(TXT("DDE_ADVISE: %s %s (ignored)"), pConv->Service(), pLink->Item());

		return;
	}

	// Create a cache entry, if a new link.
	if (pValue == NULL)
		pValue = m_oLinkCache.Create(pConv, pLink);

	ASSERT(pValue != NULL);

	// Update links' cached value.
	pValue->m_oLastValue  = oData;
	pValue->m_tLastUpdate = CDateTime::Current();

	// Create advise packet.
	HCONV      hConv = pConv->Handle();
	CBuffer    oBuffer;
	CMemStream oStream(oBuffer);

	oStream.Create();

	oStream.Write(&hConv, sizeof(hConv));
	oStream << pLink->Item();
	oStream << (uint32) pLink->Format();
	oStream << oData;
	oStream << true;

	oStream.Close();

	CNetDDEPacket oPacket(CNetDDEPacket::DDE_ADVISE, oBuffer);

	// Notify all NetDDEClients...
	for (size_t i = 0; i < m_aoConnections.Size(); ++i)
	{
		CNetDDESvrSocket* pConnection = m_aoConnections[i];

		// Ignore, if connection severed.
		if (!pConnection->IsOpen())
			continue;

		// Connection references link?
		if (pConnection->IsLinkUsed(pLink))
		{
			try
			{
				if (App.m_bTraceUpdates)
				{
					uint    nFormat = pLink->Format();
					CString strData;

					if (nFormat == CF_TEXT)
						strData = oData.ToString(ANSI_TEXT);
					else if (nFormat == CF_UNICODETEXT)
						strData = oData.ToString(UNICODE_TEXT);
					else
						strData = CClipboard::FormatName(nFormat);

					App.Trace(TXT("DDE_ADVISE: %s %s [%s]"), pConv->Service(), pLink->Item(), strData);
				}

				// Send advise message.
				pConnection->SendPacket(oPacket);

				// Update stats.
				++m_nPktsSent;
			}
			catch (CSocketException& e)
			{
				App.Trace(TXT("SOCKET_ERROR: %s"), e.twhat());
			}
		}
	}
}