2 * Copyright (C) 2005,2006,2007 MaNGOS <http://www.mangosproject.org/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include "Database/DatabaseEnv.h"
21 #include "WorldPacket.h"
22 #include "WorldSession.h"
24 #include "ObjectMgr.h"
27 #include "GameObject.h"
31 #include "ObjectAccessor.h"
32 #include "MapManager.h"
33 #include "SpellAuras.h"
34 #include "ScriptCalls.h"
36 #include "RedZoneDistrict.h"
37 #include "GridNotifiersImpl.h"
41 bool ChatHandler::HandleReloadCommand(const char* args
)
43 char* updatefield
= strtok((char*)args
, " ");
45 char* value
= strtok(NULL
, " ");
47 if (!updatefield
|| !value
)
50 uint32 tupdatefield
= (uint32
)atoi(updatefield
);
51 uint32 tvalue
= (uint32
)atoi(value
);
53 Player
*chr
= m_session
->GetPlayer();
56 SendSysMessage(LANG_NO_CHAR_SELECTED
);
59 chr
->SetUInt32Value(tupdatefield
, tvalue
);
63 bool ChatHandler::HandleLoadScriptsCommand(const char* args
)
65 if(!LoadScriptingModule(args
)) return true;
67 sWorld
.SendWorldText(LANG_SCRIPTS_RELOADED
, NULL
);
72 /** \brief GM command level 3 - Create a guild.
74 * This command allows a GM (level 3) to create a guild.
76 * The "args" parameter contains the name of the guild leader
77 * and then the name of the guild.
80 bool ChatHandler::HandleSecurityCommand(const char* args
)
82 char* pName
= strtok((char*)args
, " ");
86 char* pgm
= strtok(NULL
, " ");
90 int8 gm
= (uint8
) atoi(pgm
);
91 if ( gm
< 0 || gm
> 3)
93 SendSysMessage(LANG_BAD_VALUE
);
97 std::string name
= pName
;
99 normalizePlayerName(name
);
100 sDatabase
.escape_string(name
);
101 QueryResult
*result
= sDatabase
.PQuery("SELECT `account` FROM `character` WHERE `name` = '%s'", name
.c_str());
105 PSendSysMessage(LANG_NO_PLAYER
, pName
);
109 uint32 acc_id
= (*result
)[0].GetUInt32();
113 Player
* chr
= ObjectAccessor::Instance().FindPlayerByName(name
.c_str());
119 sprintf((char*)buf
,LANG_YOURS_SECURITY_CHANGED
, m_session
->GetPlayer()->GetName(), gm
);
120 FillSystemMessageData(&data
, m_session
, buf
);
121 chr
->GetSession()->SendPacket(&data
);
122 chr
->GetSession()->SetSecurity(gm
);
125 PSendSysMessage(LANG_YOU_CHANGE_SECURITY
, name
.c_str(), gm
);
126 loginDatabase
.PExecute("UPDATE `account` SET `gmlevel` = '%i' WHERE `id` = '%u'", gm
, acc_id
);
131 bool ChatHandler::HandleGoXYCommand(const char* args
)
133 Player
* _player
= m_session
->GetPlayer();
135 if(_player
->isInFlight())
137 SendSysMessage(LANG_YOU_IN_FLIGHT
);
141 char* px
= strtok((char*)args
, " ");
142 char* py
= strtok(NULL
, " ");
143 char* pmapid
= strtok(NULL
, " ");
148 float x
= (float)atof(px
);
149 float y
= (float)atof(py
);
152 mapid
= (uint32
)atoi(pmapid
);
153 else mapid
= _player
->GetMapId();
155 if(!MapManager::IsValidMapCoord(mapid
,x
,y
))
157 PSendSysMessage(LANG_INVALID_TARGET_COORD
,x
,y
,mapid
);
161 Map
*map
= MapManager::Instance().GetMap(mapid
, _player
);
162 float z
= max(map
->GetHeight(x
, y
, 0), map
->GetWaterLevel(x
, y
));
163 _player
->SetRecallPosition(_player
->GetMapId(),_player
->GetPositionX(),_player
->GetPositionY(),_player
->GetPositionZ(),_player
->GetOrientation());
164 _player
->TeleportTo(mapid
, x
, y
, z
, _player
->GetOrientation());
169 bool ChatHandler::HandleWorldPortCommand(const char* args
)
171 Player
* _player
= m_session
->GetPlayer();
173 if(_player
->isInFlight())
175 SendSysMessage(LANG_YOU_IN_FLIGHT
);
179 char* pContinent
= strtok((char*)args
, " ");
183 char* px
= strtok(NULL
, " ");
184 char* py
= strtok(NULL
, " ");
185 char* pz
= strtok(NULL
, " ");
187 if (!px
|| !py
|| !pz
)
193 uint32 mapid
= atoi(pContinent
);
195 if(!MapManager::IsValidMapCoord(mapid
,x
,y
))
197 PSendSysMessage(LANG_INVALID_TARGET_COORD
,x
,y
,mapid
);
201 _player
->SetRecallPosition(_player
->GetMapId(),_player
->GetPositionX(),_player
->GetPositionY(),_player
->GetPositionZ(),_player
->GetOrientation());
203 _player
->TeleportTo(mapid
, x
, y
, z
,_player
->GetOrientation());
208 bool ChatHandler::HandleAllowMovementCommand(const char* args
)
210 if(sWorld
.getAllowMovement())
212 sWorld
.SetAllowMovement(false);
213 SendSysMessage(LANG_CREATURE_MOVE_DISABLED
);
217 sWorld
.SetAllowMovement(true);
218 SendSysMessage(LANG_CREATURE_MOVE_ENABLED
);
223 bool ChatHandler::HandleGoCommand(const char* args
)
225 Player
* _player
= m_session
->GetPlayer();
227 if(_player
->isInFlight())
229 SendSysMessage(LANG_YOU_IN_FLIGHT
);
233 char* px
= strtok((char*)args
, " ");
234 char* py
= strtok(NULL
, " ");
235 char* pz
= strtok(NULL
, " ");
236 char* pmapid
= strtok(NULL
, " ");
238 if (!px
|| !py
|| !pz
|| !pmapid
)
241 float x
= (float)atof(px
);
242 float y
= (float)atof(py
);
243 float z
= (float)atof(pz
);
244 uint32 mapid
= (uint32
)atoi(pmapid
);
246 if(!MapManager::IsValidMapCoord(mapid
,x
,y
))
248 PSendSysMessage(LANG_INVALID_TARGET_COORD
,x
,y
,mapid
);
252 _player
->SetRecallPosition(_player
->GetMapId(),_player
->GetPositionX(),_player
->GetPositionY(),_player
->GetPositionZ(),_player
->GetOrientation());
254 _player
->TeleportTo(mapid
, x
, y
, z
,_player
->GetOrientation());
259 bool ChatHandler::HandleMaxSkillCommand(const char* args
)
261 Player
* SelectedPlayer
= getSelectedPlayer();
264 SendSysMessage(LANG_NO_CHAR_SELECTED
);
268 // each skills that have max skill value dependent from level seted to current level max skill value
269 SelectedPlayer
->UpdateSkillsToMaxSkillsForLevel();
273 bool ChatHandler::HandleSetSkillCommand(const char* args
)
275 // number or [name] Shift-click form |color|Hskill:skill_id|h[name]|h|r
276 char* skill_p
= extractKeyFromLink((char*)args
,"Hskill");
280 char *level_p
= strtok (NULL
, " ");
285 char *max_p
= strtok (NULL
, " ");
287 int32 skill
= atoi(skill_p
);
291 PSendSysMessage(LANG_INVALID_SKILL_ID
, skill
);
295 int32 level
= atol (level_p
);
297 Player
* target
= getSelectedPlayer();
300 PSendSysMessage(LANG_NO_CHAR_SELECTED
);
304 SkillLineEntry
const* sl
= sSkillLineStore
.LookupEntry(skill
);
307 PSendSysMessage(LANG_INVALID_SKILL_ID
, skill
);
311 if(!target
->GetSkillValue(skill
))
313 PSendSysMessage(LANG_SET_SKILL_ERROR
, target
->GetName(), skill
, sl
->name
[0]);
317 int32 max
= max_p
? atol (max_p
) : target
->GetMaxSkillValue(skill
);
319 if( level
<= 0 || level
> max
|| max
<= 0 )
322 target
->SetSkill(skill
, level
, max
);
323 PSendSysMessage(LANG_SET_SKILL
, skill
, sl
->name
[0], target
->GetName(), level
, max
);
328 const char *gmSpellList
[] =
711 //"9036", problems with ghost state
720 //"6718", phasing stealth, annoing for learn all case.
933 bool ChatHandler::HandleLearnCommand(const char* args
)
935 uint16 maxconfskill
= sWorld
.GetConfigMaxSkillValue();
940 if (!strcmp(args
, "all"))
944 PSendSysMessage(LANG_LEARNING_GM_SKILLS
, m_session
->GetPlayer()->GetName());
946 while (strcmp(gmSpellList
[loop
], "0"))
948 uint32 spell
= atol((char*)gmSpellList
[loop
]);
950 if (m_session
->GetPlayer()->HasSpell(spell
))
955 m_session
->GetPlayer()->learnSpell((uint16
)spell
);
963 if (!strcmp(args
, "all_myclass"))
965 PSendSysMessage(LANG_COMMAND_LEARNINGSPSK
, m_session
->GetPlayer()->GetName());
968 switch(m_session
->GetPlayer()->getClass())
970 case CLASS_WARRIOR
: family
= SPELLFAMILY_WARRIOR
; break;
971 case CLASS_PALADIN
: family
= SPELLFAMILY_PALADIN
; break;
972 case CLASS_HUNTER
: family
= SPELLFAMILY_HUNTER
; break;
973 case CLASS_ROGUE
: family
= SPELLFAMILY_ROGUE
; break;
974 case CLASS_PRIEST
: family
= SPELLFAMILY_PRIEST
; break;
975 case CLASS_SHAMAN
: family
= SPELLFAMILY_SHAMAN
; break;
976 case CLASS_MAGE
: family
= SPELLFAMILY_MAGE
; break;
977 case CLASS_WARLOCK
: family
= SPELLFAMILY_WARLOCK
; break;
978 case CLASS_DRUID
: family
= SPELLFAMILY_DRUID
; break;
979 default: return true;
982 for (uint32 i
= 0; i
< sSpellStore
.GetNumRows(); i
++)
984 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(i
);
985 SkillLineAbilityEntry
const *skillLine
= sSkillLineAbilityStore
.LookupEntry(i
);
986 if (skillLine
&& spellInfo
&& spellInfo
->SpellFamilyName
== family
&& !m_session
->GetPlayer()->HasSpell(i
))
987 m_session
->GetPlayer()->learnSpell((uint16
)i
);
993 if (!strcmp(args
, "all_lang"))
995 PSendSysMessage(LANG_COMMAND_LEARNINGALLLANG
, m_session
->GetPlayer()->GetName());
997 // skipping UNIVERSAL language (0)
998 for(int i
= 1; i
< LANGUAGES_COUNT
; ++i
)
999 m_session
->GetPlayer()->learnSpell(lang_description
[i
].spell_id
);
1003 Player
* target
= getSelectedPlayer();
1006 PSendSysMessage(LANG_NO_CHAR_SELECTED
);
1010 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
1011 char* cId
= extractKeyFromLink((char*)args
,"Hspell");
1015 uint32 spell
= atol(cId
);
1017 if (target
->HasSpell(spell
))
1019 SendSysMessage(LANG_KNOWN_SPELL
);
1023 target
->learnSpell((uint16
)spell
);
1028 bool ChatHandler::HandleCooldownCommand(const char* args
)
1030 Player
* target
= getSelectedPlayer();
1033 PSendSysMessage(LANG_PLAYER_NOT_FOUND
);
1039 target
->RemoveAllSpellCooldown();
1040 PSendSysMessage(LANG_REMOVEALL_COOLDOWN
, target
->GetName());
1044 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
1045 char* cId
= extractKeyFromLink((char*)args
,"Hspell");
1049 uint32 spell_id
= atol(cId
);
1051 if(!sSpellStore
.LookupEntry(spell_id
))
1053 PSendSysMessage(LANG_UNKNOWN_SPELL
, target
==m_session
->GetPlayer() ? LANG_YOU
: target
->GetName());
1057 WorldPacket
data( SMSG_CLEAR_COOLDOWN
, (4+8+4) );
1058 data
<< uint32( spell_id
);
1059 data
<< target
->GetGUID();
1061 target
->GetSession()->SendPacket(&data
);
1062 target
->RemoveSpellCooldown(spell_id
);
1063 PSendSysMessage(LANG_REMOVE_COOLDOWN
, spell_id
, target
==m_session
->GetPlayer() ? LANG_YOU
: target
->GetName());
1068 bool ChatHandler::HandleUnLearnCommand(const char* args
)
1076 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
1077 char* startS
= extractKeyFromLink((char*)args
,"Hspell");
1078 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
1079 char* endS
= extractKeyFromLink(NULL
,"Hspell");
1083 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
1084 minS
= (uint32
)atol(startS
);
1089 minS
= (uint32
)atol(startS
);
1090 maxS
= (uint32
)atol(endS
);
1097 std::swap(minS
,maxS
);
1102 Player
* target
= getSelectedPlayer();
1105 PSendSysMessage(LANG_NO_CHAR_SELECTED
);
1109 for(uint32 spell
=minS
;spell
<maxS
;spell
++)
1111 if (target
->HasSpell(spell
))
1112 target
->removeSpell(spell
);
1114 SendSysMessage(LANG_FORGET_SPELL
);
1120 bool ChatHandler::HandleAddItemCommand(const char* args
)
1127 if(args
[0]=='[') // [name] manual form
1129 char* citemName
= citemName
= strtok((char*)args
, "]");
1131 if(citemName
&& citemName
[0])
1133 std::string itemName
= citemName
+1;
1134 sDatabase
.escape_string(itemName
);
1135 QueryResult
*result
= sDatabase
.PQuery("SELECT entry FROM item_template WHERE name = '%s'", itemName
.c_str());
1138 PSendSysMessage(LANG_COMMAND_ADDITEMCOULDNOTFIND
, citemName
+1);
1141 itemId
= result
->Fetch()->GetUInt16();
1147 else if(args
[0]=='|') // [name] Shift-click form |color|Hitem:item_id:0:0:0|h[name]|h|r
1149 strtok((char*)args
, ":");
1150 char* citemId
= strtok(NULL
, ":");
1151 itemId
= atol(citemId
);
1155 else // item_id form
1157 char* citemId
= strtok((char*)args
, " ");
1158 itemId
= atol(citemId
);
1161 char* ccount
= strtok(NULL
, " ");
1165 if (ccount
) { count
= atol(ccount
); }
1166 if (count
< 1) { count
= 1; }
1168 Player
* pl
= m_session
->GetPlayer();
1169 Player
* plTarget
= getSelectedPlayer();
1173 sLog
.outDetail(LANG_ADDITEM
, itemId
, count
);
1175 ItemPrototype
const *pProto
= objmgr
.GetItemPrototype(itemId
);
1178 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, itemId
);
1182 uint32 countForStore
= count
;
1184 // item used in local operations and in add item notifier
1187 // if possible create full stacks for better performance
1188 while(countForStore
>= pProto
->Stackable
)
1191 uint8 msg
= plTarget
->CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, itemId
, pProto
->Stackable
, false );
1192 if( msg
== EQUIP_ERR_OK
)
1194 item
= plTarget
->StoreNewItem( dest
, itemId
, pProto
->Stackable
, true, Item::GenerateItemRandomPropertyId(itemId
));
1196 countForStore
-= pProto
->Stackable
;
1198 // remove binding (let GM give it to another player later)
1201 // remove binding from original stack
1202 Item
* item1
= pl
->GetItemByPos(dest
);
1204 item1
->SetBinding( false );
1206 item
->SetBinding( false );
1213 // create remaining items
1214 if(countForStore
> 0 && countForStore
< pProto
->Stackable
)
1217 uint8 msg
= plTarget
->CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, itemId
, countForStore
, false );
1219 // if can add all countForStore items
1220 if( msg
== EQUIP_ERR_OK
)
1222 item
= plTarget
->StoreNewItem( dest
, itemId
, countForStore
, true, Item::GenerateItemRandomPropertyId(itemId
));
1225 // remove binding (let GM give it to another player later)
1228 // remove binding from original stack
1229 Item
* item1
= pl
->GetItemByPos(dest
);
1231 item1
->SetBinding( false );
1233 item
->SetBinding( false );
1238 // ok search place for add only part from countForStore items in not full stacks
1239 while(countForStore
> 0)
1241 // find not full stack (last possable place for times after prev. checks)
1243 uint8 msg
= plTarget
->CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, itemId
, 1, false );
1244 if( msg
== EQUIP_ERR_OK
) // found
1246 // we can fill this stack to max stack size
1247 Item
* itemStack
= pl
->GetItemByPos(dest
);
1250 uint32 countForStack
= pProto
->Stackable
- itemStack
->GetCount();
1251 // recheck with real item amount
1252 uint8 msg
= plTarget
->CanStoreNewItem( itemStack
->GetBagSlot(), itemStack
->GetSlot(), dest
, itemId
, countForStack
, false );
1253 if( msg
== EQUIP_ERR_OK
)
1255 item
= plTarget
->StoreNewItem( dest
, itemId
, countForStack
, true, Item::GenerateItemRandomPropertyId(itemId
));
1256 countForStore
-= countForStack
;
1258 // remove binding (let GM give it to another player later)
1260 item
->SetBinding( false );
1263 break; // not possible with correct work
1266 break; // not possible with correct work
1272 if(count
> countForStore
&& item
)
1274 pl
->SendNewItem(item
,count
- countForStore
,false,true);
1276 plTarget
->SendNewItem(item
,count
- countForStore
,true,false);
1279 if(countForStore
> 0)
1280 PSendSysMessage(LANG_ITEM_CANNOT_CREATE
, itemId
, countForStore
);
1285 bool ChatHandler::HandleAddItemSetCommand(const char* args
)
1290 char* cId
= extractKeyFromLink((char*)args
,"Hitemset"); // number or [name] Shift-click form |color|Hitemset:itemset_id|h[name]|h|r
1294 uint32 itemsetId
= atol(cId
);
1296 // prevent generation all items with itemset field value '0'
1299 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND
,itemsetId
);
1303 Player
* pl
= m_session
->GetPlayer();
1304 Player
* plTarget
= getSelectedPlayer();
1308 sLog
.outDetail(LANG_ADDITEMSET
, itemsetId
);
1310 QueryResult
*result
= sDatabase
.PQuery("SELECT `entry` FROM `item_template` WHERE `itemset` = %u",itemsetId
);
1314 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND
,itemsetId
);
1321 Field
*fields
= result
->Fetch();
1322 uint32 itemId
= fields
[0].GetUInt32();
1326 uint8 msg
= plTarget
->CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, itemId
, 1, false );
1327 if( msg
== EQUIP_ERR_OK
)
1329 Item
* item
= plTarget
->StoreNewItem( dest
, itemId
, 1, true);
1331 // remove binding (let GM give it to another player later)
1333 item
->SetBinding( false );
1335 pl
->SendNewItem(item
,1,false,true);
1337 plTarget
->SendNewItem(item
,1,true,false);
1341 pl
->SendEquipError( msg
, NULL
, NULL
);
1342 PSendSysMessage(LANG_ITEM_CANNOT_CREATE
, itemId
, 1);
1345 }while( result
->NextRow() );
1352 bool ChatHandler::HandleListItemCommand(const char* args
)
1357 char* c_item_id
= strtok((char*)args
, " ");
1358 uint32 item_id
= atol(c_item_id
);
1360 if(!item_id
|| !objmgr
.GetItemPrototype(item_id
))
1362 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, item_id
);
1366 char* c_count
= strtok(NULL
, " ");
1367 int count
= c_count
? atol(c_count
) : 10;
1372 QueryResult
*result
;
1375 uint32 inv_count
= 0;
1376 result
=sDatabase
.PQuery("SELECT COUNT(`item_template`) FROM `character_inventory` WHERE `item_template`='%u'",item_id
);
1379 inv_count
= (*result
)[0].GetUInt32();
1383 result
=sDatabase
.PQuery(
1385 "SELECT `ci`.`item`,`cibag`.`slot` AS `bag`,`ci`.`slot`,`ci`.`guid`,`character`.`account`,`character`.`name` "
1386 "FROM `character_inventory` AS `ci` LEFT JOIN `character_inventory` AS `cibag` ON (`cibag`.`item`=`ci`.`bag`),`character` "
1387 "WHERE `ci`.`item_template`='%u' AND `ci`.`guid` = `character`.`guid` LIMIT %u ",
1388 item_id
,uint32(count
));
1394 Field
*fields
= result
->Fetch();
1395 uint32 item_guid
= fields
[0].GetUInt32();
1396 uint32 item_bag
= fields
[1].GetUInt32();
1397 uint32 item_slot
= fields
[2].GetUInt32();
1398 uint32 owner_guid
= fields
[3].GetUInt32();
1399 uint32 owner_acc
= fields
[4].GetUInt32();
1400 std::string owner_name
= fields
[5].GetCppString();
1402 char const* item_pos
= 0;
1403 if(Player::IsEquipmentPos(item_bag
,item_slot
))
1404 item_pos
= "[equipped]";
1405 else if(Player::IsInventoryPos(item_bag
,item_slot
))
1406 item_pos
= "[in inventory]";
1407 else if(Player::IsBankPos(item_bag
,item_slot
))
1408 item_pos
= "[in bank]";
1412 PSendSysMessage(LANG_ITEMLIST_SLOT
,
1413 item_guid
,owner_name
.c_str(),owner_guid
,owner_acc
,item_pos
);
1414 } while (result
->NextRow());
1416 uint64 res_count
= result
->GetRowCount();
1420 if(count
> res_count
)
1427 uint32 mail_count
= 0;
1428 result
=sDatabase
.PQuery("SELECT COUNT(`item_template`) FROM `mail` WHERE `item_template`='%u'",item_id
);
1431 mail_count
= (*result
)[0].GetUInt32();
1437 result
=sDatabase
.PQuery(
1439 "SELECT `mail`.`item_guid`,`mail`.`sender`,`mail`.`receiver`,`char_s`.`account`,`char_s`.`name`,`char_r`.`account`,`char_r`.`name` "
1440 "FROM `mail`,`character` as `char_s`,`character` as `char_r` "
1441 "WHERE `mail`.`item_template`='%u' AND `char_s`.`guid` = `mail`.`sender` AND `char_r`.`guid` = `mail`.`receiver` LIMIT %u",
1442 item_id
,uint32(count
));
1451 Field
*fields
= result
->Fetch();
1452 uint32 item_guid
= fields
[0].GetUInt32();
1453 uint32 item_s
= fields
[1].GetUInt32();
1454 uint32 item_r
= fields
[2].GetUInt32();
1455 uint32 item_s_acc
= fields
[3].GetUInt32();
1456 std::string item_s_name
= fields
[4].GetCppString();
1457 uint32 item_r_acc
= fields
[5].GetUInt32();
1458 std::string item_r_name
= fields
[6].GetCppString();
1460 char const* item_pos
= "[in mail]";
1462 PSendSysMessage(LANG_ITEMLIST_MAIL
,
1463 item_guid
,item_s_name
.c_str(),item_s
,item_s_acc
,item_r_name
.c_str(),item_r
,item_r_acc
,item_pos
);
1464 } while (result
->NextRow());
1466 uint64 res_count
= result
->GetRowCount();
1470 if(count
> res_count
)
1477 uint32 auc_count
= 0;
1478 result
=sDatabase
.PQuery("SELECT COUNT(`item_template`) FROM `auctionhouse` WHERE `item_template`='%u'",item_id
);
1481 auc_count
= (*result
)[0].GetUInt32();
1487 result
=sDatabase
.PQuery(
1489 "SELECT `auctionhouse`.`itemguid`,`auctionhouse`.`itemowner`,`character`.`account`,`character`.`name` "
1490 "FROM `auctionhouse`,`character` WHERE `auctionhouse`.`item_template`='%u' AND `character`.`guid` = `auctionhouse`.`itemowner` LIMIT %u",
1491 item_id
,uint32(count
));
1500 Field
*fields
= result
->Fetch();
1501 uint32 item_guid
= fields
[0].GetUInt32();
1502 uint32 owner
= fields
[1].GetUInt32();
1503 uint32 owner_acc
= fields
[2].GetUInt32();
1504 std::string owner_name
= fields
[3].GetCppString();
1506 char const* item_pos
= "[in auction]";
1508 PSendSysMessage(LANG_ITEMLIST_AUCTION
, item_guid
, owner_name
.c_str(), owner
, owner_acc
,item_pos
);
1509 } while (result
->NextRow());
1514 if(inv_count
+mail_count
+auc_count
== 0)
1516 SendSysMessage(LANG_COMMAND_NOITEMFOUND
);
1520 PSendSysMessage(LANG_COMMAND_LISTITEMMESSAGE
,item_id
,inv_count
+mail_count
+auc_count
,inv_count
,mail_count
,auc_count
);
1525 bool ChatHandler::HandleListObjectCommand(const char* args
)
1530 char* cId
= extractKeyFromLink((char*)args
,"Hgameobject_entry"); // number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
1534 uint32 go_id
= atol(cId
);
1536 GameObjectInfo
const * gInfo
= objmgr
.GetGameObjectInfo(go_id
);
1538 if(!go_id
|| !gInfo
)
1540 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID
, go_id
);
1544 char* c_count
= strtok(NULL
, " ");
1545 int count
= c_count
? atol(c_count
) : 10;
1550 Player
* pl
= m_session
->GetPlayer();
1551 QueryResult
*result
;
1553 uint32 obj_count
= 0;
1554 result
=sDatabase
.PQuery("SELECT COUNT(`guid`) FROM `gameobject` WHERE `id`='%u'",go_id
);
1557 obj_count
= (*result
)[0].GetUInt32();
1561 result
= sDatabase
.PQuery("SELECT `guid`, `id`, `position_x`, `position_y`, `position_z`, `orientation`, `map`, (POW(`position_x` - '%f', 2) + POW(`position_y` - '%f', 2) + POW(`position_z` - '%f', 2)) as `order` FROM `gameobject` WHERE `id` = '%u' ORDER BY `order` ASC LIMIT %u",
1562 pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(),go_id
,uint32(count
));
1568 Field
*fields
= result
->Fetch();
1569 uint32 guid
= fields
[0].GetUInt32();
1570 uint32 id
= fields
[1].GetUInt32();
1571 float x
= fields
[2].GetFloat();
1572 float y
= fields
[3].GetFloat();
1573 float z
= fields
[4].GetFloat();
1574 float o
= fields
[5].GetFloat();
1575 int mapid
= fields
[6].GetUInt16();
1577 PSendSysMessage(LANG_GO_LIST
, guid
, guid
, gInfo
->name
, x
, y
, z
, mapid
);
1578 } while (result
->NextRow());
1583 PSendSysMessage(LANG_COMMAND_LISTOBJMESSAGE
,go_id
,obj_count
);
1587 bool ChatHandler::HandleListCreatureCommand(const char* args
)
1592 char* cId
= extractKeyFromLink((char*)args
,"Hcreature_entry"); // number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r
1596 uint32 cr_id
= atol(cId
);
1598 CreatureInfo
const* cInfo
= objmgr
.GetCreatureTemplate(cr_id
);
1600 if(!cr_id
|| !cInfo
)
1602 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID
, cr_id
);
1606 char* c_count
= strtok(NULL
, " ");
1607 int count
= c_count
? atol(c_count
) : 10;
1612 Player
* pl
= m_session
->GetPlayer();
1613 QueryResult
*result
;
1615 uint32 cr_count
= 0;
1616 result
=sDatabase
.PQuery("SELECT COUNT(`guid`) FROM `creature` WHERE `id`='%u'",cr_id
);
1619 cr_count
= (*result
)[0].GetUInt32();
1623 result
= sDatabase
.PQuery("SELECT `guid`, `id`, `position_x`, `position_y`, `position_z`, `orientation`, `map`, (POW(`position_x` - '%f', 2) + POW(`position_y` - '%f', 2) + POW(`position_z` - '%f', 2)) as `order` FROM `creature` WHERE `id` = '%u' ORDER BY `order` ASC LIMIT %u",
1624 pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(), cr_id
,uint32(count
));
1630 Field
*fields
= result
->Fetch();
1631 uint32 guid
= fields
[0].GetUInt32();
1632 uint32 id
= fields
[1].GetUInt32();
1633 float x
= fields
[2].GetFloat();
1634 float y
= fields
[3].GetFloat();
1635 float z
= fields
[4].GetFloat();
1636 float o
= fields
[5].GetFloat();
1637 int mapid
= fields
[6].GetUInt16();
1639 PSendSysMessage(LANG_CREATURE_LIST
, guid
, guid
, cInfo
->Name
, x
, y
, z
, mapid
);
1640 } while (result
->NextRow());
1645 PSendSysMessage(LANG_COMMAND_LISTCREATUREMESSAGE
,cr_id
,cr_count
);
1649 bool ChatHandler::HandleLookupItemCommand(const char* args
)
1653 std::string namepart
= args
;
1654 sDatabase
.escape_string(namepart
);
1656 QueryResult
*result
=sDatabase
.PQuery("SELECT `entry`,`name` FROM `item_template` WHERE `name` LIKE \"%%%s%%\"",namepart
.c_str());
1659 SendSysMessage(LANG_COMMAND_NOITEMFOUND
);
1665 Field
*fields
= result
->Fetch();
1666 uint32 id
= fields
[0].GetUInt32();
1667 std::string name
= fields
[1].GetCppString();
1668 // send item in "id - id [name]" format (??)
1669 PSendSysMessage(LANG_ITEM_LIST
, id
,id
,name
.c_str());
1670 } while (result
->NextRow());
1676 bool ChatHandler::HandleLookupItemSetCommand(const char* args
)
1680 std::string namepart
= args
;
1681 uint32 counter
= 0; // Counter for figure out that we found smth.
1683 // Search in ItemSet.dbc
1684 for (uint32 id
= 0; id
< sItemSetStore
.GetNumRows(); id
++)
1686 ItemSetEntry
const *set
= sItemSetStore
.LookupEntry(id
);
1689 std::string name
= set
->name
[sWorld
.GetDBClang()];
1691 // converting name to lower case
1692 std::transform( name
.begin(), name
.end(), name
.begin(), ::tolower
);
1694 // converting string that we try to find to lower case
1695 std::transform( namepart
.begin(), namepart
.end(), namepart
.begin(), ::tolower
);
1697 if (name
.find(namepart
) != std::string::npos
)
1699 // send item set in "id - [namedlink]" format
1700 PSendSysMessage(LANG_ITEMSET_LIST
,id
,id
,set
->name
[sWorld
.GetDBClang()]);
1705 if (counter
== 0) // if counter == 0 then we found nth
1706 SendSysMessage(LANG_COMMAND_NOITEMSETFOUND
);
1710 bool ChatHandler::HandleLookupSkillCommand(const char* args
)
1715 std::string namepart
= args
;
1716 uint32 counter
= 0; // Counter for figure out that we found smth.
1718 // Search in SkillLine.dbc
1719 for (uint32 id
= 0; id
< sSkillLineStore
.GetNumRows(); id
++)
1721 SkillLineEntry
const *skillInfo
= sSkillLineStore
.LookupEntry(id
);
1724 // name - is first name field from dbc (English localized)
1725 std::string name
= skillInfo
->name
[sWorld
.GetDBClang()];
1727 // converting SkillName to lower case
1728 std::transform( name
.begin(), name
.end(), name
.begin(), ::tolower
);
1729 // converting string that we try to find to lower case
1730 std::transform( namepart
.begin(), namepart
.end(), namepart
.begin(), ::tolower
);
1732 if (name
.find(namepart
) != std::string::npos
)
1734 uint16 skill
= m_session
->GetPlayer()->GetPureSkillValue(id
);
1735 // send skill in "id - [namedlink]" format
1736 PSendSysMessage(LANG_SKILL_LIST
"%s",id
,id
,skillInfo
->name
[sWorld
.GetDBClang()],(skill
== 0 ? "" : LANG_KNOWN
));
1742 if (counter
== 0) // if counter == 0 then we found nth
1743 SendSysMessage(LANG_COMMAND_NOSKILLFOUND
);
1747 bool ChatHandler::HandleLookupSpellCommand(const char* args
)
1751 std::string namepart
= args
;
1752 uint32 counter
= 0; // Counter for figure out that we found smth.
1754 // Search in Spell.dbc
1755 for (uint32 id
= 0; id
< sSpellStore
.GetNumRows(); id
++)
1757 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(id
);
1760 // name - is first name field from dbc (English localized)
1761 std::string name
= spellInfo
->SpellName
[sWorld
.GetDBClang()];
1763 // converting SpellName to lower case
1764 std::transform( name
.begin(), name
.end(), name
.begin(), ::tolower
);
1766 // converting string that we try to find to lower case
1767 std::transform( namepart
.begin(), namepart
.end(), namepart
.begin(), ::tolower
);
1769 if (name
.find(namepart
) != std::string::npos
)
1771 uint32 rank
= objmgr
.GetSpellRank(id
); // unit32 used to prevent interpreting uint8 as char at output
1772 bool known
= m_session
->GetPlayer()->HasSpell(id
);
1773 bool learn
= (spellInfo
->Effect
[0] == SPELL_EFFECT_LEARN_SPELL
);
1774 bool talent
= (GetTalentSpellCost(id
) > 0);
1775 bool passive
= IsPassiveSpell(id
);
1777 // send spell in "id - [name, rank N] [talent] [passive] [learn] [known]" format
1778 std::ostringstream ss
;
1779 ss
<< id
<< " - |cffffffff|Hspell:" << id
<< "|h[" << spellInfo
->SpellName
[sWorld
.GetDBClang()];
1781 // include rank in link name
1783 ss
<< LANG_SPELL_RANK
<< rank
;
1796 SendSysMessage(ss
.str().c_str());
1802 if (counter
== 0) // if counter == 0 then we found nth
1803 SendSysMessage(LANG_COMMAND_NOSPELLFOUND
);
1807 bool ChatHandler::HandleLookupQuestCommand(const char* args
)
1811 std::string namepart
= args
;
1812 sDatabase
.escape_string(namepart
);
1814 QueryResult
*result
=sDatabase
.PQuery("SELECT `entry`,`Title` FROM `quest_template` WHERE `Title` LIKE \"%%%s%%\" ORDER BY `entry`",namepart
.c_str());
1817 SendSysMessage(LANG_COMMAND_NOQUESTFOUND
);
1823 Field
*fields
= result
->Fetch();
1824 uint16 id
= fields
[0].GetUInt16();
1825 std::string name
= fields
[1].GetCppString();
1827 QuestStatus status
= m_session
->GetPlayer()->GetQuestStatus(id
);
1829 char const* statusStr
= "";
1830 if(status
== QUEST_STATUS_COMPLETE
)
1832 if(m_session
->GetPlayer()->GetQuestRewardStatus(id
))
1833 statusStr
= LANG_COMMAND_QUEST_REWARDED
;
1835 statusStr
= LANG_COMMAND_QUEST_COMPLETE
;
1837 else if(status
== QUEST_STATUS_INCOMPLETE
)
1838 statusStr
= LANG_COMMAND_QUEST_ACTIVE
;
1840 PSendSysMessage(LANG_QUEST_LIST
"%s",id
,id
,name
.c_str(),(status
== QUEST_STATUS_COMPLETE
? LANG_COMPLETE
: (status
== QUEST_STATUS_INCOMPLETE
? LANG_ACTIVE
: "") ));
1841 } while (result
->NextRow());
1847 bool ChatHandler::HandleLookupCreatureCommand(const char* args
)
1852 std::string namepart
= args
;
1853 sDatabase
.escape_string(namepart
);
1855 QueryResult
*result
=sDatabase
.PQuery("SELECT `entry`,`name` FROM `creature_template` WHERE `name` LIKE \"%%%s%%\"",namepart
.c_str());
1858 SendSysMessage(LANG_COMMAND_NOCREATUREFOUND
);
1864 Field
*fields
= result
->Fetch();
1865 uint16 id
= fields
[0].GetUInt16();
1866 std::string name
= fields
[1].GetCppString();
1867 PSendSysMessage(LANG_CREATURE_ENTRY_LIST
,id
,id
,name
.c_str());
1868 } while (result
->NextRow());
1874 bool ChatHandler::HandleLookupObjectCommand(const char* args
)
1879 std::string namepart
= args
;
1880 sDatabase
.escape_string(namepart
);
1882 QueryResult
*result
=sDatabase
.PQuery("SELECT `entry`,`name` FROM `gameobject_template` WHERE `name` LIKE \"%%%s%%\"",namepart
.c_str());
1885 SendSysMessage(LANG_COMMAND_NOGAMEOBJECTFOUND
);
1891 Field
*fields
= result
->Fetch();
1892 uint32 id
= fields
[0].GetUInt32();
1893 std::string name
= fields
[1].GetCppString();
1894 PSendSysMessage(LANG_GO_ENTRY_LIST
,id
,id
,name
.c_str());
1895 } while (result
->NextRow());
1901 bool ChatHandler::HandleCreateGuildCommand(const char* args
)
1906 std::string guildname
;
1911 lname
= strtok((char*)args
, " ");
1912 gname
= strtok(NULL
, "");
1918 SendSysMessage(LANG_INSERT_GUILD_NAME
);
1923 player
= ObjectAccessor::Instance().FindPlayerByName(lname
);
1927 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
1931 if(!player
->GetGuildId())
1934 if(!guild
->create(player
->GetGUID(),guildname
))
1937 SendSysMessage(LANG_GUILD_NOT_CREATED
);
1941 objmgr
.AddGuild(guild
);
1944 SendSysMessage(LANG_PLAYER_IN_GUILD
);
1949 //float max_creature_distance = 160;
1951 bool ChatHandler::HandleGetDistanceCommand(const char* args
)
1953 Unit
* pUnit
= getSelectedUnit();
1957 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
1961 PSendSysMessage(LANG_DISTANCE
, m_session
->GetPlayer()->GetDistanceSq(pUnit
));
1966 bool ChatHandler::HandleObjectCommand(const char* args
)
1971 uint32 display_id
= atoi((char*)args
);
1973 char* safe
= strtok((char*)args
, " ");
1975 Player
*chr
= m_session
->GetPlayer();
1976 float x
= chr
->GetPositionX();
1977 float y
= chr
->GetPositionY();
1978 float z
= chr
->GetPositionZ();
1979 float o
= chr
->GetOrientation();
1981 GameObject
* pGameObj
= new GameObject(chr
);
1982 if(!pGameObj
->Create(objmgr
.GenerateLowGuid(HIGHGUID_GAMEOBJECT
), display_id
, chr
->GetMapId(), x
, y
, z
, o
, 0, 0, 0, 0, 0, 0))
1987 sLog
.outDebug(LANG_ADD_OBJ_LV3
);
1989 if(strcmp(safe
,"true") == 0)
1990 pGameObj
->SaveToDB();
1992 MapManager::Instance().GetMap(pGameObj
->GetMapId(), pGameObj
)->Add(pGameObj
);
1999 bool ChatHandler::HandleAddWeaponCommand(const char* args
)
2004 uint64 guid = m_session->GetPlayer()->GetSelection();
2007 SendSysMessage(LANG_NO_SELECTION);
2011 Creature *pCreature = ObjectAccessor::Instance().GetCreature(*m_session->GetPlayer(), guid);
2015 SendSysMessage(LANG_SELECT_CREATURE);
2019 char* pSlotID = strtok((char*)args, " ");
2023 char* pItemID = strtok(NULL, " ");
2027 uint32 ItemID = atoi(pItemID);
2028 uint32 SlotID = atoi(pSlotID);
2030 ItemPrototype* tmpItem = objmgr.GetItemPrototype(ItemID);
2038 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY, ItemID);
2042 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_01, ItemID);
2046 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_02, ItemID);
2050 PSendSysMessage(LANG_ITEM_SLOT_NOT_EXIST,SlotID);
2056 PSendSysMessage(LANG_ITEM_ADDED_TO_SLOT,ItemID,tmpItem->Name1,SlotID);
2061 PSendSysMessage(LANG_ITEM_NOT_FOUND,ItemID);
2068 bool ChatHandler::HandleGameObjectCommand(const char* args
)
2074 char* pParam1
= strtok((char*)args
, " ");
2075 uint32 id
= atoi((char*)pParam1
);
2079 char* lootID
= strtok(NULL
, " ");
2080 char* spawntimeSecs
= strtok(NULL
, " ");
2082 const GameObjectInfo
*goI
= objmgr
.GetGameObjectInfo(id
);
2086 PSendSysMessage(LANG_GAMEOBJECT_NOT_EXIST
,id
);
2090 Player
*chr
= m_session
->GetPlayer();
2091 float x
= float(chr
->GetPositionX());
2092 float y
= float(chr
->GetPositionY());
2093 float z
= float(chr
->GetPositionZ());
2094 float o
= float(chr
->GetOrientation());
2096 float rot2
= sin(o
/2);
2097 float rot3
= cos(o
/2);
2099 GameObject
* pGameObj
= new GameObject(chr
);
2100 uint32 lowGUID
= objmgr
.GenerateLowGuid(HIGHGUID_GAMEOBJECT
);
2102 if(!pGameObj
->Create(lowGUID
, goI
->id
, chr
->GetMapId(), x
, y
, z
, o
, 0, 0, rot2
, rot3
, 0, 0))
2107 //pGameObj->SetZoneId(chr->GetZoneId());
2108 pGameObj
->SetMapId(chr
->GetMapId());
2109 //pGameObj->SetNameId(id);
2110 sLog
.outDebug(LANG_GAMEOBJECT_CURRENT
, goI
->name
, lowGUID
, x
, y
, z
, o
);
2114 uint32 value
= atoi((char*)lootID
);
2115 pGameObj
->lootid
= value
;
2116 //sLog.outDebug("*** LOOT: %d", value);
2121 uint32 value
= atoi((char*)spawntimeSecs
);
2122 pGameObj
->SetRespawnTime(value
);
2123 //sLog.outDebug("*** spawntimeSecs: %d", value);
2126 pGameObj
->SaveToDB();
2127 MapManager::Instance().GetMap(pGameObj
->GetMapId(), pGameObj
)->Add(pGameObj
);
2129 PSendSysMessage(LANG_GAMEOBJECT_ADD
,id
,goI
->name
,x
,y
,z
);
2134 bool ChatHandler::HandleAnimCommand(const char* args
)
2139 uint32 anim_id
= atoi((char*)args
);
2141 WorldPacket
data( SMSG_EMOTE
, (8+4) );
2142 data
<< anim_id
<< m_session
->GetPlayer( )->GetGUID();
2143 WPAssert(data
.size() == 12);
2144 MapManager::Instance().GetMap(m_session
->GetPlayer()->GetMapId(), m_session
->GetPlayer())->MessageBoardcast(m_session
->GetPlayer(), &data
, true);
2148 bool ChatHandler::HandleStandStateCommand(const char* args
)
2153 uint32 anim_id
= atoi((char*)args
);
2154 m_session
->GetPlayer( )->SetUInt32Value( UNIT_NPC_EMOTESTATE
, anim_id
);
2159 bool ChatHandler::HandleDieCommand(const char* args
)
2161 Unit
* target
= getSelectedUnit();
2165 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
2169 if( target
->isAlive() )
2171 m_session
->GetPlayer()->DealDamage(target
, target
->GetHealth(), NULL
, DIRECT_DAMAGE
, 0, NULL
, 0, false);
2177 bool ChatHandler::HandleReviveCommand(const char* args
)
2179 Player
* SelectedPlayer
= NULL
;
2183 std::string name
= args
;
2184 normalizePlayerName(name
);
2185 SelectedPlayer
= objmgr
.GetPlayer(name
.c_str());
2188 SelectedPlayer
= getSelectedPlayer();
2192 PSendSysMessage(LANG_NO_CHAR_SELECTED
);
2196 SelectedPlayer
->ResurrectPlayer(0.5f
);
2197 SelectedPlayer
->SpawnCorpseBones();
2198 SelectedPlayer
->SaveToDB();
2202 bool ChatHandler::HandleMorphCommand(const char* args
)
2207 uint16 display_id
= (uint16
)atoi((char*)args
);
2209 Unit
*target
= getSelectedUnit();
2211 target
= m_session
->GetPlayer();
2213 target
->SetUInt32Value(UNIT_FIELD_DISPLAYID
, display_id
);
2218 bool ChatHandler::HandleAuraCommand(const char* args
)
2220 char* px
= strtok((char*)args
, " ");
2224 Unit
*target
= getSelectedUnit();
2227 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
2231 uint32 spellID
= (uint32
)atoi(px
);
2232 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry( spellID
);
2235 for(uint32 i
= 0;i
<3;i
++)
2237 uint8 eff
= spellInfo
->Effect
[i
];
2238 if (eff
>=TOTAL_SPELL_EFFECTS
)
2240 if (eff
== SPELL_EFFECT_APPLY_AURA
|| eff
== SPELL_EFFECT_APPLY_AREA_AURA
|| eff
== SPELL_EFFECT_PERSISTENT_AREA_AURA
)
2242 Aura
*Aur
= new Aura(spellInfo
, i
, target
);
2243 target
->AddAura(Aur
);
2251 bool ChatHandler::HandleUnAuraCommand(const char* args
)
2253 char* px
= strtok((char*)args
, " ");
2257 Unit
*target
= getSelectedUnit();
2260 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
2264 std::string argstr
= args
;
2265 if (argstr
== "all")
2267 target
->RemoveAllAuras();
2271 uint32 spellID
= (uint32
)atoi(px
);
2272 target
->RemoveAurasDueToSpell(spellID
);
2277 bool ChatHandler::HandleLinkGraveCommand(const char* args
)
2282 char* px
= strtok((char*)args
, " ");
2286 uint32 g_id
= (uint32
)atoi(px
);
2290 char* px2
= strtok(NULL
, " ");
2294 else if (strncmp(px2
,"horde",6)==0)
2296 else if (strncmp(px2
,"alliance",9)==0)
2301 WorldSafeLocsEntry
const* graveyard
= sWorldSafeLocsStore
.LookupEntry(g_id
);
2305 PSendSysMessage(LANG_COMMAND_GRAVEYARDNOEXIST
, g_id
);
2309 Player
* player
= m_session
->GetPlayer();
2311 QueryResult
*result
= sDatabase
.PQuery(
2312 "SELECT `id` FROM `game_graveyard_zone` WHERE `id` = %u AND `ghost_map` = %u AND `ghost_zone` = '%u' AND (`faction` = %u OR `faction` = 0 )",
2313 g_id
,player
->GetMapId(),player
->GetZoneId(),g_team
);
2319 PSendSysMessage(LANG_COMMAND_GRAVEYARDALRLINKED
, g_id
,player
->GetZoneId());
2323 sDatabase
.PExecuteLog("INSERT INTO `game_graveyard_zone` ( `id`,`ghost_map`,`ghost_zone`,`faction`) VALUES ('%u', '%u', '%u','%u')",
2324 g_id
,player
->GetMapId(),player
->GetZoneId(),g_team
);
2326 PSendSysMessage(LANG_COMMAND_GRAVEYARDLINKED
, g_id
,player
->GetZoneId());
2331 bool ChatHandler::HandleNearGraveCommand(const char* args
)
2337 else if (strncmp((char*)args
,"horde",6)==0)
2339 else if (strncmp((char*)args
,"alliance",9)==0)
2344 Player
* player
= m_session
->GetPlayer();
2346 WorldSafeLocsEntry
const* graveyard
= objmgr
.GetClosestGraveYard(
2347 player
->GetPositionX(), player
->GetPositionY(), player
->GetPositionZ(),player
->GetMapId(),player
->GetTeam());
2351 uint32 g_id
= graveyard
->ID
;
2353 QueryResult
*result
= sDatabase
.PQuery("SELECT `faction` FROM `game_graveyard_zone` WHERE `id` = %u",g_id
);
2356 PSendSysMessage(LANG_COMMAND_GRAVEYARDERROR
,g_id
);
2360 Field
*fields
= result
->Fetch();
2361 g_team
= fields
[0].GetUInt32();
2364 std::string team_name
= LANG_COMMAND_GRAVEYARD_NOTEAM
;
2367 team_name
= LANG_COMMAND_GRAVEYARD_ANY
;
2368 else if(g_team
== HORDE
)
2369 team_name
= LANG_COMMAND_GRAVEYARD_HORDE
;
2370 else if(g_team
== ALLIANCE
)
2371 team_name
= LANG_COMMAND_GRAVEYARD_ALLIANCE
;
2373 PSendSysMessage(LANG_COMMAND_GRAVEYARDNEAREST
, g_id
,team_name
.c_str(),player
->GetZoneId());
2377 std::string team_name
;
2380 team_name
= LANG_COMMAND_GRAVEYARD_ANY
;
2381 else if(g_team
== HORDE
)
2382 team_name
= LANG_COMMAND_GRAVEYARD_HORDE
;
2383 else if(g_team
== ALLIANCE
)
2384 team_name
= LANG_COMMAND_GRAVEYARD_ALLIANCE
;
2386 if(g_team
== ~uint32(0))
2387 PSendSysMessage(LANG_COMMAND_ZONENOGRAVEYARDS
, player
->GetZoneId());
2389 PSendSysMessage(LANG_COMMAND_ZONENOGRAFACTION
, player
->GetZoneId(),team_name
.c_str());
2395 bool ChatHandler::HandleSpawnTransportCommand(const char* args
)
2400 bool ChatHandler::HandleEmoteCommand(const char* args
)
2402 uint32 emote
= atoi((char*)args
);
2404 Creature
* target
= getSelectedCreature();
2407 PSendSysMessage(LANG_SELECT_CREATURE
);
2411 target
->SetUInt32Value(UNIT_NPC_EMOTESTATE
,emote
);
2416 bool ChatHandler::HandleNpcInfoCommand(const char* args
)
2418 Creature
* target
= getSelectedCreature();
2422 SendSysMessage(LANG_SELECT_CREATURE
);
2426 uint32 faction
= target
->getFaction();
2427 uint32 npcflags
= target
->GetUInt32Value(UNIT_NPC_FLAGS
);
2428 uint32 displayid
= target
->GetUInt32Value(UNIT_FIELD_DISPLAYID
);
2429 uint32 nativeid
= target
->GetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID
);
2430 uint32 Entry
= target
->GetUInt32Value(OBJECT_FIELD_ENTRY
);
2431 CreatureInfo
const* cInfo
= target
->GetCreatureInfo();
2433 PSendSysMessage(LANG_NPCINFO_CHAR
, target
->GetDBTableGUIDLow(), faction
, npcflags
, Entry
, displayid
, nativeid
);
2434 PSendSysMessage(LANG_NPCINFO_LEVEL
, target
->getLevel());
2435 PSendSysMessage(LANG_NPCINFO_HEALTH
,target
->GetUInt32Value(UNIT_FIELD_BASE_HEALTH
), target
->GetMaxHealth(), target
->GetHealth());
2436 PSendSysMessage(LANG_NPCINFO_FLAGS
, target
->GetUInt32Value(UNIT_FIELD_FLAGS
), target
->GetUInt32Value(UNIT_DYNAMIC_FLAGS
), target
->getFaction());
2437 PSendSysMessage(LANG_NPCINFO_LOOT
, cInfo
->lootid
,cInfo
->pickpocketLootId
,cInfo
->SkinLootId
);
2438 PSendSysMessage(LANG_NPCINFO_DUNGEON_ID
, target
->GetInstanceId());
2440 PSendSysMessage(LANG_NPCINFO_POSITION
,float(target
->GetPositionX()), float(target
->GetPositionY()), float(target
->GetPositionZ()));
2442 if ((npcflags
& UNIT_NPC_FLAG_VENDOR
) )
2444 SendSysMessage(LANG_NPCINFO_VENDOR
);
2446 if ((npcflags
& UNIT_NPC_FLAG_TRAINER
) )
2448 SendSysMessage(LANG_NPCINFO_TRAINER
);
2454 bool ChatHandler::HandleNpcInfoSetCommand(const char* args
)
2456 uint32 entry
= 0, testvalue
= 0;
2458 Creature
* target
= getSelectedCreature();
2461 PSendSysMessage(LANG_SELECT_CREATURE
);
2468 //m_session->GetPlayer( )->SetUInt32Value(PLAYER_FLAGS, (uint32)8);
2470 testvalue
= uint32(atoi((char*)args
));
2472 entry
= target
->GetUInt32Value( OBJECT_FIELD_ENTRY
);
2474 //m_session->SendTestCreatureQueryOpcode( entry, target->GetGUID(), testvalue );
2479 bool ChatHandler::HandleExploreCheatCommand(const char* args
)
2484 int flag
= atoi((char*)args
);
2486 Player
*chr
= getSelectedPlayer();
2489 SendSysMessage(LANG_NO_CHAR_SELECTED
);
2495 PSendSysMessage(LANG_YOU_SET_EXPLORE_ALL
, chr
->GetName());
2499 PSendSysMessage(LANG_YOU_SET_EXPLORE_NOTHING
, chr
->GetName());
2506 sprintf((char*)buf
,LANG_YOURS_EXPLORE_SET_ALL
,
2507 m_session
->GetPlayer()->GetName());
2511 sprintf((char*)buf
,LANG_YOURS_EXPLORE_SET_NOTHING
,
2512 m_session
->GetPlayer()->GetName());
2516 FillSystemMessageData(&data
, m_session
, buf
);
2517 chr
->GetSession()->SendPacket(&data
);
2519 for (uint8 i
=0; i
<64; i
++)
2523 m_session
->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1
+i
,0xFFFFFFFF);
2527 m_session
->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1
+i
,0);
2534 bool ChatHandler::HandleHoverCommand(const char* args
)
2536 char* px
= strtok((char*)args
, " ");
2543 m_session
->GetPlayer()->SetHover(flag
);
2546 SendSysMessage(LANG_HOVER_ENABLED
);
2548 PSendSysMessage(LANG_HOVER_DISABLED
);
2553 bool ChatHandler::HandleLevelUpCommand(const char* args
)
2555 char* px
= strtok((char*)args
, " ");
2556 char* py
= strtok((char*)NULL
, " ");
2558 // command format parsing
2559 char* pname
= (char*)NULL
;
2562 if(px
&& py
) // .levelup name level
2564 addlevel
= atoi(py
);
2567 else if(px
&& !py
) // .levelup name OR .levelup level
2569 if(isalpha(px
[0])) // .levelup name
2571 else // .levelup level
2572 addlevel
= atoi(px
);
2574 // else .levelup - nothing do for prepering
2578 uint64 chr_guid
= 0;
2580 if(pname
) // player by name
2582 std::string name
= pname
;
2583 normalizePlayerName(name
);
2585 chr
= objmgr
.GetPlayer(name
.c_str());
2586 if(!chr
) // not in game
2588 chr_guid
= objmgr
.GetPlayerGUIDByName(name
);
2591 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
2596 else // player by selection
2598 chr
= getSelectedPlayer();
2602 SendSysMessage(LANG_NO_CHAR_SELECTED
);
2607 assert(chr
|| chr_guid
);
2609 int32 oldlevel
= chr
? chr
->getLevel() : Player::GetUInt32ValueFromDB(UNIT_FIELD_LEVEL
,chr_guid
);
2610 int32 newlevel
= oldlevel
+ addlevel
;
2613 if(newlevel
> 255) // hardcoded maximum level
2618 chr
->InitStatsForLevel(newlevel
);
2619 chr
->InitTalentForLevel();
2620 chr
->SetUInt32Value(PLAYER_XP
,0);
2624 if(oldlevel
== newlevel
)
2625 FillSystemMessageData(&data
, chr
->GetSession(), LANG_YOURS_LEVEL_PROGRESS_RESET
);
2627 if(oldlevel
< newlevel
)
2628 FillSystemMessageData(&data
, chr
->GetSession(), fmtstring(LANG_YOURS_LEVEL_UP
,newlevel
-oldlevel
));
2630 if(oldlevel
> newlevel
)
2631 FillSystemMessageData(&data
, chr
->GetSession(), fmtstring(LANG_YOURS_LEVEL_DOWN
,newlevel
-oldlevel
));
2633 chr
->GetSession()->SendPacket( &data
);
2635 // give level to summoned pet
2636 Pet
* pet
= chr
->GetPet();
2637 if(pet
&& pet
->getPetType()==SUMMON_PET
)
2638 pet
->GivePetLevel(newlevel
);
2642 // update levle and XP at level, all other will be updated at loading
2643 std::vector
<std::string
> values
;
2644 Player::LoadValuesArrayFromDB(values
,chr_guid
);
2645 Player::SetUInt32ValueInArray(values
,UNIT_FIELD_LEVEL
,newlevel
);
2646 Player::SetUInt32ValueInArray(values
,PLAYER_XP
,0);
2647 Player::SaveValuesArrayInDB(values
,chr_guid
);
2653 bool ChatHandler::HandleShowAreaCommand(const char* args
)
2658 int area
= atoi((char*)args
);
2660 Player
*chr
= getSelectedPlayer();
2663 SendSysMessage(LANG_NO_CHAR_SELECTED
);
2667 int offset
= area
/ 32;
2668 uint32 val
= (uint32
)(1 << (area
% 32));
2672 SendSysMessage(LANG_BAD_VALUE
);
2676 uint32 currFields
= chr
->GetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
);
2677 chr
->SetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
, (uint32
)(currFields
| val
));
2679 SendSysMessage(LANG_EXPLORE_AREA
);
2683 bool ChatHandler::HandleHideAreaCommand(const char* args
)
2688 int area
= atoi((char*)args
);
2690 Player
*chr
= getSelectedPlayer();
2693 SendSysMessage(LANG_NO_CHAR_SELECTED
);
2697 int offset
= area
/ 32;
2698 uint32 val
= (uint32
)(1 << (area
% 32));
2702 SendSysMessage(LANG_BAD_VALUE
);
2706 uint32 currFields
= chr
->GetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
);
2707 chr
->SetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
, (uint32
)(currFields
^ val
));
2709 SendSysMessage(LANG_UNEXPLORE_AREA
);
2713 bool ChatHandler::HandleUpdate(const char* args
)
2721 char* pUpdateIndex
= strtok((char*)args
, " ");
2723 Unit
* chr
= getSelectedUnit();
2726 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
2734 updateIndex
= atoi(pUpdateIndex
);
2736 if(chr
->GetTypeId() == TYPEID_PLAYER
)
2738 if (updateIndex
>=PLAYER_END
) return true;
2742 if (updateIndex
>=UNIT_END
) return true;
2745 char* pvalue
= strtok(NULL
, " ");
2748 value
=chr
->GetUInt32Value(updateIndex
);
2750 PSendSysMessage(LANG_UPDATE
, chr
->GetGUIDLow(),updateIndex
,value
);
2756 PSendSysMessage(LANG_UPDATE_CHANGE
, chr
->GetGUIDLow(),updateIndex
,value
);
2758 chr
->SetUInt32Value(updateIndex
,value
);
2763 bool ChatHandler::HandleBankCommand(const char* args
)
2765 m_session
->SendShowBank( m_session
->GetPlayer()->GetGUID() );
2770 bool ChatHandler::HandleChangeWeather(const char* args
)
2776 if (sWorld
.getConfig(CONFIG_WEATHER
) == 0)
2778 SendSysMessage(LANG_WEATHER_DISABLED
);
2782 //*Change the weather of a cell
2783 char* px
= strtok((char*)args
, " ");
2784 char* py
= strtok(NULL
, " ");
2789 uint32 type
= (uint32
)atoi(px
); //0 to 3, 0: fine, 1: rain, 2: snow, 3: sand
2790 float grade
= (float)atof(py
); //0 to 1, sending -1 is instand good weather
2792 Player
*player
= m_session
->GetPlayer();
2793 uint32 zoneid
= player
->GetZoneId();
2795 Weather
* wth
= sWorld
.FindWeather(zoneid
);
2798 wth
= sWorld
.AddWeather(zoneid
);
2801 SendSysMessage(LANG_NO_WEATHER
);
2805 wth
->SetWeather(type
, grade
);
2810 bool ChatHandler::HandleSetValue(const char* args
)
2815 char* px
= strtok((char*)args
, " ");
2816 char* py
= strtok(NULL
, " ");
2817 char* pz
= strtok(NULL
, " ");
2822 Unit
* target
= getSelectedUnit();
2825 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
2829 uint64 guid
= target
->GetGUID();
2831 uint32 Opcode
= (uint32
)atoi(px
);
2832 if(Opcode
>= target
->GetValuesCount())
2834 PSendSysMessage(LANG_TOO_BIG_INDEX
, Opcode
, GUID_LOPART(guid
), target
->GetValuesCount());
2839 bool isint32
= true;
2841 isint32
= (bool)atoi(pz
);
2844 iValue
= (uint32
)atoi(py
);
2845 sLog
.outDebug( LANG_SET_UINT
, GUID_LOPART(guid
), Opcode
, iValue
);
2846 target
->SetUInt32Value( Opcode
, iValue
);
2847 PSendSysMessage(LANG_SET_UINT_FIELD
, GUID_LOPART(guid
), Opcode
,iValue
);
2851 fValue
= (float)atof(py
);
2852 sLog
.outDebug( LANG_SET_FLOAT
, GUID_LOPART(guid
), Opcode
, fValue
);
2853 target
->SetFloatValue( Opcode
, fValue
);
2854 PSendSysMessage(LANG_SET_FLOAT_FIELD
, GUID_LOPART(guid
), Opcode
,fValue
);
2860 bool ChatHandler::HandleGetValue(const char* args
)
2865 char* px
= strtok((char*)args
, " ");
2866 char* pz
= strtok(NULL
, " ");
2871 Unit
* target
= getSelectedUnit();
2874 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
2878 uint64 guid
= target
->GetGUID();
2880 uint32 Opcode
= (uint32
)atoi(px
);
2881 if(Opcode
>= target
->GetValuesCount())
2883 PSendSysMessage(LANG_TOO_BIG_INDEX
, Opcode
, GUID_LOPART(guid
), target
->GetValuesCount());
2888 bool isint32
= true;
2890 isint32
= (bool)atoi(pz
);
2894 iValue
= target
->GetUInt32Value( Opcode
);
2895 sLog
.outDebug( LANG_GET_UINT
, GUID_LOPART(guid
), Opcode
, iValue
);
2896 PSendSysMessage(LANG_GET_UINT_FIELD
, GUID_LOPART(guid
), Opcode
, iValue
);
2900 fValue
= target
->GetFloatValue( Opcode
);
2901 sLog
.outDebug( LANG_GET_FLOAT
, GUID_LOPART(guid
), Opcode
, fValue
);
2902 PSendSysMessage(LANG_GET_FLOAT_FIELD
, GUID_LOPART(guid
), Opcode
, fValue
);
2908 bool ChatHandler::HandleSet32Bit(const char* args
)
2913 char* px
= strtok((char*)args
, " ");
2914 char* py
= strtok(NULL
, " ");
2919 uint32 Opcode
= (uint32
)atoi(px
);
2920 uint32 Value
= (uint32
)atoi(py
);
2921 if (Value
> 32) //uint32 = 32 bits
2924 sLog
.outDebug( LANG_SET_32BIT
, Opcode
, Value
);
2926 m_session
->GetPlayer( )->SetUInt32Value( Opcode
, 2^Value
);
2928 PSendSysMessage(LANG_SET_32BIT_FIELD
, Opcode
,1);
2932 bool ChatHandler::HandleMod32Value(const char* args
)
2937 char* px
= strtok((char*)args
, " ");
2938 char* py
= strtok(NULL
, " ");
2943 uint32 Opcode
= (uint32
)atoi(px
);
2944 int Value
= atoi(py
);
2946 if(Opcode
>= m_session
->GetPlayer()->GetValuesCount())
2948 PSendSysMessage(LANG_TOO_BIG_INDEX
, Opcode
, m_session
->GetPlayer()->GetGUIDLow(), m_session
->GetPlayer( )->GetValuesCount());
2952 sLog
.outDebug( LANG_CHANGE_32BIT
, Opcode
, Value
);
2954 int CurrentValue
= (int)m_session
->GetPlayer( )->GetUInt32Value( Opcode
);
2956 CurrentValue
+= Value
;
2957 m_session
->GetPlayer( )->SetUInt32Value( Opcode
, (uint32
)CurrentValue
);
2959 PSendSysMessage(LANG_CHANGE_32BIT_FIELD
, Opcode
,CurrentValue
);
2964 bool ChatHandler::HandleAddTeleCommand(const char * args
)
2968 QueryResult
*result
;
2969 Player
*player
=m_session
->GetPlayer();
2970 if (!player
) return false;
2972 std::string name
= args
;
2973 sDatabase
.escape_string(name
);
2974 result
= sDatabase
.PQuery("SELECT `id` FROM `game_tele` WHERE `name` = '%s'",name
.c_str());
2977 SendSysMessage(LANG_COMMAND_TP_ALREADYEXIST
);
2982 float x
= player
->GetPositionX();
2983 float y
= player
->GetPositionY();
2984 float z
= player
->GetPositionZ();
2985 float ort
= player
->GetOrientation();
2986 int mapid
= player
->GetMapId();
2988 if(sDatabase
.PExecuteLog("INSERT INTO `game_tele` (`position_x`,`position_y`,`position_z`,`orientation`,`map`,`name`) VALUES (%f,%f,%f,%f,%d,'%s')",x
,y
,z
,ort
,mapid
,name
.c_str()))
2990 SendSysMessage(LANG_COMMAND_TP_ADDED
);
2993 SendSysMessage(LANG_COMMAND_TP_ADDEDERR
);
2998 bool ChatHandler::HandleDelTeleCommand(const char * args
)
3003 std::string name
= args
;
3004 sDatabase
.escape_string(name
);
3006 QueryResult
*result
=sDatabase
.PQuery("SELECT `id` FROM `game_tele` WHERE `name` = '%s'",name
.c_str());
3009 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND
);
3014 if(sDatabase
.PExecuteLog("DELETE FROM `game_tele` WHERE `name` = '%s'",name
.c_str()))
3016 SendSysMessage(LANG_COMMAND_TP_DELETED
);
3019 SendSysMessage(LANG_COMMAND_TP_DELETEERR
);
3023 bool ChatHandler::HandleListAurasCommand (const char * args
)
3025 Unit
*unit
= getSelectedUnit();
3028 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3032 Unit::AuraMap
& uAuras
= unit
->GetAuras();
3033 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURAS
, uAuras
.size());
3034 for (Unit::AuraMap::iterator itr
= uAuras
.begin(); itr
!= uAuras
.end(); ++itr
)
3036 PSendSysMessage(LANG_COMMAND_TARGET_AURADETAIL
, itr
->second
->GetId(), itr
->second
->GetEffIndex(), itr
->second
->GetModifier()->m_auraname
, itr
->second
->GetAuraDuration(), itr
->second
->GetSpellProto()->SpellName
[0]);
3038 for (int i
= 0; i
< TOTAL_AURAS
; i
++)
3040 Unit::AuraList
& uAuraList
= unit
->GetAurasByType(i
);
3041 if (!uAuraList
.size()) continue;
3042 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURATYPE
, uAuraList
.size(), i
);
3043 for (Unit::AuraList::iterator itr
= uAuraList
.begin(); itr
!= uAuraList
.end(); ++itr
)
3045 PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE
, (*itr
)->GetId(), (*itr
)->GetEffIndex(), (*itr
)->GetSpellProto()->SpellName
[0]);
3051 bool ChatHandler::HandleResetCommand (const char * args
)
3056 char* arg
= strtok((char*)args
, " ");
3057 std::string argstr
= arg
;
3058 char* pName
= strtok(NULL
, "");
3059 Player
*player
= NULL
;
3062 std::string name
= pName
;
3063 normalizePlayerName(name
);
3064 uint64 guid
= objmgr
.GetPlayerGUIDByName(name
.c_str());
3065 player
= objmgr
.GetPlayer(guid
);
3068 player
= getSelectedPlayer();
3072 SendSysMessage(LANG_NO_CHAR_SELECTED
);
3076 if (argstr
== "stats" || argstr
== "level")
3078 PlayerInfo
const *info
= objmgr
.GetPlayerInfo(player
->getRace(), player
->getClass());
3079 if(!info
) return false;
3081 ChrClassesEntry
const* cEntry
= sChrClassesStore
.LookupEntry(player
->getClass());
3084 sLog
.outError("Class %u not found in DBÑ (Wrong DBC files?)",player
->getClass());
3088 uint8 powertype
= cEntry
->powerType
;
3091 if(powertype
== POWER_RAGE
)
3092 unitfield
= 0x1100EE00;
3093 else if(powertype
== POWER_ENERGY
)
3094 unitfield
= 0x00000000;
3095 else if(powertype
== POWER_MANA
)
3096 unitfield
= 0x0000EE00;
3099 sLog
.outError("Invalid default powertype %u for player (class %u)",powertype
,player
->getClass());
3103 // reset m_form if no aura
3104 if(!player
->HasAuraType(SPELL_AURA_MOD_SHAPESHIFT
))
3107 player
->SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS
, 0.388999998569489f
);
3108 player
->SetFloatValue(UNIT_FIELD_COMBATREACH
, 1.5f
);
3110 player
->setFactionForRace(player
->getRace());
3112 player
->SetUInt32Value(UNIT_FIELD_BYTES_0
, ( ( player
->getRace() ) | ( player
->getClass() << 8 ) | ( player
->getGender() << 16 ) | ( powertype
<< 24 ) ) );
3114 // reset only if player not in some form;
3117 switch(player
->getGender())
3120 player
->SetUInt32Value(UNIT_FIELD_DISPLAYID
, info
->displayId_f
);
3121 player
->SetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID
, info
->displayId_f
);
3124 player
->SetUInt32Value(UNIT_FIELD_DISPLAYID
, info
->displayId_m
);
3125 player
->SetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID
, info
->displayId_m
);
3132 // set UNIT_FIELD_BYTES_1 to init state but preserve m_form value
3133 player
->SetUInt32Value(UNIT_FIELD_BYTES_1
, player
->m_form
<<16 | unitfield
);
3135 player
->SetUInt32Value(UNIT_FIELD_BYTES_2
, 0x2800 ); // 0x2800, 0x2801 2.0.8...
3136 player
->SetUInt32Value(UNIT_FIELD_FLAGS
, UNIT_FLAG_UNKNOWN1
);
3138 //-1 is default value
3139 player
->SetUInt32Value(PLAYER_FIELD_WATCHED_FACTION_INDEX
, uint32(-1));
3141 //player->SetUInt32Value(PLAYER_FIELD_BYTES, 0xEEE00000 );
3143 if(argstr
== "level")
3145 player
->InitStatsForLevel(1,false);
3146 player
->InitTalentForLevel();
3147 player
->SetUInt32Value(PLAYER_XP
,0);
3149 // reset level to summoned pet
3150 Pet
* pet
= player
->GetPet();
3151 if(pet
&& pet
->getPetType()==SUMMON_PET
)
3152 pet
->InitStatsForLevel(1);
3156 player
->InitStatsForLevel(player
->getLevel(),false);
3157 player
->InitTalentForLevel();
3160 else if (argstr
== "talents")
3161 player
->resetTalents(true);
3162 else if (argstr
== "spells")
3164 // make full copy of map (spells removed and marked as deleted at another spell remove
3165 // and we can't use original map for safe iterative with visit each spell at loop end
3166 PlayerSpellMap smap
= player
->GetSpellMap();
3168 for(PlayerSpellMap::const_iterator iter
= smap
.begin();iter
!= smap
.end(); ++iter
)
3169 player
->removeSpell(iter
->first
); // only iter->first can be accessed, object by iter->second can be deleted already
3171 PlayerInfo
const *info
= objmgr
.GetPlayerInfo(player
->getRace(),player
->getClass());
3172 std::list
<CreateSpellPair
>::const_iterator spell_itr
;
3173 for (spell_itr
= info
->spell
.begin(); spell_itr
!=info
->spell
.end(); spell_itr
++)
3175 uint16 tspell
= spell_itr
->first
;
3178 sLog
.outDebug("PLAYER: Adding initial spell, id = %u",tspell
);
3179 player
->learnSpell(tspell
);
3189 bool ChatHandler::HandleShutDownCommand(const char* args
)
3194 if(std::string(args
)=="cancel")
3196 sWorld
.ShutdownCancel();
3200 int32 time
= atoi(args
);
3202 ///- Prevent interpret wrong arg value as 0 secs shutdown time
3203 if(time
== 0 && (args
[0]!='0' || args
[1]!='\0') || time
< 0)
3206 sWorld
.ShutdownServ(time
);
3211 bool ChatHandler::HandleIdleShutDownCommand(const char* args
)
3216 if(std::string(args
)=="cancel")
3218 sWorld
.ShutdownCancel();
3222 int32 time
= atoi(args
);
3224 ///- Prevent interpret wrong arg value as 0 secs shutdown time
3225 if(time
== 0 && (args
[0]!='0' || args
[1]!='\0') || time
< 0)
3228 sWorld
.ShutdownServ(time
,true);
3233 bool ChatHandler::HandleAddQuest(const char* args
)
3235 Player
* player
= getSelectedPlayer();
3238 SendSysMessage(LANG_NO_CHAR_SELECTED
);
3242 // .addquest #entry'
3243 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
3244 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
3248 uint32 entry
= atol(cId
);
3250 ObjectMgr::QuestMap::iterator qIter
= objmgr
.QuestTemplates
.find(entry
);
3252 if(qIter
== objmgr
.QuestTemplates
.end())
3254 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
,entry
);
3258 // check item starting quest (it can work incorrectly if added without item in inventory)
3259 QueryResult
*result
= sDatabase
.PQuery("SELECT `entry` FROM `item_template` WHERE `startquest` = '%u' LIMIT 1",entry
);
3262 Field
* fields
= result
->Fetch();
3263 uint32 item_id
= fields
[0].GetUInt32();
3266 PSendSysMessage(LANG_COMMAND_QUEST_STARTFROMITEM
, entry
,item_id
);
3270 // ok, normal (creature/GO starting) quest
3271 Quest
* pQuest
= qIter
->second
;
3272 if( player
->CanAddQuest( pQuest
, true ) )
3274 player
->AddQuest( pQuest
, NULL
);
3276 if ( player
->CanCompleteQuest( entry
) )
3277 player
->CompleteQuest( entry
);
3283 bool ChatHandler::HandleRemoveQuest(const char* args
)
3285 Player
* player
= getSelectedPlayer();
3288 SendSysMessage(LANG_NO_CHAR_SELECTED
);
3292 // .removequest #entry'
3293 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
3294 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
3298 uint32 entry
= atol(cId
);
3300 ObjectMgr::QuestMap::iterator qIter
= objmgr
.QuestTemplates
.find(entry
);
3302 if(qIter
== objmgr
.QuestTemplates
.end())
3304 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
, entry
);
3308 // remove all quest entries for 'entry' from quest log
3309 for(uint8 slot
= 0; slot
< MAX_QUEST_LOG_SIZE
; ++slot
)
3311 uint32 quest
= player
->GetUInt32Value(PLAYER_QUEST_LOG_1_1
+ 3*slot
+ 0);
3314 player
->SetUInt32Value(PLAYER_QUEST_LOG_1_1
+ 3*slot
+ 0, 0);
3315 player
->SetUInt32Value(PLAYER_QUEST_LOG_1_1
+ 3*slot
+ 1, 0);
3316 player
->SetUInt32Value(PLAYER_QUEST_LOG_1_1
+ 3*slot
+ 2, 0);
3318 // we ignore unequippable quest items in this case, its' still be equipped
3319 player
->TakeQuestSourceItem( quest
, false );
3323 // set quest status to not started (will updated in DB at next save)
3324 player
->SetQuestStatus( entry
, QUEST_STATUS_NONE
);
3326 // reset rewarded for restart repeatable quest
3327 player
->getQuestStatusMap()[entry
].m_rewarded
= false;
3329 SendSysMessage(LANG_COMMAND_QUEST_REMOVED
);
3333 bool ChatHandler::HandleBanCommand(const char* args
)
3338 char* type
= strtok((char*)args
, " ");
3342 char* nameOrIP
= strtok(NULL
, " ");
3347 char* duration
= strtok(NULL
," ");
3350 if(!duration
|| !atoi(duration
))
3353 reason
= strtok(NULL
,"");
3357 if(sWorld
.BanAccount(type
, nameOrIP
, duration
, reason
,m_session
->GetPlayerName()))
3358 if(atoi(duration
)>0)
3359 PSendSysMessage(LANG_BAN_YOUBANNED
,nameOrIP
,secsToTimeString(TimeStringToSecs(duration
),true).c_str(),reason
);
3361 PSendSysMessage(LANG_BAN_YOUPERMBANNED
,nameOrIP
,reason
);
3363 PSendSysMessage(LANG_BAN_NOTFOUND
,type
,nameOrIP
);
3368 bool ChatHandler::HandleUnBanCommand(const char* args
)
3372 char* type
= strtok((char*)args
, " ");
3375 char* nameOrIP
= strtok(NULL
, " ");
3380 if(sWorld
.RemoveBanAccount(type
,nameOrIP
))
3381 PSendSysMessage(LANG_UNBAN_UNBANNED
,nameOrIP
);
3383 PSendSysMessage(LANG_UNBAN_ERROR
,nameOrIP
);
3388 bool ChatHandler::HandleBanInfoCommand(const char* args
)
3392 char* cType
= strtok((char*)args
, " ");
3393 char* cnameOrIP
= strtok(NULL
, "");
3394 if(!cType
|| !cnameOrIP
)
3396 std::string nameOrIP
= cnameOrIP
;
3397 std::string type
= cType
;
3398 if (!IsIPAddress(cnameOrIP
) && type
=="ip")
3400 loginDatabase
.escape_string(nameOrIP
);
3404 //look the accountid up
3406 std::string accountname
;
3407 if(type
== "account")
3409 QueryResult
*result
= loginDatabase
.PQuery("SELECT `id`, `username` FROM `account` WHERE `username` = '%s' ",nameOrIP
.c_str());
3412 PSendSysMessage(LANG_BANINFO_NOACCOUNT
);
3415 fields
= result
->Fetch();
3416 accountid
= fields
[0].GetUInt32();
3417 accountname
= fields
[1].GetCppString();
3420 else if(type
== "character")
3422 normalizePlayerName(nameOrIP
);
3423 QueryResult
*result
= sDatabase
.PQuery("SELECT account FROM `character` WHERE name = '%s')", nameOrIP
.c_str());
3426 PSendSysMessage(LANG_BANINFO_NOCHARACTER
);
3429 fields
= result
->Fetch();
3430 accountid
= fields
[0].GetUInt32();
3432 result
= loginDatabase
.PQuery("SELECT `username` FROM `account` WHERE `id` = '%u'", accountid
);
3435 PSendSysMessage(LANG_BANINFO_NOCHARACTER
);
3438 fields
= result
->Fetch();
3439 accountname
= fields
[0].GetCppString();
3445 QueryResult
*result
= loginDatabase
.PQuery("SELECT FROM_UNIXTIME(`bandate`), `unbandate`-`bandate`, `active`, `unbandate`-UNIX_TIMESTAMP(),`banreason`,`bannedby` FROM `account_banned` WHERE `id` = '%u' ORDER BY `bandate` ASC",accountid
);
3448 PSendSysMessage(LANG_BANINFO_NOACCOUNTBAN
, accountname
.c_str());
3451 PSendSysMessage(LANG_BANINFO_BANHISTORY
,accountname
.c_str());
3453 fields
= result
->Fetch();
3454 bool active
= false;
3455 if(fields
[2].GetBool() && (fields
[1].GetUInt64() == (uint64
)0 ||fields
[3].GetUInt64() >= (uint64
)0) )
3457 bool permanent
= (fields
[1].GetUInt64() == (uint64
)0);
3458 std::string bantime
= permanent
?LANG_BANINFO_INFINITE
:secsToTimeString(fields
[1].GetUInt64(), true);
3459 PSendSysMessage(LANG_BANINFO_HISTORYENTRY
,
3460 fields
[0].GetString(), bantime
.c_str(), active
? LANG_BANINFO_YES
:LANG_BANINFO_NO
, fields
[4].GetString(), fields
[5].GetString());
3461 }while (result
->NextRow());
3468 QueryResult
*result
= loginDatabase
.PQuery("SELECT `ip`, FROM_UNIXTIME(`bandate`), FROM_UNIXTIME(`unbandate`), `unbandate`-UNIX_TIMESTAMP(), `banreason`,`bannedby`,`unbandate`-`bandate` FROM `ip_banned` WHERE `ip` = '%s'",nameOrIP
.c_str());
3471 PSendSysMessage(LANG_BANINFO_NOIP
);
3474 fields
= result
->Fetch();
3475 bool permanent
= (fields
[6].GetUInt64()==(uint64
)0);
3476 PSendSysMessage(LANG_BANINFO_IPENTRY
,
3477 fields
[0].GetString(), fields
[1].GetString(), permanent
? LANG_BANINFO_NEVER
:fields
[2].GetString(),
3478 permanent
? LANG_BANINFO_INFINITE
:secsToTimeString(fields
[3].GetUInt64(), true).c_str(), fields
[4].GetString(), fields
[5].GetString());
3485 bool ChatHandler::HandleBanListCommand(const char* args
)
3487 loginDatabase
.Execute("DELETE FROM `ip_banned` WHERE `unbandate`<=UNIX_TIMESTAMP() AND `unbandate`<>`bandate`");
3490 char* cType
= strtok((char*)args
, " ");
3491 char* cFilter
= strtok(NULL
, "");
3492 if(!cType
|| !cFilter
)
3494 std::string Filter
= cFilter
;
3495 std::string Type
= cType
;
3496 loginDatabase
.escape_string(Filter
);
3499 QueryResult
* result
= NULL
;
3500 Field
*fields
= NULL
;
3503 result
= loginDatabase
.PQuery("SELECT `ip` FROM `ip_banned` WHERE `ip` LIKE \"%%%s%%\"",Filter
.c_str());
3506 PSendSysMessage(LANG_BANLIST_NOIP
);
3509 PSendSysMessage(LANG_BANLIST_MATCHINGIP
);
3512 fields
= result
->Fetch();
3513 PSendSysMessage("%s",fields
[0].GetString());
3514 } while (result
->NextRow());
3520 if(Type
== "account")
3522 result
= loginDatabase
.PQuery("SELECT `id` FROM `account` WHERE `username` LIKE \"%%%s%%\" ",Filter
.c_str());
3525 PSendSysMessage(LANG_BANLIST_NOACCOUNT
);
3528 //do not delete result
3530 else if(Type
== "character")
3532 result
= sDatabase
.PQuery("SELECT `account` FROM `character`, WHERE name LIKE \"%%%s%%\" ",Filter
.c_str());
3535 PSendSysMessage(LANG_BANLIST_NOCHARACTER
);
3542 PSendSysMessage(LANG_BANLIST_MATCHINGACCOUNT
);
3545 fields
= result
->Fetch();
3546 uint32 accountid
= fields
[0].GetUInt32();
3547 QueryResult
* banresult
= loginDatabase
.PQuery("SELECT `account`.`username` FROM `account`,`account_banned` WHERE `account_banned`.`id`='%u' AND `account_banned`.`active` = '1' AND `account_banned`.`id`=`account`.`id`",accountid
);
3550 Field
* fields2
= banresult
->Fetch();
3551 PSendSysMessage("%s",fields2
[0].GetString());
3554 } while (result
->NextRow());
3560 bool ChatHandler::HandleRespawnCommand(const char* args
)
3562 Player
* pl
= m_session
->GetPlayer();
3564 CellPair
p(MaNGOS::ComputeCellPair(pl
->GetPositionX(), pl
->GetPositionY()));
3565 Cell cell
= RedZone::GetZone(p
);
3566 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
3569 MaNGOS::RespawnDo u_do
;
3570 MaNGOS::WorldObjectWorker
<MaNGOS::RespawnDo
> worker(u_do
);
3572 TypeContainerVisitor
<MaNGOS::WorldObjectWorker
<MaNGOS::RespawnDo
>, GridTypeMapContainer
> obj_worker(worker
);
3573 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
3574 cell_lock
->Visit(cell_lock
, obj_worker
, *MapManager::Instance().GetMap(pl
->GetMapId(), pl
));
3579 bool ChatHandler::HandleFlyModeCommand(const char* args
)
3584 Unit
*unit
= getSelectedUnit();
3585 if (!unit
|| (unit
->GetTypeId() != TYPEID_PLAYER
))
3586 unit
= m_session
->GetPlayer();
3588 WorldPacket
data(12);
3589 if (strncmp(args
, "on", 3) == 0)
3590 data
.SetOpcode(SMSG_FLY_MODE_START
);
3591 else if (strncmp(args
, "off", 4) == 0)
3592 data
.SetOpcode(SMSG_FLY_MODE_STOP
);
3595 PSendSysMessage(LANG_COMMAND_FLYMODE_WRONGARG
);
3598 data
.append(unit
->GetPackGUID());
3599 data
<< uint32(0); // unk
3600 unit
->SendMessageToSet(&data
, true);
3601 PSendSysMessage(LANG_COMMAND_FLYMODE_STATUS
, unit
->GetName(), args
);
3605 bool ChatHandler::HandleSendOpcodeCommand(const char* args
)
3610 Unit
*unit
= getSelectedUnit();
3611 if (!unit
|| (unit
->GetTypeId() != TYPEID_PLAYER
))
3612 unit
= m_session
->GetPlayer();
3614 uint16 opcode
= atoi(args
);
3615 WorldPacket
data(opcode
, 20);
3616 data
.append(unit
->GetPackGUID());
3617 data
<< urand(0, 1024);
3618 data
<< urand(0, 1024);
3619 data
<< urand(0, 1024);
3620 unit
->SendMessageToSet(&data
, true);
3621 PSendSysMessage(LANG_COMMAND_OPCODESENT
, opcode
, unit
->GetName());
3625 bool ChatHandler::HandleSellErrorCommand(const char* args
)
3631 uint8 msg
= atoi(args
);
3632 WorldPacket
data( SMSG_SELL_ITEM
, (8+8+4+1) );
3638 m_session
->SendPacket(&data
);
3642 bool ChatHandler::HandleBuyErrorCommand(const char* args
)
3647 uint8 msg
= atoi(args
);
3648 WorldPacket
data( SMSG_BUY_FAILED
, (8+8+4+1) );
3649 data
<< m_session
->GetPlayer()->GetGUID();
3652 m_session
->SendPacket(&data
);
3656 bool ChatHandler::HandleUpdateWorldStateCommand(const char* args
)
3658 char* w
= strtok((char*)args
, " ");
3659 char* s
= strtok(NULL
, " ");
3664 uint32 world
= (uint32
)atoi(w
);
3665 uint32 state
= (uint32
)atoi(s
);
3666 m_session
->GetPlayer()->SendUpdateWorldState(world
, state
);
3670 bool ChatHandler::HandlePlaySound2Command(const char* args
)
3675 uint32 soundid
= atoi(args
);
3676 m_session
->GetPlayer()->PlaySound(soundid
, false);
3680 bool ChatHandler::HandleSendChannelNotifyCommand(const char* args
)
3685 const char *name
= "test";
3686 uint8 code
= atoi(args
);
3688 WorldPacket
data(SMSG_CHANNEL_NOTIFY
, (1+10));
3689 data
<< code
; // notify type
3690 data
<< name
; // channel name
3693 m_session
->SendPacket(&data
);
3697 bool ChatHandler::HandleSendChatMsgCommand(const char* args
)
3702 const char *msg
= "testtest";
3703 uint8 type
= atoi(args
);
3705 WorldPacket
data(SMSG_MESSAGECHAT
, 100);
3706 data
<< type
; // message type
3707 data
<< uint32(0); // lang
3708 data
<< m_session
->GetPlayer()->GetGUID(); // guid
3709 data
<< uint32(9); // msg len
3711 data
<< uint8(0); // chat tag
3712 m_session
->SendPacket(&data
);
3716 bool ChatHandler::HandleLoadPDumpCommand(const char *args
)
3721 char * file
= strtok((char*)args
, " "); if(!file
) return false;
3722 char * acc
= strtok(NULL
, " "); if(!acc
) return false;
3723 char * name
= strtok(NULL
, " ");
3724 char * guid
= name
? strtok(NULL
, " ") : NULL
;
3726 if(objmgr
.LoadPlayerDump(file
, atoi(acc
), name
? name
: "", guid
? atoi(guid
) : 0))
3727 PSendSysMessage(LANG_COMMAND_IMPORT_SUCCESS
);
3729 PSendSysMessage(LANG_COMMAND_IMPORT_FAILED
);
3734 bool ChatHandler::HandleWritePDumpCommand(const char *args
)
3739 char* file
= strtok((char*)args
, " ");
3740 char* guid
= strtok(NULL
, " ");
3742 if(!file
|| !guid
) return false;
3744 if (objmgr
.WritePlayerDump(file
, atoi(guid
)))
3745 PSendSysMessage(LANG_COMMAND_EXPORT_SUCCESS
);
3747 PSendSysMessage(LANG_COMMAND_EXPORT_FAILED
);