Skip to content

Commit b5105bc

Browse files
joschiwaldShauren
authored andcommitted
Core/Packets: updated char rename customize and factionchange packets
(cherry picked from commit f4926e0)
1 parent 1aa6d4e commit b5105bc

10 files changed

Lines changed: 527 additions & 289 deletions

File tree

src/server/database/Database/Implementation/CharacterDatabase.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ void CharacterDatabaseConnection::DoPrepareStatements()
5151
"cb.guid, cd.genitive FROM characters AS c LEFT JOIN character_pet AS cp ON c.guid = cp.owner AND cp.slot = ? "
5252
"LEFT JOIN character_declinedname AS cd ON c.guid = cd.guid LEFT JOIN guild_member AS gm ON c.guid = gm.guid "
5353
"LEFT JOIN character_banned AS cb ON c.guid = cb.guid AND cb.active = 1 WHERE c.account = ? AND c.deleteInfos_Name IS NULL ORDER BY c.guid", CONNECTION_ASYNC);
54-
PrepareStatement(CHAR_SEL_FREE_NAME, "SELECT name, at_login FROM characters WHERE guid = ? AND account = ? AND NOT EXISTS (SELECT NULL FROM characters WHERE name = ?)", CONNECTION_ASYNC);
54+
PrepareStatement(CHAR_SEL_FREE_NAME, "SELECT name, at_login FROM characters WHERE guid = ? AND NOT EXISTS (SELECT NULL FROM characters WHERE name = ?)", CONNECTION_ASYNC);
5555
PrepareStatement(CHAR_SEL_CHAR_ZONE, "SELECT zone FROM characters WHERE guid = ?", CONNECTION_SYNCH);
5656
PrepareStatement(CHAR_SEL_CHARACTER_NAME_DATA, "SELECT race, class, gender, level, name FROM characters WHERE guid = ?", CONNECTION_SYNCH);
5757
PrepareStatement(CHAR_SEL_CHAR_POSITION_XYZ, "SELECT map, position_x, position_y, position_z FROM characters WHERE guid = ?", CONNECTION_SYNCH);
@@ -161,7 +161,6 @@ void CharacterDatabaseConnection::DoPrepareStatements()
161161
PrepareStatement(CHAR_SEL_MATCH_MAKER_RATING, "SELECT matchMakerRating FROM character_arena_stats WHERE guid = ? AND slot = ?", CONNECTION_SYNCH);
162162
PrepareStatement(CHAR_SEL_CHARACTER_COUNT, "SELECT account, COUNT(guid) FROM characters WHERE account = ? GROUP BY account", CONNECTION_ASYNC);
163163
PrepareStatement(CHAR_UPD_NAME_BY_GUID, "UPDATE characters SET name = ? WHERE guid = ?", CONNECTION_ASYNC);
164-
PrepareStatement(CHAR_DEL_DECLINED_NAME, "DELETE FROM character_declinedname WHERE guid = ?", CONNECTION_ASYNC);
165164

