Browse Source

Merge pull request #463 from Hoikas/npcommon-cleanup

plString-ify the Vault
Michael Hansen 10 years ago
parent
commit
cd9057e840
  1. 4
      Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommands.cpp
  2. 14
      Sources/Plasma/FeatureLib/pfPython/cyAvatar.cpp
  3. 8
      Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp
  4. 32
      Sources/Plasma/FeatureLib/pfPython/pyAgeVault.cpp
  5. 15
      Sources/Plasma/FeatureLib/pfPython/pyDniInfoSource.cpp
  6. 10
      Sources/Plasma/FeatureLib/pfPython/pyDniInfoSource.h
  7. 2
      Sources/Plasma/FeatureLib/pfPython/pyDniInfoSourceGlue.cpp
  8. 38
      Sources/Plasma/FeatureLib/pfPython/pyVault.cpp
  9. 51
      Sources/Plasma/FeatureLib/pfPython/pyVaultAgeInfoNode.cpp
  10. 43
      Sources/Plasma/FeatureLib/pfPython/pyVaultAgeInfoNode.h
  11. 10
      Sources/Plasma/FeatureLib/pfPython/pyVaultAgeInfoNodeGlue.cpp
  12. 59
      Sources/Plasma/FeatureLib/pfPython/pyVaultChronicleNode.cpp
  13. 13
      Sources/Plasma/FeatureLib/pfPython/pyVaultChronicleNode.h
  14. 8
      Sources/Plasma/FeatureLib/pfPython/pyVaultChronicleNodeGlue.cpp
  15. 55
      Sources/Plasma/FeatureLib/pfPython/pyVaultFolderNode.cpp
  16. 10
      Sources/Plasma/FeatureLib/pfPython/pyVaultFolderNode.h
  17. 3
      Sources/Plasma/FeatureLib/pfPython/pyVaultFolderNodeGlue.cpp
  18. 35
      Sources/Plasma/FeatureLib/pfPython/pyVaultImageNode.cpp
  19. 5
      Sources/Plasma/FeatureLib/pfPython/pyVaultImageNode.h
  20. 4
      Sources/Plasma/FeatureLib/pfPython/pyVaultImageNodeGlue.cpp
  21. 14
      Sources/Plasma/FeatureLib/pfPython/pyVaultMarkerGameNode.cpp
  22. 10
      Sources/Plasma/FeatureLib/pfPython/pyVaultMarkerGameNode.h
  23. 2
      Sources/Plasma/FeatureLib/pfPython/pyVaultMarkerGameNodeGlue.cpp
  24. 35
      Sources/Plasma/FeatureLib/pfPython/pyVaultNode.cpp
  25. 1
      Sources/Plasma/FeatureLib/pfPython/pyVaultNode.h
  26. 68
      Sources/Plasma/FeatureLib/pfPython/pyVaultPlayerInfoNode.cpp
  27. 13
      Sources/Plasma/FeatureLib/pfPython/pyVaultPlayerInfoNode.h
  28. 4
      Sources/Plasma/FeatureLib/pfPython/pyVaultPlayerInfoNodeGlue.cpp
  29. 32
      Sources/Plasma/FeatureLib/pfPython/pyVaultPlayerNode.cpp
  30. 6
      Sources/Plasma/FeatureLib/pfPython/pyVaultPlayerNode.h
  31. 11
      Sources/Plasma/FeatureLib/pfPython/pyVaultSDLNode.cpp
  32. 90
      Sources/Plasma/FeatureLib/pfPython/pyVaultTextNoteNode.cpp
  33. 9
      Sources/Plasma/FeatureLib/pfPython/pyVaultTextNoteNode.h
  34. 6
      Sources/Plasma/FeatureLib/pfPython/pyVaultTextNoteNodeGlue.cpp
  35. 896
      Sources/Plasma/NucleusLib/pnNetProtocol/Private/pnNpCommon.cpp
  36. 512
      Sources/Plasma/NucleusLib/pnNetProtocol/Private/pnNpCommon.h
  37. 14
      Sources/Plasma/NucleusLib/pnUtils/pnUtMisc.h
  38. 2
      Sources/Plasma/PubUtilLib/plNetClient/plLinkEffectsMgr.cpp
  39. 2
      Sources/Plasma/PubUtilLib/plNetClient/plNetCliAgeJoiner.cpp
  40. 12
      Sources/Plasma/PubUtilLib/plNetClient/plNetLinkingMgr.cpp
  41. 5
      Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp
  42. 44
      Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp
  43. 2
      Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.h
  44. 2
      Sources/Plasma/PubUtilLib/plStatGather/plAutoProfile.cpp
  45. 4
      Sources/Plasma/PubUtilLib/plVault/Pch.h
  46. 407
      Sources/Plasma/PubUtilLib/plVault/plVaultClientApi.cpp
  47. 37
      Sources/Plasma/PubUtilLib/plVault/plVaultClientApi.h
  48. 271
      Sources/Plasma/PubUtilLib/plVault/plVaultNodeAccess.cpp
  49. 47
      Sources/Plasma/PubUtilLib/plVault/plVaultNodeAccess.h

4
Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommands.cpp

@ -6913,8 +6913,8 @@ PF_CONSOLE_GROUP(Vault)
PF_CONSOLE_CMD(Vault, Dump, "", "Prints the vault structure of current player and age to the nearest log file") PF_CONSOLE_CMD(Vault, Dump, "", "Prints the vault structure of current player and age to the nearest log file")
{ {
VaultDump(L"Player", NetCommGetPlayer()->playerInt); VaultDump("Player", NetCommGetPlayer()->playerInt);
VaultDump(L"Age", NetCommGetAge()->ageVaultId); VaultDump("Age", NetCommGetAge()->ageVaultId);
} }
#endif #endif

14
Sources/Plasma/FeatureLib/pfPython/cyAvatar.cpp

@ -1665,15 +1665,12 @@ bool cyAvatar::LoadClothingFromFile(plFileName filename)
void cyAvatar::ChangeAvatar(const char* genderName) void cyAvatar::ChangeAvatar(const char* genderName)
{ {
#ifndef PLASMA_EXTERNAL_RELEASE #ifndef PLASMA_EXTERNAL_RELEASE
plClothingMgr::ChangeAvatar((char*)genderName); plClothingMgr::ChangeAvatar(genderName);
wchar_t wStr[MAX_PATH];
StrToUnicode(wStr, genderName, arrsize(wStr));
hsRef<RelVaultNode> rvnPlr = VaultGetPlayerNode(); hsRef<RelVaultNode> rvnPlr = VaultGetPlayerNode();
if (rvnPlr) { if (rvnPlr) {
VaultPlayerNode plr(rvnPlr); VaultPlayerNode plr(rvnPlr);
plr.SetAvatarShapeName(wStr); plr.SetAvatarShapeName(genderName);
} }
#endif #endif
} }
@ -1687,13 +1684,10 @@ void cyAvatar::ChangeAvatar(const char* genderName)
// //
void cyAvatar::ChangePlayerName(const char* playerName) void cyAvatar::ChangePlayerName(const char* playerName)
{ {
wchar_t wStr[MAX_PATH];
StrToUnicode(wStr, playerName, arrsize(wStr));
hsRef<RelVaultNode> rvnPlr = VaultGetPlayerNode(); hsRef<RelVaultNode> rvnPlr = VaultGetPlayerNode();
if (rvnPlr) { if (rvnPlr) {
VaultPlayerNode plr(rvnPlr); VaultPlayerNode plr(rvnPlr);
plr.SetPlayerName(wStr); plr.SetPlayerName(playerName);
} }
} }

8
Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp

