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::HandleDebugInArcCommand(const char* /*args*/)
36 Object
*obj
= getSelectedUnit();
40 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
44 SendSysMessage(LANG_NOT_IMPLEMENTED
);
49 bool ChatHandler::HandleDebugSpellFailCommand(const char* args
)
54 char* px
= strtok((char*)args
, " ");
58 uint8 failnum
= (uint8
)atoi(px
);
60 WorldPacket
data(SMSG_CAST_FAILED
, 5);
63 data
<< uint8(failnum
);
64 m_session
->SendPacket(&data
);
69 bool ChatHandler::HandleDebugSetPoiCommand(const char* args
)
71 Player
*pPlayer
= m_session
->GetPlayer();
72 Unit
* target
= getSelectedUnit();
75 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
82 char* icon_text
= strtok((char*)args
, " ");
83 char* flags_text
= strtok(NULL
, " ");
84 if(!icon_text
|| !flags_text
)
87 uint32 icon
= atol(icon_text
);
88 uint32 flags
= atol(flags_text
);
90 sLog
.outDetail("Command : POI, NPC = %u, icon = %u flags = %u", target
->GetGUIDLow(), icon
,flags
);
91 pPlayer
->PlayerTalkClass
->SendPointOfInterest(target
->GetPositionX(), target
->GetPositionY(), Poi_Icon(icon
), flags
, 30, "Test POI");
95 bool ChatHandler::HandleDebugEquipErrorCommand(const char* args
)
100 uint8 msg
= atoi(args
);
101 m_session
->GetPlayer()->SendEquipError(msg
, 0, 0);
105 bool ChatHandler::HandleDebugSellErrorCommand(const char* args
)
110 uint8 msg
= atoi(args
);
111 m_session
->GetPlayer()->SendSellError(msg
, 0, 0, 0);
115 bool ChatHandler::HandleDebugBuyErrorCommand(const char* args
)
120 uint8 msg
= atoi(args
);
121 m_session
->GetPlayer()->SendBuyError(msg
, 0, 0, 0);
125 bool ChatHandler::HandleDebugSendOpcodeCommand(const char* /*args*/)
127 Unit
*unit
= getSelectedUnit();
128 if (!unit
|| (unit
->GetTypeId() != TYPEID_PLAYER
))
129 unit
= m_session
->GetPlayer();
131 std::ifstream
ifs("opcode.txt");
138 WorldPacket
data(opcode
, 0);
154 else if(type
== "uint16")
160 else if(type
== "uint32")
166 else if(type
== "uint64")
172 else if(type
== "float")
178 else if(type
== "string")
184 else if(type
== "pguid")
186 data
.append(unit
->GetPackGUID());
190 sLog
.outDebug("Sending opcode: unknown type '%s'", type
.c_str());
195 sLog
.outDebug("Sending opcode %u", data
.GetOpcode());
197 ((Player
*)unit
)->GetSession()->SendPacket(&data
);
198 PSendSysMessage(LANG_COMMAND_OPCODESENT
, data
.GetOpcode(), unit
->GetName());
202 bool ChatHandler::HandleDebugUpdateWorldStateCommand(const char* args
)
204 char* w
= strtok((char*)args
, " ");
205 char* s
= strtok(NULL
, " ");
210 uint32 world
= (uint32
)atoi(w
);
211 uint32 state
= (uint32
)atoi(s
);
212 m_session
->GetPlayer()->SendUpdateWorldState(world
, state
);
217 bool ChatHandler::HandleDebugPlaySoundCommand(const char* args
)
219 // USAGE: .debug playsound #soundid
220 // #soundid - ID decimal number from SoundEntries.dbc (1st column)
223 SendSysMessage(LANG_BAD_VALUE
);
224 SetSentErrorMessage(true);
228 uint32 dwSoundId
= atoi((char*)args
);
230 if(!sSoundEntriesStore
.LookupEntry(dwSoundId
))
232 PSendSysMessage(LANG_SOUND_NOT_EXIST
, dwSoundId
);
233 SetSentErrorMessage(true);
237 Unit
* unit
= getSelectedUnit();
240 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
241 SetSentErrorMessage(true);
245 if(m_session
->GetPlayer()->GetSelection())
246 unit
->PlayDistanceSound(dwSoundId
,m_session
->GetPlayer());
248 unit
->PlayDirectSound(dwSoundId
,m_session
->GetPlayer());
250 PSendSysMessage(LANG_YOU_HEAR_SOUND
, dwSoundId
);
254 //Send notification in channel
255 bool ChatHandler::HandleDebugSendChannelNotifyCommand(const char* args
)
260 const char *name
= "test";
261 uint8 code
= atoi(args
);
263 WorldPacket
data(SMSG_CHANNEL_NOTIFY
, (1+10));
264 data
<< code
; // notify type
265 data
<< name
; // channel name
268 m_session
->SendPacket(&data
);
272 //Send notification in chat
273 bool ChatHandler::HandleDebugSendChatMsgCommand(const char* args
)
278 const char *msg
= "testtest";
279 uint8 type
= atoi(args
);
281 ChatHandler::FillMessageData(&data
, m_session
, type
, 0, "chan", m_session
->GetPlayer()->GetGUID(), msg
, m_session
->GetPlayer());
282 m_session
->SendPacket(&data
);
286 bool ChatHandler::HandleDebugSendQuestPartyMsgCommand(const char* args
)
288 uint32 msg
= atol((char*)args
);
289 m_session
->GetPlayer()->SendPushToPartyResponse(m_session
->GetPlayer(), msg
);
293 bool ChatHandler::HandleDebugGetLootRecipient(const char* /*args*/)
295 Creature
* target
= getSelectedCreature();
299 PSendSysMessage("loot recipient: %s", target
->hasLootRecipient()?(target
->GetLootRecipient()?target
->GetLootRecipient()->GetName():"offline"):"no loot recipient");
303 bool ChatHandler::HandleDebugSendQuestInvalidMsgCommand(const char* args
)
305 uint32 msg
= atol((char*)args
);
306 m_session
->GetPlayer()->SendCanTakeQuestResponse(msg
);
310 bool ChatHandler::HandleDebugGetItemState(const char* args
)
315 std::string state_str
= args
;
317 ItemUpdateState state
= ITEM_UNCHANGED
;
318 bool list_queue
= false, check_all
= false;
319 if (state_str
== "unchanged") state
= ITEM_UNCHANGED
;
320 else if (state_str
== "changed") state
= ITEM_CHANGED
;
321 else if (state_str
== "new") state
= ITEM_NEW
;
322 else if (state_str
== "removed") state
= ITEM_REMOVED
;
323 else if (state_str
== "queue") list_queue
= true;
324 else if (state_str
== "check_all") check_all
= true;
327 Player
* player
= getSelectedPlayer();
328 if (!player
) player
= m_session
->GetPlayer();
330 if (!list_queue
&& !check_all
)
332 state_str
= "The player has the following " + state_str
+ " items: ";
333 SendSysMessage(state_str
.c_str());
334 for (uint8 i
= PLAYER_SLOT_START
; i
< PLAYER_SLOT_END
; i
++)
336 if(i
>= BUYBACK_SLOT_START
&& i
< BUYBACK_SLOT_END
)
339 Item
*item
= player
->GetItemByPos(INVENTORY_SLOT_BAG_0
, i
);
343 if (item
->GetState() == state
)
344 PSendSysMessage("bag: 255 slot: %d guid: %d owner: %d", item
->GetSlot(), item
->GetGUIDLow(), GUID_LOPART(item
->GetOwnerGUID()));
348 Bag
*bag
= (Bag
*)item
;
349 for (uint8 j
= 0; j
< bag
->GetBagSize(); ++j
)
351 Item
* item
= bag
->GetItemByPos(j
);
352 if (item
&& item
->GetState() == state
)
353 PSendSysMessage("bag: 255 slot: %d guid: %d owner: %d", item
->GetSlot(), item
->GetGUIDLow(), GUID_LOPART(item
->GetOwnerGUID()));
361 std::vector
<Item
*> &updateQueue
= player
->GetItemUpdateQueue();
362 for(size_t i
= 0; i
< updateQueue
.size(); i
++)
364 Item
*item
= updateQueue
[i
];
367 Bag
*container
= item
->GetContainer();
368 uint8 bag_slot
= container
? container
->GetSlot() : uint8(INVENTORY_SLOT_BAG_0
);
371 switch(item
->GetState())
373 case ITEM_UNCHANGED
: st
= "unchanged"; break;
374 case ITEM_CHANGED
: st
= "changed"; break;
375 case ITEM_NEW
: st
= "new"; break;
376 case ITEM_REMOVED
: st
= "removed"; break;
379 PSendSysMessage("bag: %d slot: %d guid: %d - state: %s", bag_slot
, item
->GetSlot(), item
->GetGUIDLow(), st
.c_str());
381 if (updateQueue
.empty())
382 PSendSysMessage("updatequeue empty");
388 std::vector
<Item
*> &updateQueue
= player
->GetItemUpdateQueue();
389 for (uint8 i
= PLAYER_SLOT_START
; i
< PLAYER_SLOT_END
; i
++)
391 if(i
>= BUYBACK_SLOT_START
&& i
< BUYBACK_SLOT_END
)
394 Item
*item
= player
->GetItemByPos(INVENTORY_SLOT_BAG_0
, i
);
397 if (item
->GetSlot() != i
)
399 PSendSysMessage("item at slot %d, guid %d has an incorrect slot value: %d", i
, item
->GetGUIDLow(), item
->GetSlot());
400 error
= true; continue;
403 if (item
->GetOwnerGUID() != player
->GetGUID())
405 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());
406 error
= true; continue;
409 if (Bag
*container
= item
->GetContainer())
411 PSendSysMessage("item at slot: %d guid: %d has a container (slot: %d, guid: %d) but shouldnt!", item
->GetSlot(), item
->GetGUIDLow(), container
->GetSlot(), container
->GetGUIDLow());
412 error
= true; continue;
415 if (item
->IsInUpdateQueue())
417 uint16 qp
= item
->GetQueuePos();
418 if (qp
> updateQueue
.size())
420 PSendSysMessage("item at slot: %d guid: %d has a queuepos (%d) larger than the update queue size! ", item
->GetSlot(), item
->GetGUIDLow(), qp
);
421 error
= true; continue;
424 if (updateQueue
[qp
] == NULL
)
426 PSendSysMessage("item at slot: %d guid: %d has a queuepos (%d) that points to NULL in the queue!", item
->GetSlot(), item
->GetGUIDLow(), qp
);
427 error
= true; continue;
430 if (updateQueue
[qp
] != item
)
432 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());
433 error
= true; continue;
436 else if (item
->GetState() != ITEM_UNCHANGED
)
438 PSendSysMessage("item at slot: %d guid: %d is not in queue but should be (state: %d)!", item
->GetSlot(), item
->GetGUIDLow(), item
->GetState());
439 error
= true; continue;
444 Bag
*bag
= (Bag
*)item
;
445 for (uint8 j
= 0; j
< bag
->GetBagSize(); ++j
)
447 Item
* item
= bag
->GetItemByPos(j
);
450 if (item
->GetSlot() != j
)
452 PSendSysMessage("the item in bag %d slot %d, guid %d has an incorrect slot value: %d", bag
->GetSlot(), j
, item
->GetGUIDLow(), item
->GetSlot());
453 error
= true; continue;
456 if (item
->GetOwnerGUID() != player
->GetGUID())
458 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(), item
->GetSlot(), item
->GetGUIDLow(), GUID_LOPART(item
->GetOwnerGUID()), player
->GetGUIDLow());
459 error
= true; continue;
462 Bag
*container
= item
->GetContainer();
465 PSendSysMessage("the item in bag %d at slot %d with guid %d has no container!", bag
->GetSlot(), item
->GetSlot(), item
->GetGUIDLow());
466 error
= true; continue;
469 if (container
!= bag
)
471 PSendSysMessage("the item in bag %d at slot %d with guid %d has a different container(slot %d guid %d)!", bag
->GetSlot(), item
->GetSlot(), item
->GetGUIDLow(), container
->GetSlot(), container
->GetGUIDLow());
472 error
= true; continue;
475 if (item
->IsInUpdateQueue())
477 uint16 qp
= item
->GetQueuePos();
478 if (qp
> updateQueue
.size())
480 PSendSysMessage("item in bag: %d at slot: %d guid: %d has a queuepos (%d) larger than the update queue size! ", bag
->GetSlot(), item
->GetSlot(), item
->GetGUIDLow(), qp
);
481 error
= true; continue;
484 if (updateQueue
[qp
] == NULL
)
486 PSendSysMessage("item in bag: %d at slot: %d guid: %d has a queuepos (%d) that points to NULL in the queue!", bag
->GetSlot(), item
->GetSlot(), item
->GetGUIDLow(), qp
);
487 error
= true; continue;
490 if (updateQueue
[qp
] != item
)
492 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(), item
->GetSlot(), item
->GetGUIDLow(), qp
, updateQueue
[qp
]->GetBagSlot(), updateQueue
[qp
]->GetSlot(), updateQueue
[qp
]->GetGUIDLow());
493 error
= true; continue;
496 else if (item
->GetState() != ITEM_UNCHANGED
)
498 PSendSysMessage("item in bag: %d at slot: %d guid: %d is not in queue but should be (state: %d)!", bag
->GetSlot(), item
->GetSlot(), item
->GetGUIDLow(), item
->GetState());
499 error
= true; continue;
505 for(size_t i
= 0; i
< updateQueue
.size(); i
++)
507 Item
*item
= updateQueue
[i
];
510 if (item
->GetOwnerGUID() != player
->GetGUID())
512 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());
513 error
= true; continue;
516 if (item
->GetQueuePos() != i
)
518 PSendSysMessage("queue(%d): for the an item (guid %d), the queuepos doesn't match it's position in the queue!", i
, item
->GetGUIDLow());
519 error
= true; continue;
522 if (item
->GetState() == ITEM_REMOVED
) continue;
523 Item
*test
= player
->GetItemByPos( item
->GetBagSlot(), item
->GetSlot());
527 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());
528 error
= true; continue;
533 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());
534 error
= true; continue;
538 SendSysMessage("All OK!");
544 bool ChatHandler::HandleDebugBattlegroundCommand(const char * /*args*/)
546 sBattleGroundMgr
.ToggleTesting();
550 bool ChatHandler::HandleDebugArenaCommand(const char * /*args*/)
552 sBattleGroundMgr
.ToggleArenaTesting();
556 bool ChatHandler::HandleDebugSpawnVehicle(const char* args
)
561 char* e
= strtok((char*)args
, " ");
562 char* i
= strtok(NULL
, " ");
567 uint32 entry
= (uint32
)atoi(e
);
568 uint32 id
= (uint32
)atoi(i
);
570 CreatureInfo
const *ci
= objmgr
.GetCreatureTemplate(entry
);
575 VehicleEntry
const *ve
= sVehicleStore
.LookupEntry(id
);
580 Vehicle
*v
= new Vehicle
;
581 Map
*map
= m_session
->GetPlayer()->GetMap();
582 if(!v
->Create(objmgr
.GenerateLowGuid(HIGHGUID_VEHICLE
), map
, entry
, id
, m_session
->GetPlayer()->GetTeam()))
589 m_session
->GetPlayer()->GetClosePoint(px
, py
, pz
, m_session
->GetPlayer()->GetObjectSize());
591 v
->Relocate(px
, py
, pz
, m_session
->GetPlayer()->GetOrientation());
593 if(!v
->IsPositionValid())
595 sLog
.outError("Vehicle (guidlow %d, entry %d) not created. Suggested coordinates isn't valid (X: %f Y: %f)",
596 v
->GetGUIDLow(), v
->GetEntry(), v
->GetPositionX(), v
->GetPositionY());
601 map
->Add((Creature
*)v
);
606 bool ChatHandler::HandleDebugSendLargePacketCommand(const char* /*args*/)
608 const char* stuffingString
= "This is a dummy string to push the packet's size beyond 128000 bytes. ";
609 std::ostringstream ss
;
610 while(ss
.str().size() < 128000)
611 ss
<< stuffingString
;
612 SendSysMessage(ss
.str().c_str());
616 bool ChatHandler::HandleDebugSendSetPhaseShiftCommand(const char* args
)
621 uint32 PhaseShift
= atoi(args
);
622 m_session
->SendSetPhaseShift(PhaseShift
);
626 bool ChatHandler::HandleDebugSetItemFlagCommand(const char* args
)
631 char* e
= strtok((char*)args
, " ");
632 char* f
= strtok(NULL
, " ");
637 uint32 guid
= (uint32
)atoi(e
);
638 uint32 flag
= (uint32
)atoi(f
);
640 Item
*i
= m_session
->GetPlayer()->GetItemByGuid(MAKE_NEW_GUID(guid
, 0, HIGHGUID_ITEM
));
645 i
->SetUInt32Value(ITEM_FIELD_FLAGS
, flag
);