OregonCore  revision 3611e8a-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 "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, 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()));
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, id, (uint32)teamval, x, y, z, o))
980  {
981  delete creature;
982  return false;
983  }
984 
985  creature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()));
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 //show info of player
1835 bool ChatHandler::HandlePInfoCommand(const char* args)
1836 {
1837  Player* target = NULL;
1838  uint64 targetGUID = 0;
1839 
1840  char* px = strtok((char*)args, " ");
1841  char* py = NULL;
1842 
1843  std::string name;
1844 
1845  if (px)
1846  {
1847  name = px;
1848 
1849  if (name.empty())
1850  return false;
1851 
1852  if (!normalizePlayerName(name))
1853  {
1855  SetSentErrorMessage(true);
1856  return false;
1857  }
1858 
1859  target = sObjectMgr.GetPlayer(name.c_str());
1860  if (target)
1861  py = strtok(NULL, " ");
1862  else
1863  {
1864  targetGUID = sObjectMgr.GetPlayerGUIDByName(name);
1865  if (targetGUID)
1866  py = strtok(NULL, " ");
1867  else
1868  py = px;
1869  }
1870  }
1871 
1872  if (!target && !targetGUID)
1873  target = getSelectedPlayer();
1874 
1875  if (!target && !targetGUID)
1876  {
1878  SetSentErrorMessage(true);
1879  return false;
1880  }
1881 
1882  uint32 accId = 0;
1883  uint32 money = 0;
1884  uint32 total_player_time = 0;
1885  uint32 level = 0;
1886  uint32 latency = 0;
1887  uint8 race;
1888  uint8 Class;
1889 
1890  // get additional information from Player object
1891  if (target)
1892  {
1893  targetGUID = target->GetGUID();
1894  name = target->GetName(); // re-read for case getSelectedPlayer() target
1895  accId = target->GetSession()->GetAccountId();
1896  money = target->GetMoney();
1897  total_player_time = target->GetTotalPlayedTime();
1898  level = target->getLevel();
1899  latency = target->GetSession()->GetLatency();
1900  race = target->getRace();
1901  Class = target->getClass();
1902  }
1903  // get additional information from DB
1904  else
1905  {
1906  QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT totaltime, level, money, account, race, class FROM characters WHERE guid = '%u'", GUID_LOPART(targetGUID));
1907  if (!result)
1908  {
1910  SetSentErrorMessage(true);
1911  return false;
1912  }
1913  Field* fields = result->Fetch();
1914  total_player_time = fields[0].GetUInt32();
1915  level = fields[1].GetUInt32();
1916  money = fields[2].GetUInt32();
1917  accId = fields[3].GetUInt32();
1918  race = fields[4].GetUInt8();
1919  Class = fields[5].GetUInt8();
1920  }
1921 
1922  std::string username = GetOregonString(LANG_ERROR);
1923  std::string email = GetOregonString(LANG_ERROR);
1924  std::string last_ip = GetOregonString(LANG_ERROR);
1925  uint32 security = 0;
1926  std::string last_login = GetOregonString(LANG_ERROR);
1927 
1928  QueryResult_AutoPtr result = LoginDatabase.PQuery("SELECT a.username,aa.gmlevel,a.email,a.last_ip,a.last_login "
1929  "FROM account a "
1930  "LEFT JOIN account_access aa "
1931  "ON (a.id = aa.id) "
1932  "WHERE a.id = '%u'", accId);
1933  if (result)
1934  {
1935  Field* fields = result->Fetch();
1936  username = fields[0].GetCppString();
1937  security = fields[1].GetUInt32();
1938  email = fields[2].GetCppString();
1939 
1940  if (email.empty())
1941  email = "-";
1942 
1943  if (!m_session || m_session->GetSecurity() >= security)
1944  {
1945  last_ip = fields[3].GetCppString();
1946  last_login = fields[4].GetCppString();
1947 
1948  uint32 ip = inet_addr(last_ip.c_str());
1949  #if OREGON_ENDIAN == BIGENDIAN
1951  #endif
1952 
1953  if (QueryResult_AutoPtr result2 = WorldDatabase.PQuery("SELECT c.country FROM ip2nationCountries c, ip2nation i WHERE "
1954  "i.ip < %u AND c.code = i.country ORDER BY i.ip DESC LIMIT 0,1", ip))
1955  {
1956  Field* fields2 = result2->Fetch();
1957  last_ip.append(" (");
1958  last_ip.append(fields2[0].GetString());
1959  last_ip.append(")");
1960  }
1961  }
1962  else
1963  {
1964  last_ip = "-";
1965  last_login = "-";
1966  }
1967  }
1968 
1969  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);
1970 
1971  std::string race_s, Class_s;
1972  switch (race)
1973  {
1974  case RACE_HUMAN:
1975  race_s = "Human";
1976  break;
1977  case RACE_ORC:
1978  race_s = "Orc";
1979  break;
1980  case RACE_DWARF:
1981  race_s = "Dwarf";
1982  break;
1983  case RACE_NIGHTELF:
1984  race_s = "Night Elf";
1985  break;
1986  case RACE_UNDEAD_PLAYER:
1987  race_s = "Undead";
1988  break;
1989  case RACE_TAUREN:
1990  race_s = "Tauren";
1991  break;
1992  case RACE_GNOME:
1993  race_s = "Gnome";
1994  break;
1995  case RACE_TROLL:
1996  race_s = "Troll";
1997  break;
1998  case RACE_BLOODELF:
1999  race_s = "Blood Elf";
2000  break;
2001  case RACE_DRAENEI:
2002  race_s = "Draenei";
2003  break;
2004  }
2005  switch (Class)
2006  {
2007  case CLASS_WARRIOR:
2008  Class_s = "Warrior";
2009  break;
2010  case CLASS_PALADIN:
2011  Class_s = "Paladin";
2012  break;
2013  case CLASS_HUNTER:
2014  Class_s = "Hunter";
2015  break;
2016  case CLASS_ROGUE:
2017  Class_s = "Rogue";
2018  break;
2019  case CLASS_PRIEST:
2020  Class_s = "Priest";
2021  break;
2022  case CLASS_SHAMAN:
2023  Class_s = "Shaman";
2024  break;
2025  case CLASS_MAGE:
2026  Class_s = "Mage";
2027  break;
2028  case CLASS_WARLOCK:
2029  Class_s = "Warlock";
2030  break;
2031  case CLASS_DRUID:
2032  Class_s = "Druid";
2033  break;
2034  }
2035 
2036  std::string timeStr = secsToTimeString(total_player_time, true, true);
2037  uint32 gold = money / GOLD;
2038  uint32 silv = (money % GOLD) / SILVER;
2039  uint32 copp = (money % GOLD) % SILVER;
2040  PSendSysMessage(LANG_PINFO_LEVEL, race_s.c_str(), Class_s.c_str(), timeStr.c_str(), level, gold, silv, copp);
2041 
2042  if (py && strncmp(py, "rep", 3) == 0)
2043  {
2044  if (!target)
2045  {
2046  // rep option not implemented for offline case
2048  SetSentErrorMessage(true);
2049  return false;
2050  }
2051 
2052  const char* FactionName;
2053  FactionStateList const& targetFSL = target->GetReputationMgr().GetStateList();
2054  for (FactionStateList::const_iterator itr = targetFSL.begin(); itr != targetFSL.end(); ++itr)
2055  {
2056  FactionEntry const* factionEntry = sFactionStore.LookupEntry(itr->second.ID);
2057  if (factionEntry)
2058  FactionName = factionEntry->name[m_session->GetSessionDbcLocale()];
2059  else
2060  FactionName = "#Not found#";
2061  ReputationRank rank = target->GetReputationMgr().GetRank(factionEntry);
2062  std::string rankName = GetOregonString(ReputationRankStrIndex[rank]);
2063  std::ostringstream ss;
2064  ss << itr->second.ID << ": |cffffffff|Hfaction:" << itr->second.ID << "|h[" << FactionName << "]|h|r " << rankName << "|h|r (" << target->GetReputationMgr().GetReputation(factionEntry) << ")";
2065 
2066  if (itr->second.Flags & FACTION_FLAG_VISIBLE)
2068  if (itr->second.Flags & FACTION_FLAG_AT_WAR)
2070  if (itr->second.Flags & FACTION_FLAG_PEACE_FORCED)
2072  if (itr->second.Flags & FACTION_FLAG_HIDDEN)
2074  if (itr->second.Flags & FACTION_FLAG_INVISIBLE_FORCED)
2076  if (itr->second.Flags & FACTION_FLAG_INACTIVE)
2078 
2079  SendSysMessage(ss.str().c_str());
2080  }
2081  }
2082  return true;
2083 }
2084 
2085 // WAYPOINT COMMANDS
2086 
2087 bool ChatHandler::HandleWpAddCommand(const char* args)
2088 {
2089  sLog.outDebug("DEBUG: HandleWpAddCommand");
2090 
2091  // optional
2092  char* path_number = NULL;
2093  uint32 pathid = 0;
2094 
2095  if (*args)
2096  path_number = strtok((char*)args, " ");
2097 
2098  uint32 point = 0;
2099  Creature* target = getSelectedCreature();
2100 
2101  if (!path_number)
2102  {
2103  if (target)
2104  pathid = target->GetWaypointPath();
2105  else
2106  {
2107  QueryResult_AutoPtr result = WorldDatabase.Query("SELECT MAX(id) FROM waypoint_data");
2108  uint32 maxpathid = result->Fetch()->GetInt32();
2109  pathid = maxpathid + 1;
2110  sLog.outDebug("DEBUG: HandleWpAddCommand - New path started.");
2111  PSendSysMessage("%s%s|r", "|cff00ff00", "New path started.");
2112  }
2113  }
2114  else
2115  pathid = atoi(path_number);
2116 
2117  // path_id -> ID of the Path
2118  // point -> number of the waypoint (if not 0)
2119 
2120  if (!pathid)
2121  {
2122  sLog.outDebug("DEBUG: HandleWpAddCommand - Current creature has no loaded path.");
2123  PSendSysMessage("%s%s|r", "|cffff33ff", "Current creature has no loaded path.");
2124  return true;
2125  }
2126 
2127  sLog.outDebug("DEBUG: HandleWpAddCommand - point == 0");
2128 
2129  QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT MAX(point) FROM waypoint_data WHERE id = '%u'", pathid);
2130 
2131  if (result)
2132  point = (*result)[0].GetUInt32();
2133 
2134  Player* player = m_session->GetPlayer();
2135  //Map *map = player->GetMap();
2136 
2137  WorldDatabase.PExecuteLog("INSERT INTO waypoint_data (id, point, position_x, position_y, position_z) VALUES ('%u','%u','%f', '%f', '%f')",
2138  pathid, point + 1, player->GetPositionX(), player->GetPositionY(), player->GetPositionZ());
2139 
2140  PSendSysMessage("%s%s%u%s%u%s|r", "|cff00ff00", "PathID: |r|cff00ffff", pathid, "|r|cff00ff00: Waypoint |r|cff00ffff", point+1, "|r|cff00ff00 created. ");
2141  return true;
2142 } // HandleWpAddCommand
2143 
2145 {
2146  if (!*args)
2147  return false;
2148 
2149  // optional
2150  char* path_number = NULL;
2151 
2152  if (*args)
2153  path_number = strtok((char*)args, " ");
2154 
2155  uint32 pathid = 0;
2156  uint32 guidlow = 0;
2157  Creature* target = getSelectedCreature();
2158 
2159  // Did player provide a path_id?
2160  if (!path_number)
2161  sLog.outDebug("DEBUG: HandleWpLoadPathCommand - No path number provided");
2162 
2163  if (!target)
2164  {
2166  SetSentErrorMessage(true);
2167  return false;
2168  }
2169 
2170  if (target->GetEntry() == 1)
2171  {
2172  PSendSysMessage("%s%s|r", "|cffff33ff", "You want to load path to a waypoint? Aren't you?");
2173  SetSentErrorMessage(true);
2174  return false;
2175  }
2176 
2177  pathid = atoi(path_number);
2178 
2179  if (!pathid)
2180  {
2181  PSendSysMessage("%s%s|r", "|cffff33ff", "No vallid path number provided.");
2182  return true;
2183  }
2184 
2185  guidlow = target->GetDBTableGUIDLow();
2186  QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT guid FROM creature_addon WHERE guid = '%u'", guidlow);
2187 
2188  if (result)
2189  WorldDatabase.PExecute("UPDATE creature_addon SET path_id = '%u' WHERE guid = '%u'", pathid, guidlow);
2190  else
2191  WorldDatabase.PExecute("INSERT INTO creature_addon(guid,path_id) VALUES ('%u','%u')", guidlow, pathid);
2192 
2193  WorldDatabase.PExecute("UPDATE creature SET MovementType = '%u' WHERE guid = '%u'", WAYPOINT_MOTION_TYPE, guidlow);
2194 
2195  target->LoadPath(pathid);
2197  target->GetMotionMaster()->Initialize();
2198  target->Say("Path loaded.", 0, 0);
2199 
2200  return true;
2201 }
2202 
2204 {
2205  if (!*args)
2206  return false;
2207 
2208  uint32 id = atoi(args);
2209 
2210  if (!id)
2211  return false;
2212 
2213  PSendSysMessage("%s%s|r|cff00ffff%u|r", "|cff00ff00", "Loading Path: ", id);
2214  sWaypointMgr->ReloadPath(id);
2215  return true;
2216 }
2217 
2218 bool ChatHandler::HandleWpUnLoadPathCommand(const char* /*args*/)
2219 {
2220  uint32 guidlow = 0;
2221  Creature* target = getSelectedCreature();
2222 
2223  if (!target)
2224  {
2225  PSendSysMessage("%s%s|r", "|cff33ffff", "You must select target.");
2226  return true;
2227  }
2228 
2229  if (target->GetCreatureAddon())
2230  {
2231  if (target->GetCreatureAddon()->path_id != 0)
2232  {
2233  WorldDatabase.PExecute("DELETE FROM creature_addon WHERE guid = %u", target->GetGUIDLow());
2234  target->UpdateWaypointID(0);
2235  WorldDatabase.PExecute("UPDATE creature SET MovementType = '%u' WHERE guid = '%u'", IDLE_MOTION_TYPE, guidlow);
2236  target->LoadPath(0);
2238  target->GetMotionMaster()->MoveTargetedHome();
2239  target->GetMotionMaster()->Initialize();
2240  target->Say("Path unloaded.", 0, 0);
2241  return true;
2242  }
2243  PSendSysMessage("%s%s|r", "|cffff33ff", "Target has no loaded path.");
2244  }
2245  return true;
2246 }
2247 
2249 {
2250  if (!*args)
2251  return false;
2252 
2253  char* show_str = strtok((char*)args, " ");
2254  std::string show = show_str;
2255 
2256  // Check
2257  if ((show != "add") && (show != "mod") && (show != "del") && (show != "listid")) return false;
2258 
2259  char* arg_id = strtok(NULL, " ");
2260  uint32 id = 0;
2261 
2262  if (show == "add")
2263  {
2264  if (arg_id)
2265  id = atoi(arg_id);
2266 
2267  if (id)
2268  {
2269  QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT id FROM waypoint_scripts WHERE guid = %u", id);
2270 
2271  if (!result)
2272  {
2273  WorldDatabase.PExecute("INSERT INTO waypoint_scripts(guid)VALUES(%u)", id);
2274  PSendSysMessage("%s%s%u|r", "|cff00ff00", "Wp Event: New waypoint event added: ", id);
2275  }
2276  else
2277  PSendSysMessage("|cff00ff00Wp Event: You have chosen an existing waypoint script guid: %u|r", id);
2278  }
2279  else
2280  {
2281  QueryResult_AutoPtr result = WorldDatabase.Query("SELECT MAX(guid) FROM waypoint_scripts");
2282  id = result->Fetch()->GetUInt32();
2283  WorldDatabase.PExecute("INSERT INTO waypoint_scripts(guid)VALUES(%u)", id + 1);
2284  PSendSysMessage("%s%s%u|r", "|cff00ff00", "Wp Event: New waypoint event added: |r|cff00ffff", id + 1);
2285  }
2286 
2287  return true;
2288  }
2289 
2290  if (show == "listid")
2291  {
2292  if (!arg_id)
2293  {
2294  PSendSysMessage("%s%s|r", "|cff33ffff", "Wp Event: You must provide waypoint script id.");
2295  return true;
2296  }
2297 
2298  id = atoi(arg_id);
2299 
2300  uint32 a2, a3, a4, a5, a6;
2301  float a8, a9, a10, a11;
2302  char const* a7;
2303 
2304  QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT guid, delay, command, datalong, datalong2, dataint, x, y, z, o FROM waypoint_scripts WHERE id = %u", id);
2305 
2306  if (!result)
2307  {
2308  PSendSysMessage("%s%s%u|r", "|cff33ffff", "Wp Event: No waypoint scripts found on id: ", id);
2309  return true;
2310  }
2311 
2312  Field* fields;
2313 
2314  do
2315  {
2316  fields = result->Fetch();
2317  a2 = fields[0].GetUInt32();
2318  a3 = fields[1].GetUInt32();
2319  a4 = fields[2].GetUInt32();
2320  a5 = fields[3].GetUInt32();
2321  a6 = fields[4].GetUInt32();
2322  a7 = fields[5].GetString();
2323  a8 = fields[6].GetFloat();
2324  a9 = fields[7].GetFloat();
2325  a10 = fields[8].GetFloat();
2326  a11 = fields[9].GetFloat();
2327 
2328  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);
2329  }
2330  while (result->NextRow());
2331  }
2332 
2333  if (show == "del")
2334  {
2335  id = atoi(arg_id);
2336 
2337  QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT guid FROM waypoint_scripts WHERE guid = %u", id);
2338 
2339  if (result)
2340  {
2341  WorldDatabase.PExecuteLog("DELETE FROM waypoint_scripts WHERE guid = %u", id);
2342  PSendSysMessage("%s%s%u|r", "|cff00ff00", "Wp Event: Waypoint script removed: ", id);
2343  }
2344  else
2345  PSendSysMessage("|cffff33ffWp Event: ERROR: you have selected an invalid script: %u|r", id);
2346 
2347  return true;
2348  }
2349 
2350  if (show == "mod")
2351  {
2352  if (!arg_id)
2353  {
2354  SendSysMessage("|cffff33ffERROR: Waypoint script guid not present.|r");
2355  return true;
2356  }
2357 
2358  id = atoi(arg_id);
2359 
2360  if (!id)
2361  {
2362  SendSysMessage("|cffff33ffERROR: No vallid waypoint script id not present.|r");
2363  return true;
2364  }
2365 
2366  char* arg_2 = strtok(NULL, " ");
2367 
2368  if (!arg_2)
2369  {
2370  SendSysMessage("|cffff33ffERROR: No argument present.|r");
2371  return true;
2372  }
2373 
2374  std::string arg_string = arg_2;
2375 
2376  if ((arg_string != "setid") && (arg_string != "delay") && (arg_string != "command")
2377  && (arg_string != "datalong") && (arg_string != "datalong2") && (arg_string != "dataint") && (arg_string != "posx")
2378  && (arg_string != "posy") && (arg_string != "posz") && (arg_string != "orientation"))
2379  {
2380  SendSysMessage("|cffff33ffERROR: No valid argument present.|r");
2381  return true;
2382  }
2383 
2384  char* arg_3;
2385  std::string arg_str_2 = arg_2;
2386  arg_3 = strtok(NULL, " ");
2387 
2388  if (!arg_3)
2389  {
2390  SendSysMessage("|cffff33ffERROR: No additional argument present.|r");
2391  return true;
2392  }
2393 
2394  float coord;
2395 
2396  if (arg_str_2 == "setid")
2397  {
2398  uint32 newid = atoi(arg_3);
2399  PSendSysMessage("%s%s|r|cff00ffff%u|r|cff00ff00%s|r|cff00ffff%u|r", "|cff00ff00", "Wp Event: Wypoint scipt guid: ", newid, " id changed: ", id);
2400  WorldDatabase.PExecuteLog("UPDATE waypoint_scripts SET id='%u' WHERE guid='%u'",
2401  newid, id);
2402  return true;
2403  }
2404  else
2405  {
2406  QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT id FROM waypoint_scripts WHERE guid='%u'", id);
2407 
2408  if (!result)
2409  {
2410  SendSysMessage("|cffff33ffERROR: You have selected an invalid waypoint script guid.|r");
2411  return true;
2412  }
2413 
2414  if (arg_str_2 == "posx")
2415  {
2416  coord = atof(arg_3);
2417  WorldDatabase.PExecuteLog("UPDATE waypoint_scripts SET x='%f' WHERE guid='%u'",
2418  coord, id);
2419  PSendSysMessage("|cff00ff00Waypoint script:|r|cff00ffff %u|r|cff00ff00 position_x updated.|r", id);
2420  return true;
2421  }
2422  else if (arg_str_2 == "posy")
2423  {
2424  coord = atof(arg_3);
2425  WorldDatabase.PExecuteLog("UPDATE waypoint_scripts SET y='%f' WHERE guid='%u'",
2426  coord, id);
2427  PSendSysMessage("|cff00ff00Waypoint script: %u position_y updated.|r", id);
2428  return true;
2429  }
2430  else if (arg_str_2 == "posz")
2431  {
2432  coord = atof(arg_3);
2433  WorldDatabase.PExecuteLog("UPDATE waypoint_scripts SET z='%f' WHERE guid='%u'",
2434  coord, id);
2435  PSendSysMessage("|cff00ff00Waypoint script: |r|cff00ffff%u|r|cff00ff00 position_z updated.|r", id);
2436  return true;
2437  }
2438  else if (arg_str_2 == "orientation")
2439  {
2440  coord = atof(arg_3);
2441  WorldDatabase.PExecuteLog("UPDATE waypoint_scripts SET o='%f' WHERE guid='%u'",
2442  coord, id);
2443  PSendSysMessage("|cff00ff00Waypoint script: |r|cff00ffff%u|r|cff00ff00 orientation updated.|r", id);
2444  return true;
2445  }
2446  else if (arg_str_2 == "dataint")
2447  {
2448  WorldDatabase.PExecuteLog("UPDATE waypoint_scripts SET %s='%u' WHERE guid='%u'",
2449  arg_2, atoi(arg_3), id);
2450  PSendSysMessage("|cff00ff00Waypoint script: |r|cff00ffff%u|r|cff00ff00 dataint updated.|r", id);
2451  return true;
2452  }
2453  else
2454  {
2455  std::string arg_str_3 = arg_3;
2456  WorldDatabase.escape_string(arg_str_3);
2457  WorldDatabase.PExecuteLog("UPDATE waypoint_scripts SET %s='%s' WHERE guid='%u'",
2458  arg_2, arg_str_3.c_str(), id);
2459  }
2460  }
2461  PSendSysMessage("%s%s|r|cff00ffff%u:|r|cff00ff00 %s %s|r", "|cff00ff00", "Waypoint script:", id, arg_2, "updated.");
2462  }
2463  return true;
2464 }
2465 
2467 {
2468  sLog.outDebug("DEBUG: HandleWpModifyCommand");
2469 
2470  if (!*args)
2471  return false;
2472 
2473  // first arg: add del text emote spell waittime move
2474  char* show_str = strtok((char*)args, " ");
2475  if (!show_str)
2476  return false;
2477 
2478  std::string show = show_str;
2479  // Check
2480  // Remember: "show" must also be the name of a column!
2481  if ((show != "delay") && (show != "action") && (show != "action_chance")
2482  && (show != "move_flag") && (show != "del") && (show != "move") && (show != "wpadd")
2483  )
2484  return false;
2485 
2486  // Next arg is: <PATHID> <WPNUM> <ARGUMENT>
2487  char* arg_str = NULL;
2488 
2489  // Did user provide a GUID
2490  // or did the user select a creature?
2491  // -> variable lowguid is filled with the GUID of the NPC
2492  uint32 pathid = 0;
2493  uint32 point = 0;
2494  uint32 wpGuid = 0;
2495  Creature* target = getSelectedCreature();
2496 
2497  if (!target || target->GetEntry() != VISUAL_WAYPOINT)
2498  {
2499  SendSysMessage("|cffff33ffERROR: You must select a waypoint.|r");
2500  return false;
2501  }
2502 
2503  sLog.outDebug("DEBUG: HandleWpModifyCommand - User did select an NPC");
2504  // The visual waypoint
2505  Creature* wpCreature = NULL;
2506  wpGuid = target->GetGUIDLow();
2507 
2508  // Did the user select a visual spawnpoint?
2509  if (wpGuid)
2511  // attempt check creature existence by DB data
2512  else
2513  {
2515  return false;
2516  }
2517  // User did select a visual waypoint?
2518  // Check the creature
2519  if (wpCreature->GetEntry() == VISUAL_WAYPOINT)
2520  {
2521  QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT id, point FROM waypoint_data WHERE wpguid = %u", wpGuid);
2522 
2523  if (!result)
2524  {
2525  sLog.outDebug("DEBUG: HandleWpModifyCommand - No waypoint found - used 'wpguid'");
2526 
2528  // Select waypoint number from database
2529  // Since we compare float values, we have to deal with
2530  // some difficulties.
2531  // Here we search for all waypoints that only differ in one from 1 thousand
2532  // (0.001) - There is no other way to compare C++ floats with mySQL floats
2533  // See also: http://dev.mysql.com/doc/refman/5.0/en/problems-with-float.html
2534  const char* maxDIFF = "0.01";
2535  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)",
2536  wpCreature->GetPositionX(), maxDIFF, wpCreature->GetPositionY(), maxDIFF, wpCreature->GetPositionZ(), maxDIFF);
2537  if (!result)
2538  {
2540  return true;
2541  }
2542  }
2543  sLog.outDebug("DEBUG: HandleWpModifyCommand - After getting wpGuid");
2544 
2545  do
2546  {
2547  Field* fields = result->Fetch();
2548  pathid = fields[0].GetUInt32();
2549  point = fields[1].GetUInt32();
2550  }
2551  while (result->NextRow());
2552 
2553  // We have the waypoint number and the GUID of the "master npc"
2554  // Text is enclosed in "<>", all other arguments not
2555  arg_str = strtok((char*)NULL, " ");
2556  }
2557 
2558  sLog.outDebug("DEBUG: HandleWpModifyCommand - Parameters parsed - now execute the command");
2559 
2560  // Check for argument
2561  if (show != "del" && show != "move" && arg_str == NULL)
2562  {
2564  return false;
2565  }
2566 
2567  if (show == "del" && target)
2568  {
2569  PSendSysMessage("|cff00ff00DEBUG: wp modify del, PathID: |r|cff00ffff%u|r", pathid);
2570 
2571  // wpCreature
2572  Creature* wpCreature = NULL;
2573 
2574  if (wpGuid != 0)
2575  {
2577  wpCreature->CombatStop();
2578  wpCreature->DeleteFromDB();
2579  wpCreature->AddObjectToRemoveList();
2580  }
2581 
2582  WorldDatabase.PExecuteLog("DELETE FROM waypoint_data WHERE id='%u' AND point='%u'",
2583  pathid, point);
2584  WorldDatabase.PExecuteLog("UPDATE waypoint_data SET point=point-1 WHERE id='%u' AND point>'%u'",
2585  pathid, point);
2586 
2588  return true;
2589  } // del
2590 
2591  if (show == "move" && target)
2592  {
2593  PSendSysMessage("|cff00ff00DEBUG: wp move, PathID: |r|cff00ffff%u|r", pathid);
2594 
2595  Player* chr = m_session->GetPlayer();
2596  Map* map = chr->GetMap();
2597  {
2598  // wpCreature
2599  Creature* wpCreature = NULL;
2600  // What to do:
2601  // Move the visual spawnpoint
2602  // Respawn the owner of the waypoints
2603  if (wpGuid != 0)
2604  {
2606  wpCreature->CombatStop();
2607  wpCreature->DeleteFromDB();
2608  wpCreature->AddObjectToRemoveList();
2609  // re-create
2610  Creature* wpCreature2 = new Creature;
2611  if (!wpCreature2->Create(sObjectMgr.GenerateLowGuid(HIGHGUID_UNIT), map, VISUAL_WAYPOINT, 0, chr->GetPositionX(), chr->GetPositionY(), chr->GetPositionZ(), chr->GetOrientation()))
2612  {
2613  PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED, VISUAL_WAYPOINT);
2614  delete wpCreature2;
2615  return false;
2616  }
2617 
2618  wpCreature2->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()));
2619  // To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells();
2620  //TODO: Should we first use "Create" then use "LoadFromDB"?
2621  if (!wpCreature2->LoadCreatureFromDB(wpCreature2->GetDBTableGUIDLow(), map))
2622  {
2623  PSendSysMessage(LANG_WAYPOINT_VP_NOTCREATED, VISUAL_WAYPOINT);
2624  delete wpCreature2;
2625  return false;
2626  }
2627  }
2628 
2629  WorldDatabase.PExecuteLog("UPDATE waypoint_data SET position_x = '%f',position_y = '%f',position_z = '%f' where id = '%u' AND point='%u'",
2630  chr->GetPositionX(), chr->GetPositionY(), chr->GetPositionZ(), pathid, point);
2631 
2633  }
2634  return true;
2635  } // move
2636 
2637  const char* text = arg_str;
2638 
2639  if (text == 0)
2640  {
2641  // show_str check for present in list of correct values, no sql injection possible
2642  WorldDatabase.PExecuteLog("UPDATE waypoint_data SET %s=NULL WHERE id='%u' AND point='%u'",
2643  show_str, pathid, point);
2644  }
2645  else
2646  {
2647  // show_str check for present in list of correct values, no sql injection possible
2648  std::string text2 = text;
2650  WorldDatabase.PExecuteLog("UPDATE waypoint_data SET %s='%s' WHERE id='%u' AND point='%u'",
2651  show_str, text2.c_str(), pathid, point);
2652  }
2653 
2655  return true;
2656 }
2657 
2658 bool ChatHandler::HandleWpShowCommand(const char* args)
2659 {
2660  sLog.outDebug("DEBUG: HandleWpShowCommand");
2661 
2662  if (!*args)
2663  return false;
2664 
2665  // first arg: on, off, first, last
2666  char* show_str = strtok((char*)args, " ");
2667  if (!show_str)
2668  return false;
2669 
2670  // second arg: GUID (optional, if a creature is selected)
2671  char* guid_str = strtok((char*)NULL, " ");
2672  sLog.outDebug("DEBUG: HandleWpShowCommand: show_str: %s guid_str: %s", show_str, guid_str);
2673 
2674  uint32 pathid = 0;
2675  Creature* target = getSelectedCreature();
2676 
2677  // Did player provide a PathID?
2678 
2679  if (!guid_str)
2680  {
2681  sLog.outDebug("DEBUG: HandleWpShowCommand: !guid_str");
2682  // No PathID provided
2683  // -> Player must have selected a creature
2684 
2685  if (!target)
2686  {
2688  SetSentErrorMessage(true);
2689  return false;
2690  }
2691 
2692  pathid = target->GetWaypointPath();
2693  }
2694  else
2695  {
2696  sLog.outDebug("|cff00ff00DEBUG: HandleWpShowCommand: PathID provided|r");
2697  // PathID provided
2698  // Warn if player also selected a creature
2699  // -> Creature selection is ignored <-
2700  if (target)
2702 
2703  pathid = atoi((char*)guid_str);
2704  }
2705 
2706  sLog.outDebug("DEBUG: HandleWpShowCommand: danach");
2707 
2708  std::string show = show_str;
2709  uint32 Maxpoint;
2710 
2711  sLog.outDebug("DEBUG: HandleWpShowCommand: PathID: %u", pathid);
2712 
2713  //PSendSysMessage("wpshow - show: %s", show);
2714 
2715  // Show info for the selected waypoint
2716  if (show == "info")
2717  {
2718  // Check if the user did specify a visual waypoint
2719  if (target->GetEntry() != VISUAL_WAYPOINT)
2720  {
2722  SetSentErrorMessage(true);
2723  return false;
2724  }
2725 
2726  QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT id, point, delay, move_flag, action, action_chance FROM waypoint_data WHERE wpguid = %u", target->GetGUIDLow());
2727 
2728  if (!result)
2729  {
2731  return true;
2732  }
2733 
2734  SendSysMessage("|cff00ffffDEBUG: wp show info:|r");
2735  do
2736  {
2737  Field* fields = result->Fetch();
2738  pathid = fields[0].GetUInt32();
2739  uint32 point = fields[1].GetUInt32();
2740  uint32 delay = fields[2].GetUInt32();
2741  uint32 flag = fields[3].GetUInt32();
2742  uint32 ev_id = fields[4].GetUInt32();
2743  uint32 ev_chance = fields[5].GetUInt32();
2744 
2745  PSendSysMessage("|cff00ff00Show info: for current point: |r|cff00ffff%u|r|cff00ff00, Path ID: |r|cff00ffff%u|r", point, pathid);
2746  PSendSysMessage("|cff00ff00Show info: delay: |r|cff00ffff%u|r", delay);
2747  PSendSysMessage("|cff00ff00Show info: Move flag: |r|cff00ffff%u|r", flag);
2748  PSendSysMessage("|cff00ff00Show info: Waypoint event: |r|cff00ffff%u|r", ev_id);
2749  PSendSysMessage("|cff00ff00Show info: Event chance: |r|cff00ffff%u|r", ev_chance);
2750  }
2751  while (result->NextRow());
2752 
2753  return true;
2754  }
2755 
2756  if (show == "on")
2757  {
2758  QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT point, position_x,position_y,position_z FROM waypoint_data WHERE id = '%u'", pathid);
2759 
2760  if (!result)
2761  {
2762  SendSysMessage("|cffff33ffPath no found.|r");
2763  SetSentErrorMessage(true);
2764  return false;
2765  }
2766 
2767  PSendSysMessage("|cff00ff00DEBUG: wp on, PathID: |cff00ffff%u|r", pathid);
2768 
2769  // Delete all visuals for this NPC
2770  QueryResult_AutoPtr result2 = WorldDatabase.PQuery("SELECT wpguid FROM waypoint_data WHERE id = '%u' and wpguid <> 0", pathid);
2771 
2772  if (result2)
2773  {
2774  bool hasError = false;
2775  do
2776  {
2777  Field* fields = result2->Fetch();
2778  uint32 wpguid = fields[0].GetUInt32();
2780 
2781  if (!pCreature)
2782  {
2784  hasError = true;
2785  WorldDatabase.PExecuteLog("DELETE FROM creature WHERE guid = '%u'", wpguid);
2786  }
2787  else
2788  {
2789  pCreature->CombatStop();
2790  pCreature->DeleteFromDB();
2791  pCreature->AddObjectToRemoveList();
2792  }
2793 
2794  }
2795  while (result2->NextRow());
2796 
2797  if (hasError)
2798  {
2802  }
2803  }
2804 
2805  do
2806  {
2807  Field* fields = result->Fetch();
2808  uint32 point = fields[0].GetUInt32();
2809  float x = fields[1].GetFloat();
2810  float y = fields[2].GetFloat();
2811  float z = fields[3].GetFloat();
2812 
2813  uint32 id = VISUAL_WAYPOINT;
2814 
2815  Player* chr = m_session->GetPlayer();
2816  Map* map = chr->GetMap();
2817  float o = chr->GetOrientation();
2818 
2819  Creature* wpCreature = new Creature;
2820  if (!wpCreature->Create(sObjectMgr.GenerateLowGuid(HIGHGUID_UNIT), map, id, 0, x, y, z, o))
2821  {
2823  delete wpCreature;
2824  return false;
2825  }
2826 
2827  sLog.outDebug("DEBUG: UPDATE waypoint_data SET wpguid = '%u'", wpCreature->GetGUIDLow());
2828  // set "wpguid" column to the visual waypoint
2829  WorldDatabase.PExecuteLog("UPDATE waypoint_data SET wpguid = '%u' WHERE id = '%u' and point = '%u'", wpCreature->GetGUIDLow(), pathid, point);
2830 
2831  wpCreature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()));
2832  if (!wpCreature->LoadCreatureFromDB(wpCreature->GetDBTableGUIDLow(), map))
2833  {
2835  delete wpCreature;
2836  return false;
2837  }
2838 
2839  if (target)
2840  {
2841  wpCreature->SetDisplayId(target->GetDisplayId());
2842  wpCreature->SetObjectScale(0.5);
2843  }
2844  }
2845  while (result->NextRow());
2846 
2847  SendSysMessage("|cff00ff00Showing the current creature's path.|r");
2848  return true;
2849  }
2850 
2851  if (show == "first")
2852  {
2853  PSendSysMessage("|cff00ff00DEBUG: wp first, GUID: %u|r", pathid);
2854 
2855  QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT position_x,position_y,position_z,orientation FROM waypoint_data WHERE point='1' AND id = '%u'", pathid);
2856  if (!result)
2857  {
2859  SetSentErrorMessage(true);
2860  return false;
2861  }
2862 
2863  Field* fields = result->Fetch();
2864  float x = fields[0].GetFloat();
2865  float y = fields[1].GetFloat();
2866  float z = fields[2].GetFloat();
2867  float o = fields[3].GetFloat();
2868  uint32 id = VISUAL_WAYPOINT;
2869 
2870  Player* chr = m_session->GetPlayer();
2871  Map* map = chr->GetMap();
2872 
2873  Creature* creature = new Creature;
2874  if (!creature->Create(sObjectMgr.GenerateLowGuid(HIGHGUID_UNIT), map, id, 0, x, y, z, o))
2875  {
2877  delete creature;
2878  return false;
2879  }
2880 
2881  creature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()));
2882  if (!creature->LoadCreatureFromDB(creature->GetDBTableGUIDLow(), map))
2883  {
2885  delete creature;
2886  return false;
2887  }
2888 
2889  if (target)
2890  {
2891  creature->SetDisplayId(target->GetDisplayId());
2892  creature->SetObjectScale(0.5);
2893  }
2894 
2895  return true;
2896  }
2897 
2898  if (show == "last")
2899  {
2900  PSendSysMessage("|cff00ff00DEBUG: wp last, PathID: |r|cff00ffff%u|r", pathid);
2901 
2902  QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT MAX(point) FROM waypoint_data WHERE id = '%u'", pathid);
2903  if (result)
2904  Maxpoint = (*result)[0].GetUInt32();
2905  else
2906  Maxpoint = 0;
2907 
2908  result = WorldDatabase.PQuery("SELECT position_x,position_y,position_z FROM waypoint_data WHERE point ='%u' AND id = '%u'", Maxpoint, pathid);
2909  if (!result)
2910  {
2912  SetSentErrorMessage(true);
2913  return false;
2914  }
2915  Field* fields = result->Fetch();
2916  float x = fields[0].GetFloat();
2917  float y = fields[1].GetFloat();
2918  float z = fields[2].GetFloat();
2919  float o = fields[3].GetFloat();
2920  uint32 id = VISUAL_WAYPOINT;
2921 
2922  Player* chr = m_session->GetPlayer();
2923  Map* map = chr->GetMap();
2924 
2925  Creature* creature = new Creature;
2926  if (!creature->Create(sObjectMgr.GenerateLowGuid(HIGHGUID_UNIT), map, id, 0, x, y, z, o))
2927  {
2929  delete creature;
2930  return false;
2931  }
2932 
2933  creature->SaveToDB(map->GetId(), (1 << map->GetSpawnMode()));
2934  if (!creature->LoadCreatureFromDB(creature->GetDBTableGUIDLow(), map))
2935  {
2937  delete creature;
2938  return false;
2939  }
2940 
2941  if (target)
2942  {
2943  creature->SetDisplayId(target->GetDisplayId());
2944  creature->SetObjectScale(0.5);
2945  }
2946 
2947  return true;
2948  }
2949 
2950  if (show == "off")
2951  {
2952  QueryResult_AutoPtr result = WorldDatabase.PQuery("SELECT guid FROM creature WHERE id = '%u'", 1);
2953  if (!result)
2954  {
2956  SetSentErrorMessage(true);
2957  return false;
2958  }
2959  bool hasError = false;
2960  do
2961  {
2962  Field* fields = result->Fetch();
2963  uint32 guid = fields[0].GetUInt32();
2965  if (!creature)
2966  {
2968  hasError = true;
2969  WorldDatabase.PExecuteLog("DELETE FROM creature WHERE guid = '%u'", guid);
2970  }
2971  else
2972  {
2973  creature->CombatStop();
2974  creature->DeleteFromDB();
2975  creature->AddObjectToRemoveList();
2976  }
2977  }
2978  while (result->NextRow());
2979  // set "wpguid" column to "empty" - no visual waypoint spawned
2980  WorldDatabase.PExecuteLog("UPDATE waypoint_data SET wpguid = '0'");
2981  //WorldDatabase.PExecuteLog("UPDATE creature_movement SET wpguid = '0' WHERE wpguid <> '0'");
2982 
2983  if (hasError)
2984  {
2988  }
2989 
2991  return true;
2992  }
2993 
2994  PSendSysMessage("|cffff33ffDEBUG: wpshow - no valid command found|r");
2995  return true;
2996 }
2997 
2998 // WAYPOINT COMMANDS
2999 
3000 //rename characters
3002 {
3003  Player* target = NULL;
3004  uint64 targetGUID = 0;
3005  std::string oldname;
3006 
3007  char* px = strtok((char*)args, " ");
3008 
3009  if (px)
3010  {
3011  oldname = px;
3012 
3013  if (!normalizePlayerName(oldname))
3014  {
3016  SetSentErrorMessage(true);
3017  return false;
3018  }
3019 
3020  target = sObjectMgr.GetPlayer(oldname.c_str());
3021 
3022  if (!target)
3023  targetGUID = sObjectMgr.GetPlayerGUIDByName(oldname);
3024  }
3025 
3026  if (!target && !targetGUID)
3027  target = getSelectedPlayer();
3028 
3029  if (!target && !targetGUID)
3030  {
3032  SetSentErrorMessage(true);
3033  return false;
3034  }
3035 
3036  if (target)
3037  {
3040  }
3041  else
3042  {
3043  PSendSysMessage(LANG_RENAME_PLAYER_GUID, oldname.c_str(), GUID_LOPART(targetGUID));
3044  CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '1' WHERE guid = '%u'", GUID_LOPART(targetGUID));
3045  }
3046 
3047  return true;
3048 }
3049 
3051 {
3052  if (!*args)
3053  return false;
3054 
3055  // Can be NULL at console call
3056  Player* target = getSelectedPlayer ();
3057 
3058  std::string namepart = args;
3059  std::wstring wnamepart;
3060 
3061  if (!Utf8toWStr (namepart, wnamepart))
3062  return false;
3063 
3064  // converting string that we try to find to lower case
3065  wstrToLower (wnamepart);
3066 
3067  uint32 counter = 0; // Counter for figure out that we found smth.
3068 
3069  for (uint32 id = 0; id < sFactionStore.GetNumRows(); ++id)
3070  {
3071  FactionEntry const* factionEntry = sFactionStore.LookupEntry (id);
3072  if (factionEntry)
3073  {
3074  FactionState const* factionState = target ? target->GetReputationMgr().GetState(factionEntry) : NULL;
3075 
3076  int loc = m_session ? int(m_session->GetSessionDbcLocale()) : sWorld.GetDefaultDbcLocale();
3077  std::string name = factionEntry->name[loc];
3078  if (name.empty())
3079  continue;
3080 
3081  if (!Utf8FitTo(name, wnamepart))
3082  {
3083  loc = 0;
3084  for (; loc < MAX_LOCALE; ++loc)
3085  {
3086  if (m_session && loc == m_session->GetSessionDbcLocale())
3087  continue;
3088 
3089  name = factionEntry->name[loc];
3090  if (name.empty())
3091  continue;
3092 
3093  if (Utf8FitTo(name, wnamepart))
3094  break;
3095  }
3096  }
3097 
3098  if (loc < MAX_LOCALE)
3099  {
3100  // send faction in "id - [faction] rank reputation [visible] [at war] [own team] [unknown] [invisible] [inactive]" format
3101  // or "id - [faction] [no reputation]" format
3102  std::ostringstream ss;
3103  if (m_session)
3104  ss << id << " - |cffffffff|Hfaction:" << id << "|h[" << name << " " << localeNames[loc] << "]|h|r";
3105  else
3106  ss << id << " - " << name << " " << localeNames[loc];
3107 
3108  if (factionState) // and then target != NULL also
3109  {
3110  ReputationRank rank = target->GetReputationMgr().GetRank(factionEntry);
3111  std::string rankName = GetOregonString(ReputationRankStrIndex[rank]);
3112 
3113  ss << " " << rankName << "|h|r (" << target->GetReputationMgr().GetReputation(factionEntry) << ")";
3114 
3115  if (factionState->Flags & FACTION_FLAG_VISIBLE)
3117  if (factionState->Flags & FACTION_FLAG_AT_WAR)
3119  if (factionState->Flags & FACTION_FLAG_PEACE_FORCED)
3121  if (factionState->Flags & FACTION_FLAG_HIDDEN)
3123  if (factionState->Flags & FACTION_FLAG_INVISIBLE_FORCED)
3125  if (factionState->Flags & FACTION_FLAG_INACTIVE)
3127  }
3128  else
3130 
3131  SendSysMessage(ss.str().c_str());
3132  counter++;
3133  }
3134  }
3135  }
3136 
3137  if (counter == 0) // if counter == 0 then we found nth
3139  return true;
3140 }
3141 
3142 //show animation
3143 bool ChatHandler::HandleAnimCommand(const char* args)
3144 {
3145  if (!*args)
3146  return false;
3147 
3148  uint32 anim_id = atoi((char*)args);
3149  m_session->GetPlayer()->HandleEmoteCommand(anim_id);
3150  return true;
3151 }
3152 
3153 //change standstate
3155 {
3156  if (!*args)
3157  return false;
3158 
3159  uint32 anim_id = atoi((char*)args);
3161 
3162  return true;
3163 }
3164 
3166 {
3167  if (!*args)
3168  return false;
3169 
3170  Player* target = getSelectedPlayer();
3171  if (!target)
3172  {
3174  SetSentErrorMessage(true);
3175  return false;
3176  }
3177 
3178  uint32 amount = (uint32)atoi(args);
3179  target->RewardHonor(NULL, 1, amount);
3180  return true;
3181 }
3182 
3183 bool ChatHandler::HandleHonorAddKillCommand(const char* /*args*/)
3184 {
3185  Unit* target = getSelectedUnit();
3186  if (!target)
3187  {
3189  SetSentErrorMessage(true);
3190  return false;
3191  }
3192 
3193  m_session->GetPlayer()->RewardHonor(target, 1);
3194  return true;
3195 }
3196 
3198 {
3199  Player* target = getSelectedPlayer();
3200  if (!target)
3201  {
3203  SetSentErrorMessage(true);
3204  return false;
3205  }
3206 
3207  target->UpdateHonorFields();
3208  return true;
3209 }
3210 
3212 {
3213  if (!*args)
3214  return false;
3215 
3216  std::string namepart = args;
3217  std::wstring wnamepart;
3218 
3219  // converting string that we try to find to lower case
3220  if (!Utf8toWStr(namepart, wnamepart))
3221  return false;
3222 
3223  wstrToLower(wnamepart);
3224 
3225  bool found = false;
3226  uint32 count = 0;
3227  uint32 maxResults = sWorld.getConfig(CONFIG_MAX_RESULTS_LOOKUP_COMMANDS);
3228 
3229  GameEventMgr::GameEventDataMap const& events = sGameEventMgr.GetEventMap();
3230  GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr.GetActiveEventList();
3231 
3232  for (uint32 id = 0; id < events.size(); ++id)
3233  {
3234  GameEventData const& eventData = events[id];
3235 
3236  std::string descr = eventData.description;
3237  if (descr.empty())
3238  continue;
3239 
3240  if (Utf8FitTo(descr, wnamepart))
3241  {
3242  if (maxResults && count++ == maxResults)
3243  {
3245  return true;
3246  }
3247 
3248  char const* active = activeEvents.find(id) != activeEvents.end() ? GetOregonString(LANG_ACTIVE) : "";
3249 
3250  if (m_session)
3251  PSendSysMessage(LANG_EVENT_ENTRY_LIST_CHAT, id, id, eventData.description.c_str(), active);
3252  else
3253  PSendSysMessage(LANG_EVENT_ENTRY_LIST_CONSOLE, id, eventData.description.c_str(), active);
3254 
3255  if (!found)
3256  found = true;
3257  }
3258  }
3259 
3260  if (!found)
3262 
3263  return true;
3264 }
3265 
3267 {
3268  uint32 counter = 0;
3269 
3270  GameEventMgr::GameEventDataMap const& events = sGameEventMgr.GetEventMap();
3271  GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr.GetActiveEventList();
3272 
3273  char const* active = GetOregonString(LANG_ACTIVE);
3274 
3275  for (GameEventMgr::ActiveEvents::const_iterator itr = activeEvents.begin(); itr != activeEvents.end(); ++itr)
3276  {
3277  uint32 event_id = *itr;
3278  GameEventData const& eventData = events[event_id];
3279 
3280  if (m_session)
3281  PSendSysMessage(LANG_EVENT_ENTRY_LIST_CHAT, event_id, event_id, eventData.description.c_str(), active);
3282  else
3283  PSendSysMessage(LANG_EVENT_ENTRY_LIST_CONSOLE, event_id, eventData.description.c_str(), active);
3284 
3285  ++counter;
3286  }
3287 
3288  if (counter == 0)
3290 
3291  return true;
3292 }
3293 
3295 {
3296  if (!*args)
3297  return false;
3298 
3299  // id or [name] Shift-click form |color|Hgameevent:id|h[name]|h|r
3300  char* cId = extractKeyFromLink((char*)args, "Hgameevent");
3301  if (!cId)
3302  return false;
3303 
3304  uint32 event_id = atoi(cId);
3305 
3306  GameEventMgr::GameEventDataMap const& events = sGameEventMgr.GetEventMap();
3307 
3308  if (event_id >= events.size())
3309  {
3311  SetSentErrorMessage(true);
3312  return false;
3313  }
3314 
3315  GameEventData const& eventData = events[event_id];
3316  if (!eventData.isValid())
3317  {
3319  SetSentErrorMessage(true);
3320  return false;
3321  }
3322 
3323  GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr.GetActiveEventList();
3324  bool active = activeEvents.find(event_id) != activeEvents.end();
3325  char const* activeStr = active ? GetOregonString(LANG_ACTIVE) : "";
3326 
3327  std::string startTimeStr = TimeToTimestampStr(eventData.start);
3328  std::string endTimeStr = TimeToTimestampStr(eventData.end);
3329 
3330  uint32 delay = sGameEventMgr.NextCheck(event_id);
3331  time_t nextTime = time(NULL) + delay;
3332  std::string nextStr = nextTime >= eventData.start && nextTime < eventData.end ? TimeToTimestampStr(time(NULL) + delay) : "-";
3333 
3334  std::string occurenceStr = secsToTimeString(eventData.occurence * MINUTE);
3335  std::string lengthStr = secsToTimeString(eventData.length * MINUTE);
3336 
3337  PSendSysMessage(LANG_EVENT_INFO, event_id, eventData.description.c_str(), activeStr,
3338  startTimeStr.c_str(), endTimeStr.c_str(), occurenceStr.c_str(), lengthStr.c_str(),
3339  nextStr.c_str());
3340  return true;
3341 }
3342 
3344 {
3345  if (!*args)
3346  return false;
3347 
3348  // id or [name] Shift-click form |color|Hgameevent:id|h[name]|h|r
3349  char* cId = extractKeyFromLink((char*)args, "Hgameevent");
3350  if (!cId)
3351  return false;
3352 
3353  int32 event_id = atoi(cId);
3354 
3355  GameEventMgr::GameEventDataMap const& events = sGameEventMgr.GetEventMap();
3356 
3357  if (event_id < 1 || uint32(event_id) >= events.size())
3358  {
3360  SetSentErrorMessage(true);
3361  return false;
3362  }
3363 
3364  GameEventData const& eventData = events[event_id];
3365  if (!eventData.isValid())
3366  {
3368  SetSentErrorMessage(true);
3369  return false;
3370  }
3371 
3372  GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr.GetActiveEventList();
3373  if (activeEvents.find(event_id) != activeEvents.end())
3374  {
3376  SetSentErrorMessage(true);
3377  return false;
3378  }
3379 
3380  sGameEventMgr.StartEvent(event_id, true);
3381  return true;
3382 }
3383 
3385 {
3386  if (!*args)
3387  return false;
3388 
3389  // id or [name] Shift-click form |color|Hgameevent:id|h[name]|h|r
3390  char* cId = extractKeyFromLink((char*)args, "Hgameevent");
3391  if (!cId)
3392  return false;
3393 
3394  int32 event_id = atoi(cId);
3395 
3396  GameEventMgr::GameEventDataMap const& events = sGameEventMgr.GetEventMap();
3397 
3398  if (event_id < 1 || uint32(event_id) >= events.size())
3399  {
3401  SetSentErrorMessage(true);
3402  return false;
3403  }
3404 
3405  GameEventData const& eventData = events[event_id];
3406  if (!eventData.isValid())
3407  {
3409  SetSentErrorMessage(true);
3410  return false;
3411  }
3412 
3413  GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr.GetActiveEventList();
3414 
3415  if (activeEvents.find(event_id) == activeEvents.end())
3416  {
3418  SetSentErrorMessage(true);
3419  return false;
3420  }
3421 
3422  sGameEventMgr.StopEvent(event_id, true);
3423  return true;
3424 }
3425 
3427 {
3428  Player* player;
3429 
3430  if (*args)
3431  {
3432  std::string playername = args;
3433 
3434  if (!normalizePlayerName(playername))
3435  {
3437  SetSentErrorMessage(true);
3438  return false;
3439  }
3440 
3441  player = sObjectMgr.GetPlayer(playername.c_str());
3442 
3443  if (!player)
3444  {
3446  SetSentErrorMessage(true);
3447  return false;
3448  }
3449  }
3450  else
3451  {
3452  player = getSelectedPlayer();
3453 
3454  if (!player)
3455  player = m_session->GetPlayer();
3456  }
3457 
3458  player->CombatStop();
3460  return true;
3461 }
3462 
3464 {
3465  uint32 classmask = m_session->GetPlayer()->getClassMask();
3466 
3467  for (uint32 i = 0; i < sSkillLineStore.GetNumRows(); ++i)
3468  {
3469  SkillLineEntry const* skillInfo = sSkillLineStore.LookupEntry(i);
3470  if (!skillInfo)
3471  continue;
3472 
3473  if (skillInfo->categoryId == SKILL_CATEGORY_PROFESSION || skillInfo->categoryId == SKILL_CATEGORY_SECONDARY)
3474  {
3475  for (uint32 j = 0; j < sSkillLineAbilityStore.GetNumRows(); ++j)
3476  {
3477  SkillLineAbilityEntry const* skillLine = sSkillLineAbilityStore.LookupEntry(j);
3478  if (!skillLine)
3479  continue;
3480 
3481  // skip racial skills
3482  if (skillLine->racemask != 0)
3483  continue;
3484 
3485  // skip wrong class skills
3486  if (skillLine->classmask && (skillLine->classmask & classmask) == 0)
3487  continue;
3488 
3489  if (skillLine->skillId != i || skillLine->forward_spellid)
3490  continue;
3491 
3492  SpellEntry const* spellInfo = sSpellStore.LookupEntry(skillLine->spellId);
3493  if (!spellInfo || !SpellMgr::IsSpellValid(spellInfo, m_session->GetPlayer(), false))
3494  continue;
3495 
3496  m_session->GetPlayer()->LearnSpell(skillLine->spellId);
3497  }
3498  }
3499  }
3500 
3502  return true;
3503 }
3504 
3506 {
3507  // Learns all recipes of specified profession and sets skill to max
3508  // Example: .learn all_recipes enchanting
3509 
3510  Player* target = getSelectedPlayer();
3511  if (!target)
3512  {
3514  return false;
3515  }
3516 
3517  if (!*args)
3518  return false;
3519 
3520  std::wstring wnamepart;
3521 
3522  if (!Utf8toWStr(args, wnamepart))
3523  return false;
3524 
3525  // converting string that we try to find to lower case
3526  wstrToLower(wnamepart);
3527 
3528  uint32 classmask = m_session->GetPlayer()->getClassMask();
3529 
3530  for (uint32 i = 0; i < sSkillLineStore.GetNumRows(); ++i)
3531  {
3532  SkillLineEntry const* skillInfo = sSkillLineStore.LookupEntry(i);
3533  if (!skillInfo)
3534  continue;
3535 
3536  if (skillInfo->categoryId != SKILL_CATEGORY_PROFESSION &&
3537  skillInfo->categoryId != SKILL_CATEGORY_SECONDARY)
3538  continue;
3539 
3540  int loc = m_session->GetSessionDbcLocale();
3541  std::string name = skillInfo->name[loc];
3542 
3543  if (Utf8FitTo(name, wnamepart))
3544  {
3545  for (uint32 j = 0; j < sSkillLineAbilityStore.GetNumRows(); ++j)
3546  {
3547  SkillLineAbilityEntry const* skillLine = sSkillLineAbilityStore.LookupEntry(j);
3548  if (!skillLine)
3549  continue;
3550 
3551  if (skillLine->skillId != i || skillLine->forward_spellid)
3552  continue;
3553 
3554  // skip racial skills
3555  if (skillLine->racemask != 0)
3556  continue;
3557 
3558  // skip wrong class skills
3559  if (skillLine->classmask && (skillLine->classmask & classmask) == 0)
3560  continue;
3561 
3562  SpellEntry const* spellInfo = sSpellStore.LookupEntry(skillLine->spellId);
3563  if (!spellInfo || !SpellMgr::IsSpellValid(spellInfo, m_session->GetPlayer(), false))
3564  continue;
3565 
3566  if (!target->HasSpell(spellInfo->Id))
3567  m_session->GetPlayer()->LearnSpell(skillLine->spellId);
3568  }
3569 
3570  uint16 maxLevel = target->GetPureMaxSkillValue(skillInfo->id);
3571  target->SetSkill(skillInfo->id, maxLevel, maxLevel);
3573  return true;
3574  }
3575  }
3576 
3577  return false;
3578 }
3579 
3581 {
3582 
3583  if (!*args)
3584  return false;
3585 
3586  std::string ip = strtok ((char*)args, " ");
3587  char* limit_str = strtok (NULL, " ");
3588  int32 limit = limit_str ? atoi (limit_str) : -1;
3589 
3591 
3592  QueryResult_AutoPtr result = LoginDatabase.PQuery ("SELECT id,username FROM account WHERE last_ip = '%s'", ip.c_str ());
3593 
3594  return LookupPlayerSearchCommand (result, limit);
3595 }
3596 
3598 {
3599  if (!*args)
3600  return false;
3601 
3602  std::string account = strtok ((char*)args, " ");
3603  char* limit_str = strtok (NULL, " ");
3604  int32 limit = limit_str ? atoi (limit_str) : -1;
3605 
3606  if (!AccountMgr::normalizeString (account))
3607  return false;
3608 
3609  LoginDatabase.escape_string (account);
3610 
3611  QueryResult_AutoPtr result = LoginDatabase.PQuery ("SELECT id,username FROM account WHERE username = '%s'", account.c_str ());
3612 
3613  return LookupPlayerSearchCommand (result, limit);
3614 }
3615 
3617 {
3618 
3619  if (!*args)
3620  return false;
3621 
3622  std::string email = strtok ((char*)args, " ");
3623  char* limit_str = strtok (NULL, " ");
3624  int32 limit = limit_str ? atoi (limit_str) : -1;
3625 
3626  LoginDatabase.escape_string (email);
3627 
3628  QueryResult_AutoPtr result = LoginDatabase.PQuery ("SELECT id,username FROM account WHERE email = '%s'", email.c_str ());
3629 
3630  return LookupPlayerSearchCommand (result, limit);
3631 }
3632 
3634 {
3635  if (!result)
3636  {
3638  SetSentErrorMessage(true);
3639  return false;
3640  }
3641 
3642  int i = 0;
3643  uint32 count = 0;
3644  uint32 maxResults = sWorld.getConfig(CONFIG_MAX_RESULTS_LOOKUP_COMMANDS);
3645  do
3646  {
3647  if (maxResults && count++ == maxResults)
3648  {
3650  return true;
3651  }
3652 
3653  Field* fields = result->Fetch();
3654  uint32 acc_id = fields[0].GetUInt32();
3655  std::string acc_name = fields[1].GetCppString();
3656 
3657  QueryResult_AutoPtr chars = CharacterDatabase.PQuery("SELECT guid,name FROM characters WHERE account = '%u'", acc_id);
3658  if (chars)
3659  {
3660  PSendSysMessage(LANG_LOOKUP_PLAYER_ACCOUNT, acc_name.c_str(), acc_id);
3661 
3662  uint64 guid = 0;
3663  std::string name;
3664 
3665  do
3666  {
3667  Field* charfields = chars->Fetch();
3668  guid = charfields[0].GetUInt64();
3669  name = charfields[1].GetCppString();
3670 
3671  PSendSysMessage(LANG_LOOKUP_PLAYER_CHARACTER, name.c_str(), guid);
3672  ++i;
3673 
3674  }
3675  while (chars->NextRow() && (limit == -1 || i < limit));
3676  }
3677  }
3678  while (result->NextRow());
3679 
3680  return true;
3681 }
3682 
3683 // Triggering corpses expire check in world
3685 {
3687  return true;
3688 }
3689 
3690 bool ChatHandler::HandleRepairitemsCommand(const char* /*args*/)
3691 {
3692  Player* target = getSelectedPlayer();
3693 
3694  if (!target)
3695  {
3697  SetSentErrorMessage(true);
3698  return false;
3699  }
3700 
3701  // Repair items
3702  target->DurabilityRepairAll(false, 0, false);
3703 
3705  if (needReportToTarget(target))
3706  ChatHandler(target).PSendSysMessage(LANG_YOUR_ITEMS_REPAIRED, GetName());
3707  return true;
3708 }
3709 
3710 bool ChatHandler::HandleCreatePetCommand(const char* /*args*/)
3711 {
3712  Player* player = m_session->GetPlayer();
3713  Creature* creatureTarget = getSelectedCreature();
3714 
3715  if (!creatureTarget || creatureTarget->IsPet() || creatureTarget->GetTypeId() == TYPEID_PLAYER)
3716  {
3718  SetSentErrorMessage(true);
3719  return false;
3720  }
3721 
3722  CreatureInfo const* cInfo = sObjectMgr.GetCreatureTemplate(creatureTarget->GetEntry());
3723  // Creatures with family CREATURE_FAMILY_NONE crashes the server
3724  if (cInfo->family == CREATURE_FAMILY_NONE)
3725  {
3726  PSendSysMessage("This creature cannot be tamed. Family id: 0 (CREATURE_FAMILY_NONE).");
3727  SetSentErrorMessage(true);
3728  return false;
3729  }
3730 
3731  if (player->GetPetGUID())
3732  {
3733  PSendSysMessage("You already have a pet");
3734  SetSentErrorMessage(true);
3735  return false;
3736  }
3737 
3738  // Everything looks OK, create new pet
3739  Pet* pet = new Pet(player, HUNTER_PET);
3740 
3741  if (!pet)
3742  return false;
3743 
3744  if (!pet->CreateBaseAtCreature(creatureTarget))
3745  {
3746  delete pet;
3747  PSendSysMessage("Error 1");
3748  return false;
3749  }
3750 
3751  creatureTarget->setDeathState(JUST_DIED);
3752  creatureTarget->RemoveCorpse();
3753  creatureTarget->SetHealth(0); // just for nice GM-mode view
3754 
3755  pet->SetUInt64Value(UNIT_FIELD_CREATEDBY, player->GetGUID());
3757 
3758  if (!pet->InitStatsForLevel(creatureTarget->getLevel()))
3759  {
3760  sLog.outError("InitStatsForLevel() in EffectTameCreature failed! Pet deleted.");
3761  PSendSysMessage("Error 2");
3762  delete pet;
3763  return false;
3764  }
3765 
3766  // prepare visual effect for levelup
3767  pet->SetUInt32Value(UNIT_FIELD_LEVEL, creatureTarget->getLevel() - 1);
3768 
3769  pet->GetCharmInfo()->SetPetNumber(sObjectMgr.GeneratePetNumber(), true);
3770  // this enables pet details window (Shift+P)
3771  pet->InitPetCreateSpells();
3772  pet->SetHealth(pet->GetMaxHealth());
3773 
3774  pet->GetMap()->AddToMap(pet->ToCreature());
3775 
3776  // visual effect for levelup
3777  pet->SetUInt32Value(UNIT_FIELD_LEVEL, creatureTarget->getLevel());
3778 
3779  player->SetMinion(pet, true);
3781  player->PetSpellInitialize();
3782 
3783  return true;
3784 }
3785 
3787 {
3788  if (!*args)
3789  return false;
3790 
3791  Player* plr = m_session->GetPlayer();
3792  Pet* pet = plr->GetPet();
3793 
3794  if (!pet)
3795  {
3796  PSendSysMessage("You have no pet");
3797  SetSentErrorMessage(true);
3798  return false;
3799  }
3800 
3801  uint32 spellId = extractSpellIdFromLink((char*)args);
3802 
3803  if (!spellId || !sSpellStore.LookupEntry(spellId))
3804  return false;
3805 
3806  // Check if pet already has it
3807  if (pet->HasSpell(spellId))
3808  {
3809  PSendSysMessage("Pet already has spell: %u", spellId);
3810  SetSentErrorMessage(true);
3811  return false;
3812  }
3813 
3814  // Check if spell is valid
3815  SpellEntry const* spellInfo = sSpellStore.LookupEntry(spellId);
3816  if (!spellInfo || !SpellMgr::IsSpellValid(spellInfo))
3817  {
3819  SetSentErrorMessage(true);
3820  return false;
3821  }
3822 
3823  pet->learnSpell(spellId);
3824 
3825  PSendSysMessage("Pet has learned spell %u", spellId);
3826  return true;
3827 }
3828 
3830 {
3831  if (!*args)
3832  return false;
3833 
3834  Player* plr = m_session->GetPlayer();
3835  Pet* pet = plr->GetPet();
3836 
3837  if (!pet)
3838  {
3839  PSendSysMessage("You have no pet");
3840  SetSentErrorMessage(true);
3841  return false;
3842  }
3843 
3844  uint32 spellId = extractSpellIdFromLink((char*)args);
3845 
3846  if (pet->HasSpell(spellId))
3847  pet->removeSpell(spellId);
3848  else
3849  PSendSysMessage("Pet doesn't have that spell");
3850 
3851  return true;
3852 }
3853 
3854 bool ChatHandler::HandlePetTpCommand(const char* args)
3855 {
3856  if (!*args)
3857  return false;
3858 
3859  Player* plr = m_session->GetPlayer();
3860  Pet* pet = plr->GetPet();
3861 
3862  if (!pet)
3863  {
3864  PSendSysMessage("You have no pet");
3865  SetSentErrorMessage(true);
3866  return false;
3867  }
3868 
3869  uint32 tp = atol(args);
3870 
3871  pet->SetTP(tp);
3872 
3873  PSendSysMessage("Pet's tp changed to %u", tp);
3874  return true;
3875 }
3876 
3878 {
3879  if (!*args)
3880  return false;
3881 
3882  char* cId = extractKeyFromLink((char*)args, "Hgameobject");
3883  if (!cId)
3884  return false;
3885 
3886  uint32 lowguid = atoi(cId);
3887  if (!lowguid)
3888  return false;
3889 
3890  GameObject* obj = NULL;
3891 
3892  // by DB guid
3893  if (GameObjectData const* go_data = sObjectMgr.GetGOData(lowguid))
3894  obj = GetObjectGlobalyWithGuidOrNearWithDbGuid(lowguid, go_data->id);
3895 
3896  if (!obj)
3897  {
3899  SetSentErrorMessage(true);
3900  return false;
3901  }
3902 
3903  // Activate
3904  obj->SetLootState(GO_READY);
3905  obj->UseDoorOrButton(10000, false, m_session->GetPlayer());
3906 
3907  PSendSysMessage("Object activated!");
3908 
3909  return true;
3910 }
3911 
3912 // add creature, temp only
3914 {
3915  if (!*args)
3916  return false;
3917  char* charID = strtok((char*)args, " ");
3918  if (!charID)
3919  return false;
3920 
3921  Player* chr = m_session->GetPlayer();
3922 
3923  float x = chr->GetPositionX();
3924  float y = chr->GetPositionY();
3925  float z = chr->GetPositionZ();
3926  float ang = chr->GetOrientation();
3927 
3928  uint32 id = atoi(charID);
3929 
3930  chr->SummonCreature(id, x, y, z, ang, TEMPSUMMON_CORPSE_DESPAWN, 120);
3931 
3932  return true;
3933 }
3934 
3935 // add go, temp only
3937 {
3938  if (!*args)
3939  return false;
3940  char* id = strtok((char*)args, " ");
3941  if (!id)
3942  return false;
3943 
3944  Player* player = m_session->GetPlayer();
3945 
3946  char* spawntime = strtok(NULL, " ");
3947  uint32 spawntm = 0;
3948 
3949  if (spawntime)
3950  spawntm = atoi((char*)spawntime);
3951 
3952  float x = player->GetPositionX();
3953  float y = player->GetPositionY();
3954  float z = player->GetPositionZ();
3955  float ang = player->GetOrientation();
3956 
3957  float rot2 = sin(ang / 2);
3958  float rot3 = cos(ang / 2);
3959 
3960  uint32 objectId = atoi(id);
3961 
3962  if (!sObjectMgr.GetGameObjectInfo(objectId))
3963  {
3965  SetSentErrorMessage(true);
3966  return false;
3967  }
3968 
3969  player->SummonGameObject(objectId, x, y, z, ang, 0, 0, rot2, rot3, spawntm);
3970 
3971  return true;
3972 }
3973 
3975 {
3976  if (!*args)
3977  return false;
3978 
3979  uint32 linkguid = (uint32) atoi((char*)args);
3980 
3981  Creature* pCreature = getSelectedCreature();
3982 
3983  if (!pCreature)
3984  {
3986  SetSentErrorMessage(true);
3987  return false;
3988  }
3989 
3990  if (!pCreature->GetDBTableGUIDLow())
3991  {
3992  PSendSysMessage("Selected creature (GUID: %u) isn't in creature table", pCreature->GetGUIDLow());
3993  SetSentErrorMessage(true);
3994  return false;
3995  }
3996 
3997  if (!sObjectMgr.SetCreatureLinkedRespawn(pCreature->GetDBTableGUIDLow(), linkguid))
3998  {
3999  PSendSysMessage("Selected creature can't link with guid '%u'", linkguid);
4000  SetSentErrorMessage(true);
4001  return false;
4002  }
4003 
4004  PSendSysMessage("LinkGUID '%u' added to creature with DBTableGUID: '%u'", linkguid, pCreature->GetDBTableGUIDLow());
4005  return true;
4006 }
4007 
4009 {
4010  if (!*args)
4011  return false;
4012 
4013  // can be NULL in console call
4014  Player* target = getSelectedPlayer();
4015 
4016  // title name have single string arg for player name
4017  char const* targetName = target ? target->GetName() : "NAME";
4018 
4019  std::string namepart = args;
4020  std::wstring wnamepart;
4021 
4022  if (!Utf8toWStr(namepart, wnamepart))
4023  return false;
4024 
4025  // converting string that we try to find to lower case
4026  wstrToLower(wnamepart);
4027 
4028  uint32 counter = 0; // Counter for figure out that we found smth.
4029  uint32 maxResults = sWorld.getConfig(CONFIG_MAX_RESULTS_LOOKUP_COMMANDS);
4030 
4031  // Search in CharTitles.dbc
4032  for (uint32 id = 0; id < sCharTitlesStore.GetNumRows(); id++)
4033  {
4034  CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(id);
4035  if (titleInfo)
4036  {
4037  int loc = m_session->GetSessionDbcLocale();
4038  std::string name = titleInfo->name[loc];
4039  if (name.empty())
4040  continue;
4041 
4042  if (!Utf8FitTo(name, wnamepart))
4043  {
4044  loc = 0;
4045  for (; loc < MAX_LOCALE; ++loc)
4046  {
4047  if (loc == m_session->GetSessionDbcLocale())
4048  continue;
4049 
4050  name = titleInfo->name[loc];
4051  if (name.empty())
4052  continue;
4053 
4054  if (Utf8FitTo(name, wnamepart))
4055  break;
4056  }
4057  }
4058 
4059  if (loc < MAX_LOCALE)
4060  {
4061  if (maxResults && counter == maxResults)
4062  {
4064  return true;
4065  }
4066 
4067  char const* knownStr = target && target->HasTitle(titleInfo) ? GetOregonString(LANG_KNOWN) : "";
4068 
4069  char const* activeStr = target && target->GetUInt32Value(PLAYER_CHOSEN_TITLE) == titleInfo->bit_index
4071  : "";
4072 
4073  char titleNameStr[80];
4074  snprintf(titleNameStr, 80, name.c_str(), targetName);
4075 
4076  // send title in "id (idx:idx) - [namedlink locale]" format
4077  if (m_session)
4078  PSendSysMessage(LANG_TITLE_LIST_CHAT, id, titleInfo->bit_index, id, titleNameStr, localeNames[loc], knownStr, activeStr);
4079  else
4080  PSendSysMessage(LANG_TITLE_LIST_CONSOLE, id, titleInfo->bit_index, titleNameStr, localeNames[loc], knownStr, activeStr);
4081 
4082  ++counter;
4083  }
4084  }
4085  }
4086  if (counter == 0) // if counter == 0 then we found nth
4088  return true;
4089 }
4090 
4092 {
4093  // number or [name] Shift-click form |color|Htitle:title_id|h[name]|h|r
4094  char* id_p = extractKeyFromLink((char*)args, "Htitle");
4095  if (!id_p)
4096  return false;
4097 
4098  int32 id = atoi(id_p);
4099  if (id <= 0)
4100  {
4102  SetSentErrorMessage(true);
4103  return false;
4104  }
4105 
4106  Player* target = getSelectedPlayer();
4107  if (!target)
4108  {
4110  SetSentErrorMessage(true);
4111  return false;
4112  }
4113 
4114  CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(id);
4115  if (!titleInfo)
4116  {
4118  SetSentErrorMessage(true);
4119  return false;
4120  }
4121 
4122  std::string tNameLink = target->GetName();
4123 
4124  char const* targetName = target->GetName();
4125  char titleNameStr[80];
4126  snprintf(titleNameStr, 80, titleInfo->name[m_session->GetSessionDbcLocale()], targetName);
4127 
4128  target->SetTitle(titleInfo);
4129  PSendSysMessage(LANG_TITLE_ADD_RES, id, titleNameStr, tNameLink.c_str());
4130 
4131  return true;
4132 }
4133 
4135 {
4136  // number or [name] Shift-click form |color|Htitle:title_id|h[name]|h|r
4137  char* id_p = extractKeyFromLink((char*)args, "Htitle");
4138  if (!id_p)
4139  return false;
4140 
4141  int32 id = atoi(id_p);
4142  if (id <= 0)
4143  {
4145  SetSentErrorMessage(true);
4146  return false;
4147  }
4148 
4149  Player* target = getSelectedPlayer();
4150  if (!target)
4151  {
4153  SetSentErrorMessage(true);
4154  return false;
4155  }
4156 
4157  CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(id);
4158  if (!titleInfo)
4159  {
4161  SetSentErrorMessage(true);
4162  return false;
4163  }
4164 
4165  target->SetTitle(titleInfo, true);
4166 
4167  char const* targetName = target->GetName();
4168  char titleNameStr[80];
4169  snprintf(titleNameStr, 80, titleInfo->name[m_session->GetSessionDbcLocale()], targetName);
4170 
4171  PSendSysMessage(LANG_TITLE_REMOVE_RES, id, titleNameStr, targetName);
4172 
4173  if (!target->HasTitle(target->GetInt32Value(PLAYER_CHOSEN_TITLE)))
4174  {
4175  target->SetUInt32Value(PLAYER_CHOSEN_TITLE, 0);
4177  }
4178 
4179  return true;
4180 }
4181 
4182 //Edit Player KnownTitles
4184 {
4185  if (!*args)
4186  return false;
4187 
4188  uint64 titles = 0;
4189 
4190  sscanf((char*)args, UI64FMTD, &titles);
4191 
4192  Player* target = getSelectedPlayer();
4193  if (!target)
4194  {
4196  SetSentErrorMessage(true);
4197  return false;
4198  }
4199 
4200  uint64 titles2 = titles;
4201 
4202  for (uint32 i = 1; i < sCharTitlesStore.GetNumRows(); ++i)
4203  if (CharTitlesEntry const* tEntry = sCharTitlesStore.LookupEntry(i))
4204  titles2 &= ~(uint64(1) << tEntry->bit_index);
4205 
4206  titles &= ~titles2; // remove not existed titles
4207 
4208  target->SetUInt64Value(PLAYER__FIELD_KNOWN_TITLES, titles);
4210 
4211  if (!target->HasTitle(target->GetInt32Value(PLAYER_CHOSEN_TITLE)))
4212  {
4213  target->SetUInt32Value(PLAYER_CHOSEN_TITLE, 0);
4215  }
4216 
4217  return true;
4218 }
4219 
4221 {
4222 
4223  Player* target = getSelectedPlayer();
4224  if (!target)
4225  {
4227  SetSentErrorMessage(true);
4228  return false;
4229  }
4230 
4232  char const* targetName = target->GetName();
4233  char const* knownStr = GetOregonString(LANG_KNOWN);
4234 
4235  // Search in CharTitles.dbc
4236  for (uint32 id = 0; id < sCharTitlesStore.GetNumRows(); id++)
4237  {
4238  CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(id);
4239  if (titleInfo && target->HasTitle(titleInfo))
4240  {
4241  std::string name = titleInfo->name[loc];
4242  if (name.empty())
4243  continue;
4244 
4245  char const* activeStr = target && target->GetUInt32Value(PLAYER_CHOSEN_TITLE) == titleInfo->bit_index
4247  : "";
4248 
4249  char titleNameStr[80];
4250  snprintf(titleNameStr, 80, name.c_str(), targetName);
4251 
4252  // send title in "id (idx:idx) - [namedlink locale]" format
4253  if (m_session)
4254  PSendSysMessage(LANG_TITLE_LIST_CHAT, id, titleInfo->bit_index, id, titleNameStr, localeNames[loc], knownStr, activeStr);
4255  else
4256  PSendSysMessage(LANG_TITLE_LIST_CONSOLE, id, titleInfo->bit_index, name.c_str(), localeNames[loc], knownStr, activeStr);
4257  }
4258  }
4259  return true;
4260 }
4261 
4263 {
4264  // number or [name] Shift-click form |color|Htitle:title_id|h[name]|h|r
4265  char* id_p = extractKeyFromLink((char*)args, "Htitle");
4266  if (!id_p)
4267  return false;
4268 
4269  int32 id = atoi(id_p);
4270  if (id <= 0)
4271  {
4273  SetSentErrorMessage(true);
4274  return false;
4275  }
4276 
4277  Player* target = getSelectedPlayer();
4278  if (!target)
4279  {
4281  SetSentErrorMessage(true);
4282  return false;
4283  }
4284 
4285  CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(id);
4286  if (!titleInfo)
4287  {
4289  SetSentErrorMessage(true);
4290  return false;
4291  }
4292 
4293  std::string tNameLink = target->GetName();
4294 
4295  target->SetTitle(titleInfo); // to be sure that title now known
4296  target->SetUInt32Value(PLAYER_CHOSEN_TITLE, titleInfo->bit_index);
4297 
4298  PSendSysMessage(LANG_TITLE_CURRENT_RES, id, titleInfo->name[m_session->GetSessionDbcLocale()], tNameLink.c_str());
4299 
4300  return true;
4301 }
4302 
4304 {
4305  uint64 account = strtoull(args, NULL, 10);
4306  if (!account)
4307  return false;
4308 
4309  uint64 linked;
4310  switch (sObjectMgr.GetRAFLinkStatus(account, &linked))
4311  {
4312  case RAF_LINK_NONE:
4313  PSendSysMessage("Account " UI64FMTD " is not linked to any account.", account);
4314  break;
4315  case RAF_LINK_REFERRER:
4316  PSendSysMessage("Account " UI64FMTD " is referrer account. (friend is: " UI64FMTD ")", account, linked);
4317  break;
4318  case RAF_LINK_REFERRED:
4319  PSendSysMessage("Account " UI64FMTD " is referred account. (friend is: " UI64FMTD ")", account, linked);
4320  if (Player* player = ObjectAccessor::Instance().FindPlayerByAccountId(account))
4321  PSendSysMessage("Character %s has %.02f grantable levels", player->GetName(), player->GetGrantableLevels());
4322  break;
4323  }
4324 
4325  return true;
4326 }
4327 
4329 {
4330  uint64 referrer = strtoull(args, NULL, 10);
4331  if (!referrer)
4332  return false;
4333 
4334  args = strchr(args, ' ');
4335  if (!args)
4336  return false;
4337 
4338  uint64 referred = strtoull(args, NULL, 10);
4339  if (!referred)
4340  return false;
4341 
4342  if (sObjectMgr.GetRAFLinkStatus(referrer) != RAF_LINK_NONE ||
4343  sObjectMgr.GetRAFLinkStatus(referred) != RAF_LINK_NONE)
4344  {
4345  PSendSysMessage("First or second account is already linked with an account.");
4346  return true;
4347  }
4348 
4349  sObjectMgr.LinkIntoRAF(referrer, referred);
4350  PSendSysMessage("Accounts successfully linked.");
4351  return true;
4352 }
4353 
4355 {
4356  uint64 acc = strtoull(args, NULL, 10);
4357  if (!acc)
4358  return false;
4359 
4360  sObjectMgr.UnlinkFromRAF(acc);
4361  PSendSysMessage("Account was sucessfully unlinked");
4362  return true;
4363 }
4364 
bool HandleCharacterRenameCommand(const char *args)
Definition: Level2.cpp:3001
bool Utf8FitTo(const std::string &str, std::wstring search)
Definition: Util.cpp:458
DBCStorage< WorldSafeLocsEntry > sWorldSafeLocsStore(WorldSafeLocsEntryfmt)
bool AddToMap(T *)
Definition: Map.cpp:424
bool HandleAnimCommand(const char *args)
Definition: Level2.cpp:3143
void CreatureRelocation(Creature *creature, float x, float y, float z, float ang, bool respawnRelocationOnFail=true)
Definition: Map.cpp:734
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:2222
bool HandleWpLoadPathCommand(const char *args)
Definition: Level2.cpp:2144
#define snprintf
Definition: Common.h:129
void SetSentErrorMessage(bool val)
Definition: Chat.h:590
uint8 GetSpawnMode() const
Definition: Map.h:394
bool LoadCreatureFromDB(uint32 guid, Map *map, bool addToMap=true)
Definition: Creature.cpp:1289
bool HasSpell(uint32 spell) const override
Definition: Pet.cpp:1927
int32 GetReputation(uint32 faction_id) const
Definition: Unit.h:416
bool HandleEventActiveListCommand(const char *args)
Definition: Level2.cpp:3266
GameObject * GetObjectGlobalyWithGuidOrNearWithDbGuid(uint32 lowguid, uint32 entry)
Definition: Chat.cpp:1776
const uint32 & GetUInt32Value(uint16 index) const
Definition: Object.h:228
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:3211
void SetPetNumber(uint32 petnumber, bool statwindow)
Definition: Unit.cpp:11314
static const int32 PointsInRank[MAX_REPUTATION_RANK]
Definition: ReputationMgr.h:67
bool HandleLookupPlayerIpCommand(const char *args)
Definition: Level2.cpp:3580
uint32 GetMaxHealth() const
Definition: Unit.h:1052
bool HandleNpcFlagCommand(const char *args)
Definition: Level2.cpp:1119
Creature * getSelectedCreature()
Definition: Chat.cpp:1637
bool HandleTitlesCurrentCommand(const char *args)
Definition: Level2.cpp:4262
bool HandleNpcAddCommand(const char *args)
Definition: Level2.cpp:954
ReputationRank
Map * GetMap() const
Definition: Object.h:829
DatabaseType WorldDatabase
Accessor to the world database.
Definition: Main.cpp:53
uint32 GetDBTableGUIDLow() const
Definition: Creature.h:476
bool HandleRAFInfoCommand(const char *args)
Definition: Level2.cpp:4303
Unit * getSelectedUnit()
Definition: Chat.cpp:1624
uint32 getFaction() const
Definition: Unit.h:1111
bool HandleActivateObjectCommand(const char *args)
Definition: Level2.cpp:3877
bool HandleUpdateHonorFieldsCommand(const char *args)
Definition: Level2.cpp:3197
void UpdateWaypointID(uint32 wpID)
Definition: Creature.h:829
QueryResult_AutoPtr PQuery(const char *format,...) ATTR_PRINTF(2
Definition: Database.cpp:400
bool HandlePetLearnCommand(const char *args)
Definition: Level2.cpp:3786
bool HandleServerCorpsesCommand(const char *args)
Definition: Level2.cpp:3684
Definition: Field.h:24
void SetObjectScale(float scale)
Definition: Object.h:199
bool IsValidPos(uint16 pos)
Definition: Player.h:1125
uint64 GetOwnerGUID() const
Definition: GameObject.h:662
bool HandleTitlesSetMaskCommand(const char *args)
Definition: Level2.cpp:4183
bool HandleWpEventCommand(const char *args)
Definition: Level2.cpp:2248
bool HandleAddHonorCommand(const char *args)
Definition: Level2.cpp:3165
uint32 GetWaypointPath()
Definition: Creature.h:816
bool HandleTurnObjectCommand(const char *args)
Definition: Level2.cpp:653
void SetTitle(CharTitlesEntry const *title, bool lost=false)
Definition: Player.cpp:20480
MotionMaster * GetMotionMaster()
Definition: Unit.h:2001
#define strtoull
Definition: Common.h:133
TempSummon * SummonCreature(uint32 id, const Position &pos, TempSummonType spwtype=TEMPSUMMON_MANUAL_DESPAWN, uint32 despwtime=0)
Definition: Object.cpp:2088
DBCStorage< FactionTemplateEntry > sFactionTemplateStore(FactionTemplateEntryfmt)
void DeleteFromDB()
Definition: GameObject.cpp:730
bool HandleNpcFactionIdCommand(const char *args)
Definition: Level2.cpp:1419
bool HandleRAFUnlinkCommand(const char *args)
Definition: Level2.cpp:4354
#define sLog
Log class singleton.
Definition: Log.h:187
virtual void SaveToDB()
Definition: Creature.cpp:1044
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 HandleNpcSetLinkCommand(const char *args)
Definition: Level2.cpp:3974
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:1835
bool HandleLookupPlayerAccountCommand(const char *args)
Definition: Level2.cpp:3597
bool HandleGoTicketCommand(const char *args)
Definition: Level2.cpp:205
void SaveRecallPosition()
Definition: Player.cpp:5755
QueryResult_AutoPtr Query(const char *sql)
Definition: Database.cpp:383
time_t GetRespawnTimeEx() const
Definition: GameObject.h:682
bool HandleGoGraveyardCommand(const char *args)
Definition: Level2.cpp:292
bool HandlePetTpCommand(const char *args)
Definition: Level2.cpp:3854
bool LookupPlayerSearchCommand(QueryResult_AutoPtr result, int32 limit)
Definition: Level2.cpp:3633
DBCStorage< AreaTriggerEntry > sAreaTriggerStore(AreaTriggerEntryfmt)
void SetNativeDisplayId(uint32 modelId)
Definition: Unit.h:1900
void Refresh()
Definition: GameObject.cpp:544
virtual void SendSysMessage(const char *str)
Definition: Chat.cpp:787
uint32 GetAccountId() const
Definition: WorldSession.h:100
bool HandleNameCommand(const char *args)
Definition: Level2.cpp:1592
bool CreateBaseAtCreature(Creature *creature)
Definition: Pet.cpp:905
void SetRespawnTime(int32 respawn)
Definition: GameObject.h:691
#define GUID_HIPART(x)
Definition: ObjectGuid.h:82
Player * GetPlayer() const
Definition: WorldSession.h:104
uint32 GetGUIDLow() const
Definition: Object.h:160
Definition: Pet.h:28
bool HandleWpModifyCommand(const char *args)
Definition: Level2.cpp:2466
bool CanSpeak() const
Definition: Player.cpp:16837
LocaleConstant GetSessionDbcLocale() const
Definition: WorldSession.h:233
bool Utf8toWStr(char const *utf8str, size_t csize, wchar_t *wstr, size_t &wsize)
Definition: Util.cpp:294
void LoadPath(uint32 pathid)
Definition: Creature.h:820
float pos_z
Definition: TicketMgr.h:40
WorldSession * m_session
Definition: Chat.h:593
bool HandleMorphCommand(const char *args)
Definition: Level2.cpp:1733
void SetMinion(Minion *minion, bool apply)
Definition: Unit.cpp:7629
FactionState const * GetState(FactionEntry const *factionEntry) const
Definition: ReputationMgr.h:75
bool HandleRepairitemsCommand(const char *args)
Definition: Level2.cpp:3690
#define sObjectMgr
Definition: ObjectMgr.h:1285
void wstrToLower(std::wstring &str)
Definition: Util.h:314
bool HandleMuteCommand(const char *args)
Definition: Level2.cpp:55
CharmInfo * GetCharmInfo()
Definition: Unit.h:1567
_Ty top() const
Definition: MotionMaster.h:132
bool Create(uint32 guidlow, uint32 name_id, Map *map, 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
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:1444
bool PExecuteLog(const char *format,...) ATTR_PRINTF(2
Definition: Database.cpp:221
uint32 GetRespawnDelay() const
Definition: GameObject.h:711
uint32 map
Definition: TicketMgr.h:41
#define MAX_REPUTATION_RANK
uint16 GetPureMaxSkillValue(uint32 skill) const
Definition: Player.cpp:5579
bool HasSpell(uint32 spell) const override
Definition: Player.cpp:3813
bool HandleRAFLinkCommand(const char *args)
Definition: Level2.cpp:4328
DBCStorage< CharTitlesEntry > sCharTitlesStore(CharTitlesEntryfmt)
Definition: Common.h:179
void setFaction(uint32 faction)
Definition: Unit.h:1115
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:204
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:1556
bool InitStatsForLevel(uint32 level)
Definition: Pet.cpp:966
Creature * GetCreature(uint64 guid)
Definition: Map.cpp:2632
ACE_UINT8 uint8
Definition: Define.h:73
float GetOrientation() const
Definition: Position.h:100
#define sWaypointMgr
void setDeathState(DeathState s) override
Definition: Creature.cpp:1558
uint32 GetDisplayId()
Definition: Unit.h:1891
#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:4220
bool learnSpell(uint16 spell_id)
Definition: Pet.cpp:1576
bool HandleTitlesRemoveCommand(const char *args)
Definition: Level2.cpp:4134
void PetSpellInitialize()
Definition: Player.cpp:17319
HostileRefManager & getHostileRefManager()
Definition: Unit.h:1842
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:1987
void PSendSysMessage(const char *format,...) ATTR_PRINTF(2
Definition: Chat.cpp:855
void SetDisplayId(uint32 modelId)
Definition: Unit.cpp:11896
void SetRespawnRadius(float dist)
Definition: Creature.h:752
bool HandleLookupFactionCommand(const char *args)
Definition: Level2.cpp:3050
DatabaseType LoginDatabase
Accessor to the realm/login database.
Definition: Main.cpp:55
void SetDefaultMovementType(MovementGeneratorType mgt)
Definition: Creature.h:707
void EndianConvertReverse(T &)
Definition: ByteConverter.h:52
bool IsAlive() const
Definition: Unit.h:1433
bool HandleDeMorphCommand(const char *args)
Definition: Level2.cpp:1721
float GetPositionY() const
Definition: Position.h:98
void DeMorph()
Definition: Unit.cpp:3610
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:3154
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:1567
void Say(const char *text, uint32 language, uint64 TargetGuid)
Definition: Creature.h:616
void CombatStop(bool cast=false)
Definition: Unit.cpp:7442
float pos_y
Definition: TicketMgr.h:39
#define _LIKE_
Definition: DatabaseEnv.h:30
static bool normalizeString(std::string &utf8str)
Definition: AccountMgr.cpp:223
bool HandleWpUnLoadPathCommand(const char *args)
Definition: Level2.cpp:2218
void UpdateObjectVisibility(bool forced=true) override
Definition: Player.cpp:18873
bool HandleGUIDCommand(const char *args)
Definition: Level2.cpp:842
std::string TimeToTimestampStr(time_t t)
Definition: Util.cpp:216
uint32 GetMapId() const
Definition: Object.h:585
void SetMaxHealth(uint32 val)
Definition: Unit.cpp:10859
uint32 extractSpellIdFromLink(char *text)
Definition: Chat.cpp:1808
void SetTP(int32 TP)
Definition: Pet.cpp:837
bool PExecute(const char *format,...) ATTR_PRINTF(2
Definition: Database.cpp:441
bool HandleEventStartCommand(const char *args)
Definition: Level2.cpp:3343
bool HandleLookupTitleCommand(const char *args)
Definition: Level2.cpp:4008
FactionStateList const & GetStateList() const
Definition: ReputationMgr.h:73
Definition: Map.h:266
#define sAccountMgr
Definition: AccountMgr.h:60
void SetAtLoginFlag(AtLoginFlags f)
Definition: Player.h:2493
void CleanupAfterTaxiFlight()
Definition: Player.cpp:17893
void SetUInt64Value(uint16 index, const uint64 &value)
Definition: Object.cpp:798
bool HandleLearnAllCraftsCommand(const char *args)
Definition: Level2.cpp:3463
char * name[16]
Definition: DBCStructure.h:118
void UseDoorOrButton(uint32 time_to_restore=0, bool alternative=false, Unit *user=NULL)
Definition: GameObject.cpp:950
uint32 DurabilityRepairAll(bool cost, float discountMod, bool guildBank)
Definition: Player.cpp:4494
std::string secsToTimeString(uint32 timeInSecs, bool shortText, bool hoursOnly)
Definition: Util.cpp:148
bool HandleItemMoveCommand(const char *args)
Definition: Level2.cpp:1686
void InitPetCreateSpells()
Definition: Pet.cpp:1605
bool IsPet() const
Definition: Unit.h:1020
const char * GetName() const
Definition: Object.h:692
ReputationMgr & GetReputationMgr()
Definition: Player.h:2091
ChatHandler()
Definition: Chat.h:90
Player * getSelectedPlayer()
Definition: Chat.cpp:1593
uint32 GetLatency() const
Definition: WorldSession.h:243
ACE_UINT64 uint64
Definition: Define.h:70
uint32 getClassMask() const
Definition: Unit.h:1040
void Respawn(bool force=false)
Definition: Creature.cpp:1630
uint64 GetPetGUID() const
Definition: Unit.h:1487
bool HandleWpShowCommand(const char *args)
Definition: Level2.cpp:2658
bool HandleGoCreatureCommand(const char *args)
Teleport the GM to the specified creature.
Definition: Level2.cpp:348
bool HandleTempGameObjectCommand(const char *args)
Definition: Level2.cpp:3936
bool RewardHonor(Unit *victim, uint32 groupsize, float honor=-1, bool pvptoken=false)
Definition: Player.cpp:6057
uint32 occurence
Definition: GameEventMgr.h:57
uint8 getRace() const
Definition: Unit.h:1037
void RemoveGameObject(GameObject *gameObj, bool del)
Definition: Unit.cpp:4674
#define sGameEventMgr
Definition: GameEventMgr.h:179
CreatureInfo const * GetCreatureTemplate() const
Definition: Creature.h:598
bool HandleTitlesAddCommand(const char *args)
Definition: Level2.cpp:4091
virtual const char * GetOregonString(int32 entry) const
Definition: Chat.cpp:750
#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:1524
std::set< uint16 > ActiveEvents
Definition: GameEventMgr.h:92
bool IsTotem() const
Definition: Unit.h:1022
bool HandleLookupPlayerEmailCommand(const char *args)
Definition: Level2.cpp:3616
static bool IsValidMapCoord(uint32 mapid, float x, float y)
Definition: MapManager.h:87
Creature * ToCreature()
Definition: Object.h:389
bool HandleGoObjectCommand(const char *args)
Definition: Level2.cpp:439
virtual void UpdateObjectVisibility(bool forced=true)
Definition: Object.cpp:2588
bool HandleTargetObjectCommand(const char *args)
Definition: Level2.cpp:495
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:2087
uint8 getClass() const
Definition: Unit.h:1039
MovementGeneratorType
Definition: MotionMaster.h:33
void SwapItem(uint16 src, uint16 dst)
Definition: Player.cpp:11135
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:5432
bool HasTitle(uint32 bitIndex)
Definition: Player.cpp:20470
bool isVendor() const
Definition: Unit.h:1232
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:1921
bool HandleGameObjectCommand(const char *args)
Definition: Level2.cpp:775
uint16 mapid
Definition: Creature.h:272
static Unit * GetUnit(WorldObject const &, uint64 guid)
std::map< RepListID, FactionState > FactionStateList
Definition: ReputationMgr.h:50
void DestroyForNearbyPlayers()
Definition: Object.cpp:2554
void SetLevel(uint32 lvl)
Definition: Unit.cpp:10817
const int32 & GetInt32Value(uint16 index) const
Definition: Object.h:222
uint32 GetEntry() const
Definition: Object.h:186
WorldSession * GetSession() const
Definition: Player.h:1959
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:3829
bool HandleTempAddSpwCommand(const char *args)
Definition: Level2.cpp:3913
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:3384
void SetHealth(uint32 val)
Definition: Unit.cpp:10826
ACE_UINT16 uint16
Definition: Define.h:72
bool isInFlight() const
Definition: Unit.h:1308
ACE_UINT32 uint32
Definition: Define.h:71
bool HandleEventInfoCommand(const char *args)
Definition: Level2.cpp:3294
void Initialize()
float GetPositionX() const
Definition: Position.h:97
void MovementExpired(bool reset=true)
Definition: MotionMaster.h:158
Pet * GetPet() const
Definition: Player.cpp:17104
void removeSpell(uint16 spell_id)
Definition: Pet.cpp:1588
GameObject * GetGameObject(uint64 guid)
Definition: Map.cpp:2638
#define VISUAL_WAYPOINT
Definition: MotionMaster.h:30
void SaveToDB()
Definition: GameObject.cpp:592
despawns instantly after death
CreatureDataAddon const * GetCreatureAddon() const
Definition: Creature.cpp:2113
float pos_x
Definition: TicketMgr.h:38
CreatureFamily family
Definition: Creature.h:165
Definition: Unit.h:884
bool SetReputation(FactionEntry const *factionEntry, int32 standing)
char * extractKeyFromLink(char *text, char const *linkType, char **something1=NULL)
Definition: Chat.cpp:1645
bool HandleCreatePetCommand(const char *args)
Definition: Level2.cpp:3710
void SetRespawnDelay(uint32 delay)
Definition: Creature.h:743
uint32 getLevel() const
Definition: Unit.h:1029
std::string description
Definition: GameEventMgr.h:62
virtual bool needReportToTarget(Player *chr) const
Definition: Chat.cpp:1875
Definition: Player.h:922
#define ticketmgr
Definition: TicketMgr.h:94
bool HandleNpcDeleteCommand(const char *args)
Definition: Level2.cpp:1144
bool HandleDelObjectCommand(const char *args)
Definition: Level2.cpp:605
static bool IsSpellValid(SpellEntry const *spellInfo, Player *pl=NULL, bool msg=true)
Definition: SpellMgr.cpp:2826
bool isValid() const
Definition: GameEventMgr.h:64
bool HandleHonorAddKillCommand(const char *args)
Definition: Level2.cpp:3183
bool HandleNpcUnFollowCommand(const char *args)
Definition: Level2.cpp:1553
Definition: Pet.h:146
void UpdateHonorFields()
Definition: Player.cpp:6022
void LearnSpell(uint32 spell_id)
Definition: Player.cpp:3198
bool HandleReloadAllPaths(const char *args)
Definition: Level2.cpp:2203
virtual char const * GetName() const
Definition: Chat.cpp:1870
#define atol(a)
Definition: Common.h:162
bool LoadGameObjectFromDB(uint32 guid, Map *map, bool addToMap=true)
Definition: GameObject.cpp:660
void UpdateRotationFields(float rotation2=0.0f, float rotation3=0.0f)
bool HandleLearnAllRecipesCommand(const char *args)
Definition: Level2.cpp:3505
void Delete()
Definition: GameObject.cpp:562
DBCStorage< SkillLineAbilityEntry > sSkillLineAbilityStore(SkillLineAbilityfmt)
const uint64 & GetGUID() const
Definition: Object.h:156
bool HandleCombatStopCommand(const char *args)
Definition: Level2.cpp:3426
bool HandleNpcSetModelCommand(const char *args)
Definition: Level2.cpp:1394
char * name[16]
Definition: DBCStructure.h:634
bool Create(uint32 guidlow, Map *map, uint32 Entry, uint32 team, float x, float y, float z, float ang, const CreatureData *data=NULL)
Definition: Creature.cpp:759