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
);
216 bool ChatHandler::HandleDebugPlaySound2Command(const char* args
)
221 uint32 soundid
= atoi(args
);
222 m_session
->GetPlayer()->PlaySound(soundid
, false);
226 //Send notification in channel
227 bool ChatHandler::HandleDebugSendChannelNotifyCommand(const char* args
)
232 const char *name
= "test";
233 uint8 code
= atoi(args
);
235 WorldPacket
data(SMSG_CHANNEL_NOTIFY
, (1+10));
236 data
<< code
; // notify type
237 data
<< name
; // channel name
240 m_session
->SendPacket(&data
);
244 //Send notification in chat
245 bool ChatHandler::HandleDebugSendChatMsgCommand(const char* args
)
250 const char *msg
= "testtest";
251 uint8 type
= atoi(args
);
253 ChatHandler::FillMessageData(&data
, m_session
, type
, 0, "chan", m_session
->GetPlayer()->GetGUID(), msg
, m_session
->GetPlayer());
254 m_session
->SendPacket(&data
);
258 bool ChatHandler::HandleDebugSendQuestPartyMsgCommand(const char* args
)
260 uint32 msg
= atol((char*)args
);
261 m_session
->GetPlayer()->SendPushToPartyResponse(m_session
->GetPlayer(), msg
);
265 bool ChatHandler::HandleDebugGetLootRecipient(const char* /*args*/)
267 Creature
* target
= getSelectedCreature();
271 PSendSysMessage("loot recipient: %s", target
->hasLootRecipient()?(target
->GetLootRecipient()?target
->GetLootRecipient()->GetName():"offline"):"no loot recipient");
275 bool ChatHandler::HandleDebugSendQuestInvalidMsgCommand(const char* args
)
277 uint32 msg
= atol((char*)args
);
278 m_session
->GetPlayer()->SendCanTakeQuestResponse(msg
);
282 bool ChatHandler::HandleDebugGetItemState(const char* args
)
287 std::string state_str
= args
;
289 ItemUpdateState state
= ITEM_UNCHANGED
;
290 bool list_queue
= false, check_all
= false;
291 if (state_str
== "unchanged") state
= ITEM_UNCHANGED
;
292 else if (state_str
== "changed") state
= ITEM_CHANGED
;
293 else if (state_str
== "new") state
= ITEM_NEW
;
294 else if (state_str
== "removed") state
= ITEM_REMOVED
;
295 else if (state_str
== "queue") list_queue
= true;
296 else if (state_str
== "check_all") check_all
= true;
299 Player
* player
= getSelectedPlayer();
300 if (!player
) player
= m_session
->GetPlayer();
302 if (!list_queue
&& !check_all
)
304 state_str
= "The player has the following " + state_str
+ " items: ";
305 SendSysMessage(state_str
.c_str());
306 for (uint8 i
= PLAYER_SLOT_START
; i
< PLAYER_SLOT_END
; i
++)
308 if(i
>= BUYBACK_SLOT_START
&& i
< BUYBACK_SLOT_END
)
311 Item
*item
= player
->GetItemByPos(INVENTORY_SLOT_BAG_0
, i
);
315 if (item
->GetState() == state
)
316 PSendSysMessage("bag: 255 slot: %d guid: %d owner: %d", item
->GetSlot(), item
->GetGUIDLow(), GUID_LOPART(item
->GetOwnerGUID()));
320 Bag
*bag
= (Bag
*)item
;
321 for (uint8 j
= 0; j
< bag
->GetBagSize(); ++j
)
323 Item
* item
= bag
->GetItemByPos(j
);
324 if (item
&& item
->GetState() == state
)
325 PSendSysMessage("bag: 255 slot: %d guid: %d owner: %d", item
->GetSlot(), item
->GetGUIDLow(), GUID_LOPART(item
->GetOwnerGUID()));
333 std::vector
<Item
*> &updateQueue
= player
->GetItemUpdateQueue();
334 for(size_t i
= 0; i
< updateQueue
.size(); i
++)
336 Item
*item
= updateQueue
[i
];
339 Bag
*container
= item
->GetContainer();
340 uint8 bag_slot
= container
? container
->GetSlot() : uint8(INVENTORY_SLOT_BAG_0
);
343 switch(item
->GetState())
345 case ITEM_UNCHANGED
: st
= "unchanged"; break;
346 case ITEM_CHANGED
: st
= "changed"; break;
347 case ITEM_NEW
: st
= "new"; break;
348 case ITEM_REMOVED
: st
= "removed"; break;
351 PSendSysMessage("bag: %d slot: %d guid: %d - state: %s", bag_slot
, item
->GetSlot(), item
->GetGUIDLow(), st
.c_str());
353 if (updateQueue
.empty())
354 PSendSysMessage("updatequeue empty");
360 std::vector
<Item
*> &updateQueue
= player
->GetItemUpdateQueue();
361 for (uint8 i
= PLAYER_SLOT_START
; i
< PLAYER_SLOT_END
; i
++)
363 if(i
>= BUYBACK_SLOT_START
&& i
< BUYBACK_SLOT_END
)
366 Item
*item
= player
->GetItemByPos(INVENTORY_SLOT_BAG_0
, i
);
369 if (item
->GetSlot() != i
)
371 PSendSysMessage("item at slot %d, guid %d has an incorrect slot value: %d", i
, item
->GetGUIDLow(), item
->GetSlot());
372 error
= true; continue;
375 if (item
->GetOwnerGUID() != player
->GetGUID())
377 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());
378 error
= true; continue;
381 if (Bag
*container
= item
->GetContainer())
383 PSendSysMessage("item at slot: %d guid: %d has a container (slot: %d, guid: %d) but shouldnt!", item
->GetSlot(), item
->GetGUIDLow(), container
->GetSlot(), container
->GetGUIDLow());
384 error
= true; continue;
387 if (item
->IsInUpdateQueue())
389 uint16 qp
= item
->GetQueuePos();
390 if (qp
> updateQueue
.size())
392 PSendSysMessage("item at slot: %d guid: %d has a queuepos (%d) larger than the update queue size! ", item
->GetSlot(), item
->GetGUIDLow(), qp
);
393 error
= true; continue;
396 if (updateQueue
[qp
] == NULL
)
398 PSendSysMessage("item at slot: %d guid: %d has a queuepos (%d) that points to NULL in the queue!", item
->GetSlot(), item
->GetGUIDLow(), qp
);
399 error
= true; continue;
402 if (updateQueue
[qp
] != item
)
404 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());
405 error
= true; continue;
408 else if (item
->GetState() != ITEM_UNCHANGED
)
410 PSendSysMessage("item at slot: %d guid: %d is not in queue but should be (state: %d)!", item
->GetSlot(), item
->GetGUIDLow(), item
->GetState());
411 error
= true; continue;
416 Bag
*bag
= (Bag
*)item
;
417 for (uint8 j
= 0; j
< bag
->GetBagSize(); ++j
)
419 Item
* item
= bag
->GetItemByPos(j
);
422 if (item
->GetSlot() != j
)
424 PSendSysMessage("the item in bag %d slot %d, guid %d has an incorrect slot value: %d", bag
->GetSlot(), j
, item
->GetGUIDLow(), item
->GetSlot());
425 error
= true; continue;
428 if (item
->GetOwnerGUID() != player
->GetGUID())
430 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());
431 error
= true; continue;
434 Bag
*container
= item
->GetContainer();
437 PSendSysMessage("the item in bag %d at slot %d with guid %d has no container!", bag
->GetSlot(), item
->GetSlot(), item
->GetGUIDLow());
438 error
= true; continue;
441 if (container
!= bag
)
443 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());
444 error
= true; continue;
447 if (item
->IsInUpdateQueue())
449 uint16 qp
= item
->GetQueuePos();
450 if (qp
> updateQueue
.size())
452 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
);
453 error
= true; continue;
456 if (updateQueue
[qp
] == NULL
)
458 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
);
459 error
= true; continue;
462 if (updateQueue
[qp
] != item
)
464 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());
465 error
= true; continue;
468 else if (item
->GetState() != ITEM_UNCHANGED
)
470 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());
471 error
= true; continue;
477 for(size_t i
= 0; i
< updateQueue
.size(); i
++)
479 Item
*item
= updateQueue
[i
];
482 if (item
->GetOwnerGUID() != player
->GetGUID())
484 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());
485 error
= true; continue;
488 if (item
->GetQueuePos() != i
)
490 PSendSysMessage("queue(%d): for the an item (guid %d), the queuepos doesn't match it's position in the queue!", i
, item
->GetGUIDLow());
491 error
= true; continue;
494 if (item
->GetState() == ITEM_REMOVED
) continue;
495 Item
*test
= player
->GetItemByPos( item
->GetBagSlot(), item
->GetSlot());
499 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());
500 error
= true; continue;
505 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());
506 error
= true; continue;
510 SendSysMessage("All OK!");
516 bool ChatHandler::HandleDebugBattlegroundCommand(const char * /*args*/)
518 sBattleGroundMgr
.ToggleTesting();
522 bool ChatHandler::HandleDebugArenaCommand(const char * /*args*/)
524 sBattleGroundMgr
.ToggleArenaTesting();
528 bool ChatHandler::HandleDebugSpawnVehicle(const char* args
)
533 char* e
= strtok((char*)args
, " ");
534 char* i
= strtok(NULL
, " ");
539 uint32 entry
= (uint32
)atoi(e
);
540 uint32 id
= (uint32
)atoi(i
);
542 CreatureInfo
const *ci
= objmgr
.GetCreatureTemplate(entry
);
547 VehicleEntry
const *ve
= sVehicleStore
.LookupEntry(id
);
552 Vehicle
*v
= new Vehicle
;
553 Map
*map
= m_session
->GetPlayer()->GetMap();
554 if(!v
->Create(objmgr
.GenerateLowGuid(HIGHGUID_VEHICLE
), map
, entry
, id
, m_session
->GetPlayer()->GetTeam()))
561 m_session
->GetPlayer()->GetClosePoint(px
, py
, pz
, m_session
->GetPlayer()->GetObjectSize());
563 v
->Relocate(px
, py
, pz
, m_session
->GetPlayer()->GetOrientation());
565 if(!v
->IsPositionValid())
567 sLog
.outError("ERROR: Vehicle (guidlow %d, entry %d) not created. Suggested coordinates isn't valid (X: %f Y: %f)",
568 v
->GetGUIDLow(), v
->GetEntry(), v
->GetPositionX(), v
->GetPositionY());
573 map
->Add((Creature
*)v
);
578 bool ChatHandler::HandleDebugSendLargePacketCommand(const char* /*args*/)
580 const char* stuffingString
= "This is a dummy string to push the packet's size beyond 128000 bytes. ";
581 std::ostringstream ss
;
582 while(ss
.str().size() < 128000)
583 ss
<< stuffingString
;
584 SendSysMessage(ss
.str().c_str());
588 bool ChatHandler::HandleDebugSendSetPhaseShiftCommand(const char* args
)
593 uint32 PhaseShift
= atoi(args
);
594 m_session
->SendSetPhaseShift(PhaseShift
);