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


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

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


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

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