feat(Core/Common): delete old Tokenizer (#10121)

This commit is contained in:
Kargatum
2022-01-21 14:59:05 +07:00
committed by GitHub
parent a25ef74de3
commit 6d7f58e6ed
24 changed files with 284 additions and 225 deletions

View File

@@ -84,6 +84,8 @@
#include "World.h"
#include "WorldPacket.h"
#include "WorldSession.h"
#include "Tokenize.h"
#include "StringConvert.h"
// TODO: this import is not necessary for compilation and marked as unused by the IDE
// however, for some reasons removing it would cause a damn linking issue
@@ -1204,33 +1206,68 @@ bool Player::BuildEnumData(PreparedQueryResult result, WorldPacket* data)
*data << uint32(petLevel);
*data << uint32(petFamily);
Tokenizer equipment(fields[22].GetString(), ' ');
std::vector<std::string_view> equipment = Acore::Tokenize(fields[22].GetStringView(), ' ', false);
for (uint8 slot = 0; slot < INVENTORY_SLOT_BAG_END; ++slot)
{
uint32 visualBase = slot * 2;
uint32 itemId = GetUInt32ValueFromArray(equipment, visualBase);
ItemTemplate const* proto = sObjectMgr->GetItemTemplate(itemId);
uint32 const visualBase = slot * 2;
Optional<uint32> itemId;
if (visualBase < equipment.size())
{
itemId = Acore::StringTo<uint32>(equipment[visualBase]);
}
ItemTemplate const* proto = nullptr;
if (itemId)
{
proto = sObjectMgr->GetItemTemplate(*itemId);
}
if (!proto)
{
if (!itemId || *itemId)
{
FMT_LOG_WARN("entities.player.loading", "Player {} has invalid equipment '{}' in `equipmentcache` at index {}. Skipped.",
guid.ToString(), (visualBase < equipment.size()) ? equipment[visualBase] : "<none>", visualBase);
}
*data << uint32(0);
*data << uint8(0);
*data << uint32(0);
continue;
}
SpellItemEnchantmentEntry const* enchant = nullptr;
uint32 enchants = GetUInt32ValueFromArray(equipment, visualBase + 1);
Optional<uint32> enchants = {};
if ((visualBase + 1) < equipment.size())
{
enchants = Acore::StringTo<uint32>(equipment[visualBase + 1]);
}
if (!enchants)
{
FMT_LOG_WARN("entities.player.loading", "Player {} has invalid enchantment info '{}' in `equipmentcache` at index {}. Skipped.",
guid.ToString(), ((visualBase + 1) < equipment.size()) ? equipment[visualBase + 1] : "<none>", visualBase + 1);
enchants = 0;
}
for (uint8 enchantSlot = PERM_ENCHANTMENT_SLOT; enchantSlot <= TEMP_ENCHANTMENT_SLOT; ++enchantSlot)
{
// values stored in 2 uint16
uint32 enchantId = 0x0000FFFF & (enchants >> enchantSlot * 16);
uint32 enchantId = 0x0000FFFF & ((*enchants) >> enchantSlot * 16);
if (!enchantId)
{
continue;
}
enchant = sSpellItemEnchantmentStore.LookupEntry(enchantId);
if (enchant)
{
break;
}
}
*data << uint32(proto->DisplayInfoID);

View File

@@ -1516,8 +1516,6 @@ public:
[[nodiscard]] bool isBeingLoaded() const override;
void Initialize(ObjectGuid::LowType guid);
static uint32 GetUInt32ValueFromArray(Tokenizer const& data, uint16 index);
static float GetFloatValueFromArray(Tokenizer const& data, uint16 index);
static uint32 GetZoneIdFromDB(ObjectGuid guid);
static bool LoadPositionFromDB(uint32& mapid, float& x, float& y, float& z, float& o, bool& in_flight, ObjectGuid::LowType guid);
@@ -1532,8 +1530,6 @@ public:
void SaveInventoryAndGoldToDB(CharacterDatabaseTransaction trans); // fast save function for item/money cheating preventing
void SaveGoldToDB(CharacterDatabaseTransaction trans);
static void SetUInt32ValueInArray(Tokenizer& data, uint16 index, uint32 value);
static void SetFloatValueInArray(Tokenizer& data, uint16 index, float value);
static void Customize(CharacterCustomizeInfo const* customizeInfo, CharacterDatabaseTransaction trans);
static void SavePositionInDB(uint32 mapid, float x, float y, float z, float o, uint32 zone, ObjectGuid guid);
static void SavePositionInDB(WorldLocation const& loc, uint16 zoneId, ObjectGuid guid, CharacterDatabaseTransaction trans);

View File

@@ -100,17 +100,6 @@ void Player::SavePositionInDB(WorldLocation const& loc, uint16 zoneId, ObjectGui
CharacterDatabase.ExecuteOrAppend(trans, stmt);
}
void Player::SetUInt32ValueInArray(Tokenizer& tokens, uint16 index, uint32 value)
{
char buf[11];
snprintf(buf, 11, "%u", value);
if (index >= tokens.size())
return;
tokens[index] = buf;
}
void Player::Customize(CharacterCustomizeInfo const* customizeInfo, CharacterDatabaseTransaction trans)
{
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_GENDER_AND_APPEARANCE);

View File

@@ -73,6 +73,8 @@
#include "WeatherMgr.h"
#include "World.h"
#include "WorldPacket.h"
#include "Tokenize.h"
#include "StringConvert.h"
// TODO: this import is not necessary for compilation and marked as unused by the IDE
// however, for some reasons removing it would cause a damn linking issue
@@ -4878,20 +4880,19 @@ void Player::_LoadEntryPointData(PreparedQueryResult result)
return;
Field* fields = result->Fetch();
m_entryPointData.joinPos = WorldLocation(fields[4].GetUInt32(), // Map
fields[0].GetFloat(), // X
fields[1].GetFloat(), // Y
fields[2].GetFloat(), // Z
fields[3].GetFloat()); // Orientation
m_entryPointData.joinPos = WorldLocation(fields[4].GetUInt32(), // Map
fields[0].GetFloat(), // X
fields[1].GetFloat(), // Y
fields[2].GetFloat(), // Z
fields[3].GetFloat()); // Orientation
std::string taxi = fields[5].GetString();
std::string_view taxi = fields[5].GetStringView();
if (!taxi.empty())
{
Tokenizer tokens(taxi, ' ');
for (Tokenizer::const_iterator iter = tokens.begin(); iter != tokens.end(); ++iter)
for (auto const& itr : Acore::Tokenize(taxi, ' ', false))
{
uint32 node = uint32(atol(*iter));
m_entryPointData.taxiPath.push_back(node);
uint32 node = Acore::StringTo<uint32>(itr).value_or(0);
m_entryPointData.taxiPath.emplace_back(node);
}
// Check integrity
@@ -4940,23 +4941,6 @@ void Player::SetHomebind(WorldLocation const& loc, uint32 areaId)
CharacterDatabase.Execute(stmt);
}
uint32 Player::GetUInt32ValueFromArray(Tokenizer const& data, uint16 index)
{
if (index >= data.size())
return 0;
return (uint32)atoi(data[index]);
}
float Player::GetFloatValueFromArray(Tokenizer const& data, uint16 index)
{
float result;
uint32 temp = Player::GetUInt32ValueFromArray(data, index);
memcpy(&result, &temp, sizeof(result));
return result;
}
bool Player::isBeingLoaded() const
{
return GetSession()->PlayerLoading();
@@ -5039,8 +5023,15 @@ bool Player::LoadFromDB(ObjectGuid playerGuid, CharacterDatabaseQueryHolder cons
SetUInt32Value(UNIT_FIELD_LEVEL, fields[6].GetUInt8());
SetUInt32Value(PLAYER_XP, fields[7].GetUInt32());
_LoadIntoDataField(fields[66].GetCString(), PLAYER_EXPLORED_ZONES_1, PLAYER_EXPLORED_ZONES_SIZE);
_LoadIntoDataField(fields[69].GetCString(), PLAYER__FIELD_KNOWN_TITLES, KNOWN_TITLES_SIZE * 2);
if (!_LoadIntoDataField(fields[66].GetString(), PLAYER_EXPLORED_ZONES_1, PLAYER_EXPLORED_ZONES_SIZE))
{
FMT_LOG_WARN("entities.player.loading", "Player::LoadFromDB: Player ({}) has invalid exploredzones data ({}). Forcing partial load.", guid, fields[66].GetStringView());
}
if (!_LoadIntoDataField(fields[69].GetString(), PLAYER__FIELD_KNOWN_TITLES, KNOWN_TITLES_SIZE * 2))
{
FMT_LOG_WARN("entities.player.loading", "Player::LoadFromDB: Player ({}) has invalid knowntitles mask ({}). Forcing partial load.", guid, fields[69].GetStringView());
}
SetObjectScale(1.0f);
SetFloatValue(UNIT_FIELD_HOVERHEIGHT, 1.0f);
@@ -5117,7 +5108,7 @@ bool Player::LoadFromDB(ObjectGuid playerGuid, CharacterDatabaseQueryHolder cons
std::string taxi_nodes = fields[42].GetString();
#define RelocateToHomebind(){ mapId = m_homebindMapId; instanceId = 0; Relocate(m_homebindX, m_homebindY, m_homebindZ); }
auto RelocateToHomebind = [this, &mapId, &instanceId]() { mapId = m_homebindMapId; instanceId = 0; Relocate(m_homebindX, m_homebindY, m_homebindZ); };
_LoadGroup();
@@ -6063,13 +6054,21 @@ Item* Player::_LoadItem(CharacterDatabaseTransaction trans, uint32 zoneId, uint3
{
stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_ITEM_BOP_TRADE);
stmt->setUInt32(0, item->GetGUID().GetCounter());
if (PreparedQueryResult result = CharacterDatabase.Query(stmt))
{
std::string strGUID = (*result)[0].GetString();
Tokenizer GUIDlist(strGUID, ' ');
AllowedLooterSet looters;
for (Tokenizer::const_iterator itr = GUIDlist.begin(); itr != GUIDlist.end(); ++itr)
looters.insert(ObjectGuid::Create<HighGuid::Player>(atol(*itr)));
for (std::string_view guidStr : Acore::Tokenize((*result)[0].GetStringView(), ' ', false))
{
if (Optional<ObjectGuid::LowType> guid = Acore::StringTo<ObjectGuid::LowType>(guidStr))
{
looters.insert(ObjectGuid::Create<HighGuid::Player>(*guid));
}
else
{
FMT_LOG_WARN("entities.player.loading", "Player::_LoadInventory: invalid item_soulbound_trade_data GUID '%s' for item %s. Skipped.", guidStr, item->GetGUID().ToString());
}
}
if (looters.size() > 1 && item->GetTemplate()->GetMaxStackSize() == 1 && item->IsSoulBound())
{

View File

@@ -17,6 +17,8 @@
#include "ObjectMgr.h"
#include "Player.h"
#include "Tokenize.h"
#include "StringConvert.h"
PlayerTaxi::PlayerTaxi() : _taxiSegment(0)
{
@@ -89,18 +91,31 @@ void PlayerTaxi::InitTaxiNodesForLevel(uint32 race, uint32 chrClass, uint8 level
SetTaximaskNode(213); //Shattered Sun Staging Area
}
void PlayerTaxi::LoadTaxiMask(std::string const& data)
bool PlayerTaxi::LoadTaxiMask(std::string_view data)
{
Tokenizer tokens(data, ' ');
bool warn = false;
std::vector<std::string_view> tokens = Acore::Tokenize(data, ' ', false);
uint8 index;
Tokenizer::const_iterator iter;
for (iter = tokens.begin(), index = 0;
(index < TaxiMaskSize) && (iter != tokens.end()); ++iter, ++index)
for (uint8 index = 0; (index < TaxiMaskSize) && (index < tokens.size()); ++index)
{
// load and set bits only for existed taxi nodes
m_taximask[index] = sTaxiNodesMask[index] & uint32(atol(*iter));
if (Optional<uint32> mask = Acore::StringTo<uint32>(tokens[index]))
{
// load and set bits only for existing taxi nodes
m_taximask[index] = sTaxiNodesMask[index] & *mask;
if (m_taximask[index] != *mask)
{
warn = true;
}
}
else
{
m_taximask[index] = 0;
warn = true;
}
}
return !warn;
}
void PlayerTaxi::AppendTaximaskTo(ByteBuffer& data, bool all)
@@ -121,12 +136,16 @@ bool PlayerTaxi::LoadTaxiDestinationsFromString(const std::string& values, TeamI
{
ClearTaxiDestinations();
Tokenizer tokens(values, ' ');
for (Tokenizer::const_iterator iter = tokens.begin(); iter != tokens.end(); ++iter)
for (auto const& itr : Acore::Tokenize(values, ' ', false))
{
uint32 node = uint32(atol(*iter));
AddTaxiDestination(node);
if (Optional<uint32> node = Acore::StringTo<uint32>(itr))
{
AddTaxiDestination(*node);
}
else
{
return false;
}
}
// Check integrity

View File

@@ -31,7 +31,7 @@ public:
// Nodes
void InitTaxiNodesForLevel(uint32 race, uint32 chrClass, uint8 level);
void LoadTaxiMask(std::string const& data);
bool LoadTaxiMask(std::string_view data);
[[nodiscard]] bool IsTaximaskNodeKnown(uint32 nodeidx) const
{