[6922] Whitespace and newline fixes
[getmangos.git] / src / game / debugcmds.cpp
blob1b77f9ac6a6ed8a2a550808e72d159028f28ae4a
1 /*
2 * Copyright (C) 2005-2008 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 << uint32(133);
65 data << uint8(failnum);
66 m_session->SendPacket(&data);
68 return true;
71 bool ChatHandler::HandleSetPoiCommand(const char* args)
73 Player *pPlayer = m_session->GetPlayer();
74 Unit* target = getSelectedUnit();
75 if(!target)
77 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
78 return true;
81 if(!args)
82 return false;
84 char* icon_text = strtok((char*)args, " ");
85 char* flags_text = strtok(NULL, " ");
86 if(!icon_text || !flags_text)
87 return false;
89 uint32 icon = atol(icon_text);
90 if ( icon < 0 )
91 icon = 0;
93 uint32 flags = atol(flags_text);
95 sLog.outDetail("Command : POI, NPC = %u, icon = %u flags = %u", target->GetGUIDLow(), icon,flags);
96 pPlayer->PlayerTalkClass->SendPointOfInterest(target->GetPositionX(), target->GetPositionY(), Poi_Icon(icon), flags, 30, "Test POI");
97 return true;
100 bool ChatHandler::HandleEquipErrorCommand(const char* args)
102 if(!args)
103 return false;
105 uint8 msg = atoi(args);
106 m_session->GetPlayer()->SendEquipError(msg, 0, 0);
107 return true;
110 bool ChatHandler::HandleSellErrorCommand(const char* args)
112 if(!args)
113 return false;
115 uint8 msg = atoi(args);
116 m_session->GetPlayer()->SendSellError(msg, 0, 0, 0);
117 return true;
120 bool ChatHandler::HandleBuyErrorCommand(const char* args)
122 if(!args)
123 return false;
125 uint8 msg = atoi(args);
126 m_session->GetPlayer()->SendBuyError(msg, 0, 0, 0);
127 return true;
130 bool ChatHandler::HandleSendOpcodeCommand(const char* /*args*/)
132 Unit *unit = getSelectedUnit();
133 if (!unit || (unit->GetTypeId() != TYPEID_PLAYER))
134 unit = m_session->GetPlayer();
136 std::ifstream ifs("opcode.txt");
137 if(ifs.bad())
138 return false;
140 uint32 opcode;
141 ifs >> opcode;
143 WorldPacket data(opcode, 0);
145 while(!ifs.eof())
147 std::string type;
148 ifs >> type;
150 if(type == "")
151 break;
153 if(type == "uint8")
155 uint16 val1;
156 ifs >> val1;
157 data << uint8(val1);
159 else if(type == "uint16")
161 uint16 val2;
162 ifs >> val2;
163 data << val2;
165 else if(type == "uint32")
167 uint32 val3;
168 ifs >> val3;
169 data << val3;
171 else if(type == "uint64")
173 uint64 val4;
174 ifs >> val4;
175 data << val4;
177 else if(type == "float")
179 float val5;
180 ifs >> val5;
181 data << val5;
183 else if(type == "string")
185 std::string val6;
186 ifs >> val6;
187 data << val6;
189 else if(type == "pguid")
191 data.append(unit->GetPackGUID());
193 else
195 sLog.outDebug("Sending opcode: unknown type '%s'", type.c_str());
196 break;
199 ifs.close();
200 sLog.outDebug("Sending opcode %u", data.GetOpcode());
201 data.hexlike();
202 ((Player*)unit)->GetSession()->SendPacket(&data);
203 PSendSysMessage(LANG_COMMAND_OPCODESENT, data.GetOpcode(), unit->GetName());
204 return true;
207 bool ChatHandler::HandleUpdateWorldStateCommand(const char* args)
209 char* w = strtok((char*)args, " ");
210 char* s = strtok(NULL, " ");
212 if (!w || !s)
213 return false;
215 uint32 world = (uint32)atoi(w);
216 uint32 state = (uint32)atoi(s);
217 m_session->GetPlayer()->SendUpdateWorldState(world, state);
218 return true;
221 bool ChatHandler::HandlePlaySound2Command(const char* args)
223 if(!args)
224 return false;
226 uint32 soundid = atoi(args);
227 m_session->GetPlayer()->PlaySound(soundid, false);
228 return true;
231 //Send notification in channel
232 bool ChatHandler::HandleSendChannelNotifyCommand(const char* args)
234 if(!args)
235 return false;
237 const char *name = "test";
238 uint8 code = atoi(args);
240 WorldPacket data(SMSG_CHANNEL_NOTIFY, (1+10));
241 data << code; // notify type
242 data << name; // channel name
243 data << uint32(0);
244 data << uint32(0);
245 m_session->SendPacket(&data);
246 return true;
249 //Send notification in chat
250 bool ChatHandler::HandleSendChatMsgCommand(const char* args)
252 if(!args)
253 return false;
255 const char *msg = "testtest";
256 uint8 type = atoi(args);
257 WorldPacket data;
258 ChatHandler::FillMessageData(&data, m_session, type, 0, "chan", m_session->GetPlayer()->GetGUID(), msg, m_session->GetPlayer());
259 m_session->SendPacket(&data);
260 return true;
263 bool ChatHandler::HandleSendQuestPartyMsgCommand(const char* args)
265 uint32 msg = atol((char*)args);
266 if (msg >= 0)
267 m_session->GetPlayer()->SendPushToPartyResponse(m_session->GetPlayer(), msg);
268 return true;
271 bool ChatHandler::HandleGetLootRecipient(const char* /*args*/)
273 Creature* target = getSelectedCreature();
274 if(!target)
275 return false;
277 PSendSysMessage("loot recipient: %s", target->hasLootRecipient()?(target->GetLootRecipient()?target->GetLootRecipient()->GetName():"offline"):"no loot recipient");
278 return true;
281 bool ChatHandler::HandleSendQuestInvalidMsgCommand(const char* args)
283 uint32 msg = atol((char*)args);
284 if (msg >= 0)
285 m_session->GetPlayer()->SendCanTakeQuestResponse(msg);
286 return true;
289 bool ChatHandler::HandleGetItemState(const char* args)
291 if (!args)
292 return false;
294 std::string state_str = args;
296 ItemUpdateState state = ITEM_UNCHANGED;
297 bool list_queue = false, check_all = false;
298 if (state_str == "unchanged") state = ITEM_UNCHANGED;
299 else if (state_str == "changed") state = ITEM_CHANGED;
300 else if (state_str == "new") state = ITEM_NEW;
301 else if (state_str == "removed") state = ITEM_REMOVED;
302 else if (state_str == "queue") list_queue = true;
303 else if (state_str == "check_all") check_all = true;
304 else return false;
306 Player* player = getSelectedPlayer();
307 if (!player) player = m_session->GetPlayer();
309 if (!list_queue && !check_all)
311 state_str = "The player has the following " + state_str + " items: ";
312 SendSysMessage(state_str.c_str());
313 for (uint8 i = PLAYER_SLOT_START; i < PLAYER_SLOT_END; i++)
315 if(i >= BUYBACK_SLOT_START && i < BUYBACK_SLOT_END)
316 continue;
318 Item *item = player->GetItemByPos(INVENTORY_SLOT_BAG_0, i);
319 if (!item) continue;
320 if (!item->IsBag())
322 if (item->GetState() == state)
323 PSendSysMessage("bag: 255 slot: %d guid: %d owner: %d", item->GetSlot(), item->GetGUIDLow(), GUID_LOPART(item->GetOwnerGUID()));
325 else
327 Bag *bag = (Bag*)item;
328 for (uint8 j = 0; j < bag->GetBagSize(); ++j)
330 Item* item = bag->GetItemByPos(j);
331 if (item && item->GetState() == state)
332 PSendSysMessage("bag: 255 slot: %d guid: %d owner: %d", item->GetSlot(), item->GetGUIDLow(), GUID_LOPART(item->GetOwnerGUID()));
338 if (list_queue)
340 std::vector<Item *> &updateQueue = player->GetItemUpdateQueue();
341 for(size_t i = 0; i < updateQueue.size(); i++)
343 Item *item = updateQueue[i];
344 if(!item) continue;
346 Bag *container = item->GetContainer();
347 uint8 bag_slot = container ? container->GetSlot() : uint8(INVENTORY_SLOT_BAG_0);
349 std::string st;
350 switch(item->GetState())
352 case ITEM_UNCHANGED: st = "unchanged"; break;
353 case ITEM_CHANGED: st = "changed"; break;
354 case ITEM_NEW: st = "new"; break;
355 case ITEM_REMOVED: st = "removed"; break;
358 PSendSysMessage("bag: %d slot: %d guid: %d - state: %s", bag_slot, item->GetSlot(), item->GetGUIDLow(), st.c_str());
360 if (updateQueue.empty())
361 PSendSysMessage("updatequeue empty");
364 if (check_all)
366 bool error = false;
367 std::vector<Item *> &updateQueue = player->GetItemUpdateQueue();
368 for (uint8 i = PLAYER_SLOT_START; i < PLAYER_SLOT_END; i++)
370 if(i >= BUYBACK_SLOT_START && i < BUYBACK_SLOT_END)
371 continue;
373 Item *item = player->GetItemByPos(INVENTORY_SLOT_BAG_0, i);
374 if (!item) continue;
376 if (item->GetSlot() != i)
378 PSendSysMessage("item at slot %d, guid %d has an incorrect slot value: %d", i, item->GetGUIDLow(), item->GetSlot());
379 error = true; continue;
382 if (item->GetOwnerGUID() != player->GetGUID())
384 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());
385 error = true; continue;
388 if (Bag *container = item->GetContainer())
390 PSendSysMessage("item at slot: %d guid: %d has a container (slot: %d, guid: %d) but shouldnt!", item->GetSlot(), item->GetGUIDLow(), container->GetSlot(), container->GetGUIDLow());
391 error = true; continue;
394 if (item->IsInUpdateQueue())
396 uint16 qp = item->GetQueuePos();
397 if (qp > updateQueue.size())
399 PSendSysMessage("item at slot: %d guid: %d has a queuepos (%d) larger than the update queue size! ", item->GetSlot(), item->GetGUIDLow(), qp);
400 error = true; continue;
403 if (updateQueue[qp] == NULL)
405 PSendSysMessage("item at slot: %d guid: %d has a queuepos (%d) that points to NULL in the queue!", item->GetSlot(), item->GetGUIDLow(), qp);
406 error = true; continue;
409 if (updateQueue[qp] != item)
411 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());
412 error = true; continue;
415 else if (item->GetState() != ITEM_UNCHANGED)
417 PSendSysMessage("item at slot: %d guid: %d is not in queue but should be (state: %d)!", item->GetSlot(), item->GetGUIDLow(), item->GetState());
418 error = true; continue;
421 if(item->IsBag())
423 Bag *bag = (Bag*)item;
424 for (uint8 j = 0; j < bag->GetBagSize(); ++j)
426 Item* item = bag->GetItemByPos(j);
427 if (!item) continue;
429 if (item->GetSlot() != j)
431 PSendSysMessage("the item in bag %d slot %d, guid %d has an incorrect slot value: %d", bag->GetSlot(), j, item->GetGUIDLow(), item->GetSlot());
432 error = true; continue;
435 if (item->GetOwnerGUID() != player->GetGUID())
437 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());
438 error = true; continue;
441 Bag *container = item->GetContainer();
442 if (!container)
444 PSendSysMessage("the item in bag %d at slot %d with guid %d has no container!", bag->GetSlot(), item->GetSlot(), item->GetGUIDLow());
445 error = true; continue;
448 if (container != bag)
450 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());
451 error = true; continue;
454 if (item->IsInUpdateQueue())
456 uint16 qp = item->GetQueuePos();
457 if (qp > updateQueue.size())
459 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);
460 error = true; continue;
463 if (updateQueue[qp] == NULL)
465 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);
466 error = true; continue;
469 if (updateQueue[qp] != item)
471 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());
472 error = true; continue;
475 else if (item->GetState() != ITEM_UNCHANGED)
477 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());
478 error = true; continue;
484 for(size_t i = 0; i < updateQueue.size(); i++)
486 Item *item = updateQueue[i];
487 if(!item) continue;
489 if (item->GetOwnerGUID() != player->GetGUID())
491 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());
492 error = true; continue;
495 if (item->GetQueuePos() != i)
497 PSendSysMessage("queue(%d): for the an item (guid %d), the queuepos doesn't match it's position in the queue!", i, item->GetGUIDLow());
498 error = true; continue;
501 if (item->GetState() == ITEM_REMOVED) continue;
502 Item *test = player->GetItemByPos( item->GetBagSlot(), item->GetSlot());
504 if (test == NULL)
506 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());
507 error = true; continue;
510 if (test != item)
512 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());
513 error = true; continue;
516 if (!error)
517 SendSysMessage("All OK!");
520 return true;
523 bool ChatHandler::HandleDebugArenaCommand(const char * /*args*/)
525 sBattleGroundMgr.ToggleArenaTesting();
526 return true;