root/trunk/src/game/debugcmds.cpp @ 2

Revision 2, 17.8 kB (checked in by yumileroy, 17 years ago)

[svn] * Proper SVN structure

Original author: Neo2003
Date: 2008-10-02 16:23:55-05:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
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.
8 *
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.
13 *
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
17 */
18
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
34bool ChatHandler::HandleDebugInArcCommand(const char* /*args*/)
35{
36    Object *obj = getSelectedUnit();
37
38    if(!obj)
39    {
40        SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
41        return true;
42    }
43
44    SendSysMessage(LANG_NOT_IMPLEMENTED);
45
46    return true;
47}
48
49bool ChatHandler::HandleDebugSpellFailCommand(const char* args)
50{
51    if(!args)
52        return false;
53
54    char* px = strtok((char*)args, " ");
55    if(!px)
56        return false;
57
58    uint8 failnum = (uint8)atoi(px);
59
60    WorldPacket data(SMSG_CAST_FAILED, 5);
61    data << (uint32)133;
62    data << failnum;
63    m_session->SendPacket(&data);
64
65    return true;
66}
67
68bool ChatHandler::HandleSetPoiCommand(const char* args)
69{
70    Player *pPlayer = m_session->GetPlayer();
71    Unit* target = getSelectedUnit();
72    if(!target)
73    {
74        SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
75        return true;
76    }
77
78    if(!args)
79        return false;
80
81    char* icon_text = strtok((char*)args, " ");
82    char* flags_text = strtok(NULL, " ");
83    if(!icon_text || !flags_text)
84        return false;
85
86    uint32 icon = atol(icon_text);
87    if ( icon < 0 )
88        icon = 0;
89
90    uint32 flags = atol(flags_text);
91
92    sLog.outDetail("Command : POI, NPC = %u, icon = %u flags = %u", target->GetGUIDLow(), icon,flags);
93    pPlayer->PlayerTalkClass->SendPointOfInterest(target->GetPositionX(), target->GetPositionY(), Poi_Icon(icon), flags, 30, "Test POI");
94    return true;
95}
96
97bool ChatHandler::HandleEquipErrorCommand(const char* args)
98{
99    if(!args)
100        return false;
101
102    uint8 msg = atoi(args);
103    m_session->GetPlayer()->SendEquipError(msg, 0, 0);
104    return true;
105}
106
107bool ChatHandler::HandleSellErrorCommand(const char* args)
108{
109    if(!args)
110        return false;
111
112    uint8 msg = atoi(args);
113    m_session->GetPlayer()->SendSellError(msg, 0, 0, 0);
114    return true;
115}
116
117bool ChatHandler::HandleBuyErrorCommand(const char* args)
118{
119    if(!args)
120        return false;
121
122    uint8 msg = atoi(args);
123    m_session->GetPlayer()->SendBuyError(msg, 0, 0, 0);
124    return true;
125}
126
127bool ChatHandler::HandleSendOpcodeCommand(const char* args)
128{
129    Unit *unit = getSelectedUnit();
130    if (!unit || (unit->GetTypeId() != TYPEID_PLAYER))
131        unit = m_session->GetPlayer();
132
133    FILE *file = fopen("opcode.txt", "r");
134    if(!file)
135        return false;
136
137    uint32 type;
138
139    uint32 val1;
140    uint64 val2;
141    float val3;
142    char val4[101];
143
144    uint32 opcode = 0;
145    fscanf(file, "%u", &opcode);
146    if(!opcode)
147    {
148        fclose(file);
149        return false;
150    }
151
152    WorldPacket data(opcode, 0);
153
154    while(fscanf(file, "%u", &type) != EOF)
155    {
156        switch(type)
157        {
158            case 0:                                         // uint8
159                fscanf(file, "%u", &val1);
160                data << uint8(val1);
161                break;
162            case 1:                                         // uint16
163                fscanf(file, "%u", &val1);
164                data << uint16(val1);
165                break;
166            case 2:                                         // uint32
167                fscanf(file, "%u", &val1);
168                data << uint32(val1);
169                break;
170            case 3:                                         // uint64
171                fscanf(file, I64FMTD, &val2);
172                data << uint64(val2);
173                break;
174            case 4:                                         // float
175                fscanf(file, "%f", &val3);
176                data << float(val3);
177                break;
178            case 5:                                         // string
179                fscanf(file, "%s", val4, 101);
180                data << val4;
181                break;
182            case 6:                                         // packed guid
183                data.append(unit->GetPackGUID());
184                break;
185            default:
186                fclose(file);
187                return false;
188        }
189    }
190    fclose(file);
191    sLog.outDebug("Sending opcode %u", data.GetOpcode());
192    data.hexlike();
193    ((Player*)unit)->GetSession()->SendPacket(&data);
194    PSendSysMessage(LANG_COMMAND_OPCODESENT, data.GetOpcode(), unit->GetName());
195    return true;
196}
197
198bool ChatHandler::HandleUpdateWorldStateCommand(const char* args)
199{
200    char* w = strtok((char*)args, " ");
201    char* s = strtok(NULL, " ");
202
203    if (!w || !s)
204        return false;
205
206    uint32 world = (uint32)atoi(w);
207    uint32 state = (uint32)atoi(s);
208    m_session->GetPlayer()->SendUpdateWorldState(world, state);
209    return true;
210}
211
212bool ChatHandler::HandlePlaySound2Command(const char* args)
213{
214    if(!args)
215        return false;
216
217    uint32 soundid = atoi(args);
218    m_session->GetPlayer()->PlaySound(soundid, false);
219    return true;
220}
221
222//Send notification in channel
223bool ChatHandler::HandleSendChannelNotifyCommand(const char* args)
224{
225    if(!args)
226        return false;
227
228    const char *name = "test";
229    uint8 code = atoi(args);
230
231    WorldPacket data(SMSG_CHANNEL_NOTIFY, (1+10));
232    data << code;                                           // notify type
233    data << name;                                           // channel name
234    data << uint32(0);
235    data << uint32(0);
236    m_session->SendPacket(&data);
237    return true;
238}
239
240//Send notification in chat
241bool ChatHandler::HandleSendChatMsgCommand(const char* args)
242{
243    if(!args)
244        return false;
245
246    const char *msg = "testtest";
247    uint8 type = atoi(args);
248    WorldPacket data;
249    ChatHandler::FillMessageData(&data, m_session, type, 0, "chan", m_session->GetPlayer()->GetGUID(), msg, m_session->GetPlayer());
250    m_session->SendPacket(&data);
251    return true;
252}
253
254bool ChatHandler::HandleSendQuestPartyMsgCommand(const char* args)
255{
256    uint32 msg = atol((char*)args);
257    if (msg >= 0)
258        m_session->GetPlayer()->SendPushToPartyResponse(m_session->GetPlayer(), msg);
259    return true;
260}
261
262bool ChatHandler::HandleGetLootRecipient(const char* args)
263{
264    Creature* target = getSelectedCreature();
265    if(!target)
266        return false;
267
268    PSendSysMessage("loot recipient: %s", target->hasLootRecipient()?(target->GetLootRecipient()?target->GetLootRecipient()->GetName():"offline"):"no loot recipient");
269    return true;
270}
271
272bool ChatHandler::HandleSendQuestInvalidMsgCommand(const char* args)
273{
274    uint32 msg = atol((char*)args);
275    if (msg >= 0)
276        m_session->GetPlayer()->SendCanTakeQuestResponse(msg);
277    return true;
278}
279
280bool ChatHandler::HandleGetItemState(const char* args)
281{
282    if (!args)
283        return false;
284
285    std::string state_str = args;
286
287    ItemUpdateState state = ITEM_UNCHANGED;
288    bool list_queue = false, check_all = false;
289    if (state_str == "unchanged") state = ITEM_UNCHANGED;
290    else if (state_str == "changed") state = ITEM_CHANGED;
291    else if (state_str == "new") state = ITEM_NEW;
292    else if (state_str == "removed") state = ITEM_REMOVED;
293    else if (state_str == "queue") list_queue = true;
294    else if (state_str == "check_all") check_all = true;
295    else return false;
296
297    Player* player = getSelectedPlayer();
298    if (!player) player = m_session->GetPlayer();
299
300    if (!list_queue && !check_all)
301    {
302        state_str = "The player has the following " + state_str + " items: ";
303        SendSysMessage(state_str.c_str());
304        for (uint8 i = PLAYER_SLOT_START; i < PLAYER_SLOT_END; i++)
305        {
306            if(i >= BUYBACK_SLOT_START && i < BUYBACK_SLOT_END)
307                continue;
308
309            Item *item = player->GetItemByPos(INVENTORY_SLOT_BAG_0, i);
310            if (!item) continue;
311            if (!item->IsBag())
312            {
313                if (item->GetState() == state)
314                    PSendSysMessage("bag: 255 slot: %d guid: %d owner: %d", item->GetSlot(), item->GetGUIDLow(), GUID_LOPART(item->GetOwnerGUID()));
315            }
316            else
317            {
318                Bag *bag = (Bag*)item;
319                const ItemPrototype *proto = bag->GetProto();
320                for (uint8 j = 0; j < proto->ContainerSlots; ++j)
321                {
322                    Item* item = bag->GetItemByPos(j);
323                    if (item && item->GetState() == state)
324                        PSendSysMessage("bag: 255 slot: %d guid: %d owner: %d", item->GetSlot(), item->GetGUIDLow(), GUID_LOPART(item->GetOwnerGUID()));
325                }
326            }
327        }
328    }
329
330    if (list_queue)
331    {
332        std::vector<Item *> &updateQueue = player->GetItemUpdateQueue();
333        for(size_t i = 0; i < updateQueue.size(); i++)
334        {
335            Item *item = updateQueue[i];
336            if(!item) continue;
337
338            Bag *container = item->GetContainer();
339            uint8 bag_slot = container ? container->GetSlot() : uint8(INVENTORY_SLOT_BAG_0);
340
341            std::string st;
342            switch(item->GetState())
343            {
344                case ITEM_UNCHANGED: st = "unchanged"; break;
345                case ITEM_CHANGED: st = "changed"; break;
346                case ITEM_NEW: st = "new"; break;
347                case ITEM_REMOVED: st = "removed"; break;
348            }
349
350            PSendSysMessage("bag: %d slot: %d guid: %d - state: %s", bag_slot, item->GetSlot(), item->GetGUIDLow(), st.c_str());
351        }
352        if (updateQueue.empty())
353            PSendSysMessage("updatequeue empty");
354    }
355
356    if (check_all)
357    {
358        bool error = false;
359        std::vector<Item *> &updateQueue = player->GetItemUpdateQueue();
360        for (uint8 i = PLAYER_SLOT_START; i < PLAYER_SLOT_END; i++)
361        {
362            if(i >= BUYBACK_SLOT_START && i < BUYBACK_SLOT_END)
363                continue;
364
365            Item *item = player->GetItemByPos(INVENTORY_SLOT_BAG_0, i);
366            if (!item) continue;
367
368            if (item->GetSlot() != i)
369            {
370                PSendSysMessage("item at slot %d, guid %d has an incorrect slot value: %d", i, item->GetGUIDLow(), item->GetSlot());
371                error = true; continue;
372            }
373
374            if (item->GetOwnerGUID() != player->GetGUID())
375            {
376                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());
377                error = true; continue;
378            }
379
380            if (Bag *container = item->GetContainer())
381            {
382                PSendSysMessage("item at slot: %d guid: %d has a container (slot: %d, guid: %d) but shouldnt!", item->GetSlot(), item->GetGUIDLow(), container->GetSlot(), container->GetGUIDLow());
383                error = true; continue;
384            }
385
386            if (item->IsInUpdateQueue())
387            {
388                uint16 qp = item->GetQueuePos();
389                if (qp > updateQueue.size())
390                {
391                    PSendSysMessage("item at slot: %d guid: %d has a queuepos (%d) larger than the update queue size! ", item->GetSlot(), item->GetGUIDLow(), qp);
392                    error = true; continue;
393                }
394
395                if (updateQueue[qp] == NULL)
396                {
397                    PSendSysMessage("item at slot: %d guid: %d has a queuepos (%d) that points to NULL in the queue!", item->GetSlot(), item->GetGUIDLow(), qp);
398                    error = true; continue;
399                }
400
401                if (updateQueue[qp] != item)
402                {
403                    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());
404                    error = true; continue;
405                }
406            }
407            else if (item->GetState() != ITEM_UNCHANGED)
408            {
409                PSendSysMessage("item at slot: %d guid: %d is not in queue but should be (state: %d)!", item->GetSlot(), item->GetGUIDLow(), item->GetState());
410                error = true; continue;
411            }
412
413            if(item->IsBag())
414            {
415                Bag *bag = (Bag*)item;
416                const ItemPrototype *proto = bag->GetProto();
417                for (uint8 j = 0; j < proto->ContainerSlots; ++j)
418                {
419                    Item* item = bag->GetItemByPos(j);
420                    if (!item) continue;
421
422                    if (item->GetSlot() != j)
423                    {
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;
426                    }
427
428                    if (item->GetOwnerGUID() != player->GetGUID())
429                    {
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;
432                    }
433
434                    Bag *container = item->GetContainer();
435                    if (!container)
436                    {
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;
439                    }
440
441                    if (container != bag)
442                    {
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;
445                    }
446
447                    if (item->IsInUpdateQueue())
448                    {
449                        uint16 qp = item->GetQueuePos();
450                        if (qp > updateQueue.size())
451                        {
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;
454                        }
455
456                        if (updateQueue[qp] == NULL)
457                        {
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;
460                        }
461
462                        if (updateQueue[qp] != item)
463                        {
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;
466                        }
467                    }
468                    else if (item->GetState() != ITEM_UNCHANGED)
469                    {
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;
472                    }
473                }
474            }
475        }
476
477        for(size_t i = 0; i < updateQueue.size(); i++)
478        {
479            Item *item = updateQueue[i];
480            if(!item) continue;
481
482            if (item->GetOwnerGUID() != player->GetGUID())
483            {
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;
486            }
487
488            if (item->GetQueuePos() != i)
489            {
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;
492            }
493
494            if (item->GetState() == ITEM_REMOVED) continue;
495            Item *test = player->GetItemByPos( item->GetBagSlot(), item->GetSlot());
496
497            if (test == NULL)
498            {
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;
501            }
502
503            if (test != item)
504            {
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;
507            }
508        }
509        if (!error)
510            SendSysMessage("All OK!");
511    }
512
513    return true;
514}
Note: See TracBrowser for help on using the browser.