OregonCore  revision 3611e8a-git
Your Favourite TBC server
Level3.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the OregonCore Project. See AUTHORS file for Copyright information
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the
6  * Free Software Foundation; either version 2 of the License, or (at your
7  * option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include "Common.h"
19 #include "Database/DatabaseEnv.h"
20 #include "WorldPacket.h"
21 #include "WorldSession.h"
22 #include "World.h"
23 #include "ObjectMgr.h"
24 #include "AuctionHouseMgr.h"
25 #include "AccountMgr.h"
26 #include "PlayerDump.h"
27 #include "SpellMgr.h"
28 #include "Player.h"
29 #include "Opcodes.h"
30 #include "GameObject.h"
31 #include "Chat.h"
32 #include "Log.h"
33 #include "Guild.h"
34 #include "ObjectAccessor.h"
35 #include "MapManager.h"
36 #include "SpellAuras.h"
37 #include "Language.h"
38 #include "GridNotifiersImpl.h"
39 #include "CellImpl.h"
40 #include "Weather.h"
41 #include "PointMovementGenerator.h"
43 #include "SkillDiscovery.h"
44 #include "SkillExtraItems.h"
45 #include "SystemConfig.h"
46 #include "Config/Config.h"
47 #include "Util.h"
48 #include "ItemEnchantmentMgr.h"
49 #include "BattlegroundMgr.h"
50 #include "InstanceSaveMgr.h"
51 #include "InstanceData.h"
52 #include "AuctionHouseBot.h"
53 #include "CreatureEventAIMgr.h"
54 #include "DisableMgr.h"
55 #include "ConditionMgr.h"
56 #include "ScriptMgr.h"
57 
59 {
60  uint32 ahMapID = 0;
61  char* opt = strtok((char*)args, " ");
62  char* ahMapIdStr = strtok(NULL, " ");
63  if (ahMapIdStr)
64  ahMapID = (uint32) strtoul(ahMapIdStr, NULL, 0);
65  if (!opt)
66  {
67  PSendSysMessage("Syntax is: ahbotoptions $option $ahMapID (2, 6 or 7) $parameter");
68  PSendSysMessage("Try ahbotoptions help to see a list of options.");
69  return false;
70  }
71  int l = strlen(opt);
72 
73  if (strncmp(opt, "help", l) == 0)
74  {
75  PSendSysMessage("AHBot commands:");
76  PSendSysMessage("ahexpire");
77  PSendSysMessage("minitems");
78  PSendSysMessage("maxitems");
79  //PSendSysMessage("");
80  //PSendSysMessage("");
81  PSendSysMessage("percentages");
82  PSendSysMessage("minprice");
83  PSendSysMessage("maxprice");
84  PSendSysMessage("minbidprice");
85  PSendSysMessage("maxbidprice");
86  PSendSysMessage("maxstack");
87  PSendSysMessage("buyerprice");
88  PSendSysMessage("bidinterval");
89  PSendSysMessage("bidsperinterval");
90  return true;
91  }
92  else if (strncmp(opt, "ahexpire", l) == 0)
93  {
94  if (!ahMapIdStr)
95  {
96  PSendSysMessage("Syntax is: ahbotoptions ahexpire $ahMapID (2, 6 or 7)");
97  return false;
98  }
99  auctionbot.Commands(0, ahMapID, 0, NULL);
100  }
101  else if (strncmp(opt, "minitems", l) == 0)
102  {
103  char* param1 = strtok(NULL, " ");
104  if ((!ahMapIdStr) || (!param1))
105  {
106  PSendSysMessage("Syntax is: ahbotoptions minitems $ahMapID (2, 6 or 7) $minItems");
107  return false;
108  }
109  auctionbot.Commands(1, ahMapID, 0, param1);
110  }
111  else if (strncmp(opt, "maxitems", l) == 0)
112  {
113  char* param1 = strtok(NULL, " ");
114  if ((!ahMapIdStr) || (!param1))
115  {
116  PSendSysMessage("Syntax is: ahbotoptions maxitems $ahMapID (2, 6 or 7) $maxItems");
117  return false;
118  }
119  auctionbot.Commands(2, ahMapID, 0, param1);
120  }
121  else if (strncmp(opt, "mintime", l) == 0)
122  {
123  PSendSysMessage("ahbotoptions mintime has been deprecated");
124  return false;
125  /*
126  char * param1 = strtok(NULL, " ");
127  if ((!ahMapIdStr) || (!param1))
128  {
129  PSendSysMessage("Syntax is: ahbotoptions mintime $ahMapID (2, 6 or 7) $mintime");
130  return false;
131  }
132  auctionbot.Commands(3, ahMapID, 0, param1);
133  */
134  }
135  else if (strncmp(opt, "maxtime", l) == 0)
136  {
137  PSendSysMessage("ahbotoptions maxtime has been deprecated");
138  return false;
139  /*
140  char * param1 = strtok(NULL, " ");
141  if ((!ahMapIdStr) || (!param1))
142  {
143  PSendSysMessage("Syntax is: ahbotoptions maxtime $ahMapID (2, 6 or 7) $maxtime");
144  return false;
145  }
146  auctionbot.Commands(4, ahMapID, 0, param1);
147  */
148  }
149  else if (strncmp(opt, "percentages", l) == 0)
150  {
151  char* param1 = strtok(NULL, " ");
152  char* param2 = strtok(NULL, " ");
153  char* param3 = strtok(NULL, " ");
154  char* param4 = strtok(NULL, " ");
155  char* param5 = strtok(NULL, " ");
156  char* param6 = strtok(NULL, " ");
157  char* param7 = strtok(NULL, " ");
158  char* param8 = strtok(NULL, " ");
159  char* param9 = strtok(NULL, " ");
160  char* param10 = strtok(NULL, " ");
161  char* param11 = strtok(NULL, " ");
162  char* param12 = strtok(NULL, " ");
163  char* param13 = strtok(NULL, " ");
164  char* param14 = strtok(NULL, " ");
165  if ((!ahMapIdStr) || (!param14))
166  {
167  PSendSysMessage("Syntax is: ahbotoptions percentages $ahMapID (2, 6 or 7) $1 $2 $3 $4 $5 $6 $7 $8 $9 $10 $11 $12 $13 $14");
168  PSendSysMessage("1 GreyTradeGoods 2 WhiteTradeGoods 3 GreenTradeGoods 4 BlueTradeGoods 5 PurpleTradeGoods");
169  PSendSysMessage("6 OrangeTradeGoods 7 YellowTradeGoods 8 GreyItems 9 WhiteItems 10 GreenItems 11 BlueItems");
170  PSendSysMessage("12 PurpleItems 13 OrangeItems 14 YellowItems");
171  PSendSysMessage("The total must add up to 100%%");
172  return false;
173  }
174  uint32 greytg = (uint32) strtoul(param1, NULL, 0);
175  uint32 whitetg = (uint32) strtoul(param2, NULL, 0);
176  uint32 greentg = (uint32) strtoul(param3, NULL, 0);
177  uint32 bluetg = (uint32) strtoul(param3, NULL, 0);
178  uint32 purpletg = (uint32) strtoul(param5, NULL, 0);
179  uint32 orangetg = (uint32) strtoul(param6, NULL, 0);
180  uint32 yellowtg = (uint32) strtoul(param7, NULL, 0);
181  uint32 greyi = (uint32) strtoul(param8, NULL, 0);
182  uint32 whitei = (uint32) strtoul(param9, NULL, 0);
183  uint32 greeni = (uint32) strtoul(param10, NULL, 0);
184  uint32 bluei = (uint32) strtoul(param11, NULL, 0);
185  uint32 purplei = (uint32) strtoul(param12, NULL, 0);
186  uint32 orangei = (uint32) strtoul(param13, NULL, 0);
187  uint32 yellowi = (uint32) strtoul(param14, NULL, 0);
188  uint32 totalPercent = greytg + whitetg + greentg + bluetg + purpletg + orangetg + yellowtg + greyi + whitei + greeni + bluei + purplei + orangei + yellowi;
189  if ((totalPercent == 0) || (totalPercent != 100))
190  {
191  PSendSysMessage("Syntax is: ahbotoptions percentages $ahMapID (2, 6 or 7) $1 $2 $3 $4 $5 $6 $7 $8 $9 $10 $11 $12 $13 $14");
192  PSendSysMessage("1 GreyTradeGoods 2 WhiteTradeGoods 3 GreenTradeGoods 4 BlueTradeGoods 5 PurpleTradeGoods");
193  PSendSysMessage("6 OrangeTradeGoods 7 YellowTradeGoods 8 GreyItems 9 WhiteItems 10 GreenItems 11 BlueItems");
194  PSendSysMessage("12 PurpleItems 13 OrangeItems 14 YellowItems");
195  PSendSysMessage("The total must add up to 100%%");
196  return false;
197  }
198  char param[100];
199  param[0] = '\0';
200  strcat(param, param1);
201  strcat(param, " ");
202  strcat(param, param2);
203  strcat(param, " ");
204  strcat(param, param3);
205  strcat(param, " ");
206  strcat(param, param4);
207  strcat(param, " ");
208  strcat(param, param5);
209  strcat(param, " ");
210  strcat(param, param6);
211  strcat(param, " ");
212  strcat(param, param7);
213  strcat(param, " ");
214  strcat(param, param8);
215  strcat(param, " ");
216  strcat(param, param9);
217  strcat(param, " ");
218  strcat(param, param10);
219  strcat(param, " ");
220  strcat(param, param11);
221  strcat(param, " ");
222  strcat(param, param12);
223  strcat(param, " ");
224  strcat(param, param13);
225  strcat(param, " ");
226  strcat(param, param14);
227  auctionbot.Commands(5, ahMapID, 0, param);
228  }
229  else if (strncmp(opt, "minprice", l) == 0)
230  {
231  char* param1 = strtok(NULL, " ");
232  char* param2 = strtok(NULL, " ");
233  if ((!ahMapIdStr) || (!param1) || (!param2))
234  {
235  PSendSysMessage("Syntax is: ahbotoptions minprice $ahMapID (2, 6 or 7) $color (grey, white, green, blue, purple, orange or yellow) $price");
236  return false;
237  }
238  if (strncmp(param1, "grey", l) == 0)
239  auctionbot.Commands(6, ahMapID, AHB_GREY, param2);
240  else if (strncmp(param1, "white", l) == 0)
241  auctionbot.Commands(6, ahMapID, AHB_WHITE, param2);
242  else if (strncmp(param1, "green", l) == 0)
243  auctionbot.Commands(6, ahMapID, AHB_GREEN, param2);
244  else if (strncmp(param1, "blue", l) == 0)
245  auctionbot.Commands(6, ahMapID, AHB_BLUE, param2);
246  else if (strncmp(param1, "purple", l) == 0)
247  auctionbot.Commands(6, ahMapID, AHB_PURPLE, param2);
248  else if (strncmp(param1, "orange", l) == 0)
249  auctionbot.Commands(6, ahMapID, AHB_ORANGE, param2);
250  else if (strncmp(param1, "yellow", l) == 0)
251  auctionbot.Commands(6, ahMapID, AHB_YELLOW, param2);
252  else
253  {
254  PSendSysMessage("Syntax is: ahbotoptions minprice $ahMapID (2, 6 or 7) $color (grey, white, green, blue, purple, orange or yellow) $price");
255  return false;
256  }
257  }
258  else if (strncmp(opt, "maxprice", l) == 0)
259  {
260  char* param1 = strtok(NULL, " ");
261  char* param2 = strtok(NULL, " ");
262  if ((!ahMapIdStr) || (!param1) || (!param2))
263  {
264  PSendSysMessage("Syntax is: ahbotoptions maxprice $ahMapID (2, 6 or 7) $color (grey, white, green, blue, purple, orange or yellow) $price");
265  return false;
266  }
267  if (strncmp(param1, "grey", l) == 0)
268  auctionbot.Commands(7, ahMapID, AHB_GREY, param2);
269  else if (strncmp(param1, "white", l) == 0)
270  auctionbot.Commands(7, ahMapID, AHB_WHITE, param2);
271  else if (strncmp(param1, "green", l) == 0)
272  auctionbot.Commands(7, ahMapID, AHB_GREEN, param2);
273  else if (strncmp(param1, "blue", l) == 0)
274  auctionbot.Commands(7, ahMapID, AHB_BLUE, param2);
275  else if (strncmp(param1, "purple", l) == 0)
276  auctionbot.Commands(7, ahMapID, AHB_PURPLE, param2);
277  else if (strncmp(param1, "orange", l) == 0)
278  auctionbot.Commands(7, ahMapID, AHB_ORANGE, param2);
279  else if (strncmp(param1, "yellow", l) == 0)
280  auctionbot.Commands(7, ahMapID, AHB_YELLOW, param2);
281  else
282  {
283  PSendSysMessage("Syntax is: ahbotoptions maxprice $ahMapID (2, 6 or 7) $color (grey, white, green, blue, purple, orange or yellow) $price");
284  return false;
285  }
286  }
287  else if (strncmp(opt, "minbidprice", l) == 0)
288  {
289  char* param1 = strtok(NULL, " ");
290  char* param2 = strtok(NULL, " ");
291  if ((!ahMapIdStr) || (!param1) || (!param2))
292  {
293  PSendSysMessage("Syntax is: ahbotoptions minbidprice $ahMapID (2, 6 or 7) $color (grey, white, green, blue, purple, orange or yellow) $price");
294  return false;
295  }
296  uint32 minBidPrice = (uint32) strtoul(param2, NULL, 0);
297  if ((minBidPrice < 1) || (minBidPrice > 100))
298  {
299  PSendSysMessage("The min bid price multiplier must be between 1 and 100");
300  return false;
301  }
302  if (strncmp(param1, "grey", l) == 0)
303  auctionbot.Commands(8, ahMapID, AHB_GREY, param2);
304  else if (strncmp(param1, "white", l) == 0)
305  auctionbot.Commands(8, ahMapID, AHB_WHITE, param2);
306  else if (strncmp(param1, "green", l) == 0)
307  auctionbot.Commands(8, ahMapID, AHB_GREEN, param2);
308  else if (strncmp(param1, "blue", l) == 0)
309  auctionbot.Commands(8, ahMapID, AHB_BLUE, param2);
310  else if (strncmp(param1, "purple", l) == 0)
311  auctionbot.Commands(8, ahMapID, AHB_PURPLE, param2);
312  else if (strncmp(param1, "orange", l) == 0)
313  auctionbot.Commands(8, ahMapID, AHB_ORANGE, param2);
314  else if (strncmp(param1, "yellow", l) == 0)
315  auctionbot.Commands(8, ahMapID, AHB_YELLOW, param2);
316  else
317  {
318  PSendSysMessage("Syntax is: ahbotoptions minbidprice $ahMapID (2, 6 or 7) $color (grey, white, green, blue, purple, orange or yellow) $price");
319  return false;
320  }
321  }
322  else if (strncmp(opt, "maxbidprice", l) == 0)
323  {
324  char* param1 = strtok(NULL, " ");
325  char* param2 = strtok(NULL, " ");
326  if ((!ahMapIdStr) || (!param1) || (!param2))
327  {
328  PSendSysMessage("Syntax is: ahbotoptions maxbidprice $ahMapID (2, 6 or 7) $color (grey, white, green, blue, purple, orange or yellow) $price");
329  return false;
330  }
331  uint32 maxBidPrice = (uint32) strtoul(param2, NULL, 0);
332  if ((maxBidPrice < 1) || (maxBidPrice > 100))
333  {
334  PSendSysMessage("The max bid price multiplier must be between 1 and 100");
335  return false;
336  }
337  if (strncmp(param1, "grey", l) == 0)
338  auctionbot.Commands(9, ahMapID, AHB_GREY, param2);
339  else if (strncmp(param1, "white", l) == 0)
340  auctionbot.Commands(9, ahMapID, AHB_WHITE, param2);
341  else if (strncmp(param1, "green", l) == 0)
342  auctionbot.Commands(9, ahMapID, AHB_GREEN, param2);
343  else if (strncmp(param1, "blue", l) == 0)
344  auctionbot.Commands(9, ahMapID, AHB_BLUE, param2);
345  else if (strncmp(param1, "purple", l) == 0)
346  auctionbot.Commands(9, ahMapID, AHB_PURPLE, param2);
347  else if (strncmp(param1, "orange", l) == 0)
348  auctionbot.Commands(9, ahMapID, AHB_ORANGE, param2);
349  else if (strncmp(param1, "yellow", l) == 0)
350  auctionbot.Commands(9, ahMapID, AHB_YELLOW, param2);
351  else
352  {
353  PSendSysMessage("Syntax is: ahbotoptions max bidprice $ahMapID (2, 6 or 7) $color (grey, white, green, blue, purple, orange or yellow) $price");
354  return false;
355  }
356  }
357  else if (strncmp(opt, "maxstack", l) == 0)
358  {
359  char* param1 = strtok(NULL, " ");
360  char* param2 = strtok(NULL, " ");
361  if ((!ahMapIdStr) || (!param1) || (!param2))
362  {
363  PSendSysMessage("Syntax is: ahbotoptions maxstack $ahMapID (2, 6 or 7) $color (grey, white, green, blue, purple, orange or yellow) $value");
364  return false;
365  }
366  int32 maxStack = (uint32) strtol(param2, NULL, 0);
367  if (maxStack < 0)
368  {
369  PSendSysMessage("maxstack can't be a negative number.");
370  return false;
371  }
372  if (strncmp(param1, "grey", l) == 0)
373  auctionbot.Commands(10, ahMapID, AHB_GREY, param2);
374  else if (strncmp(param1, "white", l) == 0)
375  auctionbot.Commands(10, ahMapID, AHB_WHITE, param2);
376  else if (strncmp(param1, "green", l) == 0)
377  auctionbot.Commands(10, ahMapID, AHB_GREEN, param2);
378  else if (strncmp(param1, "blue", l) == 0)
379  auctionbot.Commands(10, ahMapID, AHB_BLUE, param2);
380  else if (strncmp(param1, "purple", l) == 0)
381  auctionbot.Commands(10, ahMapID, AHB_PURPLE, param2);
382  else if (strncmp(param1, "orange", l) == 0)
383  auctionbot.Commands(10, ahMapID, AHB_ORANGE, param2);
384  else if (strncmp(param1, "yellow", l) == 0)
385  auctionbot.Commands(10, ahMapID, AHB_YELLOW, param2);
386  else
387  {
388  PSendSysMessage("Syntax is: ahbotoptions maxstack $ahMapID (2, 6 or 7) $color (grey, white, green, blue, purple, orange or yellow) $value");
389  return false;
390  }
391  }
392  else if (strncmp(opt, "buyerprice", l) == 0)
393  {
394  char* param1 = strtok(NULL, " ");
395  char* param2 = strtok(NULL, " ");
396  if ((!ahMapIdStr) || (!param1) || (!param2))
397  {
398  PSendSysMessage("Syntax is: ahbotoptions buyerprice $ahMapID (2, 6 or 7) $color (grey, white, green, blue or purple) $price");
399  return false;
400  }
401  if (strncmp(param1, "grey", l) == 0)
402  auctionbot.Commands(11, ahMapID, AHB_GREY, param2);
403  else if (strncmp(param1, "white", l) == 0)
404  auctionbot.Commands(11, ahMapID, AHB_WHITE, param2);
405  else if (strncmp(param1, "green", l) == 0)
406  auctionbot.Commands(11, ahMapID, AHB_GREEN, param2);
407  else if (strncmp(param1, "blue", l) == 0)
408  auctionbot.Commands(11, ahMapID, AHB_BLUE, param2);
409  else if (strncmp(param1, "purple", l) == 0)
410  auctionbot.Commands(11, ahMapID, AHB_PURPLE, param2);
411  else if (strncmp(param1, "orange", l) == 0)
412  auctionbot.Commands(11, ahMapID, AHB_ORANGE, param2);
413  else if (strncmp(param1, "yellow", l) == 0)
414  auctionbot.Commands(11, ahMapID, AHB_YELLOW, param2);
415  else
416  {
417  PSendSysMessage("Syntax is: ahbotoptions buyerprice $ahMapID (2, 6 or 7) $color (grey, white, green, blue or purple) $price");
418  return false;
419  }
420  }
421  else if (strncmp(opt, "bidinterval", l) == 0)
422  {
423  char* param1 = strtok(NULL, " ");
424  if ((!ahMapIdStr) || (!param1))
425  {
426  PSendSysMessage("Syntax is: ahbotoptions bidinterval $ahMapID (2, 6 or 7) $interval(in minutes)");
427  return false;
428  }
429  auctionbot.Commands(12, ahMapID, 0, param1);
430  }
431  else if (strncmp(opt, "bidsperinterval", l) == 0)
432  {
433  char* param1 = strtok(NULL, " ");
434  if ((!ahMapIdStr) || (!param1))
435  {
436  PSendSysMessage("Syntax is: ahbotoptions bidsperinterval $ahMapID (2, 6 or 7) $bids");
437  return false;
438  }
439  auctionbot.Commands(13, ahMapID, 0, param1);
440  }
441  else
442  {
443  PSendSysMessage("Syntax is: ahbotoptions $option $ahMapID (2, 6 or 7) $parameter");
444  PSendSysMessage("Try ahbotoptions help to see a list of options.");
445  return false;
446  }
447  return true;
448 }
449 
450 //reload commands
452 {
453  sObjectMgr.LoadReferredFriends();
454  PSendSysMessage("RAF reloaded.");
455  return true;
456 }
457 
458 bool ChatHandler::HandleReloadCommand(const char* arg)
459 {
460  // this is error catcher for wrong table name in .reload commands
461  PSendSysMessage("Db table with name starting from '%s' not found and can't be reloaded.", arg);
462  SetSentErrorMessage(true);
463  return false;
464 }
465 
467 {
470 
478 
484  return true;
485 }
486 
488 {
489  //HandleReloadQuestAreaTriggersCommand(""); -- reloaded in HandleReloadAllQuestCommand
493  return true;
494 }
495 
497 {
498  sLog.outString("Re-Loading Loot Tables...");
499  LoadLootTables();
500  SendGlobalGMSysMessage("DB tables *_loot_template reloaded.");
501  sConditionMgr.LoadConditions(true);
502  return true;
503 }
504 
505 bool ChatHandler::HandleReloadAllNpcCommand(const char* /*args*/)
506 {
510  return true;
511 }
512 
514 {
517 
518  sLog.outString("Re-Loading Quests Relations...");
519  sObjectMgr.LoadQuestRelations();
520  SendGlobalGMSysMessage("DB tables *_questrelation and *_involvedrelation reloaded.");
521  return true;
522 }
523 
525 {
526  if (sWorld.IsScriptScheduled())
527  {
528  PSendSysMessage("DB scripts used currently, please attempt reload later.");
529  SetSentErrorMessage(true);
530  return false;
531  }
532 
533  sLog.outString("Re-Loading Scripts...");
539  SendGlobalGMSysMessage("DB tables *_scripts reloaded.");
542  return true;
543 }
544 
546 {
559  return true;
560 }
561 
563 {
566  return true;
567 }
568 
570 {
577  return true;
578 }
579 
580 bool ChatHandler::HandleReloadConfigCommand(const char* /*args*/)
581 {
582  sLog.outString("Re-Loading config settings...");
583  sWorld.LoadConfigSettings(true);
585  SendGlobalGMSysMessage("World config settings reloaded.");
586  return true;
587 }
588 
590 {
591  sLog.outString("Re-Loading Tavern Area Triggers...");
592  sObjectMgr.LoadTavernAreaTriggers();
593  SendGlobalGMSysMessage("DB table areatrigger_tavern reloaded.");
594  return true;
595 }
596 
598 {
599  sLog.outString("Re-Loading AreaTrigger teleport definitions...");
600  sObjectMgr.LoadAreaTriggerTeleports();
601  SendGlobalGMSysMessage("DB table areatrigger_teleport reloaded.");
602  return true;
603 }
604 
606 {
607  sLog.outString("Re-Loading Access Requirement definitions...");
608  sObjectMgr.LoadAccessRequirements();
609  SendGlobalGMSysMessage("DB table access_requirement reloaded.");
610  return true;
611 }
612 
614 {
615  sLog.outString("Re-Loading Autobroadcast...");
616  sWorld.LoadAutobroadcasts();
617  SendGlobalGMSysMessage("DB table autobroadcast reloaded.");
618  return true;
619 }
620 
622 {
623  load_command_table = true;
624  SendGlobalGMSysMessage("DB table command will be reloaded at next chat command use.");
625  return true;
626 }
627 
629 {
630  sLog.outString("Loading Quests Relations... (creature_questrelation)");
631  sObjectMgr.LoadCreatureQuestRelations();
632  SendGlobalGMSysMessage("DB table creature_questrelation (creature quest givers) reloaded.");
633  return true;
634 }
635 
637 {
638  sLog.outString("Loading Linked Respawns... (creature_linked_respawn)");
639  sObjectMgr.LoadCreatureLinkedRespawn();
640  SendGlobalGMSysMessage("DB table creature_linked_respawn (creature linked respawns) reloaded.");
641  return true;
642 }
643 
645 {
646  sLog.outString( "Re-Loading `gossip_menu` Table!" );
647  sObjectMgr.LoadGossipMenu();
648  SendGlobalSysMessage("DB table `gossip_menu` reloaded.");
649  sConditionMgr.LoadConditions(true);
650  return true;
651 }
652 
654 {
655  sLog.outString( "Re-Loading `gossip_menu_option` Table!" );
656  sObjectMgr.LoadGossipMenuItems();
657  SendGlobalSysMessage("DB table `gossip_menu_option` reloaded.");
658  sConditionMgr.LoadConditions(true);
659  return true;
660 }
661 
663 {
664  sLog.outString("Loading Quests Relations... (creature_involvedrelation)");
665  sObjectMgr.LoadCreatureInvolvedRelations();
666  SendGlobalGMSysMessage("DB table creature_involvedrelation (creature quest takers) reloaded.");
667  return true;
668 }
669 
671 {
672  sLog.outString("Loading Quests Relations... (gameobject_questrelation)");
673  sObjectMgr.LoadGameobjectQuestRelations();
674  SendGlobalGMSysMessage("DB table gameobject_questrelation (gameobject quest givers) reloaded.");
675  return true;
676 }
677 
679 {
680  sLog.outString("Loading Quests Relations... (gameobject_involvedrelation)");
681  sObjectMgr.LoadGameobjectInvolvedRelations();
682  SendGlobalGMSysMessage("DB table gameobject_involvedrelation (gameobject quest takers) reloaded.");
683  return true;
684 }
685 
687 {
688  sLog.outString("Re-Loading Quest Area Triggers...");
689  sObjectMgr.LoadQuestAreaTriggers();
690  SendGlobalGMSysMessage("DB table areatrigger_involvedrelation (quest area triggers) reloaded.");
691  return true;
692 }
693 
695 {
696  sLog.outString("Re-Loading Quest Templates...");
697  sObjectMgr.LoadQuests();
698  SendGlobalGMSysMessage("DB table quest_template (quest definitions) reloaded.");
699  return true;
700 }
701 
703 {
704  sLog.outString("Re-Loading Loot Tables... (creature_loot_template)");
707  SendGlobalGMSysMessage("DB table creature_loot_template reloaded.");
708  sConditionMgr.LoadConditions(true);
709  return true;
710 }
711 
713 {
714  sLog.outString("Re-Loading Loot Tables... (disenchant_loot_template)");
717  SendGlobalGMSysMessage("DB table disenchant_loot_template reloaded.");
718  sConditionMgr.LoadConditions(true);
719  return true;
720 }
721 
723 {
724  sLog.outString("Re-Loading Loot Tables... (fishing_loot_template)");
727  SendGlobalGMSysMessage("DB table fishing_loot_template reloaded.");
728  sConditionMgr.LoadConditions(true);
729  return true;
730 }
731 
733 {
734  sLog.outString("Re-Loading Loot Tables... (gameobject_loot_template)");
737  SendGlobalGMSysMessage("DB table gameobject_loot_template reloaded.");
738  sConditionMgr.LoadConditions(true);
739  return true;
740 }
741 
743 {
744  sLog.outString("Re-Loading Loot Tables... (item_loot_template)");
747  SendGlobalGMSysMessage("DB table item_loot_template reloaded.");
748  sConditionMgr.LoadConditions(true);
749  return true;
750 }
751 
753 {
754  sLog.outString("Re-Loading Loot Tables... (pickpocketing_loot_template)");
757  SendGlobalGMSysMessage("DB table pickpocketing_loot_template reloaded.");
758  sConditionMgr.LoadConditions(true);
759  return true;
760 }
761 
763 {
764  sLog.outString("Re-Loading Loot Tables... (prospecting_loot_template)");
767  SendGlobalGMSysMessage("DB table prospecting_loot_template reloaded.");
768  sConditionMgr.LoadConditions(true);
769  return true;
770 }
771 
773 {
774  sLog.outString( "Re-Loading Loot Tables... (`mail_loot_template`)" );
777  SendGlobalSysMessage("DB table `mail_loot_template` reloaded.");
778  sConditionMgr.LoadConditions(true);
779  return true;
780 }
781 
783 {
784  sLog.outString("Re-Loading Loot Tables... (reference_loot_template)");
786  SendGlobalGMSysMessage("DB table reference_loot_template reloaded.");
787  sConditionMgr.LoadConditions(true);
788  return true;
789 }
790 
792 {
793  sLog.outString("Re-Loading Loot Tables... (skinning_loot_template)");
796  SendGlobalGMSysMessage("DB table skinning_loot_template reloaded.");
797  sConditionMgr.LoadConditions(true);
798  return true;
799 }
800 
802 {
803  sLog.outString("Re-Loading oregon_string Table!");
804  sObjectMgr.LoadOregonStrings();
805  SendGlobalGMSysMessage("DB table oregon_string reloaded.");
806  return true;
807 }
808 
810 {
811  sLog.outString("Re-Loading npc_gossip Table!");
812  sObjectMgr.LoadNpcTextId();
813  SendGlobalGMSysMessage("DB table npc_gossip reloaded.");
814  return true;
815 }
816 
818 {
819  sLog.outString("Re-Loading npc_trainer Table!");
820  sObjectMgr.LoadTrainerSpell();
821  SendGlobalGMSysMessage("DB table npc_trainer reloaded.");
822  return true;
823 }
824 
826 {
827  sLog.outString("Re-Loading npc_vendor Table!");
828  sObjectMgr.LoadVendors();
829  SendGlobalGMSysMessage("DB table npc_vendor reloaded.");
830  return true;
831 }
832 
834 {
835  sLog.outString("Loading ReservedNames... (reserved_name)");
836  sObjectMgr.LoadReservedPlayersNames();
837  SendGlobalGMSysMessage("DB table reserved_name (player reserved names) reloaded.");
838  return true;
839 }
840 
842 {
843  sLog.outString("Re-Loading `reputation_spillover_template` Table!");
844  sObjectMgr.LoadReputationSpilloverTemplate();
845  SendGlobalSysMessage("DB table `reputation_spillover_template` reloaded.");
846  return true;
847 }
848 
850 {
851  sLog.outString("Re-Loading Skill Discovery Table...");
853  SendGlobalGMSysMessage("DB table skill_discovery_template (recipes discovered at crafting) reloaded.");
854  return true;
855 }
856 
858 {
859  sLog.outString("Re-Loading Skill Extra Item Table...");
861  SendGlobalGMSysMessage("DB table skill_extra_item_template (extra item creation when crafting) reloaded.");
862  return true;
863 }
864 
866 {
867  sLog.outString("Re-Loading Skill Fishing base level requirements...");
868  sObjectMgr.LoadFishingBaseSkillLevel();
869  SendGlobalGMSysMessage("DB table skill_fishing_base_level (fishing base level for zone/subzone) reloaded.");
870  return true;
871 }
872 
874 {
875  sLog.outString("Re-Loading SpellAffect definitions...");
876  sSpellMgr.LoadSpellAffects();
877  SendGlobalGMSysMessage("DB table spell_affect (spell mods apply requirements) reloaded.");
878  return true;
879 }
880 
882 {
883  sLog.outString("Re-Loading Spell Required Data... ");
884  sSpellMgr.LoadSpellRequired();
885  SendGlobalGMSysMessage("DB table spell_required reloaded.");
886  return true;
887 }
888 
890 {
891  sLog.outString("Re-Loading Spell Groups...");
892  sSpellMgr.LoadSpellGroups();
893  SendGlobalGMSysMessage("DB table `spell_group` (spell elixir types) reloaded.");
894  return true;
895 }
896 
898 {
899  sLog.outString( "Re-Loading Spell Group Stack Rules..." );
900  sSpellMgr.LoadSpellGroupStackRules();
901  SendGlobalGMSysMessage("DB table `spell_group_stack_rules` (spell stacking definitions) reloaded.");
902  return true;
903 }
904 
906 {
907  sLog.outString("Re-Loading Spell Learn Spells...");
908  sSpellMgr.LoadSpellLearnSpells();
909  SendGlobalGMSysMessage("DB table spell_learn_spell reloaded.");
910  return true;
911 }
912 
914 {
915  sLog.outString("Re-Loading Spell Linked Spells...");
916  sSpellMgr.LoadSpellLinked();
917  SendGlobalGMSysMessage("DB table spell_linked_spell reloaded.");
918  return true;
919 }
920 
922 {
923  sLog.outString("Re-Loading Spell Proc Event conditions...");
924  sSpellMgr.LoadSpellProcEvents();
925  SendGlobalGMSysMessage("DB table spell_proc_event (spell proc trigger requirements) reloaded.");
926  return true;
927 }
928 
930 {
931  sLog.outString("Re-Loading Spell target coordinates...");
932  sSpellMgr.LoadSpellTargetPositions();
933  SendGlobalGMSysMessage("DB table spell_target_position (destination coordinates for spell targets) reloaded.");
934  return true;
935 }
936 
938 {
939  sLog.outString("Re-Loading Aggro Spells Definitions...");
940  sSpellMgr.LoadSpellThreats();
941  SendGlobalGMSysMessage("DB table spell_threat (spell aggro definitions) reloaded.");
942  return true;
943 }
944 
946 {
947  sLog.outString("Re-Loading Spell pet auras...");
948  sSpellMgr.LoadSpellPetAuras();
949  SendGlobalGMSysMessage("DB table spell_pet_auras reloaded.");
950  return true;
951 }
952 
954 {
955  sLog.outString("Re-Loading Page Texts...");
956  sObjectMgr.LoadPageTexts();
957  SendGlobalGMSysMessage("DB table page_texts reloaded.");
958  return true;
959 }
960 
962 {
963  sLog.outString("Re-Loading Item Random Enchantments Table...");
965  SendGlobalGMSysMessage("DB table item_enchantment_template reloaded.");
966  return true;
967 }
968 
970 {
971  if (sWorld.IsScriptScheduled())
972  {
973  SendSysMessage("DB scripts used currently, please attempt reload later.");
974  SetSentErrorMessage(true);
975  return false;
976  }
977 
978  if (*arg != 'a')
979  sLog.outString("Re-Loading Scripts from gameobject_scripts...");
980 
981  sObjectMgr.LoadGameObjectScripts();
982 
983  if (*arg != 'a')
984  SendGlobalGMSysMessage("DB table gameobject_scripts reloaded.");
985 
986  return true;
987 }
988 
990 {
991  if (sWorld.IsScriptScheduled())
992  {
993  SendSysMessage("DB scripts used currently, please attempt reload later.");
994  SetSentErrorMessage(true);
995  return false;
996  }
997 
998  if (*arg != 'a')
999  sLog.outString("Re-Loading Scripts from event_scripts...");
1000 
1001  sObjectMgr.LoadEventScripts();
1002 
1003  if (*arg != 'a')
1004  SendGlobalGMSysMessage("DB table event_scripts reloaded.");
1005 
1006  return true;
1007 }
1008 
1010 {
1011 
1012  sLog.outString("Re-Loading Texts from `creature_ai_texts`...");
1013  CreatureEAI_Mgr.LoadCreatureEventAI_Texts(true);
1014  SendGlobalSysMessage("DB table `creature_ai_texts` reloaded.");
1015  return true;
1016 }
1017 
1019 {
1020  sLog.outString("Re-Loading Summons from `creature_ai_summons`...");
1021  CreatureEAI_Mgr.LoadCreatureEventAI_Summons(true);
1022  SendGlobalSysMessage("DB table `creature_ai_summons` reloaded.");
1023  return true;
1024 }
1025 
1027 {
1028  sLog.outString("Re-Loading Scripts from `creature_ai_scripts`...");
1029  CreatureEAI_Mgr.LoadCreatureEventAI_Scripts();
1030  SendGlobalSysMessage("DB table `creature_ai_scripts` reloaded.");
1031  return true;
1032 }
1033 
1035 {
1036  if (sWorld.IsScriptScheduled())
1037  {
1038  SendSysMessage("DB scripts used currently, please attempt reload later.");
1039  SetSentErrorMessage(true);
1040  return false;
1041  }
1042 
1043  if (*arg != 'a')
1044  sLog.outString("Re-Loading Scripts from waypoint_scripts...");
1045 
1046  sObjectMgr.LoadWaypointScripts();
1047 
1048  if (*arg != 'a')
1049  SendGlobalGMSysMessage("DB table waypoint_scripts reloaded.");
1050 
1051  return true;
1052 }
1053 
1055 {
1056  if (sWorld.IsScriptScheduled())
1057  {
1058  SendSysMessage("DB scripts used currently, please attempt reload later.");
1059  SetSentErrorMessage(true);
1060  return false;
1061  }
1062 
1063  if (*arg != 'a')
1064  sLog.outString("Re-Loading Scripts from quest_end_scripts...");
1065 
1066  sObjectMgr.LoadQuestEndScripts();
1067 
1068  if (*arg != 'a')
1069  SendGlobalGMSysMessage("DB table quest_end_scripts reloaded.");
1070 
1071  return true;
1072 }
1073 
1075 {
1076  if (sWorld.IsScriptScheduled())
1077  {
1078  SendSysMessage("DB scripts used currently, please attempt reload later.");
1079  SetSentErrorMessage(true);
1080  return false;
1081  }
1082 
1083  if (*arg != 'a')
1084  sLog.outString("Re-Loading Scripts from quest_start_scripts...");
1085 
1086  sObjectMgr.LoadQuestStartScripts();
1087 
1088  if (*arg != 'a')
1089  SendGlobalGMSysMessage("DB table quest_start_scripts reloaded.");
1090 
1091  return true;
1092 }
1093 
1095 {
1096  if (sWorld.IsScriptScheduled())
1097  {
1098  SendSysMessage("DB scripts used currently, please attempt reload later.");
1099  SetSentErrorMessage(true);
1100  return false;
1101  }
1102 
1103  if (*arg != 'a')
1104  sLog.outString("Re-Loading Scripts from spell_scripts...");
1105 
1106  sObjectMgr.LoadSpellScripts();
1107 
1108  if (*arg != 'a')
1109  SendGlobalGMSysMessage("DB table spell_scripts reloaded.");
1110 
1111  return true;
1112 }
1113 
1115 {
1116  sLog.outString("Re-Loading Script strings from db_script_string...");
1117  sObjectMgr.LoadDbScriptStrings();
1118  SendGlobalGMSysMessage("DB table db_script_string reloaded.");
1119  return true;
1120 }
1121 
1123 {
1124  sLog.outString("Re-Loading Graveyard-zone links...");
1125 
1126  sObjectMgr.LoadGraveyardZones();
1127 
1128  SendGlobalGMSysMessage("DB table `graveyard_zone` reloaded.");
1129 
1130  return true;
1131 }
1132 
1134 {
1135  sLog.outString("Re-Loading Game Tele coordinates...");
1136 
1137  sObjectMgr.LoadGameTele();
1138 
1139  SendGlobalGMSysMessage("DB table game_tele reloaded.");
1140 
1141  return true;
1142 }
1143 
1145 {
1146  sLog.outString("Re-Loading disables table...");
1147  sDisableMgr.LoadDisables();
1148  sLog.outString("Checking quest disables...");
1149  sDisableMgr.CheckQuestDisables();
1150  SendGlobalGMSysMessage("DB table `disables` reloaded.");
1151 
1152  return true;
1153 }
1154 
1156 {
1157  sLog.outString("Re-Loading Locales Creature ...");
1158  sObjectMgr.LoadCreatureLocales();
1159  SendGlobalGMSysMessage("DB table locales_creature reloaded.");
1160  return true;
1161 }
1162 
1164 {
1165  sLog.outString("Re-Loading Locales Gameobject ... ");
1166  sObjectMgr.LoadGameObjectLocales();
1167  SendGlobalGMSysMessage("DB table locales_gameobject reloaded.");
1168  return true;
1169 }
1170 
1172 {
1173  sLog.outString("Re-Loading Locales Item ... ");
1174  sObjectMgr.LoadItemLocales();
1175  SendGlobalGMSysMessage("DB table locales_item reloaded.");
1176  return true;
1177 }
1178 
1180 {
1181  sLog.outString("Re-Loading Locales NPC Text ... ");
1182  sObjectMgr.LoadNpcTextLocales();
1183  SendGlobalGMSysMessage("DB table locales_npc_text reloaded.");
1184  return true;
1185 }
1186 
1188 {
1189  sLog.outString("Re-Loading Locales Page Text ... ");
1190  sObjectMgr.LoadPageTextLocales();
1191  SendGlobalGMSysMessage("DB table locales_page_text reloaded.");
1192  return true;
1193 }
1194 
1196 {
1197  sLog.outString("Re-Loading Locales Quest ... ");
1198  sObjectMgr.LoadQuestLocales();
1199  SendGlobalGMSysMessage("DB table locales_quest reloaded.");
1200  return true;
1201 }
1202 
1204 {
1205  // Reload dynamic data tables from the database
1206  sLog.outString("Re-Loading Auctions...");
1207  sAuctionMgr->LoadAuctionItems();
1208  sAuctionMgr->LoadAuctions();
1209  SendGlobalGMSysMessage("Auctions reloaded.");
1210  return true;
1211 }
1212 
1214 {
1215  sLog.outString("Re-Loading Conditions...");
1216  sConditionMgr.LoadConditions(true);
1217  SendGlobalGMSysMessage("Conditions reloaded.");
1218  return true;
1219 }
1220 
1222 {
1223  if (!*args)
1224  return false;
1225 
1226  std::string targetAccountName;
1227  uint32 targetAccountId = 0;
1228  uint32 targetSecurity = 0;
1229  int32 gm = 0;
1230  char* arg1 = strtok((char*)args, " ");
1231  char* arg2 = strtok(NULL, " ");
1232  char* arg3 = strtok(NULL, " ");
1233 
1234  if (getSelectedPlayer() && arg1 && !arg3)
1235  {
1236  targetAccountId = getSelectedPlayer()->GetSession()->GetAccountId();
1237  sAccountMgr->GetName(targetAccountId, targetAccountName);
1238  Player* targetPlayer = getSelectedPlayer();
1239  gm = atoi(arg1);
1240  uint32 gmRealmID = arg2 ? strtoul(arg2, NULL, 10) : realmID;
1241 
1242  // Check for invalid specified GM level.
1243  if (gm < SEC_PLAYER || gm > SEC_ADMINISTRATOR)
1244  {
1246  SetSentErrorMessage(true);
1247  return false;
1248  }
1249 
1250  // Check if targets GM level and specified GM level is not higher than current gm level
1251  targetSecurity = targetPlayer->GetSession()->GetSecurity();
1252  if (targetSecurity >= m_session->GetSecurity() ||
1253  uint32(gm) >= m_session->GetSecurity() ||
1254  (gmRealmID != realmID && m_session->GetSecurity() < SEC_CONSOLE))
1255  {
1257  SetSentErrorMessage(true);
1258  return false;
1259  }
1260 
1261  // Decide which string to show
1262  if (m_session->GetPlayer() != targetPlayer)
1263  PSendSysMessage(LANG_YOU_CHANGE_SECURITY, targetAccountName.c_str(), gm);
1264  else
1266 
1267  // If gmRealmID is -1, delete all values for the account id, else, insert values for the specific realmID
1268  if (gmRealmID == uint32(-1))
1269  {
1270  LoginDatabase.PExecute("DELETE FROM account_access WHERE id = '%u'", targetAccountId);
1271  LoginDatabase.PExecute("INSERT INTO account_access VALUES ('%u', '%d', -1)", targetAccountId, gm);
1272  }
1273  else
1274  {
1275  LoginDatabase.PExecute("DELETE FROM account_access WHERE id = '%u' AND RealmID = '%d'", targetAccountId, realmID);
1276  LoginDatabase.PExecute("INSERT INTO account_access VALUES ('%u','%d','%d')", targetAccountId, gm, realmID);
1277  }
1278  return true;
1279  }
1280  else
1281  {
1282  // Check for second parameter
1283  if (!arg2)
1284  return false;
1285 
1286  // Check for account
1287  targetAccountName = arg1;
1288  if (!AccountMgr::normalizeString(targetAccountName))
1289  {
1290  PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, targetAccountName.c_str());
1291  SetSentErrorMessage(true);
1292  return false;
1293  }
1294 
1295  // Check for username not exist
1296  targetAccountId = sAccountMgr->GetId(targetAccountName);
1297  if (!targetAccountId)
1298  {
1299  PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, targetAccountName.c_str());
1300  SetSentErrorMessage(true);
1301  return false;
1302  }
1303 
1304  // Check for invalid specified GM level.
1305  gm = atoi(arg2);
1306  if (gm < SEC_PLAYER || gm > SEC_ADMINISTRATOR)
1307  {
1309  SetSentErrorMessage(true);
1310  return false;
1311  }
1312 
1313  uint32 gmRealmID = arg3 ? atoi(arg3) : realmID;
1314  // Check if provided realmID is not current realmID, or isn't -1
1315  if (gmRealmID != realmID && gmRealmID != uint32(-1))
1316  {
1318  SetSentErrorMessage(true);
1319  return false;
1320  }
1321 
1322  targetAccountId = sAccountMgr->GetId(arg1);
1323  // m_session == NULL only for console
1324  uint32 plSecurity = m_session ? m_session->GetSecurity() : uint32(SEC_CONSOLE);
1325 
1326  // can set security level only for target with less security and to less security that we have
1327  // This is also reject self apply in fact
1328  targetSecurity = sAccountMgr->GetSecurity(targetAccountId);
1329  if (targetSecurity >= plSecurity || uint32(gm) >= plSecurity)
1330  {
1332  SetSentErrorMessage(true);
1333  return false;
1334  }
1335 
1336  PSendSysMessage(LANG_YOU_CHANGE_SECURITY, targetAccountName.c_str(), gm);
1337  // If gmRealmID is -1, delete all values for the account id, else, insert values for the specific realmID
1338  if (gmRealmID == uint32(-1))
1339  {
1340  LoginDatabase.PExecute("DELETE FROM account_access WHERE id = '%u'", targetAccountId);
1341  LoginDatabase.PExecute("INSERT INTO account_access VALUES ('%u', '%d', -1)", targetAccountId, gm);
1342  }
1343  else
1344  {
1345  LoginDatabase.PExecute("DELETE FROM account_access WHERE id = '%u' AND RealmID = '%d'", targetAccountId, realmID);
1346  LoginDatabase.PExecute("INSERT INTO account_access VALUES ('%u','%d','%d')", targetAccountId, gm, realmID);
1347  }
1348  return true;
1349  }
1350 }
1351 
1352 // Set password for account
1354 {
1355  if (!*args)
1356  return false;
1357 
1358  // Get the command line arguments
1359  char* szAccount = strtok ((char*)args, " ");
1360  char* szPassword1 = strtok (NULL, " ");
1361  char* szPassword2 = strtok (NULL, " ");
1362 
1363  if (!szAccount || !szPassword1 || !szPassword2)
1364  return false;
1365 
1366  std::string account_name = szAccount;
1367  if (!AccountMgr::normalizeString(account_name))
1368  {
1369  PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, account_name.c_str());
1370  SetSentErrorMessage(true);
1371  return false;
1372  }
1373 
1374  uint32 targetAccountId = sAccountMgr->GetId(account_name);
1375  if (!targetAccountId)
1376  {
1377  PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, account_name.c_str());
1378  SetSentErrorMessage(true);
1379  return false;
1380  }
1381 
1382  uint32 targetSecurity = sAccountMgr->GetSecurity(targetAccountId);
1383 
1384  // m_session == NULL only for console
1385  uint32 plSecurity = m_session ? m_session->GetSecurity() : uint32(SEC_CONSOLE);
1386 
1387  // can set password only for target with less security
1388  // This is also reject self apply in fact
1389  if (targetSecurity >= plSecurity)
1390  {
1392  SetSentErrorMessage (true);
1393  return false;
1394  }
1395 
1396  if (strcmp(szPassword1, szPassword2))
1397  {
1399  SetSentErrorMessage (true);
1400  return false;
1401  }
1402 
1403  AccountOpResult result = sAccountMgr->ChangePassword(targetAccountId, szPassword1);
1404 
1405  switch (result)
1406  {
1407  case AOR_OK:
1409  break;
1410  case AOR_NAME_NOT_EXIST:
1411  PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, account_name.c_str());
1412  SetSentErrorMessage(true);
1413  return false;
1414  case AOR_PASS_TOO_LONG:
1416  SetSentErrorMessage(true);
1417  return false;
1418  default:
1420  SetSentErrorMessage(true);
1421  return false;
1422  }
1423 
1424  return true;
1425 }
1426 
1428 {
1429  if (sWorld.getAllowMovement())
1430  {
1431  sWorld.SetAllowMovement(false);
1433  }
1434  else
1435  {
1436  sWorld.SetAllowMovement(true);
1438  }
1439  return true;
1440 }
1441 
1442 bool ChatHandler::HandleMaxSkillCommand(const char* /*args*/)
1443 {
1444  Player* SelectedPlayer = getSelectedPlayer();
1445  if (!SelectedPlayer)
1446  {
1448  SetSentErrorMessage(true);
1449  return false;
1450  }
1451 
1452  // each skills that have max skill value dependent from level seted to current level max skill value
1453  SelectedPlayer->UpdateSkillsToMaxSkillsForLevel();
1454  return true;
1455 }
1456 
1458 {
1459  // number or [name] Shift-click form |color|Hskill:skill_id|h[name]|h|r
1460  char* skill_p = extractKeyFromLink((char*)args, "Hskill");
1461  if (!skill_p)
1462  return false;
1463 
1464  char* level_p = strtok (NULL, " ");
1465 
1466  if (!level_p)
1467  return false;
1468 
1469  char* max_p = strtok (NULL, " ");
1470 
1471  int32 skill = atoi(skill_p);
1472  if (skill <= 0)
1473  {
1475  SetSentErrorMessage(true);
1476  return false;
1477  }
1478 
1479  int32 level = atol (level_p);
1480 
1481  Player* target = getSelectedPlayerOrSelf();
1482  if (!target)
1483  {
1485  SetSentErrorMessage(true);
1486  return false;
1487  }
1488 
1489  SkillLineEntry const* sl = sSkillLineStore.LookupEntry(skill);
1490  if (!sl)
1491  {
1493  SetSentErrorMessage(true);
1494  return false;
1495  }
1496 
1497  if (!target->GetSkillValue(skill))
1498  {
1500  SetSentErrorMessage(true);
1501  return false;
1502  }
1503 
1504  int32 max = max_p ? atol (max_p) : target->GetPureMaxSkillValue(skill);
1505 
1506  if (level <= 0 || level > max || max <= 0)
1507  return false;
1508 
1509  target->SetSkill(skill, level, max);
1510  PSendSysMessage(LANG_SET_SKILL, skill, sl->name[m_session->GetSessionDbcLocale()], target->GetName(), level, max);
1511 
1512  return true;
1513 }
1514 
1516 {
1517  if (!*args)
1518  return false;
1519 
1520  // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
1521  uint32 min_id = extractSpellIdFromLink((char*)args);
1522  if (!min_id)
1523  return false;
1524 
1525  // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
1526  char* tail = strtok(NULL, "");
1527 
1528  uint32 max_id = extractSpellIdFromLink(tail);
1529 
1530  if (!max_id)
1531  {
1532  // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
1533  max_id = min_id + 1;
1534  }
1535  else
1536  {
1537  if (max_id < min_id)
1538  std::swap(min_id, max_id);
1539 
1540  max_id = max_id + 1;
1541  }
1542 
1543  Player* target = getSelectedPlayer();
1544  if (!target)
1545  {
1547  SetSentErrorMessage(true);
1548  return false;
1549  }
1550 
1551  for (uint32 spell = min_id; spell < max_id; spell++)
1552  {
1553  if (target->HasSpell(spell))
1554  target->RemoveSpell(spell);
1555  else
1557  }
1558 
1559  return true;
1560 }
1561 
1563 {
1564  Player* target = getSelectedPlayerOrSelf();
1565  if (!target)
1566  {
1568  SetSentErrorMessage(true);
1569  return false;
1570  }
1571 
1572  if (!*args)
1573  {
1574  target->RemoveAllSpellCooldown();
1576  }
1577  else
1578  {
1579  // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
1580  uint32 spell_id = extractSpellIdFromLink((char*)args);
1581  if (!spell_id)
1582  return false;
1583 
1584  if (!sSpellStore.LookupEntry(spell_id))
1585  {
1587  SetSentErrorMessage(true);
1588  return false;
1589  }
1590 
1591  target->RemoveSpellCooldown(spell_id, true);
1593  }
1594  return true;
1595 }
1596 
1597 bool ChatHandler::HandleLearnAllCommand(const char* /*args*/)
1598 {
1599  static const char* allSpellList[] =
1600  {
1601  "3365",
1602  "6233",
1603  "6247",
1604  "6246",
1605  "6477",
1606  "6478",
1607  "22810",
1608  "8386",
1609  "21651",
1610  "21652",
1611  "522",
1612  "7266",
1613  "8597",
1614  "2479",
1615  "22027",
1616  "6603",
1617  "5019",
1618  "133",
1619  "168",
1620  "227",
1621  "5009",
1622  "9078",
1623  "668",
1624  "203",
1625  "20599",
1626  "20600",
1627  "81",
1628  "20597",
1629  "20598",
1630  "20864",
1631  "1459",
1632  "5504",
1633  "587",
1634  "5143",
1635  "118",
1636  "5505",
1637  "597",
1638  "604",
1639  "1449",
1640  "1460",
1641  "2855",
1642  "1008",
1643  "475",
1644  "5506",
1645  "1463",
1646  "12824",
1647  "8437",
1648  "990",
1649  "5145",
1650  "8450",
1651  "1461",
1652  "759",
1653  "8494",
1654  "8455",
1655  "8438",
1656  "6127",
1657  "8416",
1658  "6129",
1659  "8451",
1660  "8495",
1661  "8439",
1662  "3552",
1663  "8417",
1664  "10138",
1665  "12825",
1666  "10169",
1667  "10156",
1668  "10144",
1669  "10191",
1670  "10201",
1671  "10211",
1672  "10053",
1673  "10173",
1674  "10139",
1675  "10145",
1676  "10192",
1677  "10170",
1678  "10202",
1679  "10054",
1680  "10174",
1681  "10193",
1682  "12826",
1683  "2136",
1684  "143",
1685  "145",
1686  "2137",
1687  "2120",
1688  "3140",
1689  "543",
1690  "2138",
1691  "2948",
1692  "8400",
1693  "2121",
1694  "8444",
1695  "8412",
1696  "8457",
1697  "8401",
1698  "8422",
1699  "8445",
1700  "8402",
1701  "8413",
1702  "8458",
1703  "8423",
1704  "8446",
1705  "10148",
1706  "10197",
1707  "10205",
1708  "10149",
1709  "10215",
1710  "10223",
1711  "10206",
1712  "10199",
1713  "10150",
1714  "10216",
1715  "10207",
1716  "10225",
1717  "10151",
1718  "116",
1719  "205",
1720  "7300",
1721  "122",
1722  "837",
1723  "10",
1724  "7301",
1725  "7322",
1726  "6143",
1727  "120",
1728  "865",
1729  "8406",
1730  "6141",
1731  "7302",
1732  "8461",
1733  "8407",
1734  "8492",
1735  "8427",
1736  "8408",
1737  "6131",
1738  "7320",
1739  "10159",
1740  "8462",
1741  "10185",
1742  "10179",
1743  "10160",
1744  "10180",
1745  "10219",
1746  "10186",
1747  "10177",
1748  "10230",
1749  "10181",
1750  "10161",
1751  "10187",
1752  "10220",
1753  "2018",
1754  "2663",
1755  "12260",
1756  "2660",
1757  "3115",
1758  "3326",
1759  "2665",
1760  "3116",
1761  "2738",
1762  "3293",
1763  "2661",
1764  "3319",
1765  "2662",
1766  "9983",
1767  "8880",
1768  "2737",
1769  "2739",
1770  "7408",
1771  "3320",
1772  "2666",
1773  "3323",
1774  "3324",
1775  "3294",
1776  "22723",
1777  "23219",
1778  "23220",
1779  "23221",
1780  "23228",
1781  "23338",
1782  "10788",
1783  "10790",
1784  "5611",
1785  "5016",
1786  "5609",
1787  "2060",
1788  "10963",
1789  "10964",
1790  "10965",
1791  "22593",
1792  "22594",
1793  "596",
1794  "996",
1795  "499",
1796  "768",
1797  "17002",
1798  "1448",
1799  "1082",
1800  "16979",
1801  "1079",
1802  "5215",
1803  "20484",
1804  "5221",
1805  "15590",
1806  "17007",
1807  "6795",
1808  "6807",
1809  "5487",
1810  "1446",
1811  "1066",
1812  "5421",
1813  "3139",
1814  "779",
1815  "6811",
1816  "6808",
1817  "1445",
1818  "5216",
1819  "1737",
1820  "5222",
1821  "5217",
1822  "1432",
1823  "6812",
1824  "9492",
1825  "5210",
1826  "3030",
1827  "1441",
1828  "783",
1829  "6801",
1830  "20739",
1831  "8944",
1832  "9491",
1833  "22569",
1834  "5226",
1835  "6786",
1836  "1433",
1837  "8973",
1838  "1828",
1839  "9495",
1840  "9006",
1841  "6794",
1842  "8993",
1843  "5203",
1844  "16914",
1845  "6784",
1846  "9635",
1847  "22830",
1848  "20722",
1849  "9748",
1850  "6790",
1851  "9753",
1852  "9493",
1853  "9752",
1854  "9831",
1855  "9825",
1856  "9822",
1857  "5204",
1858  "5401",
1859  "22831",
1860  "6793",
1861  "9845",
1862  "17401",
1863  "9882",
1864  "9868",
1865  "20749",
1866  "9893",
1867  "9899",
1868  "9895",
1869  "9832",
1870  "9902",
1871  "9909",
1872  "22832",
1873  "9828",
1874  "9851",
1875  "9883",
1876  "9869",
1877  "17406",
1878  "17402",
1879  "9914",
1880  "20750",
1881  "9897",
1882  "9848",
1883  "3127",
1884  "107",
1885  "204",
1886  "9116",
1887  "2457",
1888  "78",
1889  "18848",
1890  "331",
1891  "403",
1892  "2098",
1893  "1752",
1894  "11278",
1895  "11288",
1896  "11284",
1897  "6461",
1898  "2344",
1899  "2345",
1900  "6463",
1901  "2346",
1902  "2352",
1903  "775",
1904  "1434",
1905  "1612",
1906  "71",
1907  "2468",
1908  "2458",
1909  "2467",
1910  "7164",
1911  "7178",
1912  "7367",
1913  "7376",
1914  "7381",
1915  "21156",
1916  "5209",
1917  "3029",
1918  "5201",
1919  "9849",
1920  "9850",
1921  "20719",
1922  "22568",
1923  "22827",
1924  "22828",
1925  "22829",
1926  "6809",
1927  "8972",
1928  "9005",
1929  "9823",
1930  "9827",
1931  "6783",
1932  "9913",
1933  "6785",
1934  "6787",
1935  "9866",
1936  "9867",
1937  "9894",
1938  "9896",
1939  "6800",
1940  "8992",
1941  "9829",
1942  "9830",
1943  "780",
1944  "769",
1945  "6749",
1946  "6750",
1947  "9755",
1948  "9754",
1949  "9908",
1950  "20745",
1951  "20742",
1952  "20747",
1953  "20748",
1954  "9746",
1955  "9745",
1956  "9880",
1957  "9881",
1958  "5391",
1959  "842",
1960  "3025",
1961  "3031",
1962  "3287",
1963  "3329",
1964  "1945",
1965  "3559",
1966  "4933",
1967  "4934",
1968  "4935",
1969  "4936",
1970  "5142",
1971  "5390",
1972  "5392",
1973  "5404",
1974  "5420",
1975  "6405",
1976  "7293",
1977  "7965",
1978  "8041",
1979  "8153",
1980  "9033",
1981  "9034",
1982  //"9036", problems with ghost state
1983  "16421",
1984  "21653",
1985  "22660",
1986  "5225",
1987  "9846",
1988  "2426",
1989  "5916",
1990  "6634",
1991  //"6718", phasing stealth, annoying for learn all case.
1992  "6719",
1993  "8822",
1994  "9591",
1995  "9590",
1996  "10032",
1997  "17746",
1998  "17747",
1999  "8203",
2000  "11392",
2001  "12495",
2002  "16380",
2003  "23452",
2004  "4079",
2005  "4996",
2006  "4997",
2007  "4998",
2008  "4999",
2009  "5000",
2010  "6348",
2011  "6349",
2012  "6481",
2013  "6482",
2014  "6483",
2015  "6484",
2016  "11362",
2017  "11410",
2018  "11409",
2019  "12510",
2020  "12509",
2021  "12885",
2022  "13142",
2023  "21463",
2024  "23460",
2025  "11421",
2026  "11416",
2027  "11418",
2028  "1851",
2029  "10059",
2030  "11423",
2031  "11417",
2032  "11422",
2033  "11419",
2034  "11424",
2035  "11420",
2036  "27",
2037  "31",
2038  "33",
2039  "34",
2040  "35",
2041  "15125",
2042  "21127",
2043  "22950",
2044  "1180",
2045  "201",
2046  "12593",
2047  "12842",
2048  "16770",
2049  "6057",
2050  "12051",
2051  "18468",
2052  "12606",
2053  "12605",
2054  "18466",
2055  "12502",
2056  "12043",
2057  "15060",
2058  "12042",
2059  "12341",
2060  "12848",
2061  "12344",
2062  "12353",
2063  "18460",
2064  "11366",
2065  "12350",
2066  "12352",
2067  "13043",
2068  "11368",
2069  "11113",
2070  "12400",
2071  "11129",
2072  "16766",
2073  "12573",
2074  "15053",
2075  "12580",
2076  "12475",
2077  "12472",
2078  "12953",
2079  "12488",
2080  "11189",
2081  "12985",
2082  "12519",
2083  "16758",
2084  "11958",
2085  "12490",
2086  "11426",
2087  "3565",
2088  "3562",
2089  "18960",
2090  "3567",
2091  "3561",
2092  "3566",
2093  "3563",
2094  "1953",
2095  "2139",
2096  "12505",
2097  "13018",
2098  "12522",
2099  "12523",
2100  "5146",
2101  "5144",
2102  "5148",
2103  "8419",
2104  "8418",
2105  "10213",
2106  "10212",
2107  "10157",
2108  "12524",
2109  "13019",
2110  "12525",
2111  "13020",
2112  "12526",
2113  "13021",
2114  "18809",
2115  "13031",
2116  "13032",
2117  "13033",
2118  "4036",
2119  "3920",
2120  "3919",
2121  "3918",
2122  "7430",
2123  "3922",
2124  "3923",
2125  "7411",
2126  "7418",
2127  "7421",
2128  "13262",
2129  "7412",
2130  "7415",
2131  "7413",
2132  "7416",
2133  "13920",
2134  "13921",
2135  "7745",
2136  "7779",
2137  "7428",
2138  "7457",
2139  "7857",
2140  "7748",
2141  "7426",
2142  "13421",
2143  "7454",
2144  "13378",
2145  "7788",
2146  "14807",
2147  "14293",
2148  "7795",
2149  "6296",
2150  "20608",
2151  "755",
2152  "444",
2153  "427",
2154  "428",
2155  "442",
2156  "447",
2157  "3578",
2158  "3581",
2159  "19027",
2160  "3580",
2161  "665",
2162  "3579",
2163  "3577",
2164  "6755",
2165  "3576",
2166  "2575",
2167  "2577",
2168  "2578",
2169  "2579",
2170  "2580",
2171  "2656",
2172  "2657",
2173  "2576",
2174  "3564",
2175  "10248",
2176  "8388",
2177  "2659",
2178  "14891",
2179  "3308",
2180  "3307",
2181  "10097",
2182  "2658",
2183  "3569",
2184  "16153",
2185  "3304",
2186  "10098",
2187  "4037",
2188  "3929",
2189  "3931",
2190  "3926",
2191  "3924",
2192  "3930",
2193  "3977",
2194  "3925",
2195  "136",
2196  "228",
2197  "5487",
2198  "43",
2199  "202",
2200  "0"
2201  };
2202 
2203  int loop = 0;
2204  while (strcmp(allSpellList[loop], "0"))
2205  {
2206  uint32 spell = atol((char*)allSpellList[loop++]);
2207 
2208  if (m_session->GetPlayer()->HasSpell(spell))
2209  continue;
2210 
2211  SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
2212  if (!spellInfo || !SpellMgr::IsSpellValid(spellInfo, m_session->GetPlayer()))
2213  {
2215  continue;
2216  }
2217 
2218  m_session->GetPlayer()->LearnSpell(spell);
2219  }
2220 
2222 
2223  return true;
2224 }
2225 
2226 bool ChatHandler::HandleLearnAllGMCommand(const char* /*args*/)
2227 {
2228  static const char* gmSpellList[] =
2229  {
2230  "24347", // Become A Fish, No Breath Bar
2231  "35132", // Visual Boom
2232  "38488", // Attack 4000-8000 AOE
2233  "38795", // Attack 2000 AOE + Slow Down 90%
2234  "15712", // Attack 200
2235  "1852", // GM Spell Silence
2236  "31899", // Kill
2237  "31924", // Kill
2238  "29878", // Kill My Self
2239  "26644", // More Kill
2240 
2241  "28550", //Invisible 24
2242  "23452", //Invisible + Target
2243  "0"
2244  };
2245 
2246  uint16 gmSpellIter = 0;
2247  while (strcmp(gmSpellList[gmSpellIter], "0"))
2248  {
2249  uint32 spell = atol((char*)gmSpellList[gmSpellIter++]);
2250 
2251  SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
2252  if (!spellInfo || !SpellMgr::IsSpellValid(spellInfo, m_session->GetPlayer()))
2253  {
2255  continue;
2256  }
2257 
2258  m_session->GetPlayer()->LearnSpell(spell);
2259  }
2260 
2262  return true;
2263 }
2264 
2266 {
2269  return true;
2270 }
2271 
2273 {
2274  Player* player = m_session->GetPlayer();
2275  uint8 level = player->getLevel();
2276  uint32 teamID = player->GetTeamId();
2277  uint32 trainerID;
2278 
2279  switch (player->getClass())
2280  {
2281  case CLASS_WARRIOR:
2282  if (teamID == TEAM_ALLIANCE)
2283  trainerID = 17504;
2284  else
2285  trainerID = 985;
2286  break;
2287  case CLASS_ROGUE:
2288  if (teamID == TEAM_ALLIANCE)
2289  trainerID = 13283;
2290  else
2291  trainerID = 3401;
2292  break;
2293  case CLASS_SHAMAN:
2294  if (teamID == TEAM_ALLIANCE)
2295  trainerID = 20407;
2296  else
2297  trainerID = 13417;
2298  break;
2299  case CLASS_PRIEST:
2300  if (teamID == TEAM_ALLIANCE)
2301  trainerID = 11406;
2302  else
2303  trainerID = 16658;
2304  break;
2305  case CLASS_MAGE:
2306  if (teamID == TEAM_ALLIANCE)
2307  trainerID = 7312;
2308  else
2309  trainerID = 16653;
2310  break;
2311  case CLASS_WARLOCK:
2312  if (teamID == TEAM_ALLIANCE)
2313  trainerID = 5172;
2314  else
2315  trainerID = 16648;
2316  break;
2317  case CLASS_HUNTER:
2318  if (teamID == TEAM_ALLIANCE)
2319  trainerID = 5516;
2320  else
2321  trainerID = 3039;
2322  break;
2323  case CLASS_DRUID:
2324  if (teamID == TEAM_ALLIANCE)
2325  trainerID = 5504;
2326  else
2327  trainerID = 16655;
2328  break;
2329  case CLASS_PALADIN:
2330  if (teamID == TEAM_ALLIANCE)
2331  trainerID = 928;
2332  else
2333  trainerID = 16681;
2334  break;
2335  default:
2336  sLog.outDebug("HandleLearnAllMySpellsCommand Failed. Invalid Class %u.", player->getClass());
2337  return false;
2338  }
2339 
2340  QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT spell FROM npc_trainer WHERE reqlevel BETWEEN 1 AND %i AND entry = %i", level, trainerID);
2341 
2342  if (!result)
2343  {
2344  sLog.outErrorDb("0 spells found for HandleLearnAllMySpellsCommand function.");
2345  return false;
2346  }
2347 
2348  do
2349  {
2350  Field* fields = result->Fetch();
2351 
2352  uint32 spellID = fields[0].GetUInt32();
2353 
2354  SpellEntry const* spellInfo = sSpellStore.LookupEntry(spellID);
2355 
2356  if (!spellInfo)
2357  continue;
2358 
2359  // skip wrong class/race skills
2360  if (!player->IsSpellFitByClassAndRace(spellInfo->Id))
2361  continue;
2362 
2363  // Skip known spells
2364  if (player->HasSpell(spellInfo->Id))
2365  continue;
2366 
2367  // Skip spells with first rank learned as talent (and all talents then also)
2368  if (GetTalentSpellCost(sSpellMgr.GetFirstSpellInChain(spellInfo->Id)) > 0)
2369  continue;
2370 
2371  // Skip broken spells
2372  if (!SpellMgr::IsSpellValid(spellInfo, player, false))
2373  continue;
2374 
2375  player->LearnSpell(spellInfo->Id);
2376  }
2377  while (result->NextRow());
2378 
2380  return true;
2381 }
2382 
2384 {
2385  Player* player = m_session->GetPlayer();
2386  uint32 classMask = player->getClassMask();
2387 
2388  for (uint32 i = 0; i < sTalentStore.GetNumRows(); i++)
2389  {
2390  TalentEntry const* talentInfo = sTalentStore.LookupEntry(i);
2391  if (!talentInfo)
2392  continue;
2393 
2394  TalentTabEntry const* talentTabInfo = sTalentTabStore.LookupEntry(talentInfo->TalentTab);
2395  if (!talentTabInfo)
2396  continue;
2397 
2398  if ((classMask & talentTabInfo->ClassMask) == 0)
2399  continue;
2400 
2401  // search highest talent rank
2402  uint32 spellId = 0;
2403  int rank = 4;
2404  for (; rank >= 0; --rank)
2405  {
2406  if (talentInfo->RankID[rank] != 0)
2407  {
2408  spellId = talentInfo->RankID[rank];
2409  break;
2410  }
2411  }
2412 
2413  if (!spellId) // ??? none spells in talent
2414  continue;
2415 
2416  SpellEntry const* spellInfo = sSpellStore.LookupEntry(spellId);
2417  if (!spellInfo || !SpellMgr::IsSpellValid(spellInfo, m_session->GetPlayer(), false))
2418  continue;
2419 
2420  // learn highest rank of talent
2421  player->LearnSpellHighestRank(spellId);
2422  }
2423 
2424  player->SetFreeTalentPoints(0);
2425 
2427  return true;
2428 }
2429 
2430 bool ChatHandler::HandleLearnAllLangCommand(const char* /*args*/)
2431 {
2432  // skipping UNIVERSAL language (0)
2433  for (uint8 i = 1; i < LANGUAGES_COUNT; ++i)
2435 
2437  return true;
2438 }
2439 
2441 {
2442  char* pName = strtok((char*)args, "");
2443  Player* player = NULL;
2444  if (pName)
2445  {
2446  std::string name = pName;
2447 
2448  if (!normalizePlayerName(name))
2449  {
2451  SetSentErrorMessage(true);
2452  return false;
2453  }
2454 
2455  player = sObjectMgr.GetPlayer(name.c_str());
2456  }
2457  else
2458  player = getSelectedPlayer();
2459 
2460  if (!player)
2461  {
2463  SetSentErrorMessage(true);
2464  return false;
2465  }
2466 
2467  player->LearnDefaultSpells();
2468  player->LearnQuestRewardedSpells();
2469 
2471  return true;
2472 }
2473 
2474 bool ChatHandler::HandleLearnCommand(const char* args)
2475 {
2476  Player* targetPlayer = getSelectedPlayerOrSelf();
2477 
2478  if (!targetPlayer)
2479  {
2481  SetSentErrorMessage(true);
2482  return false;
2483  }
2484 
2485  // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
2486  uint32 spell = extractSpellIdFromLink((char*)args);
2487  if (!spell || !sSpellStore.LookupEntry(spell))
2488  return false;
2489 
2490  if (targetPlayer->HasSpell(spell))
2491  {
2492  if (targetPlayer == m_session->GetPlayer())
2494  else
2496  SetSentErrorMessage(true);
2497  return false;
2498  }
2499 
2500  SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
2501  if (!spellInfo || !SpellMgr::IsSpellValid(spellInfo, m_session->GetPlayer()))
2502  {
2504  SetSentErrorMessage(true);
2505  return false;
2506  }
2507 
2508  targetPlayer->LearnSpell(spell);
2509 
2510  return true;
2511 }
2512 
2514 {
2515  if (!*args)
2516  return false;
2517 
2518  uint32 itemId = 0;
2519 
2520  if (args[0] == '[') // [name] manual form
2521  {
2522  char* citemName = strtok((char*)args, "]");
2523 
2524  if (citemName && citemName[0])
2525  {
2526  std::string itemName = citemName + 1;
2527  WorldDatabase.escape_string(itemName);
2528  QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT entry FROM item_template WHERE name = '%s'", itemName.c_str());
2529  if (!result)
2530  {
2532  SetSentErrorMessage(true);
2533  return false;
2534  }
2535  itemId = result->Fetch()->GetUInt16();
2536  }
2537  else
2538  return false;
2539  }
2540  else // item_id or [name] Shift-click form |color|Hitem:item_id:0:0:0|h[name]|h|r
2541  {
2542  char* cId = extractKeyFromLink((char*)args, "Hitem");
2543  if (!cId)
2544  return false;
2545  itemId = atol(cId);
2546  }
2547 
2548  char* ccount = strtok(NULL, " ");
2549 
2550  int32 count = 1;
2551 
2552  if (ccount)
2553  count = strtol(ccount, NULL, 10);
2554 
2555  if (count == 0)
2556  count = 1;
2557 
2558  Player* pl = m_session->GetPlayer();
2559  Player* plTarget = getSelectedPlayer();
2560  if (!plTarget)
2561  plTarget = pl;
2562 
2563  sLog.outDetail(GetOregonString(LANG_ADDITEM), itemId, count);
2564 
2565  ItemTemplate const* pProto = sObjectMgr.GetItemTemplate(itemId);
2566  if (!pProto)
2567  {
2569  SetSentErrorMessage(true);
2570  return false;
2571  }
2572 
2573  //Subtract
2574  if (count < 0)
2575  {
2576  plTarget->DestroyItemCount(itemId, -count, true, false);
2577  PSendSysMessage(LANG_REMOVEITEM, itemId, -count, plTarget->GetName());
2578  return true;
2579  }
2580 
2581  //Adding items
2582  uint32 noSpaceForCount = 0;
2583 
2584  // check space and find places
2585  ItemPosCountVec dest;
2586  uint8 msg = plTarget->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, itemId, count, &noSpaceForCount);
2587  if (msg != EQUIP_ERR_OK) // convert to possible store amount
2588  count -= noSpaceForCount;
2589 
2590  if (count == 0 || dest.empty()) // can't add any
2591  {
2592  PSendSysMessage(LANG_ITEM_CANNOT_CREATE, itemId, noSpaceForCount);
2593  SetSentErrorMessage(true);
2594  return false;
2595  }
2596 
2597  Item* item = plTarget->StoreNewItem(dest, itemId, true, Item::GenerateItemRandomPropertyId(itemId));
2598 
2599  // remove binding (let GM give it to another player later)
2600  if (pl == plTarget)
2601  for (ItemPosCountVec::const_iterator itr = dest.begin(); itr != dest.end(); ++itr)
2602  if (Item* item1 = pl->GetItemByPos(itr->pos))
2603  item1->SetBinding(false);
2604 
2605  if (count > 0 && item)
2606  {
2607  pl->SendNewItem(item, count, false, true);
2608  if (pl != plTarget)
2609  plTarget->SendNewItem(item, count, true, false);
2610  }
2611 
2612  if (noSpaceForCount > 0)
2613  PSendSysMessage(LANG_ITEM_CANNOT_CREATE, itemId, noSpaceForCount);
2614 
2615  return true;
2616 }
2617 
2619 {
2620  if (!*args)
2621  return false;
2622 
2623  char* cId = extractKeyFromLink((char*)args, "Hitemset"); // number or [name] Shift-click form |color|Hitemset:itemset_id|h[name]|h|r
2624  if (!cId)
2625  return false;
2626 
2627  uint32 itemsetId = atol(cId);
2628 
2629  // prevent generation all items with itemset field value '0'
2630  if (itemsetId == 0)
2631  {
2633  SetSentErrorMessage(true);
2634  return false;
2635  }
2636 
2637  Player* pl = m_session->GetPlayer();
2638  Player* plTarget = getSelectedPlayer();
2639  if (!plTarget)
2640  plTarget = pl;
2641 
2642  sLog.outDetail(GetOregonString(LANG_ADDITEMSET), itemsetId);
2643 
2644  bool found = false;
2645  for (uint32 id = 0; id < sItemStorage.MaxEntry; id++)
2646  {
2647  ItemTemplate const* pProto = sItemStorage.LookupEntry<ItemTemplate>(id);
2648  if (!pProto)
2649  continue;
2650 
2651  if (pProto->ItemSet == itemsetId)
2652  {
2653  found = true;
2654  ItemPosCountVec dest;
2655  uint8 msg = plTarget->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, pProto->ItemId, 1);
2656  if (msg == EQUIP_ERR_OK)
2657  {
2658  Item* item = plTarget->StoreNewItem(dest, pProto->ItemId, true);
2659 
2660  // remove binding (let GM give it to another player later)
2661  if (pl == plTarget)
2662  item->SetBinding(false);
2663 
2664  pl->SendNewItem(item, 1, false, true);
2665  if (pl != plTarget)
2666  plTarget->SendNewItem(item, 1, true, false);
2667  }
2668  else
2669  {
2670  pl->SendEquipError(msg, NULL, NULL);
2672  }
2673  }
2674  }
2675 
2676  if (!found)
2677  {
2679 
2680  SetSentErrorMessage(true);
2681  return false;
2682  }
2683 
2684  return true;
2685 }
2686 
2688 {
2689  if (!*args)
2690  return false;
2691 
2692  char* cId = extractKeyFromLink((char*)args, "Hitem");
2693  if (!cId)
2694  return false;
2695 
2696  uint32 item_id = atol(cId);
2697  if (!item_id)
2698  {
2700  SetSentErrorMessage(true);
2701  return false;
2702  }
2703 
2704  ItemTemplate const* itemProto = sObjectMgr.GetItemTemplate(item_id);
2705  if (!itemProto)
2706  {
2708  SetSentErrorMessage(true);
2709  return false;
2710  }
2711 
2712  char* c_count = strtok(NULL, " ");
2713  int count = c_count ? atol(c_count) : 10;
2714 
2715  if (count < 0)
2716  return false;
2717 
2718  // inventory case
2719  uint32 inv_count = 0;
2720  QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM character_inventory WHERE item_template='%u'", item_id);
2721  if (result)
2722  inv_count = (*result)[0].GetUInt32();
2723 
2724  result = CharacterDatabase.PQuery(
2725  // 0 1 2 3 4 5
2726  "SELECT ci.item, cibag.slot AS bag, ci.slot, ci.guid, characters.account,characters.name "
2727  "FROM character_inventory AS ci LEFT JOIN character_inventory AS cibag ON (cibag.item=ci.bag),characters "
2728  "WHERE ci.item_template='%u' AND ci.guid = characters.guid LIMIT %u ",
2729  item_id, uint32(count));
2730 
2731  if (result)
2732  {
2733  do
2734  {
2735  Field* fields = result->Fetch();
2736  uint32 item_guid = fields[0].GetUInt32();
2737  uint32 item_bag = fields[1].GetUInt32();
2738  uint32 item_slot = fields[2].GetUInt32();
2739  uint32 owner_guid = fields[3].GetUInt32();
2740  uint32 owner_acc = fields[4].GetUInt32();
2741  std::string owner_name = fields[5].GetCppString();
2742 
2743  char const* item_pos = 0;
2744  if (Player::IsEquipmentPos(item_bag, item_slot))
2745  item_pos = "[equipped]";
2746  else if (Player::IsInventoryPos(item_bag, item_slot))
2747  item_pos = "[in inventory]";
2748  else if (Player::IsBankPos(item_bag, item_slot))
2749  item_pos = "[in bank]";
2750  else
2751  item_pos = "";
2752 
2754  item_guid, owner_name.c_str(), owner_guid, owner_acc, item_pos);
2755  }
2756  while (result->NextRow());
2757 
2758  int64 res_count = result->GetRowCount();
2759 
2760  if (count > res_count)
2761  count -= res_count;
2762  else if (count)
2763  count = 0;
2764  }
2765 
2766  // mail case
2767  uint32 mail_count = 0;
2768  result = CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM mail_items WHERE item_template='%u'", item_id);
2769  if (result)
2770  mail_count = (*result)[0].GetUInt32();
2771 
2772  if (count > 0)
2773  {
2774  result = CharacterDatabase.PQuery(
2775  // 0 1 2 3 4 5 6
2776  "SELECT mail_items.item_guid, mail.sender, mail.receiver, char_s.account, char_s.name, char_r.account, char_r.name "
2777  "FROM mail,mail_items,characters as char_s,characters as char_r "
2778  "WHERE mail_items.item_template='%u' AND char_s.guid = mail.sender AND char_r.guid = mail.receiver AND mail.id=mail_items.mail_id LIMIT %u",
2779  item_id, uint32(count));
2780  }
2781  else
2782  result = QueryResult_AutoPtr(NULL);
2783 
2784  if (result)
2785  {
2786  do
2787  {
2788  Field* fields = result->Fetch();
2789  uint32 item_guid = fields[0].GetUInt32();
2790  uint32 item_s = fields[1].GetUInt32();
2791  uint32 item_r = fields[2].GetUInt32();
2792  uint32 item_s_acc = fields[3].GetUInt32();
2793  std::string item_s_name = fields[4].GetCppString();
2794  uint32 item_r_acc = fields[5].GetUInt32();
2795  std::string item_r_name = fields[6].GetCppString();
2796 
2797  char const* item_pos = "[in mail]";
2798 
2800  item_guid, item_s_name.c_str(), item_s, item_s_acc, item_r_name.c_str(), item_r, item_r_acc, item_pos);
2801  }
2802  while (result->NextRow());
2803 
2804  int64 res_count = result->GetRowCount();
2805 
2806  if (count > res_count)
2807  count -= res_count;
2808  else if (count)
2809  count = 0;
2810  }
2811 
2812  // auction case
2813  uint32 auc_count = 0;
2814  result = CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM auctionhouse WHERE item_template='%u'", item_id);
2815  if (result)
2816  auc_count = (*result)[0].GetUInt32();
2817 
2818  if (count > 0)
2819  {
2820  result = CharacterDatabase.PQuery(
2821  // 0 1 2 3
2822  "SELECT auctionhouse.itemguid, auctionhouse.itemowner, characters.account, characters.name "
2823  "FROM auctionhouse,characters WHERE auctionhouse.item_template='%u' AND characters.guid = auctionhouse.itemowner LIMIT %u",
2824  item_id, uint32(count));
2825  }
2826  else
2827  result = QueryResult_AutoPtr(NULL);
2828 
2829  if (result)
2830  {
2831  do
2832  {
2833  Field* fields = result->Fetch();
2834  uint32 item_guid = fields[0].GetUInt32();
2835  uint32 owner = fields[1].GetUInt32();
2836  uint32 owner_acc = fields[2].GetUInt32();
2837  std::string owner_name = fields[3].GetCppString();
2838 
2839  char const* item_pos = "[in auction]";
2840 
2841  PSendSysMessage(LANG_ITEMLIST_AUCTION, item_guid, owner_name.c_str(), owner, owner_acc, item_pos);
2842  }
2843  while (result->NextRow());
2844  }
2845 
2846  // guild bank case
2847  uint32 guild_count = 0;
2848  result = CharacterDatabase.PQuery("SELECT COUNT(item_entry) FROM guild_bank_item WHERE item_entry='%u'", item_id);
2849  if (result)
2850  guild_count = (*result)[0].GetUInt32();
2851 
2852  result = CharacterDatabase.PQuery(
2853  // 0 1 2
2854  "SELECT gi.item_guid, gi.guildid, guild.name "
2855  "FROM guild_bank_item AS gi, guild WHERE gi.item_entry='%u' AND gi.guildid = guild.guildid LIMIT %u ",
2856  item_id, uint32(count));
2857 
2858  if (result)
2859  {
2860  do
2861  {
2862  Field* fields = result->Fetch();
2863  uint32 item_guid = fields[0].GetUInt32();
2864  uint32 guild_guid = fields[1].GetUInt32();
2865  std::string guild_name = fields[2].GetCppString();
2866 
2867  char const* item_pos = "[in guild bank]";
2868 
2869  PSendSysMessage(LANG_ITEMLIST_GUILD, item_guid, guild_name.c_str(), guild_guid, item_pos);
2870  }
2871  while (result->NextRow());
2872 
2873  int64 res_count = result->GetRowCount();
2874 
2875  if (count > res_count)
2876  count -= res_count;
2877  else if (count)
2878  count = 0;
2879  }
2880 
2881  if (inv_count + mail_count + auc_count + guild_count == 0)
2882  {
2884  SetSentErrorMessage(true);
2885  return false;
2886  }
2887 
2888  PSendSysMessage(LANG_COMMAND_LISTITEMMESSAGE, item_id, inv_count + mail_count + auc_count + guild_count, inv_count, mail_count, auc_count, guild_count);
2889 
2890  return true;
2891 }
2892 
2894 {
2895  if (!*args)
2896  return false;
2897 
2898  // number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
2899  char* cId = extractKeyFromLink((char*)args, "Hgameobject_entry");
2900  if (!cId)
2901  return false;
2902 
2903  uint32 go_id = atol(cId);
2904  if (!go_id)
2905  {
2907  SetSentErrorMessage(true);
2908  return false;
2909  }
2910 
2911  GameObjectInfo const* gInfo = sObjectMgr.GetGameObjectInfo(go_id);
2912  if (!gInfo)
2913  {
2915  SetSentErrorMessage(true);
2916  return false;
2917  }
2918 
2919  char* c_count = strtok(NULL, " ");
2920  int count = c_count ? atol(c_count) : 10;
2921 
2922  if (count < 0)
2923  return false;
2924 
2925  uint32 obj_count = 0;
2926  QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT COUNT(guid) FROM gameobject WHERE id='%u'", go_id);
2927  if (result)
2928  obj_count = (*result)[0].GetUInt32();
2929 
2930  if (m_session)
2931  {
2932  Player* pl = m_session->GetPlayer();
2933  result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map, id, (POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) AS order_ FROM gameobject WHERE id = '%u' ORDER BY order_ ASC LIMIT %u",
2934  pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(), go_id, uint32(count));
2935  }
2936  else
2937  result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map, id FROM gameobject WHERE id = '%u' LIMIT %u",
2938  go_id, uint32(count));
2939 
2940  if (result)
2941  {
2942  do
2943  {
2944  Field* fields = result->Fetch();
2945  uint32 guid = fields[0].GetUInt32();
2946  float x = fields[1].GetFloat();
2947  float y = fields[2].GetFloat();
2948  float z = fields[3].GetFloat();
2949  int mapid = fields[4].GetUInt16();
2950  uint32 entry = fields[5].GetUInt32();
2951 
2952  if (m_session)
2953  PSendSysMessage(LANG_GO_LIST_CHAT, guid, entry, guid, gInfo->name, x, y, z, mapid);
2954  else
2955  PSendSysMessage(LANG_GO_LIST_CONSOLE, guid, gInfo->name, x, y, z, mapid);
2956  }
2957  while (result->NextRow());
2958  }
2959 
2960  PSendSysMessage(LANG_COMMAND_LISTOBJMESSAGE, go_id, obj_count);
2961  return true;
2962 }
2963 
2965 {
2966  float distance = (!*args) ? 10 : atol(args);
2967  uint32 count = 0;
2968 
2969  Player* pl = m_session->GetPlayer();
2970  QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT guid, id, position_x, position_y, position_z, map, "
2971  "(POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) AS order_ "
2972  "FROM gameobject WHERE map='%u' AND (POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) <= '%f' ORDER BY order_",
2973  pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(),
2974  pl->GetMapId(), pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(), distance * distance);
2975 
2976  if (result)
2977  {
2978  do
2979  {
2980  Field* fields = result->Fetch();
2981  uint32 guid = fields[0].GetUInt32();
2982  uint32 entry = fields[1].GetUInt32();
2983  float x = fields[2].GetFloat();
2984  float y = fields[3].GetFloat();
2985  float z = fields[4].GetFloat();
2986  int mapid = fields[5].GetUInt16();
2987 
2988  GameObjectInfo const* gInfo = sObjectMgr.GetGameObjectInfo(entry);
2989 
2990  if (!gInfo)
2991  continue;
2992 
2993  PSendSysMessage(LANG_GO_LIST_CHAT, guid, entry, guid, gInfo->name, x, y, z, mapid);
2994 
2995  ++count;
2996  }
2997  while (result->NextRow());
2998  }
2999 
3000  PSendSysMessage(LANG_COMMAND_NEAROBJMESSAGE, distance, count);
3001  return true;
3002 }
3003 
3005 {
3006  // number or [name] Shift-click form |color|Hgameobject:go_id|h[name]|h|r
3007  char* cId = extractKeyFromLink((char*)args, "Hgameobject");
3008  if (!cId)
3009  return false;
3010 
3011  uint32 lowguid = atoi(cId);
3012  if (!lowguid)
3013  return false;
3014 
3015  GameObject* gobj = NULL;
3016 
3017  if (GameObjectData const* goData = sObjectMgr.GetGOData(lowguid))
3018  gobj = GetObjectGlobalyWithGuidOrNearWithDbGuid(lowguid, goData->id);
3019 
3020  if (!gobj)
3021  {
3023  SetSentErrorMessage(true);
3024  return false;
3025  }
3026 
3027  char* cstate = strtok(NULL, " ");
3028  if (!cstate)
3029  return false;
3030 
3031  int32 state = atoi(cstate);
3032  if (state < 0)
3033  gobj->SendObjectDeSpawnAnim(gobj->GetGUID());
3034  else
3035  gobj->SetGoState((GOState)state);
3036 
3037  return true;
3038 
3039  return true;
3040 }
3041 
3043 {
3044  if (!*args)
3045  return false;
3046 
3047  // number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r
3048  char* cId = extractKeyFromLink((char*)args, "Hcreature_entry");
3049  if (!cId)
3050  return false;
3051 
3052  uint32 cr_id = atol(cId);
3053  if (!cr_id)
3054  {
3056  SetSentErrorMessage(true);
3057  return false;
3058  }
3059 
3060  CreatureInfo const* cInfo = sObjectMgr.GetCreatureTemplate(cr_id);
3061  if (!cInfo)
3062  {
3064  SetSentErrorMessage(true);
3065  return false;
3066  }
3067 
3068  char* c_count = strtok(NULL, " ");
3069  int count = c_count ? atol(c_count) : 10;
3070 
3071  if (count < 0)
3072  return false;
3073 
3074  uint32 cr_count = 0;
3075  QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT COUNT(guid) FROM creature WHERE id='%u'", cr_id);
3076  if (result)
3077  cr_count = (*result)[0].GetUInt32();
3078 
3079  if (m_session)
3080  {
3081  Player* pl = m_session->GetPlayer();
3082  result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map, (POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) AS order_ FROM creature WHERE id = '%u' ORDER BY order_ ASC LIMIT %u",
3083  pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(), cr_id, uint32(count));
3084  }
3085  else
3086  result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map FROM creature WHERE id = '%u' LIMIT %u",
3087  cr_id, uint32(count));
3088 
3089  if (result)
3090  {
3091  do
3092  {
3093  Field* fields = result->Fetch();
3094  uint32 guid = fields[0].GetUInt32();
3095  float x = fields[1].GetFloat();
3096  float y = fields[2].GetFloat();
3097  float z = fields[3].GetFloat();
3098  int mapid = fields[4].GetUInt16();
3099 
3100  if (m_session)
3101  PSendSysMessage(LANG_CREATURE_LIST_CHAT, guid, guid, cInfo->Name, x, y, z, mapid);
3102  else
3103  PSendSysMessage(LANG_CREATURE_LIST_CONSOLE, guid, cInfo->Name, x, y, z, mapid);
3104  }
3105  while (result->NextRow());
3106  }
3107 
3109  return true;
3110 }
3111 
3113 {
3114  if (!*args)
3115  return false;
3116 
3117  std::string namepart = args;
3118  std::wstring wnamepart;
3119 
3120  // converting string that we try to find to lower case
3121  if (!Utf8toWStr(namepart, wnamepart))
3122  return false;
3123 
3124  wstrToLower(wnamepart);
3125 
3126  bool found = false;
3127  uint32 count = 0;
3128  uint32 maxResults = sWorld.getConfig(CONFIG_MAX_RESULTS_LOOKUP_COMMANDS);
3129 
3130  // Search in item_template
3131  for (uint32 id = 0; id < sItemStorage.MaxEntry; id++)
3132  {
3133  ItemTemplate const* pProto = sItemStorage.LookupEntry<ItemTemplate >(id);
3134  if (!pProto)
3135  continue;
3136 
3137  int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : sObjectMgr.GetDBCLocaleIndex();
3138  if (loc_idx >= 0)
3139  {
3140  ItemLocale const* il = sObjectMgr.GetItemLocale(pProto->ItemId);
3141  if (il)
3142  {
3143  if (il->Name.size() > uint32(loc_idx) && !il->Name[loc_idx].empty())
3144  {
3145  std::string name = il->Name[loc_idx];
3146 
3147  if (Utf8FitTo(name, wnamepart))
3148  {
3149  if (maxResults && count++ == maxResults)
3150  {
3152  return true;
3153  }
3154 
3155  if (m_session)
3156  PSendSysMessage(LANG_ITEM_LIST_CHAT, id, id, name.c_str());
3157  else
3158  PSendSysMessage(LANG_ITEM_LIST_CONSOLE, id, name.c_str());
3159 
3160  if (!found)
3161  found = true;
3162 
3163  continue;
3164  }
3165  }
3166  }
3167  }
3168 
3169  std::string name = pProto->Name1;
3170  if (name.empty())
3171  continue;
3172 
3173  if (Utf8FitTo(name, wnamepart))
3174  {
3175  if (maxResults && count++ == maxResults)
3176  {
3178  return true;
3179  }
3180 
3181  if (m_session)
3182  PSendSysMessage(LANG_ITEM_LIST_CHAT, id, id, name.c_str());
3183  else
3184  PSendSysMessage(LANG_ITEM_LIST_CONSOLE, id, name.c_str());
3185 
3186  if (!found)
3187  found = true;
3188  }
3189  }
3190 
3191  if (!found)
3193 
3194  return true;
3195 }
3196 
3198 {
3199  if (!*args)
3200  return false;
3201 
3202  std::string namepart = args;
3203  std::wstring wnamepart;
3204 
3205  if (!Utf8toWStr(namepart, wnamepart))
3206  return false;
3207 
3208  // converting string that we try to find to lower case
3209  wstrToLower(wnamepart);
3210 
3211  bool found = false;
3212  uint32 count = 0;
3213  uint32 maxResults = sWorld.getConfig(CONFIG_MAX_RESULTS_LOOKUP_COMMANDS);
3214 
3215  // Search in ItemSet.dbc
3216  for (uint32 id = 0; id < sItemSetStore.GetNumRows(); id++)
3217  {
3218  ItemSetEntry const* set = sItemSetStore.LookupEntry(id);
3219  if (set)
3220  {
3221  int loc = m_session ? int(m_session->GetSessionDbcLocale()) : sWorld.GetDefaultDbcLocale();
3222  std::string name = set->name[loc];
3223  if (name.empty())
3224  continue;
3225 
3226  if (!Utf8FitTo(name, wnamepart))
3227  {
3228  loc = 0;
3229  for (; loc < MAX_LOCALE; ++loc)
3230  {
3231  if (m_session && loc == m_session->GetSessionDbcLocale())
3232  continue;
3233 
3234  name = set->name[loc];
3235  if (name.empty())
3236  continue;
3237 
3238  if (Utf8FitTo(name, wnamepart))
3239  break;
3240  }
3241  }
3242 
3243  if (loc < MAX_LOCALE)
3244  {
3245  if (maxResults && count++ == maxResults)
3246  {
3248  return true;
3249  }
3250 
3251  // send item set in "id - [namedlink locale]" format
3252  if (m_session)
3253  PSendSysMessage(LANG_ITEMSET_LIST_CHAT, id, id, name.c_str(), localeNames[loc]);
3254  else
3255  PSendSysMessage(LANG_ITEMSET_LIST_CONSOLE, id, name.c_str(), localeNames[loc]);
3256 
3257  if (!found)
3258  found = true;
3259  }
3260  }
3261  }
3262  if (!found)
3264  return true;
3265 }
3266 
3268 {
3269  if (!*args)
3270  return false;
3271 
3272  // can be NULL in console call
3273  Player* target = getSelectedPlayerOrSelf();
3274 
3275  std::string namepart = args;
3276  std::wstring wnamepart;
3277 
3278  if (!Utf8toWStr(namepart, wnamepart))
3279  return false;
3280 
3281  // converting string that we try to find to lower case
3282  wstrToLower(wnamepart);
3283 
3284  bool found = false;
3285  uint32 count = 0;
3286  uint32 maxResults = sWorld.getConfig(CONFIG_MAX_RESULTS_LOOKUP_COMMANDS);
3287 
3288  // Search in SkillLine.dbc
3289  for (uint32 id = 0; id < sSkillLineStore.GetNumRows(); id++)
3290  {
3291  SkillLineEntry const* skillInfo = sSkillLineStore.LookupEntry(id);
3292  if (skillInfo)
3293  {
3294  int loc = m_session ? int(m_session->GetSessionDbcLocale()) : sWorld.GetDefaultDbcLocale();
3295  std::string name = skillInfo->name[loc];
3296  if (name.empty())
3297  continue;
3298 
3299  if (!Utf8FitTo(name, wnamepart))
3300  {
3301  loc = 0;
3302  for (; loc < MAX_LOCALE; ++loc)
3303  {
3304  if (m_session && loc == m_session->GetSessionDbcLocale())
3305  continue;
3306 
3307  name = skillInfo->name[loc];
3308  if (name.empty())
3309  continue;
3310 
3311  if (Utf8FitTo(name, wnamepart))
3312  break;
3313  }
3314  }
3315 
3316  if (loc < MAX_LOCALE)
3317  {
3318  if (maxResults && count++ == maxResults)
3319  {
3321  return true;
3322  }
3323 
3324  char const* knownStr = "";
3325  if (target && target->HasSkill(id))
3326  knownStr = GetOregonString(LANG_KNOWN);
3327 
3328  // send skill in "id - [namedlink locale]" format
3329  if (m_session)
3330  PSendSysMessage(LANG_SKILL_LIST_CHAT, id, id, name.c_str(), localeNames[loc], knownStr);
3331  else
3332  PSendSysMessage(LANG_SKILL_LIST_CONSOLE, id, name.c_str(), localeNames[loc], knownStr);
3333 
3334  if (!found)
3335  found = true;
3336  }
3337  }
3338  }
3339  if (!found)
3341  return true;
3342 }
3343 
3345 {
3346  if (!*args)
3347  return false;
3348 
3349  // can be NULL at console call
3350  Player* target = getSelectedPlayer();
3351 
3352  std::string namepart = args;
3353  std::wstring wnamepart;
3354 
3355  if (!Utf8toWStr(namepart, wnamepart))
3356  return false;
3357 
3358  // converting string that we try to find to lower case
3359  wstrToLower(wnamepart);
3360 
3361  bool found = false;
3362  uint32 count = 0;
3363  uint32 maxResults = sWorld.getConfig(CONFIG_MAX_RESULTS_LOOKUP_COMMANDS);
3364 
3365  // Search in Spell.dbc
3366  for (uint32 id = 0; id < sSpellStore.GetNumRows(); id++)
3367  {
3368  SpellEntry const* spellInfo = sSpellStore.LookupEntry(id);
3369  if (spellInfo)
3370  {
3371  int loc = m_session ? int(m_session->GetSessionDbcLocale()) : sWorld.GetDefaultDbcLocale();
3372  std::string name = spellInfo->SpellName[loc];
3373  if (name.empty())
3374  continue;
3375 
3376  if (!Utf8FitTo(name, wnamepart))
3377  {
3378  loc = 0;
3379  for (; loc < MAX_LOCALE; ++loc)
3380  {
3381  if (m_session && loc == m_session->GetSessionDbcLocale())
3382  continue;
3383 
3384  name = spellInfo->SpellName[loc];
3385  if (name.empty())
3386  continue;
3387 
3388  if (Utf8FitTo(name, wnamepart))
3389  break;
3390  }
3391  }
3392 
3393  if (loc < MAX_LOCALE)
3394  {
3395  if (maxResults && count++ == maxResults)
3396  {
3398  return true;
3399  }
3400 
3401  bool known = target && target->HasSpell(id);
3402  bool learn = (spellInfo->Effect[0] == SPELL_EFFECT_LEARN_SPELL);
3403 
3404  uint32 talentCost = GetTalentSpellCost(id);
3405 
3406  bool talent = (talentCost > 0);
3407  bool passive = IsPassiveSpell(id);
3408  bool active = target && (target->HasAura(id, 0) || target->HasAura(id, 1) || target->HasAura(id, 2));
3409 
3410  // unit32 used to prevent interpreting uint8 as char at output
3411  // find rank of learned spell for learning spell, or talent rank
3412  uint32 rank = talentCost ? talentCost : sSpellMgr.GetSpellRank(learn ? spellInfo->EffectTriggerSpell[0] : id);
3413 
3414  // send spell in "id - [name, rank N] [talent] [passive] [learn] [known]" format
3415  std::ostringstream ss;
3416  if (m_session)
3417  ss << id << " - |cffffffff|Hspell:" << id << "|h[" << name;
3418  else
3419  ss << id << " - " << name;
3420 
3421  // include rank in link name
3422  if (rank)
3423  ss << GetOregonString(LANG_SPELL_RANK) << rank;
3424 
3425  if (m_session)
3426  ss << " " << localeNames[loc] << "]|h|r";
3427  else
3428  ss << " " << localeNames[loc];
3429 
3430  if (talent)
3432  if (passive)
3434  if (learn)
3435  ss << GetOregonString(LANG_LEARN);
3436  if (known)
3437  ss << GetOregonString(LANG_KNOWN);
3438  if (active)
3440 
3441  SendSysMessage(ss.str().c_str());
3442 
3443  if (!found)
3444  found = true;
3445  }
3446  }
3447  }
3448  if (!found)
3450  return true;
3451 }
3452 
3454 {
3455  if (!*args)
3456  return false;
3457 
3458  // can be NULL at console call
3459  Player* target = getSelectedPlayer();
3460 
3461  std::string namepart = args;
3462  std::wstring wnamepart;
3463 
3464  // converting string that we try to find to lower case
3465  if (!Utf8toWStr(namepart, wnamepart))
3466  return false;
3467 
3468  wstrToLower(wnamepart);
3469 
3470  bool found = false;
3471  uint32 count = 0;
3472  uint32 maxResults = sWorld.getConfig(CONFIG_MAX_RESULTS_LOOKUP_COMMANDS);
3473 
3474  ObjectMgr::QuestMap const& qTemplates = sObjectMgr.GetQuestTemplates();
3475  for (ObjectMgr::QuestMap::const_iterator iter = qTemplates.begin(); iter != qTemplates.end(); ++iter)
3476  {
3477  Quest* qinfo = iter->second;
3478 
3479  int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : sObjectMgr.GetDBCLocaleIndex();
3480  if (loc_idx >= 0)
3481  {
3482  QuestLocale const* il = sObjectMgr.GetQuestLocale(qinfo->GetQuestId());
3483  if (il)
3484  {
3485  if (il->Title.size() > uint32(loc_idx) && !il->Title[loc_idx].empty())
3486  {
3487  std::string title = il->Title[loc_idx];
3488 
3489  if (Utf8FitTo(title, wnamepart))
3490  {
3491  if (maxResults && count++ == maxResults)
3492  {
3494  return true;
3495  }
3496 
3497  char const* statusStr = "";
3498 
3499  if (target)
3500  {
3501  QuestStatus status = target->GetQuestStatus(qinfo->GetQuestId());
3502 
3503  if (status == QUEST_STATUS_COMPLETE)
3504  {
3505  if (target->GetQuestRewardStatus(qinfo->GetQuestId()))
3507  else
3509  }
3510  else if (status == QUEST_STATUS_INCOMPLETE)
3512  }
3513 
3514  if (m_session)
3515  PSendSysMessage(LANG_QUEST_LIST_CHAT, qinfo->GetQuestId(), qinfo->GetQuestId(), title.c_str(), statusStr);
3516  else
3517  PSendSysMessage(LANG_QUEST_LIST_CONSOLE, qinfo->GetQuestId(), title.c_str(), statusStr);
3518 
3519  if (!found)
3520  found = true;
3521 
3522  continue;
3523  }
3524  }
3525  }
3526  }
3527 
3528  std::string title = qinfo->GetTitle();
3529  if (title.empty())
3530  continue;
3531 
3532  if (Utf8FitTo(title, wnamepart))
3533  {
3534  if (maxResults && count++ == maxResults)
3535  {
3537  return true;
3538  }
3539 
3540  char const* statusStr = "";
3541 
3542  if (target)
3543  {
3544  QuestStatus status = target->GetQuestStatus(qinfo->GetQuestId());
3545 
3546  if (status == QUEST_STATUS_COMPLETE)
3547  {
3548  if (target->GetQuestRewardStatus(qinfo->GetQuestId()))
3550  else
3552  }
3553  else if (status == QUEST_STATUS_INCOMPLETE)
3555  }
3556 
3557  if (m_session)
3558  PSendSysMessage(LANG_QUEST_LIST_CHAT, qinfo->GetQuestId(), qinfo->GetQuestId(), title.c_str(), statusStr);
3559  else
3560  PSendSysMessage(LANG_QUEST_LIST_CONSOLE, qinfo->GetQuestId(), title.c_str(), statusStr);
3561 
3562  if (!found)
3563  found = true;
3564  }
3565  }
3566 
3567  if (!found)
3569 
3570  return true;
3571 }
3572 
3574 {
3575  if (!*args)
3576  return false;
3577 
3578  std::string namepart = args;
3579  std::wstring wnamepart;
3580 
3581  // converting string that we try to find to lower case
3582  if (!Utf8toWStr (namepart, wnamepart))
3583  return false;
3584 
3585  wstrToLower (wnamepart);
3586 
3587  bool found = false;
3588  uint32 count = 0;
3589  uint32 maxResults = sWorld.getConfig(CONFIG_MAX_RESULTS_LOOKUP_COMMANDS);
3590 
3591  for (uint32 id = 0; id < sCreatureStorage.MaxEntry; ++id)
3592  {
3594  if (!cInfo)
3595  continue;
3596 
3597  int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : sObjectMgr.GetDBCLocaleIndex();
3598  if (loc_idx >= 0)
3599  {
3600  CreatureLocale const* cl = sObjectMgr.GetCreatureLocale (id);
3601  if (cl)
3602  {
3603  if (cl->Name.size() > uint32(loc_idx) && !cl->Name[loc_idx].empty ())
3604  {
3605  std::string name = cl->Name[loc_idx];
3606 
3607  if (Utf8FitTo (name, wnamepart))
3608  {
3609  if (maxResults && count++ == maxResults)
3610  {
3612  return true;
3613  }
3614 
3615  if (m_session)
3616  PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT, id, id, name.c_str ());
3617  else
3619 
3620  if (!found)
3621  found = true;
3622 
3623  continue;
3624  }
3625  }
3626  }
3627  }
3628 
3629  std::string name = cInfo->Name;
3630  if (name.empty ())
3631  continue;
3632 
3633  if (Utf8FitTo(name, wnamepart))
3634  {
3635  if (maxResults && count++ == maxResults)
3636  {
3638  return true;
3639  }
3640 
3641  if (m_session)
3642  PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT, id, id, name.c_str ());
3643  else
3645 
3646  if (!found)
3647  found = true;
3648  }
3649  }
3650 
3651  if (!found)
3653 
3654  return true;
3655 }
3656 
3658 {
3659  if (!*args)
3660  return false;
3661 
3662  std::string namepart = args;
3663  std::wstring wnamepart;
3664 
3665  // converting string that we try to find to lower case
3666  if (!Utf8toWStr(namepart, wnamepart))
3667  return false;
3668 
3669  wstrToLower(wnamepart);
3670 
3671  bool found = false;
3672  uint32 count = 0;
3673  uint32 maxResults = sWorld.getConfig(CONFIG_MAX_RESULTS_LOOKUP_COMMANDS);
3674 
3675  for (uint32 id = 0; id < sGOStorage.MaxEntry; id++)
3676  {
3678  if (!gInfo)
3679  continue;
3680 
3681  int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : sObjectMgr.GetDBCLocaleIndex();
3682  if (loc_idx >= 0)
3683  {
3684  GameObjectLocale const* gl = sObjectMgr.GetGameObjectLocale(id);
3685  if (gl)
3686  {
3687  if (gl->Name.size() > uint32(loc_idx) && !gl->Name[loc_idx].empty())
3688  {
3689  std::string name = gl->Name[loc_idx];
3690 
3691  if (Utf8FitTo(name, wnamepart))
3692  {
3693  if (maxResults && count++ == maxResults)
3694  {
3696  return true;
3697  }
3698 
3699  if (m_session)
3700  PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT, id, id, name.c_str());
3701  else
3702  PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE, id, name.c_str());
3703 
3704  if (!found)
3705  found = true;
3706 
3707  continue;
3708  }
3709  }
3710  }
3711  }
3712 
3713  std::string name = gInfo->name;
3714  if (name.empty())
3715  continue;
3716 
3717  if (Utf8FitTo(name, wnamepart))
3718  {
3719  if (maxResults && count++ == maxResults)
3720  {
3722  return true;
3723  }
3724 
3725  if (m_session)
3726  PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT, id, id, name.c_str());
3727  else
3728  PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE, id, name.c_str());
3729 
3730  if (!found)
3731  found = true;
3732  }
3733  }
3734 
3735  if (!found)
3737 
3738  return true;
3739 }
3740 
3750 {
3751  if (!*args)
3752  return false;
3753 
3754  char* lname = strtok ((char*)args, " ");
3755  char* gname = strtok (NULL, "");
3756 
3757  if (!lname)
3758  return false;
3759 
3760  if (!gname)
3761  {
3763  SetSentErrorMessage (true);
3764  return false;
3765  }
3766 
3767  std::string guildname = gname;
3768 
3769  Player* player = ObjectAccessor::Instance ().FindPlayerByName (lname);
3770  if (!player)
3771  {
3773  SetSentErrorMessage (true);
3774  return false;
3775  }
3776 
3777  if (player->GetGuildId())
3778  {
3780  return true;
3781  }
3782 
3783  Guild* guild = new Guild;
3784  if (!guild->Create(player, guildname))
3785  {
3786  delete guild;
3788  SetSentErrorMessage (true);
3789  return false;
3790  }
3791 
3792  sObjectMgr.AddGuild (guild);
3793  return true;
3794 }
3795 
3797 {
3798  if (!*args)
3799  return false;
3800 
3801  char* par1 = strtok ((char*)args, " ");
3802  char* par2 = strtok (NULL, "");
3803  if (!par1 || !par2)
3804  return false;
3805 
3806  std::string glName = par2;
3807  Guild* targetGuild = sObjectMgr.GetGuildByName (glName);
3808  if (!targetGuild)
3809  return false;
3810 
3811  std::string plName = par1;
3812  if (!normalizePlayerName (plName))
3813  {
3815  SetSentErrorMessage (true);
3816  return false;
3817  }
3818 
3819  uint64 plGuid = 0;
3820  if (Player* targetPlayer = ObjectAccessor::Instance ().FindPlayerByName (plName.c_str ()))
3821  plGuid = targetPlayer->GetGUID ();
3822  else
3823  plGuid = sObjectMgr.GetPlayerGUIDByName (plName.c_str ());
3824 
3825  if (!plGuid)
3826  return false;
3827 
3828  // player's guild membership checked in AddMember before add
3829  if (!targetGuild->AddMember (plGuid, targetGuild->GetLowestRank ()))
3830  return false;
3831 
3832  return true;
3833 }
3834 
3836 {
3837  if (!*args)
3838  return false;
3839 
3840  char* par1 = strtok ((char*)args, " ");
3841  if (!par1)
3842  return false;
3843 
3844  std::string plName = par1;
3845  if (!normalizePlayerName (plName))
3846  {
3848  SetSentErrorMessage (true);
3849  return false;
3850  }
3851 
3852  uint64 plGuid = 0;
3853  uint32 glId = 0;
3854  if (Player* targetPlayer = ObjectAccessor::Instance ().FindPlayerByName (plName.c_str ()))
3855  {
3856  plGuid = targetPlayer->GetGUID ();
3857  glId = targetPlayer->GetGuildId ();
3858  }
3859  else
3860  {
3861  plGuid = sObjectMgr.GetPlayerGUIDByName (plName.c_str ());
3862  glId = Player::GetGuildIdFromDB (plGuid);
3863  }
3864 
3865  if (!plGuid || !glId)
3866  return false;
3867 
3868  Guild* targetGuild = sObjectMgr.GetGuildById (glId);
3869  if (!targetGuild)
3870  return false;
3871 
3872  targetGuild->DelMember (plGuid);
3873  return true;
3874 }
3875 
3877 {
3878  if (!*args)
3879  return false;
3880 
3881  char* par1 = strtok ((char*)args, " ");
3882  char* par2 = strtok (NULL, " ");
3883  if (!par1 || !par2)
3884  return false;
3885  std::string plName = par1;
3886  if (!normalizePlayerName (plName))
3887  {
3889  SetSentErrorMessage (true);
3890  return false;
3891  }
3892 
3893  uint64 plGuid = 0;
3894  uint32 glId = 0;
3895  if (Player* targetPlayer = ObjectAccessor::Instance ().FindPlayerByName (plName.c_str ()))
3896  {
3897  plGuid = targetPlayer->GetGUID ();
3898  glId = targetPlayer->GetGuildId ();
3899  }
3900  else
3901  {
3902  plGuid = sObjectMgr.GetPlayerGUIDByName (plName.c_str ());
3903  glId = Player::GetGuildIdFromDB (plGuid);
3904  }
3905 
3906  if (!plGuid || !glId)
3907  return false;
3908 
3909  Guild* targetGuild = sObjectMgr.GetGuildById (glId);
3910  if (!targetGuild)
3911  return false;
3912 
3913  uint32 newrank = uint32 (atoi (par2));
3914  if (newrank > targetGuild->GetLowestRank ())
3915  return false;
3916 
3917  targetGuild->ChangeRank (plGuid, newrank);
3918  return true;
3919 }
3920 
3922 {
3923  if (!*args)
3924  return false;
3925 
3926  char* par1 = strtok ((char*)args, " ");
3927  if (!par1)
3928  return false;
3929 
3930  std::string gld = par1;
3931 
3932  Guild* targetGuild = sObjectMgr.GetGuildByName (gld);
3933  if (!targetGuild)
3934  return false;
3935 
3936  targetGuild->Disband();
3937  delete targetGuild;
3938 
3939  return true;
3940 }
3941 
3942 bool ChatHandler::HandleGetDistanceCommand(const char* /*args*/)
3943 {
3944  Unit* pUnit = getSelectedUnit();
3945 
3946  if (!pUnit)
3947  {
3949  SetSentErrorMessage(true);
3950  return false;
3951  }
3952 
3954 
3955  return true;
3956 }
3957 
3958 // FIX-ME!!!
3959 
3960 bool ChatHandler::HandleAddWeaponCommand(const char* /*args*/)
3961 {
3962  /*if (!*args)
3963  return false;
3964 
3965  uint64 guid = m_session->GetPlayer()->GetSelection();
3966  if (guid == 0)
3967  {
3968  SendSysMessage(LANG_NO_SELECTION);
3969  return true;
3970  }
3971 
3972  Creature* pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(), guid);
3973 
3974  if (!pCreature)
3975  {
3976  SendSysMessage(LANG_SELECT_CREATURE);
3977  return true;
3978  }
3979 
3980  char* pSlotID = strtok((char*)args, " ");
3981  if (!pSlotID)
3982  return false;
3983 
3984  char* pItemID = strtok(NULL, " ");
3985  if (!pItemID)
3986  return false;
3987 
3988  uint32 ItemID = atoi(pItemID);
3989  uint32 SlotID = atoi(pSlotID);
3990 
3991  ItemTemplate* tmpItem = sObjectMgr.GetItemTemplate(ItemID);
3992 
3993  bool added = false;
3994  if (tmpItem)
3995  {
3996  switch(SlotID)
3997  {
3998  case 1:
3999  pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY, ItemID);
4000  added = true;
4001  break;
4002  case 2:
4003  pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_01, ItemID);
4004  added = true;
4005  break;
4006  case 3:
4007  pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_02, ItemID);
4008  added = true;
4009  break;
4010  default:
4011  PSendSysMessage(LANG_ITEM_SLOT_NOT_EXIST,SlotID);
4012  added = false;
4013  break;
4014  }
4015  if (added)
4016  {
4017  PSendSysMessage(LANG_ITEM_ADDED_TO_SLOT,ItemID,tmpItem->Name1,SlotID);
4018  }
4019  }
4020  else
4021  {
4022  PSendSysMessage(LANG_ITEM_NOT_FOUND,ItemID);
4023  return true;
4024  }
4025  */
4026  return true;
4027 }
4028 
4029 bool ChatHandler::HandleDieCommand(const char* /*args*/)
4030 {
4031  Unit* target = getSelectedUnit();
4032 
4033  if (!target || !m_session->GetPlayer()->GetSelection())
4034  {
4036  SetSentErrorMessage(true);
4037  return false;
4038  }
4039 
4040  if (target->IsAlive())
4041  {
4042  if (sWorld.getConfig(CONFIG_DIE_COMMAND_MODE))
4043  target->CastSpell(target, SPELL_SUICIDE, true);
4044  else
4045  m_session->GetPlayer()->CastSpell(target, SPELL_DEATH_TOUCH, true);
4046  }
4047 
4048  return true;
4049 }
4050 
4051 bool ChatHandler::HandleDamageCommand(const char* args)
4052 {
4053  if (!*args)
4054  return false;
4055 
4056  Unit* target = getSelectedUnit();
4057 
4058  if (!target || !m_session->GetPlayer()->GetSelection())
4059  {
4061  SetSentErrorMessage(true);
4062  return false;
4063  }
4064 
4065  if (!target->IsAlive())
4066  return true;
4067 
4068  char* damageStr = strtok((char*)args, " ");
4069  if (!damageStr)
4070  return false;
4071 
4072  int32 damage = atoi((char*)damageStr);
4073  if (damage <= 0)
4074  return true;
4075 
4076  char* schoolStr = strtok((char*)NULL, " ");
4077 
4078  // flat melee damage without resistence/etc reduction
4079  if (!schoolStr)
4080  {
4081  m_session->GetPlayer()->DealDamage(target, damage, NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
4083  return true;
4084  }
4085 
4086  uint32 school = schoolStr ? atoi((char*)schoolStr) : SPELL_SCHOOL_NORMAL;
4087  if (school >= MAX_SPELL_SCHOOL)
4088  return false;
4089 
4090  SpellSchoolMask schoolmask = SpellSchoolMask(1 << school);
4091 
4092  if (schoolmask & SPELL_SCHOOL_MASK_NORMAL)
4093  damage = m_session->GetPlayer()->CalcArmorReducedDamage(target, damage);
4094 
4095  char* spellStr = strtok((char*)NULL, " ");
4096 
4097  // melee damage by specific school
4098  if (!spellStr)
4099  {
4100  uint32 absorb = 0;
4101  uint32 resist = 0;
4102 
4103  m_session->GetPlayer()->CalcAbsorbResist(target, schoolmask, SPELL_DIRECT_DAMAGE, damage, &absorb, &resist);
4104 
4105  if (damage <= int32(absorb + resist))
4106  return true;
4107 
4108  damage -= absorb + resist;
4109 
4110  m_session->GetPlayer()->DealDamage(target, damage, NULL, DIRECT_DAMAGE, schoolmask, NULL, false);
4111  m_session->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2, target, 1, schoolmask, damage, absorb, resist, VICTIMSTATE_NORMAL, 0);
4112  return true;
4113  }
4114 
4115  // non-melee damage
4116 
4117  // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
4118  uint32 spellid = extractSpellIdFromLink((char*)args);
4119  if (!spellid || !sSpellStore.LookupEntry(spellid))
4120  return false;
4121 
4122  m_session->GetPlayer()->SpellNonMeleeDamageLog(target, spellid, damage, false);
4123  return true;
4124 }
4125 
4127 {
4128  if (!*args)
4129  return false;
4130 
4131  Player* target = getSelectedPlayer();
4132  if (!target)
4133  {
4135  SetSentErrorMessage(true);
4136  return false;
4137  }
4138 
4139  int32 amount = (uint32)atoi(args);
4140 
4141  target->ModifyArenaPoints(amount);
4142 
4144 
4145  return true;
4146 }
4147 
4148 bool ChatHandler::HandleReviveCommand(const char* args)
4149 {
4150  Player* player = NULL;
4151  uint32 player_guid = 0;
4152 
4153  if (*args)
4154  {
4155  std::string name = args;
4156  if (!normalizePlayerName(name))
4157  {
4159  SetSentErrorMessage(true);
4160  return false;
4161  }
4162 
4163  player = sObjectMgr.GetPlayer(name.c_str());
4164  if (!player)
4165  player_guid = sObjectMgr.GetPlayerGUIDByName(name);
4166  }
4167  else
4168  player = getSelectedPlayer();
4169 
4170  if (player)
4171  {
4172  player->ResurrectPlayer(player->GetSession()->GetSecurity() > SEC_PLAYER ? 1.0f : 0.5f);
4173  player->SpawnCorpseBones();
4174  player->SaveToDB();
4175  }
4176  else if (player_guid)
4177  {
4178  // will resurrected at login without corpse
4180  }
4181  else
4182  {
4184  SetSentErrorMessage(true);
4185  return false;
4186  }
4187 
4188  return true;
4189 }
4190 
4191 bool ChatHandler::HandleAuraCommand(const char* args)
4192 {
4193  char* px = strtok((char*)args, " ");
4194  if (!px)
4195  return false;
4196 
4197  Unit* target = getSelectedUnit();
4198  if (!target)
4199  {
4201  SetSentErrorMessage(true);
4202  return false;
4203  }
4204 
4205  uint32 spellID = (uint32)atoi(px);
4206  SpellEntry const* spellInfo = sSpellStore.LookupEntry(spellID);
4207  if (spellInfo)
4208  {
4209  for (uint32 i = 0; i < 3; i++)
4210  {
4211  uint8 eff = spellInfo->Effect[i];
4212  if (eff >= TOTAL_SPELL_EFFECTS)
4213  continue;
4214  if (IsAreaAuraEffect(eff) ||
4215  eff == SPELL_EFFECT_APPLY_AURA ||
4217  {
4218  Aura* Aur = CreateAura(spellInfo, i, NULL, target);
4219  target->AddAura(Aur);
4220  }
4221  }
4222  }
4223 
4224  return true;
4225 }
4226 
4227 bool ChatHandler::HandleUnAuraCommand(const char* args)
4228 {
4229  char* px = strtok((char*)args, " ");
4230  if (!px)
4231  return false;
4232 
4233  Unit* target = getSelectedUnit();
4234  if (!target)
4235  {
4237  SetSentErrorMessage(true);
4238  return false;
4239  }
4240 
4241  std::string argstr = args;
4242  if (argstr == "all")
4243  {
4244  target->RemoveAllAuras();
4245  return true;
4246  }
4247 
4248  uint32 spellID = (uint32)atoi(px);
4249  target->RemoveAurasDueToSpell(spellID);
4250 
4251  return true;
4252 }
4253 
4255 {
4256  if (!*args)
4257  return false;
4258 
4259  char* px = strtok((char*)args, " ");
4260  if (!px)
4261  return false;
4262 
4263  uint32 g_id = (uint32)atoi(px);
4264 
4265  uint32 g_team;
4266 
4267  char* px2 = strtok(NULL, " ");
4268 
4269  if (!px2)
4270  g_team = 0;
4271  else if (strncmp(px2, "horde", 6) == 0)
4272  g_team = HORDE;
4273  else if (strncmp(px2, "alliance", 9) == 0)
4274  g_team = ALLIANCE;
4275  else
4276  return false;
4277 
4278  WorldSafeLocsEntry const* graveyard = sWorldSafeLocsStore.LookupEntry(g_id);
4279 
4280  if (!graveyard)
4281  {
4283  SetSentErrorMessage(true);
4284  return false;
4285  }
4286 
4287  Player* player = m_session->GetPlayer();
4288 
4289  uint32 zoneId = player->GetZoneId();
4290 
4291  AreaTableEntry const* areaEntry = GetAreaEntryByAreaID(zoneId);
4292  if (!areaEntry || areaEntry->zone != 0)
4293  {
4295  SetSentErrorMessage(true);
4296  return false;
4297  }
4298 
4299  if (sObjectMgr.AddGraveYardLink(g_id, player->GetZoneId(), g_team))
4301  else
4303 
4304  return true;
4305 }
4306 
4308 {
4309  uint32 g_team;
4310 
4311  size_t argslen = strlen(args);
4312 
4313  if (!*args)
4314  g_team = 0;
4315  else if (strncmp((char*)args, "horde", argslen) == 0)
4316  g_team = HORDE;
4317  else if (strncmp((char*)args, "alliance", argslen) == 0)
4318  g_team = ALLIANCE;
4319  else
4320  return false;
4321 
4322  Player* player = m_session->GetPlayer();
4323 
4324  WorldSafeLocsEntry const* graveyard = sObjectMgr.GetClosestGraveYard(
4325  player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(), player->GetMapId(), g_team);
4326 
4327  if (graveyard)
4328  {
4329  uint32 g_id = graveyard->ID;
4330 
4331  GraveYardData const* data = sObjectMgr.FindGraveYardData(g_id, player->GetZoneId());
4332  if (!data)
4333  {
4335  SetSentErrorMessage(true);
4336  return false;
4337  }
4338 
4339  g_team = data->team;
4340 
4341  std::string team_name = GetOregonString(LANG_COMMAND_GRAVEYARD_NOTEAM);
4342 
4343  if (g_team == 0)
4345  else if (g_team == HORDE)
4347  else if (g_team == ALLIANCE)
4349 
4350  PSendSysMessage(LANG_COMMAND_GRAVEYARDNEAREST, g_id, team_name.c_str(), player->GetZoneId());
4351  }
4352  else
4353  {
4354  std::string team_name;
4355 
4356  if (g_team == 0)
4358  else if (g_team == HORDE)
4360  else if (g_team == ALLIANCE)
4362 
4363  if (g_team == ~uint32(0))
4365  else
4366  PSendSysMessage(LANG_COMMAND_ZONENOGRAFACTION, player->GetZoneId(), team_name.c_str());
4367  }
4368 
4369  return true;
4370 }
4371 
4372 //play npc emote
4374 {
4375  uint32 emote = atoi((char*)args);
4376 
4377  Creature* target = getSelectedCreature();
4378  if (!target)
4379  {
4381  SetSentErrorMessage(true);
4382  return false;
4383  }
4384 
4385  target->SetUInt32Value(UNIT_NPC_EMOTESTATE, emote);
4386 
4387  return true;
4388 }
4389 
4390 bool ChatHandler::HandleNpcInfoCommand(const char* /*args*/)
4391 {
4392  Creature* target = getSelectedCreature();
4393 
4394  if (!target)
4395  {
4397  SetSentErrorMessage(true);
4398  return false;
4399  }
4400 
4401  uint32 faction = target->getFaction();
4402  uint32 npcflags = target->GetUInt32Value(UNIT_NPC_FLAGS);
4403  uint32 displayid = target->GetDisplayId();
4404  uint32 nativeid = target->GetNativeDisplayId();
4405  uint32 Entry = target->GetEntry();
4406  CreatureInfo const* cInfo = target->GetCreatureTemplate();
4407 
4408  int32 curRespawnDelay = target->GetRespawnTimeEx() - time(NULL);
4409  if (curRespawnDelay < 0)
4410  curRespawnDelay = 0;
4411  std::string curRespawnDelayStr = secsToTimeString(curRespawnDelay, true);
4412  std::string defRespawnDelayStr = secsToTimeString(target->GetRespawnDelay(), true);
4413 
4414  PSendSysMessage(LANG_NPCINFO_CHAR, target->GetDBTableGUIDLow(), faction, npcflags, Entry, displayid, nativeid);
4416  PSendSysMessage(LANG_NPCINFO_HEALTH, target->GetCreateHealth(), target->GetMaxHealth(), target->GetHealth());
4419  PSendSysMessage(LANG_COMMAND_RAWPAWNTIMES, defRespawnDelayStr.c_str(), curRespawnDelayStr.c_str());
4422  PSendSysMessage(LANG_NPCINFO_POSITION, float(target->GetPositionX()), float(target->GetPositionY()), float(target->GetPositionZ()));
4423  PSendSysMessage(LANG_NPCINFO_AIINFO, target->GetAIName().c_str(), target->GetScriptName().c_str());
4424  if (const CreatureData* const linked = target->GetLinkedRespawnCreatureData())
4425  if (CreatureInfo const* master = GetCreatureTemplate(linked->id))
4426  PSendSysMessage(LANG_NPCINFO_LINKGUID, sObjectMgr.GetLinkedRespawnGuid(target->GetDBTableGUIDLow()), linked->id, master->Name);
4427 
4428  if ((npcflags & UNIT_NPC_FLAG_VENDOR))
4430 
4431  if ((npcflags & UNIT_NPC_FLAG_TRAINER))
4433 
4434  return true;
4435 }
4436 
4438 {
4439  if (!*args)
4440  return false;
4441 
4442  int flag = atoi((char*)args);
4443 
4444  Player* chr = getSelectedPlayer();
4445  if (chr == NULL)
4446  {
4448  SetSentErrorMessage(true);
4449  return false;
4450  }
4451 
4452  if (flag != 0)
4453  {
4455  if (needReportToTarget(chr))
4456  ChatHandler(chr).PSendSysMessage(LANG_YOURS_EXPLORE_SET_ALL, GetName());
4457  }
4458  else
4459  {
4461  if (needReportToTarget(chr))
4462  ChatHandler(chr).PSendSysMessage(LANG_YOURS_EXPLORE_SET_NOTHING, GetName());
4463  }
4464 
4465  for (uint8 i = 0; i < 128; ++i)
4466  {
4467  if (flag != 0)
4468  m_session->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1 + i, 0xFFFFFFFF);
4469  else
4471  }
4472 
4473  return true;
4474 }
4475 
4476 bool ChatHandler::HandleHoverCommand(const char* args)
4477 {
4478  char* px = strtok((char*)args, " ");
4479  uint32 flag;
4480  if (!px)
4481  flag = 1;
4482  else
4483  flag = atoi(px);
4484 
4485  m_session->GetPlayer()->SetHover(flag);
4486 
4487  if (flag)
4489  else
4491 
4492  return true;
4493 }
4494 
4496 {
4497  if (!m_session || !m_session->GetPlayer())
4498  return false;
4499 
4500  std::string argstr = (char*)args;
4501 
4502  if (!*args)
4503  argstr = (m_session->GetPlayer()->GetCommandStatus(CHEAT_GOD)) ? "off" : "on";
4504 
4505  if (argstr == "off")
4506  {
4508  SendSysMessage("Godmode is OFF. You can take damage.");
4509  return true;
4510  }
4511  else if (argstr == "on")
4512  {
4514  SendSysMessage("Godmode is ON. You won't take damage.");
4515  return true;
4516  }
4517 
4518  return false;
4519 }
4520 
4522 {
4523  if (!m_session || !m_session->GetPlayer())
4524  return false;
4525 
4526  std::string argstr = (char*)args;
4527 
4528  if (!*args)
4529  argstr = (m_session->GetPlayer()->GetCommandStatus(CHEAT_CASTTIME)) ? "off" : "on";
4530 
4531  if (argstr == "off")
4532  {
4534  SendSysMessage("CastTime Cheat is OFF. Your spells will have a casttime.");
4535  return true;
4536  }
4537  else if (argstr == "on")
4538  {
4540  SendSysMessage("CastTime Cheat is ON. Your spells won't have a casttime.");
4541  return true;
4542  }
4543 
4544  return false;
4545 }
4546 
4548 {
4549  if (!m_session || !m_session->GetPlayer())
4550  return false;
4551 
4552  std::string argstr = (char*)args;
4553 
4554  if (!*args)
4555  argstr = (m_session->GetPlayer()->GetCommandStatus(CHEAT_COOLDOWN)) ? "off" : "on";
4556 
4557  if (argstr == "off")
4558  {
4560  SendSysMessage("Cooldown Cheat is OFF. You are on the global cooldown.");
4561  return true;
4562  }
4563  else if (argstr == "on")
4564  {
4566  SendSysMessage("Cooldown Cheat is ON. You are not on the global cooldown.");
4567  return true;
4568  }
4569 
4570  return false;
4571 }
4572 
4574 {
4575  if (!m_session || !m_session->GetPlayer())
4576  return false;
4577 
4578  std::string argstr = (char*)args;
4579 
4580  if (!*args)
4581  argstr = (m_session->GetPlayer()->GetCommandStatus(CHEAT_POWER)) ? "off" : "on";
4582 
4583  if (argstr == "off")
4584  {
4586  SendSysMessage("Power Cheat is OFF. You need mana/rage/energy to use spells.");
4587  return true;
4588  }
4589  else if (argstr == "on")
4590  {
4592  SendSysMessage("Power Cheat is ON. You don't need mana/rage/energy to use spells.");
4593  return true;
4594  }
4595 
4596  return false;
4597 }
4598 
4600 {
4601  if (!*args)
4602  return false;
4603 
4604  Player* player = getSelectedPlayer();
4605  if (!player)
4606  {
4608  SetSentErrorMessage(true);
4609  return false;
4610  }
4611 
4612  if (strncmp(args, "on", 3) == 0)
4613  player->SetWaterWalking(true); // ON
4614  else if (strncmp(args, "off", 4) == 0)
4615  player->SetWaterWalking(false); // OFF
4616  else
4617  {
4619  return false;
4620  }
4621 
4623  if (needReportToTarget(player))
4624  ChatHandler(player).PSendSysMessage(LANG_YOUR_WATERWALK_SET, args, GetName());
4625  return true;
4626 
4627 }
4628 
4630 {
4631  char* px = strtok((char*)args, " ");
4632  char* py = strtok((char*)NULL, " ");
4633 
4634  // command format parsing
4635  char* pname = (char*)NULL;
4636  int addlevel = 1;
4637 
4638  if (px && py) // .levelup name level
4639  {
4640  addlevel = atoi(py);
4641  pname = px;
4642  }
4643  else if (px && !py) // .levelup name OR .levelup level
4644  {
4645  if (isalpha(px[0])) // .levelup name
4646  pname = px;
4647  else // .levelup level
4648  addlevel = atoi(px);
4649  }
4650  // else .levelup - nothing do for preparing
4651 
4652  // player
4653  Player* chr = NULL;
4654  uint64 chr_guid = 0;
4655 
4656  std::string name;
4657 
4658  if (pname) // player by name
4659  {
4660  name = pname;
4661  if (!normalizePlayerName(name))
4662  {
4664  SetSentErrorMessage(true);
4665  return false;
4666  }
4667 
4668  chr = sObjectMgr.GetPlayer(name.c_str());
4669  if (!chr) // not in game
4670  {
4671  chr_guid = sObjectMgr.GetPlayerGUIDByName(name);
4672  if (chr_guid == 0)
4673  {
4675  SetSentErrorMessage(true);
4676  return false;
4677  }
4678  }
4679  }
4680  else // player by selection
4681  {
4682  chr = getSelectedPlayer();
4683 
4684  if (chr == NULL)
4685  {
4687  SetSentErrorMessage(true);
4688  return false;
4689  }
4690 
4691  name = chr->GetName();
4692  }
4693 
4694  ASSERT(chr || chr_guid);
4695 
4696  int32 oldlevel = chr ? chr->getLevel() : Player::GetUInt32ValueFromDB(UNIT_FIELD_LEVEL, chr_guid);
4697  int32 newlevel = oldlevel + addlevel;
4698 
4699  if (newlevel < 1)
4700  newlevel = 1;
4701 
4702  if (newlevel > STRONG_MAX_LEVEL) // hardcoded maximum level
4703  newlevel = STRONG_MAX_LEVEL;
4704 
4705  if (chr)
4706  {
4707  chr->GiveLevel(newlevel);
4708  chr->InitTalentForLevel();
4709  chr->SetUInt32Value(PLAYER_XP, 0);
4710 
4711  if (oldlevel == newlevel)
4712  ChatHandler(chr).SendSysMessage(LANG_YOURS_LEVEL_PROGRESS_RESET);
4713  else if (oldlevel < newlevel)
4714  ChatHandler(chr).PSendSysMessage(LANG_YOURS_LEVEL_UP, newlevel - oldlevel);
4715  else if (oldlevel > newlevel)
4716  ChatHandler(chr).PSendSysMessage(LANG_YOURS_LEVEL_DOWN, newlevel - oldlevel);
4717  }
4718  else
4719  {
4720  // update level and XP at level, all other will be updated at loading
4721  CharacterDatabase.PExecute("UPDATE characters SET level = '%u', xp = 0 WHERE guid = '" UI64FMTD "'", newlevel, chr_guid);
4722  }
4723 
4724  if (m_session->GetPlayer() != chr) // including chr == NULL
4725  PSendSysMessage(LANG_YOU_CHANGE_LVL, name.c_str(), newlevel);
4726  return true;
4727 }
4728 
4730 {
4731  if (!*args)
4732  return false;
4733 
4734  int area = atoi((char*)args);
4735 
4736  Player* chr = getSelectedPlayer();
4737  if (chr == NULL)
4738  {
4740  SetSentErrorMessage(true);
4741  return false;
4742  }
4743 
4744  int offset = area / 32;
4745  uint32 val = (uint32)(1 << (area % 32));
4746 
4747  if (offset >= 128)
4748  {
4750  SetSentErrorMessage(true);
4751  return false;
4752  }
4753 
4754  uint32 currFields = chr->GetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset);
4755  chr->SetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset, (uint32)(currFields | val));
4756 
4758  return true;
4759 }
4760 
4762 {
4763  if (!*args)
4764  return false;
4765 
4766  int area = atoi((char*)args);
4767 
4768  Player* chr = getSelectedPlayer();
4769  if (chr == NULL)
4770  {
4772  SetSentErrorMessage(true);
4773  return false;
4774  }
4775 
4776  int offset = area / 32;
4777  uint32 val = (uint32)(1 << (area % 32));
4778 
4779  if (offset >= 128)
4780  {
4782  SetSentErrorMessage(true);
4783  return false;
4784  }
4785 
4786  uint32 currFields = chr->GetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset);
4787  chr->SetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset, (uint32)(currFields ^ val));
4788 
4790  return true;
4791 }
4792 
4793 bool ChatHandler::HandleUpdate(const char* args)
4794 {
4795  if (!*args)
4796  return false;
4797 
4798  uint32 updateIndex;
4799  uint32 value;
4800 
4801  char* pUpdateIndex = strtok((char*)args, " ");
4802 
4803  Unit* chr = getSelectedUnit();
4804  if (chr == NULL)
4805  {
4807  SetSentErrorMessage(true);
4808  return false;
4809  }
4810 
4811  if (!pUpdateIndex)
4812  return true;
4813  updateIndex = atoi(pUpdateIndex);
4814  //check updateIndex
4815  if (chr->GetTypeId() == TYPEID_PLAYER)
4816  {
4817  if (updateIndex >= PLAYER_END) return true;
4818  }
4819  else
4820  {
4821  if (updateIndex >= UNIT_END) return true;
4822  }
4823 
4824  char* pvalue = strtok(NULL, " ");
4825  if (!pvalue)
4826  {
4827  value = chr->GetUInt32Value(updateIndex);
4828 
4829  PSendSysMessage(LANG_UPDATE, chr->GetGUIDLow(), updateIndex, value);
4830  return true;
4831  }
4832 
4833  value = atoi(pvalue);
4834 
4835  PSendSysMessage(LANG_UPDATE_CHANGE, chr->GetGUIDLow(), updateIndex, value);
4836 
4837  chr->SetUInt32Value(updateIndex, value);
4838 
4839  return true;
4840 }
4841 
4842 bool ChatHandler::HandleBankCommand(const char* /*args*/)
4843 {
4845 
4846  return true;
4847 }
4848 
4849 bool ChatHandler::HandleChangeWeather(const char* args)
4850 {
4851  if (!*args)
4852  return false;
4853 
4854  //Weather is OFF
4855  if (!sWorld.getConfig(CONFIG_WEATHER))
4856  {
4858  SetSentErrorMessage(true);
4859  return false;
4860  }
4861 
4862  //*Change the weather of a cell
4863  char* px = strtok((char*)args, " ");
4864  char* py = strtok(NULL, " ");
4865 
4866  if (!px || !py)
4867  return false;
4868 
4869  uint32 type = (uint32)atoi(px); //0 to 3, 0: fine, 1: rain, 2: snow, 3: sand
4870  float grade = (float)atof(py); //0 to 1, sending -1 is instand good weather
4871 
4872  Player* player = m_session->GetPlayer();
4873  uint32 zoneid = player->GetZoneId();
4874 
4875  Weather* wth = sWorld.FindWeather(zoneid);
4876 
4877  if (!wth)
4878  wth = sWorld.AddWeather(zoneid);
4879  if (!wth)
4880  {
4882  SetSentErrorMessage(true);
4883  return false;
4884  }
4885 
4886  wth->SetWeather(WeatherType(type), grade);
4887 
4888  return true;
4889 }
4890 
4891 bool ChatHandler::HandleSetValue(const char* args)
4892 {
4893  if (!*args)
4894  return false;
4895 
4896  char* px = strtok((char*)args, " ");
4897  char* py = strtok(NULL, " ");
4898  char* pz = strtok(NULL, " ");
4899 
4900  if (!px || !py)
4901  return false;
4902 
4903  Unit* target = getSelectedUnit();
4904  if (!target)
4905  {
4907  SetSentErrorMessage(true);
4908  return false;
4909  }
4910 
4911  uint64 guid = target->GetGUID();
4912 
4913  uint32 Opcode = (uint32)atoi(px);
4914  if (Opcode >= target->GetValuesCount())
4915  {
4916  PSendSysMessage(LANG_TOO_BIG_INDEX, Opcode, GUID_LOPART(guid), target->GetValuesCount());
4917  return false;
4918  }
4919  uint32 iValue;
4920  float fValue;
4921  bool isint32 = true;
4922  if (pz)
4923  isint32 = (bool)atoi(pz);
4924  if (isint32)
4925  {
4926  iValue = (uint32)atoi(py);
4927  sLog.outDebug(GetOregonString(LANG_SET_UINT), GUID_LOPART(guid), Opcode, iValue);
4928  target->SetUInt32Value(Opcode , iValue);
4929  PSendSysMessage(LANG_SET_UINT_FIELD, GUID_LOPART(guid), Opcode, iValue);
4930  }
4931  else
4932  {
4933  fValue = (float)atof(py);
4934  sLog.outDebug(GetOregonString(LANG_SET_FLOAT), GUID_LOPART(guid), Opcode, fValue);
4935  target->SetFloatValue(Opcode , fValue);
4936  PSendSysMessage(LANG_SET_FLOAT_FIELD, GUID_LOPART(guid), Opcode, fValue);
4937  }
4938 
4939  return true;
4940 }
4941 
4942 bool ChatHandler::HandleGetValue(const char* args)
4943 {
4944  if (!*args)
4945  return false;
4946 
4947  char* px = strtok((char*)args, " ");
4948  char* pz = strtok(NULL, " ");
4949 
4950  if (!px)
4951  return false;
4952 
4953  Unit* target = getSelectedUnit();
4954  if (!target)
4955  {
4957  SetSentErrorMessage(true);
4958  return false;
4959  }
4960 
4961  uint64 guid = target->GetGUID();
4962 
4963  uint32 Opcode = (uint32)atoi(px);
4964  if (Opcode >= target->GetValuesCount())
4965  {
4966  PSendSysMessage(LANG_TOO_BIG_INDEX, Opcode, GUID_LOPART(guid), target->GetValuesCount());
4967  return false;
4968  }
4969  uint32 iValue;
4970  float fValue;
4971  bool isint32 = true;
4972  if (pz)
4973  isint32 = (bool)atoi(pz);
4974 
4975  if (isint32)
4976  {
4977  iValue = target->GetUInt32Value(Opcode);
4978  sLog.outDebug(GetOregonString(LANG_GET_UINT), GUID_LOPART(guid), Opcode, iValue);
4979  PSendSysMessage(LANG_GET_UINT_FIELD, GUID_LOPART(guid), Opcode, iValue);
4980  }
4981  else
4982  {
4983  fValue = target->GetFloatValue(Opcode);
4984  sLog.outDebug(GetOregonString(LANG_GET_FLOAT), GUID_LOPART(guid), Opcode, fValue);
4985  PSendSysMessage(LANG_GET_FLOAT_FIELD, GUID_LOPART(guid), Opcode, fValue);
4986  }
4987 
4988  return true;
4989 }
4990 
4991 bool ChatHandler::HandleSet32Bit(const char* args)
4992 {
4993  if (!*args)
4994  return false;
4995 
4996  char* px = strtok((char*)args, " ");
4997  char* py = strtok(NULL, " ");
4998 
4999  if (!px || !py)
5000  return false;
5001 
5002  uint32 Opcode = (uint32)atoi(px);
5003  uint32 Value = (uint32)atoi(py);
5004  if (Value > 32) //uint32 = 32 bits
5005  return false;
5006 
5007  sLog.outDebug(GetOregonString(LANG_SET_32BIT), Opcode, Value);
5008 
5009  m_session->GetPlayer()->SetUInt32Value(Opcode , 2 ^ Value);
5010 
5012  return true;
5013 }
5014 
5015 bool ChatHandler::HandleDebugRAFError(const char* args)
5016 {
5017  uint32 id = strtoul(args, NULL, 10);
5018  if (!id || !m_session)
5019  return false;
5020 
5022  packet << id;
5023  m_session->SendPacket(&packet);
5024  return true;
5025 }
5026 
5027 bool ChatHandler::HandleMod32Value(const char* args)
5028 {
5029  if (!*args)
5030  return false;
5031 
5032  char* px = strtok((char*)args, " ");
5033  char* py = strtok(NULL, " ");
5034 
5035  if (!px || !py)
5036  return false;
5037 
5038  uint32 Opcode = (uint32)atoi(px);
5039  int Value = atoi(py);
5040 
5041  if (Opcode >= m_session->GetPlayer()->GetValuesCount())
5042  {
5044  return false;
5045  }
5046 
5047  sLog.outDebug(GetOregonString(LANG_CHANGE_32BIT), Opcode, Value);
5048 
5049  int CurrentValue = (int)m_session->GetPlayer()->GetUInt32Value(Opcode);
5050 
5051  CurrentValue += Value;
5052  m_session->GetPlayer()->SetUInt32Value(Opcode , (uint32)CurrentValue);
5053 
5054  PSendSysMessage(LANG_CHANGE_32BIT_FIELD, Opcode, CurrentValue);
5055 
5056  return true;
5057 }
5058 
5060 {
5061  if (!*args)
5062  return false;
5063 
5064  Player* player = m_session->GetPlayer();
5065  if (!player)
5066  return false;
5067 
5068  std::string name = args;
5069 
5070  if (sObjectMgr.GetGameTele(name))
5071  {
5073  SetSentErrorMessage(true);
5074  return false;
5075  }
5076 
5077  GameTele tele;
5078  tele.position_x = player->GetPositionX();
5079  tele.position_y = player->GetPositionY();
5080  tele.position_z = player->GetPositionZ();
5081  tele.orientation = player->GetOrientation();
5082  tele.mapId = player->GetMapId();
5083  tele.name = name;
5084 
5085  if (sObjectMgr.AddGameTele(tele))
5087  else
5088  {
5090  SetSentErrorMessage(true);
5091  return false;
5092  }
5093 
5094  return true;
5095 }
5096 
5098 {
5099  if (!*args)
5100  return false;
5101 
5102  std::string name = args;
5103 
5104  if (!sObjectMgr.DeleteGameTele(name))
5105  {
5107  SetSentErrorMessage(true);
5108  return false;
5109  }
5110 
5112  return true;
5113 }
5114 
5115 bool ChatHandler::HandleListAurasCommand (const char* /*args*/)
5116 {
5117  Unit* unit = getSelectedUnit();
5118  if (!unit)
5119  {
5121  SetSentErrorMessage(true);
5122  return false;
5123  }
5124 
5125  char const* talentStr = GetOregonString(LANG_TALENT);
5126  char const* passiveStr = GetOregonString(LANG_PASSIVE);
5127 
5128  Unit::AuraMap const& uAuras = unit->GetAuras();
5130  for (Unit::AuraMap::const_iterator itr = uAuras.begin(); itr != uAuras.end(); ++itr)
5131  {
5132  bool talent = GetTalentSpellCost(itr->second->GetId()) > 0;
5133  PSendSysMessage(LANG_COMMAND_TARGET_AURADETAIL, itr->second->GetId(), itr->second->GetEffIndex(),
5134  itr->second->GetModifier()->m_auraname, itr->second->GetAuraDuration(), itr->second->GetAuraMaxDuration(),
5135  itr->second->GetSpellProto()->SpellName[m_session->GetSessionDbcLocale()],
5136  (itr->second->IsPassive() ? passiveStr : ""), (talent ? talentStr : ""),
5137  IS_PLAYER_GUID(itr->second->GetCasterGUID()) ? "player" : "creature", GUID_LOPART(itr->second->GetCasterGUID()));
5138  }
5139  for (uint16 i = 0; i < TOTAL_AURAS; ++i)
5140  {
5141  Unit::AuraList const& uAuraList = unit->GetAurasByType(AuraType(i));
5142  if (uAuraList.empty()) continue;
5143  PSendSysMessage(LANG_COMMAND_TARGET_LISTAURATYPE, uAuraList.size(), i);
5144  for (Unit::AuraList::const_iterator itr = uAuraList.begin(); itr != uAuraList.end(); ++itr)
5145  {
5146  bool talent = GetTalentSpellCost((*itr)->GetId()) > 0;
5147  PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE, (*itr)->GetId(), (*itr)->GetEffIndex(),
5148  (*itr)->GetSpellProto()->SpellName[m_session->GetSessionDbcLocale()], ((*itr)->IsPassive() ? passiveStr : ""), (talent ? talentStr : ""),
5149  IS_PLAYER_GUID((*itr)->GetCasterGUID()) ? "player" : "creature", GUID_LOPART((*itr)->GetCasterGUID()));
5150  }
5151  }
5152  return true;
5153 }
5154 
5156 {
5157  char* pName = strtok((char*)args, "");
5158  Player* player = NULL;
5159  if (pName)
5160  {
5161  std::string name = pName;
5162  if (!normalizePlayerName(name))
5163  {
5165  SetSentErrorMessage(true);
5166  return false;
5167  }
5168 
5169  uint64 guid = sObjectMgr.GetPlayerGUIDByName(name.c_str());
5170  player = sObjectMgr.GetPlayer(guid);
5171  }
5172  else
5173  player = getSelectedPlayer();
5174 
5175  if (!player)
5176  {
5178  return true;
5179  }
5180 
5181  player->SetUInt32Value(PLAYER_FIELD_KILLS, 0);
5186 
5187  return true;
5188 }
5189 
5190 static bool HandleResetStatsOrLevelHelper(Player* player)
5191 {
5192  PlayerInfo const* info = sObjectMgr.GetPlayerInfo(player->getRace(), player->getClass());
5193  if (!info) return false;
5194 
5195  ChrClassesEntry const* cEntry = sChrClassesStore.LookupEntry(player->getClass());
5196  if (!cEntry)
5197  {
5198  sLog.outError("Class %u not found in DBC (Wrong DBC files?)", player->getClass());
5199  return false;
5200  }
5201 
5202  uint8 powertype = cEntry->powerType;
5203 
5204  uint32 unitfield;
5205  if (powertype == POWER_RAGE)
5206  unitfield = 0x1100EE00;
5207  else if (powertype == POWER_ENERGY)
5208  unitfield = 0x00000000;
5209  else if (powertype == POWER_MANA)
5210  unitfield = 0x0000EE00;
5211  else
5212  {
5213  sLog.outError("Invalid default powertype %u for player (class %u)", powertype, player->getClass());
5214  return false;
5215  }
5216 
5217  // reset m_form if no aura
5218  if (!player->HasAuraType(SPELL_AURA_MOD_SHAPESHIFT))
5219  player->m_form = FORM_NONE;
5220 
5223 
5224  player->setFactionForRace(player->getRace());
5225 
5226  player->SetUInt32Value(UNIT_FIELD_BYTES_0, ((player->getRace()) | (player->getClass() << 8) | (player->getGender() << 16) | (powertype << 24)));
5227 
5228  // reset only if player not in some form;
5229  if (player->m_form == FORM_NONE)
5230  {
5231  switch (player->getGender())
5232  {
5233  case GENDER_FEMALE:
5234  player->SetDisplayId(info->displayId_f);
5235  player->SetNativeDisplayId(info->displayId_f);
5236  break;
5237  case GENDER_MALE:
5238  player->SetDisplayId(info->displayId_m);
5239  player->SetNativeDisplayId(info->displayId_m);
5240  break;
5241  default:
5242  break;
5243  }
5244  }
5245 
5246  // set UNIT_FIELD_BYTES_1 to init state but preserve m_form value
5247  player->SetUInt32Value(UNIT_FIELD_BYTES_1, unitfield);
5249  player->SetByteValue(UNIT_FIELD_BYTES_2, 3, player->m_form);
5250 
5252 
5253  //-1 is default value
5255 
5256  //player->SetUInt32Value(PLAYER_FIELD_BYTES, 0xEEE00000);
5257  return true;
5258 }
5259 
5261 {
5262  char* pName = strtok((char*)args, "");
5263  Player* player = NULL;
5264  if (pName)
5265  {
5266  std::string name = pName;
5267  if (!normalizePlayerName(name))
5268  {
5270  SetSentErrorMessage(true);
5271  return false;
5272  }
5273 
5274  uint64 guid = sObjectMgr.GetPlayerGUIDByName(name.c_str());
5275  player = sObjectMgr.GetPlayer(guid);
5276  }
5277  else
5278  player = getSelectedPlayer();
5279 
5280  if (!player)
5281  {
5283  SetSentErrorMessage(true);
5284  return false;
5285  }
5286 
5287  if (!HandleResetStatsOrLevelHelper(player))
5288  return false;
5289 
5290  // set starting level
5291  uint32 startLevel = sWorld.getConfig(CONFIG_START_PLAYER_LEVEL);
5292 
5293  player->SetLevel(startLevel);
5294  player->InitStatsForLevel(true);
5295  player->InitTaxiNodesForLevel();
5296  player->InitTalentForLevel();
5297  player->SetUInt32Value(PLAYER_XP, 0);
5298 
5299  // reset level to summoned pet
5300  Guardian* pet = player->GetGuardianPet();
5301  if (pet)
5302  pet->InitStatsForLevel(startLevel);
5303 
5304  return true;
5305 }
5306 
5308 {
5309  char* pName = strtok((char*)args, "");
5310  Player* player = NULL;
5311  if (pName)
5312  {
5313  std::string name = pName;
5314  if (!normalizePlayerName(name))
5315  {
5317  SetSentErrorMessage(true);
5318  return false;
5319  }
5320 
5321  uint64 guid = sObjectMgr.GetPlayerGUIDByName(name.c_str());
5322  player = sObjectMgr.GetPlayer(guid);
5323  }
5324  else
5325  player = getSelectedPlayer();
5326 
5327  if (!player)
5328  {
5330  SetSentErrorMessage(true);
5331  return false;
5332  }
5333 
5334  if (!HandleResetStatsOrLevelHelper(player))
5335  return false;
5336 
5337  player->InitStatsForLevel(true);
5338  player->InitTaxiNodesForLevel();
5339  player->InitTalentForLevel();
5340 
5341  return true;
5342 }
5343 
5345 {
5346  char* pName = strtok((char*)args, "");
5347  Player* player = NULL;
5348  uint64 playerGUID = 0;
5349  if (pName)
5350  {
5351  std::string name = pName;
5352 
5353  if (!normalizePlayerName(name))
5354  {
5356  SetSentErrorMessage(true);
5357  return false;
5358  }
5359 
5360  player = sObjectMgr.GetPlayer(name.c_str());
5361  if (!player)
5362  playerGUID = sObjectMgr.GetPlayerGUIDByName(name.c_str());
5363  }
5364  else
5365  player = getSelectedPlayer();
5366 
5367  if (!player && !playerGUID)
5368  {
5370  SetSentErrorMessage(true);
5371  return false;
5372  }
5373 
5374  if (player)
5375  {
5376  player->ResetSpells();
5377 
5378  ChatHandler(player).SendSysMessage(LANG_RESET_SPELLS);
5379 
5380  if (m_session->GetPlayer() != player)
5382  }
5383  else
5384  {
5385  CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'", uint32(AT_LOGIN_RESET_SPELLS), GUID_LOPART(playerGUID));
5387  }
5388 
5389  return true;
5390 }
5391 
5393 {
5394  char* pName = strtok((char*)args, "");
5395  Player* player = NULL;
5396  uint64 playerGUID = 0;
5397  if (pName)
5398  {
5399  std::string name = pName;
5400  if (!normalizePlayerName(name))
5401  {
5403  SetSentErrorMessage(true);
5404  return false;
5405  }
5406 
5407  player = sObjectMgr.GetPlayer(name.c_str());
5408  if (!player)
5409  playerGUID = sObjectMgr.GetPlayerGUIDByName(name.c_str());
5410  }
5411  else
5412  player = getSelectedPlayer();
5413 
5414  if (!player && !playerGUID)
5415  {
5417  SetSentErrorMessage(true);
5418  return false;
5419  }
5420 
5421  if (player)
5422  {
5423  player->ResetTalents(true);
5424 
5425  ChatHandler(player).SendSysMessage(LANG_RESET_TALENTS);
5426 
5427  if (m_session->GetPlayer() != player)
5429  }
5430  else
5431  {
5432  CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'", uint32(AT_LOGIN_RESET_TALENTS), GUID_LOPART(playerGUID));
5434  }
5435 
5436  return true;
5437 }
5438 
5440 {
5441  if (!*args)
5442  return false;
5443 
5444  std::string casename = args;
5445 
5446  AtLoginFlags atLogin;
5447 
5448  // Command specially created as single command to prevent using short case names
5449  if (casename == "spells")
5450  {
5451  atLogin = AT_LOGIN_RESET_SPELLS;
5452  sWorld.SendWorldText(LANG_RESETALL_SPELLS);
5453  }
5454  else if (casename == "talents")
5455  {
5456  atLogin = AT_LOGIN_RESET_TALENTS;
5457  sWorld.SendWorldText(LANG_RESETALL_TALENTS);
5458  }
5459  else
5460  {
5462  SetSentErrorMessage(true);
5463  return false;
5464  }
5465 
5466  CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE (at_login & '%u') = '0'", atLogin, atLogin);
5467 
5470  for (HashMapHolder<Player>::MapType::const_iterator itr = plist.begin(); itr != plist.end(); ++itr)
5471  itr->second->SetAtLoginFlag(atLogin);
5472 
5473  return true;
5474 }
5475 
5477 {
5478  sWorld.ShutdownCancel();
5479  return true;
5480 }
5481 
5483 {
5484  if (!*args)
5485  return false;
5486 
5487  char* time_str = strtok ((char*) args, " ");
5488  char* exitcode_str = strtok (NULL, "");
5489 
5490  int32 time = atoi (time_str);
5491 
5492  // Prevent interpret wrong arg value as 0 secs shutdown time
5493  if ((time == 0 && (time_str[0] != '0' || time_str[1] != '\0')) || time < 0)
5494  return false;
5495 
5496  if (exitcode_str)
5497  {
5498  int32 exitcode = atoi (exitcode_str);
5499 
5500  // Handle atoi() errors
5501  if (exitcode == 0 && (exitcode_str[0] != '0' || exitcode_str[1] != '\0'))
5502  return false;
5503 
5504  // Exit code should be in range of 0-125, 126-255 is used
5505  // in many shells for their own return codes and code > 255
5506  // is not supported in many others
5507  if (exitcode < 0 || exitcode > 125)
5508  return false;
5509 
5510  sWorld.ShutdownServ (time, 0, exitcode);
5511  }
5512  else
5513  sWorld.ShutdownServ(time, 0, SHUTDOWN_EXIT_CODE);
5514  return true;
5515 }
5516 
5518 {
5519  if (!*args)
5520  return false;
5521 
5522  char* time_str = strtok ((char*) args, " ");
5523  char* exitcode_str = strtok (NULL, "");
5524 
5525  int32 time = atoi (time_str);
5526 
5527  // Prevent interpret wrong arg value as 0 secs shutdown time
5528  if ((time == 0 && (time_str[0] != '0' || time_str[1] != '\0')) || time < 0)
5529  return false;
5530 
5531  if (exitcode_str)
5532  {
5533  int32 exitcode = atoi (exitcode_str);
5534 
5535  // Handle atoi() errors
5536  if (exitcode == 0 && (exitcode_str[0] != '0' || exitcode_str[1] != '\0'))</