Ejemplo n.º 1
0
bool ZBirdDummyClient::OnSockRecv(SOCKET sock, char* pPacket, DWORD dwSize)
{
	if (m_pCommandBuilder==NULL) return false;
	// New Cmd Buffer ////////////////
	m_pCommandBuilder->SetUID(m_This, GetSenderUIDBySocket(sock));
	m_pCommandBuilder->Read((char*)pPacket, dwSize);

	LockRecv();
	while(MCommand* pCmd = m_pCommandBuilder->GetCommand()) 
	{
		Post(pCmd);
	}
	UnlockRecv();

	while(MPacketHeader* pNetCmd = m_pCommandBuilder->GetNetCommand()) 
	{
		if (pNetCmd->nMsg == MSGID_REPLYCONNECT) 
		{
			MReplyConnectMsg* pMsg = (MReplyConnectMsg*)pNetCmd;
			MUID HostUID, AllocUID;
			HostUID.High = pMsg->nHostHigh;
			HostUID.Low = pMsg->nHostLow;
			AllocUID.High = pMsg->nAllocHigh;
			AllocUID.Low = pMsg->nAllocLow;
			free(pNetCmd);

			LockRecv();
			OnConnected(sock, &HostUID, &AllocUID);
			UnlockRecv();
		}
	}

	return true;
}
Ejemplo n.º 2
0
bool ZBirdDummyClient::Post(MCommand* pCommand)
{
	LockRecv();
	bool bRet = MCommandCommunicator::Post(pCommand);
	UnlockRecv();
	return bRet;
}
Ejemplo n.º 3
0
MCommand* ZBirdDummyClient::GetCommandSafe()
{
	LockRecv();
	MCommand* pCmd = MCommandCommunicator::GetCommandSafe();
	UnlockRecv();

	return pCmd;
}
Ejemplo n.º 4
0
void MMatchClient::OnTunnelingUDP(const MUID& uidSender, void* pBlob, int nCount)
{
	MCommand* pCmd = MakeCmdFromTunnelingBlob(uidSender, pBlob, nCount);
	if (pCmd == NULL) return;

	LockRecv();
	m_CommandManager.Post(pCmd);
	UnlockRecv();
}
Ejemplo n.º 5
0
void CNetUser::OnRead(char* pData, int nDataLen)
{
	LockRecv();
	m_nRecvCount--;
	if (m_nRecvCount<0)
	{
		m_nRecvCount = 0;
	}
	UnLockRecv();
	if (nDataLen>0)
	{
// 		UpdateLastPacketTime();
 		m_pNetRecvBuffer->AddBuf(nDataLen);
//		std::cout << "OnRead-" << nDataLen << std::endl;
	}
	int nMissionSize = 0;
	if (m_pNetRecvBuffer->GetMission(nMissionSize))
	{
		//有一条完整的命令
		CMission* pMission = CMissionFactory::GetInstance()->CreateMission();
		if (!pMission)
		{
			std::cout << " no memery\n";
			return;
		}
		pMission->SetNetUset(this);
		pMission->SetData(m_pNetRecvBuffer->GetBufPtr(), nMissionSize);
		m_pNetRecvBuffer->FlushBuf(nMissionSize);
		CMissionFactory::GetInstance()->AddMission(pMission);
		if (!m_bNoUse)
		{//该连接已经关闭则不接收数据
			m_pTcpContext->RecvData(m_pNetRecvBuffer->GetUnUsedBufPtr(), m_pNetRecvBuffer->GetUnUsedSize());
		}
	}
	else
	{
		int nLen = m_pNetRecvBuffer->GetUnUsedSize();
		if (nLen <= 0)
		{//没有空间,暂时不处理
			std::cout << " no buff\n";
		}
		else
		{
			if (!m_bNoUse)
			{//该连接已经关闭则不接收数据
				if (m_pTcpContext)
				{
					m_pTcpContext->RecvData(m_pNetRecvBuffer->GetUnUsedBufPtr(), nLen);
				}
			}
		}
	}
}
Ejemplo n.º 6
0
void MMatchClient::ParseUDPPacket(char* pData, MPacketHeader* pPacketHeader, DWORD dwIP, unsigned int nPort)
{
	switch (pPacketHeader->nMsg)
	{
	case MSGID_RAWCOMMAND:
		{
			unsigned short nCheckSum = MBuildCheckSum(pPacketHeader, pPacketHeader->nSize);
			if (pPacketHeader->nCheckSum != nCheckSum) {
				static int nLogCount = 0;
				if (nLogCount++ < 100) {	// Log Flooding 방지
					mlog("MMatchClient::ParseUDPPacket() -> CHECKSUM ERROR(R=%u/C=%u)\n", 
						pPacketHeader->nCheckSum, nCheckSum);
				}
				return;
			} else {
				MCommand* pCmd = new MCommand();
				if (!pCmd->SetData(pData, &m_CommandManager))
				{
					mlog("MMatchClient::ParseUDPPacket() -> SetData Error\n");

					delete pCmd;
					return;
				}

				MUID uidPeer = FindPeerUID(dwIP, nPort);
				if (uidPeer != MUID(0,0))
				{
					pCmd->m_Sender = uidPeer;
				} else {
					// TODO: 여기 수정해야함.
					sockaddr_in Addr;
					Addr.sin_addr.S_un.S_addr = dwIP;
					Addr.sin_port = nPort;
					char* pszIP = inet_ntoa(Addr.sin_addr);

					if (strcmp(pszIP, GetAgentIP()) == 0) 
					{
						pCmd->m_Sender = GetAgentServerUID();
					}
					else if( (MC_RESPONSE_SERVER_LIST_INFO == pCmd->GetID()) ||
						(MC_RESPONSE_BLOCK_COUNTRY_CODE_IP == pCmd->GetID()) )
					{
						// 특별히 하는건 없음.
						// Lcator는 Peer설정이 되지 않기때문에 여기서 따로 처리함.
					}
					else if (pCmd->GetID() == MC_UDP_PONG) 
					{
						// 특별히 하는건 없음. Command를 넘겨주기 위해서...(밑에 커맨드를 딜리트하기때문에)
					}	
					else 
					{
						delete pCmd; pCmd = NULL;
						return;
					}
				}

				pCmd->m_Receiver = m_This;

				if( IsUDPCommandValidationCheck(pCmd->GetID()) ) {
					LockRecv();				
					m_CommandManager.Post(pCmd);
					UnlockRecv();
				} else {
#ifdef _DEBUG
					mlog("%s(ID:%d) is Denied Command!\n"
						, pCmd->m_pCommandDesc->GetName(), pCmd->GetID());
#endif
				}
			}
		}
		break;
	case MSGID_COMMAND:
		{
			int nPacketSize = pPacketHeader->CalcPacketSize(&m_PeerPacketCrypter);
			unsigned short nCheckSum = MBuildCheckSum(pPacketHeader, nPacketSize);

			if (pPacketHeader->nCheckSum != nCheckSum) {
				static int nLogCount = 0;
				if (nLogCount++ < 100) {	// Log Flooding 방지
					mlog("MMatchClient::ParseUDPPacket() -> CHECKSUM ERROR(R=%u/C=%u)\n", 
						pPacketHeader->nCheckSum, nCheckSum);
				}
				return;
			} else {
				MCommand* pCmd = new MCommand();

				int nCmdSize = nPacketSize - sizeof(MPacketHeader);

				if (!m_PeerPacketCrypter.Decrypt(pData, nCmdSize))
				{
					mlog("MMatchClient::ParseUDPPacket() -> Decrypt Error\n");

					delete pCmd; pCmd = NULL;
					return;
				}

				if (!pCmd->SetData(pData, &m_CommandManager))
				{
					// TODO: 여기 수정해야함.
					sockaddr_in Addr;
					Addr.sin_addr.S_un.S_addr = dwIP;
					Addr.sin_port = nPort;
					char* pszIP = inet_ntoa(Addr.sin_addr);

					mlog("MMatchClient::ParseUDPPacket() -> MSGID_COMMAND SetData Error(%s:%d), size=%d\n", 
						pszIP, nPort, nCmdSize);

					delete pCmd; pCmd = NULL;
					return;
				}

				MUID uidPeer = FindPeerUID(dwIP, nPort);
				if (uidPeer != MUID(0,0)) {
					pCmd->m_Sender = uidPeer;
				} else {
					// Agent와는 암호화된 커맨드는 사용하지 않는다.
					delete pCmd;
					return;
/*
					// TODO: 여기 수정해야함.
					sockaddr_in Addr;
					Addr.sin_addr.S_un.S_addr = dwIP;
					Addr.sin_port = nPort;
					char* pszIP = inet_ntoa(Addr.sin_addr);

					if (strcmp(pszIP, GetAgentIP()) == 0) {
						pCmd->m_Sender = GetAgentServerUID();
					}else {
						delete pCmd; pCmd = NULL;
						return;
					}
*/
				}

				pCmd->m_Receiver = m_This;

				if( IsUDPCommandValidationCheck(pCmd->GetID()) ) {
					LockRecv();				
					m_CommandManager.Post(pCmd);
					UnlockRecv();
				} else {
#ifdef _DEBUG
					mlog("%s(ID:%d) is Denied Command!\n"
						, pCmd->m_pCommandDesc->GetName(), pCmd->GetID());
#endif
				}
			}
		}
		break;
	default:
		{
			Log("MatchClient: Parse Packet Error");
		}
		break;
	}
}