Exemple #1
0
int SOCK_SendPacket(SOCKET socket, Packet& packet, unsigned long protover, bool extended)
{
	if(!extended)
	{
		if(!packet.GetLength()) return 0;
		uint8_t* data = new uint8_t[packet.GetLength()];
		uint32_t size = packet.GetLength();
		std::vector<uint8_t> tbuf = packet.GetBuffer();
		for(uint32_t i = 0; i < size; i++)
			data[i] = tbuf[i];

		int ret_code = send_msg(socket, protover, data, size, 1);
		delete[] data;
		if(ret_code == -2) return SERR_TIMEOUT;
		if(ret_code == -1) return SERR_CONNECTION_LOST;
		return 0;
	}
	else
	{
		uint8_t* data = new uint8_t[packet.GetLength()+8];
		*(uint32_t*)(data) = packet.GetLength();
		*(uint32_t*)(data+4) = 0x80100000;
		std::vector<uint8_t> tbuf = packet.GetBuffer();
		for(uint32_t i = 0; i < packet.GetLength(); i++)
			data[i+8] = tbuf[i];

		int ret_code = send(socket, (const char*)data, packet.GetLength()+8, 0);
		delete[] data;
		if(ret_code == -1) return SERR_CONNECTION_LOST;
		return 0;
	}
}
    void LoginClientConn::UserLogout(const string &user_id) {
        proto::IMServerUserLogoutRequest logout_req;
        logout_req.set_user_id(user_id);

        Packet packet;
        PacketSetPBMsg(&packet, &logout_req);
        packet.SetVersion(IM_PROTO_VERSION);
        packet.SetServiceId(proto::SID_SERVER);
        packet.SetCommandId(proto::CID_SERVER_REQ_USERLOGOUT);
        // TODO seq num
        packet.SetSeqNum(0);

        // TODO can add to wait for logout ack list
        Send(packet.GetBuffer(), packet.GetLength());
    }
Exemple #3
0
bool CarModel::ReceivePacket(Packet * packet)
{
	std::map<in_addr_t, std::vector<SafetyPacket> >::iterator iterMessage;
	bool bValid = false;
	Packet * pNewPacket;

	packet->m_ID.iRXSeqNumber = GetNextRXSequenceNumber();
	if (m_pPhysModel != NULL && m_pPhysModel->ReceivePacket(packet))
	{
		if (m_pLinkModel != NULL && m_pLinkModel->ReceivePacket(packet))
		{
			unsigned int iBytesPerSec = GetTXRate();
			pNewPacket = packet->clone();
			struct timeval tTransmit = iBytesPerSec > 0 ? MakeTime((double)pNewPacket->GetLength() / iBytesPerSec) : timeval0;
			g_pSimulator->m_EventQueue.AddEvent(SimEvent(pNewPacket->m_tRX - tTransmit, EVENT_PRIORITY_HIGHEST, QString::null, m_strModelName, EVENT_CARMODEL_RXMESSAGEBEGIN, pNewPacket, DestroyPacket));
			bValid = true;
		}
	}

	return bValid;
}
Exemple #4
0
	void Client::SendPacket(Packet &packet)
	{
		ENetPacket *enetPacket = enet_packet_create(packet.GetData(), packet.GetLength(), ENET_PACKET_FLAG_RELIABLE);
		enet_peer_send(_peer, 0, enetPacket);
	}