Advertisement
Guest User

QueryHandler.CPP

a guest
May 26th, 2013
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 17.13 KB | None | 0 0
  1. /*
  2.  * Copyright (C) 2008-2013 TrinityCore <http://www.trinitycore.org/>
  3.  * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
  4.  *
  5.  * This program is free software; you can redistribute it and/or modify it
  6.  * under the terms of the GNU General Public License as published by the
  7.  * Free Software Foundation; either version 2 of the License, or (at your
  8.  * option) any later version.
  9.  *
  10.  * This program is distributed in the hope that it will be useful, but WITHOUT
  11.  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12.  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13.  * more details.
  14.  *
  15.  * You should have received a copy of the GNU General Public License along
  16.  * with this program. If not, see <http://www.gnu.org/licenses/>.
  17.  */
  18.  
  19. #include "Common.h"
  20. #include "Language.h"
  21. #include "DatabaseEnv.h"
  22. #include "WorldPacket.h"
  23. #include "WorldSession.h"
  24. #include "Opcodes.h"
  25. #include "Log.h"
  26. #include "World.h"
  27. #include "ObjectMgr.h"
  28. #include "Player.h"
  29. #include "UpdateMask.h"
  30. #include "NPCHandler.h"
  31. #include "Pet.h"
  32. #include "MapManager.h"
  33.  
  34. void WorldSession::SendNameQueryOpcode(uint64 guid)
  35. {
  36.     Player* player = ObjectAccessor::FindPlayer(guid);
  37.     CharacterNameData const* nameData = sWorld->GetCharacterNameData(GUID_LOPART(guid));
  38.  
  39.     WorldPacket data(SMSG_NAME_QUERY_RESPONSE, (8+1+1+1+1+1+10));
  40.     data.appendPackGUID(guid);
  41.     if (!nameData)
  42.     {
  43.         data << uint8(1);                           // name unknown
  44.         SendPacket(&data);
  45.         return;
  46.     }
  47.  
  48.     std::string suffix = "";
  49.     if(player && player->GetSession()->GetSecurity() == SEC_VIP)
  50.         suffix = " - VIP";
  51.  
  52.     if(player && player->GetSession()->GetSecurity() == SEC_MODERATOR)
  53.         suffix = " - TrialGM";
  54.  
  55.     if(player && player->GetSession()->GetSecurity() == SEC_GAMEMASTER)
  56.         suffix = " - GM";
  57.  
  58.     if(player && player->GetSession()->GetSecurity() == SEC_EVENTGM)
  59.         suffix = " - EventGM";
  60.  
  61.     if(player && player->GetSession()->GetSecurity() == SEC_HEADGM)
  62.         suffix = " - HeadGM";
  63.  
  64.     if(player && player->GetSession()->GetSecurity() == SEC_DEVELOPER)
  65.         suffix = " - Developer";
  66.  
  67.  
  68.     if(player && player->GetSession()->GetSecurity() == SEC_ADMINISTRATOR)
  69.         suffix = " - Admin";
  70.     data << uint8(0);                               // name known
  71.     data << nameData->m_name+suffix;                // played name
  72.     data << uint8(0);                               // realm name - only set for cross realm interaction (such as Battlegrounds)
  73.     data << uint8(nameData->m_race);
  74.     data << uint8(nameData->m_gender);
  75.     data << uint8(nameData->m_class);
  76.  
  77.     if (DeclinedName const* names = (player ? player->GetDeclinedNames() : NULL))
  78.     {
  79.         data << uint8(1);                           // Name is declined
  80.         for (uint8 i = 0; i < MAX_DECLINED_NAME_CASES; ++i)
  81.             data << names->name[i];
  82.     }
  83.     else
  84.         data << uint8(0);                           // Name is not declined
  85.  
  86.     SendPacket(&data);
  87. }
  88.  
  89. void WorldSession::HandleNameQueryOpcode(WorldPacket& recvData)
  90. {
  91.     uint64 guid;
  92.     recvData >> guid;
  93.  
  94.     // This is disable by default to prevent lots of console spam
  95.     // TC_LOG_INFO(LOG_FILTER_NETWORKIO, "HandleNameQueryOpcode %u", guid);
  96.  
  97.     SendNameQueryOpcode(guid);
  98. }
  99.  
  100. void WorldSession::HandleQueryTimeOpcode(WorldPacket & /*recvData*/)
  101. {
  102.     SendQueryTimeResponse();
  103. }
  104.  
  105. void WorldSession::SendQueryTimeResponse()
  106. {
  107.     WorldPacket data(SMSG_QUERY_TIME_RESPONSE, 4+4);
  108.     data << uint32(time(NULL));
  109.     data << uint32(sWorld->GetNextDailyQuestsResetTime() - time(NULL));
  110.     SendPacket(&data);
  111. }
  112.  
  113. /// Only _static_ data is sent in this packet !!!
  114. void WorldSession::HandleCreatureQueryOpcode(WorldPacket& recvData)
  115. {
  116.     uint32 entry;
  117.     recvData >> entry;
  118.     uint64 guid;
  119.     recvData >> guid;
  120.  
  121.     CreatureTemplate const* ci = sObjectMgr->GetCreatureTemplate(entry);
  122.     if (ci)
  123.     {
  124.  
  125.         std::string Name, SubName;
  126.         Name = ci->Name;
  127.         SubName = ci->SubName;
  128.  
  129.         int loc_idx = GetSessionDbLocaleIndex();
  130.         if (loc_idx >= 0)
  131.         {
  132.             if (CreatureLocale const* cl = sObjectMgr->GetCreatureLocale(entry))
  133.             {
  134.                 ObjectMgr::GetLocaleString(cl->Name, loc_idx, Name);
  135.                 ObjectMgr::GetLocaleString(cl->SubName, loc_idx, SubName);
  136.             }
  137.         }
  138.         TC_LOG_DEBUG(LOG_FILTER_NETWORKIO, "WORLD: CMSG_CREATURE_QUERY '%s' - Entry: %u.", ci->Name.c_str(), entry);
  139.                                                             // guess size
  140.         WorldPacket data(SMSG_CREATURE_QUERY_RESPONSE, 100);
  141.         data << uint32(entry);                              // creature entry
  142.         data << Name;
  143.         data << uint8(0) << uint8(0) << uint8(0);           // name2, name3, name4, always empty
  144.         data << SubName;
  145.         data << ci->IconName;                               // "Directions" for guard, string for Icons 2.3.0
  146.         data << uint32(ci->type_flags);                     // flags
  147.         data << uint32(ci->type);                           // CreatureType.dbc
  148.         data << uint32(ci->family);                         // CreatureFamily.dbc
  149.         data << uint32(ci->rank);                           // Creature Rank (elite, boss, etc)
  150.         data << uint32(ci->KillCredit[0]);                  // new in 3.1, kill credit
  151.         data << uint32(ci->KillCredit[1]);                  // new in 3.1, kill credit
  152.         data << uint32(ci->Modelid1);                       // Modelid1
  153.         data << uint32(ci->Modelid2);                       // Modelid2
  154.         data << uint32(ci->Modelid3);                       // Modelid3
  155.         data << uint32(ci->Modelid4);                       // Modelid4
  156.         data << float(ci->ModHealth);                       // dmg/hp modifier
  157.         data << float(ci->ModMana);                         // dmg/mana modifier
  158.         data << uint8(ci->RacialLeader);
  159.         for (uint32 i = 0; i < MAX_CREATURE_QUEST_ITEMS; ++i)
  160.             data << uint32(ci->questItems[i]);              // itemId[6], quest drop
  161.         data << uint32(ci->movementId);                     // CreatureMovementInfo.dbc
  162.         SendPacket(&data);
  163.         TC_LOG_DEBUG(LOG_FILTER_NETWORKIO, "WORLD: Sent SMSG_CREATURE_QUERY_RESPONSE");
  164.     }
  165.     else
  166.     {
  167.         TC_LOG_DEBUG(LOG_FILTER_NETWORKIO, "WORLD: CMSG_CREATURE_QUERY - NO CREATURE INFO! (GUID: %u, ENTRY: %u)",
  168.             GUID_LOPART(guid), entry);
  169.         WorldPacket data(SMSG_CREATURE_QUERY_RESPONSE, 4);
  170.         data << uint32(entry | 0x80000000);
  171.         SendPacket(&data);
  172.         TC_LOG_DEBUG(LOG_FILTER_NETWORKIO, "WORLD: Sent SMSG_CREATURE_QUERY_RESPONSE");
  173.     }
  174. }
  175.  
  176. /// Only _static_ data is sent in this packet !!!
  177. void WorldSession::HandleGameObjectQueryOpcode(WorldPacket& recvData)
  178. {
  179.     uint32 entry;
  180.     recvData >> entry;
  181.     uint64 guid;
  182.     recvData >> guid;
  183.  
  184.     const GameObjectTemplate* info = sObjectMgr->GetGameObjectTemplate(entry);
  185.     if (info)
  186.     {
  187.         std::string Name;
  188.         std::string IconName;
  189.         std::string CastBarCaption;
  190.  
  191.         Name = info->name;
  192.         IconName = info->IconName;
  193.         CastBarCaption = info->castBarCaption;
  194.  
  195.         int loc_idx = GetSessionDbLocaleIndex();
  196.         if (loc_idx >= 0)
  197.         {
  198.             if (GameObjectLocale const* gl = sObjectMgr->GetGameObjectLocale(entry))
  199.             {
  200.                 ObjectMgr::GetLocaleString(gl->Name, loc_idx, Name);
  201.                 ObjectMgr::GetLocaleString(gl->CastBarCaption, loc_idx, CastBarCaption);
  202.             }
  203.         }
  204.         TC_LOG_DEBUG(LOG_FILTER_NETWORKIO, "WORLD: CMSG_GAMEOBJECT_QUERY '%s' - Entry: %u. ", info->name.c_str(), entry);
  205.         WorldPacket data (SMSG_GAMEOBJECT_QUERY_RESPONSE, 150);
  206.         data << uint32(entry);
  207.         data << uint32(info->type);
  208.         data << uint32(info->displayId);
  209.         data << Name;
  210.         data << uint8(0) << uint8(0) << uint8(0);           // name2, name3, name4
  211.         data << IconName;                                   // 2.0.3, string. Icon name to use instead of default icon for go's (ex: "Attack" makes sword)
  212.         data << CastBarCaption;                             // 2.0.3, string. Text will appear in Cast Bar when using GO (ex: "Collecting")
  213.         data << info->unk1;                                 // 2.0.3, string
  214.         data.append(info->raw.data, MAX_GAMEOBJECT_DATA);
  215.         data << float(info->size);                          // go size
  216.         for (uint32 i = 0; i < MAX_GAMEOBJECT_QUEST_ITEMS; ++i)
  217.             data << uint32(info->questItems[i]);              // itemId[6], quest drop
  218.         SendPacket(&data);
  219.         TC_LOG_DEBUG(LOG_FILTER_NETWORKIO, "WORLD: Sent SMSG_GAMEOBJECT_QUERY_RESPONSE");
  220.     }
  221.     else
  222.     {
  223.         TC_LOG_DEBUG(LOG_FILTER_NETWORKIO, "WORLD: CMSG_GAMEOBJECT_QUERY - Missing gameobject info for (GUID: %u, ENTRY: %u)",
  224.             GUID_LOPART(guid), entry);
  225.         WorldPacket data (SMSG_GAMEOBJECT_QUERY_RESPONSE, 4);
  226.         data << uint32(entry | 0x80000000);
  227.         SendPacket(&data);
  228.         TC_LOG_DEBUG(LOG_FILTER_NETWORKIO, "WORLD: Sent SMSG_GAMEOBJECT_QUERY_RESPONSE");
  229.     }
  230. }
  231.  
  232. void WorldSession::HandleCorpseQueryOpcode(WorldPacket & /*recvData*/)
  233. {
  234.     TC_LOG_DEBUG(LOG_FILTER_NETWORKIO, "WORLD: Received MSG_CORPSE_QUERY");
  235.  
  236.     Corpse* corpse = GetPlayer()->GetCorpse();
  237.  
  238.     if (!corpse)
  239.     {
  240.         WorldPacket data(MSG_CORPSE_QUERY, 1);
  241.         data << uint8(0);                                   // corpse not found
  242.         SendPacket(&data);
  243.         return;
  244.     }
  245.  
  246.     uint32 mapid = corpse->GetMapId();
  247.     float x = corpse->GetPositionX();
  248.     float y = corpse->GetPositionY();
  249.     float z = corpse->GetPositionZ();
  250.     uint32 corpsemapid = mapid;
  251.  
  252.     // if corpse at different map
  253.     if (mapid != _player->GetMapId())
  254.     {
  255.         // search entrance map for proper show entrance
  256.         if (MapEntry const* corpseMapEntry = sMapStore.LookupEntry(mapid))
  257.         {
  258.             if (corpseMapEntry->IsDungeon() && corpseMapEntry->entrance_map >= 0)
  259.             {
  260.                 // if corpse map have entrance
  261.                 if (Map const* entranceMap = sMapMgr->CreateBaseMap(corpseMapEntry->entrance_map))
  262.                 {
  263.                     mapid = corpseMapEntry->entrance_map;
  264.                     x = corpseMapEntry->entrance_x;
  265.                     y = corpseMapEntry->entrance_y;
  266.                     z = entranceMap->GetHeight(GetPlayer()->GetPhaseMask(), x, y, MAX_HEIGHT);
  267.                 }
  268.             }
  269.         }
  270.     }
  271.  
  272.     WorldPacket data(MSG_CORPSE_QUERY, 1+(6*4));
  273.     data << uint8(1);                                       // corpse found
  274.     data << int32(mapid);
  275.     data << float(x);
  276.     data << float(y);
  277.     data << float(z);
  278.     data << int32(corpsemapid);
  279.     data << uint32(0);                                      // unknown
  280.     SendPacket(&data);
  281. }
  282.  
  283. void WorldSession::HandleNpcTextQueryOpcode(WorldPacket& recvData)
  284. {
  285.     uint32 textID;
  286.     uint64 guid;
  287.  
  288.     recvData >> textID;
  289.     TC_LOG_DEBUG(LOG_FILTER_NETWORKIO, "WORLD: CMSG_NPC_TEXT_QUERY ID '%u'", textID);
  290.  
  291.     recvData >> guid;
  292.     GetPlayer()->SetSelection(guid);
  293.  
  294.     GossipText const* pGossip = sObjectMgr->GetGossipText(textID);
  295.  
  296.     WorldPacket data(SMSG_NPC_TEXT_UPDATE, 100);          // guess size
  297.     data << textID;
  298.  
  299.     if (!pGossip)
  300.     {
  301.         for (uint32 i = 0; i < MAX_GOSSIP_TEXT_OPTIONS; ++i)
  302.         {
  303.             data << float(0);
  304.             data << "Greetings $N";
  305.             data << "Greetings $N";
  306.             data << uint32(0);
  307.             data << uint32(0);
  308.             data << uint32(0);
  309.             data << uint32(0);
  310.             data << uint32(0);
  311.             data << uint32(0);
  312.             data << uint32(0);
  313.         }
  314.     }
  315.     else
  316.     {
  317.         std::string Text_0[MAX_LOCALES], Text_1[MAX_LOCALES];
  318.         for (int i = 0; i < MAX_GOSSIP_TEXT_OPTIONS; ++i)
  319.         {
  320.             Text_0[i]=pGossip->Options[i].Text_0;
  321.             Text_1[i]=pGossip->Options[i].Text_1;
  322.         }
  323.  
  324.         int loc_idx = GetSessionDbLocaleIndex();
  325.         if (loc_idx >= 0)
  326.         {
  327.             if (NpcTextLocale const* nl = sObjectMgr->GetNpcTextLocale(textID))
  328.             {
  329.                 for (int i = 0; i < MAX_LOCALES; ++i)
  330.                 {
  331.                     ObjectMgr::GetLocaleString(nl->Text_0[i], loc_idx, Text_0[i]);
  332.                     ObjectMgr::GetLocaleString(nl->Text_1[i], loc_idx, Text_1[i]);
  333.                 }
  334.             }
  335.         }
  336.  
  337.         for (int i = 0; i < MAX_GOSSIP_TEXT_OPTIONS; ++i)
  338.         {
  339.             data << pGossip->Options[i].Probability;
  340.  
  341.             if (Text_0[i].empty())
  342.                 data << Text_1[i];
  343.             else
  344.                 data << Text_0[i];
  345.  
  346.             if (Text_1[i].empty())
  347.                 data << Text_0[i];
  348.             else
  349.                 data << Text_1[i];
  350.  
  351.             data << pGossip->Options[i].Language;
  352.  
  353.             for (int j = 0; j < MAX_GOSSIP_TEXT_EMOTES; ++j)
  354.             {
  355.                 data << pGossip->Options[i].Emotes[j]._Delay;
  356.                 data << pGossip->Options[i].Emotes[j]._Emote;
  357.             }
  358.         }
  359.     }
  360.  
  361.     SendPacket(&data);
  362.  
  363.     TC_LOG_DEBUG(LOG_FILTER_NETWORKIO, "WORLD: Sent SMSG_NPC_TEXT_UPDATE");
  364. }
  365.  
  366. /// Only _static_ data is sent in this packet !!!
  367. void WorldSession::HandlePageTextQueryOpcode(WorldPacket& recvData)
  368. {
  369.     TC_LOG_DEBUG(LOG_FILTER_NETWORKIO, "WORLD: Received CMSG_PAGE_TEXT_QUERY");
  370.  
  371.     uint32 pageID;
  372.     recvData >> pageID;
  373.     recvData.read_skip<uint64>();                          // guid
  374.  
  375.     while (pageID)
  376.     {
  377.         PageText const* pageText = sObjectMgr->GetPageText(pageID);
  378.                                                             // guess size
  379.         WorldPacket data(SMSG_PAGE_TEXT_QUERY_RESPONSE, 50);
  380.         data << pageID;
  381.  
  382.         if (!pageText)
  383.         {
  384.             data << "Item page missing.";
  385.             data << uint32(0);
  386.             pageID = 0;
  387.         }
  388.         else
  389.         {
  390.             std::string Text = pageText->Text;
  391.  
  392.             int loc_idx = GetSessionDbLocaleIndex();
  393.             if (loc_idx >= 0)
  394.                 if (PageTextLocale const* player = sObjectMgr->GetPageTextLocale(pageID))
  395.                     ObjectMgr::GetLocaleString(player->Text, loc_idx, Text);
  396.  
  397.             data << Text;
  398.             data << uint32(pageText->NextPage);
  399.             pageID = pageText->NextPage;
  400.         }
  401.         SendPacket(&data);
  402.  
  403.         TC_LOG_DEBUG(LOG_FILTER_NETWORKIO, "WORLD: Sent SMSG_PAGE_TEXT_QUERY_RESPONSE");
  404.     }
  405. }
  406.  
  407. void WorldSession::HandleCorpseMapPositionQuery(WorldPacket& recvData)
  408. {
  409.     TC_LOG_DEBUG(LOG_FILTER_NETWORKIO, "WORLD: Recv CMSG_CORPSE_MAP_POSITION_QUERY");
  410.  
  411.     uint32 unk;
  412.     recvData >> unk;
  413.  
  414.     WorldPacket data(SMSG_CORPSE_MAP_POSITION_QUERY_RESPONSE, 4+4+4+4);
  415.     data << float(0);
  416.     data << float(0);
  417.     data << float(0);
  418.     data << float(0);
  419.     SendPacket(&data);
  420. }
  421.  
  422. void WorldSession::HandleQuestPOIQuery(WorldPacket& recvData)
  423. {
  424.     uint32 count;
  425.     recvData >> count; // quest count, max=25
  426.  
  427.     if (count >= MAX_QUEST_LOG_SIZE)
  428.     {
  429.         recvData.rfinish();
  430.         return;
  431.     }
  432.  
  433.     WorldPacket data(SMSG_QUEST_POI_QUERY_RESPONSE, 4+(4+4)*count);
  434.     data << uint32(count); // count
  435.  
  436.     for (uint32 i = 0; i < count; ++i)
  437.     {
  438.         uint32 questId;
  439.         recvData >> questId; // quest id
  440.  
  441.         bool questOk = false;
  442.  
  443.         uint16 questSlot = _player->FindQuestSlot(questId);
  444.  
  445.         if (questSlot != MAX_QUEST_LOG_SIZE)
  446.             questOk =_player->GetQuestSlotQuestId(questSlot) == questId;
  447.  
  448.         if (questOk)
  449.         {
  450.             QuestPOIVector const* POI = sObjectMgr->GetQuestPOIVector(questId);
  451.  
  452.             if (POI)
  453.             {
  454.                 data << uint32(questId); // quest ID
  455.                 data << uint32(POI->size()); // POI count
  456.  
  457.                 for (QuestPOIVector::const_iterator itr = POI->begin(); itr != POI->end(); ++itr)
  458.                 {
  459.                     data << uint32(itr->Id);                // POI index
  460.                     data << int32(itr->ObjectiveIndex);     // objective index
  461.                     data << uint32(itr->MapId);             // mapid
  462.                     data << uint32(itr->AreaId);            // areaid
  463.                     data << uint32(itr->Unk2);              // unknown
  464.                     data << uint32(itr->Unk3);              // unknown
  465.                     data << uint32(itr->Unk4);              // unknown
  466.                     data << uint32(itr->points.size());     // POI points count
  467.  
  468.                     for (std::vector<QuestPOIPoint>::const_iterator itr2 = itr->points.begin(); itr2 != itr->points.end(); ++itr2)
  469.                     {
  470.                         data << int32(itr2->x); // POI point x
  471.                         data << int32(itr2->y); // POI point y
  472.                     }
  473.                 }
  474.             }
  475.             else
  476.             {
  477.                 data << uint32(questId); // quest ID
  478.                 data << uint32(0); // POI count
  479.             }
  480.         }
  481.         else
  482.         {
  483.             data << uint32(questId); // quest ID
  484.             data << uint32(0); // POI count
  485.         }
  486.     }
  487.  
  488.     SendPacket(&data);
  489. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement