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
20 #include "Database/DatabaseEnv.h"
21 #include "WorldPacket.h"
28 #include "GossipDef.h"
30 #include "BattleGroundMgr.h"
32 #include "ObjectMgr.h"
34 bool ChatHandler::HandleDebugSendSpellFailCommand(const char* args
)
39 char* px
= strtok((char*)args
, " ");
43 uint8 failnum
= (uint8
)atoi(px
);
44 if(failnum
==0 && *px
!='0')
47 char* p1
= strtok(NULL
, " ");
48 uint8 failarg1
= p1
? (uint8
)atoi(p1
) : 0;
50 char* p2
= strtok(NULL
, " ");
51 uint8 failarg2
= p2
? (uint8
)atoi(p2
) : 0;
54 WorldPacket
data(SMSG_CAST_FAILED
, 5);
57 data
<< uint8(failnum
);
59 data
<< uint32(failarg1
);
61 data
<< uint32(failarg2
);
63 m_session
->SendPacket(&data
);
68 bool ChatHandler::HandleDebugSendPoiCommand(const char* args
)
70 Player
*pPlayer
= m_session
->GetPlayer();
71 Unit
* target
= getSelectedUnit();
74 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
81 char* icon_text
= strtok((char*)args
, " ");
82 char* flags_text
= strtok(NULL
, " ");
83 if(!icon_text
|| !flags_text
)
86 uint32 icon
= atol(icon_text
);
87 uint32 flags
= atol(flags_text
);
89 sLog
.outDetail("Command : POI, NPC = %u, icon = %u flags = %u", target
->GetGUIDLow(), icon
,flags
);
90 pPlayer
->PlayerTalkClass
->SendPointOfInterest(target
->GetPositionX(), target
->GetPositionY(), Poi_Icon(icon
), flags
, 30, "Test POI");
94 bool ChatHandler::HandleDebugSendEquipErrorCommand(const char* args
)
99 uint8 msg
= atoi(args
);
100 m_session
->GetPlayer()->SendEquipError(msg
, 0, 0);
104 bool ChatHandler::HandleDebugSendSellErrorCommand(const char* args
)
109 uint8 msg
= atoi(args
);
110 m_session
->GetPlayer()->SendSellError(msg
, 0, 0, 0);
114 bool ChatHandler::HandleDebugSendBuyErrorCommand(const char* args
)
119 uint8 msg
= atoi(args
);
120 m_session
->GetPlayer()->SendBuyError(msg
, 0, 0, 0);
124 bool ChatHandler::HandleDebugSendOpcodeCommand(const char* /*args*/)
126 Unit
*unit
= getSelectedUnit();
127 if (!unit
|| (unit
->GetTypeId() != TYPEID_PLAYER
))
128 unit
= m_session
->GetPlayer();
130 std::ifstream
ifs("opcode.txt");
137 WorldPacket
data(opcode
, 0);
153 else if(type
== "uint16")
159 else if(type
== "uint32")
165 else if(type
== "uint64")
171 else if(type
== "float")
177 else if(type
== "string")
183 else if(type
== "pguid")
185 data
.append(unit
->GetPackGUID());
189 sLog
.outDebug("Sending opcode: unknown type '%s'", type
.c_str());
194 sLog
.outDebug("Sending opcode %u", data
.GetOpcode());
196 ((Player
*)unit
)->GetSession()->SendPacket(&data
);
197 PSendSysMessage(LANG_COMMAND_OPCODESENT
, data
.GetOpcode(), unit
->GetName());
201 bool ChatHandler::HandleDebugUpdateWorldStateCommand(const char* args
)
203 char* w
= strtok((char*)args
, " ");
204 char* s
= strtok(NULL
, " ");
209 uint32 world
= (uint32
)atoi(w
);
210 uint32 state
= (uint32
)atoi(s
);
211 m_session
->GetPlayer()->SendUpdateWorldState(world
, state
);
215 bool ChatHandler::HandleDebugPlayCinematicCommand(const char* args
)
217 // USAGE: .debug play cinematic #cinematicid
218 // #cinematicid - ID decimal number from CinemaicSequences.dbc (1st column)
221 SendSysMessage(LANG_BAD_VALUE
);
222 SetSentErrorMessage(true);
226 uint32 dwId
= atoi((char*)args
);
228 if(!sCinematicSequencesStore
.LookupEntry(dwId
))
230 PSendSysMessage(LANG_CINEMATIC_NOT_EXIST
, dwId
);
231 SetSentErrorMessage(true);
235 m_session
->GetPlayer()->SendCinematicStart(dwId
);
239 bool ChatHandler::HandleDebugPlayMovieCommand(const char* args
)
241 // USAGE: .debug play movie #movieid
242 // #movieid - ID decimal number from Movie.dbc (1st column)
245 SendSysMessage(LANG_BAD_VALUE
);
246 SetSentErrorMessage(true);
250 uint32 dwId
= atoi((char*)args
);
252 if(!sMovieStore
.LookupEntry(dwId
))
254 PSendSysMessage(LANG_MOVIE_NOT_EXIST
, dwId
);
255 SetSentErrorMessage(true);
259 m_session
->GetPlayer()->SendMovieStart(dwId
);
264 bool ChatHandler::HandleDebugPlaySoundCommand(const char* args
)
266 // USAGE: .debug playsound #soundid
267 // #soundid - ID decimal number from SoundEntries.dbc (1st column)
270 SendSysMessage(LANG_BAD_VALUE
);
271 SetSentErrorMessage(true);
275 uint32 dwSoundId
= atoi((char*)args
);
277 if(!sSoundEntriesStore
.LookupEntry(dwSoundId
))
279 PSendSysMessage(LANG_SOUND_NOT_EXIST
, dwSoundId
);
280 SetSentErrorMessage(true);
284 Unit
* unit
= getSelectedUnit();
287 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
288 SetSentErrorMessage(true);
292 if(m_session
->GetPlayer()->GetSelection())
293 unit
->PlayDistanceSound(dwSoundId
,m_session
->GetPlayer());
295 unit
->PlayDirectSound(dwSoundId
,m_session
->GetPlayer());
297 PSendSysMessage(LANG_YOU_HEAR_SOUND
, dwSoundId
);
301 //Send notification in channel
302 bool ChatHandler::HandleDebugSendChannelNotifyCommand(const char* args
)
307 const char *name
= "test";
308 uint8 code
= atoi(args
);
310 WorldPacket
data(SMSG_CHANNEL_NOTIFY
, (1+10));
311 data
<< code
; // notify type
312 data
<< name
; // channel name
315 m_session
->SendPacket(&data
);
319 //Send notification in chat
320 bool ChatHandler::HandleDebugSendChatMsgCommand(const char* args
)
325 const char *msg
= "testtest";
326 uint8 type
= atoi(args
);
328 ChatHandler::FillMessageData(&data
, m_session
, type
, 0, "chan", m_session
->GetPlayer()->GetGUID(), msg
, m_session
->GetPlayer());
329 m_session
->SendPacket(&data
);
333 bool ChatHandler::HandleDebugSendQuestPartyMsgCommand(const char* args
)
335 uint32 msg
= atol((char*)args
);
336 m_session
->GetPlayer()->SendPushToPartyResponse(m_session
->GetPlayer(), msg
);
340 bool ChatHandler::HandleDebugGetLootRecipient(const char* /*args*/)
342 Creature
* target
= getSelectedCreature();
346 PSendSysMessage("loot recipient: %s", target
->hasLootRecipient()?(target
->GetLootRecipient()?target
->GetLootRecipient()->GetName():"offline"):"no loot recipient");
350 bool ChatHandler::HandleDebugSendQuestInvalidMsgCommand(const char* args
)
352 uint32 msg
= atol((char*)args
);
353 m_session
->GetPlayer()->SendCanTakeQuestResponse(msg
);
357 bool ChatHandler::HandleDebugGetItemState(const char* args
)
362 std::string state_str
= args
;
364 ItemUpdateState state
= ITEM_UNCHANGED
;
365 bool list_queue
= false, check_all
= false;
366 if (state_str
== "unchanged") state
= ITEM_UNCHANGED
;
367 else if (state_str
== "changed") state
= ITEM_CHANGED
;
368 else if (state_str
== "new") state
= ITEM_NEW
;
369 else if (state_str
== "removed") state
= ITEM_REMOVED
;
370 else if (state_str
== "queue") list_queue
= true;
371 else if (state_str
== "check_all") check_all
= true;
374 Player
* player
= getSelectedPlayer();
375 if (!player
) player
= m_session
->GetPlayer();
377 if (!list_queue
&& !check_all
)
379 state_str
= "The player has the following " + state_str
+ " items: ";
380 SendSysMessage(state_str
.c_str());
381 for (uint8 i
= PLAYER_SLOT_START
; i
< PLAYER_SLOT_END
; ++i
)
383 if(i
>= BUYBACK_SLOT_START
&& i
< BUYBACK_SLOT_END
)
386 Item
*item
= player
->GetItemByPos(INVENTORY_SLOT_BAG_0
, i
);
390 if (item
->GetState() == state
)
391 PSendSysMessage("bag: 255 slot: %d guid: %d owner: %d", item
->GetSlot(), item
->GetGUIDLow(), GUID_LOPART(item
->GetOwnerGUID()));
395 Bag
*bag
= (Bag
*)item
;
396 for (uint8 j
= 0; j
< bag
->GetBagSize(); ++j
)
398 Item
* item2
= bag
->GetItemByPos(j
);
399 if (item2
&& item2
->GetState() == state
)
400 PSendSysMessage("bag: 255 slot: %d guid: %d owner: %d", item2
->GetSlot(), item2
->GetGUIDLow(), GUID_LOPART(item2
->GetOwnerGUID()));
408 std::vector
<Item
*> &updateQueue
= player
->GetItemUpdateQueue();
409 for(size_t i
= 0; i
< updateQueue
.size(); ++i
)
411 Item
*item
= updateQueue
[i
];
414 Bag
*container
= item
->GetContainer();
415 uint8 bag_slot
= container
? container
->GetSlot() : uint8(INVENTORY_SLOT_BAG_0
);
418 switch(item
->GetState())
420 case ITEM_UNCHANGED
: st
= "unchanged"; break;
421 case ITEM_CHANGED
: st
= "changed"; break;
422 case ITEM_NEW
: st
= "new"; break;
423 case ITEM_REMOVED
: st
= "removed"; break;
426 PSendSysMessage("bag: %d slot: %d guid: %d - state: %s", bag_slot
, item
->GetSlot(), item
->GetGUIDLow(), st
.c_str());
428 if (updateQueue
.empty())
429 PSendSysMessage("updatequeue empty");
435 std::vector
<Item
*> &updateQueue
= player
->GetItemUpdateQueue();
436 for (uint8 i
= PLAYER_SLOT_START
; i
< PLAYER_SLOT_END
; ++i
)
438 if(i
>= BUYBACK_SLOT_START
&& i
< BUYBACK_SLOT_END
)
441 Item
*item
= player
->GetItemByPos(INVENTORY_SLOT_BAG_0
, i
);
444 if (item
->GetSlot() != i
)
446 PSendSysMessage("item at slot %d, guid %d has an incorrect slot value: %d", i
, item
->GetGUIDLow(), item
->GetSlot());
447 error
= true; continue;
450 if (item
->GetOwnerGUID() != player
->GetGUID())
452 PSendSysMessage("for the item at slot %d and itemguid %d, owner's guid (%d) and player's guid (%d) don't match!", item
->GetSlot(), item
->GetGUIDLow(), GUID_LOPART(item
->GetOwnerGUID()), player
->GetGUIDLow());
453 error
= true; continue;
456 if (Bag
*container
= item
->GetContainer())
458 PSendSysMessage("item at slot: %d guid: %d has a container (slot: %d, guid: %d) but shouldnt!", item
->GetSlot(), item
->GetGUIDLow(), container
->GetSlot(), container
->GetGUIDLow());
459 error
= true; continue;
462 if (item
->IsInUpdateQueue())
464 uint16 qp
= item
->GetQueuePos();
465 if (qp
> updateQueue
.size())
467 PSendSysMessage("item at slot: %d guid: %d has a queuepos (%d) larger than the update queue size! ", item
->GetSlot(), item
->GetGUIDLow(), qp
);
468 error
= true; continue;
471 if (updateQueue
[qp
] == NULL
)
473 PSendSysMessage("item at slot: %d guid: %d has a queuepos (%d) that points to NULL in the queue!", item
->GetSlot(), item
->GetGUIDLow(), qp
);
474 error
= true; continue;
477 if (updateQueue
[qp
] != item
)
479 PSendSysMessage("item at slot: %d guid: %d has has a queuepos (%d) that points to another item in the queue (bag: %d, slot: %d, guid: %d)", item
->GetSlot(), item
->GetGUIDLow(), qp
, updateQueue
[qp
]->GetBagSlot(), updateQueue
[qp
]->GetSlot(), updateQueue
[qp
]->GetGUIDLow());
480 error
= true; continue;
483 else if (item
->GetState() != ITEM_UNCHANGED
)
485 PSendSysMessage("item at slot: %d guid: %d is not in queue but should be (state: %d)!", item
->GetSlot(), item
->GetGUIDLow(), item
->GetState());
486 error
= true; continue;
491 Bag
*bag
= (Bag
*)item
;
492 for (uint8 j
= 0; j
< bag
->GetBagSize(); ++j
)
494 Item
* item2
= bag
->GetItemByPos(j
);
495 if (!item2
) continue;
497 if (item2
->GetSlot() != j
)
499 PSendSysMessage("the item in bag %d slot %d, guid %d has an incorrect slot value: %d", bag
->GetSlot(), j
, item2
->GetGUIDLow(), item2
->GetSlot());
500 error
= true; continue;
503 if (item2
->GetOwnerGUID() != player
->GetGUID())
505 PSendSysMessage("for the item in bag %d at slot %d and itemguid %d, owner's guid (%d) and player's guid (%d) don't match!", bag
->GetSlot(), item2
->GetSlot(), item2
->GetGUIDLow(), GUID_LOPART(item2
->GetOwnerGUID()), player
->GetGUIDLow());
506 error
= true; continue;
509 Bag
*container
= item2
->GetContainer();
512 PSendSysMessage("the item in bag %d at slot %d with guid %d has no container!", bag
->GetSlot(), item2
->GetSlot(), item2
->GetGUIDLow());
513 error
= true; continue;
516 if (container
!= bag
)
518 PSendSysMessage("the item in bag %d at slot %d with guid %d has a different container(slot %d guid %d)!", bag
->GetSlot(), item2
->GetSlot(), item2
->GetGUIDLow(), container
->GetSlot(), container
->GetGUIDLow());
519 error
= true; continue;
522 if (item2
->IsInUpdateQueue())
524 uint16 qp
= item2
->GetQueuePos();
525 if (qp
> updateQueue
.size())
527 PSendSysMessage("item in bag: %d at slot: %d guid: %d has a queuepos (%d) larger than the update queue size! ", bag
->GetSlot(), item2
->GetSlot(), item2
->GetGUIDLow(), qp
);
528 error
= true; continue;
531 if (updateQueue
[qp
] == NULL
)
533 PSendSysMessage("item in bag: %d at slot: %d guid: %d has a queuepos (%d) that points to NULL in the queue!", bag
->GetSlot(), item2
->GetSlot(), item2
->GetGUIDLow(), qp
);
534 error
= true; continue;
537 if (updateQueue
[qp
] != item2
)
539 PSendSysMessage("item in bag: %d at slot: %d guid: %d has has a queuepos (%d) that points to another item in the queue (bag: %d, slot: %d, guid: %d)", bag
->GetSlot(), item2
->GetSlot(), item2
->GetGUIDLow(), qp
, updateQueue
[qp
]->GetBagSlot(), updateQueue
[qp
]->GetSlot(), updateQueue
[qp
]->GetGUIDLow());
540 error
= true; continue;
543 else if (item2
->GetState() != ITEM_UNCHANGED
)
545 PSendSysMessage("item in bag: %d at slot: %d guid: %d is not in queue but should be (state: %d)!", bag
->GetSlot(), item2
->GetSlot(), item2
->GetGUIDLow(), item2
->GetState());
546 error
= true; continue;
552 for(size_t i
= 0; i
< updateQueue
.size(); ++i
)
554 Item
*item
= updateQueue
[i
];
557 if (item
->GetOwnerGUID() != player
->GetGUID())
559 PSendSysMessage("queue(%d): for the an item (guid %d), the owner's guid (%d) and player's guid (%d) don't match!", i
, item
->GetGUIDLow(), GUID_LOPART(item
->GetOwnerGUID()), player
->GetGUIDLow());
560 error
= true; continue;
563 if (item
->GetQueuePos() != i
)
565 PSendSysMessage("queue(%d): for the an item (guid %d), the queuepos doesn't match it's position in the queue!", i
, item
->GetGUIDLow());
566 error
= true; continue;
569 if (item
->GetState() == ITEM_REMOVED
) continue;
570 Item
*test
= player
->GetItemByPos( item
->GetBagSlot(), item
->GetSlot());
574 PSendSysMessage("queue(%d): the bag(%d) and slot(%d) values for the item with guid %d are incorrect, the player doesn't have an item at that position!", i
, item
->GetBagSlot(), item
->GetSlot(), item
->GetGUIDLow());
575 error
= true; continue;
580 PSendSysMessage("queue(%d): the bag(%d) and slot(%d) values for the item with guid %d are incorrect, the item with guid %d is there instead!", i
, item
->GetBagSlot(), item
->GetSlot(), item
->GetGUIDLow(), test
->GetGUIDLow());
581 error
= true; continue;
585 SendSysMessage("All OK!");
591 bool ChatHandler::HandleDebugBattlegroundCommand(const char * /*args*/)
593 sBattleGroundMgr
.ToggleTesting();
597 bool ChatHandler::HandleDebugArenaCommand(const char * /*args*/)
599 sBattleGroundMgr
.ToggleArenaTesting();
603 bool ChatHandler::HandleDebugSpawnVehicle(const char* args
)
608 char* e
= strtok((char*)args
, " ");
609 char* i
= strtok(NULL
, " ");
614 uint32 entry
= (uint32
)atoi(e
);
615 uint32 id
= (uint32
)atoi(i
);
617 CreatureInfo
const *ci
= objmgr
.GetCreatureTemplate(entry
);
622 VehicleEntry
const *ve
= sVehicleStore
.LookupEntry(id
);
627 Vehicle
*v
= new Vehicle
;
628 Map
*map
= m_session
->GetPlayer()->GetMap();
629 if(!v
->Create(objmgr
.GenerateLowGuid(HIGHGUID_VEHICLE
), map
, entry
, id
, m_session
->GetPlayer()->GetTeam()))
636 m_session
->GetPlayer()->GetClosePoint(px
, py
, pz
, m_session
->GetPlayer()->GetObjectSize());
638 v
->Relocate(px
, py
, pz
, m_session
->GetPlayer()->GetOrientation());
640 if(!v
->IsPositionValid())
642 sLog
.outError("Vehicle (guidlow %d, entry %d) not created. Suggested coordinates isn't valid (X: %f Y: %f)",
643 v
->GetGUIDLow(), v
->GetEntry(), v
->GetPositionX(), v
->GetPositionY());
648 map
->Add((Creature
*)v
);
653 bool ChatHandler::HandleDebugSendLargePacketCommand(const char* /*args*/)
655 const char* stuffingString
= "This is a dummy string to push the packet's size beyond 128000 bytes. ";
656 std::ostringstream ss
;
657 while(ss
.str().size() < 128000)
658 ss
<< stuffingString
;
659 SendSysMessage(ss
.str().c_str());
663 bool ChatHandler::HandleDebugSendSetPhaseShiftCommand(const char* args
)
668 uint32 PhaseShift
= atoi(args
);
669 m_session
->SendSetPhaseShift(PhaseShift
);
673 bool ChatHandler::HandleDebugSetItemFlagCommand(const char* args
)
678 char* e
= strtok((char*)args
, " ");
679 char* f
= strtok(NULL
, " ");
684 uint32 guid
= (uint32
)atoi(e
);
685 uint32 flag
= (uint32
)atoi(f
);
687 Item
*i
= m_session
->GetPlayer()->GetItemByGuid(MAKE_NEW_GUID(guid
, 0, HIGHGUID_ITEM
));
692 i
->SetUInt32Value(ITEM_FIELD_FLAGS
, flag
);
698 bool ChatHandler::HandleDebugAnimCommand(const char* args
)
703 uint32 anim_id
= atoi((char*)args
);
704 m_session
->GetPlayer()->HandleEmoteCommand(anim_id
);