本文整理汇总了C++中NetworkPacket::WriteData方法的典型用法代码示例。如果您正苦于以下问题:C++ NetworkPacket::WriteData方法的具体用法?C++ NetworkPacket::WriteData怎么用?C++ NetworkPacket::WriteData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetworkPacket
的用法示例。
在下文中一共展示了NetworkPacket::WriteData方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: HandleMsg
void GossipHandler::HandleMsg( NetworkPacket & recv_data, GameClient *pClient )
{
NetworkPacket data;
char f[256];
sprintf(f, "WORLD: Gossip Opcode 0x%.4X", recv_data.opcode);
Log::getSingleton( ).outString( f );
switch (recv_data.opcode)
{
case CMSG_GOSSIP_HELLO:
{
uint16 tSize,i;
uint32 TextID;
guid cguid;
recv_data >> cguid.sno >> cguid.type;
TextID = getTextID(cguid.sno);
if(TextID == 0)
{
//text Id 0 don't exist so maybe they don't want to talk :P
data.Initialize( 8 , SMSG_NPC_WONT_TALK );
data << cguid.sno << cguid.type;
pClient->SendMsg (&data);
break;
}
//TextRelation * pRelation = getTextRelation(cguid.sno);
NPCText * theText = getNPCText(TextID);
//Calculate the size
tSize = 20 + (8*theText->m_OptionCount);
TextOption * theOption;
for(i = 1; i <= theText->m_OptionCount;i++)
{
// add option textsize to the size
theOption = getTextOption(theText->m_OptionID[i]);
tSize += strlen((char *)theOption->m_OptionText.c_str())+1;
}
//Create the Packet
data.Initialize( tSize, SMSG_GOSSIP_MESSAGE );
data << cguid.sno << cguid.type;
data << (uint32)TextID; //TextID
data << (uint32)theText->m_OptionCount; // Bullet Points Count
for(i = 1; i <= theText->m_OptionCount;i++)
{
theOption = getTextOption(theText->m_OptionID[i]);
data << (uint32)theOption->m_OptionID; //Bullet Point Number
data << (uint32)theOption->m_OptionIconID; //Bullet Point IconID
//option text
data.WriteData(theOption->m_OptionText.c_str() , strlen((char *)theOption->m_OptionText.c_str())+1 );
}
data << (uint32)0;
pClient->SendMsg (&data);
//pClient->getCurrentChar()->setUpdateValue(CORPSE_FIELD_ITEM3, 6947);
//pClient->getCurrentChar()->setUpdateValue(CORPSE_FIELD_ITEM4, (uint32)0xf0001000 );
//pClient->getCurrentChar()->UpdateObject();
}break;
case CMSG_GOSSIP_SELECT_OPTION:
{
uint32 option;
guid cguid;
recv_data >> cguid.sno >> cguid.type;
recv_data >> option;
TextOption * theOption;
theOption = getTextOption(option);
// Textid of 0 is Reserved for exiting and SH Comfirm
if(theOption->m_TextID == 0)
{
Unit *pSelection = world.GetValidCreature(cguid.sno);
if(pSelection != 0)
{
//if the selection is a spirit healer
if(pSelection->getUpdateValue(UNIT_NPC_FLAGS) == 32)
{
// Sh Accept Dialog
data.Initialize(8,SMSG_SPIRIT_HEALER_CONFIRM);
data << cguid.sno << cguid.type;
pClient->SendMsg( &data );
}
}
//close the Gossip Window
data.Initialize(0,SMSG_GOSSIP_COMPLETE);
pClient->SendMsg( &data );
break;
}
uint16 TextID,tSize,i;
//get the Text ID
TextID = theOption->m_TextID;
//get the Related text info
NPCText * theText = getNPCText(TextID);
//calculate our size
tSize = 20 + (8*theText->m_OptionCount);
for(i = 1; i <= theText->m_OptionCount;i++)
{
//get each options text and add it to the size
theOption = getTextOption(theText->m_OptionID[i]);
tSize += strlen((char *)theOption->m_OptionText.c_str())+1;
//.........这里部分代码省略.........