本文整理汇总了C++中Msg::GetLength方法的典型用法代码示例。如果您正苦于以下问题:C++ Msg::GetLength方法的具体用法?C++ Msg::GetLength怎么用?C++ Msg::GetLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Msg
的用法示例。
在下文中一共展示了Msg::GetLength方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SendRefMsg
void CBaseObj::SendRefMsg(Msg &pMsg)
{
assert(m_GateIDMax < gateinfo_count);
for (int i = m_GateIDMin; i <= m_GateIDMax; ++i)
{
gateinfo[i]->Reset();
}
static bool bNeeSendMsg = false;
static msgtail tail;
std::unordered_map<uint32, CBaseObj *> *playerlist = GetAoiList();
std::unordered_map<uint32, CBaseObj *>::iterator iter = playerlist->begin();
for (; iter != playerlist->end(); ++iter)
{
if (iter->second->IsPlayer())
{
CPlayer * p = (CPlayer *)iter->second;
if (FuncUti::isValidCret(p))
{
int32 gateid = p->GetGateID();
if (gateid >= 0 && gateid < gateinfo_count)
{
if (gateid > m_GateIDMax)
{
m_GateIDMax = gateid;
}
else if (gateid < m_GateIDMin)
{
m_GateIDMin = gateid;
}
if (gateinfo[gateid]->gate == nullptr)
{
gateinfo[gateid]->gate = p->GetGateInfo();
}
gateinfo[gateid]->nClientId[gateinfo[gateid]->nCount] = p->GetClientID();
gateinfo[gateid]->nCount += 1;
}
}
}
}
static bool bIsPlayer = false;
bIsPlayer = IsPlayer();
if (bNeeSendMsg || bIsPlayer)
{
if (bIsPlayer)
{
CPlayer *p = (CPlayer *)this;
int32 gateid = p->GetGateID();
if (gateid >= 0 && gateid < gateinfo_count)
{
if (gateid > m_GateIDMax)
{
m_GateIDMax = gateid;
}
else if (gateid < m_GateIDMin)
{
m_GateIDMin = gateid;
}
if (gateinfo[gateid]->gate == nullptr)
{
gateinfo[gateid]->gate = p->GetGateInfo();
}
gateinfo[gateid]->nClientId[gateinfo[gateid]->nCount] = p->GetClientID();
gateinfo[gateid]->nCount += 1;
}
}
bNeeSendMsg = false;
MessagePack pkmain;
pkmain.PushInt32(pMsg.GetLength());
pkmain.PushBlock(&pMsg, pMsg.GetLength());
int32 pkmainlen = pkmain.GetLength();
for (int i = m_GateIDMin; i < m_GateIDMax; ++i)
{
if (gateinfo[i]->nCount > 0)
{
tail.id = 0;
for (int j = 0; j < gateinfo[i]->nCount; ++j)
{
pkmain.PushInt32(gateinfo[i]->nClientId[j]);
--tail.id;
}
GameGatewayMgr.SendMsg(gateinfo[i]->gate, pkmain, &tail, sizeof(tail));
pkmain.SetLength(pkmainlen);
pkmain.m_index = pkmainlen - (int32)sizeof(Msg);
}
}
}
}
示例2: LogMessage
//.........这里部分代码省略.........
sequence |= 0x10; // Sequenced, first frame
}
if( payload->m_part == 2 )
{
sequence = m_sequenceCounter & 0x0f;
sequence |= 0x30; // Sequenced, second frame
}
/* at most, the payload will be 28 bytes + 1 byte for the Sequence. */
uint8 plaintextmsg[32];
plaintextmsg[0] = sequence;
for (int i = 0; i < payload->m_length; i++)
plaintextmsg[i+1] = payload->m_data[i];
/* Append the message payload after encrypting it with AES-OFB (key is EncryptPassword,
* full IV (16 bytes - 8 Random and 8 NONCE) and payload.m_data
*/
PrintHex("Input Packet:", plaintextmsg, payload->m_length+1);
#ifdef DEBUG
PrintHex("IV:", initializationVector, 16);
#endif
uint8 encryptedpayload[30];
aes_mode_reset(this->EncryptKey);
if (aes_ofb_encrypt(plaintextmsg, encryptedpayload, payload->m_length+1, initializationVector, this->EncryptKey) == EXIT_FAILURE) {
Log::Write(LogLevel_Warning, GetNodeId(), "Failed to Encrypt Packet");
delete msg;
return false;
}
#ifdef DEBUG
PrintHex("Encrypted Output", encryptedpayload, payload->m_length+1);
/* The Following Code attempts to Decrypt the Packet and Verify */
/* the first 8 bytes of a outgoing IV are random */
for (int i = 0; i < 8; i++) {
//initializationVector[i] = (rand()%0xFF)+1;
initializationVector[i] = 0xAA;
}
/* the remaining 8 bytes are the NONCE we got from the device */
for (int i = 0; i < 8; i++) {
initializationVector[8+i] = _nonce[i];
}
aes_mode_reset(this->EncryptKey);
uint8 tmpoutput[16];
if (aes_ofb_encrypt(encryptedpayload, tmpoutput, payload->m_length+1, initializationVector, this->EncryptKey) == EXIT_FAILURE) {
Log::Write(LogLevel_Warning, GetNodeId(), "Failed to Encrypt Packet");
delete msg;
return false;
}
PrintHex("Decrypted output", tmpoutput, payload->m_length+1);
#endif
for(int i=0; i<payload->m_length+1; ++i )
{
msg->Append( encryptedpayload[i] );
}
// Append the nonce identifier :)
msg->Append(_nonce[0]);
/* Append space for the authentication data Set with AES-CBCMAC (key is AuthPassword,
* Full IV (16 bytes - 8 random and 8 NONCE) and sequence|SrcNode|DstNode|payload.m_length|payload.m_data
*
*/
/* Regenerate IV */
/* the first 8 bytes of a outgoing IV are random */
for (int i = 0; i < 8; i++) {
//initializationVector[i] = (rand()%0xFF)+1;
initializationVector[i] = 0xAA;
}
/* the remaining 8 bytes are the NONCE we got from the device */
for (int i = 0; i < 8; i++) {
initializationVector[8+i] = _nonce[i];
}
uint8 mac[8];
this->GenerateAuthentication(&msg->GetBuffer()[7], msg->GetLength()+2, GetDriver()->GetNodeId(), GetNodeId(), initializationVector, mac);
for(int i=0; i<8; ++i )
{
msg->Append( mac[i] );
}
#ifdef DEBUG
PrintHex("Auth", mac, 8);
#endif
msg->Append( GetDriver()->GetTransmitOptions() );
#ifdef DEBUG
PrintHex("Outgoing", msg->GetBuffer(), msg->GetLength());
#endif
GetDriver()->SendMsg(msg, Driver::MsgQueue_Security);
/* finally, if the message we just sent is a NetworkKeySet, then we need to reset our Network Key here
* as the reply we will get back will be encrypted with the new Network key
*/
if ((this->m_networkkeyset == false) && (payload->m_data[0] == 0x98) && (payload->m_data[1] == 0x06)) {
Log::Write(LogLevel_Info, GetNodeId(), "Reseting Network Key after Inclusion");
this->m_networkkeyset = true;
SetupNetworkKey();
}
delete payload;
return true;
}