本文整理汇总了C++中NetworkPacket::ReadData方法的典型用法代码示例。如果您正苦于以下问题:C++ NetworkPacket::ReadData方法的具体用法?C++ NetworkPacket::ReadData怎么用?C++ NetworkPacket::ReadData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetworkPacket
的用法示例。
在下文中一共展示了NetworkPacket::ReadData方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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 );
//.........这里部分代码省略.........