2 * Copyright (C) 2005-2010 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
21 #include "Database/DatabaseEnv.h"
22 #include "Database/DatabaseImpl.h"
23 #include "WorldPacket.h"
24 #include "WorldSession.h"
28 #include "ObjectMgr.h"
29 #include "ObjectGuid.h"
31 #include "UpdateMask.h"
32 #include "NPCHandler.h"
34 #include "MapManager.h"
36 void WorldSession::SendNameQueryOpcode(Player
*p
)
41 WorldPacket
data( SMSG_NAME_QUERY_RESPONSE
, (8+1+1+1+1+1+10) );
42 data
<< 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
];
56 data
<< uint8(0); // is not declined
61 void WorldSession::SendNameQueryOpcodeFromDB(uint64 guid
)
63 CharacterDatabase
.AsyncPQuery(&WorldSession::SendNameQueryOpcodeFromDBCallBack
, GetAccountId(),
64 !sWorld
.getConfig(CONFIG_BOOL_DECLINED_NAMES_USED
) ?
65 // ------- Query Without Declined Names --------
67 "SELECT guid, name, race, gender, class "
68 "FROM characters WHERE guid = '%u'"
70 // --------- Query With Declined Names ---------
72 "SELECT characters.guid, name, race, gender, class, "
74 "genitive, dative, accusative, instrumental, prepositional "
75 "FROM characters LEFT JOIN character_declinedname ON characters.guid = character_declinedname.guid WHERE characters.guid = '%u'",
79 void WorldSession::SendNameQueryOpcodeFromDBCallBack(QueryResult
*result
, uint32 accountId
)
84 WorldSession
* session
= sWorld
.FindSession(accountId
);
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;
96 name
= session
->GetMangosString(LANG_NON_EXIST_CHARACTER
);
99 pRace
= fields
[2].GetUInt8();
100 pGender
= fields
[3].GetUInt8();
101 pClass
= fields
[4].GetUInt8();
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
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_BOOL_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();
121 data
<< uint8(0); // is not declined
123 session
->SendPacket( &data
);
127 void WorldSession::HandleNameQueryOpcode( WorldPacket
& recv_data
)
133 Player
*pChar
= sObjectMgr
.GetPlayer(guid
);
136 SendNameQueryOpcode(pChar
);
138 SendNameQueryOpcodeFromDB(guid
);
141 void WorldSession::HandleQueryTimeOpcode( WorldPacket
& /*recv_data*/ )
143 SendQueryTimeResponse();
146 /// Only _static_ data send in this packet !!!
147 void WorldSession::HandleCreatureQueryOpcode( WorldPacket
& recv_data
)
154 CreatureInfo
const *ci
= ObjectMgr::GetCreatureTemplate(entry
);
157 std::string Name
, SubName
;
159 SubName
= ci
->SubName
;
161 int loc_idx
= GetSessionDbLocaleIndex();
164 CreatureLocale
const *cl
= sObjectMgr
.GetCreatureLocale(entry
);
167 if (cl
->Name
.size() > size_t(loc_idx
) && !cl
->Name
[loc_idx
].empty())
168 Name
= cl
->Name
[loc_idx
];
169 if (cl
->SubName
.size() > size_t(loc_idx
) && !cl
->SubName
[loc_idx
].empty())
170 SubName
= cl
->SubName
[loc_idx
];
173 sLog
.outDetail("WORLD: CMSG_CREATURE_QUERY '%s' - Entry: %u.", ci
->Name
, entry
);
175 WorldPacket
data( SMSG_CREATURE_QUERY_RESPONSE
, 100 );
176 data
<< uint32(entry
); // creature entry
178 data
<< uint8(0) << uint8(0) << uint8(0); // name2, name3, name4, always empty
180 data
<< ci
->IconName
; // "Directions" for guard, string for Icons 2.3.0
181 data
<< uint32(ci
->type_flags
); // flags
182 data
<< uint32(ci
->type
); // CreatureType.dbc
183 data
<< uint32(ci
->family
); // CreatureFamily.dbc
184 data
<< uint32(ci
->rank
); // Creature Rank (elite, boss, etc)
185 data
<< uint32(ci
->KillCredit
[0]); // new in 3.1, kill credit
186 data
<< uint32(ci
->KillCredit
[1]); // new in 3.1, kill credit
187 data
<< uint32(ci
->DisplayID_A
[0]); // modelid_male1
188 data
<< uint32(ci
->DisplayID_H
[0]); // modelid_female1 ?
189 data
<< uint32(ci
->DisplayID_A
[1]); // modelid_male2 ?
190 data
<< uint32(ci
->DisplayID_H
[1]); // modelid_femmale2 ?
191 data
<< float(ci
->unk16
); // unk
192 data
<< float(ci
->unk17
); // unk
193 data
<< uint8(ci
->RacialLeader
);
194 for(uint32 i
= 0; i
< 6; ++i
)
195 data
<< uint32(ci
->questItems
[i
]); // itemId[6], quest drop
196 data
<< uint32(ci
->movementId
); // CreatureMovementInfo.dbc
198 sLog
.outDebug( "WORLD: Sent SMSG_CREATURE_QUERY_RESPONSE" );
202 sLog
.outDebug("WORLD: CMSG_CREATURE_QUERY - NO CREATURE INFO! (GUID: %u, ENTRY: %u)",
203 GUID_LOPART(guid
), entry
);
204 WorldPacket
data( SMSG_CREATURE_QUERY_RESPONSE
, 4 );
205 data
<< uint32(entry
| 0x80000000);
207 sLog
.outDebug( "WORLD: Sent SMSG_CREATURE_QUERY_RESPONSE" );
211 /// Only _static_ data send in this packet !!!
212 void WorldSession::HandleGameObjectQueryOpcode( WorldPacket
& recv_data
)
215 recv_data
>> entryID
;
219 const GameObjectInfo
*info
= ObjectMgr::GetGameObjectInfo(entryID
);
223 std::string IconName
;
224 std::string CastBarCaption
;
227 IconName
= info
->IconName
;
228 CastBarCaption
= info
->castBarCaption
;
230 int loc_idx
= GetSessionDbLocaleIndex();
233 GameObjectLocale
const *gl
= sObjectMgr
.GetGameObjectLocale(entryID
);
236 if (gl
->Name
.size() > size_t(loc_idx
) && !gl
->Name
[loc_idx
].empty())
237 Name
= gl
->Name
[loc_idx
];
238 if (gl
->CastBarCaption
.size() > size_t(loc_idx
) && !gl
->CastBarCaption
[loc_idx
].empty())
239 CastBarCaption
= gl
->CastBarCaption
[loc_idx
];
242 sLog
.outDetail("WORLD: CMSG_GAMEOBJECT_QUERY '%s' - Entry: %u. ", info
->name
, entryID
);
243 WorldPacket
data ( SMSG_GAMEOBJECT_QUERY_RESPONSE
, 150 );
244 data
<< uint32(entryID
);
245 data
<< uint32(info
->type
);
246 data
<< uint32(info
->displayId
);
248 data
<< uint8(0) << uint8(0) << uint8(0); // name2, name3, name4
249 data
<< IconName
; // 2.0.3, string. Icon name to use instead of default icon for go's (ex: "Attack" makes sword)
250 data
<< CastBarCaption
; // 2.0.3, string. Text will appear in Cast Bar when using GO (ex: "Collecting")
251 data
<< info
->unk1
; // 2.0.3, string
252 data
.append(info
->raw
.data
, 24);
253 data
<< float(info
->size
); // go size
254 for(uint32 i
= 0; i
< 6; ++i
)
255 data
<< uint32(info
->questItems
[i
]); // itemId[6], quest drop
257 sLog
.outDebug( "WORLD: Sent SMSG_GAMEOBJECT_QUERY_RESPONSE" );
261 sLog
.outDebug( "WORLD: CMSG_GAMEOBJECT_QUERY - Missing gameobject info for (GUID: %u, ENTRY: %u)",
262 GUID_LOPART(guid
), entryID
);
263 WorldPacket
data ( SMSG_GAMEOBJECT_QUERY_RESPONSE
, 4 );
264 data
<< uint32(entryID
| 0x80000000);
266 sLog
.outDebug( "WORLD: Sent SMSG_GAMEOBJECT_QUERY_RESPONSE" );
270 void WorldSession::HandleCorpseQueryOpcode(WorldPacket
& /*recv_data*/)
272 sLog
.outDetail("WORLD: Received MSG_CORPSE_QUERY");
274 Corpse
*corpse
= GetPlayer()->GetCorpse();
278 WorldPacket
data(MSG_CORPSE_QUERY
, 1);
279 data
<< uint8(0); // corpse not found
284 int32 mapid
= corpse
->GetMapId();
285 float x
= corpse
->GetPositionX();
286 float y
= corpse
->GetPositionY();
287 float z
= corpse
->GetPositionZ();
288 int32 corpsemapid
= mapid
;
290 // if corpse at different map
291 if(mapid
!= _player
->GetMapId())
293 // search entrance map for proper show entrance
294 if(MapEntry
const* corpseMapEntry
= sMapStore
.LookupEntry(mapid
))
296 if(corpseMapEntry
->IsDungeon() && corpseMapEntry
->entrance_map
>= 0)
298 // if corpse map have entrance
299 if(Map
const* entranceMap
= sMapMgr
.CreateBaseMap(corpseMapEntry
->entrance_map
))
301 mapid
= corpseMapEntry
->entrance_map
;
302 x
= corpseMapEntry
->entrance_x
;
303 y
= corpseMapEntry
->entrance_y
;
304 z
= entranceMap
->GetHeight(x
, y
, MAX_HEIGHT
);
310 WorldPacket
data(MSG_CORPSE_QUERY
, 1+(6*4));
311 data
<< uint8(1); // corpse found
312 data
<< int32(mapid
);
316 data
<< int32(corpsemapid
);
317 data
<< uint32(0); // unknown
321 void WorldSession::HandleNpcTextQueryOpcode( WorldPacket
& recv_data
)
327 sLog
.outDetail("WORLD: CMSG_NPC_TEXT_QUERY ID '%u'", textID
);
330 _player
->SetTargetGUID(guid
);
332 GossipText
const* pGossip
= sObjectMgr
.GetGossipText(textID
);
334 WorldPacket
data( SMSG_NPC_TEXT_UPDATE
, 100 ); // guess size
339 for(uint32 i
= 0; i
< 8; ++i
)
342 data
<< "Greetings $N";
343 data
<< "Greetings $N";
355 std::string Text_0
[8], Text_1
[8];
356 for (int i
= 0; i
< 8; ++i
)
358 Text_0
[i
]=pGossip
->Options
[i
].Text_0
;
359 Text_1
[i
]=pGossip
->Options
[i
].Text_1
;
362 int loc_idx
= GetSessionDbLocaleIndex();
365 NpcTextLocale
const *nl
= sObjectMgr
.GetNpcTextLocale(textID
);
368 for (int i
= 0; i
< 8; ++i
)
370 if (nl
->Text_0
[i
].size() > size_t(loc_idx
) && !nl
->Text_0
[i
][loc_idx
].empty())
371 Text_0
[i
]=nl
->Text_0
[i
][loc_idx
];
372 if (nl
->Text_1
[i
].size() > size_t(loc_idx
) && !nl
->Text_1
[i
][loc_idx
].empty())
373 Text_1
[i
]=nl
->Text_1
[i
][loc_idx
];
378 for (int i
= 0; i
< 8; ++i
)
380 data
<< pGossip
->Options
[i
].Probability
;
382 if ( Text_0
[i
].empty() )
387 if ( Text_1
[i
].empty() )
392 data
<< pGossip
->Options
[i
].Language
;
394 for(int j
= 0; j
< 3; ++j
)
396 data
<< pGossip
->Options
[i
].Emotes
[j
]._Delay
;
397 data
<< pGossip
->Options
[i
].Emotes
[j
]._Emote
;
404 sLog
.outDebug( "WORLD: Sent SMSG_NPC_TEXT_UPDATE" );
407 void WorldSession::HandlePageTextQueryOpcode( WorldPacket
& recv_data
)
409 sLog
.outDetail("WORLD: Received CMSG_PAGE_TEXT_QUERY");
414 recv_data
.read_skip
<uint64
>(); // guid
418 PageText
const *pPage
= sPageTextStore
.LookupEntry
<PageText
>( pageID
);
420 WorldPacket
data( SMSG_PAGE_TEXT_QUERY_RESPONSE
, 50 );
425 data
<< "Item page missing.";
431 std::string Text
= pPage
->Text
;
433 int loc_idx
= GetSessionDbLocaleIndex();
436 PageTextLocale
const *pl
= sObjectMgr
.GetPageTextLocale(pageID
);
439 if (pl
->Text
.size() > size_t(loc_idx
) && !pl
->Text
[loc_idx
].empty())
440 Text
= pl
->Text
[loc_idx
];
445 data
<< uint32(pPage
->Next_Page
);
446 pageID
= pPage
->Next_Page
;
450 sLog
.outDebug( "WORLD: Sent SMSG_PAGE_TEXT_QUERY_RESPONSE" );
454 void WorldSession::HandleCorpseMapPositionQuery( WorldPacket
& recv_data
)
456 sLog
.outDebug( "WORLD: Recv CMSG_CORPSE_MAP_POSITION_QUERY" );
461 WorldPacket
data(SMSG_CORPSE_MAP_POSITION_QUERY_RESPONSE
, 4+4+4+4);
469 void WorldSession::HandleQueryQuestsCompleted( WorldPacket
& /*recv_data */)
473 WorldPacket
data(SMSG_QUERY_QUESTS_COMPLETED_RESPONSE
, 4+4*count
);
474 data
<< uint32(count
);
476 for(QuestStatusMap::const_iterator itr
= _player
->getQuestStatusMap().begin(); itr
!= _player
->getQuestStatusMap().end(); ++itr
)
478 if(itr
->second
.m_rewarded
)
480 data
<< uint32(itr
->first
);
484 data
.put
<uint32
>(0, count
);
488 void WorldSession::HandleQuestPOIQuery(WorldPacket
& recv_data
)
491 recv_data
>> count
; // quest count, max=25
493 if(count
> MAX_QUEST_LOG_SIZE
)
495 recv_data
.rpos(recv_data
.wpos()); // set to end to avoid warnings spam
499 WorldPacket
data(SMSG_QUEST_POI_QUERY_RESPONSE
, 4+(4+4)*count
);
500 data
<< uint32(count
); // count
502 for(uint32 i
= 0; i
< count
; ++i
)
505 recv_data
>> questId
; // quest id
507 bool questOk
= false;
509 uint16 questSlot
= _player
->FindQuestSlot(questId
);
511 if(questSlot
!= MAX_QUEST_LOG_SIZE
)
512 questOk
=_player
->GetQuestSlotQuestId(questSlot
) == questId
;
516 QuestPOIVector
const *POI
= sObjectMgr
.GetQuestPOIVector(questId
);
520 data
<< uint32(questId
); // quest ID
521 data
<< uint32(POI
->size()); // POI count
524 for(QuestPOIVector::const_iterator itr
= POI
->begin(); itr
!= POI
->end(); ++itr
)
526 data
<< uint32(index
); // POI index
527 data
<< int32(itr
->ObjectiveIndex
); // objective index
528 data
<< uint32(itr
->MapId
); // mapid
529 data
<< uint32(itr
->Unk1
); // unknown
530 data
<< uint32(itr
->Unk2
); // unknown
531 data
<< uint32(itr
->Unk3
); // unknown
532 data
<< uint32(itr
->Unk4
); // unknown
533 data
<< uint32(itr
->points
.size()); // POI points count
535 for(std::vector
<QuestPOIPoint
>::const_iterator itr2
= itr
->points
.begin(); itr2
!= itr
->points
.end(); ++itr2
)
537 data
<< int32(itr2
->x
); // POI point x
538 data
<< int32(itr2
->y
); // POI point y
545 data
<< uint32(questId
); // quest ID
546 data
<< uint32(0); // POI count
551 data
<< uint32(questId
); // quest ID
552 data
<< uint32(0); // POI count
560 void WorldSession::SendQueryTimeResponse()
562 WorldPacket
data(SMSG_QUERY_TIME_RESPONSE
, 4+4);
563 data
<< uint32(time(NULL
));
564 data
<< uint32(sWorld
.GetNextDailyQuestsResetTime() - time(NULL
));