本文整理汇总了C++中NetworkPacket::Initialize方法的典型用法代码示例。如果您正苦于以下问题:C++ NetworkPacket::Initialize方法的具体用法?C++ NetworkPacket::Initialize怎么用?C++ NetworkPacket::Initialize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetworkPacket
的用法示例。
在下文中一共展示了NetworkPacket::Initialize方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: HandleMsg
void SpellHandler::HandleMsg( NetworkPacket & recv_data, GameClient *pClient )
{
NetworkPacket data;
NetworkPacket data2;
char f[256];
sprintf(f, "WORLD: Spell 0x%.4X", recv_data.opcode);
LOG.outString( f );
switch (recv_data.opcode)
{
case CMSG_USE_ITEM:
{
//printf("ok got opcode here %u\n", recv_data.length);
uint8 packslot,slot;
uint16 targets;
uint8 spell;
int datalen = recv_data.length;
recv_data >> packslot >> slot >> spell;
recv_data >> targets;
//if (targets == 0)
// return;
uint32 spellid;
//printf("recived data!\n");
//printf("Item ID - %d\nItem GUID - %d\n",pClient->getCurrentChar()->getItemIdBySlot(slot),pClient->getCurrentChar()->getGuidBySlot(slot));
Item *tmpItem = WORLDSERVER.GetItem( pClient->getCurrentChar()->getItemIdBySlot(slot) );
spellid = tmpItem->SpellID[spell - 1];
for(int i = 0;i < 5;i++)
{
//printf("spell number %d - %d\n",i,tmpItem->SpellID[i]);
}
data.Clear();
data.Initialize (datalen - 3 + 32, SMSG_SPELL_GO);
data << pClient->getCurrentChar()->GetGUID().sno << pClient->getCurrentChar()->GetGUID ().type;
data << pClient->getCurrentChar()->GetGUID().sno << pClient->getCurrentChar()->GetGUID ().type;
data << uint32(spellid);
data << uint8(0x00) << uint8(0x01);
if( targets & 0x2 || targets & 0x800 || targets & 0x8000 )
{
guid unitTarget;
recv_data >> unitTarget.sno >> unitTarget.type;
data << uint8(0x01);
data << unitTarget.sno << unitTarget.type;
data << uint8(0x00);
data << uint16(targets);
data << unitTarget.sno << unitTarget.type;
}
SpellInformation spellInfo;
//get a hook for the DB
DatabaseInterface *dbi = DATABASE.createDatabaseInterface();
//returns a SpellInformation object/struct
spellInfo = dbi->GetSpellInformation ( tmpItem->SpellID[0] );
DATABASE.removeDatabaseInterface( dbi ); //clean up used resources
if(spellInfo.spell_type == (uint32)POTIONS)
usePotion(pClient, tmpItem->SpellID[0], spellInfo, targets);
}break;
case CMSG_CAST_SPELL:
{
uint32 spell, target1, target2;
uint16 flags;
uint8 hitCount ,missCount;
recv_data >> spell >> flags;
guid pguid = pClient->getCurrentChar()->GetGUID();
SpellInformation spellInfo;
//get a hook for the DB
DatabaseInterface *dbi = DATABASE.createDatabaseInterface();
spellInfo = dbi->GetSpellInformation ( spell ); //returns a SpellInformation object/struct
DATABASE.removeDatabaseInterface( dbi ); //clean up used resources
//let's check spell type:
if( spellInfo.spell_type == (uint32)SINGLE_TARGET)
{
recv_data >> target1 >> target2;
printf("recv_data >> spell: %u\n", spell);
printf("recv_data >> flags: %u\n", flags);
Unit* pUnit_target = WORLDSERVER.GetCreature(target1);
if(pUnit_target)
{
if(spellInfo.race == 0 || pUnit_target->getRace() == spellInfo.race)
{
//if( > spellInfo.Range ){
data.Clear();
data.Initialize( 36, SMSG_SPELL_START );
data << pguid.sno << pguid.type << pguid.sno << pguid.type << spell;
data << flags << uint32 (3500) << flags << target1 << target2;
pClient->SendMsg( &data );
hitCount = 1;
missCount = 0;
data2.Clear();
//.........这里部分代码省略.........
示例2: HandleMsg
void ItemHandler::HandleMsg (NetworkPacket & recv_data, GameClient *pClient)
{
NetworkPacket data;
char f[ 256 ];
sprintf (f, "WORLDSERVER: Item Opcode 0x%.4X", recv_data.opcode);
LOG.outString (f);
switch (recv_data.opcode)
{
case CMSG_SWAP_INV_ITEM:
{
//ok i'm gonna do that a looootttt cleaner :/
uint8 srcslot, destslot;
recv_data >> srcslot >> destslot;
int slot = destslot;
//START OF LINA LVL REQUIREMENT SWAP PATCH
int8 CharLvl, ItemLvl;
//printf("ITEM: LVL TEST\n");
CharLvl=pClient->getCurrentChar()->getLevel();
ItemLvl=WORLDSERVER.GetItem(pClient->getCurrentChar()->getItemIdBySlot(srcslot))->RequiredLevel;
//printf("ITEM: CharLvl %d, ItemLvl %d\n", CharLvl, ItemLvl);
if (CharLvl < ItemLvl)
{
ChatHandler * MsgLvlItem = new ChatHandler;
if(MsgLvlItem !=NULL)
{
//NEED TO PUT SOME CODE TO UNGRAY ITEM
uint8 buf[256];
NetworkPacket data;
sprintf((char*)buf,"You need the Lvl %d to equip that item.", ItemLvl);
MsgLvlItem->FillMessageData(&data, 0x09, pClient, buf);
pClient->SendMsg (&data);
delete(MsgLvlItem);
}
else printf("ITEM: CMSG_SWAP_INV_ITEM can't send message\n");
return;
}
//END OF LINA LVL REQUIREMENT SWAP PATCH
//these are the bags slots...ignore it for now
if ((slot <= 22) && (slot >=19))
destslot = srcslot;
//check to make sure items are not being put in wrong spots
if (((srcslot > 23) && (destslot < 19)) || ((srcslot < 23) && (destslot > 19)))
{
if ((pClient->getCurrentChar()->getGuidBySlot(destslot) != 0) && (pClient->getCurrentChar()->getGuidBySlot(srcslot) != 0))
{
Item * tmpitem1 = WORLDSERVER.GetItem(pClient->getCurrentChar()->getItemIdBySlot(destslot));
Item * tmpitem2 = WORLDSERVER.GetItem(pClient->getCurrentChar()->getItemIdBySlot(srcslot));
if ((tmpitem1 != NULL) && (tmpitem2 != NULL))
{
if (tmpitem1->Inventorytype != tmpitem2->Inventorytype)
{
data.Initialize (18, SMSG_INVENTORY_CHANGE_FAILURE);
data << uint8(0x0c) ;
data << uint32(pClient->getCurrentChar()->getGuidBySlot(destslot));
data << uint32(0x00000040);
data << uint32(pClient->getCurrentChar()->getGuidBySlot(srcslot));
data << uint32(0x00000040);
data << uint8(0);
pClient->SendMsg (&data);
return;
}
}
}
}
//swap items
pClient->getCurrentChar()->SwapItemInSlot((int)srcslot, (int)destslot);
UpdateMask updateMask;
updateMask.SetLength (PLAYER_FIELDS);
//error
if (srcslot == destslot)
{
data.Initialize (18, SMSG_INVENTORY_CHANGE_FAILURE);
data << uint8(0x0c) ;
data << uint32(pClient->getCurrentChar()->getGuidBySlot(destslot));
data << uint32(0x00000040);
data << uint32(pClient->getCurrentChar()->getGuidBySlot(srcslot));
data << uint32(0x00000040);
data << uint8(0);
pClient->SendMsg (&data);
return;
}
pClient->getCurrentChar()->updateItemStats();
//send to zone players...they don't need to know about the item if the slot is over 19
if (destslot < 19)
{
pClient->getCurrentChar ()->setUpdateValue (
PLAYER_FIELD_INV_SLOT_HEAD + (destslot*2),
pClient->getCurrentChar()->getGuidBySlot(destslot),
updateMask.data);
pClient->getCurrentChar ()->setUpdateValue (
PLAYER_FIELD_INV_SLOT_HEAD + (destslot*2)+1,
pClient->getCurrentChar()->getGuidBySlot(destslot) == 0 ? 0 : 0x00000040,
updateMask.data);
}
if (srcslot < 19)
//.........这里部分代码省略.........
示例3: HandleMsg
void QueryHandler::HandleMsg( NetworkPacket & recv_data, GameClient *pClient )
{
NetworkPacket data;
char f[256];
sprintf(f, "WORLD: Query Opcode 0x%.4X", recv_data.opcode);
LOG.outString( f );
switch (recv_data.opcode)
{
case CMSG_NAME_QUERY:
{
uint32 guid;
memcpy(&guid, recv_data.data, 4);
uint32 race = 0, gender = 0, cl = 0;
char name[32];
std::map<uint32, Character*>::iterator itr = WORLDSERVER.mCharacters.find(guid);
if (itr == WORLDSERVER.mCharacters.end())
{
DatabaseInterface *dbi = DATABASE.createDatabaseInterface( );
if (!dbi->GetPlayerNameFromGUID(1, (uint8*)name))
LOG.outString( "No player name found for this guid" );
DATABASE.removeDatabaseInterface( dbi );
}
else
{
Character *pChar = WORLDSERVER.mCharacters[guid];
race = pChar->getRace();
gender = pChar->getGender();
cl = pChar->getClass();
strcpy(name, pChar->getName());
}
data.Clear();
data.length = 8 + strlen(name)+ 1 + 4*sizeof(uint32);
data.data = new uint8[ data.length ];
data.opcode = SMSG_NAME_QUERY_RESPONSE;
LOG.outString( name );
data << guid << uint32(0);
data << (std::string)name << uint32(0);
data << race << gender << cl;
// FIXME, something wrong here, crashes client.
pClient->SendMsg( &data );
} break;
case CMSG_QUERY_TIME:
{
data.Clear();
data.Initialize(4, SMSG_QUERY_TIME_RESPONSE);
data << (int32)time(NULL);
pClient->SendMsg(&data);
}break;
case CMSG_CREATURE_QUERY:
{
uint32 entry=0;
uint32 guid=0;
recv_data.ReadData(entry);
recv_data.ReadData(guid);
uint8 *name = 0;
/*std::map<uint32, uint8*>::iterator itr = WORLDSERVER.mCreatureNames.find(entry);
if (itr == WORLDSERVER.mCreatureNames.end()){
WPAssert(!"invalid creature entry");
}*/
name = WORLDSERVER.mCreatureNames[entry];
if (!name)
name = (uint8 *)"ERROR_NO_CREATURENAME_FOR_ENTRY";
// return;
printf(" WORLD: CMSG_CREATURE_QUERY '%s'\n", name );
uint16 namesize = strlen((char*)name)+1;
data.Clear();
data.Initialize(4+namesize+16, SMSG_CREATURE_QUERY_RESPONSE);
data << (uint32)entry;
strcpy((char*)data.data+4, (char*)name);
uint8 somedata[] =
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
memcpy(data.data+namesize+4, somedata, 16);
pClient->SendMsg(&data);
}break;
case CMSG_GAMEOBJECT_QUERY:
{
data.Initialize( 64, SMSG_GAMEOBJECT_QUERY_RESPONSE );
//.........这里部分代码省略.........
示例4: 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;
//.........这里部分代码省略.........