Browse Source

Async creation of subages (thanks to all the people whose Delins/Tsogals I randomly popped in on)

Adam Johnson 14 years ago
parent
commit
7a1c977ded
  1. 4
      Sources/Plasma/PubUtilLib/plMessage/plVaultNotifyMsg.h
  2. 43
      Sources/Plasma/PubUtilLib/plNetClient/plNetLinkingMgr.cpp
  3. 89
      Sources/Plasma/PubUtilLib/plVault/plVaultClientApi.cpp
  4. 2
      Sources/Plasma/PubUtilLib/plVault/plVaultClientApi.h

4
Sources/Plasma/PubUtilLib/plMessage/plVaultNotifyMsg.h

@ -45,7 +45,9 @@ public:
kUnRegisteredOwnedAge = plNetCommon::VaultTasks::kUnRegisterOwnedAge, kUnRegisteredOwnedAge = plNetCommon::VaultTasks::kUnRegisterOwnedAge,
kUnRegisteredVisitAge = plNetCommon::VaultTasks::kUnRegisterVisitAge, kUnRegisteredVisitAge = plNetCommon::VaultTasks::kUnRegisterVisitAge,
kPublicAgeCreated, kPublicAgeCreated,
kPublicAgeRemoved kPublicAgeRemoved,
kRegisteredSubAgeLink,
kRegisteredChildAgeLink,
}; };
plVaultNotifyMsg(); plVaultNotifyMsg();

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

