本文整理汇总了C++中NetworkMessage::parse_network_packet方法的典型用法代码示例。如果您正苦于以下问题:C++ NetworkMessage::parse_network_packet方法的具体用法?C++ NetworkMessage::parse_network_packet怎么用?C++ NetworkMessage::parse_network_packet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetworkMessage
的用法示例。
在下文中一共展示了NetworkMessage::parse_network_packet方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
}
示例2: if
void
newsoul::HandshakeSocket::onMessageReceived(const MessageData * data)
{
switch(data->type)
{
case 0:
{
// Apparently, we requested somebody to connect to us.
NNLOG("newsoul.messages.handshake", "Received peer handshake message HPierceFirewall");
HPierceFirewall msg;
msg.parse_network_packet(data->data, data->length);
m_Token = msg.token;
receiveBuffer().seek(data->length + 5);
// Tell the peer manager, it should know more.
m_Newsoul->peers()->firewallPiercedEvent(this);
// This particular socket is no longer needed. Remove it from the reactor.
reactor()->remove(this);
return;
}
case 1:
{
// Somebody wants to establish a connection.
NNLOG("newsoul.messages.handshake", "Received peer handshake message HInitiate");
HInitiate msg;
msg.parse_network_packet(data->data, data->length);
NNLOG("newsoul.hand.debug", "HInitiate payload: %s %s %u", msg.user.c_str(), msg.type.c_str(), msg.token);
// Set some variables.
m_Token = msg.token;
m_User = msg.user;
// Seek past the message.
if (receiveBuffer().count() >= data->length + 5)
receiveBuffer().seek(data->length + 5);
else
receiveBuffer().clear();
if(msg.type == "P")
{
// Create a new PeerSocket which will copy our descriptor and state.
newsoul::PeerSocket * that = new newsoul::PeerSocket(this);
newsoul()->peers()->addPeerSocket(that);
// Add the newly constructed socket to the reactor.
reactor()->add(that);
}
else if(msg.type == "F")
{
// Create a new TicketSocket which will copy our descriptor and state.
newsoul::TicketSocket * that = new newsoul::TicketSocket(this);
// Add the newly constructed socket to the reactor.
reactor()->add(that);
// There may be some data waiting in the buffer (sent at connection). We have to ask the ticketsocket to check it.
that->findTicket();
}
else if(msg.type == "D")
{
// Create a new DistributedSocket which will copy our descriptor and state.
newsoul::DistributedSocket * that = new newsoul::DistributedSocket(this);
// A potential parent doesn't care about our position
if (!newsoul()->searches()->isPotentialParent(m_User))
that->sendPosition();
// Add the newly constructed socket to the reactor.
reactor()->add(that);
}
else
{
NNLOG("newsoul.hand.warn", "Invalid incoming connection type '%s'.", msg.type.c_str());
}
// Clear our receive buffer so we stop processing data.
receiveBuffer().clear();
// Remove this socket from the reactor as it's no longer needed.
reactor()->remove(this);
return;
}
default:
NNLOG("newsoul.hand.warn", "Received unknown peer handshake message, type: %u, length: %u", data->type, data->length);
NetworkMessage msg;
msg.parse_network_packet(data->data, data->length);
}
}