diff options
author | Spp <spp@jorge.gr> | 2012-10-29 12:28:12 +0100 |
---|---|---|
committer | Spp <spp@jorge.gr> | 2012-10-29 12:28:12 +0100 |
commit | d2ba73d97f12da64b76895b7335500d1fc993a37 (patch) | |
tree | 35d6fda15598df1192b97634c217a34c63896dd0 /src/server/game/Handlers/CharacterHandler.cpp | |
parent | c5c8e38789f40ecf15f82cad789f2e0273557c34 (diff) |
Core/Misc: Proper fix for previous commit (c5c8e38 - check race change before perfoming faction-change actions)
Core/Misc: tab to spaces and remove trailing whitespaces
Diffstat (limited to 'src/server/game/Handlers/CharacterHandler.cpp')
-rw-r--r-- | src/server/game/Handlers/CharacterHandler.cpp | 614 |
1 files changed, 307 insertions, 307 deletions
diff --git a/src/server/game/Handlers/CharacterHandler.cpp b/src/server/game/Handlers/CharacterHandler.cpp index f14e9cc8e8d..967ddd9c75b 100644 --- a/src/server/game/Handlers/CharacterHandler.cpp +++ b/src/server/game/Handlers/CharacterHandler.cpp @@ -1648,7 +1648,7 @@ void WorldSession::HandleCharFactionOrRaceChange(WorldPacket& recv_data) uint32 used_loginFlag = ((recv_data.GetOpcode() == CMSG_CHAR_RACE_CHANGE) ? AT_LOGIN_CHANGE_RACE : AT_LOGIN_CHANGE_FACTION); if (!sObjectMgr->GetPlayerInfo(race, playerClass)) - { + {ops.. WorldPacket data(SMSG_CHAR_FACTION_CHANGE, 1); data << uint8(CHAR_CREATE_ERROR); SendPacket(&data); @@ -1731,387 +1731,387 @@ void WorldSession::HandleCharFactionOrRaceChange(WorldPacket& recv_data) sWorld->UpdateCharacterNameData(GUID_LOPART(guid), newname, gender, race); - if (oldRace == race) - return; - - TeamId team = TEAM_ALLIANCE; - - // Search each faction is targeted - switch (race) + if (oldRace != race) { - case RACE_ORC: - case RACE_TAUREN: - case RACE_UNDEAD_PLAYER: - case RACE_TROLL: - case RACE_BLOODELF: - team = TEAM_HORDE; - break; - default: - break; - } - - // Switch Languages - // delete all languages first - stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHAR_SKILL_LANGUAGES); - stmt->setUInt32(0, lowGuid); - trans->Append(stmt); - - // Now add them back - stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_CHAR_SKILL_LANGUAGE); - stmt->setUInt32(0, lowGuid); - - // Faction specific languages - if (team == TEAM_HORDE) - stmt->setUInt16(1, 109); - else - stmt->setUInt16(1, 98); - - trans->Append(stmt); - - // Race specific languages - if (race != RACE_ORC && race != RACE_HUMAN) - { - stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_CHAR_SKILL_LANGUAGE); - stmt->setUInt32(0, lowGuid); + TeamId team = TEAM_ALLIANCE; + // Search each faction is targeted switch (race) { - case RACE_DWARF: - stmt->setUInt16(1, 111); - break; - case RACE_DRAENEI: - stmt->setUInt16(1, 759); - break; - case RACE_GNOME: - stmt->setUInt16(1, 313); - break; - case RACE_NIGHTELF: - stmt->setUInt16(1, 113); - break; - case RACE_UNDEAD_PLAYER: - stmt->setUInt16(1, 673); - break; + case RACE_ORC: case RACE_TAUREN: - stmt->setUInt16(1, 115); - break; + case RACE_UNDEAD_PLAYER: case RACE_TROLL: - stmt->setUInt16(1, 315); - break; case RACE_BLOODELF: - stmt->setUInt16(1, 137); + team = TEAM_HORDE; + break; + default: break; } + // Switch Languages + // delete all languages first + stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHAR_SKILL_LANGUAGES); + stmt->setUInt32(0, lowGuid); trans->Append(stmt); - } - if (recv_data.GetOpcode() == CMSG_CHAR_FACTION_CHANGE) - { - // Delete all Flypaths - PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_CHAR_TAXI_PATH); + // Now add them back + stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_CHAR_SKILL_LANGUAGE); stmt->setUInt32(0, lowGuid); + + // Faction specific languages + if (team == TEAM_HORDE) + stmt->setUInt16(1, 109); + else + stmt->setUInt16(1, 98); + trans->Append(stmt); - if (level > 7) + // Race specific languages + if (race != RACE_ORC && race != RACE_HUMAN) { - // Update Taxi path - // this doesn't seem to be 100% blizzlike... but it can't really be helped. - std::ostringstream taximaskstream; - uint32 numFullTaximasks = level / 7; - if (numFullTaximasks > 11) - numFullTaximasks = 11; - if (team == TEAM_ALLIANCE) - { - if (playerClass != CLASS_DEATH_KNIGHT) - { - for (uint8 i = 0; i < numFullTaximasks; ++i) - taximaskstream << uint32(sAllianceTaxiNodesMask[i]) << ' '; - } - else - { - for (uint8 i = 0; i < numFullTaximasks; ++i) - taximaskstream << uint32(sAllianceTaxiNodesMask[i] | sDeathKnightTaxiNodesMask[i]) << ' '; - } - } - else + stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_CHAR_SKILL_LANGUAGE); + stmt->setUInt32(0, lowGuid); + + switch (race) { - if (playerClass != CLASS_DEATH_KNIGHT) - { - for (uint8 i = 0; i < numFullTaximasks; ++i) - taximaskstream << uint32(sHordeTaxiNodesMask[i]) << ' '; - } - else - { - for (uint8 i = 0; i < numFullTaximasks; ++i) - taximaskstream << uint32(sHordeTaxiNodesMask[i] | sDeathKnightTaxiNodesMask[i]) << ' '; - } + case RACE_DWARF: + stmt->setUInt16(1, 111); + break; + case RACE_DRAENEI: + stmt->setUInt16(1, 759); + break; + case RACE_GNOME: + stmt->setUInt16(1, 313); + break; + case RACE_NIGHTELF: + stmt->setUInt16(1, 113); + break; + case RACE_UNDEAD_PLAYER: + stmt->setUInt16(1, 673); + break; + case RACE_TAUREN: + stmt->setUInt16(1, 115); + break; + case RACE_TROLL: + stmt->setUInt16(1, 315); + break; + case RACE_BLOODELF: + stmt->setUInt16(1, 137); + break; } - uint32 numEmptyTaximasks = 11 - numFullTaximasks; - for (uint8 i = 0; i < numEmptyTaximasks; ++i) - taximaskstream << "0 "; - taximaskstream << '0'; - std::string taximask = taximaskstream.str(); - - PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_CHAR_TAXIMASK); - stmt->setString(0, taximask); - stmt->setUInt32(1, lowGuid); trans->Append(stmt); } - // Delete all current quests - stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHAR_QUESTSTATUS); - stmt->setUInt32(0, GUID_LOPART(guid)); - trans->Append(stmt); - - // Delete record of the faction old completed quests + if (recv_data.GetOpcode() == CMSG_CHAR_FACTION_CHANGE) { - std::ostringstream quests; - ObjectMgr::QuestMap const& qTemplates = sObjectMgr->GetQuestTemplates(); - for (ObjectMgr::QuestMap::const_iterator iter = qTemplates.begin(); iter != qTemplates.end(); ++iter) + // Delete all Flypaths + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_CHAR_TAXI_PATH); + stmt->setUInt32(0, lowGuid); + trans->Append(stmt); + + if (level > 7) { - Quest *qinfo = iter->second; - uint32 requiredRaces = qinfo->GetRequiredRaces(); + // Update Taxi path + // this doesn't seem to be 100% blizzlike... but it can't really be helped. + std::ostringstream taximaskstream; + uint32 numFullTaximasks = level / 7; + if (numFullTaximasks > 11) + numFullTaximasks = 11; if (team == TEAM_ALLIANCE) { - if (requiredRaces & RACEMASK_ALLIANCE) + if (playerClass != CLASS_DEATH_KNIGHT) { - quests << uint32(qinfo->GetQuestId()); - quests << ','; + for (uint8 i = 0; i < numFullTaximasks; ++i) + taximaskstream << uint32(sAllianceTaxiNodesMask[i]) << ' '; + } + else + { + for (uint8 i = 0; i < numFullTaximasks; ++i) + taximaskstream << uint32(sAllianceTaxiNodesMask[i] | sDeathKnightTaxiNodesMask[i]) << ' '; } } - else // if (team == TEAM_HORDE) + else { - if (requiredRaces & RACEMASK_HORDE) + if (playerClass != CLASS_DEATH_KNIGHT) { - quests << uint32(qinfo->GetQuestId()); - quests << ','; + for (uint8 i = 0; i < numFullTaximasks; ++i) + taximaskstream << uint32(sHordeTaxiNodesMask[i]) << ' '; + } + else + { + for (uint8 i = 0; i < numFullTaximasks; ++i) + taximaskstream << uint32(sHordeTaxiNodesMask[i] | sDeathKnightTaxiNodesMask[i]) << ' '; } } - } - std::string questsStr = quests.str(); - questsStr = questsStr.substr(0, questsStr.length() - 1); + uint32 numEmptyTaximasks = 11 - numFullTaximasks; + for (uint8 i = 0; i < numEmptyTaximasks; ++i) + taximaskstream << "0 "; + taximaskstream << '0'; + std::string taximask = taximaskstream.str(); - if (!questsStr.empty()) - trans->PAppend("DELETE FROM `character_queststatus_rewarded` WHERE guid='%u' AND quest IN (%s)", lowGuid, questsStr.c_str()); - } + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_CHAR_TAXIMASK); + stmt->setString(0, taximask); + stmt->setUInt32(1, lowGuid); + trans->Append(stmt); + } - if (!sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GUILD)) - { - // Reset guild - PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_GUILD_MEMBER); + // Delete all current quests + stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHAR_QUESTSTATUS); + stmt->setUInt32(0, GUID_LOPART(guid)); + trans->Append(stmt); - stmt->setUInt32(0, lowGuid); + // Delete record of the faction old completed quests + { + std::ostringstream quests; + ObjectMgr::QuestMap const& qTemplates = sObjectMgr->GetQuestTemplates(); + for (ObjectMgr::QuestMap::const_iterator iter = qTemplates.begin(); iter != qTemplates.end(); ++iter) + { + Quest *qinfo = iter->second; + uint32 requiredRaces = qinfo->GetRequiredRaces(); + if (team == TEAM_ALLIANCE) + { + if (requiredRaces & RACEMASK_ALLIANCE) + { + quests << uint32(qinfo->GetQuestId()); + quests << ','; + } + } + else // if (team == TEAM_HORDE) + { + if (requiredRaces & RACEMASK_HORDE) + { + quests << uint32(qinfo->GetQuestId()); + quests << ','; + } + } + } - PreparedQueryResult result = CharacterDatabase.Query(stmt); - if (result) - if (Guild* guild = sGuildMgr->GetGuildById((result->Fetch()[0]).GetUInt32())) - guild->DeleteMember(MAKE_NEW_GUID(lowGuid, 0, HIGHGUID_PLAYER)); - } + std::string questsStr = quests.str(); + questsStr = questsStr.substr(0, questsStr.length() - 1); - if (!sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_ADD_FRIEND)) - { - // Delete Friend List - PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHAR_SOCIAL_BY_GUID); - stmt->setUInt32(0, lowGuid); - trans->Append(stmt); + if (!questsStr.empty()) + trans->PAppend("DELETE FROM `character_queststatus_rewarded` WHERE guid='%u' AND quest IN (%s)", lowGuid, questsStr.c_str()); + } - stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHAR_SOCIAL_BY_FRIEND); - stmt->setUInt32(0, lowGuid); - trans->Append(stmt); + if (!sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_GUILD)) + { + // Reset guild + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_GUILD_MEMBER); - } + stmt->setUInt32(0, lowGuid); - // Leave Arena Teams - Player::LeaveAllArenaTeams(guid); + PreparedQueryResult result = CharacterDatabase.Query(stmt); + if (result) + if (Guild* guild = sGuildMgr->GetGuildById((result->Fetch()[0]).GetUInt32())) + guild->DeleteMember(MAKE_NEW_GUID(lowGuid, 0, HIGHGUID_PLAYER)); + } - // Reset homebind and position - stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_PLAYER_HOMEBIND); - stmt->setUInt32(0, lowGuid); - trans->Append(stmt); + if (!sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_ADD_FRIEND)) + { + // Delete Friend List + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHAR_SOCIAL_BY_GUID); + stmt->setUInt32(0, lowGuid); + trans->Append(stmt); - stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_PLAYER_HOMEBIND); - stmt->setUInt32(0, lowGuid); - if (team == TEAM_ALLIANCE) - { - stmt->setUInt16(1, 0); - stmt->setUInt16(2, 1519); - stmt->setFloat (3, -8867.68f); - stmt->setFloat (4, 673.373f); - stmt->setFloat (5, 97.9034f); - Player::SavePositionInDB(0, -8867.68f, 673.373f, 97.9034f, 0.0f, 1519, lowGuid); - } - else - { - stmt->setUInt16(1, 1); - stmt->setUInt16(2, 1637); - stmt->setFloat (3, 1633.33f); - stmt->setFloat (4, -4439.11f); - stmt->setFloat (5, 15.7588f); - Player::SavePositionInDB(1, 1633.33f, -4439.11f, 15.7588f, 0.0f, 1637, lowGuid); - } - trans->Append(stmt); + stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHAR_SOCIAL_BY_FRIEND); + stmt->setUInt32(0, lowGuid); + trans->Append(stmt); - // Achievement conversion - for (std::map<uint32, uint32>::const_iterator it = sObjectMgr->FactionChange_Achievements.begin(); it != sObjectMgr->FactionChange_Achievements.end(); ++it) - { - uint32 achiev_alliance = it->first; - uint32 achiev_horde = it->second; + } - PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHAR_ACHIEVEMENT_BY_ACHIEVEMENT); - stmt->setUInt16(0, uint16(team == TEAM_ALLIANCE ? achiev_alliance : achiev_horde)); - stmt->setUInt32(1, lowGuid); - trans->Append(stmt); + // Leave Arena Teams + Player::LeaveAllArenaTeams(guid); - stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_CHAR_ACHIEVEMENT); - stmt->setUInt16(0, uint16(team == TEAM_ALLIANCE ? achiev_alliance : achiev_horde)); - stmt->setUInt16(1, uint16(team == TEAM_ALLIANCE ? achiev_horde : achiev_alliance)); - stmt->setUInt32(2, lowGuid); + // Reset homebind and position + stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_PLAYER_HOMEBIND); + stmt->setUInt32(0, lowGuid); trans->Append(stmt); - } - // Item conversion - for (std::map<uint32, uint32>::const_iterator it = sObjectMgr->FactionChange_Items.begin(); it != sObjectMgr->FactionChange_Items.end(); ++it) - { - uint32 item_alliance = it->first; - uint32 item_horde = it->second; - - PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_CHAR_INVENTORY_FACTION_CHANGE); - stmt->setUInt32(0, (team == TEAM_ALLIANCE ? item_alliance : item_horde)); - stmt->setUInt32(1, (team == TEAM_ALLIANCE ? item_horde : item_alliance)); - stmt->setUInt32(2, guid); + stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_PLAYER_HOMEBIND); + stmt->setUInt32(0, lowGuid); + if (team == TEAM_ALLIANCE) + { + stmt->setUInt16(1, 0); + stmt->setUInt16(2, 1519); + stmt->setFloat (3, -8867.68f); + stmt->setFloat (4, 673.373f); + stmt->setFloat (5, 97.9034f); + Player::SavePositionInDB(0, -8867.68f, 673.373f, 97.9034f, 0.0f, 1519, lowGuid); + } + else + { + stmt->setUInt16(1, 1); + stmt->setUInt16(2, 1637); + stmt->setFloat (3, 1633.33f); + stmt->setFloat (4, -4439.11f); + stmt->setFloat (5, 15.7588f); + Player::SavePositionInDB(1, 1633.33f, -4439.11f, 15.7588f, 0.0f, 1637, lowGuid); + } trans->Append(stmt); - } - // Spell conversion - for (std::map<uint32, uint32>::const_iterator it = sObjectMgr->FactionChange_Spells.begin(); it != sObjectMgr->FactionChange_Spells.end(); ++it) - { - uint32 spell_alliance = it->first; - uint32 spell_horde = it->second; + // Achievement conversion + for (std::map<uint32, uint32>::const_iterator it = sObjectMgr->FactionChange_Achievements.begin(); it != sObjectMgr->FactionChange_Achievements.end(); ++it) + { + uint32 achiev_alliance = it->first; + uint32 achiev_horde = it->second; - PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHAR_SPELL_BY_SPELL); - stmt->setUInt32(0, (team == TEAM_ALLIANCE ? spell_alliance : spell_horde)); - stmt->setUInt32(1, lowGuid); - trans->Append(stmt); + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHAR_ACHIEVEMENT_BY_ACHIEVEMENT); + stmt->setUInt16(0, uint16(team == TEAM_ALLIANCE ? achiev_alliance : achiev_horde)); + stmt->setUInt32(1, lowGuid); + trans->Append(stmt); - stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_CHAR_SPELL_FACTION_CHANGE); - stmt->setUInt32(0, (team == TEAM_ALLIANCE ? spell_alliance : spell_horde)); - stmt->setUInt32(1, (team == TEAM_ALLIANCE ? spell_horde : spell_alliance)); - stmt->setUInt32(2, lowGuid); - trans->Append(stmt); - } + stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_CHAR_ACHIEVEMENT); + stmt->setUInt16(0, uint16(team == TEAM_ALLIANCE ? achiev_alliance : achiev_horde)); + stmt->setUInt16(1, uint16(team == TEAM_ALLIANCE ? achiev_horde : achiev_alliance)); + stmt->setUInt32(2, lowGuid); + trans->Append(stmt); + } - // Reputation conversion - for (std::map<uint32, uint32>::const_iterator it = sObjectMgr->FactionChange_Reputation.begin(); it != sObjectMgr->FactionChange_Reputation.end(); ++it) - { - uint32 reputation_alliance = it->first; - uint32 reputation_horde = it->second; - uint32 newReputation = (team == TEAM_ALLIANCE) ? reputation_alliance : reputation_horde; - uint32 oldReputation = (team == TEAM_ALLIANCE) ? reputation_horde : reputation_alliance; - - // select old standing set in db - PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHAR_REP_BY_FACTION); - stmt->setUInt32(0, oldReputation); - stmt->setUInt32(1, lowGuid); - PreparedQueryResult result = CharacterDatabase.Query(stmt); - - if (!result) + // Item conversion + for (std::map<uint32, uint32>::const_iterator it = sObjectMgr->FactionChange_Items.begin(); it != sObjectMgr->FactionChange_Items.end(); ++it) { - WorldPacket data(SMSG_CHAR_FACTION_CHANGE, 1); - data << uint8(CHAR_CREATE_ERROR); - SendPacket(&data); - return; + uint32 item_alliance = it->first; + uint32 item_horde = it->second; + + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_CHAR_INVENTORY_FACTION_CHANGE); + stmt->setUInt32(0, (team == TEAM_ALLIANCE ? item_alliance : item_horde)); + stmt->setUInt32(1, (team == TEAM_ALLIANCE ? item_horde : item_alliance)); + stmt->setUInt32(2, guid); + trans->Append(stmt); } - Field* fields = result->Fetch(); - int32 oldDBRep = fields[0].GetInt32(); - FactionEntry const* factionEntry = sFactionStore.LookupEntry(oldReputation); + // Spell conversion + for (std::map<uint32, uint32>::const_iterator it = sObjectMgr->FactionChange_Spells.begin(); it != sObjectMgr->FactionChange_Spells.end(); ++it) + { + uint32 spell_alliance = it->first; + uint32 spell_horde = it->second; - // old base reputation - int32 oldBaseRep = sObjectMgr->GetBaseReputationOff(factionEntry, oldRace, playerClass); + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHAR_SPELL_BY_SPELL); + stmt->setUInt32(0, (team == TEAM_ALLIANCE ? spell_alliance : spell_horde)); + stmt->setUInt32(1, lowGuid); + trans->Append(stmt); - // new base reputation - int32 newBaseRep = sObjectMgr->GetBaseReputationOff(sFactionStore.LookupEntry(newReputation), race, playerClass); + stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_CHAR_SPELL_FACTION_CHANGE); + stmt->setUInt32(0, (team == TEAM_ALLIANCE ? spell_alliance : spell_horde)); + stmt->setUInt32(1, (team == TEAM_ALLIANCE ? spell_horde : spell_alliance)); + stmt->setUInt32(2, lowGuid); + trans->Append(stmt); + } - // final reputation shouldnt change - int32 FinalRep = oldDBRep + oldBaseRep; - int32 newDBRep = FinalRep - newBaseRep; + // Reputation conversion + for (std::map<uint32, uint32>::const_iterator it = sObjectMgr->FactionChange_Reputation.begin(); it != sObjectMgr->FactionChange_Reputation.end(); ++it) + { + uint32 reputation_alliance = it->first; + uint32 reputation_horde = it->second; + uint32 newReputation = (team == TEAM_ALLIANCE) ? reputation_alliance : reputation_horde; + uint32 oldReputation = (team == TEAM_ALLIANCE) ? reputation_horde : reputation_alliance; + + // select old standing set in db + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHAR_REP_BY_FACTION); + stmt->setUInt32(0, oldReputation); + stmt->setUInt32(1, lowGuid); + PreparedQueryResult result = CharacterDatabase.Query(stmt); - stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHAR_REP_BY_FACTION); - stmt->setUInt32(0, newReputation); - stmt->setUInt32(1, lowGuid); - trans->Append(stmt); + if (!result) + { + WorldPacket data(SMSG_CHAR_FACTION_CHANGE, 1); + data << uint8(CHAR_CREATE_ERROR); + SendPacket(&data); + return; + } - stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_CHAR_REP_FACTION_CHANGE); - stmt->setUInt16(0, uint16(newReputation)); - stmt->setInt32(1, newDBRep); - stmt->setUInt16(2, uint16(oldReputation)); - stmt->setUInt32(3, lowGuid); - trans->Append(stmt); - } + Field* fields = result->Fetch(); + int32 oldDBRep = fields[0].GetInt32(); + FactionEntry const* factionEntry = sFactionStore.LookupEntry(oldReputation); - // Title conversion - if (knownTitlesStr) - { - const uint32 ktcount = KNOWN_TITLES_SIZE * 2; - uint32 knownTitles[ktcount]; - Tokenizer tokens(knownTitlesStr, ' ', ktcount); + // old base reputation + int32 oldBaseRep = sObjectMgr->GetBaseReputationOff(factionEntry, oldRace, playerClass); - if (tokens.size() != ktcount) - return; + // new base reputation + int32 newBaseRep = sObjectMgr->GetBaseReputationOff(sFactionStore.LookupEntry(newReputation), race, playerClass); - for (uint32 index = 0; index < ktcount; ++index) - knownTitles[index] = atol(tokens[index]); + // final reputation shouldnt change + int32 FinalRep = oldDBRep + oldBaseRep; + int32 newDBRep = FinalRep - newBaseRep; - for (std::map<uint32, uint32>::const_iterator it = sObjectMgr->FactionChange_Titles.begin(); it != sObjectMgr->FactionChange_Titles.end(); ++it) + stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHAR_REP_BY_FACTION); + stmt->setUInt32(0, newReputation); + stmt->setUInt32(1, lowGuid); + trans->Append(stmt); + + stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_CHAR_REP_FACTION_CHANGE); + stmt->setUInt16(0, uint16(newReputation)); + stmt->setInt32(1, newDBRep); + stmt->setUInt16(2, uint16(oldReputation)); + stmt->setUInt32(3, lowGuid); + trans->Append(stmt); + } + + // Title conversion + if (knownTitlesStr) { - uint32 title_alliance = it->first; - uint32 title_horde = it->second; + const uint32 ktcount = KNOWN_TITLES_SIZE * 2; + uint32 knownTitles[ktcount]; + Tokenizer tokens(knownTitlesStr, ' ', ktcount); - CharTitlesEntry const* atitleInfo = sCharTitlesStore.LookupEntry(title_alliance); - CharTitlesEntry const* htitleInfo = sCharTitlesStore.LookupEntry(title_horde); - // new team - if (team == TEAM_ALLIANCE) + if (tokens.size() != ktcount) + return; + + for (uint32 index = 0; index < ktcount; ++index) + knownTitles[index] = atol(tokens[index]); + + for (std::map<uint32, uint32>::const_iterator it = sObjectMgr->FactionChange_Titles.begin(); it != sObjectMgr->FactionChange_Titles.end(); ++it) { - uint32 bitIndex = htitleInfo->bit_index; - uint32 index = bitIndex / 32; - uint32 old_flag = 1 << (bitIndex % 32); - uint32 new_flag = 1 << (atitleInfo->bit_index % 32); - if (knownTitles[index] & old_flag) + uint32 title_alliance = it->first; + uint32 title_horde = it->second; + + CharTitlesEntry const* atitleInfo = sCharTitlesStore.LookupEntry(title_alliance); + CharTitlesEntry const* htitleInfo = sCharTitlesStore.LookupEntry(title_horde); + // new team + if (team == TEAM_ALLIANCE) { - knownTitles[index] &= ~old_flag; - // use index of the new title - knownTitles[atitleInfo->bit_index / 32] |= new_flag; + uint32 bitIndex = htitleInfo->bit_index; + uint32 index = bitIndex / 32; + uint32 old_flag = 1 << (bitIndex % 32); + uint32 new_flag = 1 << (atitleInfo->bit_index % 32); + if (knownTitles[index] & old_flag) + { + knownTitles[index] &= ~old_flag; + // use index of the new title + knownTitles[atitleInfo->bit_index / 32] |= new_flag; + } } - } - else - { - uint32 bitIndex = atitleInfo->bit_index; - uint32 index = bitIndex / 32; - uint32 old_flag = 1 << (bitIndex % 32); - uint32 new_flag = 1 << (htitleInfo->bit_index % 32); - if (knownTitles[index] & old_flag) + else { - knownTitles[index] &= ~old_flag; - // use index of the new title - knownTitles[htitleInfo->bit_index / 32] |= new_flag; + uint32 bitIndex = atitleInfo->bit_index; + uint32 index = bitIndex / 32; + uint32 old_flag = 1 << (bitIndex % 32); + uint32 new_flag = 1 << (htitleInfo->bit_index % 32); + if (knownTitles[index] & old_flag) + { + knownTitles[index] &= ~old_flag; + // use index of the new title + knownTitles[htitleInfo->bit_index / 32] |= new_flag; + } } - } - std::ostringstream ss; - for (uint32 index = 0; index < ktcount; ++index) - ss << knownTitles[index] << ' '; + std::ostringstream ss; + for (uint32 index = 0; index < ktcount; ++index) + ss << knownTitles[index] << ' '; - PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_CHAR_TITLES_FACTION_CHANGE); - stmt->setString(0, ss.str().c_str()); - stmt->setUInt32(1, lowGuid); - trans->Append(stmt); + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_CHAR_TITLES_FACTION_CHANGE); + stmt->setString(0, ss.str().c_str()); + stmt->setUInt32(1, lowGuid); + trans->Append(stmt); - // unset any currently chosen title - stmt = CharacterDatabase.GetPreparedStatement(CHAR_RES_CHAR_TITLES_FACTION_CHANGE); - stmt->setUInt32(0, lowGuid); - trans->Append(stmt); + // unset any currently chosen title + stmt = CharacterDatabase.GetPreparedStatement(CHAR_RES_CHAR_TITLES_FACTION_CHANGE); + stmt->setUInt32(0, lowGuid); + trans->Append(stmt); + } } } } @@ -2119,7 +2119,7 @@ void WorldSession::HandleCharFactionOrRaceChange(WorldPacket& recv_data) CharacterDatabase.CommitTransaction(trans); std::string IP_str = GetRemoteAddress(); - sLog->outDebug(LOG_FILTER_UNITS, "Account: %d (IP: %s), Character guid: %u Change Race/Faction to: %s", GetAccountId(), IP_str.c_str(), lowGuid, newname.c_str()); + sLog->outDebug(LOG_FILTER_PLAYER, "%s (IP: %s) changed race from %u to %u", GetPlayerInfo().c_str(), IP_str.c_str(), oldRace, race); WorldPacket data(SMSG_CHAR_FACTION_CHANGE, 1 + 8 + (newname.size() + 1) + 1 + 1 + 1 + 1 + 1 + 1 + 1); data << uint8(RESPONSE_SUCCESS); |