[7297] Fixed profession spells sorting in trainer spell list at client.
[getmangos.git] / src / game / debugcmds.cpp
blob61f2d20ec2165dabeab31d454ee8d97838161764
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 "WorldSession.h"
23 #include "World.h"
24 #include "Player.h"
25 #include "Opcodes.h"
26 #include "Chat.h"
27 #include "Log.h"
28 #include "Unit.h"
29 #include "ObjectAccessor.h"
30 #include "GossipDef.h"
31 #include "Language.h"
32 #include "MapManager.h"
33 #include "BattleGroundMgr.h"
34 #include <fstream>
35 #include "ObjectMgr.h"
37 bool ChatHandler::HandleDebugInArcCommand(const char* /*args*/)
39 Object *obj = getSelectedUnit();
41 if(!obj)
43 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
44 return true;
47 SendSysMessage(LANG_NOT_IMPLEMENTED);
49 return true;
52 bool ChatHandler::HandleDebugSpellFailCommand(const char* args)
54 if(!args)
55 return false;
57 char* px = strtok((char*)args, " ");
58 if(!px)
59 return false;
61 uint8 failnum = (uint8)atoi(px);
63 WorldPacket data(SMSG_CAST_FAILED, 5);
64 data << uint8(0);
65 data << uint32(133);
66 data << uint8(failnum);
67 m_session->SendPacket(&data);
69 return true;
72 bool ChatHandler::HandleSetPoiCommand(const char* args)
74 Player *pPlayer = m_session->GetPlayer();
75 Unit* target = getSelectedUnit();
76 if(!target)
78 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
79 return true;
82 if(!args)
83 return false;
85 char* icon_text = strtok((char*)args, " ");
86 char* flags_text = strtok(NULL, " ");
87 if(!icon_text || !flags_text)
88 return false;
90 uint32 icon = atol(icon_text);
91 if ( icon < 0 )
92 icon = 0;
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");
98 return true;
101 bool ChatHandler::HandleEquipErrorCommand(const char* args)
103 if(!args)
104 return false;
106 uint8 msg = atoi(args);
107 m_session->GetPlayer()->SendEquipError(msg, 0, 0);
108 return true;
111 bool ChatHandler::HandleSellErrorCommand(const char* args)
113 if(!args)
114 return false;
116 uint8 msg = atoi(args);
117 m_session->GetPlayer()->SendSellError(msg, 0, 0, 0);
118 return true;
121 bool ChatHandler::HandleBuyErrorCommand(const char* args)
123 if(!args)
124 return false;
126 uint8 msg = atoi(args);
127 m_session->GetPlayer()->SendBuyError(msg, 0, 0, 0);
128 return true;
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");
138 if(ifs.bad())
139 return false;
141 uint32 opcode;
142 ifs >> opcode;
144 WorldPacket data(opcode, 0);
146 while(!ifs.eof())
148 std::string type;
149 ifs >> type;
151 if(type == "")
152 break;
154 if(type == "uint8")
156 uint16 val1;
157 ifs >> val1;
158 data << uint8(val1);
160 else if(type == "uint16")
162 uint16 val2;
163 ifs >> val2;
164 data << val2;
166 else if(type == "uint32")
168 uint32 val3;
169 ifs >> val3;
170 data << val3;
172 else if(type == "uint64")
174 uint64 val4;
175 ifs >> val4;
176 data << val4;
178 else if(type == "float")
180 float val5;
181 ifs >> val5;
182 data << val5;
184 else if(type == "string")
186 std::string val6;
187 ifs >> val6;
188 data << val6;
190 else if(type == "pguid")
192 data.append(unit->GetPackGUID());
194 else
196 sLog.outDebug("Sending opcode: unknown type '%s'", type.c_str());
197 break;
200 ifs.close();
201 sLog.outDebug("Sending opcode %u", data.GetOpcode());
202 data.hexlike();
203 ((Player*)unit)->GetSession()->SendPacket(&data);
204 PSendSysMessage(LANG_COMMAND_OPCODESENT, data.GetOpcode(), unit->GetName());
205 return true;
208 bool ChatHandler::HandleUpdateWorldStateCommand(const char* args)
210 char* w = strtok((char*)args, " ");
211 char* s = strtok(NULL, " ");
213 if (!w || !s)
214 return false;
216 uint32 world = (uint32)atoi(w);
217 uint32 state = (uint32)atoi(s);
218 m_session->GetPlayer()->SendUpdateWorldState(world, state);
219 return true;
222 bool ChatHandler::HandlePlaySound2Command(const char* args)
224 if(!args)
225 return false;
227 uint32 soundid = atoi(args);
228 m_session->GetPlayer()->PlaySound(soundid, false);
229 return true;
232 //Send notification in channel
233 bool ChatHandler::HandleSendChannelNotifyCommand(const char* args)
235 if(!args)
236 return false;
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
244 data << uint32(0);
245 data << uint32(0);
246 m_session->SendPacket(&data);
247 return true;
250 //Send notification in chat
251 bool ChatHandler::HandleSendChatMsgCommand(const char* args)
253 if(!args)
254 return false;
256 const char *msg = "testtest";
257 uint8 type = atoi(args);
258 WorldPacket data;
259 ChatHandler::FillMessageData(&data, m_session, type, 0, "chan", m_session->GetPlayer()->GetGUID(), msg, m_session->GetPlayer());
260 m_session->SendPacket(&data);
261 return true;
264 bool ChatHandler::HandleSendQuestPartyMsgCommand(const char* args)
266 uint32 msg = atol((char*)args);
267 if (msg >= 0)
268 m_session->GetPlayer()->SendPushToPartyResponse(m_session->GetPlayer(), msg);
269 return true;
272 bool ChatHandler::HandleGetLootRecipient(const char* /*args*/)
274 Creature* target = getSelectedCreature();
275 if(!target)
276 return false;
278 PSendSysMessage("loot recipient: %s", target->hasLootRecipient()?(target->GetLootRecipient()?target->GetLootRecipient()->GetName():"offline"):"no loot recipient");
279 return true;
282 bool ChatHandler::HandleSendQuestInvalidMsgCommand(const char* args)
284 uint32 msg = atol((char*)args);
285 if (msg >= 0)
286 m_session->GetPlayer()->SendCanTakeQuestResponse(msg);
287 return true;
290 bool ChatHandler::HandleGetItemState(const char* args)
292 if (!args)
293 return false;
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;
305 else return false;
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)
317 continue;
319 Item *item = player->GetItemByPos(INVENTORY_SLOT_BAG_0, i);
320 if (!item) continue;
321 if (!item->IsBag())
323 if (item->GetState() == state)
324 PSendSysMessage("bag: 255 slot: %d guid: %d owner: %d", item->GetSlot(), item->GetGUIDLow(), GUID_LOPART(item->GetOwnerGUID()));
326 else
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()));
339 if (list_queue)
341 std::vector<Item *> &updateQueue = player->GetItemUpdateQueue();
342 for(size_t i = 0; i < updateQueue.size(); i++)
344 Item *item = updateQueue[i];
345 if(!item) continue;
347 Bag *container = item->GetContainer();
348 uint8 bag_slot = container ? container->GetSlot() : uint8(INVENTORY_SLOT_BAG_0);
350 std::string st;
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");
365 if (check_all)
367 bool error = false;
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)
372 continue;
374 Item *item = player->GetItemByPos(INVENTORY_SLOT_BAG_0, i);
375 if (!item) continue;
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;
422 if(item->IsBag())
424 Bag *bag = (Bag*)item;
425 for (uint8 j = 0; j < bag->GetBagSize(); ++j)
427 Item* item = bag->GetItemByPos(j);
428 if (!item) continue;
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();
443 if (!container)
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];
488 if(!item) continue;
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());
505 if (test == NULL)
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;
511 if (test != item)
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;
517 if (!error)
518 SendSysMessage("All OK!");
521 return true;
524 bool ChatHandler::HandleDebugBattlegroundCommand(const char * /*args*/)
526 sBattleGroundMgr.ToggleTesting();
527 return true;
530 bool ChatHandler::HandleDebugArenaCommand(const char * /*args*/)
532 sBattleGroundMgr.ToggleArenaTesting();
533 return true;
536 bool ChatHandler::HandleSpawnVehicle(const char* args)
538 if(!args)
539 return false;
541 char* e = strtok((char*)args, " ");
542 char* i = strtok(NULL, " ");
544 if (!e || !i)
545 return false;
547 uint32 entry = (uint32)atoi(e);
548 uint32 id = (uint32)atoi(i);
550 CreatureInfo const *ci = objmgr.GetCreatureTemplate(entry);
552 if(!ci)
553 return false;
555 VehicleEntry const *ve = sVehicleStore.LookupEntry(id);
557 if(!ve)
558 return false;
560 Vehicle *v = new Vehicle;
561 Map *map = m_session->GetPlayer()->GetMap();
562 if(!v->Create(objmgr.GenerateLowGuid(HIGHGUID_VEHICLE), map, entry, id, m_session->GetPlayer()->GetTeam()))
564 delete v;
565 return false;
568 float px, py, pz;
569 m_session->GetPlayer()->GetClosePoint(px, py, pz, m_session->GetPlayer()->GetObjectSize());
571 v->Relocate(px, py, pz, m_session->GetPlayer()->GetOrientation());
573 if(!v->IsPositionValid())
575 sLog.outError("ERROR: Vehicle (guidlow %d, entry %d) not created. Suggested coordinates isn't valid (X: %f Y: %f)",
576 v->GetGUIDLow(), v->GetEntry(), v->GetPositionX(), v->GetPositionY());
577 delete v;
578 return false;
581 map->Add((Creature*)v);
583 return true;
586 bool ChatHandler::HandleSendLargePacketCommand(const char* args)
588 const char* stuffingString = "This is a dummy string to push the packet's size beyond 128000 bytes. ";
589 std::ostringstream ss;
590 while(strlen(ss.str().c_str()) < 128000)
591 ss << stuffingString;
592 SendSysMessage(ss.str().c_str());
593 return true;
596 bool ChatHandler::HandleSendSetPhaseShiftCommand(const char* args)
598 if(!args)
599 return false;
601 uint32 PhaseShift = atoi(args);
602 m_session->SendSetPhaseShift(PhaseShift);
603 return true;