[7492] Rename subcommands functions to names more similar related chat commands
[AHbot.git] / src / game / debugcmds.cpp
blob35f587ff5c9b3ddc83ec3b6ca9a2e7e74b108e1e
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 bool ChatHandler::HandleDebugPlaySound2Command(const char* args)
218 if(!args)
219 return false;
221 uint32 soundid = atoi(args);
222 m_session->GetPlayer()->PlaySound(soundid, false);
223 return true;
226 //Send notification in channel
227 bool ChatHandler::HandleDebugSendChannelNotifyCommand(const char* args)
229 if(!args)
230 return false;
232 const char *name = "test";
233 uint8 code = atoi(args);
235 WorldPacket data(SMSG_CHANNEL_NOTIFY, (1+10));
236 data << code; // notify type
237 data << name; // channel name
238 data << uint32(0);
239 data << uint32(0);
240 m_session->SendPacket(&data);
241 return true;
244 //Send notification in chat
245 bool ChatHandler::HandleDebugSendChatMsgCommand(const char* args)
247 if(!args)
248 return false;
250 const char *msg = "testtest";
251 uint8 type = atoi(args);
252 WorldPacket data;
253 ChatHandler::FillMessageData(&data, m_session, type, 0, "chan", m_session->GetPlayer()->GetGUID(), msg, m_session->GetPlayer());
254 m_session->SendPacket(&data);
255 return true;
258 bool ChatHandler::HandleDebugSendQuestPartyMsgCommand(const char* args)
260 uint32 msg = atol((char*)args);
261 m_session->GetPlayer()->SendPushToPartyResponse(m_session->GetPlayer(), msg);
262 return true;
265 bool ChatHandler::HandleDebugGetLootRecipient(const char* /*args*/)
267 Creature* target = getSelectedCreature();
268 if(!target)
269 return false;
271 PSendSysMessage("loot recipient: %s", target->hasLootRecipient()?(target->GetLootRecipient()?target->GetLootRecipient()->GetName():"offline"):"no loot recipient");
272 return true;
275 bool ChatHandler::HandleDebugSendQuestInvalidMsgCommand(const char* args)
277 uint32 msg = atol((char*)args);
278 m_session->GetPlayer()->SendCanTakeQuestResponse(msg);
279 return true;
282 bool ChatHandler::HandleDebugGetItemState(const char* args)
284 if (!args)
285 return false;
287 std::string state_str = args;
289 ItemUpdateState state = ITEM_UNCHANGED;
290 bool list_queue = false, check_all = false;
291 if (state_str == "unchanged") state = ITEM_UNCHANGED;
292 else if (state_str == "changed") state = ITEM_CHANGED;
293 else if (state_str == "new") state = ITEM_NEW;
294 else if (state_str == "removed") state = ITEM_REMOVED;
295 else if (state_str == "queue") list_queue = true;
296 else if (state_str == "check_all") check_all = true;
297 else return false;
299 Player* player = getSelectedPlayer();
300 if (!player) player = m_session->GetPlayer();
302 if (!list_queue && !check_all)
304 state_str = "The player has the following " + state_str + " items: ";
305 SendSysMessage(state_str.c_str());
306 for (uint8 i = PLAYER_SLOT_START; i < PLAYER_SLOT_END; i++)
308 if(i >= BUYBACK_SLOT_START && i < BUYBACK_SLOT_END)
309 continue;
311 Item *item = player->GetItemByPos(INVENTORY_SLOT_BAG_0, i);
312 if (!item) continue;
313 if (!item->IsBag())
315 if (item->GetState() == state)
316 PSendSysMessage("bag: 255 slot: %d guid: %d owner: %d", item->GetSlot(), item->GetGUIDLow(), GUID_LOPART(item->GetOwnerGUID()));
318 else
320 Bag *bag = (Bag*)item;
321 for (uint8 j = 0; j < bag->GetBagSize(); ++j)
323 Item* item = bag->GetItemByPos(j);
324 if (item && item->GetState() == state)
325 PSendSysMessage("bag: 255 slot: %d guid: %d owner: %d", item->GetSlot(), item->GetGUIDLow(), GUID_LOPART(item->GetOwnerGUID()));
331 if (list_queue)
333 std::vector<Item *> &updateQueue = player->GetItemUpdateQueue();
334 for(size_t i = 0; i < updateQueue.size(); i++)
336 Item *item = updateQueue[i];
337 if(!item) continue;
339 Bag *container = item->GetContainer();
340 uint8 bag_slot = container ? container->GetSlot() : uint8(INVENTORY_SLOT_BAG_0);
342 std::string st;
343 switch(item->GetState())
345 case ITEM_UNCHANGED: st = "unchanged"; break;
346 case ITEM_CHANGED: st = "changed"; break;
347 case ITEM_NEW: st = "new"; break;
348 case ITEM_REMOVED: st = "removed"; break;
351 PSendSysMessage("bag: %d slot: %d guid: %d - state: %s", bag_slot, item->GetSlot(), item->GetGUIDLow(), st.c_str());
353 if (updateQueue.empty())
354 PSendSysMessage("updatequeue empty");
357 if (check_all)
359 bool error = false;
360 std::vector<Item *> &updateQueue = player->GetItemUpdateQueue();
361 for (uint8 i = PLAYER_SLOT_START; i < PLAYER_SLOT_END; i++)
363 if(i >= BUYBACK_SLOT_START && i < BUYBACK_SLOT_END)
364 continue;
366 Item *item = player->GetItemByPos(INVENTORY_SLOT_BAG_0, i);
367 if (!item) continue;
369 if (item->GetSlot() != i)
371 PSendSysMessage("item at slot %d, guid %d has an incorrect slot value: %d", i, item->GetGUIDLow(), item->GetSlot());
372 error = true; continue;
375 if (item->GetOwnerGUID() != player->GetGUID())
377 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());
378 error = true; continue;
381 if (Bag *container = item->GetContainer())
383 PSendSysMessage("item at slot: %d guid: %d has a container (slot: %d, guid: %d) but shouldnt!", item->GetSlot(), item->GetGUIDLow(), container->GetSlot(), container->GetGUIDLow());
384 error = true; continue;
387 if (item->IsInUpdateQueue())
389 uint16 qp = item->GetQueuePos();
390 if (qp > updateQueue.size())
392 PSendSysMessage("item at slot: %d guid: %d has a queuepos (%d) larger than the update queue size! ", item->GetSlot(), item->GetGUIDLow(), qp);
393 error = true; continue;
396 if (updateQueue[qp] == NULL)
398 PSendSysMessage("item at slot: %d guid: %d has a queuepos (%d) that points to NULL in the queue!", item->GetSlot(), item->GetGUIDLow(), qp);
399 error = true; continue;
402 if (updateQueue[qp] != item)
404 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());
405 error = true; continue;
408 else if (item->GetState() != ITEM_UNCHANGED)
410 PSendSysMessage("item at slot: %d guid: %d is not in queue but should be (state: %d)!", item->GetSlot(), item->GetGUIDLow(), item->GetState());
411 error = true; continue;
414 if(item->IsBag())
416 Bag *bag = (Bag*)item;
417 for (uint8 j = 0; j < bag->GetBagSize(); ++j)
419 Item* item = bag->GetItemByPos(j);
420 if (!item) continue;
422 if (item->GetSlot() != j)
424 PSendSysMessage("the item in bag %d slot %d, guid %d has an incorrect slot value: %d", bag->GetSlot(), j, item->GetGUIDLow(), item->GetSlot());
425 error = true; continue;
428 if (item->GetOwnerGUID() != player->GetGUID())
430 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());
431 error = true; continue;
434 Bag *container = item->GetContainer();
435 if (!container)
437 PSendSysMessage("the item in bag %d at slot %d with guid %d has no container!", bag->GetSlot(), item->GetSlot(), item->GetGUIDLow());
438 error = true; continue;
441 if (container != bag)
443 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());
444 error = true; continue;
447 if (item->IsInUpdateQueue())
449 uint16 qp = item->GetQueuePos();
450 if (qp > updateQueue.size())
452 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);
453 error = true; continue;
456 if (updateQueue[qp] == NULL)
458 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);
459 error = true; continue;
462 if (updateQueue[qp] != item)
464 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());
465 error = true; continue;
468 else if (item->GetState() != ITEM_UNCHANGED)
470 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());
471 error = true; continue;
477 for(size_t i = 0; i < updateQueue.size(); i++)
479 Item *item = updateQueue[i];
480 if(!item) continue;
482 if (item->GetOwnerGUID() != player->GetGUID())
484 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());
485 error = true; continue;
488 if (item->GetQueuePos() != i)
490 PSendSysMessage("queue(%d): for the an item (guid %d), the queuepos doesn't match it's position in the queue!", i, item->GetGUIDLow());
491 error = true; continue;
494 if (item->GetState() == ITEM_REMOVED) continue;
495 Item *test = player->GetItemByPos( item->GetBagSlot(), item->GetSlot());
497 if (test == NULL)
499 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());
500 error = true; continue;
503 if (test != item)
505 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());
506 error = true; continue;
509 if (!error)
510 SendSysMessage("All OK!");
513 return true;
516 bool ChatHandler::HandleDebugBattlegroundCommand(const char * /*args*/)
518 sBattleGroundMgr.ToggleTesting();
519 return true;
522 bool ChatHandler::HandleDebugArenaCommand(const char * /*args*/)
524 sBattleGroundMgr.ToggleArenaTesting();
525 return true;
528 bool ChatHandler::HandleDebugSpawnVehicle(const char* args)
530 if(!args)
531 return false;
533 char* e = strtok((char*)args, " ");
534 char* i = strtok(NULL, " ");
536 if (!e || !i)
537 return false;
539 uint32 entry = (uint32)atoi(e);
540 uint32 id = (uint32)atoi(i);
542 CreatureInfo const *ci = objmgr.GetCreatureTemplate(entry);
544 if(!ci)
545 return false;
547 VehicleEntry const *ve = sVehicleStore.LookupEntry(id);
549 if(!ve)
550 return false;
552 Vehicle *v = new Vehicle;
553 Map *map = m_session->GetPlayer()->GetMap();
554 if(!v->Create(objmgr.GenerateLowGuid(HIGHGUID_VEHICLE), map, entry, id, m_session->GetPlayer()->GetTeam()))
556 delete v;
557 return false;
560 float px, py, pz;
561 m_session->GetPlayer()->GetClosePoint(px, py, pz, m_session->GetPlayer()->GetObjectSize());
563 v->Relocate(px, py, pz, m_session->GetPlayer()->GetOrientation());
565 if(!v->IsPositionValid())
567 sLog.outError("ERROR: Vehicle (guidlow %d, entry %d) not created. Suggested coordinates isn't valid (X: %f Y: %f)",
568 v->GetGUIDLow(), v->GetEntry(), v->GetPositionX(), v->GetPositionY());
569 delete v;
570 return false;
573 map->Add((Creature*)v);
575 return true;
578 bool ChatHandler::HandleDebugSendLargePacketCommand(const char* /*args*/)
580 const char* stuffingString = "This is a dummy string to push the packet's size beyond 128000 bytes. ";
581 std::ostringstream ss;
582 while(ss.str().size() < 128000)
583 ss << stuffingString;
584 SendSysMessage(ss.str().c_str());
585 return true;
588 bool ChatHandler::HandleDebugSendSetPhaseShiftCommand(const char* args)
590 if(!args)
591 return false;
593 uint32 PhaseShift = atoi(args);
594 m_session->SendSetPhaseShift(PhaseShift);
595 return true;