diff options
Diffstat (limited to 'src/game/Level1.cpp')
-rw-r--r-- | src/game/Level1.cpp | 514 |
1 files changed, 345 insertions, 169 deletions
diff --git a/src/game/Level1.cpp b/src/game/Level1.cpp index 1966bf6aa51..51829e504f0 100644 --- a/src/game/Level1.cpp +++ b/src/game/Level1.cpp @@ -1,7 +1,7 @@ /* - * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> + * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> * - * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> + * Copyright (C) 2008-2009 Trinity <http://www.trinitycore.org/> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -40,6 +40,7 @@ #include "VMapFactory.h" #endif +//-----------------------Npc Commands----------------------- bool ChatHandler::HandleNpcSayCommand(const char* args) { if(!*args) @@ -53,7 +54,7 @@ bool ChatHandler::HandleNpcSayCommand(const char* args) return false; } - pCreature->Say(args, LANG_UNIVERSAL, 0); + pCreature->MonsterSay(args, LANG_UNIVERSAL, 0); return true; } @@ -71,7 +72,7 @@ bool ChatHandler::HandleNpcYellCommand(const char* args) return false; } - pCreature->Yell(args, LANG_UNIVERSAL, 0); + pCreature->MonsterYell(args, LANG_UNIVERSAL, 0); return true; } @@ -91,7 +92,7 @@ bool ChatHandler::HandleNpcTextEmoteCommand(const char* args) return false; } - pCreature->TextEmote(args, 0); + pCreature->MonsterTextEmote(args, 0); return true; } @@ -115,18 +116,22 @@ bool ChatHandler::HandleNpcWhisperCommand(const char* args) uint64 receiver_guid= atol(receiver_str); - pCreature->Whisper(text,receiver_guid); + // check online security + if (HasLowerSecurity(objmgr.GetPlayer(receiver_guid), 0)) + return false; + + pCreature->MonsterWhisper(text,receiver_guid); return true; } +//---------------------------------------------------------- bool ChatHandler::HandleNameAnnounceCommand(const char* args) { WorldPacket data; if(!*args) return false; - //char str[1024]; - //sprintf(str, GetTrinityString(LANG_ANNOUNCE_COLOR), m_session->GetPlayer()->GetName(), args); + sWorld.SendWorldText(LANG_ANNOUNCE_COLOR, m_session->GetPlayer()->GetName(), args); return true; } @@ -194,7 +199,7 @@ bool ChatHandler::HandleGMNotifyCommand(const char* args) } //Enable\Dissable GM Mode -bool ChatHandler::HandleGMmodeCommand(const char* args) +bool ChatHandler::HandleGMCommand(const char* args) { if(!*args) { @@ -627,7 +632,7 @@ bool ChatHandler::HandleGMTicketReloadCommand(const char*) } //Enable\Dissable Invisible mode -bool ChatHandler::HandleVisibleCommand(const char* args) +bool ChatHandler::HandleGMVisibleCommand(const char* args) { if (!*args) { @@ -656,14 +661,16 @@ bool ChatHandler::HandleVisibleCommand(const char* args) return false; } + + bool ChatHandler::HandleGPSCommand(const char* args) { WorldObject *obj = NULL; if (*args) { - std::string name = args; - if(normalizePlayerName(name)) - obj = objmgr.GetPlayer(name.c_str()); + uint64 guid = extractGuidFromLink((char*)args); + if(guid) + obj = (WorldObject*)ObjectAccessor::GetObjectByTypeMask(*m_session->GetPlayer(),guid,TYPEMASK_UNIT|TYPEMASK_GAMEOBJECT); if(!obj) { @@ -686,8 +693,8 @@ bool ChatHandler::HandleGPSCommand(const char* args) CellPair cell_val = Trinity::ComputeCellPair(obj->GetPositionX(), obj->GetPositionY()); Cell cell(cell_val); - uint32 zone_id = obj->GetZoneId(); - uint32 area_id = obj->GetAreaId(); + uint32 zone_id, area_id; + obj->GetZoneAndAreaId(zone_id,area_id); MapEntry const* mapEntry = sMapStore.LookupEntry(obj->GetMapId()); AreaTableEntry const* zoneEntry = GetAreaEntryByAreaID(zone_id); @@ -714,22 +721,30 @@ bool ChatHandler::HandleGPSCommand(const char* args) obj->GetMapId(), (mapEntry ? mapEntry->name[m_session->GetSessionDbcLocale()] : "<unknown>" ), zone_id, (zoneEntry ? zoneEntry->area_name[m_session->GetSessionDbcLocale()] : "<unknown>" ), area_id, (areaEntry ? areaEntry->area_name[m_session->GetSessionDbcLocale()] : "<unknown>" ), + obj->GetPhaseMask(), obj->GetPositionX(), obj->GetPositionY(), obj->GetPositionZ(), obj->GetOrientation(), cell.GridX(), cell.GridY(), cell.CellX(), cell.CellY(), obj->GetInstanceId(), zone_x, zone_y, ground_z, floor_z, have_map, have_vmap ); sLog.outDebug("Player %s GPS call for %s '%s' (%s: %u):", - GetName(), + m_session ? GetNameLink().c_str() : GetMangosString(LANG_CONSOLE_COMMAND), (obj->GetTypeId() == TYPEID_PLAYER ? "player" : "creature"), obj->GetName(), (obj->GetTypeId() == TYPEID_PLAYER ? "GUID" : "Entry"), (obj->GetTypeId() == TYPEID_PLAYER ? obj->GetGUIDLow(): obj->GetEntry()) ); sLog.outDebug(GetTrinityString(LANG_MAP_POSITION), obj->GetMapId(), (mapEntry ? mapEntry->name[sWorld.GetDefaultDbcLocale()] : "<unknown>" ), zone_id, (zoneEntry ? zoneEntry->area_name[sWorld.GetDefaultDbcLocale()] : "<unknown>" ), area_id, (areaEntry ? areaEntry->area_name[sWorld.GetDefaultDbcLocale()] : "<unknown>" ), + obj->GetPhaseMask(), obj->GetPositionX(), obj->GetPositionY(), obj->GetPositionZ(), obj->GetOrientation(), cell.GridX(), cell.GridY(), cell.CellX(), cell.CellY(), obj->GetInstanceId(), zone_x, zone_y, ground_z, floor_z, have_map, have_vmap ); + LiquidData liquid_status; + ZLiquidStatus res = map->getLiquidStatus(obj->GetPositionX(), obj->GetPositionY(), obj->GetPositionZ(), MAP_ALL_LIQUIDS, &liquid_status); + if (res) + { + PSendSysMessage(LANG_LIQUID_STATUS, liquid_status.level, liquid_status.depth_level, liquid_status.type, res); + } return true; } @@ -739,9 +754,8 @@ bool ChatHandler::HandleNamegoCommand(const char* args) if(!*args) return false; - std::string name = args; - - if(!normalizePlayerName(name)) + std::string name = extractPlayerNameFromLink((char*)args); + if(name.empty()) { SendSysMessage(LANG_PLAYER_NOT_FOUND); SetSentErrorMessage(true); @@ -751,9 +765,14 @@ bool ChatHandler::HandleNamegoCommand(const char* args) Player *chr = objmgr.GetPlayer(name.c_str()); if (chr) { - if(chr->IsBeingTeleported()==true) + std::string nameLink = playerLink(name); + // check online security + if (HasLowerSecurity(chr, 0)) + return false; + + if(chr->IsBeingTeleported()) { - PSendSysMessage(LANG_IS_TELEPORTED, chr->GetName()); + PSendSysMessage(LANG_IS_TELEPORTED, nameLink.c_str()); SetSentErrorMessage(true); return false; } @@ -762,10 +781,25 @@ bool ChatHandler::HandleNamegoCommand(const char* args) if(pMap->IsBattleGroundOrArena()) { - // cannot summon to bg - PSendSysMessage(LANG_CANNOT_SUMMON_TO_BG,chr->GetName()); - SetSentErrorMessage(true); - return false; + // only allow if gm mode is on + if (!chr->isGameMaster()) + { + PSendSysMessage(LANG_CANNOT_GO_TO_BG_GM, nameLink.c_str()); + SetSentErrorMessage(true); + return false; + } + // if both players are in different bgs + else if (chr->GetBattleGroundId() && m_session->GetPlayer()->GetBattleGroundId() != chr->GetBattleGroundId()) + { + PSendSysMessage(LANG_CANNOT_GO_TO_BG_FROM_BG, nameLink.c_str()); + SetSentErrorMessage(true); + return false; + } + // all's well, set bg id + // when porting out from the bg, it will be reset to 0 + chr->SetBattleGroundId(m_session->GetPlayer()->GetBattleGroundId(), m_session->GetPlayer()->GetBattleGroundTypeId()); + // remember current position as entry point for return at bg end teleportation + chr->SetBattleGroundEntryPoint(chr->GetMapId(),chr->GetPositionX(),chr->GetPositionY(),chr->GetPositionZ(),chr->GetOrientation()); } else if(pMap->IsDungeon()) { @@ -773,7 +807,7 @@ bool ChatHandler::HandleNamegoCommand(const char* args) if( cMap->Instanceable() && cMap->GetInstanceId() != pMap->GetInstanceId() ) { // cannot summon from instance to instance - PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST,chr->GetName()); + PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST,nameLink.c_str()); SetSentErrorMessage(true); return false; } @@ -784,15 +818,15 @@ bool ChatHandler::HandleNamegoCommand(const char* args) (m_session->GetPlayer()->GetGroup()->GetLeaderGUID() != m_session->GetPlayer()->GetGUID()) ) // the last check is a bit excessive, but let it be, just in case { - PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST,chr->GetName()); + PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST,nameLink.c_str()); SetSentErrorMessage(true); return false; } } - PSendSysMessage(LANG_SUMMONING, chr->GetName(),""); + PSendSysMessage(LANG_SUMMONING, nameLink.c_str(),""); if (needReportToTarget(chr)) - ChatHandler(chr).PSendSysMessage(LANG_SUMMONED_BY, GetName()); + ChatHandler(chr).PSendSysMessage(LANG_SUMMONED_BY, GetNameLink().c_str()); // stop flight if need if(chr->isInFlight()) @@ -811,7 +845,13 @@ bool ChatHandler::HandleNamegoCommand(const char* args) } else if (uint64 guid = objmgr.GetPlayerGUIDByName(name)) { - PSendSysMessage(LANG_SUMMONING, name.c_str(),GetTrinityString(LANG_OFFLINE)); + // check offline security + if (HasLowerSecurity(NULL, guid)) + return false; + + std::string nameLink = playerLink(name); + + PSendSysMessage(LANG_SUMMONING, nameLink.c_str(),GetTrinityString(LANG_OFFLINE)); // in point where GM stay Player::SavePositionInDB(m_session->GetPlayer()->GetMapId(), @@ -839,9 +879,8 @@ bool ChatHandler::HandleGonameCommand(const char* args) Player* _player = m_session->GetPlayer(); - std::string name = args; - - if(!normalizePlayerName(name)) + std::string name = extractPlayerNameFromLink((char*)args); + if(name.empty()) { SendSysMessage(LANG_PLAYER_NOT_FOUND); SetSentErrorMessage(true); @@ -851,26 +890,34 @@ bool ChatHandler::HandleGonameCommand(const char* args) Player *chr = objmgr.GetPlayer(name.c_str()); if (chr) { + // check online security + if (HasLowerSecurity(chr, 0)) + return false; + + std::string chrNameLink = playerLink(name); + Map* cMap = chr->GetMap(); if(cMap->IsBattleGroundOrArena()) { // only allow if gm mode is on if (!_player->isGameMaster()) { - PSendSysMessage(LANG_CANNOT_GO_TO_BG_GM,chr->GetName()); + PSendSysMessage(LANG_CANNOT_GO_TO_BG_GM,chrNameLink.c_str()); SetSentErrorMessage(true); return false; } - // if already in a bg, don't let port to other - else if (_player->GetBattleGroundId()) + // if both players are in different bgs + else if (_player->GetBattleGroundId() && _player->GetBattleGroundId() != chr->GetBattleGroundId()) { - PSendSysMessage(LANG_CANNOT_GO_TO_BG_FROM_BG,chr->GetName()); + PSendSysMessage(LANG_CANNOT_GO_TO_BG_FROM_BG,chrNameLink.c_str()); SetSentErrorMessage(true); return false; } // all's well, set bg id // when porting out from the bg, it will be reset to 0 - _player->SetBattleGroundId(chr->GetBattleGroundId()); + _player->SetBattleGroundId(chr->GetBattleGroundId(), chr->GetBattleGroundTypeId()); + // remember current position as entry point for return at bg end teleportation + _player->SetBattleGroundEntryPoint(_player->GetMapId(),_player->GetPositionX(),_player->GetPositionY(),_player->GetPositionZ(),_player->GetOrientation()); } else if(cMap->IsDungeon()) { @@ -884,7 +931,7 @@ bool ChatHandler::HandleGonameCommand(const char* args) // we are in group, we can go only if we are in the player group if (_player->GetGroup() != chr->GetGroup()) { - PSendSysMessage(LANG_CANNOT_GO_TO_INST_PARTY,chr->GetName()); + PSendSysMessage(LANG_CANNOT_GO_TO_INST_PARTY,chrNameLink.c_str()); SetSentErrorMessage(true); return false; } @@ -894,7 +941,7 @@ bool ChatHandler::HandleGonameCommand(const char* args) // we are not in group, let's verify our GM mode if (!_player->isGameMaster()) { - PSendSysMessage(LANG_CANNOT_GO_TO_INST_GM,chr->GetName()); + PSendSysMessage(LANG_CANNOT_GO_TO_INST_GM,chrNameLink.c_str()); SetSentErrorMessage(true); return false; } @@ -918,10 +965,9 @@ bool ChatHandler::HandleGonameCommand(const char* args) _player->SetDifficulty(chr->GetDifficulty()); } - PSendSysMessage(LANG_APPEARING_AT, chr->GetName()); - + PSendSysMessage(LANG_APPEARING_AT, chrNameLink.c_str()); if (_player->IsVisibleGloballyFor(chr)) - ChatHandler(chr).PSendSysMessage(LANG_APPEARING_TO, _player->GetName()); + ChatHandler(chr).PSendSysMessage(LANG_APPEARING_TO, GetNameLink().c_str()); // stop flight if need if(_player->isInFlight()) @@ -944,7 +990,13 @@ bool ChatHandler::HandleGonameCommand(const char* args) if (uint64 guid = objmgr.GetPlayerGUIDByName(name)) { - PSendSysMessage(LANG_APPEARING_AT, name.c_str()); + // check offline security + if (HasLowerSecurity(NULL, guid)) + return false; + + std::string nameLink = playerLink(name); + + PSendSysMessage(LANG_APPEARING_AT, nameLink.c_str()); // to point where player stay (if loaded) float x,y,z,o; @@ -983,12 +1035,15 @@ bool ChatHandler::HandleRecallCommand(const char* args) chr = getSelectedPlayer(); if(!chr) chr = m_session->GetPlayer(); + + // check online security + else if (HasLowerSecurity(chr, 0)) + return false; } else { - std::string name = args; - - if(!normalizePlayerName(name)) + std::string name = extractPlayerNameFromLink((char*)args); + if(name.empty()) { SendSysMessage(LANG_PLAYER_NOT_FOUND); SetSentErrorMessage(true); @@ -1003,11 +1058,15 @@ bool ChatHandler::HandleRecallCommand(const char* args) SetSentErrorMessage(true); return false; } + + // check online security + if (HasLowerSecurity(chr, 0)) + return false; } if(chr->IsBeingTeleported()) { - PSendSysMessage(LANG_IS_TELEPORTED, chr->GetName()); + PSendSysMessage(LANG_IS_TELEPORTED, GetNameLink(chr).c_str()); SetSentErrorMessage(true); return false; } @@ -1041,6 +1100,10 @@ bool ChatHandler::HandleModifyKnownTitlesCommand(const char* args) return false; } + // check online security + if (HasLowerSecurity(chr, 0)) + return false; + uint64 titles2 = titles; for(int i=1; i < sCharTitlesStore.GetNumRows(); ++i) @@ -1090,9 +1153,13 @@ bool ChatHandler::HandleModifyHPCommand(const char* args) return false; } - PSendSysMessage(LANG_YOU_CHANGE_HP, chr->GetName(), hp, hpm); + // check online security + if (HasLowerSecurity(chr, 0)) + return false; + + PSendSysMessage(LANG_YOU_CHANGE_HP, GetNameLink(chr).c_str(), hp, hpm); if (needReportToTarget(chr)) - ChatHandler(chr).PSendSysMessage(LANG_YOURS_HP_CHANGED, GetName(), hp, hpm); + ChatHandler(chr).PSendSysMessage(LANG_YOURS_HP_CHANGED, GetNameLink().c_str(), hp, hpm); chr->SetMaxHealth( hpm ); chr->SetHealth( hp ); @@ -1134,9 +1201,13 @@ bool ChatHandler::HandleModifyManaCommand(const char* args) return false; } - PSendSysMessage(LANG_YOU_CHANGE_MANA, chr->GetName(), mana, manam); + // check online security + if (HasLowerSecurity(chr, 0)) + return false; + + PSendSysMessage(LANG_YOU_CHANGE_MANA, GetNameLink(chr).c_str(), mana, manam); if (needReportToTarget(chr)) - ChatHandler(chr).PSendSysMessage(LANG_YOURS_MANA_CHANGED, GetName(), mana, manam); + ChatHandler(chr).PSendSysMessage(LANG_YOURS_MANA_CHANGED, GetNameLink().c_str(), mana, manam); chr->SetMaxPower(POWER_MANA,manam ); chr->SetPower(POWER_MANA, mana ); @@ -1179,9 +1250,13 @@ bool ChatHandler::HandleModifyEnergyCommand(const char* args) return false; } - PSendSysMessage(LANG_YOU_CHANGE_ENERGY, chr->GetName(), energy/10, energym/10); + // check online security + if (HasLowerSecurity(chr, 0)) + return false; + + PSendSysMessage(LANG_YOU_CHANGE_ENERGY, GetNameLink(chr).c_str(), energy/10, energym/10); if (needReportToTarget(chr)) - ChatHandler(chr).PSendSysMessage(LANG_YOURS_ENERGY_CHANGED, GetName(), energy/10, energym/10); + ChatHandler(chr).PSendSysMessage(LANG_YOURS_ENERGY_CHANGED, GetNameLink().c_str(), energy/10, energym/10); chr->SetMaxPower(POWER_ENERGY,energym ); chr->SetPower(POWER_ENERGY, energy ); @@ -1226,9 +1301,13 @@ bool ChatHandler::HandleModifyRageCommand(const char* args) return false; } - PSendSysMessage(LANG_YOU_CHANGE_RAGE, chr->GetName(), rage/10, ragem/10); + // check online security + if (HasLowerSecurity(chr, 0)) + return false; + + PSendSysMessage(LANG_YOU_CHANGE_RAGE, GetNameLink(chr).c_str(), rage/10, ragem/10); if (needReportToTarget(chr)) - ChatHandler(chr).PSendSysMessage(LANG_YOURS_RAGE_CHANGED, GetName(), rage/10, ragem/10); + ChatHandler(chr).PSendSysMessage(LANG_YOURS_RAGE_CHANGED, GetNameLink().c_str(), rage/10, ragem/10); chr->SetMaxPower(POWER_RAGE,ragem ); chr->SetPower(POWER_RAGE, rage ); @@ -1236,6 +1315,40 @@ bool ChatHandler::HandleModifyRageCommand(const char* args) return true; } +// Edit Player Runic Power +bool ChatHandler::HandleModifyRunicPowerCommand(const char* args) +{ + if(!*args) + return false; + + int32 rune = atoi((char*)args)*10; + int32 runem = atoi((char*)args)*10; + + if (rune <= 0 || runem <= 0 || runem < rune) + { + SendSysMessage(LANG_BAD_VALUE); + SetSentErrorMessage(true); + return false; + } + + Player *chr = getSelectedPlayer(); + if (chr == NULL) + { + SendSysMessage(LANG_NO_CHAR_SELECTED); + SetSentErrorMessage(true); + return false; + } + + PSendSysMessage(LANG_YOU_CHANGE_RUNIC_POWER, GetNameLink(chr).c_str(), rune/10, runem/10); + if (needReportToTarget(chr)) + ChatHandler(chr).PSendSysMessage(LANG_YOURS_RUNIC_POWER_CHANGED, GetNameLink().c_str(), rune/10, runem/10); + + chr->SetMaxPower(POWER_RUNIC_POWER,runem ); + chr->SetPower(POWER_RUNIC_POWER, rune ); + + return true; +} + //Edit Player Faction bool ChatHandler::HandleModifyFactionCommand(const char* args) { @@ -1350,9 +1463,13 @@ bool ChatHandler::HandleModifySpellCommand(const char* args) return false; } - PSendSysMessage(LANG_YOU_CHANGE_SPELLFLATID, spellflatid, val, mark, chr->GetName()); + // check online security + if (HasLowerSecurity(chr, 0)) + return false; + + PSendSysMessage(LANG_YOU_CHANGE_SPELLFLATID, spellflatid, val, mark, GetNameLink(chr).c_str()); if (needReportToTarget(chr)) - ChatHandler(chr).PSendSysMessage(LANG_YOURS_SPELLFLATID_CHANGED, GetName(), spellflatid, val, mark); + ChatHandler(chr).PSendSysMessage(LANG_YOURS_SPELLFLATID_CHANGED, GetNameLink().c_str(), spellflatid, val, mark); WorldPacket data(SMSG_SET_FLAT_SPELL_MODIFIER, (1+1+2+2)); data << uint8(spellflatid); @@ -1380,6 +1497,11 @@ bool ChatHandler::HandleModifyTalentCommand (const char* args) SetSentErrorMessage(true); return false; } + + // check online security + if (HasLowerSecurity(player, 0)) + return false; + player->SetFreeTalentPoints(tp); return true; } @@ -1404,21 +1526,25 @@ bool ChatHandler::HandleTaxiCheatCommand(const char* args) chr=m_session->GetPlayer(); } + // check online security + else if (HasLowerSecurity(chr, 0)) + return false; + if (argstr == "on") { chr->SetTaxiCheater(true); - PSendSysMessage(LANG_YOU_GIVE_TAXIS, chr->GetName()); + PSendSysMessage(LANG_YOU_GIVE_TAXIS, GetNameLink(chr).c_str()); if (needReportToTarget(chr)) - ChatHandler(chr).PSendSysMessage(LANG_YOURS_TAXIS_ADDED, GetName()); + ChatHandler(chr).PSendSysMessage(LANG_YOURS_TAXIS_ADDED, GetNameLink().c_str()); return true; } if (argstr == "off") { chr->SetTaxiCheater(false); - PSendSysMessage(LANG_YOU_REMOVE_TAXIS, chr->GetName()); + PSendSysMessage(LANG_YOU_REMOVE_TAXIS, GetNameLink(chr).c_str()); if (needReportToTarget(chr)) - ChatHandler(chr).PSendSysMessage(LANG_YOURS_TAXIS_REMOVED, GetName()); + ChatHandler(chr).PSendSysMessage(LANG_YOURS_TAXIS_REMOVED, GetNameLink().c_str()); return true; } @@ -1451,16 +1577,22 @@ bool ChatHandler::HandleModifyASpeedCommand(const char* args) return false; } + // check online security + if (HasLowerSecurity(chr, 0)) + return false; + + std::string chrNameLink = GetNameLink(chr); + if(chr->isInFlight()) { - PSendSysMessage(LANG_CHAR_IN_FLIGHT,chr->GetName()); + PSendSysMessage(LANG_CHAR_IN_FLIGHT,chrNameLink.c_str()); SetSentErrorMessage(true); return false; } - PSendSysMessage(LANG_YOU_CHANGE_ASPEED, ASpeed, chr->GetName()); + PSendSysMessage(LANG_YOU_CHANGE_ASPEED, ASpeed, chrNameLink.c_str()); if (needReportToTarget(chr)) - ChatHandler(chr).PSendSysMessage(LANG_YOURS_ASPEED_CHANGED, GetName(), ASpeed); + ChatHandler(chr).PSendSysMessage(LANG_YOURS_ASPEED_CHANGED, GetNameLink().c_str(), ASpeed); chr->SetSpeed(MOVE_WALK, ASpeed,true); chr->SetSpeed(MOVE_RUN, ASpeed,true); @@ -1493,16 +1625,22 @@ bool ChatHandler::HandleModifySpeedCommand(const char* args) return false; } + // check online security + if (HasLowerSecurity(chr, 0)) + return false; + + std::string chrNameLink = GetNameLink(chr); + if(chr->isInFlight()) { - PSendSysMessage(LANG_CHAR_IN_FLIGHT,chr->GetName()); + PSendSysMessage(LANG_CHAR_IN_FLIGHT,chrNameLink.c_str()); SetSentErrorMessage(true); return false; } - PSendSysMessage(LANG_YOU_CHANGE_SPEED, Speed, chr->GetName()); + PSendSysMessage(LANG_YOU_CHANGE_SPEED, Speed, chrNameLink.c_str()); if (needReportToTarget(chr)) - ChatHandler(chr).PSendSysMessage(LANG_YOURS_SPEED_CHANGED, GetName(), Speed); + ChatHandler(chr).PSendSysMessage(LANG_YOURS_SPEED_CHANGED, GetNameLink().c_str(), Speed); chr->SetSpeed(MOVE_RUN,Speed,true); @@ -1532,16 +1670,22 @@ bool ChatHandler::HandleModifySwimCommand(const char* args) return false; } + // check online security + if (HasLowerSecurity(chr, 0)) + return false; + + std::string chrNameLink = GetNameLink(chr); + if(chr->isInFlight()) { - PSendSysMessage(LANG_CHAR_IN_FLIGHT,chr->GetName()); + PSendSysMessage(LANG_CHAR_IN_FLIGHT,chrNameLink.c_str()); SetSentErrorMessage(true); return false; } - PSendSysMessage(LANG_YOU_CHANGE_SWIM_SPEED, Swim, chr->GetName()); + PSendSysMessage(LANG_YOU_CHANGE_SWIM_SPEED, Swim, chrNameLink.c_str()); if (needReportToTarget(chr)) - ChatHandler(chr).PSendSysMessage(LANG_YOURS_SWIM_SPEED_CHANGED, GetName(), Swim); + ChatHandler(chr).PSendSysMessage(LANG_YOURS_SWIM_SPEED_CHANGED, GetNameLink().c_str(), Swim); chr->SetSpeed(MOVE_SWIM,Swim,true); @@ -1571,16 +1715,22 @@ bool ChatHandler::HandleModifyBWalkCommand(const char* args) return false; } + // check online security + if (HasLowerSecurity(chr, 0)) + return false; + + std::string chrNameLink = GetNameLink(chr); + if(chr->isInFlight()) { - PSendSysMessage(LANG_CHAR_IN_FLIGHT,chr->GetName()); + PSendSysMessage(LANG_CHAR_IN_FLIGHT,chrNameLink.c_str()); SetSentErrorMessage(true); return false; } - PSendSysMessage(LANG_YOU_CHANGE_BACK_SPEED, BSpeed, chr->GetName()); + PSendSysMessage(LANG_YOU_CHANGE_BACK_SPEED, BSpeed, chrNameLink.c_str()); if (needReportToTarget(chr)) - ChatHandler(chr).PSendSysMessage(LANG_YOURS_BACK_SPEED_CHANGED, GetName(), BSpeed); + ChatHandler(chr).PSendSysMessage(LANG_YOURS_BACK_SPEED_CHANGED, GetNameLink().c_str(), BSpeed); chr->SetSpeed(MOVE_RUN_BACK,BSpeed,true); @@ -1610,9 +1760,13 @@ bool ChatHandler::HandleModifyFlyCommand(const char* args) return false; } - PSendSysMessage(LANG_YOU_CHANGE_FLY_SPEED, FSpeed, chr->GetName()); + // check online security + if (HasLowerSecurity(chr, 0)) + return false; + + PSendSysMessage(LANG_YOU_CHANGE_FLY_SPEED, FSpeed, GetNameLink(chr).c_str()); if (needReportToTarget(chr)) - ChatHandler(chr).PSendSysMessage(LANG_YOURS_FLY_SPEED_CHANGED, GetName(), FSpeed); + ChatHandler(chr).PSendSysMessage(LANG_YOURS_FLY_SPEED_CHANGED, GetNameLink().c_str(), FSpeed); chr->SetSpeed(MOVE_FLIGHT,FSpeed,true); @@ -1641,9 +1795,13 @@ bool ChatHandler::HandleModifyScaleCommand(const char* args) return false; } - PSendSysMessage(LANG_YOU_CHANGE_SIZE, Scale, chr->GetName()); + // check online security + if (HasLowerSecurity(chr, 0)) + return false; + + PSendSysMessage(LANG_YOU_CHANGE_SIZE, Scale, GetNameLink(chr).c_str()); if (needReportToTarget(chr)) - ChatHandler(chr).PSendSysMessage(LANG_YOURS_SIZE_CHANGED, GetName(), Scale); + ChatHandler(chr).PSendSysMessage(LANG_YOURS_SIZE_CHANGED, GetNameLink().c_str(), Scale); chr->SetFloatValue(OBJECT_FIELD_SCALE_X, Scale); @@ -1884,9 +2042,13 @@ bool ChatHandler::HandleModifyMountCommand(const char* args) return false; } - PSendSysMessage(LANG_YOU_GIVE_MOUNT, chr->GetName()); + // check online security + if (HasLowerSecurity(chr, 0)) + return false; + + PSendSysMessage(LANG_YOU_GIVE_MOUNT, GetNameLink(chr).c_str()); if (needReportToTarget(chr)) - ChatHandler(chr).PSendSysMessage(LANG_MOUNT_GIVED, GetName()); + ChatHandler(chr).PSendSysMessage(LANG_MOUNT_GIVED, GetNameLink().c_str()); chr->SetUInt32Value( UNIT_FIELD_FLAGS , 0x001000 ); chr->Mount(mId); @@ -1921,6 +2083,10 @@ bool ChatHandler::HandleModifyMoneyCommand(const char* args) return false; } + // check online security + if (HasLowerSecurity(chr, 0)) + return false; + int32 addmoney = atoi((char*)args); uint32 moneyuser = chr->GetMoney(); @@ -1932,25 +2098,25 @@ bool ChatHandler::HandleModifyMoneyCommand(const char* args) sLog.outDetail(GetTrinityString(LANG_CURRENT_MONEY), moneyuser, addmoney, newmoney); if(newmoney <= 0 ) { - PSendSysMessage(LANG_YOU_TAKE_ALL_MONEY, chr->GetName()); + PSendSysMessage(LANG_YOU_TAKE_ALL_MONEY, GetNameLink(chr).c_str()); if (needReportToTarget(chr)) - ChatHandler(chr).PSendSysMessage(LANG_YOURS_ALL_MONEY_GONE, GetName()); + ChatHandler(chr).PSendSysMessage(LANG_YOURS_ALL_MONEY_GONE, GetNameLink().c_str()); chr->SetMoney(0); } else { - PSendSysMessage(LANG_YOU_TAKE_MONEY, abs(addmoney), chr->GetName()); + PSendSysMessage(LANG_YOU_TAKE_MONEY, abs(addmoney), GetNameLink(chr).c_str()); if (needReportToTarget(chr)) - ChatHandler(chr).PSendSysMessage(LANG_YOURS_MONEY_TAKEN, GetName(), abs(addmoney)); + ChatHandler(chr).PSendSysMessage(LANG_YOURS_MONEY_TAKEN, GetNameLink().c_str(), abs(addmoney)); chr->SetMoney( newmoney ); } } else { - PSendSysMessage(LANG_YOU_GIVE_MONEY, addmoney, chr->GetName()); + PSendSysMessage(LANG_YOU_GIVE_MONEY, addmoney, GetNameLink(chr).c_str()); if (needReportToTarget(chr)) - ChatHandler(chr).PSendSysMessage(LANG_YOURS_MONEY_GIVEN, GetName(), addmoney); + ChatHandler(chr).PSendSysMessage(LANG_YOURS_MONEY_GIVEN, GetNameLink().c_str(), addmoney); chr->ModifyMoney( addmoney ); } @@ -1959,20 +2125,24 @@ bool ChatHandler::HandleModifyMoneyCommand(const char* args) return true; } -//Edit Player field +//Edit Unit field bool ChatHandler::HandleModifyBitCommand(const char* args) { if( !*args ) return false; - Player *chr = getSelectedPlayer(); - if (chr == NULL) + Unit *unit = getSelectedUnit(); + if (!unit) { SendSysMessage(LANG_NO_CHAR_SELECTED); SetSentErrorMessage(true); return false; } + // check online security + if (unit->GetTypeId() == TYPEID_PLAYER && HasLowerSecurity((Player *)unit, 0)) + return false; + char* pField = strtok((char*)args, " "); if (!pField) return false; @@ -1984,13 +2154,12 @@ bool ChatHandler::HandleModifyBitCommand(const char* args) uint16 field = atoi(pField); uint32 bit = atoi(pBit); - if (field < 1 || field >= PLAYER_END) + if (field < OBJECT_END || field >= unit->GetValuesCount()) { SendSysMessage(LANG_BAD_VALUE); SetSentErrorMessage(true); return false; } - if (bit < 1 || bit > 32) { SendSysMessage(LANG_BAD_VALUE); @@ -1998,17 +2167,16 @@ bool ChatHandler::HandleModifyBitCommand(const char* args) return false; } - if ( chr->HasFlag( field, (1<<(bit-1)) ) ) + if ( unit->HasFlag( field, (1<<(bit-1)) ) ) { - chr->RemoveFlag( field, (1<<(bit-1)) ); + unit->RemoveFlag( field, (1<<(bit-1)) ); PSendSysMessage(LANG_REMOVE_BIT, bit, field); } else { - chr->SetFlag( field, (1<<(bit-1)) ); + unit->SetFlag( field, (1<<(bit-1)) ); PSendSysMessage(LANG_SET_BIT, bit, field); } - return true; } @@ -2025,11 +2193,15 @@ bool ChatHandler::HandleModifyHonorCommand (const char* args) return false; } + // check online security + if (HasLowerSecurity(target, 0)) + return false; + int32 amount = (uint32)atoi(args); target->ModifyHonorPoints(amount); - PSendSysMessage(LANG_COMMAND_MODIFY_HONOR, target->GetName(), target->GetHonorPoints()); + PSendSysMessage(LANG_COMMAND_MODIFY_HONOR, GetNameLink(target).c_str(), target->GetHonorPoints()); return true; } @@ -2132,8 +2304,10 @@ bool ChatHandler::HandleLookupAreaCommand(const char* args) } } } + if (counter == 0) // if counter == 0 then we found nth SendSysMessage (LANG_COMMAND_NOAREAFOUND); + return true; } @@ -2215,35 +2389,6 @@ bool ChatHandler::HandleWhispersCommand(const char* args) return false; } -//Play sound -bool ChatHandler::HandlePlaySoundCommand(const char* args) -{ - // USAGE: .debug playsound #soundid - // #soundid - ID decimal number from SoundEntries.dbc (1st column) - // this file have about 5000 sounds. - // In this realization only caller can hear this sound. - if( *args ) - { - uint32 dwSoundId = atoi((char*)args); - - if( !sSoundEntriesStore.LookupEntry(dwSoundId) ) - { - PSendSysMessage(LANG_SOUND_NOT_EXIST, dwSoundId); - SetSentErrorMessage(true); - return false; - } - - WorldPacket data(SMSG_PLAY_OBJECT_SOUND,4+8); - data << uint32(dwSoundId) << m_session->GetPlayer()->GetGUID(); - m_session->SendPacket(&data); - - PSendSysMessage(LANG_YOU_HEAR_SOUND, dwSoundId); - return true; - } - - return false; -} - //Save all players in the world bool ChatHandler::HandleSaveAllCommand(const char* /*args*/) { @@ -2260,9 +2405,13 @@ bool ChatHandler::HandleSendMailCommand(const char* args) // format: name "subject text" "mail text" - char* pName = strtok((char*)args, " "); - if(!pName) + std::string name = extractPlayerNameFromLink((char*)args); + if(name.empty()) + { + SendSysMessage(LANG_PLAYER_NOT_FOUND); + SetSentErrorMessage(true); return false; + } char* tail1 = strtok(NULL, ""); if(!tail1) @@ -2300,18 +2449,10 @@ bool ChatHandler::HandleSendMailCommand(const char* args) if (!msgText) return false; - // pName, msgSubject, msgText isn't NUL after prev. check - std::string name = pName; + // msgSubject, msgText isn't NUL after prev. check std::string subject = msgSubject; std::string text = msgText; - if(!normalizePlayerName(name)) - { - SendSysMessage(LANG_PLAYER_NOT_FOUND); - SetSentErrorMessage(true); - return false; - } - uint64 receiver_guid = objmgr.GetPlayerGUIDByName(name); if(!receiver_guid) { @@ -2320,7 +2461,6 @@ bool ChatHandler::HandleSendMailCommand(const char* args) return false; } - uint32 mailId = objmgr.GenerateMailID(); // from console show not existed sender uint32 sender_guidlo = m_session ? m_session->GetPlayer()->GetGUIDLow() : 0; @@ -2332,24 +2472,19 @@ bool ChatHandler::HandleSendMailCommand(const char* args) WorldSession::SendMailTo(receiver,messagetype, stationery, sender_guidlo, GUID_LOPART(receiver_guid), subject, itemTextId, NULL, 0, 0, MAIL_CHECK_MASK_NONE); - PSendSysMessage(LANG_MAIL_SENT, name.c_str()); + std::string nameLink = playerLink(name); + PSendSysMessage(LANG_MAIL_SENT, nameLink.c_str()); return true; } // teleport player to given game_tele.entry -bool ChatHandler::HandleNameTeleCommand(const char * args) +bool ChatHandler::HandleTeleNameCommand(const char * args) { if(!*args) return false; - char* pName = strtok((char*)args, " "); - - if(!pName) - return false; - - std::string name = pName; - - if(!normalizePlayerName(name)) + std::string name = extractPlayerNameFromLink((char*)args); + if(name.empty()) { SendSysMessage(LANG_PLAYER_NOT_FOUND); SetSentErrorMessage(true); @@ -2380,17 +2515,22 @@ bool ChatHandler::HandleNameTeleCommand(const char * args) Player *chr = objmgr.GetPlayer(name.c_str()); if (chr) { + // check online security + if (HasLowerSecurity(chr, 0)) + return false; + + std::string chrNameLink = playerLink(name); if(chr->IsBeingTeleported()==true) { - PSendSysMessage(LANG_IS_TELEPORTED, chr->GetName()); + PSendSysMessage(LANG_IS_TELEPORTED, chrNameLink.c_str()); SetSentErrorMessage(true); return false; } - PSendSysMessage(LANG_TELEPORTING_TO, chr->GetName(),"", tele->name.c_str()); + PSendSysMessage(LANG_TELEPORTING_TO, chrNameLink.c_str(),"", tele->name.c_str()); if (needReportToTarget(chr)) - ChatHandler(chr).PSendSysMessage(LANG_TELEPORTED_TO_BY, GetName()); + ChatHandler(chr).PSendSysMessage(LANG_TELEPORTED_TO_BY, GetNameLink().c_str()); // stop flight if need if(chr->isInFlight()) @@ -2404,10 +2544,17 @@ bool ChatHandler::HandleNameTeleCommand(const char * args) chr->TeleportTo(tele->mapId,tele->position_x,tele->position_y,tele->position_z,tele->orientation); } - else if (uint64 guid = objmgr.GetPlayerGUIDByName(name.c_str())) + else if (uint64 guid = objmgr.GetPlayerGUIDByName(name)) { - PSendSysMessage(LANG_TELEPORTING_TO, name.c_str(), GetTrinityString(LANG_OFFLINE), tele->name.c_str()); - Player::SavePositionInDB(tele->mapId,tele->position_x,tele->position_y,tele->position_z,tele->orientation,MapManager::Instance().GetZoneId(tele->mapId,tele->position_x,tele->position_y),guid); + // check offline security + if (HasLowerSecurity(NULL, guid)) + return false; + + std::string nameLink = playerLink(name); + + PSendSysMessage(LANG_TELEPORTING_TO, nameLink.c_str(), GetMangosString(LANG_OFFLINE), tele->name.c_str()); + Player::SavePositionInDB(tele->mapId,tele->position_x,tele->position_y,tele->position_z,tele->orientation, + MapManager::Instance().GetZoneId(tele->mapId,tele->position_x,tele->position_y,tele->position_z),guid); } else PSendSysMessage(LANG_NO_PLAYER, name.c_str()); @@ -2416,7 +2563,7 @@ bool ChatHandler::HandleNameTeleCommand(const char * args) } //Teleport group to given game_tele.entry -bool ChatHandler::HandleGroupTeleCommand(const char * args) +bool ChatHandler::HandleTeleGroupCommand(const char * args) { if(!*args) return false; @@ -2429,6 +2576,10 @@ bool ChatHandler::HandleGroupTeleCommand(const char * args) return false; } + // check online security + if (HasLowerSecurity(player, 0)) + return false; + // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r GameTele const* tele = extractGameTeleFromLink((char*)args); if(!tele) @@ -2445,10 +2596,13 @@ bool ChatHandler::HandleGroupTeleCommand(const char * args) SetSentErrorMessage(true); return false; } + + std::string nameLink = GetNameLink(player); + Group *grp = player->GetGroup(); if(!grp) { - PSendSysMessage(LANG_NOT_IN_GROUP,player->GetName()); + PSendSysMessage(LANG_NOT_IN_GROUP,nameLink.c_str()); SetSentErrorMessage(true); return false; } @@ -2460,15 +2614,21 @@ bool ChatHandler::HandleGroupTeleCommand(const char * args) if(!pl || !pl->GetSession() ) continue; + // check online security + if (HasLowerSecurity(pl, 0)) + return false; + + std::string plNameLink = GetNameLink(pl); + if(pl->IsBeingTeleported()) { - PSendSysMessage(LANG_IS_TELEPORTED, pl->GetName()); + PSendSysMessage(LANG_IS_TELEPORTED, plNameLink.c_str()); continue; } - PSendSysMessage(LANG_TELEPORTING_TO, pl->GetName(),"", tele->name.c_str()); + PSendSysMessage(LANG_TELEPORTING_TO, plNameLink.c_str(),"", tele->name.c_str()); if (needReportToTarget(pl)) - ChatHandler(pl).PSendSysMessage(LANG_TELEPORTED_TO_BY, GetName()); + ChatHandler(pl).PSendSysMessage(LANG_TELEPORTED_TO_BY, nameLink.c_str()); // stop flight if need if(pl->isInFlight()) @@ -2492,9 +2652,8 @@ bool ChatHandler::HandleGroupgoCommand(const char* args) if(!*args) return false; - std::string name = args; - - if(!normalizePlayerName(name)) + std::string name = extractPlayerNameFromLink((char*)args); + if(name.empty()) { SendSysMessage(LANG_PLAYER_NOT_FOUND); SetSentErrorMessage(true); @@ -2509,16 +2668,22 @@ bool ChatHandler::HandleGroupgoCommand(const char* args) return false; } + // check online security + if (HasLowerSecurity(player, 0)) + return false; + Group *grp = player->GetGroup(); + std::string nameLink = playerLink(name); + if(!grp) { - PSendSysMessage(LANG_NOT_IN_GROUP,player->GetName()); + PSendSysMessage(LANG_NOT_IN_GROUP,nameLink.c_str()); SetSentErrorMessage(true); return false; } - Map* gmMap = MapManager::Instance().GetMap(m_session->GetPlayer()->GetMapId(),m_session->GetPlayer()); + Map* gmMap = m_session->GetPlayer()->GetMap(); bool to_instance = gmMap->Instanceable(); // we are in instance, and can summon only player in our group with us as lead @@ -2539,29 +2704,35 @@ bool ChatHandler::HandleGroupgoCommand(const char* args) if(!pl || pl==m_session->GetPlayer() || !pl->GetSession() ) continue; + // check online security + if (HasLowerSecurity(pl, 0)) + return false; + + std::string plNameLink = playerLink(pl->GetName()); + if(pl->IsBeingTeleported()==true) { - PSendSysMessage(LANG_IS_TELEPORTED, pl->GetName()); + PSendSysMessage(LANG_IS_TELEPORTED, plNameLink.c_str()); SetSentErrorMessage(true); return false; } if (to_instance) { - Map* plMap = MapManager::Instance().GetMap(pl->GetMapId(),pl); + Map* plMap = pl->GetMap(); if ( plMap->Instanceable() && plMap->GetInstanceId() != gmMap->GetInstanceId() ) { // cannot summon from instance to instance - PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST,pl->GetName()); + PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST,plNameLink.c_str()); SetSentErrorMessage(true); return false; } } - PSendSysMessage(LANG_SUMMONING, pl->GetName(),""); + PSendSysMessage(LANG_SUMMONING, plNameLink.c_str(),""); if (needReportToTarget(pl)) - ChatHandler(pl).PSendSysMessage(LANG_SUMMONED_BY, GetName()); + ChatHandler(pl).PSendSysMessage(LANG_SUMMONED_BY, GetNameLink().c_str()); // stop flight if need if(pl->isInFlight()) @@ -2695,6 +2866,11 @@ bool ChatHandler::HandleGoZoneXYCommand(const char* args) float x = (float)atof(px); float y = (float)atof(py); + + // prevent accept wrong numeric args + if (x==0.0f && *px!='0' || y==0.0f && *py!='0') + return false; + uint32 areaid = cAreaId ? (uint32)atoi(cAreaId) : _player->GetZoneId(); AreaTableEntry const* areaEntry = GetAreaEntryByAreaID(areaid); @@ -2791,7 +2967,7 @@ bool ChatHandler::HandleGoGridCommand(const char* args) return true; } -bool ChatHandler::HandleDrunkCommand(const char* args) +bool ChatHandler::HandleModifyDrunkCommand(const char* args) { if(!*args) return false; |