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


C++ NetworkMessage类代码示例

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


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

示例1: sendInventory

void ProtocolGameBase::sendInventory()
{
	std::map<uint16_t, uint16_t> items = player->getAllItemsClientId();

	NetworkMessage msg;
	msg.addByte(0xF5);
	msg.add<uint16_t>(items.size() + 11);

	for (uint16_t i = 1; i <= 11; i++) {
		msg.add<uint16_t>(i);
		msg.addByte(0);
		msg.add<uint16_t>(1);

	}

	for (const auto& it : items) {
		msg.add<uint16_t>(it.first);
		msg.addByte(0);
		msg.add<uint16_t>(it.second);

	}

	writeToOutputBuffer(msg);

}
开发者ID:samuel2498,项目名称:nowy,代码行数:25,代码来源:protocolgamebase.cpp

示例2: SendMessage

	void SendMessage(MessageConnection *connection)
	{
		NetworkMessage *msg = connection->StartNewMessage(191 /*A custom message number*/, 
		                                                  4 + extraBytes + 4 /*size of this message in bytes*/);
		msg->priority = 100;
		msg->reliable = true;
		msg->inOrder = true;
		msg->contentID = 1;
		DataSerializer ds(msg->data, msg->Size());
		++lastMessageNumber;
		ds.Add<u32>(lastMessageNumber);

		u32 checksum = 0;
		for(int i = 0; i < extraBytes; ++i)
		{
			u8 byte = (u8)rand();
			ds.Add<u8>(byte);

			// Just run some bit-twiddling algorithm over all the bits to generate a checksum.
			checksum ^= byte;
			checksum <<= NumBitsSet(byte);
		}
		ds.Add<u32>(checksum);
		connection->EndAndQueueMessage(msg);
	}
开发者ID:aoighost,项目名称:kNet,代码行数:25,代码来源:InOrderTest.cpp

示例3: TEST_F

TEST_F(NetworkTest, SendMessageWhenMessageIsTooLong) {
  NetworkMessage message;
  message.resize(256);
  NetworkPtr network = Network::Create(system);

  EXPECT_THROW(network->SendMessage(13, message), exception::detail::MessageTooLongException);
}
开发者ID:chyla,项目名称:pat-lms,代码行数:7,代码来源:network.cpp

示例4: parseFirstPacket

bool ProtocolOld::parseFirstPacket(NetworkMessage& msg)
{
	if(g_game.getGameState() == GAME_STATE_SHUTDOWN)
	{
		getConnection()->closeConnection();
		return false;
	}

	/*uint16_t clientOS =*/ msg.GetU16();
	uint16_t version = msg.GetU16();
	msg.SkipBytes(12);

	if(version <= 760)
		disconnectClient(0x0A, "Only clients with protocol " CLIENT_VERSION_STR " allowed!");

	if(!RSA_decrypt(msg))
	{
		getConnection()->closeConnection();
		return false;
	}

	uint32_t key[4];
	key[0] = msg.GetU32();
	key[1] = msg.GetU32();
	key[2] = msg.GetU32();
	key[3] = msg.GetU32();
	enableXTEAEncryption();
	setXTEAKey(key);

	if(version <= 822)
		disableChecksum();

	disconnectClient(0x0A, "Only clients with protocol " CLIENT_VERSION_STR " allowed!");
	return false;
}
开发者ID:CkyLua,项目名称:tfs,代码行数:35,代码来源:protocolold.cpp

示例5: sendChannel

void ProtocolGameBase::sendChannel(uint16_t channelId, const std::string& channelName, const UsersMap* channelUsers, const InvitedMap* invitedUsers)
{
	NetworkMessage msg;
	msg.addByte(0xAC);

	msg.add<uint16_t>(channelId);
	msg.addString(channelName);

	if (channelUsers) {
		msg.add<uint16_t>(channelUsers->size());
		for (const auto& it : *channelUsers) {
			msg.addString(it.second->getName());
		}
	} else {
		msg.add<uint16_t>(0x00);
	}

	if (invitedUsers) {
		msg.add<uint16_t>(invitedUsers->size());
		for (const auto& it : *invitedUsers) {
			msg.addString(it.second->getName());
		}
	} else {
		msg.add<uint16_t>(0x00);
	}
	writeToOutputBuffer(msg);
}
开发者ID:samuel2498,项目名称:nowy,代码行数:27,代码来源:protocolgamebase.cpp