@ -2469,11 +2469,9 @@ int cyMisc::GetKILevel()
{ {
int result = pfKIMsg::kNanoKI; int result = pfKIMsg::kNanoKI;
wchar_t wStr[MAX_PATH]; if (hsRef<RelVaultNode> rvn = VaultFindChronicleEntry(pfKIMsg::kChronicleKILevel)) {
StrToUnicode(wStr, pfKIMsg::kChronicleKILevel, arrsize(wStr));
if (hsRef<RelVaultNode> rvn = VaultFindChronicleEntry(wStr)) {
VaultChronicleNode chron(rvn); VaultChronicleNode chron(rvn);
result = wcstol(chron.GetEntryValue(), nil, 0); result = chron.GetEntryValue().ToInt();
} }
return result; return result;
@ -2934,7 +2932,7 @@ void cyMisc::ForceVaultNodeUpdate(unsigned nodeId)
void cyMisc::VaultDownload(unsigned nodeId) void cyMisc::VaultDownload(unsigned nodeId)
{ {
VaultDownloadAndWait( VaultDownloadAndWait(
L"PyVaultDownload", "PyVaultDownload",
nodeId, nodeId,
nil, nil,
nil nil

32
Sources/Plasma/FeatureLib/pfPython/pyAgeVault.cpp

@ -203,10 +203,7 @@ void pyAgeVault::AddDevice( const char * deviceName, PyObject * cbObject, uint32
pyVaultNode::pyVaultNodeOperationCallback * cb = new pyVaultNode::pyVaultNodeOperationCallback( cbObject ); pyVaultNode::pyVaultNodeOperationCallback * cb = new pyVaultNode::pyVaultNodeOperationCallback( cbObject );
cb->VaultOperationStarted( cbContext ); cb->VaultOperationStarted( cbContext );
wchar_t wStr[MAX_PATH]; if (hsRef<RelVaultNode> rvn = VaultAgeAddDeviceAndWait(deviceName))
StrToUnicode(wStr, deviceName, arrsize(wStr));
if (hsRef<RelVaultNode> rvn = VaultAgeAddDeviceAndWait(wStr))
cb->SetNode(rvn); cb->SetNode(rvn);
cb->VaultOperationComplete( cbContext, cb->GetNode() ? hsOK : hsFail); // cbHolder deletes itself here. cb->VaultOperationComplete( cbContext, cb->GetNode() ? hsOK : hsFail); // cbHolder deletes itself here.
@ -215,27 +212,18 @@ void pyAgeVault::AddDevice( const char * deviceName, PyObject * cbObject, uint32
// Remove a device. // Remove a device.
void pyAgeVault::RemoveDevice( const char * deviceName ) void pyAgeVault::RemoveDevice( const char * deviceName )
{ {
wchar_t wStr[MAX_PATH]; VaultAgeRemoveDevice(deviceName);
StrToUnicode(wStr, deviceName, arrsize(wStr));
VaultAgeRemoveDevice(wStr);
} }
// True if device exists in age. // True if device exists in age.
bool pyAgeVault::HasDevice( const char * deviceName ) bool pyAgeVault::HasDevice( const char * deviceName )
{ {
wchar_t wStr[MAX_PATH]; return VaultAgeHasDevice(deviceName);
StrToUnicode(wStr, deviceName, arrsize(wStr));
return VaultAgeHasDevice(wStr);
} }
PyObject * pyAgeVault::GetDevice( const char * deviceName ) PyObject * pyAgeVault::GetDevice( const char * deviceName )
{ {
wchar_t wStr[MAX_PATH]; if (hsRef<RelVaultNode> rvn = VaultAgeGetDevice(deviceName))
StrToUnicode(wStr, deviceName, arrsize(wStr));
if (hsRef<RelVaultNode> rvn = VaultAgeGetDevice(wStr))
return pyVaultTextNoteNode::New(rvn); return pyVaultTextNoteNode::New(rvn);
PYTHON_RETURN_NONE; PYTHON_RETURN_NONE;
@ -247,12 +235,7 @@ void pyAgeVault::SetDeviceInbox( const char * deviceName, const char * inboxName
pyVaultNode::pyVaultNodeOperationCallback * cb = new pyVaultNode::pyVaultNodeOperationCallback( cbObject ); pyVaultNode::pyVaultNodeOperationCallback * cb = new pyVaultNode::pyVaultNodeOperationCallback( cbObject );
cb->VaultOperationStarted( cbContext ); cb->VaultOperationStarted( cbContext );
wchar_t wDev[MAX_PATH]; if (hsRef<RelVaultNode> rvn = VaultAgeSetDeviceInboxAndWait(deviceName, inboxName))
StrToUnicode(wDev, deviceName, arrsize(wDev));
wchar_t wInb[MAX_PATH];
StrToUnicode(wInb, inboxName, arrsize(wInb));
if (hsRef<RelVaultNode> rvn = VaultAgeSetDeviceInboxAndWait(wDev, wInb))
cb->SetNode(rvn); cb->SetNode(rvn);
cb->VaultOperationComplete( cbContext, cb->GetNode() ? hsOK : hsFail ); // cbHolder deletes itself here. cb->VaultOperationComplete( cbContext, cb->GetNode() ? hsOK : hsFail ); // cbHolder deletes itself here.
@ -260,10 +243,7 @@ void pyAgeVault::SetDeviceInbox( const char * deviceName, const char * inboxName
PyObject * pyAgeVault::GetDeviceInbox( const char * deviceName ) PyObject * pyAgeVault::GetDeviceInbox( const char * deviceName )
{ {
wchar_t wStr[MAX_PATH]; if (hsRef<RelVaultNode> rvn = VaultAgeGetDeviceInbox(deviceName))
StrToUnicode(wStr, deviceName, arrsize(wStr));
if (hsRef<RelVaultNode> rvn = VaultAgeGetDeviceInbox(wStr))
return pyVaultTextNoteNode::New(rvn); return pyVaultTextNoteNode::New(rvn);
PYTHON_RETURN_NONE; PYTHON_RETURN_NONE;

15
Sources/Plasma/FeatureLib/pfPython/pyDniInfoSource.cpp

@ -50,14 +50,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "plVault/plVault.h" #include "plVault/plVault.h"
#include "pyDniCoordinates.h" #include "pyDniCoordinates.h"
pyDniInfoSource::pyDniInfoSource()
: fAgeName(nil)
{}
pyDniInfoSource::~pyDniInfoSource() {
free(fAgeName);
}
PyObject* pyDniInfoSource::GetAgeCoords( void ) PyObject* pyDniInfoSource::GetAgeCoords( void )
{ {
#if 0 // this may get retooled for another purpose someday... #if 0 // this may get retooled for another purpose someday...
@ -85,17 +77,14 @@ uint32_t pyDniInfoSource::GetAgeTime( void ) const
return result; return result;
} }
const char * pyDniInfoSource::GetAgeName( void ) const plString pyDniInfoSource::GetAgeName() const
{ {
hsRef<RelVaultNode> node = VaultGetAgeInfoNode(); hsRef<RelVaultNode> node = VaultGetAgeInfoNode();
if (!node) if (!node)
return ""; return "";
VaultAgeInfoNode ageInfo(node); VaultAgeInfoNode ageInfo(node);
return ageInfo.GetAgeInstanceName();
fAgeName = StrDupToAnsi(ageInfo.GetAgeInstanceName());
return fAgeName;
} }
plUUID pyDniInfoSource::GetAgeGuid( void ) const plUUID pyDniInfoSource::GetAgeGuid( void ) const

10
Sources/Plasma/FeatureLib/pfPython/pyDniInfoSource.h

@ -46,18 +46,16 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "pyGlueHelpers.h" #include "pyGlueHelpers.h"
class pyDniCoordinates; class pyDniCoordinates;
class plString;
class plUUID; class plUUID;
class pyDniInfoSource class pyDniInfoSource
{ {
private:
mutable char * fAgeName;
protected: protected:
pyDniInfoSource(); pyDniInfoSource() { }
public: public:
~pyDniInfoSource(); ~pyDniInfoSource() { }
// required functions for PyObject interoperability // required functions for PyObject interoperability
PYTHON_CLASS_NEW_FRIEND(ptDniInfoSource); PYTHON_CLASS_NEW_FRIEND(ptDniInfoSource);
@ -72,7 +70,7 @@ public:
// current time in current age (tbd) // current time in current age (tbd)
uint32_t GetAgeTime( void ) const; uint32_t GetAgeTime( void ) const;
// name of current age // name of current age
const char * GetAgeName( void ) const; plString GetAgeName() const;
// unique identifier for this age instance // unique identifier for this age instance
plUUID GetAgeGuid(void) const; plUUID GetAgeGuid(void) const;
}; };

2
Sources/Plasma/FeatureLib/pfPython/pyDniInfoSourceGlue.cpp

@ -69,7 +69,7 @@ PYTHON_METHOD_DEFINITION_NOARGS(ptDniInfoSource, getAgeTime)
PYTHON_METHOD_DEFINITION_NOARGS(ptDniInfoSource, getAgeName) PYTHON_METHOD_DEFINITION_NOARGS(ptDniInfoSource, getAgeName)
{ {
return PyString_FromString(self->fThis->GetAgeName()); return PyString_FromPlString(self->fThis->GetAgeName());
} }
PYTHON_METHOD_DEFINITION_NOARGS(ptDniInfoSource, getAgeGuid) PYTHON_METHOD_DEFINITION_NOARGS(ptDniInfoSource, getAgeGuid)

38
Sources/Plasma/FeatureLib/pfPython/pyVault.cpp

@ -328,10 +328,7 @@ PyObject* pyVault::GetVisitAgeLink( const pyAgeInfoStruct & info)
// Chronicle // Chronicle
PyObject* pyVault::FindChronicleEntry( const char * entryName ) PyObject* pyVault::FindChronicleEntry( const char * entryName )
{ {
wchar_t wEntryName[kMaxVaultNodeStringLength]; if (hsRef<RelVaultNode> rvn = VaultFindChronicleEntry(entryName))
StrToUnicode(wEntryName, entryName, arrsize(wEntryName));
if (hsRef<RelVaultNode> rvn = VaultFindChronicleEntry(wEntryName))
return pyVaultChronicleNode::New(rvn); return pyVaultChronicleNode::New(rvn);
// just return a None object // just return a None object
@ -340,16 +337,10 @@ PyObject* pyVault::FindChronicleEntry( const char * entryName )
void pyVault::AddChronicleEntry( const char * name, uint32_t type, const char * value ) void pyVault::AddChronicleEntry( const char * name, uint32_t type, const char * value )
{ {
wchar_t * wEntryName = StrDupToUnicode(name); // FIXME: We should ideally not block, but for now, the Python assumes that when
wchar_t * wEntryValue = StrDupToUnicode(value); // we return, the chronicle exists and can be found with findChronicleEntry.
// FIXME: We should ideally not block, but for now, the Python assumes that when
// we return, the chronicle exists and can be found with findChronicleEntry.
// Maybe we should insert a dummy into the tree? (currently hard) // Maybe we should insert a dummy into the tree? (currently hard)
VaultAddChronicleEntryAndWait(wEntryName, type, wEntryValue); VaultAddChronicleEntryAndWait(name, type, value);
free(wEntryName);
free(wEntryValue);
} }
@ -358,11 +349,8 @@ void pyVault::SendToDevice( pyVaultNode& node, const char * deviceName )
if (!node.GetNode()) if (!node.GetNode())
return; return;
wchar_t wDevName[256];
StrToUnicode(wDevName, deviceName, arrsize(wDevName));
// Note: This actually blocks (~Hoikas) // Note: This actually blocks (~Hoikas)
VaultPublishNode(node.GetNode()->GetNodeId(), wDevName); VaultPublishNode(node.GetNode()->GetNodeId(), deviceName);
} }
@ -412,16 +400,12 @@ PyObject* pyVault::GetPsnlAgeSDL() const
if (hsRef<RelVaultNode> rvnFldr = VaultGetAgesIOwnFolder()) { if (hsRef<RelVaultNode> rvnFldr = VaultGetAgesIOwnFolder()) {
templateNode->ClearFieldFlags();
templateNode->SetNodeType(plVault::kNodeType_AgeInfo); templateNode->SetNodeType(plVault::kNodeType_AgeInfo);
VaultAgeInfoNode ageInfo(templateNode); VaultAgeInfoNode ageInfo(templateNode);
wchar_t str[MAX_PATH]; ageInfo.SetAgeFilename(kPersonalAgeFilename);
StrToUnicode(str, kPersonalAgeFilename, arrsize(str));
ageInfo.SetAgeFilename(str);
if (hsRef<RelVaultNode> rvnInfo = rvnFldr->GetChildNode(templateNode, 2)) { if (hsRef<RelVaultNode> rvnInfo = rvnFldr->GetChildNode(templateNode, 2)) {
templateNode->Clear();
templateNode->ClearFieldFlags();
templateNode->SetNodeType(plVault::kNodeType_SDL); templateNode->SetNodeType(plVault::kNodeType_SDL);
if (hsRef<RelVaultNode> rvnSdl = rvnInfo->GetChildNode(templateNode, 1)) { if (hsRef<RelVaultNode> rvnSdl = rvnInfo->GetChildNode(templateNode, 1)) {
@ -451,16 +435,12 @@ void pyVault::UpdatePsnlAgeSDL( pySDLStateDataRecord & pyrec )
if (hsRef<RelVaultNode> rvnFldr = VaultGetAgesIOwnFolder()) { if (hsRef<RelVaultNode> rvnFldr = VaultGetAgesIOwnFolder()) {
templateNode->ClearFieldFlags();
templateNode->SetNodeType(plVault::kNodeType_AgeInfo); templateNode->SetNodeType(plVault::kNodeType_AgeInfo);
VaultAgeInfoNode ageInfo(templateNode); VaultAgeInfoNode ageInfo(templateNode);
wchar_t str[MAX_PATH]; ageInfo.SetAgeFilename(kPersonalAgeFilename);
StrToUnicode(str, kPersonalAgeFilename, arrsize(str));
ageInfo.SetAgeFilename(str);
if (hsRef<RelVaultNode> rvnInfo = rvnFldr->GetChildNode(templateNode, 2)) { if (hsRef<RelVaultNode> rvnInfo = rvnFldr->GetChildNode(templateNode, 2)) {
templateNode->Clear();
templateNode->ClearFieldFlags();
templateNode->SetNodeType(plVault::kNodeType_SDL); templateNode->SetNodeType(plVault::kNodeType_SDL);
if (hsRef<RelVaultNode> rvnSdl = rvnInfo->GetChildNode(templateNode, 1)) { if (hsRef<RelVaultNode> rvnSdl = rvnInfo->GetChildNode(templateNode, 1)) {

51
Sources/Plasma/FeatureLib/pfPython/pyVaultAgeInfoNode.cpp

@ -177,48 +177,42 @@ PyObject * pyVaultAgeInfoNode::GetParentAgeLink () const
} }
const char * pyVaultAgeInfoNode::GetAgeFilename() const plString pyVaultAgeInfoNode::GetAgeFilename() const
{ {
if (fNode) { if (fNode) {
char str[MAX_PATH];
VaultAgeInfoNode access(fNode); VaultAgeInfoNode access(fNode);
StrToAnsi(str, access.GetAgeFilename(), arrsize(str)); return access.GetAgeFilename();
fAgeFilename = str;
} }
return fAgeFilename.c_str(); return "";
} }
void pyVaultAgeInfoNode::SetAgeFilename( const char * v ) void pyVaultAgeInfoNode::SetAgeFilename(const plString& v)
{ {
} }
const char * pyVaultAgeInfoNode::GetAgeInstanceName() const plString pyVaultAgeInfoNode::GetAgeInstanceName() const
{ {
if (fNode) { if (fNode) {
char str[MAX_PATH];
VaultAgeInfoNode access(fNode); VaultAgeInfoNode access(fNode);
StrToAnsi(str, access.GetAgeInstanceName(), arrsize(str)); return access.GetAgeInstanceName();
fAgeInstName = str;
} }
return fAgeInstName.c_str(); return "";
} }
void pyVaultAgeInfoNode::SetAgeInstanceName( const char * v ) void pyVaultAgeInfoNode::SetAgeInstanceName(const plString& v)
{ {
} }
const char * pyVaultAgeInfoNode::GetAgeUserDefinedName() const plString pyVaultAgeInfoNode::GetAgeUserDefinedName() const
{ {
if (fNode) { if (fNode) {
char str[MAX_PATH];
VaultAgeInfoNode access(fNode); VaultAgeInfoNode access(fNode);
StrToAnsi(str, access.GetAgeUserDefinedName(), arrsize(str)); return access.GetAgeUserDefinedName();
fAgeUserName = str;
} }
return fAgeUserName.c_str(); return "";
} }
void pyVaultAgeInfoNode::SetAgeUserDefinedName( const char * v ) void pyVaultAgeInfoNode::SetAgeUserDefinedName(const plString& v)
{ {
} }
@ -236,19 +230,16 @@ void pyVaultAgeInfoNode::SetAgeInstanceGuid( const char * sguid )
{ {
} }
const char * pyVaultAgeInfoNode::GetAgeDescription() const plString pyVaultAgeInfoNode::GetAgeDescription() const
{ {
if (fNode) { if (fNode) {
char str[MAX_PATH];
memset(str, 0, sizeof(str));
VaultAgeInfoNode access(fNode); VaultAgeInfoNode access(fNode);
StrToAnsi(str, access.GetAgeDescription(), arrsize(str)); return access.GetAgeDescription();
fAgeDescription = str;
} }
return fAgeDescription.c_str(); return "";
} }
void pyVaultAgeInfoNode::SetAgeDescription( const char * v ) void pyVaultAgeInfoNode::SetAgeDescription(const plString& v)
{ {
} }
@ -303,18 +294,16 @@ bool pyVaultAgeInfoNode::IsPublic() const
return false; return false;
} }
const char * pyVaultAgeInfoNode::GetDisplayName() const plString pyVaultAgeInfoNode::GetDisplayName() const
{ {
if (fNode) { if (fNode) {
char str[MAX_PATH];
VaultAgeInfoNode access(fNode); VaultAgeInfoNode access(fNode);
if (access.GetAgeSequenceNumber() > 0) if (access.GetAgeSequenceNumber() > 0)
StrPrintf(str, arrsize(str), "%S(%d) %S", access.GetAgeUserDefinedName(), access.GetAgeSequenceNumber(), access.GetAgeInstanceName()); return plFormat("{}({}) {}", access.GetAgeUserDefinedName(), access.GetAgeSequenceNumber(), access.GetAgeInstanceName());
else else
StrPrintf(str, arrsize(str), "%S %S", access.GetAgeUserDefinedName(), access.GetAgeInstanceName()); return plFormat("{} {}", access.GetAgeUserDefinedName(), access.GetAgeInstanceName());
fAgeDispName = str;
} }
return fAgeDispName.c_str(); return "";
} }
PyObject * pyVaultAgeInfoNode::AsAgeInfoStruct() const PyObject * pyVaultAgeInfoNode::AsAgeInfoStruct() const

43
Sources/Plasma/FeatureLib/pfPython/pyVaultAgeInfoNode.h

@ -61,13 +61,6 @@ class plUUID;
class pyVaultAgeInfoNode : public pyVaultNode class pyVaultAgeInfoNode : public pyVaultNode
{ {
private:
mutable std::string fAgeFilename;
mutable std::string fAgeInstName;
mutable std::string fAgeUserName;
mutable std::string fAgeDispName;
mutable std::string fAgeDescription;
protected: protected:
// should only be created from C++ side // should only be created from C++ side
pyVaultAgeInfoNode(RelVaultNode* vaultNode); pyVaultAgeInfoNode(RelVaultNode* vaultNode);
@ -96,35 +89,35 @@ public:
PyObject * GetParentAgeLink () const; // returns pyVaultAgeLinkNode, or None if not a child age. PyObject * GetParentAgeLink () const; // returns pyVaultAgeLinkNode, or None if not a child age.
const char * GetAgeFilename() const; plString GetAgeFilename() const;
void SetAgeFilename( const char * v ); void SetAgeFilename(const plString& v);
const char * GetAgeInstanceName() const; plString GetAgeInstanceName() const;
void SetAgeInstanceName( const char * v ); void SetAgeInstanceName(const plString& v);
const char * GetAgeUserDefinedName() const; plString GetAgeUserDefinedName() const;
void SetAgeUserDefinedName( const char * v ); void SetAgeUserDefinedName(const plString& v);
plUUID GetAgeInstanceGuid() const; plUUID GetAgeInstanceGuid() const;
void SetAgeInstanceGuid( const char * guid ); void SetAgeInstanceGuid( const char * guid );
const char * GetAgeDescription() const; plString GetAgeDescription() const;
void SetAgeDescription( const char * v ); void SetAgeDescription(const plString& v);
int32_t GetSequenceNumber() const;
void SetSequenceNumber( int32_t v );
int32_t GetSequenceNumber() const; int32_t GetAgeLanguage() const;
void SetSequenceNumber( int32_t v ); void SetAgeLanguage( int32_t v );
int32_t GetAgeLanguage() const;
void SetAgeLanguage( int32_t v );
uint32_t GetAgeID() const; uint32_t GetAgeID() const;
void SetAgeID( uint32_t v ); void SetAgeID( uint32_t v );
uint32_t GetCzarID() const; uint32_t GetCzarID() const;
bool IsPublic() const; bool IsPublic() const;
const char * GetDisplayName() const; plString GetDisplayName() const;
PyObject * AsAgeInfoStruct() const; // returns pyAgeInfoStruct PyObject * AsAgeInfoStruct() const; // returns pyAgeInfoStruct
}; };

10
Sources/Plasma/FeatureLib/pfPython/pyVaultAgeInfoNodeGlue.cpp

@ -97,7 +97,7 @@ PYTHON_METHOD_DEFINITION_NOARGS(ptVaultAgeInfoNode, getParentAgeLink)
PYTHON_METHOD_DEFINITION_NOARGS(ptVaultAgeInfoNode, getAgeFilename) PYTHON_METHOD_DEFINITION_NOARGS(ptVaultAgeInfoNode, getAgeFilename)
{ {
return PyString_FromString(self->fThis->GetAgeFilename()); return PyString_FromPlString(self->fThis->GetAgeFilename());
} }
PYTHON_METHOD_DEFINITION(ptVaultAgeInfoNode, setAgeFilename, args) PYTHON_METHOD_DEFINITION(ptVaultAgeInfoNode, setAgeFilename, args)
@ -114,7 +114,7 @@ PYTHON_METHOD_DEFINITION(ptVaultAgeInfoNode, setAgeFilename, args)
PYTHON_METHOD_DEFINITION_NOARGS(ptVaultAgeInfoNode, getAgeInstanceName) PYTHON_METHOD_DEFINITION_NOARGS(ptVaultAgeInfoNode, getAgeInstanceName)
{ {
return PyString_FromString(self->fThis->GetAgeInstanceName()); return PyString_FromPlString(self->fThis->GetAgeInstanceName());
} }
PYTHON_METHOD_DEFINITION(ptVaultAgeInfoNode, setAgeInstanceName, args) PYTHON_METHOD_DEFINITION(ptVaultAgeInfoNode, setAgeInstanceName, args)
@ -131,7 +131,7 @@ PYTHON_METHOD_DEFINITION(ptVaultAgeInfoNode, setAgeInstanceName, args)
PYTHON_METHOD_DEFINITION_NOARGS(ptVaultAgeInfoNode, getAgeUserDefinedName) PYTHON_METHOD_DEFINITION_NOARGS(ptVaultAgeInfoNode, getAgeUserDefinedName)
{ {
return PyString_FromString(self->fThis->GetAgeUserDefinedName()); return PyString_FromPlString(self->fThis->GetAgeUserDefinedName());
} }
PYTHON_METHOD_DEFINITION(ptVaultAgeInfoNode, setAgeUserDefinedName, args) PYTHON_METHOD_DEFINITION(ptVaultAgeInfoNode, setAgeUserDefinedName, args)
@ -165,7 +165,7 @@ PYTHON_METHOD_DEFINITION(ptVaultAgeInfoNode, setAgeInstanceGuid, args)
PYTHON_METHOD_DEFINITION_NOARGS(ptVaultAgeInfoNode, getAgeDescription) PYTHON_METHOD_DEFINITION_NOARGS(ptVaultAgeInfoNode, getAgeDescription)
{ {
return PyString_FromString(self->fThis->GetAgeDescription()); return PyString_FromPlString(self->fThis->GetAgeDescription());
} }
PYTHON_METHOD_DEFINITION(ptVaultAgeInfoNode, setAgeDescription, args) PYTHON_METHOD_DEFINITION(ptVaultAgeInfoNode, setAgeDescription, args)
@ -243,7 +243,7 @@ PYTHON_METHOD_DEFINITION_NOARGS(ptVaultAgeInfoNode, isPublic)
PYTHON_METHOD_DEFINITION_NOARGS(ptVaultAgeInfoNode, getDisplayName) PYTHON_METHOD_DEFINITION_NOARGS(ptVaultAgeInfoNode, getDisplayName)
{ {
return PyString_FromString(self->fThis->GetDisplayName()); return PyString_FromPlString(self->fThis->GetDisplayName());
} }
PYTHON_METHOD_DEFINITION_NOARGS(ptVaultAgeInfoNode, asAgeInfoStruct) PYTHON_METHOD_DEFINITION_NOARGS(ptVaultAgeInfoNode, asAgeInfoStruct)

59
Sources/Plasma/FeatureLib/pfPython/pyVaultChronicleNode.cpp

@ -56,25 +56,16 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
// should only be created from C++ side // should only be created from C++ side
pyVaultChronicleNode::pyVaultChronicleNode(RelVaultNode* nfsNode) pyVaultChronicleNode::pyVaultChronicleNode(RelVaultNode* nfsNode)
: pyVaultNode(nfsNode) : pyVaultNode(nfsNode)
, ansiName(nil)
, ansiValue(nil)
{ {
} }
//create from the Python side //create from the Python side
pyVaultChronicleNode::pyVaultChronicleNode(int n) pyVaultChronicleNode::pyVaultChronicleNode(int n)
: pyVaultNode(new RelVaultNode) : pyVaultNode(new RelVaultNode)
, ansiName(nil)
, ansiValue(nil)
{ {
fNode->SetNodeType(plVault::kNodeType_Chronicle); fNode->SetNodeType(plVault::kNodeType_Chronicle);
} }
pyVaultChronicleNode::~pyVaultChronicleNode () {
free(ansiName);
free(ansiValue);
}
//================================================================== //==================================================================
// class RelVaultNode : public plVaultNode // class RelVaultNode : public plVaultNode
@ -84,50 +75,34 @@ void pyVaultChronicleNode::Chronicle_SetName( const char * text )
if (!fNode) if (!fNode)
return; return;
wchar_t * wStr = StrDupToUnicode(text);
VaultChronicleNode chron(fNode); VaultChronicleNode chron(fNode);
chron.SetEntryName(wStr); chron.SetEntryName(text);
free(wStr);
} }
const char * pyVaultChronicleNode::Chronicle_GetName( void ) plString pyVaultChronicleNode::Chronicle_GetName() const
{ {
if (!fNode) if (fNode) {
return ""; VaultChronicleNode chron(fNode);
return chron.GetEntryName();
free(ansiName); }
VaultChronicleNode chron(fNode); return "";
ansiName = StrDupToAnsi(chron.GetEntryName());
return ansiName;
} }
void pyVaultChronicleNode::Chronicle_SetValue( const char * text ) void pyVaultChronicleNode::Chronicle_SetValue( const char * text )
{ {
if (!fNode) if (fNode) {
return; VaultChronicleNode chron(fNode);
chron.SetEntryValue(text);
wchar_t * wStr = StrDupToUnicode(text); }
VaultChronicleNode chron(fNode);
chron.SetEntryValue(wStr);
free(wStr);
} }
const char * pyVaultChronicleNode::Chronicle_GetValue( void ) plString pyVaultChronicleNode::Chronicle_GetValue() const
{ {
if (!fNode) if (fNode) {
return ""; VaultChronicleNode chron(fNode);
return chron.GetEntryValue();
free(ansiValue); }
ansiValue = nil; return "";
VaultChronicleNode chron(fNode);
if (!chron.GetEntryValue())
return "";
ansiValue = StrDupToAnsi(chron.GetEntryValue());
return ansiValue;
} }
void pyVaultChronicleNode::Chronicle_SetType( uint32_t type ) void pyVaultChronicleNode::Chronicle_SetType( uint32_t type )

13
Sources/Plasma/FeatureLib/pfPython/pyVaultChronicleNode.h

@ -52,14 +52,11 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "pyGlueHelpers.h" #include "pyGlueHelpers.h"
#include "pyVaultNode.h" #include "pyVaultNode.h"
class plString;
struct RelVaultNode; struct RelVaultNode;
class pyVaultChronicleNode : public pyVaultNode class pyVaultChronicleNode : public pyVaultNode
{ {
char * ansiName;
char * ansiValue;
protected: protected:
// should only be created from C++ side // should only be created from C++ side
pyVaultChronicleNode(RelVaultNode* nfsNode); pyVaultChronicleNode(RelVaultNode* nfsNode);
@ -68,8 +65,8 @@ protected:
pyVaultChronicleNode(int n=0); pyVaultChronicleNode(int n=0);
public: public:
~pyVaultChronicleNode (); ~pyVaultChronicleNode() { }
// required functions for PyObject interoperability // required functions for PyObject interoperability
PYTHON_CLASS_NEW_FRIEND(ptVaultChronicleNode); PYTHON_CLASS_NEW_FRIEND(ptVaultChronicleNode);
static PyObject *New(RelVaultNode* nfsNode); static PyObject *New(RelVaultNode* nfsNode);
@ -83,9 +80,9 @@ public:
// class RelVaultNode : public plVaultNode // class RelVaultNode : public plVaultNode
// //
void Chronicle_SetName( const char * text ); void Chronicle_SetName( const char * text );
const char * Chronicle_GetName( void ); plString Chronicle_GetName() const;
void Chronicle_SetValue( const char * text ); void Chronicle_SetValue( const char * text );
const char * Chronicle_GetValue( void ); plString Chronicle_GetValue() const;
void Chronicle_SetType( uint32_t type ); void Chronicle_SetType( uint32_t type );
uint32_t Chronicle_GetType( void ); uint32_t Chronicle_GetType( void );
}; };

8
Sources/Plasma/FeatureLib/pfPython/pyVaultChronicleNodeGlue.cpp

@ -78,7 +78,7 @@ PYTHON_METHOD_DEFINITION(ptVaultChronicleNode, chronicleSetName, args)
PYTHON_METHOD_DEFINITION_NOARGS(ptVaultChronicleNode, chronicleGetName) PYTHON_METHOD_DEFINITION_NOARGS(ptVaultChronicleNode, chronicleGetName)
{ {
return PyString_FromString(self->fThis->Chronicle_GetName()); return PyString_FromPlString(self->fThis->Chronicle_GetName());
} }
PYTHON_METHOD_DEFINITION(ptVaultChronicleNode, chronicleSetValue, args) PYTHON_METHOD_DEFINITION(ptVaultChronicleNode, chronicleSetValue, args)
@ -95,7 +95,7 @@ PYTHON_METHOD_DEFINITION(ptVaultChronicleNode, chronicleSetValue, args)
PYTHON_METHOD_DEFINITION_NOARGS(ptVaultChronicleNode, chronicleGetValue) PYTHON_METHOD_DEFINITION_NOARGS(ptVaultChronicleNode, chronicleGetValue)
{ {
return PyString_FromString(self->fThis->Chronicle_GetValue()); return PyString_FromPlString(self->fThis->Chronicle_GetValue());
} }
PYTHON_METHOD_DEFINITION(ptVaultChronicleNode, chronicleSetType, args) PYTHON_METHOD_DEFINITION(ptVaultChronicleNode, chronicleSetType, args)
@ -129,7 +129,7 @@ PYTHON_METHOD_DEFINITION(ptVaultChronicleNode, setName, args)
PYTHON_METHOD_DEFINITION_NOARGS(ptVaultChronicleNode, getName) PYTHON_METHOD_DEFINITION_NOARGS(ptVaultChronicleNode, getName)
{ {
return PyString_FromString(self->fThis->Chronicle_GetName()); return PyString_FromPlString(self->fThis->Chronicle_GetName());
} }
PYTHON_METHOD_DEFINITION(ptVaultChronicleNode, setValue, args) PYTHON_METHOD_DEFINITION(ptVaultChronicleNode, setValue, args)
@ -146,7 +146,7 @@ PYTHON_METHOD_DEFINITION(ptVaultChronicleNode, setValue, args)
PYTHON_METHOD_DEFINITION_NOARGS(ptVaultChronicleNode, getValue) PYTHON_METHOD_DEFINITION_NOARGS(ptVaultChronicleNode, getValue)
{ {
return PyString_FromString(self->fThis->Chronicle_GetValue()); return PyString_FromPlString(self->fThis->Chronicle_GetValue());
} }
PYTHON_METHOD_DEFINITION(ptVaultChronicleNode, setEntryType, args) PYTHON_METHOD_DEFINITION(ptVaultChronicleNode, setEntryType, args)

55
Sources/Plasma/FeatureLib/pfPython/pyVaultFolderNode.cpp

@ -87,50 +87,27 @@ int pyVaultFolderNode::Folder_GetType( void )
return folder.GetFolderType(); return folder.GetFolderType();
} }
void pyVaultFolderNode::Folder_SetName( std::string name ) void pyVaultFolderNode::Folder_SetName(const char* name)
{ {
if (!fNode) if (fNode) {
return; VaultFolderNode folder(fNode);
folder.SetFolderName(name);
wchar_t* wName = hsStringToWString(name.c_str()); }
VaultFolderNode folder(fNode);
folder.SetFolderName(wName);
delete [] wName;
}
void pyVaultFolderNode::Folder_SetNameW( std::wstring name )
{
if (!fNode)
return;
VaultFolderNode folder(fNode);
folder.SetFolderName(name.c_str());
} }
std::string pyVaultFolderNode::Folder_GetName( void ) void pyVaultFolderNode::Folder_SetNameW(const wchar_t* name)
{ {
if (!fNode) if (fNode) {
return ""; VaultFolderNode folder(fNode);
folder.SetFolderName(plString::FromWchar(name));
VaultFolderNode folder(fNode); }
if (!folder.GetFolderName())
return "";
std::string retVal;
char* sName = hsWStringToString(folder.GetFolderName());
retVal = sName;
delete [] sName;
return retVal;
} }
std::wstring pyVaultFolderNode::Folder_GetNameW( void ) plString pyVaultFolderNode::Folder_GetName() const
{ {
if (!fNode) if (fNode) {
return L""; VaultFolderNode folder(fNode);
return folder.GetFolderName();
VaultFolderNode folder(fNode); }
if (!folder.GetFolderName()) return "";
return L"";
return folder.GetFolderName();
} }

10
Sources/Plasma/FeatureLib/pfPython/pyVaultFolderNode.h

@ -50,12 +50,11 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "HeadSpin.h" #include "HeadSpin.h"
#include "pyGlueHelpers.h" #include "pyGlueHelpers.h"
#include <string>
#include "pyVaultNode.h" #include "pyVaultNode.h"
class plString;
struct RelVaultNode; struct RelVaultNode;
class pyVaultFolderNode : public pyVaultNode class pyVaultFolderNode : public pyVaultNode
{ {
protected: protected:
@ -80,10 +79,9 @@ public:
virtual void Folder_SetType( int type ); virtual void Folder_SetType( int type );
virtual int Folder_GetType( void ); virtual int Folder_GetType( void );
void Folder_SetName( std::string name ); void Folder_SetName(const char* name);
void Folder_SetNameW( std::wstring name ); void Folder_SetNameW(const wchar_t* name);
std::string Folder_GetName( void ); plString Folder_GetName() const;
std::wstring Folder_GetNameW( void );

3
Sources/Plasma/FeatureLib/pfPython/pyVaultFolderNodeGlue.cpp

@ -164,8 +164,7 @@ PYTHON_METHOD_DEFINITION_NOARGS(ptVaultFolderNode, getFolderName)
PYTHON_METHOD_DEFINITION_NOARGS(ptVaultFolderNode, getFolderNameW) PYTHON_METHOD_DEFINITION_NOARGS(ptVaultFolderNode, getFolderNameW)
{ {
std::wstring name = self->fThis->Folder_GetNameW(); return PyUnicode_FromStringEx(self->fThis->Folder_GetName());
return PyUnicode_FromWideChar(name.c_str(), name.length());
} }
PYTHON_START_METHODS_TABLE(ptVaultFolderNode) PYTHON_START_METHODS_TABLE(ptVaultFolderNode)

35
Sources/Plasma/FeatureLib/pfPython/pyVaultImageNode.cpp

@ -116,12 +116,9 @@ void pyVaultImageNode::Image_SetTitle( const char * text )
{ {
if (!fNode) if (!fNode)
return; return;
wchar_t * wStr = hsStringToWString(text);
VaultImageNode image(fNode); VaultImageNode image(fNode);
image.SetImageTitle(wStr); image.SetImageTitle(text);
delete [] wStr;
} }
void pyVaultImageNode::Image_SetTitleW( const wchar_t* text ) void pyVaultImageNode::Image_SetTitleW( const wchar_t* text )
@ -130,34 +127,16 @@ void pyVaultImageNode::Image_SetTitleW( const wchar_t* text )
return; return;
VaultImageNode image(fNode); VaultImageNode image(fNode);
image.SetImageTitle(text); image.SetImageTitle(plString::FromWchar(text));
} }
std::string pyVaultImageNode::Image_GetTitle( void ) plString pyVaultImageNode::Image_GetTitle() const
{ {
if (!fNode) if (fNode) {
return ""; VaultImageNode image(fNode);
return image.GetImageTitle();
VaultImageNode image(fNode);
std::string retVal = "";
if (image.GetImageTitle())
{
char* temp = hsWStringToString(image.GetImageTitle());
retVal = temp;
delete [] temp;
} }
return "";
return retVal;
}
std::wstring pyVaultImageNode::Image_GetTitleW( void )
{
if (!fNode)
return L"";
VaultImageNode image(fNode);
return image.GetImageTitle() ? image.GetImageTitle() : L"";
} }
PyObject* pyVaultImageNode::Image_GetImage( void ) PyObject* pyVaultImageNode::Image_GetImage( void )

5
Sources/Plasma/FeatureLib/pfPython/pyVaultImageNode.h

@ -51,12 +51,12 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "HeadSpin.h" #include "HeadSpin.h"
#include "pyGlueHelpers.h" #include "pyGlueHelpers.h"
#include "pnKeyedObject/plKey.h" #include "pnKeyedObject/plKey.h"
#include <string>
#include "pyVaultNode.h" #include "pyVaultNode.h"
struct RelVaultNode; struct RelVaultNode;
class plMipmap; class plMipmap;
class plString;
class pyVaultImageNode : public pyVaultNode class pyVaultImageNode : public pyVaultNode
{ {
@ -88,8 +88,7 @@ public:
// //
void Image_SetTitle( const char * text ); void Image_SetTitle( const char * text );
void Image_SetTitleW( const wchar_t * text ); void Image_SetTitleW( const wchar_t * text );
std::string Image_GetTitle( void ); plString Image_GetTitle() const;
std::wstring Image_GetTitleW( void );
PyObject* Image_GetImage( void ); // returns pyImage PyObject* Image_GetImage( void ); // returns pyImage
void Image_SetImage(pyImage& image); void Image_SetImage(pyImage& image);

4
Sources/Plasma/FeatureLib/pfPython/pyVaultImageNodeGlue.cpp

@ -154,8 +154,8 @@ PYTHON_METHOD_DEFINITION_NOARGS(ptVaultImageNode, getTitle)
PYTHON_METHOD_DEFINITION_NOARGS(ptVaultImageNode, getTitleW) PYTHON_METHOD_DEFINITION_NOARGS(ptVaultImageNode, getTitleW)
{ {
std::wstring retVal = self->fThis->Image_GetTitleW(); plStringBuffer<wchar_t> retVal = self->fThis->Image_GetTitle().ToWchar();
return PyUnicode_FromWideChar(retVal.c_str(), retVal.length()); return PyUnicode_FromWideChar(retVal.GetData(), retVal.GetSize());
} }
PYTHON_METHOD_DEFINITION(ptVaultImageNode, setImage, args) PYTHON_METHOD_DEFINITION(ptVaultImageNode, setImage, args)

14
Sources/Plasma/FeatureLib/pfPython/pyVaultMarkerGameNode.cpp

@ -68,24 +68,20 @@ pyVaultMarkerGameNode::pyVaultMarkerGameNode(int n)
// class RelVaultNode : public plVaultNode // class RelVaultNode : public plVaultNode
// //
const char * pyVaultMarkerGameNode::GetGameName () const plString pyVaultMarkerGameNode::GetGameName () const
{ {
fGameName[0] = 0;
if (fNode) { if (fNode) {
VaultMarkerGameNode access(fNode); VaultMarkerGameNode access(fNode);
StrToAnsi(fGameName, access.GetGameName(), arrsize(fGameName)); return access.GetGameName();
} }
return fGameName; return "";
} }
void pyVaultMarkerGameNode::SetGameName (const char v[]) void pyVaultMarkerGameNode::SetGameName (const plString& name)
{ {
if (fNode) { if (fNode) {
VaultMarkerGameNode access(fNode); VaultMarkerGameNode access(fNode);
wchar_t unicode[kMaxVaultNodeStringLength]; access.SetGameName(name);
StrToUnicode(unicode, v, arrsize(unicode));
access.SetGameName(unicode);
} }
} }

10
Sources/Plasma/FeatureLib/pfPython/pyVaultMarkerGameNode.h

@ -53,16 +53,12 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "pyGlueHelpers.h" #include "pyGlueHelpers.h"
#include "pyVaultNode.h" #include "pyVaultNode.h"
#include "pnNetBase/pnNetBase.h" class plString;
struct RelVaultNode; struct RelVaultNode;
class plUUID; class plUUID;
class pyVaultMarkerGameNode : public pyVaultNode class pyVaultMarkerGameNode : public pyVaultNode
{ {
private:
mutable char fGameName[kMaxVaultNodeStringLength];
protected: protected:
// should only be created from C++ side // should only be created from C++ side
pyVaultMarkerGameNode(RelVaultNode* vaultNode); pyVaultMarkerGameNode(RelVaultNode* vaultNode);
@ -83,8 +79,8 @@ public:
//================================================================== //==================================================================
// class RelVaultNode : public plVaultNode // class RelVaultNode : public plVaultNode
// //
const char * GetGameName () const; plString GetGameName () const;
void SetGameName (const char v[]); void SetGameName (const plString& name);
plUUID GetGameGuid() const; plUUID GetGameGuid() const;
void SetGameGuid (const char v[]); void SetGameGuid (const char v[]);

2
Sources/Plasma/FeatureLib/pfPython/pyVaultMarkerGameNodeGlue.cpp

@ -67,7 +67,7 @@ PYTHON_INIT_DEFINITION(ptVaultMarkerGameNode, args, keywords)
PYTHON_METHOD_DEFINITION_NOARGS(ptVaultMarkerGameNode, getGameName) PYTHON_METHOD_DEFINITION_NOARGS(ptVaultMarkerGameNode, getGameName)
{ {
return PyString_FromString(self->fThis->GetGameName()); return PyString_FromPlString(self->fThis->GetGameName());
} }
PYTHON_METHOD_DEFINITION(ptVaultMarkerGameNode, setGameName, args) PYTHON_METHOD_DEFINITION(ptVaultMarkerGameNode, setGameName, args)

35
Sources/Plasma/FeatureLib/pfPython/pyVaultNode.cpp

@ -164,23 +164,17 @@ hsRef<RelVaultNode> pyVaultNode::pyVaultNodeOperationCallback::GetNode() const {
return fNode; return fNode;
} }
// only for python glue, do NOT call
pyVaultNode::pyVaultNode() pyVaultNode::pyVaultNode()
: fCreateAgeName(nil)
{ {
} }
// should only be created from C++ side // should only be created from C++ side
pyVaultNode::pyVaultNode( RelVaultNode* nfsNode ) pyVaultNode::pyVaultNode( RelVaultNode* nfsNode )
: fNode(nfsNode) : fNode(nfsNode)
, fCreateAgeName(nil)
{ {
} }
pyVaultNode::~pyVaultNode() pyVaultNode::~pyVaultNode() {}
{
free(fCreateAgeName);
}
hsRef<RelVaultNode> pyVaultNode::GetNode() const hsRef<RelVaultNode> pyVaultNode::GetNode() const
@ -291,22 +285,11 @@ uint32_t pyVaultNode::GetCreateAgeTime( void )
return GetCreateTime(); return GetCreateTime();
} }
const char * pyVaultNode::GetCreateAgeName( void ) const char * pyVaultNode::GetCreateAgeName()
{ {
if (!fNode) if (fNode)
return ""; return fNode->GetCreateAgeName().c_str();
return "";
if (fCreateAgeName)
return fCreateAgeName;
if (fNode) {
if (fNode->GetCreateAgeName())
fCreateAgeName = StrDupToAnsi(fNode->GetCreateAgeName());
else
fCreateAgeName = StrDup("");
}
return fCreateAgeName;
} }
plUUID pyVaultNode::GetCreateAgeGuid(void) const plUUID pyVaultNode::GetCreateAgeGuid(void) const
@ -359,13 +342,7 @@ void pyVaultNode::SetCreatorNodeID( uint32_t v )
void pyVaultNode::SetCreateAgeName( const char * v ) void pyVaultNode::SetCreateAgeName( const char * v )
{ {
free(fCreateAgeName); fNode->SetCreateAgeName(v);
fCreateAgeName = nil;
ASSERT(fNode);
wchar_t str[MAX_PATH];
StrToUnicode(str, v, arrsize(str));
fNode->SetCreateAgeName(str);
} }
void pyVaultNode::SetCreateAgeGuid( const char * v ) void pyVaultNode::SetCreateAgeGuid( const char * v )

1
Sources/Plasma/FeatureLib/pfPython/pyVaultNode.h

@ -99,7 +99,6 @@ public:
}; };
hsRef<RelVaultNode> fNode; hsRef<RelVaultNode> fNode;
mutable char * fCreateAgeName;
protected: protected:
// only for python glue, do NOT call // only for python glue, do NOT call

68
Sources/Plasma/FeatureLib/pfPython/pyVaultPlayerInfoNode.cpp

@ -57,24 +57,16 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
// should only be created from C++ side // should only be created from C++ side
pyVaultPlayerInfoNode::pyVaultPlayerInfoNode(RelVaultNode* nfsNode) pyVaultPlayerInfoNode::pyVaultPlayerInfoNode(RelVaultNode* nfsNode)
: pyVaultNode(nfsNode) : pyVaultNode(nfsNode)
, ansiPlayerName(nil)
, ansiAgeInstName(nil)
{ {
} }
//create from the Python side //create from the Python side
pyVaultPlayerInfoNode::pyVaultPlayerInfoNode() pyVaultPlayerInfoNode::pyVaultPlayerInfoNode()
: pyVaultNode(new RelVaultNode) : pyVaultNode(new RelVaultNode)
, ansiPlayerName(nil)
, ansiAgeInstName(nil)
{ {
fNode->SetNodeType(plVault::kNodeType_PlayerInfo); fNode->SetNodeType(plVault::kNodeType_PlayerInfo);
} }
pyVaultPlayerInfoNode::~pyVaultPlayerInfoNode () {
free(ansiPlayerName);
free(ansiAgeInstName);
}
//================================================================== //==================================================================
// class RelVaultNode : public plVaultNode // class RelVaultNode : public plVaultNode
@ -97,55 +89,39 @@ uint32_t pyVaultPlayerInfoNode::Player_GetPlayerID( void )
return playerInfo.GetPlayerId(); return playerInfo.GetPlayerId();
} }
void pyVaultPlayerInfoNode::Player_SetPlayerName( const char * name ) void pyVaultPlayerInfoNode::Player_SetPlayerName(const plString& name)
{ {
if (!fNode) if (fNode) {
return; VaultPlayerInfoNode playerInfo(fNode);
playerInfo.SetPlayerName(name);
wchar_t * wStr = StrDupToUnicode(name); }
VaultPlayerInfoNode playerInfo(fNode);
playerInfo.SetPlayerName(wStr);
free(wStr);
} }
const char * pyVaultPlayerInfoNode::Player_GetPlayerName( void ) plString pyVaultPlayerInfoNode::Player_GetPlayerName() const
{ {
if (!fNode) if (fNode) {
return ""; VaultPlayerInfoNode playerInfo(fNode);
return playerInfo.GetPlayerName();
VaultPlayerInfoNode playerInfo(fNode); }
if (!playerInfo.GetPlayerName()) return "";
return "";
free(ansiPlayerName);
ansiPlayerName = StrDupToAnsi(playerInfo.GetPlayerName());
return ansiPlayerName;
} }
// age the player is currently in, if any. // age the player is currently in, if any.
void pyVaultPlayerInfoNode::Player_SetAgeInstanceName( const char * agename ) void pyVaultPlayerInfoNode::Player_SetAgeInstanceName(const plString& name)
{ {
if (!fNode) if (fNode) {
return; VaultPlayerInfoNode playerInfo(fNode);
playerInfo.SetAgeInstName(name);
wchar_t * wStr = StrDupToUnicode(agename); }
VaultPlayerInfoNode playerInfo(fNode);
playerInfo.SetAgeInstName(wStr);
free(wStr);
} }
const char * pyVaultPlayerInfoNode::Player_GetAgeInstanceName( void ) plString pyVaultPlayerInfoNode::Player_GetAgeInstanceName() const
{ {
if (!fNode) if (fNode) {
return ""; VaultPlayerInfoNode playerInfo(fNode);
return playerInfo.GetAgeInstName();
VaultPlayerInfoNode playerInfo(fNode); }
if (!playerInfo.GetAgeInstName()) return "";
return "";
free(ansiAgeInstName);
ansiAgeInstName = StrDupToAnsi(playerInfo.GetAgeInstName());
return ansiAgeInstName;
} }
void pyVaultPlayerInfoNode::Player_SetAgeGuid( const char * guidtext) void pyVaultPlayerInfoNode::Player_SetAgeGuid( const char * guidtext)

13
Sources/Plasma/FeatureLib/pfPython/pyVaultPlayerInfoNode.h

@ -55,9 +55,6 @@ class plUUID;
class pyVaultPlayerInfoNode : public pyVaultNode class pyVaultPlayerInfoNode : public pyVaultNode
{ {
mutable char * ansiPlayerName;
mutable char * ansiAgeInstName;
protected: protected:
// should only be created from C++ side // should only be created from C++ side
pyVaultPlayerInfoNode(RelVaultNode * node); pyVaultPlayerInfoNode(RelVaultNode * node);
@ -66,7 +63,7 @@ protected:
pyVaultPlayerInfoNode(); pyVaultPlayerInfoNode();
public: public:
~pyVaultPlayerInfoNode (); ~pyVaultPlayerInfoNode() { }
// required functions for PyObject interoperability // required functions for PyObject interoperability
PYTHON_CLASS_NEW_FRIEND(ptVaultPlayerInfoNode); PYTHON_CLASS_NEW_FRIEND(ptVaultPlayerInfoNode);
@ -82,12 +79,12 @@ public:
// //
void Player_SetPlayerID( uint32_t plyrid ); void Player_SetPlayerID( uint32_t plyrid );
uint32_t Player_GetPlayerID( void ); uint32_t Player_GetPlayerID( void );
void Player_SetPlayerName( const char * name ); void Player_SetPlayerName(const plString& name);
const char * Player_GetPlayerName( void ); plString Player_GetPlayerName() const;
// age the player is currently in, if any. // age the player is currently in, if any.
void Player_SetAgeInstanceName( const char * agename ); void Player_SetAgeInstanceName(const plString& name);
const char * Player_GetAgeInstanceName( void ); plString Player_GetAgeInstanceName() const;
void Player_SetAgeGuid( const char * guidtext); void Player_SetAgeGuid( const char * guidtext);
plUUID Player_GetAgeGuid(void) const; plUUID Player_GetAgeGuid(void) const;
// online status // online status

4
Sources/Plasma/FeatureLib/pfPython/pyVaultPlayerInfoNodeGlue.cpp

@ -89,7 +89,7 @@ PYTHON_METHOD_DEFINITION(ptVaultPlayerInfoNode, playerSetName, args)
PYTHON_METHOD_DEFINITION_NOARGS(ptVaultPlayerInfoNode, playerGetName) PYTHON_METHOD_DEFINITION_NOARGS(ptVaultPlayerInfoNode, playerGetName)
{ {
return PyString_FromString(self->fThis->Player_GetPlayerName()); return PyString_FromPlString(self->fThis->Player_GetPlayerName());
} }
PYTHON_METHOD_DEFINITION(ptVaultPlayerInfoNode, playerSetAgeInstanceName, args) PYTHON_METHOD_DEFINITION(ptVaultPlayerInfoNode, playerSetAgeInstanceName, args)
@ -106,7 +106,7 @@ PYTHON_METHOD_DEFINITION(ptVaultPlayerInfoNode, playerSetAgeInstanceName, args)
PYTHON_METHOD_DEFINITION_NOARGS(ptVaultPlayerInfoNode, playerGetAgeInstanceName) PYTHON_METHOD_DEFINITION_NOARGS(ptVaultPlayerInfoNode, playerGetAgeInstanceName)
{ {
return PyString_FromString(self->fThis->Player_GetAgeInstanceName()); return PyString_FromPlString(self->fThis->Player_GetAgeInstanceName());
} }
PYTHON_METHOD_DEFINITION(ptVaultPlayerInfoNode, playerSetAgeGuid, args) PYTHON_METHOD_DEFINITION(ptVaultPlayerInfoNode, playerSetAgeGuid, args)

32
Sources/Plasma/FeatureLib/pfPython/pyVaultPlayerNode.cpp

@ -231,9 +231,7 @@ void pyVaultPlayerNode::RemoveVisitAgeLink(const char *guidstr)
PyObject *pyVaultPlayerNode::FindChronicleEntry(const char *entryName) PyObject *pyVaultPlayerNode::FindChronicleEntry(const char *entryName)
{ {
wchar_t wStr[MAX_PATH]; if (hsRef<RelVaultNode> rvn = VaultFindChronicleEntry(entryName))
StrToUnicode(wStr, entryName, arrsize(wStr));
if (hsRef<RelVaultNode> rvn = VaultFindChronicleEntry(wStr))
return pyVaultChronicleNode::New(rvn); return pyVaultChronicleNode::New(rvn);
PYTHON_RETURN_NONE; PYTHON_RETURN_NONE;
@ -244,15 +242,13 @@ void pyVaultPlayerNode::SetPlayerName(const char *value)
hsAssert(false, "python may not change a player's name this way"); hsAssert(false, "python may not change a player's name this way");
} }
std::string pyVaultPlayerNode::GetPlayerName() plString pyVaultPlayerNode::GetPlayerName() const
{ {
if (!fNode) if (fNode) {
return ""; VaultPlayerNode player(fNode);
return player.GetPlayerName();
VaultPlayerNode player(fNode); }
char ansiStr[MAX_PATH]; return "";
StrToAnsi(ansiStr, player.GetPlayerName(), arrsize(ansiStr));
return ansiStr;
} }
void pyVaultPlayerNode::SetAvatarShapeName(const char *value) void pyVaultPlayerNode::SetAvatarShapeName(const char *value)
@ -260,15 +256,13 @@ void pyVaultPlayerNode::SetAvatarShapeName(const char *value)
hsAssert(false, "python may not change a player's avatar this way"); hsAssert(false, "python may not change a player's avatar this way");
} }
std::string pyVaultPlayerNode::GetAvatarShapeName() plString pyVaultPlayerNode::GetAvatarShapeName() const
{ {
if (!fNode) if (fNode) {
return ""; VaultPlayerNode player(fNode);
return player.GetAvatarShapeName();
VaultPlayerNode player(fNode); }
char ansiStr[MAX_PATH]; return "";
StrToAnsi(ansiStr, player.GetAvatarShapeName(), arrsize(ansiStr));
return ansiStr;
} }
void pyVaultPlayerNode::SetDisabled(bool value) void pyVaultPlayerNode::SetDisabled(bool value)

6
Sources/Plasma/FeatureLib/pfPython/pyVaultPlayerNode.h

@ -49,10 +49,10 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
#include "HeadSpin.h" #include "HeadSpin.h"
#include "pyGlueHelpers.h" #include "pyGlueHelpers.h"
#include <string>
#include "pyVaultNode.h" #include "pyVaultNode.h"
class pyAgeInfoStruct; class pyAgeInfoStruct;
class plString;
struct RelVaultNode; struct RelVaultNode;
class pyVaultPlayerNode : public pyVaultNode class pyVaultPlayerNode : public pyVaultNode
@ -101,10 +101,10 @@ public:
PyObject *FindChronicleEntry(const char *entryName); // returns pyVaultChronicleNode PyObject *FindChronicleEntry(const char *entryName); // returns pyVaultChronicleNode
void SetPlayerName(const char *value); void SetPlayerName(const char *value);
std::string GetPlayerName(); plString GetPlayerName() const;
void SetAvatarShapeName(const char *value); void SetAvatarShapeName(const char *value);
std::string GetAvatarShapeName(); plString GetAvatarShapeName() const;
void SetDisabled(bool value); void SetDisabled(bool value);
bool IsDisabled(); bool IsDisabled();

11
Sources/Plasma/FeatureLib/pfPython/pyVaultSDLNode.cpp

@ -105,13 +105,10 @@ PyObject * pyVaultSDLNode::GetStateDataRecord() const
void pyVaultSDLNode::InitStateDataRecord( const char* agename, int flags) void pyVaultSDLNode::InitStateDataRecord( const char* agename, int flags)
{ {
if (!fNode) if (fNode) {
return; VaultSDLNode sdl(fNode);
sdl.InitStateDataRecord(agename, flags);
wchar_t wStr[MAX_PATH]; }
StrToUnicode(wStr, agename, arrsize(wStr));
VaultSDLNode sdl(fNode);
sdl.InitStateDataRecord(wStr, flags);
} }
void pyVaultSDLNode::SetStateDataRecord( const pySDLStateDataRecord & rec, int writeOptions/*=0 */) void pyVaultSDLNode::SetStateDataRecord( const pySDLStateDataRecord & rec, int writeOptions/*=0 */)

90
Sources/Plasma/FeatureLib/pfPython/pyVaultTextNoteNode.cpp

@ -75,14 +75,10 @@ pyVaultTextNoteNode::pyVaultTextNoteNode()
// //
void pyVaultTextNoteNode::Note_SetTitle( const char * text ) void pyVaultTextNoteNode::Note_SetTitle( const char * text )
{ {
if (!fNode) if (fNode) {
return; VaultTextNoteNode textNote(fNode);
textNote.SetNoteTitle(text);
wchar_t wStr[MAX_PATH] = L""; }
if (text)
StrToUnicode(wStr, text, arrsize(wStr));
VaultTextNoteNode textNote(fNode);
textNote.SetNoteTitle(wStr);
} }
void pyVaultTextNoteNode::Note_SetTitleW( const wchar_t * text ) void pyVaultTextNoteNode::Note_SetTitleW( const wchar_t * text )
@ -91,48 +87,24 @@ void pyVaultTextNoteNode::Note_SetTitleW( const wchar_t * text )
return; return;
VaultTextNoteNode textNote(fNode); VaultTextNoteNode textNote(fNode);
textNote.SetNoteTitle(text); textNote.SetNoteTitle(plString::FromWchar(text));
} }
std::string pyVaultTextNoteNode::Note_GetTitle( void ) plString pyVaultTextNoteNode::Note_GetTitle() const
{ {
if (!fNode) if (fNode) {
return ""; VaultTextNoteNode note(fNode);
return note.GetNoteTitle();
char * aStr = nil;
VaultTextNoteNode textNote(fNode);
if (textNote.GetNoteTitle()) {
std::string result;
aStr = StrDupToAnsi(textNote.GetNoteTitle());
result = aStr;
free(aStr);
return result;
} }
return ""; return "";
} }
std::wstring pyVaultTextNoteNode::Note_GetTitleW( void ) void pyVaultTextNoteNode::Note_SetText(const char * text)
{
if (!fNode)
return L"";
VaultTextNoteNode textNote(fNode);
if (textNote.GetNoteTitle())
return textNote.GetNoteTitle();
return L"";
}
void pyVaultTextNoteNode::Note_SetText( const char * text )
{ {
if (!fNode) if (fNode) {
return; VaultTextNoteNode textNote(fNode);
textNote.SetNoteText(text);
wchar_t * wStr = nil; }
if (text)
wStr = StrDupToUnicode(text);
VaultTextNoteNode textNote(fNode);
textNote.SetNoteText(wStr);
free(wStr);
} }
void pyVaultTextNoteNode::Note_SetTextW( const wchar_t * text ) void pyVaultTextNoteNode::Note_SetTextW( const wchar_t * text )
@ -141,37 +113,18 @@ void pyVaultTextNoteNode::Note_SetTextW( const wchar_t * text )
return; return;
VaultTextNoteNode textNote(fNode); VaultTextNoteNode textNote(fNode);
textNote.SetNoteText(text); textNote.SetNoteText(plString::FromWchar(text));
} }
std::string pyVaultTextNoteNode::Note_GetText( void ) plString pyVaultTextNoteNode::Note_GetText() const
{ {
if (!fNode) if (fNode) {
return ""; VaultTextNoteNode note(fNode);
return note.GetNoteText();
char * aStr = nil;
VaultTextNoteNode textNote(fNode);
if (textNote.GetNoteText()) {
std::string result;
aStr = StrDupToAnsi(textNote.GetNoteText());
result = aStr;
free(aStr);
return result;
} }
return ""; return "";
} }
std::wstring pyVaultTextNoteNode::Note_GetTextW( void )
{
if (!fNode)
return L"";
VaultTextNoteNode textNote(fNode);
if (textNote.GetNoteText())
return textNote.GetNoteText();
return L"";
}
void pyVaultTextNoteNode::Note_SetType( int32_t type ) void pyVaultTextNoteNode::Note_SetType( int32_t type )
{ {
if (!fNode) if (!fNode)
@ -225,10 +178,7 @@ void pyVaultTextNoteNode::SetDeviceInbox( const char * devName, PyObject * cbObj
pyVaultNode::pyVaultNodeOperationCallback * cb = new pyVaultNode::pyVaultNodeOperationCallback( cbObject ); pyVaultNode::pyVaultNodeOperationCallback * cb = new pyVaultNode::pyVaultNodeOperationCallback( cbObject );
cb->VaultOperationStarted( cbContext ); cb->VaultOperationStarted( cbContext );
wchar_t wDev[MAX_PATH]; if (hsRef<RelVaultNode> rvn = VaultAgeSetDeviceInboxAndWait(devName, DEFAULT_DEVICE_INBOX))
StrToUnicode(wDev, devName, arrsize(wDev));
if (hsRef<RelVaultNode> rvn = VaultAgeSetDeviceInboxAndWait(wDev, DEFAULT_DEVICE_INBOX))
cb->SetNode(rvn); cb->SetNode(rvn);
cb->VaultOperationComplete( cbContext, cb->GetNode() ? hsOK : hsFail ); // cbHolder deletes itself here. cb->VaultOperationComplete( cbContext, cb->GetNode() ? hsOK : hsFail ); // cbHolder deletes itself here.

9
Sources/Plasma/FeatureLib/pfPython/pyVaultTextNoteNode.h

@ -50,13 +50,12 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "HeadSpin.h" #include "HeadSpin.h"
#include "pyGlueHelpers.h" #include "pyGlueHelpers.h"
#include <string>
#include "pyVaultNode.h" #include "pyVaultNode.h"
class plString;
struct RelVaultNode; struct RelVaultNode;
class pyVaultAgeLinkNode; class pyVaultAgeLinkNode;
class pyVaultTextNoteNode : public pyVaultNode class pyVaultTextNoteNode : public pyVaultNode
{ {
protected: protected:
@ -82,12 +81,10 @@ public:
// //
void Note_SetTitle( const char * text ); void Note_SetTitle( const char * text );
void Note_SetTitleW( const wchar_t * text ); void Note_SetTitleW( const wchar_t * text );
std::string Note_GetTitle( void ); plString Note_GetTitle() const;
std::wstring Note_GetTitleW( void );
void Note_SetText( const char * text ); void Note_SetText( const char * text );
void Note_SetTextW( const wchar_t * text ); void Note_SetTextW( const wchar_t * text );
std::string Note_GetText( void ); plString Note_GetText() const;
std::wstring Note_GetTextW( void );
void Note_SetType( int32_t type ); void Note_SetType( int32_t type );
int32_t Note_GetType( void ); int32_t Note_GetType( void );

6
Sources/Plasma/FeatureLib/pfPython/pyVaultTextNoteNodeGlue.cpp

@ -173,8 +173,7 @@ PYTHON_METHOD_DEFINITION_NOARGS(ptVaultTextNoteNode, getTitle)
PYTHON_METHOD_DEFINITION_NOARGS(ptVaultTextNoteNode, getTitleW) PYTHON_METHOD_DEFINITION_NOARGS(ptVaultTextNoteNode, getTitleW)
{ {
std::wstring retVal = self->fThis->Note_GetTitleW(); return PyUnicode_FromStringEx(self->fThis->Note_GetTitle());
return PyUnicode_FromWideChar(retVal.c_str(), retVal.length());
} }
PYTHON_METHOD_DEFINITION(ptVaultTextNoteNode, setText, args) PYTHON_METHOD_DEFINITION(ptVaultTextNoteNode, setText, args)
@ -225,8 +224,7 @@ PYTHON_METHOD_DEFINITION_NOARGS(ptVaultTextNoteNode, getText)
PYTHON_METHOD_DEFINITION_NOARGS(ptVaultTextNoteNode, getTextW) PYTHON_METHOD_DEFINITION_NOARGS(ptVaultTextNoteNode, getTextW)
{ {
std::wstring retVal = self->fThis->Note_GetTextW(); return PyUnicode_FromStringEx(self->fThis->Note_GetText());
return PyUnicode_FromWideChar(retVal.c_str(), retVal.length());
} }
PYTHON_METHOD_DEFINITION(ptVaultTextNoteNode, setType, args) PYTHON_METHOD_DEFINITION(ptVaultTextNoteNode, setType, args)

896
Sources/Plasma/NucleusLib/pnNetProtocol/Private/pnNpCommon.cpp

@ -53,9 +53,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
namespace pnNpCommon { namespace pnNpCommon {
// Verify our uint64_t constants were properly inited as such.
static_assert(NetVaultNode::kBlob_2, "NetVaultNode constants failed to init");
/***************************************************************************** /*****************************************************************************
@ -297,605 +294,344 @@ void NetGameRank::CopyFrom(const NetGameRank & fromRank) {
***/ ***/
//============================================================================ //============================================================================
void NetVaultNode::DeallocNodeFields () { void NetVaultNode::Blob::operator=(const Blob& rhs)
free(createAgeName); {
free(string64_1); if (size != rhs.size) {
free(string64_2); delete[] buffer;
free(string64_3); buffer = new uint8_t[rhs.size];
free(string64_4); size = rhs.size;
free(string64_5); }
free(string64_6); memcpy(buffer, rhs.buffer, rhs.size);
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) { void NetVaultNode::Blob::operator=(Blob&& rhs)
{
DeallocNodeFields(); delete[] buffer;
size = rhs.size;
uint8_t * buffer = const_cast<uint8_t *>(inbuffer); buffer = rhs.buffer;
uint8_t * start = buffer; rhs.size = 0;
rhs.buffer = nullptr;
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) { bool NetVaultNode::Blob::operator==(const Blob& rhs) const
{
unsigned pos = buffer->Count(); if (size == rhs.size)
return memcmp(buffer, rhs.buffer, size) == 0;
uint64_t flags = fieldFlags; return false;
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::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;
}
//============================================================================
template<typename T>
static void IZero(T& dest)
{
dest = 0;
}
template<>
static void IZero<plString>(plString& dest)
{
dest = "";
}
template<>
static void IZero<plUUID>(plUUID& dest)
{
dest = kNilUuid;
}
template<>
static void IZero<NetVaultNode::Blob>(NetVaultNode::Blob& blob)
{
delete[] blob.buffer;
blob.buffer = nullptr;
blob.size = 0;
}
void NetVaultNode::CopyFrom(const NetVaultNode* node)
{
fUsedFields = node->fUsedFields;
fDirtyFields = node->fDirtyFields;
fRevision = node->fRevision;
#define COPYORZERO(field) \
if (fUsedFields & k##field) \
f##field = node->f##field; \
else \
IZero(f##field);
COPYORZERO(NodeId);
COPYORZERO(CreateTime);
COPYORZERO(ModifyTime);
COPYORZERO(CreateAgeName);
COPYORZERO(CreateAgeUuid);
COPYORZERO(CreatorAcct);
COPYORZERO(CreatorId);
COPYORZERO(NodeType);
COPYORZERO(Int32_1);
COPYORZERO(Int32_2);
COPYORZERO(Int32_3);
COPYORZERO(Int32_4);
COPYORZERO(UInt32_1);
COPYORZERO(UInt32_2);
COPYORZERO(UInt32_3);
COPYORZERO(UInt32_4);
COPYORZERO(Uuid_1);
COPYORZERO(Uuid_2);
COPYORZERO(Uuid_3);
COPYORZERO(Uuid_4);
COPYORZERO(String64_1);
COPYORZERO(String64_2);
COPYORZERO(String64_3);
COPYORZERO(String64_4);
COPYORZERO(String64_5);
COPYORZERO(String64_6);
COPYORZERO(IString64_1);
COPYORZERO(IString64_2);
COPYORZERO(Text_1);
COPYORZERO(Text_2);
COPYORZERO(Blob_1);
COPYORZERO(Blob_2);
#undef COPYORZERO
}
//============================================================================
bool NetVaultNode::Matches(const NetVaultNode* rhs) const
{
for (uint64_t bit = 1; bit; bit <<= 1) { 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 we have tested all fields on the other node, we obviously match.
if (bit > other->fieldFlags) if (bit > rhs->fUsedFields)
return true; return true;
// if the other node does not have the field, then continue to next field // If the other node does not have the field, then continue to next field
if (!(bit & other->fieldFlags)) if (!(bit & rhs->fUsedFields))
continue; continue;
// if we don't have the field (but the other node does), then return false // If we don't have this field, but the other node does, we are obviously not the same.
if (!(bit & fieldFlags)) if (!(bit & fUsedFields))
return false; return false;
#define COMPARE(flag, func, var) case flag: if (!func(var, other->var)) return false; break #define COMPARE(field) if (k##field == bit && f##field != rhs->f##field) return false;
switch (bit) { #define COMPARE_ISTRING(field) if (k##field == bit && f##field.CompareI(rhs->f##field) != 0) return false;
COMPARE(kNodeId, ICompareValue, nodeId); COMPARE(NodeId);
COMPARE(kCreateTime, ICompareValue, createTime); COMPARE(CreateTime);
COMPARE(kModifyTime, ICompareValue, modifyTime); COMPARE(ModifyTime);
COMPARE(kCreateAgeName, ICompareStringI, createAgeName); COMPARE_ISTRING(CreateAgeName);
COMPARE(kCreateAgeUuid, ICompareValue, createAgeUuid); COMPARE(CreateAgeUuid);
COMPARE(kCreatorAcct, ICompareValue, creatorAcct); COMPARE(CreatorAcct);
COMPARE(kCreatorId, ICompareValue, creatorId); COMPARE(CreatorId);
COMPARE(kNodeType, ICompareValue, nodeType); COMPARE(NodeType);
COMPARE(kInt32_1, ICompareValue, int32_1); COMPARE(Int32_1);
COMPARE(kInt32_2, ICompareValue, int32_2); COMPARE(Int32_2);
COMPARE(kInt32_3, ICompareValue, int32_3); COMPARE(Int32_3);
COMPARE(kInt32_4, ICompareValue, int32_4); COMPARE(Int32_4);
COMPARE(kUInt32_1, ICompareValue, uint32_1); COMPARE(UInt32_1);
COMPARE(kUInt32_2, ICompareValue, uint32_2); COMPARE(UInt32_2);
COMPARE(kUInt32_3, ICompareValue, uint32_3); COMPARE(UInt32_3);
COMPARE(kUInt32_4, ICompareValue, uint32_4); COMPARE(UInt32_4);
COMPARE(kUuid_1, ICompareValue, uuid_1); COMPARE(Uuid_1);
COMPARE(kUuid_2, ICompareValue, uuid_2); COMPARE(Uuid_2);
COMPARE(kUuid_3, ICompareValue, uuid_3); COMPARE(Uuid_3);
COMPARE(kUuid_4, ICompareValue, uuid_4); COMPARE(Uuid_4);
COMPARE(kString64_1, ICompareString, string64_1); COMPARE(String64_1);
COMPARE(kString64_2, ICompareString, string64_2); COMPARE(String64_2);
COMPARE(kString64_3, ICompareString, string64_3); COMPARE(String64_3);
COMPARE(kString64_4, ICompareString, string64_4); COMPARE(String64_4);
COMPARE(kString64_5, ICompareString, string64_5); COMPARE(String64_5);
COMPARE(kString64_6, ICompareString, string64_6); COMPARE(String64_6);
COMPARE(kIString64_1, ICompareStringI, istring64_1); COMPARE_ISTRING(IString64_1);
COMPARE(kIString64_2, ICompareStringI, istring64_2); COMPARE_ISTRING(IString64_2);
COMPARE(kText_1, ICompareString, text_1); COMPARE(Text_1);
COMPARE(kText_2, ICompareString, text_2); COMPARE(Text_2);
COMPARE(kBlob_1, ICompareArray, blob_1); COMPARE(Blob_1);
COMPARE(kBlob_2, ICompareArray, blob_2); COMPARE(Blob_2);
DEFAULT_FATAL(bit); #undef COMPARE
} #undef COMPARE_ISTRING
#undef COMPARE
} }
return true;
}
//============================================================================ // We should never get here, but this silences a warning.
void NetVaultNode::CopyFrom (const NetVaultNode * other, unsigned copyOpts) { return true;
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
}
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);
}
/*****************************************************************************
*
* CSrvPackBuffer
*
***/
//============================================================================
CSrvPackBuffer::CSrvPackBuffer (unsigned bytes) {
m_data = (uint8_t *)malloc(bytes);
m_pos = m_data;
m_end = m_pos + bytes;
}
//============================================================================
void * CSrvPackBuffer::Alloc (unsigned bytes) {
ASSERT((signed) bytes >= 0);
ASSERT(m_pos + bytes <= m_end);
uint8_t * pos = m_pos;
m_pos += bytes;
return pos;
}
//============================================================================
void CSrvPackBuffer::AddData (const void * ptr, unsigned bytes) {
memcpy(Alloc(bytes), ptr, bytes);
}
//============================================================================
void CSrvPackBuffer::AddString (const wchar_t str[]) {
AddData(str, StrBytes(str));
}
//============================================================================
void CSrvPackBuffer::AddDWordArray (const uint32_t * arr, unsigned count) {
// Don't let large counts cause pointer wrap
count &= 0x00ffffff;
AddData(arr, count * sizeof(arr[0]));
}
//============================================================================
unsigned CSrvPackBuffer::Size () {
return m_pos - m_data;
}
/*****************************************************************************
*
* CSrvUnpackBuffer
*
***/
//============================================================================
CSrvUnpackBuffer::CSrvUnpackBuffer (const void * buffer, unsigned count) {
m_pos = (const uint8_t *) buffer;
m_end = m_pos + count;
} }
//============================================================================ //============================================================================
const void * CSrvUnpackBuffer::GetData (unsigned bytes) { template<typename T>
for (;;) { static void IRead(const uint8_t*& buf, T& dest)
const uint8_t * result = m_pos; {
m_pos += bytes; const T* ptr = reinterpret_cast<const T*>(buf);
dest = *ptr;
if (m_pos < result) buf += sizeof(T);
break; }
if (m_pos > m_end)
break; template<>
static void IRead<plString>(const uint8_t*& buf, plString& dest)
return result; {
uint32_t size = *(reinterpret_cast<const uint32_t*>(buf));
uint32_t arraySize = size / 2;
buf += sizeof(uint32_t);
plStringBuffer<uint16_t> str;
uint16_t* theStrBuffer = str.CreateWritableBuffer(arraySize - 1);
memcpy(theStrBuffer, buf, size);
theStrBuffer[arraySize - 1] = 0;
dest = plString::FromUtf16(str);
buf += size;
}
template<>
static void IRead<NetVaultNode::Blob>(const uint8_t*& buf, NetVaultNode::Blob& blob)
{
blob.size = *(reinterpret_cast<const uint32_t*>(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<const uint64_t*>(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<typename T>
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<plString>(ARRAY(uint8_t)* buffer, plString value)
{
plStringBuffer<uint16_t> 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<const NetVaultNode::Blob&>(ARRAY(uint8_t)* buffer, const NetVaultNode::Blob& blob)
{
IWrite(buffer, static_cast<uint32_t>(blob.size));
if (blob.size > 0) {
uint8_t* ptr = buffer->New(blob.size);
memcpy(ptr, blob.buffer, blob.size);
} }
m_end = nil;
return nil;
} }
//============================================================================ void NetVaultNode::Write(ARRAY(uint8_t)* buf, uint32_t ioFlags)
const wchar_t * CSrvUnpackBuffer::GetString () { {
uint64_t flags = fUsedFields;
if (m_end) { if (ioFlags & kDirtyNodeType)
const wchar_t * end = (const wchar_t *) (m_end - sizeof(wchar_t) + 1); fDirtyFields |= kNodeType;
for (const wchar_t * cur = (const wchar_t *) m_pos; cur < end; ) { if (ioFlags & kDirtyString64_1)
if (*cur++) fDirtyFields |= kString64_1;
continue; if (ioFlags & kDirtyOnly)
flags &= fDirtyFields;
const wchar_t * pos = (const wchar_t *) m_pos; IWrite(buf, flags);
m_pos = (const uint8_t *) cur;
return pos; #define WRITE(field) if (flags & k##field) IWrite(buf, f##field);
} WRITE(NodeId);
} WRITE(CreateTime);
WRITE(ModifyTime);
m_end = NULL; WRITE(CreateAgeName);
return NULL; WRITE(CreateAgeUuid);
} WRITE(CreatorAcct);
WRITE(CreatorId);
//============================================================================ WRITE(NodeType);
const uint32_t * CSrvUnpackBuffer::GetDWordArray (unsigned count) { WRITE(Int32_1);
// Don't let large counts cause pointer wrap WRITE(Int32_2);
if (count & 0x00ffffff) WRITE(Int32_3);
return (const uint32_t *)GetData(count * sizeof(uint32_t)); WRITE(Int32_4);
WRITE(UInt32_1);
m_end = nil; WRITE(UInt32_2);
return nil; WRITE(UInt32_3);
} WRITE(UInt32_4);
WRITE(Uuid_1);
//============================================================================ WRITE(Uuid_2);
unsigned CSrvUnpackBuffer::BytesLeft () { WRITE(Uuid_3);
return m_end ? m_end - m_pos : 0; WRITE(Uuid_4);
} WRITE(String64_1);
WRITE(String64_2);
//============================================================================ WRITE(String64_3);
bool CSrvUnpackBuffer::ParseError () { WRITE(String64_4);
return !m_end; 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;
} }

512
Sources/Plasma/NucleusLib/pnNetProtocol/Private/pnNpCommon.h

@ -153,258 +153,244 @@ struct NetGameRank {
* *
***/ ***/
//============================================================================ class NetVaultNode : public hsRefCnt
// NetVaultNode {
//============================================================================ protected:
// Threaded apps: App is responsible for locking node->critsect before accessing *any* field in this struct enum NodeFields
struct NetVaultNode : hsRefCnt { {
enum RwOptions { kNodeId = (1 << 0),
kRwDirtyOnly = 1<<0, // READ : No meaning kCreateTime = (1 << 1),
// WRITE: Only write fields marked dirty kModifyTime = (1 << 2),
kRwUpdateDirty = 1<<1, // READ : Set dirty flag on fields read from stream kCreateAgeName = (1 << 3),
// WRITE: Clear dirty flag on fields written to stream 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 { public:
kCopySetDirty = 1<<0, // set dirty flag on changed dst fields /**
kCopyOverwrite = 1<<1, // overwrite fields for which dst node already has values * This is public only so that it may be referenced by anonymous functions.
kCopyClear = 1<<2, // clear dst fields for which src node does not have values * Should not be used outside NetVaultNode.
*/
struct Blob
{
size_t size;
uint8_t* buffer;
Blob() : size(0), buffer(nullptr) { }
~Blob() { delete[] buffer; }
void operator =(const Blob& rhs);
void operator =(Blob&& rhs);
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: 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 fUsedFields;
uint64_t bit, uint64_t fDirtyFields;
wchar_t ** pdst, plUUID fRevision;
const wchar_t src[],
unsigned chars uint32_t fNodeId;
) { uint32_t fCreateTime;
free(*pdst); uint32_t fModifyTime;
if (src && src[0]) plString fCreateAgeName;
*pdst = StrDupLen(src, chars); plUUID fCreateAgeUuid;
else plUUID fCreatorAcct;
*pdst = StrDupLen(L"", chars); uint32_t fCreatorId;
fieldFlags |= bit; uint32_t fNodeType;
dirtyFlags |= bit; 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<typename T>
inline void ISetVaultField(uint64_t bits, T& field, T value)
{
field = value;
fUsedFields |= bits;
fDirtyFields |= bits;
} }
template <typename T> template<typename T>
inline void IVaultNodeSetValue ( inline void ISetVaultField_NoDirty(uint64_t bits, T& field, T value)
uint64_t bit, {
T * pdst, field = value;
const T & src fUsedFields |= bits;
) {
*pdst = src;
fieldFlags |= bit;
dirtyFlags |= bit;
} }
void IVaultNodeSetBlob ( void ISetVaultBlob(uint64_t bits, Blob& blob, const uint8_t* buf, size_t size);
uint64_t bit,
uint8_t ** pdst, public:
unsigned * pdstLen, enum IOFlags
const uint8_t src[], {
unsigned srcLen /** Only write fields marked dirty */
) { kDirtyOnly = (1 << 0),
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 DeallocNodeFields(); /** 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: public:
NetVaultNode (); NetVaultNode()
~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),
// Threaded apps: Must be called with node->critsect locked fUInt32_4(0), fUsedFields(0), fDirtyFields(0)
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
/** Clears this NetVaultNode for subsequent usage */
bool Matches (const NetVaultNode * other); void Clear();
void CopyFrom (const NetVaultNode * other, uint32_t copyOpts);
/** Copies data from \a node to this NetVaultNode */
uint64_t GetFieldFlags () const { return fieldFlags; } void CopyFrom(const NetVaultNode* node);
void ClearFieldFlags () { fieldFlags = 0; }
bool Matches(const NetVaultNode* rhs) const;
uint64_t GetDirtyFlags () const { return dirtyFlags; }
void SetDirtyFlags (uint64_t flags) { dirtyFlags |= flags; } void Read(const uint8_t* buf, size_t size);
void ClearDirtyFlags (uint64_t flags) { dirtyFlags &= ~flags; } void Write(ARRAY(uint8_t)* buf, uint32_t ioFlags=0);
// Threaded apps: Must be called with node->critsect locked protected:
void SetNodeId (uint32_t v); uint64_t GetFieldFlags() const { return fUsedFields; }
void SetNodeId_NoDirty (uint32_t v) { nodeId = v; }
void SetCreateTime (uint32_t v); public:
void SetModifyTime (uint32_t v); bool IsDirty() const { return fDirtyFields != 0; }
void SetCreateAgeName (const wchar_t v[]);
void SetCreateAgeUuid (const plUUID & v); plUUID GetRevision() const { return fRevision; }
void SetCreatorAcct (const plUUID & v); void GenerateRevision() { fRevision = plUUID::Generate(); }
void SetCreatorId (uint32_t v);
void SetNodeType (uint32_t v); uint32_t GetNodeId() const { return fNodeId; }
void SetInt32_1 (int32_t v); uint32_t GetCreateTime() const { return fCreateTime; }
void SetInt32_2 (int32_t v); uint32_t GetModifyTime() const { return fModifyTime; }
void SetInt32_3 (int32_t v); plString GetCreateAgeName() const { return fCreateAgeName; }
void SetInt32_4 (int32_t v); plUUID GetCreateAgeUuid() const { return fCreateAgeUuid; }
void SetUInt32_1 (uint32_t v); plUUID GetCreatorAcct() const { return fCreatorAcct; }
void SetUInt32_2 (uint32_t v); uint32_t GetCreatorId() const { return fCreatorId; }
void SetUInt32_3 (uint32_t v); uint32_t GetNodeType() const { return fNodeType; }
void SetUInt32_4 (uint32_t v); int32_t GetInt32_1() const { return fInt32_1; }
void SetUuid_1 (const plUUID & v); int32_t GetInt32_2() const { return fInt32_2; }
void SetUuid_2 (const plUUID & v); int32_t GetInt32_3() const { return fInt32_3; }
void SetUuid_3 (const plUUID & v); int32_t GetInt32_4() const { return fInt32_4; }
void SetUuid_4 (const plUUID & v); uint32_t GetUInt32_1() const { return fUInt32_1; }
void SetString64_1 (const wchar_t v[]); uint32_t GetUInt32_2() const { return fUInt32_2; }
void SetString64_2 (const wchar_t v[]); uint32_t GetUInt32_3() const { return fUInt32_3; }
void SetString64_3 (const wchar_t v[]); uint32_t GetUInt32_4() const { return fUInt32_4; }
void SetString64_4 (const wchar_t v[]); plUUID GetUuid_1() const { return fUuid_1; }
void SetString64_5 (const wchar_t v[]); plUUID GetUuid_2() const { return fUuid_2; }
void SetString64_6 (const wchar_t v[]); plUUID GetUuid_3() const { return fUuid_3; }
void SetIString64_1 (const wchar_t v[]); plUUID GetUuid_4() const { return fUuid_4; }
void SetIString64_2 (const wchar_t v[]); plString GetString64_1() const { return fString64_1; }
void SetText_1 (const wchar_t v[]); plString GetString64_2() const { return fString64_2; }
void SetText_2 (const wchar_t v[]); plString GetString64_3() const { return fString64_3; }
void SetBlob_1 (const uint8_t v[], uint32_t len); plString GetString64_4() const { return fString64_4; }
void SetBlob_2 (const uint8_t v[], uint32_t len); plString GetString64_5() const { return fString64_5; }
plString GetString64_6() const { return fString64_6; }
uint32_t GetNodeId () const { return nodeId; } plString GetIString64_1() const { return fIString64_1; }
uint32_t GetCreateTime () const { return createTime; } plString GetIString64_2() const { return fIString64_2; }
uint32_t GetModifyTime () const { return modifyTime; } plString GetText_1() const { return fText_1; }
const wchar_t * GetCreateAgeName () const { return createAgeName; } plString GetText_2() const { return fText_2; }
plUUID GetCreateAgeUuid () const { return createAgeUuid; }
plUUID GetCreatorAcct () const { return creatorAcct; } const uint8_t* GetBlob_1() const { return fBlob_1.buffer; }
uint32_t GetCreatorId () const { return creatorId; } size_t GetBlob_1Length() const { return fBlob_1.size; }
uint32_t GetNodeType () const { return nodeType; }
int32_t GetInt32_1 () const { return int32_1; } const uint8_t* GetBlob_2() const { return fBlob_2.buffer; }
int32_t GetInt32_2 () const { return int32_2; } size_t GetBlob_2Length() const { return fBlob_2.size; }
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; }
};
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) // NetVaultNodeRef (packed because is sent over wire directly)
@ -417,51 +403,3 @@ struct NetVaultNodeRef {
bool seen; bool seen;
}; };
#pragma pack(pop) #pragma pack(pop)
//============================================================================
// SrvPackBuffer
//============================================================================
// Allocate a CSrvPackBuffer on the heap with one extra uint32_t to allow for padding
#define SRV_ALLOC_BUFFER(bytes) \
new(malloc(sizeof(CSrvPackBuffer) + (bytes) + sizeof(uint32_t))) \
CSrvPackBuffer(bytes + sizeof(uint32_t))
// Allocate a CSrvPackBuffer on the stack with one extra uint32_t to allow for padding
#define SRV_ALLOCA_BUFFER(bytes) \
new(_alloca(sizeof(CSrvPackBuffer) + (bytes) + sizeof(uint32_t))) \
CSrvPackBuffer(bytes + sizeof(uint32_t))
class CSrvPackBuffer {
public:
CSrvPackBuffer (unsigned bytes);
void * Alloc (unsigned bytes);
void AddData (const void * ptr, unsigned bytes);
void AddString (const wchar_t str[]);
void AddDWordArray (const uint32_t * arr, unsigned count);
// add new "Add..." methods here as needed
unsigned Size ();
private:
uint8_t * m_pos;
uint8_t * m_end;
uint8_t * m_data;
};
class CSrvUnpackBuffer {
public:
CSrvUnpackBuffer (const void * buffer, unsigned count);
const void * GetData (unsigned bytes);
const wchar_t * GetString ();
const uint32_t * GetDWordArray (unsigned count);
unsigned BytesLeft ();
bool ParseError ();
private:
const uint8_t * m_pos;
const uint8_t * m_end;
};

14
Sources/Plasma/NucleusLib/pnUtils/pnUtMisc.h

@ -69,18 +69,4 @@ void * ModuleGetInstance ();
const wchar_t * AppGetCommandLine (); const wchar_t * AppGetCommandLine ();
/*****************************************************************************
*
* Misc types
*
***/
// used to dump the internal state of a module
typedef void (CDECL * FStateDump)(
void * param,
const wchar_t fmt[],
...
);
#endif #endif

2
Sources/Plasma/PubUtilLib/plNetClient/plLinkEffectsMgr.cpp

@ -64,7 +64,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "pnKeyedObject/plFixedKey.h" #include "pnKeyedObject/plFixedKey.h"
// chronicle var // chronicle var
#define kCleftSolved L"CleftSolved" #define kCleftSolved "CleftSolved"
#include "plAvatar/plArmatureMod.h" #include "plAvatar/plArmatureMod.h"
#include "plAvatar/plAvatarTasks.h" #include "plAvatar/plAvatarTasks.h"

2
Sources/Plasma/PubUtilLib/plNetClient/plNetCliAgeJoiner.cpp

@ -408,7 +408,7 @@ bool plNCAgeJoiner::MsgReceive (plMessage * msg) {
else if (unsigned ageVaultId = NetCommGetAge()->ageVaultId) { else if (unsigned ageVaultId = NetCommGetAge()->ageVaultId) {
// Download the age vault // Download the age vault
VaultDownload( VaultDownload(
L"AgeJoin", "AgeJoin",
ageVaultId, ageVaultId,
AgeVaultDownloadCallback, AgeVaultDownloadCallback,
this, this,

12
Sources/Plasma/PubUtilLib/plNetClient/plNetLinkingMgr.cpp

@ -777,10 +777,8 @@ void plNetLinkingMgr::IPostProcessLink( void )
// Update our online status // Update our online status
if (hsRef<RelVaultNode> rvnInfo = VaultGetPlayerInfoNode()) { if (hsRef<RelVaultNode> rvnInfo = VaultGetPlayerInfoNode()) {
VaultPlayerInfoNode accInfo(rvnInfo); VaultPlayerInfoNode accInfo(rvnInfo);
wchar_t ageInstName[MAX_PATH];
plUUID ageInstGuid = *info->GetAgeInstanceGuid(); plUUID ageInstGuid = *info->GetAgeInstanceGuid();
StrToUnicode(ageInstName, info->GetAgeInstanceName(), arrsize(ageInstName)); accInfo.SetAgeInstName(info->GetAgeInstanceName());
accInfo.SetAgeInstName(ageInstName);
accInfo.SetAgeInstUuid(ageInstGuid); accInfo.SetAgeInstUuid(ageInstGuid);
accInfo.SetOnline(true); accInfo.SetOnline(true);
} }
@ -869,11 +867,9 @@ uint8_t plNetLinkingMgr::IPreProcessLink(void)
// Update our online status // Update our online status
if (hsRef<RelVaultNode> rvnInfo = VaultGetPlayerInfoNode()) { if (hsRef<RelVaultNode> rvnInfo = VaultGetPlayerInfoNode()) {
VaultPlayerInfoNode accInfo(rvnInfo); VaultPlayerInfoNode accInfo(rvnInfo);
wchar_t ageInstName[MAX_PATH]; const plUUID* ageInstGuid = info->GetAgeInstanceGuid();
plUUID ageInstGuid = *GetAgeLink()->GetAgeInfo()->GetAgeInstanceGuid(); accInfo.SetAgeInstName(info->GetAgeInstanceName());
StrToUnicode(ageInstName, info->GetAgeInstanceName(), arrsize(ageInstName)); accInfo.SetAgeInstUuid(*ageInstGuid);
accInfo.SetAgeInstName(ageInstName);
accInfo.SetAgeInstUuid(ageInstGuid);
accInfo.SetOnline(true); accInfo.SetOnline(true);
} }
#endif #endif

5
Sources/Plasma/PubUtilLib/plNetClientComm/plNetClientComm.cpp

@ -311,7 +311,7 @@ static void INetCliAuthSetPlayerRequestCallback (
s_needAvatarLoad = true; s_needAvatarLoad = true;
VaultDownload( VaultDownload(
L"SetActivePlayer", "SetActivePlayer",
s_player->playerInt, s_player->playerInt,
PlayerInitCallback, PlayerInitCallback,
param, param,
@ -367,7 +367,7 @@ static void INetCliAuthLoginSetPlayerRequestCallback (
} }
else { else {
VaultDownload( VaultDownload(
L"SetActivePlayer", "SetActivePlayer",
s_player->playerInt, s_player->playerInt,
LoginPlayerInitCallback, LoginPlayerInitCallback,
param, param,
@ -1120,7 +1120,6 @@ void NetCommSetActivePlayer (//--> plNetCommActivePlayerMsg
if (s_player) { if (s_player) {
if (hsRef<RelVaultNode> rvn = VaultGetPlayerInfoNode()) { if (hsRef<RelVaultNode> rvn = VaultGetPlayerInfoNode()) {
VaultPlayerInfoNode pInfo(rvn); VaultPlayerInfoNode pInfo(rvn);
pInfo.SetAgeInstName(nil);
pInfo.SetAgeInstUuid(kNilUuid); pInfo.SetAgeInstUuid(kNilUuid);
pInfo.SetOnline(false); pInfo.SetOnline(false);
NetCliAuthVaultNodeSave(rvn, nil, nil); NetCliAuthVaultNodeSave(rvn, nil, nil);

44
Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp

@ -49,6 +49,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#pragma hdrstop #pragma hdrstop
#include "pnEncryption/plChallengeHash.h" #include "pnEncryption/plChallengeHash.h"
#include "plVault/plVaultConstants.h"
namespace Ngl { namespace Auth { namespace Ngl { namespace Auth {
/***************************************************************************** /*****************************************************************************
@ -3950,7 +3951,7 @@ bool VaultFetchNodeTrans::Recv (
if (IS_NET_SUCCESS(reply.result)) { if (IS_NET_SUCCESS(reply.result)) {
m_node = new NetVaultNode; m_node = new NetVaultNode;
m_node->Read_LCS(reply.nodeBuffer, reply.nodeBytes, 0); m_node->Read(reply.nodeBuffer, reply.nodeBytes);
} }
m_result = reply.result; m_result = reply.result;
@ -3984,9 +3985,7 @@ bool VaultFindNodeTrans::Send () {
return false; return false;
ARRAY(uint8_t) buffer; ARRAY(uint8_t) buffer;
m_node->critsect.Enter(); m_node->Write(&buffer);
m_node->Write_LCS(&buffer, 0);
m_node->critsect.Leave();
const uintptr_t msg[] = { const uintptr_t msg[] = {
kCli2Auth_VaultNodeFind, kCli2Auth_VaultNodeFind,
@ -4054,7 +4053,7 @@ bool VaultCreateNodeTrans::Send () {
return false; return false;
ARRAY(uint8_t) buffer; ARRAY(uint8_t) buffer;
m_templateNode->Write_LCS(&buffer, 0); m_templateNode->Write(&buffer, 0);
const uintptr_t msg[] = { const uintptr_t msg[] = {
kCli2Auth_VaultNodeCreate, kCli2Auth_VaultNodeCreate,
@ -5608,43 +5607,34 @@ unsigned NetCliAuthVaultNodeSave (
FNetCliAuthVaultNodeSaveCallback callback, FNetCliAuthVaultNodeSaveCallback callback,
void * param void * param
) { ) {
ASSERTMSG(!(node->GetDirtyFlags() & NetVaultNode::kNodeType), "Node type may not be changed"); if (!node->IsDirty())
// 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())
return 0; return 0;
if (!node->GetNodeId()) if (!node->GetNodeId())
return 0; 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 // 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; ARRAY(uint8_t) buffer;
unsigned bytes = node->Write_LCS(&buffer, NetVaultNode::kRwDirtyOnly | NetVaultNode::kRwUpdateDirty); node->Write(&buffer, ioFlags);
VaultSaveNodeTrans * trans = new VaultSaveNodeTrans( VaultSaveNodeTrans * trans = new VaultSaveNodeTrans(
node->GetNodeId(), node->GetNodeId(),
node->revisionId, node->GetRevision(),
buffer.Count(), buffer.Count(),
buffer.Ptr(), buffer.Ptr(),
callback, callback,
param param
); );
NetTransSend(trans); NetTransSend(trans);
return bytes; return buffer.Count();
} }
//============================================================================ //============================================================================

2
Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.h

@ -383,7 +383,7 @@ void NetCliAuthFileRequest (
//============================================================================ //============================================================================
// Vault Operations // Vault Operations
//============================================================================ //============================================================================
struct NetVaultNode; class NetVaultNode;
struct NetVaultNodeRef; struct NetVaultNodeRef;
// VaultNodeChanged // VaultNodeChanged

2
Sources/Plasma/PubUtilLib/plStatGather/plAutoProfile.cpp

@ -382,7 +382,7 @@ bool plAutoProfileImp::MsgReceive(plMessage* msg)
if (ageBeginLoadingMsg) if (ageBeginLoadingMsg)
{ {
plgDispatch::Dispatch()->UnRegisterForExactType(plAgeBeginLoadingMsg::Index(), GetKey()); plgDispatch::Dispatch()->UnRegisterForExactType(plAgeBeginLoadingMsg::Index(), GetKey());
VaultAddChronicleEntryAndWait(L"InitialAvCursomizationsDone", 0, L"1"); VaultAddChronicleEntryAndWait("InitialAvCursomizationsDone", 0, "1");
return true; return true;
} }

4
Sources/Plasma/PubUtilLib/plVault/Pch.h

@ -62,7 +62,10 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
// 'Old' system is full of compiler warnings at /W4, so just hide them // 'Old' system is full of compiler warnings at /W4, so just hide them
#pragma warning(push, 0) #pragma warning(push, 0)
#include <algorithm> #include <algorithm>
#include <memory>
#include <sstream> #include <sstream>
#include <unordered_map>
#include "hsStringTokenizer.h" #include "hsStringTokenizer.h"
#include "hsGeometry3.h" #include "hsGeometry3.h"
#include "plSDL/plSDL.h" #include "plSDL/plSDL.h"
@ -77,6 +80,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "plGImage/plJPEG.h" #include "plGImage/plJPEG.h"
#include "plMessage/plVaultNotifyMsg.h" #include "plMessage/plVaultNotifyMsg.h"
#include "plNetClientComm/plNetClientComm.h" #include "plNetClientComm/plNetClientComm.h"
#include "plStatusLog/plStatusLog.h"
#define KI_CONSTANTS_ONLY #define KI_CONSTANTS_ONLY
#include "pfMessage/pfKIMsg.h" // for KI level constants =( #include "pfMessage/pfKIMsg.h" // for KI level constants =(

407
Sources/Plasma/PubUtilLib/plVault/plVaultClientApi.cpp

@ -74,17 +74,6 @@ struct INotifyAfterDownload : THashKeyVal<unsigned> {
{} {}
}; };
struct DeviceInbox : CHashKeyStr {
HASHLINK(DeviceInbox) link;
wchar_t inboxName[kMaxVaultNodeStringLength];
DeviceInbox (const wchar_t device[], const wchar_t inbox[])
: CHashKeyStr(device)
{
StrCopy(inboxName, inbox, arrsize(inboxName));
}
};
// A RelVaultNodeLink may be either stored in the global table, // A RelVaultNodeLink may be either stored in the global table,
// or stored in an IRelVaultNode's parents or children table. // or stored in an IRelVaultNode's parents or children table.
struct RelVaultNodeLink : THashKeyVal<unsigned> { struct RelVaultNodeLink : THashKeyVal<unsigned> {
@ -184,7 +173,7 @@ struct VaultDownloadTrans {
FVaultProgressCallback progressCallback; FVaultProgressCallback progressCallback;
void * cbProgressParam; void * cbProgressParam;
wchar_t tag[MAX_PATH]; plString tag;
unsigned nodeCount; unsigned nodeCount;
unsigned nodesLeft; unsigned nodesLeft;
unsigned vaultId; unsigned vaultId;
@ -194,18 +183,15 @@ struct VaultDownloadTrans {
: callback(nil), cbParam(nil), progressCallback(nil), cbProgressParam(nil), : callback(nil), cbParam(nil), progressCallback(nil), cbProgressParam(nil),
nodeCount(0), nodesLeft(0), vaultId(0), result(kNetSuccess) nodeCount(0), nodesLeft(0), vaultId(0), result(kNetSuccess)
{ {
memset(tag, 0, sizeof(tag));
} }
VaultDownloadTrans (const wchar_t * _tag, FVaultDownloadCallback _callback, VaultDownloadTrans (const plString& _tag, FVaultDownloadCallback _callback,
void * _cbParam, FVaultProgressCallback _progressCallback, void * _cbParam, FVaultProgressCallback _progressCallback,
void * _cbProgressParam, unsigned _vaultId) void * _cbProgressParam, unsigned _vaultId)
: callback(_callback), cbParam(_cbParam), progressCallback(_progressCallback), : callback(_callback), cbParam(_cbParam), progressCallback(_progressCallback),
cbProgressParam(_cbProgressParam), nodeCount(0), nodesLeft(0), cbProgressParam(_cbProgressParam), nodeCount(0), nodesLeft(0),
vaultId(_vaultId), result(kNetSuccess) vaultId(_vaultId), result(kNetSuccess), tag(_tag)
{ {
wcsncpy(tag, _tag, arrsize(tag));
tag[arrsize(tag)-1] = 0;
} }
@ -293,11 +279,7 @@ static HASHTABLEDECL(
link link
) s_notifyAfterDownload; ) s_notifyAfterDownload;
static HASHTABLEDECL( static std::unordered_map<plString, plString, plString::hash> s_ageDeviceInboxes;
DeviceInbox,
CHashKeyStr,
link
) s_ageDeviceInboxes;
static bool s_processPlayerInbox = false; static bool s_processPlayerInbox = false;
@ -553,14 +535,14 @@ static void VaultNodeFetched (
// Add to global node table // Add to global node table
RelVaultNodeLink * link = s_nodes.Find(node->GetNodeId()); RelVaultNodeLink * link = s_nodes.Find(node->GetNodeId());
if (!link) { if (!link) {
link = new RelVaultNodeLink(false, 0, node->GetNodeId(), new RelVaultNode); link = new RelVaultNodeLink(false, 0, node->GetNodeId(), new RelVaultNode());
link->node->SetNodeId_NoDirty(node->GetNodeId()); link->node->SetNodeId_NoDirty(node->GetNodeId());
s_nodes.Add(link); s_nodes.Add(link);
} }
link->node->CopyFrom(node, NetVaultNode::kCopyOverwrite); link->node->CopyFrom(node);
InitFetchedNode(link->node); InitFetchedNode(link->node);
link->node->Print(L"Fetched", LogDumpProc, 0); link->node->Print("Fetched", 0);
} }
//============================================================================ //============================================================================
@ -602,7 +584,7 @@ static void VaultNodeChanged (
// We are the party responsible for the change, so we already have the // We are the party responsible for the change, so we already have the
// latest version of the node; no need to fetch it. // latest version of the node; no need to fetch it.
if (link->node->revisionId == revisionId) if (link->node->GetRevision() == revisionId)
return; return;
// We have the node and we weren't the one that changed it, so fetch it. // We have the node and we weren't the one that changed it, so fetch it.
@ -651,7 +633,7 @@ static void VaultNodeAdded (
continue; continue;
prevId = link->node->GetNodeId(); prevId = link->node->GetNodeId();
VaultDownload( VaultDownload(
L"NodeAdded", "NodeAdded",
nodeIds[i], nodeIds[i],
VaultNodeAddedDownloadCallback, VaultNodeAddedDownloadCallback,
(void*)nodeIds[i], (void*)nodeIds[i],
@ -726,15 +708,10 @@ static void SaveDirtyNodes () {
for (RelVaultNodeLink * link = s_nodes.Head(); link; link = s_nodes.Next(link)) { for (RelVaultNodeLink * link = s_nodes.Head(); link; link = s_nodes.Next(link)) {
if (bytesWritten >= kMaxBytesPerSaveUpdate) if (bytesWritten >= kMaxBytesPerSaveUpdate)
break; break;
if (link->node->GetDirtyFlags()) { if (link->node->IsDirty()) {
// Auth server needs the name of the sdl record
if (link->node->GetNodeType() == plVault::kNodeType_SDL)
link->node->SetDirtyFlags(VaultSDLNode::kSDLName);
if (unsigned bytes = NetCliAuthVaultNodeSave(link->node, nil, nil)) { if (unsigned bytes = NetCliAuthVaultNodeSave(link->node, nil, nil)) {
bytesWritten += bytes; bytesWritten += bytes;
link->node->Print(L"Saving", LogDumpProc, 0); link->node->Print("Saving", 0);
} }
} }
} }
@ -882,7 +859,7 @@ void VaultDownloadTrans::VaultNodeFetched (
} }
if (!trans->nodesLeft) { if (!trans->nodesLeft) {
VaultDump(trans->tag, trans->vaultId, LogDumpProc); VaultDump(trans->tag, trans->vaultId);
if (trans->callback) if (trans->callback)
trans->callback( trans->callback(
@ -1389,93 +1366,12 @@ void RelVaultNode::SetSeen (unsigned parentId, bool seen) {
} }
//============================================================================ //============================================================================
template <typename T> void RelVaultNode::Print (const plString& tag, unsigned level) {
static bool IStrSqlEscape (const T src[], T * dst, unsigned dstChars) { plStringStream ss;
// count the number of ' chars ss << tag;
unsigned ticks = 0; ss << plString::Fill(level * 2, ' ');
{ ss << " " << GetNodeId();
const T * cur = src; ss << " " << plVault::NodeTypeStr(GetNodeType());
while (*cur) {
if (*cur == L'\'')
++ticks;
cur++;
}
}
unsigned reqChars = StrLen(src) + ticks + 1;
if (dstChars < reqChars)
// failure!
return false;
T * cur = dst;
// copy src to dst, escaping ' chars
while (*src) {
if (*src == L'\'') {
*cur++ = L'\'';
*cur++ = *src++;
continue;
}
*cur++ = *src++;
}
// null-terminate dst string
*cur = 0;
// success!
return true;
}
static void IGetStringFieldValue (
const wchar_t * value,
wchar_t * dst,
size_t dstChars
) {
wchar_t * tmp = (wchar_t*)malloc(sizeof(wchar_t) * dstChars);
IStrSqlEscape(value, tmp, dstChars);
swprintf(dst, dstChars, L"'%s'", tmp);
free(tmp);
}
static void IGetUuidFieldValue (
const plUUID & value,
wchar_t * dst,
size_t dstChars
) {
swprintf(dst, dstChars, L"hextoraw('%S')", value.AsString().c_str());
}
static void IGetUintFieldValue (
uint32_t value,
wchar_t * dst,
size_t dstChars
) {
swprintf(dst, dstChars, L"%u", value);
}
static void IGetIntFieldValue (
int32_t value,
wchar_t * dst,
size_t dstChars
) {
swprintf(dst, dstChars, L"%d", value);
}
void RelVaultNode::Print (const wchar_t tag[], FStateDump dumpProc, unsigned level) {
wchar_t str[1024];
StrPrintf(
str,
arrsize(str),
L"%s%*s%*s%u, %S",
tag ? tag : L"",
tag ? 1 : 0,
" ",
level * 2,
" ",
GetNodeId(),
plVault::NodeTypeStr(GetNodeType(), false)
);
for (uint64_t bit = 1; bit; bit <<= 1) { for (uint64_t bit = 1; bit; bit <<= 1) {
if (!(GetFieldFlags() & bit)) if (!(GetFieldFlags() & bit))
@ -1483,60 +1379,66 @@ void RelVaultNode::Print (const wchar_t tag[], FStateDump dumpProc, unsigned lev
if (bit > GetFieldFlags()) if (bit > GetFieldFlags())
break; break;
#define STPRINT(flag, func) case k##flag: { \ #define STPRINT(flag) \
wcsncat(str, L", " L ## #flag L"=", arrsize(str)); \ case k##flag: \
const size_t chars = wcslen(str); \ ss << ", " #flag "=\"" << Get##flag() << "\""; \
func(Get##flag(), str + chars, arrsize(str) - chars * sizeof(str[0])); \ break;
}; break #define STPRINT_ESCAPE(flag) \
#define STNAME(flag) case k##flag: { \ case k##flag: \
wcsncat(str, L", " L ## #flag, arrsize(str)); \ ss << ", " #flag "=\"" << Get##flag().Replace("\"", "\\\"") << "\""; \
}; break break;
#define STNAME(flag) \
case k##flag: \
ss << ", " << #flag; \
break;
switch (bit) { switch (bit) {
STPRINT(NodeId, IGetUintFieldValue); STPRINT(NodeId);
STPRINT(CreateTime, IGetUintFieldValue); STPRINT(CreateTime);
STPRINT(ModifyTime, IGetUintFieldValue); STPRINT(ModifyTime);
STPRINT(CreateAgeName, IGetStringFieldValue); STPRINT(CreateAgeName);
STPRINT(CreateAgeUuid, IGetUuidFieldValue); STPRINT(CreateAgeUuid);
STPRINT(CreatorAcct, IGetUuidFieldValue); STPRINT(CreatorAcct);
STPRINT(CreatorId, IGetUintFieldValue); STPRINT(CreatorId);
STPRINT(NodeType, IGetUintFieldValue); STPRINT(NodeType);
STPRINT(Int32_1, IGetIntFieldValue); STPRINT(Int32_1);
STPRINT(Int32_2, IGetIntFieldValue); STPRINT(Int32_2);
STPRINT(Int32_3, IGetIntFieldValue); STPRINT(Int32_3);
STPRINT(Int32_4, IGetIntFieldValue); STPRINT(Int32_4);
STPRINT(UInt32_1, IGetUintFieldValue); STPRINT(UInt32_1);
STPRINT(UInt32_2, IGetUintFieldValue); STPRINT(UInt32_2);
STPRINT(UInt32_3, IGetUintFieldValue); STPRINT(UInt32_3);
STPRINT(UInt32_4, IGetUintFieldValue); STPRINT(UInt32_4);
STPRINT(Uuid_1, IGetUuidFieldValue); STPRINT(Uuid_1);
STPRINT(Uuid_2, IGetUuidFieldValue); STPRINT(Uuid_2);
STPRINT(Uuid_3, IGetUuidFieldValue); STPRINT(Uuid_3);
STPRINT(Uuid_4, IGetUuidFieldValue); STPRINT(Uuid_4);
STPRINT(String64_1, IGetStringFieldValue); STPRINT_ESCAPE(String64_1);
STPRINT(String64_2, IGetStringFieldValue); STPRINT_ESCAPE(String64_2);
STPRINT(String64_3, IGetStringFieldValue); STPRINT_ESCAPE(String64_3);
STPRINT(String64_4, IGetStringFieldValue); STPRINT_ESCAPE(String64_4);
STPRINT(String64_5, IGetStringFieldValue); STPRINT_ESCAPE(String64_5);
STPRINT(String64_6, IGetStringFieldValue); STPRINT_ESCAPE(String64_6);
STPRINT(IString64_1, IGetStringFieldValue); STPRINT_ESCAPE(IString64_1);
STPRINT(IString64_2, IGetStringFieldValue); STPRINT_ESCAPE(IString64_2);
STNAME(Text_1); STNAME(Text_1);
STNAME(Text_2); STNAME(Text_2);
STNAME(Blob_1); STNAME(Blob_1);
STNAME(Blob_2); STNAME(Blob_2);
DEFAULT_FATAL(bit); DEFAULT_FATAL(bit);
} }
#undef STPRINT #undef STPRINT
#undef STNAME
} }
dumpProc(nil, str); plStatusLog::AddLineS("VaultClient.log", ss.GetString().c_str());
} }
//============================================================================ //============================================================================
void RelVaultNode::PrintTree (FStateDump dumpProc, unsigned level) { void RelVaultNode::PrintTree (unsigned level) {
Print(L"", dumpProc, level); Print("", level);
for (RelVaultNodeLink * link = state->children.Head(); link; link = state->children.Next(link)) for (RelVaultNodeLink * link = state->children.Head(); link; link = state->children.Next(link))
link->node->PrintTree(dumpProc, level + 1); link->node->PrintTree(level + 1);
} }
//============================================================================ //============================================================================
@ -1875,18 +1777,18 @@ void VaultDeleteNode (
//============================================================================ //============================================================================
void VaultPublishNode ( void VaultPublishNode (
unsigned nodeId, unsigned nodeId,
const wchar_t deviceName[] const plString& deviceName
) { ) {
hsRef<RelVaultNode> rvn; hsRef<RelVaultNode> rvn;
rvn = VaultAgeGetDeviceInbox(deviceName); rvn = VaultAgeGetDeviceInbox(deviceName);
if (!rvn) { if (!rvn) {
LogMsg(kLogDebug, L"Failed to find inbox for device %s, adding it on-the-fly", deviceName); LogMsg(kLogDebug, L"Failed to find inbox for device %S, adding it on-the-fly", deviceName.c_str());
VaultAgeSetDeviceInboxAndWait(deviceName, DEFAULT_DEVICE_INBOX); VaultAgeSetDeviceInboxAndWait(deviceName, DEFAULT_DEVICE_INBOX);
rvn = VaultAgeGetDeviceInbox(deviceName); rvn = VaultAgeGetDeviceInbox(deviceName);
if (!rvn) { if (!rvn) {
LogMsg(kLogDebug, L"Failed to add inbox to device %s on-the-fly", deviceName); LogMsg(kLogDebug, L"Failed to add inbox to device %S on-the-fly", deviceName.c_str());
return; return;
} }
} }
@ -1914,10 +1816,8 @@ void VaultCreateNode (
if (hsRef<RelVaultNode> age = VaultGetAgeNode()) { if (hsRef<RelVaultNode> age = VaultGetAgeNode()) {
VaultAgeNode access(age); VaultAgeNode access(age);
if (!(templateNode->GetFieldFlags() & NetVaultNode::kCreateAgeName)) templateNode->SetCreateAgeName(access.GetAgeName());
templateNode->SetCreateAgeName(access.GetAgeName()); templateNode->SetCreateAgeUuid(access.GetAgeInstanceGuid());
if (!(templateNode->GetFieldFlags() & NetVaultNode::kCreateAgeUuid))
templateNode->SetCreateAgeUuid(access.GetAgeInstanceGuid());
} }
NetCliAuthVaultNodeCreate( NetCliAuthVaultNodeCreate(
@ -2297,9 +2197,7 @@ bool VaultGetLinkToMyNeighborhood (plAgeLinkStruct * link) {
templateNode->SetNodeType(plVault::kNodeType_AgeInfo); templateNode->SetNodeType(plVault::kNodeType_AgeInfo);
VaultAgeInfoNode ageInfo(templateNode); VaultAgeInfoNode ageInfo(templateNode);
wchar_t str[MAX_PATH]; ageInfo.SetAgeFilename(kNeighborhoodAgeFilename);
StrToUnicode(str, kNeighborhoodAgeFilename, arrsize(str));
ageInfo.SetAgeFilename(str);
hsRef<RelVaultNode> node; hsRef<RelVaultNode> node;
if (node = rvnFldr->GetChildNode(templateNode, 2)) { if (node = rvnFldr->GetChildNode(templateNode, 2)) {
@ -2320,9 +2218,7 @@ bool VaultGetLinkToMyPersonalAge (plAgeLinkStruct * link) {
templateNode->SetNodeType(plVault::kNodeType_AgeInfo); templateNode->SetNodeType(plVault::kNodeType_AgeInfo);
VaultAgeInfoNode ageInfo(templateNode); VaultAgeInfoNode ageInfo(templateNode);
wchar_t str[MAX_PATH]; ageInfo.SetAgeFilename(kPersonalAgeFilename);
StrToUnicode(str, kPersonalAgeFilename, arrsize(str));
ageInfo.SetAgeFilename(str);
hsRef<RelVaultNode> node; hsRef<RelVaultNode> node;
if (node = rvnFldr->GetChildNode(templateNode, 2)) { if (node = rvnFldr->GetChildNode(templateNode, 2)) {
@ -2343,9 +2239,7 @@ bool VaultGetLinkToCity (plAgeLinkStruct * link) {
templateNode->SetNodeType(plVault::kNodeType_AgeInfo); templateNode->SetNodeType(plVault::kNodeType_AgeInfo);
VaultAgeInfoNode ageInfo(templateNode); VaultAgeInfoNode ageInfo(templateNode);
wchar_t str[MAX_PATH]; ageInfo.SetAgeFilename(kCityAgeFilename);
StrToUnicode(str, kCityAgeFilename, arrsize(str));
ageInfo.SetAgeFilename(str);
hsRef<RelVaultNode> node; hsRef<RelVaultNode> node;
if (node = rvnFldr->GetChildNode(templateNode, 2)) { if (node = rvnFldr->GetChildNode(templateNode, 2)) {
@ -2368,16 +2262,14 @@ hsRef<RelVaultNode> VaultGetOwnedAgeLink (const plAgeInfoStruct * info) {
VaultAgeInfoNode ageInfo(templateNode); VaultAgeInfoNode ageInfo(templateNode);
if (info->HasAgeFilename()) { if (info->HasAgeFilename()) {
wchar_t str[MAX_PATH]; ageInfo.SetAgeFilename(info->GetAgeFilename());
StrToUnicode(str, info->GetAgeFilename(), arrsize(str));
ageInfo.SetAgeFilename(str);
} }
if (info->HasAgeInstanceGuid()) { if (info->HasAgeInstanceGuid()) {
ageInfo.SetAgeInstanceGuid(*info->GetAgeInstanceGuid()); ageInfo.SetAgeInstanceGuid(*info->GetAgeInstanceGuid());
} }
if (hsRef<RelVaultNode> rvnInfo = rvnFldr->GetChildNode(templateNode, 2)) { if (hsRef<RelVaultNode> rvnInfo = rvnFldr->GetChildNode(templateNode, 2)) {
templateNode->ClearFieldFlags(); templateNode->Clear();
templateNode->SetNodeType(plVault::kNodeType_AgeLink); templateNode->SetNodeType(plVault::kNodeType_AgeLink);
rvnLink = rvnInfo->GetParentNode(templateNode, 1); rvnLink = rvnInfo->GetParentNode(templateNode, 1);
} }
@ -2390,7 +2282,6 @@ hsRef<RelVaultNode> VaultGetOwnedAgeLink (const plAgeInfoStruct * info) {
hsRef<RelVaultNode> VaultGetOwnedAgeInfo (const plAgeInfoStruct * info) { hsRef<RelVaultNode> VaultGetOwnedAgeInfo (const plAgeInfoStruct * info) {
hsRef<RelVaultNode> rvnInfo; hsRef<RelVaultNode> rvnInfo;
if (hsRef<RelVaultNode> rvnFldr = VaultGetAgesIOwnFolder()) { if (hsRef<RelVaultNode> rvnFldr = VaultGetAgesIOwnFolder()) {
hsRef<NetVaultNode> templateNode = new NetVaultNode; hsRef<NetVaultNode> templateNode = new NetVaultNode;
@ -2398,9 +2289,7 @@ hsRef<RelVaultNode> VaultGetOwnedAgeInfo (const plAgeInfoStruct * info) {
VaultAgeInfoNode ageInfo(templateNode); VaultAgeInfoNode ageInfo(templateNode);
if (info->HasAgeFilename()) { if (info->HasAgeFilename()) {
wchar_t str[MAX_PATH]; ageInfo.SetAgeFilename(info->GetAgeFilename());
StrToUnicode(str, info->GetAgeFilename(), arrsize(str));
ageInfo.SetAgeFilename(str);
} }
if (info->HasAgeInstanceGuid()) { if (info->HasAgeInstanceGuid()) {
ageInfo.SetAgeInstanceGuid(*info->GetAgeInstanceGuid()); ageInfo.SetAgeInstanceGuid(*info->GetAgeInstanceGuid());
@ -2408,7 +2297,6 @@ hsRef<RelVaultNode> VaultGetOwnedAgeInfo (const plAgeInfoStruct * info) {
rvnInfo = rvnFldr->GetChildNode(templateNode, 2); rvnInfo = rvnFldr->GetChildNode(templateNode, 2);
} }
return rvnInfo; return rvnInfo;
} }
@ -2488,16 +2376,14 @@ bool VaultSetAgePublicAndWait (NetVaultNode * ageInfoNode, bool publicOrNot) {
NetCliAuthSetAgePublic(ageInfoNode->GetNodeId(), publicOrNot); NetCliAuthSetAgePublic(ageInfoNode->GetNodeId(), publicOrNot);
VaultAgeInfoNode access(ageInfoNode); VaultAgeInfoNode access(ageInfoNode);
char ageName[MAX_PATH];
StrToAnsi(ageName, access.GetAgeFilename(), arrsize(ageName));
plVaultNotifyMsg * msg = new plVaultNotifyMsg; plVaultNotifyMsg * msg = new plVaultNotifyMsg;
if (publicOrNot) if (publicOrNot)
msg->SetType(plVaultNotifyMsg::kPublicAgeCreated); msg->SetType(plVaultNotifyMsg::kPublicAgeCreated);
else else
msg->SetType(plVaultNotifyMsg::kPublicAgeRemoved); msg->SetType(plVaultNotifyMsg::kPublicAgeRemoved);
msg->SetResultCode(true); msg->SetResultCode(true);
msg->GetArgs()->AddString(plNetCommon::VaultTaskArgs::kAgeFilename, ageName); msg->GetArgs()->AddString(plNetCommon::VaultTaskArgs::kAgeFilename, access.GetAgeFilename().c_str());
msg->Send(); msg->Send();
return true; return true;
} }
@ -2513,17 +2399,15 @@ hsRef<RelVaultNode> VaultGetVisitAgeLink (const plAgeInfoStruct * info) {
VaultAgeInfoNode ageInfo(templateNode); VaultAgeInfoNode ageInfo(templateNode);
if (info->HasAgeFilename()) { if (info->HasAgeFilename()) {
wchar_t str[MAX_PATH]; ageInfo.SetAgeFilename(info->GetAgeFilename());
StrToUnicode(str, info->GetAgeFilename(), arrsize(str));
ageInfo.SetAgeFilename(str);
} }
if (info->HasAgeInstanceGuid()) { if (info->HasAgeInstanceGuid()) {
ageInfo.SetAgeInstanceGuid(*info->GetAgeInstanceGuid()); ageInfo.SetAgeInstanceGuid(*info->GetAgeInstanceGuid());
} }
if (hsRef<RelVaultNode> rvnInfo = rvnFldr->GetChildNode(templateNode, 2)) { if (hsRef<RelVaultNode> rvnInfo = rvnFldr->GetChildNode(templateNode, 2)) {
templateNode->ClearFieldFlags(); templateNode->Clear();
templateNode->SetNodeType(plVault::kNodeType_AgeLink); templateNode->SetNodeType(plVault::kNodeType_AgeLink);
rvnLink = rvnInfo->GetParentNode(templateNode, 1); rvnLink = rvnInfo->GetParentNode(templateNode, 1);
} }
} }
@ -2539,7 +2423,6 @@ bool VaultGetVisitAgeLink (const plAgeInfoStruct * info, class plAgeLinkStruct *
VaultAgeLinkNode ageLink(rvn); VaultAgeLinkNode ageLink(rvn);
ageLink.CopyTo(link); ageLink.CopyTo(link);
return true; return true;
} }
@ -2688,7 +2571,7 @@ bool VaultRegisterOwnedAgeAndWait (const plAgeLinkStruct * link) {
memset(&param, 0, sizeof(param)); memset(&param, 0, sizeof(param));
VaultDownload( VaultDownload(
L"RegisterOwnedAge", "RegisterOwnedAge",
ageInfoId, ageInfoId,
_FetchVaultCallback, _FetchVaultCallback,
&param, &param,
@ -2870,7 +2753,7 @@ namespace _VaultRegisterOwnedAge {
p->fSpawn = (plSpawnPointInfo*)param; p->fSpawn = (plSpawnPointInfo*)param;
VaultDownload( VaultDownload(
L"RegisterOwnedAge", "RegisterOwnedAge",
ageInfoVaultId, ageInfoVaultId,
(FVaultDownloadCallback)_DownloadCallback, (FVaultDownloadCallback)_DownloadCallback,
p, p,
@ -3048,7 +2931,7 @@ bool VaultRegisterVisitAgeAndWait (const plAgeLinkStruct * link) {
memset(&param, 0, sizeof(param)); memset(&param, 0, sizeof(param));
VaultDownload( VaultDownload(
L"RegisterVisitAge", "RegisterVisitAge",
ageInfoId, ageInfoId,
_FetchVaultCallback, _FetchVaultCallback,
&param, &param,
@ -3222,7 +3105,7 @@ namespace _VaultRegisterVisitAge {
_Params* p = (_Params*)param; _Params* p = (_Params*)param;
p->fAgeInfoId = (void*)ageInfoId; p->fAgeInfoId = (void*)ageInfoId;
VaultDownload(L"RegisterVisitAge", VaultDownload("RegisterVisitAge",
ageInfoId, ageInfoId,
(FVaultDownloadCallback)_DownloadCallback, (FVaultDownloadCallback)_DownloadCallback,
param, param,
@ -3365,7 +3248,7 @@ bool VaultUnregisterVisitAgeAndWait (const plAgeInfoStruct * info) {
} }
//============================================================================ //============================================================================
hsRef<RelVaultNode> VaultFindChronicleEntry (const wchar_t entryName[], int entryType) { hsRef<RelVaultNode> VaultFindChronicleEntry (const plString& entryName, int entryType) {
hsRef<RelVaultNode> result; hsRef<RelVaultNode> result;
if (hsRef<RelVaultNode> rvnFldr = GetChildFolderNode(GetPlayerNode(), plVault::kChronicleFolder, 1)) { if (hsRef<RelVaultNode> rvnFldr = GetChildFolderNode(GetPlayerNode(), plVault::kChronicleFolder, 1)) {
@ -3382,7 +3265,7 @@ hsRef<RelVaultNode> VaultFindChronicleEntry (const wchar_t entryName[], int entr
} }
//============================================================================ //============================================================================
bool VaultHasChronicleEntry (const wchar_t entryName[], int entryType) { bool VaultHasChronicleEntry (const plString& entryName, int entryType) {
if (VaultFindChronicleEntry(entryName, entryType)) if (VaultFindChronicleEntry(entryName, entryType))
return true; return true;
return false; return false;
@ -3390,9 +3273,9 @@ bool VaultHasChronicleEntry (const wchar_t entryName[], int entryType) {
//============================================================================ //============================================================================
void VaultAddChronicleEntryAndWait ( void VaultAddChronicleEntryAndWait (
const wchar_t entryName[], const plString& entryName,
int entryType, int entryType,
const wchar_t entryValue[] const plString& entryValue
) { ) {
if (hsRef<RelVaultNode> rvnChrn = VaultFindChronicleEntry(entryName, entryType)) { if (hsRef<RelVaultNode> rvnChrn = VaultFindChronicleEntry(entryName, entryType)) {
VaultChronicleNode chrnNode(rvnChrn); VaultChronicleNode chrnNode(rvnChrn);
@ -3458,18 +3341,13 @@ bool VaultSetCCRStatus (bool online) {
} }
//============================================================================ //============================================================================
void VaultDump (const wchar_t tag[], unsigned vaultId, FStateDump dumpProc) { void VaultDump (const plString& tag, unsigned vaultId) {
LogMsg(kLogDebug, L"<---- ID:%u, Begin Vault%*s%s ---->", vaultId, tag ? 1 : 0, L" ", tag); plStatusLog::AddLineS("VaultClient.log", plFormat("<---- ID:{}, Begin Vault {} ---->", vaultId, tag).c_str());
if (hsRef<RelVaultNode> rvn = VaultGetNode(vaultId)) if (hsRef<RelVaultNode> rvn = VaultGetNode(vaultId))
rvn->PrintTree(dumpProc, 0); rvn->PrintTree(0);
LogMsg(kLogDebug, L"<---- ID:%u, End Vault%*s%s ---->", vaultId, tag ? 1 : 0, L" ", tag);
}
//============================================================================ plStatusLog::AddLineS("VaultClient.log", plFormat("<---- ID:{}, End Vault {} ---->", vaultId, tag).c_str());
void VaultDump (const wchar_t tag[], unsigned vaultId) {
VaultDump (tag, vaultId, LogDumpProc);
} }
//============================================================================ //============================================================================
@ -3526,7 +3404,7 @@ bool VaultAmOwnerOfCurrentAge () {
VaultAgeInfoNode curAgeInfo(currentAgeInfoNode); VaultAgeInfoNode curAgeInfo(currentAgeInfoNode);
plAgeInfoStruct info; plAgeInfoStruct info;
info.SetAgeFilename(plString::FromWchar(curAgeInfo.GetAgeFilename())); info.SetAgeFilename(curAgeInfo.GetAgeFilename());
if (hsRef<RelVaultNode> rvnLink = VaultGetOwnedAgeLink(&info)) { if (hsRef<RelVaultNode> rvnLink = VaultGetOwnedAgeLink(&info)) {
@ -3778,13 +3656,11 @@ hsRef<RelVaultNode> VaultFindAgeSubAgeLink (const plAgeInfoStruct * info) {
templateNode->SetNodeType(plVault::kNodeType_AgeInfo); templateNode->SetNodeType(plVault::kNodeType_AgeInfo);
VaultAgeInfoNode ageInfo(templateNode); VaultAgeInfoNode ageInfo(templateNode);
wchar_t str[MAX_PATH]; ageInfo.SetAgeFilename(info->GetAgeFilename());
StrToUnicode(str, info->GetAgeFilename(), arrsize(str));
ageInfo.SetAgeFilename(str);
if (hsRef<RelVaultNode> rvnInfo = rvnFldr->GetChildNode(templateNode, 2)) { if (hsRef<RelVaultNode> rvnInfo = rvnFldr->GetChildNode(templateNode, 2)) {
templateNode->ClearFieldFlags(); templateNode->Clear();
templateNode->SetNodeType(plVault::kNodeType_AgeLink); templateNode->SetNodeType(plVault::kNodeType_AgeLink);
rvnLink = rvnInfo->GetParentNode(templateNode, 1); rvnLink = rvnInfo->GetParentNode(templateNode, 1);
} }
} }
@ -3808,7 +3684,7 @@ void VaultAddAgeChronicleEntry (
} }
//============================================================================ //============================================================================
hsRef<RelVaultNode> VaultAgeAddDeviceAndWait (const wchar_t deviceName[]) { hsRef<RelVaultNode> VaultAgeAddDeviceAndWait (const plString& deviceName) {
if (hsRef<RelVaultNode> existing = VaultAgeGetDevice(deviceName)) if (hsRef<RelVaultNode> existing = VaultAgeGetDevice(deviceName))
return existing; return existing;
@ -3836,7 +3712,7 @@ hsRef<RelVaultNode> VaultAgeAddDeviceAndWait (const wchar_t deviceName[]) {
} }
//============================================================================ //============================================================================
void VaultAgeRemoveDevice (const wchar_t deviceName[]) { void VaultAgeRemoveDevice (const plString& deviceName) {
if (hsRef<RelVaultNode> folder = VaultGetAgeDevicesFolder()) { if (hsRef<RelVaultNode> folder = VaultGetAgeDevicesFolder()) {
hsRef<NetVaultNode> templateNode = new NetVaultNode; hsRef<NetVaultNode> templateNode = new NetVaultNode;
templateNode->SetNodeType(plVault::kNodeType_TextNote); templateNode->SetNodeType(plVault::kNodeType_TextNote);
@ -3845,14 +3721,15 @@ void VaultAgeRemoveDevice (const wchar_t deviceName[]) {
if (hsRef<RelVaultNode> device = folder->GetChildNode(templateNode, 1)) { if (hsRef<RelVaultNode> device = folder->GetChildNode(templateNode, 1)) {
VaultRemoveChildNode(folder->GetNodeId(), device->GetNodeId(), nil, nil); VaultRemoveChildNode(folder->GetNodeId(), device->GetNodeId(), nil, nil);
if (DeviceInbox * deviceInbox = s_ageDeviceInboxes.Find(CHashKeyStr(deviceName))) auto it = s_ageDeviceInboxes.find(deviceName);
delete device; if (it != s_ageDeviceInboxes.end())
s_ageDeviceInboxes.erase(it);
} }
} }
} }
//============================================================================ //============================================================================
bool VaultAgeHasDevice (const wchar_t deviceName[]) { bool VaultAgeHasDevice (const plString& deviceName) {
bool found = false; bool found = false;
if (hsRef<RelVaultNode> folder = VaultGetAgeDevicesFolder()) { if (hsRef<RelVaultNode> folder = VaultGetAgeDevicesFolder()) {
hsRef<NetVaultNode> templateNode = new NetVaultNode; hsRef<NetVaultNode> templateNode = new NetVaultNode;
@ -3866,7 +3743,7 @@ bool VaultAgeHasDevice (const wchar_t deviceName[]) {
} }
//============================================================================ //============================================================================
hsRef<RelVaultNode> VaultAgeGetDevice (const wchar_t deviceName[]) { hsRef<RelVaultNode> VaultAgeGetDevice (const plString& deviceName) {
hsRef<RelVaultNode> result; hsRef<RelVaultNode> result;
if (hsRef<RelVaultNode> folder = VaultGetAgeDevicesFolder()) { if (hsRef<RelVaultNode> folder = VaultGetAgeDevicesFolder()) {
hsRef<NetVaultNode> templateNode = new NetVaultNode; hsRef<NetVaultNode> templateNode = new NetVaultNode;
@ -3880,24 +3757,17 @@ hsRef<RelVaultNode> VaultAgeGetDevice (const wchar_t deviceName[]) {
} }
//============================================================================ //============================================================================
hsRef<RelVaultNode> VaultAgeSetDeviceInboxAndWait (const wchar_t deviceName[], const wchar_t inboxName[]) { hsRef<RelVaultNode> VaultAgeSetDeviceInboxAndWait (const plString& deviceName, const plString& inboxName) {
DeviceInbox * devInbox = s_ageDeviceInboxes.Find(CHashKeyStr(deviceName)); s_ageDeviceInboxes[deviceName] = inboxName;
if (devInbox) {
StrCopy(devInbox->inboxName, inboxName, arrsize(devInbox->inboxName));
}
else {
devInbox = new DeviceInbox(deviceName, inboxName);
s_ageDeviceInboxes.Add(devInbox);
}
// if we found the inbox or its a global inbox then return here, otherwise if its the default inbox and // if we found the inbox or its a global inbox then return here, otherwise if its the default inbox and
// it wasn't found then continue on and create the inbox // it wasn't found then continue on and create the inbox
hsRef<RelVaultNode> existing = VaultAgeGetDeviceInbox(deviceName); hsRef<RelVaultNode> existing = VaultAgeGetDeviceInbox(deviceName);
if (existing || StrCmp(inboxName, DEFAULT_DEVICE_INBOX) != 0) if (existing || inboxName == DEFAULT_DEVICE_INBOX)
return existing; return existing;
hsRef<RelVaultNode> device, inbox; hsRef<RelVaultNode> device, inbox;
for (;;) { for (;;) {
device = VaultAgeGetDevice(deviceName); device = VaultAgeGetDevice(deviceName);
if (!device) if (!device)
@ -3911,7 +3781,7 @@ hsRef<RelVaultNode> VaultAgeSetDeviceInboxAndWait (const wchar_t deviceName[], c
VaultFolderNode access(inbox); VaultFolderNode access(inbox);
access.SetFolderName(inboxName); access.SetFolderName(inboxName);
access.SetFolderType(plVault::kDeviceInboxFolder); access.SetFolderType(plVault::kDeviceInboxFolder);
VaultAddChildNodeAndWait(device->GetNodeId(), inbox->GetNodeId(), 0); VaultAddChildNodeAndWait(device->GetNodeId(), inbox->GetNodeId(), 0);
break; break;
} }
@ -3920,28 +3790,26 @@ hsRef<RelVaultNode> VaultAgeSetDeviceInboxAndWait (const wchar_t deviceName[], c
} }
//============================================================================ //============================================================================
hsRef<RelVaultNode> VaultAgeGetDeviceInbox (const wchar_t deviceName[]) { hsRef<RelVaultNode> VaultAgeGetDeviceInbox (const plString& deviceName) {
hsRef<RelVaultNode> result; hsRef<RelVaultNode> result;
DeviceInbox * devInbox = s_ageDeviceInboxes.Find(CHashKeyStr(deviceName)); auto it = s_ageDeviceInboxes.find(deviceName);
if (devInbox) if (it != s_ageDeviceInboxes.end()) {
{
hsRef<RelVaultNode> parentNode; hsRef<RelVaultNode> parentNode;
const wchar_t * inboxName = nil; const wchar_t * inboxName = nil;
if (StrCmp(devInbox->inboxName, DEFAULT_DEVICE_INBOX) == 0) { //if (StrCmp(devInbox->inboxName, DEFAULT_DEVICE_INBOX) == 0) {
if (it->second == DEFAULT_DEVICE_INBOX)
parentNode = VaultAgeGetDevice(deviceName); parentNode = VaultAgeGetDevice(deviceName);
} else
else {
parentNode = VaultGetGlobalInbox(); parentNode = VaultGetGlobalInbox();
}
if (parentNode) { if (parentNode) {
hsRef<NetVaultNode> templateNode = new NetVaultNode; hsRef<NetVaultNode> templateNode = new NetVaultNode;
templateNode->SetNodeType(plVault::kNodeType_Folder); templateNode->SetNodeType(plVault::kNodeType_Folder);
VaultFolderNode access(templateNode); VaultFolderNode access(templateNode);
access.SetFolderType(plVault::kDeviceInboxFolder); access.SetFolderType(plVault::kDeviceInboxFolder);
access.SetFolderName(devInbox->inboxName); access.SetFolderName(it->second);
result = parentNode->GetChildNode(templateNode, 1); result = parentNode->GetChildNode(templateNode, 1);
} }
} }
@ -3950,9 +3818,7 @@ hsRef<RelVaultNode> VaultAgeGetDeviceInbox (const wchar_t deviceName[]) {
//============================================================================ //============================================================================
void VaultClearDeviceInboxMap () { void VaultClearDeviceInboxMap () {
while (DeviceInbox * inbox = s_ageDeviceInboxes.Head()) { s_ageDeviceInboxes.clear();
delete inbox;
}
} }
//============================================================================ //============================================================================
@ -3998,13 +3864,11 @@ hsRef<RelVaultNode> VaultGetSubAgeLink (const plAgeInfoStruct * info) {
templateNode->SetNodeType(plVault::kNodeType_AgeInfo); templateNode->SetNodeType(plVault::kNodeType_AgeInfo);
VaultAgeInfoNode ageInfo(templateNode); VaultAgeInfoNode ageInfo(templateNode);
wchar_t str[MAX_PATH]; ageInfo.SetAgeFilename(info->GetAgeFilename());
StrToUnicode(str, info->GetAgeFilename(), arrsize(str));
ageInfo.SetAgeFilename(str);
if (hsRef<RelVaultNode> rvnInfo = rvnFldr->GetChildNode(templateNode, 2)) { if (hsRef<RelVaultNode> rvnInfo = rvnFldr->GetChildNode(templateNode, 2)) {
templateNode->ClearFieldFlags(); templateNode->Clear();
templateNode->SetNodeType(plVault::kNodeType_AgeLink); templateNode->SetNodeType(plVault::kNodeType_AgeLink);
rvnLink = rvnInfo->GetParentNode(templateNode, 1); rvnLink = rvnInfo->GetParentNode(templateNode, 1);
} }
} }
@ -4175,7 +4039,7 @@ bool VaultAgeFindOrCreateSubAgeLinkAndWait (
memset(&param, 0, sizeof(param)); memset(&param, 0, sizeof(param));
VaultDownload( VaultDownload(
L"CreateSubAge", "CreateSubAge",
ageInfoId, ageInfoId,
_FetchVaultCallback, _FetchVaultCallback,
&param, &param,
@ -4292,7 +4156,7 @@ namespace _VaultCreateSubAge {
} }
// Download age vault // Download age vault
VaultDownload(L"CreateSubAge", VaultDownload("CreateSubAge",
ageInfoId, ageInfoId,
(FVaultDownloadCallback)_DownloadCallback, (FVaultDownloadCallback)_DownloadCallback,
(void*)ageInfoId, (void*)ageInfoId,
@ -4438,13 +4302,11 @@ bool VaultAgeFindOrCreateChildAgeLinkAndWait (
templateNode->SetNodeType(plVault::kNodeType_AgeInfo); templateNode->SetNodeType(plVault::kNodeType_AgeInfo);
VaultAgeInfoNode ageInfo(templateNode); VaultAgeInfoNode ageInfo(templateNode);
wchar_t str[MAX_PATH]; ageInfo.SetAgeFilename(info->GetAgeFilename());
StrToUnicode(str, info->GetAgeFilename(), arrsize(str));
ageInfo.SetAgeFilename(str);
if (hsRef<RelVaultNode> rvnInfo = rvnChildAges->GetChildNode(templateNode, 2)) { if (hsRef<RelVaultNode> rvnInfo = rvnChildAges->GetChildNode(templateNode, 2)) {
templateNode->ClearFieldFlags(); templateNode->Clear();
templateNode->SetNodeType(plVault::kNodeType_AgeLink); templateNode->SetNodeType(plVault::kNodeType_AgeLink);
rvnLink = rvnInfo->GetParentNode(templateNode, 1); rvnLink = rvnInfo->GetParentNode(templateNode, 1);
} }
@ -4517,7 +4379,7 @@ bool VaultAgeFindOrCreateChildAgeLinkAndWait (
memset(&param, 0, sizeof(param)); memset(&param, 0, sizeof(param));
VaultDownload( VaultDownload(
L"CreateChildAge", "CreateChildAge",
ageInfoId, ageInfoId,
_FetchVaultCallback, _FetchVaultCallback,
&param, &param,
@ -4646,7 +4508,7 @@ namespace _VaultCreateChildAge {
p->fAgeInfoId = (void*)ageInfoId; p->fAgeInfoId = (void*)ageInfoId;
// Download age vault // Download age vault
VaultDownload(L"CreateChildAge", VaultDownload("CreateChildAge",
ageInfoId, ageInfoId,
(FVaultDownloadCallback)_DownloadCallback, (FVaultDownloadCallback)_DownloadCallback,
param, param,
@ -4684,14 +4546,11 @@ uint8_t VaultAgeFindOrCreateChildAgeLink(
// Still here? Try to find the Child Ages folder // Still here? Try to find the Child Ages folder
uint8_t retval = hsFail; uint8_t retval = hsFail;
if (hsRef<RelVaultNode> rvnChildAges = rvnParentInfo->GetChildAgeInfoListNode(plVault::kChildAgesFolder, 1)) { if (hsRef<RelVaultNode> rvnChildAges = rvnParentInfo->GetChildAgeInfoListNode(plVault::kChildAgesFolder, 1)) {
wchar_t hack[MAX_PATH];
StrToUnicode(hack, info->GetAgeFilename(), arrsize(hack));
// Search for our age // Search for our age
hsRef<NetVaultNode> temp = new NetVaultNode; hsRef<NetVaultNode> temp = new NetVaultNode;
temp->SetNodeType(plVault::kNodeType_AgeInfo); temp->SetNodeType(plVault::kNodeType_AgeInfo);
VaultAgeInfoNode theAge(temp); VaultAgeInfoNode theAge(temp);
theAge.SetAgeFilename(hack); theAge.SetAgeFilename(info->GetAgeFilename());
if (hsRef<RelVaultNode> rvnAgeInfo = rvnChildAges->GetChildNode(temp, 2)) { if (hsRef<RelVaultNode> rvnAgeInfo = rvnChildAges->GetChildNode(temp, 2)) {
hsRef<RelVaultNode> rvnAgeLink = rvnAgeInfo->GetParentAgeLink(); hsRef<RelVaultNode> rvnAgeLink = rvnAgeInfo->GetParentAgeLink();
@ -4741,7 +4600,7 @@ void VaultCCRDumpPlayers() {
//============================================================================ //============================================================================
void VaultDownload ( void VaultDownload (
const wchar_t tag[], const plString& tag,
unsigned vaultId, unsigned vaultId,
FVaultDownloadCallback callback, FVaultDownloadCallback callback,
void * cbParam, void * cbParam,
@ -4773,7 +4632,7 @@ static void _DownloadVaultCallback (
} }
void VaultDownloadAndWait ( void VaultDownloadAndWait (
const wchar_t tag[], const plString& tag,
unsigned vaultId, unsigned vaultId,
FVaultProgressCallback progressCallback, FVaultProgressCallback progressCallback,
void * cbProgressParam void * cbProgressParam

37
Sources/Plasma/PubUtilLib/plVault/plVaultClientApi.h

@ -181,8 +181,8 @@ struct RelVaultNode : NetVaultNode {
void SetSeen (unsigned parentId, bool seen); void SetSeen (unsigned parentId, bool seen);
// logging // logging
void Print (const wchar_t tag[], FStateDump dumpProc, unsigned level); void Print (const plString& tag, unsigned level);
void PrintTree (FStateDump dumpProc, unsigned level); void PrintTree (unsigned level);
// AgeInfoNode-specific (and it checks!) // AgeInfoNode-specific (and it checks!)
hsRef<RelVaultNode> GetParentAgeLink (); hsRef<RelVaultNode> GetParentAgeLink ();
@ -246,7 +246,7 @@ void VaultDeleteNode (
); );
void VaultPublishNode ( void VaultPublishNode (
unsigned nodeId, unsigned nodeId,
const wchar_t deviceName[] const plString& deviceName
); );
void VaultSendNode ( void VaultSendNode (
RelVaultNode* srcNode, RelVaultNode* srcNode,
@ -354,20 +354,19 @@ bool VaultRegisterVisitAgeAndWait(const plAgeLinkStruct * link);
void VaultRegisterVisitAge(const plAgeLinkStruct* link); void VaultRegisterVisitAge(const plAgeLinkStruct* link);
bool VaultUnregisterOwnedAgeAndWait(const plAgeInfoStruct * info); bool VaultUnregisterOwnedAgeAndWait(const plAgeInfoStruct * info);
bool VaultUnregisterVisitAgeAndWait(const plAgeInfoStruct * info); bool VaultUnregisterVisitAgeAndWait(const plAgeInfoStruct * info);
hsRef<RelVaultNode> VaultFindChronicleEntry(const wchar_t entryName[], int entryType = -1); hsRef<RelVaultNode> VaultFindChronicleEntry(const plString& entryName, int entryType = -1);
bool VaultHasChronicleEntry(const wchar_t entryName[], int entryType = -1); bool VaultHasChronicleEntry(const plString& entryName, int entryType = -1);
// if entry of same name and type already exists, value is updated // if entry of same name and type already exists, value is updated
void VaultAddChronicleEntryAndWait ( void VaultAddChronicleEntryAndWait (
const wchar_t entryName[], const plString& entryName,
int entryType, int entryType,
const wchar_t entryValue[] const plString& entryValue
); );
bool VaultAmIgnoringPlayer (unsigned playerId); bool VaultAmIgnoringPlayer (unsigned playerId);
unsigned VaultGetKILevel (); unsigned VaultGetKILevel ();
bool VaultGetCCRStatus (); // true=online, false=away bool VaultGetCCRStatus (); // true=online, false=away
bool VaultSetCCRStatus (bool online); // true=online, false=away bool VaultSetCCRStatus (bool online); // true=online, false=away
void VaultDump (const wchar_t tag[], unsigned vaultId, FStateDump dumpProc); void VaultDump (const plString& tag, unsigned vaultId);
void VaultDump (const wchar_t tag[], unsigned vaultId);
bool VaultAmInMyPersonalAge (); bool VaultAmInMyPersonalAge ();
bool VaultAmInMyNeighborhoodAge (); bool VaultAmInMyNeighborhoodAge ();
@ -388,7 +387,7 @@ void VaultProcessPlayerInbox ();
* *
***/ ***/
#define DEFAULT_DEVICE_INBOX L"DevInbox" #define DEFAULT_DEVICE_INBOX "DevInbox"
hsRef<RelVaultNode> VaultGetAgeNode(); hsRef<RelVaultNode> VaultGetAgeNode();
hsRef<RelVaultNode> VaultGetAgeInfoNode(); hsRef<RelVaultNode> VaultGetAgeInfoNode();
@ -410,12 +409,12 @@ void VaultAddAgeChronicleEntry (
int entryType, int entryType,
const wchar_t entryValue[] const wchar_t entryValue[]
); );
hsRef<RelVaultNode> VaultAgeAddDeviceAndWait(const wchar_t deviceName[]); // blocks until completion hsRef<RelVaultNode> VaultAgeAddDeviceAndWait(const plString& deviceName); // blocks until completion
void VaultAgeRemoveDevice (const wchar_t deviceName[]); void VaultAgeRemoveDevice (const plString& deviceName);
bool VaultAgeHasDevice (const wchar_t deviceName[]); bool VaultAgeHasDevice (const plString& deviceName);
hsRef<RelVaultNode> VaultAgeGetDevice(const wchar_t deviceName[]); hsRef<RelVaultNode> VaultAgeGetDevice(const plString& deviceName);
hsRef<RelVaultNode> VaultAgeSetDeviceInboxAndWait(const wchar_t deviceName[], const wchar_t inboxName[]); // blocks until completion hsRef<RelVaultNode> VaultAgeSetDeviceInboxAndWait(const plString& deviceName, const plString& inboxName); // blocks until completion
hsRef<RelVaultNode> VaultAgeGetDeviceInbox(const wchar_t deviceName[]); hsRef<RelVaultNode> VaultAgeGetDeviceInbox(const plString& deviceName);
void VaultClearDeviceInboxMap (); void VaultClearDeviceInboxMap ();
bool VaultAgeGetAgeSDL (class plStateDataRecord * out); bool VaultAgeGetAgeSDL (class plStateDataRecord * out);
@ -470,7 +469,7 @@ typedef void (*FVaultProgressCallback)(
); );
void VaultDownload ( void VaultDownload (
const wchar_t tag[], const plString& tag,
unsigned vaultId, unsigned vaultId,
FVaultDownloadCallback callback, FVaultDownloadCallback callback,
void * cbParam, void * cbParam,
@ -478,7 +477,7 @@ void VaultDownload (
void * cbProgressParam void * cbProgressParam
); );
void VaultDownloadAndWait ( void VaultDownloadAndWait (
const wchar_t tag[], const plString& tag,
unsigned vaultId, unsigned vaultId,
FVaultProgressCallback progressCallback, FVaultProgressCallback progressCallback,
void * cbProgressParam void * cbProgressParam

271
Sources/Plasma/PubUtilLib/plVault/plVaultNodeAccess.cpp

@ -48,37 +48,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "Pch.h" #include "Pch.h"
#pragma hdrstop #pragma hdrstop
//============================================================================
// Volatile Vault Node Fields - be very careful when adding to this
//============================================================================
struct NodeTypeToVolatileField {
unsigned nodeType;
uint64_t volatileFields;
};
NodeTypeToVolatileField volatileFieldList[] = {
{plVault::kNodeType_PlayerInfo, VaultPlayerInfoNode::kOnline | VaultPlayerInfoNode::kAgeInstName | VaultPlayerInfoNode::kAgeInstUuid},
{0, 0}
};
//============================================================================
uint64_t GetNodeVolatileFields(NetVaultNode* node) {
uint64_t volatileFields = 0;
unsigned index = 0;
while (volatileFieldList[index].nodeType != 0) {
if (node->GetNodeType() == volatileFieldList[index].nodeType) {
volatileFields |= volatileFieldList[index].volatileFields;
break;
}
++index;
}
return volatileFields;
}
/***************************************************************************** /*****************************************************************************
* *
* VaultTextNoteNode * VaultTextNoteNode
@ -99,170 +68,66 @@ enum EAgeInfoFields {
#ifdef CLIENT #ifdef CLIENT
void VaultTextNoteNode::SetVisitInfo (const plAgeInfoStruct & info) { void VaultTextNoteNode::SetVisitInfo (const plAgeInfoStruct & info) {
plStringStream str;
ARRAY(wchar_t) buf;
for (unsigned i = 0; i < kNumAgeInfoFields; ++i) { for (unsigned i = 0; i < kNumAgeInfoFields; ++i) {
switch (i) { switch (i) {
case kAgeFilename: { case kAgeFilename:
wchar_t src[128]; str << info.GetAgeFilename();
StrToUnicode(src, info.GetAgeFilename(), arrsize(src));
unsigned len = StrLen(src);
wchar_t * dst = buf.New(len);
memcpy(dst, src, len * sizeof(src[0]));
}
break; break;
case kAgeInstName:
case kAgeInstName: { str << info.GetAgeInstanceName();
wchar_t src[128];
StrToUnicode(src, info.GetAgeInstanceName(), arrsize(src));
unsigned len = StrLen(src);
wchar_t * dst = buf.New(len);
memcpy(dst, src, len * sizeof(src[0]));
}
break; break;
case kAgeUserName:
case kAgeUserName: { str << info.GetAgeUserDefinedName();
wchar_t src[128];
StrToUnicode(src, info.GetAgeUserDefinedName(), arrsize(src));
unsigned len = StrLen(src);
wchar_t * dst = buf.New(len);
memcpy(dst, src, len * sizeof(src[0]));
}
break; break;
case kAgeDesc:
case kAgeDesc: { str << info.GetAgeDescription();
wchar_t src[128];
StrToUnicode(src, info.GetAgeDescription(), arrsize(src));
unsigned len = StrLen(src);
wchar_t * dst = buf.New(len);
memcpy(dst, src, len * sizeof(src[0]));
}
break; break;
case kAgeInstGuid:
case kAgeInstGuid: { str << info.GetAgeInstanceGuid()->AsString();
plUUID guid = *info.GetAgeInstanceGuid();
wchar_t src[64];
wcsncpy(src, guid.AsString().ToWchar(), 64);
unsigned len = StrLen(src);
wchar_t * dst = buf.New(len);
memcpy(dst, src, len * sizeof(src[0]));
}
break; break;
case kAgeLanguage:
case kAgeLanguage: { str << info.GetAgeLanguage();
wchar_t src[32];
StrPrintf(src, arrsize(src), L"%u", info.GetAgeLanguage());
unsigned len = StrLen(src);
wchar_t * dst = buf.New(len);
memcpy(dst, src, len * sizeof(src[0]));
}
break; break;
case kAgeSequence:
case kAgeSequence: { str << info.GetAgeSequenceNumber();
wchar_t src[32];
StrPrintf(src, arrsize(src), L"%u", info.GetAgeSequenceNumber());
unsigned len = StrLen(src);
wchar_t * dst = buf.New(len);
memcpy(dst, src, len * sizeof(src[0]));
}
break; break;
DEFAULT_FATAL(i); DEFAULT_FATAL(i);
} }
wchar_t * sep = buf.New(1); str << "|";
*sep = L'|';
} }
wchar_t * term = buf.New(1); SetNoteText(str.GetString());
*term = 0;
SetNoteText(buf.Ptr());
} }
#endif #endif
//============================================================================ //============================================================================
#ifdef CLIENT #ifdef CLIENT
bool VaultTextNoteNode::GetVisitInfo (plAgeInfoStruct * info) { bool VaultTextNoteNode::GetVisitInfo (plAgeInfoStruct * info) {
std::vector<plString> toks = GetNoteText().Split("|");
hsAssert(toks.size() == kNumAgeInfoFields, "visit text note malformed--discarding");
if (toks.size() != kNumAgeInfoFields)
return false;
wchar_t * mem; if (!toks[kAgeFilename].IsEmpty())
const wchar_t * str = mem = wcsdup(GetNoteText()); info->SetAgeFilename(toks[kAgeFilename]);
if (!toks[kAgeInstName].IsEmpty())
for (unsigned i = 0; i < kNumAgeInfoFields; ++i) { info->SetAgeInstanceName(toks[kAgeInstName]);
if (!toks[kAgeUserName].IsEmpty())
wchar_t token[1024]; info->SetAgeUserDefinedName(toks[kAgeUserName]);
switch (i) { if (!toks[kAgeDesc].IsEmpty())
case kAgeFilename: { info->SetAgeDescription(toks[kAgeDesc]);
StrTokenize(&str, token, arrsize(token), L"|", 1); if (!toks[kAgeInstGuid].IsEmpty()) {
if (StrLen(token) > 0) { std::unique_ptr<plUUID> guid = std::make_unique<plUUID>(toks[kAgeInstGuid]);
char ansi[1024]; info->SetAgeInstanceGuid(guid.get());
StrToAnsi(ansi, token, arrsize(ansi));
info->SetAgeFilename(ansi);
}
}
break;
case kAgeInstName: {
StrTokenize(&str, token, arrsize(token), L"|", 1);
if (StrLen(token) > 0) {
char ansi[1024];
StrToAnsi(ansi, token, arrsize(ansi));
info->SetAgeInstanceName(ansi);
}
}
break;
case kAgeUserName: {
StrTokenize(&str, token, arrsize(token), L"|", 1);
if (StrLen(token) > 0) {
char ansi[1024];
StrToAnsi(ansi, token, arrsize(ansi));
info->SetAgeUserDefinedName(ansi);
}
}
break;
case kAgeDesc: {
StrTokenize(&str, token, arrsize(token), L"|", 1);
if (StrLen(token) > 0) {
char ansi[1024];
StrToAnsi(ansi, token, arrsize(ansi));
info->SetAgeDescription(ansi);
}
}
break;
case kAgeInstGuid: {
StrTokenize(&str, token, arrsize(token), L"|", 1);
if (StrLen(token) > 0) {
plUUID uuid(plString::FromWchar(token));
info->SetAgeInstanceGuid(&uuid);
}
}
break;
case kAgeLanguage: {
StrTokenize(&str, token, arrsize(token), L"|", 1);
if (StrLen(token) > 0) {
info->SetAgeLanguage(StrToUnsigned(token, nil, 10));
}
}
break;
case kAgeSequence: {
StrTokenize(&str, token, arrsize(token), L"|", 1);
if (StrLen(token) > 0) {
info->SetAgeSequenceNumber(StrToUnsigned(token, nil, 10));
}
}
break;
DEFAULT_FATAL(i);
}
} }
if (!toks[kAgeLanguage].IsEmpty())
free(mem); info->SetAgeLanguage(toks[kAgeLanguage].ToUInt());
if (!toks[kAgeSequence].IsEmpty())
info->SetAgeSequenceNumber(toks[kAgeSequence].ToUInt());
return true; return true;
} }
#endif #endif
@ -327,7 +192,7 @@ void VaultSDLNode::SetStateDataRecord (const plStateDataRecord * rec, unsigned w
//============================================================================ //============================================================================
#ifdef CLIENT #ifdef CLIENT
void VaultSDLNode::InitStateDataRecord (const wchar_t sdlRecName[], unsigned writeOptions) { void VaultSDLNode::InitStateDataRecord (const plString& sdlRecName, unsigned writeOptions) {
{ {
plStateDataRecord * rec = new plStateDataRecord; plStateDataRecord * rec = new plStateDataRecord;
bool exists = GetStateDataRecord(rec, 0); bool exists = GetStateDataRecord(rec, 0);
@ -336,9 +201,7 @@ void VaultSDLNode::InitStateDataRecord (const wchar_t sdlRecName[], unsigned wri
return; return;
} }
char aStr[MAX_PATH]; if (plStateDescriptor * des = plSDLMgr::GetInstance()->FindDescriptor(sdlRecName, plSDL::kLatestVersion)) {
StrToAnsi(aStr, sdlRecName, arrsize(aStr));
if (plStateDescriptor * des = plSDLMgr::GetInstance()->FindDescriptor(aStr, plSDL::kLatestVersion)) {
plStateDataRecord rec(des); plStateDataRecord rec(des);
rec.SetFromDefaults(false); rec.SetFromDefaults(false);
SetStateDataRecord(&rec, writeOptions|plSDL::kDontWriteDirtyFlag); SetStateDataRecord(&rec, writeOptions|plSDL::kDontWriteDirtyFlag);
@ -555,44 +418,17 @@ const class plUnifiedTime * VaultAgeInfoNode::GetAgeTime () const {
//============================================================================ //============================================================================
#ifdef CLIENT #ifdef CLIENT
void VaultAgeInfoNode::CopyFrom (const plAgeInfoStruct * info) { void VaultAgeInfoNode::CopyFrom (const plAgeInfoStruct * info) {
wchar_t str[MAX_PATH];
// age filename // age filename
if (info->HasAgeFilename()) { SetAgeFilename(info->HasAgeFilename() ? info->GetAgeFilename() : "");
StrToUnicode(str, info->GetAgeFilename(), arrsize(str));
SetAgeFilename(str);
}
else {
SetAgeFilename(nil);
}
// age instance name // age instance name
if (info->HasAgeInstanceName()) { SetAgeInstanceName(info->HasAgeInstanceName() ? info->GetAgeInstanceName() : "");
StrToUnicode(str, info->GetAgeInstanceName(), arrsize(str));
SetAgeInstanceName(str);
}
else {
SetAgeInstanceName(nil);
}
// age user-defined name // age user-defined name
if (info->HasAgeUserDefinedName()) { SetAgeUserDefinedName(info->HasAgeUserDefinedName() ? info->GetAgeUserDefinedName() : "");
StrToUnicode(str, info->GetAgeUserDefinedName(), arrsize(str));
SetAgeUserDefinedName(str);
}
else {
SetAgeUserDefinedName(nil);
}
// age description // age description
// TODO SetAgeDescription(info->HasAgeDescription() ? info->GetAgeDescription() : "");
if (info->HasAgeDescription()) {
// StrToUnicode(str, info->GetAgeDescription(), arrsize(str));
// SetAgeDescription(str);
}
else {
// SetAgeDescription(nil);
}
// age sequence number // age sequence number
SetAgeSequenceNumber(info->GetAgeSequenceNumber()); SetAgeSequenceNumber(info->GetAgeSequenceNumber());
@ -608,22 +444,17 @@ void VaultAgeInfoNode::CopyFrom (const plAgeInfoStruct * info) {
//============================================================================ //============================================================================
#ifdef CLIENT #ifdef CLIENT
void VaultAgeInfoNode::CopyTo (plAgeInfoStruct * info) const { void VaultAgeInfoNode::CopyTo (plAgeInfoStruct * info) const {
char str[MAX_PATH];
// age filename // age filename
StrToAnsi(str, GetAgeFilename(), arrsize(str)); info->SetAgeFilename(GetAgeFilename());
info->SetAgeFilename(str);
// age instance name // age instance name
StrToAnsi(str, GetAgeInstanceName(), arrsize(str)); info->SetAgeInstanceName(GetAgeInstanceName());
info->SetAgeInstanceName(str);
// age user-defined name // age user-defined name
StrToAnsi(str, GetAgeUserDefinedName(), arrsize(str)); info->SetAgeUserDefinedName(GetAgeUserDefinedName());
info->SetAgeUserDefinedName(str);
// age description // age description
// TODO info->SetAgeDescription(GetAgeDescription());
// age sequence number // age sequence number
info->SetAgeSequenceNumber(GetAgeSequenceNumber()); info->SetAgeSequenceNumber(GetAgeSequenceNumber());

47
Sources/Plasma/PubUtilLib/plVault/plVaultNodeAccess.h

@ -64,11 +64,6 @@ struct plSpawnPointInfo;
typedef std::vector<plSpawnPointInfo> plSpawnPointVec; typedef std::vector<plSpawnPointInfo> plSpawnPointVec;
#endif #endif
//============================================================================
// Volatile Vault Node Fields
//============================================================================
uint64_t GetNodeVolatileFields(NetVaultNode* node);
//============================================================================ //============================================================================
// NetVaultNodeAccess // NetVaultNodeAccess
//============================================================================ //============================================================================
@ -83,22 +78,24 @@ private:
}; };
#define VNODE_ACCESSOR(type, name, basename) \ #define VNODE_ACCESSOR(type, name, basename) \
static const uint64_t k##name = NetVaultNode::k##basename; \
type Get##name () const { return base->Get##basename(); } \ type Get##name () const { return base->Get##basename(); } \
void Set##name (type v) { base->Set##basename(v); } void Set##name (type v) { base->Set##basename(v); }
#define VNODE_BLOB(name, basename) \ #define VNODE_BLOB(name, basename) \
static const uint64_t k##name = NetVaultNode::k##basename; \
const uint8_t * Get##name () const { return base->Get##basename(); } \ const uint8_t * Get##name () const { return base->Get##basename(); } \
size_t Get##name##Length () const { return base->Get##basename##Length(); } \ size_t Get##name##Length () const { return base->Get##basename##Length(); } \
void Set##name (const uint8_t data[], size_t length) { base->Set##basename(data, length); } void Set##name (const uint8_t data[], size_t length) { base->Set##basename(data, length); }
#define VNODE_STRING(name, basename) \
plString Get##name () const { return base->Get##basename(); } \
void Set##name (const plString& v) { base->Set##basename(v); }
//============================================================================ //============================================================================
// VaultPlayerNode // VaultPlayerNode
//============================================================================ //============================================================================
struct VaultPlayerNode : NetVaultNodeAccess { struct VaultPlayerNode : NetVaultNodeAccess {
VNODE_ACCESSOR(const wchar_t *, PlayerName, IString64_1); VNODE_STRING ( PlayerName, IString64_1);
VNODE_ACCESSOR(const wchar_t *, AvatarShapeName, String64_1); VNODE_STRING ( AvatarShapeName, String64_1);
VNODE_ACCESSOR(int32_t, Disabled, Int32_1); VNODE_ACCESSOR(int32_t, Disabled, Int32_1);
VNODE_ACCESSOR(int32_t, Explorer, Int32_2); // explorer = 1, visitor = 0 VNODE_ACCESSOR(int32_t, Explorer, Int32_2); // explorer = 1, visitor = 0
VNODE_ACCESSOR(uint32_t, OnlineTime, UInt32_1); VNODE_ACCESSOR(uint32_t, OnlineTime, UInt32_1);
@ -114,8 +111,8 @@ struct VaultPlayerNode : NetVaultNodeAccess {
//============================================================================ //============================================================================
struct VaultPlayerInfoNode : NetVaultNodeAccess { struct VaultPlayerInfoNode : NetVaultNodeAccess {
VNODE_ACCESSOR(uint32_t, PlayerId, UInt32_1); VNODE_ACCESSOR(uint32_t, PlayerId, UInt32_1);
VNODE_ACCESSOR(const wchar_t *, PlayerName, IString64_1); VNODE_STRING ( PlayerName, IString64_1);
VNODE_ACCESSOR(const wchar_t *, AgeInstName, String64_1); // name of age player is currently in VNODE_STRING ( AgeInstName, String64_1); // name of age player is currently in
VNODE_ACCESSOR(plUUID, AgeInstUuid, Uuid_1); // guid of age player is currently in VNODE_ACCESSOR(plUUID, AgeInstUuid, Uuid_1); // guid of age player is currently in
VNODE_ACCESSOR(int32_t, Online, Int32_1); // whether or not player is online VNODE_ACCESSOR(int32_t, Online, Int32_1); // whether or not player is online
VNODE_ACCESSOR(int32_t, CCRLevel, Int32_2); VNODE_ACCESSOR(int32_t, CCRLevel, Int32_2);
@ -129,7 +126,7 @@ struct VaultPlayerInfoNode : NetVaultNodeAccess {
//============================================================================ //============================================================================
struct VaultFolderNode : NetVaultNodeAccess { struct VaultFolderNode : NetVaultNodeAccess {
VNODE_ACCESSOR(int32_t, FolderType, Int32_1); VNODE_ACCESSOR(int32_t, FolderType, Int32_1);
VNODE_ACCESSOR(const wchar_t *, FolderName, String64_1); VNODE_STRING ( FolderName, String64_1);
VaultFolderNode (NetVaultNode * node) : NetVaultNodeAccess(node) { } VaultFolderNode (NetVaultNode * node) : NetVaultNodeAccess(node) { }
}; };
@ -154,8 +151,8 @@ struct VaultAgeInfoListNode : VaultFolderNode {
//============================================================================ //============================================================================
struct VaultChronicleNode : NetVaultNodeAccess { struct VaultChronicleNode : NetVaultNodeAccess {
VNODE_ACCESSOR(int32_t, EntryType, Int32_1); VNODE_ACCESSOR(int32_t, EntryType, Int32_1);
VNODE_ACCESSOR(const wchar_t *, EntryName, String64_1); VNODE_STRING ( EntryName, String64_1);
VNODE_ACCESSOR(const wchar_t *, EntryValue, Text_1); VNODE_STRING ( EntryValue, Text_1);
VaultChronicleNode (NetVaultNode * node) : NetVaultNodeAccess(node) { } VaultChronicleNode (NetVaultNode * node) : NetVaultNodeAccess(node) { }
}; };
@ -165,7 +162,7 @@ struct VaultChronicleNode : NetVaultNodeAccess {
// VaultSDLNode // VaultSDLNode
//============================================================================ //============================================================================
struct VaultSDLNode : NetVaultNodeAccess { struct VaultSDLNode : NetVaultNodeAccess {
VNODE_ACCESSOR(const wchar_t *, SDLName, String64_1); VNODE_STRING ( SDLName, String64_1);
VNODE_ACCESSOR(int32_t, SDLIdent, Int32_1); VNODE_ACCESSOR(int32_t, SDLIdent, Int32_1);
VNODE_BLOB ( SDLData, Blob_1); VNODE_BLOB ( SDLData, Blob_1);
@ -174,7 +171,7 @@ struct VaultSDLNode : NetVaultNodeAccess {
#ifdef CLIENT #ifdef CLIENT
bool GetStateDataRecord (class plStateDataRecord * out, unsigned readOptions = 0); bool GetStateDataRecord (class plStateDataRecord * out, unsigned readOptions = 0);
void SetStateDataRecord (const class plStateDataRecord * rec, unsigned writeOptions = 0); void SetStateDataRecord (const class plStateDataRecord * rec, unsigned writeOptions = 0);
void InitStateDataRecord (const wchar_t sdlRecName[], unsigned writeOptions = 0); void InitStateDataRecord (const plString& sdlRecName, unsigned writeOptions = 0);
#endif // def CLIENT #endif // def CLIENT
}; };
@ -206,7 +203,7 @@ struct VaultImageNode : NetVaultNodeAccess {
enum ImageTypes { kNone=0, kJPEG=1, kPNG=2 }; enum ImageTypes { kNone=0, kJPEG=1, kPNG=2 };
VNODE_ACCESSOR(int32_t, ImageType, Int32_1); VNODE_ACCESSOR(int32_t, ImageType, Int32_1);
VNODE_ACCESSOR(const wchar_t *, ImageTitle, String64_1); VNODE_STRING ( ImageTitle, String64_1);
VNODE_BLOB ( ImageData, Blob_1); VNODE_BLOB ( ImageData, Blob_1);
VaultImageNode (NetVaultNode * node) : NetVaultNodeAccess(node) { } VaultImageNode (NetVaultNode * node) : NetVaultNodeAccess(node) { }
@ -234,8 +231,8 @@ struct VaultCliImageNode : VaultImageNode {
struct VaultTextNoteNode : NetVaultNodeAccess { struct VaultTextNoteNode : NetVaultNodeAccess {
VNODE_ACCESSOR(int32_t, NoteType, Int32_1); VNODE_ACCESSOR(int32_t, NoteType, Int32_1);
VNODE_ACCESSOR(int32_t, NoteSubType, Int32_2); VNODE_ACCESSOR(int32_t, NoteSubType, Int32_2);
VNODE_ACCESSOR(const wchar_t *, NoteTitle, String64_1); VNODE_STRING ( NoteTitle, String64_1);
VNODE_ACCESSOR(const wchar_t *, NoteText, Text_1); VNODE_STRING ( NoteText, Text_1);
VaultTextNoteNode (NetVaultNode * node) : NetVaultNodeAccess(node) { } VaultTextNoteNode (NetVaultNode * node) : NetVaultNodeAccess(node) { }
@ -252,7 +249,7 @@ struct VaultTextNoteNode : NetVaultNodeAccess {
struct VaultAgeNode : NetVaultNodeAccess { struct VaultAgeNode : NetVaultNodeAccess {
VNODE_ACCESSOR(plUUID, AgeInstanceGuid, Uuid_1); VNODE_ACCESSOR(plUUID, AgeInstanceGuid, Uuid_1);
VNODE_ACCESSOR(plUUID, ParentAgeInstanceGuid, Uuid_2); VNODE_ACCESSOR(plUUID, ParentAgeInstanceGuid, Uuid_2);
VNODE_ACCESSOR(const wchar_t *, AgeName, String64_1); VNODE_STRING ( AgeName, String64_1);
VaultAgeNode (NetVaultNode * node) : NetVaultNodeAccess(node) { } VaultAgeNode (NetVaultNode * node) : NetVaultNodeAccess(node) { }
}; };
@ -261,12 +258,12 @@ struct VaultAgeNode : NetVaultNodeAccess {
// VaultAgeInfoNode // VaultAgeInfoNode
//============================================================================ //============================================================================
struct VaultAgeInfoNode : NetVaultNodeAccess { struct VaultAgeInfoNode : NetVaultNodeAccess {
VNODE_ACCESSOR(const wchar_t *, AgeFilename, String64_2); // "Garden" VNODE_STRING ( AgeFilename, String64_2); // "Garden"
VNODE_ACCESSOR(const wchar_t *, AgeInstanceName, String64_3); // "Eder Kemo" VNODE_STRING ( AgeInstanceName, String64_3); // "Eder Kemo"
VNODE_ACCESSOR(const wchar_t *, AgeUserDefinedName, String64_4); // "Joe's" VNODE_STRING ( AgeUserDefinedName, String64_4); // "Joe's"
VNODE_ACCESSOR(plUUID, AgeInstanceGuid, Uuid_1); // 6278b081-342a-4229-ac1b-a0b8a2658390 VNODE_ACCESSOR(plUUID, AgeInstanceGuid, Uuid_1); // 6278b081-342a-4229-ac1b-a0b8a2658390
VNODE_ACCESSOR(plUUID, ParentAgeInstanceGuid, Uuid_2); // 9192be7f-89ef-41bc-83db-79afe451e399 VNODE_ACCESSOR(plUUID, ParentAgeInstanceGuid, Uuid_2); // 9192be7f-89ef-41bc-83db-79afe451e399
VNODE_ACCESSOR(const wchar_t *, AgeDescription, Text_1); // "Stay out!" VNODE_STRING ( AgeDescription, Text_1); // "Stay out!"
VNODE_ACCESSOR(int32_t, AgeSequenceNumber, Int32_1); VNODE_ACCESSOR(int32_t, AgeSequenceNumber, Int32_1);
VNODE_ACCESSOR(int32_t, AgeLanguage, Int32_3); // The language of the client that made this age VNODE_ACCESSOR(int32_t, AgeLanguage, Int32_3); // The language of the client that made this age
VNODE_ACCESSOR(uint32_t, AgeId, UInt32_1); VNODE_ACCESSOR(uint32_t, AgeId, UInt32_1);
@ -299,7 +296,7 @@ struct VaultSystemNode : NetVaultNodeAccess {
// VaultMarkerGameNode // VaultMarkerGameNode
//============================================================================ //============================================================================
struct VaultMarkerGameNode : NetVaultNodeAccess { struct VaultMarkerGameNode : NetVaultNodeAccess {
VNODE_ACCESSOR(const wchar_t *, GameName, Text_1); VNODE_STRING ( GameName, Text_1);
VNODE_ACCESSOR(plUUID, GameGuid, Uuid_1); VNODE_ACCESSOR(plUUID, GameGuid, Uuid_1);
VaultMarkerGameNode (NetVaultNode * node) : NetVaultNodeAccess(node) { } VaultMarkerGameNode (NetVaultNode * node) : NetVaultNodeAccess(node) { }

Loading…
Cancel
Save