2 * Copyright (C) 2005,2006 MaNGOS <http://www.mangosproject.org/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include "Database/DatabaseEnv.h"
21 #include "WorldPacket.h"
22 #include "WorldSession.h"
24 #include "ObjectMgr.h"
27 #include "GameObject.h"
30 #include "ObjectAccessor.h"
31 #include "MapManager.h"
35 bool ChatHandler::HandleTargetObjectCommand(const char* args
)
38 Player
* pl
= m_session
->GetPlayer();
43 int32 id
= atoi((char*)args
);
45 result
= sDatabase
.PQuery("SELECT `guid`, `id`, `position_x`, `position_y`, `position_z`, `orientation`, `map`, (POW(`position_x` - '%f', 2) + POW(`position_y` - '%f', 2) + POW(`position_z` - '%f', 2)) as `order` FROM `gameobject` WHERE `map` = '%i' AND `id` = '%u' ORDER BY `order` ASC LIMIT 1",
46 pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(), pl
->GetMapId(),id
);
49 std::string name
= args
;
50 sDatabase
.escape_string(name
);
51 result
= sDatabase
.PQuery(
52 "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` "
53 "FROM `gameobject`,`gameobject_template` WHERE `gameobject_template`.`entry` = `gameobject`.`id` AND `map` = %i AND `name` LIKE '%%%s%%' ORDER BY `order` ASC LIMIT 1",
54 pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(), pl
->GetMapId(),name
.c_str());
58 result
= sDatabase
.PQuery("SELECT `guid`, `id`, `position_x`, `position_y`, `position_z`, `orientation`, `map`, (POW(`position_x` - %f, 2) + POW(`position_y` - %f, 2) + POW(`position_z` - %f, 2)) as `order` FROM `gameobject` WHERE `map` = %i ORDER BY `order` ASC LIMIT 1", m_session
->GetPlayer()->GetPositionX(), m_session
->GetPlayer()->GetPositionY(), m_session
->GetPlayer()->GetPositionZ(), m_session
->GetPlayer()->GetMapId());
62 SendSysMessage("Nothing found!");
66 Field
*fields
= result
->Fetch();
67 uint32 guid
= fields
[0].GetUInt32();
68 uint32 id
= fields
[1].GetUInt32();
69 float x
= fields
[2].GetFloat();
70 float y
= fields
[3].GetFloat();
71 float z
= fields
[4].GetFloat();
72 float o
= fields
[5].GetFloat();
73 int mapid
= fields
[6].GetUInt16();
76 const GameObjectInfo
*goI
= objmgr
.GetGameObjectInfo(id
);
80 PSendSysMessage(LANG_GAMEOBJECT_NOT_EXIST
,id
);
84 PSendSysMessage("Selected object:\n%s\nGUID: %u ID: %u\nX: %f Y: %f Z: %f MapId: %u\nOrientation: %f", goI
->name
, guid
, id
, x
, y
, z
, mapid
, o
);
89 bool ChatHandler::HandleGoObjectCommand(const char* args
)
91 if(m_session
->GetPlayer()->isInFlight())
93 SendSysMessage(LANG_YOU_IN_FLIGHT
);
100 int32 guid
= atoi((char*)args
);
104 QueryResult
*result
= sDatabase
.PQuery("SELECT `position_x`,`position_y`,`position_z`,`orientation`,`map` FROM `gameobject` WHERE `guid` = '%i'",guid
);
107 SendSysMessage("Object not found!");
111 Field
*fields
= result
->Fetch();
112 float x
= fields
[0].GetFloat();
113 float y
= fields
[1].GetFloat();
114 float z
= fields
[2].GetFloat();
115 float ort
= fields
[3].GetFloat();
116 int mapid
= fields
[4].GetUInt16();
119 if(!MapManager::ExistMAP(mapid
,x
,y
))
121 PSendSysMessage("target map not exist (X: %f Y: %f MapId:%u)",x
,y
,mapid
);
125 m_session
->GetPlayer()->TeleportTo(mapid
, x
, y
, z
, ort
);
129 bool ChatHandler::HandleGoCreatureCommand(const char* args
)
131 if(m_session
->GetPlayer()->isInFlight())
133 SendSysMessage(LANG_YOU_IN_FLIGHT
);
140 int32 guid
= atoi((char*)args
);
144 QueryResult
*result
= sDatabase
.PQuery("SELECT `position_x`,`position_y`,`position_z`,`orientation`,`map` FROM `creature` WHERE `guid` = '%i'",guid
);
147 SendSysMessage("Creature not found!");
151 Field
*fields
= result
->Fetch();
152 float x
= fields
[0].GetFloat();
153 float y
= fields
[1].GetFloat();
154 float z
= fields
[2].GetFloat();
155 float ort
= fields
[3].GetFloat();
156 int mapid
= fields
[4].GetUInt16();
160 if(!MapManager::ExistMAP(mapid
,x
,y
))
162 PSendSysMessage("target map not exist (X: %f Y: %f MapId:%u)",x
,y
,mapid
);
166 m_session
->GetPlayer()->TeleportTo(mapid
, x
, y
, z
, ort
);
170 bool ChatHandler::HandleGUIDCommand(const char* args
)
172 uint64 guid
= m_session
->GetPlayer()->GetSelection();
176 SendSysMessage(LANG_NO_SELECTION
);
180 PSendSysMessage(LANG_OBJECT_GUID
, GUID_LOPART(guid
), GUID_HIPART(guid
));
184 bool ChatHandler::HandleNameCommand(const char* args
)
190 if(strlen((char*)args)>75)
192 PSendSysMessage(LANG_TOO_LONG_NAME, strlen((char*)args)-75);
196 for (uint8 i = 0; i < strlen(args); i++)
198 if(!isalpha(args[i]) && args[i]!=' ')
200 SendSysMessage(LANG_CHARS_ONLY);
206 guid = m_session->GetPlayer()->GetSelection();
209 SendSysMessage(LANG_NO_SELECTION);
213 Creature* pCreature = ObjectAccessor::Instance().GetCreature(*m_session->GetPlayer(), guid);
217 SendSysMessage(LANG_SELECT_CREATURE);
221 pCreature->SetName(args);
222 uint32 idname = objmgr.AddCreatureTemplate(pCreature->GetName());
223 pCreature->SetUInt32Value(OBJECT_FIELD_ENTRY, idname);
225 pCreature->SaveToDB();
231 bool ChatHandler::HandleSubNameCommand(const char* args
)
238 if(strlen((char*)args)>75)
241 PSendSysMessage(LANG_TOO_LONG_SUBNAME, strlen((char*)args)-75);
245 for (uint8 i = 0; i < strlen(args); i++)
247 if(!isalpha(args[i]) && args[i]!=' ')
249 SendSysMessage(LANG_CHARS_ONLY);
254 guid = m_session->GetPlayer()->GetSelection();
257 SendSysMessage(LANG_NO_SELECTION);
261 Creature* pCreature = ObjectAccessor::Instance().GetCreature(*m_session->GetPlayer(), guid);
265 SendSysMessage(LANG_SELECT_CREATURE);
269 uint32 idname = objmgr.AddCreatureSubName(pCreature->GetName(),args,pCreature->GetUInt32Value(UNIT_FIELD_DISPLAYID));
270 pCreature->SetUInt32Value(OBJECT_FIELD_ENTRY, idname);
272 pCreature->SaveToDB();
277 bool ChatHandler::HandleNYICommand(const char* args
)
279 SendSysMessage(LANG_NOT_IMPLEMENTED
);
283 bool ChatHandler::HandleProgCommand(const char* args
)
285 if(m_session
->GetPlayer()->isInFlight())
287 SendSysMessage(LANG_YOU_IN_FLIGHT
);
291 m_session
->GetPlayer()->TeleportTo(451, 16391.80f
, 16341.20f
, 69.44f
,0.0f
);
296 bool ChatHandler::HandleItemMoveCommand(const char* args
)
298 uint8 srcslot
, dstslot
;
300 char* pParam1
= strtok((char*)args
, " ");
304 char* pParam2
= strtok(NULL
, " ");
308 srcslot
= (uint8
)atoi(pParam1
);
309 dstslot
= (uint8
)atoi(pParam2
);
311 uint16 src
= ((INVENTORY_SLOT_BAG_0
<< 8) | srcslot
);
312 uint16 dst
= ((INVENTORY_SLOT_BAG_0
<< 8) | dstslot
);
314 m_session
->GetPlayer()->SwapItem( src
, dst
);
319 bool ChatHandler::HandleSpawnCommand(const char* args
)
321 char* pEntry
= strtok((char*)args
, " ");
325 char* pFlags
= strtok(NULL
, " ");
329 char* pLevel
= strtok(NULL
, " ");
333 char* pName
= strtok(NULL
, "%");
337 uint32 level
= atoi(pLevel
);
339 for (uint8 i
= 0; i
< strlen(pName
); i
++)
341 if(!isalpha(pName
[i
]) && pName
[i
]!=' ')
343 SendSysMessage(LANG_CHARS_ONLY
);
347 SpawnCreature(m_session
, pName
, level
);
352 bool ChatHandler::HandleAddSpwCommand(const char* args
)
354 char* charID
= strtok((char*)args
, " ");
358 uint32 id
= atoi(charID
);
360 Player
*chr
= m_session
->GetPlayer();
361 float x
= chr
->GetPositionX();
362 float y
= chr
->GetPositionY();
363 float z
= chr
->GetPositionZ();
364 float o
= chr
->GetOrientation();
366 Creature
* pCreature
= new Creature
;
367 if (!pCreature
->Create(objmgr
.GenerateLowGuid(HIGHGUID_UNIT
), chr
->GetMapId(), x
, y
, z
, o
, id
))
373 pCreature
->SaveToDB();
374 pCreature
->LoadFromDB(pCreature
->GetGUIDLow()); // To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells();
375 MapManager::Instance().GetMap(pCreature
->GetMapId())->Add(pCreature
);
377 sLog
.outDebug(LANG_ADD_OBJ
);
382 bool ChatHandler::HandleDeleteCommand(const char* args
)
384 Creature
*unit
= getSelectedCreature();
387 SendSysMessage(LANG_SELECT_CREATURE
);
393 unit
->DeleteFromDB();
395 ObjectAccessor::Instance().AddObjectToRemoveList(unit
);
397 SendSysMessage("Creature Removed");
402 bool ChatHandler::HandleDelObjectCommand(const char* args
)
407 uint32 lowguid
= atoi((char*)args
);
411 GameObject
* obj
= ObjectAccessor::Instance().GetGameObject(*m_session
->GetPlayer(), MAKE_GUID(lowguid
, HIGHGUID_GAMEOBJECT
));
415 PSendSysMessage("Game Object (GUID: %u) not found", lowguid
);
419 uint64 owner_guid
= obj
->GetOwnerGUID();
422 Unit
* owner
= ObjectAccessor::Instance().GetUnit(*m_session
->GetPlayer(),owner_guid
);
423 if(!owner
&& GUID_HIPART(owner_guid
)!=HIGHGUID_PLAYER
)
425 PSendSysMessage("Game Object (GUID: %u) have references in not found creature %u GO list, can't be deleted.", GUID_LOPART(owner_guid
), obj
->GetGUIDLow());
429 owner
->RemoveGameObject(obj
,false);
435 PSendSysMessage("Game Object (GUID: %u) removed", obj
->GetGUIDLow());
440 bool ChatHandler::HandleTurnObjectCommand(const char* args
)
445 char* plowguid
= strtok((char*)args
, " ");
450 uint32 lowguid
= (uint32
)atoi(plowguid
);
452 GameObject
* obj
= ObjectAccessor::Instance().GetGameObject(*m_session
->GetPlayer(), MAKE_GUID(lowguid
, HIGHGUID_GAMEOBJECT
));
456 PSendSysMessage("Game Object (GUID: %u) not found", lowguid
);
460 char* po
= strtok(NULL
, " ");
469 Player
*chr
= m_session
->GetPlayer();
470 o
= chr
->GetOrientation();
473 float rot2
= sin(o
/2);
474 float rot3
= cos(o
/2);
476 obj
->Relocate(obj
->GetPositionX(), obj
->GetPositionY(), obj
->GetPositionZ(), o
);
478 obj
->SetFloatValue(GAMEOBJECT_FACING
, o
);
479 obj
->SetFloatValue(GAMEOBJECT_ROTATION
+2, rot2
);
480 obj
->SetFloatValue(GAMEOBJECT_ROTATION
+3, rot3
);
485 PSendSysMessage("Game Object (GUID: %u) turned", obj
->GetGUIDLow(), o
);
490 bool ChatHandler::HandleMoveObjectCommand(const char* args
)
495 char* plowguid
= strtok((char*)args
, " ");
500 uint32 lowguid
= (uint32
)atoi(plowguid
);
502 GameObject
* obj
= ObjectAccessor::Instance().GetGameObject(*m_session
->GetPlayer(), MAKE_GUID(lowguid
, HIGHGUID_GAMEOBJECT
));
506 PSendSysMessage("Game Object (GUID: %u) not found", lowguid
);
510 char* px
= strtok(NULL
, " ");
511 char* py
= strtok(NULL
, " ");
512 char* pz
= strtok(NULL
, " ");
516 Player
*chr
= m_session
->GetPlayer();
518 obj
->Relocate(chr
->GetPositionX(), chr
->GetPositionY(), chr
->GetPositionZ(), obj
->GetOrientation());
520 obj
->SetFloatValue(GAMEOBJECT_POS_X
, chr
->GetPositionX());
521 obj
->SetFloatValue(GAMEOBJECT_POS_Y
, chr
->GetPositionY());
522 obj
->SetFloatValue(GAMEOBJECT_POS_Z
, chr
->GetPositionZ());
529 float x
= (float)atof(px
);
530 float y
= (float)atof(py
);
531 float z
= (float)atof(pz
);
533 if(!MapManager::ExistMAP(obj
->GetMapId(),x
,y
))
535 PSendSysMessage(".move target map not exist (X: %f Y: %f MapId:%u)",x
,y
,obj
->GetMapId());
539 obj
->Relocate(x
, y
, z
, obj
->GetOrientation());
541 obj
->SetFloatValue(GAMEOBJECT_POS_X
, x
);
542 obj
->SetFloatValue(GAMEOBJECT_POS_Y
, y
);
543 obj
->SetFloatValue(GAMEOBJECT_POS_Z
, z
);
549 PSendSysMessage("Game Object (GUID: %u) moved", obj
->GetGUIDLow());
554 bool ChatHandler::HandleDeMorphCommand(const char* args
)
556 sLog
.outError(LANG_DEMORPHED
,m_session
->GetPlayer()->GetName());
557 m_session
->GetPlayer()->DeMorph();
561 bool ChatHandler::HandleItemCommand(const char* args
)
564 char* pitem = strtok((char*)args, " ");
568 uint64 guid = m_session->GetPlayer()->GetSelection();
571 SendSysMessage(LANG_NO_SELECTION);
575 Creature* pCreature = ObjectAccessor::Instance().GetCreature(*m_session->GetPlayer(), guid);
579 SendSysMessage(LANG_SELECT_CREATURE);
583 uint32 item = atoi(pitem);
586 char* pamount = strtok(NULL, " ");
588 amount = atoi(pamount);
590 ItemPrototype* tmpItem = objmgr.GetItemPrototype(item);
594 QueryResult *result = sDatabase.PQuery("INSERT INTO `npc_vendor` (`entry`,`itemguid`,`amount`) VALUES('%u','%u','%d')",pCreature->GetEntry(), item, amount);
596 uint8 itemscount = pCreature->GetItemCount();
597 pCreature->setItemId(itemscount , item);
598 pCreature->setItemAmount(itemscount , amount);
599 pCreature->IncrItemCount();
600 PSendSysMessage(LANG_ITEM_ADDED_TO_LIST,item,tmpItem->Name1);
605 PSendSysMessage(LANG_ITEM_NOT_FOUND,item);
611 bool ChatHandler::HandleItemRemoveCommand(const char* args
)
614 char* iguid = strtok((char*)args, " ");
618 uint64 guid = m_session->GetPlayer()->GetSelection();
621 SendSysMessage(LANG_NO_SELECTION);
625 Creature *pCreature = ObjectAccessor::Instance().GetCreature(*m_session->GetPlayer(), guid);
629 SendSysMessage(LANG_SELECT_CREATURE);
633 uint32 itemguid = atoi(iguid);
634 int slot = pCreature->GetItemSlot(itemguid);
638 uint32 guidlow = GUID_LOPART(guid);
640 sDatabase.PExecute("DELETE FROM `npc_vendor` WHERE `entry` = '%u' AND `itemguid` = '%u'",pCreature->GetEntry(),itemguid);
642 pCreature->setItemId(slot , 0);
643 pCreature->setItemAmount(slot , 0);
644 ItemPrototype* tmpItem = objmgr.GetItemPrototype(itemguid);
647 PSendSysMessage(LANG_ITEM_DELETED_FROM_LIST,itemguid,tmpItem->Name1);
651 PSendSysMessage(LANG_ITEM_DELETED_FROM_LIST,itemguid,"<unknonwn>");
657 PSendSysMessage(LANG_ITEM_NOT_IN_LIST,itemguid);
663 bool ChatHandler::HandleAddMoveCommand(const char* args
)
668 char* guid_str
= strtok((char*)args
, " ");
669 char* wait_str
= strtok((char*)NULL
, " ");
671 uint32 lowguid
= atoi((char*)guid_str
);
673 Creature
* pCreature
= NULL
;
676 pCreature
= ObjectAccessor::Instance().GetCreature(*m_session
->GetPlayer(),MAKE_GUID(lowguid
,HIGHGUID_UNIT
));
680 PSendSysMessage("Creature (GUID: %u) not found", lowguid
);
684 int wait
= wait_str
? atoi(wait_str
) : 0;
691 QueryResult
*result
= sDatabase
.PQuery( "SELECT MAX(`point`) FROM `creature_movement` WHERE `id` = '%u'",pCreature
->GetGUIDLow());
694 point
= (*result
)[0].GetUInt32()+1;
701 Player
* player
= m_session
->GetPlayer();
703 sDatabase
.PExecute("INSERT INTO `creature_movement` (`id`,`point`,`position_x`,`position_y`,`position_z`,`waittime`) VALUES ('%u','%u','%f', '%f', '%f','%u')",
704 pCreature
->GetGUIDLow(), point
, player
->GetPositionX(), player
->GetPositionY(), player
->GetPositionZ(), wait
);
706 // update movement type
707 if(pCreature
->GetDefaultMovementType()!=WAYPOINT_MOTION_TYPE
)
709 pCreature
->SetDefaultMovementType(WAYPOINT_MOTION_TYPE
);
710 sDatabase
.PExecute("UPDATE `creature` SET `MovementType` = '%u' WHERE `guid` = '%u'", pCreature
->GetDefaultMovementType(),pCreature
->GetGUIDLow());
713 SendSysMessage(LANG_WAYPOINT_ADDED
);
718 bool ChatHandler::HandleRandomCommand(const char* args
)
723 int option
= atoi((char*)args
);
725 if (option
!= 0 && option
!= 1)
727 //m_session->GetPlayer( )->SendMessageToSet( &data, true );
728 SendSysMessage(LANG_USE_BOL
);
732 Creature
* pCreature
= getSelectedCreature();
736 SendSysMessage(LANG_SELECT_CREATURE
);
740 // fix me : 'moverandom' doesn't exist in https://svn.mangosproject.org/trac/MaNGOS/wiki/Database/creature ?
741 // perhaps it should be 'state'?
742 sDatabase
.PExecute("UPDATE `creature` SET `moverandom` = '%i' WHERE `guid` = '%u'", option
, pCreature
->GetGUIDLow());
744 pCreature
->setMoveRandomFlag(option
> 0);
746 SendSysMessage(LANG_VALUE_SAVED
);
751 bool ChatHandler::HandleRunCommand(const char* args
)
756 int option
= atoi((char*)args
);
758 if(option
!= 0 && option
!= 1)
760 SendSysMessage(LANG_USE_BOL
);
764 Creature
* pCreature
= getSelectedCreature();
768 SendSysMessage(LANG_SELECT_CREATURE
);
772 // fix me : 'running' doesn't exist in https://svn.mangosproject.org/trac/MaNGOS/wiki/Database/creatures ?
773 // perhaps it should be 'state'?
774 sDatabase
.PExecute("UPDATE `creature` SET `running` = '%i' WHERE `guid` = '%u'", option
, pCreature
->GetGUIDLow());
776 pCreature
->setMoveRunFlag(option
> 0);
778 SendSysMessage(LANG_VALUE_SAVED
);
782 bool ChatHandler::HandleChangeLevelCommand(const char* args
)
787 uint8 lvl
= (uint8
) atoi((char*)args
);
788 if ( lvl
< 1 || lvl
> sWorld
.getConfig(CONFIG_MAX_PLAYER_LEVEL
) + 3)
790 SendSysMessage(LANG_BAD_VALUE
);
794 Creature
* pCreature
= getSelectedCreature();
797 SendSysMessage(LANG_SELECT_CREATURE
);
801 pCreature
->SetHealth( 100 + 30*lvl
);
802 pCreature
->SetMaxHealth( 100 + 30*lvl
);
803 pCreature
->SetLevel( lvl
);
805 pCreature
->SaveToDB();
810 bool ChatHandler::HandleNPCFlagCommand(const char* args
)
815 uint32 npcFlags
= (uint32
) atoi((char*)args
);
817 Creature
* pCreature
= getSelectedCreature();
821 SendSysMessage(LANG_SELECT_CREATURE
);
825 pCreature
->SetUInt32Value(UNIT_NPC_FLAGS
, npcFlags
);
827 sDatabase
.PExecute("UPDATE `creature_template` SET `npcflag` = '%u' WHERE `entry` = '%u'", npcFlags
, pCreature
->GetEntry());
829 SendSysMessage(LANG_VALUE_SAVED_REJOIN
);
831 uint32 entry
= pCreature
->GetUInt32Value( OBJECT_FIELD_ENTRY
);
832 m_session
->SendCreatureQuery( entry
, pCreature
->GetGUID() );
837 bool ChatHandler::HandleDisplayIdCommand(const char* args
)
842 uint32 displayId
= (uint32
) atoi((char*)args
);
844 Creature
*pCreature
= getSelectedCreature();
848 SendSysMessage(LANG_SELECT_CREATURE
);
852 pCreature
->SetUInt32Value(UNIT_FIELD_DISPLAYID
, displayId
);
854 pCreature
->SaveToDB();
859 bool ChatHandler::HandleFactionIdCommand(const char* args
)
864 uint32 factionId
= (uint32
) atoi((char*)args
);
866 Creature
* pCreature
= getSelectedCreature();
870 SendSysMessage(LANG_SELECT_CREATURE
);
874 pCreature
->setFaction(factionId
);
876 pCreature
->SaveToDB();
881 bool ChatHandler::HandleKickPlayerCommand(const char *args
)
883 char* kickName
= strtok((char*)args
, " ");
886 Player
* player
= getSelectedPlayer();
887 if(player
==m_session
->GetPlayer())
889 SendSysMessage("You can't kick self by selecting, use .kick name ;)");
893 player
->GetSession()->KickPlayer();
897 std::string name
= kickName
;
898 normalizePlayerName(name
);
899 if(sWorld
.KickPlayer(name
))
900 PSendSysMessage("Player %s kicked.",name
.c_str());
902 PSendSysMessage("Player %s not found.",name
.c_str());
908 bool ChatHandler::HandlePInfoCommand(const char* args
)
910 Player
* target
= NULL
;
912 char* px
= strtok((char*)args
, " ");
915 std::string name
= px
;
916 normalizePlayerName(name
);
917 target
= objmgr
.GetPlayer(name
.c_str());
920 target
= getSelectedPlayer();
924 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
928 std::string username
= "<error>";
929 std::string last_ip
= "<error>";
931 QueryResult
* result
= loginDatabase
.PQuery("SELECT `username`, `last_ip` FROM `account` WHERE `id` = '%u'",target
->GetSession()->GetAccountId());
934 Field
* fields
= result
->Fetch();
935 username
= fields
[0].GetCppString();
936 if(m_session
->GetSecurity() >= target
->GetSession()->GetSecurity())
937 last_ip
= fields
[1].GetCppString();
944 PSendSysMessage(LANG_PINFO_ACCOUNT
, target
->GetName(), target
->GetGUIDLow(), username
.c_str(), target
->GetSession()->GetAccountId(), target
->GetSession()->GetSecurity(), last_ip
.c_str());
946 uint32 days
= target
->GetTotalPlayedTime() / (60*60*24);
947 uint32 hours
= (target
->GetTotalPlayedTime() % (60*60*24)) / (60*60);
948 uint32 gold
= target
->GetMoney() /(100*100);
949 uint32 silv
= (target
->GetMoney() % (100*100)) / 100;
950 uint32 copp
= (target
->GetMoney() % (100*100)) % 100;
951 PSendSysMessage(LANG_PINFO_LEVEL
, days
, hours
, target
->getLevel(), gold
,silv
,copp
);
956 void ChatHandler::ShowTicket(uint64 guid
, uint32 category
, char const* text
)
959 objmgr
.GetPlayerNameByGUID(guid
,name
);
961 if(name
=="") name
= " <unknown> ";
963 PSendSysMessage("Ticket of %s (Category: %i):\n%s\n", name
.c_str(),category
,text
);
966 bool ChatHandler::HandleTicketCommand(const char* args
)
968 char* px
= strtok((char*)args
, " ");
973 QueryResult
*result
= sDatabase
.Query("SELECT `ticket_id` FROM `character_ticket`");
974 size_t count
= result
? result
->GetRowCount() : 0;
976 PSendSysMessage("Tickets count: %i show new tickets: %s\n", count
,m_session
->GetPlayer()->isAcceptTickets() ? "on" : "off");
982 if(strncmp(px
,"on",3) == 0)
984 m_session
->GetPlayer()->SetAcceptTicket(true);
985 SendSysMessage("New ticket show: on");
990 if(strncmp(px
,"off",4) == 0)
992 m_session
->GetPlayer()->SetAcceptTicket(false);
993 SendSysMessage("New ticket show: off");
1001 QueryResult
*result
= sDatabase
.Query("SELECT `guid`,`ticket_category`,`ticket_text` FROM `character_ticket`");
1003 if(!result
|| uint64(num
) > result
->GetRowCount())
1005 PSendSysMessage("Ticket %i doesn't exist", num
);
1010 for(int i
= 1; i
< num
; ++i
)
1013 Field
* fields
= result
->Fetch();
1015 uint64 guid
= fields
[0].GetUInt64();
1016 uint32 category
= fields
[1].GetUInt32();
1017 char const* text
= fields
[2].GetString();
1019 ShowTicket(guid
,category
,text
);
1024 std::string name
= px
;
1025 normalizePlayerName(name
);
1026 sDatabase
.escape_string(name
); // prevent SQL injection - normal name don't must changed by this call
1028 uint64 guid
= objmgr
.GetPlayerGUIDByName(name
.c_str());
1033 // ticket $char_name
1034 QueryResult
*result
= sDatabase
.PQuery("SELECT `guid`,`ticket_category`,`ticket_text` FROM `character_ticket` WHERE `guid` = '%u'",GUID_LOPART(guid
));
1039 Field
* fields
= result
->Fetch();
1041 uint32 category
= fields
[1].GetUInt32();
1042 char const* text
= fields
[2].GetString();
1044 ShowTicket(guid
,category
,text
);
1050 uint32
ChatHandler::GetTicketIDByNum(uint32 num
)
1052 QueryResult
*result
= sDatabase
.Query("SELECT `ticket_id` FROM `character_ticket`");
1054 if(!result
|| num
> result
->GetRowCount())
1056 PSendSysMessage("Ticket %i doesn't exist", num
);
1061 for(uint32 i
= 1; i
< num
; ++i
)
1064 Field
* fields
= result
->Fetch();
1066 uint32 id
= fields
[0].GetUInt32();
1071 bool ChatHandler::HandleDelTicketCommand(const char *args
)
1073 char* px
= strtok((char*)args
, " ");
1078 if(strncmp(px
,"all",4) == 0)
1080 QueryResult
*result
= sDatabase
.Query("SELECT `guid` FROM `character_ticket`");
1085 // notify players about ticket deleting
1088 Field
* fields
= result
->Fetch();
1090 uint64 guid
= fields
[0].GetUInt64();
1092 if(Player
* sender
= objmgr
.GetPlayer(guid
))
1093 sender
->GetSession()->SendGMTicketGetTicket(1,0);
1095 }while(result
->NextRow());
1099 sDatabase
.PExecute("DELETE FROM `character_ticket`");
1100 SendSysMessage("All tickets deleted.");
1104 int num
= (uint32
)atoi(px
);
1109 QueryResult
*result
= sDatabase
.PQuery("SELECT `ticket_id`,`guid` FROM `character_ticket` LIMIT '%i'",num
);
1111 if(!result
|| uint64(num
) > result
->GetRowCount())
1113 PSendSysMessage("Ticket %i doesn't exist", num
);
1118 for(int i
= 1; i
< num
; ++i
)
1121 Field
* fields
= result
->Fetch();
1123 uint32 id
= fields
[0].GetUInt32();
1124 uint64 guid
= fields
[1].GetUInt64();
1127 sDatabase
.PExecute("DELETE FROM `character_ticket` WHERE `ticket_id` = '%u'", id
);
1129 // notify players about ticket deleting
1130 if(Player
* sender
= objmgr
.GetPlayer(guid
))
1132 sender
->GetSession()->SendGMTicketGetTicket(1,0);
1133 PSendSysMessage("Character %s ticket deleted.",sender
->GetName());
1136 SendSysMessage("Ticket deleted.");
1141 std::string name
= px
;
1142 normalizePlayerName(name
);
1143 sDatabase
.escape_string(name
); // prevent SQL injection - normal name don't must changed by this call
1145 uint64 guid
= objmgr
.GetPlayerGUIDByName(name
.c_str());
1150 // delticket $char_name
1151 sDatabase
.PExecute("DELETE FROM `character_ticket` WHERE `guid` = '%u'",GUID_LOPART(guid
));
1153 // notify players about ticket deleting
1154 if(Player
* sender
= objmgr
.GetPlayer(guid
))
1155 sender
->GetSession()->SendGMTicketGetTicket(1,0);
1157 PSendSysMessage("Character %s ticket deleted.",px
);