[4054] added: Line of sight (vmaps) [part 1]
[mangos-git.git] / src / game / Level3.cpp
bloba1a552fde1e7c04012a7cc2a1113fbf79d848dc9
1 /*
2 * Copyright (C) 2005,2006,2007 MaNGOS <http://www.mangosproject.org/>
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 "Player.h"
26 #include "Opcodes.h"
27 #include "GameObject.h"
28 #include "Chat.h"
29 #include "Log.h"
30 #include "Guild.h"
31 #include "ObjectAccessor.h"
32 #include "MapManager.h"
33 #include "SpellAuras.h"
34 #include "ScriptCalls.h"
35 #include "Language.h"
36 #include "RedZoneDistrict.h"
37 #include "GridNotifiersImpl.h"
38 #include "CellImpl.h"
39 #include "Weather.h"
41 bool ChatHandler::HandleReloadCommand(const char* args)
43 char* updatefield = strtok((char*)args, " ");
45 char* value = strtok(NULL, " ");
47 if (!updatefield || !value)
48 return false;
50 uint32 tupdatefield = (uint32)atoi(updatefield);
51 uint32 tvalue = (uint32)atoi(value);
53 Player *chr = m_session->GetPlayer();
54 if (chr == NULL)
56 SendSysMessage(LANG_NO_CHAR_SELECTED);
57 return true;
59 chr->SetUInt32Value(tupdatefield, tvalue);
60 return true;
63 bool ChatHandler::HandleLoadScriptsCommand(const char* args)
65 if(!LoadScriptingModule(args)) return true;
67 sWorld.SendWorldText(LANG_SCRIPTS_RELOADED, NULL);
69 return true;
72 /** \brief GM command level 3 - Create a guild.
74 * This command allows a GM (level 3) to create a guild.
76 * The "args" parameter contains the name of the guild leader
77 * and then the name of the guild.
80 bool ChatHandler::HandleSecurityCommand(const char* args)
82 char* pName = strtok((char*)args, " ");
83 if (!pName)
84 return false;
86 char* pgm = strtok(NULL, " ");
87 if (!pgm)
88 return false;
90 int8 gm = (uint8) atoi(pgm);
91 if ( gm < 0 || gm > 3)
93 SendSysMessage(LANG_BAD_VALUE);
94 return true;
97 std::string name = pName;
99 normalizePlayerName(name);
100 sDatabase.escape_string(name);
101 QueryResult *result = sDatabase.PQuery("SELECT `account` FROM `character` WHERE `name` = '%s'", name.c_str());
103 if(!result)
105 PSendSysMessage(LANG_NO_PLAYER, pName);
106 return true;
109 uint32 acc_id = (*result)[0].GetUInt32();
111 delete result;
113 Player* chr = ObjectAccessor::Instance().FindPlayerByName(name.c_str());
115 if (chr)
117 WorldPacket data;
118 char buf[256];
119 sprintf((char*)buf,LANG_YOURS_SECURITY_CHANGED, m_session->GetPlayer()->GetName(), gm);
120 FillSystemMessageData(&data, m_session, buf);
121 chr->GetSession()->SendPacket(&data);
122 chr->GetSession()->SetSecurity(gm);
125 PSendSysMessage(LANG_YOU_CHANGE_SECURITY, name.c_str(), gm);
126 loginDatabase.PExecute("UPDATE `account` SET `gmlevel` = '%i' WHERE `id` = '%u'", gm, acc_id);
128 return true;
131 bool ChatHandler::HandleGoXYCommand(const char* args)
133 Player* _player = m_session->GetPlayer();
135 if(_player->isInFlight())
137 SendSysMessage(LANG_YOU_IN_FLIGHT);
138 return true;
141 char* px = strtok((char*)args, " ");
142 char* py = strtok(NULL, " ");
143 char* pmapid = strtok(NULL, " ");
145 if (!px || !py)
146 return false;
148 float x = (float)atof(px);
149 float y = (float)atof(py);
150 uint32 mapid;
151 if (pmapid)
152 mapid = (uint32)atoi(pmapid);
153 else mapid = _player->GetMapId();
155 if(!MapManager::IsValidMapCoord(mapid,x,y))
157 PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,mapid);
158 return true;
161 Map *map = MapManager::Instance().GetMap(mapid, _player);
162 float z = max(map->GetHeight(x, y, 0), map->GetWaterLevel(x, y));
163 _player->SetRecallPosition(_player->GetMapId(),_player->GetPositionX(),_player->GetPositionY(),_player->GetPositionZ(),_player->GetOrientation());
164 _player->TeleportTo(mapid, x, y, z, _player->GetOrientation());
166 return true;
169 bool ChatHandler::HandleWorldPortCommand(const char* args)
171 Player* _player = m_session->GetPlayer();
173 if(_player->isInFlight())
175 SendSysMessage(LANG_YOU_IN_FLIGHT);
176 return true;
179 char* pContinent = strtok((char*)args, " ");
180 if (!pContinent)
181 return false;
183 char* px = strtok(NULL, " ");
184 char* py = strtok(NULL, " ");
185 char* pz = strtok(NULL, " ");
187 if (!px || !py || !pz)
188 return false;
190 float x = atof(px);
191 float y = atof(py);
192 float z = atof(pz);
193 uint32 mapid = atoi(pContinent);
195 if(!MapManager::IsValidMapCoord(mapid,x,y))
197 PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,mapid);
198 return true;
201 _player->SetRecallPosition(_player->GetMapId(),_player->GetPositionX(),_player->GetPositionY(),_player->GetPositionZ(),_player->GetOrientation());
203 _player->TeleportTo(mapid, x, y, z,_player->GetOrientation());
205 return true;
208 bool ChatHandler::HandleAllowMovementCommand(const char* args)
210 if(sWorld.getAllowMovement())
212 sWorld.SetAllowMovement(false);
213 SendSysMessage(LANG_CREATURE_MOVE_DISABLED);
215 else
217 sWorld.SetAllowMovement(true);
218 SendSysMessage(LANG_CREATURE_MOVE_ENABLED);
220 return true;
223 bool ChatHandler::HandleGoCommand(const char* args)
225 Player* _player = m_session->GetPlayer();
227 if(_player->isInFlight())
229 SendSysMessage(LANG_YOU_IN_FLIGHT);
230 return true;
233 char* px = strtok((char*)args, " ");
234 char* py = strtok(NULL, " ");
235 char* pz = strtok(NULL, " ");
236 char* pmapid = strtok(NULL, " ");
238 if (!px || !py || !pz || !pmapid)
239 return false;
241 float x = (float)atof(px);
242 float y = (float)atof(py);
243 float z = (float)atof(pz);
244 uint32 mapid = (uint32)atoi(pmapid);
246 if(!MapManager::IsValidMapCoord(mapid,x,y))
248 PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,mapid);
249 return true;
252 _player->SetRecallPosition(_player->GetMapId(),_player->GetPositionX(),_player->GetPositionY(),_player->GetPositionZ(),_player->GetOrientation());
254 _player->TeleportTo(mapid, x, y, z,_player->GetOrientation());
256 return true;
259 bool ChatHandler::HandleMaxSkillCommand(const char* args)
261 Player* SelectedPlayer = getSelectedPlayer();
262 if(!SelectedPlayer)
264 SendSysMessage(LANG_NO_CHAR_SELECTED);
265 return true;
268 // each skills that have max skill value dependent from level seted to current level max skill value
269 SelectedPlayer->UpdateSkillsToMaxSkillsForLevel();
270 return true;
273 bool ChatHandler::HandleSetSkillCommand(const char* args)
275 // number or [name] Shift-click form |color|Hskill:skill_id|h[name]|h|r
276 char* skill_p = extractKeyFromLink((char*)args,"Hskill");
277 if(!skill_p)
278 return false;
280 char *level_p = strtok (NULL, " ");
282 if( !level_p)
283 return false;
285 char *max_p = strtok (NULL, " ");
287 int32 skill = atoi(skill_p);
289 if (skill <= 0)
291 PSendSysMessage(LANG_INVALID_SKILL_ID, skill);
292 return true;
295 int32 level = atol (level_p);
297 Player * target = getSelectedPlayer();
298 if(!target)
300 PSendSysMessage(LANG_NO_CHAR_SELECTED);
301 return true;
304 SkillLineEntry const* sl = sSkillLineStore.LookupEntry(skill);
305 if(!sl)
307 PSendSysMessage(LANG_INVALID_SKILL_ID, skill);
308 return true;
311 if(!target->GetSkillValue(skill))
313 PSendSysMessage(LANG_SET_SKILL_ERROR, target->GetName(), skill, sl->name[0]);
314 return true;
317 int32 max = max_p ? atol (max_p) : target->GetMaxSkillValue(skill);
319 if( level <= 0 || level > max || max <= 0 )
320 return false;
322 target->SetSkill(skill, level, max);
323 PSendSysMessage(LANG_SET_SKILL, skill, sl->name[0], target->GetName(), level, max);
325 return true;
328 const char *gmSpellList[] =
330 "3365",
331 "6233",
332 "6247",
333 "6246",
334 "6477",
335 "6478",
336 "22810",
337 "8386",
338 "21651",
339 "21652",
340 "522",
341 "7266",
342 "8597",
343 "2479",
344 "22027",
345 "6603",
346 "5019",
347 "133",
348 "168",
349 "227",
350 "5009",
351 "9078",
352 "668",
353 "203",
354 "20599",
355 "20600",
356 "81",
357 "20597",
358 "20598",
359 "20864",
360 "1459",
361 "5504",
362 "587",
363 "5143",
364 "118",
365 "5505",
366 "597",
367 "604",
368 "1449",
369 "1460",
370 "2855",
371 "1008",
372 "475",
373 "5506",
374 "1463",
375 "12824",
376 "8437",
377 "990",
378 "5145",
379 "8450",
380 "1461",
381 "759",
382 "8494",
383 "8455",
384 "8438",
385 "6127",
386 "8416",
387 "6129",
388 "8451",
389 "8495",
390 "8439",
391 "3552",
392 "8417",
393 "10138",
394 "12825",
395 "10169",
396 "10156",
397 "10144",
398 "10191",
399 "10201",
400 "10211",
401 "10053",
402 "10173",
403 "10139",
404 "10145",
405 "10192",
406 "10170",
407 "10202",
408 "10054",
409 "10174",
410 "10193",
411 "12826",
412 "2136",
413 "143",
414 "145",
415 "2137",
416 "2120",
417 "3140",
418 "543",
419 "2138",
420 "2948",
421 "8400",
422 "2121",
423 "8444",
424 "8412",
425 "8457",
426 "8401",
427 "8422",
428 "8445",
429 "8402",
430 "8413",
431 "8458",
432 "8423",
433 "8446",
434 "10148",
435 "10197",
436 "10205",
437 "10149",
438 "10215",
439 "10223",
440 "10206",
441 "10199",
442 "10150",
443 "10216",
444 "10207",
445 "10225",
446 "10151",
447 "116",
448 "205",
449 "7300",
450 "122",
451 "837",
452 "10",
453 "7301",
454 "7322",
455 "6143",
456 "120",
457 "865",
458 "8406",
459 "6141",
460 "7302",
461 "8461",
462 "8407",
463 "8492",
464 "8427",
465 "8408",
466 "6131",
467 "7320",
468 "10159",
469 "8462",
470 "10185",
471 "10179",
472 "10160",
473 "10180",
474 "10219",
475 "10186",
476 "10177",
477 "10230",
478 "10181",
479 "10161",
480 "10187",
481 "10220",
482 "2018",
483 "2663",
484 "12260",
485 "2660",
486 "3115",
487 "3326",
488 "2665",
489 "3116",
490 "2738",
491 "3293",
492 "2661",
493 "3319",
494 "2662",
495 "9983",
496 "8880",
497 "2737",
498 "2739",
499 "7408",
500 "3320",
501 "2666",
502 "3323",
503 "3324",
504 "3294",
505 "22723",
506 "23219",
507 "23220",
508 "23221",
509 "23228",
510 "23338",
511 "10788",
512 "10790",
513 "5611",
514 "5016",
515 "5609",
516 "2060",
517 "10963",
518 "10964",
519 "10965",
520 "22593",
521 "22594",
522 "596",
523 "996",
524 "499",
525 "768",
526 "17002",
527 "1448",
528 "1082",
529 "16979",
530 "1079",
531 "5215",
532 "20484",
533 "5221",
534 "15590",
535 "17007",
536 "6795",
537 "6807",
538 "5487",
539 "1446",
540 "1066",
541 "5421",
542 "3139",
543 "779",
544 "6811",
545 "6808",
546 "1445",
547 "5216",
548 "1737",
549 "5222",
550 "5217",
551 "1432",
552 "6812",
553 "9492",
554 "5210",
555 "3030",
556 "1441",
557 "783",
558 "6801",
559 "20739",
560 "8944",
561 "9491",
562 "22569",
563 "5226",
564 "6786",
565 "1433",
566 "8973",
567 "1828",
568 "9495",
569 "9006",
570 "6794",
571 "8993",
572 "5203",
573 "16914",
574 "6784",
575 "9635",
576 "22830",
577 "20722",
578 "9748",
579 "6790",
580 "9753",
581 "9493",
582 "9752",
583 "9831",
584 "9825",
585 "9822",
586 "5204",
587 "5401",
588 "22831",
589 "6793",
590 "9845",
591 "17401",
592 "9882",
593 "9868",
594 "20749",
595 "9893",
596 "9899",
597 "9895",
598 "9832",
599 "9902",
600 "9909",
601 "22832",
602 "9828",
603 "9851",
604 "9883",
605 "9869",
606 "17406",
607 "17402",
608 "9914",
609 "20750",
610 "9897",
611 "9848",
612 "3127",
613 "107",
614 "204",
615 "9116",
616 "2457",
617 "78",
618 "18848",
619 "331",
620 "403",
621 "2098",
622 "1752",
623 "11278",
624 "11288",
625 "11284",
626 "6461",
627 "2344",
628 "2345",
629 "6463",
630 "2346",
631 "2352",
632 "775",
633 "1434",
634 "1612",
635 "71",
636 "2468",
637 "2458",
638 "2467",
639 "7164",
640 "7178",
641 "7367",
642 "7376",
643 "7381",
644 "21156",
645 "5209",
646 "3029",
647 "5201",
648 "9849",
649 "9850",
650 "20719",
651 "22568",
652 "22827",
653 "22828",
654 "22829",
655 "6809",
656 "8972",
657 "9005",
658 "9823",
659 "9827",
660 "6783",
661 "9913",
662 "6785",
663 "6787",
664 "9866",
665 "9867",
666 "9894",
667 "9896",
668 "6800",
669 "8992",
670 "9829",
671 "9830",
672 "780",
673 "769",
674 "6749",
675 "6750",
676 "9755",
677 "9754",
678 "9908",
679 "20745",
680 "20742",
681 "20747",
682 "20748",
683 "9746",
684 "9745",
685 "9880",
686 "9881",
687 "5391",
688 "842",
689 "3025",
690 "3031",
691 "3287",
692 "3329",
693 "1945",
694 "3559",
695 "4933",
696 "4934",
697 "4935",
698 "4936",
699 "5142",
700 "5390",
701 "5392",
702 "5404",
703 "5420",
704 "6405",
705 "7293",
706 "7965",
707 "8041",
708 "8153",
709 "9033",
710 "9034",
711 //"9036", problems with ghost state
712 "16421",
713 "21653",
714 "22660",
715 "5225",
716 "9846",
717 "2426",
718 "5916",
719 "6634",
720 //"6718", phasing stealth, annoing for learn all case.
721 "6719",
722 "8822",
723 "9591",
724 "9590",
725 "10032",
726 "17746",
727 "17747",
728 "8203",
729 "11392",
730 "12495",
731 "16380",
732 "23452",
733 "4079",
734 "4996",
735 "4997",
736 "4998",
737 "4999",
738 "5000",
739 "6348",
740 "6349",
741 "6481",
742 "6482",
743 "6483",
744 "6484",
745 "11362",
746 "11410",
747 "11409",
748 "12510",
749 "12509",
750 "12885",
751 "13142",
752 "21463",
753 "23460",
754 "11421",
755 "11416",
756 "11418",
757 "1851",
758 "10059",
759 "11423",
760 "11417",
761 "11422",
762 "11419",
763 "11424",
764 "11420",
765 "27",
766 "31",
767 "33",
768 "34",
769 "35",
770 "15125",
771 "21127",
772 "22950",
773 "1180",
774 "201",
775 "12593",
776 "12842",
777 "16770",
778 "6057",
779 "12051",
780 "18468",
781 "12606",
782 "12605",
783 "18466",
784 "12502",
785 "12043",
786 "15060",
787 "12042",
788 "12341",
789 "12848",
790 "12344",
791 "12353",
792 "18460",
793 "11366",
794 "12350",
795 "12352",
796 "13043",
797 "11368",
798 "11113",
799 "12400",
800 "11129",
801 "16766",
802 "12573",
803 "15053",
804 "12580",
805 "12475",
806 "12472",
807 "12953",
808 "12488",
809 "11189",
810 "12985",
811 "12519",
812 "16758",
813 "11958",
814 "12490",
815 "11426",
816 "3565",
817 "3562",
818 "18960",
819 "3567",
820 "3561",
821 "3566",
822 "3563",
823 "1953",
824 "2139",
825 "12505",
826 "13018",
827 "12522",
828 "12523",
829 "5146",
830 "5144",
831 "5148",
832 "8419",
833 "8418",
834 "10213",
835 "10212",
836 "10157",
837 "12524",
838 "13019",
839 "12525",
840 "13020",
841 "12526",
842 "13021",
843 "18809",
844 "13031",
845 "13032",
846 "13033",
847 "4036",
848 "3920",
849 "3919",
850 "3918",
851 "7430",
852 "3922",
853 "3923",
854 "3921",
855 "7411",
856 "7418",
857 "7421",
858 "13262",
859 "7412",
860 "7415",
861 "7413",
862 "7416",
863 "13920",
864 "13921",
865 "7745",
866 "7779",
867 "7428",
868 "7457",
869 "7857",
870 "7748",
871 "7426",
872 "13421",
873 "7454",
874 "13378",
875 "7788",
876 "14807",
877 "14293",
878 "7795",
879 "6296",
880 "20608",
881 "755",
882 "444",
883 "427",
884 "428",
885 "442",
886 "447",
887 "3578",
888 "3581",
889 "19027",
890 "3580",
891 "665",
892 "3579",
893 "3577",
894 "6755",
895 "3576",
896 "2575",
897 "2577",
898 "2578",
899 "2579",
900 "2580",
901 "2656",
902 "2657",
903 "2576",
904 "3564",
905 "10248",
906 "8388",
907 "2659",
908 "14891",
909 "3308",
910 "3307",
911 "10097",
912 "2658",
913 "3569",
914 "16153",
915 "3304",
916 "10098",
917 "4037",
918 "3929",
919 "3931",
920 "3926",
921 "3924",
922 "3930",
923 "3977",
924 "3925",
925 "136",
926 "228",
927 "5487",
928 "43",
929 "202",
933 bool ChatHandler::HandleLearnCommand(const char* args)
935 uint16 maxconfskill = sWorld.GetConfigMaxSkillValue();
937 if (!*args)
938 return false;
940 if (!strcmp(args, "all"))
942 int loop = 0;
944 PSendSysMessage(LANG_LEARNING_GM_SKILLS, m_session->GetPlayer()->GetName());
946 while (strcmp(gmSpellList[loop], "0"))
948 uint32 spell = atol((char*)gmSpellList[loop]);
950 if (m_session->GetPlayer()->HasSpell(spell))
952 loop++;
953 continue;
955 m_session->GetPlayer()->learnSpell((uint16)spell);
957 loop++;
960 return true;
963 if (!strcmp(args, "all_myclass"))
965 PSendSysMessage(LANG_COMMAND_LEARNINGSPSK, m_session->GetPlayer()->GetName());
967 uint32 family = 0;
968 switch(m_session->GetPlayer()->getClass())
970 case CLASS_WARRIOR: family = SPELLFAMILY_WARRIOR; break;
971 case CLASS_PALADIN: family = SPELLFAMILY_PALADIN; break;
972 case CLASS_HUNTER: family = SPELLFAMILY_HUNTER; break;
973 case CLASS_ROGUE: family = SPELLFAMILY_ROGUE; break;
974 case CLASS_PRIEST: family = SPELLFAMILY_PRIEST; break;
975 case CLASS_SHAMAN: family = SPELLFAMILY_SHAMAN; break;
976 case CLASS_MAGE: family = SPELLFAMILY_MAGE; break;
977 case CLASS_WARLOCK: family = SPELLFAMILY_WARLOCK; break;
978 case CLASS_DRUID: family = SPELLFAMILY_DRUID; break;
979 default: return true;
982 for (uint32 i = 0; i < sSpellStore.GetNumRows(); i++)
984 SpellEntry const *spellInfo = sSpellStore.LookupEntry(i);
985 SkillLineAbilityEntry const *skillLine = sSkillLineAbilityStore.LookupEntry(i);
986 if (skillLine && spellInfo && spellInfo->SpellFamilyName == family && !m_session->GetPlayer()->HasSpell(i))
987 m_session->GetPlayer()->learnSpell((uint16)i);
990 return true;
993 if (!strcmp(args, "all_lang"))
995 PSendSysMessage(LANG_COMMAND_LEARNINGALLLANG, m_session->GetPlayer()->GetName());
997 // skipping UNIVERSAL language (0)
998 for(int i = 1; i < LANGUAGES_COUNT; ++i)
999 m_session->GetPlayer()->learnSpell(lang_description[i].spell_id);
1000 return true;
1003 Player* target = getSelectedPlayer();
1004 if(!target)
1006 PSendSysMessage(LANG_NO_CHAR_SELECTED);
1007 return true;
1010 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
1011 char* cId = extractKeyFromLink((char*)args,"Hspell");
1012 if(!cId)
1013 return false;
1015 uint32 spell = atol(cId);
1017 if (target->HasSpell(spell))
1019 SendSysMessage(LANG_KNOWN_SPELL);
1020 return true;
1023 target->learnSpell((uint16)spell);
1025 return true;
1028 bool ChatHandler::HandleCooldownCommand(const char* args)
1030 Player* target = getSelectedPlayer();
1031 if(!target)
1033 PSendSysMessage(LANG_PLAYER_NOT_FOUND);
1034 return true;
1037 if (!*args)
1039 target->RemoveAllSpellCooldown();
1040 PSendSysMessage(LANG_REMOVEALL_COOLDOWN, target->GetName());
1042 else
1044 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
1045 char* cId = extractKeyFromLink((char*)args,"Hspell");
1046 if(!cId)
1047 return false;
1049 uint32 spell_id = atol(cId);
1051 if(!sSpellStore.LookupEntry(spell_id))
1053 PSendSysMessage(LANG_UNKNOWN_SPELL, target==m_session->GetPlayer() ? LANG_YOU : target->GetName());
1054 return true;
1057 WorldPacket data( SMSG_CLEAR_COOLDOWN, (4+8+4) );
1058 data << uint32( spell_id );
1059 data << target->GetGUID();
1060 data << uint32(0);
1061 target->GetSession()->SendPacket(&data);
1062 target->RemoveSpellCooldown(spell_id);
1063 PSendSysMessage(LANG_REMOVE_COOLDOWN, spell_id, target==m_session->GetPlayer() ? LANG_YOU : target->GetName());
1065 return true;
1068 bool ChatHandler::HandleUnLearnCommand(const char* args)
1070 if (!*args)
1071 return false;
1073 uint32 minS;
1074 uint32 maxS;
1076 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
1077 char* startS = extractKeyFromLink((char*)args,"Hspell");
1078 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
1079 char* endS = extractKeyFromLink(NULL,"Hspell");
1081 if (!endS)
1083 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
1084 minS = (uint32)atol(startS);
1085 maxS = minS+1;
1087 else
1089 minS = (uint32)atol(startS);
1090 maxS = (uint32)atol(endS);
1091 if (maxS >= minS)
1093 maxS=maxS+1;
1095 else
1097 std::swap(minS,maxS);
1098 maxS=minS+1;
1102 Player* target = getSelectedPlayer();
1103 if(!target)
1105 PSendSysMessage(LANG_NO_CHAR_SELECTED);
1106 return true;
1109 for(uint32 spell=minS;spell<maxS;spell++)
1111 if (target->HasSpell(spell))
1112 target->removeSpell(spell);
1113 else
1114 SendSysMessage(LANG_FORGET_SPELL);
1117 return true;
1120 bool ChatHandler::HandleAddItemCommand(const char* args)
1122 if (!*args)
1123 return false;
1125 uint32 itemId = 0;
1127 if(args[0]=='[') // [name] manual form
1129 char* citemName = citemName = strtok((char*)args, "]");
1131 if(citemName && citemName[0])
1133 std::string itemName = citemName+1;
1134 sDatabase.escape_string(itemName);
1135 QueryResult *result = sDatabase.PQuery("SELECT entry FROM item_template WHERE name = '%s'", itemName.c_str());
1136 if (!result)
1138 PSendSysMessage(LANG_COMMAND_ADDITEMCOULDNOTFIND, citemName+1);
1139 return true;
1141 itemId = result->Fetch()->GetUInt16();
1142 delete result;
1144 else
1145 return false;
1147 else if(args[0]=='|') // [name] Shift-click form |color|Hitem:item_id:0:0:0|h[name]|h|r
1149 strtok((char*)args, ":");
1150 char* citemId = strtok(NULL, ":");
1151 itemId = atol(citemId);
1152 strtok(NULL, "]");
1153 strtok(NULL, " ");
1155 else // item_id form
1157 char* citemId = strtok((char*)args, " ");
1158 itemId = atol(citemId);
1161 char* ccount = strtok(NULL, " ");
1163 int32 count = 1;
1165 if (ccount) { count = atol(ccount); }
1166 if (count < 1) { count = 1; }
1168 Player* pl = m_session->GetPlayer();
1169 Player* plTarget = getSelectedPlayer();
1170 if(!plTarget)
1171 plTarget = pl;
1173 sLog.outDetail(LANG_ADDITEM, itemId, count);
1175 ItemPrototype const *pProto = objmgr.GetItemPrototype(itemId);
1176 if(!pProto)
1178 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, itemId);
1179 return true;
1182 uint32 countForStore = count;
1184 // item used in local operations and in add item notifier
1185 Item* item = NULL;
1187 // if possible create full stacks for better performance
1188 while(countForStore >= pProto->Stackable)
1190 uint16 dest;
1191 uint8 msg = plTarget->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, itemId, pProto->Stackable, false );
1192 if( msg == EQUIP_ERR_OK )
1194 item = plTarget->StoreNewItem( dest, itemId, pProto->Stackable, true, Item::GenerateItemRandomPropertyId(itemId));
1196 countForStore-= pProto->Stackable;
1198 // remove binding (let GM give it to another player later)
1199 if(pl==plTarget)
1201 // remove binding from original stack
1202 Item* item1 = pl->GetItemByPos(dest);
1203 if(item1!=item)
1204 item1->SetBinding( false );
1205 // and new stack
1206 item->SetBinding( false );
1209 else
1210 break;
1213 // create remaining items
1214 if(countForStore > 0 && countForStore < pProto->Stackable)
1216 uint16 dest;
1217 uint8 msg = plTarget->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, itemId, countForStore, false );
1219 // if can add all countForStore items
1220 if( msg == EQUIP_ERR_OK )
1222 item = plTarget->StoreNewItem( dest, itemId, countForStore, true, Item::GenerateItemRandomPropertyId(itemId));
1223 countForStore = 0;
1225 // remove binding (let GM give it to another player later)
1226 if(pl==plTarget)
1228 // remove binding from original stack
1229 Item* item1 = pl->GetItemByPos(dest);
1230 if(item1!=item)
1231 item1->SetBinding( false );
1232 // and new stack
1233 item->SetBinding( false );
1238 // ok search place for add only part from countForStore items in not full stacks
1239 while(countForStore > 0)
1241 // find not full stack (last possable place for times after prev. checks)
1242 uint16 dest;
1243 uint8 msg = plTarget->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, itemId, 1, false );
1244 if( msg == EQUIP_ERR_OK ) // found
1246 // we can fill this stack to max stack size
1247 Item* itemStack = pl->GetItemByPos(dest);
1248 if(itemStack)
1250 uint32 countForStack = pProto->Stackable - itemStack->GetCount();
1251 // recheck with real item amount
1252 uint8 msg = plTarget->CanStoreNewItem( itemStack->GetBagSlot(), itemStack->GetSlot(), dest, itemId, countForStack, false );
1253 if( msg == EQUIP_ERR_OK )
1255 item = plTarget->StoreNewItem( dest, itemId, countForStack, true, Item::GenerateItemRandomPropertyId(itemId));
1256 countForStore-= countForStack;
1258 // remove binding (let GM give it to another player later)
1259 if(pl==plTarget)
1260 item->SetBinding( false );
1262 else
1263 break; // not possible with correct work
1265 else
1266 break; // not possible with correct work
1268 else
1269 break;
1272 if(count > countForStore && item)
1274 pl->SendNewItem(item,count - countForStore,false,true);
1275 if(pl!=plTarget)
1276 plTarget->SendNewItem(item,count - countForStore,true,false);
1279 if(countForStore > 0)
1280 PSendSysMessage(LANG_ITEM_CANNOT_CREATE, itemId, countForStore);
1282 return true;
1285 bool ChatHandler::HandleAddItemSetCommand(const char* args)
1287 if (!*args)
1288 return false;
1290 char* cId = extractKeyFromLink((char*)args,"Hitemset"); // number or [name] Shift-click form |color|Hitemset:itemset_id|h[name]|h|r
1291 if (!cId)
1292 return false;
1294 uint32 itemsetId = atol(cId);
1296 // prevent generation all items with itemset field value '0'
1297 if (itemsetId == 0)
1299 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND,itemsetId);
1300 return true;
1303 Player* pl = m_session->GetPlayer();
1304 Player* plTarget = getSelectedPlayer();
1305 if(!plTarget)
1306 plTarget = pl;
1308 sLog.outDetail(LANG_ADDITEMSET, itemsetId);
1310 QueryResult *result = sDatabase.PQuery("SELECT `entry` FROM `item_template` WHERE `itemset` = %u",itemsetId);
1312 if(!result)
1314 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND,itemsetId);
1316 return true;
1321 Field *fields = result->Fetch();
1322 uint32 itemId = fields[0].GetUInt32();
1324 uint16 dest;
1326 uint8 msg = plTarget->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, itemId, 1, false );
1327 if( msg == EQUIP_ERR_OK )
1329 Item* item = plTarget->StoreNewItem( dest, itemId, 1, true);
1331 // remove binding (let GM give it to another player later)
1332 if(pl==plTarget)
1333 item->SetBinding( false );
1335 pl->SendNewItem(item,1,false,true);
1336 if(pl!=plTarget)
1337 plTarget->SendNewItem(item,1,true,false);
1339 else
1341 pl->SendEquipError( msg, NULL, NULL );
1342 PSendSysMessage(LANG_ITEM_CANNOT_CREATE, itemId, 1);
1345 }while( result->NextRow() );
1347 delete result;
1349 return true;
1352 bool ChatHandler::HandleListItemCommand(const char* args)
1354 if(!*args)
1355 return false;
1357 char* c_item_id = strtok((char*)args, " ");
1358 uint32 item_id = atol(c_item_id);
1360 if(!item_id || !objmgr.GetItemPrototype(item_id))
1362 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, item_id);
1363 return true;
1366 char* c_count = strtok(NULL, " ");
1367 int count = c_count ? atol(c_count) : 10;
1369 if(count < 0)
1370 return false;
1372 QueryResult *result;
1374 // inventory case
1375 uint32 inv_count = 0;
1376 result=sDatabase.PQuery("SELECT COUNT(`item_template`) FROM `character_inventory` WHERE `item_template`='%u'",item_id);
1377 if(result)
1379 inv_count = (*result)[0].GetUInt32();
1380 delete result;
1383 result=sDatabase.PQuery(
1384 // 0 1 2 3 4 5
1385 "SELECT `ci`.`item`,`cibag`.`slot` AS `bag`,`ci`.`slot`,`ci`.`guid`,`character`.`account`,`character`.`name` "
1386 "FROM `character_inventory` AS `ci` LEFT JOIN `character_inventory` AS `cibag` ON (`cibag`.`item`=`ci`.`bag`),`character` "
1387 "WHERE `ci`.`item_template`='%u' AND `ci`.`guid` = `character`.`guid` LIMIT %u ",
1388 item_id,uint32(count));
1390 if(result)
1394 Field *fields = result->Fetch();
1395 uint32 item_guid = fields[0].GetUInt32();
1396 uint32 item_bag = fields[1].GetUInt32();
1397 uint32 item_slot = fields[2].GetUInt32();
1398 uint32 owner_guid = fields[3].GetUInt32();
1399 uint32 owner_acc = fields[4].GetUInt32();
1400 std::string owner_name = fields[5].GetCppString();
1402 char const* item_pos = 0;
1403 if(Player::IsEquipmentPos(item_bag,item_slot))
1404 item_pos = "[equipped]";
1405 else if(Player::IsInventoryPos(item_bag,item_slot))
1406 item_pos = "[in inventory]";
1407 else if(Player::IsBankPos(item_bag,item_slot))
1408 item_pos = "[in bank]";
1409 else
1410 item_pos = "";
1412 PSendSysMessage(LANG_ITEMLIST_SLOT,
1413 item_guid,owner_name.c_str(),owner_guid,owner_acc,item_pos);
1414 } while (result->NextRow());
1416 uint64 res_count = result->GetRowCount();
1418 delete result;
1420 if(count > res_count)
1421 count-=res_count;
1422 else if(count)
1423 count = 0;
1426 // mail case
1427 uint32 mail_count = 0;
1428 result=sDatabase.PQuery("SELECT COUNT(`item_template`) FROM `mail` WHERE `item_template`='%u'",item_id);
1429 if(result)
1431 mail_count = (*result)[0].GetUInt32();
1432 delete result;
1435 if(count > 0)
1437 result=sDatabase.PQuery(
1438 // 0 1 2 3 4 5 6
1439 "SELECT `mail`.`item_guid`,`mail`.`sender`,`mail`.`receiver`,`char_s`.`account`,`char_s`.`name`,`char_r`.`account`,`char_r`.`name` "
1440 "FROM `mail`,`character` as `char_s`,`character` as `char_r` "
1441 "WHERE `mail`.`item_template`='%u' AND `char_s`.`guid` = `mail`.`sender` AND `char_r`.`guid` = `mail`.`receiver` LIMIT %u",
1442 item_id,uint32(count));
1444 else
1445 result = NULL;
1447 if(result)
1451 Field *fields = result->Fetch();
1452 uint32 item_guid = fields[0].GetUInt32();
1453 uint32 item_s = fields[1].GetUInt32();
1454 uint32 item_r = fields[2].GetUInt32();
1455 uint32 item_s_acc = fields[3].GetUInt32();
1456 std::string item_s_name = fields[4].GetCppString();
1457 uint32 item_r_acc = fields[5].GetUInt32();
1458 std::string item_r_name = fields[6].GetCppString();
1460 char const* item_pos = "[in mail]";
1462 PSendSysMessage(LANG_ITEMLIST_MAIL,
1463 item_guid,item_s_name.c_str(),item_s,item_s_acc,item_r_name.c_str(),item_r,item_r_acc,item_pos);
1464 } while (result->NextRow());
1466 uint64 res_count = result->GetRowCount();
1468 delete result;
1470 if(count > res_count)
1471 count-=res_count;
1472 else if(count)
1473 count = 0;
1476 // auction case
1477 uint32 auc_count = 0;
1478 result=sDatabase.PQuery("SELECT COUNT(`item_template`) FROM `auctionhouse` WHERE `item_template`='%u'",item_id);
1479 if(result)
1481 auc_count = (*result)[0].GetUInt32();
1482 delete result;
1485 if(count > 0)
1487 result=sDatabase.PQuery(
1488 // 0 1 2 3
1489 "SELECT `auctionhouse`.`itemguid`,`auctionhouse`.`itemowner`,`character`.`account`,`character`.`name` "
1490 "FROM `auctionhouse`,`character` WHERE `auctionhouse`.`item_template`='%u' AND `character`.`guid` = `auctionhouse`.`itemowner` LIMIT %u",
1491 item_id,uint32(count));
1493 else
1494 result = NULL;
1496 if(result)
1500 Field *fields = result->Fetch();
1501 uint32 item_guid = fields[0].GetUInt32();
1502 uint32 owner = fields[1].GetUInt32();
1503 uint32 owner_acc = fields[2].GetUInt32();
1504 std::string owner_name = fields[3].GetCppString();
1506 char const* item_pos = "[in auction]";
1508 PSendSysMessage(LANG_ITEMLIST_AUCTION, item_guid, owner_name.c_str(), owner, owner_acc,item_pos);
1509 } while (result->NextRow());
1511 delete result;
1514 if(inv_count+mail_count+auc_count == 0)
1516 SendSysMessage(LANG_COMMAND_NOITEMFOUND);
1517 return true;
1520 PSendSysMessage(LANG_COMMAND_LISTITEMMESSAGE,item_id,inv_count+mail_count+auc_count,inv_count,mail_count,auc_count);
1522 return true;
1525 bool ChatHandler::HandleListObjectCommand(const char* args)
1527 if(!*args)
1528 return false;
1530 char* cId = extractKeyFromLink((char*)args,"Hgameobject_entry"); // number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
1531 if(!cId)
1532 return false;
1534 uint32 go_id = atol(cId);
1536 GameObjectInfo const * gInfo = objmgr.GetGameObjectInfo(go_id);
1538 if(!go_id || !gInfo)
1540 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID, go_id);
1541 return true;
1544 char* c_count = strtok(NULL, " ");
1545 int count = c_count ? atol(c_count) : 10;
1547 if(count < 0)
1548 return false;
1550 Player* pl = m_session->GetPlayer();
1551 QueryResult *result;
1553 uint32 obj_count = 0;
1554 result=sDatabase.PQuery("SELECT COUNT(`guid`) FROM `gameobject` WHERE `id`='%u'",go_id);
1555 if(result)
1557 obj_count = (*result)[0].GetUInt32();
1558 delete result;
1561 result = sDatabase.PQuery("SELECT `guid`, `id`, `position_x`, `position_y`, `position_z`, `orientation`, `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",
1562 pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(),go_id,uint32(count));
1564 if (result)
1568 Field *fields = result->Fetch();
1569 uint32 guid = fields[0].GetUInt32();
1570 uint32 id = fields[1].GetUInt32();
1571 float x = fields[2].GetFloat();
1572 float y = fields[3].GetFloat();
1573 float z = fields[4].GetFloat();
1574 float o = fields[5].GetFloat();
1575 int mapid = fields[6].GetUInt16();
1577 PSendSysMessage(LANG_GO_LIST, guid, guid, gInfo->name, x, y, z, mapid);
1578 } while (result->NextRow());
1580 delete result;
1583 PSendSysMessage(LANG_COMMAND_LISTOBJMESSAGE,go_id,obj_count);
1584 return true;
1587 bool ChatHandler::HandleListCreatureCommand(const char* args)
1589 if(!*args)
1590 return false;
1592 char* cId = extractKeyFromLink((char*)args,"Hcreature_entry"); // number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r
1593 if(!cId)
1594 return false;
1596 uint32 cr_id = atol(cId);
1598 CreatureInfo const* cInfo = objmgr.GetCreatureTemplate(cr_id);
1600 if(!cr_id || !cInfo)
1602 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID, cr_id);
1603 return true;
1606 char* c_count = strtok(NULL, " ");
1607 int count = c_count ? atol(c_count) : 10;
1609 if(count < 0)
1610 return false;
1612 Player* pl = m_session->GetPlayer();
1613 QueryResult *result;
1615 uint32 cr_count = 0;
1616 result=sDatabase.PQuery("SELECT COUNT(`guid`) FROM `creature` WHERE `id`='%u'",cr_id);
1617 if(result)
1619 cr_count = (*result)[0].GetUInt32();
1620 delete result;
1623 result = sDatabase.PQuery("SELECT `guid`, `id`, `position_x`, `position_y`, `position_z`, `orientation`, `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",
1624 pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(), cr_id,uint32(count));
1626 if (result)
1630 Field *fields = result->Fetch();
1631 uint32 guid = fields[0].GetUInt32();
1632 uint32 id = fields[1].GetUInt32();
1633 float x = fields[2].GetFloat();
1634 float y = fields[3].GetFloat();
1635 float z = fields[4].GetFloat();
1636 float o = fields[5].GetFloat();
1637 int mapid = fields[6].GetUInt16();
1639 PSendSysMessage(LANG_CREATURE_LIST, guid, guid, cInfo->Name, x, y, z, mapid);
1640 } while (result->NextRow());
1642 delete result;
1645 PSendSysMessage(LANG_COMMAND_LISTCREATUREMESSAGE,cr_id,cr_count);
1646 return true;
1649 bool ChatHandler::HandleLookupItemCommand(const char* args)
1651 if(!*args)
1652 return false;
1653 std::string namepart = args;
1654 sDatabase.escape_string(namepart);
1656 QueryResult *result=sDatabase.PQuery("SELECT `entry`,`name` FROM `item_template` WHERE `name` LIKE \"%%%s%%\"",namepart.c_str());
1657 if(!result)
1659 SendSysMessage(LANG_COMMAND_NOITEMFOUND);
1660 return true;
1665 Field *fields = result->Fetch();
1666 uint32 id = fields[0].GetUInt32();
1667 std::string name = fields[1].GetCppString();
1668 // send item in "id - id [name]" format (??)
1669 PSendSysMessage(LANG_ITEM_LIST, id,id,name.c_str());
1670 } while (result->NextRow());
1672 delete result;
1673 return true;
1676 bool ChatHandler::HandleLookupItemSetCommand(const char* args)
1678 if(!*args)
1679 return false;
1680 std::string namepart = args;
1681 uint32 counter = 0; // Counter for figure out that we found smth.
1683 // Search in ItemSet.dbc
1684 for (uint32 id = 0; id < sItemSetStore.GetNumRows(); id++)
1686 ItemSetEntry const *set = sItemSetStore.LookupEntry(id);
1687 if(set)
1689 std::string name = set->name[sWorld.GetDBClang()];
1691 // converting name to lower case
1692 std::transform( name.begin(), name.end(), name.begin(), ::tolower );
1694 // converting string that we try to find to lower case
1695 std::transform( namepart.begin(), namepart.end(), namepart.begin(), ::tolower );
1697 if (name.find(namepart) != std::string::npos)
1699 // send item set in "id - [namedlink]" format
1700 PSendSysMessage(LANG_ITEMSET_LIST,id,id,set->name[sWorld.GetDBClang()]);
1701 counter++;
1705 if (counter == 0) // if counter == 0 then we found nth
1706 SendSysMessage(LANG_COMMAND_NOITEMSETFOUND);
1707 return true;
1710 bool ChatHandler::HandleLookupSkillCommand(const char* args)
1712 if(!*args)
1713 return false;
1715 std::string namepart = args;
1716 uint32 counter = 0; // Counter for figure out that we found smth.
1718 // Search in SkillLine.dbc
1719 for (uint32 id = 0; id < sSkillLineStore.GetNumRows(); id++)
1721 SkillLineEntry const *skillInfo = sSkillLineStore.LookupEntry(id);
1722 if(skillInfo)
1724 // name - is first name field from dbc (English localized)
1725 std::string name = skillInfo->name[sWorld.GetDBClang()];
1727 // converting SkillName to lower case
1728 std::transform( name.begin(), name.end(), name.begin(), ::tolower );
1729 // converting string that we try to find to lower case
1730 std::transform( namepart.begin(), namepart.end(), namepart.begin(), ::tolower );
1732 if (name.find(namepart) != std::string::npos)
1734 uint16 skill = m_session->GetPlayer()->GetPureSkillValue(id);
1735 // send skill in "id - [namedlink]" format
1736 PSendSysMessage(LANG_SKILL_LIST "%s",id,id,skillInfo->name[sWorld.GetDBClang()],(skill == 0 ? "" : LANG_KNOWN));
1738 counter++;
1742 if (counter == 0) // if counter == 0 then we found nth
1743 SendSysMessage(LANG_COMMAND_NOSKILLFOUND);
1744 return true;
1747 bool ChatHandler::HandleLookupSpellCommand(const char* args)
1749 if(!*args)
1750 return false;
1751 std::string namepart = args;
1752 uint32 counter = 0; // Counter for figure out that we found smth.
1754 // Search in Spell.dbc
1755 for (uint32 id = 0; id < sSpellStore.GetNumRows(); id++)
1757 SpellEntry const *spellInfo = sSpellStore.LookupEntry(id);
1758 if(spellInfo)
1760 // name - is first name field from dbc (English localized)
1761 std::string name = spellInfo->SpellName[sWorld.GetDBClang()];
1763 // converting SpellName to lower case
1764 std::transform( name.begin(), name.end(), name.begin(), ::tolower );
1766 // converting string that we try to find to lower case
1767 std::transform( namepart.begin(), namepart.end(), namepart.begin(), ::tolower );
1769 if (name.find(namepart) != std::string::npos)
1771 uint32 rank = objmgr.GetSpellRank(id); // unit32 used to prevent interpreting uint8 as char at output
1772 bool known = m_session->GetPlayer()->HasSpell(id);
1773 bool learn = (spellInfo->Effect[0] == SPELL_EFFECT_LEARN_SPELL);
1774 bool talent = (GetTalentSpellCost(id) > 0);
1775 bool passive = IsPassiveSpell(id);
1777 // send spell in "id - [name, rank N] [talent] [passive] [learn] [known]" format
1778 std::ostringstream ss;
1779 ss << id << " - |cffffffff|Hspell:" << id << "|h[" << spellInfo->SpellName[sWorld.GetDBClang()];
1781 // include rank in link name
1782 if(rank)
1783 ss << LANG_SPELL_RANK << rank;
1785 ss << "]|h|r";
1787 if(talent)
1788 ss << LANG_TALENT;
1789 if(passive)
1790 ss << LANG_PASSIVE;
1791 if(learn)
1792 ss << LANG_LEARN;
1793 if(known)
1794 ss << LANG_KNOWN;
1796 SendSysMessage(ss.str().c_str());
1798 ++counter;
1802 if (counter == 0) // if counter == 0 then we found nth
1803 SendSysMessage(LANG_COMMAND_NOSPELLFOUND);
1804 return true;
1807 bool ChatHandler::HandleLookupQuestCommand(const char* args)
1809 if(!*args)
1810 return false;
1811 std::string namepart = args;
1812 sDatabase.escape_string(namepart);
1814 QueryResult *result=sDatabase.PQuery("SELECT `entry`,`Title` FROM `quest_template` WHERE `Title` LIKE \"%%%s%%\" ORDER BY `entry`",namepart.c_str());
1815 if(!result)
1817 SendSysMessage(LANG_COMMAND_NOQUESTFOUND);
1818 return true;
1823 Field *fields = result->Fetch();
1824 uint16 id = fields[0].GetUInt16();
1825 std::string name = fields[1].GetCppString();
1827 QuestStatus status = m_session->GetPlayer()->GetQuestStatus(id);
1829 char const* statusStr = "";
1830 if(status == QUEST_STATUS_COMPLETE)
1832 if(m_session->GetPlayer()->GetQuestRewardStatus(id))
1833 statusStr = LANG_COMMAND_QUEST_REWARDED;
1834 else
1835 statusStr = LANG_COMMAND_QUEST_COMPLETE;
1837 else if(status == QUEST_STATUS_INCOMPLETE)
1838 statusStr = LANG_COMMAND_QUEST_ACTIVE;
1840 PSendSysMessage(LANG_QUEST_LIST "%s",id,id,name.c_str(),(status == QUEST_STATUS_COMPLETE ? LANG_COMPLETE : (status == QUEST_STATUS_INCOMPLETE ? LANG_ACTIVE : "") ));
1841 } while (result->NextRow());
1843 delete result;
1844 return true;
1847 bool ChatHandler::HandleLookupCreatureCommand(const char* args)
1849 if(!*args)
1850 return false;
1852 std::string namepart = args;
1853 sDatabase.escape_string(namepart);
1855 QueryResult *result=sDatabase.PQuery("SELECT `entry`,`name` FROM `creature_template` WHERE `name` LIKE \"%%%s%%\"",namepart.c_str());
1856 if(!result)
1858 SendSysMessage(LANG_COMMAND_NOCREATUREFOUND);
1859 return true;
1864 Field *fields = result->Fetch();
1865 uint16 id = fields[0].GetUInt16();
1866 std::string name = fields[1].GetCppString();
1867 PSendSysMessage(LANG_CREATURE_ENTRY_LIST,id,id,name.c_str());
1868 } while (result->NextRow());
1870 delete result;
1871 return true;
1874 bool ChatHandler::HandleLookupObjectCommand(const char* args)
1876 if(!*args)
1877 return false;
1879 std::string namepart = args;
1880 sDatabase.escape_string(namepart);
1882 QueryResult *result=sDatabase.PQuery("SELECT `entry`,`name` FROM `gameobject_template` WHERE `name` LIKE \"%%%s%%\"",namepart.c_str());
1883 if(!result)
1885 SendSysMessage(LANG_COMMAND_NOGAMEOBJECTFOUND);
1886 return true;
1891 Field *fields = result->Fetch();
1892 uint32 id = fields[0].GetUInt32();
1893 std::string name = fields[1].GetCppString();
1894 PSendSysMessage(LANG_GO_ENTRY_LIST,id,id,name.c_str());
1895 } while (result->NextRow());
1897 delete result;
1898 return true;
1901 bool ChatHandler::HandleCreateGuildCommand(const char* args)
1903 Guild *guild;
1904 Player * player;
1905 char *lname,*gname;
1906 std::string guildname;
1908 if (!*args)
1909 return false;
1911 lname = strtok((char*)args, " ");
1912 gname = strtok(NULL, "");
1914 if(!lname)
1915 return false;
1916 else if(!gname)
1918 SendSysMessage(LANG_INSERT_GUILD_NAME);
1919 return true;
1922 guildname = gname;
1923 player = ObjectAccessor::Instance().FindPlayerByName(lname);
1925 if(!player)
1927 SendSysMessage(LANG_PLAYER_NOT_FOUND);
1928 return true;
1931 if(!player->GetGuildId())
1933 guild = new Guild;
1934 if(!guild->create(player->GetGUID(),guildname))
1936 delete guild;
1937 SendSysMessage(LANG_GUILD_NOT_CREATED);
1938 return true;
1941 objmgr.AddGuild(guild);
1943 else
1944 SendSysMessage(LANG_PLAYER_IN_GUILD);
1946 return true;
1949 //float max_creature_distance = 160;
1951 bool ChatHandler::HandleGetDistanceCommand(const char* args)
1953 Unit* pUnit = getSelectedUnit();
1955 if(!pUnit)
1957 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
1958 return true;
1961 PSendSysMessage(LANG_DISTANCE, m_session->GetPlayer()->GetDistanceSq(pUnit));
1963 return true;
1966 bool ChatHandler::HandleObjectCommand(const char* args)
1968 if (!*args)
1969 return false;
1971 uint32 display_id = atoi((char*)args);
1973 char* safe = strtok((char*)args, " ");
1975 Player *chr = m_session->GetPlayer();
1976 float x = chr->GetPositionX();
1977 float y = chr->GetPositionY();
1978 float z = chr->GetPositionZ();
1979 float o = chr->GetOrientation();
1981 GameObject* pGameObj = new GameObject(chr);
1982 if(!pGameObj->Create(objmgr.GenerateLowGuid(HIGHGUID_GAMEOBJECT), display_id, chr->GetMapId(), x, y, z, o, 0, 0, 0, 0, 0, 0))
1984 delete pGameObj;
1985 return false;
1987 sLog.outDebug(LANG_ADD_OBJ_LV3);
1989 if(strcmp(safe,"true") == 0)
1990 pGameObj->SaveToDB();
1992 MapManager::Instance().GetMap(pGameObj->GetMapId(), pGameObj)->Add(pGameObj);
1994 return true;
1997 // FIX-ME!!!
1999 bool ChatHandler::HandleAddWeaponCommand(const char* args)
2001 /*if (!*args)
2002 return false;
2004 uint64 guid = m_session->GetPlayer()->GetSelection();
2005 if (guid == 0)
2007 SendSysMessage(LANG_NO_SELECTION);
2008 return true;
2011 Creature *pCreature = ObjectAccessor::Instance().GetCreature(*m_session->GetPlayer(), guid);
2013 if(!pCreature)
2015 SendSysMessage(LANG_SELECT_CREATURE);
2016 return true;
2019 char* pSlotID = strtok((char*)args, " ");
2020 if (!pSlotID)
2021 return false;
2023 char* pItemID = strtok(NULL, " ");
2024 if (!pItemID)
2025 return false;
2027 uint32 ItemID = atoi(pItemID);
2028 uint32 SlotID = atoi(pSlotID);
2030 ItemPrototype* tmpItem = objmgr.GetItemPrototype(ItemID);
2032 bool added = false;
2033 if(tmpItem)
2035 switch(SlotID)
2037 case 1:
2038 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY, ItemID);
2039 added = true;
2040 break;
2041 case 2:
2042 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_01, ItemID);
2043 added = true;
2044 break;
2045 case 3:
2046 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_02, ItemID);
2047 added = true;
2048 break;
2049 default:
2050 PSendSysMessage(LANG_ITEM_SLOT_NOT_EXIST,SlotID);
2051 added = false;
2052 break;
2054 if(added)
2056 PSendSysMessage(LANG_ITEM_ADDED_TO_SLOT,ItemID,tmpItem->Name1,SlotID);
2059 else
2061 PSendSysMessage(LANG_ITEM_NOT_FOUND,ItemID);
2062 return true;
2065 return true;
2068 bool ChatHandler::HandleGameObjectCommand(const char* args)
2070 if (!*args)
2071 return false;
2074 char* pParam1 = strtok((char*)args, " ");
2075 uint32 id = atoi((char*)pParam1);
2076 if(!id)
2077 return false;
2079 char* lootID = strtok(NULL, " ");
2080 char* spawntimeSecs = strtok(NULL, " ");
2082 const GameObjectInfo *goI = objmgr.GetGameObjectInfo(id);
2084 if (!goI)
2086 PSendSysMessage(LANG_GAMEOBJECT_NOT_EXIST,id);
2087 return false;
2090 Player *chr = m_session->GetPlayer();
2091 float x = float(chr->GetPositionX());
2092 float y = float(chr->GetPositionY());
2093 float z = float(chr->GetPositionZ());
2094 float o = float(chr->GetOrientation());
2096 float rot2 = sin(o/2);
2097 float rot3 = cos(o/2);
2099 GameObject* pGameObj = new GameObject(chr);
2100 uint32 lowGUID = objmgr.GenerateLowGuid(HIGHGUID_GAMEOBJECT);
2102 if(!pGameObj->Create(lowGUID, goI->id, chr->GetMapId(), x, y, z, o, 0, 0, rot2, rot3, 0, 0))
2104 delete pGameObj;
2105 return false;
2107 //pGameObj->SetZoneId(chr->GetZoneId());
2108 pGameObj->SetMapId(chr->GetMapId());
2109 //pGameObj->SetNameId(id);
2110 sLog.outDebug(LANG_GAMEOBJECT_CURRENT, goI->name, lowGUID, x, y, z, o);
2112 if( lootID )
2114 uint32 value = atoi((char*)lootID);
2115 pGameObj->lootid = value;
2116 //sLog.outDebug("*** LOOT: %d", value);
2119 if( spawntimeSecs )
2121 uint32 value = atoi((char*)spawntimeSecs);
2122 pGameObj->SetRespawnTime(value);
2123 //sLog.outDebug("*** spawntimeSecs: %d", value);
2126 pGameObj->SaveToDB();
2127 MapManager::Instance().GetMap(pGameObj->GetMapId(), pGameObj)->Add(pGameObj);
2129 PSendSysMessage(LANG_GAMEOBJECT_ADD,id,goI->name,x,y,z);
2131 return true;
2134 bool ChatHandler::HandleAnimCommand(const char* args)
2136 if (!*args)
2137 return false;
2139 uint32 anim_id = atoi((char*)args);
2141 WorldPacket data( SMSG_EMOTE, (8+4) );
2142 data << anim_id << m_session->GetPlayer( )->GetGUID();
2143 WPAssert(data.size() == 12);
2144 MapManager::Instance().GetMap(m_session->GetPlayer()->GetMapId(), m_session->GetPlayer())->MessageBoardcast(m_session->GetPlayer(), &data, true);
2145 return true;
2148 bool ChatHandler::HandleStandStateCommand(const char* args)
2150 if (!*args)
2151 return false;
2153 uint32 anim_id = atoi((char*)args);
2154 m_session->GetPlayer( )->SetUInt32Value( UNIT_NPC_EMOTESTATE , anim_id );
2156 return true;
2159 bool ChatHandler::HandleDieCommand(const char* args)
2161 Unit* target = getSelectedUnit();
2163 if(!target)
2165 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
2166 return true;
2169 if( target->isAlive() )
2171 m_session->GetPlayer()->DealDamage(target, target->GetHealth(), NULL, DIRECT_DAMAGE, 0, NULL, 0, false);
2174 return true;
2177 bool ChatHandler::HandleReviveCommand(const char* args)
2179 Player* SelectedPlayer = NULL;
2181 if (*args)
2183 std::string name = args;
2184 normalizePlayerName(name);
2185 SelectedPlayer = objmgr.GetPlayer(name.c_str());
2187 else
2188 SelectedPlayer = getSelectedPlayer();
2190 if(!SelectedPlayer)
2192 PSendSysMessage(LANG_NO_CHAR_SELECTED);
2193 return true;
2196 SelectedPlayer->ResurrectPlayer(0.5f);
2197 SelectedPlayer->SpawnCorpseBones();
2198 SelectedPlayer->SaveToDB();
2199 return true;
2202 bool ChatHandler::HandleMorphCommand(const char* args)
2204 if (!*args)
2205 return false;
2207 uint16 display_id = (uint16)atoi((char*)args);
2209 Unit *target = getSelectedUnit();
2210 if(!target)
2211 target = m_session->GetPlayer();
2213 target->SetUInt32Value(UNIT_FIELD_DISPLAYID, display_id);
2215 return true;
2218 bool ChatHandler::HandleAuraCommand(const char* args)
2220 char* px = strtok((char*)args, " ");
2221 if (!px)
2222 return false;
2224 Unit *target = getSelectedUnit();
2225 if(!target)
2227 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
2228 return true;
2231 uint32 spellID = (uint32)atoi(px);
2232 SpellEntry const *spellInfo = sSpellStore.LookupEntry( spellID );
2233 if(spellInfo)
2235 for(uint32 i = 0;i<3;i++)
2237 uint8 eff = spellInfo->Effect[i];
2238 if (eff>=TOTAL_SPELL_EFFECTS)
2239 continue;
2240 if (eff == SPELL_EFFECT_APPLY_AURA || eff == SPELL_EFFECT_APPLY_AREA_AURA || eff == SPELL_EFFECT_PERSISTENT_AREA_AURA)
2242 Aura *Aur = new Aura(spellInfo, i, target);
2243 target->AddAura(Aur);
2248 return true;
2251 bool ChatHandler::HandleUnAuraCommand(const char* args)
2253 char* px = strtok((char*)args, " ");
2254 if (!px)
2255 return false;
2257 Unit *target = getSelectedUnit();
2258 if(!target)
2260 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
2261 return true;
2264 std::string argstr = args;
2265 if (argstr == "all")
2267 target->RemoveAllAuras();
2268 return true;
2271 uint32 spellID = (uint32)atoi(px);
2272 target->RemoveAurasDueToSpell(spellID);
2274 return true;
2277 bool ChatHandler::HandleLinkGraveCommand(const char* args)
2279 if(!*args)
2280 return false;
2282 char* px = strtok((char*)args, " ");
2283 if (!px)
2284 return false;
2286 uint32 g_id = (uint32)atoi(px);
2288 uint32 g_team;
2290 char* px2 = strtok(NULL, " ");
2292 if (!px2)
2293 g_team = 0;
2294 else if (strncmp(px2,"horde",6)==0)
2295 g_team = HORDE;
2296 else if (strncmp(px2,"alliance",9)==0)
2297 g_team = ALLIANCE;
2298 else
2299 return false;
2301 WorldSafeLocsEntry const* graveyard = sWorldSafeLocsStore.LookupEntry(g_id);
2303 if(!graveyard )
2305 PSendSysMessage(LANG_COMMAND_GRAVEYARDNOEXIST, g_id);
2306 return true;
2309 Player* player = m_session->GetPlayer();
2311 QueryResult *result = sDatabase.PQuery(
2312 "SELECT `id` FROM `game_graveyard_zone` WHERE `id` = %u AND `ghost_map` = %u AND `ghost_zone` = '%u' AND (`faction` = %u OR `faction` = 0 )",
2313 g_id,player->GetMapId(),player->GetZoneId(),g_team);
2315 if(result)
2317 delete result;
2319 PSendSysMessage(LANG_COMMAND_GRAVEYARDALRLINKED, g_id,player->GetZoneId());
2321 else
2323 sDatabase.PExecuteLog("INSERT INTO `game_graveyard_zone` ( `id`,`ghost_map`,`ghost_zone`,`faction`) VALUES ('%u', '%u', '%u','%u')",
2324 g_id,player->GetMapId(),player->GetZoneId(),g_team);
2326 PSendSysMessage(LANG_COMMAND_GRAVEYARDLINKED, g_id,player->GetZoneId());
2328 return true;
2331 bool ChatHandler::HandleNearGraveCommand(const char* args)
2333 uint32 g_team;
2335 if(!*args)
2336 g_team = 0;
2337 else if (strncmp((char*)args,"horde",6)==0)
2338 g_team = HORDE;
2339 else if (strncmp((char*)args,"alliance",9)==0)
2340 g_team = ALLIANCE;
2341 else
2342 return false;
2344 Player* player = m_session->GetPlayer();
2346 WorldSafeLocsEntry const* graveyard = objmgr.GetClosestGraveYard(
2347 player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(),player->GetMapId(),player->GetTeam());
2349 if(graveyard)
2351 uint32 g_id = graveyard->ID;
2353 QueryResult *result = sDatabase.PQuery("SELECT `faction` FROM `game_graveyard_zone` WHERE `id` = %u",g_id);
2354 if (!result)
2356 PSendSysMessage(LANG_COMMAND_GRAVEYARDERROR,g_id);
2357 return true;
2360 Field *fields = result->Fetch();
2361 g_team = fields[0].GetUInt32();
2362 delete result;
2364 std::string team_name = LANG_COMMAND_GRAVEYARD_NOTEAM;
2366 if(g_team == 0)
2367 team_name = LANG_COMMAND_GRAVEYARD_ANY;
2368 else if(g_team == HORDE)
2369 team_name = LANG_COMMAND_GRAVEYARD_HORDE;
2370 else if(g_team == ALLIANCE)
2371 team_name = LANG_COMMAND_GRAVEYARD_ALLIANCE;
2373 PSendSysMessage(LANG_COMMAND_GRAVEYARDNEAREST, g_id,team_name.c_str(),player->GetZoneId());
2375 else
2377 std::string team_name;
2379 if(g_team == 0)
2380 team_name = LANG_COMMAND_GRAVEYARD_ANY;
2381 else if(g_team == HORDE)
2382 team_name = LANG_COMMAND_GRAVEYARD_HORDE;
2383 else if(g_team == ALLIANCE)
2384 team_name = LANG_COMMAND_GRAVEYARD_ALLIANCE;
2386 if(g_team == ~uint32(0))
2387 PSendSysMessage(LANG_COMMAND_ZONENOGRAVEYARDS, player->GetZoneId());
2388 else
2389 PSendSysMessage(LANG_COMMAND_ZONENOGRAFACTION, player->GetZoneId(),team_name.c_str());
2392 return true;
2395 bool ChatHandler::HandleSpawnTransportCommand(const char* args)
2397 return true;
2400 bool ChatHandler::HandleEmoteCommand(const char* args)
2402 uint32 emote = atoi((char*)args);
2404 Creature* target = getSelectedCreature();
2405 if(!target)
2407 PSendSysMessage(LANG_SELECT_CREATURE);
2408 return true;
2411 target->SetUInt32Value(UNIT_NPC_EMOTESTATE,emote);
2413 return true;
2416 bool ChatHandler::HandleNpcInfoCommand(const char* args)
2418 Creature* target = getSelectedCreature();
2420 if(!target)
2422 SendSysMessage(LANG_SELECT_CREATURE);
2423 return true;
2426 uint32 faction = target->getFaction();
2427 uint32 npcflags = target->GetUInt32Value(UNIT_NPC_FLAGS);
2428 uint32 displayid = target->GetUInt32Value(UNIT_FIELD_DISPLAYID);
2429 uint32 nativeid = target->GetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID);
2430 uint32 Entry = target->GetUInt32Value(OBJECT_FIELD_ENTRY);
2431 CreatureInfo const* cInfo = target->GetCreatureInfo();
2433 PSendSysMessage(LANG_NPCINFO_CHAR, target->GetDBTableGUIDLow(), faction, npcflags, Entry, displayid, nativeid);
2434 PSendSysMessage(LANG_NPCINFO_LEVEL, target->getLevel());
2435 PSendSysMessage(LANG_NPCINFO_HEALTH,target->GetUInt32Value(UNIT_FIELD_BASE_HEALTH), target->GetMaxHealth(), target->GetHealth());
2436 PSendSysMessage(LANG_NPCINFO_FLAGS, target->GetUInt32Value(UNIT_FIELD_FLAGS), target->GetUInt32Value(UNIT_DYNAMIC_FLAGS), target->getFaction());
2437 PSendSysMessage(LANG_NPCINFO_LOOT, cInfo->lootid,cInfo->pickpocketLootId,cInfo->SkinLootId);
2438 PSendSysMessage(LANG_NPCINFO_DUNGEON_ID, target->GetInstanceId());
2440 PSendSysMessage(LANG_NPCINFO_POSITION,float(target->GetPositionX()), float(target->GetPositionY()), float(target->GetPositionZ()));
2442 if ((npcflags & UNIT_NPC_FLAG_VENDOR) )
2444 SendSysMessage(LANG_NPCINFO_VENDOR);
2446 if ((npcflags & UNIT_NPC_FLAG_TRAINER) )
2448 SendSysMessage(LANG_NPCINFO_TRAINER);
2451 return true;
2454 bool ChatHandler::HandleNpcInfoSetCommand(const char* args)
2456 uint32 entry = 0, testvalue = 0;
2458 Creature* target = getSelectedCreature();
2459 if(!target)
2461 PSendSysMessage(LANG_SELECT_CREATURE);
2462 return true;
2465 if(!args)
2466 return true;
2468 //m_session->GetPlayer( )->SetUInt32Value(PLAYER_FLAGS, (uint32)8);
2470 testvalue = uint32(atoi((char*)args));
2472 entry = target->GetUInt32Value( OBJECT_FIELD_ENTRY );
2474 //m_session->SendTestCreatureQueryOpcode( entry, target->GetGUID(), testvalue );
2476 return true;
2479 bool ChatHandler::HandleExploreCheatCommand(const char* args)
2481 if (!*args)
2482 return false;
2484 int flag = atoi((char*)args);
2486 Player *chr = getSelectedPlayer();
2487 if (chr == NULL)
2489 SendSysMessage(LANG_NO_CHAR_SELECTED);
2490 return true;
2493 if (flag != 0)
2495 PSendSysMessage(LANG_YOU_SET_EXPLORE_ALL, chr->GetName());
2497 else
2499 PSendSysMessage(LANG_YOU_SET_EXPLORE_NOTHING, chr->GetName());
2502 char buf[256];
2504 if (flag != 0)
2506 sprintf((char*)buf,LANG_YOURS_EXPLORE_SET_ALL,
2507 m_session->GetPlayer()->GetName());
2509 else
2511 sprintf((char*)buf,LANG_YOURS_EXPLORE_SET_NOTHING,
2512 m_session->GetPlayer()->GetName());
2515 WorldPacket data;
2516 FillSystemMessageData(&data, m_session, buf);
2517 chr->GetSession()->SendPacket(&data);
2519 for (uint8 i=0; i<64; i++)
2521 if (flag != 0)
2523 m_session->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1+i,0xFFFFFFFF);
2525 else
2527 m_session->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1+i,0);
2531 return true;
2534 bool ChatHandler::HandleHoverCommand(const char* args)
2536 char* px = strtok((char*)args, " ");
2537 uint32 flag;
2538 if (!px)
2539 flag = 1;
2540 else
2541 flag = atoi(px);
2543 m_session->GetPlayer()->SetHover(flag);
2545 if (flag)
2546 SendSysMessage(LANG_HOVER_ENABLED);
2547 else
2548 PSendSysMessage(LANG_HOVER_DISABLED);
2550 return true;
2553 bool ChatHandler::HandleLevelUpCommand(const char* args)
2555 char* px = strtok((char*)args, " ");
2556 char* py = strtok((char*)NULL, " ");
2558 // command format parsing
2559 char* pname = (char*)NULL;
2560 int addlevel = 1;
2562 if(px && py) // .levelup name level
2564 addlevel = atoi(py);
2565 pname = px;
2567 else if(px && !py) // .levelup name OR .levelup level
2569 if(isalpha(px[0])) // .levelup name
2570 pname = px;
2571 else // .levelup level
2572 addlevel = atoi(px);
2574 // else .levelup - nothing do for prepering
2576 // player
2577 Player *chr = NULL;
2578 uint64 chr_guid = 0;
2580 if(pname) // player by name
2582 std::string name = pname;
2583 normalizePlayerName(name);
2585 chr = objmgr.GetPlayer(name.c_str());
2586 if(!chr) // not in game
2588 chr_guid = objmgr.GetPlayerGUIDByName(name);
2589 if (chr_guid == 0)
2591 SendSysMessage(LANG_PLAYER_NOT_FOUND);
2592 return true;
2596 else // player by selection
2598 chr = getSelectedPlayer();
2600 if (chr == NULL)
2602 SendSysMessage(LANG_NO_CHAR_SELECTED);
2603 return true;
2607 assert(chr || chr_guid);
2609 int32 oldlevel = chr ? chr->getLevel() : Player::GetUInt32ValueFromDB(UNIT_FIELD_LEVEL,chr_guid);
2610 int32 newlevel = oldlevel + addlevel;
2611 if(newlevel < 1)
2612 newlevel = 1;
2613 if(newlevel > 255) // hardcoded maximum level
2614 newlevel = 255;
2616 if(chr)
2618 chr->InitStatsForLevel(newlevel);
2619 chr->InitTalentForLevel();
2620 chr->SetUInt32Value(PLAYER_XP,0);
2622 WorldPacket data;
2624 if(oldlevel == newlevel)
2625 FillSystemMessageData(&data, chr->GetSession(), LANG_YOURS_LEVEL_PROGRESS_RESET);
2626 else
2627 if(oldlevel < newlevel)
2628 FillSystemMessageData(&data, chr->GetSession(), fmtstring(LANG_YOURS_LEVEL_UP,newlevel-oldlevel));
2629 else
2630 if(oldlevel > newlevel)
2631 FillSystemMessageData(&data, chr->GetSession(), fmtstring(LANG_YOURS_LEVEL_DOWN,newlevel-oldlevel));
2633 chr->GetSession()->SendPacket( &data );
2635 // give level to summoned pet
2636 Pet* pet = chr->GetPet();
2637 if(pet && pet->getPetType()==SUMMON_PET)
2638 pet->GivePetLevel(newlevel);
2640 else
2642 // update levle and XP at level, all other will be updated at loading
2643 std::vector<std::string> values;
2644 Player::LoadValuesArrayFromDB(values,chr_guid);
2645 Player::SetUInt32ValueInArray(values,UNIT_FIELD_LEVEL,newlevel);
2646 Player::SetUInt32ValueInArray(values,PLAYER_XP,0);
2647 Player::SaveValuesArrayInDB(values,chr_guid);
2650 return true;
2653 bool ChatHandler::HandleShowAreaCommand(const char* args)
2655 if (!*args)
2656 return false;
2658 int area = atoi((char*)args);
2660 Player *chr = getSelectedPlayer();
2661 if (chr == NULL)
2663 SendSysMessage(LANG_NO_CHAR_SELECTED);
2664 return true;
2667 int offset = area / 32;
2668 uint32 val = (uint32)(1 << (area % 32));
2670 if(offset >= 64)
2672 SendSysMessage(LANG_BAD_VALUE);
2673 return true;
2676 uint32 currFields = chr->GetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset);
2677 chr->SetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset, (uint32)(currFields | val));
2679 SendSysMessage(LANG_EXPLORE_AREA);
2680 return true;
2683 bool ChatHandler::HandleHideAreaCommand(const char* args)
2685 if (!*args)
2686 return false;
2688 int area = atoi((char*)args);
2690 Player *chr = getSelectedPlayer();
2691 if (chr == NULL)
2693 SendSysMessage(LANG_NO_CHAR_SELECTED);
2694 return true;
2697 int offset = area / 32;
2698 uint32 val = (uint32)(1 << (area % 32));
2700 if(offset >= 64)
2702 SendSysMessage(LANG_BAD_VALUE);
2703 return true;
2706 uint32 currFields = chr->GetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset);
2707 chr->SetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset, (uint32)(currFields ^ val));
2709 SendSysMessage(LANG_UNEXPLORE_AREA);
2710 return true;
2713 bool ChatHandler::HandleUpdate(const char* args)
2715 if(!*args)
2716 return false;
2718 uint32 updateIndex;
2719 uint32 value;
2721 char* pUpdateIndex = strtok((char*)args, " ");
2723 Unit* chr = getSelectedUnit();
2724 if (chr == NULL)
2726 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
2727 return true;
2730 if(!pUpdateIndex)
2732 return true;
2734 updateIndex = atoi(pUpdateIndex);
2735 //check updateIndex
2736 if(chr->GetTypeId() == TYPEID_PLAYER)
2738 if (updateIndex>=PLAYER_END) return true;
2740 else
2742 if (updateIndex>=UNIT_END) return true;
2745 char* pvalue = strtok(NULL, " ");
2746 if (!pvalue)
2748 value=chr->GetUInt32Value(updateIndex);
2750 PSendSysMessage(LANG_UPDATE, chr->GetGUIDLow(),updateIndex,value);
2751 return true;
2754 value=atoi(pvalue);
2756 PSendSysMessage(LANG_UPDATE_CHANGE, chr->GetGUIDLow(),updateIndex,value);
2758 chr->SetUInt32Value(updateIndex,value);
2760 return true;
2763 bool ChatHandler::HandleBankCommand(const char* args)
2765 m_session->SendShowBank( m_session->GetPlayer()->GetGUID() );
2767 return true;
2770 bool ChatHandler::HandleChangeWeather(const char* args)
2772 if(!*args)
2773 return false;
2775 //Weather is OFF
2776 if (sWorld.getConfig(CONFIG_WEATHER) == 0)
2778 SendSysMessage(LANG_WEATHER_DISABLED);
2779 return true;
2782 //*Change the weather of a cell
2783 char* px = strtok((char*)args, " ");
2784 char* py = strtok(NULL, " ");
2786 if (!px || !py)
2787 return false;
2789 uint32 type = (uint32)atoi(px); //0 to 3, 0: fine, 1: rain, 2: snow, 3: sand
2790 float grade = (float)atof(py); //0 to 1, sending -1 is instand good weather
2792 Player *player = m_session->GetPlayer();
2793 uint32 zoneid = player->GetZoneId();
2795 Weather* wth = sWorld.FindWeather(zoneid);
2797 if(!wth)
2798 wth = sWorld.AddWeather(zoneid);
2799 if(!wth)
2801 SendSysMessage(LANG_NO_WEATHER);
2802 return true;
2805 wth->SetWeather(type, grade);
2807 return true;
2810 bool ChatHandler::HandleSetValue(const char* args)
2812 if(!*args)
2813 return false;
2815 char* px = strtok((char*)args, " ");
2816 char* py = strtok(NULL, " ");
2817 char* pz = strtok(NULL, " ");
2819 if (!px || !py)
2820 return false;
2822 Unit* target = getSelectedUnit();
2823 if(!target)
2825 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
2826 return true;
2829 uint64 guid = target->GetGUID();
2831 uint32 Opcode = (uint32)atoi(px);
2832 if(Opcode >= target->GetValuesCount())
2834 PSendSysMessage(LANG_TOO_BIG_INDEX, Opcode, GUID_LOPART(guid), target->GetValuesCount());
2835 return false;
2837 uint32 iValue;
2838 float fValue;
2839 bool isint32 = true;
2840 if(pz)
2841 isint32 = (bool)atoi(pz);
2842 if(isint32)
2844 iValue = (uint32)atoi(py);
2845 sLog.outDebug( LANG_SET_UINT, GUID_LOPART(guid), Opcode, iValue);
2846 target->SetUInt32Value( Opcode , iValue );
2847 PSendSysMessage(LANG_SET_UINT_FIELD, GUID_LOPART(guid), Opcode,iValue);
2849 else
2851 fValue = (float)atof(py);
2852 sLog.outDebug( LANG_SET_FLOAT, GUID_LOPART(guid), Opcode, fValue);
2853 target->SetFloatValue( Opcode , fValue );
2854 PSendSysMessage(LANG_SET_FLOAT_FIELD, GUID_LOPART(guid), Opcode,fValue);
2857 return true;
2860 bool ChatHandler::HandleGetValue(const char* args)
2862 if(!*args)
2863 return false;
2865 char* px = strtok((char*)args, " ");
2866 char* pz = strtok(NULL, " ");
2868 if (!px)
2869 return false;
2871 Unit* target = getSelectedUnit();
2872 if(!target)
2874 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
2875 return true;
2878 uint64 guid = target->GetGUID();
2880 uint32 Opcode = (uint32)atoi(px);
2881 if(Opcode >= target->GetValuesCount())
2883 PSendSysMessage(LANG_TOO_BIG_INDEX, Opcode, GUID_LOPART(guid), target->GetValuesCount());
2884 return false;
2886 uint32 iValue;
2887 float fValue;
2888 bool isint32 = true;
2889 if(pz)
2890 isint32 = (bool)atoi(pz);
2892 if(isint32)
2894 iValue = target->GetUInt32Value( Opcode );
2895 sLog.outDebug( LANG_GET_UINT, GUID_LOPART(guid), Opcode, iValue);
2896 PSendSysMessage(LANG_GET_UINT_FIELD, GUID_LOPART(guid), Opcode, iValue);
2898 else
2900 fValue = target->GetFloatValue( Opcode );
2901 sLog.outDebug( LANG_GET_FLOAT, GUID_LOPART(guid), Opcode, fValue);
2902 PSendSysMessage(LANG_GET_FLOAT_FIELD, GUID_LOPART(guid), Opcode, fValue);
2905 return true;
2908 bool ChatHandler::HandleSet32Bit(const char* args)
2910 if(!*args)
2911 return false;
2913 char* px = strtok((char*)args, " ");
2914 char* py = strtok(NULL, " ");
2916 if (!px || !py)
2917 return false;
2919 uint32 Opcode = (uint32)atoi(px);
2920 uint32 Value = (uint32)atoi(py);
2921 if (Value > 32) //uint32 = 32 bits
2922 return false;
2924 sLog.outDebug( LANG_SET_32BIT , Opcode, Value);
2926 m_session->GetPlayer( )->SetUInt32Value( Opcode , 2^Value );
2928 PSendSysMessage(LANG_SET_32BIT_FIELD, Opcode,1);
2929 return true;
2932 bool ChatHandler::HandleMod32Value(const char* args)
2934 if(!*args)
2935 return false;
2937 char* px = strtok((char*)args, " ");
2938 char* py = strtok(NULL, " ");
2940 if (!px || !py)
2941 return false;
2943 uint32 Opcode = (uint32)atoi(px);
2944 int Value = atoi(py);
2946 if(Opcode >= m_session->GetPlayer()->GetValuesCount())
2948 PSendSysMessage(LANG_TOO_BIG_INDEX, Opcode, m_session->GetPlayer()->GetGUIDLow(), m_session->GetPlayer( )->GetValuesCount());
2949 return false;
2952 sLog.outDebug( LANG_CHANGE_32BIT , Opcode, Value);
2954 int CurrentValue = (int)m_session->GetPlayer( )->GetUInt32Value( Opcode );
2956 CurrentValue += Value;
2957 m_session->GetPlayer( )->SetUInt32Value( Opcode , (uint32)CurrentValue );
2959 PSendSysMessage(LANG_CHANGE_32BIT_FIELD, Opcode,CurrentValue);
2961 return true;
2964 bool ChatHandler::HandleAddTeleCommand(const char * args)
2966 if(!*args)
2967 return false;
2968 QueryResult *result;
2969 Player *player=m_session->GetPlayer();
2970 if (!player) return false;
2972 std::string name = args;
2973 sDatabase.escape_string(name);
2974 result = sDatabase.PQuery("SELECT `id` FROM `game_tele` WHERE `name` = '%s'",name.c_str());
2975 if (result)
2977 SendSysMessage(LANG_COMMAND_TP_ALREADYEXIST);
2978 delete result;
2979 return true;
2982 float x = player->GetPositionX();
2983 float y = player->GetPositionY();
2984 float z = player->GetPositionZ();
2985 float ort = player->GetOrientation();
2986 int mapid = player->GetMapId();
2988 if(sDatabase.PExecuteLog("INSERT INTO `game_tele` (`position_x`,`position_y`,`position_z`,`orientation`,`map`,`name`) VALUES (%f,%f,%f,%f,%d,'%s')",x,y,z,ort,mapid,name.c_str()))
2990 SendSysMessage(LANG_COMMAND_TP_ADDED);
2992 else
2993 SendSysMessage(LANG_COMMAND_TP_ADDEDERR);
2995 return true;
2998 bool ChatHandler::HandleDelTeleCommand(const char * args)
3000 if(!*args)
3001 return false;
3003 std::string name = args;
3004 sDatabase.escape_string(name);
3006 QueryResult *result=sDatabase.PQuery("SELECT `id` FROM `game_tele` WHERE `name` = '%s'",name.c_str());
3007 if (!result)
3009 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
3010 return true;
3012 delete result;
3014 if(sDatabase.PExecuteLog("DELETE FROM `game_tele` WHERE `name` = '%s'",name.c_str()))
3016 SendSysMessage(LANG_COMMAND_TP_DELETED);
3018 else
3019 SendSysMessage(LANG_COMMAND_TP_DELETEERR);
3020 return true;
3023 bool ChatHandler::HandleListAurasCommand (const char * args)
3025 Unit *unit = getSelectedUnit();
3026 if(!unit)
3028 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3029 return true;
3032 Unit::AuraMap& uAuras = unit->GetAuras();
3033 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURAS, uAuras.size());
3034 for (Unit::AuraMap::iterator itr = uAuras.begin(); itr != uAuras.end(); ++itr)
3036 PSendSysMessage(LANG_COMMAND_TARGET_AURADETAIL, itr->second->GetId(), itr->second->GetEffIndex(), itr->second->GetModifier()->m_auraname, itr->second->GetAuraDuration(), itr->second->GetSpellProto()->SpellName[0]);
3038 for (int i = 0; i < TOTAL_AURAS; i++)
3040 Unit::AuraList& uAuraList = unit->GetAurasByType(i);
3041 if (!uAuraList.size()) continue;
3042 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURATYPE, uAuraList.size(), i);
3043 for (Unit::AuraList::iterator itr = uAuraList.begin(); itr != uAuraList.end(); ++itr)
3045 PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE, (*itr)->GetId(), (*itr)->GetEffIndex(), (*itr)->GetSpellProto()->SpellName[0]);
3048 return true;
3051 bool ChatHandler::HandleResetCommand (const char * args)
3053 if(!*args)
3054 return false;
3056 char* arg = strtok((char*)args, " ");
3057 std::string argstr = arg;
3058 char* pName = strtok(NULL, "");
3059 Player *player = NULL;
3060 if (pName)
3062 std::string name = pName;
3063 normalizePlayerName(name);
3064 uint64 guid = objmgr.GetPlayerGUIDByName(name.c_str());
3065 player = objmgr.GetPlayer(guid);
3067 else
3068 player = getSelectedPlayer();
3070 if(!player)
3072 SendSysMessage(LANG_NO_CHAR_SELECTED);
3073 return true;
3076 if (argstr == "stats" || argstr == "level")
3078 PlayerInfo const *info = objmgr.GetPlayerInfo(player->getRace(), player->getClass());
3079 if(!info) return false;
3081 ChrClassesEntry const* cEntry = sChrClassesStore.LookupEntry(player->getClass());
3082 if(!cEntry)
3084 sLog.outError("Class %u not found in DBÑ (Wrong DBC files?)",player->getClass());
3085 return true;
3088 uint8 powertype = cEntry->powerType;
3090 uint32 unitfield;
3091 if(powertype == POWER_RAGE)
3092 unitfield = 0x1100EE00;
3093 else if(powertype == POWER_ENERGY)
3094 unitfield = 0x00000000;
3095 else if(powertype == POWER_MANA)
3096 unitfield = 0x0000EE00;
3097 else
3099 sLog.outError("Invalid default powertype %u for player (class %u)",powertype,player->getClass());
3100 return true;
3103 // reset m_form if no aura
3104 if(!player->HasAuraType(SPELL_AURA_MOD_SHAPESHIFT))
3105 player->m_form = 0;
3107 player->SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS, 0.388999998569489f );
3108 player->SetFloatValue(UNIT_FIELD_COMBATREACH, 1.5f );
3110 player->setFactionForRace(player->getRace());
3112 player->SetUInt32Value(UNIT_FIELD_BYTES_0, ( ( player->getRace() ) | ( player->getClass() << 8 ) | ( player->getGender() << 16 ) | ( powertype << 24 ) ) );
3114 // reset only if player not in some form;
3115 if(!player->m_form)
3117 switch(player->getGender())
3119 case GENDER_FEMALE:
3120 player->SetUInt32Value(UNIT_FIELD_DISPLAYID, info->displayId_f);
3121 player->SetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID, info->displayId_f);
3122 break;
3123 case GENDER_MALE:
3124 player->SetUInt32Value(UNIT_FIELD_DISPLAYID, info->displayId_m);
3125 player->SetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID, info->displayId_m);
3126 break;
3127 default:
3128 break;
3132 // set UNIT_FIELD_BYTES_1 to init state but preserve m_form value
3133 player->SetUInt32Value(UNIT_FIELD_BYTES_1, player->m_form<<16 | unitfield );
3135 player->SetUInt32Value(UNIT_FIELD_BYTES_2, 0x2800 ); // 0x2800, 0x2801 2.0.8...
3136 player->SetUInt32Value(UNIT_FIELD_FLAGS , UNIT_FLAG_UNKNOWN1 );
3138 //-1 is default value
3139 player->SetUInt32Value(PLAYER_FIELD_WATCHED_FACTION_INDEX, uint32(-1));
3141 //player->SetUInt32Value(PLAYER_FIELD_BYTES, 0xEEE00000 );
3143 if(argstr == "level")
3145 player->InitStatsForLevel(1,false);
3146 player->InitTalentForLevel();
3147 player->SetUInt32Value(PLAYER_XP,0);
3149 // reset level to summoned pet
3150 Pet* pet = player->GetPet();
3151 if(pet && pet->getPetType()==SUMMON_PET)
3152 pet->InitStatsForLevel(1);
3154 else
3156 player->InitStatsForLevel(player->getLevel(),false);
3157 player->InitTalentForLevel();
3160 else if (argstr == "talents")
3161 player->resetTalents(true);
3162 else if (argstr == "spells")
3164 // make full copy of map (spells removed and marked as deleted at another spell remove
3165 // and we can't use original map for safe iterative with visit each spell at loop end
3166 PlayerSpellMap smap = player->GetSpellMap();
3168 for(PlayerSpellMap::const_iterator iter = smap.begin();iter != smap.end(); ++iter)
3169 player->removeSpell(iter->first); // only iter->first can be accessed, object by iter->second can be deleted already
3171 PlayerInfo const *info = objmgr.GetPlayerInfo(player->getRace(),player->getClass());
3172 std::list<CreateSpellPair>::const_iterator spell_itr;
3173 for (spell_itr = info->spell.begin(); spell_itr!=info->spell.end(); spell_itr++)
3175 uint16 tspell = spell_itr->first;
3176 if (tspell)
3178 sLog.outDebug("PLAYER: Adding initial spell, id = %u",tspell);
3179 player->learnSpell(tspell);
3183 else
3184 return false;
3186 return true;
3189 bool ChatHandler::HandleShutDownCommand(const char* args)
3191 if(!*args)
3192 return false;
3194 if(std::string(args)=="cancel")
3196 sWorld.ShutdownCancel();
3198 else
3200 int32 time = atoi(args);
3202 ///- Prevent interpret wrong arg value as 0 secs shutdown time
3203 if(time == 0 && (args[0]!='0' || args[1]!='\0') || time < 0)
3204 return false;
3206 sWorld.ShutdownServ(time);
3208 return true;
3211 bool ChatHandler::HandleIdleShutDownCommand(const char* args)
3213 if(!*args)
3214 return false;
3216 if(std::string(args)=="cancel")
3218 sWorld.ShutdownCancel();
3220 else
3222 int32 time = atoi(args);
3224 ///- Prevent interpret wrong arg value as 0 secs shutdown time
3225 if(time == 0 && (args[0]!='0' || args[1]!='\0') || time < 0)
3226 return false;
3228 sWorld.ShutdownServ(time,true);
3230 return true;
3233 bool ChatHandler::HandleAddQuest(const char* args)
3235 Player* player = getSelectedPlayer();
3236 if(!player)
3238 SendSysMessage(LANG_NO_CHAR_SELECTED);
3239 return true;
3242 // .addquest #entry'
3243 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
3244 char* cId = extractKeyFromLink((char*)args,"Hquest");
3245 if(!cId)
3246 return false;
3248 uint32 entry = atol(cId);
3250 ObjectMgr::QuestMap::iterator qIter = objmgr.QuestTemplates.find(entry);
3252 if(qIter == objmgr.QuestTemplates.end())
3254 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND,entry);
3255 return true;
3258 // check item starting quest (it can work incorrectly if added without item in inventory)
3259 QueryResult *result = sDatabase.PQuery("SELECT `entry` FROM `item_template` WHERE `startquest` = '%u' LIMIT 1",entry);
3260 if(result)
3262 Field* fields = result->Fetch();
3263 uint32 item_id = fields[0].GetUInt32();
3264 delete result;
3266 PSendSysMessage(LANG_COMMAND_QUEST_STARTFROMITEM, entry,item_id);
3267 return true;
3270 // ok, normal (creature/GO starting) quest
3271 Quest* pQuest = qIter->second;
3272 if( player->CanAddQuest( pQuest, true ) )
3274 player->AddQuest( pQuest, NULL );
3276 if ( player->CanCompleteQuest( entry ) )
3277 player->CompleteQuest( entry );
3280 return true;
3283 bool ChatHandler::HandleRemoveQuest(const char* args)
3285 Player* player = getSelectedPlayer();
3286 if(!player)
3288 SendSysMessage(LANG_NO_CHAR_SELECTED);
3289 return true;
3292 // .removequest #entry'
3293 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
3294 char* cId = extractKeyFromLink((char*)args,"Hquest");
3295 if(!cId)
3296 return false;
3298 uint32 entry = atol(cId);
3300 ObjectMgr::QuestMap::iterator qIter = objmgr.QuestTemplates.find(entry);
3302 if(qIter == objmgr.QuestTemplates.end())
3304 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, entry);
3305 return true;
3308 // remove all quest entries for 'entry' from quest log
3309 for(uint8 slot = 0; slot < MAX_QUEST_LOG_SIZE; ++slot )
3311 uint32 quest = player->GetUInt32Value(PLAYER_QUEST_LOG_1_1 + 3*slot + 0);
3312 if(quest==entry)
3314 player->SetUInt32Value(PLAYER_QUEST_LOG_1_1 + 3*slot + 0, 0);
3315 player->SetUInt32Value(PLAYER_QUEST_LOG_1_1 + 3*slot + 1, 0);
3316 player->SetUInt32Value(PLAYER_QUEST_LOG_1_1 + 3*slot + 2, 0);
3318 // we ignore unequippable quest items in this case, its' still be equipped
3319 player->TakeQuestSourceItem( quest, false );
3323 // set quest status to not started (will updated in DB at next save)
3324 player->SetQuestStatus( entry, QUEST_STATUS_NONE);
3326 // reset rewarded for restart repeatable quest
3327 player->getQuestStatusMap()[entry].m_rewarded = false;
3329 SendSysMessage(LANG_COMMAND_QUEST_REMOVED);
3330 return true;
3333 bool ChatHandler::HandleBanCommand(const char* args)
3335 if(!args)
3336 return false;
3338 char* type = strtok((char*)args, " ");
3340 if(!type)
3341 return false;
3342 char* nameOrIP = strtok(NULL, " ");
3344 if(!nameOrIP)
3345 return false;
3347 char* duration = strtok(NULL," ");
3348 char* reason;
3350 if(!duration || !atoi(duration))
3351 return false;
3352 else
3353 reason = strtok(NULL,"");
3354 if(!reason)
3355 return false;
3357 if(sWorld.BanAccount(type, nameOrIP, duration, reason,m_session->GetPlayerName()))
3358 if(atoi(duration)>0)
3359 PSendSysMessage(LANG_BAN_YOUBANNED,nameOrIP,secsToTimeString(TimeStringToSecs(duration),true).c_str(),reason);
3360 else
3361 PSendSysMessage(LANG_BAN_YOUPERMBANNED,nameOrIP,reason);
3362 else
3363 PSendSysMessage(LANG_BAN_NOTFOUND,type,nameOrIP);
3365 return true;
3368 bool ChatHandler::HandleUnBanCommand(const char* args)
3370 if(!args)
3371 return false;
3372 char* type = strtok((char*)args, " ");
3373 if(!type)
3374 return false;
3375 char* nameOrIP = strtok(NULL, " ");
3377 if(!nameOrIP)
3378 return false;
3380 if(sWorld.RemoveBanAccount(type,nameOrIP))
3381 PSendSysMessage(LANG_UNBAN_UNBANNED,nameOrIP);
3382 else
3383 PSendSysMessage(LANG_UNBAN_ERROR,nameOrIP);
3385 return true;
3388 bool ChatHandler::HandleBanInfoCommand(const char* args)
3390 if(!args)
3391 return false;
3392 char* cType = strtok((char*)args, " ");
3393 char* cnameOrIP = strtok(NULL, "");
3394 if(!cType || !cnameOrIP)
3395 return false;
3396 std::string nameOrIP = cnameOrIP;
3397 std::string type = cType;
3398 if (!IsIPAddress(cnameOrIP) && type=="ip")
3399 return false;
3400 loginDatabase.escape_string(nameOrIP);
3401 Field *fields;
3402 if(type!="ip")
3404 //look the accountid up
3405 uint32 accountid;
3406 std::string accountname;
3407 if(type == "account")
3409 QueryResult *result = loginDatabase.PQuery("SELECT `id`, `username` FROM `account` WHERE `username` = '%s' ",nameOrIP.c_str());
3410 if (!result)
3412 PSendSysMessage(LANG_BANINFO_NOACCOUNT);
3413 return true;
3415 fields = result->Fetch();
3416 accountid = fields[0].GetUInt32();
3417 accountname = fields[1].GetCppString();
3418 delete result;
3420 else if(type == "character")
3422 normalizePlayerName(nameOrIP);
3423 QueryResult *result = sDatabase.PQuery("SELECT account FROM `character` WHERE name = '%s')", nameOrIP.c_str());
3424 if (!result)
3426 PSendSysMessage(LANG_BANINFO_NOCHARACTER);
3427 return true;
3429 fields = result->Fetch();
3430 accountid = fields[0].GetUInt32();
3431 delete result;
3432 result = loginDatabase.PQuery("SELECT `username` FROM `account` WHERE `id` = '%u'", accountid);
3433 if (!result)
3435 PSendSysMessage(LANG_BANINFO_NOCHARACTER);
3436 return true;
3438 fields = result->Fetch();
3439 accountname = fields[0].GetCppString();
3440 delete result;
3442 else
3443 return false;
3445 QueryResult *result = loginDatabase.PQuery("SELECT FROM_UNIXTIME(`bandate`), `unbandate`-`bandate`, `active`, `unbandate`-UNIX_TIMESTAMP(),`banreason`,`bannedby` FROM `account_banned` WHERE `id` = '%u' ORDER BY `bandate` ASC",accountid);
3446 if(!result)
3448 PSendSysMessage(LANG_BANINFO_NOACCOUNTBAN, accountname.c_str());
3449 return true;
3451 PSendSysMessage(LANG_BANINFO_BANHISTORY,accountname.c_str());
3453 fields = result->Fetch();
3454 bool active = false;
3455 if(fields[2].GetBool() && (fields[1].GetUInt64() == (uint64)0 ||fields[3].GetUInt64() >= (uint64)0) )
3456 active = true;
3457 bool permanent = (fields[1].GetUInt64() == (uint64)0);
3458 std::string bantime = permanent?LANG_BANINFO_INFINITE:secsToTimeString(fields[1].GetUInt64(), true);
3459 PSendSysMessage(LANG_BANINFO_HISTORYENTRY,
3460 fields[0].GetString(), bantime.c_str(), active ? LANG_BANINFO_YES:LANG_BANINFO_NO, fields[4].GetString(), fields[5].GetString());
3461 }while (result->NextRow());
3463 delete result;
3464 return true;
3466 else
3468 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'",nameOrIP.c_str());
3469 if(!result)
3471 PSendSysMessage(LANG_BANINFO_NOIP);
3472 return true;
3474 fields = result->Fetch();
3475 bool permanent = (fields[6].GetUInt64()==(uint64)0);
3476 PSendSysMessage(LANG_BANINFO_IPENTRY,
3477 fields[0].GetString(), fields[1].GetString(), permanent ? LANG_BANINFO_NEVER:fields[2].GetString(),
3478 permanent ? LANG_BANINFO_INFINITE:secsToTimeString(fields[3].GetUInt64(), true).c_str(), fields[4].GetString(), fields[5].GetString());
3479 delete result;
3480 return true;
3482 return false;
3485 bool ChatHandler::HandleBanListCommand(const char* args)
3487 loginDatabase.Execute("DELETE FROM `ip_banned` WHERE `unbandate`<=UNIX_TIMESTAMP() AND `unbandate`<>`bandate`");
3488 if(!*args)
3489 return false;
3490 char* cType = strtok((char*)args, " ");
3491 char* cFilter = strtok(NULL, "");
3492 if(!cType || !cFilter)
3493 return false;
3494 std::string Filter = cFilter;
3495 std::string Type = cType;
3496 loginDatabase.escape_string(Filter);
3499 QueryResult* result = NULL;
3500 Field *fields = NULL;
3501 if(Type == "ip")
3503 result = loginDatabase.PQuery("SELECT `ip` FROM `ip_banned` WHERE `ip` LIKE \"%%%s%%\"",Filter.c_str());
3504 if(!result)
3506 PSendSysMessage(LANG_BANLIST_NOIP);
3507 return true;
3509 PSendSysMessage(LANG_BANLIST_MATCHINGIP);
3512 fields = result->Fetch();
3513 PSendSysMessage("%s",fields[0].GetString());
3514 } while (result->NextRow());
3516 delete result;
3517 return true;
3519 //lookup accountid
3520 if(Type == "account")
3522 result = loginDatabase.PQuery("SELECT `id` FROM `account` WHERE `username` LIKE \"%%%s%%\" ",Filter.c_str());
3523 if (!result)
3525 PSendSysMessage(LANG_BANLIST_NOACCOUNT);
3526 return true;
3528 //do not delete result
3530 else if(Type == "character")
3532 result = sDatabase.PQuery("SELECT `account` FROM `character`, WHERE name LIKE \"%%%s%%\" ",Filter.c_str());
3533 if (!result)
3535 PSendSysMessage(LANG_BANLIST_NOCHARACTER);
3536 return true;
3539 else
3540 return false;
3542 PSendSysMessage(LANG_BANLIST_MATCHINGACCOUNT);
3545 fields = result->Fetch();
3546 uint32 accountid = fields[0].GetUInt32();
3547 QueryResult* banresult = loginDatabase.PQuery("SELECT `account`.`username` FROM `account`,`account_banned` WHERE `account_banned`.`id`='%u' AND `account_banned`.`active` = '1' AND `account_banned`.`id`=`account`.`id`",accountid);
3548 if(banresult)
3550 Field* fields2 = banresult->Fetch();
3551 PSendSysMessage("%s",fields2[0].GetString());
3552 delete banresult;
3554 } while (result->NextRow());
3556 delete result;
3557 return true;
3560 bool ChatHandler::HandleRespawnCommand(const char* args)
3562 Player* pl = m_session->GetPlayer();
3564 CellPair p(MaNGOS::ComputeCellPair(pl->GetPositionX(), pl->GetPositionY()));
3565 Cell cell = RedZone::GetZone(p);
3566 cell.data.Part.reserved = ALL_DISTRICT;
3567 cell.SetNoCreate();
3569 MaNGOS::RespawnDo u_do;
3570 MaNGOS::WorldObjectWorker<MaNGOS::RespawnDo> worker(u_do);
3572 TypeContainerVisitor<MaNGOS::WorldObjectWorker<MaNGOS::RespawnDo>, GridTypeMapContainer > obj_worker(worker);
3573 CellLock<GridReadGuard> cell_lock(cell, p);
3574 cell_lock->Visit(cell_lock, obj_worker, *MapManager::Instance().GetMap(pl->GetMapId(), pl));
3576 return true;
3579 bool ChatHandler::HandleFlyModeCommand(const char* args)
3581 if(!args)
3582 return false;
3584 Unit *unit = getSelectedUnit();
3585 if (!unit || (unit->GetTypeId() != TYPEID_PLAYER))
3586 unit = m_session->GetPlayer();
3588 WorldPacket data(12);
3589 if (strncmp(args, "on", 3) == 0)
3590 data.SetOpcode(SMSG_FLY_MODE_START);
3591 else if (strncmp(args, "off", 4) == 0)
3592 data.SetOpcode(SMSG_FLY_MODE_STOP);
3593 else
3595 PSendSysMessage(LANG_COMMAND_FLYMODE_WRONGARG);
3596 return false;
3598 data.append(unit->GetPackGUID());
3599 data << uint32(0); // unk
3600 unit->SendMessageToSet(&data, true);
3601 PSendSysMessage(LANG_COMMAND_FLYMODE_STATUS, unit->GetName(), args);
3602 return true;
3605 bool ChatHandler::HandleSendOpcodeCommand(const char* args)
3607 if(!args)
3608 return false;
3610 Unit *unit = getSelectedUnit();
3611 if (!unit || (unit->GetTypeId() != TYPEID_PLAYER))
3612 unit = m_session->GetPlayer();
3614 uint16 opcode = atoi(args);
3615 WorldPacket data(opcode, 20);
3616 data.append(unit->GetPackGUID());
3617 data << urand(0, 1024);
3618 data << urand(0, 1024);
3619 data << urand(0, 1024);
3620 unit->SendMessageToSet(&data, true);
3621 PSendSysMessage(LANG_COMMAND_OPCODESENT, opcode, unit->GetName());
3622 return true;
3625 bool ChatHandler::HandleSellErrorCommand(const char* args)
3627 if(!args)
3628 return false;
3630 uint32 param = 0;
3631 uint8 msg = atoi(args);
3632 WorldPacket data( SMSG_SELL_ITEM, (8+8+4+1) );
3633 data << uint64(0);
3634 data << uint64(25);
3635 if( param > 0 )
3636 data << param;
3637 data << msg;
3638 m_session->SendPacket(&data);
3639 return true;
3642 bool ChatHandler::HandleBuyErrorCommand(const char* args)
3644 if(!args)
3645 return false;
3647 uint8 msg = atoi(args);
3648 WorldPacket data( SMSG_BUY_FAILED, (8+8+4+1) );
3649 data << m_session->GetPlayer()->GetGUID();
3650 data << uint32(0);
3651 data << msg;
3652 m_session->SendPacket(&data);
3653 return true;
3656 bool ChatHandler::HandleUpdateWorldStateCommand(const char* args)
3658 char* w = strtok((char*)args, " ");
3659 char* s = strtok(NULL, " ");
3661 if (!w || !s)
3662 return false;
3664 uint32 world = (uint32)atoi(w);
3665 uint32 state = (uint32)atoi(s);
3666 m_session->GetPlayer()->SendUpdateWorldState(world, state);
3667 return true;
3670 bool ChatHandler::HandlePlaySound2Command(const char* args)
3672 if(!args)
3673 return false;
3675 uint32 soundid = atoi(args);
3676 m_session->GetPlayer()->PlaySound(soundid, false);
3677 return true;
3680 bool ChatHandler::HandleSendChannelNotifyCommand(const char* args)
3682 if(!args)
3683 return false;
3685 const char *name = "test";
3686 uint8 code = atoi(args);
3688 WorldPacket data(SMSG_CHANNEL_NOTIFY, (1+10));
3689 data << code; // notify type
3690 data << name; // channel name
3691 data << uint32(0);
3692 data << uint32(0);
3693 m_session->SendPacket(&data);
3694 return true;
3697 bool ChatHandler::HandleSendChatMsgCommand(const char* args)
3699 if(!args)
3700 return false;
3702 const char *msg = "testtest";
3703 uint8 type = atoi(args);
3705 WorldPacket data(SMSG_MESSAGECHAT, 100);
3706 data << type; // message type
3707 data << uint32(0); // lang
3708 data << m_session->GetPlayer()->GetGUID(); // guid
3709 data << uint32(9); // msg len
3710 data << msg; // msg
3711 data << uint8(0); // chat tag
3712 m_session->SendPacket(&data);
3713 return true;
3716 bool ChatHandler::HandleLoadPDumpCommand(const char *args)
3718 if(!args)
3719 return false;
3721 char * file = strtok((char*)args, " "); if(!file) return false;
3722 char * acc = strtok(NULL, " "); if(!acc) return false;
3723 char * name = strtok(NULL, " ");
3724 char * guid = name ? strtok(NULL, " ") : NULL;
3726 if(objmgr.LoadPlayerDump(file, atoi(acc), name ? name : "", guid ? atoi(guid) : 0))
3727 PSendSysMessage(LANG_COMMAND_IMPORT_SUCCESS);
3728 else
3729 PSendSysMessage(LANG_COMMAND_IMPORT_FAILED);
3731 return true;
3734 bool ChatHandler::HandleWritePDumpCommand(const char *args)
3736 if(!args)
3737 return false;
3739 char* file = strtok((char*)args, " ");
3740 char* guid = strtok(NULL, " ");
3742 if(!file || !guid) return false;
3744 if (objmgr.WritePlayerDump(file, atoi(guid)))
3745 PSendSysMessage(LANG_COMMAND_EXPORT_SUCCESS);
3746 else
3747 PSendSysMessage(LANG_COMMAND_EXPORT_FAILED);
3749 return true;