@ -46,7 +46,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "plAvatar/plArmatureMod.h" #include "plAvatar/plArmatureMod.h"
#include "plFile/hsFiles.h" #include "plFile/hsFiles.h"
#include "plMessage/plNCAgeJoinerMsg.h" #include "plMessage/plNCAgeJoinerMsg.h"
#include "plVault/plVault.h"
/***************************************************************************** /*****************************************************************************
@ -477,26 +476,38 @@ bool plNetLinkingMgr::IProcessVaultNotifyMsg(plVaultNotifyMsg* msg)
if (fDeferredLink == nil) if (fDeferredLink == nil)
return false; return false;
if (msg->GetType() != plVaultNotifyMsg::kRegisteredOwnedAge)
return false;
// Find the AgeLinks
plAgeLinkStruct* cur = GetAgeLink(); plAgeLinkStruct* cur = GetAgeLink();
if (RelVaultNode* cVaultLink = VaultGetOwnedAgeLinkIncRef(cur->GetAgeInfo())) RelVaultNode* cVaultLink = nil;
switch (msg->GetType())
{
case plVaultNotifyMsg::kRegisteredOwnedAge:
case plVaultNotifyMsg::kRegisteredSubAgeLink:
cVaultLink = VaultGetNodeIncRef(msg->GetArgs()->GetInt(plNetCommon::VaultTaskArgs::kAgeLinkNode));
break;
default:
return false;
}
if (cVaultLink != nil)
{ {
// Test to see if this is what we want // This is something that Cyan does... >.<
if (cVaultLink->nodeId == msg->GetArgs()->GetInt(plNetCommon::VaultTaskArgs::kAgeLinkNode)) // It's very useful though...
VaultAgeLinkNode accLink(cVaultLink);
accLink.CopyTo(cur);
if (RelVaultNode* rvnInfo = cVaultLink->GetChildNodeIncRef(plVault::kNodeType_AgeInfo, 1))
{ {
IDoLink(fDeferredLink); VaultAgeInfoNode accInfo(rvnInfo);
return true; accInfo.CopyTo(cur->GetAgeInfo());
rvnInfo->DecRef();
} }
IDoLink(fDeferredLink);
fDeferredLink = nil;
return true;
cVaultLink->DecRef(); cVaultLink->DecRef();
} }
// Nuke the deferred link ptr, just 'cause
fDeferredLink = nil;
return false; return false;
} }
@ -797,7 +808,7 @@ void plNetLinkingMgr::IPostProcessLink( void )
case plNetCommon::LinkingRules::kSubAgeBook: { case plNetCommon::LinkingRules::kSubAgeBook: {
// Register the previous age as a sub age of the current one so that we can link back to that instance // Register the previous age as a sub age of the current one so that we can link back to that instance
plAgeLinkStruct subAgeLink; plAgeLinkStruct subAgeLink;
VaultAgeFindOrCreateSubAgeLinkAndWait(GetPrevAgeLink()->GetAgeInfo(), &subAgeLink, NetCommGetAge()->ageInstId); VaultAgeFindOrCreateSubAgeLink(GetPrevAgeLink()->GetAgeInfo(), &subAgeLink, NetCommGetAge()->ageInstId);
} }
break; break;
} }
@ -1022,10 +1033,10 @@ UInt8 plNetLinkingMgr::IPreProcessLink(void)
case plNetCommon::LinkingRules::kSubAgeBook: case plNetCommon::LinkingRules::kSubAgeBook:
{ {
plAgeLinkStruct subAgeLink; plAgeLinkStruct subAgeLink;
if (VaultAgeFindOrCreateSubAgeLinkAndWait(info, &subAgeLink, NetCommGetAge()->ageInstId)) if (VaultAgeFindOrCreateSubAgeLink(info, &subAgeLink, NetCommGetAge()->ageInstId))
info->CopyFrom(subAgeLink.GetAgeInfo()); info->CopyFrom(subAgeLink.GetAgeInfo());
else else
success = kLinkFailed; success = kLinkDeferred;
} }
break; break;

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

@ -4426,6 +4426,95 @@ bool VaultAgeFindOrCreateSubAgeLinkAndWait (
return true; return true;
} }
//============================================================================
namespace _VaultCreateSubAge {
void _CreateNodeCallback(ENetError result, void* state, void* param, RelVaultNode* node) {
if (IS_NET_ERROR(result)) {
LogMsg(kLogError, "CreateSubAge: Failed to create AgeLink (async)");
DEL(param);
return;
}
UInt32 ageInfoId = *(UInt32*)param;
// Add the children to the right places
VaultAddChildNode(node->nodeId, ageInfoId, 0, nil, nil);
if (RelVaultNode* saFldr = VaultGetAgeSubAgesFolderIncRef()) {
VaultAddChildNode(saFldr->nodeId, node->nodeId, 0, nil, nil);
saFldr->DecRef();
} else
LogMsg(kLogError, "CreateSubAge: Couldn't find SubAges folder (async)");
// Send the VaultNotify that the plNetLinkingMgr wants...
plVaultNotifyMsg * msg = NEWZERO(plVaultNotifyMsg);
msg->SetType(plVaultNotifyMsg::kRegisteredSubAgeLink);
msg->SetResultCode(result);
msg->GetArgs()->AddInt(plNetCommon::VaultTaskArgs::kAgeLinkNode, node->nodeId);
msg->Send();
DEL(param);
}
void _DownloadCallback(ENetError result, void* param) {
if (IS_NET_ERROR(result)) {
LogMsg(kLogError, "CreateSubAge: Failed to download age vault (async)");
DEL(param);
return;
}
// Create the AgeLink node
VaultCreateNode(plVault::kNodeType_AgeLink,
(FVaultCreateNodeCallback)_CreateNodeCallback,
nil,
param
);
}
void _InitAgeCallback(ENetError result, void* state, void* param, UInt32 ageVaultId, UInt32 ageInfoId) {
if (IS_NET_ERROR(result)) {
LogMsg(kLogError, "CreateSubAge: Failed to init age (async)");
return;
}
// Download age vault
VaultDownload(L"CreateSubAge",
ageInfoId,
(FVaultDownloadCallback)_DownloadCallback,
TRACKED_NEW UInt32(ageInfoId),
nil,
nil
);
}
}; // namespace _VaultCreateSubAge
bool VaultAgeFindOrCreateSubAgeLink(const plAgeInfoStruct* info, plAgeLinkStruct* link, const Uuid& parentUuid) {
using namespace _VaultCreateSubAge;
// First, try to find an already existing subage
if (RelVaultNode* rvnLink = VaultGetSubAgeLinkIncRef(info)) {
VaultAgeLinkNode accLink(rvnLink);
accLink.CopyTo(link);
if (RelVaultNode* rvnInfo = rvnLink->GetChildNodeIncRef(plVault::kNodeType_AgeInfo, 1)) {
VaultAgeInfoNode accInfo(rvnInfo);
accInfo.CopyTo(link->GetAgeInfo());
rvnInfo->DecRef();
}
rvnLink->DecRef();
return true;
}
VaultInitAge(info,
parentUuid,
(FVaultInitAgeCallback)_InitAgeCallback,
nil,
nil
);
return false;
}
//============================================================================ //============================================================================
namespace _VaultCreateChildAgeAndWait { namespace _VaultCreateChildAgeAndWait {

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

@ -408,6 +408,7 @@ void VaultAgeUpdateAgeSDL (const class plStateDataRecord * rec);
unsigned VaultAgeGetAgeTime (); unsigned VaultAgeGetAgeTime ();
RelVaultNode * VaultGetSubAgeLinkIncRef (const plAgeInfoStruct * info);
bool VaultAgeGetSubAgeLink ( bool VaultAgeGetSubAgeLink (
const plAgeInfoStruct * info, const plAgeInfoStruct * info,
plAgeLinkStruct * link plAgeLinkStruct * link
@ -417,6 +418,7 @@ bool VaultAgeFindOrCreateSubAgeLinkAndWait (
plAgeLinkStruct * link, plAgeLinkStruct * link,
const Uuid & parentAgeInstId const Uuid & parentAgeInstId
); );
bool VaultAgeFindOrCreateSubAgeLink(const plAgeInfoStruct* info, plAgeLinkStruct* link, const Uuid& parentUuid);
bool VaultAgeFindOrCreateChildAgeLinkAndWait ( bool VaultAgeFindOrCreateChildAgeLinkAndWait (
const wchar parentAgeName[], // nil --> current age, non-nil --> owned age by given name const wchar parentAgeName[], // nil --> current age, non-nil --> owned age by given name
const plAgeInfoStruct * info, const plAgeInfoStruct * info,

Loading…
Cancel
Save