[7616] Implement .debug play cinematic and .debig play movie. Rename .debug playsound...
[getmangos.git] / src / game / debugcmds.cpp
blobfa20d2439b7f68575341d795e66d4e75f1e229f3
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::HandleDebugSendSpellFailCommand(const char* args)
36 if(!args)
37 return false;
39 char* px = strtok((char*)args, " ");
40 if(!px)
41 return false;
43 uint8 failnum = (uint8)atoi(px);
44 if(failnum==0 && *px!='0')
45 return false;
47 char* p1 = strtok(NULL, " ");
48 uint8 failarg1 = p1 ? (uint8)atoi(p1) : 0;
50 char* p2 = strtok(NULL, " ");
51 uint8 failarg2 = p2 ? (uint8)atoi(p2) : 0;
54 WorldPacket data(SMSG_CAST_FAILED, 5);
55 data << uint8(0);
56 data << uint32(133);
57 data << uint8(failnum);
58 if(p1 || p2)
59 data << uint32(failarg1);
60 if(p2)
61 data << uint32(failarg2);
63 m_session->SendPacket(&data);
65 return true;
68 bool ChatHandler::HandleDebugSendPoiCommand(const char* args)
70 Player *pPlayer = m_session->GetPlayer();
71 Unit* target = getSelectedUnit();
72 if(!target)
74 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
75 return true;
78 if(!args)
79 return false;
81 char* icon_text = strtok((char*)args, " ");
82 char* flags_text = strtok(NULL, " ");
83 if(!icon_text || !flags_text)
84 return false;
86 uint32 icon = atol(icon_text);
87 uint32 flags = atol(flags_text);
89 sLog.outDetail("Command : POI, NPC = %u, icon = %u flags = %u", target->GetGUIDLow(), icon,flags);
90 pPlayer->PlayerTalkClass->SendPointOfInterest(target->GetPositionX(), target->GetPositionY(), Poi_Icon(icon), flags, 30, "Test POI");
91 return true;
94 bool ChatHandler::HandleDebugSendEquipErrorCommand(const char* args)
96 if(!args)
97 return false;
99 uint8 msg = atoi(args);
100 m_session->GetPlayer()->SendEquipError(msg, 0, 0);
101 return true;
104 bool ChatHandler::HandleDebugSendSellErrorCommand(const char* args)
106 if(!args)
107 return false;
109 uint8 msg = atoi(args);
110 m_session->GetPlayer()->SendSellError(msg, 0, 0, 0);
111 return true;
114 bool ChatHandler::HandleDebugSendBuyErrorCommand(const char* args)
116 if(!args)
117 return false;
119 uint8 msg = atoi(args);
120 m_session->GetPlayer()->SendBuyError(msg, 0, 0, 0);
121 return true;
124 bool ChatHandler::HandleDebugSendOpcodeCommand(const char* /*args*/)
126 Unit *unit = getSelectedUnit();
127 if (!unit || (unit->GetTypeId() != TYPEID_PLAYER))
128 unit = m_session->GetPlayer();
130 std::ifstream ifs("opcode.txt");
131 if(ifs.bad())
132 return false;
134 uint32 opcode;
135 ifs >> opcode;
137 WorldPacket data(opcode, 0);
139 while(!ifs.eof())
141 std::string type;
142 ifs >> type;
144 if(type == "")
145 break;
147 if(type == "uint8")
149 uint16 val1;
150 ifs >> val1;
151 data << uint8(val1);
153 else if(type == "uint16")
155 uint16 val2;
156 ifs >> val2;
157 data << val2;
159 else if(type == "uint32")
161 uint32 val3;
162 ifs >> val3;
163 data << val3;
165 else if(type == "uint64")
167 uint64 val4;
168 ifs >> val4;
169 data << val4;
171 else if(type == "float")
173 float val5;
174 ifs >> val5;
175 data << val5;
177 else if(type == "string")
179 std::string val6;
180 ifs >> val6;
181 data << val6;
183 else if(type == "pguid")
185 data.append(unit->GetPackGUID());
187 else
189 sLog.outDebug("Sending opcode: unknown type '%s'", type.c_str());
190 break;
193 ifs.close();
194 sLog.outDebug("Sending opcode %u", data.GetOpcode());
195 data.hexlike();
196 ((Player*)unit)->GetSession()->SendPacket(&data);
197 PSendSysMessage(LANG_COMMAND_OPCODESENT, data.GetOpcode(), unit->GetName());
198 return true;
201 bool ChatHandler::HandleDebugUpdateWorldStateCommand(const char* args)
203 char* w = strtok((char*)args, " ");
204 char* s = strtok(NULL, " ");
206 if (!w || !s)
207 return false;
209 uint32 world = (uint32)atoi(w);
210 uint32 state = (uint32)atoi(s);
211 m_session->GetPlayer()->SendUpdateWorldState(world, state);
212 return true;
215 bool ChatHandler::HandleDebugPlayCinematicCommand(const char* args)
217 // USAGE: .debug play cinematic #cinematicid
218 // #cinematicid - ID decimal number from CinemaicSequences.dbc (1st column)
219 if( !*args )
221 SendSysMessage(LANG_BAD_VALUE);
222 SetSentErrorMessage(true);
223 return false;
226 uint32 dwId = atoi((char*)args);
228 if(!sCinematicSequencesStore.LookupEntry(dwId))
230 PSendSysMessage(LANG_CINEMATIC_NOT_EXIST, dwId);
231 SetSentErrorMessage(true);
232 return false;
235 m_session->GetPlayer()->SendCinematicStart(dwId);
236 return true;
239 bool ChatHandler::HandleDebugPlayMovieCommand(const char* args)
241 // USAGE: .debug play movie #movieid
242 // #movieid - ID decimal number from Movie.dbc (1st column)
243 if( !*args )
245 SendSysMessage(LANG_BAD_VALUE);
246 SetSentErrorMessage(true);
247 return false;
250 uint32 dwId = atoi((char*)args);
252 if(!sMovieStore.LookupEntry(dwId))
254 PSendSysMessage(LANG_MOVIE_NOT_EXIST, dwId);
255 SetSentErrorMessage(true);
256 return false;
259 m_session->GetPlayer()->SendMovieStart(dwId);
260 return true;
263 //Play sound
264 bool ChatHandler::HandleDebugPlaySoundCommand(const char* args)
266 // USAGE: .debug playsound #soundid
267 // #soundid - ID decimal number from SoundEntries.dbc (1st column)
268 if( !*args )
270 SendSysMessage(LANG_BAD_VALUE);
271 SetSentErrorMessage(true);
272 return false;
275 uint32 dwSoundId = atoi((char*)args);
277 if(!sSoundEntriesStore.LookupEntry(dwSoundId))
279 PSendSysMessage(LANG_SOUND_NOT_EXIST, dwSoundId);
280 SetSentErrorMessage(true);
281 return false;
284 Unit* unit = getSelectedUnit();
285 if(!unit)
287 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
288 SetSentErrorMessage(true);
289 return false;
292 if(m_session->GetPlayer()->GetSelection())
293 unit->PlayDistanceSound(dwSoundId,m_session->GetPlayer());
294 else
295 unit->PlayDirectSound(dwSoundId,m_session->GetPlayer());
297 PSendSysMessage(LANG_YOU_HEAR_SOUND, dwSoundId);
298 return true;
301 //Send notification in channel
302 bool ChatHandler::HandleDebugSendChannelNotifyCommand(const char* args)
304 if(!args)
305 return false;
307 const char *name = "test";
308 uint8 code = atoi(args);
310 WorldPacket data(SMSG_CHANNEL_NOTIFY, (1+10));
311 data << code; // notify type
312 data << name; // channel name
313 data << uint32(0);
314 data << uint32(0);
315 m_session->SendPacket(&data);
316 return true;
319 //Send notification in chat
320 bool ChatHandler::HandleDebugSendChatMsgCommand(const char* args)
322 if(!args)
323 return false;
325 const char *msg = "testtest";
326 uint8 type = atoi(args);
327 WorldPacket data;
328 ChatHandler::FillMessageData(&data, m_session, type, 0, "chan", m_session->GetPlayer()->GetGUID(), msg, m_session->GetPlayer());
329 m_session->SendPacket(&data);
330 return true;
333 bool ChatHandler::HandleDebugSendQuestPartyMsgCommand(const char* args)
335 uint32 msg = atol((char*)args);
336 m_session->GetPlayer()->SendPushToPartyResponse(m_session->GetPlayer(), msg);
337 return true;
340 bool ChatHandler::HandleDebugGetLootRecipient(const char* /*args*/)
342 Creature* target = getSelectedCreature();
343 if(!target)
344 return false;
346 PSendSysMessage("loot recipient: %s", target->hasLootRecipient()?(target->GetLootRecipient()?target->GetLootRecipient()->GetName():"offline"):"no loot recipient");
347 return true;
350 bool ChatHandler::HandleDebugSendQuestInvalidMsgCommand(const char* args)
352 uint32 msg = atol((char*)args);
353 m_session->GetPlayer()->SendCanTakeQuestResponse(msg);
354 return true;
357 bool ChatHandler::HandleDebugGetItemState(const char* args)
359 if (!args)
360 return false;
362 std::string state_str = args;
364 ItemUpdateState state = ITEM_UNCHANGED;
365 bool list_queue = false, check_all = false;
366 if (state_str == "unchanged") state = ITEM_UNCHANGED;
367 else if (state_str == "changed") state = ITEM_CHANGED;
368 else if (state_str == "new") state = ITEM_NEW;
369 else if (state_str == "removed") state = ITEM_REMOVED;
370 else if (state_str == "queue") list_queue = true;
371 else if (state_str == "check_all") check_all = true;
372 else return false;
374 Player* player = getSelectedPlayer();
375 if (!player) player = m_session->GetPlayer();
377 if (!list_queue && !check_all)
379 state_str = "The player has the following " + state_str + " items: ";
380 SendSysMessage(state_str.c_str());
381 for (uint8 i = PLAYER_SLOT_START; i < PLAYER_SLOT_END; i++)
383 if(i >= BUYBACK_SLOT_START && i < BUYBACK_SLOT_END)
384 continue;
386 Item *item = player->GetItemByPos(INVENTORY_SLOT_BAG_0, i);
387 if (!item) continue;
388 if (!item->IsBag())
390 if (item->GetState() == state)
391 PSendSysMessage("bag: 255 slot: %d guid: %d owner: %d", item->GetSlot(), item->GetGUIDLow(), GUID_LOPART(item->GetOwnerGUID()));
393 else
395 Bag *bag = (Bag*)item;
396 for (uint8 j = 0; j < bag->GetBagSize(); ++j)
398 Item* item = bag->GetItemByPos(j);
399 if (item && item->GetState() == state)
400 PSendSysMessage("bag: 255 slot: %d guid: %d owner: %d", item->GetSlot(), item->GetGUIDLow(), GUID_LOPART(item->GetOwnerGUID()));
406 if (list_queue)
408 std::vector<Item *> &updateQueue = player->GetItemUpdateQueue();
409 for(size_t i = 0; i < updateQueue.size(); i++)
411 Item *item = updateQueue[i];
412 if(!item) continue;
414 Bag *container = item->GetContainer();
415 uint8 bag_slot = container ? container->GetSlot() : uint8(INVENTORY_SLOT_BAG_0);
417 std::string st;
418 switch(item->GetState())
420 case ITEM_UNCHANGED: st = "unchanged"; break;
421 case ITEM_CHANGED: st = "changed"; break;
422 case ITEM_NEW: st = "new"; break;
423 case ITEM_REMOVED: st = "removed"; break;
426 PSendSysMessage("bag: %d slot: %d guid: %d - state: %s", bag_slot, item->GetSlot(), item->GetGUIDLow(), st.c_str());
428 if (updateQueue.empty())
429 PSendSysMessage("updatequeue empty");
432 if (check_all)
434 bool error = false;
435 std::vector<Item *> &updateQueue = player->GetItemUpdateQueue();
436 for (uint8 i = PLAYER_SLOT_START; i < PLAYER_SLOT_END; i++)
438 if(i >= BUYBACK_SLOT_START && i < BUYBACK_SLOT_END)
439 continue;
441 Item *item = player->GetItemByPos(INVENTORY_SLOT_BAG_0, i);
442 if (!item) continue;
444 if (item->GetSlot() != i)
446 PSendSysMessage("item at slot %d, guid %d has an incorrect slot value: %d", i, item->GetGUIDLow(), item->GetSlot());
447 error = true; continue;
450 if (item->GetOwnerGUID() != player->GetGUID())
452 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());
453 error = true; continue;
456 if (Bag *container = item->GetContainer())
458 PSendSysMessage("item at slot: %d guid: %d has a container (slot: %d, guid: %d) but shouldnt!", item->GetSlot(), item->GetGUIDLow(), container->GetSlot(), container->GetGUIDLow());
459 error = true; continue;
462 if (item->IsInUpdateQueue())
464 uint16 qp = item->GetQueuePos();
465 if (qp > updateQueue.size())
467 PSendSysMessage("item at slot: %d guid: %d has a queuepos (%d) larger than the update queue size! ", item->GetSlot(), item->GetGUIDLow(), qp);
468 error = true; continue;
471 if (updateQueue[qp] == NULL)
473 PSendSysMessage("item at slot: %d guid: %d has a queuepos (%d) that points to NULL in the queue!", item->GetSlot(), item->GetGUIDLow(), qp);
474 error = true; continue;
477 if (updateQueue[qp] != item)
479 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());
480 error = true; continue;
483 else if (item->GetState() != ITEM_UNCHANGED)
485 PSendSysMessage("item at slot: %d guid: %d is not in queue but should be (state: %d)!", item->GetSlot(), item->GetGUIDLow(), item->GetState());
486 error = true; continue;
489 if(item->IsBag())
491 Bag *bag = (Bag*)item;
492 for (uint8 j = 0; j < bag->GetBagSize(); ++j)
494 Item* item = bag->GetItemByPos(j);
495 if (!item) continue;
497 if (item->GetSlot() != j)
499 PSendSysMessage("the item in bag %d slot %d, guid %d has an incorrect slot value: %d", bag->GetSlot(), j, item->GetGUIDLow(), item->GetSlot());
500 error = true; continue;
503 if (item->GetOwnerGUID() != player->GetGUID())
505 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());
506 error = true; continue;
509 Bag *container = item->GetContainer();
510 if (!container)
512 PSendSysMessage("the item in bag %d at slot %d with guid %d has no container!", bag->GetSlot(), item->GetSlot(), item->GetGUIDLow());
513 error = true; continue;
516 if (container != bag)
518 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());
519 error = true; continue;
522 if (item->IsInUpdateQueue())
524 uint16 qp = item->GetQueuePos();
525 if (qp > updateQueue.size())
527 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);
528 error = true; continue;
531 if (updateQueue[qp] == NULL)
533 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);
534 error = true; continue;
537 if (updateQueue[qp] != item)
539 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());
540 error = true; continue;
543 else if (item->GetState() != ITEM_UNCHANGED)
545 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());
546 error = true; continue;
552 for(size_t i = 0; i < updateQueue.size(); i++)
554 Item *item = updateQueue[i];
555 if(!item) continue;
557 if (item->GetOwnerGUID() != player->GetGUID())
559 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());
560 error = true; continue;
563 if (item->GetQueuePos() != i)
565 PSendSysMessage("queue(%d): for the an item (guid %d), the queuepos doesn't match it's position in the queue!", i, item->GetGUIDLow());
566 error = true; continue;
569 if (item->GetState() == ITEM_REMOVED) continue;
570 Item *test = player->GetItemByPos( item->GetBagSlot(), item->GetSlot());
572 if (test == NULL)
574 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());
575 error = true; continue;
578 if (test != item)
580 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());
581 error = true; continue;
584 if (!error)
585 SendSysMessage("All OK!");
588 return true;
591 bool ChatHandler::HandleDebugBattlegroundCommand(const char * /*args*/)
593 sBattleGroundMgr.ToggleTesting();
594 return true;
597 bool ChatHandler::HandleDebugArenaCommand(const char * /*args*/)
599 sBattleGroundMgr.ToggleArenaTesting();
600 return true;
603 bool ChatHandler::HandleDebugSpawnVehicle(const char* args)
605 if(!args)
606 return false;
608 char* e = strtok((char*)args, " ");
609 char* i = strtok(NULL, " ");
611 if (!e || !i)
612 return false;
614 uint32 entry = (uint32)atoi(e);
615 uint32 id = (uint32)atoi(i);
617 CreatureInfo const *ci = objmgr.GetCreatureTemplate(entry);
619 if(!ci)
620 return false;
622 VehicleEntry const *ve = sVehicleStore.LookupEntry(id);
624 if(!ve)
625 return false;
627 Vehicle *v = new Vehicle;
628 Map *map = m_session->GetPlayer()->GetMap();
629 if(!v->Create(objmgr.GenerateLowGuid(HIGHGUID_VEHICLE), map, entry, id, m_session->GetPlayer()->GetTeam()))
631 delete v;
632 return false;
635 float px, py, pz;
636 m_session->GetPlayer()->GetClosePoint(px, py, pz, m_session->GetPlayer()->GetObjectSize());
638 v->Relocate(px, py, pz, m_session->GetPlayer()->GetOrientation());
640 if(!v->IsPositionValid())
642 sLog.outError("Vehicle (guidlow %d, entry %d) not created. Suggested coordinates isn't valid (X: %f Y: %f)",
643 v->GetGUIDLow(), v->GetEntry(), v->GetPositionX(), v->GetPositionY());
644 delete v;
645 return false;
648 map->Add((Creature*)v);
650 return true;
653 bool ChatHandler::HandleDebugSendLargePacketCommand(const char* /*args*/)
655 const char* stuffingString = "This is a dummy string to push the packet's size beyond 128000 bytes. ";
656 std::ostringstream ss;
657 while(ss.str().size() < 128000)
658 ss << stuffingString;
659 SendSysMessage(ss.str().c_str());
660 return true;
663 bool ChatHandler::HandleDebugSendSetPhaseShiftCommand(const char* args)
665 if(!args)
666 return false;
668 uint32 PhaseShift = atoi(args);
669 m_session->SendSetPhaseShift(PhaseShift);
670 return true;
673 bool ChatHandler::HandleDebugSetItemFlagCommand(const char* args)
675 if(!args)
676 return false;
678 char* e = strtok((char*)args, " ");
679 char* f = strtok(NULL, " ");
681 if (!e || !f)
682 return false;
684 uint32 guid = (uint32)atoi(e);
685 uint32 flag = (uint32)atoi(f);
687 Item *i = m_session->GetPlayer()->GetItemByGuid(MAKE_NEW_GUID(guid, 0, HIGHGUID_ITEM));
689 if(!i)
690 return false;
692 i->SetUInt32Value(ITEM_FIELD_FLAGS, flag);
694 return true;
697 //show animation
698 bool ChatHandler::HandleDebugAnimCommand(const char* args)
700 if (!*args)
701 return false;
703 uint32 anim_id = atoi((char*)args);
704 m_session->GetPlayer()->HandleEmoteCommand(anim_id);
705 return true;