示例6: AllocMessage

void RMENet::OnReceivePing(NetworkMessage *nmsg)
{
	// Send pong
	NetworkMessage* omsg = AllocMessage();
	omsg->AddByte(0x02);
	connection->Send(omsg);
}
开发者ID:TheSumm,项目名称:rme,代码行数:7,代码来源:rme_net.cpp

示例7: switch

	NetworkMessage* NetworkMessage::DeserializePacket( OS::StreamReader& s)
	{
		byte d[4];
		s.read(d, 4);
		NetworkMessageType v=(NetworkMessageType)core::BitConverter::ToUInt32(d);
		NetworkMessage* ret = 0;
		switch (v)
		{
		case NetworkMessageType::SpeedChange:
			ret = new SpeedChangeMessage();
			break;
		case NetworkMessageType::HeadChange:
			ret = new HeadChangeMessage();
			break;
		case NetworkMessageType::Stop:
			ret = new StopMessage();
			break;
		case NetworkMessageType::VideoImage:
			ret = new VideoImageMessage();
			break;
		}
		if (ret != 0)
			if(!ret->Deserialize(s))
			{
				delete ret;
				ret=0;
			}
		return ret;
	}
开发者ID:yingzhang536,项目名称:mrayy-Game-Engine,代码行数:29,代码来源:NetworkMessages.cpp

示例8: LOG

void NetworkServer::BroadcastMessage(unsigned long id, bool reliable, bool inOrder, unsigned long priority, 
                                     unsigned long contentID, const char *data, size_t numBytes,
                                     MessageConnection *exclude)
{
	PolledTimer timer;
	Lockable<ConnectionMap>::LockType clientsLock = clients.Acquire();
	if (timer.MSecsElapsed() >= 50.f)
	{
		LOG(LogWaits, "NetworkServer::BroadcastMessage: Accessing the connection list took %f msecs.",
			timer.MSecsElapsed());
	}

	for(ConnectionMap::iterator iter = clientsLock->begin(); iter != clientsLock->end(); ++iter)
	{
		MessageConnection *connection = iter->second;
		assert(connection);
		if (connection == exclude || !connection->IsWriteOpen())
			continue;

		NetworkMessage *msg = connection->StartNewMessage(id, numBytes);
		msg->reliable = reliable;
		msg->inOrder = inOrder;
		msg->priority = priority;
		msg->contentID = contentID;
		assert(msg->data);
		assert(msg->Size() == numBytes);
		memcpy(msg->data, data, numBytes);
		connection->EndAndQueueMessage(msg);
	}
}
开发者ID:AGreatFish,项目名称:Urho3D,代码行数:30,代码来源:NetworkServer.cpp

示例9: recvFrom

/*! Receive a NetworkMessage. Workes like recv, but buffer and size is
    taken from the NetworkMessage
    \see Socket::recv
 */
int DgramSocket::recvFrom(NetworkMessage &msg,SocketAddress &from)
{
    NetworkMessage::Header hdr;
    peek(&hdr,sizeof(hdr));
    msg.setSize(osgntohl(hdr.size));
    return recvFrom(msg.getBuffer(),msg.getSize(),from);
}
开发者ID:mlimper,项目名称:OpenSG1x,代码行数:11,代码来源:OSGDgramSocket.cpp

示例10: AllocateNewMessage

NetworkMessage *MessageConnection::StartNewMessage(unsigned long id, size_t numBytes)
{
    NetworkMessage *msg = AllocateNewMessage();
    if (!msg)
    {
        LOG(LogError, "MessageConnection::SendMessage: StartNewMessage failed! Discarding message send.");
        return 0; // Failed to allocate a new message. This is caused only by memory allocation issues.
    }

    msg->id = id;
    msg->reliable = false;
    msg->contentID = 0;
    msg->obsolete = false;

    // Give the new message the lowest priority by default.
    msg->priority = 0;

    // By default, the message is not fragmented. Later when admitting the message into the send queue, the need for
    // fragmentation is examined and this field will be updated if needed.
    msg->transfer = 0;

#ifdef KNET_NETWORK_PROFILING
    msg->profilerName = "";
#endif

    msg->Resize(numBytes);

    return msg;
}
开发者ID:r8d8,项目名称:Urho3D,代码行数:29,代码来源:MessageConnection.cpp

