本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例6: AllocMessage
void RMENet::OnReceivePing(NetworkMessage *nmsg)
{
// Send pong
NetworkMessage* omsg = AllocMessage();
omsg->AddByte(0x02);
connection->Send(omsg);
}
示例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;
}
示例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);
}
}
示例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);
}
示例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;
}
示例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)));
}
}
示例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());
}
示例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);
}
}
示例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!");
}
示例15: sendCancelWalk
void ProtocolGameBase::sendCancelWalk()
{
NetworkMessage msg;
msg.addByte(0xB5);
msg.addByte(player->getDirection());
writeToOutputBuffer(msg);
}