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. 39
      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,
kUnRegisteredVisitAge = plNetCommon::VaultTasks::kUnRegisterVisitAge,
kPublicAgeCreated,
kPublicAgeRemoved
kPublicAgeRemoved,
kRegisteredSubAgeLink,
kRegisteredChildAgeLink,
};
plVaultNotifyMsg();

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

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

@ -4426,6 +4426,95 @@ bool VaultAgeFindOrCreateSubAgeLinkAndWait (
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 {

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

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

Loading…
Cancel
Save