示例11: parseSpectatorSay

void ProtocolSpectator::parseSpectatorSay(NetworkMessage& msg)
{
	SpeakClasses type = (SpeakClasses)msg.getByte();
	uint16_t channelId = 0;

	if (type == TALKTYPE_CHANNEL_Y) {
		channelId = msg.get<uint16_t>();
	} else {
		return;
	}

	const std::string text = msg.getString();

	if (text.length() > 255 || channelId != CHANNEL_CAST || !client) {
		return;
	}

	if (client) {
		if (client->isSpectatorMuted(spectatorId)) {
			sendTextMessage(TextMessage(MESSAGE_STATUS_SMALL, "You have been muted."));
			return;
		}

		if (parseCoomand(text)) {
			return;
		}

		g_dispatcher.addTask(createTask(std::bind(&ProtocolCaster::broadcastSpectatorMessage, client, spectatorName, text)));
	}
}
开发者ID:comedinha,项目名称:New-Poke-Lite,代码行数:30,代码来源:protocolspectator.cpp

示例12: respond_nack

void UdpMulticastChannel::respond_nack(const NackMessage& nack_msg )
{
    NetworkMessage* msg = outgoing->get_message(NetworkChannel::get_host_name(),nack_msg.message_num());
    for(int i = 0; i < nack_msg.missing_packets_size(); i++)
        this->sender->sync_send(msg->get_packet(nack_msg.missing_packets(i))->SerializeAsString());

}
开发者ID:vagvaz,项目名称:Narukom,代码行数:7,代码来源:udp_multicast_channel.cpp

示例13: newsoul

void
newsoul::DistributedSocket::onMessageReceived(const MessageData * data)
{
    if (m_DataTimeout.isValid())
        newsoul()->reactor()->removeTimeout(m_DataTimeout);

  switch(data->type)
  {
    #define MAP_MESSAGE(ID, TYPE, EVENT) \
      case ID: \
      { \
        NNLOG("newsoul.messages.distributed", "Received distributed message " #TYPE "."); \
        TYPE msg; \
        msg.setDistributedSocket(this); \
        msg.parse_network_packet(data->data, data->length); \
        EVENT(&msg); \
        break; \
      }
    #include "distributedeventtable.h"
    #undef MAP_MESSAGE

    default:
        NNLOG("newsoul.distrib.warn", "Received unknown distributed message, type: %u, length: %u", data->type, data->length);
        NetworkMessage msg;
        msg.parse_network_packet(data->data, data->length);
  }
}
开发者ID:KenjiTakahashi,项目名称:newsoul,代码行数:27,代码来源:distributedsocket.cpp

示例14: onRecvFirstMessage

void ProtocolOld::onRecvFirstMessage(NetworkMessage& msg)
{
	if(g_game.getGameState() == GAMESTATE_SHUTDOWN)
	{
		getConnection()->close();
		return;
	}

	msg.skip(2);
	uint16_t version = msg.get<uint16_t>();

	msg.skip(12);
	if(version <= 760)
		disconnectClient(0x0A, "Only clients with protocol " CLIENT_VERSION_STRING " allowed!");

	if(!RSA_decrypt(msg))
	{
		getConnection()->close();
		return;
	}

	uint32_t key[4] = {msg.get<uint32_t>(), msg.get<uint32_t>(), msg.get<uint32_t>(), msg.get<uint32_t>()};
	enableXTEAEncryption();
	setXTEAKey(key);

	if(version <= 822)
		disableChecksum();

	disconnectClient(0x0A, "Only clients with protocol " CLIENT_VERSION_STRING " allowed!");
}
开发者ID:A-Syntax,项目名称:crystalserver,代码行数:30,代码来源:protocolold.cpp

示例15: sendCancelWalk

void ProtocolGameBase::sendCancelWalk()
{
	NetworkMessage msg;
	msg.addByte(0xB5);
	msg.addByte(player->getDirection());
	writeToOutputBuffer(msg);
}
开发者ID:samuel2498,项目名称:nowy,代码行数:7,代码来源:protocolgamebase.cpp


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