2 * Copyright (C) 2005-2008 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"
22 #include "WorldSession.h"
29 #include "ObjectAccessor.h"
30 #include "GossipDef.h"
32 #include "MapManager.h"
33 #include "BattleGroundMgr.h"
35 #include "ObjectMgr.h"
37 bool ChatHandler::HandleDebugInArcCommand(const char* /*args*/)
39 Object
*obj
= getSelectedUnit();
43 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
47 SendSysMessage(LANG_NOT_IMPLEMENTED
);
52 bool ChatHandler::HandleDebugSpellFailCommand(const char* args
)
57 char* px
= strtok((char*)args
, " ");
61 uint8 failnum
= (uint8
)atoi(px
);
63 WorldPacket
data(SMSG_CAST_FAILED
, 5);
65 data
<< uint8(failnum
);
66 m_session
->SendPacket(&data
);
71 bool ChatHandler::HandleSetPoiCommand(const char* args
)
73 Player
*pPlayer
= m_session
->GetPlayer();
74 Unit
* target
= getSelectedUnit();
77 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
84 char* icon_text
= strtok((char*)args
, " ");
85 char* flags_text
= strtok(NULL
, " ");
86 if(!icon_text
|| !flags_text
)
89 uint32 icon
= atol(icon_text
);
93 uint32 flags
= atol(flags_text
);
95 sLog
.outDetail("Command : POI, NPC = %u, icon = %u flags = %u", target
->GetGUIDLow(), icon
,flags
);
96 pPlayer
->PlayerTalkClass
->SendPointOfInterest(target
->GetPositionX(), target
->GetPositionY(), Poi_Icon(icon
), flags
, 30, "Test POI");
100 bool ChatHandler::HandleEquipErrorCommand(const char* args
)
105 uint8 msg
= atoi(args
);
106 m_session
->GetPlayer()->SendEquipError(msg
, 0, 0);
110 bool ChatHandler::HandleSellErrorCommand(const char* args
)
115 uint8 msg
= atoi(args
);
116 m_session
->GetPlayer()->SendSellError(msg
, 0, 0, 0);
120 bool ChatHandler::HandleBuyErrorCommand(const char* args
)
125 uint8 msg
= atoi(args
);
126 m_session
->GetPlayer()->SendBuyError(msg
, 0, 0, 0);
130 bool ChatHandler::HandleSendOpcodeCommand(const char* /*args*/)
132 Unit
*unit
= getSelectedUnit();
133 if (!unit
|| (unit
->GetTypeId() != TYPEID_PLAYER
))
134 unit
= m_session
->GetPlayer();
136 std::ifstream
ifs("opcode.txt");
143 WorldPacket
data(opcode
, 0);
159 else if(type
== "uint16")
165 else if(type
== "uint32")
171 else if(type
== "uint64")
177 else if(type
== "float")
183 else if(type
== "string")
189 else if(type
== "pguid")
191 data
.append(unit
->GetPackGUID());
195 sLog
.outDebug("Sending opcode: unknown type '%s'", type
.c_str());
200 sLog
.outDebug("Sending opcode %u", data
.GetOpcode());
202 ((Player
*)unit
)->GetSession()->SendPacket(&data
);
203 PSendSysMessage(LANG_COMMAND_OPCODESENT
, data
.GetOpcode(), unit
->GetName());
207 bool ChatHandler::HandleUpdateWorldStateCommand(const char* args
)
209 char* w
= strtok((char*)args
, " ");
210 char* s
= strtok(NULL
, " ");
215 uint32 world
= (uint32
)atoi(w
);
216 uint32 state
= (uint32
)atoi(s
);
217 m_session
->GetPlayer()->SendUpdateWorldState(world
, state
);
221 bool ChatHandler::HandlePlaySound2Command(const char* args
)
226 uint32 soundid
= atoi(args
);
227 m_session
->GetPlayer()->PlaySound(soundid
, false);
231 //Send notification in channel
232 bool ChatHandler::HandleSendChannelNotifyCommand(const char* args
)
237 const char *name
= "test";
238 uint8 code
= atoi(args
);
240 WorldPacket
data(SMSG_CHANNEL_NOTIFY
, (1+10));
241 data
<< code
; // notify type
242 data
<< name
; // channel name
245 m_session
->SendPacket(&data
);
249 //Send notification in chat
250 bool ChatHandler::HandleSendChatMsgCommand(const char* args
)
255 const char *msg
= "testtest";
256 uint8 type
= atoi(args
);
258 ChatHandler::FillMessageData(&data
, m_session
, type
, 0, "chan", m_session
->GetPlayer()->GetGUID(), msg
, m_session
->GetPlayer());
259 m_session
->SendPacket(&data
);
263 bool ChatHandler::HandleSendQuestPartyMsgCommand(const char* args
)
265 uint32 msg
= atol((char*)args
);
267 m_session
->GetPlayer()->SendPushToPartyResponse(m_session
->GetPlayer(), msg
);
271 bool ChatHandler::HandleGetLootRecipient(const char* /*args*/)
273 Creature
* target
= getSelectedCreature();
277 PSendSysMessage("loot recipient: %s", target
->hasLootRecipient()?(target
->GetLootRecipient()?target
->GetLootRecipient()->GetName():"offline"):"no loot recipient");
281 bool ChatHandler::HandleSendQuestInvalidMsgCommand(const char* args
)
283 uint32 msg
= atol((char*)args
);
285 m_session
->GetPlayer()->SendCanTakeQuestResponse(msg
);
289 bool ChatHandler::HandleGetItemState(const char* args
)
294 std::string state_str
= args
;
296 ItemUpdateState state
= ITEM_UNCHANGED
;
297 bool list_queue
= false, check_all
= false;
298 if (state_str
== "unchanged") state
= ITEM_UNCHANGED
;
299 else if (state_str
== "changed") state
= ITEM_CHANGED
;
300 else if (state_str
== "new") state
= ITEM_NEW
;
301 else if (state_str
== "removed") state
= ITEM_REMOVED
;
302 else if (state_str
== "queue") list_queue
= true;
303 else if (state_str
== "check_all") check_all
= true;
306 Player
* player
= getSelectedPlayer();
307 if (!player
) player
= m_session
->GetPlayer();
309 if (!list_queue
&& !check_all
)
311 state_str
= "The player has the following " + state_str
+ " items: ";
312 SendSysMessage(state_str
.c_str());
313 for (uint8 i
= PLAYER_SLOT_START
; i
< PLAYER_SLOT_END
; i
++)
315 if(i
>= BUYBACK_SLOT_START
&& i
< BUYBACK_SLOT_END
)
318 Item
*item
= player
->GetItemByPos(INVENTORY_SLOT_BAG_0
, i
);
322 if (item
->GetState() == state
)
323 PSendSysMessage("bag: 255 slot: %d guid: %d owner: %d", item
->GetSlot(), item
->GetGUIDLow(), GUID_LOPART(item
->GetOwnerGUID()));
327 Bag
*bag
= (Bag
*)item
;
328 for (uint8 j
= 0; j
< bag
->GetBagSize(); ++j
)
330 Item
* item
= bag
->GetItemByPos(j
);
331 if (item
&& item
->GetState() == state
)
332 PSendSysMessage("bag: 255 slot: %d guid: %d owner: %d", item
->GetSlot(), item
->GetGUIDLow(), GUID_LOPART(item
->GetOwnerGUID()));
340 std::vector
<Item
*> &updateQueue
= player
->GetItemUpdateQueue();
341 for(size_t i
= 0; i
< updateQueue
.size(); i
++)
343 Item
*item
= updateQueue
[i
];
346 Bag
*container
= item
->GetContainer();
347 uint8 bag_slot
= container
? container
->GetSlot() : uint8(INVENTORY_SLOT_BAG_0
);
350 switch(item
->GetState())
352 case ITEM_UNCHANGED
: st
= "unchanged"; break;
353 case ITEM_CHANGED
: st
= "changed"; break;
354 case ITEM_NEW
: st
= "new"; break;
355 case ITEM_REMOVED
: st
= "removed"; break;
358 PSendSysMessage("bag: %d slot: %d guid: %d - state: %s", bag_slot
, item
->GetSlot(), item
->GetGUIDLow(), st
.c_str());
360 if (updateQueue
.empty())
361 PSendSysMessage("updatequeue empty");
367 std::vector
<Item
*> &updateQueue
= player
->GetItemUpdateQueue();
368 for (uint8 i
= PLAYER_SLOT_START
; i
< PLAYER_SLOT_END
; i
++)
370 if(i
>= BUYBACK_SLOT_START
&& i
< BUYBACK_SLOT_END
)
373 Item
*item
= player
->GetItemByPos(INVENTORY_SLOT_BAG_0
, i
);
376 if (item
->GetSlot() != i
)
378 PSendSysMessage("item at slot %d, guid %d has an incorrect slot value: %d", i
, item
->GetGUIDLow(), item
->GetSlot());
379 error
= true; continue;
382 if (item
->GetOwnerGUID() != player
->GetGUID())
384 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());
385 error
= true; continue;
388 if (Bag
*container
= item
->GetContainer())
390 PSendSysMessage("item at slot: %d guid: %d has a container (slot: %d, guid: %d) but shouldnt!", item
->GetSlot(), item
->GetGUIDLow(), container
->GetSlot(), container
->GetGUIDLow());
391 error
= true; continue;
394 if (item
->IsInUpdateQueue())
396 uint16 qp
= item
->GetQueuePos();
397 if (qp
> updateQueue
.size())
399 PSendSysMessage("item at slot: %d guid: %d has a queuepos (%d) larger than the update queue size! ", item
->GetSlot(), item
->GetGUIDLow(), qp
);
400 error
= true; continue;
403 if (updateQueue
[qp
] == NULL
)
405 PSendSysMessage("item at slot: %d guid: %d has a queuepos (%d) that points to NULL in the queue!", item
->GetSlot(), item
->GetGUIDLow(), qp
);
406 error
= true; continue;
409 if (updateQueue
[qp
] != item
)
411 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());
412 error
= true; continue;
415 else if (item
->GetState() != ITEM_UNCHANGED
)
417 PSendSysMessage("item at slot: %d guid: %d is not in queue but should be (state: %d)!", item
->GetSlot(), item
->GetGUIDLow(), item
->GetState());
418 error
= true; continue;
423 Bag
*bag
= (Bag
*)item
;
424 for (uint8 j
= 0; j
< bag
->GetBagSize(); ++j
)
426 Item
* item
= bag
->GetItemByPos(j
);
429 if (item
->GetSlot() != j
)
431 PSendSysMessage("the item in bag %d slot %d, guid %d has an incorrect slot value: %d", bag
->GetSlot(), j
, item
->GetGUIDLow(), item
->GetSlot());
432 error
= true; continue;
435 if (item
->GetOwnerGUID() != player
->GetGUID())
437 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());
438 error
= true; continue;
441 Bag
*container
= item
->GetContainer();
444 PSendSysMessage("the item in bag %d at slot %d with guid %d has no container!", bag
->GetSlot(), item
->GetSlot(), item
->GetGUIDLow());
445 error
= true; continue;
448 if (container
!= bag
)
450 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());
451 error
= true; continue;
454 if (item
->IsInUpdateQueue())
456 uint16 qp
= item
->GetQueuePos();
457 if (qp
> updateQueue
.size())
459 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
);
460 error
= true; continue;
463 if (updateQueue
[qp
] == NULL
)
465 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
);
466 error
= true; continue;
469 if (updateQueue
[qp
] != item
)
471 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());
472 error
= true; continue;
475 else if (item
->GetState() != ITEM_UNCHANGED
)
477 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());
478 error
= true; continue;
484 for(size_t i
= 0; i
< updateQueue
.size(); i
++)
486 Item
*item
= updateQueue
[i
];
489 if (item
->GetOwnerGUID() != player
->GetGUID())
491 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());
492 error
= true; continue;
495 if (item
->GetQueuePos() != i
)
497 PSendSysMessage("queue(%d): for the an item (guid %d), the queuepos doesn't match it's position in the queue!", i
, item
->GetGUIDLow());
498 error
= true; continue;
501 if (item
->GetState() == ITEM_REMOVED
) continue;
502 Item
*test
= player
->GetItemByPos( item
->GetBagSlot(), item
->GetSlot());
506 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());
507 error
= true; continue;
512 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());
513 error
= true; continue;
517 SendSysMessage("All OK!");
523 bool ChatHandler::HandleDebugArenaCommand(const char * /*args*/)
525 sBattleGroundMgr
.ToggleArenaTesting();