aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Handlers/CharacterHandler.cpp
diff options
context:
space:
mode:
authortibbi <tibbi@centrum.sk>2012-10-08 17:21:09 +0100
committertibbi <tibbi@centrum.sk>2012-10-08 17:21:09 +0100
commit5896da6689410f1c06ee86f8b093fb2d370eb84f (patch)
tree495f30c78128f4112f68a1072d4fb2af56acde51 /src/server/game/Handlers/CharacterHandler.cpp
parentd49c2a5e4d66b1f4bd4bdff3d6ed92902e8565f8 (diff)
some optimization + adding level to CharacterNameData
Diffstat (limited to 'src/server/game/Handlers/CharacterHandler.cpp')
-rw-r--r--src/server/game/Handlers/CharacterHandler.cpp40
1 files changed, 16 insertions, 24 deletions
diff --git a/src/server/game/Handlers/CharacterHandler.cpp b/src/server/game/Handlers/CharacterHandler.cpp
index 30bc6df0539..91388d9bf11 100644
--- a/src/server/game/Handlers/CharacterHandler.cpp
+++ b/src/server/game/Handlers/CharacterHandler.cpp
@@ -660,7 +660,7 @@ void WorldSession::HandleCharCreateCallback(PreparedQueryResult result, Characte
std::string IP_str = GetRemoteAddress();
sLog->outInfo(LOG_FILTER_CHARACTER, "Account: %d (IP: %s) Create Character:[%s] (GUID: %u)", GetAccountId(), IP_str.c_str(), createInfo->Name.c_str(), newChar.GetGUIDLow());
sScriptMgr->OnPlayerCreate(&newChar);
- sWorld->AddCharacterNameData(newChar.GetGUIDLow(), std::string(newChar.GetName()), newChar.getGender(), newChar.getRace(), newChar.getClass());
+ sWorld->AddCharacterNameData(newChar.GetGUIDLow(), std::string(newChar.GetName()), newChar.getGender(), newChar.getRace(), newChar.getClass(), newChar.getLevel());
newChar.CleanupsBeforeDelete();
delete createInfo;
@@ -1626,22 +1626,14 @@ void WorldSession::HandleCharFactionOrRaceChange(WorldPacket& recv_data)
uint32 lowGuid = GUID_LOPART(guid);
// get the players old (at this moment current) race
- PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHAR_RACE);
- stmt->setUInt32(0, guid);
- PreparedQueryResult result = CharacterDatabase.Query(stmt);
- if (!result)
- {
- WorldPacket data(SMSG_CHAR_FACTION_CHANGE, 1);
- data << uint8(CHAR_CREATE_ERROR);
- SendPacket(&data);
- return;
- }
- Field* fields = result->Fetch();
- uint8 oldRace = fields[0].GetUInt8();
+ CharacterNameData const* nameData = sWorld->GetCharacterNameData(lowGuid);
+ uint8 oldRace = nameData->m_race;
+ uint8 playerClass = nameData->m_class;
+ uint8 level = nameData->m_level;
- stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHAR_CLASS_LVL_AT_LOGIN);
+ PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHAR_CLASS_LVL_AT_LOGIN);
stmt->setUInt32(0, lowGuid);
- result = CharacterDatabase.Query(stmt);
+ PreparedQueryResult result = CharacterDatabase.Query(stmt);
if (!result)
{
@@ -1651,9 +1643,7 @@ void WorldSession::HandleCharFactionOrRaceChange(WorldPacket& recv_data)
return;
}
- fields = result->Fetch();
- uint32 playerClass = uint32(fields[0].GetUInt8());
- uint32 level = uint32(fields[1].GetUInt8());
+ Field* fields = result->Fetch();
uint32 at_loginFlags = fields[2].GetUInt16();
uint32 used_loginFlag = ((recv_data.GetOpcode() == CMSG_CHAR_RACE_CHANGE) ? AT_LOGIN_CHANGE_RACE : AT_LOGIN_CHANGE_FACTION);
char const* knownTitlesStr = fields[3].GetCString();
@@ -2015,10 +2005,12 @@ void WorldSession::HandleCharFactionOrRaceChange(WorldPacket& recv_data)
{
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, team == TEAM_ALLIANCE ? reputation_horde : reputation_alliance);
+ stmt->setUInt32(0, oldReputation);
stmt->setUInt32(1, lowGuid);
PreparedQueryResult result = CharacterDatabase.Query(stmt);
@@ -2032,27 +2024,27 @@ void WorldSession::HandleCharFactionOrRaceChange(WorldPacket& recv_data)
Field* fields = result->Fetch();
int32 oldDBRep = fields[0].GetInt32();
- FactionEntry const* factionEntry = sFactionStore.LookupEntry(team == TEAM_ALLIANCE ? reputation_horde : reputation_alliance);
+ FactionEntry const* factionEntry = sFactionStore.LookupEntry(oldReputation);
// old base reputation
int32 oldBaseRep = sObjectMgr->GetBaseReputation(factionEntry, oldRace, playerClass);
// new base reputation
- int32 newBaseRep = sObjectMgr->GetBaseReputation(sFactionStore.LookupEntry(team == TEAM_ALLIANCE ? reputation_alliance : reputation_horde), race, playerClass);
+ int32 newBaseRep = sObjectMgr->GetBaseReputation(sFactionStore.LookupEntry(newReputation), race, playerClass);
// final reputation shouldnt change
int32 FinalRep = oldDBRep + oldBaseRep;
int32 newDBRep = FinalRep - newBaseRep;
stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CHAR_REP_BY_FACTION);
- stmt->setUInt32(0, uint16(team == TEAM_ALLIANCE ? reputation_alliance : reputation_horde));
+ stmt->setUInt32(0, newReputation);
stmt->setUInt32(1, lowGuid);
trans->Append(stmt);
stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_CHAR_REP_FACTION_CHANGE);
- stmt->setUInt16(0, uint16(team == TEAM_ALLIANCE ? reputation_alliance : reputation_horde));
+ stmt->setUInt16(0, uint16(newReputation));
stmt->setInt32(1, newDBRep);
- stmt->setUInt16(2, uint16(team == TEAM_ALLIANCE ? reputation_horde : reputation_alliance));
+ stmt->setUInt16(2, uint16(oldReputation));
stmt->setUInt32(3, lowGuid);
trans->Append(stmt);
}