diff --git a/Sources/Plasma/NucleusLib/pnNetProtocol/Private/pnNpCommon.cpp b/Sources/Plasma/NucleusLib/pnNetProtocol/Private/pnNpCommon.cpp index 550acb3c..3f619dbe 100644 --- a/Sources/Plasma/NucleusLib/pnNetProtocol/Private/pnNpCommon.cpp +++ b/Sources/Plasma/NucleusLib/pnNetProtocol/Private/pnNpCommon.cpp @@ -53,9 +53,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com namespace pnNpCommon { -// Verify our uint64_t constants were properly inited as such. -static_assert(NetVaultNode::kBlob_2, "NetVaultNode constants failed to init"); - /***************************************************************************** @@ -297,489 +294,289 @@ void NetGameRank::CopyFrom(const NetGameRank & fromRank) { ***/ //============================================================================ -void NetVaultNode::DeallocNodeFields () { - free(createAgeName); - free(string64_1); - free(string64_2); - free(string64_3); - free(string64_4); - free(string64_5); - free(string64_6); - free(istring64_1); - free(istring64_2); - free(text_1); - free(text_2); - free(blob_1); - free(blob_2); -} - -//============================================================================ -NetVaultNode::NetVaultNode () - : hsRefCnt(0), fieldFlags(0), dirtyFlags(0) - , nodeId(0), createTime(0), modifyTime(0) - , createAgeName(nil), creatorId(0) - , nodeType(0) - , int32_1(0), int32_2(0), int32_3(0), int32_4(0) - , uint32_1(0), uint32_2(0), uint32_3(0), uint32_4(0) - , string64_1(nil), string64_2(nil), string64_3(nil), string64_4(nil) - , string64_5(nil), string64_6(nil) - , istring64_1(nil), istring64_2(nil) - , text_1(nil), text_2(nil) - , blob_1(nil), blob_1Length(0), blob_2(nil), blob_2Length(0) { } - -//============================================================================ -NetVaultNode::~NetVaultNode () { - DeallocNodeFields(); -} - -//============================================================================ -uint32_t NetVaultNode::Read_LCS (const uint8_t inbuffer[], uint32_t bufsz, unsigned rwOpts) { - - DeallocNodeFields(); - - uint8_t * buffer = const_cast(inbuffer); - uint8_t * start = buffer; - - IReadValue(&fieldFlags, &buffer, &bufsz); - - #define READ(flag, func, varptr) if (flag & fieldFlags) func(varptr, &buffer, &bufsz); - #define READARR(flag, func, varptr, lenptr) if (flag & fieldFlags) func(varptr, lenptr, &buffer, &bufsz); - READ(kNodeId, IReadValue, &nodeId); - READ(kCreateTime, IReadValue, &createTime); - READ(kModifyTime, IReadValue, &modifyTime); - READ(kCreateAgeName,IReadString, &createAgeName); - READ(kCreateAgeUuid,IReadValue, &createAgeUuid); - READ(kCreatorAcct, IReadValue, &creatorAcct); - READ(kCreatorId, IReadValue, &creatorId); - READ(kNodeType, IReadValue, &nodeType); - READ(kInt32_1, IReadValue, &int32_1); - READ(kInt32_2, IReadValue, &int32_2); - READ(kInt32_3, IReadValue, &int32_3); - READ(kInt32_4, IReadValue, &int32_4); - READ(kUInt32_1, IReadValue, &uint32_1); - READ(kUInt32_2, IReadValue, &uint32_2); - READ(kUInt32_3, IReadValue, &uint32_3); - READ(kUInt32_4, IReadValue, &uint32_4); - READ(kUuid_1, IReadValue, &uuid_1); - READ(kUuid_2, IReadValue, &uuid_2); - READ(kUuid_3, IReadValue, &uuid_3); - READ(kUuid_4, IReadValue, &uuid_4); - READ(kString64_1, IReadString, &string64_1); - READ(kString64_2, IReadString, &string64_2); - READ(kString64_3, IReadString, &string64_3); - READ(kString64_4, IReadString, &string64_4); - READ(kString64_5, IReadString, &string64_5); - READ(kString64_6, IReadString, &string64_6); - READ(kIString64_1, IReadString, &istring64_1); - READ(kIString64_2, IReadString, &istring64_2); - READ(kText_1, IReadString, &text_1); - READ(kText_2, IReadString, &text_2); - READARR(kBlob_1, IReadArray, &blob_1, &blob_1Length); - READARR(kBlob_2, IReadArray, &blob_2, &blob_2Length); - #undef READARR - #undef READ - - if (fieldFlags & ~kAllValidFields) - FATAL("Invalid field flag(s) encountered"); - - if (rwOpts & kRwUpdateDirty) - dirtyFlags = fieldFlags; - else - dirtyFlags = 0; - - return buffer - start; -} - -//============================================================================ -uint32_t NetVaultNode::Write_LCS (ARRAY(uint8_t) * buffer, unsigned rwOpts) { - - unsigned pos = buffer->Count(); - - uint64_t flags = fieldFlags; - - if (rwOpts & kRwDirtyOnly) - flags &= dirtyFlags; - - if (!flags) - return 0; - - IWriteValue(flags, buffer); - - #define WRITE(flag, func, var) if (flag & flags) func(var, buffer); - #define WRITEARR(flag, func, var, len) if (flag & flags) func(var, len, buffer); - WRITE(kNodeId, IWriteValue, nodeId ); - WRITE(kCreateTime, IWriteValue, createTime ); - WRITE(kModifyTime, IWriteValue, modifyTime ); - WRITE(kCreateAgeName, IWriteString, createAgeName ? createAgeName : L"" ); - WRITE(kCreateAgeUuid, IWriteValue, createAgeUuid ); - WRITE(kCreatorAcct, IWriteValue, creatorAcct ); - WRITE(kCreatorId, IWriteValue, creatorId ); - WRITE(kNodeType, IWriteValue, nodeType ); - WRITE(kInt32_1, IWriteValue, int32_1 ); - WRITE(kInt32_2, IWriteValue, int32_2 ); - WRITE(kInt32_3, IWriteValue, int32_3 ); - WRITE(kInt32_4, IWriteValue, int32_4 ); - WRITE(kUInt32_1, IWriteValue, uint32_1 ); - WRITE(kUInt32_2, IWriteValue, uint32_2 ); - WRITE(kUInt32_3, IWriteValue, uint32_3 ); - WRITE(kUInt32_4, IWriteValue, uint32_4 ); - WRITE(kUuid_1, IWriteValue, uuid_1 ); - WRITE(kUuid_2, IWriteValue, uuid_2 ); - WRITE(kUuid_3, IWriteValue, uuid_3 ); - WRITE(kUuid_4, IWriteValue, uuid_4 ); - WRITE(kString64_1, IWriteString, string64_1 ? string64_1 : L"" ); - WRITE(kString64_2, IWriteString, string64_2 ? string64_2 : L"" ); - WRITE(kString64_3, IWriteString, string64_3 ? string64_3 : L"" ); - WRITE(kString64_4, IWriteString, string64_4 ? string64_4 : L"" ); - WRITE(kString64_5, IWriteString, string64_5 ? string64_5 : L"" ); - WRITE(kString64_6, IWriteString, string64_6 ? string64_6 : L"" ); - WRITE(kIString64_1, IWriteString, istring64_1 ? istring64_1 : L"" ); - WRITE(kIString64_2, IWriteString, istring64_2 ? istring64_2 : L"" ); - WRITE(kText_1, IWriteString, text_1 ? text_1 : L"" ); - WRITE(kText_2, IWriteString, text_2 ? text_2 : L"" ); - WRITEARR(kBlob_1, IWriteArray, blob_1, blob_1Length); - WRITEARR(kBlob_2, IWriteArray, blob_2, blob_2Length); - #undef WRITEARR - #undef WRITE - - if (flags & ~kAllValidFields) - FATAL("Invalid field flag(s) encountered"); - - if (rwOpts & kRwUpdateDirty) - dirtyFlags = 0; - // else, preserve existing dirtyFlags value - - return buffer->Count() - pos; +bool NetVaultNode::Blob::operator==(const Blob& rhs) const +{ + if (size == rhs.size) + return memcmp(buffer, rhs.buffer, size) == 0; + return false; } //============================================================================ -bool NetVaultNode::Matches (const NetVaultNode * other) { +void NetVaultNode::Clear() +{ + // Sneaky -- we're just going to set the fields to empty. + // If a field is neither used nor dirty, it doesn't matter what value it actually has. + fUsedFields = 0; + fDirtyFields = 0; + fRevision = kNilUuid; +} + +//============================================================================ +void NetVaultNode::CopyFrom(const NetVaultNode* node) +{ + fUsedFields = node->fUsedFields; + fDirtyFields = node->fDirtyFields; + fRevision = node->fRevision; + +#define COPY(field) f##field = node->f##field + COPY(NodeId); + COPY(CreateTime); + COPY(ModifyTime); + COPY(CreateAgeName); + COPY(CreateAgeUuid); + COPY(CreatorAcct); + COPY(CreatorId); + COPY(NodeType); + COPY(Int32_1); + COPY(Int32_2); + COPY(Int32_3); + COPY(Int32_4); + COPY(UInt32_1); + COPY(UInt32_2); + COPY(UInt32_3); + COPY(UInt32_4); + COPY(Uuid_1); + COPY(Uuid_2); + COPY(Uuid_3); + COPY(Uuid_4); + COPY(String64_1); + COPY(String64_2); + COPY(String64_3); + COPY(String64_4); + COPY(String64_5); + COPY(String64_6); + COPY(IString64_1); + COPY(IString64_2); + COPY(Text_1); + COPY(Text_2); + COPY(Blob_1); + COPY(Blob_2); +#undef COPY +} + +//============================================================================ +bool NetVaultNode::Matches(const NetVaultNode* rhs) const +{ for (uint64_t bit = 1; bit; bit <<= 1) { - // if bit has gone past all set fields on the other node without failing, return true - if (bit > other->fieldFlags) + // If we have tested all fields on the other node, we obviously match. + if (bit > rhs->fUsedFields) return true; - // if the other node does not have the field, then continue to next field - if (!(bit & other->fieldFlags)) + // If the other node does not have the field, then continue to next field + if (!(bit & rhs->fUsedFields)) continue; - // if we don't have the field (but the other node does), then return false - if (!(bit & fieldFlags)) + // If we don't have this field, but the other node does, we are obviously not the same. + if (!(bit & fUsedFields)) return false; - #define COMPARE(flag, func, var) case flag: if (!func(var, other->var)) return false; break - switch (bit) { - COMPARE(kNodeId, ICompareValue, nodeId); - COMPARE(kCreateTime, ICompareValue, createTime); - COMPARE(kModifyTime, ICompareValue, modifyTime); - COMPARE(kCreateAgeName, ICompareStringI, createAgeName); - COMPARE(kCreateAgeUuid, ICompareValue, createAgeUuid); - COMPARE(kCreatorAcct, ICompareValue, creatorAcct); - COMPARE(kCreatorId, ICompareValue, creatorId); - COMPARE(kNodeType, ICompareValue, nodeType); - COMPARE(kInt32_1, ICompareValue, int32_1); - COMPARE(kInt32_2, ICompareValue, int32_2); - COMPARE(kInt32_3, ICompareValue, int32_3); - COMPARE(kInt32_4, ICompareValue, int32_4); - COMPARE(kUInt32_1, ICompareValue, uint32_1); - COMPARE(kUInt32_2, ICompareValue, uint32_2); - COMPARE(kUInt32_3, ICompareValue, uint32_3); - COMPARE(kUInt32_4, ICompareValue, uint32_4); - COMPARE(kUuid_1, ICompareValue, uuid_1); - COMPARE(kUuid_2, ICompareValue, uuid_2); - COMPARE(kUuid_3, ICompareValue, uuid_3); - COMPARE(kUuid_4, ICompareValue, uuid_4); - COMPARE(kString64_1, ICompareString, string64_1); - COMPARE(kString64_2, ICompareString, string64_2); - COMPARE(kString64_3, ICompareString, string64_3); - COMPARE(kString64_4, ICompareString, string64_4); - COMPARE(kString64_5, ICompareString, string64_5); - COMPARE(kString64_6, ICompareString, string64_6); - COMPARE(kIString64_1, ICompareStringI, istring64_1); - COMPARE(kIString64_2, ICompareStringI, istring64_2); - COMPARE(kText_1, ICompareString, text_1); - COMPARE(kText_2, ICompareString, text_2); - COMPARE(kBlob_1, ICompareArray, blob_1); - COMPARE(kBlob_2, ICompareArray, blob_2); - DEFAULT_FATAL(bit); - } - #undef COMPARE +#define COMPARE(field) if (k##field == bit && f##field != rhs->f##field) return false; +#define COMPARE_ISTRING(field) if (k##field == bit && f##field.CompareI(rhs->f##field) != 0) return false; + COMPARE(NodeId); + COMPARE(CreateTime); + COMPARE(ModifyTime); + COMPARE_ISTRING(CreateAgeName); + COMPARE(CreateAgeUuid); + COMPARE(CreatorAcct); + COMPARE(CreatorId); + COMPARE(NodeType); + COMPARE(Int32_1); + COMPARE(Int32_2); + COMPARE(Int32_3); + COMPARE(Int32_4); + COMPARE(UInt32_1); + COMPARE(UInt32_2); + COMPARE(UInt32_3); + COMPARE(UInt32_4); + COMPARE(Uuid_1); + COMPARE(Uuid_2); + COMPARE(Uuid_3); + COMPARE(Uuid_4); + COMPARE(String64_1); + COMPARE(String64_2); + COMPARE(String64_3); + COMPARE(String64_4); + COMPARE(String64_5); + COMPARE(String64_6); + COMPARE_ISTRING(IString64_1); + COMPARE_ISTRING(IString64_2); + COMPARE(Text_1); + COMPARE(Text_2); + COMPARE(Blob_1); + COMPARE(Blob_2); +#undef COMPARE +#undef COMPARE_ISTRING } + + // We should never get here, but this silences a warning. return true; } //============================================================================ -void NetVaultNode::CopyFrom (const NetVaultNode * other, unsigned copyOpts) { - if (this == other) - return; - - uint64_t origDirtyFlags = dirtyFlags; - - for (uint64_t bit = 1; bit; bit <<= 1) { - // we already have a value for this field... - if (bit & fieldFlags) { - if (!(copyOpts & kCopyOverwrite)) - continue; // don't overwrite our field value - } - - // other does not have a value for this field... - if (!(bit & other->fieldFlags)) { - // clear our field? - if (!(copyOpts & kCopyClear)) - continue; - // clear our field. - if (bit & fieldFlags) { - #define _ZERO(flag, func, var, z) case flag: func(bit, &var, z); break - #define _ZEROSTRING(flag, func, var, z) case flag: func(bit, &var, z, kMaxVaultNodeStringLength); break - #define _ZEROCLOB(flag, func, var, z) case flag: func(bit, &var, z, (unsigned)-1); break - #define _ZEROARR(flag, func, var, varlen) case flag: func(bit, &var, &varlen, nil, 0); break - switch (bit) { - _ZERO(kNodeId, IVaultNodeSetValue, nodeId, (unsigned)0); - _ZERO(kCreateTime, IVaultNodeSetValue, createTime, (unsigned)0); - _ZERO(kModifyTime, IVaultNodeSetValue, modifyTime, (unsigned)0); - _ZEROSTRING(kCreateAgeName, IVaultNodeSetString, createAgeName, L""); - _ZERO(kCreateAgeUuid, IVaultNodeSetValue, createAgeUuid, kNilUuid); - _ZERO(kCreatorAcct, IVaultNodeSetValue, creatorAcct, kNilUuid); - _ZERO(kCreatorId, IVaultNodeSetValue, creatorId, (unsigned)0); - _ZERO(kNodeType, IVaultNodeSetValue, nodeType, (unsigned)0); - _ZERO(kInt32_1, IVaultNodeSetValue, int32_1, (signed)0); - _ZERO(kInt32_2, IVaultNodeSetValue, int32_2, (signed)0); - _ZERO(kInt32_3, IVaultNodeSetValue, int32_3, (signed)0); - _ZERO(kInt32_4, IVaultNodeSetValue, int32_4, (signed)0); - _ZERO(kUInt32_1, IVaultNodeSetValue, uint32_1, (unsigned)0); - _ZERO(kUInt32_2, IVaultNodeSetValue, uint32_2, (unsigned)0); - _ZERO(kUInt32_3, IVaultNodeSetValue, uint32_3, (unsigned)0); - _ZERO(kUInt32_4, IVaultNodeSetValue, uint32_4, (unsigned)0); - _ZERO(kUuid_1, IVaultNodeSetValue, uuid_1, kNilUuid); - _ZERO(kUuid_2, IVaultNodeSetValue, uuid_2, kNilUuid); - _ZERO(kUuid_3, IVaultNodeSetValue, uuid_3, kNilUuid); - _ZERO(kUuid_4, IVaultNodeSetValue, uuid_4, kNilUuid); - _ZEROSTRING(kString64_1, IVaultNodeSetString, string64_1, L""); - _ZEROSTRING(kString64_2, IVaultNodeSetString, string64_2, L""); - _ZEROSTRING(kString64_3, IVaultNodeSetString, string64_3, L""); - _ZEROSTRING(kString64_4, IVaultNodeSetString, string64_4, L""); - _ZEROSTRING(kString64_5, IVaultNodeSetString, string64_5, L""); - _ZEROSTRING(kString64_6, IVaultNodeSetString, string64_6, L""); - _ZEROSTRING(kIString64_1, IVaultNodeSetString, istring64_1, L""); - _ZEROSTRING(kIString64_2, IVaultNodeSetString, istring64_2, L""); - _ZEROCLOB(kText_1, IVaultNodeSetString, text_1, L""); - _ZEROCLOB(kText_2, IVaultNodeSetString, text_2, L""); - _ZEROARR(kBlob_1, IVaultNodeSetBlob, blob_1, blob_1Length); - _ZEROARR(kBlob_2, IVaultNodeSetBlob, blob_2, blob_2Length); - DEFAULT_FATAL(bit); - } - #undef _ZEROARR - #undef _ZEROCLOB - #undef _ZEROSTRING - #undef _ZERO - } - } - - #define COPY(flag, func, var) case flag: func(bit, &var, other->var); break - #define COPYSTRING(flag, func, var) case flag: func(bit, &var, other->var, kMaxVaultNodeStringLength); break - #define COPYCLOB(flag, func, var) case flag: func(bit, &var, other->var, (unsigned)-1); break - #define COPYARR(flag, func, var, varlen) case flag: func(bit, &var, &varlen, other->var, other->varlen); break - switch (bit) { - COPY(kNodeId, IVaultNodeSetValue, nodeId ); - COPY(kCreateTime, IVaultNodeSetValue, createTime ); - COPY(kModifyTime, IVaultNodeSetValue, modifyTime ); - COPYSTRING(kCreateAgeName, IVaultNodeSetString, createAgeName ); - COPY(kCreateAgeUuid, IVaultNodeSetValue, createAgeUuid ); - COPY(kCreatorAcct, IVaultNodeSetValue, creatorAcct ); - COPY(kCreatorId, IVaultNodeSetValue, creatorId ); - COPY(kNodeType, IVaultNodeSetValue, nodeType ); - COPY(kInt32_1, IVaultNodeSetValue, int32_1 ); - COPY(kInt32_2, IVaultNodeSetValue, int32_2 ); - COPY(kInt32_3, IVaultNodeSetValue, int32_3 ); - COPY(kInt32_4, IVaultNodeSetValue, int32_4 ); - COPY(kUInt32_1, IVaultNodeSetValue, uint32_1 ); - COPY(kUInt32_2, IVaultNodeSetValue, uint32_2 ); - COPY(kUInt32_3, IVaultNodeSetValue, uint32_3 ); - COPY(kUInt32_4, IVaultNodeSetValue, uint32_4 ); - COPY(kUuid_1, IVaultNodeSetValue, uuid_1 ); - COPY(kUuid_2, IVaultNodeSetValue, uuid_2 ); - COPY(kUuid_3, IVaultNodeSetValue, uuid_3 ); - COPY(kUuid_4, IVaultNodeSetValue, uuid_4 ); - COPYSTRING(kString64_1, IVaultNodeSetString, string64_1 ); - COPYSTRING(kString64_2, IVaultNodeSetString, string64_2 ); - COPYSTRING(kString64_3, IVaultNodeSetString, string64_3 ); - COPYSTRING(kString64_4, IVaultNodeSetString, string64_4 ); - COPYSTRING(kString64_5, IVaultNodeSetString, string64_5 ); - COPYSTRING(kString64_6, IVaultNodeSetString, string64_6 ); - COPYSTRING(kIString64_1, IVaultNodeSetString, istring64_1 ); - COPYSTRING(kIString64_2, IVaultNodeSetString, istring64_2 ); - COPYCLOB(kText_1, IVaultNodeSetString, text_1 ); - COPYCLOB(kText_2, IVaultNodeSetString, text_2 ); - COPYARR(kBlob_1, IVaultNodeSetBlob, blob_1, blob_1Length); - COPYARR(kBlob_2, IVaultNodeSetBlob, blob_2, blob_2Length); - DEFAULT_FATAL(bit); - } - #undef COPYARR - #undef COPYCLOB - #undef COPYSTRING - #undef COPY +template +static void IRead(const uint8_t*& buf, T& dest) +{ + const T* ptr = reinterpret_cast(buf); + dest = *ptr; + buf += sizeof(T); +} + +template<> +static void IRead(const uint8_t*& buf, plString& dest) +{ + uint32_t size = *(reinterpret_cast(buf)); + buf += sizeof(uint32_t); + + plStringBuffer str; + uint16_t* theStrBuffer = str.CreateWritableBuffer(size / sizeof(uint16_t)); + memcpy(theStrBuffer, buf, size); + dest = plString::FromUtf16(str); + buf += size; +} + +template<> +static void IRead(const uint8_t*& buf, NetVaultNode::Blob& blob) +{ + blob.size = *(reinterpret_cast(buf)); + buf += sizeof(uint32_t); + + delete[] blob.buffer; + blob.buffer = new uint8_t[blob.size]; + memcpy(blob.buffer, buf, blob.size); + buf += blob.size; +} + +void NetVaultNode::Read(const uint8_t* buf, size_t size) +{ + fUsedFields= *(reinterpret_cast(buf)); + buf += sizeof(uint64_t); + +#define READ(field) if (fUsedFields & k##field) IRead(buf, f##field); + READ(NodeId); + READ(CreateTime); + READ(ModifyTime); + READ(CreateAgeName); + READ(CreateAgeUuid); + READ(CreatorAcct); + READ(CreatorId); + READ(NodeType); + READ(Int32_1); + READ(Int32_2); + READ(Int32_3); + READ(Int32_4); + READ(UInt32_1); + READ(UInt32_2); + READ(UInt32_3); + READ(UInt32_4); + READ(Uuid_1); + READ(Uuid_2); + READ(Uuid_3); + READ(Uuid_4); + READ(String64_1); + READ(String64_2); + READ(String64_3); + READ(String64_4); + READ(String64_5); + READ(String64_6); + READ(IString64_1); + READ(IString64_2); + READ(Text_1); + READ(Text_2); + READ(Blob_1); + READ(Blob_2); +#undef READ + + fDirtyFields = 0; +} + +//============================================================================ +template +static void IWrite(ARRAY(uint8_t)* buffer, T value) +{ + uint8_t* ptr = buffer->New(sizeof(T)); + memcpy(ptr, &value, sizeof(T)); +} + +template<> +static void IWrite(ARRAY(uint8_t)* buffer, plString value) +{ + plStringBuffer utf16 = value.ToUtf16(); + uint32_t strsz = (utf16.GetSize() + 1) * 2; + IWrite(buffer, strsz); + + uint8_t* ptr = buffer->New(strsz); + memcpy(ptr, utf16.GetData(), strsz); +} + +template<> +static void IWrite(ARRAY(uint8_t)* buffer, const NetVaultNode::Blob& blob) +{ + IWrite(buffer, static_cast(blob.size)); + + if (blob.size > 0) { + uint8_t* ptr = buffer->New(blob.size); + memcpy(ptr, blob.buffer, blob.size); } - - if (!(copyOpts & kCopySetDirty)) - dirtyFlags = origDirtyFlags; -} - -//============================================================================ -void NetVaultNode::SetNodeId (unsigned v) { - IVaultNodeSetValue(kNodeId, &nodeId, v); -} - -//============================================================================ -void NetVaultNode::SetCreateTime (unsigned v) { - IVaultNodeSetValue(kCreateTime, &createTime, v); -} - -//============================================================================ -void NetVaultNode::SetModifyTime (unsigned v) { - IVaultNodeSetValue(kModifyTime, &modifyTime, v); -} - -//============================================================================ -void NetVaultNode::SetCreateAgeName (const wchar_t v[]) { - IVaultNodeSetString(kCreateAgeName, &createAgeName, v, kMaxVaultNodeStringLength); -} - -//============================================================================ -void NetVaultNode::SetCreateAgeUuid (const plUUID& v) { - IVaultNodeSetValue(kCreateAgeUuid, &createAgeUuid, v); -} - -//============================================================================ -void NetVaultNode::SetCreatorAcct (const plUUID& v) { - IVaultNodeSetValue(kCreatorAcct, &creatorAcct, v); -} - -//============================================================================ -void NetVaultNode::SetCreatorId (unsigned v) { - IVaultNodeSetValue(kCreatorId, &creatorId, v); -} - -//============================================================================ -void NetVaultNode::SetNodeType (unsigned v) { - IVaultNodeSetValue(kNodeType, &nodeType, v); -} - -//============================================================================ -void NetVaultNode::SetInt32_1 (int v) { - IVaultNodeSetValue(kInt32_1, &int32_1, v); -} - -//============================================================================ -void NetVaultNode::SetInt32_2 (int v) { - IVaultNodeSetValue(kInt32_2, &int32_2, v); -} - -//============================================================================ -void NetVaultNode::SetInt32_3 (int v) { - IVaultNodeSetValue(kInt32_3, &int32_3, v); } -//============================================================================ -void NetVaultNode::SetInt32_4 (int v) { - IVaultNodeSetValue(kInt32_4, &int32_4, v); -} - -//============================================================================ -void NetVaultNode::SetUInt32_1 (unsigned v) { - IVaultNodeSetValue(kUInt32_1, &uint32_1, v); -} - -//============================================================================ -void NetVaultNode::SetUInt32_2 (unsigned v) { - IVaultNodeSetValue(kUInt32_2, &uint32_2, v); -} - -//============================================================================ -void NetVaultNode::SetUInt32_3 (unsigned v) { - IVaultNodeSetValue(kUInt32_3, &uint32_3, v); -} - -//============================================================================ -void NetVaultNode::SetUInt32_4 (unsigned v) { - IVaultNodeSetValue(kUInt32_4, &uint32_4, v); -} - -//============================================================================ -void NetVaultNode::SetUuid_1 (const plUUID& v) { - IVaultNodeSetValue(kUuid_1, &uuid_1, v); -} - -//============================================================================ -void NetVaultNode::SetUuid_2 (const plUUID& v) { - IVaultNodeSetValue(kUuid_2, &uuid_2, v); -} - -//============================================================================ -void NetVaultNode::SetUuid_3 (const plUUID& v) { - IVaultNodeSetValue(kUuid_3, &uuid_3, v); -} - -//============================================================================ -void NetVaultNode::SetUuid_4 (const plUUID& v) { - IVaultNodeSetValue(kUuid_4, &uuid_4, v); -} - -//============================================================================ -void NetVaultNode::SetString64_1 (const wchar_t v[]) { - IVaultNodeSetString(kString64_1, &string64_1, v, kMaxVaultNodeStringLength); -} - -//============================================================================ -void NetVaultNode::SetString64_2 (const wchar_t v[]) { - IVaultNodeSetString(kString64_2, &string64_2, v, kMaxVaultNodeStringLength); -} - -//============================================================================ -void NetVaultNode::SetString64_3 (const wchar_t v[]) { - IVaultNodeSetString(kString64_3, &string64_3, v, kMaxVaultNodeStringLength); -} - -//============================================================================ -void NetVaultNode::SetString64_4 (const wchar_t v[]) { - IVaultNodeSetString(kString64_4, &string64_4, v, kMaxVaultNodeStringLength); -} - -//============================================================================ -void NetVaultNode::SetString64_5 (const wchar_t v[]) { - IVaultNodeSetString(kString64_5, &string64_5, v, kMaxVaultNodeStringLength); -} - -//============================================================================ -void NetVaultNode::SetString64_6 (const wchar_t v[]) { - IVaultNodeSetString(kString64_6, &string64_6, v, kMaxVaultNodeStringLength); -} - -//============================================================================ -void NetVaultNode::SetIString64_1 (const wchar_t v[]) { - IVaultNodeSetString(kIString64_1, &istring64_1, v, kMaxVaultNodeStringLength); -} - -//============================================================================ -void NetVaultNode::SetIString64_2 (const wchar_t v[]) { - IVaultNodeSetString(kIString64_2, &istring64_2, v, kMaxVaultNodeStringLength); -} - -//============================================================================ -void NetVaultNode::SetText_1 (const wchar_t v[]) { - IVaultNodeSetString(kText_1, &text_1, v, (unsigned)-1); -} - -//============================================================================ -void NetVaultNode::SetText_2 (const wchar_t v[]) { - IVaultNodeSetString(kText_2, &text_2, v, (unsigned)-1); -} - -//============================================================================ -void NetVaultNode::SetBlob_1 (const uint8_t v[], uint32_t len) { - IVaultNodeSetBlob(kBlob_1, &blob_1, &blob_1Length, v, len); -} - -//============================================================================ -void NetVaultNode::SetBlob_2 (const uint8_t v[], uint32_t len) { - IVaultNodeSetBlob(kBlob_2, &blob_2, &blob_2Length, v, len); +void NetVaultNode::Write(ARRAY(uint8_t)* buf, uint32_t ioFlags) +{ + uint64_t flags = fUsedFields; + if (ioFlags & kDirtyNodeType) + fDirtyFields |= kNodeType; + if (ioFlags & kDirtyString64_1) + fDirtyFields |= kString64_1; + if (ioFlags & kDirtyOnly) + flags &= fDirtyFields; + IWrite(buf, flags); + +#define WRITE(field) if (flags & k##field) IWrite(buf, f##field); + WRITE(NodeId); + WRITE(CreateTime); + WRITE(ModifyTime); + WRITE(CreateAgeName); + WRITE(CreateAgeUuid); + WRITE(CreatorAcct); + WRITE(CreatorId); + WRITE(NodeType); + WRITE(Int32_1); + WRITE(Int32_2); + WRITE(Int32_3); + WRITE(Int32_4); + WRITE(UInt32_1); + WRITE(UInt32_2); + WRITE(UInt32_3); + WRITE(UInt32_4); + WRITE(Uuid_1); + WRITE(Uuid_2); + WRITE(Uuid_3); + WRITE(Uuid_4); + WRITE(String64_1); + WRITE(String64_2); + WRITE(String64_3); + WRITE(String64_4); + WRITE(String64_5); + WRITE(String64_6); + WRITE(IString64_1); + WRITE(IString64_2); + WRITE(Text_1); + WRITE(Text_2); + WRITE(Blob_1); + WRITE(Blob_2); +#undef WRITE + + if (ioFlags & kClearDirty) + fDirtyFields = 0; +} + +//============================================================================ +void NetVaultNode::ISetVaultBlob(uint64_t bits, NetVaultNode::Blob& blob, const uint8_t* buf, size_t size) +{ + delete[] blob.buffer; + blob.buffer = new uint8_t[size]; + blob.size = size; + memcpy(blob.buffer, buf, size); + + fUsedFields |= bits; + fDirtyFields |= bits; } diff --git a/Sources/Plasma/NucleusLib/pnNetProtocol/Private/pnNpCommon.h b/Sources/Plasma/NucleusLib/pnNetProtocol/Private/pnNpCommon.h index a71ee99b..2d77c726 100644 --- a/Sources/Plasma/NucleusLib/pnNetProtocol/Private/pnNpCommon.h +++ b/Sources/Plasma/NucleusLib/pnNetProtocol/Private/pnNpCommon.h @@ -153,258 +153,241 @@ struct NetGameRank { * ***/ -//============================================================================ -// NetVaultNode -//============================================================================ -// Threaded apps: App is responsible for locking node->critsect before accessing *any* field in this struct -struct NetVaultNode : hsRefCnt { - enum RwOptions { - kRwDirtyOnly = 1<<0, // READ : No meaning - // WRITE: Only write fields marked dirty - kRwUpdateDirty = 1<<1, // READ : Set dirty flag on fields read from stream - // WRITE: Clear dirty flag on fields written to stream +class NetVaultNode : public hsRefCnt +{ +protected: + enum NodeFields + { + kNodeId = (1 << 0), + kCreateTime = (1 << 1), + kModifyTime = (1 << 2), + kCreateAgeName = (1 << 3), + kCreateAgeUuid = (1 << 4), + kCreatorAcct = (1 << 5), + kCreatorId = (1 << 6), + kNodeType = (1 << 7), + kInt32_1 = (1 << 8), + kInt32_2 = (1 << 9), + kInt32_3 = (1 << 10), + kInt32_4 = (1 << 11), + kUInt32_1 = (1 << 12), + kUInt32_2 = (1 << 13), + kUInt32_3 = (1 << 14), + kUInt32_4 = (1 << 15), + kUuid_1 = (1 << 16), + kUuid_2 = (1 << 17), + kUuid_3 = (1 << 18), + kUuid_4 = (1 << 19), + kString64_1 = (1 << 20), + kString64_2 = (1 << 21), + kString64_3 = (1 << 22), + kString64_4 = (1 << 23), + kString64_5 = (1 << 24), + kString64_6 = (1 << 25), + kIString64_1 = (1 << 26), + kIString64_2 = (1 << 27), + kText_1 = (1 << 28), + kText_2 = (1 << 29), + kBlob_1 = (1 << 30), + kBlob_2 = (1 << 31), + + kValidFields = (kNodeId | kCreateTime | kModifyTime | kCreateAgeName | kCreateAgeUuid | + kCreatorAcct | kCreatorId | kNodeType | kInt32_1 | kInt32_2 | kInt32_3 | + kInt32_4 | kUInt32_1 | kUInt32_2 | kUInt32_3 | kUInt32_3 | kUInt32_4 | + kUuid_1 | kUuid_2 | kUuid_3 | kUuid_4 | kString64_1 | kString64_2 | + kString64_3 | kString64_4 | kString64_5 | kString64_6 | kIString64_1 | + kIString64_2 | kText_1 | kText_2 | kBlob_1 | kBlob_2) }; - - enum CopyOptions { - kCopySetDirty = 1<<0, // set dirty flag on changed dst fields - kCopyOverwrite = 1<<1, // overwrite fields for which dst node already has values - kCopyClear = 1<<2, // clear dst fields for which src node does not have values + +public: + /** + * This is public only so that it may be referenced by anonymous functions. + * Should not be used outside NetVaultNode. + */ + struct Blob + { + size_t size; + uint8_t* buffer; + + Blob() : size(0), buffer(nullptr) { } + ~Blob() { delete[] buffer; } + + bool operator ==(const Blob& rhs) const; + bool operator !=(const Blob& rhs) const { return !operator==(rhs); } }; - - // These flag values must not change unless all servers are - // simultaneously replaced, so basically forget it. - static const uint64_t kNodeId = (uint64_t)1<< 0; - static const uint64_t kCreateTime = (uint64_t)1<< 1; - static const uint64_t kModifyTime = (uint64_t)1<< 2; - static const uint64_t kCreateAgeName = (uint64_t)1<< 3; - static const uint64_t kCreateAgeUuid = (uint64_t)1<< 4; - static const uint64_t kCreatorAcct = (uint64_t)1<< 5; - static const uint64_t kCreatorId = (uint64_t)1<< 6; - static const uint64_t kNodeType = (uint64_t)1<< 7; - static const uint64_t kInt32_1 = (uint64_t)1<< 8; - static const uint64_t kInt32_2 = (uint64_t)1<< 9; - static const uint64_t kInt32_3 = (uint64_t)1<<10; - static const uint64_t kInt32_4 = (uint64_t)1<<11; - static const uint64_t kUInt32_1 = (uint64_t)1<<12; - static const uint64_t kUInt32_2 = (uint64_t)1<<13; - static const uint64_t kUInt32_3 = (uint64_t)1<<14; - static const uint64_t kUInt32_4 = (uint64_t)1<<15; - static const uint64_t kUuid_1 = (uint64_t)1<<16; - static const uint64_t kUuid_2 = (uint64_t)1<<17; - static const uint64_t kUuid_3 = (uint64_t)1<<18; - static const uint64_t kUuid_4 = (uint64_t)1<<19; - static const uint64_t kString64_1 = (uint64_t)1<<20; - static const uint64_t kString64_2 = (uint64_t)1<<21; - static const uint64_t kString64_3 = (uint64_t)1<<22; - static const uint64_t kString64_4 = (uint64_t)1<<23; - static const uint64_t kString64_5 = (uint64_t)1<<24; - static const uint64_t kString64_6 = (uint64_t)1<<25; - static const uint64_t kIString64_1 = (uint64_t)1<<26; - static const uint64_t kIString64_2 = (uint64_t)1<<27; - // blobs always come last - static const uint64_t kText_1 = (uint64_t)1<<28; - static const uint64_t kText_2 = (uint64_t)1<<29; - static const uint64_t kBlob_1 = (uint64_t)1<<30; - static const uint64_t kBlob_2 = (uint64_t)1<<31; - - static const uint64_t kAllValidFields = 0x00000000FFFFFFFFULL; - - CCritSect critsect; - - plUUID revisionId; private: - uint64_t fieldFlags; - uint64_t dirtyFlags; - - // Treat these as read-only or node flag fields will become invalid - // Threaded apps: Must be accessed with node->critsect locked - uint32_t nodeId; - uint32_t createTime; - uint32_t modifyTime; - wchar_t * createAgeName; - plUUID createAgeUuid; - plUUID creatorAcct; // accountId of node creator - uint32_t creatorId; // playerId of node creator - uint32_t nodeType; - int32_t int32_1; - int32_t int32_2; - int32_t int32_3; - int32_t int32_4; - uint32_t uint32_1; - uint32_t uint32_2; - uint32_t uint32_3; - uint32_t uint32_4; - plUUID uuid_1; - plUUID uuid_2; - plUUID uuid_3; - plUUID uuid_4; - wchar_t * string64_1; - wchar_t * string64_2; - wchar_t * string64_3; - wchar_t * string64_4; - wchar_t * string64_5; - wchar_t * string64_6; - wchar_t * istring64_1; - wchar_t * istring64_2; - wchar_t * text_1; - wchar_t * text_2; - uint8_t * blob_1; uint32_t blob_1Length; - uint8_t * blob_2; uint32_t blob_2Length; - - void IVaultNodeSetString ( - uint64_t bit, - char ** pdst, - const char src[], - unsigned chars - ) { - free(*pdst); - if (src && src[0]) - *pdst = StrDupLen(src, chars); - else - *pdst = StrDupLen("", chars); - fieldFlags |= bit; - dirtyFlags |= bit; - } - void IVaultNodeSetString ( - uint64_t bit, - wchar_t ** pdst, - const wchar_t src[], - unsigned chars - ) { - free(*pdst); - if (src && src[0]) - *pdst = StrDupLen(src, chars); - else - *pdst = StrDupLen(L"", chars); - fieldFlags |= bit; - dirtyFlags |= bit; + uint64_t fUsedFields; + uint64_t fDirtyFields; + plUUID fRevision; + + uint32_t fNodeId; + uint32_t fCreateTime; + uint32_t fModifyTime; + plString fCreateAgeName; + plUUID fCreateAgeUuid; + plUUID fCreatorAcct; + uint32_t fCreatorId; + uint32_t fNodeType; + int32_t fInt32_1; + int32_t fInt32_2; + int32_t fInt32_3; + int32_t fInt32_4; + uint32_t fUInt32_1; + uint32_t fUInt32_2; + uint32_t fUInt32_3; + uint32_t fUInt32_4; + plUUID fUuid_1; + plUUID fUuid_2; + plUUID fUuid_3; + plUUID fUuid_4; + plString fString64_1; + plString fString64_2; + plString fString64_3; + plString fString64_4; + plString fString64_5; + plString fString64_6; + plString fIString64_1; + plString fIString64_2; + plString fText_1; + plString fText_2; + Blob fBlob_1; + Blob fBlob_2; + + template + inline void ISetVaultField(uint64_t bits, T& field, T value) + { + field = value; + fUsedFields |= bits; + fDirtyFields |= bits; } - template - inline void IVaultNodeSetValue ( - uint64_t bit, - T * pdst, - const T & src - ) { - *pdst = src; - fieldFlags |= bit; - dirtyFlags |= bit; + template + inline void ISetVaultField_NoDirty(uint64_t bits, T& field, T value) + { + field = value; + fUsedFields |= bits; } - void IVaultNodeSetBlob ( - uint64_t bit, - uint8_t ** pdst, - unsigned * pdstLen, - const uint8_t src[], - unsigned srcLen - ) { - free(*pdst); - if (src) { - *pdst = (uint8_t*)malloc(srcLen); - memcpy(*pdst, src, srcLen); - *pdstLen = srcLen; - } - else { - *pdst = nil; - *pdstLen = 0; - } - fieldFlags |= bit; - dirtyFlags |= bit; - } + void ISetVaultBlob(uint64_t bits, Blob& blob, const uint8_t* buf, size_t size); - void DeallocNodeFields(); +public: + enum IOFlags + { + /** Only write fields marked dirty */ + kDirtyOnly = (1 << 0), + + /** Clears the dirty flag on fields written to the stream */ + kClearDirty = (1 << 1), + + /** Indicates that we should mark the NodeType fields as dirty before writing */ + kDirtyNodeType = (1 << 2), + + /** Indicates that we should mark the String64_1 field as dirty before writing */ + kDirtyString64_1 = (1 << 3), + }; public: - NetVaultNode (); - ~NetVaultNode (); - - // Threaded apps: Must be called with node->critsect locked - uint32_t Read_LCS (const uint8_t buffer[], uint32_t bufsz, uint32_t rwOpts); // returns number of bytes read - uint32_t Write_LCS (ARRAY(uint8_t) * buffer, uint32_t rwOpts); // returns number of bytes written - - bool Matches (const NetVaultNode * other); - void CopyFrom (const NetVaultNode * other, uint32_t copyOpts); - - uint64_t GetFieldFlags () const { return fieldFlags; } - void ClearFieldFlags () { fieldFlags = 0; } - - uint64_t GetDirtyFlags () const { return dirtyFlags; } - void SetDirtyFlags (uint64_t flags) { dirtyFlags |= flags; } - void ClearDirtyFlags (uint64_t flags) { dirtyFlags &= ~flags; } - - // Threaded apps: Must be called with node->critsect locked - void SetNodeId (uint32_t v); - void SetNodeId_NoDirty (uint32_t v) { nodeId = v; } - void SetCreateTime (uint32_t v); - void SetModifyTime (uint32_t v); - void SetCreateAgeName (const wchar_t v[]); - void SetCreateAgeUuid (const plUUID & v); - void SetCreatorAcct (const plUUID & v); - void SetCreatorId (uint32_t v); - void SetNodeType (uint32_t v); - void SetInt32_1 (int32_t v); - void SetInt32_2 (int32_t v); - void SetInt32_3 (int32_t v); - void SetInt32_4 (int32_t v); - void SetUInt32_1 (uint32_t v); - void SetUInt32_2 (uint32_t v); - void SetUInt32_3 (uint32_t v); - void SetUInt32_4 (uint32_t v); - void SetUuid_1 (const plUUID & v); - void SetUuid_2 (const plUUID & v); - void SetUuid_3 (const plUUID & v); - void SetUuid_4 (const plUUID & v); - void SetString64_1 (const wchar_t v[]); - void SetString64_2 (const wchar_t v[]); - void SetString64_3 (const wchar_t v[]); - void SetString64_4 (const wchar_t v[]); - void SetString64_5 (const wchar_t v[]); - void SetString64_6 (const wchar_t v[]); - void SetIString64_1 (const wchar_t v[]); - void SetIString64_2 (const wchar_t v[]); - void SetText_1 (const wchar_t v[]); - void SetText_2 (const wchar_t v[]); - void SetBlob_1 (const uint8_t v[], uint32_t len); - void SetBlob_2 (const uint8_t v[], uint32_t len); - - uint32_t GetNodeId () const { return nodeId; } - uint32_t GetCreateTime () const { return createTime; } - uint32_t GetModifyTime () const { return modifyTime; } - const wchar_t * GetCreateAgeName () const { return createAgeName; } - plUUID GetCreateAgeUuid () const { return createAgeUuid; } - plUUID GetCreatorAcct () const { return creatorAcct; } - uint32_t GetCreatorId () const { return creatorId; } - uint32_t GetNodeType () const { return nodeType; } - int32_t GetInt32_1 () const { return int32_1; } - int32_t GetInt32_2 () const { return int32_2; } - int32_t GetInt32_3 () const { return int32_3; } - int32_t GetInt32_4 () const { return int32_4; } - uint32_t GetUInt32_1 () const { return uint32_1; } - uint32_t GetUInt32_2 () const { return uint32_2; } - uint32_t GetUInt32_3 () const { return uint32_3; } - uint32_t GetUInt32_4 () const { return uint32_4; } - plUUID GetUuid_1 () const { return uuid_1; } - plUUID GetUuid_2 () const { return uuid_2; } - plUUID GetUuid_3 () const { return uuid_3; } - plUUID GetUuid_4 () const { return uuid_4; } - const wchar_t * GetString64_1 () const { return string64_1; } - const wchar_t * GetString64_2 () const { return string64_2; } - const wchar_t * GetString64_3 () const { return string64_3; } - const wchar_t * GetString64_4 () const { return string64_4; } - const wchar_t * GetString64_5 () const { return string64_5; } - const wchar_t * GetString64_6 () const { return string64_6; } - const wchar_t * GetIString64_1 () const { return istring64_1; } - const wchar_t * GetIString64_2 () const { return istring64_2; } - const wchar_t * GetText_1 () const { return text_1; } - const wchar_t * GetText_2 () const { return text_2; } - const uint8_t * GetBlob_1 () const { return blob_1; } - size_t GetBlob_1Length () const { return blob_1Length; } - const uint8_t * GetBlob_2 () const { return blob_2; } - size_t GetBlob_2Length () const { return blob_2Length; } -}; + NetVaultNode() + : fNodeId(0), fCreateTime(0), fModifyTime(0), fCreatorId(0), fNodeType(0), fInt32_1(0), + fInt32_2(0), fInt32_3(0), fInt32_4(0), fUInt32_1(0), fUInt32_2(0), fUInt32_3(0), + fUInt32_4(0), fUsedFields(0), fDirtyFields(0) + { } + + /** Clears this NetVaultNode for subsequent usage */ + void Clear(); + + /** Copies data from \a node to this NetVaultNode */ + void CopyFrom(const NetVaultNode* node); + + bool Matches(const NetVaultNode* rhs) const; + + void Read(const uint8_t* buf, size_t size); + void Write(ARRAY(uint8_t)* buf, uint32_t ioFlags=0); +protected: + uint64_t GetFieldFlags() const { return fUsedFields; } + +public: + bool IsDirty() const { return fDirtyFields != 0; } + + plUUID GetRevision() const { return fRevision; } + void GenerateRevision() { fRevision = plUUID::Generate(); } + + uint32_t GetNodeId() const { return fNodeId; } + uint32_t GetCreateTime() const { return fCreateTime; } + uint32_t GetModifyTime() const { return fModifyTime; } + plString GetCreateAgeName() const { return fCreateAgeName; } + plUUID GetCreateAgeUuid() const { return fCreateAgeUuid; } + plUUID GetCreatorAcct() const { return fCreatorAcct; } + uint32_t GetCreatorId() const { return fCreatorId; } + uint32_t GetNodeType() const { return fNodeType; } + int32_t GetInt32_1() const { return fInt32_1; } + int32_t GetInt32_2() const { return fInt32_2; } + int32_t GetInt32_3() const { return fInt32_3; } + int32_t GetInt32_4() const { return fInt32_4; } + uint32_t GetUInt32_1() const { return fUInt32_1; } + uint32_t GetUInt32_2() const { return fUInt32_2; } + uint32_t GetUInt32_3() const { return fUInt32_3; } + uint32_t GetUInt32_4() const { return fUInt32_4; } + plUUID GetUuid_1() const { return fUuid_1; } + plUUID GetUuid_2() const { return fUuid_2; } + plUUID GetUuid_3() const { return fUuid_3; } + plUUID GetUuid_4() const { return fUuid_4; } + plString GetString64_1() const { return fString64_1; } + plString GetString64_2() const { return fString64_2; } + plString GetString64_3() const { return fString64_3; } + plString GetString64_4() const { return fString64_4; } + plString GetString64_5() const { return fString64_5; } + plString GetString64_6() const { return fString64_6; } + plString GetIString64_1() const { return fIString64_1; } + plString GetIString64_2() const { return fIString64_2; } + plString GetText_1() const { return fText_1; } + plString GetText_2() const { return fText_2; } + + const uint8_t* GetBlob_1() const { return fBlob_1.buffer; } + size_t GetBlob_1Length() const { return fBlob_1.size; } + + const uint8_t* GetBlob_2() const { return fBlob_2.buffer; } + size_t GetBlob_2Length() const { return fBlob_2.size; } + +public: + void SetNodeId(uint32_t value) { ISetVaultField(kNodeId, fNodeId, value); } + void SetNodeId_NoDirty(uint32_t value) { ISetVaultField_NoDirty(kNodeId, fNodeId, value); } + void SetCreateTime(uint32_t value) { ISetVaultField(kCreateTime, fCreateTime, value); } + void SetModifyTime(uint32_t value) { ISetVaultField(kModifyTime, fModifyTime, value); } + void SetCreateAgeName(plString value) { ISetVaultField(kCreateAgeName, fCreateAgeName, value); } + void SetCreateAgeUuid(plUUID value) { ISetVaultField(kCreateAgeUuid, fCreateAgeUuid, value); } + void SetCreatorAcct(plUUID value) { ISetVaultField(kCreatorAcct, fCreatorAcct, value); } + void SetCreatorId(uint32_t value) { ISetVaultField(kCreatorId, fCreatorId, value); } + void SetNodeType(uint32_t value) { ISetVaultField(kNodeType, fNodeType, value); } + void SetInt32_1(int32_t value) { ISetVaultField(kInt32_1, fInt32_1, value); } + void SetInt32_2(int32_t value) { ISetVaultField(kInt32_2, fInt32_2, value); } + void SetInt32_3(int32_t value) { ISetVaultField(kInt32_3, fInt32_3, value); } + void SetInt32_4(int32_t value) { ISetVaultField(kInt32_4, fInt32_4, value); } + void SetUInt32_1(uint32_t value) { ISetVaultField(kUInt32_1, fUInt32_1, value); } + void SetUInt32_2(uint32_t value) { ISetVaultField(kUInt32_2, fUInt32_2, value); } + void SetUInt32_3(uint32_t value) { ISetVaultField(kUInt32_3, fUInt32_3, value); } + void SetUInt32_4(uint32_t value) { ISetVaultField(kUInt32_4, fUInt32_4, value); } + void SetUuid_1(const plUUID& value) { ISetVaultField(kUuid_1, fUuid_1, value); } + void SetUuid_2(const plUUID& value) { ISetVaultField(kUuid_2, fUuid_2, value); } + void SetUuid_3(const plUUID& value) { ISetVaultField(kUuid_3, fUuid_3, value); } + void SetUuid_4(const plUUID& value) { ISetVaultField(kUuid_4, fUuid_4, value); } + void SetString64_1(const plString& value) { ISetVaultField(kString64_1, fString64_1, value); } + void SetString64_2(const plString& value) { ISetVaultField(kString64_2, fString64_2, value); } + void SetString64_3(const plString& value) { ISetVaultField(kString64_3, fString64_3, value); } + void SetString64_4(const plString& value) { ISetVaultField(kString64_4, fString64_4, value); } + void SetString64_5(const plString& value) { ISetVaultField(kString64_5, fString64_5, value); } + void SetString64_6(const plString& value) { ISetVaultField(kString64_6, fString64_6, value); } + void SetIString64_1(const plString& value) { ISetVaultField(kIString64_1, fIString64_1, value); } + void SetIString64_2(const plString& value) { ISetVaultField(kIString64_2, fIString64_2, value); } + void SetText_1(const plString& value) { ISetVaultField(kText_1, fText_1, value); } + void SetText_2(const plString& value) { ISetVaultField(kText_2, fText_2, value); } + + void SetBlob_1(const uint8_t* buf, size_t size) { ISetVaultBlob(kBlob_1, fBlob_1, buf, size); } + void SetBlob_2(const uint8_t* buf, size_t size) { ISetVaultBlob(kBlob_2, fBlob_2, buf, size); } +}; //============================================================================ // NetVaultNodeRef (packed because is sent over wire directly) diff --git a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp index bb17cefc..1912b336 100644 --- a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp +++ b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp @@ -49,6 +49,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #pragma hdrstop #include "pnEncryption/plChallengeHash.h" +#include "plVault/plVaultConstants.h" namespace Ngl { namespace Auth { /***************************************************************************** @@ -3950,7 +3951,7 @@ bool VaultFetchNodeTrans::Recv ( if (IS_NET_SUCCESS(reply.result)) { m_node = new NetVaultNode; - m_node->Read_LCS(reply.nodeBuffer, reply.nodeBytes, 0); + m_node->Read(reply.nodeBuffer, reply.nodeBytes); } m_result = reply.result; @@ -3984,9 +3985,7 @@ bool VaultFindNodeTrans::Send () { return false; ARRAY(uint8_t) buffer; - m_node->critsect.Enter(); - m_node->Write_LCS(&buffer, 0); - m_node->critsect.Leave(); + m_node->Write(&buffer); const uintptr_t msg[] = { kCli2Auth_VaultNodeFind, @@ -4054,7 +4053,7 @@ bool VaultCreateNodeTrans::Send () { return false; ARRAY(uint8_t) buffer; - m_templateNode->Write_LCS(&buffer, 0); + m_templateNode->Write(&buffer, 0); const uintptr_t msg[] = { kCli2Auth_VaultNodeCreate, @@ -5608,43 +5607,34 @@ unsigned NetCliAuthVaultNodeSave ( FNetCliAuthVaultNodeSaveCallback callback, void * param ) { - ASSERTMSG(!(node->GetDirtyFlags() & NetVaultNode::kNodeType), "Node type may not be changed"); - - // Clear dirty bits of read-only fields before we write the node to the msg buffer - node->ClearDirtyFlags( - NetVaultNode::kNodeId | - NetVaultNode::kNodeType | - NetVaultNode::kCreatorAcct | - NetVaultNode::kCreatorId | - NetVaultNode::kCreateTime - ); - - if (!node->GetDirtyFlags()) + if (!node->IsDirty()) return 0; - + if (!node->GetNodeId()) return 0; - - // force sending of the nodeType value, since the auth needs it. - // auth will clear the field before sending it on to the vault. - node->SetDirtyFlags(NetVaultNode::kNodeType); // We're definitely saving this node, so assign a revisionId - node->revisionId = plUUID::Generate(); + node->GenerateRevision(); + + // Lots of hacks for MOULa :( + uint32_t ioFlags = NetVaultNode::kDirtyOnly | NetVaultNode::kClearDirty; + if (node->GetNodeType() == plVault::kNodeType_SDL) + ioFlags |= NetVaultNode::kDirtyString64_1; + ioFlags |= NetVaultNode::kDirtyNodeType; ARRAY(uint8_t) buffer; - unsigned bytes = node->Write_LCS(&buffer, NetVaultNode::kRwDirtyOnly | NetVaultNode::kRwUpdateDirty); - + node->Write(&buffer, ioFlags); + VaultSaveNodeTrans * trans = new VaultSaveNodeTrans( node->GetNodeId(), - node->revisionId, + node->GetRevision(), buffer.Count(), buffer.Ptr(), callback, param ); NetTransSend(trans); - return bytes; + return buffer.Count(); } //============================================================================ diff --git a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.h b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.h index 18826649..33f9ad91 100644 --- a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.h +++ b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.h @@ -383,7 +383,7 @@ void NetCliAuthFileRequest ( //============================================================================ // Vault Operations //============================================================================ -struct NetVaultNode; +class NetVaultNode; struct NetVaultNodeRef; // VaultNodeChanged