From 20249cec67999e2787686e6af8a228cb5fbc7336 Mon Sep 17 00:00:00 2001 From: Uleat Date: Sat, 14 Feb 2015 21:36:54 -0500 Subject: [PATCH] Pre-purposed prep-work --- common/clientversions.h | 55 +++++++++++++++++++++++++++++++++++++++++ world/client.cpp | 32 ++++++++++++------------ world/client.h | 3 ++- world/worlddb.cpp | 13 ++++------ zone/client.cpp | 4 +-- zone/client.h | 6 ++--- zone/client_packet.cpp | 5 ++-- zone/client_process.cpp | 2 +- 8 files changed, 86 insertions(+), 34 deletions(-) diff --git a/common/clientversions.h b/common/clientversions.h index 040e5dc12..675429eab 100644 --- a/common/clientversions.h +++ b/common/clientversions.h @@ -95,4 +95,59 @@ static const char* ClientVersionName(ClientVersion version) }; } +static uint32 ClientBitFromVersion(ClientVersion clientVersion) +{ + switch (clientVersion) + { + case ClientVersion::Unknown: + case ClientVersion::Client62: + return 0; + case ClientVersion::Titanium: + case ClientVersion::SoF: + case ClientVersion::SoD: + case ClientVersion::UF: + case ClientVersion::RoF: + case ClientVersion::RoF2: + case ClientVersion::MobNPC: + case ClientVersion::MobMerc: + case ClientVersion::MobBot: + case ClientVersion::MobPet: + return ((uint32)1 << (static_cast(clientVersion) - 1)); + default: + return 0; + } +} + +static ClientVersion ClientVersionFromBit(uint32 clientVersionBit) +{ + switch (clientVersionBit) + { + case (uint32)static_cast(ClientVersion::Unknown): + case ((uint32)1 << (static_cast(ClientVersion::Client62) - 1)): + return ClientVersion::Unknown; + case ((uint32)1 << (static_cast(ClientVersion::Titanium) - 1)): + return ClientVersion::Titanium; + case ((uint32)1 << (static_cast(ClientVersion::SoF) - 1)): + return ClientVersion::SoF; + case ((uint32)1 << (static_cast(ClientVersion::SoD) - 1)): + return ClientVersion::SoD; + case ((uint32)1 << (static_cast(ClientVersion::UF) - 1)): + return ClientVersion::UF; + case ((uint32)1 << (static_cast(ClientVersion::RoF) - 1)): + return ClientVersion::RoF; + case ((uint32)1 << (static_cast(ClientVersion::RoF2) - 1)): + return ClientVersion::RoF2; + case ((uint32)1 << (static_cast(ClientVersion::MobNPC) - 1)): + return ClientVersion::MobNPC; + case ((uint32)1 << (static_cast(ClientVersion::MobMerc) - 1)): + return ClientVersion::MobMerc; + case ((uint32)1 << (static_cast(ClientVersion::MobBot) - 1)): + return ClientVersion::MobBot; + case ((uint32)1 << (static_cast(ClientVersion::MobPet) - 1)): + return ClientVersion::MobPet; + default: + return ClientVersion::Unknown; + } +} + #endif /* CLIENTVERSIONS_H */ diff --git a/world/client.cpp b/world/client.cpp index ace58ffea..f26328e12 100644 --- a/world/client.cpp +++ b/world/client.cpp @@ -86,11 +86,11 @@ Client::Client(EQStreamInterface* ieqs) charid = 0; pwaitingforbootup = 0; StartInTutorial = false; - ClientVersionBit = 0; - numclients++; - if (eqs->GetClientVersion() != ClientVersion::Unknown) - ClientVersionBit = 1 << (static_cast(eqs->GetClientVersion()) - 1); + m_ClientVersion = eqs->GetClientVersion(); + m_ClientVersionBit = ClientBitFromVersion(m_ClientVersion); + + numclients++; } Client::~Client() { @@ -161,7 +161,7 @@ void Client::SendCharInfo() { cle->SetOnline(CLE_Status_CharSelect); } - if (ClientVersionBit & BIT_RoFAndLater) + if (m_ClientVersionBit & BIT_RoFAndLater) { // Can make max char per account into a rule - New to VoA SendMaxCharCreate(10); @@ -176,7 +176,7 @@ void Client::SendCharInfo() { auto outapp = new EQApplicationPacket(OP_SendCharInfo, sizeof(CharacterSelect_Struct)); CharacterSelect_Struct* cs = (CharacterSelect_Struct*)outapp->pBuffer; - database.GetCharSelectInfo(GetAccountID(), cs, ClientVersionBit); + database.GetCharSelectInfo(GetAccountID(), cs, m_ClientVersionBit); QueuePacket(outapp); safe_delete(outapp); @@ -671,7 +671,7 @@ bool Client::HandleCharacterCreatePacket(const EQApplicationPacket *app) { } else { - if(ClientVersionBit & BIT_TitaniumAndEarlier) + if (m_ClientVersionBit & BIT_TitaniumAndEarlier) StartInTutorial = true; SendCharInfo(); } @@ -719,7 +719,7 @@ bool Client::HandleEnterWorldPacket(const EQApplicationPacket *app) { if(!pZoning && ew->return_home && !ew->tutorial) { auto cs = new CharacterSelect_Struct; memset(cs, 0, sizeof(CharacterSelect_Struct)); - database.GetCharSelectInfo(GetAccountID(), cs, ClientVersionBit); + database.GetCharSelectInfo(GetAccountID(), cs, m_ClientVersionBit); bool home_enabled = false; for(int x = 0; x < 10; ++x) @@ -749,7 +749,7 @@ bool Client::HandleEnterWorldPacket(const EQApplicationPacket *app) { if(!pZoning && (RuleB(World, EnableTutorialButton) && (ew->tutorial || StartInTutorial))) { auto cs = new CharacterSelect_Struct; memset(cs, 0, sizeof(CharacterSelect_Struct)); - database.GetCharSelectInfo(GetAccountID(), cs, ClientVersionBit); + database.GetCharSelectInfo(GetAccountID(), cs, m_ClientVersionBit); bool tutorial_enabled = false; for(int x = 0; x < 10; ++x) @@ -846,9 +846,9 @@ bool Client::HandleEnterWorldPacket(const EQApplicationPacket *app) { char ConnectionType; - if(ClientVersionBit & BIT_UFAndLater) + if (m_ClientVersionBit & BIT_UFAndLater) ConnectionType = 'U'; - else if(ClientVersionBit & BIT_SoFAndLater) + else if (m_ClientVersionBit & BIT_SoFAndLater) ConnectionType = 'S'; else ConnectionType = 'C'; @@ -872,7 +872,7 @@ bool Client::HandleEnterWorldPacket(const EQApplicationPacket *app) { outapp2 = new EQApplicationPacket(OP_SetChatServer2); - if(ClientVersionBit & BIT_TitaniumAndEarlier) + if (m_ClientVersionBit & BIT_TitaniumAndEarlier) ConnectionType = 'M'; sprintf(buffer,"%s,%i,%s.%s,%c%08X", @@ -906,7 +906,7 @@ bool Client::HandleDeleteCharacterPacket(const EQApplicationPacket *app) { bool Client::HandleZoneChangePacket(const EQApplicationPacket *app) { // HoT sends this to world while zoning and wants it echoed back. - if(ClientVersionBit & BIT_RoFAndLater) + if (m_ClientVersionBit & BIT_RoFAndLater) { QueuePacket(app); } @@ -1370,7 +1370,7 @@ bool Client::OPCharCreate(char *name, CharCreate_Struct *cc) Log.Out(Logs::Detail, Logs::World_Server, "Beard: %d Beardcolor: %d", cc->beard, cc->beardcolor); /* Validate the char creation struct */ - if (ClientVersionBit & BIT_SoFAndLater) { + if (m_ClientVersionBit & BIT_SoFAndLater) { if (!CheckCharCreateInfoSoF(cc)) { Log.Out(Logs::Detail, Logs::World_Server,"CheckCharCreateInfo did not validate the request (bad race/class/stats)"); return false; @@ -1438,7 +1438,7 @@ bool Client::OPCharCreate(char *name, CharCreate_Struct *cc) pp.pvp = database.GetServerType() == 1 ? 1 : 0; /* If it is an SoF Client and the SoF Start Zone rule is set, send new chars there */ - if (ClientVersionBit & BIT_SoFAndLater) { + if (m_ClientVersionBit & BIT_SoFAndLater) { Log.Out(Logs::Detail, Logs::World_Server,"Found 'SoFStartZoneID' rule setting: %i", RuleI(World, SoFStartZoneID)); if (RuleI(World, SoFStartZoneID) > 0) { pp.zone_id = RuleI(World, SoFStartZoneID); @@ -1454,7 +1454,7 @@ bool Client::OPCharCreate(char *name, CharCreate_Struct *cc) } } /* use normal starting zone logic to either get defaults, or if startzone was set, load that from the db table.*/ - bool ValidStartZone = database.GetStartZone(&pp, cc, ClientVersionBit & BIT_TitaniumAndEarlier); + bool ValidStartZone = database.GetStartZone(&pp, cc, m_ClientVersionBit & BIT_TitaniumAndEarlier); if (!ValidStartZone){ return false; diff --git a/world/client.h b/world/client.h index c6b67f91d..ea1df42ba 100644 --- a/world/client.h +++ b/world/client.h @@ -84,7 +84,8 @@ private: uint32 pwaitingforbootup; bool StartInTutorial; - uint32 ClientVersionBit; + ClientVersion m_ClientVersion; + uint32 m_ClientVersionBit; bool OPCharCreate(char *name, CharCreate_Struct *cc); void SetClassStartingSkills( PlayerProfile_Struct *pp ); diff --git a/world/worlddb.cpp b/world/worlddb.cpp index 223ae89d6..3409a1e17 100644 --- a/world/worlddb.cpp +++ b/world/worlddb.cpp @@ -33,8 +33,9 @@ extern std::vector character_create_race_class_combos; // the current stuff is at the bottom of this function -void WorldDatabase::GetCharSelectInfo(uint32 account_id, CharacterSelect_Struct* cs, uint32 ClientVersion) { - Inventory *inv; +void WorldDatabase::GetCharSelectInfo(uint32 account_id, CharacterSelect_Struct* cs, uint32 ClientVersion) +{ + Inventory *inv = nullptr; uint8 has_home = 0; uint8 has_bind = 0; @@ -74,7 +75,7 @@ void WorldDatabase::GetCharSelectInfo(uint32 account_id, CharacterSelect_Struct* "character_data " "WHERE `account_id` = %i ORDER BY `name` LIMIT 10 ", account_id); auto results = database.QueryDatabase(cquery); int char_num = 0; - for (auto row = results.begin(); row != results.end(); ++row) { + for (auto row = results.begin(); row != results.end() && char_num < 10; ++row, ++char_num) { PlayerProfile_Struct pp; memset(&pp, 0, sizeof(PlayerProfile_Struct)); @@ -167,6 +168,7 @@ void WorldDatabase::GetCharSelectInfo(uint32 account_id, CharacterSelect_Struct* } /* Load Inventory */ + // If we ensure that the material data is updated appropriately, we can do away with inventory loads inv = new Inventory; if (GetInventory(account_id, cs->name[char_num], inv)) { @@ -237,11 +239,6 @@ void WorldDatabase::GetCharSelectInfo(uint32 account_id, CharacterSelect_Struct* } safe_delete(inv); - - if (++char_num > 10) - { - break; - } } return; diff --git a/zone/client.cpp b/zone/client.cpp index 63a9b5073..816b21e15 100644 --- a/zone/client.cpp +++ b/zone/client.cpp @@ -250,7 +250,7 @@ Client::Client(EQStreamInterface* ieqs) AttemptedMessages = 0; TotalKarma = 0; m_ClientVersion = ClientVersion::Unknown; - ClientVersionBit = 0; + m_ClientVersionBit = 0; AggroCount = 0; RestRegenHP = 0; RestRegenMana = 0; @@ -7468,7 +7468,7 @@ void Client::SendClearMercInfo() void Client::DuplicateLoreMessage(uint32 ItemID) { - if(!(ClientVersionBit & BIT_RoFAndLater)) + if (!(m_ClientVersionBit & BIT_RoFAndLater)) { Message_StringID(0, PICK_LORE); return; diff --git a/zone/client.h b/zone/client.h index f2325ccca..e49f39805 100644 --- a/zone/client.h +++ b/zone/client.h @@ -1022,7 +1022,7 @@ public: inline int CompletedTasksInSet(int TaskSet) { return (taskstate ? taskstate->CompletedTasksInSet(TaskSet) :0); } inline const ClientVersion GetClientVersion() const { return m_ClientVersion; } - inline const uint32 GetClientVersionBit() const { return ClientVersionBit; } + inline const uint32 GetClientVersionBit() const { return m_ClientVersionBit; } inline void SetClientVersion(ClientVersion in) { m_ClientVersion = in; } /** Adventure Stuff **/ @@ -1140,7 +1140,7 @@ public: void HandleLFGuildResponse(ServerPacket *pack); void SendLFGuildStatus(); void SendGuildLFGuildStatus(); - inline bool XTargettingAvailable() const { return ((ClientVersionBit & BIT_UFAndLater) && RuleB(Character, EnableXTargetting)); } + inline bool XTargettingAvailable() const { return ((m_ClientVersionBit & BIT_UFAndLater) && RuleB(Character, EnableXTargetting)); } inline uint8 GetMaxXTargets() const { return MaxXTargets; } void SetMaxXTargets(uint8 NewMax); bool IsXTarget(const Mob *m) const; @@ -1517,7 +1517,7 @@ private: uint32 AttemptedMessages; ClientVersion m_ClientVersion; - uint32 ClientVersionBit; + uint32 m_ClientVersionBit; int XPRate; diff --git a/zone/client_packet.cpp b/zone/client_packet.cpp index 3fa28c891..1b866073b 100644 --- a/zone/client_packet.cpp +++ b/zone/client_packet.cpp @@ -1191,8 +1191,7 @@ void Client::Handle_Connect_OP_ZoneEntry(const EQApplicationPacket *app) conn_state = ReceivedZoneEntry; SetClientVersion(Connection()->GetClientVersion()); - if (m_ClientVersion != ClientVersion::Unknown) - ClientVersionBit = 1 << (static_cast(m_ClientVersion) - 1); + m_ClientVersionBit = ClientBitFromVersion(Connection()->GetClientVersion()); bool siv = m_inv.SetInventoryVersion(m_ClientVersion); Log.Out(Logs::General, Logs::None, "%s inventory version to %s(%i)", (siv ? "Succeeded in setting" : "Failed to set"), ClientVersionName(m_ClientVersion), m_ClientVersion); @@ -1736,7 +1735,7 @@ void Client::Handle_Connect_OP_ZoneEntry(const EQApplicationPacket *app) safe_delete(outapp); } - if (ClientVersionBit & BIT_UFAndLater) { + if (m_ClientVersionBit & BIT_UFAndLater) { outapp = new EQApplicationPacket(OP_XTargetResponse, 8); outapp->WriteUInt32(GetMaxXTargets()); outapp->WriteUInt32(0); diff --git a/zone/client_process.cpp b/zone/client_process.cpp index 3f9d0ee3a..4f228ba8a 100644 --- a/zone/client_process.cpp +++ b/zone/client_process.cpp @@ -968,7 +968,7 @@ void Client::BulkSendInventoryItems() void Client::BulkSendMerchantInventory(int merchant_id, int npcid) { const Item_Struct* handyitem = nullptr; uint32 numItemSlots = 80; //The max number of items passed in the transaction. - if (ClientVersionBit & BIT_RoFAndLater) { // RoF+ can send 200 items + if (m_ClientVersionBit & BIT_RoFAndLater) { // RoF+ can send 200 items numItemSlots = 200; } const Item_Struct *item;