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"
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);
66 data
<< uint8(failnum
);
67 m_session
->SendPacket(&data
);
72 bool ChatHandler::HandleSetPoiCommand(const char* args
)
74 Player
*pPlayer
= m_session
->GetPlayer();
75 Unit
* target
= getSelectedUnit();
78 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
85 char* icon_text
= strtok((char*)args
, " ");
86 char* flags_text
= strtok(NULL
, " ");
87 if(!icon_text
|| !flags_text
)
90 uint32 icon
= atol(icon_text
);
94 uint32 flags
= atol(flags_text
);
96 sLog
.outDetail("Command : POI, NPC = %u, icon = %u flags = %u", target
->GetGUIDLow(), icon
,flags
);
97 pPlayer
->PlayerTalkClass
->SendPointOfInterest(target
->GetPositionX(), target
->GetPositionY(), Poi_Icon(icon
), flags
, 30, "Test POI");
101 bool ChatHandler::HandleEquipErrorCommand(const char* args
)
106 uint8 msg
= atoi(args
);
107 m_session
->GetPlayer()->SendEquipError(msg
, 0, 0);
111 bool ChatHandler::HandleSellErrorCommand(const char* args
)
116 uint8 msg
= atoi(args
);
117 m_session
->GetPlayer()->SendSellError(msg
, 0, 0, 0);
121 bool ChatHandler::HandleBuyErrorCommand(const char* args
)
126 uint8 msg
= atoi(args
);
127 m_session
->GetPlayer()->SendBuyError(msg
, 0, 0, 0);
131 bool ChatHandler::HandleSendOpcodeCommand(const char* /*args*/)
133 Unit
*unit
= getSelectedUnit();
134 if (!unit
|| (unit
->GetTypeId() != TYPEID_PLAYER
))
135 unit
= m_session
->GetPlayer();
137 std::ifstream
ifs("opcode.txt");
144 WorldPacket
data(opcode
, 0);
160 else if(type
== "uint16")
166 else if(type
== "uint32")
172 else if(type
== "uint64")
178 else if(type
== "float")
184 else if(type
== "string")
190 else if(type
== "pguid")
192 data
.append(unit
->GetPackGUID());
196 sLog
.outDebug("Sending opcode: unknown type '%s'", type
.c_str());
201 sLog
.outDebug("Sending opcode %u", data
.GetOpcode());
203 ((Player
*)unit
)->GetSession()->SendPacket(&data
);
204 PSendSysMessage(LANG_COMMAND_OPCODESENT
, data
.GetOpcode(), unit
->GetName());
208 bool ChatHandler::HandleUpdateWorldStateCommand(const char* args
)
210 char* w
= strtok((char*)args
, " ");
211 char* s
= strtok(NULL
, " ");
216 uint32 world
= (uint32
)atoi(w
);
217 uint32 state
= (uint32
)atoi(s
);
218 m_session
->GetPlayer()->SendUpdateWorldState(world
, state
);
222 bool ChatHandler::HandlePlaySound2Command(const char* args
)
227 uint32 soundid
= atoi(args
);
228 m_session
->GetPlayer()->PlaySound(soundid
, false);
232 //Send notification in channel
233 bool ChatHandler::HandleSendChannelNotifyCommand(const char* args
)
238 const char *name
= "test";
239 uint8 code
= atoi(args
);
241 WorldPacket
data(SMSG_CHANNEL_NOTIFY
, (1+10));
242 data
<< code
; // notify type
243 data
<< name
; // channel name
246 m_session
->SendPacket(&data
);
250 //Send notification in chat
251 bool ChatHandler::HandleSendChatMsgCommand(const char* args
)
256 const char *msg
= "testtest";
257 uint8 type
= atoi(args
);
259 ChatHandler::FillMessageData(&data
, m_session
, type
, 0, "chan", m_session
->GetPlayer()->GetGUID(), msg
, m_session
->GetPlayer());
260 m_session
->SendPacket(&data
);
264 bool ChatHandler::HandleSendQuestPartyMsgCommand(const char* args
)
266 uint32 msg
= atol((char*)args
);
268 m_session
->GetPlayer()->SendPushToPartyResponse(m_session
->GetPlayer(), msg
);
272 bool ChatHandler::HandleGetLootRecipient(const char* /*args*/)
274 Creature
* target
= getSelectedCreature();
278 PSendSysMessage("loot recipient: %s", target
->hasLootRecipient()?(target
->GetLootRecipient()?target
->GetLootRecipient()->GetName():"offline"):"no loot recipient");
282 bool ChatHandler::HandleSendQuestInvalidMsgCommand(const char* args
)
284 uint32 msg
= atol((char*)args
);
286 m_session
->GetPlayer()->SendCanTakeQuestResponse(msg
);
290 bool ChatHandler::HandleGetItemState(const char* args
)
295 std::string state_str
= args
;
297 ItemUpdateState state
= ITEM_UNCHANGED
;
298 bool list_queue
= false, check_all
= false;
299 if (state_str
== "unchanged") state
= ITEM_UNCHANGED
;
300 else if (state_str
== "changed") state
= ITEM_CHANGED
;
301 else if (state_str
== "new") state
= ITEM_NEW
;
302 else if (state_str
== "removed") state
= ITEM_REMOVED
;
303 else if (state_str
== "queue") list_queue
= true;
304 else if (state_str
== "check_all") check_all
= true;
307 Player
* player
= getSelectedPlayer();
308 if (!player
) player
= m_session
->GetPlayer();
310 if (!list_queue
&& !check_all
)
312 state_str
= "The player has the following " + state_str
+ " items: ";
313 SendSysMessage(state_str
.c_str());
314 for (uint8 i
= PLAYER_SLOT_START
; i
< PLAYER_SLOT_END
; i
++)
316 if(i
>= BUYBACK_SLOT_START
&& i
< BUYBACK_SLOT_END
)
319 Item
*item
= player
->GetItemByPos(INVENTORY_SLOT_BAG_0
, i
);
323 if (item
->GetState() == state
)
324 PSendSysMessage("bag: 255 slot: %d guid: %d owner: %d", item
->GetSlot(), item
->GetGUIDLow(), GUID_LOPART(item
->GetOwnerGUID()));
328 Bag
*bag
= (Bag
*)item
;
329 for (uint8 j
= 0; j
< bag
->GetBagSize(); ++j
)
331 Item
* item
= bag
->GetItemByPos(j
);
332 if (item
&& item
->GetState() == state
)
333 PSendSysMessage("bag: 255 slot: %d guid: %d owner: %d", item
->GetSlot(), item
->GetGUIDLow(), GUID_LOPART(item
->GetOwnerGUID()));
341 std::vector
<Item
*> &updateQueue
= player
->GetItemUpdateQueue();
342 for(size_t i
= 0; i
< updateQueue
.size(); i
++)
344 Item
*item
= updateQueue
[i
];
347 Bag
*container
= item
->GetContainer();
348 uint8 bag_slot
= container
? container
->GetSlot() : uint8(INVENTORY_SLOT_BAG_0
);
351 switch(item
->GetState())
353 case ITEM_UNCHANGED
: st
= "unchanged"; break;
354 case ITEM_CHANGED
: st
= "changed"; break;
355 case ITEM_NEW
: st
= "new"; break;
356 case ITEM_REMOVED
: st
= "removed"; break;
359 PSendSysMessage("bag: %d slot: %d guid: %d - state: %s", bag_slot
, item
->GetSlot(), item
->GetGUIDLow(), st
.c_str());
361 if (updateQueue
.empty())
362 PSendSysMessage("updatequeue empty");
368 std::vector
<Item
*> &updateQueue
= player
->GetItemUpdateQueue();
369 for (uint8 i
= PLAYER_SLOT_START
; i
< PLAYER_SLOT_END
; i
++)
371 if(i
>= BUYBACK_SLOT_START
&& i
< BUYBACK_SLOT_END
)
374 Item
*item
= player
->GetItemByPos(INVENTORY_SLOT_BAG_0
, i
);
377 if (item
->GetSlot() != i
)
379 PSendSysMessage("item at slot %d, guid %d has an incorrect slot value: %d", i
, item
->GetGUIDLow(), item
->GetSlot());
380 error
= true; continue;
383 if (item
->GetOwnerGUID() != player
->GetGUID())
385 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());
386 error
= true; continue;
389 if (Bag
*container
= item
->GetContainer())
391 PSendSysMessage("item at slot: %d guid: %d has a container (slot: %d, guid: %d) but shouldnt!", item
->GetSlot(), item
->GetGUIDLow(), container
->GetSlot(), container
->GetGUIDLow());
392 error
= true; continue;
395 if (item
->IsInUpdateQueue())
397 uint16 qp
= item
->GetQueuePos();
398 if (qp
> updateQueue
.size())
400 PSendSysMessage("item at slot: %d guid: %d has a queuepos (%d) larger than the update queue size! ", item
->GetSlot(), item
->GetGUIDLow(), qp
);
401 error
= true; continue;
404 if (updateQueue
[qp
] == NULL
)
406 PSendSysMessage("item at slot: %d guid: %d has a queuepos (%d) that points to NULL in the queue!", item
->GetSlot(), item
->GetGUIDLow(), qp
);
407 error
= true; continue;
410 if (updateQueue
[qp
] != item
)
412 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());
413 error
= true; continue;
416 else if (item
->GetState() != ITEM_UNCHANGED
)
418 PSendSysMessage("item at slot: %d guid: %d is not in queue but should be (state: %d)!", item
->GetSlot(), item
->GetGUIDLow(), item
->GetState());
419 error
= true; continue;
424 Bag
*bag
= (Bag
*)item
;
425 for (uint8 j
= 0; j
< bag
->GetBagSize(); ++j
)
427 Item
* item
= bag
->GetItemByPos(j
);
430 if (item
->GetSlot() != j
)
432 PSendSysMessage("the item in bag %d slot %d, guid %d has an incorrect slot value: %d", bag
->GetSlot(), j
, item
->GetGUIDLow(), item
->GetSlot());
433 error
= true; continue;
436 if (item
->GetOwnerGUID() != player
->GetGUID())
438 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());
439 error
= true; continue;
442 Bag
*container
= item
->GetContainer();
445 PSendSysMessage("the item in bag %d at slot %d with guid %d has no container!", bag
->GetSlot(), item
->GetSlot(), item
->GetGUIDLow());
446 error
= true; continue;
449 if (container
!= bag
)
451 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());
452 error
= true; continue;
455 if (item
->IsInUpdateQueue())
457 uint16 qp
= item
->GetQueuePos();
458 if (qp
> updateQueue
.size())
460 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
);
461 error
= true; continue;
464 if (updateQueue
[qp
] == NULL
)
466 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
);
467 error
= true; continue;
470 if (updateQueue
[qp
] != item
)
472 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());
473 error
= true; continue;
476 else if (item
->GetState() != ITEM_UNCHANGED
)
478 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());
479 error
= true; continue;
485 for(size_t i
= 0; i
< updateQueue
.size(); i
++)
487 Item
*item
= updateQueue
[i
];
490 if (item
->GetOwnerGUID() != player
->GetGUID())
492 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());
493 error
= true; continue;
496 if (item
->GetQueuePos() != i
)
498 PSendSysMessage("queue(%d): for the an item (guid %d), the queuepos doesn't match it's position in the queue!", i
, item
->GetGUIDLow());
499 error
= true; continue;
502 if (item
->GetState() == ITEM_REMOVED
) continue;
503 Item
*test
= player
->GetItemByPos( item
->GetBagSlot(), item
->GetSlot());
507 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());
508 error
= true; continue;
513 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());
514 error
= true; continue;
518 SendSysMessage("All OK!");
524 bool ChatHandler::HandleDebugArenaCommand(const char * /*args*/)
526 sBattleGroundMgr
.ToggleArenaTesting();
530 bool ChatHandler::HandleSpawnVehicle(const char* args
)
535 char* e
= strtok((char*)args
, " ");
536 char* i
= strtok(NULL
, " ");
541 uint32 entry
= (uint32
)atoi(e
);
542 uint32 id
= (uint32
)atoi(i
);
544 CreatureInfo
const *ci
= objmgr
.GetCreatureTemplate(entry
);
549 VehicleEntry
const *ve
= sVehicleStore
.LookupEntry(id
);
554 Vehicle
*v
= new Vehicle
;
555 Map
*map
= m_session
->GetPlayer()->GetMap();
556 if(!v
->Create(objmgr
.GenerateLowGuid(HIGHGUID_VEHICLE
), map
, entry
, id
, m_session
->GetPlayer()->GetTeam()))
563 m_session
->GetPlayer()->GetClosePoint(px
, py
, pz
, m_session
->GetPlayer()->GetObjectSize());
565 v
->Relocate(px
, py
, pz
, m_session
->GetPlayer()->GetOrientation());
567 if(!v
->IsPositionValid())
569 sLog
.outError("ERROR: Vehicle (guidlow %d, entry %d) not created. Suggested coordinates isn't valid (X: %f Y: %f)",
570 v
->GetGUIDLow(), v
->GetEntry(), v
->GetPositionX(), v
->GetPositionY());
575 map
->Add((Creature
*)v
);
580 bool ChatHandler::HandleSendLargePacketCommand(const char* args
)
582 const char* stuffingString
= "This is a dummy string to push the packet's size beyond 128000 bytes. ";
583 std::ostringstream ss
;
584 while(strlen(ss
.str().c_str()) < 128000)
585 ss
<< stuffingString
;
586 SendSysMessage(ss
.str().c_str());