当前位置: 首页>>代码示例>>C++>>正文


C++ NetworkPacket::Clear方法代码示例

本文整理汇总了C++中NetworkPacket::Clear方法的典型用法代码示例。如果您正苦于以下问题:C++ NetworkPacket::Clear方法的具体用法?C++ NetworkPacket::Clear怎么用?C++ NetworkPacket::Clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NetworkPacket的用法示例。


在下文中一共展示了NetworkPacket::Clear方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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 );
//.........这里部分代码省略.........
开发者ID:madhatternc,项目名称:mangos2,代码行数:101,代码来源:QueryHandler.cpp

示例2: 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();
//.........这里部分代码省略.........
开发者ID:madhatternc,项目名称:mangos2,代码行数:101,代码来源:SpellHandler.cpp

示例3: HandleMsg


//.........这里部分代码省略.........
                return;
            itemguid = pClient->getCurrentChar()->getGuidBySlot(destslot);
            pClient->getCurrentChar()->AddItemToSlot(destslot,0,0);

            UpdateMask updateMask;
            updateMask.SetLength (PLAYER_FIELDS);

            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);
            }
            pClient->getCurrentChar ()->UpdateObject (&updateMask, &data);
            //              WORLDSERVERSERVER.SendZoneMessage(&data, pClient, 0);
            pClient->getCurrentChar()->SendMessageToSet(&data, false);

            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);
            pClient->getCurrentChar ()->UpdateObject (&updateMask, &data);
            pClient->SendMsg (&data);

            data.Clear();
            data.Initialize(8, SMSG_DESTROY_OBJECT);
            data << itemguid << uint32(0x00000040);
            //              WORLDSERVER.SendZoneMessage(&data, pClient, 1);
            pClient->getCurrentChar()->SendMessageToSet(&data, true);
            break;
        }
        case CMSG_AUTOEQUIP_ITEM:
        {

            uint8 srcslot, destslot;
            recv_data >> srcslot >> destslot;

            int8 CharLvl, ItemLvl;
            //START OF LINA LVL REQUIREMENT AUTOEQUIP PATCH
            CharLvl=pClient->getCurrentChar()->getLevel();
            ItemLvl=WORLDSERVER.GetItem(pClient->getCurrentChar()->getItemIdBySlot(destslot))->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_AUTOEQUIP_ITEM can't send message\n");
                return;
开发者ID:madhatternc,项目名称:mangos2,代码行数:67,代码来源:ItemHandler.cpp


注:本文中的NetworkPacket::Clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。