mirror of
https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git
synced 2025-07-14 02:27:40 -04:00
Implement async chronicle creation and age registration. Update pyVault to use the new implementations.
This commit is contained in:
@ -60,6 +60,9 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
|||||||
|
|
||||||
#include "plSDL/plSDL.h"
|
#include "plSDL/plSDL.h"
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
//============================================================================
|
//============================================================================
|
||||||
static PyObject * GetFolder (unsigned folderType) {
|
static PyObject * GetFolder (unsigned folderType) {
|
||||||
@ -349,7 +352,7 @@ void pyVault::AddChronicleEntry( const char * name, UInt32 type, const char * va
|
|||||||
wchar * wEntryName = StrDupToUnicode(name);
|
wchar * wEntryName = StrDupToUnicode(name);
|
||||||
wchar * wEntryValue = StrDupToUnicode(value);
|
wchar * wEntryValue = StrDupToUnicode(value);
|
||||||
|
|
||||||
VaultAddChronicleEntryAndWait(wEntryName, type, wEntryValue);
|
VaultAddChronicleEntry(wEntryName, type, wEntryValue);
|
||||||
|
|
||||||
FREE(wEntryName);
|
FREE(wEntryName);
|
||||||
FREE(wEntryValue);
|
FREE(wEntryValue);
|
||||||
@ -362,7 +365,9 @@ void pyVault::SendToDevice( pyVaultNode& node, const char * deviceName )
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
wchar wDevName[256];
|
wchar wDevName[256];
|
||||||
StrToUnicode(wDevName, deviceName, arrsize(wDevName));
|
StrToUnicode(wDevName, deviceName, arrsize(wDevName));
|
||||||
|
|
||||||
|
// Note: This actually blocks (~Hoikas)
|
||||||
VaultPublishNode(node.GetNode()->nodeId, wDevName);
|
VaultPublishNode(node.GetNode()->nodeId, wDevName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -528,12 +533,14 @@ void pyVault::RegisterMTStation( const char * stationName, const char * backLink
|
|||||||
wchar wSpawnPt[256];
|
wchar wSpawnPt[256];
|
||||||
StrToUnicode(wStationName, stationName, arrsize(wStationName));
|
StrToUnicode(wStationName, stationName, arrsize(wStationName));
|
||||||
StrToUnicode(wSpawnPt, backLinkSpawnPtObjName, arrsize(wSpawnPt));
|
StrToUnicode(wSpawnPt, backLinkSpawnPtObjName, arrsize(wSpawnPt));
|
||||||
|
|
||||||
|
// Note: This doesn't actually block (~Hoikas)
|
||||||
VaultRegisterMTStationAndWait( wStationName, wSpawnPt);
|
VaultRegisterMTStationAndWait( wStationName, wSpawnPt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void pyVault::RegisterOwnedAge( const pyAgeLinkStruct & link )
|
void pyVault::RegisterOwnedAge( const pyAgeLinkStruct & link )
|
||||||
{
|
{
|
||||||
VaultRegisterOwnedAgeAndWait(link.GetAgeLink());
|
VaultRegisterOwnedAge(link.GetAgeLink());
|
||||||
}
|
}
|
||||||
|
|
||||||
void pyVault::UnRegisterOwnedAge( const char * ageFilename )
|
void pyVault::UnRegisterOwnedAge( const char * ageFilename )
|
||||||
@ -557,22 +564,27 @@ void pyVault::UnRegisterVisitAge( const char * guidstr )
|
|||||||
VaultUnregisterVisitAgeAndWait(&info);
|
VaultUnregisterVisitAgeAndWait(&info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//============================================================================
|
||||||
void pyVault::InvitePlayerToAge( const pyAgeLinkStruct & link, UInt32 playerID )
|
void pyVault::InvitePlayerToAge( const pyAgeLinkStruct & link, UInt32 playerID )
|
||||||
{
|
{
|
||||||
ENetError error;
|
|
||||||
NetVaultNode * templateNode = NEWZERO(NetVaultNode);
|
NetVaultNode * templateNode = NEWZERO(NetVaultNode);
|
||||||
templateNode->IncRef();
|
templateNode->IncRef();
|
||||||
templateNode->SetNodeType(plVault::kNodeType_TextNote);
|
templateNode->SetNodeType(plVault::kNodeType_TextNote);
|
||||||
VaultTextNoteNode visitAcc(templateNode);
|
VaultTextNoteNode visitAcc(templateNode);
|
||||||
visitAcc.SetNoteType(plVault::kNoteType_Visit);
|
visitAcc.SetNoteType(plVault::kNoteType_Visit);
|
||||||
visitAcc.SetVisitInfo(*link.GetAgeLink()->GetAgeInfo());
|
visitAcc.SetVisitInfo(*link.GetAgeLink()->GetAgeInfo());
|
||||||
if (RelVaultNode * rvn = VaultCreateNodeAndWaitIncRef(templateNode, &error)) {
|
VaultCreateNode(templateNode, (FVaultCreateNodeCallback)_InvitePlayerToAge, nil, TRACKED_NEW UInt32(playerID));
|
||||||
VaultSendNode(rvn, playerID);
|
|
||||||
rvn->DecRef();
|
|
||||||
}
|
|
||||||
templateNode->DecRef();
|
templateNode->DecRef();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _InvitePlayerToAge(ENetError result, void* state, void* param, RelVaultNode* node)
|
||||||
|
{
|
||||||
|
if (result == kNetSuccess)
|
||||||
|
VaultSendNode(node, *((UInt32*)param));
|
||||||
|
delete param;
|
||||||
|
}
|
||||||
|
|
||||||
|
//============================================================================
|
||||||
void pyVault::UnInvitePlayerToAge( const char * str, UInt32 playerID )
|
void pyVault::UnInvitePlayerToAge( const char * str, UInt32 playerID )
|
||||||
{
|
{
|
||||||
plAgeInfoStruct info;
|
plAgeInfoStruct info;
|
||||||
@ -588,30 +600,36 @@ void pyVault::UnInvitePlayerToAge( const char * str, UInt32 playerID )
|
|||||||
rvnLink->DecRef();
|
rvnLink->DecRef();
|
||||||
}
|
}
|
||||||
|
|
||||||
ENetError error;
|
|
||||||
NetVaultNode * templateNode = NEWZERO(NetVaultNode);
|
NetVaultNode * templateNode = NEWZERO(NetVaultNode);
|
||||||
templateNode->IncRef();
|
templateNode->IncRef();
|
||||||
templateNode->SetNodeType(plVault::kNodeType_TextNote);
|
templateNode->SetNodeType(plVault::kNodeType_TextNote);
|
||||||
VaultTextNoteNode visitAcc(templateNode);
|
VaultTextNoteNode visitAcc(templateNode);
|
||||||
visitAcc.SetNoteType(plVault::kNoteType_UnVisit);
|
visitAcc.SetNoteType(plVault::kNoteType_UnVisit);
|
||||||
visitAcc.SetVisitInfo(info);
|
visitAcc.SetVisitInfo(info);
|
||||||
if (RelVaultNode * rvn = VaultCreateNodeAndWaitIncRef(templateNode, &error)) {
|
VaultCreateNode(templateNode, (FVaultCreateNodeCallback)_UninvitePlayerToAge, nil, TRACKED_NEW UInt32(playerID));
|
||||||
VaultSendNode(rvn, playerID);
|
|
||||||
rvn->DecRef();
|
|
||||||
}
|
|
||||||
templateNode->DecRef();
|
templateNode->DecRef();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _UninvitePlayerToAge(ENetError result, void* state, void* param, RelVaultNode* node)
|
||||||
|
{
|
||||||
|
if (result == kNetSuccess)
|
||||||
|
VaultSendNode(node, *((UInt32*)param));
|
||||||
|
delete param;
|
||||||
|
}
|
||||||
|
|
||||||
|
//============================================================================
|
||||||
void pyVault::OfferLinkToPlayer( const pyAgeLinkStruct & link, UInt32 playerID )
|
void pyVault::OfferLinkToPlayer( const pyAgeLinkStruct & link, UInt32 playerID )
|
||||||
{
|
{
|
||||||
hsAssert(false, "eric, port me");
|
hsAssert(false, "eric, port me");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//============================================================================
|
||||||
void pyVault::CreateNeighborhood()
|
void pyVault::CreateNeighborhood()
|
||||||
{
|
{
|
||||||
plNetClientMgr * nc = plNetClientMgr::GetInstance();
|
plNetClientMgr * nc = plNetClientMgr::GetInstance();
|
||||||
|
|
||||||
// Unregister old hood
|
// Unregister old hood
|
||||||
|
// Note: This doesn't actually block (~Hoikas)
|
||||||
plAgeInfoStruct info;
|
plAgeInfoStruct info;
|
||||||
info.SetAgeFilename(kNeighborhoodAgeFilename);
|
info.SetAgeFilename(kNeighborhoodAgeFilename);
|
||||||
VaultUnregisterOwnedAgeAndWait(&info);
|
VaultUnregisterOwnedAgeAndWait(&info);
|
||||||
@ -640,11 +658,12 @@ void pyVault::CreateNeighborhood()
|
|||||||
link.GetAgeInfo()->SetAgeUserDefinedName( title.c_str() );
|
link.GetAgeInfo()->SetAgeUserDefinedName( title.c_str() );
|
||||||
link.GetAgeInfo()->SetAgeDescription( desc.c_str() );
|
link.GetAgeInfo()->SetAgeDescription( desc.c_str() );
|
||||||
|
|
||||||
VaultRegisterOwnedAgeAndWait(&link);
|
VaultRegisterOwnedAge(&link);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool pyVault::SetAgePublic( const pyAgeInfoStruct * ageInfo, bool makePublic )
|
bool pyVault::SetAgePublic( const pyAgeInfoStruct * ageInfo, bool makePublic )
|
||||||
{
|
{
|
||||||
|
// Note: This doesn't actually block (~Hoikas)
|
||||||
return VaultSetOwnedAgePublicAndWait(ageInfo->GetAgeInfo(), makePublic);
|
return VaultSetOwnedAgePublicAndWait(ageInfo->GetAgeInfo(), makePublic);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,6 +54,15 @@ class pyAgeLinkStruct;
|
|||||||
|
|
||||||
class pySDLStateDataRecord;
|
class pySDLStateDataRecord;
|
||||||
|
|
||||||
|
// Async Helpers... :)
|
||||||
|
#ifndef BUILDING_PYPLASMA
|
||||||
|
enum ENetError;
|
||||||
|
struct RelVaultNode;
|
||||||
|
|
||||||
|
void _InvitePlayerToAge(ENetError result, void* state, void* param, RelVaultNode* node);
|
||||||
|
void _UninvitePlayerToAge(ENetError result, void* state, void* param, RelVaultNode* node);
|
||||||
|
#endif // BUILDING_PYPLASMA
|
||||||
|
|
||||||
|
|
||||||
class pyVault
|
class pyVault
|
||||||
{
|
{
|
||||||
|
@ -2786,6 +2786,122 @@ bool VaultRegisterOwnedAgeAndWait (const plAgeLinkStruct * link) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//============================================================================
|
||||||
|
namespace _VaultRegisterOwnedAge {
|
||||||
|
struct _Params {
|
||||||
|
plSpawnPointInfo* fSpawn;
|
||||||
|
UInt32* fAgeInfoId;
|
||||||
|
|
||||||
|
~_Params() {
|
||||||
|
delete fSpawn;
|
||||||
|
delete fAgeInfoId;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
void _AddAgeInfoNode(ENetError result, void* param) {
|
||||||
|
if (result != kNetSuccess)
|
||||||
|
LogMsg(kLogError, "VaultRegisterOwnedAge: Failed to add info to link (async)");
|
||||||
|
}
|
||||||
|
|
||||||
|
void _AddAgeLinkNode(ENetError result, void* param) {
|
||||||
|
if (result != kNetSuccess)
|
||||||
|
LogMsg(kLogError, "VaultRegisterOwnedAge: Failed to add age to bookshelf (async)");
|
||||||
|
}
|
||||||
|
|
||||||
|
void _AddPlayerInfoNode(ENetError result, void* param) {
|
||||||
|
if (result != kNetSuccess)
|
||||||
|
LogMsg(kLogError, "VaultRegisterOwnedAge: Failed to add playerInfo to ageOwners (async)");
|
||||||
|
}
|
||||||
|
|
||||||
|
void _CreateAgeLinkNode(ENetError result, void* state, void* param, RelVaultNode* node) {
|
||||||
|
if (result != kNetSuccess) {
|
||||||
|
LogMsg(kLogError, "VaultRegisterOwnedAge: Failed to create AgeLink (async)");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Grab our params
|
||||||
|
_Params* p = (_Params*)param;
|
||||||
|
|
||||||
|
// Set swpoint
|
||||||
|
VaultAgeLinkNode aln(node);
|
||||||
|
aln.AddSpawnPoint(*(p->fSpawn));
|
||||||
|
|
||||||
|
// Make some refs
|
||||||
|
RelVaultNode* agesIOwn = VaultGetAgesIOwnFolderIncRef();
|
||||||
|
RelVaultNode* plyrInfo = VaultGetPlayerInfoNodeIncRef();
|
||||||
|
VaultAddChildNode(agesIOwn->nodeId, node->nodeId, 0, (FVaultAddChildNodeCallback)_AddAgeLinkNode, nil);
|
||||||
|
VaultAddChildNode(node->nodeId, *(p->fAgeInfoId), 0, (FVaultAddChildNodeCallback)_AddAgeInfoNode, nil);
|
||||||
|
|
||||||
|
// Add our PlayerInfo to important places
|
||||||
|
if (RelVaultNode* rvnAgeInfo = VaultGetNodeIncRef(*(p->fAgeInfoId))) {
|
||||||
|
if (RelVaultNode* rvnAgeOwners = rvnAgeInfo->GetChildPlayerInfoListNodeIncRef(plVault::kAgeOwnersFolder, 1)) {
|
||||||
|
VaultAddChildNode(rvnAgeOwners->nodeId, plyrInfo->nodeId, 0, (FVaultAddChildNodeCallback)_AddPlayerInfoNode, nil);
|
||||||
|
rvnAgeOwners->DecRef();
|
||||||
|
}
|
||||||
|
|
||||||
|
rvnAgeInfo->DecRef();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fire off vault callbacks
|
||||||
|
plVaultNotifyMsg* msg = NEWZERO(plVaultNotifyMsg);
|
||||||
|
msg->SetType(plVaultNotifyMsg::kRegisteredOwnedAge);
|
||||||
|
msg->SetResultCode(result);
|
||||||
|
msg->GetArgs()->AddInt(plNetCommon::VaultTaskArgs::kAgeLinkNode, node->nodeId);
|
||||||
|
msg->Send();
|
||||||
|
|
||||||
|
// Don't leak memory
|
||||||
|
agesIOwn->DecRef();
|
||||||
|
plyrInfo->DecRef();
|
||||||
|
delete p;
|
||||||
|
}
|
||||||
|
|
||||||
|
void _DownloadCallback(ENetError result, void* param) {
|
||||||
|
if (result == kNetSuccess) {
|
||||||
|
VaultCreateNode(plVault::kNodeType_AgeLink, (FVaultCreateNodeCallback)_CreateAgeLinkNode, nil, param);
|
||||||
|
} else
|
||||||
|
LogMsg(kLogError, "VaultRegisterOwnedAge: Failed to download age vault (async)");
|
||||||
|
}
|
||||||
|
|
||||||
|
void _InitAgeCallback(ENetError result, void* state, void* param, UInt32 ageVaultId, UInt32 ageInfoVaultId) {
|
||||||
|
if (result == kNetSuccess) {
|
||||||
|
_Params* p = TRACKED_NEW _Params();
|
||||||
|
p->fAgeInfoId = TRACKED_NEW UInt32(ageInfoVaultId);
|
||||||
|
p->fSpawn = (plSpawnPointInfo*)param;
|
||||||
|
|
||||||
|
VaultDownload(
|
||||||
|
L"RegisterOwnedAge",
|
||||||
|
ageInfoVaultId,
|
||||||
|
(FVaultDownloadCallback)_DownloadCallback,
|
||||||
|
p,
|
||||||
|
nil,
|
||||||
|
nil);
|
||||||
|
} else
|
||||||
|
LogMsg(kLogError, "VaultRegisterOwnedAge: Failed to init age (async)");
|
||||||
|
}
|
||||||
|
}; // namespace _VaultRegisterOwnedAge
|
||||||
|
|
||||||
|
void VaultRegisterOwnedAge(const plAgeLinkStruct* link) {
|
||||||
|
using namespace _VaultRegisterOwnedAge;
|
||||||
|
|
||||||
|
RelVaultNode* agesIOwn = VaultGetAgesIOwnFolderIncRef();
|
||||||
|
if (agesIOwn == nil) {
|
||||||
|
LogMsg(kLogError, "VaultRegisterOwnedAge: Couldn't find the stupid AgesIOwnfolder!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure we don't already have the age
|
||||||
|
plAgeLinkStruct existing;
|
||||||
|
if (VaultGetOwnedAgeLink(link->GetAgeInfo(), &existing))
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Let's go async, my friend :)
|
||||||
|
VaultInitAge(link->GetAgeInfo(),
|
||||||
|
kNilGuid,
|
||||||
|
(FVaultInitAgeCallback)_InitAgeCallback,
|
||||||
|
nil,
|
||||||
|
TRACKED_NEW plSpawnPointInfo(link->SpawnPoint()));
|
||||||
|
}
|
||||||
|
|
||||||
//============================================================================
|
//============================================================================
|
||||||
namespace _VaultRegisterVisitAgeAndWait {
|
namespace _VaultRegisterVisitAgeAndWait {
|
||||||
|
|
||||||
@ -3199,6 +3315,38 @@ bool VaultHasChronicleEntry (const wchar entryName[], int entryType) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//============================================================================
|
||||||
|
void VaultAddChronicleEntry (const wchar entryName[], int entryType, const wchar entryValue[]) {
|
||||||
|
// Sometimes we try to create chrons in StartUp.
|
||||||
|
// This is bad...
|
||||||
|
if (GetPlayerNode() == nil)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (RelVaultNode* rvnChrn = VaultFindChronicleEntryIncRef(entryName, entryType)) {
|
||||||
|
VaultChronicleNode chrnNode(rvnChrn);
|
||||||
|
chrnNode.SetEntryValue(entryValue);
|
||||||
|
rvnChrn->DecRef();
|
||||||
|
} else {
|
||||||
|
NetVaultNode* templateNode = NEWZERO(NetVaultNode);
|
||||||
|
templateNode->IncRef();
|
||||||
|
templateNode->SetNodeType(plVault::kNodeType_Chronicle);
|
||||||
|
VaultChronicleNode chrnNode(templateNode);
|
||||||
|
chrnNode.SetEntryName(entryName);
|
||||||
|
chrnNode.SetEntryType(entryType);
|
||||||
|
chrnNode.SetEntryValue(entryValue);
|
||||||
|
VaultCreateNode(templateNode, (FVaultCreateNodeCallback)(_VaultAddChronicleEntryCB), nil, nil);
|
||||||
|
templateNode->DecRef();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _VaultAddChronicleEntryCB(ENetError result, void* state, void * param, RelVaultNode* node) {
|
||||||
|
if (result == ENetError::kNetSuccess) {
|
||||||
|
RelVaultNode* rvnFldr = GetChildFolderNode(GetPlayerNode(), plVault::kChronicleFolder, 1);
|
||||||
|
if (rvnFldr != nil)
|
||||||
|
VaultAddChildNode(rvnFldr->nodeId, node->nodeId, 0, nil, nil);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//============================================================================
|
//============================================================================
|
||||||
void VaultAddChronicleEntryAndWait (
|
void VaultAddChronicleEntryAndWait (
|
||||||
const wchar entryName[],
|
const wchar entryName[],
|
||||||
|
@ -332,12 +332,15 @@ bool VaultSetOwnedAgePublicAndWait (const plAgeInfoStruct * info, boo
|
|||||||
RelVaultNode * VaultGetVisitAgeLinkIncRef (const plAgeInfoStruct * info);
|
RelVaultNode * VaultGetVisitAgeLinkIncRef (const plAgeInfoStruct * info);
|
||||||
bool VaultGetVisitAgeLink (const plAgeInfoStruct * info, class plAgeLinkStruct * link);
|
bool VaultGetVisitAgeLink (const plAgeInfoStruct * info, class plAgeLinkStruct * link);
|
||||||
bool VaultRegisterOwnedAgeAndWait (const plAgeLinkStruct * link);
|
bool VaultRegisterOwnedAgeAndWait (const plAgeLinkStruct * link);
|
||||||
|
void VaultRegisterOwnedAge(const plAgeLinkStruct* link);
|
||||||
bool VaultRegisterVisitAgeAndWait (const plAgeLinkStruct * link);
|
bool VaultRegisterVisitAgeAndWait (const plAgeLinkStruct * link);
|
||||||
bool VaultUnregisterOwnedAgeAndWait (const plAgeInfoStruct * info);
|
bool VaultUnregisterOwnedAgeAndWait (const plAgeInfoStruct * info);
|
||||||
bool VaultUnregisterVisitAgeAndWait (const plAgeInfoStruct * info);
|
bool VaultUnregisterVisitAgeAndWait (const plAgeInfoStruct * info);
|
||||||
RelVaultNode * VaultFindChronicleEntryIncRef (const wchar entryName[], int entryType = -1);
|
RelVaultNode * VaultFindChronicleEntryIncRef (const wchar entryName[], int entryType = -1);
|
||||||
bool VaultHasChronicleEntry (const wchar entryName[], int entryType = -1);
|
bool VaultHasChronicleEntry (const wchar 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 VaultAddChronicleEntry (const wchar entryName[], int entryType, const wchar entryValue[]);
|
||||||
|
void _VaultAddChronicleEntryCB(ENetError result, void* state, void * param, RelVaultNode* node);
|
||||||
void VaultAddChronicleEntryAndWait (
|
void VaultAddChronicleEntryAndWait (
|
||||||
const wchar entryName[],
|
const wchar entryName[],
|
||||||
int entryType,
|
int entryType,
|
||||||
|
Reference in New Issue
Block a user