[9033] Fixed percent mana regneration from spell 53228 and ranks buff.
[getmangos.git] / src / game / QueryHandler.cpp
blob89a72a476a4796a7be35587b0e3acaf9d44f43bc
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 "ObjectDefines.h"
30 #include "Player.h"
31 #include "UpdateMask.h"
32 #include "NPCHandler.h"
33 #include "Pet.h"
34 #include "MapManager.h"
36 void WorldSession::SendNameQueryOpcode(Player *p)
38 if(!p)
39 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; if > 1, then end of packet
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();
103 // guess size
104 WorldPacket data( SMSG_NAME_QUERY_RESPONSE, (8+1+1+1+1+1+1+10) );
105 data.appendPackGUID(MAKE_NEW_GUID(guid, 0, HIGHGUID_PLAYER));
106 data << uint8(0); // added in 3.1; if > 1, then end of packet
107 data << name;
108 data << uint8(0); // realm name for cross realm BG usage
109 data << uint8(pRace); // race
110 data << uint8(pGender); // gender
111 data << uint8(pClass); // class
113 // if the first declined name field (5) is empty, the rest must be too
114 if(sWorld.getConfig(CONFIG_DECLINED_NAMES_USED) && fields[5].GetCppString() != "")
116 data << uint8(1); // is declined
117 for(int i = 5; i < MAX_DECLINED_NAME_CASES+5; ++i)
118 data << fields[i].GetCppString();
120 else
121 data << uint8(0); // is not declined
123 session->SendPacket( &data );
124 delete result;
127 void WorldSession::HandleNameQueryOpcode( WorldPacket & recv_data )
129 uint64 guid;
131 recv_data >> guid;
133 Player *pChar = sObjectMgr.GetPlayer(guid);
135 if (pChar)
136 SendNameQueryOpcode(pChar);
137 else
138 SendNameQueryOpcodeFromDB(guid);
141 void WorldSession::HandleQueryTimeOpcode( WorldPacket & /*recv_data*/ )
143 WorldPacket data( SMSG_QUERY_TIME_RESPONSE, 4+4 );
144 data << (uint32)time(NULL);
145 data << (uint32)0;
146 SendPacket( &data );
149 /// Only _static_ data send in this packet !!!
150 void WorldSession::HandleCreatureQueryOpcode( WorldPacket & recv_data )
152 uint32 entry;
153 recv_data >> entry;
154 uint64 guid;
155 recv_data >> guid;
157 CreatureInfo const *ci = ObjectMgr::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 = sObjectMgr.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 < 6; ++i)
199 data << uint32(ci->questItems[i]); // itemId[6], quest drop
200 data << uint32(ci->movementId); // CreatureMovementInfo.dbc
201 SendPacket( &data );
202 sLog.outDebug( "WORLD: Sent SMSG_CREATURE_QUERY_RESPONSE" );
204 else
206 sLog.outDebug("WORLD: CMSG_CREATURE_QUERY - NO CREATURE INFO! (GUID: %u, ENTRY: %u)",
207 GUID_LOPART(guid), entry);
208 WorldPacket data( SMSG_CREATURE_QUERY_RESPONSE, 4 );
209 data << uint32(entry | 0x80000000);
210 SendPacket( &data );
211 sLog.outDebug( "WORLD: Sent SMSG_CREATURE_QUERY_RESPONSE" );
215 /// Only _static_ data send in this packet !!!
216 void WorldSession::HandleGameObjectQueryOpcode( WorldPacket & recv_data )
218 uint32 entryID;
219 recv_data >> entryID;
220 uint64 guid;
221 recv_data >> guid;
223 const GameObjectInfo *info = ObjectMgr::GetGameObjectInfo(entryID);
224 if(info)
226 std::string Name;
227 std::string IconName;
228 std::string CastBarCaption;
230 Name = info->name;
231 IconName = info->IconName;
232 CastBarCaption = info->castBarCaption;
234 int loc_idx = GetSessionDbLocaleIndex();
235 if (loc_idx >= 0)
237 GameObjectLocale const *gl = sObjectMgr.GetGameObjectLocale(entryID);
238 if (gl)
240 if (gl->Name.size() > size_t(loc_idx) && !gl->Name[loc_idx].empty())
241 Name = gl->Name[loc_idx];
242 if (gl->CastBarCaption.size() > size_t(loc_idx) && !gl->CastBarCaption[loc_idx].empty())
243 CastBarCaption = gl->CastBarCaption[loc_idx];
246 sLog.outDetail("WORLD: CMSG_GAMEOBJECT_QUERY '%s' - Entry: %u. ", info->name, entryID);
247 WorldPacket data ( SMSG_GAMEOBJECT_QUERY_RESPONSE, 150 );
248 data << uint32(entryID);
249 data << uint32(info->type);
250 data << uint32(info->displayId);
251 data << Name;
252 data << uint8(0) << uint8(0) << uint8(0); // name2, name3, name4
253 data << IconName; // 2.0.3, string. Icon name to use instead of default icon for go's (ex: "Attack" makes sword)
254 data << CastBarCaption; // 2.0.3, string. Text will appear in Cast Bar when using GO (ex: "Collecting")
255 data << info->unk1; // 2.0.3, string
256 data.append(info->raw.data, 24);
257 data << float(info->size); // go size
258 for(uint32 i = 0; i < 6; ++i)
259 data << uint32(info->questItems[i]); // itemId[6], quest drop
260 SendPacket( &data );
261 sLog.outDebug( "WORLD: Sent SMSG_GAMEOBJECT_QUERY_RESPONSE" );
263 else
265 sLog.outDebug( "WORLD: CMSG_GAMEOBJECT_QUERY - Missing gameobject info for (GUID: %u, ENTRY: %u)",
266 GUID_LOPART(guid), entryID );
267 WorldPacket data ( SMSG_GAMEOBJECT_QUERY_RESPONSE, 4 );
268 data << uint32(entryID | 0x80000000);
269 SendPacket( &data );
270 sLog.outDebug( "WORLD: Sent SMSG_GAMEOBJECT_QUERY_RESPONSE" );
274 void WorldSession::HandleCorpseQueryOpcode(WorldPacket & /*recv_data*/)
276 sLog.outDetail("WORLD: Received MSG_CORPSE_QUERY");
278 Corpse *corpse = GetPlayer()->GetCorpse();
280 if(!corpse)
282 WorldPacket data(MSG_CORPSE_QUERY, 1);
283 data << uint8(0); // corpse not found
284 SendPacket(&data);
285 return;
288 int32 mapid = corpse->GetMapId();
289 float x = corpse->GetPositionX();
290 float y = corpse->GetPositionY();
291 float z = corpse->GetPositionZ();
292 int32 corpsemapid = mapid;
294 // if corpse at different map
295 if(mapid != _player->GetMapId())
297 // search entrance map for proper show entrance
298 if(MapEntry const* corpseMapEntry = sMapStore.LookupEntry(mapid))
300 if(corpseMapEntry->IsDungeon() && corpseMapEntry->entrance_map >= 0)
302 // if corpse map have entrance
303 if(Map const* entranceMap = sMapMgr.CreateBaseMap(corpseMapEntry->entrance_map))
305 mapid = corpseMapEntry->entrance_map;
306 x = corpseMapEntry->entrance_x;
307 y = corpseMapEntry->entrance_y;
308 z = entranceMap->GetHeight(x, y, MAX_HEIGHT);
314 WorldPacket data(MSG_CORPSE_QUERY, 1+(6*4));
315 data << uint8(1); // corpse found
316 data << int32(mapid);
317 data << float(x);
318 data << float(y);
319 data << float(z);
320 data << int32(corpsemapid);
321 data << uint32(0); // unknown
322 SendPacket(&data);
325 void WorldSession::HandleNpcTextQueryOpcode( WorldPacket & recv_data )
327 uint32 textID;
328 uint64 guid;
330 recv_data >> textID;
331 sLog.outDetail("WORLD: CMSG_NPC_TEXT_QUERY ID '%u'", textID);
333 recv_data >> guid;
334 _player->SetTargetGUID(guid);
336 GossipText const* pGossip = sObjectMgr.GetGossipText(textID);
338 WorldPacket data( SMSG_NPC_TEXT_UPDATE, 100 ); // guess size
339 data << textID;
341 if (!pGossip)
343 for(uint32 i = 0; i < 8; ++i)
345 data << float(0);
346 data << "Greetings $N";
347 data << "Greetings $N";
348 data << uint32(0);
349 data << uint32(0);
350 data << uint32(0);
351 data << uint32(0);
352 data << uint32(0);
353 data << uint32(0);
354 data << uint32(0);
357 else
359 std::string Text_0[8], Text_1[8];
360 for (int i = 0; i < 8; ++i)
362 Text_0[i]=pGossip->Options[i].Text_0;
363 Text_1[i]=pGossip->Options[i].Text_1;
366 int loc_idx = GetSessionDbLocaleIndex();
367 if (loc_idx >= 0)
369 NpcTextLocale const *nl = sObjectMgr.GetNpcTextLocale(textID);
370 if (nl)
372 for (int i = 0; i < 8; ++i)
374 if (nl->Text_0[i].size() > size_t(loc_idx) && !nl->Text_0[i][loc_idx].empty())
375 Text_0[i]=nl->Text_0[i][loc_idx];
376 if (nl->Text_1[i].size() > size_t(loc_idx) && !nl->Text_1[i][loc_idx].empty())
377 Text_1[i]=nl->Text_1[i][loc_idx];
382 for (int i = 0; i < 8; ++i)
384 data << pGossip->Options[i].Probability;
386 if ( Text_0[i].empty() )
387 data << Text_1[i];
388 else
389 data << Text_0[i];
391 if ( Text_1[i].empty() )
392 data << Text_0[i];
393 else
394 data << Text_1[i];
396 data << pGossip->Options[i].Language;
398 for(int j = 0; j < 3; ++j)
400 data << pGossip->Options[i].Emotes[j]._Delay;
401 data << pGossip->Options[i].Emotes[j]._Emote;
406 SendPacket( &data );
408 sLog.outDebug( "WORLD: Sent SMSG_NPC_TEXT_UPDATE" );
411 void WorldSession::HandlePageTextQueryOpcode( WorldPacket & recv_data )
413 sLog.outDetail("WORLD: Received CMSG_PAGE_TEXT_QUERY");
414 recv_data.hexlike();
416 uint32 pageID;
417 recv_data >> pageID;
418 recv_data.read_skip<uint64>(); // guid
420 while (pageID)
422 PageText const *pPage = sPageTextStore.LookupEntry<PageText>( pageID );
423 // guess size
424 WorldPacket data( SMSG_PAGE_TEXT_QUERY_RESPONSE, 50 );
425 data << pageID;
427 if (!pPage)
429 data << "Item page missing.";
430 data << uint32(0);
431 pageID = 0;
433 else
435 std::string Text = pPage->Text;
437 int loc_idx = GetSessionDbLocaleIndex();
438 if (loc_idx >= 0)
440 PageTextLocale const *pl = sObjectMgr.GetPageTextLocale(pageID);
441 if (pl)
443 if (pl->Text.size() > size_t(loc_idx) && !pl->Text[loc_idx].empty())
444 Text = pl->Text[loc_idx];
448 data << Text;
449 data << uint32(pPage->Next_Page);
450 pageID = pPage->Next_Page;
452 SendPacket( &data );
454 sLog.outDebug( "WORLD: Sent SMSG_PAGE_TEXT_QUERY_RESPONSE" );
458 void WorldSession::HandleCorpseMapPositionQuery( WorldPacket & recv_data )
460 sLog.outDebug( "WORLD: Recv CMSG_CORPSE_MAP_POSITION_QUERY" );
462 uint32 unk;
463 recv_data >> unk;
465 WorldPacket data(CMSG_CORPSE_MAP_POSITION_QUERY_RESPONSE, 4+4+4+4);
466 data << float(0);
467 data << float(0);
468 data << float(0);
469 data << float(0);
470 SendPacket(&data);