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 <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
//============================================================================
|
||||
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 * wEntryValue = StrDupToUnicode(value);
|
||||
|
||||
VaultAddChronicleEntryAndWait(wEntryName, type, wEntryValue);
|
||||
VaultAddChronicleEntry(wEntryName, type, wEntryValue);
|
||||
|
||||
FREE(wEntryName);
|
||||
FREE(wEntryValue);
|
||||
@ -362,7 +365,9 @@ void pyVault::SendToDevice( pyVaultNode& node, const char * deviceName )
|
||||
return;
|
||||
|
||||
wchar wDevName[256];
|
||||
StrToUnicode(wDevName, deviceName, arrsize(wDevName));
|
||||
StrToUnicode(wDevName, deviceName, arrsize(wDevName));
|
||||
|
||||
// Note: This actually blocks (~Hoikas)
|
||||
VaultPublishNode(node.GetNode()->nodeId, wDevName);
|
||||
}
|
||||
|
||||
@ -528,12 +533,14 @@ void pyVault::RegisterMTStation( const char * stationName, const char * backLink
|
||||
wchar wSpawnPt[256];
|
||||
StrToUnicode(wStationName, stationName, arrsize(wStationName));
|
||||
StrToUnicode(wSpawnPt, backLinkSpawnPtObjName, arrsize(wSpawnPt));
|
||||
|
||||
// Note: This doesn't actually block (~Hoikas)
|
||||
VaultRegisterMTStationAndWait( wStationName, wSpawnPt);
|
||||
}
|
||||
|
||||
void pyVault::RegisterOwnedAge( const pyAgeLinkStruct & link )
|
||||
{
|
||||
VaultRegisterOwnedAgeAndWait(link.GetAgeLink());
|
||||
VaultRegisterOwnedAge(link.GetAgeLink());
|
||||
}
|
||||
|
||||
void pyVault::UnRegisterOwnedAge( const char * ageFilename )
|
||||
@ -557,22 +564,27 @@ void pyVault::UnRegisterVisitAge( const char * guidstr )
|
||||
VaultUnregisterVisitAgeAndWait(&info);
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
void pyVault::InvitePlayerToAge( const pyAgeLinkStruct & link, UInt32 playerID )
|
||||
{
|
||||
ENetError error;
|
||||
NetVaultNode * templateNode = NEWZERO(NetVaultNode);
|
||||
templateNode->IncRef();
|
||||
templateNode->SetNodeType(plVault::kNodeType_TextNote);
|
||||
VaultTextNoteNode visitAcc(templateNode);
|
||||
visitAcc.SetNoteType(plVault::kNoteType_Visit);
|
||||
visitAcc.SetVisitInfo(*link.GetAgeLink()->GetAgeInfo());
|
||||
if (RelVaultNode * rvn = VaultCreateNodeAndWaitIncRef(templateNode, &error)) {
|
||||
VaultSendNode(rvn, playerID);
|
||||
rvn->DecRef();
|
||||
}
|
||||
VaultCreateNode(templateNode, (FVaultCreateNodeCallback)_InvitePlayerToAge, nil, TRACKED_NEW UInt32(playerID));
|
||||
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 )
|
||||
{
|
||||
plAgeInfoStruct info;
|
||||
@ -588,30 +600,36 @@ void pyVault::UnInvitePlayerToAge( const char * str, UInt32 playerID )
|
||||
rvnLink->DecRef();
|
||||
}
|
||||
|
||||
ENetError error;
|
||||
NetVaultNode * templateNode = NEWZERO(NetVaultNode);
|
||||
templateNode->IncRef();
|
||||
templateNode->SetNodeType(plVault::kNodeType_TextNote);
|
||||
VaultTextNoteNode visitAcc(templateNode);
|
||||
visitAcc.SetNoteType(plVault::kNoteType_UnVisit);
|
||||
visitAcc.SetVisitInfo(info);
|
||||
if (RelVaultNode * rvn = VaultCreateNodeAndWaitIncRef(templateNode, &error)) {
|
||||
VaultSendNode(rvn, playerID);
|
||||
rvn->DecRef();
|
||||
}
|
||||
VaultCreateNode(templateNode, (FVaultCreateNodeCallback)_UninvitePlayerToAge, nil, TRACKED_NEW UInt32(playerID));
|
||||
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 )
|
||||
{
|
||||
hsAssert(false, "eric, port me");
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
void pyVault::CreateNeighborhood()
|
||||
{
|
||||
plNetClientMgr * nc = plNetClientMgr::GetInstance();
|
||||
|
||||
// Unregister old hood
|
||||
// Unregister old hood
|
||||
// Note: This doesn't actually block (~Hoikas)
|
||||
plAgeInfoStruct info;
|
||||
info.SetAgeFilename(kNeighborhoodAgeFilename);
|
||||
VaultUnregisterOwnedAgeAndWait(&info);
|
||||
@ -640,11 +658,12 @@ void pyVault::CreateNeighborhood()
|
||||
link.GetAgeInfo()->SetAgeUserDefinedName( title.c_str() );
|
||||
link.GetAgeInfo()->SetAgeDescription( desc.c_str() );
|
||||
|
||||
VaultRegisterOwnedAgeAndWait(&link);
|
||||
VaultRegisterOwnedAge(&link);
|
||||
}
|
||||
|
||||
bool pyVault::SetAgePublic( const pyAgeInfoStruct * ageInfo, bool makePublic )
|
||||
{
|
||||
// Note: This doesn't actually block (~Hoikas)
|
||||
return VaultSetOwnedAgePublicAndWait(ageInfo->GetAgeInfo(), makePublic);
|
||||
}
|
||||
|
||||
|
@ -54,6 +54,15 @@ class pyAgeLinkStruct;
|
||||
|
||||
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
|
||||
{
|
||||
|
@ -2786,6 +2786,122 @@ bool VaultRegisterOwnedAgeAndWait (const plAgeLinkStruct * link) {
|
||||
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 {
|
||||
|
||||
@ -3199,6 +3315,38 @@ bool VaultHasChronicleEntry (const wchar entryName[], int entryType) {
|
||||
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 (
|
||||
const wchar entryName[],
|
||||
|
@ -332,12 +332,15 @@ bool VaultSetOwnedAgePublicAndWait (const plAgeInfoStruct * info, boo
|
||||
RelVaultNode * VaultGetVisitAgeLinkIncRef (const plAgeInfoStruct * info);
|
||||
bool VaultGetVisitAgeLink (const plAgeInfoStruct * info, class plAgeLinkStruct * link);
|
||||
bool VaultRegisterOwnedAgeAndWait (const plAgeLinkStruct * link);
|
||||
void VaultRegisterOwnedAge(const plAgeLinkStruct* link);
|
||||
bool VaultRegisterVisitAgeAndWait (const plAgeLinkStruct * link);
|
||||
bool VaultUnregisterOwnedAgeAndWait (const plAgeInfoStruct * info);
|
||||
bool VaultUnregisterVisitAgeAndWait (const plAgeInfoStruct * info);
|
||||
RelVaultNode * VaultFindChronicleEntryIncRef (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
|
||||
void VaultAddChronicleEntry (const wchar entryName[], int entryType, const wchar entryValue[]);
|
||||
void _VaultAddChronicleEntryCB(ENetError result, void* state, void * param, RelVaultNode* node);
|
||||
void VaultAddChronicleEntryAndWait (
|
||||
const wchar entryName[],
|
||||
int entryType,
|
||||
|
Reference in New Issue
Block a user