当前位置: 首页>>代码示例>>C++>>正文


C++ CNetMsg::GetWrite方法代码示例

本文整理汇总了C++中CNetMsg::GetWrite方法的典型用法代码示例。如果您正苦于以下问题:C++ CNetMsg::GetWrite方法的具体用法?C++ CNetMsg::GetWrite怎么用?C++ CNetMsg::GetWrite使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CNetMsg的用法示例。


在下文中一共展示了CNetMsg::GetWrite方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: SetBroadcastResponse

	bool CServer::SetBroadcastResponse(CNetMsg& msg)
	{
		//Early Out
		if (this->m_pRak == NULL)
			return false;
		//Response can't be over 400 bytes
		if (msg.GetWrite() > 400)
			return false;

		this->m_pRak->SetOfflinePingResponse(msg.GetData(), msg.GetWrite());
		return true;
	}
开发者ID:kingnobody8,项目名称:fs.armada,代码行数:12,代码来源:Server.cpp

示例2: send_msg

	bool CServer::send_msg(CNetMsg& msg, const TPeer& dest, const PacketPriority& prio, const PacketReliability& reli)
	{
		//Early Out
		if (this->m_pRak == NULL)
			return false;

		//Duplicate to all clients
		if (dest.m_scID == -1)
		{
			ulong size = this->m_vClients.size();
			for (ulong i = 0; i < size; ++i)
			{
				if (!this->send_msg(msg, this->m_vClients[i], prio, reli))
					return false;
			}
			return true;
		}

		//Parse msg to bitstream
		RakNet::BitStream stream;
		RakNet::Time timeStamp = RakNet::GetTime();
		stream.Write(RakNet::MessageID(ID_TIMESTAMP));
		stream.Write(timeStamp);
		stream.Write(RakNet::MessageID(msg.GetType()));
		stream.Write(msg.GetData(), msg.GetWrite());

#if DB_NET_MSG_SR
		printf("S : Sending Msg to: \t\t\t%s\n", dest.m_Addr.ToString());
		printf("  : Client #%d\n", dest.m_scID);
		printf("  : Msg Type:\t%s\n", ENetMsgStr(msg.GetType()));
		printf("  : Msg Size:\t%d\n", msg.GetWrite());
		printf("  : Msg Time:\t%d\n", timeStamp);
#endif

		return this->m_pRak->Send(&stream, prio, reli, 0, dest.m_Guid, false) != 0;
	}
开发者ID:kingnobody8,项目名称:fs.armada,代码行数:36,代码来源:Server.cpp

示例3: parse_msg

	bool CServer::parse_msg(RakNet::Packet* packet)
	{
#pragma region DEBUG_OUTPUT
#if DB_NET_MSG_CNT
		switch (packet->data[0])
		{
		case ID_NEW_INCOMING_CONNECTION:{
											printf("S : Incoming Connection from: \t\t%s\n", packet->systemAddress.ToString());
											break; }
		case ID_DISCONNECTION_NOTIFICATION:{
											   printf("S : Disconnection from: \t\t%s\n", packet->systemAddress.ToString());
											   break; }
		case ID_CONNECTION_LOST:{
									printf("S : Lost Connection from: \t\t%s\n", packet->systemAddress.ToString());
									break; }
		case ID_UNCONNECTED_PING:{
									 printf("S : Received Ping Broadcast from: \t%s\n", packet->systemAddress.ToString());
									 break; }
		case ID_TIMESTAMP:{
							  printf("S : Received Msg from: \t\t\t%s\n", packet->systemAddress.ToString());
							  break;	}
		default: {
					 printf("S : Received Identifier %i from: \t\t%s\n", packet->data[0], packet->systemAddress.ToString());
					 break; }
		}
#endif
#pragma endregion
		
		//Set Msg Type
		CNetMsg msg = CNetMsg(ENetMsg(packet->data[0]));

		//If connecting client then give an id
		if (packet->data[0] == ID_NEW_INCOMING_CONNECTION)
		{
			this->connect_client(packet);
		}

		//Get Peer Data
		TPeer peer;
		peer.m_Addr = packet->systemAddress;
		peer.m_Guid = packet->guid;
		ulong size = this->m_vClients.size();
		for (ulong i = 0; i < size; ++i)
		{
			if (this->m_vClients[i].m_Guid == peer.m_Guid)
			{
				peer.m_scID = schar(i);
				break;
			}
		}
		msg.SetPeer(peer);

		//If user type, then get data
		if (packet->data[0] == ID_TIMESTAMP)
		{
			//Get the header parts of the packet
			RakNet::BitStream		bsIn(packet->data, packet->length, false);
			uchar					useTimeStamp;
			RakNet::Time			timeStamp;
			uchar					typeID;
			//Read them in
			bsIn.Read((RakNet::MessageID)useTimeStamp);
			bsIn.Read(timeStamp);
			bsIn.Read((RakNet::MessageID)typeID);
			ulong offset = bsIn.GetReadOffset() / 8;
			//Parse into a CNetMsg
			msg.SetType(ENetMsg(typeID));
			msg.WriteRaw((const char*)(packet->data + offset), ushort(packet->length - offset));
			msg.SetTime(timeStamp);
#if DB_NET_MSG_SR
			printf("  : Client #%d\n", peer.m_scID);
			printf("  : Msg Type:\t%s\n", ENetMsgStr(msg.GetType()));
			printf("  : Msg Size:\t%d\n", msg.GetWrite());
			printf("  : Msg Time:\t%d\n", msg.GetTime());
#endif
		}

		//Add msg to vector
		this->m_vMsgs.push_back(msg);
		return true;
	}
开发者ID:kingnobody8,项目名称:fs.armada,代码行数:81,代码来源:Server.cpp


注:本文中的CNetMsg::GetWrite方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。