Merge branch '310' of git://github.com/mangos/mangos into 310
[AHbot.git] / src / game / Level3.cpp
blob2b42e0d7425f70cc317855fa54c3f02e29f16386
1 /*
2 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include "Common.h"
20 #include "Database/DatabaseEnv.h"
21 #include "WorldPacket.h"
22 #include "WorldSession.h"
23 #include "World.h"
24 #include "ObjectMgr.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 "ScriptCalls.h"
37 #include "Language.h"
38 #include "GridNotifiersImpl.h"
39 #include "CellImpl.h"
40 #include "Weather.h"
41 #include "PointMovementGenerator.h"
42 #include "TargetedMovementGenerator.h"
43 #include "SkillDiscovery.h"
44 #include "SkillExtraItems.h"
45 #include "SystemConfig.h"
46 #include "Config/ConfigEnv.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"
54 bool ChatHandler::HandleAHBotOptionsCommand(const char* args)
56 uint32 ahMapID = 0;
57 char * opt = strtok((char*)args, " ");
58 char * ahMapIdStr = strtok(NULL, " ");
59 if (ahMapIdStr)
61 ahMapID = (uint32) strtoul(ahMapIdStr, NULL, 0);
63 if (!opt)
65 PSendSysMessage("Syntax is: ahbotoptions $option $ahMapID (2, 6 or 7) $parameter");
66 PSendSysMessage("Try ahbotoptions help to see a list of options.");
67 return false;
69 int l = strlen(opt);
71 if (strncmp(opt,"help",l) == 0)
73 PSendSysMessage("AHBot commands:");
74 PSendSysMessage("ahexpire");
75 PSendSysMessage("minitems");
76 PSendSysMessage("maxitems");
77 PSendSysMessage("mintime");
78 PSendSysMessage("maxtime");
79 PSendSysMessage("percentages");
80 PSendSysMessage("minprice");
81 PSendSysMessage("maxprice");
82 PSendSysMessage("minbidprice");
83 PSendSysMessage("maxbidprice");
84 PSendSysMessage("maxstack");
85 PSendSysMessage("buyerprice");
86 PSendSysMessage("bidinterval");
87 PSendSysMessage("bidsperinterval");
88 return true;
90 else if (strncmp(opt,"ahexpire",l) == 0)
92 if (!ahMapIdStr)
94 PSendSysMessage("Syntax is: ahbotoptions ahexpire $ahMapID (2, 6 or 7)");
95 return false;
97 AuctionHouseBotCommands(0, ahMapID, NULL, NULL);
99 else if (strncmp(opt,"minitems",l) == 0)
101 char * param1 = strtok(NULL, " ");
102 if ((!ahMapIdStr) || (!param1))
104 PSendSysMessage("Syntax is: ahbotoptions minitems $ahMapID (2, 6 or 7) $minItems");
105 return false;
107 AuctionHouseBotCommands(1, ahMapID, NULL, param1);
109 else if (strncmp(opt,"maxitems",l) == 0)
111 char * param1 = strtok(NULL, " ");
112 if ((!ahMapIdStr) || (!param1))
114 PSendSysMessage("Syntax is: ahbotoptions maxitems $ahMapID (2, 6 or 7) $maxItems");
115 return false;
117 AuctionHouseBotCommands(2, ahMapID, NULL, param1);
119 else if (strncmp(opt,"mintime",l) == 0)
121 char * param1 = strtok(NULL, " ");
122 if ((!ahMapIdStr) || (!param1))
124 PSendSysMessage("Syntax is: ahbotoptions mintime $ahMapID (2, 6 or 7) $mintime");
125 return false;
127 AuctionHouseBotCommands(3, ahMapID, NULL, param1);
129 else if (strncmp(opt,"maxtime",l) == 0)
131 char * param1 = strtok(NULL, " ");
132 if ((!ahMapIdStr) || (!param1))
134 PSendSysMessage("Syntax is: ahbotoptions maxtime $ahMapID (2, 6 or 7) $maxtime");
135 return false;
137 AuctionHouseBotCommands(4, ahMapID, NULL, param1);
139 else if (strncmp(opt,"percentages",l) == 0)
141 char * param1 = strtok(NULL, " ");
142 char * param2 = strtok(NULL, " ");
143 char * param3 = strtok(NULL, " ");
144 char * param4 = strtok(NULL, " ");
145 char * param5 = strtok(NULL, " ");
146 char * param6 = strtok(NULL, " ");
147 char * param7 = strtok(NULL, " ");
148 char * param8 = strtok(NULL, " ");
149 char * param9 = strtok(NULL, " ");
150 char * param10 = strtok(NULL, " ");
151 char * param11 = strtok(NULL, " ");
152 char * param12 = strtok(NULL, " ");
153 char * param13 = strtok(NULL, " ");
154 char * param14 = strtok(NULL, " ");
155 if ((!ahMapIdStr) || (!param14))
157 PSendSysMessage("Syntax is: ahbotoptions percentages $ahMapID (2, 6 or 7) $1 $2 $3 $4 $5 $6 $7 $8 $9 $10 $11 $12 $13 $14");
158 PSendSysMessage("1 GreyTradeGoods 2 WhiteTradeGoods 3 GreenTradeGoods 4 BlueTradeGoods 5 PurpleTradeGoods");
159 PSendSysMessage("6 OrangeTradeGoods 7 YellowTradeGoods 8 GreyItems 9 WhiteItems 10 GreenItems 11 BlueItems");
160 PSendSysMessage("12 PurpleItems 13 OrangeItems 14 YellowItems");
161 PSendSysMessage("The total must add up to 100%");
162 return false;
164 uint32 greytg = (uint32) strtoul(param1, NULL, 0);
165 uint32 whitetg = (uint32) strtoul(param2, NULL, 0);
166 uint32 greentg = (uint32) strtoul(param3, NULL, 0);
167 uint32 bluetg = (uint32) strtoul(param3, NULL, 0);
168 uint32 purpletg = (uint32) strtoul(param5, NULL, 0);
169 uint32 orangetg = (uint32) strtoul(param6, NULL, 0);
170 uint32 yellowtg = (uint32) strtoul(param7, NULL, 0);
171 uint32 greyi = (uint32) strtoul(param8, NULL, 0);
172 uint32 whitei = (uint32) strtoul(param9, NULL, 0);
173 uint32 greeni = (uint32) strtoul(param10, NULL, 0);
174 uint32 bluei = (uint32) strtoul(param11, NULL, 0);
175 uint32 purplei = (uint32) strtoul(param12, NULL, 0);
176 uint32 orangei = (uint32) strtoul(param13, NULL, 0);
177 uint32 yellowi = (uint32) strtoul(param14, NULL, 0);
178 uint32 totalPercent = greytg + whitetg + greentg + bluetg + purpletg + orangetg + yellowtg + greyi + whitei + greeni + bluei + purplei + orangei + yellowi;
179 if ((totalPercent == 0) || (totalPercent != 100))
181 PSendSysMessage("Syntax is: ahbotoptions percentages $ahMapID (2, 6 or 7) $1 $2 $3 $4 $5 $6 $7 $8 $9 $10 $11 $12 $13 $14");
182 PSendSysMessage("1 GreyTradeGoods 2 WhiteTradeGoods 3 GreenTradeGoods 4 BlueTradeGoods 5 PurpleTradeGoods");
183 PSendSysMessage("6 OrangeTradeGoods 7 YellowTradeGoods 8 GreyItems 9 WhiteItems 10 GreenItems 11 BlueItems");
184 PSendSysMessage("12 PurpleItems 13 OrangeItems 14 YellowItems");
185 PSendSysMessage("The total must add up to 100%");
186 return false;
188 char param[100];
189 param[0] = '\0';
190 strcat(param, param1);
191 strcat(param, " ");
192 strcat(param, param2);
193 strcat(param, " ");
194 strcat(param, param3);
195 strcat(param, " ");
196 strcat(param, param4);
197 strcat(param, " ");
198 strcat(param, param5);
199 strcat(param, " ");
200 strcat(param, param6);
201 strcat(param, " ");
202 strcat(param, param7);
203 strcat(param, " ");
204 strcat(param, param8);
205 strcat(param, " ");
206 strcat(param, param9);
207 strcat(param, " ");
208 strcat(param, param10);
209 strcat(param, " ");
210 strcat(param, param11);
211 strcat(param, " ");
212 strcat(param, param12);
213 strcat(param, " ");
214 strcat(param, param13);
215 strcat(param, " ");
216 strcat(param, param14);
217 AuctionHouseBotCommands(5, ahMapID, NULL, param);
219 else if (strncmp(opt,"minprice",l) == 0)
221 char * param1 = strtok(NULL, " ");
222 char * param2 = strtok(NULL, " ");
223 if ((!ahMapIdStr) || (!param1) || (!param2))
225 PSendSysMessage("Syntax is: ahbotoptions minprice $ahMapID (2, 6 or 7) $color (grey, white, green, blue, purple, orange or yellow) $price");
226 return false;
228 if (strncmp(param1,"grey",l) == 0)
230 AuctionHouseBotCommands(6, ahMapID, AHB_GREY, param2);
232 else if (strncmp(param1,"white",l) == 0)
234 AuctionHouseBotCommands(6, ahMapID, AHB_WHITE, param2);
236 else if (strncmp(param1,"green",l) == 0)
238 AuctionHouseBotCommands(6, ahMapID, AHB_GREEN, param2);
240 else if (strncmp(param1,"blue",l) == 0)
242 AuctionHouseBotCommands(6, ahMapID, AHB_BLUE, param2);
244 else if (strncmp(param1,"purple",l) == 0)
246 AuctionHouseBotCommands(6, ahMapID, AHB_PURPLE, param2);
248 else if (strncmp(param1,"orange",l) == 0)
250 AuctionHouseBotCommands(6, ahMapID, AHB_ORANGE, param2);
252 else if (strncmp(param1,"yellow",l) == 0)
254 AuctionHouseBotCommands(6, ahMapID, AHB_YELLOW, param2);
256 else
258 PSendSysMessage("Syntax is: ahbotoptions minprice $ahMapID (2, 6 or 7) $color (grey, white, green, blue, purple, orange or yellow) $price");
259 return false;
262 else if (strncmp(opt,"maxprice",l) == 0)
264 char * param1 = strtok(NULL, " ");
265 char * param2 = strtok(NULL, " ");
266 if ((!ahMapIdStr) || (!param1) || (!param2))
268 PSendSysMessage("Syntax is: ahbotoptions maxprice $ahMapID (2, 6 or 7) $color (grey, white, green, blue, purple, orange or yellow) $price");
269 return false;
271 if (strncmp(param1,"grey",l) == 0)
273 AuctionHouseBotCommands(7, ahMapID, AHB_GREY, param2);
275 else if (strncmp(param1,"white",l) == 0)
277 AuctionHouseBotCommands(7, ahMapID, AHB_WHITE, param2);
279 else if (strncmp(param1,"green",l) == 0)
281 AuctionHouseBotCommands(7, ahMapID, AHB_GREEN, param2);
283 else if (strncmp(param1,"blue",l) == 0)
285 AuctionHouseBotCommands(7, ahMapID, AHB_BLUE, param2);
287 else if (strncmp(param1,"purple",l) == 0)
289 AuctionHouseBotCommands(7, ahMapID, AHB_PURPLE, param2);
291 else if (strncmp(param1,"orange",l) == 0)
293 AuctionHouseBotCommands(7, ahMapID, AHB_ORANGE, param2);
295 else if (strncmp(param1,"yellow",l) == 0)
297 AuctionHouseBotCommands(7, ahMapID, AHB_YELLOW, param2);
299 else
301 PSendSysMessage("Syntax is: ahbotoptions maxprice $ahMapID (2, 6 or 7) $color (grey, white, green, blue, purple, orange or yellow) $price");
302 return false;
305 else if (strncmp(opt,"minbidprice",l) == 0)
307 char * param1 = strtok(NULL, " ");
308 char * param2 = strtok(NULL, " ");
309 if ((!ahMapIdStr) || (!param1) || (!param2))
311 PSendSysMessage("Syntax is: ahbotoptions minbidprice $ahMapID (2, 6 or 7) $color (grey, white, green, blue, purple, orange or yellow) $price");
312 return false;
314 uint32 minBidPrice = (uint32) strtoul(param2, NULL, 0);
315 if ((minBidPrice < 1) || (minBidPrice > 100))
317 PSendSysMessage("The min bid price multiplier must be between 1 and 100");
318 return false;
320 if (strncmp(param1,"grey",l) == 0)
322 AuctionHouseBotCommands(8, ahMapID, AHB_GREY, param2);
324 else if (strncmp(param1,"white",l) == 0)
326 AuctionHouseBotCommands(8, ahMapID, AHB_WHITE, param2);
328 else if (strncmp(param1,"green",l) == 0)
330 AuctionHouseBotCommands(8, ahMapID, AHB_GREEN, param2);
332 else if (strncmp(param1,"blue",l) == 0)
334 AuctionHouseBotCommands(8, ahMapID, AHB_BLUE, param2);
336 else if (strncmp(param1,"purple",l) == 0)
338 AuctionHouseBotCommands(8, ahMapID, AHB_PURPLE, param2);
340 else if (strncmp(param1,"orange",l) == 0)
342 AuctionHouseBotCommands(8, ahMapID, AHB_ORANGE, param2);
344 else if (strncmp(param1,"yellow",l) == 0)
346 AuctionHouseBotCommands(8, ahMapID, AHB_YELLOW, param2);
348 else
350 PSendSysMessage("Syntax is: ahbotoptions minbidprice $ahMapID (2, 6 or 7) $color (grey, white, green, blue, purple, orange or yellow) $price");
351 return false;
354 else if (strncmp(opt,"maxbidprice",l) == 0)
356 char * param1 = strtok(NULL, " ");
357 char * param2 = strtok(NULL, " ");
358 if ((!ahMapIdStr) || (!param1) || (!param2))
360 PSendSysMessage("Syntax is: ahbotoptions maxbidprice $ahMapID (2, 6 or 7) $color (grey, white, green, blue, purple, orange or yellow) $price");
361 return false;
363 uint32 maxBidPrice = (uint32) strtoul(param2, NULL, 0);
364 if ((maxBidPrice < 1) || (maxBidPrice > 100))
366 PSendSysMessage("The max bid price multiplier must be between 1 and 100");
367 return false;
369 if (strncmp(param1,"grey",l) == 0)
371 AuctionHouseBotCommands(9, ahMapID, AHB_GREY, param2);
373 else if (strncmp(param1,"white",l) == 0)
375 AuctionHouseBotCommands(9, ahMapID, AHB_WHITE, param2);
377 else if (strncmp(param1,"green",l) == 0)
379 AuctionHouseBotCommands(9, ahMapID, AHB_GREEN, param2);
381 else if (strncmp(param1,"blue",l) == 0)
383 AuctionHouseBotCommands(9, ahMapID, AHB_BLUE, param2);
385 else if (strncmp(param1,"purple",l) == 0)
387 AuctionHouseBotCommands(9, ahMapID, AHB_PURPLE, param2);
389 else if (strncmp(param1,"orange",l) == 0)
391 AuctionHouseBotCommands(9, ahMapID, AHB_ORANGE, param2);
393 else if (strncmp(param1,"yellow",l) == 0)
395 AuctionHouseBotCommands(9, ahMapID, AHB_YELLOW, param2);
397 else
399 PSendSysMessage("Syntax is: ahbotoptions max bidprice $ahMapID (2, 6 or 7) $color (grey, white, green, blue, purple, orange or yellow) $price");
400 return false;
403 else if (strncmp(opt,"maxstack",l) == 0)
405 char * param1 = strtok(NULL, " ");
406 char * param2 = strtok(NULL, " ");
407 if ((!ahMapIdStr) || (!param1) || (!param2))
409 PSendSysMessage("Syntax is: ahbotoptions maxstack $ahMapID (2, 6 or 7) $color (grey, white, green, blue, purple, orange or yellow) $value");
410 return false;
412 uint32 maxStack = (uint32) strtoul(param2, NULL, 0);
413 if (maxStack < 0)
415 PSendSysMessage("maxstack can't be a negative number.");
416 return false;
418 if (strncmp(param1,"grey",l) == 0)
420 AuctionHouseBotCommands(10, ahMapID, AHB_GREY, param2);
422 else if (strncmp(param1,"white",l) == 0)
424 AuctionHouseBotCommands(10, ahMapID, AHB_WHITE, param2);
426 else if (strncmp(param1,"green",l) == 0)
428 AuctionHouseBotCommands(10, ahMapID, AHB_GREEN, param2);
430 else if (strncmp(param1,"blue",l) == 0)
432 AuctionHouseBotCommands(10, ahMapID, AHB_BLUE, param2);
434 else if (strncmp(param1,"purple",l) == 0)
436 AuctionHouseBotCommands(10, ahMapID, AHB_PURPLE, param2);
438 else if (strncmp(param1,"orange",l) == 0)
440 AuctionHouseBotCommands(10, ahMapID, AHB_ORANGE, param2);
442 else if (strncmp(param1,"yellow",l) == 0)
444 AuctionHouseBotCommands(10, ahMapID, AHB_YELLOW, param2);
446 else
448 PSendSysMessage("Syntax is: ahbotoptions maxstack $ahMapID (2, 6 or 7) $color (grey, white, green, blue, purple, orange or yellow) $value");
449 return false;
452 else if (strncmp(opt,"buyerprice",l) == 0)
454 char * param1 = strtok(NULL, " ");
455 char * param2 = strtok(NULL, " ");
456 if ((!ahMapIdStr) || (!param1) || (!param2))
458 PSendSysMessage("Syntax is: ahbotoptions buyerprice $ahMapID (2, 6 or 7) $color (grey, white, green, blue or purple) $price");
459 return false;
461 if (strncmp(param1,"grey",l) == 0)
463 AuctionHouseBotCommands(11, ahMapID, AHB_GREY, param2);
465 else if (strncmp(param1,"white",l) == 0)
467 AuctionHouseBotCommands(11, ahMapID, AHB_WHITE, param2);
469 else if (strncmp(param1,"green",l) == 0)
471 AuctionHouseBotCommands(11, ahMapID, AHB_GREEN, param2);
473 else if (strncmp(param1,"blue",l) == 0)
475 AuctionHouseBotCommands(11, ahMapID, AHB_BLUE, param2);
477 else if (strncmp(param1,"purple",l) == 0)
479 AuctionHouseBotCommands(11, ahMapID, AHB_PURPLE, param2);
481 else if (strncmp(param1,"orange",l) == 0)
483 AuctionHouseBotCommands(11, ahMapID, AHB_ORANGE, param2);
485 else if (strncmp(param1,"yellow",l) == 0)
487 AuctionHouseBotCommands(11, ahMapID, AHB_YELLOW, param2);
489 else
491 PSendSysMessage("Syntax is: ahbotoptions buyerprice $ahMapID (2, 6 or 7) $color (grey, white, green, blue or purple) $price");
492 return false;
495 else if (strncmp(opt,"bidinterval",l) == 0)
497 char * param1 = strtok(NULL, " ");
498 if ((!ahMapIdStr) || (!param1))
500 PSendSysMessage("Syntax is: ahbotoptions bidinterval $ahMapID (2, 6 or 7) $interval(in minutes)");
501 return false;
503 AuctionHouseBotCommands(12, ahMapID, NULL, param1);
505 else if (strncmp(opt,"bidsperinterval",l) == 0)
507 char * param1 = strtok(NULL, " ");
508 if ((!ahMapIdStr) || (!param1))
510 PSendSysMessage("Syntax is: ahbotoptions bidsperinterval $ahMapID (2, 6 or 7) $bids");
511 return false;
513 AuctionHouseBotCommands(13, ahMapID, NULL, param1);
515 else
517 PSendSysMessage("Syntax is: ahbotoptions $option $ahMapID (2, 6 or 7) $parameter");
518 PSendSysMessage("Try ahbotoptions help to see a list of options.");
519 return false;
521 return true;
524 //reload commands
525 bool ChatHandler::HandleReloadAllCommand(const char*)
527 HandleReloadSkillFishingBaseLevelCommand("");
529 HandleReloadAllAchievementCommand("");
530 HandleReloadAllAreaCommand("");
531 HandleReloadAllLootCommand("");
532 HandleReloadAllNpcCommand("");
533 HandleReloadAllQuestCommand("");
534 HandleReloadAllSpellCommand("");
535 HandleReloadAllItemCommand("");
536 HandleReloadAllLocalesCommand("");
538 HandleReloadCommandCommand("");
539 HandleReloadReservedNameCommand("");
540 HandleReloadMangosStringCommand("");
541 HandleReloadGameTeleCommand("");
542 return true;
545 bool ChatHandler::HandleReloadAllAchievementCommand(const char*)
547 HandleReloadAchievementCriteriaDataCommand("");
548 HandleReloadAchievementRewardCommand("");
549 return true;
552 bool ChatHandler::HandleReloadAllAreaCommand(const char*)
554 //HandleReloadQuestAreaTriggersCommand(""); -- reloaded in HandleReloadAllQuestCommand
555 HandleReloadAreaTriggerTeleportCommand("");
556 HandleReloadAreaTriggerTavernCommand("");
557 HandleReloadGameGraveyardZoneCommand("");
558 return true;
561 bool ChatHandler::HandleReloadAllLootCommand(const char*)
563 sLog.outString( "Re-Loading Loot Tables..." );
564 LoadLootTables();
565 SendGlobalSysMessage("DB tables `*_loot_template` reloaded.");
566 return true;
569 bool ChatHandler::HandleReloadAllNpcCommand(const char* /*args*/)
571 HandleReloadNpcGossipCommand("a");
572 HandleReloadNpcOptionCommand("a");
573 HandleReloadNpcTrainerCommand("a");
574 HandleReloadNpcVendorCommand("a");
575 HandleReloadPointsOfInterestCommand("a");
576 HandleReloadSpellClickSpellsCommand("a");
577 return true;
580 bool ChatHandler::HandleReloadAllQuestCommand(const char* /*args*/)
582 HandleReloadQuestAreaTriggersCommand("a");
583 HandleReloadQuestTemplateCommand("a");
585 sLog.outString( "Re-Loading Quests Relations..." );
586 objmgr.LoadQuestRelations();
587 SendGlobalSysMessage("DB tables `*_questrelation` and `*_involvedrelation` reloaded.");
588 return true;
591 bool ChatHandler::HandleReloadAllScriptsCommand(const char*)
593 if(sWorld.IsScriptScheduled())
595 PSendSysMessage("DB scripts used currently, please attempt reload later.");
596 SetSentErrorMessage(true);
597 return false;
600 sLog.outString( "Re-Loading Scripts..." );
601 HandleReloadGameObjectScriptsCommand("a");
602 HandleReloadEventScriptsCommand("a");
603 HandleReloadQuestEndScriptsCommand("a");
604 HandleReloadQuestStartScriptsCommand("a");
605 HandleReloadSpellScriptsCommand("a");
606 SendGlobalSysMessage("DB tables `*_scripts` reloaded.");
607 HandleReloadDbScriptStringCommand("a");
608 return true;
611 bool ChatHandler::HandleReloadAllSpellCommand(const char*)
613 HandleReloadSkillDiscoveryTemplateCommand("a");
614 HandleReloadSkillExtraItemTemplateCommand("a");
615 HandleReloadSpellAffectCommand("a");
616 HandleReloadSpellAreaCommand("a");
617 HandleReloadSpellChainCommand("a");
618 HandleReloadSpellElixirCommand("a");
619 HandleReloadSpellLearnSpellCommand("a");
620 HandleReloadSpellProcEventCommand("a");
621 HandleReloadSpellBonusesCommand("a");
622 HandleReloadSpellScriptTargetCommand("a");
623 HandleReloadSpellTargetPositionCommand("a");
624 HandleReloadSpellThreatsCommand("a");
625 HandleReloadSpellPetAurasCommand("a");
626 return true;
629 bool ChatHandler::HandleReloadAllItemCommand(const char*)
631 HandleReloadPageTextsCommand("a");
632 HandleReloadItemEnchantementsCommand("a");
633 return true;
636 bool ChatHandler::HandleReloadAllLocalesCommand(const char* /*args*/)
638 HandleReloadLocalesAchievementRewardCommand("a");
639 HandleReloadLocalesCreatureCommand("a");
640 HandleReloadLocalesGameobjectCommand("a");
641 HandleReloadLocalesItemCommand("a");
642 HandleReloadLocalesNpcTextCommand("a");
643 HandleReloadLocalesPageTextCommand("a");
644 HandleReloadLocalesPointsOfInterestCommand("a");
645 HandleReloadLocalesQuestCommand("a");
646 return true;
649 bool ChatHandler::HandleReloadConfigCommand(const char* /*args*/)
651 sLog.outString( "Re-Loading config settings..." );
652 sWorld.LoadConfigSettings(true);
653 SendGlobalSysMessage("World config settings reloaded.");
654 return true;
657 bool ChatHandler::HandleReloadAchievementCriteriaDataCommand(const char*)
659 sLog.outString( "Re-Loading Additional Achievement Criteria Data..." );
660 achievementmgr.LoadAchievementCriteriaData();
661 SendGlobalSysMessage("DB table `achievement_criteria_data` reloaded.");
662 return true;
665 bool ChatHandler::HandleReloadAchievementRewardCommand(const char*)
667 sLog.outString( "Re-Loading Achievement Reward Data..." );
668 achievementmgr.LoadRewards();
669 SendGlobalSysMessage("DB table `achievement_reward` reloaded.");
670 return true;
673 bool ChatHandler::HandleReloadAreaTriggerTavernCommand(const char*)
675 sLog.outString( "Re-Loading Tavern Area Triggers..." );
676 objmgr.LoadTavernAreaTriggers();
677 SendGlobalSysMessage("DB table `areatrigger_tavern` reloaded.");
678 return true;
681 bool ChatHandler::HandleReloadAreaTriggerTeleportCommand(const char*)
683 sLog.outString( "Re-Loading AreaTrigger teleport definitions..." );
684 objmgr.LoadAreaTriggerTeleports();
685 SendGlobalSysMessage("DB table `areatrigger_teleport` reloaded.");
686 return true;
689 bool ChatHandler::HandleReloadCommandCommand(const char*)
691 load_command_table = true;
692 SendGlobalSysMessage("DB table `command` will be reloaded at next chat command use.");
693 return true;
696 bool ChatHandler::HandleReloadCreatureQuestRelationsCommand(const char*)
698 sLog.outString( "Loading Quests Relations... (`creature_questrelation`)" );
699 objmgr.LoadCreatureQuestRelations();
700 SendGlobalSysMessage("DB table `creature_questrelation` (creature quest givers) reloaded.");
701 return true;
704 bool ChatHandler::HandleReloadCreatureQuestInvRelationsCommand(const char*)
706 sLog.outString( "Loading Quests Relations... (`creature_involvedrelation`)" );
707 objmgr.LoadCreatureInvolvedRelations();
708 SendGlobalSysMessage("DB table `creature_involvedrelation` (creature quest takers) reloaded.");
709 return true;
712 bool ChatHandler::HandleReloadGOQuestRelationsCommand(const char*)
714 sLog.outString( "Loading Quests Relations... (`gameobject_questrelation`)" );
715 objmgr.LoadGameobjectQuestRelations();
716 SendGlobalSysMessage("DB table `gameobject_questrelation` (gameobject quest givers) reloaded.");
717 return true;
720 bool ChatHandler::HandleReloadGOQuestInvRelationsCommand(const char*)
722 sLog.outString( "Loading Quests Relations... (`gameobject_involvedrelation`)" );
723 objmgr.LoadGameobjectInvolvedRelations();
724 SendGlobalSysMessage("DB table `gameobject_involvedrelation` (gameobject quest takers) reloaded.");
725 return true;
728 bool ChatHandler::HandleReloadQuestAreaTriggersCommand(const char*)
730 sLog.outString( "Re-Loading Quest Area Triggers..." );
731 objmgr.LoadQuestAreaTriggers();
732 SendGlobalSysMessage("DB table `areatrigger_involvedrelation` (quest area triggers) reloaded.");
733 return true;
736 bool ChatHandler::HandleReloadQuestTemplateCommand(const char*)
738 sLog.outString( "Re-Loading Quest Templates..." );
739 objmgr.LoadQuests();
740 SendGlobalSysMessage("DB table `quest_template` (quest definitions) reloaded.");
742 /// dependent also from `gameobject` but this table not reloaded anyway
743 sLog.outString( "Re-Loading GameObjects for quests..." );
744 objmgr.LoadGameObjectForQuests();
745 SendGlobalSysMessage("Data GameObjects for quests reloaded.");
746 return true;
749 bool ChatHandler::HandleReloadLootTemplatesCreatureCommand(const char*)
751 sLog.outString( "Re-Loading Loot Tables... (`creature_loot_template`)" );
752 LoadLootTemplates_Creature();
753 LootTemplates_Creature.CheckLootRefs();
754 SendGlobalSysMessage("DB table `creature_loot_template` reloaded.");
755 return true;
758 bool ChatHandler::HandleReloadLootTemplatesDisenchantCommand(const char*)
760 sLog.outString( "Re-Loading Loot Tables... (`disenchant_loot_template`)" );
761 LoadLootTemplates_Disenchant();
762 LootTemplates_Disenchant.CheckLootRefs();
763 SendGlobalSysMessage("DB table `disenchant_loot_template` reloaded.");
764 return true;
767 bool ChatHandler::HandleReloadLootTemplatesFishingCommand(const char*)
769 sLog.outString( "Re-Loading Loot Tables... (`fishing_loot_template`)" );
770 LoadLootTemplates_Fishing();
771 LootTemplates_Fishing.CheckLootRefs();
772 SendGlobalSysMessage("DB table `fishing_loot_template` reloaded.");
773 return true;
776 bool ChatHandler::HandleReloadLootTemplatesGameobjectCommand(const char*)
778 sLog.outString( "Re-Loading Loot Tables... (`gameobject_loot_template`)" );
779 LoadLootTemplates_Gameobject();
780 LootTemplates_Gameobject.CheckLootRefs();
781 SendGlobalSysMessage("DB table `gameobject_loot_template` reloaded.");
782 return true;
785 bool ChatHandler::HandleReloadLootTemplatesItemCommand(const char*)
787 sLog.outString( "Re-Loading Loot Tables... (`item_loot_template`)" );
788 LoadLootTemplates_Item();
789 LootTemplates_Item.CheckLootRefs();
790 SendGlobalSysMessage("DB table `item_loot_template` reloaded.");
791 return true;
794 bool ChatHandler::HandleReloadLootTemplatesMillingCommand(const char*)
796 sLog.outString( "Re-Loading Loot Tables... (`milling_loot_template`)" );
797 LoadLootTemplates_Milling();
798 LootTemplates_Milling.CheckLootRefs();
799 SendGlobalSysMessage("DB table `milling_loot_template` reloaded.");
800 return true;
803 bool ChatHandler::HandleReloadLootTemplatesPickpocketingCommand(const char*)
805 sLog.outString( "Re-Loading Loot Tables... (`pickpocketing_loot_template`)" );
806 LoadLootTemplates_Pickpocketing();
807 LootTemplates_Pickpocketing.CheckLootRefs();
808 SendGlobalSysMessage("DB table `pickpocketing_loot_template` reloaded.");
809 return true;
812 bool ChatHandler::HandleReloadLootTemplatesProspectingCommand(const char*)
814 sLog.outString( "Re-Loading Loot Tables... (`prospecting_loot_template`)" );
815 LoadLootTemplates_Prospecting();
816 LootTemplates_Prospecting.CheckLootRefs();
817 SendGlobalSysMessage("DB table `prospecting_loot_template` reloaded.");
818 return true;
821 bool ChatHandler::HandleReloadLootTemplatesQuestMailCommand(const char*)
823 sLog.outString( "Re-Loading Loot Tables... (`quest_mail_loot_template`)" );
824 LoadLootTemplates_QuestMail();
825 LootTemplates_QuestMail.CheckLootRefs();
826 SendGlobalSysMessage("DB table `quest_mail_loot_template` reloaded.");
827 return true;
830 bool ChatHandler::HandleReloadLootTemplatesReferenceCommand(const char*)
832 sLog.outString( "Re-Loading Loot Tables... (`reference_loot_template`)" );
833 LoadLootTemplates_Reference();
834 SendGlobalSysMessage("DB table `reference_loot_template` reloaded.");
835 return true;
838 bool ChatHandler::HandleReloadLootTemplatesSkinningCommand(const char*)
840 sLog.outString( "Re-Loading Loot Tables... (`skinning_loot_template`)" );
841 LoadLootTemplates_Skinning();
842 LootTemplates_Skinning.CheckLootRefs();
843 SendGlobalSysMessage("DB table `skinning_loot_template` reloaded.");
844 return true;
847 bool ChatHandler::HandleReloadLootTemplatesSpellCommand(const char*)
849 sLog.outString( "Re-Loading Loot Tables... (`spell_loot_template`)" );
850 LoadLootTemplates_Spell();
851 LootTemplates_Spell.CheckLootRefs();
852 SendGlobalSysMessage("DB table `spell_loot_template` reloaded.");
853 return true;
856 bool ChatHandler::HandleReloadMangosStringCommand(const char*)
858 sLog.outString( "Re-Loading mangos_string Table!" );
859 objmgr.LoadMangosStrings();
860 SendGlobalSysMessage("DB table `mangos_string` reloaded.");
861 return true;
864 bool ChatHandler::HandleReloadNpcOptionCommand(const char*)
866 sLog.outString( "Re-Loading `npc_option` Table!" );
867 objmgr.LoadNpcOptions();
868 SendGlobalSysMessage("DB table `npc_option` reloaded.");
869 return true;
872 bool ChatHandler::HandleReloadNpcGossipCommand(const char*)
874 sLog.outString( "Re-Loading `npc_gossip` Table!" );
875 objmgr.LoadNpcTextId();
876 SendGlobalSysMessage("DB table `npc_gossip` reloaded.");
877 return true;
880 bool ChatHandler::HandleReloadNpcTrainerCommand(const char*)
882 sLog.outString( "Re-Loading `npc_trainer` Table!" );
883 objmgr.LoadTrainerSpell();
884 SendGlobalSysMessage("DB table `npc_trainer` reloaded.");
885 return true;
888 bool ChatHandler::HandleReloadNpcVendorCommand(const char*)
890 sLog.outString( "Re-Loading `npc_vendor` Table!" );
891 objmgr.LoadVendors();
892 SendGlobalSysMessage("DB table `npc_vendor` reloaded.");
893 return true;
896 bool ChatHandler::HandleReloadPointsOfInterestCommand(const char*)
898 sLog.outString( "Re-Loading `points_of_interest` Table!" );
899 objmgr.LoadPointsOfInterest();
900 SendGlobalSysMessage("DB table `points_of_interest` reloaded.");
901 return true;
904 bool ChatHandler::HandleReloadSpellClickSpellsCommand(const char*)
906 sLog.outString( "Re-Loading `npc_spellclick_spells` Table!" );
907 objmgr.LoadNPCSpellClickSpells();
908 SendGlobalSysMessage("DB table `npc_spellclick_spells` reloaded.");
909 return true;
912 bool ChatHandler::HandleReloadReservedNameCommand(const char*)
914 sLog.outString( "Loading ReservedNames... (`reserved_name`)" );
915 objmgr.LoadReservedPlayersNames();
916 SendGlobalSysMessage("DB table `reserved_name` (player reserved names) reloaded.");
917 return true;
920 bool ChatHandler::HandleReloadSkillDiscoveryTemplateCommand(const char* /*args*/)
922 sLog.outString( "Re-Loading Skill Discovery Table..." );
923 LoadSkillDiscoveryTable();
924 SendGlobalSysMessage("DB table `skill_discovery_template` (recipes discovered at crafting) reloaded.");
925 return true;
928 bool ChatHandler::HandleReloadSkillExtraItemTemplateCommand(const char* /*args*/)
930 sLog.outString( "Re-Loading Skill Extra Item Table..." );
931 LoadSkillExtraItemTable();
932 SendGlobalSysMessage("DB table `skill_extra_item_template` (extra item creation when crafting) reloaded.");
933 return true;
936 bool ChatHandler::HandleReloadSkillFishingBaseLevelCommand(const char* /*args*/)
938 sLog.outString( "Re-Loading Skill Fishing base level requirements..." );
939 objmgr.LoadFishingBaseSkillLevel();
940 SendGlobalSysMessage("DB table `skill_fishing_base_level` (fishing base level for zone/subzone) reloaded.");
941 return true;
944 bool ChatHandler::HandleReloadSpellAffectCommand(const char*)
946 sLog.outString( "Re-Loading SpellAffect definitions..." );
947 spellmgr.LoadSpellAffects();
948 SendGlobalSysMessage("DB table `spell_affect` (spell mods apply requirements) reloaded.");
949 return true;
952 bool ChatHandler::HandleReloadSpellAreaCommand(const char*)
954 sLog.outString( "Re-Loading SpellArea Data..." );
955 spellmgr.LoadSpellAreas();
956 SendGlobalSysMessage("DB table `spell_area` (spell dependences from area/quest/auras state) reloaded.");
957 return true;
960 bool ChatHandler::HandleReloadSpellChainCommand(const char*)
962 sLog.outString( "Re-Loading Spell Chain Data... " );
963 spellmgr.LoadSpellChains();
964 SendGlobalSysMessage("DB table `spell_chain` (spell ranks) reloaded.");
965 return true;
968 bool ChatHandler::HandleReloadSpellElixirCommand(const char*)
970 sLog.outString( "Re-Loading Spell Elixir types..." );
971 spellmgr.LoadSpellElixirs();
972 SendGlobalSysMessage("DB table `spell_elixir` (spell elixir types) reloaded.");
973 return true;
976 bool ChatHandler::HandleReloadSpellLearnSpellCommand(const char*)
978 sLog.outString( "Re-Loading Spell Learn Spells..." );
979 spellmgr.LoadSpellLearnSpells();
980 SendGlobalSysMessage("DB table `spell_learn_spell` reloaded.");
981 return true;
984 bool ChatHandler::HandleReloadSpellProcEventCommand(const char*)
986 sLog.outString( "Re-Loading Spell Proc Event conditions..." );
987 spellmgr.LoadSpellProcEvents();
988 SendGlobalSysMessage("DB table `spell_proc_event` (spell proc trigger requirements) reloaded.");
989 return true;
992 bool ChatHandler::HandleReloadSpellBonusesCommand(const char*)
994 sLog.outString( "Re-Loading Spell Bonus Data..." );
995 spellmgr.LoadSpellBonusess();
996 SendGlobalSysMessage("DB table `spell_bonus_data` (spell damage/healing coefficients) reloaded.");
997 return true;
1000 bool ChatHandler::HandleReloadSpellScriptTargetCommand(const char*)
1002 sLog.outString( "Re-Loading SpellsScriptTarget..." );
1003 spellmgr.LoadSpellScriptTarget();
1004 SendGlobalSysMessage("DB table `spell_script_target` (spell targets selection in case specific creature/GO requirements) reloaded.");
1005 return true;
1008 bool ChatHandler::HandleReloadSpellTargetPositionCommand(const char*)
1010 sLog.outString( "Re-Loading Spell target coordinates..." );
1011 spellmgr.LoadSpellTargetPositions();
1012 SendGlobalSysMessage("DB table `spell_target_position` (destination coordinates for spell targets) reloaded.");
1013 return true;
1016 bool ChatHandler::HandleReloadSpellThreatsCommand(const char*)
1018 sLog.outString( "Re-Loading Aggro Spells Definitions...");
1019 spellmgr.LoadSpellThreats();
1020 SendGlobalSysMessage("DB table `spell_threat` (spell aggro definitions) reloaded.");
1021 return true;
1024 bool ChatHandler::HandleReloadSpellPetAurasCommand(const char*)
1026 sLog.outString( "Re-Loading Spell pet auras...");
1027 spellmgr.LoadSpellPetAuras();
1028 SendGlobalSysMessage("DB table `spell_pet_auras` reloaded.");
1029 return true;
1032 bool ChatHandler::HandleReloadPageTextsCommand(const char*)
1034 sLog.outString( "Re-Loading Page Texts..." );
1035 objmgr.LoadPageTexts();
1036 SendGlobalSysMessage("DB table `page_texts` reloaded.");
1037 return true;
1040 bool ChatHandler::HandleReloadItemEnchantementsCommand(const char*)
1042 sLog.outString( "Re-Loading Item Random Enchantments Table..." );
1043 LoadRandomEnchantmentsTable();
1044 SendGlobalSysMessage("DB table `item_enchantment_template` reloaded.");
1045 return true;
1048 bool ChatHandler::HandleReloadGameObjectScriptsCommand(const char* arg)
1050 if(sWorld.IsScriptScheduled())
1052 SendSysMessage("DB scripts used currently, please attempt reload later.");
1053 SetSentErrorMessage(true);
1054 return false;
1057 if(*arg!='a')
1058 sLog.outString( "Re-Loading Scripts from `gameobject_scripts`...");
1060 objmgr.LoadGameObjectScripts();
1062 if(*arg!='a')
1063 SendGlobalSysMessage("DB table `gameobject_scripts` reloaded.");
1065 return true;
1068 bool ChatHandler::HandleReloadEventScriptsCommand(const char* arg)
1070 if(sWorld.IsScriptScheduled())
1072 SendSysMessage("DB scripts used currently, please attempt reload later.");
1073 SetSentErrorMessage(true);
1074 return false;
1077 if(*arg!='a')
1078 sLog.outString( "Re-Loading Scripts from `event_scripts`...");
1080 objmgr.LoadEventScripts();
1082 if(*arg!='a')
1083 SendGlobalSysMessage("DB table `event_scripts` reloaded.");
1085 return true;
1088 bool ChatHandler::HandleReloadQuestEndScriptsCommand(const char* arg)
1090 if(sWorld.IsScriptScheduled())
1092 SendSysMessage("DB scripts used currently, please attempt reload later.");
1093 SetSentErrorMessage(true);
1094 return false;
1097 if(*arg!='a')
1098 sLog.outString( "Re-Loading Scripts from `quest_end_scripts`...");
1100 objmgr.LoadQuestEndScripts();
1102 if(*arg!='a')
1103 SendGlobalSysMessage("DB table `quest_end_scripts` reloaded.");
1105 return true;
1108 bool ChatHandler::HandleReloadQuestStartScriptsCommand(const char* arg)
1110 if(sWorld.IsScriptScheduled())
1112 SendSysMessage("DB scripts used currently, please attempt reload later.");
1113 SetSentErrorMessage(true);
1114 return false;
1117 if(*arg!='a')
1118 sLog.outString( "Re-Loading Scripts from `quest_start_scripts`...");
1120 objmgr.LoadQuestStartScripts();
1122 if(*arg!='a')
1123 SendGlobalSysMessage("DB table `quest_start_scripts` reloaded.");
1125 return true;
1128 bool ChatHandler::HandleReloadSpellScriptsCommand(const char* arg)
1130 if(sWorld.IsScriptScheduled())
1132 SendSysMessage("DB scripts used currently, please attempt reload later.");
1133 SetSentErrorMessage(true);
1134 return false;
1137 if(*arg!='a')
1138 sLog.outString( "Re-Loading Scripts from `spell_scripts`...");
1140 objmgr.LoadSpellScripts();
1142 if(*arg!='a')
1143 SendGlobalSysMessage("DB table `spell_scripts` reloaded.");
1145 return true;
1148 bool ChatHandler::HandleReloadDbScriptStringCommand(const char* /*arg*/)
1150 sLog.outString( "Re-Loading Script strings from `db_script_string`...");
1151 objmgr.LoadDbScriptStrings();
1152 SendGlobalSysMessage("DB table `db_script_string` reloaded.");
1153 return true;
1156 bool ChatHandler::HandleReloadGameGraveyardZoneCommand(const char* /*arg*/)
1158 sLog.outString( "Re-Loading Graveyard-zone links...");
1160 objmgr.LoadGraveyardZones();
1162 SendGlobalSysMessage("DB table `game_graveyard_zone` reloaded.");
1164 return true;
1167 bool ChatHandler::HandleReloadGameTeleCommand(const char* /*arg*/)
1169 sLog.outString( "Re-Loading Game Tele coordinates...");
1171 objmgr.LoadGameTele();
1173 SendGlobalSysMessage("DB table `game_tele` reloaded.");
1175 return true;
1178 bool ChatHandler::HandleReloadLocalesAchievementRewardCommand(const char*)
1180 sLog.outString( "Re-Loading Locales Achievement Reward Data..." );
1181 achievementmgr.LoadRewardLocales();
1182 SendGlobalSysMessage("DB table `locales_achievement_reward` reloaded.");
1183 return true;
1186 bool ChatHandler::HandleReloadLocalesCreatureCommand(const char* /*arg*/)
1188 sLog.outString( "Re-Loading Locales Creature ...");
1189 objmgr.LoadCreatureLocales();
1190 SendGlobalSysMessage("DB table `locales_creature` reloaded.");
1191 return true;
1194 bool ChatHandler::HandleReloadLocalesGameobjectCommand(const char* /*arg*/)
1196 sLog.outString( "Re-Loading Locales Gameobject ... ");
1197 objmgr.LoadGameObjectLocales();
1198 SendGlobalSysMessage("DB table `locales_gameobject` reloaded.");
1199 return true;
1202 bool ChatHandler::HandleReloadLocalesItemCommand(const char* /*arg*/)
1204 sLog.outString( "Re-Loading Locales Item ... ");
1205 objmgr.LoadItemLocales();
1206 SendGlobalSysMessage("DB table `locales_item` reloaded.");
1207 return true;
1210 bool ChatHandler::HandleReloadLocalesNpcTextCommand(const char* /*arg*/)
1212 sLog.outString( "Re-Loading Locales NPC Text ... ");
1213 objmgr.LoadNpcTextLocales();
1214 SendGlobalSysMessage("DB table `locales_npc_text` reloaded.");
1215 return true;
1218 bool ChatHandler::HandleReloadLocalesPageTextCommand(const char* /*arg*/)
1220 sLog.outString( "Re-Loading Locales Page Text ... ");
1221 objmgr.LoadPageTextLocales();
1222 SendGlobalSysMessage("DB table `locales_page_text` reloaded.");
1223 return true;
1226 bool ChatHandler::HandleReloadLocalesPointsOfInterestCommand(const char* /*arg*/)
1228 sLog.outString( "Re-Loading Locales Points Of Interest ... ");
1229 objmgr.LoadPointOfInterestLocales();
1230 SendGlobalSysMessage("DB table `locales_points_of_interest` reloaded.");
1231 return true;
1234 bool ChatHandler::HandleReloadLocalesQuestCommand(const char* /*arg*/)
1236 sLog.outString( "Re-Loading Locales Quest ... ");
1237 objmgr.LoadQuestLocales();
1238 SendGlobalSysMessage("DB table `locales_quest` reloaded.");
1239 return true;
1242 bool ChatHandler::HandleLoadScriptsCommand(const char* args)
1244 if(!LoadScriptingModule(args)) return true;
1246 sWorld.SendWorldText(LANG_SCRIPTS_RELOADED);
1247 return true;
1250 bool ChatHandler::HandleAccountSetGmLevelCommand(const char* args)
1252 char* arg1 = strtok((char*)args, " ");
1253 if( !arg1 )
1254 return false;
1256 /// must be NULL if targeted syntax and must be not nULL if not targeted
1257 char* arg2 = strtok(NULL, " ");
1259 std::string targetAccountName;
1260 uint32 targetAccountId = 0;
1262 /// only target player different from self allowed (if targetPlayer!=NULL then not console)
1263 Player* targetPlayer = getSelectedPlayer();
1264 if(targetPlayer && m_session->GetPlayer()!=targetPlayer)
1266 /// wrong command syntax or unexpected targeting
1267 if(arg2)
1268 return false;
1270 /// security level expected in arg2 after this if.
1271 arg2 = arg1;
1273 targetAccountId = targetPlayer->GetSession()->GetAccountId();
1274 accmgr.GetName(targetAccountId, targetAccountName);
1276 else
1278 /// wrong command syntax (second arg expected)
1279 if(!arg2)
1280 return false;
1282 targetAccountName = arg1;
1283 if(!AccountMgr::normilizeString(targetAccountName))
1285 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,targetAccountName.c_str());
1286 SetSentErrorMessage(true);
1287 return false;
1290 targetAccountId = accmgr.GetId(targetAccountName);
1291 if(!targetAccountId)
1293 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,targetAccountName.c_str());
1294 SetSentErrorMessage(true);
1295 return false;
1299 int32 gm = (int32)atoi(arg2);
1300 if ( gm < SEC_PLAYER || gm > SEC_ADMINISTRATOR )
1302 SendSysMessage(LANG_BAD_VALUE);
1303 SetSentErrorMessage(true);
1304 return false;
1307 /// can set security level only for target with less security and to less security that we have
1308 /// This will reject self apply by specify account name
1309 if(HasLowerSecurityAccount(NULL,targetAccountId,true))
1310 return false;
1312 /// account can't set security to same or grater level, need more power GM or console
1313 AccountTypes plSecurity = m_session ? m_session->GetSecurity() : SEC_CONSOLE;
1314 if (AccountTypes(gm) >= plSecurity )
1316 SendSysMessage(LANG_YOURS_SECURITY_IS_LOW);
1317 SetSentErrorMessage(true);
1318 return false;
1321 // This will prevent self apply by self target or no target
1322 if(targetPlayer && m_session->GetPlayer()!=targetPlayer)
1324 ChatHandler(targetPlayer).PSendSysMessage(LANG_YOURS_SECURITY_CHANGED,GetNameLink().c_str(), gm);
1325 targetPlayer->GetSession()->SetSecurity(AccountTypes(gm));
1328 PSendSysMessage(LANG_YOU_CHANGE_SECURITY, targetAccountName.c_str(), gm);
1329 loginDatabase.PExecute("UPDATE account SET gmlevel = '%i' WHERE id = '%u'", gm, targetAccountId);
1331 return true;
1334 /// Set password for account
1335 bool ChatHandler::HandleAccountSetPasswordCommand(const char* args)
1337 if(!*args)
1338 return false;
1340 ///- Get the command line arguments
1341 char *szAccount = strtok ((char*)args," ");
1342 char *szPassword1 = strtok (NULL," ");
1343 char *szPassword2 = strtok (NULL," ");
1345 if (!szAccount||!szPassword1 || !szPassword2)
1346 return false;
1348 std::string account_name = szAccount;
1349 if(!AccountMgr::normilizeString(account_name))
1351 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
1352 SetSentErrorMessage(true);
1353 return false;
1356 uint32 targetAccountId = accmgr.GetId(account_name);
1357 if (!targetAccountId)
1359 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
1360 SetSentErrorMessage(true);
1361 return false;
1364 /// can set password only for target with less security
1365 /// This is also reject self apply in fact
1366 if(HasLowerSecurityAccount (NULL,targetAccountId,true))
1367 return false;
1369 if (strcmp(szPassword1,szPassword2))
1371 SendSysMessage (LANG_NEW_PASSWORDS_NOT_MATCH);
1372 SetSentErrorMessage (true);
1373 return false;
1376 AccountOpResult result = accmgr.ChangePassword(targetAccountId, szPassword1);
1378 switch(result)
1380 case AOR_OK:
1381 SendSysMessage(LANG_COMMAND_PASSWORD);
1382 break;
1383 case AOR_NAME_NOT_EXIST:
1384 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
1385 SetSentErrorMessage(true);
1386 return false;
1387 case AOR_PASS_TOO_LONG:
1388 SendSysMessage(LANG_PASSWORD_TOO_LONG);
1389 SetSentErrorMessage(true);
1390 return false;
1391 default:
1392 SendSysMessage(LANG_COMMAND_NOTCHANGEPASSWORD);
1393 SetSentErrorMessage(true);
1394 return false;
1397 return true;
1400 bool ChatHandler::HandleMaxSkillCommand(const char* /*args*/)
1402 Player* SelectedPlayer = getSelectedPlayer();
1403 if(!SelectedPlayer)
1405 SendSysMessage(LANG_NO_CHAR_SELECTED);
1406 SetSentErrorMessage(true);
1407 return false;
1410 // each skills that have max skill value dependent from level seted to current level max skill value
1411 SelectedPlayer->UpdateSkillsToMaxSkillsForLevel();
1412 return true;
1415 bool ChatHandler::HandleSetSkillCommand(const char* args)
1417 // number or [name] Shift-click form |color|Hskill:skill_id|h[name]|h|r
1418 char* skill_p = extractKeyFromLink((char*)args,"Hskill");
1419 if(!skill_p)
1420 return false;
1422 char *level_p = strtok (NULL, " ");
1424 if( !level_p)
1425 return false;
1427 char *max_p = strtok (NULL, " ");
1429 int32 skill = atoi(skill_p);
1430 if (skill <= 0)
1432 PSendSysMessage(LANG_INVALID_SKILL_ID, skill);
1433 SetSentErrorMessage(true);
1434 return false;
1437 int32 level = atol (level_p);
1439 Player * target = getSelectedPlayer();
1440 if(!target)
1442 SendSysMessage(LANG_NO_CHAR_SELECTED);
1443 SetSentErrorMessage(true);
1444 return false;
1447 SkillLineEntry const* sl = sSkillLineStore.LookupEntry(skill);
1448 if(!sl)
1450 PSendSysMessage(LANG_INVALID_SKILL_ID, skill);
1451 SetSentErrorMessage(true);
1452 return false;
1455 std::string tNameLink = GetNameLink(target);
1457 if(!target->GetSkillValue(skill))
1459 PSendSysMessage(LANG_SET_SKILL_ERROR, tNameLink.c_str(), skill, sl->name[0]);
1460 SetSentErrorMessage(true);
1461 return false;
1464 int32 max = max_p ? atol (max_p) : target->GetPureMaxSkillValue(skill);
1466 if( level <= 0 || level > max || max <= 0 )
1467 return false;
1469 target->SetSkill(skill, level, max);
1470 PSendSysMessage(LANG_SET_SKILL, skill, sl->name[0], tNameLink.c_str(), level, max);
1472 return true;
1475 bool ChatHandler::HandleUnLearnCommand(const char* args)
1477 if (!*args)
1478 return false;
1480 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
1481 uint32 spell_id = extractSpellIdFromLink((char*)args);
1482 if(!spell_id)
1483 return false;
1485 char const* allStr = strtok(NULL," ");
1486 bool allRanks = allStr ? (strncmp(allStr, "all", strlen(allStr)) == 0) : false;
1488 Player* target = getSelectedPlayer();
1489 if(!target)
1491 SendSysMessage(LANG_NO_CHAR_SELECTED);
1492 SetSentErrorMessage(true);
1493 return false;
1496 if(allRanks)
1497 spell_id = spellmgr.GetFirstSpellInChain (spell_id);
1499 if (target->HasSpell(spell_id))
1500 target->removeSpell(spell_id,false,!allRanks);
1501 else
1502 SendSysMessage(LANG_FORGET_SPELL);
1504 return true;
1507 bool ChatHandler::HandleCooldownCommand(const char* args)
1509 Player* target = getSelectedPlayer();
1510 if(!target)
1512 SendSysMessage(LANG_PLAYER_NOT_FOUND);
1513 SetSentErrorMessage(true);
1514 return false;
1517 std::string tNameLink = GetNameLink(target);
1519 if (!*args)
1521 target->RemoveAllSpellCooldown();
1522 PSendSysMessage(LANG_REMOVEALL_COOLDOWN, tNameLink.c_str());
1524 else
1526 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
1527 uint32 spell_id = extractSpellIdFromLink((char*)args);
1528 if(!spell_id)
1529 return false;
1531 if(!sSpellStore.LookupEntry(spell_id))
1533 PSendSysMessage(LANG_UNKNOWN_SPELL, target==m_session->GetPlayer() ? GetMangosString(LANG_YOU) : tNameLink.c_str());
1534 SetSentErrorMessage(true);
1535 return false;
1538 WorldPacket data( SMSG_CLEAR_COOLDOWN, (4+8) );
1539 data << uint32(spell_id);
1540 data << uint64(target->GetGUID());
1541 target->GetSession()->SendPacket(&data);
1542 target->RemoveSpellCooldown(spell_id);
1543 PSendSysMessage(LANG_REMOVE_COOLDOWN, spell_id, target==m_session->GetPlayer() ? GetMangosString(LANG_YOU) : tNameLink.c_str());
1545 return true;
1548 bool ChatHandler::HandleLearnAllCommand(const char* /*args*/)
1550 static const char *allSpellList[] =
1552 "3365",
1553 "6233",
1554 "6247",
1555 "6246",
1556 "6477",
1557 "6478",
1558 "22810",
1559 "8386",
1560 "21651",
1561 "21652",
1562 "522",
1563 "7266",
1564 "8597",
1565 "2479",
1566 "22027",
1567 "6603",
1568 "5019",
1569 "133",
1570 "168",
1571 "227",
1572 "5009",
1573 "9078",
1574 "668",
1575 "203",
1576 "20599",
1577 "20600",
1578 "81",
1579 "20597",
1580 "20598",
1581 "20864",
1582 "1459",
1583 "5504",
1584 "587",
1585 "5143",
1586 "118",
1587 "5505",
1588 "597",
1589 "604",
1590 "1449",
1591 "1460",
1592 "2855",
1593 "1008",
1594 "475",
1595 "5506",
1596 "1463",
1597 "12824",
1598 "8437",
1599 "990",
1600 "5145",
1601 "8450",
1602 "1461",
1603 "759",
1604 "8494",
1605 "8455",
1606 "8438",
1607 "6127",
1608 "8416",
1609 "6129",
1610 "8451",
1611 "8495",
1612 "8439",
1613 "3552",
1614 "8417",
1615 "10138",
1616 "12825",
1617 "10169",
1618 "10156",
1619 "10144",
1620 "10191",
1621 "10201",
1622 "10211",
1623 "10053",
1624 "10173",
1625 "10139",
1626 "10145",
1627 "10192",
1628 "10170",
1629 "10202",
1630 "10054",
1631 "10174",
1632 "10193",
1633 "12826",
1634 "2136",
1635 "143",
1636 "145",
1637 "2137",
1638 "2120",
1639 "3140",
1640 "543",
1641 "2138",
1642 "2948",
1643 "8400",
1644 "2121",
1645 "8444",
1646 "8412",
1647 "8457",
1648 "8401",
1649 "8422",
1650 "8445",
1651 "8402",
1652 "8413",
1653 "8458",
1654 "8423",
1655 "8446",
1656 "10148",
1657 "10197",
1658 "10205",
1659 "10149",
1660 "10215",
1661 "10223",
1662 "10206",
1663 "10199",
1664 "10150",
1665 "10216",
1666 "10207",
1667 "10225",
1668 "10151",
1669 "116",
1670 "205",
1671 "7300",
1672 "122",
1673 "837",
1674 "10",
1675 "7301",
1676 "7322",
1677 "6143",
1678 "120",
1679 "865",
1680 "8406",
1681 "6141",
1682 "7302",
1683 "8461",
1684 "8407",
1685 "8492",
1686 "8427",
1687 "8408",
1688 "6131",
1689 "7320",
1690 "10159",
1691 "8462",
1692 "10185",
1693 "10179",
1694 "10160",
1695 "10180",
1696 "10219",
1697 "10186",
1698 "10177",
1699 "10230",
1700 "10181",
1701 "10161",
1702 "10187",
1703 "10220",
1704 "2018",
1705 "2663",
1706 "12260",
1707 "2660",
1708 "3115",
1709 "3326",
1710 "2665",
1711 "3116",
1712 "2738",
1713 "3293",
1714 "2661",
1715 "3319",
1716 "2662",
1717 "9983",
1718 "8880",
1719 "2737",
1720 "2739",
1721 "7408",
1722 "3320",
1723 "2666",
1724 "3323",
1725 "3324",
1726 "3294",
1727 "22723",
1728 "23219",
1729 "23220",
1730 "23221",
1731 "23228",
1732 "23338",
1733 "10788",
1734 "10790",
1735 "5611",
1736 "5016",
1737 "5609",
1738 "2060",
1739 "10963",
1740 "10964",
1741 "10965",
1742 "22593",
1743 "22594",
1744 "596",
1745 "996",
1746 "499",
1747 "768",
1748 "17002",
1749 "1448",
1750 "1082",
1751 "16979",
1752 "1079",
1753 "5215",
1754 "20484",
1755 "5221",
1756 "15590",
1757 "17007",
1758 "6795",
1759 "6807",
1760 "5487",
1761 "1446",
1762 "1066",
1763 "5421",
1764 "3139",
1765 "779",
1766 "6811",
1767 "6808",
1768 "1445",
1769 "5216",
1770 "1737",
1771 "5222",
1772 "5217",
1773 "1432",
1774 "6812",
1775 "9492",
1776 "5210",
1777 "3030",
1778 "1441",
1779 "783",
1780 "6801",
1781 "20739",
1782 "8944",
1783 "9491",
1784 "22569",
1785 "5226",
1786 "6786",
1787 "1433",
1788 "8973",
1789 "1828",
1790 "9495",
1791 "9006",
1792 "6794",
1793 "8993",
1794 "5203",
1795 "16914",
1796 "6784",
1797 "9635",
1798 "22830",
1799 "20722",
1800 "9748",
1801 "6790",
1802 "9753",
1803 "9493",
1804 "9752",
1805 "9831",
1806 "9825",
1807 "9822",
1808 "5204",
1809 "5401",
1810 "22831",
1811 "6793",
1812 "9845",
1813 "17401",
1814 "9882",
1815 "9868",
1816 "20749",
1817 "9893",
1818 "9899",
1819 "9895",
1820 "9832",
1821 "9902",
1822 "9909",
1823 "22832",
1824 "9828",
1825 "9851",
1826 "9883",
1827 "9869",
1828 "17406",
1829 "17402",
1830 "9914",
1831 "20750",
1832 "9897",
1833 "9848",
1834 "3127",
1835 "107",
1836 "204",
1837 "9116",
1838 "2457",
1839 "78",
1840 "18848",
1841 "331",
1842 "403",
1843 "2098",
1844 "1752",
1845 "11278",
1846 "11288",
1847 "11284",
1848 "6461",
1849 "2344",
1850 "2345",
1851 "6463",
1852 "2346",
1853 "2352",
1854 "775",
1855 "1434",
1856 "1612",
1857 "71",
1858 "2468",
1859 "2458",
1860 "2467",
1861 "7164",
1862 "7178",
1863 "7367",
1864 "7376",
1865 "7381",
1866 "21156",
1867 "5209",
1868 "3029",
1869 "5201",
1870 "9849",
1871 "9850",
1872 "20719",
1873 "22568",
1874 "22827",
1875 "22828",
1876 "22829",
1877 "6809",
1878 "8972",
1879 "9005",
1880 "9823",
1881 "9827",
1882 "6783",
1883 "9913",
1884 "6785",
1885 "6787",
1886 "9866",
1887 "9867",
1888 "9894",
1889 "9896",
1890 "6800",
1891 "8992",
1892 "9829",
1893 "9830",
1894 "780",
1895 "769",
1896 "6749",
1897 "6750",
1898 "9755",
1899 "9754",
1900 "9908",
1901 "20745",
1902 "20742",
1903 "20747",
1904 "20748",
1905 "9746",
1906 "9745",
1907 "9880",
1908 "9881",
1909 "5391",
1910 "842",
1911 "3025",
1912 "3031",
1913 "3287",
1914 "3329",
1915 "1945",
1916 "3559",
1917 "4933",
1918 "4934",
1919 "4935",
1920 "4936",
1921 "5142",
1922 "5390",
1923 "5392",
1924 "5404",
1925 "5420",
1926 "6405",
1927 "7293",
1928 "7965",
1929 "8041",
1930 "8153",
1931 "9033",
1932 "9034",
1933 //"9036", problems with ghost state
1934 "16421",
1935 "21653",
1936 "22660",
1937 "5225",
1938 "9846",
1939 "2426",
1940 "5916",
1941 "6634",
1942 //"6718", phasing stealth, annoying for learn all case.
1943 "6719",
1944 "8822",
1945 "9591",
1946 "9590",
1947 "10032",
1948 "17746",
1949 "17747",
1950 "8203",
1951 "11392",
1952 "12495",
1953 "16380",
1954 "23452",
1955 "4079",
1956 "4996",
1957 "4997",
1958 "4998",
1959 "4999",
1960 "5000",
1961 "6348",
1962 "6349",
1963 "6481",
1964 "6482",
1965 "6483",
1966 "6484",
1967 "11362",
1968 "11410",
1969 "11409",
1970 "12510",
1971 "12509",
1972 "12885",
1973 "13142",
1974 "21463",
1975 "23460",
1976 "11421",
1977 "11416",
1978 "11418",
1979 "1851",
1980 "10059",
1981 "11423",
1982 "11417",
1983 "11422",
1984 "11419",
1985 "11424",
1986 "11420",
1987 "27",
1988 "31",
1989 "33",
1990 "34",
1991 "35",
1992 "15125",
1993 "21127",
1994 "22950",
1995 "1180",
1996 "201",
1997 "12593",
1998 "12842",
1999 "16770",
2000 "6057",
2001 "12051",
2002 "18468",
2003 "12606",
2004 "12605",
2005 "18466",
2006 "12502",
2007 "12043",
2008 "15060",
2009 "12042",
2010 "12341",
2011 "12848",
2012 "12344",
2013 "12353",
2014 "18460",
2015 "11366",
2016 "12350",
2017 "12352",
2018 "13043",
2019 "11368",
2020 "11113",
2021 "12400",
2022 "11129",
2023 "16766",
2024 "12573",
2025 "15053",
2026 "12580",
2027 "12475",
2028 "12472",
2029 "12953",
2030 "12488",
2031 "11189",
2032 "12985",
2033 "12519",
2034 "16758",
2035 "11958",
2036 "12490",
2037 "11426",
2038 "3565",
2039 "3562",
2040 "18960",
2041 "3567",
2042 "3561",
2043 "3566",
2044 "3563",
2045 "1953",
2046 "2139",
2047 "12505",
2048 "13018",
2049 "12522",
2050 "12523",
2051 "5146",
2052 "5144",
2053 "5148",
2054 "8419",
2055 "8418",
2056 "10213",
2057 "10212",
2058 "10157",
2059 "12524",
2060 "13019",
2061 "12525",
2062 "13020",
2063 "12526",
2064 "13021",
2065 "18809",
2066 "13031",
2067 "13032",
2068 "13033",
2069 "4036",
2070 "3920",
2071 "3919",
2072 "3918",
2073 "7430",
2074 "3922",
2075 "3923",
2076 "7411",
2077 "7418",
2078 "7421",
2079 "13262",
2080 "7412",
2081 "7415",
2082 "7413",
2083 "7416",
2084 "13920",
2085 "13921",
2086 "7745",
2087 "7779",
2088 "7428",
2089 "7457",
2090 "7857",
2091 "7748",
2092 "7426",
2093 "13421",
2094 "7454",
2095 "13378",
2096 "7788",
2097 "14807",
2098 "14293",
2099 "7795",
2100 "6296",
2101 "20608",
2102 "755",
2103 "444",
2104 "427",
2105 "428",
2106 "442",
2107 "447",
2108 "3578",
2109 "3581",
2110 "19027",
2111 "3580",
2112 "665",
2113 "3579",
2114 "3577",
2115 "6755",
2116 "3576",
2117 "2575",
2118 "2577",
2119 "2578",
2120 "2579",
2121 "2580",
2122 "2656",
2123 "2657",
2124 "2576",
2125 "3564",
2126 "10248",
2127 "8388",
2128 "2659",
2129 "14891",
2130 "3308",
2131 "3307",
2132 "10097",
2133 "2658",
2134 "3569",
2135 "16153",
2136 "3304",
2137 "10098",
2138 "4037",
2139 "3929",
2140 "3931",
2141 "3926",
2142 "3924",
2143 "3930",
2144 "3977",
2145 "3925",
2146 "136",
2147 "228",
2148 "5487",
2149 "43",
2150 "202",
2154 int loop = 0;
2155 while(strcmp(allSpellList[loop], "0"))
2157 uint32 spell = atol((char*)allSpellList[loop++]);
2159 if (m_session->GetPlayer()->HasSpell(spell))
2160 continue;
2162 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
2163 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
2165 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
2166 continue;
2169 m_session->GetPlayer()->learnSpell(spell,false);
2172 SendSysMessage(LANG_COMMAND_LEARN_MANY_SPELLS);
2174 return true;
2177 bool ChatHandler::HandleLearnAllGMCommand(const char* /*args*/)
2179 static const char *gmSpellList[] =
2181 "24347", // Become A Fish, No Breath Bar
2182 "35132", // Visual Boom
2183 "38488", // Attack 4000-8000 AOE
2184 "38795", // Attack 2000 AOE + Slow Down 90%
2185 "15712", // Attack 200
2186 "1852", // GM Spell Silence
2187 "31899", // Kill
2188 "31924", // Kill
2189 "29878", // Kill My Self
2190 "26644", // More Kill
2192 "28550", //Invisible 24
2193 "23452", //Invisible + Target
2197 uint16 gmSpellIter = 0;
2198 while( strcmp(gmSpellList[gmSpellIter], "0") )
2200 uint32 spell = atol((char*)gmSpellList[gmSpellIter++]);
2202 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
2203 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
2205 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
2206 continue;
2209 m_session->GetPlayer()->learnSpell(spell,false);
2212 SendSysMessage(LANG_LEARNING_GM_SKILLS);
2213 return true;
2216 bool ChatHandler::HandleLearnAllMyClassCommand(const char* /*args*/)
2218 HandleLearnAllMySpellsCommand("");
2219 HandleLearnAllMyTalentsCommand("");
2220 return true;
2223 bool ChatHandler::HandleLearnAllMySpellsCommand(const char* /*args*/)
2225 ChrClassesEntry const* clsEntry = sChrClassesStore.LookupEntry(m_session->GetPlayer()->getClass());
2226 if(!clsEntry)
2227 return true;
2228 uint32 family = clsEntry->spellfamily;
2230 for (uint32 i = 0; i < sSpellStore.GetNumRows(); ++i)
2232 SpellEntry const *spellInfo = sSpellStore.LookupEntry(i);
2233 if(!spellInfo)
2234 continue;
2236 // skip server-side/triggered spells
2237 if(spellInfo->spellLevel==0)
2238 continue;
2240 // skip wrong class/race skills
2241 if(!m_session->GetPlayer()->IsSpellFitByClassAndRace(spellInfo->Id))
2242 continue;
2244 // skip other spell families
2245 if( spellInfo->SpellFamilyName != family)
2246 continue;
2248 // skip spells with first rank learned as talent (and all talents then also)
2249 uint32 first_rank = spellmgr.GetFirstSpellInChain(spellInfo->Id);
2250 if(GetTalentSpellCost(first_rank) > 0 )
2251 continue;
2253 // skip broken spells
2254 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer(),false))
2255 continue;
2257 m_session->GetPlayer()->learnSpell(i,false);
2260 SendSysMessage(LANG_COMMAND_LEARN_CLASS_SPELLS);
2261 return true;
2264 bool ChatHandler::HandleLearnAllMyTalentsCommand(const char* /*args*/)
2266 Player* player = m_session->GetPlayer();
2267 uint32 classMask = player->getClassMask();
2269 for (uint32 i = 0; i < sTalentStore.GetNumRows(); ++i)
2271 TalentEntry const *talentInfo = sTalentStore.LookupEntry(i);
2272 if(!talentInfo)
2273 continue;
2275 TalentTabEntry const *talentTabInfo = sTalentTabStore.LookupEntry( talentInfo->TalentTab );
2276 if(!talentTabInfo)
2277 continue;
2279 if( (classMask & talentTabInfo->ClassMask) == 0 )
2280 continue;
2282 // search highest talent rank
2283 uint32 spellid = 0;
2285 for(int rank = MAX_TALENT_RANK-1; rank >= 0; --rank)
2287 if(talentInfo->RankID[rank]!=0)
2289 spellid = talentInfo->RankID[rank];
2290 break;
2294 if(!spellid) // ??? none spells in talent
2295 continue;
2297 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spellid);
2298 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer(),false))
2299 continue;
2301 // learn highest rank of talent and learn all non-talent spell ranks (recursive by tree)
2302 player->learnSpellHighRank(spellid);
2305 SendSysMessage(LANG_COMMAND_LEARN_CLASS_TALENTS);
2306 return true;
2309 bool ChatHandler::HandleLearnAllMyPetTalentsCommand(const char* /*args*/)
2311 Player* player = m_session->GetPlayer();
2313 Pet* pet = player->GetPet();
2314 if(!pet)
2316 SendSysMessage(LANG_NO_PET_FOUND);
2317 SetSentErrorMessage(true);
2318 return false;
2321 CreatureInfo const *ci = pet->GetCreatureInfo();
2322 if(!ci)
2324 SendSysMessage(LANG_WRONG_PET_TYPE);
2325 SetSentErrorMessage(true);
2326 return false;
2329 CreatureFamilyEntry const *pet_family = sCreatureFamilyStore.LookupEntry(ci->family);
2330 if(!pet_family)
2332 SendSysMessage(LANG_WRONG_PET_TYPE);
2333 SetSentErrorMessage(true);
2334 return false;
2337 if(pet_family->petTalentType < 0) // not hunter pet
2339 SendSysMessage(LANG_WRONG_PET_TYPE);
2340 SetSentErrorMessage(true);
2341 return false;
2344 for (uint32 i = 0; i < sTalentStore.GetNumRows(); ++i)
2346 TalentEntry const *talentInfo = sTalentStore.LookupEntry(i);
2347 if(!talentInfo)
2348 continue;
2350 TalentTabEntry const *talentTabInfo = sTalentTabStore.LookupEntry( talentInfo->TalentTab );
2351 if(!talentTabInfo)
2352 continue;
2354 // prevent learn talent for different family (cheating)
2355 if(((1 << pet_family->petTalentType) & talentTabInfo->petTalentMask)==0)
2356 continue;
2358 // search highest talent rank
2359 uint32 spellid = 0;
2361 for(int rank = MAX_TALENT_RANK-1; rank >= 0; --rank)
2363 if(talentInfo->RankID[rank]!=0)
2365 spellid = talentInfo->RankID[rank];
2366 break;
2370 if(!spellid) // ??? none spells in talent
2371 continue;
2373 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spellid);
2374 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer(),false))
2375 continue;
2377 // learn highest rank of talent and learn all non-talent spell ranks (recursive by tree)
2378 pet->learnSpellHighRank(spellid);
2381 SendSysMessage(LANG_COMMAND_LEARN_PET_TALENTS);
2382 return true;
2385 bool ChatHandler::HandleLearnAllLangCommand(const char* /*args*/)
2387 // skipping UNIVERSAL language (0)
2388 for(int i = 1; i < LANGUAGES_COUNT; ++i)
2389 m_session->GetPlayer()->learnSpell(lang_description[i].spell_id,false);
2391 SendSysMessage(LANG_COMMAND_LEARN_ALL_LANG);
2392 return true;
2395 bool ChatHandler::HandleLearnAllDefaultCommand(const char* args)
2397 Player *player = NULL;
2398 if (*args)
2400 std::string name = extractPlayerNameFromLink((char*)args);
2401 if(name.empty())
2403 SendSysMessage(LANG_PLAYER_NOT_FOUND);
2404 SetSentErrorMessage(true);
2405 return false;
2408 player = objmgr.GetPlayer(name.c_str());
2410 else
2411 player = getSelectedPlayer();
2413 if(!player)
2415 SendSysMessage(LANG_NO_CHAR_SELECTED);
2416 SetSentErrorMessage(true);
2417 return false;
2420 player->learnDefaultSpells();
2421 player->learnQuestRewardedSpells();
2423 PSendSysMessage(LANG_COMMAND_LEARN_ALL_DEFAULT_AND_QUEST,GetNameLink(player).c_str());
2424 return true;
2427 bool ChatHandler::HandleLearnCommand(const char* args)
2429 Player* targetPlayer = getSelectedPlayer();
2431 if(!targetPlayer)
2433 SendSysMessage(LANG_PLAYER_NOT_FOUND);
2434 SetSentErrorMessage(true);
2435 return false;
2438 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
2439 uint32 spell = extractSpellIdFromLink((char*)args);
2440 if(!spell || !sSpellStore.LookupEntry(spell))
2441 return false;
2443 char const* allStr = strtok(NULL," ");
2444 bool allRanks = allStr ? (strncmp(allStr, "all", strlen(allStr)) == 0) : false;
2446 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
2447 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
2449 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
2450 SetSentErrorMessage(true);
2451 return false;
2454 if (!allRanks && targetPlayer->HasSpell(spell))
2456 if(targetPlayer == m_session->GetPlayer())
2457 SendSysMessage(LANG_YOU_KNOWN_SPELL);
2458 else
2459 PSendSysMessage(LANG_TARGET_KNOWN_SPELL,GetNameLink(targetPlayer).c_str());
2460 SetSentErrorMessage(true);
2461 return false;
2464 if(allRanks)
2465 targetPlayer->learnSpellHighRank(spell);
2466 else
2467 targetPlayer->learnSpell(spell,false);
2469 return true;
2472 bool ChatHandler::HandleAddItemCommand(const char* args)
2474 if (!*args)
2475 return false;
2477 uint32 itemId = 0;
2479 if(args[0]=='[') // [name] manual form
2481 char* citemName = strtok((char*)args, "]");
2483 if(citemName && citemName[0])
2485 std::string itemName = citemName+1;
2486 WorldDatabase.escape_string(itemName);
2487 QueryResult *result = WorldDatabase.PQuery("SELECT entry FROM item_template WHERE name = '%s'", itemName.c_str());
2488 if (!result)
2490 PSendSysMessage(LANG_COMMAND_COULDNOTFIND, citemName+1);
2491 SetSentErrorMessage(true);
2492 return false;
2494 itemId = result->Fetch()->GetUInt16();
2495 delete result;
2497 else
2498 return false;
2500 else // item_id or [name] Shift-click form |color|Hitem:item_id:0:0:0|h[name]|h|r
2502 char* cId = extractKeyFromLink((char*)args,"Hitem");
2503 if(!cId)
2504 return false;
2505 itemId = atol(cId);
2508 char* ccount = strtok(NULL, " ");
2510 int32 count = 1;
2512 if (ccount)
2513 count = strtol(ccount, NULL, 10);
2515 if (count == 0)
2516 count = 1;
2518 Player* pl = m_session->GetPlayer();
2519 Player* plTarget = getSelectedPlayer();
2520 if(!plTarget)
2521 plTarget = pl;
2523 sLog.outDetail(GetMangosString(LANG_ADDITEM), itemId, count);
2525 ItemPrototype const *pProto = objmgr.GetItemPrototype(itemId);
2526 if(!pProto)
2528 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, itemId);
2529 SetSentErrorMessage(true);
2530 return false;
2533 //Subtract
2534 if (count < 0)
2536 plTarget->DestroyItemCount(itemId, -count, true, false);
2537 PSendSysMessage(LANG_REMOVEITEM, itemId, -count, GetNameLink(plTarget).c_str());
2538 return true;
2541 //Adding items
2542 uint32 noSpaceForCount = 0;
2544 // check space and find places
2545 ItemPosCountVec dest;
2546 uint8 msg = plTarget->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, itemId, count, &noSpaceForCount );
2547 if( msg != EQUIP_ERR_OK ) // convert to possible store amount
2548 count -= noSpaceForCount;
2550 if( count == 0 || dest.empty()) // can't add any
2552 PSendSysMessage(LANG_ITEM_CANNOT_CREATE, itemId, noSpaceForCount );
2553 SetSentErrorMessage(true);
2554 return false;
2557 Item* item = plTarget->StoreNewItem( dest, itemId, true, Item::GenerateItemRandomPropertyId(itemId));
2559 // remove binding (let GM give it to another player later)
2560 if(pl==plTarget)
2561 for(ItemPosCountVec::const_iterator itr = dest.begin(); itr != dest.end(); ++itr)
2562 if(Item* item1 = pl->GetItemByPos(itr->pos))
2563 item1->SetBinding( false );
2565 if(count > 0 && item)
2567 pl->SendNewItem(item,count,false,true);
2568 if(pl!=plTarget)
2569 plTarget->SendNewItem(item,count,true,false);
2572 if(noSpaceForCount > 0)
2573 PSendSysMessage(LANG_ITEM_CANNOT_CREATE, itemId, noSpaceForCount);
2575 return true;
2578 bool ChatHandler::HandleAddItemSetCommand(const char* args)
2580 if (!*args)
2581 return false;
2583 char* cId = extractKeyFromLink((char*)args,"Hitemset"); // number or [name] Shift-click form |color|Hitemset:itemset_id|h[name]|h|r
2584 if (!cId)
2585 return false;
2587 uint32 itemsetId = atol(cId);
2589 // prevent generation all items with itemset field value '0'
2590 if (itemsetId == 0)
2592 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND,itemsetId);
2593 SetSentErrorMessage(true);
2594 return false;
2597 Player* pl = m_session->GetPlayer();
2598 Player* plTarget = getSelectedPlayer();
2599 if(!plTarget)
2600 plTarget = pl;
2602 sLog.outDetail(GetMangosString(LANG_ADDITEMSET), itemsetId);
2604 bool found = false;
2605 for (uint32 id = 0; id < sItemStorage.MaxEntry; id++)
2607 ItemPrototype const *pProto = sItemStorage.LookupEntry<ItemPrototype>(id);
2608 if (!pProto)
2609 continue;
2611 if (pProto->ItemSet == itemsetId)
2613 found = true;
2614 ItemPosCountVec dest;
2615 uint8 msg = plTarget->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, pProto->ItemId, 1 );
2616 if (msg == EQUIP_ERR_OK)
2618 Item* item = plTarget->StoreNewItem( dest, pProto->ItemId, true);
2620 // remove binding (let GM give it to another player later)
2621 if (pl==plTarget)
2622 item->SetBinding( false );
2624 pl->SendNewItem(item,1,false,true);
2625 if (pl!=plTarget)
2626 plTarget->SendNewItem(item,1,true,false);
2628 else
2630 pl->SendEquipError( msg, NULL, NULL );
2631 PSendSysMessage(LANG_ITEM_CANNOT_CREATE, pProto->ItemId, 1);
2636 if (!found)
2638 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND,itemsetId);
2640 SetSentErrorMessage(true);
2641 return false;
2644 return true;
2647 bool ChatHandler::HandleListItemCommand(const char* args)
2649 if(!*args)
2650 return false;
2652 char* cId = extractKeyFromLink((char*)args,"Hitem");
2653 if(!cId)
2654 return false;
2656 uint32 item_id = atol(cId);
2657 if(!item_id)
2659 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, item_id);
2660 SetSentErrorMessage(true);
2661 return false;
2664 ItemPrototype const* itemProto = objmgr.GetItemPrototype(item_id);
2665 if(!itemProto)
2667 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, item_id);
2668 SetSentErrorMessage(true);
2669 return false;
2672 char* c_count = strtok(NULL, " ");
2673 int count = c_count ? atol(c_count) : 10;
2675 if(count < 0)
2676 return false;
2678 QueryResult *result;
2680 // inventory case
2681 uint32 inv_count = 0;
2682 result=CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM character_inventory WHERE item_template='%u'",item_id);
2683 if(result)
2685 inv_count = (*result)[0].GetUInt32();
2686 delete result;
2689 result=CharacterDatabase.PQuery(
2690 // 0 1 2 3 4 5
2691 "SELECT ci.item, cibag.slot AS bag, ci.slot, ci.guid, characters.account,characters.name "
2692 "FROM character_inventory AS ci LEFT JOIN character_inventory AS cibag ON (cibag.item=ci.bag),characters "
2693 "WHERE ci.item_template='%u' AND ci.guid = characters.guid LIMIT %u ",
2694 item_id,uint32(count));
2696 if(result)
2700 Field *fields = result->Fetch();
2701 uint32 item_guid = fields[0].GetUInt32();
2702 uint32 item_bag = fields[1].GetUInt32();
2703 uint32 item_slot = fields[2].GetUInt32();
2704 uint32 owner_guid = fields[3].GetUInt32();
2705 uint32 owner_acc = fields[4].GetUInt32();
2706 std::string owner_name = fields[5].GetCppString();
2708 char const* item_pos = 0;
2709 if(Player::IsEquipmentPos(item_bag,item_slot))
2710 item_pos = "[equipped]";
2711 else if(Player::IsInventoryPos(item_bag,item_slot))
2712 item_pos = "[in inventory]";
2713 else if(Player::IsBankPos(item_bag,item_slot))
2714 item_pos = "[in bank]";
2715 else
2716 item_pos = "";
2718 PSendSysMessage(LANG_ITEMLIST_SLOT,
2719 item_guid,owner_name.c_str(),owner_guid,owner_acc,item_pos);
2720 } while (result->NextRow());
2722 int64 res_count = result->GetRowCount();
2724 delete result;
2726 if(count > res_count)
2727 count-=res_count;
2728 else if(count)
2729 count = 0;
2732 // mail case
2733 uint32 mail_count = 0;
2734 result=CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM mail_items WHERE item_template='%u'", item_id);
2735 if(result)
2737 mail_count = (*result)[0].GetUInt32();
2738 delete result;
2741 if(count > 0)
2743 result=CharacterDatabase.PQuery(
2744 // 0 1 2 3 4 5 6
2745 "SELECT mail_items.item_guid, mail.sender, mail.receiver, char_s.account, char_s.name, char_r.account, char_r.name "
2746 "FROM mail,mail_items,characters as char_s,characters as char_r "
2747 "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",
2748 item_id,uint32(count));
2750 else
2751 result = NULL;
2753 if(result)
2757 Field *fields = result->Fetch();
2758 uint32 item_guid = fields[0].GetUInt32();
2759 uint32 item_s = fields[1].GetUInt32();
2760 uint32 item_r = fields[2].GetUInt32();
2761 uint32 item_s_acc = fields[3].GetUInt32();
2762 std::string item_s_name = fields[4].GetCppString();
2763 uint32 item_r_acc = fields[5].GetUInt32();
2764 std::string item_r_name = fields[6].GetCppString();
2766 char const* item_pos = "[in mail]";
2768 PSendSysMessage(LANG_ITEMLIST_MAIL,
2769 item_guid,item_s_name.c_str(),item_s,item_s_acc,item_r_name.c_str(),item_r,item_r_acc,item_pos);
2770 } while (result->NextRow());
2772 int64 res_count = result->GetRowCount();
2774 delete result;
2776 if(count > res_count)
2777 count-=res_count;
2778 else if(count)
2779 count = 0;
2782 // auction case
2783 uint32 auc_count = 0;
2784 result=CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM auctionhouse WHERE item_template='%u'",item_id);
2785 if(result)
2787 auc_count = (*result)[0].GetUInt32();
2788 delete result;
2791 if(count > 0)
2793 result=CharacterDatabase.PQuery(
2794 // 0 1 2 3
2795 "SELECT auctionhouse.itemguid, auctionhouse.itemowner, characters.account, characters.name "
2796 "FROM auctionhouse,characters WHERE auctionhouse.item_template='%u' AND characters.guid = auctionhouse.itemowner LIMIT %u",
2797 item_id,uint32(count));
2799 else
2800 result = NULL;
2802 if(result)
2806 Field *fields = result->Fetch();
2807 uint32 item_guid = fields[0].GetUInt32();
2808 uint32 owner = fields[1].GetUInt32();
2809 uint32 owner_acc = fields[2].GetUInt32();
2810 std::string owner_name = fields[3].GetCppString();
2812 char const* item_pos = "[in auction]";
2814 PSendSysMessage(LANG_ITEMLIST_AUCTION, item_guid, owner_name.c_str(), owner, owner_acc,item_pos);
2815 } while (result->NextRow());
2817 delete result;
2820 // guild bank case
2821 uint32 guild_count = 0;
2822 result=CharacterDatabase.PQuery("SELECT COUNT(item_entry) FROM guild_bank_item WHERE item_entry='%u'",item_id);
2823 if(result)
2825 guild_count = (*result)[0].GetUInt32();
2826 delete result;
2829 result=CharacterDatabase.PQuery(
2830 // 0 1 2
2831 "SELECT gi.item_guid, gi.guildid, guild.name "
2832 "FROM guild_bank_item AS gi, guild WHERE gi.item_entry='%u' AND gi.guildid = guild.guildid LIMIT %u ",
2833 item_id,uint32(count));
2835 if(result)
2839 Field *fields = result->Fetch();
2840 uint32 item_guid = fields[0].GetUInt32();
2841 uint32 guild_guid = fields[1].GetUInt32();
2842 std::string guild_name = fields[2].GetCppString();
2844 char const* item_pos = "[in guild bank]";
2846 PSendSysMessage(LANG_ITEMLIST_GUILD,item_guid,guild_name.c_str(),guild_guid,item_pos);
2847 } while (result->NextRow());
2849 int64 res_count = result->GetRowCount();
2851 delete result;
2853 if(count > res_count)
2854 count-=res_count;
2855 else if(count)
2856 count = 0;
2859 if(inv_count+mail_count+auc_count+guild_count == 0)
2861 SendSysMessage(LANG_COMMAND_NOITEMFOUND);
2862 SetSentErrorMessage(true);
2863 return false;
2866 PSendSysMessage(LANG_COMMAND_LISTITEMMESSAGE,item_id,inv_count+mail_count+auc_count+guild_count,inv_count,mail_count,auc_count,guild_count);
2868 return true;
2871 bool ChatHandler::HandleListObjectCommand(const char* args)
2873 if(!*args)
2874 return false;
2876 // number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
2877 char* cId = extractKeyFromLink((char*)args,"Hgameobject_entry");
2878 if(!cId)
2879 return false;
2881 uint32 go_id = atol(cId);
2882 if(!go_id)
2884 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID, go_id);
2885 SetSentErrorMessage(true);
2886 return false;
2889 GameObjectInfo const * gInfo = objmgr.GetGameObjectInfo(go_id);
2890 if(!gInfo)
2892 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID, go_id);
2893 SetSentErrorMessage(true);
2894 return false;
2897 char* c_count = strtok(NULL, " ");
2898 int count = c_count ? atol(c_count) : 10;
2900 if(count < 0)
2901 return false;
2903 QueryResult *result;
2905 uint32 obj_count = 0;
2906 result=WorldDatabase.PQuery("SELECT COUNT(guid) FROM gameobject WHERE id='%u'",go_id);
2907 if(result)
2909 obj_count = (*result)[0].GetUInt32();
2910 delete result;
2913 if(m_session)
2915 Player* pl = m_session->GetPlayer();
2916 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 gameobject WHERE id = '%u' ORDER BY order_ ASC LIMIT %u",
2917 pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(),go_id,uint32(count));
2919 else
2920 result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map FROM gameobject WHERE id = '%u' LIMIT %u",
2921 go_id,uint32(count));
2923 if (result)
2927 Field *fields = result->Fetch();
2928 uint32 guid = fields[0].GetUInt32();
2929 float x = fields[1].GetFloat();
2930 float y = fields[2].GetFloat();
2931 float z = fields[3].GetFloat();
2932 int mapid = fields[4].GetUInt16();
2934 if (m_session)
2935 PSendSysMessage(LANG_GO_LIST_CHAT, guid, guid, gInfo->name, x, y, z, mapid);
2936 else
2937 PSendSysMessage(LANG_GO_LIST_CONSOLE, guid, gInfo->name, x, y, z, mapid);
2938 } while (result->NextRow());
2940 delete result;
2943 PSendSysMessage(LANG_COMMAND_LISTOBJMESSAGE,go_id,obj_count);
2944 return true;
2947 bool ChatHandler::HandleListCreatureCommand(const char* args)
2949 if(!*args)
2950 return false;
2952 // number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r
2953 char* cId = extractKeyFromLink((char*)args,"Hcreature_entry");
2954 if(!cId)
2955 return false;
2957 uint32 cr_id = atol(cId);
2958 if(!cr_id)
2960 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID, cr_id);
2961 SetSentErrorMessage(true);
2962 return false;
2965 CreatureInfo const* cInfo = objmgr.GetCreatureTemplate(cr_id);
2966 if(!cInfo)
2968 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID, cr_id);
2969 SetSentErrorMessage(true);
2970 return false;
2973 char* c_count = strtok(NULL, " ");
2974 int count = c_count ? atol(c_count) : 10;
2976 if(count < 0)
2977 return false;
2979 QueryResult *result;
2981 uint32 cr_count = 0;
2982 result=WorldDatabase.PQuery("SELECT COUNT(guid) FROM creature WHERE id='%u'",cr_id);
2983 if(result)
2985 cr_count = (*result)[0].GetUInt32();
2986 delete result;
2989 if(m_session)
2991 Player* pl = m_session->GetPlayer();
2992 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",
2993 pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(), cr_id,uint32(count));
2995 else
2996 result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map FROM creature WHERE id = '%u' LIMIT %u",
2997 cr_id,uint32(count));
2999 if (result)
3003 Field *fields = result->Fetch();
3004 uint32 guid = fields[0].GetUInt32();
3005 float x = fields[1].GetFloat();
3006 float y = fields[2].GetFloat();
3007 float z = fields[3].GetFloat();
3008 int mapid = fields[4].GetUInt16();
3010 if (m_session)
3011 PSendSysMessage(LANG_CREATURE_LIST_CHAT, guid, guid, cInfo->Name, x, y, z, mapid);
3012 else
3013 PSendSysMessage(LANG_CREATURE_LIST_CONSOLE, guid, cInfo->Name, x, y, z, mapid);
3014 } while (result->NextRow());
3016 delete result;
3019 PSendSysMessage(LANG_COMMAND_LISTCREATUREMESSAGE,cr_id,cr_count);
3020 return true;
3023 bool ChatHandler::HandleLookupItemCommand(const char* args)
3025 if(!*args)
3026 return false;
3028 std::string namepart = args;
3029 std::wstring wnamepart;
3031 // converting string that we try to find to lower case
3032 if(!Utf8toWStr(namepart,wnamepart))
3033 return false;
3035 wstrToLower(wnamepart);
3037 uint32 counter = 0;
3039 // Search in `item_template`
3040 for (uint32 id = 0; id < sItemStorage.MaxEntry; id++)
3042 ItemPrototype const *pProto = sItemStorage.LookupEntry<ItemPrototype >(id);
3043 if(!pProto)
3044 continue;
3046 int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex();
3047 if ( loc_idx >= 0 )
3049 ItemLocale const *il = objmgr.GetItemLocale(pProto->ItemId);
3050 if (il)
3052 if (il->Name.size() > loc_idx && !il->Name[loc_idx].empty())
3054 std::string name = il->Name[loc_idx];
3056 if (Utf8FitTo(name, wnamepart))
3058 if (m_session)
3059 PSendSysMessage(LANG_ITEM_LIST_CHAT, id, id, name.c_str());
3060 else
3061 PSendSysMessage(LANG_ITEM_LIST_CONSOLE, id, name.c_str());
3062 ++counter;
3063 continue;
3069 std::string name = pProto->Name1;
3070 if(name.empty())
3071 continue;
3073 if (Utf8FitTo(name, wnamepart))
3075 if (m_session)
3076 PSendSysMessage(LANG_ITEM_LIST_CHAT, id, id, name.c_str());
3077 else
3078 PSendSysMessage(LANG_ITEM_LIST_CONSOLE, id, name.c_str());
3079 ++counter;
3083 if (counter==0)
3084 SendSysMessage(LANG_COMMAND_NOITEMFOUND);
3086 return true;
3089 bool ChatHandler::HandleLookupItemSetCommand(const char* args)
3091 if(!*args)
3092 return false;
3094 std::string namepart = args;
3095 std::wstring wnamepart;
3097 if(!Utf8toWStr(namepart,wnamepart))
3098 return false;
3100 // converting string that we try to find to lower case
3101 wstrToLower( wnamepart );
3103 uint32 counter = 0; // Counter for figure out that we found smth.
3105 // Search in ItemSet.dbc
3106 for (uint32 id = 0; id < sItemSetStore.GetNumRows(); id++)
3108 ItemSetEntry const *set = sItemSetStore.LookupEntry(id);
3109 if(set)
3111 int loc = m_session ? m_session->GetSessionDbcLocale() : sWorld.GetDefaultDbcLocale();
3112 std::string name = set->name[loc];
3113 if(name.empty())
3114 continue;
3116 if (!Utf8FitTo(name, wnamepart))
3118 loc = 0;
3119 for(; loc < MAX_LOCALE; ++loc)
3121 if(m_session && loc==m_session->GetSessionDbcLocale())
3122 continue;
3124 name = set->name[loc];
3125 if(name.empty())
3126 continue;
3128 if (Utf8FitTo(name, wnamepart))
3129 break;
3133 if(loc < MAX_LOCALE)
3135 // send item set in "id - [namedlink locale]" format
3136 if (m_session)
3137 PSendSysMessage(LANG_ITEMSET_LIST_CHAT,id,id,name.c_str(),localeNames[loc]);
3138 else
3139 PSendSysMessage(LANG_ITEMSET_LIST_CONSOLE,id,name.c_str(),localeNames[loc]);
3140 ++counter;
3144 if (counter == 0) // if counter == 0 then we found nth
3145 SendSysMessage(LANG_COMMAND_NOITEMSETFOUND);
3146 return true;
3149 bool ChatHandler::HandleLookupSkillCommand(const char* args)
3151 if(!*args)
3152 return false;
3154 // can be NULL in console call
3155 Player* target = getSelectedPlayer();
3157 std::string namepart = args;
3158 std::wstring wnamepart;
3160 if(!Utf8toWStr(namepart,wnamepart))
3161 return false;
3163 // converting string that we try to find to lower case
3164 wstrToLower( wnamepart );
3166 uint32 counter = 0; // Counter for figure out that we found smth.
3168 // Search in SkillLine.dbc
3169 for (uint32 id = 0; id < sSkillLineStore.GetNumRows(); id++)
3171 SkillLineEntry const *skillInfo = sSkillLineStore.LookupEntry(id);
3172 if(skillInfo)
3174 int loc = m_session ? m_session->GetSessionDbcLocale() : sWorld.GetDefaultDbcLocale();
3175 std::string name = skillInfo->name[loc];
3176 if(name.empty())
3177 continue;
3179 if (!Utf8FitTo(name, wnamepart))
3181 loc = 0;
3182 for(; loc < MAX_LOCALE; ++loc)
3184 if(m_session && loc==m_session->GetSessionDbcLocale())
3185 continue;
3187 name = skillInfo->name[loc];
3188 if(name.empty())
3189 continue;
3191 if (Utf8FitTo(name, wnamepart))
3192 break;
3196 if(loc < MAX_LOCALE)
3198 char valStr[50] = "";
3199 char const* knownStr = "";
3200 if(target && target->HasSkill(id))
3202 knownStr = GetMangosString(LANG_KNOWN);
3203 uint32 curValue = target->GetPureSkillValue(id);
3204 uint32 maxValue = target->GetPureMaxSkillValue(id);
3205 uint32 permValue = target->GetSkillPermBonusValue(id);
3206 uint32 tempValue = target->GetSkillTempBonusValue(id);
3208 char const* valFormat = GetMangosString(LANG_SKILL_VALUES);
3209 snprintf(valStr,50,valFormat,curValue,maxValue,permValue,tempValue);
3212 // send skill in "id - [namedlink locale]" format
3213 if (m_session)
3214 PSendSysMessage(LANG_SKILL_LIST_CHAT,id,id,name.c_str(),localeNames[loc],knownStr,valStr);
3215 else
3216 PSendSysMessage(LANG_SKILL_LIST_CONSOLE,id,name.c_str(),localeNames[loc],knownStr,valStr);
3218 ++counter;
3222 if (counter == 0) // if counter == 0 then we found nth
3223 SendSysMessage(LANG_COMMAND_NOSKILLFOUND);
3224 return true;
3227 bool ChatHandler::HandleLookupSpellCommand(const char* args)
3229 if(!*args)
3230 return false;
3232 // can be NULL at console call
3233 Player* target = getSelectedPlayer();
3235 std::string namepart = args;
3236 std::wstring wnamepart;
3238 if(!Utf8toWStr(namepart,wnamepart))
3239 return false;
3241 // converting string that we try to find to lower case
3242 wstrToLower( wnamepart );
3244 uint32 counter = 0; // Counter for figure out that we found smth.
3246 // Search in Spell.dbc
3247 for (uint32 id = 0; id < sSpellStore.GetNumRows(); id++)
3249 SpellEntry const *spellInfo = sSpellStore.LookupEntry(id);
3250 if(spellInfo)
3252 int loc = m_session ? m_session->GetSessionDbcLocale() : sWorld.GetDefaultDbcLocale();
3253 std::string name = spellInfo->SpellName[loc];
3254 if(name.empty())
3255 continue;
3257 if (!Utf8FitTo(name, wnamepart))
3259 loc = 0;
3260 for(; loc < MAX_LOCALE; ++loc)
3262 if(m_session && loc==m_session->GetSessionDbcLocale())
3263 continue;
3265 name = spellInfo->SpellName[loc];
3266 if(name.empty())
3267 continue;
3269 if (Utf8FitTo(name, wnamepart))
3270 break;
3274 if(loc < MAX_LOCALE)
3276 bool known = target && target->HasSpell(id);
3277 bool learn = (spellInfo->Effect[0] == SPELL_EFFECT_LEARN_SPELL);
3279 uint32 talentCost = GetTalentSpellCost(id);
3281 bool talent = (talentCost > 0);
3282 bool passive = IsPassiveSpell(id);
3283 bool active = target && target->HasAura(id);
3285 // unit32 used to prevent interpreting uint8 as char at output
3286 // find rank of learned spell for learning spell, or talent rank
3287 uint32 rank = talentCost ? talentCost : spellmgr.GetSpellRank(learn ? spellInfo->EffectTriggerSpell[0] : id);
3289 // send spell in "id - [name, rank N] [talent] [passive] [learn] [known]" format
3290 std::ostringstream ss;
3291 if (m_session)
3292 ss << id << " - |cffffffff|Hspell:" << id << "|h[" << name;
3293 else
3294 ss << id << " - " << name;
3296 // include rank in link name
3297 if(rank)
3298 ss << GetMangosString(LANG_SPELL_RANK) << rank;
3300 if (m_session)
3301 ss << " " << localeNames[loc] << "]|h|r";
3302 else
3303 ss << " " << localeNames[loc];
3305 if(talent)
3306 ss << GetMangosString(LANG_TALENT);
3307 if(passive)
3308 ss << GetMangosString(LANG_PASSIVE);
3309 if(learn)
3310 ss << GetMangosString(LANG_LEARN);
3311 if(known)
3312 ss << GetMangosString(LANG_KNOWN);
3313 if(active)
3314 ss << GetMangosString(LANG_ACTIVE);
3316 SendSysMessage(ss.str().c_str());
3318 ++counter;
3322 if (counter == 0) // if counter == 0 then we found nth
3323 SendSysMessage(LANG_COMMAND_NOSPELLFOUND);
3324 return true;
3327 bool ChatHandler::HandleLookupQuestCommand(const char* args)
3329 if(!*args)
3330 return false;
3332 // can be NULL at console call
3333 Player* target = getSelectedPlayer();
3335 std::string namepart = args;
3336 std::wstring wnamepart;
3338 // converting string that we try to find to lower case
3339 if(!Utf8toWStr(namepart,wnamepart))
3340 return false;
3342 wstrToLower(wnamepart);
3344 uint32 counter = 0 ;
3346 ObjectMgr::QuestMap const& qTemplates = objmgr.GetQuestTemplates();
3347 for (ObjectMgr::QuestMap::const_iterator iter = qTemplates.begin(); iter != qTemplates.end(); ++iter)
3349 Quest * qinfo = iter->second;
3351 int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex();
3352 if ( loc_idx >= 0 )
3354 QuestLocale const *il = objmgr.GetQuestLocale(qinfo->GetQuestId());
3355 if (il)
3357 if (il->Title.size() > loc_idx && !il->Title[loc_idx].empty())
3359 std::string title = il->Title[loc_idx];
3361 if (Utf8FitTo(title, wnamepart))
3363 char const* statusStr = "";
3365 if(target)
3367 QuestStatus status = target->GetQuestStatus(qinfo->GetQuestId());
3369 if(status == QUEST_STATUS_COMPLETE)
3371 if(target->GetQuestRewardStatus(qinfo->GetQuestId()))
3372 statusStr = GetMangosString(LANG_COMMAND_QUEST_REWARDED);
3373 else
3374 statusStr = GetMangosString(LANG_COMMAND_QUEST_COMPLETE);
3376 else if(status == QUEST_STATUS_INCOMPLETE)
3377 statusStr = GetMangosString(LANG_COMMAND_QUEST_ACTIVE);
3380 if (m_session)
3381 PSendSysMessage(LANG_QUEST_LIST_CHAT,qinfo->GetQuestId(),qinfo->GetQuestId(),title.c_str(),statusStr);
3382 else
3383 PSendSysMessage(LANG_QUEST_LIST_CONSOLE,qinfo->GetQuestId(),title.c_str(),statusStr);
3384 ++counter;
3385 continue;
3391 std::string title = qinfo->GetTitle();
3392 if(title.empty())
3393 continue;
3395 if (Utf8FitTo(title, wnamepart))
3397 char const* statusStr = "";
3399 if(target)
3401 QuestStatus status = target->GetQuestStatus(qinfo->GetQuestId());
3403 if(status == QUEST_STATUS_COMPLETE)
3405 if(target->GetQuestRewardStatus(qinfo->GetQuestId()))
3406 statusStr = GetMangosString(LANG_COMMAND_QUEST_REWARDED);
3407 else
3408 statusStr = GetMangosString(LANG_COMMAND_QUEST_COMPLETE);
3410 else if(status == QUEST_STATUS_INCOMPLETE)
3411 statusStr = GetMangosString(LANG_COMMAND_QUEST_ACTIVE);
3414 if (m_session)
3415 PSendSysMessage(LANG_QUEST_LIST_CHAT,qinfo->GetQuestId(),qinfo->GetQuestId(),title.c_str(),statusStr);
3416 else
3417 PSendSysMessage(LANG_QUEST_LIST_CONSOLE,qinfo->GetQuestId(),title.c_str(),statusStr);
3419 ++counter;
3423 if (counter==0)
3424 SendSysMessage(LANG_COMMAND_NOQUESTFOUND);
3426 return true;
3429 bool ChatHandler::HandleLookupCreatureCommand(const char* args)
3431 if (!*args)
3432 return false;
3434 std::string namepart = args;
3435 std::wstring wnamepart;
3437 // converting string that we try to find to lower case
3438 if (!Utf8toWStr (namepart,wnamepart))
3439 return false;
3441 wstrToLower (wnamepart);
3443 uint32 counter = 0;
3445 for (uint32 id = 0; id< sCreatureStorage.MaxEntry; ++id)
3447 CreatureInfo const* cInfo = sCreatureStorage.LookupEntry<CreatureInfo> (id);
3448 if(!cInfo)
3449 continue;
3451 int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex();
3452 if (loc_idx >= 0)
3454 CreatureLocale const *cl = objmgr.GetCreatureLocale (id);
3455 if (cl)
3457 if (cl->Name.size() > loc_idx && !cl->Name[loc_idx].empty ())
3459 std::string name = cl->Name[loc_idx];
3461 if (Utf8FitTo (name, wnamepart))
3463 if (m_session)
3464 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT, id, id, name.c_str ());
3465 else
3466 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE, id, name.c_str ());
3467 ++counter;
3468 continue;
3474 std::string name = cInfo->Name;
3475 if (name.empty ())
3476 continue;
3478 if (Utf8FitTo(name, wnamepart))
3480 if (m_session)
3481 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT, id, id, name.c_str ());
3482 else
3483 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE, id, name.c_str ());
3484 ++counter;
3488 if (counter==0)
3489 SendSysMessage (LANG_COMMAND_NOCREATUREFOUND);
3491 return true;
3494 bool ChatHandler::HandleLookupObjectCommand(const char* args)
3496 if(!*args)
3497 return false;
3499 std::string namepart = args;
3500 std::wstring wnamepart;
3502 // converting string that we try to find to lower case
3503 if(!Utf8toWStr(namepart,wnamepart))
3504 return false;
3506 wstrToLower(wnamepart);
3508 uint32 counter = 0;
3510 for (uint32 id = 0; id< sGOStorage.MaxEntry; id++ )
3512 GameObjectInfo const* gInfo = sGOStorage.LookupEntry<GameObjectInfo>(id);
3513 if(!gInfo)
3514 continue;
3516 int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex();
3517 if ( loc_idx >= 0 )
3519 GameObjectLocale const *gl = objmgr.GetGameObjectLocale(id);
3520 if (gl)
3522 if (gl->Name.size() > loc_idx && !gl->Name[loc_idx].empty())
3524 std::string name = gl->Name[loc_idx];
3526 if (Utf8FitTo(name, wnamepart))
3528 if (m_session)
3529 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT, id, id, name.c_str());
3530 else
3531 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE, id, name.c_str());
3532 ++counter;
3533 continue;
3539 std::string name = gInfo->name;
3540 if(name.empty())
3541 continue;
3543 if(Utf8FitTo(name, wnamepart))
3545 if (m_session)
3546 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT, id, id, name.c_str());
3547 else
3548 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE, id, name.c_str());
3549 ++counter;
3553 if(counter==0)
3554 SendSysMessage(LANG_COMMAND_NOGAMEOBJECTFOUND);
3556 return true;
3559 bool ChatHandler::HandleLookupTaxiNodeCommand(const char * args)
3561 if(!*args)
3562 return false;
3564 std::string namepart = args;
3565 std::wstring wnamepart;
3567 if(!Utf8toWStr(namepart,wnamepart))
3568 return false;
3570 // converting string that we try to find to lower case
3571 wstrToLower( wnamepart );
3573 uint32 counter = 0; // Counter for figure out that we found smth.
3575 // Search in TaxiNodes.dbc
3576 for (uint32 id = 0; id < sTaxiNodesStore.GetNumRows(); id++)
3578 TaxiNodesEntry const *nodeEntry = sTaxiNodesStore.LookupEntry(id);
3579 if(nodeEntry)
3581 int loc = m_session ? m_session->GetSessionDbcLocale() : sWorld.GetDefaultDbcLocale();
3582 std::string name = nodeEntry->name[loc];
3583 if(name.empty())
3584 continue;
3586 if (!Utf8FitTo(name, wnamepart))
3588 loc = 0;
3589 for(; loc < MAX_LOCALE; ++loc)
3591 if(m_session && loc==m_session->GetSessionDbcLocale())
3592 continue;
3594 name = nodeEntry->name[loc];
3595 if(name.empty())
3596 continue;
3598 if (Utf8FitTo(name, wnamepart))
3599 break;
3603 if(loc < MAX_LOCALE)
3605 // send taxinode in "id - [name] (Map:m X:x Y:y Z:z)" format
3606 if (m_session)
3607 PSendSysMessage (LANG_TAXINODE_ENTRY_LIST_CHAT, id, id, name.c_str(),localeNames[loc],
3608 nodeEntry->map_id,nodeEntry->x,nodeEntry->y,nodeEntry->z);
3609 else
3610 PSendSysMessage (LANG_TAXINODE_ENTRY_LIST_CONSOLE, id, name.c_str(), localeNames[loc],
3611 nodeEntry->map_id,nodeEntry->x,nodeEntry->y,nodeEntry->z);
3612 ++counter;
3616 if (counter == 0) // if counter == 0 then we found nth
3617 SendSysMessage(LANG_COMMAND_NOSPELLFOUND);
3618 return true;
3621 /** \brief GM command level 3 - Create a guild.
3623 * This command allows a GM (level 3) to create a guild.
3625 * The "args" parameter contains the name of the guild leader
3626 * and then the name of the guild.
3629 bool ChatHandler::HandleGuildCreateCommand(const char* args)
3632 if (!*args)
3633 return false;
3635 char *lname = strtok ((char*)args, " ");
3636 char *gname = strtok (NULL, "");
3638 if (!lname)
3639 return false;
3641 if (!gname)
3643 SendSysMessage (LANG_INSERT_GUILD_NAME);
3644 SetSentErrorMessage (true);
3645 return false;
3648 std::string guildname = gname;
3650 Player* player = ObjectAccessor::Instance ().FindPlayerByName (lname);
3651 if (!player)
3653 SendSysMessage (LANG_PLAYER_NOT_FOUND);
3654 SetSentErrorMessage (true);
3655 return false;
3658 if (player->GetGuildId())
3660 SendSysMessage (LANG_PLAYER_IN_GUILD);
3661 return true;
3664 Guild *guild = new Guild;
3665 if (!guild->create (player,guildname))
3667 delete guild;
3668 SendSysMessage (LANG_GUILD_NOT_CREATED);
3669 SetSentErrorMessage (true);
3670 return false;
3673 objmgr.AddGuild (guild);
3674 return true;
3677 bool ChatHandler::HandleGuildInviteCommand(const char *args)
3679 if (!*args)
3680 return false;
3682 char* par1 = strtok ((char*)args, " ");
3683 char* par2 = strtok (NULL, "");
3684 if(!par1 || !par2)
3685 return false;
3687 std::string glName = par2;
3688 Guild* targetGuild = objmgr.GetGuildByName (glName);
3689 if (!targetGuild)
3690 return false;
3692 std::string plName = extractPlayerNameFromLink(par1);
3693 if(plName.empty())
3695 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3696 SetSentErrorMessage(true);
3697 return false;
3700 uint64 plGuid = 0;
3701 if (Player* targetPlayer = ObjectAccessor::Instance ().FindPlayerByName (plName.c_str ()))
3702 plGuid = targetPlayer->GetGUID ();
3703 else
3704 plGuid = objmgr.GetPlayerGUIDByName (plName);
3706 if (!plGuid)
3707 return false;
3709 // player's guild membership checked in AddMember before add
3710 if (!targetGuild->AddMember (plGuid,targetGuild->GetLowestRank ()))
3711 return false;
3713 return true;
3716 bool ChatHandler::HandleGuildUninviteCommand(const char *args)
3718 if (!*args)
3719 return false;
3721 char* par1 = strtok ((char*)args, " ");
3722 if(!par1)
3723 return false;
3725 std::string plName = extractPlayerNameFromLink(par1);
3726 if(plName.empty())
3728 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3729 SetSentErrorMessage(true);
3730 return false;
3733 uint64 plGuid = 0;
3734 uint32 glId = 0;
3735 if (Player* targetPlayer = ObjectAccessor::Instance ().FindPlayerByName (plName.c_str ()))
3737 plGuid = targetPlayer->GetGUID ();
3738 glId = targetPlayer->GetGuildId ();
3740 else
3742 plGuid = objmgr.GetPlayerGUIDByName (plName);
3743 glId = Player::GetGuildIdFromDB (plGuid);
3746 if (!plGuid || !glId)
3747 return false;
3749 Guild* targetGuild = objmgr.GetGuildById (glId);
3750 if (!targetGuild)
3751 return false;
3753 targetGuild->DelMember (plGuid);
3755 return true;
3758 bool ChatHandler::HandleGuildRankCommand(const char *args)
3760 if (!*args)
3761 return false;
3763 char* par1 = strtok ((char*)args, " ");
3764 char* par2 = strtok (NULL, " ");
3765 if (!par1 || !par2)
3766 return false;
3768 std::string plName = extractPlayerNameFromLink(par1);
3769 if(plName.empty())
3771 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3772 SetSentErrorMessage(true);
3773 return false;
3777 uint64 plGuid = 0;
3778 uint32 glId = 0;
3779 if (Player* targetPlayer = ObjectAccessor::Instance ().FindPlayerByName (plName.c_str ()))
3781 plGuid = targetPlayer->GetGUID ();
3782 glId = targetPlayer->GetGuildId ();
3784 else
3786 plGuid = objmgr.GetPlayerGUIDByName (plName);
3787 glId = Player::GetGuildIdFromDB (plGuid);
3790 if (!plGuid || !glId)
3791 return false;
3793 Guild* targetGuild = objmgr.GetGuildById (glId);
3794 if (!targetGuild)
3795 return false;
3797 uint32 newrank = uint32 (atoi (par2));
3798 if (newrank > targetGuild->GetLowestRank ())
3799 return false;
3801 targetGuild->ChangeRank (plGuid,newrank);
3803 return true;
3806 bool ChatHandler::HandleGuildDeleteCommand(const char* args)
3808 if (!*args)
3809 return false;
3811 char* par1 = strtok ((char*)args, " ");
3812 if (!par1)
3813 return false;
3815 std::string gld = par1;
3817 Guild* targetGuild = objmgr.GetGuildByName (gld);
3818 if (!targetGuild)
3819 return false;
3821 targetGuild->Disband ();
3823 return true;
3826 bool ChatHandler::HandleGetDistanceCommand(const char* args)
3828 WorldObject* obj = NULL;
3830 if (*args)
3832 uint64 guid = extractGuidFromLink((char*)args);
3833 if(guid)
3834 obj = (WorldObject*)ObjectAccessor::GetObjectByTypeMask(*m_session->GetPlayer(),guid,TYPEMASK_UNIT|TYPEMASK_GAMEOBJECT);
3836 if(!obj)
3838 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3839 SetSentErrorMessage(true);
3840 return false;
3843 else
3845 obj = getSelectedUnit();
3847 if(!obj)
3849 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3850 SetSentErrorMessage(true);
3851 return false;
3855 PSendSysMessage(LANG_DISTANCE, m_session->GetPlayer()->GetDistance(obj),m_session->GetPlayer()->GetDistance2d(obj));
3857 return true;
3860 bool ChatHandler::HandleDieCommand(const char* /*args*/)
3862 Unit* target = getSelectedUnit();
3864 if(!target || !m_session->GetPlayer()->GetSelection())
3866 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3867 SetSentErrorMessage(true);
3868 return false;
3871 if(target->GetTypeId()==TYPEID_PLAYER)
3873 if(HasLowerSecurity((Player*)target,0,false))
3874 return false;
3877 if( target->isAlive() )
3879 m_session->GetPlayer()->DealDamage(target, target->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
3882 return true;
3885 bool ChatHandler::HandleDamageCommand(const char * args)
3887 if (!*args)
3888 return false;
3890 Unit* target = getSelectedUnit();
3892 if (!target || !m_session->GetPlayer()->GetSelection())
3894 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3895 SetSentErrorMessage(true);
3896 return false;
3899 if (!target->isAlive())
3900 return true;
3902 char* damageStr = strtok((char*)args, " ");
3903 if (!damageStr)
3904 return false;
3906 int32 damage_int = atoi((char*)damageStr);
3907 if(damage_int <=0)
3908 return true;
3910 uint32 damage = damage_int;
3912 char* schoolStr = strtok((char*)NULL, " ");
3914 // flat melee damage without resistence/etc reduction
3915 if (!schoolStr)
3917 m_session->GetPlayer()->DealDamage(target, damage, NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
3918 if (target != m_session->GetPlayer())
3919 m_session->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2, target, 1, SPELL_SCHOOL_MASK_NORMAL, damage, 0, 0, VICTIMSTATE_NORMAL, 0);
3920 return true;
3923 uint32 school = schoolStr ? atoi((char*)schoolStr) : SPELL_SCHOOL_NORMAL;
3924 if(school >= MAX_SPELL_SCHOOL)
3925 return false;
3927 SpellSchoolMask schoolmask = SpellSchoolMask(1 << school);
3929 if ( schoolmask & SPELL_SCHOOL_MASK_NORMAL )
3930 damage = m_session->GetPlayer()->CalcArmorReducedDamage(target, damage);
3932 char* spellStr = strtok((char*)NULL, " ");
3934 // melee damage by specific school
3935 if (!spellStr)
3937 uint32 absorb = 0;
3938 uint32 resist = 0;
3940 m_session->GetPlayer()->CalcAbsorbResist(target,schoolmask, SPELL_DIRECT_DAMAGE, damage, &absorb, &resist);
3942 if (damage <= absorb + resist)
3943 return true;
3945 damage -= absorb + resist;
3947 m_session->GetPlayer()->DealDamageMods(target,damage,&absorb);
3948 m_session->GetPlayer()->DealDamage(target, damage, NULL, DIRECT_DAMAGE, schoolmask, NULL, false);
3949 m_session->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2, target, 1, schoolmask, damage, absorb, resist, VICTIMSTATE_NORMAL, 0);
3950 return true;
3953 // non-melee damage
3955 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3956 uint32 spellid = extractSpellIdFromLink((char*)args);
3957 if (!spellid || !sSpellStore.LookupEntry(spellid))
3958 return false;
3960 m_session->GetPlayer()->SpellNonMeleeDamageLog(target, spellid, damage);
3961 return true;
3964 bool ChatHandler::HandleModifyArenaCommand(const char * args)
3966 if (!*args)
3967 return false;
3969 Player *target = getSelectedPlayer();
3970 if(!target)
3972 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3973 SetSentErrorMessage(true);
3974 return false;
3977 int32 amount = (uint32)atoi(args);
3979 target->ModifyArenaPoints(amount);
3981 PSendSysMessage(LANG_COMMAND_MODIFY_ARENA, GetNameLink(target).c_str(), target->GetArenaPoints());
3983 return true;
3986 bool ChatHandler::HandleReviveCommand(const char* args)
3988 Player* player = NULL;
3989 uint64 player_guid = 0;
3991 if (*args)
3993 std::string name = extractPlayerNameFromLink((char*)args);
3994 if (name.empty())
3996 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3997 SetSentErrorMessage(true);
3998 return false;
4001 player = objmgr.GetPlayer(name.c_str());
4002 if (!player)
4003 player_guid = objmgr.GetPlayerGUIDByName(name);
4005 else
4006 player = getSelectedPlayer();
4008 if (player)
4010 player->ResurrectPlayer(0.5f);
4011 player->SpawnCorpseBones();
4012 player->SaveToDB();
4014 else if (player_guid)
4016 // will resurrected at login without corpse
4017 ObjectAccessor::Instance().ConvertCorpseForPlayer(player_guid);
4019 else
4021 SendSysMessage(LANG_NO_CHAR_SELECTED);
4022 SetSentErrorMessage(true);
4023 return false;
4026 return true;
4029 bool ChatHandler::HandleAuraCommand(const char* args)
4031 Unit *target = getSelectedUnit();
4032 if(!target)
4034 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
4035 SetSentErrorMessage(true);
4036 return false;
4039 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
4040 uint32 spellID = extractSpellIdFromLink((char*)args);
4042 SpellEntry const *spellInfo = sSpellStore.LookupEntry( spellID );
4043 if(spellInfo)
4045 for(uint32 i = 0;i<3;++i)
4047 uint8 eff = spellInfo->Effect[i];
4048 if (eff>=TOTAL_SPELL_EFFECTS)
4049 continue;
4050 if( IsAreaAuraEffect(eff) ||
4051 eff == SPELL_EFFECT_APPLY_AURA ||
4052 eff == SPELL_EFFECT_PERSISTENT_AREA_AURA )
4054 Aura *Aur = CreateAura(spellInfo, i, NULL, target);
4055 target->AddAura(Aur);
4060 return true;
4063 bool ChatHandler::HandleUnAuraCommand(const char* args)
4065 Unit *target = getSelectedUnit();
4066 if(!target)
4068 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
4069 SetSentErrorMessage(true);
4070 return false;
4073 std::string argstr = args;
4074 if (argstr == "all")
4076 target->RemoveAllAuras();
4077 return true;
4080 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
4081 uint32 spellID = extractSpellIdFromLink((char*)args);
4082 if(!spellID)
4083 return false;
4085 target->RemoveAurasDueToSpell(spellID);
4087 return true;
4090 bool ChatHandler::HandleLinkGraveCommand(const char* args)
4092 if(!*args)
4093 return false;
4095 char* px = strtok((char*)args, " ");
4096 if (!px)
4097 return false;
4099 uint32 g_id = (uint32)atoi(px);
4101 uint32 g_team;
4103 char* px2 = strtok(NULL, " ");
4105 if (!px2)
4106 g_team = 0;
4107 else if (strncmp(px2,"horde",6)==0)
4108 g_team = HORDE;
4109 else if (strncmp(px2,"alliance",9)==0)
4110 g_team = ALLIANCE;
4111 else
4112 return false;
4114 WorldSafeLocsEntry const* graveyard = sWorldSafeLocsStore.LookupEntry(g_id);
4116 if(!graveyard )
4118 PSendSysMessage(LANG_COMMAND_GRAVEYARDNOEXIST, g_id);
4119 SetSentErrorMessage(true);
4120 return false;
4123 Player* player = m_session->GetPlayer();
4125 uint32 zoneId = player->GetZoneId();
4127 AreaTableEntry const *areaEntry = GetAreaEntryByAreaID(zoneId);
4128 if(!areaEntry || areaEntry->zone !=0 )
4130 PSendSysMessage(LANG_COMMAND_GRAVEYARDWRONGZONE, g_id,zoneId);
4131 SetSentErrorMessage(true);
4132 return false;
4135 if(objmgr.AddGraveYardLink(g_id,zoneId,g_team))
4136 PSendSysMessage(LANG_COMMAND_GRAVEYARDLINKED, g_id,zoneId);
4137 else
4138 PSendSysMessage(LANG_COMMAND_GRAVEYARDALRLINKED, g_id,zoneId);
4140 return true;
4143 bool ChatHandler::HandleNearGraveCommand(const char* args)
4145 uint32 g_team;
4147 size_t argslen = strlen(args);
4149 if(!*args)
4150 g_team = 0;
4151 else if (strncmp((char*)args,"horde",argslen)==0)
4152 g_team = HORDE;
4153 else if (strncmp((char*)args,"alliance",argslen)==0)
4154 g_team = ALLIANCE;
4155 else
4156 return false;
4158 Player* player = m_session->GetPlayer();
4159 uint32 zone_id = player->GetZoneId();
4161 WorldSafeLocsEntry const* graveyard = objmgr.GetClosestGraveYard(
4162 player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(),player->GetMapId(),g_team);
4164 if(graveyard)
4166 uint32 g_id = graveyard->ID;
4168 GraveYardData const* data = objmgr.FindGraveYardData(g_id,zone_id);
4169 if (!data)
4171 PSendSysMessage(LANG_COMMAND_GRAVEYARDERROR,g_id);
4172 SetSentErrorMessage(true);
4173 return false;
4176 g_team = data->team;
4178 std::string team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_NOTEAM);
4180 if(g_team == 0)
4181 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ANY);
4182 else if(g_team == HORDE)
4183 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE);
4184 else if(g_team == ALLIANCE)
4185 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE);
4187 PSendSysMessage(LANG_COMMAND_GRAVEYARDNEAREST, g_id,team_name.c_str(),zone_id);
4189 else
4191 std::string team_name;
4193 if(g_team == 0)
4194 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ANY);
4195 else if(g_team == HORDE)
4196 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE);
4197 else if(g_team == ALLIANCE)
4198 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE);
4200 if(g_team == ~uint32(0))
4201 PSendSysMessage(LANG_COMMAND_ZONENOGRAVEYARDS, zone_id);
4202 else
4203 PSendSysMessage(LANG_COMMAND_ZONENOGRAFACTION, zone_id,team_name.c_str());
4206 return true;
4209 //-----------------------Npc Commands-----------------------
4210 bool ChatHandler::HandleNpcAllowMovementCommand(const char* /*args*/)
4212 if(sWorld.getAllowMovement())
4214 sWorld.SetAllowMovement(false);
4215 SendSysMessage(LANG_CREATURE_MOVE_DISABLED);
4217 else
4219 sWorld.SetAllowMovement(true);
4220 SendSysMessage(LANG_CREATURE_MOVE_ENABLED);
4222 return true;
4225 bool ChatHandler::HandleNpcChangeEntryCommand(const char *args)
4227 if (!*args)
4228 return false;
4230 uint32 newEntryNum = atoi(args);
4231 if(!newEntryNum)
4232 return false;
4234 Unit* unit = getSelectedUnit();
4235 if(!unit || unit->GetTypeId() != TYPEID_UNIT)
4237 SendSysMessage(LANG_SELECT_CREATURE);
4238 SetSentErrorMessage(true);
4239 return false;
4241 Creature* creature = (Creature*)unit;
4242 if(creature->UpdateEntry(newEntryNum))
4243 SendSysMessage(LANG_DONE);
4244 else
4245 SendSysMessage(LANG_ERROR);
4246 return true;
4249 bool ChatHandler::HandleNpcInfoCommand(const char* /*args*/)
4251 Creature* target = getSelectedCreature();
4253 if(!target)
4255 SendSysMessage(LANG_SELECT_CREATURE);
4256 SetSentErrorMessage(true);
4257 return false;
4260 uint32 faction = target->getFaction();
4261 uint32 npcflags = target->GetUInt32Value(UNIT_NPC_FLAGS);
4262 uint32 displayid = target->GetDisplayId();
4263 uint32 nativeid = target->GetNativeDisplayId();
4264 uint32 Entry = target->GetEntry();
4265 CreatureInfo const* cInfo = target->GetCreatureInfo();
4267 int32 curRespawnDelay = target->GetRespawnTimeEx()-time(NULL);
4268 if(curRespawnDelay < 0)
4269 curRespawnDelay = 0;
4270 std::string curRespawnDelayStr = secsToTimeString(curRespawnDelay,true);
4271 std::string defRespawnDelayStr = secsToTimeString(target->GetRespawnDelay(),true);
4273 PSendSysMessage(LANG_NPCINFO_CHAR, target->GetDBTableGUIDLow(), faction, npcflags, Entry, displayid, nativeid);
4274 PSendSysMessage(LANG_NPCINFO_LEVEL, target->getLevel());
4275 PSendSysMessage(LANG_NPCINFO_HEALTH,target->GetCreateHealth(), target->GetMaxHealth(), target->GetHealth());
4276 PSendSysMessage(LANG_NPCINFO_FLAGS, target->GetUInt32Value(UNIT_FIELD_FLAGS), target->GetUInt32Value(UNIT_DYNAMIC_FLAGS), target->getFaction());
4277 PSendSysMessage(LANG_COMMAND_RAWPAWNTIMES, defRespawnDelayStr.c_str(),curRespawnDelayStr.c_str());
4278 PSendSysMessage(LANG_NPCINFO_LOOT, cInfo->lootid,cInfo->pickpocketLootId,cInfo->SkinLootId);
4279 PSendSysMessage(LANG_NPCINFO_DUNGEON_ID, target->GetInstanceId());
4280 PSendSysMessage(LANG_NPCINFO_POSITION,float(target->GetPositionX()), float(target->GetPositionY()), float(target->GetPositionZ()));
4282 if ((npcflags & UNIT_NPC_FLAG_VENDOR) )
4284 SendSysMessage(LANG_NPCINFO_VENDOR);
4286 if ((npcflags & UNIT_NPC_FLAG_TRAINER) )
4288 SendSysMessage(LANG_NPCINFO_TRAINER);
4291 return true;
4294 //play npc emote
4295 bool ChatHandler::HandleNpcPlayEmoteCommand(const char* args)
4297 uint32 emote = atoi((char*)args);
4299 Creature* target = getSelectedCreature();
4300 if(!target)
4302 SendSysMessage(LANG_SELECT_CREATURE);
4303 SetSentErrorMessage(true);
4304 return false;
4307 target->SetUInt32Value(UNIT_NPC_EMOTESTATE,emote);
4309 return true;
4312 //TODO: NpcCommands that needs to be fixed :
4314 bool ChatHandler::HandleNpcAddWeaponCommand(const char* /*args*/)
4316 /*if (!*args)
4317 return false;
4319 uint64 guid = m_session->GetPlayer()->GetSelection();
4320 if (guid == 0)
4322 SendSysMessage(LANG_NO_SELECTION);
4323 return true;
4326 Creature *pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(), guid);
4328 if(!pCreature)
4330 SendSysMessage(LANG_SELECT_CREATURE);
4331 return true;
4334 char* pSlotID = strtok((char*)args, " ");
4335 if (!pSlotID)
4336 return false;
4338 char* pItemID = strtok(NULL, " ");
4339 if (!pItemID)
4340 return false;
4342 uint32 ItemID = atoi(pItemID);
4343 uint32 SlotID = atoi(pSlotID);
4345 ItemPrototype* tmpItem = objmgr.GetItemPrototype(ItemID);
4347 bool added = false;
4348 if(tmpItem)
4350 switch(SlotID)
4352 case 1:
4353 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY, ItemID);
4354 added = true;
4355 break;
4356 case 2:
4357 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_01, ItemID);
4358 added = true;
4359 break;
4360 case 3:
4361 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_02, ItemID);
4362 added = true;
4363 break;
4364 default:
4365 PSendSysMessage(LANG_ITEM_SLOT_NOT_EXIST,SlotID);
4366 added = false;
4367 break;
4370 if(added)
4371 PSendSysMessage(LANG_ITEM_ADDED_TO_SLOT,ItemID,tmpItem->Name1,SlotID);
4373 else
4375 PSendSysMessage(LANG_ITEM_NOT_FOUND,ItemID);
4376 return true;
4379 return true;
4381 //----------------------------------------------------------
4383 bool ChatHandler::HandleExploreCheatCommand(const char* args)
4385 if (!*args)
4386 return false;
4388 int flag = atoi((char*)args);
4390 Player *chr = getSelectedPlayer();
4391 if (chr == NULL)
4393 SendSysMessage(LANG_NO_CHAR_SELECTED);
4394 SetSentErrorMessage(true);
4395 return false;
4398 if (flag != 0)
4400 PSendSysMessage(LANG_YOU_SET_EXPLORE_ALL, GetNameLink(chr).c_str());
4401 if (needReportToTarget(chr))
4402 ChatHandler(chr).PSendSysMessage(LANG_YOURS_EXPLORE_SET_ALL,GetNameLink().c_str());
4404 else
4406 PSendSysMessage(LANG_YOU_SET_EXPLORE_NOTHING, GetNameLink(chr).c_str());
4407 if (needReportToTarget(chr))
4408 ChatHandler(chr).PSendSysMessage(LANG_YOURS_EXPLORE_SET_NOTHING,GetNameLink().c_str());
4411 for (uint8 i=0; i<128; ++i)
4413 if (flag != 0)
4415 m_session->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1+i,0xFFFFFFFF);
4417 else
4419 m_session->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1+i,0);
4423 return true;
4426 bool ChatHandler::HandleHoverCommand(const char* args)
4428 char* px = strtok((char*)args, " ");
4429 uint32 flag;
4430 if (!px)
4431 flag = 1;
4432 else
4433 flag = atoi(px);
4435 m_session->GetPlayer()->SetHover(flag);
4437 if (flag)
4438 SendSysMessage(LANG_HOVER_ENABLED);
4439 else
4440 SendSysMessage(LANG_HOVER_DISABLED);
4442 return true;
4445 void ChatHandler::HandleCharacterLevel(Player* player, uint64 player_guid, uint32 oldlevel, uint32 newlevel)
4447 if(player)
4449 player->GiveLevel(newlevel);
4450 player->InitTalentForLevel();
4451 player->SetUInt32Value(PLAYER_XP,0);
4453 if(needReportToTarget(player))
4455 if(oldlevel == newlevel)
4456 ChatHandler(player).PSendSysMessage(LANG_YOURS_LEVEL_PROGRESS_RESET,GetNameLink().c_str());
4457 else if(oldlevel < newlevel)
4458 ChatHandler(player).PSendSysMessage(LANG_YOURS_LEVEL_UP,GetNameLink().c_str(),newlevel);
4459 else // if(oldlevel > newlevel)
4460 ChatHandler(player).PSendSysMessage(LANG_YOURS_LEVEL_DOWN,GetNameLink().c_str(),newlevel);
4463 else
4465 // update level and XP at level, all other will be updated at loading
4466 Tokens values;
4467 Player::LoadValuesArrayFromDB(values,player_guid);
4468 Player::SetUInt32ValueInArray(values,UNIT_FIELD_LEVEL,newlevel);
4469 Player::SetUInt32ValueInArray(values,PLAYER_XP,0);
4470 Player::SaveValuesArrayInDB(values,player_guid);
4474 bool ChatHandler::HandleCharacterLevelCommand(const char* args)
4476 char* px = strtok((char*)args, " ");
4477 char* py = strtok((char*)NULL, " ");
4479 // command format parsing
4480 char* pname = (char*)NULL;
4481 int32 newlevel = 0;
4483 if(px && py) // .character level $name #level
4485 newlevel = atoi(py);
4486 pname = px;
4488 else if(px && !py) // .character level $name OR .character level #level
4490 if(isalpha(px[0])) // .character level $name
4491 pname = px;
4492 else // .character level #level
4493 newlevel = atoi(px);
4495 // // .character level - progress reset
4497 if(newlevel < 1)
4498 return false; // invalid level
4500 if(newlevel > STRONG_MAX_LEVEL) // hardcoded maximum level
4501 newlevel = STRONG_MAX_LEVEL;
4503 // player
4504 Player *chr = NULL;
4505 uint64 chr_guid = 0;
4507 std::string name;
4509 if(pname) // player by name
4511 name = extractPlayerNameFromLink(pname);
4512 if(name.empty())
4514 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4515 SetSentErrorMessage(true);
4516 return false;
4519 chr = objmgr.GetPlayer(name.c_str());
4520 if(!chr) // not in game
4522 chr_guid = objmgr.GetPlayerGUIDByName(name);
4523 if (chr_guid == 0)
4525 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4526 SetSentErrorMessage(true);
4527 return false;
4531 else // player by selection
4533 chr = getSelectedPlayer();
4535 if (chr == NULL)
4537 SendSysMessage(LANG_NO_CHAR_SELECTED);
4538 SetSentErrorMessage(true);
4539 return false;
4542 name = chr->GetName();
4545 assert(chr || chr_guid);
4547 int32 oldlevel = chr ? chr->getLevel() : Player::GetUInt32ValueFromDB(UNIT_FIELD_LEVEL,chr_guid);
4549 if(!px && !py) // .character level - progress reset
4550 newlevel = oldlevel;
4552 HandleCharacterLevel(chr,chr_guid,oldlevel,newlevel);
4554 if(m_session && m_session->GetPlayer() != chr) // including player==NULL
4556 std::string nameLink = playerLink(name);
4557 PSendSysMessage(LANG_YOU_CHANGE_LVL,nameLink.c_str(),newlevel);
4560 return true;
4563 bool ChatHandler::HandleLevelUpCommand(const char* args)
4565 char* px = strtok((char*)args, " ");
4566 char* py = strtok((char*)NULL, " ");
4568 // command format parsing
4569 char* pname = (char*)NULL;
4570 int addlevel = 1;
4572 if(px && py) // .levelup name level
4574 addlevel = atoi(py);
4575 pname = px;
4577 else if(px && !py) // .levelup name OR .levelup level
4579 if(isalpha(px[0])) // .levelup name
4580 pname = px;
4581 else // .levelup level
4582 addlevel = atoi(px);
4584 // else .levelup - nothing do for preparing
4586 // player
4587 Player *chr = NULL;
4588 uint64 chr_guid = 0;
4590 std::string name;
4592 if(pname) // player by name
4594 name = extractPlayerNameFromLink(pname);
4595 if(name.empty())
4597 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4598 SetSentErrorMessage(true);
4599 return false;
4602 chr = objmgr.GetPlayer(name.c_str());
4603 if(!chr) // not in game
4605 chr_guid = objmgr.GetPlayerGUIDByName(name);
4606 if (chr_guid == 0)
4608 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4609 SetSentErrorMessage(true);
4610 return false;
4614 else // player by selection
4616 chr = getSelectedPlayer();
4618 if (chr == NULL)
4620 SendSysMessage(LANG_NO_CHAR_SELECTED);
4621 SetSentErrorMessage(true);
4622 return false;
4625 name = chr->GetName();
4628 assert(chr || chr_guid);
4630 int32 oldlevel = chr ? chr->getLevel() : Player::GetUInt32ValueFromDB(UNIT_FIELD_LEVEL,chr_guid);
4631 int32 newlevel = oldlevel + addlevel;
4632 if(newlevel < 1)
4633 newlevel = 1;
4634 if(newlevel > STRONG_MAX_LEVEL) // hardcoded maximum level
4635 newlevel = STRONG_MAX_LEVEL;
4637 HandleCharacterLevel(chr,chr_guid,oldlevel,newlevel);
4639 if(m_session && m_session->GetPlayer() != chr) // including chr==NULL
4641 std::string nameLink = playerLink(name);
4642 PSendSysMessage(LANG_YOU_CHANGE_LVL,nameLink.c_str(),newlevel);
4645 return true;
4648 bool ChatHandler::HandleShowAreaCommand(const char* args)
4650 if (!*args)
4651 return false;
4653 Player *chr = getSelectedPlayer();
4654 if (chr == NULL)
4656 SendSysMessage(LANG_NO_CHAR_SELECTED);
4657 SetSentErrorMessage(true);
4658 return false;
4661 int area = GetAreaFlagByAreaID(atoi((char*)args));
4662 int offset = area / 32;
4663 uint32 val = (uint32)(1 << (area % 32));
4665 if(area<0 || offset >= 128)
4667 SendSysMessage(LANG_BAD_VALUE);
4668 SetSentErrorMessage(true);
4669 return false;
4672 uint32 currFields = chr->GetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset);
4673 chr->SetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset, (uint32)(currFields | val));
4675 SendSysMessage(LANG_EXPLORE_AREA);
4676 return true;
4679 bool ChatHandler::HandleHideAreaCommand(const char* args)
4681 if (!*args)
4682 return false;
4684 Player *chr = getSelectedPlayer();
4685 if (chr == NULL)
4687 SendSysMessage(LANG_NO_CHAR_SELECTED);
4688 SetSentErrorMessage(true);
4689 return false;
4692 int area = GetAreaFlagByAreaID(atoi((char*)args));
4693 int offset = area / 32;
4694 uint32 val = (uint32)(1 << (area % 32));
4696 if(area<0 || offset >= 128)
4698 SendSysMessage(LANG_BAD_VALUE);
4699 SetSentErrorMessage(true);
4700 return false;
4703 uint32 currFields = chr->GetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset);
4704 chr->SetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset, (uint32)(currFields ^ val));
4706 SendSysMessage(LANG_UNEXPLORE_AREA);
4707 return true;
4710 bool ChatHandler::HandleDebugUpdate(const char* args)
4712 if(!*args)
4713 return false;
4715 uint32 updateIndex;
4716 uint32 value;
4718 char* pUpdateIndex = strtok((char*)args, " ");
4720 Unit* chr = getSelectedUnit();
4721 if (chr == NULL)
4723 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
4724 SetSentErrorMessage(true);
4725 return false;
4728 if(!pUpdateIndex)
4730 return true;
4732 updateIndex = atoi(pUpdateIndex);
4733 //check updateIndex
4734 if(chr->GetTypeId() == TYPEID_PLAYER)
4736 if (updateIndex>=PLAYER_END) return true;
4738 else
4740 if (updateIndex>=UNIT_END) return true;
4743 char* pvalue = strtok(NULL, " ");
4744 if (!pvalue)
4746 value=chr->GetUInt32Value(updateIndex);
4748 PSendSysMessage(LANG_UPDATE, chr->GetGUIDLow(),updateIndex,value);
4749 return true;
4752 value=atoi(pvalue);
4754 PSendSysMessage(LANG_UPDATE_CHANGE, chr->GetGUIDLow(),updateIndex,value);
4756 chr->SetUInt32Value(updateIndex,value);
4758 return true;
4761 bool ChatHandler::HandleBankCommand(const char* /*args*/)
4763 m_session->SendShowBank( m_session->GetPlayer()->GetGUID() );
4765 return true;
4768 bool ChatHandler::HandleChangeWeather(const char* args)
4770 if(!*args)
4771 return false;
4773 //Weather is OFF
4774 if (!sWorld.getConfig(CONFIG_WEATHER))
4776 SendSysMessage(LANG_WEATHER_DISABLED);
4777 SetSentErrorMessage(true);
4778 return false;
4781 //*Change the weather of a cell
4782 char* px = strtok((char*)args, " ");
4783 char* py = strtok(NULL, " ");
4785 if (!px || !py)
4786 return false;
4788 uint32 type = (uint32)atoi(px); //0 to 3, 0: fine, 1: rain, 2: snow, 3: sand
4789 float grade = (float)atof(py); //0 to 1, sending -1 is instand good weather
4791 Player *player = m_session->GetPlayer();
4792 uint32 zoneid = player->GetZoneId();
4794 Weather* wth = sWorld.FindWeather(zoneid);
4796 if(!wth)
4797 wth = sWorld.AddWeather(zoneid);
4798 if(!wth)
4800 SendSysMessage(LANG_NO_WEATHER);
4801 SetSentErrorMessage(true);
4802 return false;
4805 wth->SetWeather(WeatherType(type), grade);
4807 return true;
4810 bool ChatHandler::HandleDebugSetValue(const char* args)
4812 if(!*args)
4813 return false;
4815 char* px = strtok((char*)args, " ");
4816 char* py = strtok(NULL, " ");
4817 char* pz = strtok(NULL, " ");
4819 if (!px || !py)
4820 return false;
4822 Unit* target = getSelectedUnit();
4823 if(!target)
4825 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
4826 SetSentErrorMessage(true);
4827 return false;
4830 uint64 guid = target->GetGUID();
4832 uint32 Opcode = (uint32)atoi(px);
4833 if(Opcode >= target->GetValuesCount())
4835 PSendSysMessage(LANG_TOO_BIG_INDEX, Opcode, GUID_LOPART(guid), target->GetValuesCount());
4836 return false;
4838 uint32 iValue;
4839 float fValue;
4840 bool isint32 = true;
4841 if(pz)
4842 isint32 = (bool)atoi(pz);
4843 if(isint32)
4845 iValue = (uint32)atoi(py);
4846 sLog.outDebug(GetMangosString(LANG_SET_UINT), GUID_LOPART(guid), Opcode, iValue);
4847 target->SetUInt32Value( Opcode , iValue );
4848 PSendSysMessage(LANG_SET_UINT_FIELD, GUID_LOPART(guid), Opcode,iValue);
4850 else
4852 fValue = (float)atof(py);
4853 sLog.outDebug(GetMangosString(LANG_SET_FLOAT), GUID_LOPART(guid), Opcode, fValue);
4854 target->SetFloatValue( Opcode , fValue );
4855 PSendSysMessage(LANG_SET_FLOAT_FIELD, GUID_LOPART(guid), Opcode,fValue);
4858 return true;
4861 bool ChatHandler::HandleDebugGetValue(const char* args)
4863 if(!*args)
4864 return false;
4866 char* px = strtok((char*)args, " ");
4867 char* pz = strtok(NULL, " ");
4869 if (!px)
4870 return false;
4872 Unit* target = getSelectedUnit();
4873 if(!target)
4875 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
4876 SetSentErrorMessage(true);
4877 return false;
4880 uint64 guid = target->GetGUID();
4882 uint32 Opcode = (uint32)atoi(px);
4883 if(Opcode >= target->GetValuesCount())
4885 PSendSysMessage(LANG_TOO_BIG_INDEX, Opcode, GUID_LOPART(guid), target->GetValuesCount());
4886 return false;
4888 uint32 iValue;
4889 float fValue;
4890 bool isint32 = true;
4891 if(pz)
4892 isint32 = (bool)atoi(pz);
4894 if(isint32)
4896 iValue = target->GetUInt32Value( Opcode );
4897 sLog.outDebug(GetMangosString(LANG_GET_UINT), GUID_LOPART(guid), Opcode, iValue);
4898 PSendSysMessage(LANG_GET_UINT_FIELD, GUID_LOPART(guid), Opcode, iValue);
4900 else
4902 fValue = target->GetFloatValue( Opcode );
4903 sLog.outDebug(GetMangosString(LANG_GET_FLOAT), GUID_LOPART(guid), Opcode, fValue);
4904 PSendSysMessage(LANG_GET_FLOAT_FIELD, GUID_LOPART(guid), Opcode, fValue);
4907 return true;
4910 bool ChatHandler::HandleSet32Bit(const char* args)
4912 if(!*args)
4913 return false;
4915 char* px = strtok((char*)args, " ");
4916 char* py = strtok(NULL, " ");
4918 if (!px || !py)
4919 return false;
4921 uint32 Opcode = (uint32)atoi(px);
4922 uint32 Value = (uint32)atoi(py);
4923 if (Value > 32) //uint32 = 32 bits
4924 return false;
4926 sLog.outDebug(GetMangosString(LANG_SET_32BIT), Opcode, Value);
4928 m_session->GetPlayer( )->SetUInt32Value( Opcode , 2^Value );
4930 PSendSysMessage(LANG_SET_32BIT_FIELD, Opcode,1);
4931 return true;
4934 bool ChatHandler::HandleDebugMod32Value(const char* args)
4936 if(!*args)
4937 return false;
4939 char* px = strtok((char*)args, " ");
4940 char* py = strtok(NULL, " ");
4942 if (!px || !py)
4943 return false;
4945 uint32 Opcode = (uint32)atoi(px);
4946 int Value = atoi(py);
4948 if(Opcode >= m_session->GetPlayer()->GetValuesCount())
4950 PSendSysMessage(LANG_TOO_BIG_INDEX, Opcode, m_session->GetPlayer()->GetGUIDLow(), m_session->GetPlayer( )->GetValuesCount());
4951 return false;
4954 sLog.outDebug(GetMangosString(LANG_CHANGE_32BIT), Opcode, Value);
4956 int CurrentValue = (int)m_session->GetPlayer( )->GetUInt32Value( Opcode );
4958 CurrentValue += Value;
4959 m_session->GetPlayer( )->SetUInt32Value( Opcode , (uint32)CurrentValue );
4961 PSendSysMessage(LANG_CHANGE_32BIT_FIELD, Opcode,CurrentValue);
4963 return true;
4966 bool ChatHandler::HandleTeleAddCommand(const char * args)
4968 if(!*args)
4969 return false;
4971 Player *player=m_session->GetPlayer();
4972 if (!player)
4973 return false;
4975 std::string name = args;
4977 if(objmgr.GetGameTele(name))
4979 SendSysMessage(LANG_COMMAND_TP_ALREADYEXIST);
4980 SetSentErrorMessage(true);
4981 return false;
4984 GameTele tele;
4985 tele.position_x = player->GetPositionX();
4986 tele.position_y = player->GetPositionY();
4987 tele.position_z = player->GetPositionZ();
4988 tele.orientation = player->GetOrientation();
4989 tele.mapId = player->GetMapId();
4990 tele.name = name;
4992 if(objmgr.AddGameTele(tele))
4994 SendSysMessage(LANG_COMMAND_TP_ADDED);
4996 else
4998 SendSysMessage(LANG_COMMAND_TP_ADDEDERR);
4999 SetSentErrorMessage(true);
5000 return false;
5003 return true;
5006 bool ChatHandler::HandleTeleDelCommand(const char * args)
5008 if(!*args)
5009 return false;
5011 std::string name = args;
5013 if(!objmgr.DeleteGameTele(name))
5015 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
5016 SetSentErrorMessage(true);
5017 return false;
5020 SendSysMessage(LANG_COMMAND_TP_DELETED);
5021 return true;
5024 bool ChatHandler::HandleListAurasCommand (const char * /*args*/)
5026 Unit *unit = getSelectedUnit();
5027 if(!unit)
5029 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5030 SetSentErrorMessage(true);
5031 return false;
5034 char const* talentStr = GetMangosString(LANG_TALENT);
5035 char const* passiveStr = GetMangosString(LANG_PASSIVE);
5037 Unit::AuraMap const& uAuras = unit->GetAuras();
5038 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURAS, uAuras.size());
5039 for (Unit::AuraMap::const_iterator itr = uAuras.begin(); itr != uAuras.end(); ++itr)
5041 bool talent = GetTalentSpellCost(itr->second->GetId()) > 0;
5043 char const* name = itr->second->GetSpellProto()->SpellName[m_session->GetSessionDbcLocale()];
5045 if (m_session)
5047 std::ostringstream ss_name;
5048 ss_name << "|cffffffff|Hspell:" << itr->second->GetId() << "|h[" << name << "]|h|r";
5050 PSendSysMessage(LANG_COMMAND_TARGET_AURADETAIL, itr->second->GetId(), itr->second->GetEffIndex(),
5051 itr->second->GetModifier()->m_auraname, itr->second->GetAuraDuration(), itr->second->GetAuraMaxDuration(),
5052 ss_name.str().c_str(),
5053 (itr->second->IsPassive() ? passiveStr : ""),(talent ? talentStr : ""),
5054 IS_PLAYER_GUID(itr->second->GetCasterGUID()) ? "player" : "creature",GUID_LOPART(itr->second->GetCasterGUID()));
5056 else
5058 PSendSysMessage(LANG_COMMAND_TARGET_AURADETAIL, itr->second->GetId(), itr->second->GetEffIndex(),
5059 itr->second->GetModifier()->m_auraname, itr->second->GetAuraDuration(), itr->second->GetAuraMaxDuration(),
5060 name,
5061 (itr->second->IsPassive() ? passiveStr : ""),(talent ? talentStr : ""),
5062 IS_PLAYER_GUID(itr->second->GetCasterGUID()) ? "player" : "creature",GUID_LOPART(itr->second->GetCasterGUID()));
5065 for (int i = 0; i < TOTAL_AURAS; ++i)
5067 Unit::AuraList const& uAuraList = unit->GetAurasByType(AuraType(i));
5068 if (uAuraList.empty()) continue;
5069 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURATYPE, uAuraList.size(), i);
5070 for (Unit::AuraList::const_iterator itr = uAuraList.begin(); itr != uAuraList.end(); ++itr)
5072 bool talent = GetTalentSpellCost((*itr)->GetId()) > 0;
5074 char const* name = (*itr)->GetSpellProto()->SpellName[m_session->GetSessionDbcLocale()];
5076 if (m_session)
5078 std::ostringstream ss_name;
5079 ss_name << "|cffffffff|Hspell:" << (*itr)->GetId() << "|h[" << name << "]|h|r";
5081 PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE, (*itr)->GetId(), (*itr)->GetEffIndex(),
5082 ss_name.str().c_str(),((*itr)->IsPassive() ? passiveStr : ""),(talent ? talentStr : ""),
5083 IS_PLAYER_GUID((*itr)->GetCasterGUID()) ? "player" : "creature",GUID_LOPART((*itr)->GetCasterGUID()));
5085 else
5087 PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE, (*itr)->GetId(), (*itr)->GetEffIndex(),
5088 name,((*itr)->IsPassive() ? passiveStr : ""),(talent ? talentStr : ""),
5089 IS_PLAYER_GUID((*itr)->GetCasterGUID()) ? "player" : "creature",GUID_LOPART((*itr)->GetCasterGUID()));
5093 return true;
5096 bool ChatHandler::HandleResetAchievementsCommand (const char * args)
5098 char* pName = strtok((char*)args, "");
5099 Player *player = NULL;
5100 uint64 guid = 0;
5101 if (pName)
5103 std::string name = extractPlayerNameFromLink(pName);
5104 if(name.empty())
5106 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5107 SetSentErrorMessage(true);
5108 return false;
5111 guid = objmgr.GetPlayerGUIDByName(name);
5112 player = objmgr.GetPlayer(guid);
5114 else
5116 player = getSelectedPlayer();
5117 if(player)
5118 guid = player->GetGUID();
5121 if(!player && !guid)
5123 SendSysMessage(LANG_NO_CHAR_SELECTED);
5124 return true;
5127 if(player)
5128 player->GetAchievementMgr().Reset();
5129 else if(guid)
5130 AchievementMgr::DeleteFromDB(GUID_LOPART(guid));
5132 return true;
5135 bool ChatHandler::HandleResetHonorCommand (const char * args)
5137 char* pName = strtok((char*)args, "");
5138 Player *player = NULL;
5139 if (pName)
5141 std::string name = extractPlayerNameFromLink(pName);
5142 if(name.empty())
5144 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5145 SetSentErrorMessage(true);
5146 return false;
5149 uint64 guid = objmgr.GetPlayerGUIDByName(name);
5150 player = objmgr.GetPlayer(guid);
5152 else
5153 player = getSelectedPlayer();
5155 if(!player)
5157 SendSysMessage(LANG_NO_CHAR_SELECTED);
5158 return true;
5161 player->SetUInt32Value(PLAYER_FIELD_KILLS, 0);
5162 player->SetUInt32Value(PLAYER_FIELD_LIFETIME_HONORBALE_KILLS, 0);
5163 player->SetUInt32Value(PLAYER_FIELD_HONOR_CURRENCY, 0);
5164 player->SetUInt32Value(PLAYER_FIELD_TODAY_CONTRIBUTION, 0);
5165 player->SetUInt32Value(PLAYER_FIELD_YESTERDAY_CONTRIBUTION, 0);
5167 player->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_EARN_HONORABLE_KILL);
5169 return true;
5172 static bool HandleResetStatsOrLevelHelper(Player* player)
5174 PlayerInfo const *info = objmgr.GetPlayerInfo(player->getRace(), player->getClass());
5175 if(!info) return false;
5177 ChrClassesEntry const* cEntry = sChrClassesStore.LookupEntry(player->getClass());
5178 if(!cEntry)
5180 sLog.outError("Class %u not found in DBC (Wrong DBC files?)",player->getClass());
5181 return false;
5184 uint8 powertype = cEntry->powerType;
5186 // reset m_form if no aura
5187 if(!player->HasAuraType(SPELL_AURA_MOD_SHAPESHIFT))
5188 player->m_form = FORM_NONE;
5190 player->SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS, DEFAULT_WORLD_OBJECT_SIZE );
5191 player->SetFloatValue(UNIT_FIELD_COMBATREACH, 1.5f );
5193 player->setFactionForRace(player->getRace());
5195 player->SetUInt32Value(UNIT_FIELD_BYTES_0, ( ( player->getRace() ) | ( player->getClass() << 8 ) | ( player->getGender() << 16 ) | ( powertype << 24 ) ) );
5197 // reset only if player not in some form;
5198 if(player->m_form==FORM_NONE)
5200 switch(player->getGender())
5202 case GENDER_FEMALE:
5203 player->SetDisplayId(info->displayId_f);
5204 player->SetNativeDisplayId(info->displayId_f);
5205 break;
5206 case GENDER_MALE:
5207 player->SetDisplayId(info->displayId_m);
5208 player->SetNativeDisplayId(info->displayId_m);
5209 break;
5210 default:
5211 break;
5215 player->SetByteValue(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_PVP );
5216 player->SetByteValue(UNIT_FIELD_BYTES_2, 3, player->m_form);
5218 player->SetUInt32Value(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE);
5220 //-1 is default value
5221 player->SetUInt32Value(PLAYER_FIELD_WATCHED_FACTION_INDEX, uint32(-1));
5223 //player->SetUInt32Value(PLAYER_FIELD_BYTES, 0xEEE00000 );
5224 return true;
5227 bool ChatHandler::HandleResetLevelCommand(const char * args)
5229 char* pName = strtok((char*)args, "");
5230 Player *player = NULL;
5231 if (pName)
5233 std::string name = extractPlayerNameFromLink(pName);
5234 if(name.empty())
5236 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5237 SetSentErrorMessage(true);
5238 return false;
5241 uint64 guid = objmgr.GetPlayerGUIDByName(name);
5242 player = objmgr.GetPlayer(guid);
5244 else
5245 player = getSelectedPlayer();
5247 if(!player)
5249 SendSysMessage(LANG_NO_CHAR_SELECTED);
5250 SetSentErrorMessage(true);
5251 return false;
5254 if(!HandleResetStatsOrLevelHelper(player))
5255 return false;
5257 // set starting level
5258 uint32 start_level = player->getClass() != CLASS_DEATH_KNIGHT
5259 ? sWorld.getConfig(CONFIG_START_PLAYER_LEVEL)
5260 : sWorld.getConfig(CONFIG_START_HEROIC_PLAYER_LEVEL);
5262 player->SetLevel(start_level);
5263 player->InitRunes();
5264 player->InitStatsForLevel(true);
5265 player->InitTaxiNodesForLevel();
5266 player->InitGlyphsForLevel();
5267 player->InitTalentForLevel();
5268 player->SetUInt32Value(PLAYER_XP,0);
5270 // reset level to summoned pet
5271 Pet* pet = player->GetPet();
5272 if(pet && pet->getPetType()==SUMMON_PET)
5274 pet->InitStatsForLevel(1);
5275 pet->InitTalentForLevel();
5277 return true;
5280 bool ChatHandler::HandleResetStatsCommand(const char * args)
5282 char* pName = strtok((char*)args, "");
5283 Player *player = NULL;
5284 if (pName)
5286 std::string name = extractPlayerNameFromLink(pName);
5287 if(name.empty())
5289 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5290 SetSentErrorMessage(true);
5291 return false;
5294 uint64 guid = objmgr.GetPlayerGUIDByName(name);
5295 player = objmgr.GetPlayer(guid);
5297 else
5298 player = getSelectedPlayer();
5300 if(!player)
5302 SendSysMessage(LANG_NO_CHAR_SELECTED);
5303 SetSentErrorMessage(true);
5304 return false;
5307 if(!HandleResetStatsOrLevelHelper(player))
5308 return false;
5310 player->InitRunes();
5311 player->InitStatsForLevel(true);
5312 player->InitTaxiNodesForLevel();
5313 player->InitGlyphsForLevel();
5314 player->InitTalentForLevel();
5316 return true;
5319 bool ChatHandler::HandleResetSpellsCommand(const char * args)
5321 char* pName = strtok((char*)args, "");
5322 Player *player = NULL;
5323 uint64 playerGUID = 0;
5324 if (pName)
5326 std::string name = extractPlayerNameFromLink(pName);
5327 if(name.empty())
5329 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5330 SetSentErrorMessage(true);
5331 return false;
5334 player = objmgr.GetPlayer(name.c_str());
5335 if(!player)
5336 playerGUID = objmgr.GetPlayerGUIDByName(name);
5338 else
5339 player = getSelectedPlayer();
5341 if(!player && !playerGUID)
5343 SendSysMessage(LANG_NO_CHAR_SELECTED);
5344 SetSentErrorMessage(true);
5345 return false;
5348 if(player)
5350 player->resetSpells();
5352 ChatHandler(player).SendSysMessage(LANG_RESET_SPELLS);
5353 if(m_session->GetPlayer()!=player)
5354 PSendSysMessage(LANG_RESET_SPELLS_ONLINE,GetNameLink(player).c_str());
5356 else
5358 CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_SPELLS), GUID_LOPART(playerGUID));
5359 PSendSysMessage(LANG_RESET_SPELLS_OFFLINE,pName);
5362 return true;
5365 bool ChatHandler::HandleResetTalentsCommand(const char * args)
5367 char* pName = strtok((char*)args, "");
5368 Player *player = NULL;
5369 uint64 playerGUID = 0;
5370 if (pName)
5372 std::string name = extractPlayerNameFromLink(pName);
5373 if(name.empty())
5375 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5376 SetSentErrorMessage(true);
5377 return false;
5380 player = objmgr.GetPlayer(name.c_str());
5381 if(!player)
5382 playerGUID = objmgr.GetPlayerGUIDByName(name);
5384 else
5385 player = getSelectedPlayer();
5387 if(player)
5389 player->resetTalents(true);
5391 ChatHandler(player).SendSysMessage(LANG_RESET_TALENTS);
5392 if(m_session->GetPlayer()!=player)
5393 PSendSysMessage(LANG_RESET_TALENTS_ONLINE,GetNameLink(player).c_str());
5395 return true;
5397 else if (playerGUID)
5399 CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_TALENTS), GUID_LOPART(playerGUID) );
5400 std::string nameLink = playerLink(pName);
5401 PSendSysMessage(LANG_RESET_TALENTS_OFFLINE,nameLink.c_str());
5402 return true;
5404 // Try reset talenents as Hunter Pet
5405 Creature* creature = getSelectedCreature();
5406 if (creature && creature->isPet() && ((Pet *)creature)->getPetType() == HUNTER_PET)
5408 ((Pet *)creature)->resetTalents(true);
5409 Unit *owner = creature->GetOwner();
5410 if (owner && owner->GetTypeId() == TYPEID_PLAYER)
5412 player = (Player *)owner;
5413 ChatHandler(player).SendSysMessage(LANG_RESET_PET_TALENTS);
5414 if(m_session->GetPlayer()!=player)
5415 PSendSysMessage(LANG_RESET_PET_TALENTS_ONLINE,GetNameLink(player).c_str());
5417 return true;
5420 SendSysMessage(LANG_NO_CHAR_SELECTED);
5421 SetSentErrorMessage(true);
5422 return false;
5425 bool ChatHandler::HandleResetAllCommand(const char * args)
5427 if(!*args)
5428 return false;
5430 std::string casename = args;
5432 AtLoginFlags atLogin;
5434 // Command specially created as single command to prevent using short case names
5435 if(casename=="spells")
5437 atLogin = AT_LOGIN_RESET_SPELLS;
5438 sWorld.SendWorldText(LANG_RESETALL_SPELLS);
5440 else if(casename=="talents")
5442 atLogin = AT_LOGIN_RESET_TALENTS;
5443 sWorld.SendWorldText(LANG_RESETALL_TALENTS);
5445 else
5447 PSendSysMessage(LANG_RESETALL_UNKNOWN_CASE,args);
5448 SetSentErrorMessage(true);
5449 return false;
5452 CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE (at_login & '%u') = '0'",atLogin,atLogin);
5453 HashMapHolder<Player>::MapType const& plist = ObjectAccessor::Instance().GetPlayers();
5454 for(HashMapHolder<Player>::MapType::const_iterator itr = plist.begin(); itr != plist.end(); ++itr)
5455 itr->second->SetAtLoginFlag(atLogin);
5457 return true;
5460 bool ChatHandler::HandleServerShutDownCancelCommand(const char* /*args*/)
5462 sWorld.ShutdownCancel();
5463 return true;
5466 bool ChatHandler::HandleServerShutDownCommand(const char* args)
5468 if(!*args)
5469 return false;
5471 char* time_str = strtok ((char*) args, " ");
5472 char* exitcode_str = strtok (NULL, "");
5474 int32 time = atoi (time_str);
5476 ///- Prevent interpret wrong arg value as 0 secs shutdown time
5477 if ((time == 0 && (time_str[0]!='0' || time_str[1]!='\0')) || time < 0)
5478 return false;
5480 if (exitcode_str)
5482 int32 exitcode = atoi (exitcode_str);
5484 // Handle atoi() errors
5485 if (exitcode == 0 && (exitcode_str[0] != '0' || exitcode_str[1] != '\0'))
5486 return false;
5488 // Exit code should be in range of 0-125, 126-255 is used
5489 // in many shells for their own return codes and code > 255
5490 // is not supported in many others
5491 if (exitcode < 0 || exitcode > 125)
5492 return false;
5494 sWorld.ShutdownServ (time, 0, exitcode);
5496 else
5497 sWorld.ShutdownServ(time,0,SHUTDOWN_EXIT_CODE);
5498 return true;
5501 bool ChatHandler::HandleServerRestartCommand(const char* args)
5503 if(!*args)
5504 return false;
5506 char* time_str = strtok ((char*) args, " ");
5507 char* exitcode_str = strtok (NULL, "");
5509 int32 time = atoi (time_str);
5511 ///- Prevent interpret wrong arg value as 0 secs shutdown time
5512 if(time == 0 && (time_str[0]!='0' || time_str[1]!='\0') || time < 0)
5513 return false;
5515 if (exitcode_str)
5517 int32 exitcode = atoi (exitcode_str);
5519 // Handle atoi() errors
5520 if (exitcode == 0 && (exitcode_str[0] != '0' || exitcode_str[1] != '\0'))
5521 return false;
5523 // Exit code should be in range of 0-125, 126-255 is used
5524 // in many shells for their own return codes and code > 255
5525 // is not supported in many others
5526 if (exitcode < 0 || exitcode > 125)
5527 return false;
5529 sWorld.ShutdownServ (time, SHUTDOWN_MASK_RESTART, exitcode);
5531 else
5532 sWorld.ShutdownServ(time, SHUTDOWN_MASK_RESTART, RESTART_EXIT_CODE);
5533 return true;
5536 bool ChatHandler::HandleServerIdleRestartCommand(const char* args)
5538 if(!*args)
5539 return false;
5541 char* time_str = strtok ((char*) args, " ");
5542 char* exitcode_str = strtok (NULL, "");
5544 int32 time = atoi (time_str);
5546 ///- Prevent interpret wrong arg value as 0 secs shutdown time
5547 if(time == 0 && (time_str[0]!='0' || time_str[1]!='\0') || time < 0)
5548 return false;
5550 if (exitcode_str)
5552 int32 exitcode = atoi (exitcode_str);
5554 // Handle atoi() errors
5555 if (exitcode == 0 && (exitcode_str[0] != '0' || exitcode_str[1] != '\0'))
5556 return false;
5558 // Exit code should be in range of 0-125, 126-255 is used
5559 // in many shells for their own return codes and code > 255
5560 // is not supported in many others
5561 if (exitcode < 0 || exitcode > 125)
5562 return false;
5564 sWorld.ShutdownServ (time, SHUTDOWN_MASK_RESTART|SHUTDOWN_MASK_IDLE, exitcode);
5566 else
5567 sWorld.ShutdownServ(time,SHUTDOWN_MASK_RESTART|SHUTDOWN_MASK_IDLE,RESTART_EXIT_CODE);
5568 return true;
5571 bool ChatHandler::HandleServerIdleShutDownCommand(const char* args)
5573 if(!*args)
5574 return false;
5576 char* time_str = strtok ((char*) args, " ");
5577 char* exitcode_str = strtok (NULL, "");
5579 int32 time = atoi (time_str);
5581 ///- Prevent interpret wrong arg value as 0 secs shutdown time
5582 if(time == 0 && (time_str[0]!='0' || time_str[1]!='\0') || time < 0)
5583 return false;
5585 if (exitcode_str)
5587 int32 exitcode = atoi (exitcode_str);
5589 // Handle atoi() errors
5590 if (exitcode == 0 && (exitcode_str[0] != '0' || exitcode_str[1] != '\0'))
5591 return false;
5593 // Exit code should be in range of 0-125, 126-255 is used
5594 // in many shells for their own return codes and code > 255
5595 // is not supported in many others
5596 if (exitcode < 0 || exitcode > 125)
5597 return false;
5599 sWorld.ShutdownServ (time, SHUTDOWN_MASK_IDLE, exitcode);
5601 else
5602 sWorld.ShutdownServ(time,SHUTDOWN_MASK_IDLE,SHUTDOWN_EXIT_CODE);
5603 return true;
5606 bool ChatHandler::HandleQuestAdd(const char* args)
5608 Player* player = getSelectedPlayer();
5609 if(!player)
5611 SendSysMessage(LANG_NO_CHAR_SELECTED);
5612 SetSentErrorMessage(true);
5613 return false;
5616 // .addquest #entry'
5617 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
5618 char* cId = extractKeyFromLink((char*)args,"Hquest");
5619 if(!cId)
5620 return false;
5622 uint32 entry = atol(cId);
5624 Quest const* pQuest = objmgr.GetQuestTemplate(entry);
5626 if(!pQuest)
5628 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND,entry);
5629 SetSentErrorMessage(true);
5630 return false;
5633 // check item starting quest (it can work incorrectly if added without item in inventory)
5634 for (uint32 id = 0; id < sItemStorage.MaxEntry; id++)
5636 ItemPrototype const *pProto = sItemStorage.LookupEntry<ItemPrototype>(id);
5637 if (!pProto)
5638 continue;
5640 if (pProto->StartQuest == entry)
5642 PSendSysMessage(LANG_COMMAND_QUEST_STARTFROMITEM, entry, pProto->ItemId);
5643 SetSentErrorMessage(true);
5644 return false;
5648 // ok, normal (creature/GO starting) quest
5649 if( player->CanAddQuest( pQuest, true ) )
5651 player->AddQuest( pQuest, NULL );
5653 if ( player->CanCompleteQuest( entry ) )
5654 player->CompleteQuest( entry );
5657 return true;
5660 bool ChatHandler::HandleQuestRemove(const char* args)
5662 Player* player = getSelectedPlayer();
5663 if(!player)
5665 SendSysMessage(LANG_NO_CHAR_SELECTED);
5666 SetSentErrorMessage(true);
5667 return false;
5670 // .removequest #entry'
5671 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
5672 char* cId = extractKeyFromLink((char*)args,"Hquest");
5673 if(!cId)
5674 return false;
5676 uint32 entry = atol(cId);
5678 Quest const* pQuest = objmgr.GetQuestTemplate(entry);
5680 if(!pQuest)
5682 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, entry);
5683 SetSentErrorMessage(true);
5684 return false;
5687 // remove all quest entries for 'entry' from quest log
5688 for(uint8 slot = 0; slot < MAX_QUEST_LOG_SIZE; ++slot )
5690 uint32 quest = player->GetQuestSlotQuestId(slot);
5691 if(quest==entry)
5693 player->SetQuestSlot(slot,0);
5695 // we ignore unequippable quest items in this case, its' still be equipped
5696 player->TakeQuestSourceItem( quest, false );
5700 // set quest status to not started (will updated in DB at next save)
5701 player->SetQuestStatus( entry, QUEST_STATUS_NONE);
5703 // reset rewarded for restart repeatable quest
5704 player->getQuestStatusMap()[entry].m_rewarded = false;
5706 SendSysMessage(LANG_COMMAND_QUEST_REMOVED);
5707 return true;
5710 bool ChatHandler::HandleQuestComplete(const char* args)
5712 Player* player = getSelectedPlayer();
5713 if(!player)
5715 SendSysMessage(LANG_NO_CHAR_SELECTED);
5716 SetSentErrorMessage(true);
5717 return false;
5720 // .quest complete #entry
5721 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
5722 char* cId = extractKeyFromLink((char*)args,"Hquest");
5723 if(!cId)
5724 return false;
5726 uint32 entry = atol(cId);
5728 Quest const* pQuest = objmgr.GetQuestTemplate(entry);
5730 // If player doesn't have the quest
5731 if(!pQuest || player->GetQuestStatus(entry) == QUEST_STATUS_NONE)
5733 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, entry);
5734 SetSentErrorMessage(true);
5735 return false;
5738 // Add quest items for quests that require items
5739 for(uint8 x = 0; x < QUEST_OBJECTIVES_COUNT; ++x)
5741 uint32 id = pQuest->ReqItemId[x];
5742 uint32 count = pQuest->ReqItemCount[x];
5743 if(!id || !count)
5744 continue;
5746 uint32 curItemCount = player->GetItemCount(id,true);
5748 ItemPosCountVec dest;
5749 uint8 msg = player->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, id, count-curItemCount );
5750 if( msg == EQUIP_ERR_OK )
5752 Item* item = player->StoreNewItem( dest, id, true);
5753 player->SendNewItem(item,count-curItemCount,true,false);
5757 // All creature/GO slain/casted (not required, but otherwise it will display "Creature slain 0/10")
5758 for(uint8 i = 0; i < QUEST_OBJECTIVES_COUNT; ++i)
5760 uint32 creature = pQuest->ReqCreatureOrGOId[i];
5761 uint32 creaturecount = pQuest->ReqCreatureOrGOCount[i];
5763 if(uint32 spell_id = pQuest->ReqSpell[i])
5765 for(uint16 z = 0; z < creaturecount; ++z)
5766 player->CastedCreatureOrGO(creature,0,spell_id);
5768 else if(creature > 0)
5770 for(uint16 z = 0; z < creaturecount; ++z)
5771 player->KilledMonster(creature,0);
5773 else if(creature < 0)
5775 for(uint16 z = 0; z < creaturecount; ++z)
5776 player->CastedCreatureOrGO(creature,0,0);
5780 // If the quest requires reputation to complete
5781 if(uint32 repFaction = pQuest->GetRepObjectiveFaction())
5783 uint32 repValue = pQuest->GetRepObjectiveValue();
5784 uint32 curRep = player->GetReputationMgr().GetReputation(repFaction);
5785 if(curRep < repValue)
5786 if(FactionEntry const *factionEntry = sFactionStore.LookupEntry(repFaction))
5787 player->GetReputationMgr().SetReputation(factionEntry,repValue);
5790 // If the quest requires money
5791 int32 ReqOrRewMoney = pQuest->GetRewOrReqMoney();
5792 if(ReqOrRewMoney < 0)
5793 player->ModifyMoney(-ReqOrRewMoney);
5795 player->CompleteQuest(entry);
5796 return true;
5799 bool ChatHandler::HandleBanAccountCommand(const char* args)
5801 return HandleBanHelper(BAN_ACCOUNT,args);
5804 bool ChatHandler::HandleBanCharacterCommand(const char* args)
5806 return HandleBanHelper(BAN_CHARACTER,args);
5809 bool ChatHandler::HandleBanIPCommand(const char* args)
5811 return HandleBanHelper(BAN_IP,args);
5814 bool ChatHandler::HandleBanHelper(BanMode mode, const char* args)
5816 if (!*args)
5817 return false;
5819 char* cnameOrIP = strtok ((char*)args, " ");
5820 if (!cnameOrIP)
5821 return false;
5823 std::string nameOrIP = cnameOrIP;
5825 char* duration = strtok (NULL," ");
5826 if(!duration || !atoi(duration))
5827 return false;
5829 char* reason = strtok (NULL,"");
5830 if(!reason)
5831 return false;
5833 switch(mode)
5835 case BAN_ACCOUNT:
5836 if(!AccountMgr::normilizeString(nameOrIP))
5838 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,nameOrIP.c_str());
5839 SetSentErrorMessage(true);
5840 return false;
5842 break;
5843 case BAN_CHARACTER:
5844 if(!normalizePlayerName(nameOrIP))
5846 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5847 SetSentErrorMessage(true);
5848 return false;
5850 break;
5851 case BAN_IP:
5852 if(!IsIPAddress(nameOrIP.c_str()))
5853 return false;
5854 break;
5857 switch(sWorld.BanAccount(mode, nameOrIP, duration, reason,m_session ? m_session->GetPlayerName() : ""))
5859 case BAN_SUCCESS:
5860 if(atoi(duration)>0)
5861 PSendSysMessage(LANG_BAN_YOUBANNED,nameOrIP.c_str(),secsToTimeString(TimeStringToSecs(duration),true).c_str(),reason);
5862 else
5863 PSendSysMessage(LANG_BAN_YOUPERMBANNED,nameOrIP.c_str(),reason);
5864 break;
5865 case BAN_SYNTAX_ERROR:
5866 return false;
5867 case BAN_NOTFOUND:
5868 switch(mode)
5870 default:
5871 PSendSysMessage(LANG_BAN_NOTFOUND,"account",nameOrIP.c_str());
5872 break;
5873 case BAN_CHARACTER:
5874 PSendSysMessage(LANG_BAN_NOTFOUND,"character",nameOrIP.c_str());
5875 break;
5876 case BAN_IP:
5877 PSendSysMessage(LANG_BAN_NOTFOUND,"ip",nameOrIP.c_str());
5878 break;
5880 SetSentErrorMessage(true);
5881 return false;
5884 return true;
5887 bool ChatHandler::HandleUnBanAccountCommand(const char* args)
5889 return HandleUnBanHelper(BAN_ACCOUNT,args);
5892 bool ChatHandler::HandleUnBanCharacterCommand(const char* args)
5894 return HandleUnBanHelper(BAN_CHARACTER,args);
5897 bool ChatHandler::HandleUnBanIPCommand(const char* args)
5899 return HandleUnBanHelper(BAN_IP,args);
5902 bool ChatHandler::HandleUnBanHelper(BanMode mode, const char* args)
5904 if (!*args)
5905 return false;
5907 char* cnameOrIP = strtok ((char*)args, " ");
5908 if(!cnameOrIP)
5909 return false;
5911 std::string nameOrIP = cnameOrIP;
5913 switch(mode)
5915 case BAN_ACCOUNT:
5916 if(!AccountMgr::normilizeString(nameOrIP))
5918 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,nameOrIP.c_str());
5919 SetSentErrorMessage(true);
5920 return false;
5922 break;
5923 case BAN_CHARACTER:
5924 if(!normalizePlayerName(nameOrIP))
5926 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5927 SetSentErrorMessage(true);
5928 return false;
5930 break;
5931 case BAN_IP:
5932 if(!IsIPAddress(nameOrIP.c_str()))
5933 return false;
5934 break;
5937 if(sWorld.RemoveBanAccount(mode,nameOrIP))
5938 PSendSysMessage(LANG_UNBAN_UNBANNED,nameOrIP.c_str());
5939 else
5940 PSendSysMessage(LANG_UNBAN_ERROR,nameOrIP.c_str());
5942 return true;
5945 bool ChatHandler::HandleBanInfoAccountCommand(const char* args)
5947 if (!*args)
5948 return false;
5950 char* cname = strtok((char*)args, "");
5951 if(!cname)
5952 return false;
5954 std::string account_name = cname;
5955 if(!AccountMgr::normilizeString(account_name))
5957 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5958 SetSentErrorMessage(true);
5959 return false;
5962 uint32 accountid = accmgr.GetId(account_name);
5963 if(!accountid)
5965 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5966 return true;
5969 return HandleBanInfoHelper(accountid,account_name.c_str());
5972 bool ChatHandler::HandleBanInfoCharacterCommand(const char* args)
5974 if (!*args)
5975 return false;
5977 std::string name = extractPlayerNameFromLink((char*)args);
5978 if(name.empty())
5980 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5981 SetSentErrorMessage(true);
5982 return false;
5985 uint32 accountid = objmgr.GetPlayerAccountIdByPlayerName(name);
5986 if(!accountid)
5988 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5989 SetSentErrorMessage(true);
5990 return false;
5993 std::string accountname;
5994 if(!accmgr.GetName(accountid,accountname))
5996 PSendSysMessage(LANG_BANINFO_NOCHARACTER);
5997 return true;
6000 return HandleBanInfoHelper(accountid,accountname.c_str());
6003 bool ChatHandler::HandleBanInfoHelper(uint32 accountid, char const* accountname)
6005 QueryResult *result = loginDatabase.PQuery("SELECT FROM_UNIXTIME(bandate), unbandate-bandate, active, unbandate,banreason,bannedby FROM account_banned WHERE id = '%u' ORDER BY bandate ASC",accountid);
6006 if(!result)
6008 PSendSysMessage(LANG_BANINFO_NOACCOUNTBAN, accountname);
6009 return true;
6012 PSendSysMessage(LANG_BANINFO_BANHISTORY,accountname);
6015 Field* fields = result->Fetch();
6017 time_t unbandate = time_t(fields[3].GetUInt64());
6018 bool active = false;
6019 if(fields[2].GetBool() && (fields[1].GetUInt64() == (uint64)0 ||unbandate >= time(NULL)) )
6020 active = true;
6021 bool permanent = (fields[1].GetUInt64() == (uint64)0);
6022 std::string bantime = permanent?GetMangosString(LANG_BANINFO_INFINITE):secsToTimeString(fields[1].GetUInt64(), true);
6023 PSendSysMessage(LANG_BANINFO_HISTORYENTRY,
6024 fields[0].GetString(), bantime.c_str(), active ? GetMangosString(LANG_BANINFO_YES):GetMangosString(LANG_BANINFO_NO), fields[4].GetString(), fields[5].GetString());
6025 }while (result->NextRow());
6027 delete result;
6028 return true;
6031 bool ChatHandler::HandleBanInfoIPCommand(const char* args)
6033 if (!*args)
6034 return false;
6036 char* cIP = strtok ((char*)args, "");
6037 if(!cIP)
6038 return false;
6040 if (!IsIPAddress(cIP))
6041 return false;
6043 std::string IP = cIP;
6045 loginDatabase.escape_string(IP);
6046 QueryResult *result = loginDatabase.PQuery("SELECT ip, FROM_UNIXTIME(bandate), FROM_UNIXTIME(unbandate), unbandate-UNIX_TIMESTAMP(), banreason,bannedby,unbandate-bandate FROM ip_banned WHERE ip = '%s'",IP.c_str());
6047 if(!result)
6049 PSendSysMessage(LANG_BANINFO_NOIP);
6050 return true;
6053 Field *fields = result->Fetch();
6054 bool permanent = !fields[6].GetUInt64();
6055 PSendSysMessage(LANG_BANINFO_IPENTRY,
6056 fields[0].GetString(), fields[1].GetString(), permanent ? GetMangosString(LANG_BANINFO_NEVER):fields[2].GetString(),
6057 permanent ? GetMangosString(LANG_BANINFO_INFINITE):secsToTimeString(fields[3].GetUInt64(), true).c_str(), fields[4].GetString(), fields[5].GetString());
6058 delete result;
6059 return true;
6062 bool ChatHandler::HandleBanListCharacterCommand(const char* args)
6064 loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
6066 char* cFilter = strtok ((char*)args, " ");
6067 if(!cFilter)
6068 return false;
6070 std::string filter = cFilter;
6071 loginDatabase.escape_string(filter);
6072 QueryResult* result = CharacterDatabase.PQuery("SELECT account FROM characters WHERE name "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'"),filter.c_str());
6073 if (!result)
6075 PSendSysMessage(LANG_BANLIST_NOCHARACTER);
6076 return true;
6079 return HandleBanListHelper(result);
6082 bool ChatHandler::HandleBanListAccountCommand(const char* args)
6084 loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
6086 char* cFilter = strtok((char*)args, " ");
6087 std::string filter = cFilter ? cFilter : "";
6088 loginDatabase.escape_string(filter);
6090 QueryResult* result;
6092 if(filter.empty())
6094 result = loginDatabase.Query("SELECT account.id, username FROM account, account_banned"
6095 " WHERE account.id = account_banned.id AND active = 1 GROUP BY account.id");
6097 else
6099 result = loginDatabase.PQuery("SELECT account.id, username FROM account, account_banned"
6100 " WHERE account.id = account_banned.id AND active = 1 AND username "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'")" GROUP BY account.id",
6101 filter.c_str());
6104 if (!result)
6106 PSendSysMessage(LANG_BANLIST_NOACCOUNT);
6107 return true;
6110 return HandleBanListHelper(result);
6113 bool ChatHandler::HandleBanListHelper(QueryResult* result)
6115 PSendSysMessage(LANG_BANLIST_MATCHINGACCOUNT);
6117 // Chat short output
6118 if(m_session)
6122 Field* fields = result->Fetch();
6123 uint32 accountid = fields[0].GetUInt32();
6125 QueryResult* banresult = loginDatabase.PQuery("SELECT account.username FROM account,account_banned WHERE account_banned.id='%u' AND account_banned.id=account.id",accountid);
6126 if(banresult)
6128 Field* fields2 = banresult->Fetch();
6129 PSendSysMessage("%s",fields2[0].GetString());
6130 delete banresult;
6132 } while (result->NextRow());
6134 // Console wide output
6135 else
6137 SendSysMessage(LANG_BANLIST_ACCOUNTS);
6138 SendSysMessage("===============================================================================");
6139 SendSysMessage(LANG_BANLIST_ACCOUNTS_HEADER);
6142 SendSysMessage("-------------------------------------------------------------------------------");
6143 Field *fields = result->Fetch();
6144 uint32 account_id = fields[0].GetUInt32 ();
6146 std::string account_name;
6148 // "account" case, name can be get in same query
6149 if(result->GetFieldCount() > 1)
6150 account_name = fields[1].GetCppString();
6151 // "character" case, name need extract from another DB
6152 else
6153 accmgr.GetName (account_id,account_name);
6155 // No SQL injection. id is uint32.
6156 QueryResult *banInfo = loginDatabase.PQuery("SELECT bandate,unbandate,bannedby,banreason FROM account_banned WHERE id = %u ORDER BY unbandate", account_id);
6157 if (banInfo)
6159 Field *fields2 = banInfo->Fetch();
6162 time_t t_ban = fields2[0].GetUInt64();
6163 tm* aTm_ban = localtime(&t_ban);
6165 if (fields2[0].GetUInt64() == fields2[1].GetUInt64())
6167 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
6168 account_name.c_str(),aTm_ban->tm_year%100, aTm_ban->tm_mon+1, aTm_ban->tm_mday, aTm_ban->tm_hour, aTm_ban->tm_min,
6169 fields2[2].GetString(),fields2[3].GetString());
6171 else
6173 time_t t_unban = fields2[1].GetUInt64();
6174 tm* aTm_unban = localtime(&t_unban);
6175 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
6176 account_name.c_str(),aTm_ban->tm_year%100, aTm_ban->tm_mon+1, aTm_ban->tm_mday, aTm_ban->tm_hour, aTm_ban->tm_min,
6177 aTm_unban->tm_year%100, aTm_unban->tm_mon+1, aTm_unban->tm_mday, aTm_unban->tm_hour, aTm_unban->tm_min,
6178 fields2[2].GetString(),fields2[3].GetString());
6180 }while ( banInfo->NextRow() );
6181 delete banInfo;
6183 }while( result->NextRow() );
6184 SendSysMessage("===============================================================================");
6187 delete result;
6188 return true;
6191 bool ChatHandler::HandleBanListIPCommand(const char* args)
6193 loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
6195 char* cFilter = strtok((char*)args, " ");
6196 std::string filter = cFilter ? cFilter : "";
6197 loginDatabase.escape_string(filter);
6199 QueryResult* result;
6201 if(filter.empty())
6203 result = loginDatabase.Query ("SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
6204 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP())"
6205 " ORDER BY unbandate" );
6207 else
6209 result = loginDatabase.PQuery( "SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
6210 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP()) AND ip "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'")
6211 " ORDER BY unbandate",filter.c_str() );
6214 if(!result)
6216 PSendSysMessage(LANG_BANLIST_NOIP);
6217 return true;
6220 PSendSysMessage(LANG_BANLIST_MATCHINGIP);
6221 // Chat short output
6222 if(m_session)
6226 Field* fields = result->Fetch();
6227 PSendSysMessage("%s",fields[0].GetString());
6228 } while (result->NextRow());
6230 // Console wide output
6231 else
6233 SendSysMessage(LANG_BANLIST_IPS);
6234 SendSysMessage("===============================================================================");
6235 SendSysMessage(LANG_BANLIST_IPS_HEADER);
6238 SendSysMessage("-------------------------------------------------------------------------------");
6239 Field *fields = result->Fetch();
6240 time_t t_ban = fields[1].GetUInt64();
6241 tm* aTm_ban = localtime(&t_ban);
6242 if ( fields[1].GetUInt64() == fields[2].GetUInt64() )
6244 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
6245 fields[0].GetString(), aTm_ban->tm_year%100, aTm_ban->tm_mon+1, aTm_ban->tm_mday, aTm_ban->tm_hour, aTm_ban->tm_min,
6246 fields[3].GetString(), fields[4].GetString());
6248 else
6250 time_t t_unban = fields[2].GetUInt64();
6251 tm* aTm_unban = localtime(&t_unban);
6252 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
6253 fields[0].GetString(), aTm_ban->tm_year%100, aTm_ban->tm_mon+1, aTm_ban->tm_mday, aTm_ban->tm_hour, aTm_ban->tm_min,
6254 aTm_unban->tm_year%100, aTm_unban->tm_mon+1, aTm_unban->tm_mday, aTm_unban->tm_hour, aTm_unban->tm_min,
6255 fields[3].GetString(), fields[4].GetString());
6257 }while( result->NextRow() );
6258 SendSysMessage("===============================================================================");
6261 delete result;
6262 return true;
6265 bool ChatHandler::HandleRespawnCommand(const char* /*args*/)
6267 Player* pl = m_session->GetPlayer();
6269 // accept only explicitly selected target (not implicitly self targeting case)
6270 Unit* target = getSelectedUnit();
6271 if(pl->GetSelection() && target)
6273 if(target->GetTypeId()!=TYPEID_UNIT)
6275 SendSysMessage(LANG_SELECT_CREATURE);
6276 SetSentErrorMessage(true);
6277 return false;
6280 if(target->isDead())
6281 ((Creature*)target)->Respawn();
6282 return true;
6285 CellPair p(MaNGOS::ComputeCellPair(pl->GetPositionX(), pl->GetPositionY()));
6286 Cell cell(p);
6287 cell.data.Part.reserved = ALL_DISTRICT;
6288 cell.SetNoCreate();
6290 MaNGOS::RespawnDo u_do;
6291 MaNGOS::WorldObjectWorker<MaNGOS::RespawnDo> worker(pl,u_do);
6293 TypeContainerVisitor<MaNGOS::WorldObjectWorker<MaNGOS::RespawnDo>, GridTypeMapContainer > obj_worker(worker);
6294 CellLock<GridReadGuard> cell_lock(cell, p);
6295 cell_lock->Visit(cell_lock, obj_worker, *pl->GetMap());
6297 return true;
6300 bool ChatHandler::HandleGMFlyCommand(const char* args)
6302 if (!*args)
6303 return false;
6305 Player *target = getSelectedPlayer();
6306 if (!target)
6307 target = m_session->GetPlayer();
6309 WorldPacket data(12);
6310 if (strncmp(args, "on", 3) == 0)
6311 data.SetOpcode(SMSG_MOVE_SET_CAN_FLY);
6312 else if (strncmp(args, "off", 4) == 0)
6313 data.SetOpcode(SMSG_MOVE_UNSET_CAN_FLY);
6314 else
6316 SendSysMessage(LANG_USE_BOL);
6317 return false;
6319 data.append(target->GetPackGUID());
6320 data << uint32(0); // unknown
6321 target->SendMessageToSet(&data, true);
6322 PSendSysMessage(LANG_COMMAND_FLYMODE_STATUS, GetNameLink(target).c_str(), args);
6323 return true;
6326 bool ChatHandler::HandlePDumpLoadCommand(const char *args)
6328 if (!*args)
6329 return false;
6331 char * file = strtok((char*)args, " ");
6332 if(!file)
6333 return false;
6335 char * account = strtok(NULL, " ");
6336 if(!account)
6337 return false;
6339 std::string account_name = account;
6340 if(!AccountMgr::normilizeString(account_name))
6342 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
6343 SetSentErrorMessage(true);
6344 return false;
6347 uint32 account_id = accmgr.GetId(account_name);
6348 if(!account_id)
6350 account_id = atoi(account); // use original string
6351 if(!account_id)
6353 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
6354 SetSentErrorMessage(true);
6355 return false;
6359 if(!accmgr.GetName(account_id,account_name))
6361 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
6362 SetSentErrorMessage(true);
6363 return false;
6366 char* guid_str = NULL;
6367 char* name_str = strtok(NULL, " ");
6369 std::string name;
6370 if(name_str)
6372 name = name_str;
6373 // normalize the name if specified and check if it exists
6374 if(!normalizePlayerName(name))
6376 PSendSysMessage(LANG_INVALID_CHARACTER_NAME);
6377 SetSentErrorMessage(true);
6378 return false;
6381 if(!ObjectMgr::IsValidName(name,true))
6383 PSendSysMessage(LANG_INVALID_CHARACTER_NAME);
6384 SetSentErrorMessage(true);
6385 return false;
6388 guid_str = strtok(NULL, " ");
6391 uint32 guid = 0;
6393 if(guid_str)
6395 guid = atoi(guid_str);
6396 if(!guid)
6398 PSendSysMessage(LANG_INVALID_CHARACTER_GUID);
6399 SetSentErrorMessage(true);
6400 return false;
6403 if(objmgr.GetPlayerAccountIdByGUID(guid))
6405 PSendSysMessage(LANG_CHARACTER_GUID_IN_USE,guid);
6406 SetSentErrorMessage(true);
6407 return false;
6411 switch(PlayerDumpReader().LoadDump(file, account_id, name, guid))
6413 case DUMP_SUCCESS:
6414 PSendSysMessage(LANG_COMMAND_IMPORT_SUCCESS);
6415 break;
6416 case DUMP_FILE_OPEN_ERROR:
6417 PSendSysMessage(LANG_FILE_OPEN_FAIL,file);
6418 SetSentErrorMessage(true);
6419 return false;
6420 case DUMP_FILE_BROKEN:
6421 PSendSysMessage(LANG_DUMP_BROKEN,file);
6422 SetSentErrorMessage(true);
6423 return false;
6424 case DUMP_TOO_MANY_CHARS:
6425 PSendSysMessage(LANG_ACCOUNT_CHARACTER_LIST_FULL,account_name.c_str(),account_id);
6426 SetSentErrorMessage(true);
6427 return false;
6428 default:
6429 PSendSysMessage(LANG_COMMAND_IMPORT_FAILED);
6430 SetSentErrorMessage(true);
6431 return false;
6434 return true;
6437 bool ChatHandler::HandlePDumpWriteCommand(const char *args)
6439 if (!*args)
6440 return false;
6442 char* file = strtok((char*)args, " ");
6443 char* p2 = strtok(NULL, " ");
6445 if(!file || !p2)
6446 return false;
6448 uint32 guid;
6449 // character name can't start from number
6450 if (isNumeric(p2[0]))
6451 guid = atoi(p2);
6452 else
6454 std::string name = extractPlayerNameFromLink(p2);
6455 if(name.empty())
6457 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6458 SetSentErrorMessage(true);
6459 return false;
6462 guid = objmgr.GetPlayerGUIDByName(name);
6465 if(!objmgr.GetPlayerAccountIdByGUID(guid))
6467 PSendSysMessage(LANG_PLAYER_NOT_FOUND);
6468 SetSentErrorMessage(true);
6469 return false;
6472 switch(PlayerDumpWriter().WriteDump(file, guid))
6474 case DUMP_SUCCESS:
6475 PSendSysMessage(LANG_COMMAND_EXPORT_SUCCESS);
6476 break;
6477 case DUMP_FILE_OPEN_ERROR:
6478 PSendSysMessage(LANG_FILE_OPEN_FAIL,file);
6479 SetSentErrorMessage(true);
6480 return false;
6481 default:
6482 PSendSysMessage(LANG_COMMAND_EXPORT_FAILED);
6483 SetSentErrorMessage(true);
6484 return false;
6487 return true;
6490 bool ChatHandler::HandleMovegensCommand(const char* /*args*/)
6492 Unit* unit = getSelectedUnit();
6493 if(!unit)
6495 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
6496 SetSentErrorMessage(true);
6497 return false;
6500 PSendSysMessage(LANG_MOVEGENS_LIST,(unit->GetTypeId()==TYPEID_PLAYER ? "Player" : "Creature" ),unit->GetGUIDLow());
6502 MotionMaster* mm = unit->GetMotionMaster();
6503 for(MotionMaster::const_iterator itr = mm->begin(); itr != mm->end(); ++itr)
6505 switch((*itr)->GetMovementGeneratorType())
6507 case IDLE_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_IDLE); break;
6508 case RANDOM_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_RANDOM); break;
6509 case WAYPOINT_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_WAYPOINT); break;
6510 case ANIMAL_RANDOM_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_ANIMAL_RANDOM); break;
6511 case CONFUSED_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_CONFUSED); break;
6512 case TARGETED_MOTION_TYPE:
6514 if(unit->GetTypeId()==TYPEID_PLAYER)
6516 TargetedMovementGenerator<Player> const* mgen = static_cast<TargetedMovementGenerator<Player> const*>(*itr);
6517 Unit* target = mgen->GetTarget();
6518 if(target)
6519 PSendSysMessage(LANG_MOVEGENS_TARGETED_PLAYER,target->GetName(),target->GetGUIDLow());
6520 else
6521 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL);
6523 else
6525 TargetedMovementGenerator<Creature> const* mgen = static_cast<TargetedMovementGenerator<Creature> const*>(*itr);
6526 Unit* target = mgen->GetTarget();
6527 if(target)
6528 PSendSysMessage(LANG_MOVEGENS_TARGETED_CREATURE,target->GetName(),target->GetGUIDLow());
6529 else
6530 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL);
6532 break;
6534 case HOME_MOTION_TYPE:
6535 if(unit->GetTypeId()==TYPEID_UNIT)
6537 float x,y,z;
6538 (*itr)->GetDestination(x,y,z);
6539 PSendSysMessage(LANG_MOVEGENS_HOME_CREATURE,x,y,z);
6541 else
6542 SendSysMessage(LANG_MOVEGENS_HOME_PLAYER);
6543 break;
6544 case FLIGHT_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_FLIGHT); break;
6545 case POINT_MOTION_TYPE:
6547 float x,y,z;
6548 (*itr)->GetDestination(x,y,z);
6549 PSendSysMessage(LANG_MOVEGENS_POINT,x,y,z);
6550 break;
6552 case FLEEING_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_FEAR); break;
6553 case DISTRACT_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_DISTRACT); break;
6554 default:
6555 PSendSysMessage(LANG_MOVEGENS_UNKNOWN,(*itr)->GetMovementGeneratorType());
6556 break;
6559 return true;
6562 bool ChatHandler::HandleServerPLimitCommand(const char *args)
6564 if(*args)
6566 char* param = strtok((char*)args, " ");
6567 if(!param)
6568 return false;
6570 int l = strlen(param);
6572 if( strncmp(param,"player",l) == 0 )
6573 sWorld.SetPlayerLimit(-SEC_PLAYER);
6574 else if(strncmp(param,"moderator",l) == 0 )
6575 sWorld.SetPlayerLimit(-SEC_MODERATOR);
6576 else if(strncmp(param,"gamemaster",l) == 0 )
6577 sWorld.SetPlayerLimit(-SEC_GAMEMASTER);
6578 else if(strncmp(param,"administrator",l) == 0 )
6579 sWorld.SetPlayerLimit(-SEC_ADMINISTRATOR);
6580 else if(strncmp(param,"reset",l) == 0 )
6581 sWorld.SetPlayerLimit( sConfig.GetIntDefault("PlayerLimit", DEFAULT_PLAYER_LIMIT) );
6582 else
6584 int val = atoi(param);
6585 if(val < -SEC_ADMINISTRATOR) val = -SEC_ADMINISTRATOR;
6587 sWorld.SetPlayerLimit(val);
6590 // kick all low security level players
6591 if(sWorld.GetPlayerAmountLimit() > SEC_PLAYER)
6592 sWorld.KickAllLess(sWorld.GetPlayerSecurityLimit());
6595 uint32 pLimit = sWorld.GetPlayerAmountLimit();
6596 AccountTypes allowedAccountType = sWorld.GetPlayerSecurityLimit();
6597 char const* secName = "";
6598 switch(allowedAccountType)
6600 case SEC_PLAYER: secName = "Player"; break;
6601 case SEC_MODERATOR: secName = "Moderator"; break;
6602 case SEC_GAMEMASTER: secName = "Gamemaster"; break;
6603 case SEC_ADMINISTRATOR: secName = "Administrator"; break;
6604 default: secName = "<unknown>"; break;
6607 PSendSysMessage("Player limits: amount %u, min. security level %s.",pLimit,secName);
6609 return true;
6612 bool ChatHandler::HandleCastCommand(const char* args)
6614 if(!*args)
6615 return false;
6617 Unit* target = getSelectedUnit();
6619 if(!target)
6621 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
6622 SetSentErrorMessage(true);
6623 return false;
6626 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
6627 uint32 spell = extractSpellIdFromLink((char*)args);
6628 if(!spell)
6629 return false;
6631 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
6632 if(!spellInfo)
6633 return false;
6635 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
6637 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
6638 SetSentErrorMessage(true);
6639 return false;
6642 char* trig_str = strtok(NULL, " ");
6643 if(trig_str)
6645 int l = strlen(trig_str);
6646 if(strncmp(trig_str,"triggered",l) != 0 )
6647 return false;
6650 bool triggered = (trig_str != NULL);
6652 m_session->GetPlayer()->CastSpell(target,spell,triggered);
6654 return true;
6657 bool ChatHandler::HandleCastBackCommand(const char* args)
6659 Creature* caster = getSelectedCreature();
6661 if(!caster)
6663 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
6664 SetSentErrorMessage(true);
6665 return false;
6668 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
6669 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
6670 uint32 spell = extractSpellIdFromLink((char*)args);
6671 if(!spell || !sSpellStore.LookupEntry(spell))
6672 return false;
6674 char* trig_str = strtok(NULL, " ");
6675 if(trig_str)
6677 int l = strlen(trig_str);
6678 if(strncmp(trig_str,"triggered",l) != 0 )
6679 return false;
6682 bool triggered = (trig_str != NULL);
6684 // update orientation at server
6685 caster->SetOrientation(caster->GetAngle(m_session->GetPlayer()));
6687 // and client
6688 WorldPacket data;
6689 caster->BuildHeartBeatMsg(&data);
6690 caster->SendMessageToSet(&data,true);
6692 caster->CastSpell(m_session->GetPlayer(),spell,triggered);
6694 return true;
6697 bool ChatHandler::HandleCastDistCommand(const char* args)
6699 if(!*args)
6700 return false;
6702 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
6703 uint32 spell = extractSpellIdFromLink((char*)args);
6704 if(!spell)
6705 return false;
6707 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
6708 if(!spellInfo)
6709 return false;
6711 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
6713 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
6714 SetSentErrorMessage(true);
6715 return false;
6718 char *distStr = strtok(NULL, " ");
6720 float dist = 0;
6722 if(distStr)
6723 sscanf(distStr, "%f", &dist);
6725 char* trig_str = strtok(NULL, " ");
6726 if(trig_str)
6728 int l = strlen(trig_str);
6729 if(strncmp(trig_str,"triggered",l) != 0 )
6730 return false;
6733 bool triggered = (trig_str != NULL);
6735 float x,y,z;
6736 m_session->GetPlayer()->GetClosePoint(x,y,z,dist);
6738 m_session->GetPlayer()->CastSpell(x,y,z,spell,triggered);
6739 return true;
6742 bool ChatHandler::HandleCastTargetCommand(const char* args)
6744 Creature* caster = getSelectedCreature();
6746 if(!caster)
6748 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
6749 SetSentErrorMessage(true);
6750 return false;
6753 if(!caster->getVictim())
6755 SendSysMessage(LANG_SELECTED_TARGET_NOT_HAVE_VICTIM);
6756 SetSentErrorMessage(true);
6757 return false;
6760 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
6761 uint32 spell = extractSpellIdFromLink((char*)args);
6762 if(!spell || !sSpellStore.LookupEntry(spell))
6763 return false;
6765 char* trig_str = strtok(NULL, " ");
6766 if(trig_str)
6768 int l = strlen(trig_str);
6769 if(strncmp(trig_str,"triggered",l) != 0 )
6770 return false;
6773 bool triggered = (trig_str != NULL);
6775 // update orientation at server
6776 caster->SetOrientation(caster->GetAngle(m_session->GetPlayer()));
6778 // and client
6779 WorldPacket data;
6780 caster->BuildHeartBeatMsg(&data);
6781 caster->SendMessageToSet(&data,true);
6783 caster->CastSpell(caster->getVictim(),spell,triggered);
6785 return true;
6789 ComeToMe command REQUIRED for 3rd party scripting library to have access to PointMovementGenerator
6790 Without this function 3rd party scripting library will get linking errors (unresolved external)
6791 when attempting to use the PointMovementGenerator
6793 bool ChatHandler::HandleComeToMeCommand(const char *args)
6795 Creature* caster = getSelectedCreature();
6797 if(!caster)
6799 SendSysMessage(LANG_SELECT_CREATURE);
6800 SetSentErrorMessage(true);
6801 return false;
6804 char* newFlagStr = strtok((char*)args, " ");
6806 if(!newFlagStr)
6807 return false;
6809 uint32 newFlags = atoi(newFlagStr);
6811 caster->SetUnitMovementFlags(newFlags);
6813 Player* pl = m_session->GetPlayer();
6815 caster->GetMotionMaster()->MovePoint(0, pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ());
6816 return true;
6819 bool ChatHandler::HandleCastSelfCommand(const char* args)
6821 if(!*args)
6822 return false;
6824 Unit* target = getSelectedUnit();
6826 if(!target)
6828 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
6829 SetSentErrorMessage(true);
6830 return false;
6833 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
6834 uint32 spell = extractSpellIdFromLink((char*)args);
6835 if(!spell)
6836 return false;
6838 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
6839 if(!spellInfo)
6840 return false;
6842 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
6844 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
6845 SetSentErrorMessage(true);
6846 return false;
6849 target->CastSpell(target,spell,false);
6851 return true;
6854 std::string GetTimeString(uint32 time)
6856 uint16 days = time / DAY, hours = (time % DAY) / HOUR, minute = (time % HOUR) / MINUTE;
6857 std::ostringstream ss;
6858 if(days) ss << days << "d ";
6859 if(hours) ss << hours << "h ";
6860 ss << minute << "m";
6861 return ss.str();
6864 bool ChatHandler::HandleInstanceListBindsCommand(const char* /*args*/)
6866 Player* player = getSelectedPlayer();
6867 if (!player) player = m_session->GetPlayer();
6868 uint32 counter = 0;
6869 for(uint8 i = 0; i < TOTAL_DIFFICULTIES; ++i)
6871 Player::BoundInstancesMap &binds = player->GetBoundInstances(i);
6872 for(Player::BoundInstancesMap::const_iterator itr = binds.begin(); itr != binds.end(); ++itr)
6874 InstanceSave *save = itr->second.save;
6875 std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
6876 PSendSysMessage("map: %d inst: %d perm: %s diff: %s canReset: %s TTR: %s", itr->first, save->GetInstanceId(), itr->second.perm ? "yes" : "no", save->GetDifficulty() == DIFFICULTY_NORMAL ? "normal" : "heroic", save->CanReset() ? "yes" : "no", timeleft.c_str());
6877 counter++;
6880 PSendSysMessage("player binds: %d", counter);
6881 counter = 0;
6882 Group *group = player->GetGroup();
6883 if(group)
6885 for(uint8 i = 0; i < TOTAL_DIFFICULTIES; ++i)
6887 Group::BoundInstancesMap &binds = group->GetBoundInstances(i);
6888 for(Group::BoundInstancesMap::const_iterator itr = binds.begin(); itr != binds.end(); ++itr)
6890 InstanceSave *save = itr->second.save;
6891 std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
6892 PSendSysMessage("map: %d inst: %d perm: %s diff: %s canReset: %s TTR: %s", itr->first, save->GetInstanceId(), itr->second.perm ? "yes" : "no", save->GetDifficulty() == DIFFICULTY_NORMAL ? "normal" : "heroic", save->CanReset() ? "yes" : "no", timeleft.c_str());
6893 counter++;
6897 PSendSysMessage("group binds: %d", counter);
6899 return true;
6902 bool ChatHandler::HandleInstanceUnbindCommand(const char* args)
6904 if(!*args)
6905 return false;
6907 std::string cmd = args;
6908 if(cmd == "all")
6910 Player* player = getSelectedPlayer();
6911 if (!player) player = m_session->GetPlayer();
6912 uint32 counter = 0;
6913 for(uint8 i = 0; i < TOTAL_DIFFICULTIES; ++i)
6915 Player::BoundInstancesMap &binds = player->GetBoundInstances(i);
6916 for(Player::BoundInstancesMap::iterator itr = binds.begin(); itr != binds.end();)
6918 if(itr->first != player->GetMapId())
6920 InstanceSave *save = itr->second.save;
6921 std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
6922 PSendSysMessage("unbinding map: %d inst: %d perm: %s diff: %s canReset: %s TTR: %s", itr->first, save->GetInstanceId(), itr->second.perm ? "yes" : "no", save->GetDifficulty() == DIFFICULTY_NORMAL ? "normal" : "heroic", save->CanReset() ? "yes" : "no", timeleft.c_str());
6923 player->UnbindInstance(itr, i);
6924 counter++;
6926 else
6927 ++itr;
6930 PSendSysMessage("instances unbound: %d", counter);
6932 return true;
6935 bool ChatHandler::HandleInstanceStatsCommand(const char* /*args*/)
6937 PSendSysMessage("instances loaded: %d", MapManager::Instance().GetNumInstances());
6938 PSendSysMessage("players in instances: %d", MapManager::Instance().GetNumPlayersInInstances());
6939 PSendSysMessage("instance saves: %d", sInstanceSaveManager.GetNumInstanceSaves());
6940 PSendSysMessage("players bound: %d", sInstanceSaveManager.GetNumBoundPlayersTotal());
6941 PSendSysMessage("groups bound: %d", sInstanceSaveManager.GetNumBoundGroupsTotal());
6942 return true;
6945 bool ChatHandler::HandleInstanceSaveDataCommand(const char * /*args*/)
6947 Player* pl = m_session->GetPlayer();
6949 Map* map = pl->GetMap();
6950 if (!map->IsDungeon())
6952 PSendSysMessage("Map is not a dungeon.");
6953 SetSentErrorMessage(true);
6954 return false;
6957 if (!((InstanceMap*)map)->GetInstanceData())
6959 PSendSysMessage("Map has no instance data.");
6960 SetSentErrorMessage(true);
6961 return false;
6964 ((InstanceMap*)map)->GetInstanceData()->SaveToDB();
6965 return true;
6968 /// Display the list of GMs
6969 bool ChatHandler::HandleGMListFullCommand(const char* /*args*/)
6971 ///- Get the accounts with GM Level >0
6972 QueryResult *result = loginDatabase.Query( "SELECT username,gmlevel FROM account WHERE gmlevel > 0" );
6973 if(result)
6975 SendSysMessage(LANG_GMLIST);
6976 SendSysMessage("========================");
6977 SendSysMessage(LANG_GMLIST_HEADER);
6978 SendSysMessage("========================");
6980 ///- Circle through them. Display username and GM level
6983 Field *fields = result->Fetch();
6984 PSendSysMessage("|%15s|%6s|", fields[0].GetString(),fields[1].GetString());
6985 }while( result->NextRow() );
6987 PSendSysMessage("========================");
6988 delete result;
6990 else
6991 PSendSysMessage(LANG_GMLIST_EMPTY);
6992 return true;
6995 /// Define the 'Message of the day' for the realm
6996 bool ChatHandler::HandleServerSetMotdCommand(const char* args)
6998 sWorld.SetMotd(args);
6999 PSendSysMessage(LANG_MOTD_NEW, args);
7000 return true;
7003 /// Set/Unset the expansion level for an account
7004 bool ChatHandler::HandleAccountSetAddonCommand(const char* args)
7006 ///- Get the command line arguments
7007 char *szAcc = strtok((char*)args," ");
7008 char *szExp = strtok(NULL," ");
7010 if(!szAcc)
7011 return false;
7013 std::string account_name;
7014 uint32 account_id;
7016 if(!szExp)
7018 Player* player = getSelectedPlayer();
7019 if(!player)
7020 return false;
7022 account_id = player->GetSession()->GetAccountId();
7023 accmgr.GetName(account_id,account_name);
7024 szExp = szAcc;
7026 else
7028 ///- Convert Account name to Upper Format
7029 account_name = szAcc;
7030 if(!AccountMgr::normilizeString(account_name))
7032 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
7033 SetSentErrorMessage(true);
7034 return false;
7037 account_id = accmgr.GetId(account_name);
7038 if(!account_id)
7040 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
7041 SetSentErrorMessage(true);
7042 return false;
7047 // Let set addon state only for lesser (strong) security level
7048 // or to self account
7049 if (m_session && m_session->GetAccountId () != account_id &&
7050 HasLowerSecurityAccount (NULL,account_id,true))
7051 return false;
7053 int lev=atoi(szExp); //get int anyway (0 if error)
7054 if(lev < 0)
7055 return false;
7057 // No SQL injection
7058 loginDatabase.PExecute("UPDATE account SET expansion = '%d' WHERE id = '%u'",lev,account_id);
7059 PSendSysMessage(LANG_ACCOUNT_SETADDON,account_name.c_str(),account_id,lev);
7060 return true;
7063 //Send items by mail
7064 bool ChatHandler::HandleSendItemsCommand(const char* args)
7066 if(!*args)
7067 return false;
7069 // format: name "subject text" "mail text" item1[:count1] item2[:count2] ... item12[:count12]
7071 std::string name = extractPlayerNameFromLink((char*)args);
7072 if(name.empty())
7074 SendSysMessage(LANG_PLAYER_NOT_FOUND);
7075 SetSentErrorMessage(true);
7076 return false;
7079 char* tail1 = strtok(NULL, "");
7080 if(!tail1)
7081 return false;
7083 char* msgSubject;
7084 if(*tail1=='"')
7085 msgSubject = strtok(tail1+1, "\"");
7086 else
7088 char* space = strtok(tail1, "\"");
7089 if(!space)
7090 return false;
7091 msgSubject = strtok(NULL, "\"");
7094 if (!msgSubject)
7095 return false;
7097 char* tail2 = strtok(NULL, "");
7098 if(!tail2)
7099 return false;
7101 char* msgText;
7102 if(*tail2=='"')
7103 msgText = strtok(tail2+1, "\"");
7104 else
7106 char* space = strtok(tail2, "\"");
7107 if(!space)
7108 return false;
7109 msgText = strtok(NULL, "\"");
7112 if (!msgText)
7113 return false;
7115 // msgSubject, msgText isn't NUL after prev. check
7116 std::string subject = msgSubject;
7117 std::string text = msgText;
7119 // extract items
7120 typedef std::pair<uint32,uint32> ItemPair;
7121 typedef std::list< ItemPair > ItemPairs;
7122 ItemPairs items;
7124 // get all tail string
7125 char* tail = strtok(NULL, "");
7127 // get from tail next item str
7128 while(char* itemStr = strtok(tail, " "))
7130 // and get new tail
7131 tail = strtok(NULL, "");
7133 // parse item str
7134 char* itemIdStr = strtok(itemStr, ":");
7135 char* itemCountStr = strtok(NULL, " ");
7137 uint32 item_id = atoi(itemIdStr);
7138 if(!item_id)
7139 return false;
7141 ItemPrototype const* item_proto = objmgr.GetItemPrototype(item_id);
7142 if(!item_proto)
7144 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, item_id);
7145 SetSentErrorMessage(true);
7146 return false;
7149 uint32 item_count = itemCountStr ? atoi(itemCountStr) : 1;
7150 if(item_count < 1 || item_proto->MaxCount > 0 && item_count > uint32(item_proto->MaxCount))
7152 PSendSysMessage(LANG_COMMAND_INVALID_ITEM_COUNT, item_count,item_id);
7153 SetSentErrorMessage(true);
7154 return false;
7157 while(item_count > item_proto->GetMaxStackSize())
7159 items.push_back(ItemPair(item_id,item_proto->GetMaxStackSize()));
7160 item_count -= item_proto->GetMaxStackSize();
7163 items.push_back(ItemPair(item_id,item_count));
7165 if(items.size() > MAX_MAIL_ITEMS)
7167 PSendSysMessage(LANG_COMMAND_MAIL_ITEMS_LIMIT, MAX_MAIL_ITEMS);
7168 SetSentErrorMessage(true);
7169 return false;
7173 uint64 receiver_guid = objmgr.GetPlayerGUIDByName(name);
7174 if(!receiver_guid)
7176 SendSysMessage(LANG_PLAYER_NOT_FOUND);
7177 SetSentErrorMessage(true);
7178 return false;
7181 // from console show not existed sender
7182 uint32 sender_guidlo = m_session ? m_session->GetPlayer()->GetGUIDLow() : 0;
7184 uint32 messagetype = MAIL_NORMAL;
7185 uint32 stationery = MAIL_STATIONERY_GM;
7186 uint32 itemTextId = !text.empty() ? objmgr.CreateItemText( text ) : 0;
7188 Player *receiver = objmgr.GetPlayer(receiver_guid);
7190 // fill mail
7191 MailItemsInfo mi; // item list preparing
7193 for(ItemPairs::const_iterator itr = items.begin(); itr != items.end(); ++itr)
7195 if(Item* item = Item::CreateItem(itr->first,itr->second,m_session ? m_session->GetPlayer() : 0))
7197 item->SaveToDB(); // save for prevent lost at next mail load, if send fail then item will deleted
7198 mi.AddItem(item->GetGUIDLow(), item->GetEntry(), item);
7202 WorldSession::SendMailTo(receiver,messagetype, stationery, sender_guidlo, GUID_LOPART(receiver_guid), subject, itemTextId, &mi, 0, 0, MAIL_CHECK_MASK_NONE);
7204 std::string nameLink = playerLink(name);
7205 PSendSysMessage(LANG_MAIL_SENT, nameLink.c_str());
7206 return true;
7209 ///Send money by mail
7210 bool ChatHandler::HandleSendMoneyCommand(const char* args)
7212 if (!*args)
7213 return false;
7215 /// format: name "subject text" "mail text" money
7217 std::string name = extractPlayerNameFromLink((char*)args);
7218 if(name.empty())
7220 SendSysMessage(LANG_PLAYER_NOT_FOUND);
7221 SetSentErrorMessage(true);
7222 return false;
7225 char* tail1 = strtok(NULL, "");
7226 if (!tail1)
7227 return false;
7229 char* msgSubject;
7230 if (*tail1=='"')
7231 msgSubject = strtok(tail1+1, "\"");
7232 else
7234 char* space = strtok(tail1, "\"");
7235 if (!space)
7236 return false;
7237 msgSubject = strtok(NULL, "\"");
7240 if (!msgSubject)
7241 return false;
7243 char* tail2 = strtok(NULL, "");
7244 if (!tail2)
7245 return false;
7247 char* msgText;
7248 if (*tail2=='"')
7249 msgText = strtok(tail2+1, "\"");
7250 else
7252 char* space = strtok(tail2, "\"");
7253 if (!space)
7254 return false;
7255 msgText = strtok(NULL, "\"");
7258 if (!msgText)
7259 return false;
7261 char* money_str = strtok(NULL, "");
7262 int32 money = money_str ? atoi(money_str) : 0;
7263 if (money <= 0)
7264 return false;
7266 // msgSubject, msgText isn't NUL after prev. check
7267 std::string subject = msgSubject;
7268 std::string text = msgText;
7270 uint64 receiver_guid = objmgr.GetPlayerGUIDByName(name);
7271 if (!receiver_guid)
7273 SendSysMessage(LANG_PLAYER_NOT_FOUND);
7274 SetSentErrorMessage(true);
7275 return false;
7278 // from console show not existed sender
7279 uint32 sender_guidlo = m_session ? m_session->GetPlayer()->GetGUIDLow() : 0;
7281 uint32 messagetype = MAIL_NORMAL;
7282 uint32 stationery = MAIL_STATIONERY_GM;
7283 uint32 itemTextId = !text.empty() ? objmgr.CreateItemText( text ) : 0;
7285 Player *receiver = objmgr.GetPlayer(receiver_guid);
7287 WorldSession::SendMailTo(receiver,messagetype, stationery, sender_guidlo, GUID_LOPART(receiver_guid), subject, itemTextId, NULL, money, 0, MAIL_CHECK_MASK_NONE);
7289 std::string nameLink = playerLink(name);
7290 PSendSysMessage(LANG_MAIL_SENT, nameLink.c_str());
7291 return true;
7294 /// Send a message to a player in game
7295 bool ChatHandler::HandleSendMessageCommand(const char* args)
7297 ///- Get the command line arguments
7298 std::string name = extractPlayerNameFromLink((char*)args);
7299 if(name.empty())
7301 SendSysMessage(LANG_PLAYER_NOT_FOUND);
7302 SetSentErrorMessage(true);
7303 return false;
7306 char* msg_str = strtok(NULL, "");
7307 if(!msg_str)
7308 return false;
7310 ///- Find the player and check that he is not logging out.
7311 Player *rPlayer = objmgr.GetPlayer(name.c_str());
7312 if(!rPlayer)
7314 SendSysMessage(LANG_PLAYER_NOT_FOUND);
7315 SetSentErrorMessage(true);
7316 return false;
7319 if(rPlayer->GetSession()->isLogingOut())
7321 SendSysMessage(LANG_PLAYER_NOT_FOUND);
7322 SetSentErrorMessage(true);
7323 return false;
7326 ///- Send the message
7327 //Use SendAreaTriggerMessage for fastest delivery.
7328 rPlayer->GetSession()->SendAreaTriggerMessage("%s", msg_str);
7329 rPlayer->GetSession()->SendAreaTriggerMessage("|cffff0000[Message from administrator]:|r");
7331 //Confirmation message
7332 std::string nameLink = playerLink(name);
7333 PSendSysMessage(LANG_SENDMESSAGE,nameLink.c_str(),msg_str);
7334 return true;
7337 bool ChatHandler::HandleFlushArenaPointsCommand(const char * /*args*/)
7339 sBattleGroundMgr.DistributeArenaPoints();
7340 return true;
7343 bool ChatHandler::HandleModifyGenderCommand(const char *args)
7345 if(!*args)
7346 return false;
7348 Player *player = getSelectedPlayer();
7350 if(!player)
7352 PSendSysMessage(LANG_PLAYER_NOT_FOUND);
7353 SetSentErrorMessage(true);
7354 return false;
7357 PlayerInfo const* info = objmgr.GetPlayerInfo(player->getRace(), player->getClass());
7358 if(!info)
7359 return false;
7361 char const* gender_str = (char*)args;
7362 int gender_len = strlen(gender_str);
7364 Gender gender;
7366 if(!strncmp(gender_str, "male", gender_len)) // MALE
7368 if(player->getGender() == GENDER_MALE)
7369 return true;
7371 gender = GENDER_MALE;
7373 else if (!strncmp(gender_str, "female", gender_len)) // FEMALE
7375 if(player->getGender() == GENDER_FEMALE)
7376 return true;
7378 gender = GENDER_FEMALE;
7380 else
7382 SendSysMessage(LANG_MUST_MALE_OR_FEMALE);
7383 SetSentErrorMessage(true);
7384 return false;
7387 // Set gender
7388 player->SetByteValue(UNIT_FIELD_BYTES_0, 2, gender);
7389 player->SetByteValue(PLAYER_BYTES_3, 0, gender);
7391 // Change display ID
7392 player->SetDisplayId(gender ? info->displayId_f : info->displayId_m);
7393 player->SetNativeDisplayId(gender ? info->displayId_f : info->displayId_m);
7395 char const* gender_full = gender ? "female" : "male";
7397 PSendSysMessage(LANG_YOU_CHANGE_GENDER, GetNameLink(player).c_str(), gender_full);
7399 if (needReportToTarget(player))
7400 ChatHandler(player).PSendSysMessage(LANG_YOUR_GENDER_CHANGED, gender_full, GetNameLink().c_str());
7402 return true;