AHBot for 3.1.x
[AHbot.git] / src / game / Level3.cpp
bloba8867cd12403e0095410fd4506b031958f703a84
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 return true;
579 bool ChatHandler::HandleReloadAllQuestCommand(const char* /*args*/)
581 HandleReloadQuestAreaTriggersCommand("a");
582 HandleReloadQuestTemplateCommand("a");
584 sLog.outString( "Re-Loading Quests Relations..." );
585 objmgr.LoadQuestRelations();
586 SendGlobalSysMessage("DB tables `*_questrelation` and `*_involvedrelation` reloaded.");
587 return true;
590 bool ChatHandler::HandleReloadAllScriptsCommand(const char*)
592 if(sWorld.IsScriptScheduled())
594 PSendSysMessage("DB scripts used currently, please attempt reload later.");
595 SetSentErrorMessage(true);
596 return false;
599 sLog.outString( "Re-Loading Scripts..." );
600 HandleReloadGameObjectScriptsCommand("a");
601 HandleReloadEventScriptsCommand("a");
602 HandleReloadQuestEndScriptsCommand("a");
603 HandleReloadQuestStartScriptsCommand("a");
604 HandleReloadSpellScriptsCommand("a");
605 SendGlobalSysMessage("DB tables `*_scripts` reloaded.");
606 HandleReloadDbScriptStringCommand("a");
607 return true;
610 bool ChatHandler::HandleReloadAllSpellCommand(const char*)
612 HandleReloadSkillDiscoveryTemplateCommand("a");
613 HandleReloadSkillExtraItemTemplateCommand("a");
614 HandleReloadSpellAffectCommand("a");
615 HandleReloadSpellAreaCommand("a");
616 HandleReloadSpellChainCommand("a");
617 HandleReloadSpellElixirCommand("a");
618 HandleReloadSpellLearnSpellCommand("a");
619 HandleReloadSpellProcEventCommand("a");
620 HandleReloadSpellBonusesCommand("a");
621 HandleReloadSpellScriptTargetCommand("a");
622 HandleReloadSpellTargetPositionCommand("a");
623 HandleReloadSpellThreatsCommand("a");
624 HandleReloadSpellPetAurasCommand("a");
625 return true;
628 bool ChatHandler::HandleReloadAllItemCommand(const char*)
630 HandleReloadPageTextsCommand("a");
631 HandleReloadItemEnchantementsCommand("a");
632 return true;
635 bool ChatHandler::HandleReloadAllLocalesCommand(const char* /*args*/)
637 HandleReloadLocalesAchievementRewardCommand("a");
638 HandleReloadLocalesCreatureCommand("a");
639 HandleReloadLocalesGameobjectCommand("a");
640 HandleReloadLocalesItemCommand("a");
641 HandleReloadLocalesNpcTextCommand("a");
642 HandleReloadLocalesPageTextCommand("a");
643 HandleReloadLocalesPointsOfInterestCommand("a");
644 HandleReloadLocalesQuestCommand("a");
645 return true;
648 bool ChatHandler::HandleReloadConfigCommand(const char* /*args*/)
650 sLog.outString( "Re-Loading config settings..." );
651 sWorld.LoadConfigSettings(true);
652 SendGlobalSysMessage("World config settings reloaded.");
653 return true;
656 bool ChatHandler::HandleReloadAchievementCriteriaDataCommand(const char*)
658 sLog.outString( "Re-Loading Additional Achievement Criteria Data..." );
659 achievementmgr.LoadAchievementCriteriaData();
660 SendGlobalSysMessage("DB table `achievement_criteria_data` reloaded.");
661 return true;
664 bool ChatHandler::HandleReloadAchievementRewardCommand(const char*)
666 sLog.outString( "Re-Loading Achievement Reward Data..." );
667 achievementmgr.LoadRewards();
668 SendGlobalSysMessage("DB table `achievement_reward` reloaded.");
669 return true;
672 bool ChatHandler::HandleReloadAreaTriggerTavernCommand(const char*)
674 sLog.outString( "Re-Loading Tavern Area Triggers..." );
675 objmgr.LoadTavernAreaTriggers();
676 SendGlobalSysMessage("DB table `areatrigger_tavern` reloaded.");
677 return true;
680 bool ChatHandler::HandleReloadAreaTriggerTeleportCommand(const char*)
682 sLog.outString( "Re-Loading AreaTrigger teleport definitions..." );
683 objmgr.LoadAreaTriggerTeleports();
684 SendGlobalSysMessage("DB table `areatrigger_teleport` reloaded.");
685 return true;
688 bool ChatHandler::HandleReloadCommandCommand(const char*)
690 load_command_table = true;
691 SendGlobalSysMessage("DB table `command` will be reloaded at next chat command use.");
692 return true;
695 bool ChatHandler::HandleReloadCreatureQuestRelationsCommand(const char*)
697 sLog.outString( "Loading Quests Relations... (`creature_questrelation`)" );
698 objmgr.LoadCreatureQuestRelations();
699 SendGlobalSysMessage("DB table `creature_questrelation` (creature quest givers) reloaded.");
700 return true;
703 bool ChatHandler::HandleReloadCreatureQuestInvRelationsCommand(const char*)
705 sLog.outString( "Loading Quests Relations... (`creature_involvedrelation`)" );
706 objmgr.LoadCreatureInvolvedRelations();
707 SendGlobalSysMessage("DB table `creature_involvedrelation` (creature quest takers) reloaded.");
708 return true;
711 bool ChatHandler::HandleReloadGOQuestRelationsCommand(const char*)
713 sLog.outString( "Loading Quests Relations... (`gameobject_questrelation`)" );
714 objmgr.LoadGameobjectQuestRelations();
715 SendGlobalSysMessage("DB table `gameobject_questrelation` (gameobject quest givers) reloaded.");
716 return true;
719 bool ChatHandler::HandleReloadGOQuestInvRelationsCommand(const char*)
721 sLog.outString( "Loading Quests Relations... (`gameobject_involvedrelation`)" );
722 objmgr.LoadGameobjectInvolvedRelations();
723 SendGlobalSysMessage("DB table `gameobject_involvedrelation` (gameobject quest takers) reloaded.");
724 return true;
727 bool ChatHandler::HandleReloadQuestAreaTriggersCommand(const char*)
729 sLog.outString( "Re-Loading Quest Area Triggers..." );
730 objmgr.LoadQuestAreaTriggers();
731 SendGlobalSysMessage("DB table `areatrigger_involvedrelation` (quest area triggers) reloaded.");
732 return true;
735 bool ChatHandler::HandleReloadQuestTemplateCommand(const char*)
737 sLog.outString( "Re-Loading Quest Templates..." );
738 objmgr.LoadQuests();
739 SendGlobalSysMessage("DB table `quest_template` (quest definitions) reloaded.");
741 /// dependent also from `gameobject` but this table not reloaded anyway
742 sLog.outString( "Re-Loading GameObjects for quests..." );
743 objmgr.LoadGameObjectForQuests();
744 SendGlobalSysMessage("Data GameObjects for quests reloaded.");
745 return true;
748 bool ChatHandler::HandleReloadLootTemplatesCreatureCommand(const char*)
750 sLog.outString( "Re-Loading Loot Tables... (`creature_loot_template`)" );
751 LoadLootTemplates_Creature();
752 LootTemplates_Creature.CheckLootRefs();
753 SendGlobalSysMessage("DB table `creature_loot_template` reloaded.");
754 return true;
757 bool ChatHandler::HandleReloadLootTemplatesDisenchantCommand(const char*)
759 sLog.outString( "Re-Loading Loot Tables... (`disenchant_loot_template`)" );
760 LoadLootTemplates_Disenchant();
761 LootTemplates_Disenchant.CheckLootRefs();
762 SendGlobalSysMessage("DB table `disenchant_loot_template` reloaded.");
763 return true;
766 bool ChatHandler::HandleReloadLootTemplatesFishingCommand(const char*)
768 sLog.outString( "Re-Loading Loot Tables... (`fishing_loot_template`)" );
769 LoadLootTemplates_Fishing();
770 LootTemplates_Fishing.CheckLootRefs();
771 SendGlobalSysMessage("DB table `fishing_loot_template` reloaded.");
772 return true;
775 bool ChatHandler::HandleReloadLootTemplatesGameobjectCommand(const char*)
777 sLog.outString( "Re-Loading Loot Tables... (`gameobject_loot_template`)" );
778 LoadLootTemplates_Gameobject();
779 LootTemplates_Gameobject.CheckLootRefs();
780 SendGlobalSysMessage("DB table `gameobject_loot_template` reloaded.");
781 return true;
784 bool ChatHandler::HandleReloadLootTemplatesItemCommand(const char*)
786 sLog.outString( "Re-Loading Loot Tables... (`item_loot_template`)" );
787 LoadLootTemplates_Item();
788 LootTemplates_Item.CheckLootRefs();
789 SendGlobalSysMessage("DB table `item_loot_template` reloaded.");
790 return true;
793 bool ChatHandler::HandleReloadLootTemplatesMillingCommand(const char*)
795 sLog.outString( "Re-Loading Loot Tables... (`milling_loot_template`)" );
796 LoadLootTemplates_Milling();
797 LootTemplates_Milling.CheckLootRefs();
798 SendGlobalSysMessage("DB table `milling_loot_template` reloaded.");
799 return true;
802 bool ChatHandler::HandleReloadLootTemplatesPickpocketingCommand(const char*)
804 sLog.outString( "Re-Loading Loot Tables... (`pickpocketing_loot_template`)" );
805 LoadLootTemplates_Pickpocketing();
806 LootTemplates_Pickpocketing.CheckLootRefs();
807 SendGlobalSysMessage("DB table `pickpocketing_loot_template` reloaded.");
808 return true;
811 bool ChatHandler::HandleReloadLootTemplatesProspectingCommand(const char*)
813 sLog.outString( "Re-Loading Loot Tables... (`prospecting_loot_template`)" );
814 LoadLootTemplates_Prospecting();
815 LootTemplates_Prospecting.CheckLootRefs();
816 SendGlobalSysMessage("DB table `prospecting_loot_template` reloaded.");
817 return true;
820 bool ChatHandler::HandleReloadLootTemplatesQuestMailCommand(const char*)
822 sLog.outString( "Re-Loading Loot Tables... (`quest_mail_loot_template`)" );
823 LoadLootTemplates_QuestMail();
824 LootTemplates_QuestMail.CheckLootRefs();
825 SendGlobalSysMessage("DB table `quest_mail_loot_template` reloaded.");
826 return true;
829 bool ChatHandler::HandleReloadLootTemplatesReferenceCommand(const char*)
831 sLog.outString( "Re-Loading Loot Tables... (`reference_loot_template`)" );
832 LoadLootTemplates_Reference();
833 SendGlobalSysMessage("DB table `reference_loot_template` reloaded.");
834 return true;
837 bool ChatHandler::HandleReloadLootTemplatesSkinningCommand(const char*)
839 sLog.outString( "Re-Loading Loot Tables... (`skinning_loot_template`)" );
840 LoadLootTemplates_Skinning();
841 LootTemplates_Skinning.CheckLootRefs();
842 SendGlobalSysMessage("DB table `skinning_loot_template` reloaded.");
843 return true;
846 bool ChatHandler::HandleReloadLootTemplatesSpellCommand(const char*)
848 sLog.outString( "Re-Loading Loot Tables... (`spell_loot_template`)" );
849 LoadLootTemplates_Spell();
850 LootTemplates_Spell.CheckLootRefs();
851 SendGlobalSysMessage("DB table `spell_loot_template` reloaded.");
852 return true;
855 bool ChatHandler::HandleReloadMangosStringCommand(const char*)
857 sLog.outString( "Re-Loading mangos_string Table!" );
858 objmgr.LoadMangosStrings();
859 SendGlobalSysMessage("DB table `mangos_string` reloaded.");
860 return true;
863 bool ChatHandler::HandleReloadNpcOptionCommand(const char*)
865 sLog.outString( "Re-Loading `npc_option` Table!" );
866 objmgr.LoadNpcOptions();
867 SendGlobalSysMessage("DB table `npc_option` reloaded.");
868 return true;
871 bool ChatHandler::HandleReloadNpcGossipCommand(const char*)
873 sLog.outString( "Re-Loading `npc_gossip` Table!" );
874 objmgr.LoadNpcTextId();
875 SendGlobalSysMessage("DB table `npc_gossip` reloaded.");
876 return true;
879 bool ChatHandler::HandleReloadNpcTrainerCommand(const char*)
881 sLog.outString( "Re-Loading `npc_trainer` Table!" );
882 objmgr.LoadTrainerSpell();
883 SendGlobalSysMessage("DB table `npc_trainer` reloaded.");
884 return true;
887 bool ChatHandler::HandleReloadNpcVendorCommand(const char*)
889 sLog.outString( "Re-Loading `npc_vendor` Table!" );
890 objmgr.LoadVendors();
891 SendGlobalSysMessage("DB table `npc_vendor` reloaded.");
892 return true;
895 bool ChatHandler::HandleReloadPointsOfInterestCommand(const char*)
897 sLog.outString( "Re-Loading `points_of_interest` Table!" );
898 objmgr.LoadPointsOfInterest();
899 SendGlobalSysMessage("DB table `points_of_interest` reloaded.");
900 return true;
903 bool ChatHandler::HandleReloadReservedNameCommand(const char*)
905 sLog.outString( "Loading ReservedNames... (`reserved_name`)" );
906 objmgr.LoadReservedPlayersNames();
907 SendGlobalSysMessage("DB table `reserved_name` (player reserved names) reloaded.");
908 return true;
911 bool ChatHandler::HandleReloadSkillDiscoveryTemplateCommand(const char* /*args*/)
913 sLog.outString( "Re-Loading Skill Discovery Table..." );
914 LoadSkillDiscoveryTable();
915 SendGlobalSysMessage("DB table `skill_discovery_template` (recipes discovered at crafting) reloaded.");
916 return true;
919 bool ChatHandler::HandleReloadSkillExtraItemTemplateCommand(const char* /*args*/)
921 sLog.outString( "Re-Loading Skill Extra Item Table..." );
922 LoadSkillExtraItemTable();
923 SendGlobalSysMessage("DB table `skill_extra_item_template` (extra item creation when crafting) reloaded.");
924 return true;
927 bool ChatHandler::HandleReloadSkillFishingBaseLevelCommand(const char* /*args*/)
929 sLog.outString( "Re-Loading Skill Fishing base level requirements..." );
930 objmgr.LoadFishingBaseSkillLevel();
931 SendGlobalSysMessage("DB table `skill_fishing_base_level` (fishing base level for zone/subzone) reloaded.");
932 return true;
935 bool ChatHandler::HandleReloadSpellAffectCommand(const char*)
937 sLog.outString( "Re-Loading SpellAffect definitions..." );
938 spellmgr.LoadSpellAffects();
939 SendGlobalSysMessage("DB table `spell_affect` (spell mods apply requirements) reloaded.");
940 return true;
943 bool ChatHandler::HandleReloadSpellAreaCommand(const char*)
945 sLog.outString( "Re-Loading SpellArea Data..." );
946 spellmgr.LoadSpellAreas();
947 SendGlobalSysMessage("DB table `spell_area` (spell dependences from area/quest/auras state) reloaded.");
948 return true;
951 bool ChatHandler::HandleReloadSpellChainCommand(const char*)
953 sLog.outString( "Re-Loading Spell Chain Data... " );
954 spellmgr.LoadSpellChains();
955 SendGlobalSysMessage("DB table `spell_chain` (spell ranks) reloaded.");
956 return true;
959 bool ChatHandler::HandleReloadSpellElixirCommand(const char*)
961 sLog.outString( "Re-Loading Spell Elixir types..." );
962 spellmgr.LoadSpellElixirs();
963 SendGlobalSysMessage("DB table `spell_elixir` (spell elixir types) reloaded.");
964 return true;
967 bool ChatHandler::HandleReloadSpellLearnSpellCommand(const char*)
969 sLog.outString( "Re-Loading Spell Learn Spells..." );
970 spellmgr.LoadSpellLearnSpells();
971 SendGlobalSysMessage("DB table `spell_learn_spell` reloaded.");
972 return true;
975 bool ChatHandler::HandleReloadSpellProcEventCommand(const char*)
977 sLog.outString( "Re-Loading Spell Proc Event conditions..." );
978 spellmgr.LoadSpellProcEvents();
979 SendGlobalSysMessage("DB table `spell_proc_event` (spell proc trigger requirements) reloaded.");
980 return true;
983 bool ChatHandler::HandleReloadSpellBonusesCommand(const char*)
985 sLog.outString( "Re-Loading Spell Bonus Data..." );
986 spellmgr.LoadSpellBonusess();
987 SendGlobalSysMessage("DB table `spell_bonus_data` (spell damage/healing coefficients) reloaded.");
988 return true;
991 bool ChatHandler::HandleReloadSpellScriptTargetCommand(const char*)
993 sLog.outString( "Re-Loading SpellsScriptTarget..." );
994 spellmgr.LoadSpellScriptTarget();
995 SendGlobalSysMessage("DB table `spell_script_target` (spell targets selection in case specific creature/GO requirements) reloaded.");
996 return true;
999 bool ChatHandler::HandleReloadSpellTargetPositionCommand(const char*)
1001 sLog.outString( "Re-Loading Spell target coordinates..." );
1002 spellmgr.LoadSpellTargetPositions();
1003 SendGlobalSysMessage("DB table `spell_target_position` (destination coordinates for spell targets) reloaded.");
1004 return true;
1007 bool ChatHandler::HandleReloadSpellThreatsCommand(const char*)
1009 sLog.outString( "Re-Loading Aggro Spells Definitions...");
1010 spellmgr.LoadSpellThreats();
1011 SendGlobalSysMessage("DB table `spell_threat` (spell aggro definitions) reloaded.");
1012 return true;
1015 bool ChatHandler::HandleReloadSpellPetAurasCommand(const char*)
1017 sLog.outString( "Re-Loading Spell pet auras...");
1018 spellmgr.LoadSpellPetAuras();
1019 SendGlobalSysMessage("DB table `spell_pet_auras` reloaded.");
1020 return true;
1023 bool ChatHandler::HandleReloadPageTextsCommand(const char*)
1025 sLog.outString( "Re-Loading Page Texts..." );
1026 objmgr.LoadPageTexts();
1027 SendGlobalSysMessage("DB table `page_texts` reloaded.");
1028 return true;
1031 bool ChatHandler::HandleReloadItemEnchantementsCommand(const char*)
1033 sLog.outString( "Re-Loading Item Random Enchantments Table..." );
1034 LoadRandomEnchantmentsTable();
1035 SendGlobalSysMessage("DB table `item_enchantment_template` reloaded.");
1036 return true;
1039 bool ChatHandler::HandleReloadGameObjectScriptsCommand(const char* arg)
1041 if(sWorld.IsScriptScheduled())
1043 SendSysMessage("DB scripts used currently, please attempt reload later.");
1044 SetSentErrorMessage(true);
1045 return false;
1048 if(*arg!='a')
1049 sLog.outString( "Re-Loading Scripts from `gameobject_scripts`...");
1051 objmgr.LoadGameObjectScripts();
1053 if(*arg!='a')
1054 SendGlobalSysMessage("DB table `gameobject_scripts` reloaded.");
1056 return true;
1059 bool ChatHandler::HandleReloadEventScriptsCommand(const char* arg)
1061 if(sWorld.IsScriptScheduled())
1063 SendSysMessage("DB scripts used currently, please attempt reload later.");
1064 SetSentErrorMessage(true);
1065 return false;
1068 if(*arg!='a')
1069 sLog.outString( "Re-Loading Scripts from `event_scripts`...");
1071 objmgr.LoadEventScripts();
1073 if(*arg!='a')
1074 SendGlobalSysMessage("DB table `event_scripts` reloaded.");
1076 return true;
1079 bool ChatHandler::HandleReloadQuestEndScriptsCommand(const char* arg)
1081 if(sWorld.IsScriptScheduled())
1083 SendSysMessage("DB scripts used currently, please attempt reload later.");
1084 SetSentErrorMessage(true);
1085 return false;
1088 if(*arg!='a')
1089 sLog.outString( "Re-Loading Scripts from `quest_end_scripts`...");
1091 objmgr.LoadQuestEndScripts();
1093 if(*arg!='a')
1094 SendGlobalSysMessage("DB table `quest_end_scripts` reloaded.");
1096 return true;
1099 bool ChatHandler::HandleReloadQuestStartScriptsCommand(const char* arg)
1101 if(sWorld.IsScriptScheduled())
1103 SendSysMessage("DB scripts used currently, please attempt reload later.");
1104 SetSentErrorMessage(true);
1105 return false;
1108 if(*arg!='a')
1109 sLog.outString( "Re-Loading Scripts from `quest_start_scripts`...");
1111 objmgr.LoadQuestStartScripts();
1113 if(*arg!='a')
1114 SendGlobalSysMessage("DB table `quest_start_scripts` reloaded.");
1116 return true;
1119 bool ChatHandler::HandleReloadSpellScriptsCommand(const char* arg)
1121 if(sWorld.IsScriptScheduled())
1123 SendSysMessage("DB scripts used currently, please attempt reload later.");
1124 SetSentErrorMessage(true);
1125 return false;
1128 if(*arg!='a')
1129 sLog.outString( "Re-Loading Scripts from `spell_scripts`...");
1131 objmgr.LoadSpellScripts();
1133 if(*arg!='a')
1134 SendGlobalSysMessage("DB table `spell_scripts` reloaded.");
1136 return true;
1139 bool ChatHandler::HandleReloadDbScriptStringCommand(const char* arg)
1141 sLog.outString( "Re-Loading Script strings from `db_script_string`...");
1142 objmgr.LoadDbScriptStrings();
1143 SendGlobalSysMessage("DB table `db_script_string` reloaded.");
1144 return true;
1147 bool ChatHandler::HandleReloadGameGraveyardZoneCommand(const char* /*arg*/)
1149 sLog.outString( "Re-Loading Graveyard-zone links...");
1151 objmgr.LoadGraveyardZones();
1153 SendGlobalSysMessage("DB table `game_graveyard_zone` reloaded.");
1155 return true;
1158 bool ChatHandler::HandleReloadGameTeleCommand(const char* /*arg*/)
1160 sLog.outString( "Re-Loading Game Tele coordinates...");
1162 objmgr.LoadGameTele();
1164 SendGlobalSysMessage("DB table `game_tele` reloaded.");
1166 return true;
1169 bool ChatHandler::HandleReloadLocalesAchievementRewardCommand(const char*)
1171 sLog.outString( "Re-Loading Locales Achievement Reward Data..." );
1172 achievementmgr.LoadRewardLocales();
1173 SendGlobalSysMessage("DB table `locales_achievement_reward` reloaded.");
1174 return true;
1177 bool ChatHandler::HandleReloadLocalesCreatureCommand(const char* /*arg*/)
1179 sLog.outString( "Re-Loading Locales Creature ...");
1180 objmgr.LoadCreatureLocales();
1181 SendGlobalSysMessage("DB table `locales_creature` reloaded.");
1182 return true;
1185 bool ChatHandler::HandleReloadLocalesGameobjectCommand(const char* /*arg*/)
1187 sLog.outString( "Re-Loading Locales Gameobject ... ");
1188 objmgr.LoadGameObjectLocales();
1189 SendGlobalSysMessage("DB table `locales_gameobject` reloaded.");
1190 return true;
1193 bool ChatHandler::HandleReloadLocalesItemCommand(const char* /*arg*/)
1195 sLog.outString( "Re-Loading Locales Item ... ");
1196 objmgr.LoadItemLocales();
1197 SendGlobalSysMessage("DB table `locales_item` reloaded.");
1198 return true;
1201 bool ChatHandler::HandleReloadLocalesNpcTextCommand(const char* /*arg*/)
1203 sLog.outString( "Re-Loading Locales NPC Text ... ");
1204 objmgr.LoadNpcTextLocales();
1205 SendGlobalSysMessage("DB table `locales_npc_text` reloaded.");
1206 return true;
1209 bool ChatHandler::HandleReloadLocalesPageTextCommand(const char* /*arg*/)
1211 sLog.outString( "Re-Loading Locales Page Text ... ");
1212 objmgr.LoadPageTextLocales();
1213 SendGlobalSysMessage("DB table `locales_page_text` reloaded.");
1214 return true;
1217 bool ChatHandler::HandleReloadLocalesPointsOfInterestCommand(const char* /*arg*/)
1219 sLog.outString( "Re-Loading Locales Points Of Interest ... ");
1220 objmgr.LoadPointOfInterestLocales();
1221 SendGlobalSysMessage("DB table `locales_points_of_interest` reloaded.");
1222 return true;
1225 bool ChatHandler::HandleReloadLocalesQuestCommand(const char* /*arg*/)
1227 sLog.outString( "Re-Loading Locales Quest ... ");
1228 objmgr.LoadQuestLocales();
1229 SendGlobalSysMessage("DB table `locales_quest` reloaded.");
1230 return true;
1233 bool ChatHandler::HandleLoadScriptsCommand(const char* args)
1235 if(!LoadScriptingModule(args)) return true;
1237 sWorld.SendWorldText(LANG_SCRIPTS_RELOADED);
1238 return true;
1241 bool ChatHandler::HandleAccountSetGmLevelCommand(const char* args)
1243 char* arg1 = strtok((char*)args, " ");
1244 if( !arg1 )
1245 return false;
1247 /// must be NULL if targeted syntax and must be not nULL if not targeted
1248 char* arg2 = strtok(NULL, " ");
1250 std::string targetAccountName;
1251 uint32 targetAccountId = 0;
1253 /// only target player different from self allowed (if targetPlayer!=NULL then not console)
1254 Player* targetPlayer = getSelectedPlayer();
1255 if(targetPlayer && m_session->GetPlayer()!=targetPlayer)
1257 /// wrong command syntax or unexpected targeting
1258 if(arg2)
1259 return false;
1261 /// security level expected in arg2 after this if.
1262 arg2 = arg1;
1264 targetAccountId = targetPlayer->GetSession()->GetAccountId();
1265 accmgr.GetName(targetAccountId, targetAccountName);
1267 else
1269 /// wrong command syntax (second arg expected)
1270 if(!arg2)
1271 return false;
1273 targetAccountName = arg1;
1274 if(!AccountMgr::normilizeString(targetAccountName))
1276 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,targetAccountName.c_str());
1277 SetSentErrorMessage(true);
1278 return false;
1281 targetAccountId = accmgr.GetId(targetAccountName);
1282 if(!targetAccountId)
1284 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,targetAccountName.c_str());
1285 SetSentErrorMessage(true);
1286 return false;
1290 int32 gm = (int32)atoi(arg2);
1291 if ( gm < SEC_PLAYER || gm > SEC_ADMINISTRATOR )
1293 SendSysMessage(LANG_BAD_VALUE);
1294 SetSentErrorMessage(true);
1295 return false;
1298 /// can set security level only for target with less security and to less security that we have
1299 /// This will reject self apply by specify account name
1300 if(HasLowerSecurityAccount(NULL,targetAccountId,true))
1301 return false;
1303 /// account can't set security to same or grater level, need more power GM or console
1304 AccountTypes plSecurity = m_session ? m_session->GetSecurity() : SEC_CONSOLE;
1305 if (AccountTypes(gm) >= plSecurity )
1307 SendSysMessage(LANG_YOURS_SECURITY_IS_LOW);
1308 SetSentErrorMessage(true);
1309 return false;
1312 // This will prevent self apply by self target or no target
1313 if(targetPlayer && m_session->GetPlayer()!=targetPlayer)
1315 ChatHandler(targetPlayer).PSendSysMessage(LANG_YOURS_SECURITY_CHANGED,GetNameLink().c_str(), gm);
1316 targetPlayer->GetSession()->SetSecurity(AccountTypes(gm));
1319 PSendSysMessage(LANG_YOU_CHANGE_SECURITY, targetAccountName.c_str(), gm);
1320 loginDatabase.PExecute("UPDATE account SET gmlevel = '%i' WHERE id = '%u'", gm, targetAccountId);
1322 return true;
1325 /// Set password for account
1326 bool ChatHandler::HandleAccountSetPasswordCommand(const char* args)
1328 if(!*args)
1329 return false;
1331 ///- Get the command line arguments
1332 char *szAccount = strtok ((char*)args," ");
1333 char *szPassword1 = strtok (NULL," ");
1334 char *szPassword2 = strtok (NULL," ");
1336 if (!szAccount||!szPassword1 || !szPassword2)
1337 return false;
1339 std::string account_name = szAccount;
1340 if(!AccountMgr::normilizeString(account_name))
1342 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
1343 SetSentErrorMessage(true);
1344 return false;
1347 uint32 targetAccountId = accmgr.GetId(account_name);
1348 if (!targetAccountId)
1350 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
1351 SetSentErrorMessage(true);
1352 return false;
1355 /// can set password only for target with less security
1356 /// This is also reject self apply in fact
1357 if(HasLowerSecurityAccount (NULL,targetAccountId,true))
1358 return false;
1360 if (strcmp(szPassword1,szPassword2))
1362 SendSysMessage (LANG_NEW_PASSWORDS_NOT_MATCH);
1363 SetSentErrorMessage (true);
1364 return false;
1367 AccountOpResult result = accmgr.ChangePassword(targetAccountId, szPassword1);
1369 switch(result)
1371 case AOR_OK:
1372 SendSysMessage(LANG_COMMAND_PASSWORD);
1373 break;
1374 case AOR_NAME_NOT_EXIST:
1375 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
1376 SetSentErrorMessage(true);
1377 return false;
1378 case AOR_PASS_TOO_LONG:
1379 SendSysMessage(LANG_PASSWORD_TOO_LONG);
1380 SetSentErrorMessage(true);
1381 return false;
1382 default:
1383 SendSysMessage(LANG_COMMAND_NOTCHANGEPASSWORD);
1384 SetSentErrorMessage(true);
1385 return false;
1388 return true;
1391 bool ChatHandler::HandleMaxSkillCommand(const char* /*args*/)
1393 Player* SelectedPlayer = getSelectedPlayer();
1394 if(!SelectedPlayer)
1396 SendSysMessage(LANG_NO_CHAR_SELECTED);
1397 SetSentErrorMessage(true);
1398 return false;
1401 // each skills that have max skill value dependent from level seted to current level max skill value
1402 SelectedPlayer->UpdateSkillsToMaxSkillsForLevel();
1403 return true;
1406 bool ChatHandler::HandleSetSkillCommand(const char* args)
1408 // number or [name] Shift-click form |color|Hskill:skill_id|h[name]|h|r
1409 char* skill_p = extractKeyFromLink((char*)args,"Hskill");
1410 if(!skill_p)
1411 return false;
1413 char *level_p = strtok (NULL, " ");
1415 if( !level_p)
1416 return false;
1418 char *max_p = strtok (NULL, " ");
1420 int32 skill = atoi(skill_p);
1421 if (skill <= 0)
1423 PSendSysMessage(LANG_INVALID_SKILL_ID, skill);
1424 SetSentErrorMessage(true);
1425 return false;
1428 int32 level = atol (level_p);
1430 Player * target = getSelectedPlayer();
1431 if(!target)
1433 SendSysMessage(LANG_NO_CHAR_SELECTED);
1434 SetSentErrorMessage(true);
1435 return false;
1438 SkillLineEntry const* sl = sSkillLineStore.LookupEntry(skill);
1439 if(!sl)
1441 PSendSysMessage(LANG_INVALID_SKILL_ID, skill);
1442 SetSentErrorMessage(true);
1443 return false;
1446 std::string tNameLink = GetNameLink(target);
1448 if(!target->GetSkillValue(skill))
1450 PSendSysMessage(LANG_SET_SKILL_ERROR, tNameLink.c_str(), skill, sl->name[0]);
1451 SetSentErrorMessage(true);
1452 return false;
1455 int32 max = max_p ? atol (max_p) : target->GetPureMaxSkillValue(skill);
1457 if( level <= 0 || level > max || max <= 0 )
1458 return false;
1460 target->SetSkill(skill, level, max);
1461 PSendSysMessage(LANG_SET_SKILL, skill, sl->name[0], tNameLink.c_str(), level, max);
1463 return true;
1466 bool ChatHandler::HandleUnLearnCommand(const char* args)
1468 if (!*args)
1469 return false;
1471 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
1472 uint32 spell_id = extractSpellIdFromLink((char*)args);
1473 if(!spell_id)
1474 return false;
1476 char const* allStr = strtok(NULL," ");
1477 bool allRanks = allStr ? (strncmp(allStr, "all", strlen(allStr)) == 0) : false;
1479 Player* target = getSelectedPlayer();
1480 if(!target)
1482 SendSysMessage(LANG_NO_CHAR_SELECTED);
1483 SetSentErrorMessage(true);
1484 return false;
1487 if(allRanks)
1488 spell_id = spellmgr.GetFirstSpellInChain (spell_id);
1490 if (target->HasSpell(spell_id))
1491 target->removeSpell(spell_id,false,!allRanks);
1492 else
1493 SendSysMessage(LANG_FORGET_SPELL);
1495 return true;
1498 bool ChatHandler::HandleCooldownCommand(const char* args)
1500 Player* target = getSelectedPlayer();
1501 if(!target)
1503 SendSysMessage(LANG_PLAYER_NOT_FOUND);
1504 SetSentErrorMessage(true);
1505 return false;
1508 std::string tNameLink = GetNameLink(target);
1510 if (!*args)
1512 target->RemoveAllSpellCooldown();
1513 PSendSysMessage(LANG_REMOVEALL_COOLDOWN, tNameLink.c_str());
1515 else
1517 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
1518 uint32 spell_id = extractSpellIdFromLink((char*)args);
1519 if(!spell_id)
1520 return false;
1522 if(!sSpellStore.LookupEntry(spell_id))
1524 PSendSysMessage(LANG_UNKNOWN_SPELL, target==m_session->GetPlayer() ? GetMangosString(LANG_YOU) : tNameLink.c_str());
1525 SetSentErrorMessage(true);
1526 return false;
1529 WorldPacket data( SMSG_CLEAR_COOLDOWN, (4+8) );
1530 data << uint32(spell_id);
1531 data << uint64(target->GetGUID());
1532 target->GetSession()->SendPacket(&data);
1533 target->RemoveSpellCooldown(spell_id);
1534 PSendSysMessage(LANG_REMOVE_COOLDOWN, spell_id, target==m_session->GetPlayer() ? GetMangosString(LANG_YOU) : tNameLink.c_str());
1536 return true;
1539 bool ChatHandler::HandleLearnAllCommand(const char* /*args*/)
1541 static const char *allSpellList[] =
1543 "3365",
1544 "6233",
1545 "6247",
1546 "6246",
1547 "6477",
1548 "6478",
1549 "22810",
1550 "8386",
1551 "21651",
1552 "21652",
1553 "522",
1554 "7266",
1555 "8597",
1556 "2479",
1557 "22027",
1558 "6603",
1559 "5019",
1560 "133",
1561 "168",
1562 "227",
1563 "5009",
1564 "9078",
1565 "668",
1566 "203",
1567 "20599",
1568 "20600",
1569 "81",
1570 "20597",
1571 "20598",
1572 "20864",
1573 "1459",
1574 "5504",
1575 "587",
1576 "5143",
1577 "118",
1578 "5505",
1579 "597",
1580 "604",
1581 "1449",
1582 "1460",
1583 "2855",
1584 "1008",
1585 "475",
1586 "5506",
1587 "1463",
1588 "12824",
1589 "8437",
1590 "990",
1591 "5145",
1592 "8450",
1593 "1461",
1594 "759",
1595 "8494",
1596 "8455",
1597 "8438",
1598 "6127",
1599 "8416",
1600 "6129",
1601 "8451",
1602 "8495",
1603 "8439",
1604 "3552",
1605 "8417",
1606 "10138",
1607 "12825",
1608 "10169",
1609 "10156",
1610 "10144",
1611 "10191",
1612 "10201",
1613 "10211",
1614 "10053",
1615 "10173",
1616 "10139",
1617 "10145",
1618 "10192",
1619 "10170",
1620 "10202",
1621 "10054",
1622 "10174",
1623 "10193",
1624 "12826",
1625 "2136",
1626 "143",
1627 "145",
1628 "2137",
1629 "2120",
1630 "3140",
1631 "543",
1632 "2138",
1633 "2948",
1634 "8400",
1635 "2121",
1636 "8444",
1637 "8412",
1638 "8457",
1639 "8401",
1640 "8422",
1641 "8445",
1642 "8402",
1643 "8413",
1644 "8458",
1645 "8423",
1646 "8446",
1647 "10148",
1648 "10197",
1649 "10205",
1650 "10149",
1651 "10215",
1652 "10223",
1653 "10206",
1654 "10199",
1655 "10150",
1656 "10216",
1657 "10207",
1658 "10225",
1659 "10151",
1660 "116",
1661 "205",
1662 "7300",
1663 "122",
1664 "837",
1665 "10",
1666 "7301",
1667 "7322",
1668 "6143",
1669 "120",
1670 "865",
1671 "8406",
1672 "6141",
1673 "7302",
1674 "8461",
1675 "8407",
1676 "8492",
1677 "8427",
1678 "8408",
1679 "6131",
1680 "7320",
1681 "10159",
1682 "8462",
1683 "10185",
1684 "10179",
1685 "10160",
1686 "10180",
1687 "10219",
1688 "10186",
1689 "10177",
1690 "10230",
1691 "10181",
1692 "10161",
1693 "10187",
1694 "10220",
1695 "2018",
1696 "2663",
1697 "12260",
1698 "2660",
1699 "3115",
1700 "3326",
1701 "2665",
1702 "3116",
1703 "2738",
1704 "3293",
1705 "2661",
1706 "3319",
1707 "2662",
1708 "9983",
1709 "8880",
1710 "2737",
1711 "2739",
1712 "7408",
1713 "3320",
1714 "2666",
1715 "3323",
1716 "3324",
1717 "3294",
1718 "22723",
1719 "23219",
1720 "23220",
1721 "23221",
1722 "23228",
1723 "23338",
1724 "10788",
1725 "10790",
1726 "5611",
1727 "5016",
1728 "5609",
1729 "2060",
1730 "10963",
1731 "10964",
1732 "10965",
1733 "22593",
1734 "22594",
1735 "596",
1736 "996",
1737 "499",
1738 "768",
1739 "17002",
1740 "1448",
1741 "1082",
1742 "16979",
1743 "1079",
1744 "5215",
1745 "20484",
1746 "5221",
1747 "15590",
1748 "17007",
1749 "6795",
1750 "6807",
1751 "5487",
1752 "1446",
1753 "1066",
1754 "5421",
1755 "3139",
1756 "779",
1757 "6811",
1758 "6808",
1759 "1445",
1760 "5216",
1761 "1737",
1762 "5222",
1763 "5217",
1764 "1432",
1765 "6812",
1766 "9492",
1767 "5210",
1768 "3030",
1769 "1441",
1770 "783",
1771 "6801",
1772 "20739",
1773 "8944",
1774 "9491",
1775 "22569",
1776 "5226",
1777 "6786",
1778 "1433",
1779 "8973",
1780 "1828",
1781 "9495",
1782 "9006",
1783 "6794",
1784 "8993",
1785 "5203",
1786 "16914",
1787 "6784",
1788 "9635",
1789 "22830",
1790 "20722",
1791 "9748",
1792 "6790",
1793 "9753",
1794 "9493",
1795 "9752",
1796 "9831",
1797 "9825",
1798 "9822",
1799 "5204",
1800 "5401",
1801 "22831",
1802 "6793",
1803 "9845",
1804 "17401",
1805 "9882",
1806 "9868",
1807 "20749",
1808 "9893",
1809 "9899",
1810 "9895",
1811 "9832",
1812 "9902",
1813 "9909",
1814 "22832",
1815 "9828",
1816 "9851",
1817 "9883",
1818 "9869",
1819 "17406",
1820 "17402",
1821 "9914",
1822 "20750",
1823 "9897",
1824 "9848",
1825 "3127",
1826 "107",
1827 "204",
1828 "9116",
1829 "2457",
1830 "78",
1831 "18848",
1832 "331",
1833 "403",
1834 "2098",
1835 "1752",
1836 "11278",
1837 "11288",
1838 "11284",
1839 "6461",
1840 "2344",
1841 "2345",
1842 "6463",
1843 "2346",
1844 "2352",
1845 "775",
1846 "1434",
1847 "1612",
1848 "71",
1849 "2468",
1850 "2458",
1851 "2467",
1852 "7164",
1853 "7178",
1854 "7367",
1855 "7376",
1856 "7381",
1857 "21156",
1858 "5209",
1859 "3029",
1860 "5201",
1861 "9849",
1862 "9850",
1863 "20719",
1864 "22568",
1865 "22827",
1866 "22828",
1867 "22829",
1868 "6809",
1869 "8972",
1870 "9005",
1871 "9823",
1872 "9827",
1873 "6783",
1874 "9913",
1875 "6785",
1876 "6787",
1877 "9866",
1878 "9867",
1879 "9894",
1880 "9896",
1881 "6800",
1882 "8992",
1883 "9829",
1884 "9830",
1885 "780",
1886 "769",
1887 "6749",
1888 "6750",
1889 "9755",
1890 "9754",
1891 "9908",
1892 "20745",
1893 "20742",
1894 "20747",
1895 "20748",
1896 "9746",
1897 "9745",
1898 "9880",
1899 "9881",
1900 "5391",
1901 "842",
1902 "3025",
1903 "3031",
1904 "3287",
1905 "3329",
1906 "1945",
1907 "3559",
1908 "4933",
1909 "4934",
1910 "4935",
1911 "4936",
1912 "5142",
1913 "5390",
1914 "5392",
1915 "5404",
1916 "5420",
1917 "6405",
1918 "7293",
1919 "7965",
1920 "8041",
1921 "8153",
1922 "9033",
1923 "9034",
1924 //"9036", problems with ghost state
1925 "16421",
1926 "21653",
1927 "22660",
1928 "5225",
1929 "9846",
1930 "2426",
1931 "5916",
1932 "6634",
1933 //"6718", phasing stealth, annoying for learn all case.
1934 "6719",
1935 "8822",
1936 "9591",
1937 "9590",
1938 "10032",
1939 "17746",
1940 "17747",
1941 "8203",
1942 "11392",
1943 "12495",
1944 "16380",
1945 "23452",
1946 "4079",
1947 "4996",
1948 "4997",
1949 "4998",
1950 "4999",
1951 "5000",
1952 "6348",
1953 "6349",
1954 "6481",
1955 "6482",
1956 "6483",
1957 "6484",
1958 "11362",
1959 "11410",
1960 "11409",
1961 "12510",
1962 "12509",
1963 "12885",
1964 "13142",
1965 "21463",
1966 "23460",
1967 "11421",
1968 "11416",
1969 "11418",
1970 "1851",
1971 "10059",
1972 "11423",
1973 "11417",
1974 "11422",
1975 "11419",
1976 "11424",
1977 "11420",
1978 "27",
1979 "31",
1980 "33",
1981 "34",
1982 "35",
1983 "15125",
1984 "21127",
1985 "22950",
1986 "1180",
1987 "201",
1988 "12593",
1989 "12842",
1990 "16770",
1991 "6057",
1992 "12051",
1993 "18468",
1994 "12606",
1995 "12605",
1996 "18466",
1997 "12502",
1998 "12043",
1999 "15060",
2000 "12042",
2001 "12341",
2002 "12848",
2003 "12344",
2004 "12353",
2005 "18460",
2006 "11366",
2007 "12350",
2008 "12352",
2009 "13043",
2010 "11368",
2011 "11113",
2012 "12400",
2013 "11129",
2014 "16766",
2015 "12573",
2016 "15053",
2017 "12580",
2018 "12475",
2019 "12472",
2020 "12953",
2021 "12488",
2022 "11189",
2023 "12985",
2024 "12519",
2025 "16758",
2026 "11958",
2027 "12490",
2028 "11426",
2029 "3565",
2030 "3562",
2031 "18960",
2032 "3567",
2033 "3561",
2034 "3566",
2035 "3563",
2036 "1953",
2037 "2139",
2038 "12505",
2039 "13018",
2040 "12522",
2041 "12523",
2042 "5146",
2043 "5144",
2044 "5148",
2045 "8419",
2046 "8418",
2047 "10213",
2048 "10212",
2049 "10157",
2050 "12524",
2051 "13019",
2052 "12525",
2053 "13020",
2054 "12526",
2055 "13021",
2056 "18809",
2057 "13031",
2058 "13032",
2059 "13033",
2060 "4036",
2061 "3920",
2062 "3919",
2063 "3918",
2064 "7430",
2065 "3922",
2066 "3923",
2067 "7411",
2068 "7418",
2069 "7421",
2070 "13262",
2071 "7412",
2072 "7415",
2073 "7413",
2074 "7416",
2075 "13920",
2076 "13921",
2077 "7745",
2078 "7779",
2079 "7428",
2080 "7457",
2081 "7857",
2082 "7748",
2083 "7426",
2084 "13421",
2085 "7454",
2086 "13378",
2087 "7788",
2088 "14807",
2089 "14293",
2090 "7795",
2091 "6296",
2092 "20608",
2093 "755",
2094 "444",
2095 "427",
2096 "428",
2097 "442",
2098 "447",
2099 "3578",
2100 "3581",
2101 "19027",
2102 "3580",
2103 "665",
2104 "3579",
2105 "3577",
2106 "6755",
2107 "3576",
2108 "2575",
2109 "2577",
2110 "2578",
2111 "2579",
2112 "2580",
2113 "2656",
2114 "2657",
2115 "2576",
2116 "3564",
2117 "10248",
2118 "8388",
2119 "2659",
2120 "14891",
2121 "3308",
2122 "3307",
2123 "10097",
2124 "2658",
2125 "3569",
2126 "16153",
2127 "3304",
2128 "10098",
2129 "4037",
2130 "3929",
2131 "3931",
2132 "3926",
2133 "3924",
2134 "3930",
2135 "3977",
2136 "3925",
2137 "136",
2138 "228",
2139 "5487",
2140 "43",
2141 "202",
2145 int loop = 0;
2146 while(strcmp(allSpellList[loop], "0"))
2148 uint32 spell = atol((char*)allSpellList[loop++]);
2150 if (m_session->GetPlayer()->HasSpell(spell))
2151 continue;
2153 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
2154 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
2156 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
2157 continue;
2160 m_session->GetPlayer()->learnSpell(spell,false);
2163 SendSysMessage(LANG_COMMAND_LEARN_MANY_SPELLS);
2165 return true;
2168 bool ChatHandler::HandleLearnAllGMCommand(const char* /*args*/)
2170 static const char *gmSpellList[] =
2172 "24347", // Become A Fish, No Breath Bar
2173 "35132", // Visual Boom
2174 "38488", // Attack 4000-8000 AOE
2175 "38795", // Attack 2000 AOE + Slow Down 90%
2176 "15712", // Attack 200
2177 "1852", // GM Spell Silence
2178 "31899", // Kill
2179 "31924", // Kill
2180 "29878", // Kill My Self
2181 "26644", // More Kill
2183 "28550", //Invisible 24
2184 "23452", //Invisible + Target
2188 uint16 gmSpellIter = 0;
2189 while( strcmp(gmSpellList[gmSpellIter], "0") )
2191 uint32 spell = atol((char*)gmSpellList[gmSpellIter++]);
2193 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
2194 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
2196 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
2197 continue;
2200 m_session->GetPlayer()->learnSpell(spell,false);
2203 SendSysMessage(LANG_LEARNING_GM_SKILLS);
2204 return true;
2207 bool ChatHandler::HandleLearnAllMyClassCommand(const char* /*args*/)
2209 HandleLearnAllMySpellsCommand("");
2210 HandleLearnAllMyTalentsCommand("");
2211 return true;
2214 bool ChatHandler::HandleLearnAllMySpellsCommand(const char* /*args*/)
2216 ChrClassesEntry const* clsEntry = sChrClassesStore.LookupEntry(m_session->GetPlayer()->getClass());
2217 if(!clsEntry)
2218 return true;
2219 uint32 family = clsEntry->spellfamily;
2221 for (uint32 i = 0; i < sSpellStore.GetNumRows(); ++i)
2223 SpellEntry const *spellInfo = sSpellStore.LookupEntry(i);
2224 if(!spellInfo)
2225 continue;
2227 // skip server-side/triggered spells
2228 if(spellInfo->spellLevel==0)
2229 continue;
2231 // skip wrong class/race skills
2232 if(!m_session->GetPlayer()->IsSpellFitByClassAndRace(spellInfo->Id))
2233 continue;
2235 // skip other spell families
2236 if( spellInfo->SpellFamilyName != family)
2237 continue;
2239 // skip spells with first rank learned as talent (and all talents then also)
2240 uint32 first_rank = spellmgr.GetFirstSpellInChain(spellInfo->Id);
2241 if(GetTalentSpellCost(first_rank) > 0 )
2242 continue;
2244 // skip broken spells
2245 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer(),false))
2246 continue;
2248 m_session->GetPlayer()->learnSpell(i,false);
2251 SendSysMessage(LANG_COMMAND_LEARN_CLASS_SPELLS);
2252 return true;
2255 bool ChatHandler::HandleLearnAllMyTalentsCommand(const char* /*args*/)
2257 Player* player = m_session->GetPlayer();
2258 uint32 classMask = player->getClassMask();
2260 for (uint32 i = 0; i < sTalentStore.GetNumRows(); ++i)
2262 TalentEntry const *talentInfo = sTalentStore.LookupEntry(i);
2263 if(!talentInfo)
2264 continue;
2266 TalentTabEntry const *talentTabInfo = sTalentTabStore.LookupEntry( talentInfo->TalentTab );
2267 if(!talentTabInfo)
2268 continue;
2270 if( (classMask & talentTabInfo->ClassMask) == 0 )
2271 continue;
2273 // search highest talent rank
2274 uint32 spellid = 0;
2276 for(int rank = MAX_TALENT_RANK-1; rank >= 0; --rank)
2278 if(talentInfo->RankID[rank]!=0)
2280 spellid = talentInfo->RankID[rank];
2281 break;
2285 if(!spellid) // ??? none spells in talent
2286 continue;
2288 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spellid);
2289 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer(),false))
2290 continue;
2292 // learn highest rank of talent and learn all non-talent spell ranks (recursive by tree)
2293 player->learnSpellHighRank(spellid);
2296 SendSysMessage(LANG_COMMAND_LEARN_CLASS_TALENTS);
2297 return true;
2300 bool ChatHandler::HandleLearnAllMyPetTalentsCommand(const char* /*args*/)
2302 Player* player = m_session->GetPlayer();
2304 Pet* pet = player->GetPet();
2305 if(!pet)
2307 SendSysMessage(LANG_NO_PET_FOUND);
2308 SetSentErrorMessage(true);
2309 return false;
2312 CreatureInfo const *ci = pet->GetCreatureInfo();
2313 if(!ci)
2315 SendSysMessage(LANG_WRONG_PET_TYPE);
2316 SetSentErrorMessage(true);
2317 return false;
2320 CreatureFamilyEntry const *pet_family = sCreatureFamilyStore.LookupEntry(ci->family);
2321 if(!pet_family)
2323 SendSysMessage(LANG_WRONG_PET_TYPE);
2324 SetSentErrorMessage(true);
2325 return false;
2328 if(pet_family->petTalentType < 0) // not hunter pet
2330 SendSysMessage(LANG_WRONG_PET_TYPE);
2331 SetSentErrorMessage(true);
2332 return false;
2335 for (uint32 i = 0; i < sTalentStore.GetNumRows(); ++i)
2337 TalentEntry const *talentInfo = sTalentStore.LookupEntry(i);
2338 if(!talentInfo)
2339 continue;
2341 TalentTabEntry const *talentTabInfo = sTalentTabStore.LookupEntry( talentInfo->TalentTab );
2342 if(!talentTabInfo)
2343 continue;
2345 // prevent learn talent for different family (cheating)
2346 if(((1 << pet_family->petTalentType) & talentTabInfo->petTalentMask)==0)
2347 continue;
2349 // search highest talent rank
2350 uint32 spellid = 0;
2352 for(int rank = MAX_TALENT_RANK-1; rank >= 0; --rank)
2354 if(talentInfo->RankID[rank]!=0)
2356 spellid = talentInfo->RankID[rank];
2357 break;
2361 if(!spellid) // ??? none spells in talent
2362 continue;
2364 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spellid);
2365 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer(),false))
2366 continue;
2368 // learn highest rank of talent and learn all non-talent spell ranks (recursive by tree)
2369 pet->learnSpellHighRank(spellid);
2372 SendSysMessage(LANG_COMMAND_LEARN_PET_TALENTS);
2373 return true;
2376 bool ChatHandler::HandleLearnAllLangCommand(const char* /*args*/)
2378 // skipping UNIVERSAL language (0)
2379 for(int i = 1; i < LANGUAGES_COUNT; ++i)
2380 m_session->GetPlayer()->learnSpell(lang_description[i].spell_id,false);
2382 SendSysMessage(LANG_COMMAND_LEARN_ALL_LANG);
2383 return true;
2386 bool ChatHandler::HandleLearnAllDefaultCommand(const char* args)
2388 Player *player = NULL;
2389 if (*args)
2391 std::string name = extractPlayerNameFromLink((char*)args);
2392 if(name.empty())
2394 SendSysMessage(LANG_PLAYER_NOT_FOUND);
2395 SetSentErrorMessage(true);
2396 return false;
2399 player = objmgr.GetPlayer(name.c_str());
2401 else
2402 player = getSelectedPlayer();
2404 if(!player)
2406 SendSysMessage(LANG_NO_CHAR_SELECTED);
2407 SetSentErrorMessage(true);
2408 return false;
2411 player->learnDefaultSpells();
2412 player->learnQuestRewardedSpells();
2414 PSendSysMessage(LANG_COMMAND_LEARN_ALL_DEFAULT_AND_QUEST,GetNameLink(player).c_str());
2415 return true;
2418 bool ChatHandler::HandleLearnCommand(const char* args)
2420 Player* targetPlayer = getSelectedPlayer();
2422 if(!targetPlayer)
2424 SendSysMessage(LANG_PLAYER_NOT_FOUND);
2425 SetSentErrorMessage(true);
2426 return false;
2429 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
2430 uint32 spell = extractSpellIdFromLink((char*)args);
2431 if(!spell || !sSpellStore.LookupEntry(spell))
2432 return false;
2434 char const* allStr = strtok(NULL," ");
2435 bool allRanks = allStr ? (strncmp(allStr, "all", strlen(allStr)) == 0) : false;
2437 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
2438 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
2440 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
2441 SetSentErrorMessage(true);
2442 return false;
2445 if (!allRanks && targetPlayer->HasSpell(spell))
2447 if(targetPlayer == m_session->GetPlayer())
2448 SendSysMessage(LANG_YOU_KNOWN_SPELL);
2449 else
2450 PSendSysMessage(LANG_TARGET_KNOWN_SPELL,GetNameLink(targetPlayer).c_str());
2451 SetSentErrorMessage(true);
2452 return false;
2455 if(allRanks)
2456 targetPlayer->learnSpellHighRank(spell);
2457 else
2458 targetPlayer->learnSpell(spell,false);
2460 return true;
2463 bool ChatHandler::HandleAddItemCommand(const char* args)
2465 if (!*args)
2466 return false;
2468 uint32 itemId = 0;
2470 if(args[0]=='[') // [name] manual form
2472 char* citemName = citemName = strtok((char*)args, "]");
2474 if(citemName && citemName[0])
2476 std::string itemName = citemName+1;
2477 WorldDatabase.escape_string(itemName);
2478 QueryResult *result = WorldDatabase.PQuery("SELECT entry FROM item_template WHERE name = '%s'", itemName.c_str());
2479 if (!result)
2481 PSendSysMessage(LANG_COMMAND_COULDNOTFIND, citemName+1);
2482 SetSentErrorMessage(true);
2483 return false;
2485 itemId = result->Fetch()->GetUInt16();
2486 delete result;
2488 else
2489 return false;
2491 else // item_id or [name] Shift-click form |color|Hitem:item_id:0:0:0|h[name]|h|r
2493 char* cId = extractKeyFromLink((char*)args,"Hitem");
2494 if(!cId)
2495 return false;
2496 itemId = atol(cId);
2499 char* ccount = strtok(NULL, " ");
2501 int32 count = 1;
2503 if (ccount)
2504 count = strtol(ccount, NULL, 10);
2506 if (count == 0)
2507 count = 1;
2509 Player* pl = m_session->GetPlayer();
2510 Player* plTarget = getSelectedPlayer();
2511 if(!plTarget)
2512 plTarget = pl;
2514 sLog.outDetail(GetMangosString(LANG_ADDITEM), itemId, count);
2516 ItemPrototype const *pProto = objmgr.GetItemPrototype(itemId);
2517 if(!pProto)
2519 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, itemId);
2520 SetSentErrorMessage(true);
2521 return false;
2524 //Subtract
2525 if (count < 0)
2527 plTarget->DestroyItemCount(itemId, -count, true, false);
2528 PSendSysMessage(LANG_REMOVEITEM, itemId, -count, GetNameLink(plTarget).c_str());
2529 return true;
2532 //Adding items
2533 uint32 noSpaceForCount = 0;
2535 // check space and find places
2536 ItemPosCountVec dest;
2537 uint8 msg = plTarget->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, itemId, count, &noSpaceForCount );
2538 if( msg != EQUIP_ERR_OK ) // convert to possible store amount
2539 count -= noSpaceForCount;
2541 if( count == 0 || dest.empty()) // can't add any
2543 PSendSysMessage(LANG_ITEM_CANNOT_CREATE, itemId, noSpaceForCount );
2544 SetSentErrorMessage(true);
2545 return false;
2548 Item* item = plTarget->StoreNewItem( dest, itemId, true, Item::GenerateItemRandomPropertyId(itemId));
2550 // remove binding (let GM give it to another player later)
2551 if(pl==plTarget)
2552 for(ItemPosCountVec::const_iterator itr = dest.begin(); itr != dest.end(); ++itr)
2553 if(Item* item1 = pl->GetItemByPos(itr->pos))
2554 item1->SetBinding( false );
2556 if(count > 0 && item)
2558 pl->SendNewItem(item,count,false,true);
2559 if(pl!=plTarget)
2560 plTarget->SendNewItem(item,count,true,false);
2563 if(noSpaceForCount > 0)
2564 PSendSysMessage(LANG_ITEM_CANNOT_CREATE, itemId, noSpaceForCount);
2566 return true;
2569 bool ChatHandler::HandleAddItemSetCommand(const char* args)
2571 if (!*args)
2572 return false;
2574 char* cId = extractKeyFromLink((char*)args,"Hitemset"); // number or [name] Shift-click form |color|Hitemset:itemset_id|h[name]|h|r
2575 if (!cId)
2576 return false;
2578 uint32 itemsetId = atol(cId);
2580 // prevent generation all items with itemset field value '0'
2581 if (itemsetId == 0)
2583 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND,itemsetId);
2584 SetSentErrorMessage(true);
2585 return false;
2588 Player* pl = m_session->GetPlayer();
2589 Player* plTarget = getSelectedPlayer();
2590 if(!plTarget)
2591 plTarget = pl;
2593 sLog.outDetail(GetMangosString(LANG_ADDITEMSET), itemsetId);
2595 bool found = false;
2596 for (uint32 id = 0; id < sItemStorage.MaxEntry; id++)
2598 ItemPrototype const *pProto = sItemStorage.LookupEntry<ItemPrototype>(id);
2599 if (!pProto)
2600 continue;
2602 if (pProto->ItemSet == itemsetId)
2604 found = true;
2605 ItemPosCountVec dest;
2606 uint8 msg = plTarget->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, pProto->ItemId, 1 );
2607 if (msg == EQUIP_ERR_OK)
2609 Item* item = plTarget->StoreNewItem( dest, pProto->ItemId, true);
2611 // remove binding (let GM give it to another player later)
2612 if (pl==plTarget)
2613 item->SetBinding( false );
2615 pl->SendNewItem(item,1,false,true);
2616 if (pl!=plTarget)
2617 plTarget->SendNewItem(item,1,true,false);
2619 else
2621 pl->SendEquipError( msg, NULL, NULL );
2622 PSendSysMessage(LANG_ITEM_CANNOT_CREATE, pProto->ItemId, 1);
2627 if (!found)
2629 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND,itemsetId);
2631 SetSentErrorMessage(true);
2632 return false;
2635 return true;
2638 bool ChatHandler::HandleListItemCommand(const char* args)
2640 if(!*args)
2641 return false;
2643 char* cId = extractKeyFromLink((char*)args,"Hitem");
2644 if(!cId)
2645 return false;
2647 uint32 item_id = atol(cId);
2648 if(!item_id)
2650 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, item_id);
2651 SetSentErrorMessage(true);
2652 return false;
2655 ItemPrototype const* itemProto = objmgr.GetItemPrototype(item_id);
2656 if(!itemProto)
2658 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, item_id);
2659 SetSentErrorMessage(true);
2660 return false;
2663 char* c_count = strtok(NULL, " ");
2664 int count = c_count ? atol(c_count) : 10;
2666 if(count < 0)
2667 return false;
2669 QueryResult *result;
2671 // inventory case
2672 uint32 inv_count = 0;
2673 result=CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM character_inventory WHERE item_template='%u'",item_id);
2674 if(result)
2676 inv_count = (*result)[0].GetUInt32();
2677 delete result;
2680 result=CharacterDatabase.PQuery(
2681 // 0 1 2 3 4 5
2682 "SELECT ci.item, cibag.slot AS bag, ci.slot, ci.guid, characters.account,characters.name "
2683 "FROM character_inventory AS ci LEFT JOIN character_inventory AS cibag ON (cibag.item=ci.bag),characters "
2684 "WHERE ci.item_template='%u' AND ci.guid = characters.guid LIMIT %u ",
2685 item_id,uint32(count));
2687 if(result)
2691 Field *fields = result->Fetch();
2692 uint32 item_guid = fields[0].GetUInt32();
2693 uint32 item_bag = fields[1].GetUInt32();
2694 uint32 item_slot = fields[2].GetUInt32();
2695 uint32 owner_guid = fields[3].GetUInt32();
2696 uint32 owner_acc = fields[4].GetUInt32();
2697 std::string owner_name = fields[5].GetCppString();
2699 char const* item_pos = 0;
2700 if(Player::IsEquipmentPos(item_bag,item_slot))
2701 item_pos = "[equipped]";
2702 else if(Player::IsInventoryPos(item_bag,item_slot))
2703 item_pos = "[in inventory]";
2704 else if(Player::IsBankPos(item_bag,item_slot))
2705 item_pos = "[in bank]";
2706 else
2707 item_pos = "";
2709 PSendSysMessage(LANG_ITEMLIST_SLOT,
2710 item_guid,owner_name.c_str(),owner_guid,owner_acc,item_pos);
2711 } while (result->NextRow());
2713 int64 res_count = result->GetRowCount();
2715 delete result;
2717 if(count > res_count)
2718 count-=res_count;
2719 else if(count)
2720 count = 0;
2723 // mail case
2724 uint32 mail_count = 0;
2725 result=CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM mail_items WHERE item_template='%u'", item_id);
2726 if(result)
2728 mail_count = (*result)[0].GetUInt32();
2729 delete result;
2732 if(count > 0)
2734 result=CharacterDatabase.PQuery(
2735 // 0 1 2 3 4 5 6
2736 "SELECT mail_items.item_guid, mail.sender, mail.receiver, char_s.account, char_s.name, char_r.account, char_r.name "
2737 "FROM mail,mail_items,characters as char_s,characters as char_r "
2738 "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",
2739 item_id,uint32(count));
2741 else
2742 result = NULL;
2744 if(result)
2748 Field *fields = result->Fetch();
2749 uint32 item_guid = fields[0].GetUInt32();
2750 uint32 item_s = fields[1].GetUInt32();
2751 uint32 item_r = fields[2].GetUInt32();
2752 uint32 item_s_acc = fields[3].GetUInt32();
2753 std::string item_s_name = fields[4].GetCppString();
2754 uint32 item_r_acc = fields[5].GetUInt32();
2755 std::string item_r_name = fields[6].GetCppString();
2757 char const* item_pos = "[in mail]";
2759 PSendSysMessage(LANG_ITEMLIST_MAIL,
2760 item_guid,item_s_name.c_str(),item_s,item_s_acc,item_r_name.c_str(),item_r,item_r_acc,item_pos);
2761 } while (result->NextRow());
2763 int64 res_count = result->GetRowCount();
2765 delete result;
2767 if(count > res_count)
2768 count-=res_count;
2769 else if(count)
2770 count = 0;
2773 // auction case
2774 uint32 auc_count = 0;
2775 result=CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM auctionhouse WHERE item_template='%u'",item_id);
2776 if(result)
2778 auc_count = (*result)[0].GetUInt32();
2779 delete result;
2782 if(count > 0)
2784 result=CharacterDatabase.PQuery(
2785 // 0 1 2 3
2786 "SELECT auctionhouse.itemguid, auctionhouse.itemowner, characters.account, characters.name "
2787 "FROM auctionhouse,characters WHERE auctionhouse.item_template='%u' AND characters.guid = auctionhouse.itemowner LIMIT %u",
2788 item_id,uint32(count));
2790 else
2791 result = NULL;
2793 if(result)
2797 Field *fields = result->Fetch();
2798 uint32 item_guid = fields[0].GetUInt32();
2799 uint32 owner = fields[1].GetUInt32();
2800 uint32 owner_acc = fields[2].GetUInt32();
2801 std::string owner_name = fields[3].GetCppString();
2803 char const* item_pos = "[in auction]";
2805 PSendSysMessage(LANG_ITEMLIST_AUCTION, item_guid, owner_name.c_str(), owner, owner_acc,item_pos);
2806 } while (result->NextRow());
2808 delete result;
2811 // guild bank case
2812 uint32 guild_count = 0;
2813 result=CharacterDatabase.PQuery("SELECT COUNT(item_entry) FROM guild_bank_item WHERE item_entry='%u'",item_id);
2814 if(result)
2816 guild_count = (*result)[0].GetUInt32();
2817 delete result;
2820 result=CharacterDatabase.PQuery(
2821 // 0 1 2
2822 "SELECT gi.item_guid, gi.guildid, guild.name "
2823 "FROM guild_bank_item AS gi, guild WHERE gi.item_entry='%u' AND gi.guildid = guild.guildid LIMIT %u ",
2824 item_id,uint32(count));
2826 if(result)
2830 Field *fields = result->Fetch();
2831 uint32 item_guid = fields[0].GetUInt32();
2832 uint32 guild_guid = fields[1].GetUInt32();
2833 std::string guild_name = fields[2].GetCppString();
2835 char const* item_pos = "[in guild bank]";
2837 PSendSysMessage(LANG_ITEMLIST_GUILD,item_guid,guild_name.c_str(),guild_guid,item_pos);
2838 } while (result->NextRow());
2840 int64 res_count = result->GetRowCount();
2842 delete result;
2844 if(count > res_count)
2845 count-=res_count;
2846 else if(count)
2847 count = 0;
2850 if(inv_count+mail_count+auc_count+guild_count == 0)
2852 SendSysMessage(LANG_COMMAND_NOITEMFOUND);
2853 SetSentErrorMessage(true);
2854 return false;
2857 PSendSysMessage(LANG_COMMAND_LISTITEMMESSAGE,item_id,inv_count+mail_count+auc_count+guild_count,inv_count,mail_count,auc_count,guild_count);
2859 return true;
2862 bool ChatHandler::HandleListObjectCommand(const char* args)
2864 if(!*args)
2865 return false;
2867 // number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
2868 char* cId = extractKeyFromLink((char*)args,"Hgameobject_entry");
2869 if(!cId)
2870 return false;
2872 uint32 go_id = atol(cId);
2873 if(!go_id)
2875 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID, go_id);
2876 SetSentErrorMessage(true);
2877 return false;
2880 GameObjectInfo const * gInfo = objmgr.GetGameObjectInfo(go_id);
2881 if(!gInfo)
2883 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID, go_id);
2884 SetSentErrorMessage(true);
2885 return false;
2888 char* c_count = strtok(NULL, " ");
2889 int count = c_count ? atol(c_count) : 10;
2891 if(count < 0)
2892 return false;
2894 QueryResult *result;
2896 uint32 obj_count = 0;
2897 result=WorldDatabase.PQuery("SELECT COUNT(guid) FROM gameobject WHERE id='%u'",go_id);
2898 if(result)
2900 obj_count = (*result)[0].GetUInt32();
2901 delete result;
2904 if(m_session)
2906 Player* pl = m_session->GetPlayer();
2907 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",
2908 pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(),go_id,uint32(count));
2910 else
2911 result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map FROM gameobject WHERE id = '%u' LIMIT %u",
2912 go_id,uint32(count));
2914 if (result)
2918 Field *fields = result->Fetch();
2919 uint32 guid = fields[0].GetUInt32();
2920 float x = fields[1].GetFloat();
2921 float y = fields[2].GetFloat();
2922 float z = fields[3].GetFloat();
2923 int mapid = fields[4].GetUInt16();
2925 if (m_session)
2926 PSendSysMessage(LANG_GO_LIST_CHAT, guid, guid, gInfo->name, x, y, z, mapid);
2927 else
2928 PSendSysMessage(LANG_GO_LIST_CONSOLE, guid, gInfo->name, x, y, z, mapid);
2929 } while (result->NextRow());
2931 delete result;
2934 PSendSysMessage(LANG_COMMAND_LISTOBJMESSAGE,go_id,obj_count);
2935 return true;
2938 bool ChatHandler::HandleListCreatureCommand(const char* args)
2940 if(!*args)
2941 return false;
2943 // number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r
2944 char* cId = extractKeyFromLink((char*)args,"Hcreature_entry");
2945 if(!cId)
2946 return false;
2948 uint32 cr_id = atol(cId);
2949 if(!cr_id)
2951 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID, cr_id);
2952 SetSentErrorMessage(true);
2953 return false;
2956 CreatureInfo const* cInfo = objmgr.GetCreatureTemplate(cr_id);
2957 if(!cInfo)
2959 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID, cr_id);
2960 SetSentErrorMessage(true);
2961 return false;
2964 char* c_count = strtok(NULL, " ");
2965 int count = c_count ? atol(c_count) : 10;
2967 if(count < 0)
2968 return false;
2970 QueryResult *result;
2972 uint32 cr_count = 0;
2973 result=WorldDatabase.PQuery("SELECT COUNT(guid) FROM creature WHERE id='%u'",cr_id);
2974 if(result)
2976 cr_count = (*result)[0].GetUInt32();
2977 delete result;
2980 if(m_session)
2982 Player* pl = m_session->GetPlayer();
2983 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",
2984 pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(), cr_id,uint32(count));
2986 else
2987 result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map FROM creature WHERE id = '%u' LIMIT %u",
2988 cr_id,uint32(count));
2990 if (result)
2994 Field *fields = result->Fetch();
2995 uint32 guid = fields[0].GetUInt32();
2996 float x = fields[1].GetFloat();
2997 float y = fields[2].GetFloat();
2998 float z = fields[3].GetFloat();
2999 int mapid = fields[4].GetUInt16();
3001 if (m_session)
3002 PSendSysMessage(LANG_CREATURE_LIST_CHAT, guid, guid, cInfo->Name, x, y, z, mapid);
3003 else
3004 PSendSysMessage(LANG_CREATURE_LIST_CONSOLE, guid, cInfo->Name, x, y, z, mapid);
3005 } while (result->NextRow());
3007 delete result;
3010 PSendSysMessage(LANG_COMMAND_LISTCREATUREMESSAGE,cr_id,cr_count);
3011 return true;
3014 bool ChatHandler::HandleLookupItemCommand(const char* args)
3016 if(!*args)
3017 return false;
3019 std::string namepart = args;
3020 std::wstring wnamepart;
3022 // converting string that we try to find to lower case
3023 if(!Utf8toWStr(namepart,wnamepart))
3024 return false;
3026 wstrToLower(wnamepart);
3028 uint32 counter = 0;
3030 // Search in `item_template`
3031 for (uint32 id = 0; id < sItemStorage.MaxEntry; id++)
3033 ItemPrototype const *pProto = sItemStorage.LookupEntry<ItemPrototype >(id);
3034 if(!pProto)
3035 continue;
3037 int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex();
3038 if ( loc_idx >= 0 )
3040 ItemLocale const *il = objmgr.GetItemLocale(pProto->ItemId);
3041 if (il)
3043 if (il->Name.size() > loc_idx && !il->Name[loc_idx].empty())
3045 std::string name = il->Name[loc_idx];
3047 if (Utf8FitTo(name, wnamepart))
3049 if (m_session)
3050 PSendSysMessage(LANG_ITEM_LIST_CHAT, id, id, name.c_str());
3051 else
3052 PSendSysMessage(LANG_ITEM_LIST_CONSOLE, id, name.c_str());
3053 ++counter;
3054 continue;
3060 std::string name = pProto->Name1;
3061 if(name.empty())
3062 continue;
3064 if (Utf8FitTo(name, wnamepart))
3066 if (m_session)
3067 PSendSysMessage(LANG_ITEM_LIST_CHAT, id, id, name.c_str());
3068 else
3069 PSendSysMessage(LANG_ITEM_LIST_CONSOLE, id, name.c_str());
3070 ++counter;
3074 if (counter==0)
3075 SendSysMessage(LANG_COMMAND_NOITEMFOUND);
3077 return true;
3080 bool ChatHandler::HandleLookupItemSetCommand(const char* args)
3082 if(!*args)
3083 return false;
3085 std::string namepart = args;
3086 std::wstring wnamepart;
3088 if(!Utf8toWStr(namepart,wnamepart))
3089 return false;
3091 // converting string that we try to find to lower case
3092 wstrToLower( wnamepart );
3094 uint32 counter = 0; // Counter for figure out that we found smth.
3096 // Search in ItemSet.dbc
3097 for (uint32 id = 0; id < sItemSetStore.GetNumRows(); id++)
3099 ItemSetEntry const *set = sItemSetStore.LookupEntry(id);
3100 if(set)
3102 int loc = m_session ? m_session->GetSessionDbcLocale() : sWorld.GetDefaultDbcLocale();
3103 std::string name = set->name[loc];
3104 if(name.empty())
3105 continue;
3107 if (!Utf8FitTo(name, wnamepart))
3109 loc = 0;
3110 for(; loc < MAX_LOCALE; ++loc)
3112 if(m_session && loc==m_session->GetSessionDbcLocale())
3113 continue;
3115 name = set->name[loc];
3116 if(name.empty())
3117 continue;
3119 if (Utf8FitTo(name, wnamepart))
3120 break;
3124 if(loc < MAX_LOCALE)
3126 // send item set in "id - [namedlink locale]" format
3127 if (m_session)
3128 PSendSysMessage(LANG_ITEMSET_LIST_CHAT,id,id,name.c_str(),localeNames[loc]);
3129 else
3130 PSendSysMessage(LANG_ITEMSET_LIST_CONSOLE,id,name.c_str(),localeNames[loc]);
3131 ++counter;
3135 if (counter == 0) // if counter == 0 then we found nth
3136 SendSysMessage(LANG_COMMAND_NOITEMSETFOUND);
3137 return true;
3140 bool ChatHandler::HandleLookupSkillCommand(const char* args)
3142 if(!*args)
3143 return false;
3145 // can be NULL in console call
3146 Player* target = getSelectedPlayer();
3148 std::string namepart = args;
3149 std::wstring wnamepart;
3151 if(!Utf8toWStr(namepart,wnamepart))
3152 return false;
3154 // converting string that we try to find to lower case
3155 wstrToLower( wnamepart );
3157 uint32 counter = 0; // Counter for figure out that we found smth.
3159 // Search in SkillLine.dbc
3160 for (uint32 id = 0; id < sSkillLineStore.GetNumRows(); id++)
3162 SkillLineEntry const *skillInfo = sSkillLineStore.LookupEntry(id);
3163 if(skillInfo)
3165 int loc = m_session ? m_session->GetSessionDbcLocale() : sWorld.GetDefaultDbcLocale();
3166 std::string name = skillInfo->name[loc];
3167 if(name.empty())
3168 continue;
3170 if (!Utf8FitTo(name, wnamepart))
3172 loc = 0;
3173 for(; loc < MAX_LOCALE; ++loc)
3175 if(m_session && loc==m_session->GetSessionDbcLocale())
3176 continue;
3178 name = skillInfo->name[loc];
3179 if(name.empty())
3180 continue;
3182 if (Utf8FitTo(name, wnamepart))
3183 break;
3187 if(loc < MAX_LOCALE)
3189 char valStr[50] = "";
3190 char const* knownStr = "";
3191 if(target && target->HasSkill(id))
3193 knownStr = GetMangosString(LANG_KNOWN);
3194 uint32 curValue = target->GetPureSkillValue(id);
3195 uint32 maxValue = target->GetPureMaxSkillValue(id);
3196 uint32 permValue = target->GetSkillPermBonusValue(id);
3197 uint32 tempValue = target->GetSkillTempBonusValue(id);
3199 char const* valFormat = GetMangosString(LANG_SKILL_VALUES);
3200 snprintf(valStr,50,valFormat,curValue,maxValue,permValue,tempValue);
3203 // send skill in "id - [namedlink locale]" format
3204 if (m_session)
3205 PSendSysMessage(LANG_SKILL_LIST_CHAT,id,id,name.c_str(),localeNames[loc],knownStr,valStr);
3206 else
3207 PSendSysMessage(LANG_SKILL_LIST_CONSOLE,id,name.c_str(),localeNames[loc],knownStr,valStr);
3209 ++counter;
3213 if (counter == 0) // if counter == 0 then we found nth
3214 SendSysMessage(LANG_COMMAND_NOSKILLFOUND);
3215 return true;
3218 bool ChatHandler::HandleLookupSpellCommand(const char* args)
3220 if(!*args)
3221 return false;
3223 // can be NULL at console call
3224 Player* target = getSelectedPlayer();
3226 std::string namepart = args;
3227 std::wstring wnamepart;
3229 if(!Utf8toWStr(namepart,wnamepart))
3230 return false;
3232 // converting string that we try to find to lower case
3233 wstrToLower( wnamepart );
3235 uint32 counter = 0; // Counter for figure out that we found smth.
3237 // Search in Spell.dbc
3238 for (uint32 id = 0; id < sSpellStore.GetNumRows(); id++)
3240 SpellEntry const *spellInfo = sSpellStore.LookupEntry(id);
3241 if(spellInfo)
3243 int loc = m_session ? m_session->GetSessionDbcLocale() : sWorld.GetDefaultDbcLocale();
3244 std::string name = spellInfo->SpellName[loc];
3245 if(name.empty())
3246 continue;
3248 if (!Utf8FitTo(name, wnamepart))
3250 loc = 0;
3251 for(; loc < MAX_LOCALE; ++loc)
3253 if(m_session && loc==m_session->GetSessionDbcLocale())
3254 continue;
3256 name = spellInfo->SpellName[loc];
3257 if(name.empty())
3258 continue;
3260 if (Utf8FitTo(name, wnamepart))
3261 break;
3265 if(loc < MAX_LOCALE)
3267 bool known = target && target->HasSpell(id);
3268 bool learn = (spellInfo->Effect[0] == SPELL_EFFECT_LEARN_SPELL);
3270 uint32 talentCost = GetTalentSpellCost(id);
3272 bool talent = (talentCost > 0);
3273 bool passive = IsPassiveSpell(id);
3274 bool active = target && target->HasAura(id);
3276 // unit32 used to prevent interpreting uint8 as char at output
3277 // find rank of learned spell for learning spell, or talent rank
3278 uint32 rank = talentCost ? talentCost : spellmgr.GetSpellRank(learn ? spellInfo->EffectTriggerSpell[0] : id);
3280 // send spell in "id - [name, rank N] [talent] [passive] [learn] [known]" format
3281 std::ostringstream ss;
3282 if (m_session)
3283 ss << id << " - |cffffffff|Hspell:" << id << "|h[" << name;
3284 else
3285 ss << id << " - " << name;
3287 // include rank in link name
3288 if(rank)
3289 ss << GetMangosString(LANG_SPELL_RANK) << rank;
3291 if (m_session)
3292 ss << " " << localeNames[loc] << "]|h|r";
3293 else
3294 ss << " " << localeNames[loc];
3296 if(talent)
3297 ss << GetMangosString(LANG_TALENT);
3298 if(passive)
3299 ss << GetMangosString(LANG_PASSIVE);
3300 if(learn)
3301 ss << GetMangosString(LANG_LEARN);
3302 if(known)
3303 ss << GetMangosString(LANG_KNOWN);
3304 if(active)
3305 ss << GetMangosString(LANG_ACTIVE);
3307 SendSysMessage(ss.str().c_str());
3309 ++counter;
3313 if (counter == 0) // if counter == 0 then we found nth
3314 SendSysMessage(LANG_COMMAND_NOSPELLFOUND);
3315 return true;
3318 bool ChatHandler::HandleLookupQuestCommand(const char* args)
3320 if(!*args)
3321 return false;
3323 // can be NULL at console call
3324 Player* target = getSelectedPlayer();
3326 std::string namepart = args;
3327 std::wstring wnamepart;
3329 // converting string that we try to find to lower case
3330 if(!Utf8toWStr(namepart,wnamepart))
3331 return false;
3333 wstrToLower(wnamepart);
3335 uint32 counter = 0 ;
3337 ObjectMgr::QuestMap const& qTemplates = objmgr.GetQuestTemplates();
3338 for (ObjectMgr::QuestMap::const_iterator iter = qTemplates.begin(); iter != qTemplates.end(); ++iter)
3340 Quest * qinfo = iter->second;
3342 int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex();
3343 if ( loc_idx >= 0 )
3345 QuestLocale const *il = objmgr.GetQuestLocale(qinfo->GetQuestId());
3346 if (il)
3348 if (il->Title.size() > loc_idx && !il->Title[loc_idx].empty())
3350 std::string title = il->Title[loc_idx];
3352 if (Utf8FitTo(title, wnamepart))
3354 char const* statusStr = "";
3356 if(target)
3358 QuestStatus status = target->GetQuestStatus(qinfo->GetQuestId());
3360 if(status == QUEST_STATUS_COMPLETE)
3362 if(target->GetQuestRewardStatus(qinfo->GetQuestId()))
3363 statusStr = GetMangosString(LANG_COMMAND_QUEST_REWARDED);
3364 else
3365 statusStr = GetMangosString(LANG_COMMAND_QUEST_COMPLETE);
3367 else if(status == QUEST_STATUS_INCOMPLETE)
3368 statusStr = GetMangosString(LANG_COMMAND_QUEST_ACTIVE);
3371 if (m_session)
3372 PSendSysMessage(LANG_QUEST_LIST_CHAT,qinfo->GetQuestId(),qinfo->GetQuestId(),title.c_str(),statusStr);
3373 else
3374 PSendSysMessage(LANG_QUEST_LIST_CONSOLE,qinfo->GetQuestId(),title.c_str(),statusStr);
3375 ++counter;
3376 continue;
3382 std::string title = qinfo->GetTitle();
3383 if(title.empty())
3384 continue;
3386 if (Utf8FitTo(title, wnamepart))
3388 char const* statusStr = "";
3390 if(target)
3392 QuestStatus status = target->GetQuestStatus(qinfo->GetQuestId());
3394 if(status == QUEST_STATUS_COMPLETE)
3396 if(target->GetQuestRewardStatus(qinfo->GetQuestId()))
3397 statusStr = GetMangosString(LANG_COMMAND_QUEST_REWARDED);
3398 else
3399 statusStr = GetMangosString(LANG_COMMAND_QUEST_COMPLETE);
3401 else if(status == QUEST_STATUS_INCOMPLETE)
3402 statusStr = GetMangosString(LANG_COMMAND_QUEST_ACTIVE);
3405 if (m_session)
3406 PSendSysMessage(LANG_QUEST_LIST_CHAT,qinfo->GetQuestId(),qinfo->GetQuestId(),title.c_str(),statusStr);
3407 else
3408 PSendSysMessage(LANG_QUEST_LIST_CONSOLE,qinfo->GetQuestId(),title.c_str(),statusStr);
3410 ++counter;
3414 if (counter==0)
3415 SendSysMessage(LANG_COMMAND_NOQUESTFOUND);
3417 return true;
3420 bool ChatHandler::HandleLookupCreatureCommand(const char* args)
3422 if (!*args)
3423 return false;
3425 std::string namepart = args;
3426 std::wstring wnamepart;
3428 // converting string that we try to find to lower case
3429 if (!Utf8toWStr (namepart,wnamepart))
3430 return false;
3432 wstrToLower (wnamepart);
3434 uint32 counter = 0;
3436 for (uint32 id = 0; id< sCreatureStorage.MaxEntry; ++id)
3438 CreatureInfo const* cInfo = sCreatureStorage.LookupEntry<CreatureInfo> (id);
3439 if(!cInfo)
3440 continue;
3442 int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex();
3443 if (loc_idx >= 0)
3445 CreatureLocale const *cl = objmgr.GetCreatureLocale (id);
3446 if (cl)
3448 if (cl->Name.size() > loc_idx && !cl->Name[loc_idx].empty ())
3450 std::string name = cl->Name[loc_idx];
3452 if (Utf8FitTo (name, wnamepart))
3454 if (m_session)
3455 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT, id, id, name.c_str ());
3456 else
3457 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE, id, name.c_str ());
3458 ++counter;
3459 continue;
3465 std::string name = cInfo->Name;
3466 if (name.empty ())
3467 continue;
3469 if (Utf8FitTo(name, wnamepart))
3471 if (m_session)
3472 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT, id, id, name.c_str ());
3473 else
3474 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE, id, name.c_str ());
3475 ++counter;
3479 if (counter==0)
3480 SendSysMessage (LANG_COMMAND_NOCREATUREFOUND);
3482 return true;
3485 bool ChatHandler::HandleLookupObjectCommand(const char* args)
3487 if(!*args)
3488 return false;
3490 std::string namepart = args;
3491 std::wstring wnamepart;
3493 // converting string that we try to find to lower case
3494 if(!Utf8toWStr(namepart,wnamepart))
3495 return false;
3497 wstrToLower(wnamepart);
3499 uint32 counter = 0;
3501 for (uint32 id = 0; id< sGOStorage.MaxEntry; id++ )
3503 GameObjectInfo const* gInfo = sGOStorage.LookupEntry<GameObjectInfo>(id);
3504 if(!gInfo)
3505 continue;
3507 int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex();
3508 if ( loc_idx >= 0 )
3510 GameObjectLocale const *gl = objmgr.GetGameObjectLocale(id);
3511 if (gl)
3513 if (gl->Name.size() > loc_idx && !gl->Name[loc_idx].empty())
3515 std::string name = gl->Name[loc_idx];
3517 if (Utf8FitTo(name, wnamepart))
3519 if (m_session)
3520 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT, id, id, name.c_str());
3521 else
3522 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE, id, name.c_str());
3523 ++counter;
3524 continue;
3530 std::string name = gInfo->name;
3531 if(name.empty())
3532 continue;
3534 if(Utf8FitTo(name, wnamepart))
3536 if (m_session)
3537 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT, id, id, name.c_str());
3538 else
3539 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE, id, name.c_str());
3540 ++counter;
3544 if(counter==0)
3545 SendSysMessage(LANG_COMMAND_NOGAMEOBJECTFOUND);
3547 return true;
3550 /** \brief GM command level 3 - Create a guild.
3552 * This command allows a GM (level 3) to create a guild.
3554 * The "args" parameter contains the name of the guild leader
3555 * and then the name of the guild.
3558 bool ChatHandler::HandleGuildCreateCommand(const char* args)
3561 if (!*args)
3562 return false;
3564 char *lname = strtok ((char*)args, " ");
3565 char *gname = strtok (NULL, "");
3567 if (!lname)
3568 return false;
3570 if (!gname)
3572 SendSysMessage (LANG_INSERT_GUILD_NAME);
3573 SetSentErrorMessage (true);
3574 return false;
3577 std::string guildname = gname;
3579 Player* player = ObjectAccessor::Instance ().FindPlayerByName (lname);
3580 if (!player)
3582 SendSysMessage (LANG_PLAYER_NOT_FOUND);
3583 SetSentErrorMessage (true);
3584 return false;
3587 if (player->GetGuildId())
3589 SendSysMessage (LANG_PLAYER_IN_GUILD);
3590 return true;
3593 Guild *guild = new Guild;
3594 if (!guild->create (player,guildname))
3596 delete guild;
3597 SendSysMessage (LANG_GUILD_NOT_CREATED);
3598 SetSentErrorMessage (true);
3599 return false;
3602 objmgr.AddGuild (guild);
3603 return true;
3606 bool ChatHandler::HandleGuildInviteCommand(const char *args)
3608 if (!*args)
3609 return false;
3611 char* par1 = strtok ((char*)args, " ");
3612 char* par2 = strtok (NULL, "");
3613 if(!par1 || !par2)
3614 return false;
3616 std::string glName = par2;
3617 Guild* targetGuild = objmgr.GetGuildByName (glName);
3618 if (!targetGuild)
3619 return false;
3621 std::string plName = extractPlayerNameFromLink(par1);
3622 if(plName.empty())
3624 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3625 SetSentErrorMessage(true);
3626 return false;
3629 uint64 plGuid = 0;
3630 if (Player* targetPlayer = ObjectAccessor::Instance ().FindPlayerByName (plName.c_str ()))
3631 plGuid = targetPlayer->GetGUID ();
3632 else
3633 plGuid = objmgr.GetPlayerGUIDByName (plName);
3635 if (!plGuid)
3636 return false;
3638 // player's guild membership checked in AddMember before add
3639 if (!targetGuild->AddMember (plGuid,targetGuild->GetLowestRank ()))
3640 return false;
3642 return true;
3645 bool ChatHandler::HandleGuildUninviteCommand(const char *args)
3647 if (!*args)
3648 return false;
3650 char* par1 = strtok ((char*)args, " ");
3651 if(!par1)
3652 return false;
3654 std::string plName = extractPlayerNameFromLink(par1);
3655 if(plName.empty())
3657 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3658 SetSentErrorMessage(true);
3659 return false;
3662 uint64 plGuid = 0;
3663 uint32 glId = 0;
3664 if (Player* targetPlayer = ObjectAccessor::Instance ().FindPlayerByName (plName.c_str ()))
3666 plGuid = targetPlayer->GetGUID ();
3667 glId = targetPlayer->GetGuildId ();
3669 else
3671 plGuid = objmgr.GetPlayerGUIDByName (plName);
3672 glId = Player::GetGuildIdFromDB (plGuid);
3675 if (!plGuid || !glId)
3676 return false;
3678 Guild* targetGuild = objmgr.GetGuildById (glId);
3679 if (!targetGuild)
3680 return false;
3682 targetGuild->DelMember (plGuid);
3684 return true;
3687 bool ChatHandler::HandleGuildRankCommand(const char *args)
3689 if (!*args)
3690 return false;
3692 char* par1 = strtok ((char*)args, " ");
3693 char* par2 = strtok (NULL, " ");
3694 if (!par1 || !par2)
3695 return false;
3697 std::string plName = extractPlayerNameFromLink(par1);
3698 if(plName.empty())
3700 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3701 SetSentErrorMessage(true);
3702 return false;
3706 uint64 plGuid = 0;
3707 uint32 glId = 0;
3708 if (Player* targetPlayer = ObjectAccessor::Instance ().FindPlayerByName (plName.c_str ()))
3710 plGuid = targetPlayer->GetGUID ();
3711 glId = targetPlayer->GetGuildId ();
3713 else
3715 plGuid = objmgr.GetPlayerGUIDByName (plName);
3716 glId = Player::GetGuildIdFromDB (plGuid);
3719 if (!plGuid || !glId)
3720 return false;
3722 Guild* targetGuild = objmgr.GetGuildById (glId);
3723 if (!targetGuild)
3724 return false;
3726 uint32 newrank = uint32 (atoi (par2));
3727 if (newrank > targetGuild->GetLowestRank ())
3728 return false;
3730 targetGuild->ChangeRank (plGuid,newrank);
3732 return true;
3735 bool ChatHandler::HandleGuildDeleteCommand(const char* args)
3737 if (!*args)
3738 return false;
3740 char* par1 = strtok ((char*)args, " ");
3741 if (!par1)
3742 return false;
3744 std::string gld = par1;
3746 Guild* targetGuild = objmgr.GetGuildByName (gld);
3747 if (!targetGuild)
3748 return false;
3750 targetGuild->Disband ();
3752 return true;
3755 bool ChatHandler::HandleGetDistanceCommand(const char* args)
3757 WorldObject* obj = NULL;
3759 if (*args)
3761 uint64 guid = extractGuidFromLink((char*)args);
3762 if(guid)
3763 obj = (WorldObject*)ObjectAccessor::GetObjectByTypeMask(*m_session->GetPlayer(),guid,TYPEMASK_UNIT|TYPEMASK_GAMEOBJECT);
3765 if(!obj)
3767 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3768 SetSentErrorMessage(true);
3769 return false;
3772 else
3774 obj = getSelectedUnit();
3776 if(!obj)
3778 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3779 SetSentErrorMessage(true);
3780 return false;
3784 PSendSysMessage(LANG_DISTANCE, m_session->GetPlayer()->GetDistance(obj),m_session->GetPlayer()->GetDistance2d(obj));
3786 return true;
3789 bool ChatHandler::HandleDieCommand(const char* /*args*/)
3791 Unit* target = getSelectedUnit();
3793 if(!target || !m_session->GetPlayer()->GetSelection())
3795 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3796 SetSentErrorMessage(true);
3797 return false;
3800 if(target->GetTypeId()==TYPEID_PLAYER)
3802 if(HasLowerSecurity((Player*)target,0,false))
3803 return false;
3806 if( target->isAlive() )
3808 m_session->GetPlayer()->DealDamage(target, target->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
3811 return true;
3814 bool ChatHandler::HandleDamageCommand(const char * args)
3816 if (!*args)
3817 return false;
3819 Unit* target = getSelectedUnit();
3821 if(!target || !m_session->GetPlayer()->GetSelection())
3823 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3824 SetSentErrorMessage(true);
3825 return false;
3828 if( !target->isAlive() )
3829 return true;
3831 char* damageStr = strtok((char*)args, " ");
3832 if(!damageStr)
3833 return false;
3835 int32 damage = atoi((char*)damageStr);
3836 if(damage <=0)
3837 return true;
3839 char* schoolStr = strtok((char*)NULL, " ");
3841 // flat melee damage without resistence/etc reduction
3842 if(!schoolStr)
3844 m_session->GetPlayer()->DealDamage(target, damage, NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
3845 m_session->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2, target, 1, SPELL_SCHOOL_MASK_NORMAL, damage, 0, 0, VICTIMSTATE_NORMAL, 0);
3846 return true;
3849 uint32 school = schoolStr ? atoi((char*)schoolStr) : SPELL_SCHOOL_NORMAL;
3850 if(school >= MAX_SPELL_SCHOOL)
3851 return false;
3853 SpellSchoolMask schoolmask = SpellSchoolMask(1 << school);
3855 if ( schoolmask & SPELL_SCHOOL_MASK_NORMAL )
3856 damage = m_session->GetPlayer()->CalcArmorReducedDamage(target, damage);
3858 char* spellStr = strtok((char*)NULL, " ");
3860 // melee damage by specific school
3861 if(!spellStr)
3863 uint32 absorb = 0;
3864 uint32 resist = 0;
3866 m_session->GetPlayer()->CalcAbsorbResist(target,schoolmask, SPELL_DIRECT_DAMAGE, damage, &absorb, &resist);
3868 if (damage <= absorb + resist)
3869 return true;
3871 damage -= absorb + resist;
3873 m_session->GetPlayer()->DealDamage(target, damage, NULL, DIRECT_DAMAGE, schoolmask, NULL, false);
3874 m_session->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2, target, 1, schoolmask, damage, absorb, resist, VICTIMSTATE_NORMAL, 0);
3875 return true;
3878 // non-melee damage
3880 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3881 uint32 spellid = extractSpellIdFromLink((char*)args);
3882 if(!spellid || !sSpellStore.LookupEntry(spellid))
3883 return false;
3885 m_session->GetPlayer()->SpellNonMeleeDamageLog(target, spellid, damage, false);
3886 return true;
3889 bool ChatHandler::HandleModifyArenaCommand(const char * args)
3891 if (!*args)
3892 return false;
3894 Player *target = getSelectedPlayer();
3895 if(!target)
3897 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3898 SetSentErrorMessage(true);
3899 return false;
3902 int32 amount = (uint32)atoi(args);
3904 target->ModifyArenaPoints(amount);
3906 PSendSysMessage(LANG_COMMAND_MODIFY_ARENA, GetNameLink(target).c_str(), target->GetArenaPoints());
3908 return true;
3911 bool ChatHandler::HandleReviveCommand(const char* args)
3913 Player* player = NULL;
3914 uint64 player_guid = 0;
3916 if (*args)
3918 std::string name = extractPlayerNameFromLink((char*)args);
3919 if (name.empty())
3921 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3922 SetSentErrorMessage(true);
3923 return false;
3926 player = objmgr.GetPlayer(name.c_str());
3927 if (!player)
3928 player_guid = objmgr.GetPlayerGUIDByName(name);
3930 else
3931 player = getSelectedPlayer();
3933 if (player)
3935 player->ResurrectPlayer(0.5f);
3936 player->SpawnCorpseBones();
3937 player->SaveToDB();
3939 else if (player_guid)
3941 // will resurrected at login without corpse
3942 ObjectAccessor::Instance().ConvertCorpseForPlayer(player_guid);
3944 else
3946 SendSysMessage(LANG_NO_CHAR_SELECTED);
3947 SetSentErrorMessage(true);
3948 return false;
3951 return true;
3954 bool ChatHandler::HandleAuraCommand(const char* args)
3956 Unit *target = getSelectedUnit();
3957 if(!target)
3959 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3960 SetSentErrorMessage(true);
3961 return false;
3964 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3965 uint32 spellID = extractSpellIdFromLink((char*)args);
3967 SpellEntry const *spellInfo = sSpellStore.LookupEntry( spellID );
3968 if(spellInfo)
3970 for(uint32 i = 0;i<3;++i)
3972 uint8 eff = spellInfo->Effect[i];
3973 if (eff>=TOTAL_SPELL_EFFECTS)
3974 continue;
3975 if( IsAreaAuraEffect(eff) ||
3976 eff == SPELL_EFFECT_APPLY_AURA ||
3977 eff == SPELL_EFFECT_PERSISTENT_AREA_AURA )
3979 Aura *Aur = CreateAura(spellInfo, i, NULL, target);
3980 target->AddAura(Aur);
3985 return true;
3988 bool ChatHandler::HandleUnAuraCommand(const char* args)
3990 Unit *target = getSelectedUnit();
3991 if(!target)
3993 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3994 SetSentErrorMessage(true);
3995 return false;
3998 std::string argstr = args;
3999 if (argstr == "all")
4001 target->RemoveAllAuras();
4002 return true;
4005 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
4006 uint32 spellID = extractSpellIdFromLink((char*)args);
4007 if(!spellID)
4008 return false;
4010 target->RemoveAurasDueToSpell(spellID);
4012 return true;
4015 bool ChatHandler::HandleLinkGraveCommand(const char* args)
4017 if(!*args)
4018 return false;
4020 char* px = strtok((char*)args, " ");
4021 if (!px)
4022 return false;
4024 uint32 g_id = (uint32)atoi(px);
4026 uint32 g_team;
4028 char* px2 = strtok(NULL, " ");
4030 if (!px2)
4031 g_team = 0;
4032 else if (strncmp(px2,"horde",6)==0)
4033 g_team = HORDE;
4034 else if (strncmp(px2,"alliance",9)==0)
4035 g_team = ALLIANCE;
4036 else
4037 return false;
4039 WorldSafeLocsEntry const* graveyard = sWorldSafeLocsStore.LookupEntry(g_id);
4041 if(!graveyard )
4043 PSendSysMessage(LANG_COMMAND_GRAVEYARDNOEXIST, g_id);
4044 SetSentErrorMessage(true);
4045 return false;
4048 Player* player = m_session->GetPlayer();
4050 uint32 zoneId = player->GetZoneId();
4052 AreaTableEntry const *areaEntry = GetAreaEntryByAreaID(zoneId);
4053 if(!areaEntry || areaEntry->zone !=0 )
4055 PSendSysMessage(LANG_COMMAND_GRAVEYARDWRONGZONE, g_id,zoneId);
4056 SetSentErrorMessage(true);
4057 return false;
4060 if(objmgr.AddGraveYardLink(g_id,zoneId,g_team))
4061 PSendSysMessage(LANG_COMMAND_GRAVEYARDLINKED, g_id,zoneId);
4062 else
4063 PSendSysMessage(LANG_COMMAND_GRAVEYARDALRLINKED, g_id,zoneId);
4065 return true;
4068 bool ChatHandler::HandleNearGraveCommand(const char* args)
4070 uint32 g_team;
4072 size_t argslen = strlen(args);
4074 if(!*args)
4075 g_team = 0;
4076 else if (strncmp((char*)args,"horde",argslen)==0)
4077 g_team = HORDE;
4078 else if (strncmp((char*)args,"alliance",argslen)==0)
4079 g_team = ALLIANCE;
4080 else
4081 return false;
4083 Player* player = m_session->GetPlayer();
4084 uint32 zone_id = player->GetZoneId();
4086 WorldSafeLocsEntry const* graveyard = objmgr.GetClosestGraveYard(
4087 player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(),player->GetMapId(),g_team);
4089 if(graveyard)
4091 uint32 g_id = graveyard->ID;
4093 GraveYardData const* data = objmgr.FindGraveYardData(g_id,zone_id);
4094 if (!data)
4096 PSendSysMessage(LANG_COMMAND_GRAVEYARDERROR,g_id);
4097 SetSentErrorMessage(true);
4098 return false;
4101 g_team = data->team;
4103 std::string team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_NOTEAM);
4105 if(g_team == 0)
4106 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ANY);
4107 else if(g_team == HORDE)
4108 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE);
4109 else if(g_team == ALLIANCE)
4110 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE);
4112 PSendSysMessage(LANG_COMMAND_GRAVEYARDNEAREST, g_id,team_name.c_str(),zone_id);
4114 else
4116 std::string team_name;
4118 if(g_team == 0)
4119 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ANY);
4120 else if(g_team == HORDE)
4121 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE);
4122 else if(g_team == ALLIANCE)
4123 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE);
4125 if(g_team == ~uint32(0))
4126 PSendSysMessage(LANG_COMMAND_ZONENOGRAVEYARDS, zone_id);
4127 else
4128 PSendSysMessage(LANG_COMMAND_ZONENOGRAFACTION, zone_id,team_name.c_str());
4131 return true;
4134 //-----------------------Npc Commands-----------------------
4135 bool ChatHandler::HandleNpcAllowMovementCommand(const char* /*args*/)
4137 if(sWorld.getAllowMovement())
4139 sWorld.SetAllowMovement(false);
4140 SendSysMessage(LANG_CREATURE_MOVE_DISABLED);
4142 else
4144 sWorld.SetAllowMovement(true);
4145 SendSysMessage(LANG_CREATURE_MOVE_ENABLED);
4147 return true;
4150 bool ChatHandler::HandleNpcChangeEntryCommand(const char *args)
4152 if (!*args)
4153 return false;
4155 uint32 newEntryNum = atoi(args);
4156 if(!newEntryNum)
4157 return false;
4159 Unit* unit = getSelectedUnit();
4160 if(!unit || unit->GetTypeId() != TYPEID_UNIT)
4162 SendSysMessage(LANG_SELECT_CREATURE);
4163 SetSentErrorMessage(true);
4164 return false;
4166 Creature* creature = (Creature*)unit;
4167 if(creature->UpdateEntry(newEntryNum))
4168 SendSysMessage(LANG_DONE);
4169 else
4170 SendSysMessage(LANG_ERROR);
4171 return true;
4174 bool ChatHandler::HandleNpcInfoCommand(const char* /*args*/)
4176 Creature* target = getSelectedCreature();
4178 if(!target)
4180 SendSysMessage(LANG_SELECT_CREATURE);
4181 SetSentErrorMessage(true);
4182 return false;
4185 uint32 faction = target->getFaction();
4186 uint32 npcflags = target->GetUInt32Value(UNIT_NPC_FLAGS);
4187 uint32 displayid = target->GetDisplayId();
4188 uint32 nativeid = target->GetNativeDisplayId();
4189 uint32 Entry = target->GetEntry();
4190 CreatureInfo const* cInfo = target->GetCreatureInfo();
4192 int32 curRespawnDelay = target->GetRespawnTimeEx()-time(NULL);
4193 if(curRespawnDelay < 0)
4194 curRespawnDelay = 0;
4195 std::string curRespawnDelayStr = secsToTimeString(curRespawnDelay,true);
4196 std::string defRespawnDelayStr = secsToTimeString(target->GetRespawnDelay(),true);
4198 PSendSysMessage(LANG_NPCINFO_CHAR, target->GetDBTableGUIDLow(), faction, npcflags, Entry, displayid, nativeid);
4199 PSendSysMessage(LANG_NPCINFO_LEVEL, target->getLevel());
4200 PSendSysMessage(LANG_NPCINFO_HEALTH,target->GetCreateHealth(), target->GetMaxHealth(), target->GetHealth());
4201 PSendSysMessage(LANG_NPCINFO_FLAGS, target->GetUInt32Value(UNIT_FIELD_FLAGS), target->GetUInt32Value(UNIT_DYNAMIC_FLAGS), target->getFaction());
4202 PSendSysMessage(LANG_COMMAND_RAWPAWNTIMES, defRespawnDelayStr.c_str(),curRespawnDelayStr.c_str());
4203 PSendSysMessage(LANG_NPCINFO_LOOT, cInfo->lootid,cInfo->pickpocketLootId,cInfo->SkinLootId);
4204 PSendSysMessage(LANG_NPCINFO_DUNGEON_ID, target->GetInstanceId());
4205 PSendSysMessage(LANG_NPCINFO_POSITION,float(target->GetPositionX()), float(target->GetPositionY()), float(target->GetPositionZ()));
4207 if ((npcflags & UNIT_NPC_FLAG_VENDOR) )
4209 SendSysMessage(LANG_NPCINFO_VENDOR);
4211 if ((npcflags & UNIT_NPC_FLAG_TRAINER) )
4213 SendSysMessage(LANG_NPCINFO_TRAINER);
4216 return true;
4219 //play npc emote
4220 bool ChatHandler::HandleNpcPlayEmoteCommand(const char* args)
4222 uint32 emote = atoi((char*)args);
4224 Creature* target = getSelectedCreature();
4225 if(!target)
4227 SendSysMessage(LANG_SELECT_CREATURE);
4228 SetSentErrorMessage(true);
4229 return false;
4232 target->SetUInt32Value(UNIT_NPC_EMOTESTATE,emote);
4234 return true;
4237 //TODO: NpcCommands that needs to be fixed :
4239 bool ChatHandler::HandleNpcAddWeaponCommand(const char* /*args*/)
4241 /*if (!*args)
4242 return false;
4244 uint64 guid = m_session->GetPlayer()->GetSelection();
4245 if (guid == 0)
4247 SendSysMessage(LANG_NO_SELECTION);
4248 return true;
4251 Creature *pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(), guid);
4253 if(!pCreature)
4255 SendSysMessage(LANG_SELECT_CREATURE);
4256 return true;
4259 char* pSlotID = strtok((char*)args, " ");
4260 if (!pSlotID)
4261 return false;
4263 char* pItemID = strtok(NULL, " ");
4264 if (!pItemID)
4265 return false;
4267 uint32 ItemID = atoi(pItemID);
4268 uint32 SlotID = atoi(pSlotID);
4270 ItemPrototype* tmpItem = objmgr.GetItemPrototype(ItemID);
4272 bool added = false;
4273 if(tmpItem)
4275 switch(SlotID)
4277 case 1:
4278 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY, ItemID);
4279 added = true;
4280 break;
4281 case 2:
4282 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_01, ItemID);
4283 added = true;
4284 break;
4285 case 3:
4286 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_02, ItemID);
4287 added = true;
4288 break;
4289 default:
4290 PSendSysMessage(LANG_ITEM_SLOT_NOT_EXIST,SlotID);
4291 added = false;
4292 break;
4295 if(added)
4296 PSendSysMessage(LANG_ITEM_ADDED_TO_SLOT,ItemID,tmpItem->Name1,SlotID);
4298 else
4300 PSendSysMessage(LANG_ITEM_NOT_FOUND,ItemID);
4301 return true;
4304 return true;
4306 //----------------------------------------------------------
4308 bool ChatHandler::HandleExploreCheatCommand(const char* args)
4310 if (!*args)
4311 return false;
4313 int flag = atoi((char*)args);
4315 Player *chr = getSelectedPlayer();
4316 if (chr == NULL)
4318 SendSysMessage(LANG_NO_CHAR_SELECTED);
4319 SetSentErrorMessage(true);
4320 return false;
4323 if (flag != 0)
4325 PSendSysMessage(LANG_YOU_SET_EXPLORE_ALL, GetNameLink(chr).c_str());
4326 if (needReportToTarget(chr))
4327 ChatHandler(chr).PSendSysMessage(LANG_YOURS_EXPLORE_SET_ALL,GetNameLink().c_str());
4329 else
4331 PSendSysMessage(LANG_YOU_SET_EXPLORE_NOTHING, GetNameLink(chr).c_str());
4332 if (needReportToTarget(chr))
4333 ChatHandler(chr).PSendSysMessage(LANG_YOURS_EXPLORE_SET_NOTHING,GetNameLink().c_str());
4336 for (uint8 i=0; i<128; ++i)
4338 if (flag != 0)
4340 m_session->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1+i,0xFFFFFFFF);
4342 else
4344 m_session->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1+i,0);
4348 return true;
4351 bool ChatHandler::HandleHoverCommand(const char* args)
4353 char* px = strtok((char*)args, " ");
4354 uint32 flag;
4355 if (!px)
4356 flag = 1;
4357 else
4358 flag = atoi(px);
4360 m_session->GetPlayer()->SetHover(flag);
4362 if (flag)
4363 SendSysMessage(LANG_HOVER_ENABLED);
4364 else
4365 SendSysMessage(LANG_HOVER_DISABLED);
4367 return true;
4370 void ChatHandler::HandleCharacterLevel(Player* player, uint64 player_guid, uint32 oldlevel, uint32 newlevel)
4372 if(player)
4374 player->GiveLevel(newlevel);
4375 player->InitTalentForLevel();
4376 player->SetUInt32Value(PLAYER_XP,0);
4378 if(needReportToTarget(player))
4380 if(oldlevel == newlevel)
4381 ChatHandler(player).PSendSysMessage(LANG_YOURS_LEVEL_PROGRESS_RESET,GetNameLink().c_str());
4382 else if(oldlevel < newlevel)
4383 ChatHandler(player).PSendSysMessage(LANG_YOURS_LEVEL_UP,GetNameLink().c_str(),newlevel);
4384 else // if(oldlevel > newlevel)
4385 ChatHandler(player).PSendSysMessage(LANG_YOURS_LEVEL_DOWN,GetNameLink().c_str(),newlevel);
4388 else
4390 // update level and XP at level, all other will be updated at loading
4391 Tokens values;
4392 Player::LoadValuesArrayFromDB(values,player_guid);
4393 Player::SetUInt32ValueInArray(values,UNIT_FIELD_LEVEL,newlevel);
4394 Player::SetUInt32ValueInArray(values,PLAYER_XP,0);
4395 Player::SaveValuesArrayInDB(values,player_guid);
4399 bool ChatHandler::HandleCharacterLevelCommand(const char* args)
4401 char* px = strtok((char*)args, " ");
4402 char* py = strtok((char*)NULL, " ");
4404 // command format parsing
4405 char* pname = (char*)NULL;
4406 int32 newlevel = 0;
4408 if(px && py) // .character level $name #level
4410 newlevel = atoi(py);
4411 pname = px;
4413 else if(px && !py) // .character level $name OR .character level #level
4415 if(isalpha(px[0])) // .character level $name
4416 pname = px;
4417 else // .character level #level
4418 newlevel = atoi(px);
4420 // // .character level - progress reset
4422 if(newlevel < 1)
4423 return false; // invalid level
4425 if(newlevel > STRONG_MAX_LEVEL) // hardcoded maximum level
4426 newlevel = STRONG_MAX_LEVEL;
4428 // player
4429 Player *chr = NULL;
4430 uint64 chr_guid = 0;
4432 std::string name;
4434 if(pname) // player by name
4436 name = extractPlayerNameFromLink(pname);
4437 if(name.empty())
4439 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4440 SetSentErrorMessage(true);
4441 return false;
4444 chr = objmgr.GetPlayer(name.c_str());
4445 if(!chr) // not in game
4447 chr_guid = objmgr.GetPlayerGUIDByName(name);
4448 if (chr_guid == 0)
4450 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4451 SetSentErrorMessage(true);
4452 return false;
4456 else // player by selection
4458 chr = getSelectedPlayer();
4460 if (chr == NULL)
4462 SendSysMessage(LANG_NO_CHAR_SELECTED);
4463 SetSentErrorMessage(true);
4464 return false;
4467 name = chr->GetName();
4470 assert(chr || chr_guid);
4472 int32 oldlevel = chr ? chr->getLevel() : Player::GetUInt32ValueFromDB(UNIT_FIELD_LEVEL,chr_guid);
4474 if(!px && !py) // .character level - progress reset
4475 newlevel = oldlevel;
4477 HandleCharacterLevel(chr,chr_guid,oldlevel,newlevel);
4479 if(m_session && m_session->GetPlayer() != chr) // including player==NULL
4481 std::string nameLink = playerLink(name);
4482 PSendSysMessage(LANG_YOU_CHANGE_LVL,nameLink.c_str(),newlevel);
4485 return true;
4488 bool ChatHandler::HandleLevelUpCommand(const char* args)
4490 char* px = strtok((char*)args, " ");
4491 char* py = strtok((char*)NULL, " ");
4493 // command format parsing
4494 char* pname = (char*)NULL;
4495 int addlevel = 1;
4497 if(px && py) // .levelup name level
4499 addlevel = atoi(py);
4500 pname = px;
4502 else if(px && !py) // .levelup name OR .levelup level
4504 if(isalpha(px[0])) // .levelup name
4505 pname = px;
4506 else // .levelup level
4507 addlevel = atoi(px);
4509 // else .levelup - nothing do for preparing
4511 // player
4512 Player *chr = NULL;
4513 uint64 chr_guid = 0;
4515 std::string name;
4517 if(pname) // player by name
4519 name = extractPlayerNameFromLink(pname);
4520 if(name.empty())
4522 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4523 SetSentErrorMessage(true);
4524 return false;
4527 chr = objmgr.GetPlayer(name.c_str());
4528 if(!chr) // not in game
4530 chr_guid = objmgr.GetPlayerGUIDByName(name);
4531 if (chr_guid == 0)
4533 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4534 SetSentErrorMessage(true);
4535 return false;
4539 else // player by selection
4541 chr = getSelectedPlayer();
4543 if (chr == NULL)
4545 SendSysMessage(LANG_NO_CHAR_SELECTED);
4546 SetSentErrorMessage(true);
4547 return false;
4550 name = chr->GetName();
4553 assert(chr || chr_guid);
4555 int32 oldlevel = chr ? chr->getLevel() : Player::GetUInt32ValueFromDB(UNIT_FIELD_LEVEL,chr_guid);
4556 int32 newlevel = oldlevel + addlevel;
4557 if(newlevel < 1)
4558 newlevel = 1;
4559 if(newlevel > STRONG_MAX_LEVEL) // hardcoded maximum level
4560 newlevel = STRONG_MAX_LEVEL;
4562 HandleCharacterLevel(chr,chr_guid,oldlevel,newlevel);
4564 if(m_session && m_session->GetPlayer() != chr) // including chr==NULL
4566 std::string nameLink = playerLink(name);
4567 PSendSysMessage(LANG_YOU_CHANGE_LVL,nameLink.c_str(),newlevel);
4570 return true;
4573 bool ChatHandler::HandleShowAreaCommand(const char* args)
4575 if (!*args)
4576 return false;
4578 Player *chr = getSelectedPlayer();
4579 if (chr == NULL)
4581 SendSysMessage(LANG_NO_CHAR_SELECTED);
4582 SetSentErrorMessage(true);
4583 return false;
4586 int area = GetAreaFlagByAreaID(atoi((char*)args));
4587 int offset = area / 32;
4588 uint32 val = (uint32)(1 << (area % 32));
4590 if(area<0 || offset >= 128)
4592 SendSysMessage(LANG_BAD_VALUE);
4593 SetSentErrorMessage(true);
4594 return false;
4597 uint32 currFields = chr->GetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset);
4598 chr->SetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset, (uint32)(currFields | val));
4600 SendSysMessage(LANG_EXPLORE_AREA);
4601 return true;
4604 bool ChatHandler::HandleHideAreaCommand(const char* args)
4606 if (!*args)
4607 return false;
4609 Player *chr = getSelectedPlayer();
4610 if (chr == NULL)
4612 SendSysMessage(LANG_NO_CHAR_SELECTED);
4613 SetSentErrorMessage(true);
4614 return false;
4617 int area = GetAreaFlagByAreaID(atoi((char*)args));
4618 int offset = area / 32;
4619 uint32 val = (uint32)(1 << (area % 32));
4621 if(area<0 || offset >= 128)
4623 SendSysMessage(LANG_BAD_VALUE);
4624 SetSentErrorMessage(true);
4625 return false;
4628 uint32 currFields = chr->GetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset);
4629 chr->SetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset, (uint32)(currFields ^ val));
4631 SendSysMessage(LANG_UNEXPLORE_AREA);
4632 return true;
4635 bool ChatHandler::HandleDebugUpdate(const char* args)
4637 if(!*args)
4638 return false;
4640 uint32 updateIndex;
4641 uint32 value;
4643 char* pUpdateIndex = strtok((char*)args, " ");
4645 Unit* chr = getSelectedUnit();
4646 if (chr == NULL)
4648 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
4649 SetSentErrorMessage(true);
4650 return false;
4653 if(!pUpdateIndex)
4655 return true;
4657 updateIndex = atoi(pUpdateIndex);
4658 //check updateIndex
4659 if(chr->GetTypeId() == TYPEID_PLAYER)
4661 if (updateIndex>=PLAYER_END) return true;
4663 else
4665 if (updateIndex>=UNIT_END) return true;
4668 char* pvalue = strtok(NULL, " ");
4669 if (!pvalue)
4671 value=chr->GetUInt32Value(updateIndex);
4673 PSendSysMessage(LANG_UPDATE, chr->GetGUIDLow(),updateIndex,value);
4674 return true;
4677 value=atoi(pvalue);
4679 PSendSysMessage(LANG_UPDATE_CHANGE, chr->GetGUIDLow(),updateIndex,value);
4681 chr->SetUInt32Value(updateIndex,value);
4683 return true;
4686 bool ChatHandler::HandleBankCommand(const char* /*args*/)
4688 m_session->SendShowBank( m_session->GetPlayer()->GetGUID() );
4690 return true;
4693 bool ChatHandler::HandleChangeWeather(const char* args)
4695 if(!*args)
4696 return false;
4698 //Weather is OFF
4699 if (!sWorld.getConfig(CONFIG_WEATHER))
4701 SendSysMessage(LANG_WEATHER_DISABLED);
4702 SetSentErrorMessage(true);
4703 return false;
4706 //*Change the weather of a cell
4707 char* px = strtok((char*)args, " ");
4708 char* py = strtok(NULL, " ");
4710 if (!px || !py)
4711 return false;
4713 uint32 type = (uint32)atoi(px); //0 to 3, 0: fine, 1: rain, 2: snow, 3: sand
4714 float grade = (float)atof(py); //0 to 1, sending -1 is instand good weather
4716 Player *player = m_session->GetPlayer();
4717 uint32 zoneid = player->GetZoneId();
4719 Weather* wth = sWorld.FindWeather(zoneid);
4721 if(!wth)
4722 wth = sWorld.AddWeather(zoneid);
4723 if(!wth)
4725 SendSysMessage(LANG_NO_WEATHER);
4726 SetSentErrorMessage(true);
4727 return false;
4730 wth->SetWeather(WeatherType(type), grade);
4732 return true;
4735 bool ChatHandler::HandleDebugSetValue(const char* args)
4737 if(!*args)
4738 return false;
4740 char* px = strtok((char*)args, " ");
4741 char* py = strtok(NULL, " ");
4742 char* pz = strtok(NULL, " ");
4744 if (!px || !py)
4745 return false;
4747 Unit* target = getSelectedUnit();
4748 if(!target)
4750 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
4751 SetSentErrorMessage(true);
4752 return false;
4755 uint64 guid = target->GetGUID();
4757 uint32 Opcode = (uint32)atoi(px);
4758 if(Opcode >= target->GetValuesCount())
4760 PSendSysMessage(LANG_TOO_BIG_INDEX, Opcode, GUID_LOPART(guid), target->GetValuesCount());
4761 return false;
4763 uint32 iValue;
4764 float fValue;
4765 bool isint32 = true;
4766 if(pz)
4767 isint32 = (bool)atoi(pz);
4768 if(isint32)
4770 iValue = (uint32)atoi(py);
4771 sLog.outDebug(GetMangosString(LANG_SET_UINT), GUID_LOPART(guid), Opcode, iValue);
4772 target->SetUInt32Value( Opcode , iValue );
4773 PSendSysMessage(LANG_SET_UINT_FIELD, GUID_LOPART(guid), Opcode,iValue);
4775 else
4777 fValue = (float)atof(py);
4778 sLog.outDebug(GetMangosString(LANG_SET_FLOAT), GUID_LOPART(guid), Opcode, fValue);
4779 target->SetFloatValue( Opcode , fValue );
4780 PSendSysMessage(LANG_SET_FLOAT_FIELD, GUID_LOPART(guid), Opcode,fValue);
4783 return true;
4786 bool ChatHandler::HandleDebugGetValue(const char* args)
4788 if(!*args)
4789 return false;
4791 char* px = strtok((char*)args, " ");
4792 char* pz = strtok(NULL, " ");
4794 if (!px)
4795 return false;
4797 Unit* target = getSelectedUnit();
4798 if(!target)
4800 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
4801 SetSentErrorMessage(true);
4802 return false;
4805 uint64 guid = target->GetGUID();
4807 uint32 Opcode = (uint32)atoi(px);
4808 if(Opcode >= target->GetValuesCount())
4810 PSendSysMessage(LANG_TOO_BIG_INDEX, Opcode, GUID_LOPART(guid), target->GetValuesCount());
4811 return false;
4813 uint32 iValue;
4814 float fValue;
4815 bool isint32 = true;
4816 if(pz)
4817 isint32 = (bool)atoi(pz);
4819 if(isint32)
4821 iValue = target->GetUInt32Value( Opcode );
4822 sLog.outDebug(GetMangosString(LANG_GET_UINT), GUID_LOPART(guid), Opcode, iValue);
4823 PSendSysMessage(LANG_GET_UINT_FIELD, GUID_LOPART(guid), Opcode, iValue);
4825 else
4827 fValue = target->GetFloatValue( Opcode );
4828 sLog.outDebug(GetMangosString(LANG_GET_FLOAT), GUID_LOPART(guid), Opcode, fValue);
4829 PSendSysMessage(LANG_GET_FLOAT_FIELD, GUID_LOPART(guid), Opcode, fValue);
4832 return true;
4835 bool ChatHandler::HandleSet32Bit(const char* args)
4837 if(!*args)
4838 return false;
4840 char* px = strtok((char*)args, " ");
4841 char* py = strtok(NULL, " ");
4843 if (!px || !py)
4844 return false;
4846 uint32 Opcode = (uint32)atoi(px);
4847 uint32 Value = (uint32)atoi(py);
4848 if (Value > 32) //uint32 = 32 bits
4849 return false;
4851 sLog.outDebug(GetMangosString(LANG_SET_32BIT), Opcode, Value);
4853 m_session->GetPlayer( )->SetUInt32Value( Opcode , 2^Value );
4855 PSendSysMessage(LANG_SET_32BIT_FIELD, Opcode,1);
4856 return true;
4859 bool ChatHandler::HandleDebugMod32Value(const char* args)
4861 if(!*args)
4862 return false;
4864 char* px = strtok((char*)args, " ");
4865 char* py = strtok(NULL, " ");
4867 if (!px || !py)
4868 return false;
4870 uint32 Opcode = (uint32)atoi(px);
4871 int Value = atoi(py);
4873 if(Opcode >= m_session->GetPlayer()->GetValuesCount())
4875 PSendSysMessage(LANG_TOO_BIG_INDEX, Opcode, m_session->GetPlayer()->GetGUIDLow(), m_session->GetPlayer( )->GetValuesCount());
4876 return false;
4879 sLog.outDebug(GetMangosString(LANG_CHANGE_32BIT), Opcode, Value);
4881 int CurrentValue = (int)m_session->GetPlayer( )->GetUInt32Value( Opcode );
4883 CurrentValue += Value;
4884 m_session->GetPlayer( )->SetUInt32Value( Opcode , (uint32)CurrentValue );
4886 PSendSysMessage(LANG_CHANGE_32BIT_FIELD, Opcode,CurrentValue);
4888 return true;
4891 bool ChatHandler::HandleTeleAddCommand(const char * args)
4893 if(!*args)
4894 return false;
4896 Player *player=m_session->GetPlayer();
4897 if (!player)
4898 return false;
4900 std::string name = args;
4902 if(objmgr.GetGameTele(name))
4904 SendSysMessage(LANG_COMMAND_TP_ALREADYEXIST);
4905 SetSentErrorMessage(true);
4906 return false;
4909 GameTele tele;
4910 tele.position_x = player->GetPositionX();
4911 tele.position_y = player->GetPositionY();
4912 tele.position_z = player->GetPositionZ();
4913 tele.orientation = player->GetOrientation();
4914 tele.mapId = player->GetMapId();
4915 tele.name = name;
4917 if(objmgr.AddGameTele(tele))
4919 SendSysMessage(LANG_COMMAND_TP_ADDED);
4921 else
4923 SendSysMessage(LANG_COMMAND_TP_ADDEDERR);
4924 SetSentErrorMessage(true);
4925 return false;
4928 return true;
4931 bool ChatHandler::HandleTeleDelCommand(const char * args)
4933 if(!*args)
4934 return false;
4936 std::string name = args;
4938 if(!objmgr.DeleteGameTele(name))
4940 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
4941 SetSentErrorMessage(true);
4942 return false;
4945 SendSysMessage(LANG_COMMAND_TP_DELETED);
4946 return true;
4949 bool ChatHandler::HandleListAurasCommand (const char * /*args*/)
4951 Unit *unit = getSelectedUnit();
4952 if(!unit)
4954 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
4955 SetSentErrorMessage(true);
4956 return false;
4959 char const* talentStr = GetMangosString(LANG_TALENT);
4960 char const* passiveStr = GetMangosString(LANG_PASSIVE);
4962 Unit::AuraMap const& uAuras = unit->GetAuras();
4963 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURAS, uAuras.size());
4964 for (Unit::AuraMap::const_iterator itr = uAuras.begin(); itr != uAuras.end(); ++itr)
4966 bool talent = GetTalentSpellCost(itr->second->GetId()) > 0;
4968 char const* name = itr->second->GetSpellProto()->SpellName[m_session->GetSessionDbcLocale()];
4970 if (m_session)
4972 std::ostringstream ss_name;
4973 ss_name << "|cffffffff|Hspell:" << itr->second->GetId() << "|h[" << name << "]|h|r";
4975 PSendSysMessage(LANG_COMMAND_TARGET_AURADETAIL, itr->second->GetId(), itr->second->GetEffIndex(),
4976 itr->second->GetModifier()->m_auraname, itr->second->GetAuraDuration(), itr->second->GetAuraMaxDuration(),
4977 ss_name.str().c_str(),
4978 (itr->second->IsPassive() ? passiveStr : ""),(talent ? talentStr : ""),
4979 IS_PLAYER_GUID(itr->second->GetCasterGUID()) ? "player" : "creature",GUID_LOPART(itr->second->GetCasterGUID()));
4981 else
4983 PSendSysMessage(LANG_COMMAND_TARGET_AURADETAIL, itr->second->GetId(), itr->second->GetEffIndex(),
4984 itr->second->GetModifier()->m_auraname, itr->second->GetAuraDuration(), itr->second->GetAuraMaxDuration(),
4985 name,
4986 (itr->second->IsPassive() ? passiveStr : ""),(talent ? talentStr : ""),
4987 IS_PLAYER_GUID(itr->second->GetCasterGUID()) ? "player" : "creature",GUID_LOPART(itr->second->GetCasterGUID()));
4990 for (int i = 0; i < TOTAL_AURAS; ++i)
4992 Unit::AuraList const& uAuraList = unit->GetAurasByType(AuraType(i));
4993 if (uAuraList.empty()) continue;
4994 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURATYPE, uAuraList.size(), i);
4995 for (Unit::AuraList::const_iterator itr = uAuraList.begin(); itr != uAuraList.end(); ++itr)
4997 bool talent = GetTalentSpellCost((*itr)->GetId()) > 0;
4999 char const* name = (*itr)->GetSpellProto()->SpellName[m_session->GetSessionDbcLocale()];
5001 if (m_session)
5003 std::ostringstream ss_name;
5004 ss_name << "|cffffffff|Hspell:" << (*itr)->GetId() << "|h[" << name << "]|h|r";
5006 PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE, (*itr)->GetId(), (*itr)->GetEffIndex(),
5007 ss_name.str().c_str(),((*itr)->IsPassive() ? passiveStr : ""),(talent ? talentStr : ""),
5008 IS_PLAYER_GUID((*itr)->GetCasterGUID()) ? "player" : "creature",GUID_LOPART((*itr)->GetCasterGUID()));
5010 else
5012 PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE, (*itr)->GetId(), (*itr)->GetEffIndex(),
5013 name,((*itr)->IsPassive() ? passiveStr : ""),(talent ? talentStr : ""),
5014 IS_PLAYER_GUID((*itr)->GetCasterGUID()) ? "player" : "creature",GUID_LOPART((*itr)->GetCasterGUID()));
5018 return true;
5021 bool ChatHandler::HandleResetAchievementsCommand (const char * args)
5023 char* pName = strtok((char*)args, "");
5024 Player *player = NULL;
5025 uint64 guid = 0;
5026 if (pName)
5028 std::string name = extractPlayerNameFromLink(pName);
5029 if(name.empty())
5031 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5032 SetSentErrorMessage(true);
5033 return false;
5036 guid = objmgr.GetPlayerGUIDByName(name);
5037 player = objmgr.GetPlayer(guid);
5039 else
5041 player = getSelectedPlayer();
5042 if(player)
5043 guid = player->GetGUID();
5046 if(!player && !guid)
5048 SendSysMessage(LANG_NO_CHAR_SELECTED);
5049 return true;
5052 if(player)
5053 player->GetAchievementMgr().Reset();
5054 else if(guid)
5055 AchievementMgr::DeleteFromDB(GUID_LOPART(guid));
5057 return true;
5060 bool ChatHandler::HandleResetHonorCommand (const char * args)
5062 char* pName = strtok((char*)args, "");
5063 Player *player = NULL;
5064 if (pName)
5066 std::string name = extractPlayerNameFromLink(pName);
5067 if(name.empty())
5069 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5070 SetSentErrorMessage(true);
5071 return false;
5074 uint64 guid = objmgr.GetPlayerGUIDByName(name);
5075 player = objmgr.GetPlayer(guid);
5077 else
5078 player = getSelectedPlayer();
5080 if(!player)
5082 SendSysMessage(LANG_NO_CHAR_SELECTED);
5083 return true;
5086 player->SetUInt32Value(PLAYER_FIELD_KILLS, 0);
5087 player->SetUInt32Value(PLAYER_FIELD_LIFETIME_HONORBALE_KILLS, 0);
5088 player->SetUInt32Value(PLAYER_FIELD_HONOR_CURRENCY, 0);
5089 player->SetUInt32Value(PLAYER_FIELD_TODAY_CONTRIBUTION, 0);
5090 player->SetUInt32Value(PLAYER_FIELD_YESTERDAY_CONTRIBUTION, 0);
5092 player->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_EARN_HONORABLE_KILL);
5094 return true;
5097 static bool HandleResetStatsOrLevelHelper(Player* player)
5099 PlayerInfo const *info = objmgr.GetPlayerInfo(player->getRace(), player->getClass());
5100 if(!info) return false;
5102 ChrClassesEntry const* cEntry = sChrClassesStore.LookupEntry(player->getClass());
5103 if(!cEntry)
5105 sLog.outError("Class %u not found in DBC (Wrong DBC files?)",player->getClass());
5106 return false;
5109 uint8 powertype = cEntry->powerType;
5111 // reset m_form if no aura
5112 if(!player->HasAuraType(SPELL_AURA_MOD_SHAPESHIFT))
5113 player->m_form = FORM_NONE;
5115 player->SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS, DEFAULT_WORLD_OBJECT_SIZE );
5116 player->SetFloatValue(UNIT_FIELD_COMBATREACH, 1.5f );
5118 player->setFactionForRace(player->getRace());
5120 player->SetUInt32Value(UNIT_FIELD_BYTES_0, ( ( player->getRace() ) | ( player->getClass() << 8 ) | ( player->getGender() << 16 ) | ( powertype << 24 ) ) );
5122 // reset only if player not in some form;
5123 if(player->m_form==FORM_NONE)
5125 switch(player->getGender())
5127 case GENDER_FEMALE:
5128 player->SetDisplayId(info->displayId_f);
5129 player->SetNativeDisplayId(info->displayId_f);
5130 break;
5131 case GENDER_MALE:
5132 player->SetDisplayId(info->displayId_m);
5133 player->SetNativeDisplayId(info->displayId_m);
5134 break;
5135 default:
5136 break;
5140 player->SetByteValue(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_PVP );
5141 player->SetByteValue(UNIT_FIELD_BYTES_2, 3, player->m_form);
5143 player->SetUInt32Value(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE);
5145 //-1 is default value
5146 player->SetUInt32Value(PLAYER_FIELD_WATCHED_FACTION_INDEX, uint32(-1));
5148 //player->SetUInt32Value(PLAYER_FIELD_BYTES, 0xEEE00000 );
5149 return true;
5152 bool ChatHandler::HandleResetLevelCommand(const char * args)
5154 char* pName = strtok((char*)args, "");
5155 Player *player = NULL;
5156 if (pName)
5158 std::string name = extractPlayerNameFromLink(pName);
5159 if(name.empty())
5161 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5162 SetSentErrorMessage(true);
5163 return false;
5166 uint64 guid = objmgr.GetPlayerGUIDByName(name);
5167 player = objmgr.GetPlayer(guid);
5169 else
5170 player = getSelectedPlayer();
5172 if(!player)
5174 SendSysMessage(LANG_NO_CHAR_SELECTED);
5175 SetSentErrorMessage(true);
5176 return false;
5179 if(!HandleResetStatsOrLevelHelper(player))
5180 return false;
5182 // set starting level
5183 uint32 start_level = player->getClass() != CLASS_DEATH_KNIGHT
5184 ? sWorld.getConfig(CONFIG_START_PLAYER_LEVEL)
5185 : sWorld.getConfig(CONFIG_START_HEROIC_PLAYER_LEVEL);
5187 player->SetLevel(start_level);
5188 player->InitRunes();
5189 player->InitStatsForLevel(true);
5190 player->InitTaxiNodesForLevel();
5191 player->InitGlyphsForLevel();
5192 player->InitTalentForLevel();
5193 player->SetUInt32Value(PLAYER_XP,0);
5195 // reset level to summoned pet
5196 Pet* pet = player->GetPet();
5197 if(pet && pet->getPetType()==SUMMON_PET)
5199 pet->InitStatsForLevel(1);
5200 pet->InitTalentForLevel();
5202 return true;
5205 bool ChatHandler::HandleResetStatsCommand(const char * args)
5207 char* pName = strtok((char*)args, "");
5208 Player *player = NULL;
5209 if (pName)
5211 std::string name = extractPlayerNameFromLink(pName);
5212 if(name.empty())
5214 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5215 SetSentErrorMessage(true);
5216 return false;
5219 uint64 guid = objmgr.GetPlayerGUIDByName(name);
5220 player = objmgr.GetPlayer(guid);
5222 else
5223 player = getSelectedPlayer();
5225 if(!player)
5227 SendSysMessage(LANG_NO_CHAR_SELECTED);
5228 SetSentErrorMessage(true);
5229 return false;
5232 if(!HandleResetStatsOrLevelHelper(player))
5233 return false;
5235 player->InitRunes();
5236 player->InitStatsForLevel(true);
5237 player->InitTaxiNodesForLevel();
5238 player->InitGlyphsForLevel();
5239 player->InitTalentForLevel();
5241 return true;
5244 bool ChatHandler::HandleResetSpellsCommand(const char * args)
5246 char* pName = strtok((char*)args, "");
5247 Player *player = NULL;
5248 uint64 playerGUID = 0;
5249 if (pName)
5251 std::string name = extractPlayerNameFromLink(pName);
5252 if(name.empty())
5254 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5255 SetSentErrorMessage(true);
5256 return false;
5259 player = objmgr.GetPlayer(name.c_str());
5260 if(!player)
5261 playerGUID = objmgr.GetPlayerGUIDByName(name);
5263 else
5264 player = getSelectedPlayer();
5266 if(!player && !playerGUID)
5268 SendSysMessage(LANG_NO_CHAR_SELECTED);
5269 SetSentErrorMessage(true);
5270 return false;
5273 if(player)
5275 player->resetSpells();
5277 ChatHandler(player).SendSysMessage(LANG_RESET_SPELLS);
5278 if(m_session->GetPlayer()!=player)
5279 PSendSysMessage(LANG_RESET_SPELLS_ONLINE,GetNameLink(player).c_str());
5281 else
5283 CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_SPELLS), GUID_LOPART(playerGUID));
5284 PSendSysMessage(LANG_RESET_SPELLS_OFFLINE,pName);
5287 return true;
5290 bool ChatHandler::HandleResetTalentsCommand(const char * args)
5292 char* pName = strtok((char*)args, "");
5293 Player *player = NULL;
5294 uint64 playerGUID = 0;
5295 if (pName)
5297 std::string name = extractPlayerNameFromLink(pName);
5298 if(name.empty())
5300 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5301 SetSentErrorMessage(true);
5302 return false;
5305 player = objmgr.GetPlayer(name.c_str());
5306 if(!player)
5307 playerGUID = objmgr.GetPlayerGUIDByName(name);
5309 else
5310 player = getSelectedPlayer();
5312 if(player)
5314 player->resetTalents(true);
5316 ChatHandler(player).SendSysMessage(LANG_RESET_TALENTS);
5317 if(m_session->GetPlayer()!=player)
5318 PSendSysMessage(LANG_RESET_TALENTS_ONLINE,GetNameLink(player).c_str());
5320 return true;
5322 else if (playerGUID)
5324 CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_TALENTS), GUID_LOPART(playerGUID) );
5325 std::string nameLink = playerLink(pName);
5326 PSendSysMessage(LANG_RESET_TALENTS_OFFLINE,nameLink.c_str());
5327 return true;
5329 // Try reset talenents as Hunter Pet
5330 Creature* creature = getSelectedCreature();
5331 if (creature && creature->isPet() && ((Pet *)creature)->getPetType() == HUNTER_PET)
5333 ((Pet *)creature)->resetTalents(true);
5334 Unit *owner = creature->GetOwner();
5335 if (owner && owner->GetTypeId() == TYPEID_PLAYER)
5337 player = (Player *)owner;
5338 ChatHandler(player).SendSysMessage(LANG_RESET_PET_TALENTS);
5339 if(m_session->GetPlayer()!=player)
5340 PSendSysMessage(LANG_RESET_PET_TALENTS_ONLINE,GetNameLink(player).c_str());
5342 return true;
5345 SendSysMessage(LANG_NO_CHAR_SELECTED);
5346 SetSentErrorMessage(true);
5347 return false;
5350 bool ChatHandler::HandleResetAllCommand(const char * args)
5352 if(!*args)
5353 return false;
5355 std::string casename = args;
5357 AtLoginFlags atLogin;
5359 // Command specially created as single command to prevent using short case names
5360 if(casename=="spells")
5362 atLogin = AT_LOGIN_RESET_SPELLS;
5363 sWorld.SendWorldText(LANG_RESETALL_SPELLS);
5365 else if(casename=="talents")
5367 atLogin = AT_LOGIN_RESET_TALENTS;
5368 sWorld.SendWorldText(LANG_RESETALL_TALENTS);
5370 else
5372 PSendSysMessage(LANG_RESETALL_UNKNOWN_CASE,args);
5373 SetSentErrorMessage(true);
5374 return false;
5377 CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE (at_login & '%u') = '0'",atLogin,atLogin);
5378 HashMapHolder<Player>::MapType const& plist = ObjectAccessor::Instance().GetPlayers();
5379 for(HashMapHolder<Player>::MapType::const_iterator itr = plist.begin(); itr != plist.end(); ++itr)
5380 itr->second->SetAtLoginFlag(atLogin);
5382 return true;
5385 bool ChatHandler::HandleServerShutDownCancelCommand(const char* args)
5387 sWorld.ShutdownCancel();
5388 return true;
5391 bool ChatHandler::HandleServerShutDownCommand(const char* args)
5393 if(!*args)
5394 return false;
5396 char* time_str = strtok ((char*) args, " ");
5397 char* exitcode_str = strtok (NULL, "");
5399 int32 time = atoi (time_str);
5401 ///- Prevent interpret wrong arg value as 0 secs shutdown time
5402 if(time == 0 && (time_str[0]!='0' || time_str[1]!='\0') || time < 0)
5403 return false;
5405 if (exitcode_str)
5407 int32 exitcode = atoi (exitcode_str);
5409 // Handle atoi() errors
5410 if (exitcode == 0 && (exitcode_str[0] != '0' || exitcode_str[1] != '\0'))
5411 return false;
5413 // Exit code should be in range of 0-125, 126-255 is used
5414 // in many shells for their own return codes and code > 255
5415 // is not supported in many others
5416 if (exitcode < 0 || exitcode > 125)
5417 return false;
5419 sWorld.ShutdownServ (time, 0, exitcode);
5421 else
5422 sWorld.ShutdownServ(time,0,SHUTDOWN_EXIT_CODE);
5423 return true;
5426 bool ChatHandler::HandleServerRestartCommand(const char* args)
5428 if(!*args)
5429 return false;
5431 char* time_str = strtok ((char*) args, " ");
5432 char* exitcode_str = strtok (NULL, "");
5434 int32 time = atoi (time_str);
5436 ///- Prevent interpret wrong arg value as 0 secs shutdown time
5437 if(time == 0 && (time_str[0]!='0' || time_str[1]!='\0') || time < 0)
5438 return false;
5440 if (exitcode_str)
5442 int32 exitcode = atoi (exitcode_str);
5444 // Handle atoi() errors
5445 if (exitcode == 0 && (exitcode_str[0] != '0' || exitcode_str[1] != '\0'))
5446 return false;
5448 // Exit code should be in range of 0-125, 126-255 is used
5449 // in many shells for their own return codes and code > 255
5450 // is not supported in many others
5451 if (exitcode < 0 || exitcode > 125)
5452 return false;
5454 sWorld.ShutdownServ (time, SHUTDOWN_MASK_RESTART, exitcode);
5456 else
5457 sWorld.ShutdownServ(time, SHUTDOWN_MASK_RESTART, RESTART_EXIT_CODE);
5458 return true;
5461 bool ChatHandler::HandleServerIdleRestartCommand(const char* args)
5463 if(!*args)
5464 return false;
5466 char* time_str = strtok ((char*) args, " ");
5467 char* exitcode_str = strtok (NULL, "");
5469 int32 time = atoi (time_str);
5471 ///- Prevent interpret wrong arg value as 0 secs shutdown time
5472 if(time == 0 && (time_str[0]!='0' || time_str[1]!='\0') || time < 0)
5473 return false;
5475 if (exitcode_str)
5477 int32 exitcode = atoi (exitcode_str);
5479 // Handle atoi() errors
5480 if (exitcode == 0 && (exitcode_str[0] != '0' || exitcode_str[1] != '\0'))
5481 return false;
5483 // Exit code should be in range of 0-125, 126-255 is used
5484 // in many shells for their own return codes and code > 255
5485 // is not supported in many others
5486 if (exitcode < 0 || exitcode > 125)
5487 return false;
5489 sWorld.ShutdownServ (time, SHUTDOWN_MASK_RESTART|SHUTDOWN_MASK_IDLE, exitcode);
5491 else
5492 sWorld.ShutdownServ(time,SHUTDOWN_MASK_RESTART|SHUTDOWN_MASK_IDLE,RESTART_EXIT_CODE);
5493 return true;
5496 bool ChatHandler::HandleServerIdleShutDownCommand(const char* args)
5498 if(!*args)
5499 return false;
5501 char* time_str = strtok ((char*) args, " ");
5502 char* exitcode_str = strtok (NULL, "");
5504 int32 time = atoi (time_str);
5506 ///- Prevent interpret wrong arg value as 0 secs shutdown time
5507 if(time == 0 && (time_str[0]!='0' || time_str[1]!='\0') || time < 0)
5508 return false;
5510 if (exitcode_str)
5512 int32 exitcode = atoi (exitcode_str);
5514 // Handle atoi() errors
5515 if (exitcode == 0 && (exitcode_str[0] != '0' || exitcode_str[1] != '\0'))
5516 return false;
5518 // Exit code should be in range of 0-125, 126-255 is used
5519 // in many shells for their own return codes and code > 255
5520 // is not supported in many others
5521 if (exitcode < 0 || exitcode > 125)
5522 return false;
5524 sWorld.ShutdownServ (time, SHUTDOWN_MASK_IDLE, exitcode);
5526 else
5527 sWorld.ShutdownServ(time,SHUTDOWN_MASK_IDLE,SHUTDOWN_EXIT_CODE);
5528 return true;
5531 bool ChatHandler::HandleQuestAdd(const char* args)
5533 Player* player = getSelectedPlayer();
5534 if(!player)
5536 SendSysMessage(LANG_NO_CHAR_SELECTED);
5537 SetSentErrorMessage(true);
5538 return false;
5541 // .addquest #entry'
5542 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
5543 char* cId = extractKeyFromLink((char*)args,"Hquest");
5544 if(!cId)
5545 return false;
5547 uint32 entry = atol(cId);
5549 Quest const* pQuest = objmgr.GetQuestTemplate(entry);
5551 if(!pQuest)
5553 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND,entry);
5554 SetSentErrorMessage(true);
5555 return false;
5558 // check item starting quest (it can work incorrectly if added without item in inventory)
5559 for (uint32 id = 0; id < sItemStorage.MaxEntry; id++)
5561 ItemPrototype const *pProto = sItemStorage.LookupEntry<ItemPrototype>(id);
5562 if (!pProto)
5563 continue;
5565 if (pProto->StartQuest == entry)
5567 PSendSysMessage(LANG_COMMAND_QUEST_STARTFROMITEM, entry, pProto->ItemId);
5568 SetSentErrorMessage(true);
5569 return false;
5573 // ok, normal (creature/GO starting) quest
5574 if( player->CanAddQuest( pQuest, true ) )
5576 player->AddQuest( pQuest, NULL );
5578 if ( player->CanCompleteQuest( entry ) )
5579 player->CompleteQuest( entry );
5582 return true;
5585 bool ChatHandler::HandleQuestRemove(const char* args)
5587 Player* player = getSelectedPlayer();
5588 if(!player)
5590 SendSysMessage(LANG_NO_CHAR_SELECTED);
5591 SetSentErrorMessage(true);
5592 return false;
5595 // .removequest #entry'
5596 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
5597 char* cId = extractKeyFromLink((char*)args,"Hquest");
5598 if(!cId)
5599 return false;
5601 uint32 entry = atol(cId);
5603 Quest const* pQuest = objmgr.GetQuestTemplate(entry);
5605 if(!pQuest)
5607 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, entry);
5608 SetSentErrorMessage(true);
5609 return false;
5612 // remove all quest entries for 'entry' from quest log
5613 for(uint8 slot = 0; slot < MAX_QUEST_LOG_SIZE; ++slot )
5615 uint32 quest = player->GetQuestSlotQuestId(slot);
5616 if(quest==entry)
5618 player->SetQuestSlot(slot,0);
5620 // we ignore unequippable quest items in this case, its' still be equipped
5621 player->TakeQuestSourceItem( quest, false );
5625 // set quest status to not started (will updated in DB at next save)
5626 player->SetQuestStatus( entry, QUEST_STATUS_NONE);
5628 // reset rewarded for restart repeatable quest
5629 player->getQuestStatusMap()[entry].m_rewarded = false;
5631 SendSysMessage(LANG_COMMAND_QUEST_REMOVED);
5632 return true;
5635 bool ChatHandler::HandleQuestComplete(const char* args)
5637 Player* player = getSelectedPlayer();
5638 if(!player)
5640 SendSysMessage(LANG_NO_CHAR_SELECTED);
5641 SetSentErrorMessage(true);
5642 return false;
5645 // .quest complete #entry
5646 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
5647 char* cId = extractKeyFromLink((char*)args,"Hquest");
5648 if(!cId)
5649 return false;
5651 uint32 entry = atol(cId);
5653 Quest const* pQuest = objmgr.GetQuestTemplate(entry);
5655 // If player doesn't have the quest
5656 if(!pQuest || player->GetQuestStatus(entry) == QUEST_STATUS_NONE)
5658 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, entry);
5659 SetSentErrorMessage(true);
5660 return false;
5663 // Add quest items for quests that require items
5664 for(uint8 x = 0; x < QUEST_OBJECTIVES_COUNT; ++x)
5666 uint32 id = pQuest->ReqItemId[x];
5667 uint32 count = pQuest->ReqItemCount[x];
5668 if(!id || !count)
5669 continue;
5671 uint32 curItemCount = player->GetItemCount(id,true);
5673 ItemPosCountVec dest;
5674 uint8 msg = player->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, id, count-curItemCount );
5675 if( msg == EQUIP_ERR_OK )
5677 Item* item = player->StoreNewItem( dest, id, true);
5678 player->SendNewItem(item,count-curItemCount,true,false);
5682 // All creature/GO slain/casted (not required, but otherwise it will display "Creature slain 0/10")
5683 for(uint8 i = 0; i < QUEST_OBJECTIVES_COUNT; ++i)
5685 uint32 creature = pQuest->ReqCreatureOrGOId[i];
5686 uint32 creaturecount = pQuest->ReqCreatureOrGOCount[i];
5688 if(uint32 spell_id = pQuest->ReqSpell[i])
5690 for(uint16 z = 0; z < creaturecount; ++z)
5691 player->CastedCreatureOrGO(creature,0,spell_id);
5693 else if(creature > 0)
5695 for(uint16 z = 0; z < creaturecount; ++z)
5696 player->KilledMonster(creature,0);
5698 else if(creature < 0)
5700 for(uint16 z = 0; z < creaturecount; ++z)
5701 player->CastedCreatureOrGO(creature,0,0);
5705 // If the quest requires reputation to complete
5706 if(uint32 repFaction = pQuest->GetRepObjectiveFaction())
5708 uint32 repValue = pQuest->GetRepObjectiveValue();
5709 uint32 curRep = player->GetReputationMgr().GetReputation(repFaction);
5710 if(curRep < repValue)
5711 if(FactionEntry const *factionEntry = sFactionStore.LookupEntry(repFaction))
5712 player->GetReputationMgr().SetReputation(factionEntry,repValue);
5715 // If the quest requires money
5716 int32 ReqOrRewMoney = pQuest->GetRewOrReqMoney();
5717 if(ReqOrRewMoney < 0)
5718 player->ModifyMoney(-ReqOrRewMoney);
5720 player->CompleteQuest(entry);
5721 return true;
5724 bool ChatHandler::HandleBanAccountCommand(const char* args)
5726 return HandleBanHelper(BAN_ACCOUNT,args);
5729 bool ChatHandler::HandleBanCharacterCommand(const char* args)
5731 return HandleBanHelper(BAN_CHARACTER,args);
5734 bool ChatHandler::HandleBanIPCommand(const char* args)
5736 return HandleBanHelper(BAN_IP,args);
5739 bool ChatHandler::HandleBanHelper(BanMode mode, const char* args)
5741 if (!*args)
5742 return false;
5744 char* cnameOrIP = strtok ((char*)args, " ");
5745 if (!cnameOrIP)
5746 return false;
5748 std::string nameOrIP = cnameOrIP;
5750 char* duration = strtok (NULL," ");
5751 if(!duration || !atoi(duration))
5752 return false;
5754 char* reason = strtok (NULL,"");
5755 if(!reason)
5756 return false;
5758 switch(mode)
5760 case BAN_ACCOUNT:
5761 if(!AccountMgr::normilizeString(nameOrIP))
5763 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,nameOrIP.c_str());
5764 SetSentErrorMessage(true);
5765 return false;
5767 break;
5768 case BAN_CHARACTER:
5769 if(!normalizePlayerName(nameOrIP))
5771 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5772 SetSentErrorMessage(true);
5773 return false;
5775 break;
5776 case BAN_IP:
5777 if(!IsIPAddress(nameOrIP.c_str()))
5778 return false;
5779 break;
5782 switch(sWorld.BanAccount(mode, nameOrIP, duration, reason,m_session ? m_session->GetPlayerName() : ""))
5784 case BAN_SUCCESS:
5785 if(atoi(duration)>0)
5786 PSendSysMessage(LANG_BAN_YOUBANNED,nameOrIP.c_str(),secsToTimeString(TimeStringToSecs(duration),true).c_str(),reason);
5787 else
5788 PSendSysMessage(LANG_BAN_YOUPERMBANNED,nameOrIP.c_str(),reason);
5789 break;
5790 case BAN_SYNTAX_ERROR:
5791 return false;
5792 case BAN_NOTFOUND:
5793 switch(mode)
5795 default:
5796 PSendSysMessage(LANG_BAN_NOTFOUND,"account",nameOrIP.c_str());
5797 break;
5798 case BAN_CHARACTER:
5799 PSendSysMessage(LANG_BAN_NOTFOUND,"character",nameOrIP.c_str());
5800 break;
5801 case BAN_IP:
5802 PSendSysMessage(LANG_BAN_NOTFOUND,"ip",nameOrIP.c_str());
5803 break;
5805 SetSentErrorMessage(true);
5806 return false;
5809 return true;
5812 bool ChatHandler::HandleUnBanAccountCommand(const char* args)
5814 return HandleUnBanHelper(BAN_ACCOUNT,args);
5817 bool ChatHandler::HandleUnBanCharacterCommand(const char* args)
5819 return HandleUnBanHelper(BAN_CHARACTER,args);
5822 bool ChatHandler::HandleUnBanIPCommand(const char* args)
5824 return HandleUnBanHelper(BAN_IP,args);
5827 bool ChatHandler::HandleUnBanHelper(BanMode mode, const char* args)
5829 if (!*args)
5830 return false;
5832 char* cnameOrIP = strtok ((char*)args, " ");
5833 if(!cnameOrIP)
5834 return false;
5836 std::string nameOrIP = cnameOrIP;
5838 switch(mode)
5840 case BAN_ACCOUNT:
5841 if(!AccountMgr::normilizeString(nameOrIP))
5843 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,nameOrIP.c_str());
5844 SetSentErrorMessage(true);
5845 return false;
5847 break;
5848 case BAN_CHARACTER:
5849 if(!normalizePlayerName(nameOrIP))
5851 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5852 SetSentErrorMessage(true);
5853 return false;
5855 break;
5856 case BAN_IP:
5857 if(!IsIPAddress(nameOrIP.c_str()))
5858 return false;
5859 break;
5862 if(sWorld.RemoveBanAccount(mode,nameOrIP))
5863 PSendSysMessage(LANG_UNBAN_UNBANNED,nameOrIP.c_str());
5864 else
5865 PSendSysMessage(LANG_UNBAN_ERROR,nameOrIP.c_str());
5867 return true;
5870 bool ChatHandler::HandleBanInfoAccountCommand(const char* args)
5872 if (!*args)
5873 return false;
5875 char* cname = strtok((char*)args, "");
5876 if(!cname)
5877 return false;
5879 std::string account_name = cname;
5880 if(!AccountMgr::normilizeString(account_name))
5882 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5883 SetSentErrorMessage(true);
5884 return false;
5887 uint32 accountid = accmgr.GetId(account_name);
5888 if(!accountid)
5890 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5891 return true;
5894 return HandleBanInfoHelper(accountid,account_name.c_str());
5897 bool ChatHandler::HandleBanInfoCharacterCommand(const char* args)
5899 if (!*args)
5900 return false;
5902 std::string name = extractPlayerNameFromLink((char*)args);
5903 if(name.empty())
5905 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5906 SetSentErrorMessage(true);
5907 return false;
5910 uint32 accountid = objmgr.GetPlayerAccountIdByPlayerName(name);
5911 if(!accountid)
5913 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5914 SetSentErrorMessage(true);
5915 return false;
5918 std::string accountname;
5919 if(!accmgr.GetName(accountid,accountname))
5921 PSendSysMessage(LANG_BANINFO_NOCHARACTER);
5922 return true;
5925 return HandleBanInfoHelper(accountid,accountname.c_str());
5928 bool ChatHandler::HandleBanInfoHelper(uint32 accountid, char const* accountname)
5930 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);
5931 if(!result)
5933 PSendSysMessage(LANG_BANINFO_NOACCOUNTBAN, accountname);
5934 return true;
5937 PSendSysMessage(LANG_BANINFO_BANHISTORY,accountname);
5940 Field* fields = result->Fetch();
5942 time_t unbandate = time_t(fields[3].GetUInt64());
5943 bool active = false;
5944 if(fields[2].GetBool() && (fields[1].GetUInt64() == (uint64)0 ||unbandate >= time(NULL)) )
5945 active = true;
5946 bool permanent = (fields[1].GetUInt64() == (uint64)0);
5947 std::string bantime = permanent?GetMangosString(LANG_BANINFO_INFINITE):secsToTimeString(fields[1].GetUInt64(), true);
5948 PSendSysMessage(LANG_BANINFO_HISTORYENTRY,
5949 fields[0].GetString(), bantime.c_str(), active ? GetMangosString(LANG_BANINFO_YES):GetMangosString(LANG_BANINFO_NO), fields[4].GetString(), fields[5].GetString());
5950 }while (result->NextRow());
5952 delete result;
5953 return true;
5956 bool ChatHandler::HandleBanInfoIPCommand(const char* args)
5958 if (!*args)
5959 return false;
5961 char* cIP = strtok ((char*)args, "");
5962 if(!cIP)
5963 return false;
5965 if (!IsIPAddress(cIP))
5966 return false;
5968 std::string IP = cIP;
5970 loginDatabase.escape_string(IP);
5971 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());
5972 if(!result)
5974 PSendSysMessage(LANG_BANINFO_NOIP);
5975 return true;
5978 Field *fields = result->Fetch();
5979 bool permanent = !fields[6].GetUInt64();
5980 PSendSysMessage(LANG_BANINFO_IPENTRY,
5981 fields[0].GetString(), fields[1].GetString(), permanent ? GetMangosString(LANG_BANINFO_NEVER):fields[2].GetString(),
5982 permanent ? GetMangosString(LANG_BANINFO_INFINITE):secsToTimeString(fields[3].GetUInt64(), true).c_str(), fields[4].GetString(), fields[5].GetString());
5983 delete result;
5984 return true;
5987 bool ChatHandler::HandleBanListCharacterCommand(const char* args)
5989 loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5991 char* cFilter = strtok ((char*)args, " ");
5992 if(!cFilter)
5993 return false;
5995 std::string filter = cFilter;
5996 loginDatabase.escape_string(filter);
5997 QueryResult* result = CharacterDatabase.PQuery("SELECT account FROM characters WHERE name "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'"),filter.c_str());
5998 if (!result)
6000 PSendSysMessage(LANG_BANLIST_NOCHARACTER);
6001 return true;
6004 return HandleBanListHelper(result);
6007 bool ChatHandler::HandleBanListAccountCommand(const char* args)
6009 loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
6011 char* cFilter = strtok((char*)args, " ");
6012 std::string filter = cFilter ? cFilter : "";
6013 loginDatabase.escape_string(filter);
6015 QueryResult* result;
6017 if(filter.empty())
6019 result = loginDatabase.Query("SELECT account.id, username FROM account, account_banned"
6020 " WHERE account.id = account_banned.id AND active = 1 GROUP BY account.id");
6022 else
6024 result = loginDatabase.PQuery("SELECT account.id, username FROM account, account_banned"
6025 " WHERE account.id = account_banned.id AND active = 1 AND username "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'")" GROUP BY account.id",
6026 filter.c_str());
6029 if (!result)
6031 PSendSysMessage(LANG_BANLIST_NOACCOUNT);
6032 return true;
6035 return HandleBanListHelper(result);
6038 bool ChatHandler::HandleBanListHelper(QueryResult* result)
6040 PSendSysMessage(LANG_BANLIST_MATCHINGACCOUNT);
6042 // Chat short output
6043 if(m_session)
6047 Field* fields = result->Fetch();
6048 uint32 accountid = fields[0].GetUInt32();
6050 QueryResult* banresult = loginDatabase.PQuery("SELECT account.username FROM account,account_banned WHERE account_banned.id='%u' AND account_banned.id=account.id",accountid);
6051 if(banresult)
6053 Field* fields2 = banresult->Fetch();
6054 PSendSysMessage("%s",fields2[0].GetString());
6055 delete banresult;
6057 } while (result->NextRow());
6059 // Console wide output
6060 else
6062 SendSysMessage(LANG_BANLIST_ACCOUNTS);
6063 SendSysMessage("===============================================================================");
6064 SendSysMessage(LANG_BANLIST_ACCOUNTS_HEADER);
6067 SendSysMessage("-------------------------------------------------------------------------------");
6068 Field *fields = result->Fetch();
6069 uint32 account_id = fields[0].GetUInt32 ();
6071 std::string account_name;
6073 // "account" case, name can be get in same query
6074 if(result->GetFieldCount() > 1)
6075 account_name = fields[1].GetCppString();
6076 // "character" case, name need extract from another DB
6077 else
6078 accmgr.GetName (account_id,account_name);
6080 // No SQL injection. id is uint32.
6081 QueryResult *banInfo = loginDatabase.PQuery("SELECT bandate,unbandate,bannedby,banreason FROM account_banned WHERE id = %u ORDER BY unbandate", account_id);
6082 if (banInfo)
6084 Field *fields2 = banInfo->Fetch();
6087 time_t t_ban = fields2[0].GetUInt64();
6088 tm* aTm_ban = localtime(&t_ban);
6090 if (fields2[0].GetUInt64() == fields2[1].GetUInt64())
6092 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
6093 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,
6094 fields2[2].GetString(),fields2[3].GetString());
6096 else
6098 time_t t_unban = fields2[1].GetUInt64();
6099 tm* aTm_unban = localtime(&t_unban);
6100 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
6101 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,
6102 aTm_unban->tm_year%100, aTm_unban->tm_mon+1, aTm_unban->tm_mday, aTm_unban->tm_hour, aTm_unban->tm_min,
6103 fields2[2].GetString(),fields2[3].GetString());
6105 }while ( banInfo->NextRow() );
6106 delete banInfo;
6108 }while( result->NextRow() );
6109 SendSysMessage("===============================================================================");
6112 delete result;
6113 return true;
6116 bool ChatHandler::HandleBanListIPCommand(const char* args)
6118 loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
6120 char* cFilter = strtok((char*)args, " ");
6121 std::string filter = cFilter ? cFilter : "";
6122 loginDatabase.escape_string(filter);
6124 QueryResult* result;
6126 if(filter.empty())
6128 result = loginDatabase.Query ("SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
6129 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP())"
6130 " ORDER BY unbandate" );
6132 else
6134 result = loginDatabase.PQuery( "SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
6135 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP()) AND ip "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'")
6136 " ORDER BY unbandate",filter.c_str() );
6139 if(!result)
6141 PSendSysMessage(LANG_BANLIST_NOIP);
6142 return true;
6145 PSendSysMessage(LANG_BANLIST_MATCHINGIP);
6146 // Chat short output
6147 if(m_session)
6151 Field* fields = result->Fetch();
6152 PSendSysMessage("%s",fields[0].GetString());
6153 } while (result->NextRow());
6155 // Console wide output
6156 else
6158 SendSysMessage(LANG_BANLIST_IPS);
6159 SendSysMessage("===============================================================================");
6160 SendSysMessage(LANG_BANLIST_IPS_HEADER);
6163 SendSysMessage("-------------------------------------------------------------------------------");
6164 Field *fields = result->Fetch();
6165 time_t t_ban = fields[1].GetUInt64();
6166 tm* aTm_ban = localtime(&t_ban);
6167 if ( fields[1].GetUInt64() == fields[2].GetUInt64() )
6169 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
6170 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,
6171 fields[3].GetString(), fields[4].GetString());
6173 else
6175 time_t t_unban = fields[2].GetUInt64();
6176 tm* aTm_unban = localtime(&t_unban);
6177 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
6178 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,
6179 aTm_unban->tm_year%100, aTm_unban->tm_mon+1, aTm_unban->tm_mday, aTm_unban->tm_hour, aTm_unban->tm_min,
6180 fields[3].GetString(), fields[4].GetString());
6182 }while( result->NextRow() );
6183 SendSysMessage("===============================================================================");
6186 delete result;
6187 return true;
6190 bool ChatHandler::HandleRespawnCommand(const char* /*args*/)
6192 Player* pl = m_session->GetPlayer();
6194 // accept only explicitly selected target (not implicitly self targeting case)
6195 Unit* target = getSelectedUnit();
6196 if(pl->GetSelection() && target)
6198 if(target->GetTypeId()!=TYPEID_UNIT)
6200 SendSysMessage(LANG_SELECT_CREATURE);
6201 SetSentErrorMessage(true);
6202 return false;
6205 if(target->isDead())
6206 ((Creature*)target)->Respawn();
6207 return true;
6210 CellPair p(MaNGOS::ComputeCellPair(pl->GetPositionX(), pl->GetPositionY()));
6211 Cell cell(p);
6212 cell.data.Part.reserved = ALL_DISTRICT;
6213 cell.SetNoCreate();
6215 MaNGOS::RespawnDo u_do;
6216 MaNGOS::WorldObjectWorker<MaNGOS::RespawnDo> worker(pl,u_do);
6218 TypeContainerVisitor<MaNGOS::WorldObjectWorker<MaNGOS::RespawnDo>, GridTypeMapContainer > obj_worker(worker);
6219 CellLock<GridReadGuard> cell_lock(cell, p);
6220 cell_lock->Visit(cell_lock, obj_worker, *pl->GetMap());
6222 return true;
6225 bool ChatHandler::HandleGMFlyCommand(const char* args)
6227 if (!*args)
6228 return false;
6230 Player *target = getSelectedPlayer();
6231 if (!target)
6232 target = m_session->GetPlayer();
6234 WorldPacket data(12);
6235 if (strncmp(args, "on", 3) == 0)
6236 data.SetOpcode(SMSG_MOVE_SET_CAN_FLY);
6237 else if (strncmp(args, "off", 4) == 0)
6238 data.SetOpcode(SMSG_MOVE_UNSET_CAN_FLY);
6239 else
6241 SendSysMessage(LANG_USE_BOL);
6242 return false;
6244 data.append(target->GetPackGUID());
6245 data << uint32(0); // unknown
6246 target->SendMessageToSet(&data, true);
6247 PSendSysMessage(LANG_COMMAND_FLYMODE_STATUS, GetNameLink(target).c_str(), args);
6248 return true;
6251 bool ChatHandler::HandlePDumpLoadCommand(const char *args)
6253 if (!*args)
6254 return false;
6256 char * file = strtok((char*)args, " ");
6257 if(!file)
6258 return false;
6260 char * account = strtok(NULL, " ");
6261 if(!account)
6262 return false;
6264 std::string account_name = account;
6265 if(!AccountMgr::normilizeString(account_name))
6267 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
6268 SetSentErrorMessage(true);
6269 return false;
6272 uint32 account_id = accmgr.GetId(account_name);
6273 if(!account_id)
6275 account_id = atoi(account); // use original string
6276 if(!account_id)
6278 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
6279 SetSentErrorMessage(true);
6280 return false;
6284 if(!accmgr.GetName(account_id,account_name))
6286 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
6287 SetSentErrorMessage(true);
6288 return false;
6291 char* guid_str = NULL;
6292 char* name_str = strtok(NULL, " ");
6294 std::string name;
6295 if(name_str)
6297 name = name_str;
6298 // normalize the name if specified and check if it exists
6299 if(!normalizePlayerName(name))
6301 PSendSysMessage(LANG_INVALID_CHARACTER_NAME);
6302 SetSentErrorMessage(true);
6303 return false;
6306 if(!ObjectMgr::IsValidName(name,true))
6308 PSendSysMessage(LANG_INVALID_CHARACTER_NAME);
6309 SetSentErrorMessage(true);
6310 return false;
6313 guid_str = strtok(NULL, " ");
6316 uint32 guid = 0;
6318 if(guid_str)
6320 guid = atoi(guid_str);
6321 if(!guid)
6323 PSendSysMessage(LANG_INVALID_CHARACTER_GUID);
6324 SetSentErrorMessage(true);
6325 return false;
6328 if(objmgr.GetPlayerAccountIdByGUID(guid))
6330 PSendSysMessage(LANG_CHARACTER_GUID_IN_USE,guid);
6331 SetSentErrorMessage(true);
6332 return false;
6336 switch(PlayerDumpReader().LoadDump(file, account_id, name, guid))
6338 case DUMP_SUCCESS:
6339 PSendSysMessage(LANG_COMMAND_IMPORT_SUCCESS);
6340 break;
6341 case DUMP_FILE_OPEN_ERROR:
6342 PSendSysMessage(LANG_FILE_OPEN_FAIL,file);
6343 SetSentErrorMessage(true);
6344 return false;
6345 case DUMP_FILE_BROKEN:
6346 PSendSysMessage(LANG_DUMP_BROKEN,file);
6347 SetSentErrorMessage(true);
6348 return false;
6349 case DUMP_TOO_MANY_CHARS:
6350 PSendSysMessage(LANG_ACCOUNT_CHARACTER_LIST_FULL,account_name.c_str(),account_id);
6351 SetSentErrorMessage(true);
6352 return false;
6353 default:
6354 PSendSysMessage(LANG_COMMAND_IMPORT_FAILED);
6355 SetSentErrorMessage(true);
6356 return false;
6359 return true;
6362 bool ChatHandler::HandlePDumpWriteCommand(const char *args)
6364 if (!*args)
6365 return false;
6367 char* file = strtok((char*)args, " ");
6368 char* p2 = strtok(NULL, " ");
6370 if(!file || !p2)
6371 return false;
6373 uint32 guid;
6374 // character name can't start from number
6375 if (isNumeric(p2[0]))
6376 guid = atoi(p2);
6377 else
6379 std::string name = extractPlayerNameFromLink(p2);
6380 if(name.empty())
6382 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6383 SetSentErrorMessage(true);
6384 return false;
6387 guid = objmgr.GetPlayerGUIDByName(name);
6390 if(!objmgr.GetPlayerAccountIdByGUID(guid))
6392 PSendSysMessage(LANG_PLAYER_NOT_FOUND);
6393 SetSentErrorMessage(true);
6394 return false;
6397 switch(PlayerDumpWriter().WriteDump(file, guid))
6399 case DUMP_SUCCESS:
6400 PSendSysMessage(LANG_COMMAND_EXPORT_SUCCESS);
6401 break;
6402 case DUMP_FILE_OPEN_ERROR:
6403 PSendSysMessage(LANG_FILE_OPEN_FAIL,file);
6404 SetSentErrorMessage(true);
6405 return false;
6406 default:
6407 PSendSysMessage(LANG_COMMAND_EXPORT_FAILED);
6408 SetSentErrorMessage(true);
6409 return false;
6412 return true;
6415 bool ChatHandler::HandleMovegensCommand(const char* /*args*/)
6417 Unit* unit = getSelectedUnit();
6418 if(!unit)
6420 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
6421 SetSentErrorMessage(true);
6422 return false;
6425 PSendSysMessage(LANG_MOVEGENS_LIST,(unit->GetTypeId()==TYPEID_PLAYER ? "Player" : "Creature" ),unit->GetGUIDLow());
6427 MotionMaster* mm = unit->GetMotionMaster();
6428 for(MotionMaster::const_iterator itr = mm->begin(); itr != mm->end(); ++itr)
6430 switch((*itr)->GetMovementGeneratorType())
6432 case IDLE_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_IDLE); break;
6433 case RANDOM_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_RANDOM); break;
6434 case WAYPOINT_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_WAYPOINT); break;
6435 case ANIMAL_RANDOM_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_ANIMAL_RANDOM); break;
6436 case CONFUSED_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_CONFUSED); break;
6437 case TARGETED_MOTION_TYPE:
6439 if(unit->GetTypeId()==TYPEID_PLAYER)
6441 TargetedMovementGenerator<Player> const* mgen = static_cast<TargetedMovementGenerator<Player> const*>(*itr);
6442 Unit* target = mgen->GetTarget();
6443 if(target)
6444 PSendSysMessage(LANG_MOVEGENS_TARGETED_PLAYER,target->GetName(),target->GetGUIDLow());
6445 else
6446 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL);
6448 else
6450 TargetedMovementGenerator<Creature> const* mgen = static_cast<TargetedMovementGenerator<Creature> const*>(*itr);
6451 Unit* target = mgen->GetTarget();
6452 if(target)
6453 PSendSysMessage(LANG_MOVEGENS_TARGETED_CREATURE,target->GetName(),target->GetGUIDLow());
6454 else
6455 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL);
6457 break;
6459 case HOME_MOTION_TYPE:
6460 if(unit->GetTypeId()==TYPEID_UNIT)
6462 float x,y,z;
6463 (*itr)->GetDestination(x,y,z);
6464 PSendSysMessage(LANG_MOVEGENS_HOME_CREATURE,x,y,z);
6466 else
6467 SendSysMessage(LANG_MOVEGENS_HOME_PLAYER);
6468 break;
6469 case FLIGHT_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_FLIGHT); break;
6470 case POINT_MOTION_TYPE:
6472 float x,y,z;
6473 (*itr)->GetDestination(x,y,z);
6474 PSendSysMessage(LANG_MOVEGENS_POINT,x,y,z);
6475 break;
6477 case FLEEING_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_FEAR); break;
6478 case DISTRACT_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_DISTRACT); break;
6479 default:
6480 PSendSysMessage(LANG_MOVEGENS_UNKNOWN,(*itr)->GetMovementGeneratorType());
6481 break;
6484 return true;
6487 bool ChatHandler::HandleServerPLimitCommand(const char *args)
6489 if(*args)
6491 char* param = strtok((char*)args, " ");
6492 if(!param)
6493 return false;
6495 int l = strlen(param);
6497 if( strncmp(param,"player",l) == 0 )
6498 sWorld.SetPlayerLimit(-SEC_PLAYER);
6499 else if(strncmp(param,"moderator",l) == 0 )
6500 sWorld.SetPlayerLimit(-SEC_MODERATOR);
6501 else if(strncmp(param,"gamemaster",l) == 0 )
6502 sWorld.SetPlayerLimit(-SEC_GAMEMASTER);
6503 else if(strncmp(param,"administrator",l) == 0 )
6504 sWorld.SetPlayerLimit(-SEC_ADMINISTRATOR);
6505 else if(strncmp(param,"reset",l) == 0 )
6506 sWorld.SetPlayerLimit( sConfig.GetIntDefault("PlayerLimit", DEFAULT_PLAYER_LIMIT) );
6507 else
6509 int val = atoi(param);
6510 if(val < -SEC_ADMINISTRATOR) val = -SEC_ADMINISTRATOR;
6512 sWorld.SetPlayerLimit(val);
6515 // kick all low security level players
6516 if(sWorld.GetPlayerAmountLimit() > SEC_PLAYER)
6517 sWorld.KickAllLess(sWorld.GetPlayerSecurityLimit());
6520 uint32 pLimit = sWorld.GetPlayerAmountLimit();
6521 AccountTypes allowedAccountType = sWorld.GetPlayerSecurityLimit();
6522 char const* secName = "";
6523 switch(allowedAccountType)
6525 case SEC_PLAYER: secName = "Player"; break;
6526 case SEC_MODERATOR: secName = "Moderator"; break;
6527 case SEC_GAMEMASTER: secName = "Gamemaster"; break;
6528 case SEC_ADMINISTRATOR: secName = "Administrator"; break;
6529 default: secName = "<unknown>"; break;
6532 PSendSysMessage("Player limits: amount %u, min. security level %s.",pLimit,secName);
6534 return true;
6537 bool ChatHandler::HandleCastCommand(const char* args)
6539 if(!*args)
6540 return false;
6542 Unit* target = getSelectedUnit();
6544 if(!target)
6546 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
6547 SetSentErrorMessage(true);
6548 return false;
6551 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
6552 uint32 spell = extractSpellIdFromLink((char*)args);
6553 if(!spell)
6554 return false;
6556 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
6557 if(!spellInfo)
6558 return false;
6560 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
6562 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
6563 SetSentErrorMessage(true);
6564 return false;
6567 char* trig_str = strtok(NULL, " ");
6568 if(trig_str)
6570 int l = strlen(trig_str);
6571 if(strncmp(trig_str,"triggered",l) != 0 )
6572 return false;
6575 bool triggered = (trig_str != NULL);
6577 m_session->GetPlayer()->CastSpell(target,spell,triggered);
6579 return true;
6582 bool ChatHandler::HandleCastBackCommand(const char* args)
6584 Creature* caster = getSelectedCreature();
6586 if(!caster)
6588 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
6589 SetSentErrorMessage(true);
6590 return false;
6593 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
6594 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
6595 uint32 spell = extractSpellIdFromLink((char*)args);
6596 if(!spell || !sSpellStore.LookupEntry(spell))
6597 return false;
6599 char* trig_str = strtok(NULL, " ");
6600 if(trig_str)
6602 int l = strlen(trig_str);
6603 if(strncmp(trig_str,"triggered",l) != 0 )
6604 return false;
6607 bool triggered = (trig_str != NULL);
6609 // update orientation at server
6610 caster->SetOrientation(caster->GetAngle(m_session->GetPlayer()));
6612 // and client
6613 WorldPacket data;
6614 caster->BuildHeartBeatMsg(&data);
6615 caster->SendMessageToSet(&data,true);
6617 caster->CastSpell(m_session->GetPlayer(),spell,triggered);
6619 return true;
6622 bool ChatHandler::HandleCastDistCommand(const char* args)
6624 if(!*args)
6625 return false;
6627 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
6628 uint32 spell = extractSpellIdFromLink((char*)args);
6629 if(!spell)
6630 return false;
6632 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
6633 if(!spellInfo)
6634 return false;
6636 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
6638 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
6639 SetSentErrorMessage(true);
6640 return false;
6643 char *distStr = strtok(NULL, " ");
6645 float dist = 0;
6647 if(distStr)
6648 sscanf(distStr, "%f", &dist);
6650 char* trig_str = strtok(NULL, " ");
6651 if(trig_str)
6653 int l = strlen(trig_str);
6654 if(strncmp(trig_str,"triggered",l) != 0 )
6655 return false;
6658 bool triggered = (trig_str != NULL);
6660 float x,y,z;
6661 m_session->GetPlayer()->GetClosePoint(x,y,z,dist);
6663 m_session->GetPlayer()->CastSpell(x,y,z,spell,triggered);
6664 return true;
6667 bool ChatHandler::HandleCastTargetCommand(const char* args)
6669 Creature* caster = getSelectedCreature();
6671 if(!caster)
6673 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
6674 SetSentErrorMessage(true);
6675 return false;
6678 if(!caster->getVictim())
6680 SendSysMessage(LANG_SELECTED_TARGET_NOT_HAVE_VICTIM);
6681 SetSentErrorMessage(true);
6682 return false;
6685 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
6686 uint32 spell = extractSpellIdFromLink((char*)args);
6687 if(!spell || !sSpellStore.LookupEntry(spell))
6688 return false;
6690 char* trig_str = strtok(NULL, " ");
6691 if(trig_str)
6693 int l = strlen(trig_str);
6694 if(strncmp(trig_str,"triggered",l) != 0 )
6695 return false;
6698 bool triggered = (trig_str != NULL);
6700 // update orientation at server
6701 caster->SetOrientation(caster->GetAngle(m_session->GetPlayer()));
6703 // and client
6704 WorldPacket data;
6705 caster->BuildHeartBeatMsg(&data);
6706 caster->SendMessageToSet(&data,true);
6708 caster->CastSpell(caster->getVictim(),spell,triggered);
6710 return true;
6714 ComeToMe command REQUIRED for 3rd party scripting library to have access to PointMovementGenerator
6715 Without this function 3rd party scripting library will get linking errors (unresolved external)
6716 when attempting to use the PointMovementGenerator
6718 bool ChatHandler::HandleComeToMeCommand(const char *args)
6720 Creature* caster = getSelectedCreature();
6722 if(!caster)
6724 SendSysMessage(LANG_SELECT_CREATURE);
6725 SetSentErrorMessage(true);
6726 return false;
6729 char* newFlagStr = strtok((char*)args, " ");
6731 if(!newFlagStr)
6732 return false;
6734 uint32 newFlags = atoi(newFlagStr);
6736 caster->SetUnitMovementFlags(newFlags);
6738 Player* pl = m_session->GetPlayer();
6740 caster->GetMotionMaster()->MovePoint(0, pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ());
6741 return true;
6744 bool ChatHandler::HandleCastSelfCommand(const char* args)
6746 if(!*args)
6747 return false;
6749 Unit* target = getSelectedUnit();
6751 if(!target)
6753 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
6754 SetSentErrorMessage(true);
6755 return false;
6758 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
6759 uint32 spell = extractSpellIdFromLink((char*)args);
6760 if(!spell)
6761 return false;
6763 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
6764 if(!spellInfo)
6765 return false;
6767 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
6769 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
6770 SetSentErrorMessage(true);
6771 return false;
6774 target->CastSpell(target,spell,false);
6776 return true;
6779 std::string GetTimeString(uint32 time)
6781 uint16 days = time / DAY, hours = (time % DAY) / HOUR, minute = (time % HOUR) / MINUTE;
6782 std::ostringstream ss;
6783 if(days) ss << days << "d ";
6784 if(hours) ss << hours << "h ";
6785 ss << minute << "m";
6786 return ss.str();
6789 bool ChatHandler::HandleInstanceListBindsCommand(const char* /*args*/)
6791 Player* player = getSelectedPlayer();
6792 if (!player) player = m_session->GetPlayer();
6793 uint32 counter = 0;
6794 for(uint8 i = 0; i < TOTAL_DIFFICULTIES; ++i)
6796 Player::BoundInstancesMap &binds = player->GetBoundInstances(i);
6797 for(Player::BoundInstancesMap::const_iterator itr = binds.begin(); itr != binds.end(); ++itr)
6799 InstanceSave *save = itr->second.save;
6800 std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
6801 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());
6802 counter++;
6805 PSendSysMessage("player binds: %d", counter);
6806 counter = 0;
6807 Group *group = player->GetGroup();
6808 if(group)
6810 for(uint8 i = 0; i < TOTAL_DIFFICULTIES; ++i)
6812 Group::BoundInstancesMap &binds = group->GetBoundInstances(i);
6813 for(Group::BoundInstancesMap::const_iterator itr = binds.begin(); itr != binds.end(); ++itr)
6815 InstanceSave *save = itr->second.save;
6816 std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
6817 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());
6818 counter++;
6822 PSendSysMessage("group binds: %d", counter);
6824 return true;
6827 bool ChatHandler::HandleInstanceUnbindCommand(const char* args)
6829 if(!*args)
6830 return false;
6832 std::string cmd = args;
6833 if(cmd == "all")
6835 Player* player = getSelectedPlayer();
6836 if (!player) player = m_session->GetPlayer();
6837 uint32 counter = 0;
6838 for(uint8 i = 0; i < TOTAL_DIFFICULTIES; ++i)
6840 Player::BoundInstancesMap &binds = player->GetBoundInstances(i);
6841 for(Player::BoundInstancesMap::iterator itr = binds.begin(); itr != binds.end();)
6843 if(itr->first != player->GetMapId())
6845 InstanceSave *save = itr->second.save;
6846 std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
6847 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());
6848 player->UnbindInstance(itr, i);
6849 counter++;
6851 else
6852 ++itr;
6855 PSendSysMessage("instances unbound: %d", counter);
6857 return true;
6860 bool ChatHandler::HandleInstanceStatsCommand(const char* /*args*/)
6862 PSendSysMessage("instances loaded: %d", MapManager::Instance().GetNumInstances());
6863 PSendSysMessage("players in instances: %d", MapManager::Instance().GetNumPlayersInInstances());
6864 PSendSysMessage("instance saves: %d", sInstanceSaveManager.GetNumInstanceSaves());
6865 PSendSysMessage("players bound: %d", sInstanceSaveManager.GetNumBoundPlayersTotal());
6866 PSendSysMessage("groups bound: %d", sInstanceSaveManager.GetNumBoundGroupsTotal());
6867 return true;
6870 bool ChatHandler::HandleInstanceSaveDataCommand(const char * /*args*/)
6872 Player* pl = m_session->GetPlayer();
6874 Map* map = pl->GetMap();
6875 if (!map->IsDungeon())
6877 PSendSysMessage("Map is not a dungeon.");
6878 SetSentErrorMessage(true);
6879 return false;
6882 if (!((InstanceMap*)map)->GetInstanceData())
6884 PSendSysMessage("Map has no instance data.");
6885 SetSentErrorMessage(true);
6886 return false;
6889 ((InstanceMap*)map)->GetInstanceData()->SaveToDB();
6890 return true;
6893 /// Display the list of GMs
6894 bool ChatHandler::HandleGMListFullCommand(const char* /*args*/)
6896 ///- Get the accounts with GM Level >0
6897 QueryResult *result = loginDatabase.Query( "SELECT username,gmlevel FROM account WHERE gmlevel > 0" );
6898 if(result)
6900 SendSysMessage(LANG_GMLIST);
6901 SendSysMessage("========================");
6902 SendSysMessage(LANG_GMLIST_HEADER);
6903 SendSysMessage("========================");
6905 ///- Circle through them. Display username and GM level
6908 Field *fields = result->Fetch();
6909 PSendSysMessage("|%15s|%6s|", fields[0].GetString(),fields[1].GetString());
6910 }while( result->NextRow() );
6912 PSendSysMessage("========================");
6913 delete result;
6915 else
6916 PSendSysMessage(LANG_GMLIST_EMPTY);
6917 return true;
6920 /// Define the 'Message of the day' for the realm
6921 bool ChatHandler::HandleServerSetMotdCommand(const char* args)
6923 sWorld.SetMotd(args);
6924 PSendSysMessage(LANG_MOTD_NEW, args);
6925 return true;
6928 /// Set/Unset the expansion level for an account
6929 bool ChatHandler::HandleAccountSetAddonCommand(const char* args)
6931 ///- Get the command line arguments
6932 char *szAcc = strtok((char*)args," ");
6933 char *szExp = strtok(NULL," ");
6935 if(!szAcc)
6936 return false;
6938 std::string account_name;
6939 uint32 account_id;
6941 if(!szExp)
6943 Player* player = getSelectedPlayer();
6944 if(!player)
6945 return false;
6947 account_id = player->GetSession()->GetAccountId();
6948 accmgr.GetName(account_id,account_name);
6949 szExp = szAcc;
6951 else
6953 ///- Convert Account name to Upper Format
6954 account_name = szAcc;
6955 if(!AccountMgr::normilizeString(account_name))
6957 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
6958 SetSentErrorMessage(true);
6959 return false;
6962 account_id = accmgr.GetId(account_name);
6963 if(!account_id)
6965 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
6966 SetSentErrorMessage(true);
6967 return false;
6972 // Let set addon state only for lesser (strong) security level
6973 // or to self account
6974 if (m_session && m_session->GetAccountId () != account_id &&
6975 HasLowerSecurityAccount (NULL,account_id,true))
6976 return false;
6978 int lev=atoi(szExp); //get int anyway (0 if error)
6979 if(lev < 0)
6980 return false;
6982 // No SQL injection
6983 loginDatabase.PExecute("UPDATE account SET expansion = '%d' WHERE id = '%u'",lev,account_id);
6984 PSendSysMessage(LANG_ACCOUNT_SETADDON,account_name.c_str(),account_id,lev);
6985 return true;
6988 //Send items by mail
6989 bool ChatHandler::HandleSendItemsCommand(const char* args)
6991 if(!*args)
6992 return false;
6994 // format: name "subject text" "mail text" item1[:count1] item2[:count2] ... item12[:count12]
6996 std::string name = extractPlayerNameFromLink((char*)args);
6997 if(name.empty())
6999 SendSysMessage(LANG_PLAYER_NOT_FOUND);
7000 SetSentErrorMessage(true);
7001 return false;
7004 char* tail1 = strtok(NULL, "");
7005 if(!tail1)
7006 return false;
7008 char* msgSubject;
7009 if(*tail1=='"')
7010 msgSubject = strtok(tail1+1, "\"");
7011 else
7013 char* space = strtok(tail1, "\"");
7014 if(!space)
7015 return false;
7016 msgSubject = strtok(NULL, "\"");
7019 if (!msgSubject)
7020 return false;
7022 char* tail2 = strtok(NULL, "");
7023 if(!tail2)
7024 return false;
7026 char* msgText;
7027 if(*tail2=='"')
7028 msgText = strtok(tail2+1, "\"");
7029 else
7031 char* space = strtok(tail2, "\"");
7032 if(!space)
7033 return false;
7034 msgText = strtok(NULL, "\"");
7037 if (!msgText)
7038 return false;
7040 // msgSubject, msgText isn't NUL after prev. check
7041 std::string subject = msgSubject;
7042 std::string text = msgText;
7044 // extract items
7045 typedef std::pair<uint32,uint32> ItemPair;
7046 typedef std::list< ItemPair > ItemPairs;
7047 ItemPairs items;
7049 // get all tail string
7050 char* tail = strtok(NULL, "");
7052 // get from tail next item str
7053 while(char* itemStr = strtok(tail, " "))
7055 // and get new tail
7056 tail = strtok(NULL, "");
7058 // parse item str
7059 char* itemIdStr = strtok(itemStr, ":");
7060 char* itemCountStr = strtok(NULL, " ");
7062 uint32 item_id = atoi(itemIdStr);
7063 if(!item_id)
7064 return false;
7066 ItemPrototype const* item_proto = objmgr.GetItemPrototype(item_id);
7067 if(!item_proto)
7069 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, item_id);
7070 SetSentErrorMessage(true);
7071 return false;
7074 uint32 item_count = itemCountStr ? atoi(itemCountStr) : 1;
7075 if(item_count < 1 || item_proto->MaxCount > 0 && item_count > uint32(item_proto->MaxCount))
7077 PSendSysMessage(LANG_COMMAND_INVALID_ITEM_COUNT, item_count,item_id);
7078 SetSentErrorMessage(true);
7079 return false;
7082 while(item_count > item_proto->GetMaxStackSize())
7084 items.push_back(ItemPair(item_id,item_proto->GetMaxStackSize()));
7085 item_count -= item_proto->GetMaxStackSize();
7088 items.push_back(ItemPair(item_id,item_count));
7090 if(items.size() > MAX_MAIL_ITEMS)
7092 PSendSysMessage(LANG_COMMAND_MAIL_ITEMS_LIMIT, MAX_MAIL_ITEMS);
7093 SetSentErrorMessage(true);
7094 return false;
7098 uint64 receiver_guid = objmgr.GetPlayerGUIDByName(name);
7099 if(!receiver_guid)
7101 SendSysMessage(LANG_PLAYER_NOT_FOUND);
7102 SetSentErrorMessage(true);
7103 return false;
7106 // from console show not existed sender
7107 uint32 sender_guidlo = m_session ? m_session->GetPlayer()->GetGUIDLow() : 0;
7109 uint32 messagetype = MAIL_NORMAL;
7110 uint32 stationery = MAIL_STATIONERY_GM;
7111 uint32 itemTextId = !text.empty() ? objmgr.CreateItemText( text ) : 0;
7113 Player *receiver = objmgr.GetPlayer(receiver_guid);
7115 // fill mail
7116 MailItemsInfo mi; // item list preparing
7118 for(ItemPairs::const_iterator itr = items.begin(); itr != items.end(); ++itr)
7120 if(Item* item = Item::CreateItem(itr->first,itr->second,m_session ? m_session->GetPlayer() : 0))
7122 item->SaveToDB(); // save for prevent lost at next mail load, if send fail then item will deleted
7123 mi.AddItem(item->GetGUIDLow(), item->GetEntry(), item);
7127 WorldSession::SendMailTo(receiver,messagetype, stationery, sender_guidlo, GUID_LOPART(receiver_guid), subject, itemTextId, &mi, 0, 0, MAIL_CHECK_MASK_NONE);
7129 std::string nameLink = playerLink(name);
7130 PSendSysMessage(LANG_MAIL_SENT, nameLink.c_str());
7131 return true;
7134 ///Send money by mail
7135 bool ChatHandler::HandleSendMoneyCommand(const char* args)
7137 if (!*args)
7138 return false;
7140 /// format: name "subject text" "mail text" money
7142 std::string name = extractPlayerNameFromLink((char*)args);
7143 if(name.empty())
7145 SendSysMessage(LANG_PLAYER_NOT_FOUND);
7146 SetSentErrorMessage(true);
7147 return false;
7150 char* tail1 = strtok(NULL, "");
7151 if (!tail1)
7152 return false;
7154 char* msgSubject;
7155 if (*tail1=='"')
7156 msgSubject = strtok(tail1+1, "\"");
7157 else
7159 char* space = strtok(tail1, "\"");
7160 if (!space)
7161 return false;
7162 msgSubject = strtok(NULL, "\"");
7165 if (!msgSubject)
7166 return false;
7168 char* tail2 = strtok(NULL, "");
7169 if (!tail2)
7170 return false;
7172 char* msgText;
7173 if (*tail2=='"')
7174 msgText = strtok(tail2+1, "\"");
7175 else
7177 char* space = strtok(tail2, "\"");
7178 if (!space)
7179 return false;
7180 msgText = strtok(NULL, "\"");
7183 if (!msgText)
7184 return false;
7186 char* money_str = strtok(NULL, "");
7187 int32 money = money_str ? atoi(money_str) : 0;
7188 if (money <= 0)
7189 return false;
7191 // msgSubject, msgText isn't NUL after prev. check
7192 std::string subject = msgSubject;
7193 std::string text = msgText;
7195 uint64 receiver_guid = objmgr.GetPlayerGUIDByName(name);
7196 if (!receiver_guid)
7198 SendSysMessage(LANG_PLAYER_NOT_FOUND);
7199 SetSentErrorMessage(true);
7200 return false;
7203 // from console show not existed sender
7204 uint32 sender_guidlo = m_session ? m_session->GetPlayer()->GetGUIDLow() : 0;
7206 uint32 messagetype = MAIL_NORMAL;
7207 uint32 stationery = MAIL_STATIONERY_GM;
7208 uint32 itemTextId = !text.empty() ? objmgr.CreateItemText( text ) : 0;
7210 Player *receiver = objmgr.GetPlayer(receiver_guid);
7212 WorldSession::SendMailTo(receiver,messagetype, stationery, sender_guidlo, GUID_LOPART(receiver_guid), subject, itemTextId, NULL, money, 0, MAIL_CHECK_MASK_NONE);
7214 std::string nameLink = playerLink(name);
7215 PSendSysMessage(LANG_MAIL_SENT, nameLink.c_str());
7216 return true;
7219 /// Send a message to a player in game
7220 bool ChatHandler::HandleSendMessageCommand(const char* args)
7222 ///- Get the command line arguments
7223 std::string name = extractPlayerNameFromLink((char*)args);
7224 if(name.empty())
7226 SendSysMessage(LANG_PLAYER_NOT_FOUND);
7227 SetSentErrorMessage(true);
7228 return false;
7231 char* msg_str = strtok(NULL, "");
7232 if(!msg_str)
7233 return false;
7235 ///- Find the player and check that he is not logging out.
7236 Player *rPlayer = objmgr.GetPlayer(name.c_str());
7237 if(!rPlayer)
7239 SendSysMessage(LANG_PLAYER_NOT_FOUND);
7240 SetSentErrorMessage(true);
7241 return false;
7244 if(rPlayer->GetSession()->isLogingOut())
7246 SendSysMessage(LANG_PLAYER_NOT_FOUND);
7247 SetSentErrorMessage(true);
7248 return false;
7251 ///- Send the message
7252 //Use SendAreaTriggerMessage for fastest delivery.
7253 rPlayer->GetSession()->SendAreaTriggerMessage("%s", msg_str);
7254 rPlayer->GetSession()->SendAreaTriggerMessage("|cffff0000[Message from administrator]:|r");
7256 //Confirmation message
7257 std::string nameLink = playerLink(name);
7258 PSendSysMessage(LANG_SENDMESSAGE,nameLink.c_str(),msg_str);
7259 return true;
7262 bool ChatHandler::HandleFlushArenaPointsCommand(const char * /*args*/)
7264 sBattleGroundMgr.DistributeArenaPoints();
7265 return true;
7268 bool ChatHandler::HandleModifyGenderCommand(const char *args)
7270 if(!*args)
7271 return false;
7273 Player *player = getSelectedPlayer();
7275 if(!player)
7277 PSendSysMessage(LANG_NO_PLAYER);
7278 SetSentErrorMessage(true);
7279 return false;
7282 PlayerInfo const* info = objmgr.GetPlayerInfo(player->getRace(), player->getClass());
7283 if(!info)
7284 return false;
7286 char const* gender_str = (char*)args;
7287 int gender_len = strlen(gender_str);
7289 Gender gender;
7291 if(!strncmp(gender_str, "male", gender_len)) // MALE
7293 if(player->getGender() == GENDER_MALE)
7294 return true;
7296 gender = GENDER_MALE;
7298 else if (!strncmp(gender_str, "female", gender_len)) // FEMALE
7300 if(player->getGender() == GENDER_FEMALE)
7301 return true;
7303 gender = GENDER_FEMALE;
7305 else
7307 SendSysMessage(LANG_MUST_MALE_OR_FEMALE);
7308 SetSentErrorMessage(true);
7309 return false;
7312 // Set gender
7313 player->SetByteValue(UNIT_FIELD_BYTES_0, 2, gender);
7314 player->SetByteValue(PLAYER_BYTES_3, 0, gender);
7316 // Change display ID
7317 player->SetDisplayId(gender ? info->displayId_f : info->displayId_m);
7318 player->SetNativeDisplayId(gender ? info->displayId_f : info->displayId_m);
7320 char const* gender_full = gender ? "female" : "male";
7322 PSendSysMessage(LANG_YOU_CHANGE_GENDER, GetNameLink(player).c_str(), gender_full);
7324 if (needReportToTarget(player))
7325 ChatHandler(player).PSendSysMessage(LANG_YOUR_GENDER_CHANGED, gender_full, GetNameLink().c_str());
7327 return true;