166165
// Guild handling
167166
// 0: uint32, 1: string, 2: uint32, 3: string, 4: string, 5: uint64, 6-10: uint32, 11: uint64
@@ -388,7 +387,7 @@ void CharacterDatabaseConnection::DoPrepareStatements()
388387
PrepareStatement(CHAR_DEL_GLOBAL_INSTANCE_RESETTIME, "DELETE FROM instance_reset WHERE mapid = ? AND difficulty = ?", CONNECTION_SYNCH);
389388
PrepareStatement(CHAR_UPD_GLOBAL_INSTANCE_RESETTIME, "UPDATE instance_reset SET resettime = ? WHERE mapid = ? AND difficulty = ?", CONNECTION_BOTH);
390389
PrepareStatement(CHAR_UPD_CHAR_ONLINE, "UPDATE characters SET online = 1 WHERE guid = ?", CONNECTION_ASYNC);
391-
PrepareStatement(CHAR_UPD_CHAR_NAME_AT_LOGIN, "UPDATE characters set name = ?, at_login = ? WHERE guid = ?", CONNECTION_ASYNC);
390+
PrepareStatement(CHAR_UPD_CHAR_NAME_AT_LOGIN, "UPDATE characters SET name = ?, at_login = ? WHERE guid = ?", CONNECTION_ASYNC);
392391
PrepareStatement(CHAR_UPD_WORLDSTATE, "UPDATE worldstates SET value = ? WHERE entry = ?", CONNECTION_ASYNC);
393392
PrepareStatement(CHAR_INS_WORLDSTATE, "INSERT INTO worldstates (entry, value) VALUES (?, ?)", CONNECTION_ASYNC);
394393
PrepareStatement(CHAR_DEL_CHAR_INSTANCE_BY_INSTANCE_GUID, "DELETE FROM character_instance WHERE guid = ? AND instance = ?", CONNECTION_ASYNC);
@@ -416,7 +415,6 @@ void CharacterDatabaseConnection::DoPrepareStatements()
416415
PrepareStatement(CHAR_SEL_PINFO_XP, "SELECT a.xp, b.guid FROM characters a LEFT JOIN guild_member b ON a.guid = b.guid WHERE a.guid = ?", CONNECTION_SYNCH);
417416
PrepareStatement(CHAR_SEL_CHAR_HOMEBIND, "SELECT mapId, zoneId, posX, posY, posZ FROM character_homebind WHERE guid = ?", CONNECTION_SYNCH);
418417
PrepareStatement(CHAR_SEL_CHAR_GUID_NAME_BY_ACC, "SELECT guid, name, online FROM characters WHERE account = ?", CONNECTION_SYNCH);
419-
PrepareStatement(CHAR_SEL_CHARACTER_AT_LOGIN, "SELECT at_login FROM characters WHERE guid = ?", CONNECTION_SYNCH);
420418
PrepareStatement(CHAR_SEL_CHAR_CUSTOMIZE_INFO, "SELECT name, race, class, gender, at_login FROM characters WHERE guid = ?", CONNECTION_ASYNC);
421419
PrepareStatement(CHAR_SEL_CHAR_RACE_OR_FACTION_CHANGE_INFOS, "SELECT c.at_login, c.knownTitles, gm.guid, c.map FROM characters c LEFT JOIN group_member gm ON c.guid = gm.memberGuid WHERE c.guid = ?", CONNECTION_ASYNC);
422420
PrepareStatement(CHAR_SEL_INSTANCE, "SELECT data, completedEncounters FROM instance WHERE map = ? AND id = ?", CONNECTION_SYNCH);

src/server/database/Database/Implementation/CharacterDatabase.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ enum CharacterDatabaseStatements : uint32
145145
CHAR_SEL_MATCH_MAKER_RATING,
146146
CHAR_SEL_CHARACTER_COUNT,
147147
CHAR_UPD_NAME_BY_GUID,
148-
CHAR_DEL_DECLINED_NAME,
149148

150149
CHAR_INS_GUILD,
151150
CHAR_DEL_GUILD,
@@ -345,7 +344,6 @@ enum CharacterDatabaseStatements : uint32
345344
CHAR_SEL_PINFO_BANS,
346345
CHAR_SEL_CHAR_HOMEBIND,
347346
CHAR_SEL_CHAR_GUID_NAME_BY_ACC,
348-
CHAR_SEL_CHARACTER_AT_LOGIN,
349347
CHAR_SEL_CHAR_CUSTOMIZE_INFO,
350348
CHAR_SEL_CHAR_RACE_OR_FACTION_CHANGE_INFOS,
351349
CHAR_SEL_INSTANCE,

src/server/game/Entities/Player/Player.cpp

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "ChannelMgr.h"
3333
#include "CharacterCache.h"
3434
#include "CharacterDatabaseCleaner.h"
35+
#include "CharacterPackets.h"
3536
#include "Chat.h"
3637
#include "CinematicMgr.h"
3738
#include "CombatLogPackets.h"
@@ -380,7 +381,7 @@ void Player::CleanupsBeforeDelete(bool finalCleanup)
380381
itr->second.save->RemovePlayer(this);
381382
}
382383

