DarkflameServer/dGame/dComponents/ItemComponent.cpp
EmosewaMC c22040c6eb ItemComponent Pass
make use of Writing a length
add C include guard
2023-07-04 22:17:44 -07:00

33 lines
1014 B
C++

#include "ItemComponent.h"
#include "Entity.h"
#include "eUgcModerationStatus.h"
ItemComponent::ItemComponent(Entity* parent) : Component(parent) {
m_ParentEntity = parent;
m_DirtyItemInfo = false;
m_UgId = m_ParentEntity->GetVarAs<LWOOBJID>(u"userModelID");
if (m_UgId == LWOOBJID_EMPTY) m_UgId = m_ParentEntity->GetObjectID();
m_UgModerationStatus = eUgcModerationStatus::NoStatus;
m_UgDescription = u"";
}
void ItemComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
outBitStream->Write(m_DirtyItemInfo || bIsInitialUpdate);
if (m_DirtyItemInfo || bIsInitialUpdate) {
outBitStream->Write(m_UgId);
outBitStream->Write(m_UgModerationStatus);
outBitStream->Write(!m_UgDescription.empty());
if (!m_UgDescription.empty()){
outBitStream->Write<uint32_t>(m_UgDescription.length());
outBitStream->Write(reinterpret_cast<const char*>(m_UgDescription.c_str()), m_UgDescription.length() * sizeof(uint16_t));
}
m_DirtyItemInfo = false;
}
}