diff options
author | Nay <dnpd.dd@gmail.com> | 2013-07-13 23:07:01 +0100 |
---|---|---|
committer | Nay <dnpd.dd@gmail.com> | 2013-07-13 23:07:01 +0100 |
commit | d6f3460796c3326d3d9aa64bc90de2b14afb0c48 (patch) | |
tree | d2bbc9963eee6a25ae63ebe1a284490e40416938 | |
parent | 330dd624b6f979df9bae087a7fc2e55fdc9ee360 (diff) |
Script/Commands: Fix a crash in .arena captain command
-rw-r--r-- | src/server/game/Globals/ObjectMgr.cpp | 2 | ||||
-rw-r--r-- | src/server/game/Globals/ObjectMgr.h | 14 | ||||
-rw-r--r-- | src/server/scripts/Commands/cs_arena.cpp | 26 |
3 files changed, 28 insertions, 14 deletions
diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp index 6a4bbcc4388..7393fb825c9 100644 --- a/src/server/game/Globals/ObjectMgr.cpp +++ b/src/server/game/Globals/ObjectMgr.cpp @@ -2000,7 +2000,7 @@ uint64 ObjectMgr::GetPlayerGUIDByName(std::string const& name) const return guid; } -bool ObjectMgr::GetPlayerNameByGUID(uint64 guid, std::string &name) const +bool ObjectMgr::GetPlayerNameByGUID(uint64 guid, std::string& name) const { // prevent DB access for online player if (Player* player = ObjectAccessor::FindPlayer(guid)) diff --git a/src/server/game/Globals/ObjectMgr.h b/src/server/game/Globals/ObjectMgr.h index 266fe8ee35c..1c986e2e48a 100644 --- a/src/server/game/Globals/ObjectMgr.h +++ b/src/server/game/Globals/ObjectMgr.h @@ -716,7 +716,19 @@ class ObjectMgr void GetPlayerLevelInfo(uint32 race, uint32 class_, uint8 level, PlayerLevelInfo* info) const; uint64 GetPlayerGUIDByName(std::string const& name) const; - bool GetPlayerNameByGUID(uint64 guid, std::string &name) const; + + /** + * Retrieves the player name by guid. + * + * If the player is online, the name is retrieved immediately otherwise + * a database query is done. + * + * @param guid player full guid + * @param name returned name + * + * @return true if player was found, false otherwise + */ + bool GetPlayerNameByGUID(uint64 guid, std::string& name) const; uint32 GetPlayerTeamByGUID(uint64 guid) const; uint32 GetPlayerAccountIdByGUID(uint64 guid) const; uint32 GetPlayerAccountIdByPlayerName(std::string const& name) const; diff --git a/src/server/scripts/Commands/cs_arena.cpp b/src/server/scripts/Commands/cs_arena.cpp index b631bab0764..b6a1b27b830 100644 --- a/src/server/scripts/Commands/cs_arena.cpp +++ b/src/server/scripts/Commands/cs_arena.cpp @@ -228,9 +228,9 @@ public: if (!handler->extractPlayerTarget(nameStr, &target, &targetGuid)) return false; - ArenaTeam* Arena = sArenaTeamMgr->GetArenaTeamById(teamId); + ArenaTeam* arena = sArenaTeamMgr->GetArenaTeamById(teamId); - if (!Arena) + if (!arena) { handler->PSendSysMessage(LANG_ARENA_ERROR_NOT_FOUND, teamId); handler->SetSentErrorMessage(true); @@ -244,36 +244,38 @@ public: return false; } - if (Arena->IsFighting()) + if (arena->IsFighting()) { handler->SendSysMessage(LANG_ARENA_ERROR_COMBAT); handler->SetSentErrorMessage(true); return false; } - if (!Arena->IsMember(targetGuid)) + if (!arena->IsMember(targetGuid)) { - handler->PSendSysMessage(LANG_ARENA_ERROR_NOT_MEMBER, nameStr, Arena->GetName().c_str()); + handler->PSendSysMessage(LANG_ARENA_ERROR_NOT_MEMBER, nameStr, arena->GetName().c_str()); handler->SetSentErrorMessage(true); return false; } - if (Arena->GetCaptain() == targetGuid) + if (arena->GetCaptain() == targetGuid) { - handler->PSendSysMessage(LANG_ARENA_ERROR_CAPTAIN, nameStr, Arena->GetName().c_str()); + handler->PSendSysMessage(LANG_ARENA_ERROR_CAPTAIN, nameStr, arena->GetName().c_str()); handler->SetSentErrorMessage(true); return false; } - Player* oldCaptain = sObjectMgr->GetPlayerByLowGUID(Arena->GetCaptain()); - Arena->SetCaptain(targetGuid); - handler->PSendSysMessage(LANG_ARENA_CAPTAIN, Arena->GetName().c_str(), Arena->GetId(), oldCaptain->GetName().c_str(), target->GetName().c_str()); + std::string oldCaptainName; + sObjectMgr->GetPlayerNameByGUID(arena->GetCaptain(), oldCaptainName); + arena->SetCaptain(targetGuid); + + handler->PSendSysMessage(LANG_ARENA_CAPTAIN, arena->GetName().c_str(), arena->GetId(), oldCaptainName.c_str(), target->GetName().c_str()); if (handler->GetSession()) TC_LOG_DEBUG(LOG_FILTER_ARENAS, "GameMaster: %s [GUID: %u] promoted player: %s [GUID: %u] to leader of arena team \"%s\"[Id: %u]", - handler->GetSession()->GetPlayer()->GetName().c_str(), handler->GetSession()->GetPlayer()->GetGUIDLow(), target->GetName().c_str(), target->GetGUIDLow(), Arena->GetName().c_str(), Arena->GetId()); + handler->GetSession()->GetPlayer()->GetName().c_str(), handler->GetSession()->GetPlayer()->GetGUIDLow(), target->GetName().c_str(), target->GetGUIDLow(), arena->GetName().c_str(), arena->GetId()); else TC_LOG_DEBUG(LOG_FILTER_ARENAS, "Console: promoted player: %s [GUID: %u] to leader of arena team \"%s\"[Id: %u]", - target->GetName().c_str(), target->GetGUIDLow(), Arena->GetName().c_str(), Arena->GetId()); + target->GetName().c_str(), target->GetGUIDLow(), arena->GetName().c_str(), arena->GetId()); return true; } |