383-
bool Player::Create(ObjectGuid::LowType guidlow, CharacterCreateInfo* createInfo)
384+
bool Player::Create(ObjectGuid::LowType guidlow, WorldPackets::Character::CharacterCreateInfo const* createInfo)
384385
{
385386
//FIXME: outfitId not used in player creating
386387
/// @todo need more checks against packet modifications
@@ -418,14 +419,14 @@ bool Player::Create(ObjectGuid::LowType guidlow, CharacterCreateInfo* createInfo
418419

419420
SetFactionForRace(createInfo->Race);
420421

421-
if (!IsValidGender(createInfo->Gender))
422+
if (!IsValidGender(createInfo->Sex))
422423
{
423424
TC_LOG_ERROR("entities.player.cheat", "Player::Create: Possible hacking attempt: Account {} tried to create a character named '{}' with an invalid gender ({}) - refusing to do so",
424-
GetSession()->GetAccountId(), m_name, createInfo->Gender);
425+
GetSession()->GetAccountId(), m_name, createInfo->Sex);
425426
return false;
426427
}
427428

428-
if (!ValidateAppearance(createInfo->Race, createInfo->Class, createInfo->Gender, createInfo->HairStyle, createInfo->HairColor, createInfo->Face, createInfo->FacialHair, createInfo->Skin, true))
429+
if (!ValidateAppearance(createInfo->Race, createInfo->Class, createInfo->Sex, createInfo->HairStyle, createInfo->HairColor, createInfo->Face, createInfo->FacialHairStyle, createInfo->Skin, true))
429430
{
430431
TC_LOG_ERROR("entities.player.cheat", "Player::Create: Possible hacking attempt: Account {} tried to create a character named '{}' with invalid appearance attributes - refusing to do so",
431432
GetSession()->GetAccountId(), m_name);
@@ -434,7 +435,7 @@ bool Player::Create(ObjectGuid::LowType guidlow, CharacterCreateInfo* createInfo
434435

435436
SetRace(createInfo->Race);
436437
SetClass(createInfo->Class);
437-
SetGender(Gender(createInfo->Gender));
438+
SetGender(Gender(createInfo->Sex));
438439
SetPowerType(Powers(powertype), false);
439440
InitDisplayIds();
440441
if (sWorld->getIntConfig(CONFIG_GAME_TYPE) == REALM_TYPE_PVP || sWorld->getIntConfig(CONFIG_GAME_TYPE) == REALM_TYPE_RPPVP)
@@ -451,9 +452,9 @@ bool Player::Create(ObjectGuid::LowType guidlow, CharacterCreateInfo* createInfo
451452
SetFaceId(createInfo->Face);
452453
SetHairStyleId(createInfo->HairStyle);
453454
SetHairColorId(createInfo->HairColor);
454-
SetFacialStyle(createInfo->FacialHair);
455+
SetFacialStyle(createInfo->FacialHairStyle);
455456
SetRestState((GetSession()->IsARecruiter() || GetSession()->GetRecruiterId() != 0) ? REST_STATE_RAF_LINKED : REST_STATE_NOT_RAF_LINKED);
456-
SetNativeGender(Gender(createInfo->Gender));
457+
SetNativeGender(Gender(createInfo->Sex));
457458

458459
// set starting level
459460
SetLevel(GetStartLevel(createInfo->Class), false);
@@ -492,7 +493,7 @@ bool Player::Create(ObjectGuid::LowType guidlow, CharacterCreateInfo* createInfo
492493
addActionButton(action_itr->button, action_itr->action, action_itr->type);
493494

494495
// original items
495-
if (CharStartOutfitEntry const* oEntry = GetCharStartOutfitEntry(createInfo->Race, createInfo->Class, createInfo->Gender))
496+
if (CharStartOutfitEntry const* oEntry = GetCharStartOutfitEntry(createInfo->Race, createInfo->Class, createInfo->Sex))
496497
{
497498
for (int j = 0; j < MAX_OUTFIT_ITEMS; ++j)
498499
{
@@ -3901,23 +3902,23 @@ void Player::DeleteFromDB(ObjectGuid playerguid, uint32 accountId, bool updateRe
39013902

39023903
// Convert guid to low GUID for CharacterNameData, but also other methods on success
39033904
ObjectGuid::LowType guid = playerguid.GetCounter();
3904-
uint32 charDelete_method = sWorld->getIntConfig(CONFIG_CHARDELETE_METHOD);
3905+
uint32 charDeleteMethod = sWorld->getIntConfig(CONFIG_CHARDELETE_METHOD);
39053906
CharacterCacheEntry const* characterInfo = sCharacterCache->GetCharacterCacheByGuid(playerguid);
39063907
std::string name;
39073908
if (characterInfo)
39083909
name = characterInfo->Name;
39093910

39103911
if (deleteFinally)
3911-
charDelete_method = CHAR_DELETE_REMOVE;
3912+
charDeleteMethod = CHAR_DELETE_REMOVE;
39123913
else if (characterInfo) // To avoid a query, we select loaded data. If it doesn't exist, return.
39133914
{
39143915
// Define the required variables
3915-
uint32 charDelete_minLvl = sWorld->getIntConfig(characterInfo->Class != CLASS_DEATH_KNIGHT ? CONFIG_CHARDELETE_MIN_LEVEL : CONFIG_CHARDELETE_DEATH_KNIGHT_MIN_LEVEL);
3916+
uint32 charDeleteMinLvl = sWorld->getIntConfig(characterInfo->Class != CLASS_DEATH_KNIGHT ? CONFIG_CHARDELETE_MIN_LEVEL : CONFIG_CHARDELETE_DEATH_KNIGHT_MIN_LEVEL);
39163917

39173918
// if we want to finalize the character removal or the character does not meet the level requirement of either heroic or non-heroic settings,
39183919
// we set it to mode CHAR_DELETE_REMOVE
3919-
if (characterInfo->Level < charDelete_minLvl)
3920-
charDelete_method = CHAR_DELETE_REMOVE;
3920+
if (characterInfo->Level < charDeleteMinLvl)
3921+
charDeleteMethod = CHAR_DELETE_REMOVE;
39213922
}
39223923

39233924
CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
@@ -3945,7 +3946,7 @@ void Player::DeleteFromDB(ObjectGuid playerguid, uint32 accountId, bool updateRe
39453946
// Remove signs from petitions (also remove petitions if owner);
39463947
RemovePetitionsAndSigns(playerguid, CHARTER_TYPE_ANY);
39473948

3948-
switch (charDelete_method)
3949+
switch (charDeleteMethod)
39493950
{
39503951
// Completely remove from the database
39513952
case CHAR_DELETE_REMOVE:
@@ -4240,7 +4241,7 @@ void Player::DeleteFromDB(ObjectGuid playerguid, uint32 accountId, bool updateRe
42404241
}
42414242
default:
42424243
TC_LOG_ERROR("entities.player.cheat", "Player::DeleteFromDB: Tried to delete player ({}) with unsupported delete method ({}).",
4243-
playerguid.ToString(), charDelete_method);
4244+
playerguid.ToString(), charDeleteMethod);
42444245

42454246
if (trans->GetSize() > 0)
42464247
CharacterDatabase.CommitTransaction(trans);
@@ -6292,6 +6293,15 @@ uint32 Player::TeamForRace(uint8 race)
62926293
return ALLIANCE;
62936294
}
62946295

6296+
TeamId Player::TeamIdForRace(uint8 race)
6297+
{
6298+
if (ChrRacesEntry const* rEntry = sChrRacesStore.LookupEntry(race))
6299+
return TeamId(rEntry->Alliance);
6300+
6301+
TC_LOG_ERROR("entities.player", "Race (%u) not found in DBC: wrong DBC files?", race);
6302+
return TEAM_NEUTRAL;
6303+
}
6304+
62956305
void Player::SetFactionForRace(uint8 race)
62966306
{
62976307
m_team = TeamForRace(race);
@@ -20068,21 +20078,6 @@ void Player::SavePositionInDB(WorldLocation const& loc, uint16 zoneId, ObjectGui
2006820078
CharacterDatabase.ExecuteOrAppend(trans, stmt);
2006920079
}
2007020080

20071-
void Player::Customize(CharacterCustomizeInfo const* customizeInfo, CharacterDatabaseTransaction trans)
20072-
{
20073-
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_GENDER_AND_APPEARANCE);
20074-
20075-
stmt->setUInt8(0, customizeInfo->Gender);
20076-
stmt->setUInt8(1, customizeInfo->Skin);
20077-
stmt->setUInt8(2, customizeInfo->Face);
20078-
stmt->setUInt8(3, customizeInfo->HairStyle);
20079-
stmt->setUInt8(4, customizeInfo->HairColor);
20080-
stmt->setUInt8(5, customizeInfo->FacialHair);
20081-
stmt->setUInt32(6, customizeInfo->Guid.GetCounter());
20082-
20083-
CharacterDatabase.ExecuteOrAppend(trans, stmt);
20084-
}
20085-
2008620081
void Player::SendAttackSwingCantAttack() const
2008720082
{
2008820083
SendDirectMessage(WorldPackets::Combat::AttackSwingCantAttack().Write());

src/server/game/Entities/Player/Player.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ struct AchievementEntry;
3939
struct AreaTableEntry;
4040
struct AreaTriggerEntry;
4141
struct BarberShopStyleEntry;
42-
struct CharacterCustomizeInfo;
4342
struct CharTitlesEntry;
4443
struct ChatChannelsEntry;
4544
struct CreatureTemplate;
@@ -59,7 +58,6 @@ class Bag;
5958
class Battleground;
6059
class CinematicMgr;
6160
class Channel;
62-
class CharacterCreateInfo;
6361
class Creature;
6462
class DynamicObject;
6563
class GameClient;
@@ -82,6 +80,14 @@ enum ItemClass : uint8;
8280
enum LootError : uint8;
8381
enum LootType : uint8;
8482

83+
namespace WorldPackets
84+
{
85+
namespace Character
86+
{
87+
struct CharacterCreateInfo;
88+
}
89+
}
90+
8591
typedef std::deque<Mail*> PlayerMails;
8692

8793
#define PLAYER_MAX_SKILLS 128
@@ -941,7 +947,7 @@ class TC_GAME_API Player : public Unit, public GridObject<Player>
941947
void SendSummonRequestFrom(Unit* summoner);
942948
void SummonIfPossible(bool agree);
943949

944-
bool Create(ObjectGuid::LowType guidlow, CharacterCreateInfo* createInfo);
950+
bool Create(ObjectGuid::LowType guidlow, WorldPackets::Character::CharacterCreateInfo const* createInfo);
945951

946952
void Update(uint32 time) override;
947953

@@ -1381,7 +1387,6 @@ class TC_GAME_API Player : public Unit, public GridObject<Player>
13811387
void SaveInventoryAndGoldToDB(CharacterDatabaseTransaction trans); // fast save function for item/money cheating preventing
13821388
void SaveGoldToDB(CharacterDatabaseTransaction trans) const;
13831389

1384-
static void Customize(CharacterCustomizeInfo const* customizeInfo, CharacterDatabaseTransaction trans);
13851390
static void SavePositionInDB(WorldLocation const& loc, uint16 zoneId, ObjectGuid guid, CharacterDatabaseTransaction trans);
13861391

13871392
static void DeleteFromDB(ObjectGuid playerguid, uint32 accountId, bool updateRealmChars = true, bool deleteFinally = false);
@@ -1821,6 +1826,7 @@ class TC_GAME_API Player : public Unit, public GridObject<Player>
18211826
void CheckAreaExploreAndOutdoor(void);
18221827

18231828
static uint32 TeamForRace(uint8 race);
1829+
static TeamId TeamIdForRace(uint8 race);
18241830
uint32 GetTeam() const { return m_team; }
18251831
TeamId GetTeamId() const { return m_team == ALLIANCE ? TEAM_ALLIANCE : TEAM_HORDE; }
18261832
void SetFactionForRace(uint8 race);

0 commit comments

Comments
 (0)