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

@@ -148,7 +148,13 @@ bool Corpse::LoadCorpseFromDB(ObjectGuid::LowType guid, Field* fields)
SetObjectScale(1.0f);
SetUInt32Value(CORPSE_FIELD_DISPLAY_ID, fields[5].GetUInt32());
_LoadIntoDataField(fields[6].GetCString(), CORPSE_FIELD_ITEM, EQUIPMENT_SLOT_END);
if (!_LoadIntoDataField(fields[6].GetString(), CORPSE_FIELD_ITEM, EQUIPMENT_SLOT_END))
{
FMT_LOG_ERROR("entities.player", "Corpse ({}, owner: {}) is not created, given equipment info is not valid ('{}')",
GetGUID().ToString(), GetOwnerGUID().ToString(), fields[6].GetString());
}
SetUInt32Value(CORPSE_FIELD_BYTES_1, fields[7].GetUInt32());
SetUInt32Value(CORPSE_FIELD_BYTES_2, fields[8].GetUInt32());
SetUInt32Value(CORPSE_FIELD_GUILD, fields[9].GetUInt32());

View File

@@ -27,6 +27,8 @@
#include "SpellMgr.h"
#include "WorldPacket.h"
#include "WorldSession.h"
#include "Tokenize.h"
#include "StringConvert.h"
void AddItemsSetItem(Player* player, Item* item)
{
@@ -410,7 +412,10 @@ bool Item::LoadFromDB(ObjectGuid::LowType guid, ObjectGuid owner_guid, Field* fi
ItemTemplate const* proto = GetTemplate();
if (!proto)
{
FMT_LOG_ERROR("entities.item", "Invalid entry {} for item {}. Refusing to load.", GetEntry(), GetGUID().ToString());
return false;
}
// set owner (not if item is only loaded for gbank/auction/mail
if (owner_guid)
@@ -430,10 +435,17 @@ bool Item::LoadFromDB(ObjectGuid::LowType guid, ObjectGuid owner_guid, Field* fi
need_save = true;
}
Tokenizer tokens(fields[4].GetString(), ' ', MAX_ITEM_PROTO_SPELLS);
std::vector<std::string_view> tokens = Acore::Tokenize(fields[4].GetStringView(), ' ', false);
if (tokens.size() == MAX_ITEM_PROTO_SPELLS)
{
for (uint8 i = 0; i < MAX_ITEM_PROTO_SPELLS; ++i)
SetSpellCharges(i, atoi(tokens[i]));
{
if (Optional<int32> charges = Acore::StringTo<int32>(tokens[i]))
SetSpellCharges(i, *charges);
else
FMT_LOG_ERROR("entities.item", "Invalid charge info '{}' for item {}, charge data not loaded.", tokens.at(i), GetGUID().ToString());
}
}
SetUInt32Value(ITEM_FIELD_FLAGS, fields[5].GetUInt32());
// Remove bind flag for items vs NO_BIND set
@@ -444,7 +456,12 @@ bool Item::LoadFromDB(ObjectGuid::LowType guid, ObjectGuid owner_guid, Field* fi
}
std::string enchants = fields[6].GetString();
_LoadIntoDataField(enchants.c_str(), ITEM_FIELD_ENCHANTMENT_1_1, MAX_ENCHANTMENT_SLOT * MAX_ENCHANTMENT_OFFSET);
if (!_LoadIntoDataField(fields[6].GetString(), ITEM_FIELD_ENCHANTMENT_1_1, MAX_ENCHANTMENT_SLOT * MAX_ENCHANTMENT_OFFSET))
{
FMT_LOG_WARN("entities.item", "Invalid enchantment data '{}' for item {}. Forcing partial load.", fields[6].GetString(), GetGUID().ToString());
}
SetInt32Value(ITEM_FIELD_RANDOM_PROPERTIES_ID, fields[7].GetInt16());
// recalculate suffix factor
if (GetItemRandomPropertyId() < 0)

View File

@@ -48,6 +48,8 @@
#include "Vehicle.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
@@ -610,21 +612,29 @@ uint32 Object::GetUpdateFieldData(Player const* target, uint32*& flags) const
return visibleFlag;
}
void Object::_LoadIntoDataField(std::string const& data, uint32 startOffset, uint32 count)
bool Object::_LoadIntoDataField(std::string const& data, uint32 startOffset, uint32 count)
{
if (data.empty())
return;
return false;
Tokenizer tokens(data, ' ', count);
std::vector<std::string_view> tokens = Acore::Tokenize(data, ' ', false);
if (tokens.size() != count)
return;
return false;
for (uint32 index = 0; index < count; ++index)
{
m_uint32Values[startOffset + index] = atol(tokens[index]);
Optional<uint32> val = Acore::StringTo<uint32>(tokens[index]);
if (!val)
{
return false;
}
m_uint32Values[startOffset + index] = *val;
_changesMask.SetBit(startOffset + index);
}
return true;
}
void Object::SetInt32Value(uint16 index, int32 value)

View File

@@ -202,7 +202,7 @@ protected:
void _InitValues();
void _Create(ObjectGuid::LowType guidlow, uint32 entry, HighGuid guidhigh);
[[nodiscard]] std::string _ConcatFields(uint16 startIndex, uint16 size) const;
void _LoadIntoDataField(std::string const& data, uint32 startOffset, uint32 count);
bool _LoadIntoDataField(std::string const& data, uint32 startOffset, uint32 count);
uint32 GetUpdateFieldData(Player const* target, uint32*& flags) const;

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
{

View File

@@ -67,6 +67,8 @@
#include "Vehicle.h"
#include "World.h"
#include "WorldPacket.h"
#include "Tokenize.h"
#include "StringConvert.h"
#include <math.h>
float baseMoveSpeed[MAX_MOVE_TYPE] =
@@ -15218,30 +15220,36 @@ void CharmInfo::SetPetNumber(uint32 petnumber, bool statwindow)
void CharmInfo::LoadPetActionBar(const std::string& data)
{
Tokenizer tokens(data, ' ');
std::vector<std::string_view> tokens = Acore::Tokenize(data, ' ', false);
if (tokens.size() != (ACTION_BAR_INDEX_END - ACTION_BAR_INDEX_START) * 2)
return; // non critical, will reset to default
uint8 index = ACTION_BAR_INDEX_START;
Tokenizer::const_iterator iter = tokens.begin();
for (; index < ACTION_BAR_INDEX_END; ++iter, ++index)
auto iter = tokens.begin();
for (uint8 index = ACTION_BAR_INDEX_START; index < ACTION_BAR_INDEX_END; ++index)
{
// use unsigned cast to avoid sign negative format use at long-> ActiveStates (int) conversion
ActiveStates type = ActiveStates(atol(*iter));
++iter;
uint32 action = uint32(atol(*iter));
Optional<uint8> type = Acore::StringTo<uint8>(*(iter++));
Optional<uint32> action = Acore::StringTo<uint32>(*(iter++));
PetActionBar[index].SetActionAndType(action, type);
if (!type || !action)
{
continue;
}
PetActionBar[index].SetActionAndType(*action, static_cast<ActiveStates>(*type));
// check correctness
if (PetActionBar[index].IsActionBarForSpell())
{
SpellInfo const* spelInfo = sSpellMgr->GetSpellInfo(PetActionBar[index].GetAction());
if (!spelInfo)
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(PetActionBar[index].GetAction());
if (!spellInfo)
{
SetActionBar(index, 0, ACT_PASSIVE);
else if (!spelInfo->IsAutocastable())
}
else if (!spellInfo->IsAutocastable())
{
SetActionBar(index, PetActionBar[index].GetAction(), ACT_PASSIVE);
}
}
}
}

View File

@@ -972,7 +972,7 @@ private:
GlobalCooldownList m_GlobalCooldowns;
};
enum ActiveStates
enum ActiveStates : uint8
{
ACT_PASSIVE = 0x01, // 0x01 - passive
ACT_DISABLED = 0x81, // 0x80 - castable