本文整理汇总了C++中NetworkMessage::WriteBytes方法的典型用法代码示例。如果您正苦于以下问题:C++ NetworkMessage::WriteBytes方法的具体用法?C++ NetworkMessage::WriteBytes怎么用?C++ NetworkMessage::WriteBytes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetworkMessage
的用法示例。
在下文中一共展示了NetworkMessage::WriteBytes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: acceptMsg
///---------------------------------------------------------------------------------
/// Join Request
///---------------------------------------------------------------------------------
NETWORK_MESSAGE_DEFINITION_WITH_OPTIONS( MSG_TYPE_JOIN_REQUEST, MO_RELIABLE )
{
DeveloperConsole::WriteLine( "Join request from " + sender.m_addr.GetAddrStr(), INFO_TEXT_COLOR );
char* id = nullptr;
msg.ReadString( id );
AddConnectionResult result = ACR_DENIED;
NetworkConnection* conn = sender.m_session->AddConnection( sender.m_addr, std::string( id ), result );
if (conn && result == ACR_ACCEPTED)
{
NetworkMessage acceptMsg( MSG_TYPE_JOIN_ACCEPT );
uint8_t maxConnections = (uint8_t) sender.m_session->GetMaxConnections();
acceptMsg.WriteBytes( (void*)&maxConnections, sizeof( maxConnections ) );
uint8_t connIdx = conn->GetConnectionIndex();
acceptMsg.WriteBytes( (void*)&connIdx, sizeof( connIdx ) );
uint8_t hostIdx = 0;
acceptMsg.WriteBytes( (void*)&hostIdx, sizeof( hostIdx ) );
std::string hostID = sender.m_session->GetHost()->GetUniqueID();
acceptMsg.WriteString( hostID.c_str() );
uint8_t invalidIdx = CONNECTION_INVALID_INDEX;
acceptMsg.WriteBytes( (void*)&invalidIdx, sizeof( invalidIdx ) );
conn->AddMessage( acceptMsg );
}
else
{
uint8_t denyReason;
NetworkMessage* denyMsg = new NetworkMessage( MSG_TYPE_JOIN_DENY );
switch (result)
{
case ACR_DENIED:
denyReason = 0;
break;
case ACR_FULL:
denyReason = 1;
break;
case ACR_ID_TAKEN:
denyReason = 2;
break;
default:
break;
}
denyMsg->WriteBytes( (void*)&denyReason, sizeof( denyReason ) );
sender.m_session->SendDirectMessage( denyMsg, &sender.m_addr );
}
}