[8483] Implement glyph 43361.
[getmangos.git] / src / game / QueryHandler.cpp
blob2b836521dc8fc69fe5d2ffcbe331ee791f0adbb5
1 /*
2 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include "Common.h"
20 #include "Language.h"
21 #include "Database/DatabaseEnv.h"
22 #include "Database/DatabaseImpl.h"
23 #include "WorldPacket.h"
24 #include "WorldSession.h"
25 #include "Opcodes.h"
26 #include "Log.h"
27 #include "World.h"
28 #include "ObjectMgr.h"
29 #include "Player.h"
30 #include "UpdateMask.h"
31 #include "NPCHandler.h"
32 #include "Pet.h"
33 #include "MapManager.h"
35 void WorldSession::SendNameQueryOpcode(Player *p)
37 if(!p)
38 return;
40 // guess size
41 WorldPacket data( SMSG_NAME_QUERY_RESPONSE, (8+1+1+1+1+1+10) );
42 data.append(p->GetPackGUID()); // player guid
43 data << uint8(0); // added in 3.1
44 data << p->GetName(); // played name
45 data << uint8(0); // realm name for cross realm BG usage
46 data << uint8(p->getRace());
47 data << uint8(p->getGender());
48 data << uint8(p->getClass());
49 if(DeclinedName const* names = p->GetDeclinedNames())
51 data << uint8(1); // is declined
52 for(int i = 0; i < MAX_DECLINED_NAME_CASES; ++i)
53 data << names->name[i];
55 else
56 data << uint8(0); // is not declined
58 SendPacket(&data);
61 void WorldSession::SendNameQueryOpcodeFromDB(uint64 guid)
63 CharacterDatabase.AsyncPQuery(&WorldSession::SendNameQueryOpcodeFromDBCallBack, GetAccountId(),
64 !sWorld.getConfig(CONFIG_DECLINED_NAMES_USED) ?
65 // ------- Query Without Declined Names --------
66 // 0 1 2 3 4
67 "SELECT guid, name, race, gender, class "
68 "FROM characters WHERE guid = '%u'"
70 // --------- Query With Declined Names ---------
71 // 0 1 2 3 4
72 "SELECT characters.guid, name, race, gender, class, "
73 // 5 6 7 8 9
74 "genitive, dative, accusative, instrumental, prepositional "
75 "FROM characters LEFT JOIN character_declinedname ON characters.guid = character_declinedname.guid WHERE characters.guid = '%u'",
76 GUID_LOPART(guid));
79 void WorldSession::SendNameQueryOpcodeFromDBCallBack(QueryResult *result, uint32 accountId)
81 if(!result)
82 return;
84 WorldSession * session = sWorld.FindSession(accountId);
85 if(!session)
87 delete result;
88 return;
91 Field *fields = result->Fetch();
92 uint32 guid = fields[0].GetUInt32();
93 std::string name = fields[1].GetCppString();
94 uint8 pRace = 0, pGender = 0, pClass = 0;
95 if(name == "")
96 name = session->GetMangosString(LANG_NON_EXIST_CHARACTER);
97 else
99 pRace = fields[2].GetUInt8();
100 pGender = fields[3].GetUInt8();
101 pClass = fields[4].GetUInt8();
104 // guess size
105 WorldPacket data( SMSG_NAME_QUERY_RESPONSE, (8+1+1+1+1+1+1+10) );
106 data.appendPackGUID(MAKE_NEW_GUID(guid, 0, HIGHGUID_PLAYER));
107 data << uint8(0); // added in 3.1
108 data << name;
109 data << uint8(0); // realm name for cross realm BG usage
110 data << uint8(pRace); // race
111 data << uint8(pGender); // gender
112 data << uint8(pClass); // class
114 // if the first declined name field (5) is empty, the rest must be too
115 if(sWorld.getConfig(CONFIG_DECLINED_NAMES_USED) && fields[5].GetCppString() != "")
117 data << uint8(1); // is declined
118 for(int i = 5; i < MAX_DECLINED_NAME_CASES+5; ++i)
119 data << fields[i].GetCppString();
121 else
122 data << uint8(0); // is not declined
124 session->SendPacket( &data );
125 delete result;
128 void WorldSession::HandleNameQueryOpcode( WorldPacket & recv_data )
130 uint64 guid;
132 recv_data >> guid;
134 Player *pChar = objmgr.GetPlayer(guid);
136 if (pChar)
137 SendNameQueryOpcode(pChar);
138 else
139 SendNameQueryOpcodeFromDB(guid);
142 void WorldSession::HandleQueryTimeOpcode( WorldPacket & /*recv_data*/ )
144 WorldPacket data( SMSG_QUERY_TIME_RESPONSE, 4+4 );
145 data << (uint32)time(NULL);
146 data << (uint32)0;
147 SendPacket( &data );
150 /// Only _static_ data send in this packet !!!
151 void WorldSession::HandleCreatureQueryOpcode( WorldPacket & recv_data )
153 uint32 entry;
154 recv_data >> entry;
155 recv_data.read_skip<uint64>(); // guid
157 CreatureInfo const *ci = objmgr.GetCreatureTemplate(entry);
158 if (ci)
161 std::string Name, SubName;
162 Name = ci->Name;
163 SubName = ci->SubName;
165 int loc_idx = GetSessionDbLocaleIndex();
166 if (loc_idx >= 0)
168 CreatureLocale const *cl = objmgr.GetCreatureLocale(entry);
169 if (cl)
171 if (cl->Name.size() > size_t(loc_idx) && !cl->Name[loc_idx].empty())
172 Name = cl->Name[loc_idx];
173 if (cl->SubName.size() > size_t(loc_idx) && !cl->SubName[loc_idx].empty())
174 SubName = cl->SubName[loc_idx];
177 sLog.outDetail("WORLD: CMSG_CREATURE_QUERY '%s' - Entry: %u.", ci->Name, entry);
178 // guess size
179 WorldPacket data( SMSG_CREATURE_QUERY_RESPONSE, 100 );
180 data << uint32(entry); // creature entry
181 data << Name;
182 data << uint8(0) << uint8(0) << uint8(0); // name2, name3, name4, always empty
183 data << SubName;
184 data << ci->IconName; // "Directions" for guard, string for Icons 2.3.0
185 data << uint32(ci->type_flags); // flags
186 data << uint32(ci->type); // CreatureType.dbc
187 data << uint32(ci->family); // CreatureFamily.dbc
188 data << uint32(ci->rank); // Creature Rank (elite, boss, etc)
189 data << uint32(ci->KillCredit[0]); // new in 3.1, kill credit
190 data << uint32(ci->KillCredit[1]); // new in 3.1, kill credit
191 data << uint32(ci->DisplayID_A[0]); // modelid_male1
192 data << uint32(ci->DisplayID_H[0]); // modelid_female1 ?
193 data << uint32(ci->DisplayID_A[1]); // modelid_male2 ?
194 data << uint32(ci->DisplayID_H[1]); // modelid_femmale2 ?
195 data << float(ci->unk16); // unk
196 data << float(ci->unk17); // unk
197 data << uint8(ci->RacialLeader);
198 for(uint32 i = 0; i < 4; ++i)
199 data << uint32(ci->questItems[i]); // itemId[4], quest drop
200 data << uint32(ci->movementId); // CreatureMovementInfo.dbc
201 SendPacket( &data );
202 sLog.outDebug( "WORLD: Sent SMSG_CREATURE_QUERY_RESPONSE" );
204 else
206 uint64 guid;
207 recv_data >> guid;
209 sLog.outDebug("WORLD: CMSG_CREATURE_QUERY - NO CREATURE INFO! (GUID: %u, ENTRY: %u)",
210 GUID_LOPART(guid), entry);
211 WorldPacket data( SMSG_CREATURE_QUERY_RESPONSE, 4 );
212 data << uint32(entry | 0x80000000);
213 SendPacket( &data );
214 sLog.outDebug( "WORLD: Sent SMSG_CREATURE_QUERY_RESPONSE" );
218 /// Only _static_ data send in this packet !!!
219 void WorldSession::HandleGameObjectQueryOpcode( WorldPacket & recv_data )
221 uint32 entryID;
222 recv_data >> entryID;
223 recv_data.read_skip<uint64>(); // guid
225 const GameObjectInfo *info = objmgr.GetGameObjectInfo(entryID);
226 if(info)
228 std::string Name;
229 std::string IconName;
230 std::string CastBarCaption;
232 Name = info->name;
233 IconName = info->IconName;
234 CastBarCaption = info->castBarCaption;
236 int loc_idx = GetSessionDbLocaleIndex();
237 if (loc_idx >= 0)
239 GameObjectLocale const *gl = objmgr.GetGameObjectLocale(entryID);
240 if (gl)
242 if (gl->Name.size() > size_t(loc_idx) && !gl->Name[loc_idx].empty())
243 Name = gl->Name[loc_idx];
244 if (gl->CastBarCaption.size() > size_t(loc_idx) && !gl->CastBarCaption[loc_idx].empty())
245 CastBarCaption = gl->CastBarCaption[loc_idx];
248 sLog.outDetail("WORLD: CMSG_GAMEOBJECT_QUERY '%s' - Entry: %u. ", info->name, entryID);
249 WorldPacket data ( SMSG_GAMEOBJECT_QUERY_RESPONSE, 150 );
250 data << uint32(entryID);
251 data << uint32(info->type);
252 data << uint32(info->displayId);
253 data << Name;
254 data << uint8(0) << uint8(0) << uint8(0); // name2, name3, name4
255 data << IconName; // 2.0.3, string. Icon name to use instead of default icon for go's (ex: "Attack" makes sword)
256 data << CastBarCaption; // 2.0.3, string. Text will appear in Cast Bar when using GO (ex: "Collecting")
257 data << info->unk1; // 2.0.3, string
258 data.append(info->raw.data, 24);
259 data << float(info->size); // go size
260 for(uint32 i = 0; i < 4; ++i)
261 data << uint32(info->questItems[i]); // itemId[4], quest drop
262 SendPacket( &data );
263 sLog.outDebug( "WORLD: Sent SMSG_GAMEOBJECT_QUERY_RESPONSE" );
265 else
268 uint64 guid;
269 recv_data >> guid;
271 sLog.outDebug( "WORLD: CMSG_GAMEOBJECT_QUERY - Missing gameobject info for (GUID: %u, ENTRY: %u)",
272 GUID_LOPART(guid), entryID );
273 WorldPacket data ( SMSG_GAMEOBJECT_QUERY_RESPONSE, 4 );
274 data << uint32(entryID | 0x80000000);
275 SendPacket( &data );
276 sLog.outDebug( "WORLD: Sent SMSG_GAMEOBJECT_QUERY_RESPONSE" );
280 void WorldSession::HandleCorpseQueryOpcode(WorldPacket & /*recv_data*/)
282 sLog.outDetail("WORLD: Received MSG_CORPSE_QUERY");
284 Corpse *corpse = GetPlayer()->GetCorpse();
286 if(!corpse)
288 WorldPacket data(MSG_CORPSE_QUERY, 1);
289 data << uint8(0); // corpse not found
290 SendPacket(&data);
291 return;
294 int32 mapid = corpse->GetMapId();
295 float x = corpse->GetPositionX();
296 float y = corpse->GetPositionY();
297 float z = corpse->GetPositionZ();
298 int32 corpsemapid = mapid;
300 // if corpse at different map
301 if(mapid != _player->GetMapId())
303 // search entrance map for proper show entrance
304 if(MapEntry const* corpseMapEntry = sMapStore.LookupEntry(mapid))
306 if(corpseMapEntry->IsDungeon() && corpseMapEntry->entrance_map >= 0)
308 // if corpse map have entrance
309 if(Map const* entranceMap = MapManager::Instance().CreateBaseMap(corpseMapEntry->entrance_map))
311 mapid = corpseMapEntry->entrance_map;
312 x = corpseMapEntry->entrance_x;
313 y = corpseMapEntry->entrance_y;
314 z = entranceMap->GetHeight(x, y, MAX_HEIGHT);
320 WorldPacket data(MSG_CORPSE_QUERY, 1+(5*4));
321 data << uint8(1); // corpse found
322 data << int32(mapid);
323 data << float(x);
324 data << float(y);
325 data << float(z);
326 data << int32(corpsemapid);
327 SendPacket(&data);
330 void WorldSession::HandleNpcTextQueryOpcode( WorldPacket & recv_data )
332 uint32 textID;
333 uint64 guid;
335 recv_data >> textID;
336 sLog.outDetail("WORLD: CMSG_NPC_TEXT_QUERY ID '%u'", textID);
338 recv_data >> guid;
339 GetPlayer()->SetUInt64Value(UNIT_FIELD_TARGET, guid);
341 GossipText const* pGossip = objmgr.GetGossipText(textID);
343 WorldPacket data( SMSG_NPC_TEXT_UPDATE, 100 ); // guess size
344 data << textID;
346 if (!pGossip)
348 for(uint32 i = 0; i < 8; ++i)
350 data << float(0);
351 data << "Greetings $N";
352 data << "Greetings $N";
353 data << uint32(0);
354 data << uint32(0);
355 data << uint32(0);
356 data << uint32(0);
357 data << uint32(0);
358 data << uint32(0);
359 data << uint32(0);
362 else
364 std::string Text_0[8], Text_1[8];
365 for (int i = 0; i < 8; ++i)
367 Text_0[i]=pGossip->Options[i].Text_0;
368 Text_1[i]=pGossip->Options[i].Text_1;
371 int loc_idx = GetSessionDbLocaleIndex();
372 if (loc_idx >= 0)
374 NpcTextLocale const *nl = objmgr.GetNpcTextLocale(textID);
375 if (nl)
377 for (int i = 0; i < 8; ++i)
379 if (nl->Text_0[i].size() > size_t(loc_idx) && !nl->Text_0[i][loc_idx].empty())
380 Text_0[i]=nl->Text_0[i][loc_idx];
381 if (nl->Text_1[i].size() > size_t(loc_idx) && !nl->Text_1[i][loc_idx].empty())
382 Text_1[i]=nl->Text_1[i][loc_idx];
387 for (int i = 0; i < 8; ++i)
389 data << pGossip->Options[i].Probability;
391 if ( Text_0[i].empty() )
392 data << Text_1[i];
393 else
394 data << Text_0[i];
396 if ( Text_1[i].empty() )
397 data << Text_0[i];
398 else
399 data << Text_1[i];
401 data << pGossip->Options[i].Language;
403 for(int j = 0; j < 3; ++j)
405 data << pGossip->Options[i].Emotes[j]._Delay;
406 data << pGossip->Options[i].Emotes[j]._Emote;
411 SendPacket( &data );
413 sLog.outDebug( "WORLD: Sent SMSG_NPC_TEXT_UPDATE" );
416 void WorldSession::HandlePageTextQueryOpcode( WorldPacket & recv_data )
418 uint32 pageID;
420 recv_data >> pageID;
421 sLog.outDetail("WORLD: Received CMSG_PAGE_TEXT_QUERY for pageID '%u'", pageID);
423 while (pageID)
425 PageText const *pPage = sPageTextStore.LookupEntry<PageText>( pageID );
426 // guess size
427 WorldPacket data( SMSG_PAGE_TEXT_QUERY_RESPONSE, 50 );
428 data << pageID;
430 if (!pPage)
432 data << "Item page missing.";
433 data << uint32(0);
434 pageID = 0;
436 else
438 std::string Text = pPage->Text;
440 int loc_idx = GetSessionDbLocaleIndex();
441 if (loc_idx >= 0)
443 PageTextLocale const *pl = objmgr.GetPageTextLocale(pageID);
444 if (pl)
446 if (pl->Text.size() > size_t(loc_idx) && !pl->Text[loc_idx].empty())
447 Text = pl->Text[loc_idx];
451 data << Text;
452 data << uint32(pPage->Next_Page);
453 pageID = pPage->Next_Page;
455 SendPacket( &data );
457 sLog.outDebug( "WORLD: Sent SMSG_PAGE_TEXT_QUERY_RESPONSE" );