[7518] Implement new script command SCRIPT_COMMAND_PLAY_SOUND (look in World.h for...
[AHbot.git] / src / game / debugcmds.cpp
blobdbc8f4b2c529f661d5b11ba0c75cccfea510c22c
1 /*
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
19 #include "Common.h"
20 #include "Database/DatabaseEnv.h"
21 #include "WorldPacket.h"
22 #include "Vehicle.h"
23 #include "Player.h"
24 #include "Opcodes.h"
25 #include "Chat.h"
26 #include "Log.h"
27 #include "Unit.h"
28 #include "GossipDef.h"
29 #include "Language.h"
30 #include "BattleGroundMgr.h"
31 #include <fstream>
32 #include "ObjectMgr.h"
34 bool ChatHandler::HandleDebugInArcCommand(const char* /*args*/)
36 Object *obj = getSelectedUnit();
38 if(!obj)
40 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
41 return true;
44 SendSysMessage(LANG_NOT_IMPLEMENTED);
46 return true;
49 bool ChatHandler::HandleDebugSpellFailCommand(const char* args)
51 if(!args)
52 return false;
54 char* px = strtok((char*)args, " ");
55 if(!px)
56 return false;
58 uint8 failnum = (uint8)atoi(px);
60 WorldPacket data(SMSG_CAST_FAILED, 5);
61 data << uint8(0);
62 data << uint32(133);
63 data << uint8(failnum);
64 m_session->SendPacket(&data);
66 return true;
69 bool ChatHandler::HandleDebugSetPoiCommand(const char* args)
71 Player *pPlayer = m_session->GetPlayer();
72 Unit* target = getSelectedUnit();
73 if(!target)
75 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
76 return true;
79 if(!args)
80 return false;
82 char* icon_text = strtok((char*)args, " ");
83 char* flags_text = strtok(NULL, " ");
84 if(!icon_text || !flags_text)
85 return false;
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");
92 return true;
95 bool ChatHandler::HandleDebugEquipErrorCommand(const char* args)
97 if(!args)
98 return false;
100 uint8 msg = atoi(args);
101 m_session->GetPlayer()->SendEquipError(msg, 0, 0);
102 return true;
105 bool ChatHandler::HandleDebugSellErrorCommand(const char* args)
107 if(!args)
108 return false;
110 uint8 msg = atoi(args);
111 m_session->GetPlayer()->SendSellError(msg, 0, 0, 0);
112 return true;
115 bool ChatHandler::HandleDebugBuyErrorCommand(const char* args)
117 if(!args)
118 return false;
120 uint8 msg = atoi(args);
121 m_session->GetPlayer()->SendBuyError(msg, 0, 0, 0);
122 return true;
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");
132 if(ifs.bad())
133 return false;
135 uint32 opcode;
136 ifs >> opcode;
138 WorldPacket data(opcode, 0);
140 while(!ifs.eof())
142 std::string type;
143 ifs >> type;
145 if(type == "")
146 break;
148 if(type == "uint8")
150 uint16 val1;
151 ifs >> val1;
152 data << uint8(val1);
154 else if(type == "uint16")
156 uint16 val2;
157 ifs >> val2;
158 data << val2;
160 else if(type == "uint32")
162 uint32 val3;
163 ifs >> val3;
164 data << val3;
166 else if(type == "uint64")
168 uint64 val4;
169 ifs >> val4;
170 data << val4;
172 else if(type == "float")
174 float val5;
175 ifs >> val5;
176 data << val5;
178 else if(type == "string")
180 std::string val6;
181 ifs >> val6;
182 data << val6;
184 else if(type == "pguid")
186 data.append(unit->GetPackGUID());
188 else
190 sLog.outDebug("Sending opcode: unknown type '%s'", type.c_str());
191 break;
194 ifs.close();
195 sLog.outDebug("Sending opcode %u", data.GetOpcode());
196 data.hexlike();
197 ((Player*)unit)->GetSession()->SendPacket(&data);
198 PSendSysMessage(LANG_COMMAND_OPCODESENT, data.GetOpcode(), unit->GetName());
199 return true;
202 bool ChatHandler::HandleDebugUpdateWorldStateCommand(const char* args)
204 char* w = strtok((char*)args, " ");
205 char* s = strtok(NULL, " ");
207 if (!w || !s)
208 return false;
210 uint32 world = (uint32)atoi(w);
211 uint32 state = (uint32)atoi(s);
212 m_session->GetPlayer()->SendUpdateWorldState(world, state);
213 return true;
216 //Play sound
217 bool ChatHandler::HandleDebugPlaySoundCommand(const char* args)
219 // USAGE: .debug playsound #soundid
220 // #soundid - ID decimal number from SoundEntries.dbc (1st column)
221 if( !*args )
223 SendSysMessage(LANG_BAD_VALUE);
224 SetSentErrorMessage(true);
225 return false;
228 uint32 dwSoundId = atoi((char*)args);
230 if(!sSoundEntriesStore.LookupEntry(dwSoundId))
232 PSendSysMessage(LANG_SOUND_NOT_EXIST, dwSoundId);
233 SetSentErrorMessage(true);
234 return false;
237 Unit* unit = getSelectedUnit();
238 if(!unit)
240 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
241 SetSentErrorMessage(true);
242 return false;
245 if(m_session->GetPlayer()->GetSelection())
246 unit->PlayDistanceSound(dwSoundId,m_session->GetPlayer());
247 else
248 unit->PlayDirectSound(dwSoundId,m_session->GetPlayer());
250 PSendSysMessage(LANG_YOU_HEAR_SOUND, dwSoundId);
251 return true;
254 //Send notification in channel
255 bool ChatHandler::HandleDebugSendChannelNotifyCommand(const char* args)
257 if(!args)
258 return false;
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
266 data << uint32(0);
267 data << uint32(0);
268 m_session->SendPacket(&data);
269 return true;
272 //Send notification in chat
273 bool ChatHandler::HandleDebugSendChatMsgCommand(const char* args)
275 if(!args)
276 return false;
278 const char *msg = "testtest";
279 uint8 type = atoi(args);
280 WorldPacket data;
281 ChatHandler::FillMessageData(&data, m_session, type, 0, "chan", m_session->GetPlayer()->GetGUID(), msg, m_session->GetPlayer());
282 m_session->SendPacket(&data);
283 return true;
286 bool ChatHandler::HandleDebugSendQuestPartyMsgCommand(const char* args)
288 uint32 msg = atol((char*)args);
289 m_session->GetPlayer()->SendPushToPartyResponse(m_session->GetPlayer(), msg);
290 return true;
293 bool ChatHandler::HandleDebugGetLootRecipient(const char* /*args*/)
295 Creature* target = getSelectedCreature();
296 if(!target)
297 return false;
299 PSendSysMessage("loot recipient: %s", target->hasLootRecipient()?(target->GetLootRecipient()?target->GetLootRecipient()->GetName():"offline"):"no loot recipient");
300 return true;
303 bool ChatHandler::HandleDebugSendQuestInvalidMsgCommand(const char* args)
305 uint32 msg = atol((char*)args);
306 m_session->GetPlayer()->SendCanTakeQuestResponse(msg);
307 return true;
310 bool ChatHandler::HandleDebugGetItemState(const char* args)
312 if (!args)
313 return false;
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;
325 else return false;
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)
337 continue;
339 Item *item = player->GetItemByPos(INVENTORY_SLOT_BAG_0, i);
340 if (!item) continue;
341 if (!item->IsBag())
343 if (item->GetState() == state)
344 PSendSysMessage("bag: 255 slot: %d guid: %d owner: %d", item->GetSlot(), item->GetGUIDLow(), GUID_LOPART(item->GetOwnerGUID()));
346 else
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()));
359 if (list_queue)
361 std::vector<Item *> &updateQueue = player->GetItemUpdateQueue();
362 for(size_t i = 0; i < updateQueue.size(); i++)
364 Item *item = updateQueue[i];
365 if(!item) continue;
367 Bag *container = item->GetContainer();
368 uint8 bag_slot = container ? container->GetSlot() : uint8(INVENTORY_SLOT_BAG_0);
370 std::string st;
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");
385 if (check_all)
387 bool error = false;
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)
392 continue;
394 Item *item = player->GetItemByPos(INVENTORY_SLOT_BAG_0, i);
395 if (!item) continue;
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;
442 if(item->IsBag())
444 Bag *bag = (Bag*)item;
445 for (uint8 j = 0; j < bag->GetBagSize(); ++j)
447 Item* item = bag->GetItemByPos(j);
448 if (!item) continue;
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();
463 if (!container)
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];
508 if(!item) continue;
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());
525 if (test == NULL)
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;
531 if (test != item)
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;
537 if (!error)
538 SendSysMessage("All OK!");
541 return true;
544 bool ChatHandler::HandleDebugBattlegroundCommand(const char * /*args*/)
546 sBattleGroundMgr.ToggleTesting();
547 return true;
550 bool ChatHandler::HandleDebugArenaCommand(const char * /*args*/)
552 sBattleGroundMgr.ToggleArenaTesting();
553 return true;
556 bool ChatHandler::HandleDebugSpawnVehicle(const char* args)
558 if(!args)
559 return false;
561 char* e = strtok((char*)args, " ");
562 char* i = strtok(NULL, " ");
564 if (!e || !i)
565 return false;
567 uint32 entry = (uint32)atoi(e);
568 uint32 id = (uint32)atoi(i);
570 CreatureInfo const *ci = objmgr.GetCreatureTemplate(entry);
572 if(!ci)
573 return false;
575 VehicleEntry const *ve = sVehicleStore.LookupEntry(id);
577 if(!ve)
578 return false;
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()))
584 delete v;
585 return false;
588 float px, py, pz;
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());
597 delete v;
598 return false;
601 map->Add((Creature*)v);
603 return true;
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());
613 return true;
616 bool ChatHandler::HandleDebugSendSetPhaseShiftCommand(const char* args)
618 if(!args)
619 return false;
621 uint32 PhaseShift = atoi(args);
622 m_session->SendSetPhaseShift(PhaseShift);
623 return true;
626 bool ChatHandler::HandleDebugSetItemFlagCommand(const char* args)
628 if(!args)
629 return false;
631 char* e = strtok((char*)args, " ");
632 char* f = strtok(NULL, " ");
634 if (!e || !f)
635 return false;
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));
642 if(!i)
643 return false;
645 i->SetUInt32Value(ITEM_FIELD_FLAGS, flag);
647 return true;