OregonCore  revision 71a6c59-git
Your Favourite TBC server
Level2.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the OregonCore Project. See AUTHORS file for Copyright information
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the
6  * Free Software Foundation; either version 2 of the License, or (at your
7  * option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include "Common.h"
19 #include "Database/DatabaseEnv.h"
20 #include "WorldPacket.h"
21 #include "WorldSession.h"
22 #include "World.h"
23 #include "ObjectMgr.h"
24 #include "Player.h"
25 #include "Item.h"
26 #include "GameObject.h"
27 #include "Opcodes.h"
28 #include "Chat.h"
29 #include "ObjectAccessor.h"
30 #include "MapManager.h"
31 #include "Language.h"
32 #include "GameEventMgr.h"
33 #include "SpellMgr.h"
34 #include "PoolMgr.h"
35 #include "AccountMgr.h"
36 #include "WaypointManager.h"
37 #include "CreatureGroups.h"
38 #include "Utilities/Util.h"
39 #include <cctype>
40 #include <iostream>
41 #include <fstream>
42 #include <map>
43 #include "TicketMgr.h"
44 #include "ace/INET_Addr.h"
45 
46 #include "TargetedMovementGenerator.h" // for HandleNpcUnFollowCommand
47 
48 static uint32 ReputationRankStrIndex[MAX_REPUTATION_RANK] =
49 {
52 };
53 
54 //mute player for some times
55 bool ChatHandler::HandleMuteCommand(const char* args)
56 {
57  if (!*args)
58  return false;
59 
60  char* charname = strtok((char*)args, " ");
61  if (!charname)
62  return false;
63 
64  std::string cname = charname;
65 
66  char* timetonotspeak = strtok(NULL, " ");
67  if (!timetonotspeak)
68  return false;
69 
70  char* mutereason = strtok(NULL, "");
71  std::string mutereasonstr;
72  if (!mutereason)
73  mutereasonstr = "No reason.";
74  else
75  mutereasonstr = mutereason;
76 
77  uint32 notspeaktime = (uint32) atoi(timetonotspeak);
78 
79  if (!normalizePlayerName(cname))
80  {
82  SetSentErrorMessage(true);
83  return false;
84  }
85 
86  uint64 guid = sObjectMgr.GetPlayerGUIDByName(cname.c_str());
87  if (!guid)
88  {
90  SetSentErrorMessage(true);
91  return false;
92  }
93 
94  Player* chr = sObjectMgr.GetPlayer(guid);
95 
96  // check security
97  uint32 account_id = 0;
98  uint32 security = 0;
99 
100  if (chr)
101  {
102  account_id = chr->GetSession()->GetAccountId();
103  security = chr->GetSession()->GetSecurity();
104  }
105  else
106  {
107  account_id = sObjectMgr.GetPlayerAccountIdByGUID(guid);
108  security = sAccountMgr->GetSecurity(account_id);
109  }
110 
111  if (m_session && security >= m_session->GetSecurity())
112  {
114  SetSentErrorMessage(true);
115  return false;
116  }
117 
118  time_t mutetime = time(NULL) + notspeaktime * 60;
119 
120  if (chr)
121  chr->GetSession()->m_muteTime = mutetime;
122 
123  LoginDatabase.PExecute("UPDATE account SET mutetime = " UI64FMTD " WHERE id = '%u'", uint64(mutetime), account_id);
124 
125  if (chr)
126  ChatHandler(chr).PSendSysMessage(LANG_YOUR_CHAT_DISABLED, notspeaktime, mutereasonstr.c_str());
127 
128  PSendSysMessage(LANG_YOU_DISABLE_CHAT, cname.c_str(), notspeaktime, mutereasonstr.c_str());
129 
130  return true;
131 }
132 
133 //unmute player
134 bool ChatHandler::HandleUnmuteCommand(const char* args)
135 {
136  if (!*args)
137  return false;
138 
139  char* charname = strtok((char*)args, " ");
140  if (!charname)
141  return false;
142 
143  std::string cname = charname;
144 
145  if (!normalizePlayerName(cname))
146  {
148  SetSentErrorMessage(true);
149  return false;
150  }
151 
152  uint64 guid = sObjectMgr.GetPlayerGUIDByName(cname.c_str());
153  if (!guid)
154  {
156  SetSentErrorMessage(true);
157  return false;
158  }
159 
160  Player* chr = sObjectMgr.GetPlayer(guid);
161 
162  // check security
163  uint32 account_id = 0;
164  uint32 security = 0;
165 
166  if (chr)
167  {
168  account_id = chr->GetSession()->GetAccountId();
169  security = chr->GetSession()->GetSecurity();
170  }
171  else
172  {
173  account_id = sObjectMgr.GetPlayerAccountIdByGUID(guid);
174  security = sAccountMgr->GetSecurity(account_id);
175  }
176 
177  if (m_session && security >= m_session->GetSecurity())
178  {
180  SetSentErrorMessage(true);
181  return false;
182  }
183 
184  if (chr)
185  {
186  if (chr->CanSpeak())
187  {
189  SetSentErrorMessage(true);
190  return false;
191  }
192 
193  chr->GetSession()->m_muteTime = 0;
194  }
195 
196  LoginDatabase.PExecute("UPDATE account SET mutetime = '0' WHERE id = '%u'", account_id);
197 
198  if (chr)
199  ChatHandler(chr).PSendSysMessage(LANG_YOUR_CHAT_ENABLED);
200 
201  PSendSysMessage(LANG_YOU_ENABLE_CHAT, cname.c_str());
202  return true;
203 }
204 
206 {
207  if (!*args)
208  return false;
209 
210  char* cstrticket_id = strtok((char*)args, " ");
211 
212  if (!cstrticket_id)
213  return false;
214 
215  uint64 ticket_id = atoi(cstrticket_id);
216  if (!ticket_id)
217  return false;
218 
219  GM_Ticket* ticket = ticketmgr.GetGMTicket(ticket_id);
220  if (!ticket)
221  {
223  return true;
224  }
225 
226  float x, y, z;
227  int mapid;
228 
229  x = ticket->pos_x;
230  y = ticket->pos_y;
231  z = ticket->pos_z;
232  mapid = ticket->map;
233 
234  Player* _player = m_session->GetPlayer();
235  if (_player->IsInFlight())
236  {
237  _player->GetMotionMaster()->MovementExpired();
238  _player->CleanupAfterTaxiFlight();
239  }
240  else
241  _player->SaveRecallPosition();
242 
243  _player->TeleportTo(mapid, x, y, z, 1, 0);
244  return true;
245 }
246 
248 {
249  Player* _player = m_session->GetPlayer();
250 
251  if (!*args)
252  return false;
253 
254  char* atId = strtok((char*)args, " ");
255  if (!atId)
256  return false;
257 
258  int32 i_atId = atoi(atId);
259 
260  if (!i_atId)
261  return false;
262 
263  AreaTriggerEntry const* at = sAreaTriggerStore.LookupEntry(i_atId);
264  if (!at)
265  {
267  SetSentErrorMessage(true);
268  return false;
269  }
270 
271  if (!MapManager::IsValidMapCoord(at->mapid, at->x, at->y, at->z))
272  {
274  SetSentErrorMessage(true);
275  return false;
276  }
277 
278  // stop flight if need
279  if (_player->IsInFlight())
280  {
281  _player->GetMotionMaster()->MovementExpired();
282  _player->CleanupAfterTaxiFlight();
283  }
284  // save only in non-flight case
285  else
286  _player->SaveRecallPosition();
287 
288  _player->TeleportTo(at->mapid, at->x, at->y, at->z, _player->GetOrientation());
289  return true;
290 }
291 
293 {
294  Player* _player = m_session->GetPlayer();
295 
296  if (!*args)
297  return false;
298 
299  char* gyId = strtok((char*)args, " ");
300  if (!gyId)
301  return false;
302 
303  int32 i_gyId = atoi(gyId);
304 
305  if (!i_gyId)
306  return false;
307 
308  WorldSafeLocsEntry const* gy = sWorldSafeLocsStore.LookupEntry(i_gyId);
309  if (!gy)
310  {
312  SetSentErrorMessage(true);
313  return false;
314  }
315 
316  if (!MapManager::IsValidMapCoord(gy->map_id, gy->x, gy->y, gy->z))
317  {
319  SetSentErrorMessage(true);
320  return false;
321  }
322 
323  // stop flight if need
324  if (_player->IsInFlight())
325  {
326  _player->GetMotionMaster()->MovementExpired();
327  _player->CleanupAfterTaxiFlight();
328  }
329  // save only in non-flight case
330  else
331  _player->SaveRecallPosition();
332 
333  _player->TeleportTo(gy->map_id, gy->x, gy->y, gy->z, _player->GetOrientation());
334  return true;
335 }
336 
347 //teleport to creature
349 {
350  if (!*args)
351  return false;
352  Player* _player = m_session->GetPlayer();
353 
354  // "id" or number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r
355  char* pParam1 = extractKeyFromLink((char*)args, "Hcreature");
356  if (!pParam1)
357  return false;
358 
359  std::ostringstream whereClause;
360 
361  // User wants to teleport to the NPC's template entry
362  if (strcmp(pParam1, "id") == 0)
363  {
364  //sLog.outError("DEBUG: ID found");
365 
366  // Get the "creature_template.entry"
367  // number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r
368  char* tail = strtok(NULL, "");
369  if (!tail)
370  return false;
371  char* cId = extractKeyFromLink(tail, "Hcreature_entry");
372  if (!cId)
373  return false;
374 
375  int32 tEntry = atoi(cId);
376  //sLog.outError("DEBUG: ID value: %d", tEntry);
377  if (!tEntry)
378  return false;
379 
380  whereClause << "WHERE id = '" << tEntry << "'";
381  }
382  else
383  {
384  //sLog.outError("DEBUG: ID *not found*");
385 
386  int32 guid = atoi(pParam1);
387 
388  // Number is invalid - maybe the user specified the mob's name
389  if (!guid)
390  {
391  std::string name = pParam1;
393  whereClause << ", creature_template WHERE creature.id = creature_template.entry AND creature_template.name " _LIKE_ " '" << name << "'";
394  }
395  else
396  whereClause << "WHERE guid = '" << guid << "'";
397  }
398  //sLog.outError("DEBUG: %s", whereClause.c_str());
399 
400  QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT position_x,position_y,position_z,orientation,map FROM creature %s", whereClause.str().c_str());
401  if (!result)
402  {
404  SetSentErrorMessage(true);
405  return false;
406  }
407  if (result->GetRowCount() > 1)
409 
410  Field* fields = result->Fetch();
411  float x = fields[0].GetFloat();
412  float y = fields[1].GetFloat();
413  float z = fields[2].GetFloat();
414  float ort = fields[3].GetFloat();
415  int mapid = fields[4].GetUInt16();
416 
417  if (!MapManager::IsValidMapCoord(mapid, x, y, z, ort))
418  {
420  SetSentErrorMessage(true);
421  return false;
422  }
423 
424  // stop flight if need
425  if (_player->IsInFlight())
426  {
427  _player->GetMotionMaster()->MovementExpired();
428  _player->CleanupAfterTaxiFlight();
429  }
430  // save only in non-flight case
431  else
432  _player->SaveRecallPosition();
433 
434  _player->TeleportTo(mapid, x, y, z, ort);
435  return true;
436 }
437 
438 //teleport to gameobject
440 {
441  if (!*args)
442  return false;
443 
444  Player* _player = m_session->GetPlayer();
445 
446  // number or [name] Shift-click form |color|Hgameobject:go_guid|h[name]|h|r
447  char* cId = extractKeyFromLink((char*)args, "Hgameobject");
448  if (!cId)
449  return false;
450 
451  int32 guid = atoi(cId);
452  if (!guid)
453  return false;
454 
455  float x, y, z, ort;
456  int mapid;
457 
458  // by DB guid
459  if (GameObjectData const* go_data = sObjectMgr.GetGOData(guid))
460  {
461  x = go_data->posX;
462  y = go_data->posY;
463  z = go_data->posZ;
464  ort = go_data->orientation;
465  mapid = go_data->mapid;
466  }
467  else
468  {
470  SetSentErrorMessage(true);
471  return false;
472  }
473 
474  if (!MapManager::IsValidMapCoord(mapid, x, y, z, ort))
475  {
477  SetSentErrorMessage(true);
478  return false;
479  }
480 
481  // stop flight if need
482  if (_player->IsInFlight())
483  {
484  _player->GetMotionMaster()->MovementExpired();
485  _player->CleanupAfterTaxiFlight();
486  }
487  // save only in non-flight case
488  else
489  _player->SaveRecallPosition();
490 
491  _player->TeleportTo(mapid, x, y, z, ort);
492  return true;
493 }
494 
496 {
497  Player* pl = m_session->GetPlayer();
498  QueryResult_AutoPtr result;
499  GameEventMgr::ActiveEvents const& activeEventsList = sGameEventMgr.GetActiveEventList();
500  if (*args)
501  {
502  int32 id = atoi((char*)args);
503  if (id)
504  result = WorldDatabase.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 map = '%i' AND id = '%u' ORDER BY order_ ASC LIMIT 1",
505  pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(), pl->GetMapId(), id);
506  else
507  {
508  std::string name = args;
510  result = WorldDatabase.PQuery(
511  "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_ "
512  "FROM gameobject,gameobject_template WHERE gameobject_template.entry = gameobject.id AND map = %i AND name " _LIKE_ " " _CONCAT3_("'%%'", "'%s'", "'%%'")" ORDER BY order_ ASC LIMIT 1",
513  pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(), pl->GetMapId(), name.c_str());
514  }
515  }
516  else
517  {
518  std::ostringstream eventFilter;
519  eventFilter << " AND (event IS NULL ";
520  bool initString = true;
521 
522  for (GameEventMgr::ActiveEvents::const_iterator itr = activeEventsList.begin(); itr != activeEventsList.end(); ++itr)
523  {
524  if (initString)
525  {
526  eventFilter << "OR event IN (" << *itr;
527  initString = false;
528  }
529  else
530  eventFilter << "," << *itr;
531  }
532 
533  if (!initString)
534  eventFilter << "))";
535  else
536  eventFilter << ")";
537 
538  result = WorldDatabase.PQuery("SELECT gameobject.guid, id, position_x, position_y, position_z, orientation, map, "
539  "(POW(position_x - %f, 2) + POW(position_y - %f, 2) + POW(position_z - %f, 2)) AS order_ FROM gameobject "
540  "LEFT OUTER JOIN game_event_gameobject on gameobject.guid=game_event_gameobject.guid WHERE map = '%i' %s ORDER BY order_ ASC LIMIT 10",
542  }
543 
544  if (!result)
545  {
547  return true;
548  }
549 
550  bool found = false;
551  float x, y, z, o;
552  uint32 lowguid, id;
553  uint16 mapid;
554  uint32 pool_id;
555 
556  do
557  {
558  Field* fields = result->Fetch();
559  lowguid = fields[0].GetUInt32();
560  id = fields[1].GetUInt32();
561  x = fields[2].GetFloat();
562  y = fields[3].GetFloat();
563  z = fields[4].GetFloat();
564  o = fields[5].GetFloat();
565  mapid = fields[6].GetUInt16();
566  pool_id = sPoolMgr.IsPartOfAPool<GameObject>(lowguid);
567  if (!pool_id || (pool_id && sPoolMgr.IsSpawnedObject<GameObject>(pool_id)))
568  found = true;
569  }
570  while (result->NextRow() && (!found));
571 
572  if (!found)
573  {
575  return false;
576  }
577 
578  GameObjectInfo const* goI = sObjectMgr.GetGameObjectInfo(id);
579 
580  if (!goI)
581  {
583  return false;
584  }
585 
587 
588  PSendSysMessage(LANG_GAMEOBJECT_DETAIL, lowguid, goI->name, lowguid, id, x, y, z, mapid, o);
589 
590  if (target)
591  {
592  int32 curRespawnDelay = target->GetRespawnTimeEx() - time(NULL);
593  if (curRespawnDelay < 0)
594  curRespawnDelay = 0;
595 
596  std::string curRespawnDelayStr = secsToTimeString(curRespawnDelay, true);
597  std::string defRespawnDelayStr = secsToTimeString(target->GetRespawnDelay(), true);
598 
599  PSendSysMessage(LANG_COMMAND_RAWPAWNTIMES, defRespawnDelayStr.c_str(), curRespawnDelayStr.c_str());
600  }
601  return true;
602 }
603 
604 //delete object by selection or guid
606 {
607  // number or [name] Shift-click form |color|Hgameobject:go_guid|h[name]|h|r
608  char* cId = extractKeyFromLink((char*)args, "Hgameobject");
609  if (!cId)
610  return false;
611 
612  uint32 lowguid = atoi(cId);
613  if (!lowguid)
614  return false;
615 
616  GameObject* obj = NULL;
617 
618  // by DB guid
619  if (GameObjectData const* go_data = sObjectMgr.GetGOData(lowguid))
620  obj = GetObjectGlobalyWithGuidOrNearWithDbGuid(lowguid, go_data->id);
621 
622  if (!obj)
623  {
625  SetSentErrorMessage(true);
626  return false;
627  }
628 
629  uint64 owner_guid = obj->GetOwnerGUID();
630  if (owner_guid)
631  {
632  Unit* owner = ObjectAccessor::GetUnit(*m_session->GetPlayer(), owner_guid);
633  if (!owner || !IS_PLAYER_GUID(owner_guid))
634  {
636  SetSentErrorMessage(true);
637  return false;
638  }
639 
640  owner->RemoveGameObject(obj, false);
641  }
642 
643  obj->SetRespawnTime(0); // not save respawn time
644  obj->Delete();
645  obj->DeleteFromDB();
646 
648 
649  return true;
650 }
651 
652 //turn selected object
654 {
655  // number or [name] Shift-click form |color|Hgameobject:go_id|h[name]|h|r
656  char* cId = extractKeyFromLink((char*)args, "Hgameobject");
657  if (!cId)
658  return false;
659 
660  uint32 lowguid = atoi(cId);
661  if (!lowguid)
662  return false;
663 
664  GameObject* obj = NULL;
665 
666  // by DB guid
667  if (GameObjectData const* go_data = sObjectMgr.GetGOData(lowguid))
668  obj = GetObjectGlobalyWithGuidOrNearWithDbGuid(lowguid, go_data->id);
669 
670  if (!obj)
671  {
673  SetSentErrorMessage(true);
674  return false;
675  }
676 
677  char* po = strtok(NULL, " ");
678  float o;
679 
680  if (po)
681  o = (float)atof(po);
682  else
683  {
684  Player* chr = m_session->GetPlayer();
685  o = chr->GetOrientation();
686  }
687 
688  obj->Relocate(obj->GetPositionX(), obj->GetPositionY(), obj->GetPositionZ(), o);
689  obj->UpdateRotationFields();
691  obj->UpdateObjectVisibility();
692 
693  obj->SaveToDB();
694  obj->Refresh();
695 
697 
698  return true;
699 }
700 
701 //move selected object
703 {
704  // number or [name] Shift-click form |color|Hgameobject:go_guid|h[name]|h|r
705  char* cId = extractKeyFromLink((char*)args, "Hgameobject");
706  if (!cId)
707  return false;
708 
709  uint32 lowguid = atoi(cId);
710  if (!lowguid)
711  return false;
712 
713  GameObject* obj = NULL;
714 
715  // by DB guid
716  if (GameObjectData const* go_data = sObjectMgr.GetGOData(lowguid))
717  obj = GetObjectGlobalyWithGuidOrNearWithDbGuid(lowguid, go_data->id);
718 
719  if (!obj)
720  {
722  SetSentErrorMessage(true);
723  return false;
724  }
725 
726  char* px = strtok(NULL, " ");
727  char* py = strtok(NULL, " ");
728  char* pz = strtok(NULL, " ");
729 
730  if (!px)
731  {
732  Player* chr = m_session->GetPlayer();
733  obj->Relocate(chr->GetPositionX(), chr->GetPositionY(), chr->GetPositionZ(), obj->GetOrientation());
737 
739  obj->UpdateObjectVisibility();
740  }
741  else
742  {
743  if (!py || !pz)
744  return false;
745 
746  float x = (float)atof(px);
747  float y = (float)atof(py);
748  float z = (float)atof(pz);
749 
750  if (!MapManager::IsValidMapCoord(obj->GetMapId(), x, y, z))
751  {
753  SetSentErrorMessage(true);
754  return false;
755  }
756 
757  obj->Relocate(x, y, z, obj->GetOrientation());
761 
763  obj->UpdateObjectVisibility();
764  }
765 
766  obj->SaveToDB();
767  obj->Refresh();
768 
770 
771  return true;
772 }
773 
774 //spawn go
776 {
777  if (!*args)
778  return false;
779 
780  char* pParam1 = strtok((char*)args, " ");
781  if (!pParam1)
782  return false;
783 
784  uint32 id = atoi((char*)pParam1);
785  if (!id)
786  return false;
787 
788  char* spawntimeSecs = strtok(NULL, " ");
789 
790  const GameObjectInfo* gInfo = sObjectMgr.GetGameObjectInfo(id);
791 
792  if (!gInfo)
793  {
795  SetSentErrorMessage(true);
796  return false;
797  }
798 
799  Player* chr = m_session->GetPlayer();
800  float x = float(chr->GetPositionX());
801  float y = float(chr->GetPositionY());
802  float z = float(chr->GetPositionZ());
803  float o = float(chr->GetOrientation());
804  Map* map = chr->GetMap();
805 
806  GameObject* pGameObj = new GameObject;
807  uint32 db_lowGUID = sObjectMgr.GenerateLowGuid(HIGHGUID_GAMEOBJECT);
808 
809  if (!pGameObj->Create(db_lowGUID, gInfo->id, map, 0x00000001, x, y, z, o, 0.0f, 0.0f, 0.0f, 0.0f, 0, GO_STATE_READY))
810  {
811  delete pGameObj;
812  return false;
813  }
814 
815  if (spawntimeSecs)
816  {
817  uint32 value = atoi((char*)spawntimeSecs);
818  pGameObj->SetRespawnTime(value);
819  //sLog.outDebug("*** spawntimeSecs: %d", value);
820  }
821 
822  // fill the gameobject data and save to the db
823  pGameObj->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), chr->GetPhaseMaskForSpawn());
824  delete pGameObj;
825 
826  pGameObj = new GameObject();
827  // this will generate a new guid if the object is in an instance
828  if (!pGameObj->LoadGameObjectFromDB(db_lowGUID, map))
829  {
830  delete pGameObj;
831  return false;
832  }
833 
834  sLog.outDebug(GetOregonString(LANG_GAMEOBJECT_CURRENT), gInfo->name, db_lowGUID, x, y, z, o);
835 
836  // @todo is it really necessary to add both the real and DB table guid here ?
837  sObjectMgr.AddGameobjectToGrid(db_lowGUID, sObjectMgr.GetGOData(db_lowGUID));
838 
839  PSendSysMessage(LANG_GAMEOBJECT_ADD, id, gInfo->name, db_lowGUID, x, y, z);
840  return true;
841 }
842 bool ChatHandler::HandleGUIDCommand(const char* /*args*/)
843 {
844  uint64 guid = m_session->GetPlayer()->GetSelection();
845 
846  if (guid == 0)
847  {
849  SetSentErrorMessage(true);
850  return false;
851  }
852 
854  return true;
855 }
856 
858 {
859  if (!*args) return false;
860 
861  Player* target = NULL;
862  target = getSelectedPlayer();
863 
864  if (!target)
865  {
867  SetSentErrorMessage(true);
868  return false;
869  }
870 
871  char* factionTxt = extractKeyFromLink((char*)args, "Hfaction");
872  if (!factionTxt)
873  return false;
874 
875  uint32 factionId = atoi(factionTxt);
876 
877  int32 amount = 0;
878  char* rankTxt = strtok(NULL, " ");
879  if (!rankTxt)
880  return false;
881 
882  amount = atoi(rankTxt);
883  if ((amount == 0) && (rankTxt[0] != '-') && !isdigit(rankTxt[0]))
884  {
885  std::string rankStr = rankTxt;
886  std::wstring wrankStr;
887  if (!Utf8toWStr(rankStr, wrankStr))
888  return false;
889  wstrToLower(wrankStr);
890 
891  int r = 0;
892  amount = -42000;
893  for (; r < MAX_REPUTATION_RANK; ++r)
894  {
895  std::string rank = GetOregonString(ReputationRankStrIndex[r]);
896  if (rank.empty())
897  continue;
898 
899  std::wstring wrank;
900  if (!Utf8toWStr(rank, wrank))
901  continue;
902 
903  wstrToLower(wrank);
904 
905  if (wrank.substr(0, wrankStr.size()) == wrankStr)
906  {
907  char* deltaTxt = strtok(NULL, " ");
908  if (deltaTxt)
909  {
910  int32 delta = atoi(deltaTxt);
911  if ((delta < 0) || (delta > ReputationMgr::PointsInRank[r] - 1))
912  {
914  SetSentErrorMessage(true);
915  return false;
916  }
917  amount += delta;
918  }
919  break;
920  }
921  amount += ReputationMgr::PointsInRank[r];
922  }
923  if (r >= MAX_REPUTATION_RANK)
924  {
926  SetSentErrorMessage(true);
927  return false;
928  }
929  }
930 
931  FactionEntry const* factionEntry = sFactionStore.LookupEntry(factionId);
932 
933  if (!factionEntry)
934  {
936  SetSentErrorMessage(true);
937  return false;
938  }
939 
940  if (factionEntry->reputationListID < 0)
941  {
943  SetSentErrorMessage(true);
944  return false;
945  }
946 
947  target->GetReputationMgr().SetReputation(factionEntry, amount);
948  PSendSysMessage(LANG_COMMAND_MODIFY_REP, factionEntry->name[m_session->GetSessionDbcLocale()], factionId, target->GetName(), target->GetReputationMgr().GetReputation(factionEntry));
949  return true;
950 }
951 
952 //-----------------------Npc Commands-----------------------
953 //add spawn of creature
954 bool ChatHandler::HandleNpcAddCommand(const char* args)
955 {
956  if (!*args)
957  return false;
958  char* charID = strtok((char*)args, " ");
959  if (!charID)
960  return false;
961 
962  char* team = strtok(NULL, " ");
963  int32 teamval = 0;
964  if (team)
965  teamval = atoi(team);
966  if (teamval < 0)
967  teamval = 0;
968 
969  uint32 id = atoi(charID);
970 
971  Player* chr = m_session->GetPlayer();
972  float x = chr->GetPositionX();
973  float y = chr->GetPositionY();
974  float z = chr->GetPositionZ();
975  float o = chr->GetOrientation();
976  Map* map = chr->GetMap();
977 
978  Creature* creature = new Creature;
979  if (!creature->Create(sObjectMgr.GenerateLowGuid(HIGHGUID_UNIT), map, PHASEMASK_NORMAL, id, (uint32)teamval, x, y, z, o))
980  {
981  delete creature;
982  return false;
983  }
984 
985  creature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), chr->GetPhaseMaskForSpawn());
986 
987  uint32 db_guid = creature->GetDBTableGUIDLow();
988 
989  // To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells();
990  if (!creature->LoadCreatureFromDB(db_guid, map))
991  {
992  delete creature;
993  return false;
994  }
995 
996  sObjectMgr.AddCreatureToGrid(db_guid, sObjectMgr.GetCreatureData(db_guid));
997  return true;
998 }
999 
1000 //add item in vendorlist
1002 {
1003  if (!*args)
1004  return false;
1005 
1006  char* pitem = extractKeyFromLink((char*)args, "Hitem");
1007  if (!pitem)
1008  {
1010  SetSentErrorMessage(true);
1011  return false;
1012  }
1013 
1014  uint32 itemId = atol(pitem);
1015 
1016  char* fmaxcount = strtok(NULL, " "); //add maxcount, default: 0
1017  uint32 maxcount = 0;
1018  if (fmaxcount)
1019  maxcount = atol(fmaxcount);
1020 
1021  char* fincrtime = strtok(NULL, " "); //add incrtime, default: 0
1022  uint32 incrtime = 0;
1023  if (fincrtime)
1024  incrtime = atol(fincrtime);
1025 
1026  char* fextendedcost = strtok(NULL, " "); //add ExtendedCost, default: 0
1027  uint32 extendedcost = fextendedcost ? atol(fextendedcost) : 0;
1028 
1029  Creature* vendor = getSelectedCreature();
1030 
1031  uint32 vendor_entry = vendor ? vendor->GetEntry() : 0;
1032 
1033  if (!sObjectMgr.IsVendorItemValid(vendor_entry, itemId, maxcount, incrtime, extendedcost, m_session->GetPlayer()))
1034  {
1035  SetSentErrorMessage(true);
1036  return false;
1037  }
1038 
1039  sObjectMgr.AddVendorItem(vendor_entry, itemId, maxcount, incrtime, extendedcost);
1040 
1041  ItemTemplate const* pProto = sObjectMgr.GetItemTemplate(itemId);
1042 
1043  PSendSysMessage(LANG_ITEM_ADDED_TO_LIST, itemId, pProto->Name1, maxcount, incrtime, extendedcost);
1044  return true;
1045 }
1046 
1047 //del item from vendor list
1049 {
1050  if (!*args)
1051  return false;
1052 
1053  Creature* vendor = getSelectedCreature();
1054  if (!vendor || !vendor->IsVendor())
1055  {
1057  SetSentErrorMessage(true);
1058  return false;
1059  }
1060 
1061  char* pitem = extractKeyFromLink((char*)args, "Hitem");
1062  if (!pitem)
1063  {
1065  SetSentErrorMessage(true);
1066  return false;
1067  }
1068  uint32 itemId = atol(pitem);
1069 
1070  if (!sObjectMgr.RemoveVendorItem(vendor->GetEntry(), itemId))
1071  {
1073  SetSentErrorMessage(true);
1074  return false;
1075  }
1076 
1077  ItemTemplate const* pProto = sObjectMgr.GetItemTemplate(itemId);
1078 
1080  return true;
1081 }
1082 
1083 //change level of creature or pet
1085 {
1086  if (!*args)
1087  return false;
1088 
1089  uint8 lvl = (uint8) atoi((char*)args);
1090  if (lvl < 1 || lvl > sWorld.getConfig(CONFIG_MAX_PLAYER_LEVEL) + 3)
1091  {
1093  SetSentErrorMessage(true);
1094  return false;
1095  }
1096 
1097  Creature* pCreature = getSelectedCreature();
1098  if (!pCreature)
1099  {
1101  SetSentErrorMessage(true);
1102  return false;
1103  }
1104 
1105  if (pCreature->IsPet())
1106  ((Pet*)pCreature)->GivePetLevel(lvl);
1107  else
1108  {
1109  pCreature->SetMaxHealth(100 + 30 * lvl);
1110  pCreature->SetHealth(100 + 30 * lvl);
1111  pCreature->SetLevel(lvl);
1112  pCreature->SaveToDB();
1113  }
1114 
1115  return true;
1116 }
1117 
1118 //set npcflag of creature
1120 {
1121  if (!*args)
1122  return false;
1123 
1124  uint32 npcFlags = (uint32) atoi((char*)args);
1125 
1126  Creature* pCreature = getSelectedCreature();
1127 
1128  if (!pCreature)
1129  {
1131  SetSentErrorMessage(true);
1132  return false;
1133  }
1134 
1135  pCreature->SetUInt32Value(UNIT_NPC_FLAGS, npcFlags);
1136 
1137  WorldDatabase.PExecuteLog("UPDATE creature_template SET npcflag = '%u' WHERE entry = '%u'", npcFlags, pCreature->GetEntry());
1138 
1140 
1141  return true;
1142 }
1143 
1145 {
1146  Creature* unit = NULL;
1147 
1148  if (*args)
1149  {
1150  // number or [name] Shift-click form |color|Hcreature:creature_guid|h[name]|h|r
1151  char* cId = extractKeyFromLink((char*)args, "Hcreature");
1152  if (!cId)
1153  return false;
1154 
1155  uint32 lowguid = atoi(cId);
1156  if (!lowguid)
1157  return false;
1158 
1159  if (CreatureData const* cr_data = sObjectMgr.GetCreatureData(lowguid))
1160  unit = m_session->GetPlayer()->GetMap()->GetCreature(MAKE_NEW_GUID(lowguid, cr_data->id, HIGHGUID_UNIT));
1161  }
1162  else
1163  unit = getSelectedCreature();
1164 
1165  if (!unit || unit->IsPet() || unit->IsTotem())
1166  {
1168  SetSentErrorMessage(true);
1169  return false;
1170  }
1171 
1172  // Delete the creature
1173  unit->CombatStop();
1174  unit->DeleteFromDB();
1175  unit->AddObjectToRemoveList();
1176 
1178 
1179  return true;
1180 }
1181 
1182 //move selected creature
1184 {
1185  uint32 lowguid = 0;
1186 
1187  Creature* pCreature = getSelectedCreature();
1188 
1189  if (!pCreature)
1190  {
1191  // number or [name] Shift-click form |color|Hcreature:creature_guid|h[name]|h|r
1192  char* cId = extractKeyFromLink((char*)args, "Hcreature");
1193  if (!cId)
1194  return false;
1195 
1196  lowguid = atoi(cId);
1197 
1198  /* FIXME: impossibel without entry
1199  if (lowguid)
1200  pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(),MAKE_GUID(lowguid,HIGHGUID_UNIT));
1201  */
1202 
1203  // Attempting creature load from DB data
1204  if (!pCreature)
1205  {
1206  CreatureData const* data = sObjectMgr.GetCreatureData(lowguid);
1207  if (!data)
1208  {
1210  SetSentErrorMessage(true);
1211  return false;
1212  }
1213 
1214  uint32 map_id = data->mapid;
1215 
1216  if (m_session->GetPlayer()->GetMapId() != map_id)
1217  {
1219  SetSentErrorMessage(true);
1220  return false;
1221  }
1222  }
1223  else
1224  lowguid = pCreature->GetDBTableGUIDLow();
1225  }
1226  else
1227  lowguid = pCreature->GetDBTableGUIDLow();
1228 
1229  float x = m_session->GetPlayer()->GetPositionX();
1230  float y = m_session->GetPlayer()->GetPositionY();
1231  float z = m_session->GetPlayer()->GetPositionZ();
1232  float o = m_session->GetPlayer()->GetOrientation();
1233 
1234  if (pCreature)
1235  {
1236  if (CreatureData const* data = sObjectMgr.GetCreatureData(pCreature->GetDBTableGUIDLow()))
1237  {
1238  const_cast<CreatureData*>(data)->posX = x;
1239  const_cast<CreatureData*>(data)->posY = y;
1240  const_cast<CreatureData*>(data)->posZ = z;
1241  const_cast<CreatureData*>(data)->orientation = o;
1242  }
1243  pCreature->GetMap()->CreatureRelocation(pCreature, x, y, z, o);
1244  pCreature->GetMotionMaster()->Initialize();
1245  if (pCreature->IsAlive()) // dead creature will reset movement generator at respawn
1246  {
1247  pCreature->setDeathState(DEAD);
1248  pCreature->Respawn();
1249  }
1250  }
1251 
1252  WorldDatabase.PExecuteLog("UPDATE creature SET position_x = '%f', position_y = '%f', position_z = '%f', orientation = '%f' WHERE guid = '%u'", x, y, z, o, lowguid);
1254  return true;
1255 }
1256 
1270 {
1271  if (!*args)
1272  return false;
1273 
1274  // 3 arguments:
1275  // GUID (optional - you can also select the creature)
1276  // stay|random|way (determines the kind of movement)
1277  // NODEL (optional - tells the system NOT to delete any waypoints)
1278  // this is very handy if you want to do waypoints, that are
1279  // later switched on/off according to special events (like escort
1280  // quests, etc)
1281  char* guid_str = strtok((char*)args, " ");
1282  char* type_str = strtok((char*)NULL, " ");
1283  char* dontdel_str = strtok((char*)NULL, " ");
1284 
1285  bool doNotDelete = false;
1286 
1287  if (!guid_str)
1288  return false;
1289 
1290  uint32 lowguid = 0;
1291  Creature* pCreature = NULL;
1292 
1293  if (dontdel_str)
1294  {
1295  //sLog.outError("DEBUG: All 3 params are set");
1296 
1297  // All 3 params are set
1298  // GUID
1299  // type
1300  // doNotDEL
1301  if (stricmp(dontdel_str, "NODEL") == 0)
1302  {
1303  //sLog.outError("DEBUG: doNotDelete = true;");
1304  doNotDelete = true;
1305  }
1306  }
1307  else
1308  {
1309  // Only 2 params - but maybe NODEL is set
1310  if (type_str)
1311  {
1312  sLog.outError("DEBUG: Only 2 params ");
1313  if (stricmp(type_str, "NODEL") == 0)
1314  {
1315  //sLog.outError("DEBUG: type_str, NODEL ");
1316  doNotDelete = true;
1317  type_str = NULL;
1318  }
1319  }
1320  }
1321 
1322  if (!type_str) // case .setmovetype $move_type (with selected creature)
1323  {
1324  type_str = guid_str;
1325  pCreature = getSelectedCreature();
1326  if (!pCreature || pCreature->IsPet())
1327  return false;
1328  lowguid = pCreature->GetDBTableGUIDLow();
1329  }
1330  else // case .setmovetype #creature_guid $move_type (with selected creature)
1331  {
1332  lowguid = atoi((char*)guid_str);
1333 
1334  /* impossible without entry
1335  if (lowguid)
1336  pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(),MAKE_GUID(lowguid,HIGHGUID_UNIT));
1337  */
1338 
1339  // attempt check creature existence by DB data
1340  if (!pCreature)
1341  {
1342  CreatureData const* data = sObjectMgr.GetCreatureData(lowguid);
1343  if (!data)
1344  {
1346  SetSentErrorMessage(true);
1347  return false;
1348  }
1349  }
1350  else
1351  lowguid = pCreature->GetDBTableGUIDLow();
1352  }
1353 
1354  // now lowguid is low guid really existed creature
1355  // and pCreature point (maybe) to this creature or NULL
1356 
1357  MovementGeneratorType move_type;
1358 
1359  std::string type = type_str;
1360 
1361  if (type == "stay")
1362  move_type = IDLE_MOTION_TYPE;
1363  else if (type == "random")
1364  move_type = RANDOM_MOTION_TYPE;
1365  else if (type == "way")
1366  move_type = WAYPOINT_MOTION_TYPE;
1367  else
1368  return false;
1369 
1370  if (pCreature)
1371  {
1372  // update movement type
1373  if (doNotDelete == false)
1374  pCreature->LoadPath(0);
1375 
1376  pCreature->SetDefaultMovementType(move_type);
1377  pCreature->GetMotionMaster()->Initialize();
1378  if (pCreature->IsAlive()) // dead creature will reset movement generator at respawn
1379  {
1380  pCreature->setDeathState(JUST_DIED);
1381  pCreature->Respawn();
1382  }
1383  pCreature->SaveToDB();
1384  }
1385  if (doNotDelete == false)
1387  else
1389 
1390  return true;
1391 }
1392 
1393 //set model of creature
1395 {
1396  if (!*args)
1397  return false;
1398 
1399  uint32 displayId = (uint32) atoi((char*)args);
1400 
1401  Creature* pCreature = getSelectedCreature();
1402 
1403  if (!pCreature || pCreature->IsPet())
1404  {
1406  SetSentErrorMessage(true);
1407  return false;
1408  }
1409 
1410  pCreature->SetDisplayId(displayId);
1411  pCreature->SetNativeDisplayId(displayId);
1412 
1413  pCreature->SaveToDB();
1414 
1415  return true;
1416 }
1417 
1418 //set faction of creature
1420 {
1421  if (!*args)
1422  return false;
1423 
1424  uint32 factionId = (uint32) atoi((char*)args);
1425 
1426  if (!sFactionTemplateStore.LookupEntry(factionId))
1427  {
1428  PSendSysMessage(LANG_WRONG_FACTION, factionId);
1429  SetSentErrorMessage(true);
1430  return false;
1431  }
1432 
1433  Creature* pCreature = getSelectedCreature();
1434 
1435  if (!pCreature)
1436  {
1438  SetSentErrorMessage(true);
1439  return false;
1440  }
1441 
1442  pCreature->SetFaction(factionId);
1443 
1444  // faction is set in creature_template - not inside creature
1445 
1446  // update in memory
1447  if (CreatureInfo const* cinfo = pCreature->GetCreatureTemplate())
1448  {
1449  const_cast<CreatureInfo*>(cinfo)->faction = factionId;
1450  }
1451 
1452  // and DB
1453  WorldDatabase.PExecuteLog("UPDATE creature_template SET faction = '%u' WHERE entry = '%u'", factionId, pCreature->GetEntry());
1454 
1455  return true;
1456 }
1457 
1458 //set spawn dist of creature
1460 {
1461  if (!*args)
1462  return false;
1463 
1464  float option = atof((char*)args);
1465  if (option < 0.0f)
1466  {
1468  return false;
1469  }
1470 
1472  if (option > 0.0f)
1473  mtype = RANDOM_MOTION_TYPE;
1474 
1475  Creature* pCreature = getSelectedCreature();
1476  uint32 u_guidlow = 0;
1477 
1478  if (pCreature)
1479  u_guidlow = pCreature->GetDBTableGUIDLow();
1480  else
1481  return false;
1482 
1483  pCreature->SetRespawnRadius((float)option);
1484  pCreature->SetDefaultMovementType(mtype);
1485  pCreature->GetMotionMaster()->Initialize();
1486  if (pCreature->IsAlive()) // dead creature will reset movement generator at respawn
1487  {
1488  pCreature->setDeathState(JUST_DIED);
1489  pCreature->Respawn();
1490  }
1491 
1492  WorldDatabase.PExecuteLog("UPDATE creature SET spawndist=%f, MovementType=%i WHERE guid=%u", option, mtype, u_guidlow);
1494  return true;
1495 }
1496 
1498 {
1499  if (!*args)
1500  return false;
1501 
1502  char* stime = strtok((char*)args, " ");
1503 
1504  if (!stime)
1505  return false;
1506 
1507  int i_stime = atoi((char*)stime);
1508 
1509  if (i_stime < 0)
1510  {
1512  SetSentErrorMessage(true);
1513  return false;
1514  }
1515 
1516  Creature* pCreature = getSelectedCreature();
1517  uint32 u_guidlow = 0;
1518 
1519  if (pCreature)
1520  u_guidlow = pCreature->GetDBTableGUIDLow();
1521  else
1522  return false;
1523 
1524  WorldDatabase.PExecuteLog("UPDATE creature SET spawntimesecs=%i WHERE guid=%u", i_stime, u_guidlow);
1525  pCreature->SetRespawnDelay((uint32)i_stime);
1527 
1528  return true;
1529 }
1530 
1531 bool ChatHandler::HandleNpcFollowCommand(const char* /*args*/)
1532 {
1533  Player* player = m_session->GetPlayer();
1534  Creature* creature = getSelectedCreature();
1535 
1536  if (!creature)
1537  {
1539  SetSentErrorMessage(true);
1540  return false;
1541  }
1542 
1545  player->UpdateObjectVisibility();
1546  // Follow player - Using pet's default dist and angle
1547  //creature->GetMotionMaster()->MoveFollow(player, PET_FOLLOW_DIST, PET_FOLLOW_ANGLE);
1548 
1550  return true;
1551 }
1552 
1553 bool ChatHandler::HandleNpcUnFollowCommand(const char* /*args*/)
1554 {
1555  Player* player = m_session->GetPlayer();
1556  Creature* creature = getSelectedCreature();
1557 
1558  if (!creature)
1559  {
1561  SetSentErrorMessage(true);
1562  return false;
1563  }
1564 
1565  if (/*creature->GetMotionMaster()->empty() ||*/
1567  {
1569  SetSentErrorMessage(true);
1570  return false;
1571  }
1572 
1574  = static_cast<FollowMovementGenerator<Creature> const*>((creature->GetMotionMaster()->top()));
1575 
1576  if (mgen->GetTarget() != player)
1577  {
1579  SetSentErrorMessage(true);
1580  return false;
1581  }
1582 
1583  // reset movement
1584  creature->GetMotionMaster()->MovementExpired(true);
1585 
1587  return true;
1588 }
1589 
1590 //@todo NpcCommands that need to be fixed :
1591 
1592 bool ChatHandler::HandleNameCommand(const char* /*args*/)
1593 {
1594  /* Temp. disabled
1595  if (!*args)
1596  return false;
1597 
1598  if (strlen((char*)args)>75)
1599  {
1600  PSendSysMessage(LANG_TOO_LONG_NAME, strlen((char*)args)-75);
1601  return true;
1602  }
1603 
1604  for (uint8 i = 0; i < strlen(args); ++i)
1605  {
1606  if (!isalpha(args[i]) && args[i] != ' ')
1607  {
1608  SendSysMessage(LANG_CHARS_ONLY);
1609  return false;
1610  }
1611  }
1612 
1613  uint64 guid;
1614  guid = m_session->GetPlayer()->GetSelection();
1615  if (guid == 0)
1616  {
1617  SendSysMessage(LANG_NO_SELECTION);
1618  return true;
1619  }
1620 
1621  Creature* pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(), guid);
1622 
1623  if (!pCreature)
1624  {
1625  SendSysMessage(LANG_SELECT_CREATURE);
1626  return true;
1627  }
1628 
1629  pCreature->SetName(args);
1630  uint32 idname = sObjectMgr.AddCreatureTemplate(pCreature->GetName());
1631  pCreature->SetUInt32Value(OBJECT_FIELD_ENTRY, idname);
1632 
1633  pCreature->SaveToDB();
1634  */
1635 
1636  return true;
1637 }
1638 
1639 bool ChatHandler::HandleSubNameCommand(const char* /*args*/)
1640 {
1641  /* Temp. disabled
1642 
1643  if (!*args)
1644  args = "";
1645 
1646  if (strlen((char*)args)>75)
1647  {
1648 
1649  PSendSysMessage(LANG_TOO_LONG_SUBNAME, strlen((char*)args)-75);
1650  return true;
1651  }
1652 
1653  for (uint8 i = 0; i < strlen(args); i++)
1654  {
1655  if (!isalpha(args[i]) && args[i] != ' ')
1656  {
1657  SendSysMessage(LANG_CHARS_ONLY);
1658  return false;
1659  }
1660  }
1661  uint64 guid;
1662  guid = m_session->GetPlayer()->GetSelection();
1663  if (guid == 0)
1664  {
1665  SendSysMessage(LANG_NO_SELECTION);
1666  return true;
1667  }
1668 
1669  Creature* pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(), guid);
1670 
1671  if (!pCreature)
1672  {
1673  SendSysMessage(LANG_SELECT_CREATURE);
1674  return true;
1675  }
1676 
1677  uint32 idname = sObjectMgr.AddCreatureSubName(pCreature->GetName(),args,pCreature->GetUInt32Value(UNIT_FIELD_DISPLAYID));
1678  pCreature->SetUInt32Value(OBJECT_FIELD_ENTRY, idname);
1679 
1680  pCreature->SaveToDB();
1681  */
1682  return true;
1683 }
1684 
1685 //move item to other slot
1687 {
1688  if (!*args)
1689  return false;
1690  uint8 srcslot, dstslot;
1691 
1692  char* pParam1 = strtok((char*)args, " ");
1693  if (!pParam1)
1694  return false;
1695 
1696  char* pParam2 = strtok(NULL, " ");
1697  if (!pParam2)
1698  return false;
1699 
1700  srcslot = (uint8)atoi(pParam1);
1701  dstslot = (uint8)atoi(pParam2);
1702 
1703  if (srcslot == dstslot)
1704  return true;
1705 
1707  return false;
1708 
1710  return false;
1711 
1712  uint16 src = ((INVENTORY_SLOT_BAG_0 << 8) | srcslot);
1713  uint16 dst = ((INVENTORY_SLOT_BAG_0 << 8) | dstslot);
1714 
1715  m_session->GetPlayer()->SwapItem(src, dst);
1716 
1717  return true;
1718 }
1719 
1720 //demorph player or unit
1721 bool ChatHandler::HandleDeMorphCommand(const char* /*args*/)
1722 {
1723  Unit* target = getSelectedUnit();
1724  if (!target)
1725  target = m_session->GetPlayer();
1726 
1727  target->DeMorph();
1728 
1729  return true;
1730 }
1731 
1732 //morph creature or player
1733 bool ChatHandler::HandleMorphCommand(const char* args)
1734 {
1735  if (!*args)
1736  return false;
1737 
1738  uint16 display_id = (uint16)atoi((char*)args);
1739 
1740  Unit* target = getSelectedUnit();
1741  if (!target)
1742  target = m_session->GetPlayer();
1743 
1744  target->SetDisplayId(display_id);
1745 
1746  return true;
1747 }
1748 
1749 //kick player
1751 {
1752  const char* kickName = strtok((char*)args, " ");
1753  char* kickReason = strtok(NULL, "\n");
1754  std::string reason = "No Reason";
1755  std::string kicker = "Console";
1756  if (kickReason)
1757  reason = kickReason;
1758  if (m_session)
1759  kicker = m_session->GetPlayer()->GetName();
1760 
1761  if (!kickName)
1762  {
1763  Player* player = getSelectedPlayer();
1764  if (!player)
1765  {
1767  SetSentErrorMessage(true);
1768  return false;
1769  }
1770 
1771  if (player == m_session->GetPlayer())
1772  {
1774  SetSentErrorMessage(true);
1775  return false;
1776  }
1777 
1778  if (sWorld.getConfig(CONFIG_SHOW_KICK_IN_WORLD) == 1)
1779  sWorld.SendWorldText(LANG_COMMAND_KICKMESSAGE, player->GetName(), kicker.c_str(), reason.c_str());
1780  else
1781  PSendSysMessage(LANG_COMMAND_KICKMESSAGE, player->GetName(), kicker.c_str(), reason.c_str());
1782 
1783  player->GetSession()->KickPlayer();
1784  }
1785  else
1786  {
1787  std::string name = kickName;
1788  if (!normalizePlayerName(name))
1789  {
1791  SetSentErrorMessage(true);
1792  return false;
1793  }
1794 
1795  if (m_session && name == m_session->GetPlayer()->GetName())
1796  {
1798  SetSentErrorMessage(true);
1799  return false;
1800  }
1801 
1802  Player* player = sObjectMgr.GetPlayer(kickName);
1803  if (!player)
1804  {
1806  SetSentErrorMessage(true);
1807  return false;
1808  }
1809 
1810  if (m_session && player->GetSession()->GetSecurity() > m_session->GetSecurity())
1811  {
1812  SendSysMessage(LANG_YOURS_SECURITY_IS_LOW); //maybe replacement string for this later on
1813  SetSentErrorMessage(true);
1814  return false;
1815  }
1816 
1817  if (sWorld.KickPlayer(name.c_str()))
1818  {
1819  if (sWorld.getConfig(CONFIG_SHOW_KICK_IN_WORLD) == 1)
1820 
1821  sWorld.SendWorldText(LANG_COMMAND_KICKMESSAGE, name.c_str(), kicker.c_str(), reason.c_str());
1822  else
1823  PSendSysMessage(LANG_COMMAND_KICKMESSAGE, name.c_str(), kicker.c_str(), reason.c_str());
1824  }
1825  else
1826  {
1828  return false;
1829  }
1830  }
1831  return true;
1832 }
1833 
1834 //set temporary phase mask for player
1836 {
1837  if (!*args)
1838  return false;
1839 
1840  uint32 phasemask = (uint32)atoi((char*)args);
1841 
1842  Unit *target = getSelectedUnit();
1843  if(!target)
1844  target = m_session->GetPlayer();
1845 
1846 
1847  target->SetPhaseMask(phasemask,true);
1848 
1849  return true;
1850 }
1851 
1852 //show info of player
1853 bool ChatHandler::HandlePInfoCommand(const char* args)
1854 {
1855  Player* target = NULL;
1856  uint64 targetGUID = 0;
1857 
1858  char* px = strtok((char*)args, " ");
1859  char* py = NULL;
1860 
1861  std::string name;
1862 
1863  if (px)
1864  {
1865  name = px;
1866 
1867  if (name.empty())
1868  return false;
1869 
1870  if (!normalizePlayerName(name))
1871  {
1873  SetSentErrorMessage(true);
1874  return false;
1875  }
1876 
1877  target = sObjectMgr.GetPlayer(name.c_str());
1878  if (target)
1879  py = strtok(NULL, " ");
1880  else
1881  {
1882  targetGUID = sObjectMgr.GetPlayerGUIDByName(name);
1883  if (targetGUID)
1884  py = strtok(NULL, " ");
1885  else
1886  py = px;
1887  }
1888  }
1889 
1890  if (!target && !targetGUID)
1891  target = getSelectedPlayer();
1892 
1893  if (!target && !targetGUID)
1894  {
1896  SetSentErrorMessage(true);
1897  return false;
1898  }
1899 
1900  uint32 accId = 0;
1901  uint32 money = 0;
1902  uint32 total_player_time = 0;
1903  uint32 level = 0;
1904  uint32 latency = 0;
1905  uint8 race;
1906  uint8 Class;
1907 
1908  // get additional information from Player object
1909  if (target)
1910  {
1911  targetGUID = target->GetGUID();
1912  name = target->GetName(); // re-read for case getSelectedPlayer() target
1913  accId = target->GetSession()->GetAccountId();
1914  money = target->GetMoney();
1915  total_player_time = target->GetTotalPlayedTime();
1916  level = target->getLevel();
1917  latency = target->GetSession()->GetLatency();
1918  race = target->getRace();
1919  Class = target->getClass();
1920  }
1921  // get additional information from DB
1922  else
1923  {
1924  QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT totaltime, level, money, account, race, class FROM characters WHERE guid = '%u'", GUID_LOPART(targetGUID));
1925  if (!result)
1926  {
1928  SetSentErrorMessage(true);
1929  return false;
1930  }
1931  Field* fields = result->Fetch();
1932  total_player_time = fields[0].GetUInt32();
1933  level = fields[1].GetUInt32();
1934  money = fields[2].GetUInt32();
1935  accId = fields[3].GetUInt32();
1936  race = fields[4].GetUInt8();
1937  Class = fields[5].GetUInt8();
1938  }
1939 
1940  std::string username = GetOregonString(LANG_ERROR);
1941  std::string email = GetOregonString(LANG_ERROR);
1942  std::string last_ip = GetOregonString(LANG_ERROR);
1943  uint32 security = 0;
1944  std::string last_login = GetOregonString(LANG_ERROR);
1945 
1946  QueryResult_AutoPtr result = LoginDatabase.PQuery("SELECT a.username,aa.gmlevel,a.email,a.last_ip,a.last_login "
1947  "FROM account a "
1948  "LEFT JOIN account_access aa "
1949  "ON (a.id = aa.id) "
1950  "WHERE a.id = '%u'", accId);
1951  if (result)
1952  {
1953  Field* fields = result->Fetch();
1954  username = fields[0].GetCppString();
1955  security = fields[1].GetUInt32();
1956  email = fields[2].GetCppString();
1957 
1958  if (email.empty())
1959  email = "-";
1960 
1961  if (!m_session || m_session->GetSecurity() >= security)
1962  {
1963  last_ip = fields[3].GetCppString();
1964  last_login = fields[4].GetCppString();
1965 
1966  uint32 ip = inet_addr(last_ip.c_str());
1967  #if OREGON_ENDIAN == BIGENDIAN
1969  #endif
1970 
1971  if (QueryResult_AutoPtr result2 = WorldDatabase.PQuery("SELECT c.country FROM ip2nationCountries c, ip2nation i WHERE "
1972  "i.ip < %u AND c.code = i.country ORDER BY i.ip DESC LIMIT 0,1", ip))
1973  {
1974  Field* fields2 = result2->Fetch();
1975  last_ip.append(" (");
1976  last_ip.append(fields2[0].GetString());
1977  last_ip.append(")");
1978  }
1979  }
1980  else
1981  {
1982  last_ip = "-";
1983  last_login = "-";
1984  }
1985  }
1986 
1987  PSendSysMessage(LANG_PINFO_ACCOUNT, (target ? "" : GetOregonString(LANG_OFFLINE)), name.c_str(), GUID_LOPART(targetGUID), username.c_str(), accId, email.c_str(), security, last_ip.c_str(), last_login.c_str(), latency);
1988 
1989  std::string race_s, Class_s;
1990  switch (race)
1991  {
1992  case RACE_HUMAN:
1993  race_s = "Human";
1994  break;
1995  case RACE_ORC:
1996  race_s = "Orc";
1997  break;
1998  case RACE_DWARF:
1999  race_s = "Dwarf";
2000  break;
2001  case RACE_NIGHTELF:
2002  race_s = "Night Elf";
2003  break;
2004  case RACE_UNDEAD_PLAYER:
2005  race_s = "Undead";
2006  break;
2007  case RACE_TAUREN:
2008  race_s = "Tauren";
2009  break;
2010  case RACE_GNOME:
2011  race_s = "Gnome";
2012  break;
2013  case RACE_TROLL:
2014  race_s = "Troll";
2015  break;
2016  case RACE_BLOODELF:
2017  race_s = "Blood Elf";
2018  break;
2019  case RACE_DRAENEI:
2020  race_s = "Draenei";
2021  break;
2022  }
2023  switch (Class)
2024  {
2025  case CLASS_WARRIOR:
2026  Class_s = "Warrior";
2027  break;
2028  case CLASS_PALADIN:
2029  Class_s = "Paladin";
2030  break;
2031  case CLASS_HUNTER:
2032  Class_s = "Hunter";
2033  break;
2034  case CLASS_ROGUE:
2035  Class_s = "Rogue";
2036  break;
2037  case CLASS_PRIEST:
2038  Class_s = "Priest";
2039  break;
2040  case CLASS_SHAMAN:
2041  Class_s = "Shaman";
2042  break;
2043  case CLASS_MAGE:
2044  Class_s = "Mage";
2045  break;
2046  case CLASS_WARLOCK:
2047  Class_s = "Warlock";
2048  break;
2049  case CLASS_DRUID:
2050  Class_s = "Druid";
2051  break;
2052  }
2053 
2054  std::string timeStr = secsToTimeString(total_player_time, true, true);
2055  uint32 gold = money / GOLD;
2056  uint32 silv = (money % GOLD) / SILVER;
2057  uint32 copp = (money % GOLD) % SILVER;
2058  PSendSysMessage(LANG_PINFO_LEVEL, race_s.c_str(), Class_s.c_str(), timeStr.c_str(), level, gold, silv, copp);
2059 
2060  if (py && strncmp(py, "rep", 3) == 0)
2061  {
2062  if (!target)
2063  {
2064  // rep option not implemented for offline case
2066  SetSentErrorMessage(true);
2067  return false;
2068  }
2069 
2070  const char* FactionName;
2071  FactionStateList const& targetFSL = target->GetReputationMgr().GetStateList();
2072  for (FactionStateList::const_iterator itr = targetFSL.begin(); itr != targetFSL.end(); ++itr)
2073  {
2074  FactionEntry const* factionEntry = sFactionStore.LookupEntry(itr->second.ID);
2075  if (factionEntry)
2076  FactionName = factionEntry->name[m_session->GetSessionDbcLocale()];
2077  else
2078  FactionName = "#Not found#";
2079  ReputationRank rank = target->GetReputationMgr().GetRank(factionEntry);
2080  std::string rankName = GetOregonString(ReputationRankStrIndex[rank]);
2081  std::ostringstream ss;
2082  ss << itr->second.ID << ": |cffffffff|Hfaction:" << itr->second.ID << "|h[" << FactionName << "]|h|r " << rankName << "|h|r (" << target->GetReputationMgr().GetReputation(factionEntry) << ")";
2083 
2084  if (itr->second.Flags & FACTION_FLAG_VISIBLE)
2086  if (itr->second.Flags & FACTION_FLAG_AT_WAR)
2088  if (itr->second.Flags & FACTION_FLAG_PEACE_FORCED)
2090  if (itr->second.Flags & FACTION_FLAG_HIDDEN)
2092  if (itr->second.Flags & FACTION_FLAG_INVISIBLE_FORCED)
2094  if (itr->second.Flags & FACTION_FLAG_INACTIVE)
2096 
2097  SendSysMessage(ss.str().c_str());
2098  }
2099  }
2100  return true;
2101 }
2102 
2103 // WAYPOINT COMMANDS
2104 
2105 bool ChatHandler::HandleWpAddCommand(const char* args)
2106 {
2107  sLog.outDebug("DEBUG: HandleWpAddCommand");
2108 
2109  // optional
2110  char* path_number = NULL;
2111  uint32 pathid = 0;
2112 
2113  if (*args)
2114  path_number = strtok((char*)args, " ");
2115 
2116  uint32 point = 0;
2117  Creature* target = getSelectedCreature();
2118 
2119  if (!path_number)
2120  {
2121  if (target)
2122  pathid = target->GetWaypointPath();
2123  else
2124  {
2125  QueryResult_AutoPtr result = WorldDatabase.Query("SELECT MAX(id) FROM waypoint_data");
2126  uint32 maxpathid = result->Fetch()->GetInt32();
2127  pathid = maxpathid + 1;
2128  sLog.outDebug("DEBUG: HandleWpAddCommand - New path started.");
2129  PSendSysMessage("%s%s|r", "|cff00ff00", "New path started.");
2130  }
2131  }
2132  else
2133  pathid = atoi(path_number);
2134 
2135  // path_id -> ID of the Path
2136  // point -> number of the waypoint (if not 0)
2137 
2138  if (!pathid)
2139  {
2140  sLog.outDebug("DEBUG: HandleWpAddCommand - Current creature has no loaded path.");
2141  PSendSysMessage("%s%s|r", "|cffff33ff", "Current creature has no loaded path.");
2142  return true;
2143  }
2144 
2145  sLog.outDebug("DEBUG: HandleWpAddCommand - point == 0");
2146 
2147  QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT MAX(point) FROM waypoint_data WHERE id = '%u'", pathid);
2148 
2149  if (result)
2150  point = (*result)[0].GetUInt32();
2151 
2152  Player* player = m_session->GetPlayer();
2153  //Map *map = player->GetMap();
2154 
2155  WorldDatabase.PExecuteLog("INSERT INTO waypoint_data (id, point, position_x, position_y, position_z) VALUES ('%u','%u','%f', '%f', '%f')",
2156  pathid, point + 1, player->GetPositionX(), player->GetPositionY(), player->GetPositionZ());
2157 
2158  PSendSysMessage("%s%s%u%s%u%s|r", "|cff00ff00", "PathID: |r|cff00ffff", pathid, "|r|cff00ff00: Waypoint |r|cff00ffff", point+1, "|r|cff00ff00 created. ");
2159  return true;
2160 } // HandleWpAddCommand
2161 
2163 {
2164  if (!*args)
2165  return false;
2166 
2167  // optional
2168  char* path_number = NULL;
2169 
2170  if (*args)
2171  path_number = strtok((char*)args, " ");
2172 
2173  uint32 pathid = 0;
2174  uint32 guidlow = 0;
2175  Creature* target = getSelectedCreature();
2176 
2177  // Did player provide a path_id?
2178  if (!path_number)
2179  sLog.outDebug("DEBUG: HandleWpLoadPathCommand - No path number provided");
2180 
2181  if (!target)
2182  {
2184  SetSentErrorMessage(true);
2185  return false;
2186  }
2187 
2188  if (target->GetEntry() == 1)
2189  {
2190  PSendSysMessage("%s%s|r", "|cffff33ff", "You want to load path to a waypoint? Aren't you?");
2191  SetSentErrorMessage(true);
2192  return false;
2193  }
2194 
2195  pathid = atoi(path_number);
2196 
2197  if (!pathid)
2198  {
2199  PSendSysMessage("%s%s|r", "|cffff33ff", "No vallid path number provided.");
2200  return true;
2201  }
2202 
2203  guidlow = target->GetDBTableGUIDLow();
2204  QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT guid FROM creature_addon WHERE guid = '%u'", guidlow);
2205 
2206  if (result)
2207  WorldDatabase.PExecute("UPDATE creature_addon SET path_id = '%u' WHERE guid = '%u'", pathid, guidlow);
2208  else
2209  WorldDatabase.PExecute("INSERT INTO creature_addon(guid,path_id) VALUES ('%u','%u')", guidlow, pathid);
2210 
2211  WorldDatabase.PExecute("UPDATE creature SET MovementType = '%u' WHERE guid = '%u'", WAYPOINT_MOTION_TYPE, guidlow);
2212 
2213  target->LoadPath(pathid);
2215  target->GetMotionMaster()->Initialize();
2216  target->Say("Path loaded.", 0, 0);
2217 
2218  return true;
2219 }
2220 
2222 {
2223  if (!*args)
2224  return false;
2225 
2226  uint32 id = atoi(args);
2227 
2228  if (!id)
2229  return false;
2230 
2231  PSendSysMessage("%s%s|r|cff00ffff%u|r", "|cff00ff00", "Loading Path: ", id);
2232  sWaypointMgr->ReloadPath(id);
2233  return true;
2234 }
2235 
2236 bool ChatHandler::HandleWpUnLoadPathCommand(const char* /*args*/)
2237 {
2238  uint32 guidlow = 0;
2239  Creature* target = getSelectedCreature();
2240 
2241  if (!target)
2242  {
2243  PSendSysMessage("%s%s|r", "|cff33ffff", "You must select target.");
2244  return true;
2245  }
2246 
2247  if (target->GetCreatureAddon())
2248  {
2249  if (target->GetCreatureAddon()->path_id != 0)
2250  {
2251  WorldDatabase.PExecute("DELETE FROM creature_addon WHERE guid = %u", target->GetGUIDLow());
2252  target->UpdateWaypointID(0);
2253  WorldDatabase.PExecute("UPDATE creature SET MovementType = '%u' WHERE guid = '%u'", IDLE_MOTION_TYPE, guidlow);
2254  target->LoadPath(0);
2256  target->GetMotionMaster()->MoveTargetedHome();
2257  target->GetMotionMaster()->Initialize();
2258  target->Say("Path unloaded.", 0, 0);
2259  return true;
2260  }
2261  PSendSysMessage("%s%s|r", "|cffff33ff", "Target has no loaded path.");
2262  }
2263  return true;
2264 }
2265 
2267 {
2268  if (!*args)
2269  return false;
2270 
2271  char* show_str = strtok((char*)args, " ");
2272  std::string show = show_str;
2273 
2274  // Check
2275  if ((show != "add") && (show != "mod") && (show != "del") && (show != "listid")) return false;
2276 
2277  char* arg_id = strtok(NULL, " ");
2278  uint32 id = 0;
2279 
2280  if (show == "add")
2281  {
2282  if (arg_id)
2283  id = atoi(arg_id);
2284 
2285  if (id)
2286  {
2287  QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT id FROM waypoint_scripts WHERE guid = %u", id);
2288 
2289  if (!result)
2290  {
2291  WorldDatabase.PExecute("INSERT INTO waypoint_scripts(guid)VALUES(%u)", id);
2292  PSendSysMessage("%s%s%u|r", "|cff00ff00", "Wp Event: New waypoint event added: ", id);
2293  }
2294  else
2295  PSendSysMessage("|cff00ff00Wp Event: You have chosen an existing waypoint script guid: %u|r", id);
2296  }
2297  else
2298  {
2299  QueryResult_AutoPtr result = WorldDatabase.Query("SELECT MAX(guid) FROM waypoint_scripts");
2300  id = result->Fetch()->GetUInt32();
2301  WorldDatabase.PExecute("INSERT INTO waypoint_scripts(guid)VALUES(%u)", id + 1);
2302  PSendSysMessage("%s%s%u|r", "|cff00ff00", "Wp Event: New waypoint event added: |r|cff00ffff", id + 1);
2303  }
2304 
2305  return true;
2306  }
2307 
2308  if (show == "listid")
2309  {
2310  if (!arg_id)
2311  {
2312  PSendSysMessage("%s%s|r", "|cff33ffff", "Wp Event: You must provide waypoint script id.");
2313  return true;
2314  }
2315 
2316  id = atoi(arg_id);
2317 
2318  uint32 a2, a3, a4, a5, a6;
2319  float a8, a9, a10, a11;
2320  char const* a7;
2321 
2322  QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT guid, delay, command, datalong, datalong2, dataint, x, y, z, o FROM waypoint_scripts WHERE id = %u", id);
2323 
2324  if (!result)
2325  {
2326  PSendSysMessage("%s%s%u|r", "|cff33ffff", "Wp Event: No waypoint scripts found on id: ", id);
2327  return true;
2328  }
2329 
2330  Field* fields;
2331 
2332  do
2333  {
2334  fields = result->Fetch();
2335  a2 = fields[0].GetUInt32();
2336  a3 = fields[1].GetUInt32();
2337  a4 = fields[2].GetUInt32();
2338  a5 = fields[3].GetUInt32();
2339  a6 = fields[4].GetUInt32();
2340  a7 = fields[5].GetString();
2341  a8 = fields[6].GetFloat();
2342  a9 = fields[7].GetFloat();
2343  a10 = fields[8].GetFloat();
2344  a11 = fields[9].GetFloat();
2345 
2346  PSendSysMessage("|cffff33ffid:|r|cff00ffff %u|r|cff00ff00, guid: |r|cff00ffff%u|r|cff00ff00, delay: |r|cff00ffff%u|r|cff00ff00, command: |r|cff00ffff%u|r|cff00ff00, datalong: |r|cff00ffff%u|r|cff00ff00, datalong2: |r|cff00ffff%u|r|cff00ff00, datatext: |r|cff00ffff%s|r|cff00ff00, posx: |r|cff00ffff%f|r|cff00ff00, posy: |r|cff00ffff%f|r|cff00ff00, posz: |r|cff00ffff%f|r|cff00ff00, orientation: |r|cff00ffff%f|r", id, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11);
2347  }
2348  while (result->NextRow());
2349  }
2350 
2351  if (show == "del")
2352  {
2353  id = atoi(arg_id);
2354 
2355  QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT guid FROM waypoint_scripts WHERE guid = %u", id);
2356 
2357  if (result)
2358  {
2359  WorldDatabase.PExecuteLog("DELETE FROM waypoint_scripts WHERE guid = %u", id);
2360  PSendSysMessage("%s%s%u|r", "|cff00ff00", "Wp Event: Waypoint script removed: ", id);
2361  }
2362  else
2363  PSendSysMessage("|cffff33ffWp Event: ERROR: you have selected an invalid script: %u|r", id);
2364 
2365  return true;
2366  }
2367 
2368  if (show == "mod")
2369  {
2370  if (!arg_id)
2371  {
2372  SendSysMessage("|cffff33ffERROR: Waypoint script guid not present.|r");
2373  return true;
2374  }
2375 
2376  id = atoi(arg_id);
2377 
2378  if (!id)
2379  {
2380  SendSysMessage("|cffff33ffERROR: No vallid waypoint script id not present.|r");
2381  return true;
2382  }
2383 
2384  char* arg_2 = strtok(NULL, " ");
2385 
2386  if (!arg_2)
2387  {
2388  SendSysMessage("|cffff33ffERROR: No argument present.|r");
2389  return true;
2390  }
2391 
2392  std::string arg_string = arg_2;
2393 
2394  if ((arg_string != "setid") && (arg_string != "delay") && (arg_string != "command")
2395  && (arg_string != "datalong") && (arg_string != "datalong2") && (arg_string != "dataint") && (arg_string != "posx")
2396  && (arg_string != "posy") && (arg_string != "posz") && (arg_string != "orientation"))
2397  {
2398  SendSysMessage("|cffff33ffERROR: No valid argument present.|r");
2399  return true;
2400  }
2401 
2402  char* arg_3;
2403  std::string arg_str_2 = arg_2;
2404  arg_3 = strtok(NULL, " ");
2405 
2406  if (!arg_3)
2407  {
2408  SendSysMessage("|cffff33ffERROR: No additional argument present.|r");
2409  return true;
2410  }
2411 
2412  float coord;
2413 
2414  if (arg_str_2 == "setid")
2415  {
2416  uint32 newid = atoi(arg_3);
2417  PSendSysMessage("%s%s|r|cff00ffff%u|r|cff00ff00%s|r|cff00ffff%u|r", "|cff00ff00", "Wp Event: Wypoint scipt guid: ", newid, " id changed: ", id);
2418  WorldDatabase.PExecuteLog("UPDATE waypoint_scripts SET id='%u' WHERE guid='%u'",
2419  newid, id);
2420  return true;
2421  }
2422  else
2423  {
2424  QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT id FROM waypoint_scripts WHERE guid='%u'", id);
2425 
2426  if (!result)
2427  {
2428  SendSysMessage("|cffff33ffERROR: You have selected an invalid waypoint script guid.|r");
2429  return true;
2430  }
2431 
2432  if (arg_str_2 == "posx")
2433  {
2434  coord = atof(arg_3);
2435  WorldDatabase.PExecuteLog("UPDATE waypoint_scripts SET x='%f' WHERE guid='%u'",
2436  coord, id);
2437  PSendSysMessage("|cff00ff00Waypoint script:|r|cff00ffff %u|r|cff00ff00 position_x updated.|r", id);
2438  return true;
2439  }
2440  else if (arg_str_2 == "posy")
2441  {
2442  coord = atof(arg_3);
2443  WorldDatabase.PExecuteLog("UPDATE waypoint_scripts SET y='%f' WHERE guid='%u'",
2444  coord, id);
2445  PSendSysMessage("|cff00ff00Waypoint script: %u position_y updated.|r", id);
2446  return true;
2447  }
2448  else if (arg_str_2 == "posz")
2449  {
2450  coord = atof(arg_3);
2451  WorldDatabase.PExecuteLog("UPDATE waypoint_scripts SET z='%f' WHERE guid='%u'",
2452  coord, id);
2453  PSendSysMessage("|cff00ff00Waypoint script: |r|cff00ffff%u|r|cff00ff00 position_z updated.|r", id);
2454  return true;
2455  }
2456  else if (arg_str_2 == "orientation")
2457  {
2458  coord = atof(arg_3);
2459  WorldDatabase.PExecuteLog("UPDATE waypoint_scripts SET o='%f' WHERE guid='%u'",
2460  coord, id);
2461  PSendSysMessage("|cff00ff00Waypoint script: |r|cff00ffff%u|r|cff00ff00 orientation updated.|r", id);
2462  return true;
2463  }
2464  else if (arg_str_2 == "dataint")
2465  {
2466  WorldDatabase.PExecuteLog("UPDATE waypoint_scripts SET %s='%u' WHERE guid='%u'",
2467  arg_2, atoi(arg_3), id);
2468  PSendSysMessage("|cff00ff00Waypoint script: |r|cff00ffff%u|r|cff00ff00 dataint updated.|r", id);
2469  return true;
2470  }
2471  else
2472  {
2473  std::string arg_str_3 = arg_3;
2474  WorldDatabase.escape_string(arg_str_3);
2475  WorldDatabase.PExecuteLog("UPDATE waypoint_scripts SET %s='%s' WHERE guid='%u'",
2476  arg_2, arg_str_3.c_str(), id);
2477  }
2478  }
2479  PSendSysMessage("%s%s|r|cff00ffff%u:|r|cff00ff00 %s %s|r", "|cff00ff00", "Waypoint script:", id, arg_2, "updated.");
2480  }
2481  return true;
2482 }
2483 
2485 {
2486  sLog.outDebug("DEBUG: HandleWpModifyCommand");
2487 
2488  if (!*args)
2489  return false;
2490 
2491  // first arg: add del text emote spell waittime move
2492  char* show_str = strtok((char*)args, " ");
2493  if (!show_str)
2494  return false;
2495 
2496  std::string show = show_str;
2497  // Check
2498  // Remember: "show" must also be the name of a column!
2499  if ((show != "delay") && (show != "action") && (show != "action_chance")
2500  && (show != "move_type") && (show != "del") && (show != "move") && (show != "wpadd")
2501  )
2502  return false;
2503 
2504  // Next arg is: <PATHID> <WPNUM> <ARGUMENT>
2505  char* arg_str = NULL;
2506 
2507  // Did user provide a GUID
2508  // or did the user select a creature?
2509  // -> variable lowguid is filled with the GUID of the NPC
2510  uint32 pathid = 0;
2511  uint32 point = 0;
2512  uint32 wpGuid = 0;
2513  Creature* target = getSelectedCreature();
2514 
2515  if (!target || target->GetEntry() != VISUAL_WAYPOINT)
2516  {
2517  SendSysMessage("|cffff33ffERROR: You must select a waypoint.|r");
2518  return false;
2519  }
2520 
2521  sLog.outDebug("DEBUG: HandleWpModifyCommand - User did select an NPC");
2522  // The visual waypoint
2523  Creature* wpCreature = NULL;
2524  wpGuid = target->GetGUIDLow();
2525 
2526  // Did the user select a visual spawnpoint?
2527  if (wpGuid)
2529  // attempt check creature existence by DB data
2530  else
2531  {
2533  return false;
2534  }
2535  // User did select a visual waypoint?
2536  // Check the creature
2537  if (wpCreature->GetEntry() == VISUAL_WAYPOINT)
2538  {
2539  QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT id, point FROM waypoint_data WHERE wpguid = %u", wpGuid);
2540 
2541  if (!result)
2542  {
2543  sLog.outDebug("DEBUG: HandleWpModifyCommand - No waypoint found - used 'wpguid'");
2544 
2546  // Select waypoint number from database
2547  // Since we compare float values, we have to deal with
2548  // some difficulties.
2549  // Here we search for all waypoints that only differ in one from 1 thousand
2550  // (0.001) - There is no other way to compare C++ floats with mySQL floats
2551  // See also: http://dev.mysql.com/doc/refman/5.0/en/problems-with-float.html
2552  const char* maxDIFF = "0.01";
2553  result = WorldDatabase.PQuery("SELECT id, point FROM waypoint_data WHERE (abs(position_x - %f) <= %s) and (abs(position_y - %f) <= %s) and (abs(position_z - %f) <= %s)",
2554  wpCreature->GetPositionX(), maxDIFF, wpCreature->GetPositionY(), maxDIFF, wpCreature->GetPositionZ(), maxDIFF);
2555  if (!result)
2556  {
2558  return true;
2559  }
2560  }
2561  sLog.outDebug("DEBUG: HandleWpModifyCommand - After getting wpGuid");
2562 
2563  do
2564  {
2565  Field* fields = result->Fetch();
2566  pathid = fields[0].GetUInt32();
2567  point = fields[1].GetUInt32();
2568  }
2569  while (result->NextRow());
2570 
2571  // We have the waypoint number and the GUID of the "master npc"
2572  // Text is enclosed in "<>", all other arguments not
2573  arg_str = strtok((char*)NULL, " ");
2574  }
2575 
2576  sLog.outDebug("DEBUG: HandleWpModifyCommand - Parameters parsed - now execute the command");
2577 
2578  // Check for argument
2579  if (show != "del" && show != "move" && arg_str == NULL)
2580  {
2582  return false;
2583  }
2584 
2585  if (show == "del" && target)
2586  {
2587  PSendSysMessage("|cff00ff00DEBUG: wp modify del, PathID: |r|cff00ffff%u|r", pathid);
2588 
2589  // wpCreature
2590  Creature* wpCreature = NULL;
2591 
2592  if (wpGuid != 0)
2593  {
2595  wpCreature->CombatStop();
2596  wpCreature->DeleteFromDB();
2597  wpCreature->AddObjectToRemoveList();
2598  }
2599 
2600  WorldDatabase.PExecuteLog("DELETE FROM waypoint_data WHERE id='%u' AND point='%u'",
2601  pathid, point);
2602  WorldDatabase.PExecuteLog("UPDATE waypoint_data SET point=point-1 WHERE id='%u' AND point>'%u'",
2603  pathid, point);
2604 
2606  return true;
2607  } // del
2608 
2609  if (show == "move" && target)
2610  {
2611  PSendSysMessage("|cff00ff00DEBUG: wp move, PathID: |r|cff00ffff%u|r", pathid);
2612 
2613  Player* chr = m_session->GetPlayer();
2614  Map* map = chr->GetMap();
2615  {
2616  // wpCreature
2617  Creature* wpCreature = NULL;
2618  // What to do:
2619  // Move the visual spawnpoint
2620  // Respawn the owner of the waypoints
2621  if (wpGuid != 0)
2622  {
2624  wpCreature->CombatStop();
2625  wpCreature->DeleteFromDB();
2626  wpCreature->AddObjectToRemoveList();
2627  // re-create
2628  Creature* wpCreature2 = new Creature;
2629  if (!wpCreature2->Create(sObjectMgr.GenerateLowGuid(HIGHGUID_UNIT), map, PHASEMASK_NORMAL, VISUAL_WAYPOINT, 0, chr->GetPositionX(), chr->GetPositionY(), chr->GetPositionZ(), chr->GetOrientation()))
2630  {
2631  PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED, VISUAL_WAYPOINT);
2632  delete wpCreature2;
2633  return false;
2634  }
2635 
2636  wpCreature2->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), chr->GetPhaseMaskForSpawn());
2637  // To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells();
2638  //TODO: Should we first use "Create" then use "LoadFromDB"?
2639  if (!wpCreature2->LoadCreatureFromDB(wpCreature2->GetDBTableGUIDLow(), map))
2640  {
2641  PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED, VISUAL_WAYPOINT);
2642  delete wpCreature2;
2643  return false;
2644  }
2645  }
2646 
2647  WorldDatabase.PExecuteLog("UPDATE waypoint_data SET position_x = '%f',position_y = '%f',position_z = '%f' where id = '%u' AND point='%u'",
2648  chr->GetPositionX(), chr->GetPositionY(), chr->GetPositionZ(), pathid, point);
2649 
2651  }
2652  return true;
2653  } // move
2654 
2655  const char* text = arg_str;
2656 
2657  if (text == 0)
2658  {
2659  // show_str check for present in list of correct values, no sql injection possible
2660  WorldDatabase.PExecuteLog("UPDATE waypoint_data SET %s=NULL WHERE id='%u' AND point='%u'",
2661  show_str, pathid, point);
2662  }
2663  else
2664  {
2665  // show_str check for present in list of correct values, no sql injection possible
2666  std::string text2 = text;
2668  WorldDatabase.PExecuteLog("UPDATE waypoint_data SET %s='%s' WHERE id='%u' AND point='%u'",
2669  show_str, text2.c_str(), pathid, point);
2670  }
2671 
2673  return true;
2674 }
2675 
2676 bool ChatHandler::HandleWpShowCommand(const char* args)
2677 {
2678  sLog.outDebug("DEBUG: HandleWpShowCommand");
2679 
2680  if (!*args)
2681  return false;
2682 
2683  // first arg: on, off, first, last
2684  char* show_str = strtok((char*)args, " ");
2685  if (!show_str)
2686  return false;
2687 
2688  // second arg: GUID (optional, if a creature is selected)
2689  char* guid_str = strtok((char*)NULL, " ");
2690  sLog.outDebug("DEBUG: HandleWpShowCommand: show_str: %s guid_str: %s", show_str, guid_str);
2691 
2692  uint32 pathid = 0;
2693  Creature* target = getSelectedCreature();
2694 
2695  // Did player provide a PathID?
2696 
2697  if (!guid_str)
2698  {
2699  sLog.outDebug("DEBUG: HandleWpShowCommand: !guid_str");
2700  // No PathID provided
2701  // -> Player must have selected a creature
2702 
2703  if (!target)
2704  {
2706  SetSentErrorMessage(true);
2707  return false;
2708  }
2709 
2710  pathid = target->GetWaypointPath();
2711  }
2712  else
2713  {
2714  sLog.outDebug("|cff00ff00DEBUG: HandleWpShowCommand: PathID provided|r");
2715  // PathID provided
2716  // Warn if player also selected a creature
2717  // -> Creature selection is ignored <-
2718  if (target)
2720 
2721  pathid = atoi((char*)guid_str);
2722  }
2723 
2724  sLog.outDebug("DEBUG: HandleWpShowCommand: danach");
2725 
2726  std::string show = show_str;
2727  uint32 Maxpoint;
2728 
2729  sLog.outDebug("DEBUG: HandleWpShowCommand: PathID: %u", pathid);
2730 
2731  //PSendSysMessage("wpshow - show: %s", show);
2732 
2733  // Show info for the selected waypoint
2734  if (show == "info")
2735  {
2736  // Check if the user did specify a visual waypoint
2737  if (target->GetEntry() != VISUAL_WAYPOINT)
2738  {
2740  SetSentErrorMessage(true);
2741  return false;
2742  }
2743 
2744  QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT id, point, delay, move_type, action, action_chance FROM waypoint_data WHERE wpguid = %u", target->GetGUIDLow());
2745 
2746  if (!result)
2747  {
2749  return true;
2750  }
2751 
2752  SendSysMessage("|cff00ffffDEBUG: wp show info:|r");
2753  do
2754  {
2755  Field* fields = result->Fetch();
2756  pathid = fields[0].GetUInt32();
2757  uint32 point = fields[1].GetUInt32();
2758  uint32 delay = fields[2].GetUInt32();
2759  uint32 flag = fields[3].GetUInt32();
2760  uint32 ev_id = fields[4].GetUInt32();
2761  uint32 ev_chance = fields[5].GetUInt32();
2762 
2763  PSendSysMessage("|cff00ff00Show info: for current point: |r|cff00ffff%u|r|cff00ff00, Path ID: |r|cff00ffff%u|r", point, pathid);
2764  PSendSysMessage("|cff00ff00Show info: delay: |r|cff00ffff%u|r", delay);
2765  PSendSysMessage("|cff00ff00Show info: Move flag: |r|cff00ffff%u|r", flag);
2766  PSendSysMessage("|cff00ff00Show info: Waypoint event: |r|cff00ffff%u|r", ev_id);
2767  PSendSysMessage("|cff00ff00Show info: Event chance: |r|cff00ffff%u|r", ev_chance);
2768  }
2769  while (result->NextRow());
2770 
2771  return true;
2772  }
2773 
2774  if (show == "on")
2775  {
2776  QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT point, position_x,position_y,position_z FROM waypoint_data WHERE id = '%u'", pathid);
2777 
2778  if (!result)
2779  {
2780  SendSysMessage("|cffff33ffPath no found.|r");
2781  SetSentErrorMessage(true);
2782  return false;
2783  }
2784 
2785  PSendSysMessage("|cff00ff00DEBUG: wp on, PathID: |cff00ffff%u|r", pathid);
2786 
2787  // Delete all visuals for this NPC
2788  QueryResult_AutoPtr result2 = WorldDatabase.PQuery("SELECT wpguid FROM waypoint_data WHERE id = '%u' and wpguid <> 0", pathid);
2789 
2790  if (result2)
2791  {
2792  bool hasError = false;
2793  do
2794  {
2795  Field* fields = result2->Fetch();
2796  uint32 wpguid = fields[0].GetUInt32();
2798 
2799  if (!pCreature)
2800  {
2802  hasError = true;
2803  WorldDatabase.PExecuteLog("DELETE FROM creature WHERE guid = '%u'", wpguid);
2804  }
2805  else
2806  {
2807  pCreature->CombatStop();
2808  pCreature->DeleteFromDB();
2809  pCreature->AddObjectToRemoveList();
2810  }
2811 
2812  }
2813  while (result2->NextRow());
2814 
2815  if (hasError)
2816  {
2820  }
2821  }
2822 
2823  do
2824  {
2825  Field* fields = result->Fetch();
2826  uint32 point = fields[0].GetUInt32();
2827  float x = fields[1].GetFloat();
2828  float y = fields[2].GetFloat();
2829  float z = fields[3].GetFloat();
2830 
2831  uint32 id = VISUAL_WAYPOINT;
2832 
2833  Player* chr = m_session->GetPlayer();
2834  Map* map = chr->GetMap();
2835  float o = chr->GetOrientation();
2836 
2837  Creature* wpCreature = new Creature;
2838  if (!wpCreature->Create(sObjectMgr.GenerateLowGuid(HIGHGUID_UNIT), map, chr->GetPhaseMaskForSpawn(), id, 0, x, y, z, o))
2839  {
2841  delete wpCreature;
2842  return false;
2843  }
2844 
2845  sLog.outDebug("DEBUG: UPDATE waypoint_data SET wpguid = '%u'", wpCreature->GetGUIDLow());
2846  // set "wpguid" column to the visual waypoint
2847  WorldDatabase.PExecuteLog("UPDATE waypoint_data SET wpguid = '%u' WHERE id = '%u' and point = '%u'", wpCreature->GetGUIDLow(), pathid, point);
2848 
2849  wpCreature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), chr->GetPhaseMaskForSpawn());
2850  if (!wpCreature->LoadCreatureFromDB(wpCreature->GetDBTableGUIDLow(), map))
2851  {
2853  delete wpCreature;
2854  return false;
2855  }
2856 
2857  if (target)
2858  {
2859  wpCreature->SetDisplayId(target->GetDisplayId());
2860  wpCreature->SetObjectScale(0.5);
2861  }
2862  }
2863  while (result->NextRow());
2864 
2865  SendSysMessage("|cff00ff00Showing the current creature's path.|r");
2866  return true;
2867  }
2868 
2869  if (show == "first")
2870  {
2871  PSendSysMessage("|cff00ff00DEBUG: wp first, GUID: %u|r", pathid);
2872 
2873  QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT position_x,position_y,position_z,orientation FROM waypoint_data WHERE point='1' AND id = '%u'", pathid);
2874  if (!result)
2875  {
2877  SetSentErrorMessage(true);
2878  return false;
2879  }
2880 
2881  Field* fields = result->Fetch();
2882  float x = fields[0].GetFloat();
2883  float y = fields[1].GetFloat();
2884  float z = fields[2].GetFloat();
2885  float o = fields[3].GetFloat();
2886  uint32 id = VISUAL_WAYPOINT;
2887 
2888  Player* chr = m_session->GetPlayer();
2889  Map* map = chr->GetMap();
2890 
2891  Creature* creature = new Creature;
2892  if (!creature->Create(sObjectMgr.GenerateLowGuid(HIGHGUID_UNIT), map, chr->GetPhaseMaskForSpawn(), id, 0, x, y, z, o))
2893  {
2895  delete creature;
2896  return false;
2897  }
2898 
2899  creature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), chr->GetPhaseMaskForSpawn());
2900  if (!creature->LoadCreatureFromDB(creature->GetDBTableGUIDLow(), map))
2901  {
2903  delete creature;
2904  return false;
2905  }
2906 
2907  if (target)
2908  {
2909  creature->SetDisplayId(target->GetDisplayId());
2910  creature->SetObjectScale(0.5);
2911  }
2912 
2913  return true;
2914  }
2915 
2916  if (show == "last")
2917  {
2918  PSendSysMessage("|cff00ff00DEBUG: wp last, PathID: |r|cff00ffff%u|r", pathid);
2919 
2920  QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT MAX(point) FROM waypoint_data WHERE id = '%u'", pathid);
2921  if (result)
2922  Maxpoint = (*result)[0].GetUInt32();
2923  else
2924  Maxpoint = 0;
2925 
2926  result = WorldDatabase.PQuery("SELECT position_x,position_y,position_z FROM waypoint_data WHERE point ='%u' AND id = '%u'", Maxpoint, pathid);
2927  if (!result)
2928  {
2930  SetSentErrorMessage(true);
2931  return false;
2932  }
2933  Field* fields = result->Fetch();
2934  float x = fields[0].GetFloat();
2935  float y = fields[1].GetFloat();
2936  float z = fields[2].GetFloat();
2937  float o = fields[3].GetFloat();
2938  uint32 id = VISUAL_WAYPOINT;
2939 
2940  Player* chr = m_session->GetPlayer();
2941  Map* map = chr->GetMap();
2942 
2943  Creature* creature = new Creature;
2944  if (!creature->Create(sObjectMgr.GenerateLowGuid(HIGHGUID_UNIT), map, chr->GetPhaseMaskForSpawn(), id, 0, x, y, z, o))
2945  {
2947  delete creature;
2948  return false;
2949  }
2950 
2951  creature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()), chr->GetPhaseMaskForSpawn());
2952  if (!creature->LoadCreatureFromDB(creature->GetDBTableGUIDLow(), map))
2953  {
2955  delete creature;
2956  return false;
2957  }
2958 
2959  if (target)
2960  {
2961  creature->SetDisplayId(target->GetDisplayId());
2962  creature->SetObjectScale(0.5);
2963  }
2964 
2965  return true;
2966  }
2967 
2968  if (show == "off")
2969  {
2970  QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT guid FROM creature WHERE id = '%u'", 1);
2971  if (!result)
2972  {
2974  SetSentErrorMessage(true);
2975  return false;
2976  }
2977  bool hasError = false;
2978  do
2979  {
2980  Field* fields = result->Fetch();
2981  uint32 guid = fields[0].GetUInt32();
2983  if (!creature)
2984  {
2986  hasError = true;
2987  WorldDatabase.PExecuteLog("DELETE FROM creature WHERE guid = '%u'", guid);
2988  }
2989  else
2990  {
2991  creature->CombatStop();
2992  creature->DeleteFromDB();
2993  creature->AddObjectToRemoveList();
2994  }
2995  }
2996  while (result->NextRow());
2997  // set "wpguid" column to "empty" - no visual waypoint spawned
2998  WorldDatabase.PExecuteLog("UPDATE waypoint_data SET wpguid = '0'");
2999  //WorldDatabase.PExecuteLog("UPDATE creature_movement SET wpguid = '0' WHERE wpguid <> '0'");
3000 
3001  if (hasError)
3002  {
3006  }
3007 
3009  return true;
3010  }
3011 
3012  PSendSysMessage("|cffff33ffDEBUG: wpshow - no valid command found|r");
3013  return true;
3014 }
3015 
3016 // WAYPOINT COMMANDS
3017 
3018 //rename characters
3020 {
3021  Player* target = NULL;
3022  uint64 targetGUID = 0;
3023  std::string oldname;
3024 
3025  char* px = strtok((char*)args, " ");
3026 
3027  if (px)
3028  {
3029  oldname = px;
3030 
3031  if (!normalizePlayerName(oldname))
3032  {
3034  SetSentErrorMessage(true);
3035  return false;
3036  }
3037 
3038  target = sObjectMgr.GetPlayer(oldname.c_str());
3039 
3040  if (!target)
3041  targetGUID = sObjectMgr.GetPlayerGUIDByName(oldname);
3042  }
3043 
3044  if (!target && !targetGUID)
3045  target = getSelectedPlayer();
3046 
3047  if (!target && !targetGUID)
3048  {
3050  SetSentErrorMessage(true);
3051  return false;
3052  }
3053 
3054  if (target)
3055  {
3058  }
3059  else
3060  {
3061  PSendSysMessage(LANG_RENAME_PLAYER_GUID, oldname.c_str(), GUID_LOPART(targetGUID));
3062  CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '1' WHERE guid = '%u'", GUID_LOPART(targetGUID));
3063  }
3064 
3065  return true;
3066 }
3067 
3069 {
3070  if (!*args)
3071  return false;
3072 
3073  // Can be NULL at console call
3074  Player* target = getSelectedPlayer ();
3075 
3076  std::string namepart = args;
3077  std::wstring wnamepart;
3078 
3079  if (!Utf8toWStr (namepart, wnamepart))
3080  return false;
3081 
3082  // converting string that we try to find to lower case
3083  wstrToLower (wnamepart);
3084 
3085  uint32 counter = 0; // Counter for figure out that we found smth.
3086 
3087  for (uint32 id = 0; id < sFactionStore.GetNumRows(); ++id)
3088  {
3089  FactionEntry const* factionEntry = sFactionStore.LookupEntry (id);
3090  if (factionEntry)
3091  {
3092  FactionState const* factionState = target ? target->GetReputationMgr().GetState(factionEntry) : NULL;
3093 
3094  int loc = m_session ? int(m_session->GetSessionDbcLocale()) : sWorld.GetDefaultDbcLocale();
3095  std::string name = factionEntry->name[loc];
3096  if (name.empty())
3097  continue;
3098 
3099  if (!Utf8FitTo(name, wnamepart))
3100  {
3101  loc = 0;
3102  for (; loc < MAX_LOCALE; ++loc)
3103  {
3104  if (m_session && loc == m_session->GetSessionDbcLocale())
3105  continue;
3106 
3107  name = factionEntry->name[loc];
3108  if (name.empty())
3109  continue;
3110 
3111  if (Utf8FitTo(name, wnamepart))
3112  break;
3113  }
3114  }
3115 
3116  if (loc < MAX_LOCALE)
3117  {
3118  // send faction in "id - [faction] rank reputation [visible] [at war] [own team] [unknown] [invisible] [inactive]" format
3119  // or "id - [faction] [no reputation]" format
3120  std::ostringstream ss;
3121  if (m_session)
3122  ss << id << " - |cffffffff|Hfaction:" << id << "|h[" << name << " " << localeNames[loc] << "]|h|r";
3123  else
3124  ss << id << " - " << name << " " << localeNames[loc];
3125 
3126  if (factionState) // and then target != NULL also
3127  {
3128  ReputationRank rank = target->GetReputationMgr().GetRank(factionEntry);
3129  std::string rankName = GetOregonString(ReputationRankStrIndex[rank]);
3130 
3131  ss << " " << rankName << "|h|r (" << target->GetReputationMgr().GetReputation(factionEntry) << ")";
3132 
3133  if (factionState->Flags & FACTION_FLAG_VISIBLE)
3135  if (factionState->Flags & FACTION_FLAG_AT_WAR)
3137  if (factionState->Flags & FACTION_FLAG_PEACE_FORCED)
3139  if (factionState->Flags & FACTION_FLAG_HIDDEN)
3141  if (factionState->Flags & FACTION_FLAG_INVISIBLE_FORCED)
3143  if (factionState->Flags & FACTION_FLAG_INACTIVE)
3145  }
3146  else
3148 
3149  SendSysMessage(ss.str().c_str());
3150  counter++;
3151  }
3152  }
3153  }
3154 
3155  if (counter == 0) // if counter == 0 then we found nth
3157  return true;
3158 }
3159 
3160 //show animation
3161 bool ChatHandler::HandleAnimCommand(const char* args)
3162 {
3163  if (!*args)
3164  return false;
3165 
3166  uint32 anim_id = atoi((char*)args);
3167  m_session->GetPlayer()->HandleEmoteCommand(anim_id);
3168  return true;
3169 }
3170 
3171 //change standstate
3173 {
3174  if (!*args)
3175  return false;
3176 
3177  uint32 anim_id = atoi((char*)args);
3179 
3180  return true;
3181 }
3182 
3184 {
3185  if (!*args)
3186  return false;
3187 
3188  Player* target = getSelectedPlayer();
3189  if (!target)
3190  {
3192  SetSentErrorMessage(true);
3193  return false;
3194  }
3195 
3196  uint32 amount = (uint32)atoi(args);
3197  target->RewardHonor(NULL, 1, amount);
3198  return true;
3199 }
3200 
3201 bool ChatHandler::HandleHonorAddKillCommand(const char* /*args*/)
3202 {
3203  Unit* target = getSelectedUnit();
3204  if (!target)
3205  {
3207  SetSentErrorMessage(true);
3208  return false;
3209  }
3210 
3211  m_session->GetPlayer()->RewardHonor(target, 1);
3212  return true;
3213 }
3214 
3216 {
3217  Player* target = getSelectedPlayer();
3218  if (!target)
3219  {
3221  SetSentErrorMessage(true);
3222  return false;
3223  }
3224 
3225  target->UpdateHonorFields();
3226  return true;
3227 }
3228 
3230 {
3231  if (!*args)
3232  return false;
3233 
3234  std::string namepart = args;
3235  std::wstring wnamepart;
3236 
3237  // converting string that we try to find to lower case
3238  if (!Utf8toWStr(namepart, wnamepart))
3239  return false;
3240 
3241  wstrToLower(wnamepart);
3242 
3243  bool found = false;
3244  uint32 count = 0;
3245  uint32 maxResults = sWorld.getConfig(CONFIG_MAX_RESULTS_LOOKUP_COMMANDS);
3246 
3247  GameEventMgr::GameEventDataMap const& events = sGameEventMgr.GetEventMap();
3248  GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr.GetActiveEventList();
3249 
3250  for (uint32 id = 0; id < events.size(); ++id)
3251  {
3252  GameEventData const& eventData = events[id];
3253 
3254  std::string descr = eventData.description;
3255  if (descr.empty())
3256  continue;
3257 
3258  if (Utf8FitTo(descr, wnamepart))
3259  {
3260  if (maxResults && count++ == maxResults)
3261  {
3263  return true;
3264  }
3265 
3266  char const* active = activeEvents.find(id) != activeEvents.end() ? GetOregonString(LANG_ACTIVE) : "";
3267 
3268  if (m_session)
3269  PSendSysMessage(LANG_EVENT_ENTRY_LIST_CHAT, id, id, eventData.description.c_str(), active);
3270  else
3271  PSendSysMessage(LANG_EVENT_ENTRY_LIST_CONSOLE, id, eventData.description.c_str(), active);
3272 
3273  if (!found)
3274  found = true;
3275  }
3276  }
3277 
3278  if (!found)
3280 
3281  return true;
3282 }
3283 
3285 {
3286  uint32 counter = 0;
3287 
3288  GameEventMgr::GameEventDataMap const& events = sGameEventMgr.GetEventMap();
3289  GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr.GetActiveEventList();
3290 
3291  char const* active = GetOregonString(LANG_ACTIVE);
3292 
3293  for (GameEventMgr::ActiveEvents::const_iterator itr = activeEvents.begin(); itr != activeEvents.end(); ++itr)
3294  {
3295  uint32 event_id = *itr;
3296  GameEventData const& eventData = events[event_id];
3297 
3298  if (m_session)
3299  PSendSysMessage(LANG_EVENT_ENTRY_LIST_CHAT, event_id, event_id, eventData.description.c_str(), active);
3300  else
3301  PSendSysMessage(LANG_EVENT_ENTRY_LIST_CONSOLE, event_id, eventData.description.c_str(), active);
3302 
3303  ++counter;
3304  }
3305 
3306  if (counter == 0)
3308 
3309  return true;
3310 }
3311 
3313 {
3314  if (!*args)
3315  return false;
3316 
3317  // id or [name] Shift-click form |color|Hgameevent:id|h[name]|h|r
3318  char* cId = extractKeyFromLink((char*)args, "Hgameevent");
3319  if (!cId)
3320  return false;
3321 
3322  uint32 event_id = atoi(cId);
3323 
3324  GameEventMgr::GameEventDataMap const& events = sGameEventMgr.GetEventMap();
3325 
3326  if (event_id >= events.size())
3327  {
3329  SetSentErrorMessage(true);
3330  return false;
3331  }
3332 
3333  GameEventData const& eventData = events[event_id];
3334  if (!eventData.isValid())
3335  {
3337  SetSentErrorMessage(true);
3338  return false;
3339  }
3340 
3341  GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr.GetActiveEventList();
3342  bool active = activeEvents.find(event_id) != activeEvents.end();
3343  char const* activeStr = active ? GetOregonString(LANG_ACTIVE) : "";
3344 
3345  std::string startTimeStr = TimeToTimestampStr(eventData.start);
3346  std::string endTimeStr = TimeToTimestampStr(eventData.end);
3347 
3348  uint32 delay = sGameEventMgr.NextCheck(event_id);
3349  time_t nextTime = time(NULL) + delay;
3350  std::string nextStr = nextTime >= eventData.start && nextTime < eventData.end ? TimeToTimestampStr(time(NULL) + delay) : "-";
3351 
3352  std::string occurenceStr = secsToTimeString(eventData.occurence * MINUTE);
3353  std::string lengthStr = secsToTimeString(eventData.length * MINUTE);
3354 
3355  PSendSysMessage(LANG_EVENT_INFO, event_id, eventData.description.c_str(), activeStr,
3356  startTimeStr.c_str(), endTimeStr.c_str(), occurenceStr.c_str(), lengthStr.c_str(),
3357  nextStr.c_str());
3358  return true;
3359 }
3360 
3362 {
3363  if (!*args)
3364  return false;
3365 
3366  // id or [name] Shift-click form |color|Hgameevent:id|h[name]|h|r
3367  char* cId = extractKeyFromLink((char*)args, "Hgameevent");
3368  if (!cId)
3369  return false;
3370 
3371  int32 event_id = atoi(cId);
3372 
3373  GameEventMgr::GameEventDataMap const& events = sGameEventMgr.GetEventMap();
3374 
3375  if (event_id < 1 || uint32(event_id) >= events.size())
3376  {
3378  SetSentErrorMessage(true);
3379  return false;
3380  }
3381 
3382  GameEventData const& eventData = events[event_id];
3383  if (!eventData.isValid())
3384  {
3386  SetSentErrorMessage(true);
3387  return false;
3388  }
3389 
3390  GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr.GetActiveEventList();
3391  if (activeEvents.find(event_id) != activeEvents.end())
3392  {
3394  SetSentErrorMessage(true);
3395  return false;
3396  }
3397 
3398  sGameEventMgr.StartEvent(event_id, true);
3399  return true;
3400 }
3401 
3403 {
3404  if (!*args)
3405  return false;
3406 
3407  // id or [name] Shift-click form |color|Hgameevent:id|h[name]|h|r
3408  char* cId = extractKeyFromLink((char*)args, "Hgameevent");
3409  if (!cId)
3410  return false;
3411 
3412  int32 event_id = atoi(cId);
3413 
3414  GameEventMgr::GameEventDataMap const& events = sGameEventMgr.GetEventMap();
3415 
3416  if (event_id < 1 || uint32(event_id) >= events.size())
3417  {
3419  SetSentErrorMessage(true);
3420  return false;
3421  }
3422 
3423  GameEventData const& eventData = events[event_id];
3424  if (!eventData.isValid())
3425  {
3427  SetSentErrorMessage(true);
3428  return false;
3429  }
3430 
3431  GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr.GetActiveEventList();
3432 
3433  if (activeEvents.find(event_id) == activeEvents.end())
3434  {
3436  SetSentErrorMessage(true);
3437  return false;
3438  }
3439 
3440  sGameEventMgr.StopEvent(event_id, true);
3441  return true;
3442 }
3443 
3445 {
3446  Player* player;
3447 
3448  if (*args)
3449  {
3450  std::string playername = args;
3451 
3452  if (!normalizePlayerName(playername))
3453  {
3455  SetSentErrorMessage(true);
3456  return false;
3457  }
3458 
3459  player = sObjectMgr.GetPlayer(playername.c_str());
3460 
3461  if (!player)
3462  {
3464  SetSentErrorMessage(true);
3465  return false;
3466  }
3467  }
3468  else
3469  {
3470  player = getSelectedPlayer();
3471 
3472  if (!player)
3473  player = m_session->GetPlayer();
3474  }
3475 
3476  player->CombatStop();
3478  return true;
3479 }
3480 
3482 {
3483  uint32 classmask = m_session->GetPlayer()->getClassMask();
3484 
3485  for (uint32 i = 0; i < sSkillLineStore.GetNumRows(); ++i)
3486  {
3487  SkillLineEntry const* skillInfo = sSkillLineStore.LookupEntry(i);
3488  if (!skillInfo)
3489  continue;
3490 
3491  if (skillInfo->categoryId == SKILL_CATEGORY_PROFESSION || skillInfo->categoryId == SKILL_CATEGORY_SECONDARY)
3492  {
3493  for (uint32 j = 0; j < sSkillLineAbilityStore.GetNumRows(); ++j)
3494  {
3495  SkillLineAbilityEntry const* skillLine = sSkillLineAbilityStore.LookupEntry(j);
3496  if (!skillLine)
3497  continue;
3498 
3499  // skip racial skills
3500  if (skillLine->racemask != 0)
3501  continue;
3502 
3503  // skip wrong class skills
3504  if (skillLine->classmask && (skillLine->classmask & classmask) == 0)
3505  continue;
3506 
3507  if (skillLine->skillId != i || skillLine->forward_spellid)
3508  continue;
3509 
3510  SpellEntry const* spellInfo = sSpellStore.LookupEntry(skillLine->spellId);
3511  if (!spellInfo || !SpellMgr::IsSpellValid(spellInfo, m_session->GetPlayer(), false))
3512  continue;
3513 
3514  m_session->GetPlayer()->LearnSpell(skillLine->spellId);
3515  }
3516  }
3517  }
3518 
3520  return true;
3521 }
3522 
3524 {
3525  // Learns all recipes of specified profession and sets skill to max
3526  // Example: .learn all_recipes enchanting
3527 
3528  Player* target = getSelectedPlayer();
3529  if (!target)
3530  {
3532  return false;
3533  }
3534 
3535  if (!*args)
3536  return false;
3537 
3538  std::wstring wnamepart;
3539 
3540  if (!Utf8toWStr(args, wnamepart))
3541  return false;
3542 
3543  // converting string that we try to find to lower case
3544  wstrToLower(wnamepart);
3545 
3546  uint32 classmask = m_session->GetPlayer()->getClassMask();
3547 
3548  for (uint32 i = 0; i < sSkillLineStore.GetNumRows(); ++i)
3549  {
3550  SkillLineEntry const* skillInfo = sSkillLineStore.LookupEntry(i);
3551  if (!skillInfo)
3552  continue;
3553 
3554  if (skillInfo->categoryId != SKILL_CATEGORY_PROFESSION &&
3555  skillInfo->categoryId != SKILL_CATEGORY_SECONDARY)
3556  continue;
3557 
3558  int loc = m_session->GetSessionDbcLocale();
3559  std::string name = skillInfo->name[loc];
3560 
3561  if (Utf8FitTo(name, wnamepart))
3562  {
3563  for (uint32 j = 0; j < sSkillLineAbilityStore.GetNumRows(); ++j)
3564  {
3565  SkillLineAbilityEntry const* skillLine = sSkillLineAbilityStore.LookupEntry(j);
3566  if (!skillLine)
3567  continue;
3568 
3569  if (skillLine->skillId != i || skillLine->forward_spellid)
3570  continue;
3571 
3572  // skip racial skills
3573  if (skillLine->racemask != 0)
3574  continue;
3575 
3576  // skip wrong class skills
3577  if (skillLine->classmask && (skillLine->classmask & classmask) == 0)
3578  continue;
3579 
3580  SpellEntry const* spellInfo = sSpellStore.LookupEntry(skillLine->spellId);
3581  if (!spellInfo || !SpellMgr::IsSpellValid(spellInfo, m_session->GetPlayer(), false))
3582  continue;
3583 
3584  if (!target->HasSpell(spellInfo->Id))
3585  m_session->GetPlayer()->LearnSpell(skillLine->spellId);
3586  }
3587 
3588  uint16 maxLevel = target->GetPureMaxSkillValue(skillInfo->id);
3589  target->SetSkill(skillInfo->id, maxLevel, maxLevel);
3591  return true;
3592  }
3593  }
3594 
3595  return false;
3596 }
3597 
3599 {
3600 
3601  if (!*args)
3602  return false;
3603 
3604  std::string ip = strtok ((char*)args, " ");
3605  char* limit_str = strtok (NULL, " ");
3606  int32 limit = limit_str ? atoi (limit_str) : -1;
3607 
3609 
3610  QueryResult_AutoPtr result = LoginDatabase.PQuery ("SELECT id,username FROM account WHERE last_ip = '%s'", ip.c_str ());
3611 
3612  return LookupPlayerSearchCommand (result, limit);
3613 }
3614 
3616 {
3617  if (!*args)
3618  return false;
3619 
3620  std::string account = strtok ((char*)args, " ");
3621  char* limit_str = strtok (NULL, " ");
3622  int32 limit = limit_str ? atoi (limit_str) : -1;
3623 
3624  if (!AccountMgr::normalizeString (account))
3625  return false;
3626 
3627  LoginDatabase.escape_string (account);
3628 
3629  QueryResult_AutoPtr result = LoginDatabase.PQuery ("SELECT id,username FROM account WHERE username = '%s'", account.c_str ());
3630 
3631  return LookupPlayerSearchCommand (result, limit);
3632 }
3633 
3635 {
3636 
3637  if (!*args)
3638  return false;
3639 
3640  std::string email = strtok ((char*)args, " ");
3641  char* limit_str = strtok (NULL, " ");
3642  int32 limit = limit_str ? atoi (limit_str) : -1;
3643 
3644  LoginDatabase.escape_string (email);
3645 
3646  QueryResult_AutoPtr result = LoginDatabase.PQuery ("SELECT id,username FROM account WHERE email = '%s'", email.c_str ());
3647 
3648  return LookupPlayerSearchCommand (result, limit);
3649 }
3650 
3652 {
3653  if (!result)
3654  {
3656  SetSentErrorMessage(true);
3657  return false;
3658  }
3659 
3660  int i = 0;
3661  uint32 count = 0;
3662  uint32 maxResults = sWorld.getConfig(CONFIG_MAX_RESULTS_LOOKUP_COMMANDS);
3663  do
3664  {
3665  if (maxResults && count++ == maxResults)
3666  {
3668  return true;
3669  }
3670 
3671  Field* fields = result->Fetch();
3672  uint32 acc_id = fields[0].GetUInt32();
3673  std::string acc_name = fields[1].GetCppString();
3674 
3675  QueryResult_AutoPtr chars = CharacterDatabase.PQuery("SELECT guid,name FROM characters WHERE account = '%u'", acc_id);
3676  if (chars)
3677  {
3678  PSendSysMessage(LANG_LOOKUP_PLAYER_ACCOUNT, acc_name.c_str(), acc_id);
3679 
3680  uint64 guid = 0;
3681  std::string name;
3682 
3683  do
3684  {
3685  Field* charfields = chars->Fetch();
3686  guid = charfields[0].GetUInt64();
3687  name = charfields[1].GetCppString();
3688 
3689  PSendSysMessage(LANG_LOOKUP_PLAYER_CHARACTER, name.c_str(), guid);
3690  ++i;
3691 
3692  }
3693  while (chars->NextRow() && (limit == -1 || i < limit));
3694  }
3695  }
3696  while (result->NextRow());
3697 
3698  return true;
3699 }
3700 
3701 // Triggering corpses expire check in world
3703 {
3705  return true;
3706 }
3707 
3708 bool ChatHandler::HandleRepairitemsCommand(const char* /*args*/)
3709 {
3710  Player* target = getSelectedPlayer();
3711 
3712  if (!target)
3713  {
3715  SetSentErrorMessage(true);
3716  return false;
3717  }
3718 
3719  // Repair items
3720  target->DurabilityRepairAll(false, 0, false);
3721 
3723  if (needReportToTarget(target))
3724  ChatHandler(target).PSendSysMessage(LANG_YOUR_ITEMS_REPAIRED, GetName());
3725  return true;
3726 }
3727 
3728 bool ChatHandler::HandleCreatePetCommand(const char* /*args*/)
3729 {
3730  Player* player = m_session->GetPlayer();
3731  Creature* creatureTarget = getSelectedCreature();
3732 
3733  if (!creatureTarget || creatureTarget->IsPet() || creatureTarget->GetTypeId() == TYPEID_PLAYER)
3734  {
3736  SetSentErrorMessage(true);
3737  return false;
3738  }
3739 
3740  CreatureInfo const* cInfo = sObjectMgr.GetCreatureTemplate(creatureTarget->GetEntry());
3741  // Creatures with family CREATURE_FAMILY_NONE crashes the server
3742  if (cInfo->family == CREATURE_FAMILY_NONE)
3743  {
3744  PSendSysMessage("This creature cannot be tamed. Family id: 0 (CREATURE_FAMILY_NONE).");
3745  SetSentErrorMessage(true);
3746  return false;
3747  }
3748 
3749  if (player->GetPetGUID())
3750  {
3751  PSendSysMessage("You already have a pet");
3752  SetSentErrorMessage(true);
3753  return false;
3754  }
3755 
3756  // Everything looks OK, create new pet
3757  Pet* pet = new Pet(player, HUNTER_PET);
3758 
3759  if (!pet)
3760  return false;
3761 
3762  if (!pet->CreateBaseAtCreature(creatureTarget))
3763  {
3764  delete pet;
3765  PSendSysMessage("Error 1");
3766  return false;
3767  }
3768 
3769  creatureTarget->setDeathState(JUST_DIED);
3770  creatureTarget->RemoveCorpse();
3771  creatureTarget->SetHealth(0); // just for nice GM-mode view
3772 
3773  pet->SetUInt64Value(UNIT_FIELD_CREATEDBY, player->GetGUID());
3775 
3776  if (!pet->InitStatsForLevel(creatureTarget->getLevel()))
3777  {
3778  sLog.outError("InitStatsForLevel() in EffectTameCreature failed! Pet deleted.");
3779  PSendSysMessage("Error 2");
3780  delete pet;
3781  return false;
3782  }
3783 
3784  // prepare visual effect for levelup
3785  pet->SetUInt32Value(UNIT_FIELD_LEVEL, creatureTarget->getLevel() - 1);
3786 
3787  pet->GetCharmInfo()->SetPetNumber(sObjectMgr.GeneratePetNumber(), true);
3788  // this enables pet details window (Shift+P)
3789  pet->InitPetCreateSpells();
3790  pet->SetHealth(pet->GetMaxHealth());
3791 
3792  pet->GetMap()->AddToMap(pet->ToCreature());
3793 
3794  // visual effect for levelup
3795  pet->SetUInt32Value(UNIT_FIELD_LEVEL, creatureTarget->getLevel());
3796 
3797  player->SetMinion(pet, true);
3799  player->PetSpellInitialize();
3800 
3801  return true;
3802 }
3803 
3805 {
3806  if (!*args)
3807  return false;
3808 
3809  Player* plr = m_session->GetPlayer();
3810  Pet* pet = plr->GetPet();
3811 
3812  if (!pet)
3813  {
3814  PSendSysMessage("You have no pet");
3815  SetSentErrorMessage(true);
3816  return false;
3817  }
3818 
3819  uint32 spellId = extractSpellIdFromLink((char*)args);
3820 
3821  if (!spellId || !sSpellStore.LookupEntry(spellId))
3822  return false;
3823 
3824  // Check if pet already has it
3825  if (pet->HasSpell(spellId))
3826  {
3827  PSendSysMessage("Pet already has spell: %u", spellId);
3828  SetSentErrorMessage(true);
3829  return false;
3830  }
3831 
3832  // Check if spell is valid
3833  SpellEntry const* spellInfo = sSpellStore.LookupEntry(spellId);
3834  if (!spellInfo || !SpellMgr::IsSpellValid(spellInfo))
3835  {
3837  SetSentErrorMessage(true);
3838  return false;
3839  }
3840 
3841  pet->learnSpell(spellId);
3842 
3843  PSendSysMessage("Pet has learned spell %u", spellId);
3844  return true;
3845 }
3846 
3848 {
3849  if (!*args)
3850  return false;
3851 
3852  Player* plr = m_session->GetPlayer();
3853  Pet* pet = plr->GetPet();
3854 
3855  if (!pet)
3856  {
3857  PSendSysMessage("You have no pet");
3858  SetSentErrorMessage(true);
3859  return false;
3860  }
3861 
3862  uint32 spellId = extractSpellIdFromLink((char*)args);
3863 
3864  if (pet->HasSpell(spellId))
3865  pet->removeSpell(spellId);
3866  else
3867  PSendSysMessage("Pet doesn't have that spell");
3868 
3869  return true;
3870 }
3871 
3872 bool ChatHandler::HandlePetTpCommand(const char* args)
3873 {
3874  if (!*args)
3875  return false;
3876 
3877  Player* plr = m_session->GetPlayer();
3878  Pet* pet = plr->GetPet();
3879 
3880  if (!pet)
3881  {
3882  PSendSysMessage("You have no pet");
3883  SetSentErrorMessage(true);
3884  return false;
3885  }
3886 
3887  uint32 tp = atol(args);
3888 
3889  pet->SetTP(tp);
3890 
3891  PSendSysMessage("Pet's tp changed to %u", tp);
3892  return true;
3893 }
3894 
3896 {
3897  if (!*args)
3898  return false;
3899 
3900  char* cId = extractKeyFromLink((char*)args, "Hgameobject");
3901  if (!cId)
3902  return false;
3903 
3904  uint32 lowguid = atoi(cId);
3905  if (!lowguid)
3906  return false;
3907 
3908  GameObject* obj = NULL;
3909 
3910  // by DB guid
3911  if (GameObjectData const* go_data = sObjectMgr.GetGOData(lowguid))
3912  obj = GetObjectGlobalyWithGuidOrNearWithDbGuid(lowguid, go_data->id);
3913 
3914  if (!obj)
3915  {
3917  SetSentErrorMessage(true);
3918  return false;
3919  }
3920 
3921  // Activate
3922  obj->SetLootState(GO_READY);
3923  obj->UseDoorOrButton(10000, false, m_session->GetPlayer());
3924 
3925  PSendSysMessage("Object activated!");
3926 
3927  return true;
3928 }
3929 
3930 // add creature, temp only
3932 {
3933  if (!*args)
3934  return false;
3935  char* charID = strtok((char*)args, " ");
3936  if (!charID)
3937  return false;
3938 
3939  Player* chr = m_session->GetPlayer();
3940 
3941  float x = chr->GetPositionX();
3942  float y = chr->GetPositionY();
3943  float z = chr->GetPositionZ();
3944  float ang = chr->GetOrientation();
3945 
3946  uint32 id = atoi(charID);
3947 
3948  chr->SummonCreature(id, x, y, z, ang, TEMPSUMMON_CORPSE_DESPAWN, 120);
3949 
3950  return true;
3951 }
3952 
3953 // add go, temp only
3955 {
3956  if (!*args)
3957  return false;
3958  char* id = strtok((char*)args, " ");
3959  if (!id)
3960  return false;
3961 
3962  Player* player = m_session->GetPlayer();
3963 
3964  char* spawntime = strtok(NULL, " ");
3965  uint32 spawntm = 0;
3966 
3967  if (spawntime)
3968  spawntm = atoi((char*)spawntime);
3969 
3970  float x = player->GetPositionX();
3971  float y = player->GetPositionY();
3972  float z = player->GetPositionZ();
3973  float ang = player->GetOrientation();
3974 
3975  float rot2 = sin(ang / 2);
3976  float rot3 = cos(ang / 2);
3977 
3978  uint32 objectId = atoi(id);
3979 
3980  if (!sObjectMgr.GetGameObjectInfo(objectId))
3981  {
3983  SetSentErrorMessage(true);
3984  return false;
3985  }
3986 
3987  player->SummonGameObject(objectId, x, y, z, ang, 0, 0, rot2, rot3, spawntm);
3988 
3989  return true;
3990 }
3991 
3993 {
3994  if (!*args)
3995  return false;
3996 
3997  uint32 linkguid = (uint32) atoi((char*)args);
3998 
3999  Creature* pCreature = getSelectedCreature();
4000 
4001  if (!pCreature)
4002  {
4004  SetSentErrorMessage(true);
4005  return false;
4006  }
4007 
4008  if (!pCreature->GetDBTableGUIDLow())
4009  {
4010  PSendSysMessage("Selected creature (GUID: %u) isn't in creature table", pCreature->GetGUIDLow());
4011  SetSentErrorMessage(true);
4012  return false;
4013  }
4014 
4015  if (!sObjectMgr.SetCreatureLinkedRespawn(pCreature->GetDBTableGUIDLow(), linkguid))
4016  {
4017  PSendSysMessage("Selected creature can't link with guid '%u'", linkguid);
4018  SetSentErrorMessage(true);
4019  return false;
4020  }
4021 
4022  PSendSysMessage("LinkGUID '%u' added to creature with DBTableGUID: '%u'", linkguid, pCreature->GetDBTableGUIDLow());
4023  return true;
4024 }
4025 
4027 {
4028  if (!*args)
4029  return false;
4030 
4031  // can be NULL in console call
4032  Player* target = getSelectedPlayer();
4033 
4034  // title name have single string arg for player name
4035  char const* targetName = target ? target->GetName() : "NAME";
4036 
4037  std::string namepart = args;
4038  std::wstring wnamepart;
4039 
4040  if (!Utf8toWStr(namepart, wnamepart))
4041  return false;
4042 
4043  // converting string that we try to find to lower case
4044  wstrToLower(wnamepart);
4045 
4046  uint32 counter = 0; // Counter for figure out that we found smth.
4047  uint32 maxResults = sWorld.getConfig(CONFIG_MAX_RESULTS_LOOKUP_COMMANDS);
4048 
4049  // Search in CharTitles.dbc
4050  for (uint32 id = 0; id < sCharTitlesStore.GetNumRows(); id++)
4051  {
4052  CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(id);
4053  if (titleInfo)
4054  {
4055  int loc = m_session->GetSessionDbcLocale();
4056  std::string name = titleInfo->name[loc];
4057  if (name.empty())
4058  continue;
4059 
4060  if (!Utf8FitTo(name, wnamepart))
4061  {
4062  loc = 0;
4063  for (; loc < MAX_LOCALE; ++loc)
4064  {
4065  if (loc == m_session->GetSessionDbcLocale())
4066  continue;
4067 
4068  name = titleInfo->name[loc];
4069  if (name.empty())
4070  continue;
4071 
4072  if (Utf8FitTo(name, wnamepart))
4073  break;
4074  }
4075  }
4076 
4077  if (loc < MAX_LOCALE)
4078  {
4079  if (maxResults && counter == maxResults)
4080  {
4082  return true;
4083  }
4084 
4085  char const* knownStr = target && target->HasTitle(titleInfo) ? GetOregonString(LANG_KNOWN) : "";
4086 
4087  char const* activeStr = target && target->GetUInt32Value(PLAYER_CHOSEN_TITLE) == titleInfo->bit_index
4089  : "";
4090 
4091  char titleNameStr[80];
4092  snprintf(titleNameStr, 80, name.c_str(), targetName);
4093 
4094  // send title in "id (idx:idx) - [namedlink locale]" format
4095  if (m_session)
4096  PSendSysMessage(LANG_TITLE_LIST_CHAT, id, titleInfo->bit_index, id, titleNameStr, localeNames[loc], knownStr, activeStr);
4097  else
4098  PSendSysMessage(LANG_TITLE_LIST_CONSOLE, id, titleInfo->bit_index, titleNameStr, localeNames[loc], knownStr, activeStr);
4099 
4100  ++counter;
4101  }
4102  }
4103  }
4104  if (counter == 0) // if counter == 0 then we found nth
4106  return true;
4107 }
4108 
4110 {
4111  // number or [name] Shift-click form |color|Htitle:title_id|h[name]|h|r
4112  char* id_p = extractKeyFromLink((char*)args, "Htitle");
4113  if (!id_p)
4114  return false;
4115 
4116  int32 id = atoi(id_p);
4117  if (id <= 0)
4118  {
4120  SetSentErrorMessage(true);
4121  return false;
4122  }
4123 
4124  Player* target = getSelectedPlayer();
4125  if (!target)
4126  {
4128  SetSentErrorMessage(true);
4129  return false;
4130  }
4131 
4132  CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(id);
4133  if (!titleInfo)
4134  {
4136  SetSentErrorMessage(true);
4137  return false;
4138  }
4139 
4140  std::string tNameLink = target->GetName();
4141 
4142  char const* targetName = target->GetName();
4143  char titleNameStr[80];
4144  snprintf(titleNameStr, 80, titleInfo->name[m_session->GetSessionDbcLocale()], targetName);
4145 
4146  target->SetTitle(titleInfo);
4147  PSendSysMessage(LANG_TITLE_ADD_RES, id, titleNameStr, tNameLink.c_str());
4148 
4149  return true;
4150 }
4151 
4153 {
4154  // number or [name] Shift-click form |color|Htitle:title_id|h[name]|h|r
4155  char* id_p = extractKeyFromLink((char*)args, "Htitle");
4156  if (!id_p)
4157  return false;
4158 
4159  int32 id = atoi(id_p);
4160  if (id <= 0)
4161  {
4163  SetSentErrorMessage(true);
4164  return false;
4165  }
4166 
4167  Player* target = getSelectedPlayer();
4168  if (!target)
4169  {
4171  SetSentErrorMessage(true);
4172  return false;
4173  }
4174 
4175  CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(id);
4176  if (!titleInfo)
4177  {
4179  SetSentErrorMessage(true);
4180  return false;
4181  }
4182 
4183  target->SetTitle(titleInfo, true);
4184 
4185  char const* targetName = target->GetName();
4186  char titleNameStr[80];
4187  snprintf(titleNameStr, 80, titleInfo->name[m_session->GetSessionDbcLocale()], targetName);
4188 
4189  PSendSysMessage(LANG_TITLE_REMOVE_RES, id, titleNameStr, targetName);
4190 
4191  if (!target->HasTitle(target->GetInt32Value(PLAYER_CHOSEN_TITLE)))
4192  {
4193  target->SetUInt32Value(PLAYER_CHOSEN_TITLE, 0);
4195  }
4196 
4197  return true;
4198 }
4199 
4200 //Edit Player KnownTitles
4202 {
4203  if (!*args)
4204  return false;
4205 
4206  uint64 titles = 0;
4207 
4208  sscanf((char*)args, UI64FMTD, &titles);
4209 
4210  Player* target = getSelectedPlayer();
4211  if (!target)
4212  {
4214  SetSentErrorMessage(true);
4215  return false;
4216  }
4217 
4218  uint64 titles2 = titles;
4219 
4220  for (uint32 i = 1; i < sCharTitlesStore.GetNumRows(); ++i)
4221  if (CharTitlesEntry const* tEntry = sCharTitlesStore.LookupEntry(i))
4222  titles2 &= ~(uint64(1) << tEntry->bit_index);
4223 
4224  titles &= ~titles2; // remove not existed titles
4225 
4226  target->SetUInt64Value(PLAYER__FIELD_KNOWN_TITLES, titles);
4228 
4229  if (!target->HasTitle(target->GetInt32Value(PLAYER_CHOSEN_TITLE)))
4230  {
4231  target->SetUInt32Value(PLAYER_CHOSEN_TITLE, 0);
4233  }
4234 
4235  return true;
4236 }
4237 
4239 {
4240 
4241  Player* target = getSelectedPlayer();
4242  if (!target)
4243  {
4245  SetSentErrorMessage(true);
4246  return false;
4247  }
4248 
4250  char const* targetName = target->GetName();
4251  char const* knownStr = GetOregonString(LANG_KNOWN);
4252 
4253  // Search in CharTitles.dbc
4254  for (uint32 id = 0; id < sCharTitlesStore.GetNumRows(); id++)
4255  {
4256  CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(id);
4257  if (titleInfo && target->HasTitle(titleInfo))
4258  {
4259  std::string name = titleInfo->name[loc];
4260  if (name.empty())
4261  continue;
4262 
4263  char const* activeStr = target && target->GetUInt32Value(PLAYER_CHOSEN_TITLE) == titleInfo->bit_index
4265  : "";
4266 
4267  char titleNameStr[80];
4268  snprintf(titleNameStr, 80, name.c_str(), targetName);
4269 
4270  // send title in "id (idx:idx) - [namedlink locale]" format
4271  if (m_session)
4272  PSendSysMessage(LANG_TITLE_LIST_CHAT, id, titleInfo->bit_index, id, titleNameStr, localeNames[loc], knownStr, activeStr);
4273  else
4274  PSendSysMessage(LANG_TITLE_LIST_CONSOLE, id, titleInfo->bit_index, name.c_str(), localeNames[loc], knownStr, activeStr);
4275  }
4276  }
4277  return true;
4278 }
4279 
4281 {
4282  // number or [name] Shift-click form |color|Htitle:title_id|h[name]|h|r
4283  char* id_p = extractKeyFromLink((char*)args, "Htitle");
4284  if (!id_p)
4285  return false;
4286 
4287  int32 id = atoi(id_p);
4288  if (id <= 0)
4289  {
4291  SetSentErrorMessage(true);
4292  return false;
4293  }
4294 
4295  Player* target = getSelectedPlayer();
4296  if (!target)
4297  {
4299  SetSentErrorMessage(true);
4300  return false;
4301  }
4302 
4303  CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(id);
4304  if (!titleInfo)
4305  {
4307  SetSentErrorMessage(true);
4308  return false;
4309  }
4310 
4311  std::string tNameLink = target->GetName();
4312 
4313  target->SetTitle(titleInfo); // to be sure that title now known
4314  target->SetUInt32Value(PLAYER_CHOSEN_TITLE, titleInfo->bit_index);
4315 
4316  PSendSysMessage(LANG_TITLE_CURRENT_RES, id, titleInfo->name[m_session->GetSessionDbcLocale()], tNameLink.c_str());
4317 
4318  return true;
4319 }
4320 
4322 {
4323  uint64 account = strtoull(args, NULL, 10);
4324  if (!account)
4325  return false;
4326 
4327  uint64 linked;
4328  switch (sObjectMgr.GetRAFLinkStatus(account, &linked))
4329  {
4330  case RAF_LINK_NONE:
4331  PSendSysMessage("Account " UI64FMTD " is not linked to any account.", account);
4332  break;
4333  case RAF_LINK_REFERRER:
4334  PSendSysMessage("Account " UI64FMTD " is referrer account. (friend is: " UI64FMTD ")", account, linked);
4335  break;
4336  case RAF_LINK_REFERRED:
4337  PSendSysMessage("Account " UI64FMTD " is referred account. (friend is: " UI64FMTD ")", account, linked);
4338  if (Player* player = ObjectAccessor::Instance().FindPlayerByAccountId(account))
4339  PSendSysMessage("Character %s has %.02f grantable levels", player->GetName(), player->GetGrantableLevels());
4340  break;
4341  }
4342 
4343  return true;
4344 }
4345 
4347 {
4348  uint64 referrer = strtoull(args, NULL, 10);
4349  if (!referrer)
4350  return false;
4351 
4352  args = strchr(args, ' ');
4353  if (!args)
4354  return false;
4355 
4356  uint64 referred = strtoull(args, NULL, 10);
4357  if (!referred)
4358  return false;
4359 
4360  if (sObjectMgr.GetRAFLinkStatus(referrer) != RAF_LINK_NONE ||
4361  sObjectMgr.GetRAFLinkStatus(referred) != RAF_LINK_NONE)
4362  {
4363  PSendSysMessage("First or second account is already linked with an account.");
4364  return true;
4365  }
4366 
4367  sObjectMgr.LinkIntoRAF(referrer, referred);
4368  PSendSysMessage("Accounts successfully linked.");
4369  return true;
4370 }
4371 
4373 {
4374  uint64 acc = strtoull(args, NULL, 10);
4375  if (!acc)
4376  return false;
4377 
4378  sObjectMgr.UnlinkFromRAF(acc);
4379  PSendSysMessage("Account was sucessfully unlinked");
4380  return true;
4381 }
4382 
4383 //change phasemask of creature or pet
4385 {
4386  if (!*args)
4387  return false;
4388 
4389  uint32 phasemask = (uint32)atoi((char*)args);
4390  if (phasemask == 0)
4391  {
4393  SetSentErrorMessage(true);
4394  return false;
4395  }
4396 
4397  Creature* pCreature = getSelectedCreature();
4398  if (!pCreature)
4399  {
4401  SetSentErrorMessage(true);
4402  return false;
4403  }
4404 
4405  pCreature->SetPhaseMask(phasemask, true);
4406 
4407  if (!pCreature->IsPet())
4408  pCreature->SaveToDB();
4409 
4410  return true;
4411 }
4412 
4413 //set pahsemask for selected object
4415 {
4416  // number or [name] Shift-click form |color|Hgameobject:go_id|h[name]|h|r
4417  char* cId = extractKeyFromLink((char*)args, "Hgameobject");
4418  if (!cId)
4419  return false;
4420 
4421  uint32 lowguid = atoi(cId);
4422  if (!lowguid)
4423  return false;
4424 
4425  GameObject* obj = NULL;
4426  // by DB guid
4427  if (GameObjectData const* go_data = sObjectMgr.GetGOData(lowguid))
4428  obj = GetObjectGlobalyWithGuidOrNearWithDbGuid(lowguid, go_data->id);
4429 
4430  if (!obj)
4431  {
4433  SetSentErrorMessage(true);
4434  return false;
4435  }
4436 
4437  char* phaseStr = strtok(NULL, " ");
4438  uint32 phasemask = phaseStr ? atoi(phaseStr) : 0;
4439  if (phasemask == 0)
4440  {
4442  SetSentErrorMessage(true);
4443  return false;
4444  }
4445 
4446  obj->SetPhaseMask(phasemask, true);
4447  obj->SaveToDB();
4448  return true;
4449 }
bool HandleCharacterRenameCommand(const char *args)
Definition: Level2.cpp:3019
bool Utf8FitTo(const std::string &str, std::wstring search)
Definition: Util.cpp:419
DBCStorage< WorldSafeLocsEntry > sWorldSafeLocsStore(WorldSafeLocsEntryfmt)
bool AddToMap(T *)
Definition: Map.cpp:424
bool HandleAnimCommand(const char *args)
Definition: Level2.cpp:3161
void CreatureRelocation(Creature *creature, float x, float y, float z, float ang, bool respawnRelocationOnFail=true)
Definition: Map.cpp:734
bool IsVendor() const
Definition: Unit.h:1214
GameObject * SummonGameObject(uint32 entry, float x, float y, float z, float ang, float rotation0, float rotation1, float rotation2, float rotation3, uint32 respawnTime)
Definition: Object.cpp:2225
bool HandleWpLoadPathCommand(const char *args)
Definition: Level2.cpp:2162
#define snprintf
Definition: Common.h:129
void SetSentErrorMessage(bool val)
Definition: Chat.h:593
uint8 GetSpawnMode() const
Definition: Map.h:394
bool LoadCreatureFromDB(uint32 guid, Map *map, bool addToMap=true)
Definition: Creature.cpp:1300
bool HasSpell(uint32 spell) const override
Definition: Pet.cpp:1929
int32 GetReputation(uint32 faction_id) const
Definition: Unit.h:440
bool HandleEventActiveListCommand(const char *args)
Definition: Level2.cpp:3284
GameObject * GetObjectGlobalyWithGuidOrNearWithDbGuid(uint32 lowguid, uint32 entry)
Definition: Chat.cpp:1779
const uint32 & GetUInt32Value(uint16 index) const
Definition: Object.h:234
bool HandleNpcSpawnDistCommand(const char *args)
Definition: Level2.cpp:1459
DBCStorage< SkillLineEntry > sSkillLineStore(SkillLinefmt)
bool HandleUnmuteCommand(const char *args)
Definition: Level2.cpp:134
#define GUID_LOPART(x)
Definition: ObjectGuid.h:110
bool HandleLookupEventCommand(const char *args)
Definition: Level2.cpp:3229
void SetPetNumber(uint32 petnumber, bool statwindow)
Definition: Unit.cpp:11393
static const int32 PointsInRank[MAX_REPUTATION_RANK]
Definition: ReputationMgr.h:68
bool HandleLookupPlayerIpCommand(const char *args)
Definition: Level2.cpp:3598
bool HandleGOPhaseCommand(const char *args)
Definition: Level2.cpp:4414
uint32 GetMaxHealth() const
Definition: Unit.h:1075
bool HandleNpcFlagCommand(const char *args)
Definition: Level2.cpp:1119
uint32 GetPhaseMaskForSpawn() const
Definition: Player.cpp:15732
Creature * getSelectedCreature()
Definition: Chat.cpp:1640
bool HandleTitlesCurrentCommand(const char *args)
Definition: Level2.cpp:4280
bool HandleNpcAddCommand(const char *args)
Definition: Level2.cpp:954
ReputationRank
Map * GetMap() const
Definition: Object.h:841
DatabaseType WorldDatabase
Accessor to the world database.
Definition: Main.cpp:53
uint32 GetFaction() const
Definition: Unit.h:1116
uint32 GetDBTableGUIDLow() const
Definition: Creature.h:476
bool HandleRAFInfoCommand(const char *args)
Definition: Level2.cpp:4321
Unit * getSelectedUnit()
Definition: Chat.cpp:1627
bool HandleActivateObjectCommand(const char *args)
Definition: Level2.cpp:3895
bool HandleUpdateHonorFieldsCommand(const char *args)
Definition: Level2.cpp:3215
void UpdateWaypointID(uint32 wpID)
Definition: Creature.h:754
QueryResult_AutoPtr PQuery(const char *format,...) ATTR_PRINTF(2
Definition: Database.cpp:400
bool HandlePetLearnCommand(const char *args)
Definition: Level2.cpp:3804
bool HandleServerCorpsesCommand(const char *args)
Definition: Level2.cpp:3702
Definition: Field.h:24
void SetObjectScale(float scale)
Definition: Object.h:205
bool IsValidPos(uint16 pos)
Definition: Player.h:1127
uint64 GetOwnerGUID() const
Definition: GameObject.h:664
bool HandleTitlesSetMaskCommand(const char *args)
Definition: Level2.cpp:4201
bool HandleWpEventCommand(const char *args)
Definition: Level2.cpp:2266
bool HandleAddHonorCommand(const char *args)
Definition: Level2.cpp:3183
uint32 GetWaypointPath()
Definition: Creature.h:741
bool HandleTurnObjectCommand(const char *args)
Definition: Level2.cpp:653
void SetTitle(CharTitlesEntry const *title, bool lost=false)
Definition: Player.cpp:20514
MotionMaster * GetMotionMaster()
Definition: Unit.h:1890
#define strtoull
Definition: Common.h:133
TempSummon * SummonCreature(uint32 id, const Position &pos, TempSummonType spwtype=TEMPSUMMON_MANUAL_DESPAWN, uint32 despwtime=0)
Definition: Object.cpp:2091
DBCStorage< FactionTemplateEntry > sFactionTemplateStore(FactionTemplateEntryfmt)
void DeleteFromDB()
Definition: GameObject.cpp:735
bool HandleNpcFactionIdCommand(const char *args)
Definition: Level2.cpp:1419
bool HandleRAFUnlinkCommand(const char *args)
Definition: Level2.cpp:4372
bool HandleNpcSetPhaseCommand(const char *args)
Definition: Level2.cpp:4384
#define sLog
Log class singleton.
Definition: Log.h:187
virtual void SaveToDB()
Definition: Creature.cpp:1050
void MoveTargetedHome()
bool HandleNpcFollowCommand(const char *args)
Definition: Level2.cpp:1531
bool HandleNpcMoveCommand(const char *args)
Definition: Level2.cpp:1183
MovementGeneratorType GetCurrentMovementGeneratorType() const
bool HandleKickPlayerCommand(const char *args)
Definition: Level2.cpp:1750
bool IsInFlight() const
Definition: Unit.h:1239
bool HandleNpcSetLinkCommand(const char *args)
Definition: Level2.cpp:3992
void SetUInt32Value(uint16 index, uint32 value)
Definition: Object.cpp:779
ACE_INT32 int32
Definition: Define.h:67
unsigned long escape_string(char *to, const char *from, unsigned long length)
Definition: Database.cpp:212
bool HandlePInfoCommand(const char *args)
Definition: Level2.cpp:1853
bool HandleLookupPlayerAccountCommand(const char *args)
Definition: Level2.cpp:3615
bool HandleGoTicketCommand(const char *args)
Definition: Level2.cpp:205
void SaveRecallPosition()
Definition: Player.cpp:5697
QueryResult_AutoPtr Query(const char *sql)
Definition: Database.cpp:383
time_t GetRespawnTimeEx() const
Definition: GameObject.h:684
bool HandleGoGraveyardCommand(const char *args)
Definition: Level2.cpp:292
bool HandlePetTpCommand(const char *args)
Definition: Level2.cpp:3872
bool LookupPlayerSearchCommand(QueryResult_AutoPtr result, int32 limit)
Definition: Level2.cpp:3651
DBCStorage< AreaTriggerEntry > sAreaTriggerStore(AreaTriggerEntryfmt)
void SetNativeDisplayId(uint32 modelId)
Definition: Unit.h:1791
void Refresh()
Definition: GameObject.cpp:546
virtual void SendSysMessage(const char *str)
Definition: Chat.cpp:790
uint32 GetAccountId() const
Definition: WorldSession.h:100
bool HandleNameCommand(const char *args)
Definition: Level2.cpp:1592
bool CreateBaseAtCreature(Creature *creature)
Definition: Pet.cpp:906
void SetRespawnTime(int32 respawn)
Definition: GameObject.h:693
#define GUID_HIPART(x)
Definition: ObjectGuid.h:82
Player * GetPlayer() const
Definition: WorldSession.h:104
uint32 GetGUIDLow() const
Definition: Object.h:166
Definition: Pet.h:28
bool HandleWpModifyCommand(const char *args)
Definition: Level2.cpp:2484
bool CanSpeak() const
Definition: Player.cpp:16854
LocaleConstant GetSessionDbcLocale() const
Definition: WorldSession.h:233
bool Utf8toWStr(char const *utf8str, size_t csize, wchar_t *wstr, size_t &wsize)
Definition: Util.cpp:255
void LoadPath(uint32 pathid)
Definition: Creature.h:745
float pos_z
Definition: TicketMgr.h:40
WorldSession * m_session
Definition: Chat.h:596
bool HandleMorphCommand(const char *args)
Definition: Level2.cpp:1733
void SetMinion(Minion *minion, bool apply)
Definition: Unit.cpp:7705
FactionState const * GetState(FactionEntry const *factionEntry) const
Definition: ReputationMgr.h:76
bool HandleRepairitemsCommand(const char *args)
Definition: Level2.cpp:3708
#define sObjectMgr
Definition: ObjectMgr.h:1285
void wstrToLower(std::wstring &str)
Definition: Util.h:308
bool HandleMuteCommand(const char *args)
Definition: Level2.cpp:55
CharmInfo * GetCharmInfo()
Definition: Unit.h:1458
_Ty top() const
Definition: MotionMaster.h:132
DBCStorage< SpellEntry > sSpellStore(SpellEntryfmt)
char * name[16]
Definition: DBCStructure.h:270
bool HandleNpcSetMoveTypeCommand(const char *args)
Definition: Level2.cpp:1269
const char * GetString() const
Definition: Field.h:41
virtual void DeleteFromDB()
Definition: Creature.cpp:1461
bool PExecuteLog(const char *format,...) ATTR_PRINTF(2
Definition: Database.cpp:221
uint32 GetRespawnDelay() const
Definition: GameObject.h:713
uint32 map
Definition: TicketMgr.h:41
#define MAX_REPUTATION_RANK
uint16 GetPureMaxSkillValue(uint32 skill) const
Definition: Player.cpp:5521
uint8 getLevel() const
Definition: Unit.h:1057
bool HasSpell(uint32 spell) const override
Definition: Player.cpp:3755
bool HandleRAFLinkCommand(const char *args)
Definition: Level2.cpp:4346
DBCStorage< CharTitlesEntry > sCharTitlesStore(CharTitlesEntryfmt)
Definition: Common.h:179
uint32 GetId(void) const
Definition: Map.h:333
#define IS_PLAYER_GUID(Guid)
Definition: ObjectGuid.h:69
void SetLootState(LootState s, Unit *unit=NULL)
uint8 GetTypeId() const
Definition: Object.h:210
void SavePetToDB(PetSaveMode mode)
Definition: Pet.cpp:364
uint32 GetTotalPlayedTime()
Definition: Player.h:1056
char const * localeNames[MAX_LOCALE]
Definition: Common.cpp:20
bool normalizePlayerName(std::string &name)
Definition: ObjectMgr.cpp:225
bool TeleportTo(uint32 mapid, float x, float y, float z, float orientation, uint32 options=0)
Definition: Player.cpp:1488
bool InitStatsForLevel(uint32 level)
Definition: Pet.cpp:967
Creature * GetCreature(uint64 guid)
Definition: Map.cpp:2630
bool HandleModifyPhaseCommand(const char *args)
Definition: Level2.cpp:1835
ACE_UINT8 uint8
Definition: Define.h:73
float GetOrientation() const
Definition: Position.h:100
#define sWaypointMgr
void setDeathState(DeathState s) override
Definition: Creature.cpp:1575
uint32 GetDisplayId()
Definition: Unit.h:1782
#define UI64FMTD
Definition: Common.h:149
void Relocate(float x, float y)
Definition: Position.h:65
std::string GetCppString() const
Definition: Field.h:52
bool HandleCharacterTitlesCommand(const char *args)
Definition: Level2.cpp:4238
bool learnSpell(uint16 spell_id)
Definition: Pet.cpp:1577
bool HandleTitlesRemoveCommand(const char *args)
Definition: Level2.cpp:4152
void SetPhaseMask(uint32 newPhaseMask, bool update) override
Definition: Unit.cpp:13499
void PetSpellInitialize()
Definition: Player.cpp:17336
HostileRefManager & getHostileRefManager()
Definition: Unit.h:1733
const uint8 MAX_LOCALE
Definition: Common.h:224
#define sPoolMgr
Definition: PoolMgr.h:162
bool HandleSubNameCommand(const char *args)
Definition: Level2.cpp:1639
time_t m_muteTime
Definition: WorldSession.h:230
void AddObjectToRemoveList()
Definition: Object.cpp:1990
void PSendSysMessage(const char *format,...) ATTR_PRINTF(2
Definition: Chat.cpp:858
void SetDisplayId(uint32 modelId)
Definition: Unit.cpp:11975
void SetRespawnRadius(float dist)
Definition: Creature.h:677
bool HandleLookupFactionCommand(const char *args)
Definition: Level2.cpp:3068
DatabaseType LoginDatabase
Accessor to the realm/login database.
Definition: Main.cpp:55
void SetDefaultMovementType(MovementGeneratorType mgt)
Definition: Creature.h:632
void EndianConvertReverse(T &)
Definition: ByteConverter.h:52
bool IsAlive() const
Definition: Unit.h:1336
bool HandleDeMorphCommand(const char *args)
Definition: Level2.cpp:1721
float GetPositionY() const
Definition: Position.h:98
void DeMorph()
Definition: Unit.cpp:3664
int32 reputationListID
Definition: DBCStructure.h:264
#define MAKE_NEW_GUID(l, e, h)
Definition: ObjectGuid.h:80
bool HandleNpcSpawnTimeCommand(const char *args)
Definition: Level2.cpp:1497
bool HandleStandStateCommand(const char *args)
Definition: Level2.cpp:3172
etc mysql my cnf *Then change max_allowed_packet to a bigger value
float GetPositionZ() const
Definition: Position.h:99
bool HandleModifyRepCommand(const char *args)
Definition: Level2.cpp:857
const uint64 & GetSelection() const
Definition: Player.h:1553
void Say(const char *text, uint32 language, uint64 TargetGuid)
Definition: Creature.h:566
void CombatStop(bool cast=false)
Definition: Unit.cpp:7518
float pos_y
Definition: TicketMgr.h:39
#define _LIKE_
Definition: DatabaseEnv.h:30
bool Create(uint32 guidlow, Map *map, uint32 phaseMask, uint32 Entry, uint32 team, float x, float y, float z, float ang, const CreatureData *data=NULL)
Definition: Creature.cpp:764
static bool normalizeString(std::string &utf8str)
Definition: AccountMgr.cpp:223
bool HandleWpUnLoadPathCommand(const char *args)
Definition: Level2.cpp:2236
void UpdateObjectVisibility(bool forced=true) override
Definition: Player.cpp:18890
bool HandleGUIDCommand(const char *args)
Definition: Level2.cpp:842
std::string TimeToTimestampStr(time_t t)
Definition: Util.cpp:177
uint32 GetMapId() const
Definition: Object.h:591
void SetMaxHealth(uint32 val)
Definition: Unit.cpp:10938
uint32 extractSpellIdFromLink(char *text)
Definition: Chat.cpp:1811
void SetTP(int32 TP)
Definition: Pet.cpp:838
bool PExecute(const char *format,...) ATTR_PRINTF(2
Definition: Database.cpp:441
bool HandleEventStartCommand(const char *args)
Definition: Level2.cpp:3361
bool HandleLookupTitleCommand(const char *args)
Definition: Level2.cpp:4026
FactionStateList const & GetStateList() const
Definition: ReputationMgr.h:74
Definition: Map.h:266
#define sAccountMgr
Definition: AccountMgr.h:60
void SetAtLoginFlag(AtLoginFlags f)
Definition: Player.h:2481
void CleanupAfterTaxiFlight()
Definition: Player.cpp:17910
void SetUInt64Value(uint16 index, const uint64 &value)
Definition: Object.cpp:798
bool HandleLearnAllCraftsCommand(const char *args)
Definition: Level2.cpp:3481
char * name[16]
Definition: DBCStructure.h:118
void UseDoorOrButton(uint32 time_to_restore=0, bool alternative=false, Unit *user=NULL)
Definition: GameObject.cpp:955
uint32 DurabilityRepairAll(bool cost, float discountMod, bool guildBank)
Definition: Player.cpp:4436
std::string secsToTimeString(uint32 timeInSecs, bool shortText, bool hoursOnly)
Definition: Util.cpp:109
bool HandleItemMoveCommand(const char *args)
Definition: Level2.cpp:1686
void InitPetCreateSpells()
Definition: Pet.cpp:1606
bool IsPet() const
Definition: Unit.h:1048
const char * GetName() const
Definition: Object.h:704
ReputationMgr & GetReputationMgr()
Definition: Player.h:2079
ChatHandler()
Definition: Chat.h:90
Player * getSelectedPlayer()
Definition: Chat.cpp:1596
uint32 GetLatency() const
Definition: WorldSession.h:243
ACE_UINT64 uint64
Definition: Define.h:70
uint32 getClassMask() const
Definition: Unit.h:1063
void Respawn(bool force=false)
Definition: Creature.cpp:1651
uint64 GetPetGUID() const
Definition: Unit.h:1378
bool HandleWpShowCommand(const char *args)
Definition: Level2.cpp:2676
bool HandleGoCreatureCommand(const char *args)
Teleport the GM to the specified creature.
Definition: Level2.cpp:348
bool HandleTempGameObjectCommand(const char *args)
Definition: Level2.cpp:3954
bool RewardHonor(Unit *victim, uint32 groupsize, float honor=-1, bool pvptoken=false)
Definition: Player.cpp:5998
uint32 occurence
Definition: GameEventMgr.h:57
uint8 getRace() const
Definition: Unit.h:1060
void RemoveGameObject(GameObject *gameObj, bool del)
Definition: Unit.cpp:4729
#define sGameEventMgr
Definition: GameEventMgr.h:179
CreatureInfo const * GetCreatureTemplate() const
Definition: Creature.h:557
void SetPhaseMask(uint32 newPhaseMask, bool update) override
bool HandleTitlesAddCommand(const char *args)
Definition: Level2.cpp:4109
virtual const char * GetOregonString(int32 entry) const
Definition: Chat.cpp:753
#define _CONCAT3_(A, B, C)
Definition: DatabaseEnv.h:32
ACE_Refcounted_Auto_Ptr< QueryResult, ACE_Null_Mutex > QueryResult_AutoPtr
Definition: QueryResult.h:113
uint32 GetMoney()
Definition: Player.h:1510
std::set< uint16 > ActiveEvents
Definition: GameEventMgr.h:92
bool IsTotem() const
Definition: Unit.h:1050
bool HandleLookupPlayerEmailCommand(const char *args)
Definition: Level2.cpp:3634
static bool IsValidMapCoord(uint32 mapid, float x, float y)
Definition: MapManager.h:87
Creature * ToCreature()
Definition: Object.h:395
bool HandleGoObjectCommand(const char *args)
Definition: Level2.cpp:439
virtual void UpdateObjectVisibility(bool forced=true)
Definition: Object.cpp:2599
bool HandleTargetObjectCommand(const char *args)
Definition: Level2.cpp:495
void SetFaction(uint32 faction)
Definition: Unit.h:1117
bool HandleDelVendorItemCommand(const char *args)
Definition: Level2.cpp:1048
DBCStorage< FactionEntry > sFactionStore(FactionEntryfmt)
void SetFloatValue(uint16 index, float value)
Definition: Object.cpp:859
bool HandleWpAddCommand(const char *args)
Definition: Level2.cpp:2105
uint8 getClass() const
Definition: Unit.h:1062
bool Create(uint32 guidlow, uint32 name_id, Map *map, uint32 phaseMask, float x, float y, float z, float ang, float rotation0, float rotation1, float rotation2, float rotation3, uint32 animprogress, GOState go_state, uint32 ArtKit=0)
Definition: GameObject.cpp:166
MovementGeneratorType
Definition: MotionMaster.h:33
void SwapItem(uint16 src, uint16 dst)
Definition: Player.cpp:11079
std::vector< GameEventData > GameEventDataMap
Definition: GameEventMgr.h:94
ReputationRank GetRank(FactionEntry const *factionEntry) const
bool HandleAddVendorItemCommand(const char *args)
Definition: Level2.cpp:1001
void SetSkill(uint32 id, uint16 currVal, uint16 maxVal)
Definition: Player.cpp:5374
bool HasTitle(uint32 bitIndex)
Definition: Player.cpp:20504
void RemoveCorpse(bool setSpawnTime=true)
Definition: Creature.cpp:234
bool HandleMoveObjectCommand(const char *args)
Definition: Level2.cpp:702
bool HandleChangeLevelCommand(const char *args)
Definition: Level2.cpp:1084
void HandleEmoteCommand(uint32 anim_id)
Definition: Unit.cpp:1970
bool HandleGameObjectCommand(const char *args)
Definition: Level2.cpp:775
uint16 mapid
Definition: Creature.h:270
static Unit * GetUnit(WorldObject const &, uint64 guid)
std::map< RepListID, FactionState > FactionStateList
Definition: ReputationMgr.h:51
void DestroyForNearbyPlayers()
Definition: Object.cpp:2565
void SetLevel(uint32 lvl)
Definition: Unit.cpp:10896
const int32 & GetInt32Value(uint16 index) const
Definition: Object.h:228
uint32 GetEntry() const
Definition: Object.h:192
WorldSession * GetSession() const
Definition: Player.h:1944
bool HandleGoTriggerCommand(const char *args)
Definition: Level2.cpp:247
LocaleConstant
Definition: Common.h:211
#define sWorld
Definition: World.h:860
bool HandlePetUnlearnCommand(const char *args)
Definition: Level2.cpp:3847
bool HandleTempAddSpwCommand(const char *args)
Definition: Level2.cpp:3931
DatabaseType CharacterDatabase
Accessor to the character database.
Definition: Main.cpp:54
void uint32 GetSecurity() const
Definition: WorldSession.h:96
bool HandleEventStopCommand(const char *args)
Definition: Level2.cpp:3402
void SetHealth(uint32 val)
Definition: Unit.cpp:10905
ACE_UINT16 uint16
Definition: Define.h:72
ACE_UINT32 uint32
Definition: Define.h:71
bool HandleEventInfoCommand(const char *args)
Definition: Level2.cpp:3312
void Initialize()
float GetPositionX() const
Definition: Position.h:97
void MovementExpired(bool reset=true)
Definition: MotionMaster.h:158
Pet * GetPet() const
Definition: Player.cpp:17121
void removeSpell(uint16 spell_id)
Definition: Pet.cpp:1589
GameObject * GetGameObject(uint64 guid)
Definition: Map.cpp:2636
#define VISUAL_WAYPOINT
Definition: MotionMaster.h:30
void SaveToDB()
Definition: GameObject.cpp:594
despawns instantly after death
CreatureDataAddon const * GetCreatureAddon() const
Definition: Creature.cpp:2127
float pos_x
Definition: TicketMgr.h:38
CreatureFamily family
Definition: Creature.h:164
Definition: Unit.h:908
bool SetReputation(FactionEntry const *factionEntry, int32 standing)
char * extractKeyFromLink(char *text, char const *linkType, char **something1=NULL)
Definition: Chat.cpp:1648
bool HandleCreatePetCommand(const char *args)
Definition: Level2.cpp:3728
void SetRespawnDelay(uint32 delay)
Definition: Creature.h:668
std::string description
Definition: GameEventMgr.h:62
virtual bool needReportToTarget(Player *chr) const
Definition: Chat.cpp:1878
Definition: Player.h:922