コード例 #1
0
void plSceneInputInterface::ILinkOffereeToAge()
{
    // check vault to see if we've got an instance of the offered age now, if not create one and wait until we get a reply...
    plAgeInfoStruct info;
    info.SetAgeFilename(fOfferedAgeFile);
    info.SetAgeInstanceName(fOfferedAgeInstance);

    bool isAgeInstanceGuidSet = fAgeInstanceGuid.IsSet();
    
    plAgeLinkStruct link;
    
    if (isAgeInstanceGuidSet) {
        info.SetAgeInstanceGuid(&fAgeInstanceGuid);
        link.GetAgeInfo()->CopyFrom(&info);

        fAgeInstanceGuid.Clear();
    }
    else if (!VaultGetOwnedAgeLink(&info, &link)) {
    
        // We must have an owned copy of the age before we can offer it, so make one now
        plUUID guid(GuidGenerate());
        info.SetAgeInstanceGuid(&guid);
        std::string title;
        std::string desc;

        unsigned nameLen = plNetClientMgr::GetInstance()->GetPlayerName().GetSize();
        if (plNetClientMgr::GetInstance()->GetPlayerName().CharAt(nameLen - 1) == 's' || plNetClientMgr::GetInstance()->GetPlayerName().CharAt(nameLen - 1) == 'S') {
            xtl::format( title, "%s'", plNetClientMgr::GetInstance()->GetPlayerName().c_str() );
            xtl::format( desc, "%s' %s", plNetClientMgr::GetInstance()->GetPlayerName().c_str(), link.GetAgeInfo()->GetAgeInstanceName() );
        }
        else {
            xtl::format( title, "%s's", plNetClientMgr::GetInstance()->GetPlayerName().c_str() );
            xtl::format( desc, "%s's %s", plNetClientMgr::GetInstance()->GetPlayerName().c_str(), link.GetAgeInfo()->GetAgeInstanceName() );
        }

        info.SetAgeUserDefinedName( title.c_str() );
        info.SetAgeDescription( desc.c_str() );

        link.GetAgeInfo()->CopyFrom(&info);
        if (!VaultRegisterOwnedAgeAndWait(&link)) {
            // failed to become an owner of the age for some reason, offer cannot continue
            return;
        }
    }
    else if (RelVaultNode * linkNode = VaultGetOwnedAgeLinkIncRef(&info)) {
        // We have the age in our AgesIOwnFolder. If its volatile, dump it for the new one.
        VaultAgeLinkNode linkAcc(linkNode);
        if (linkAcc.volat) {
            if (VaultUnregisterOwnedAgeAndWait(link.GetAgeInfo())) {
                plUUID guid(GuidGenerate());
                link.GetAgeInfo()->SetAgeInstanceGuid(&guid);
                VaultRegisterOwnedAgeAndWait(&link);
            }
        }
        linkNode->DecRef();
    }

    if (fSpawnPoint) {
        plSpawnPointInfo spawnPoint;
        spawnPoint.SetName(fSpawnPoint);
        link.SetSpawnPoint(spawnPoint);
    }
    
            
    // We now own the age, offer it

    if (0 == stricmp(fOfferedAgeFile, kPersonalAgeFilename))
        plNetLinkingMgr::GetInstance()->OfferLinkToPlayer(&link, fOffereeID, fManager->GetKey());
    else
        plNetLinkingMgr::GetInstance()->LinkPlayerToAge(&link, fOffereeID);
        
    if (!fPendingLink && stricmp(fOfferedAgeFile, kPersonalAgeFilename))
    {   
        // tell our local dialog to pop up again...
        plKey avKey = plNetClientMgr::GetInstance()->GetLocalPlayerKey();
        ISendOfferNotification(avKey, 0, false);
        // make them clickable again(in case they come back?)
        //IManageIgnoredAvatars(fOffereeKey, false);
        
        fBookMode = kNotOffering;
        fOffereeKey = nil;
        fPendingLink = false;
    }
    else // this is a yeesha book link, must wait for multistage callbacks
    {
        // commented out until after 0.9
        fBookMode = kOfferLinkPending;
        fPendingLink = true;
//          fBookMode = kNotOffering;
//          fOffereeKey = nil;
//          fPendingLink = false;
//          ISendAvatarDisabledNotification(true);
    }
}
コード例 #2
0
ファイル: plNetLinkingMgr.cpp プロジェクト: Filtik/Plasma
uint8_t plNetLinkingMgr::IPreProcessLink(void)
{
    // Grab some stuff we're gonna use extensively
    plNetClientMgr* nc = plNetClientMgr::GetInstance();
    plAgeLinkStruct* link = GetAgeLink();
    plAgeInfoStruct* info = link->GetAgeInfo();

    PreProcessResult success = kLinkImmediately;

    if ( nc->GetFlagsBit( plNetClientMgr::kNullSend ) )
    {
        hsLogEntry( nc->DebugMsg( "NetClientMgr nullsend. Not linking." ) );
        return kLinkFailed;
    }

#if 0
    // Appear offline until we're done linking
    if (RelVaultNode * rvnInfo = VaultGetPlayerInfoNodeIncRef()) {
        VaultPlayerInfoNode accInfo(rvnInfo);
        accInfo.SetAgeInstName(nil);
        accInfo.SetAgeInstUuid(kNilUuid);
        accInfo.SetOnline(false);
        rvnInfo->DecRef();
    }
#else
    // Update our online status 
    if (RelVaultNode * rvnInfo = VaultGetPlayerInfoNodeIncRef()) {
        VaultPlayerInfoNode accInfo(rvnInfo);
        wchar_t ageInstName[MAX_PATH];
        plUUID ageInstGuid = *GetAgeLink()->GetAgeInfo()->GetAgeInstanceGuid();
        StrToUnicode(ageInstName, info->GetAgeInstanceName(), arrsize(ageInstName));
        accInfo.SetAgeInstName(ageInstName);
        accInfo.SetAgeInstUuid(ageInstGuid);
        accInfo.SetOnline(true);
        rvnInfo->DecRef();
    }
#endif

    //------------------------------------------------------------------------
    // Fixup empty fields
    if (info->HasAgeFilename())
    {
        info->SetAgeFilename(plNetLinkingMgr::GetProperAgeName(info->GetAgeFilename()).c_str());

        if (!info->HasAgeInstanceName())
        {
            info->SetAgeInstanceName(info->GetAgeFilename());
        }
    }

    hsLogEntry(nc->DebugMsg( "plNetLinkingMgr: Pre-Process: Linking with %s rules...",
        plNetCommon::LinkingRules::LinkingRuleStr(link->GetLinkingRules())));

    //------------------------------------------------------------------------
    // SPECIAL CASE: StartUp: force basic link
    if (info->GetAgeFilename().CompareI(kStartUpAgeFilename) == 0)
        link->SetLinkingRules( plNetCommon::LinkingRules::kBasicLink );

    //------------------------------------------------------------------------
    // SPECIAL CASE: Nexus: force original link
    if (info->GetAgeFilename().CompareI(kNexusAgeFilename) == 0)
        link->SetLinkingRules(plNetCommon::LinkingRules::kOriginalBook);

    //------------------------------------------------------------------------
    // SPECIAL CASE: ACA: force original link
    if (info->GetAgeFilename().CompareI(kAvCustomizationFilename) == 0)
        link->SetLinkingRules(plNetCommon::LinkingRules::kOriginalBook);

    hsLogEntry(nc->DebugMsg("plNetLinkingMgr: Process: Linking with %s rules...",
        plNetCommon::LinkingRules::LinkingRuleStr(link->GetLinkingRules())));

    switch (link->GetLinkingRules())
    {
        //--------------------------------------------------------------------
        // BASIC LINK. Link to a unique instance of the age, if no instance specified.
        case plNetCommon::LinkingRules::kBasicLink:
            if (!info->HasAgeInstanceGuid()) {
                plUUID newuuid = plUUID::Generate();
                info->SetAgeInstanceGuid(&newuuid);
            }
        break;

        //--------------------------------------------------------------------
        // ORIGINAL BOOK.  Become an owner of the age, if not already one.
        case plNetCommon::LinkingRules::kOriginalBook:
            {
                // create a new ageinfo struct with the filename of the age because
                // we just want to find out if we own *any* link to the age, not the specific
                // link that we're linking through
                plAgeInfoStruct ageInfo;
                ageInfo.SetAgeFilename(info->GetAgeFilename());

                plAgeLinkStruct ownedLink;
                if (!VaultGetOwnedAgeLink(&ageInfo, &ownedLink)) {
                    // Fill in fields for new age create.
                    if (!info->HasAgeUserDefinedName())
                    {
                        // set user-defined name
                        plString title;
                        unsigned nameLen = nc->GetPlayerName().GetSize();
                        if (nc->GetPlayerName().ToLower().CharAt(nameLen - 1) == 's')
                            title = plString::Format("%s'", nc->GetPlayerName().c_str());
                        else
                            title = plString::Format("%s's", nc->GetPlayerName().c_str());
                        info->SetAgeUserDefinedName(title.c_str());
                    }
                    if (!info->HasAgeDescription())
                    {
                        // set description
                        plString desc;
                        unsigned nameLen = nc->GetPlayerName().GetSize();
                        if (nc->GetPlayerName().ToLower().CharAt(nameLen - 1) == 's')
                            desc = plString::Format("%s' %s", nc->GetPlayerName().c_str(), info->GetAgeInstanceName().c_str());
                        else
                            desc = plString::Format("%s's %s", nc->GetPlayerName().c_str(), info->GetAgeInstanceName().c_str());
                        info->SetAgeDescription(desc.c_str());
                    }
                    if (!info->HasAgeInstanceGuid()) {
                        plUUID newuuid = plUUID::Generate();
                        info->SetAgeInstanceGuid(&newuuid);
                    }
                    
                    // register this as an owned age now before we link to it.
                    // Note: We MUST break or the OwnedBook code will fail!
                    VaultRegisterOwnedAge(link);
                    success = kLinkDeferred;
                    break;
                }
                else if (RelVaultNode* linkNode = VaultGetOwnedAgeLinkIncRef(&ageInfo)) {
                    // We have the age in our AgesIOwnFolder. If its volatile, dump it for the new one.
                    VaultAgeLinkNode linkAcc(linkNode);
                    if (linkAcc.GetVolatile()) {
                        if (VaultUnregisterOwnedAgeAndWait(&ageInfo)) {
                            // Fill in fields for new age create.
                            if (!info->HasAgeUserDefinedName())
                            {
                                // set user-defined name
                                plString title;
                                unsigned nameLen = nc->GetPlayerName().GetSize();
                                if (nc->GetPlayerName().ToLower().CharAt(nameLen - 1) == 's')
                                    title = plString::Format("%s'", nc->GetPlayerName().c_str());
                                else
                                    title = plString::Format("%s's", nc->GetPlayerName().c_str());
                                info->SetAgeUserDefinedName(title.c_str());
                            }

                            if (!info->HasAgeDescription())
                            {
                                // set description
                                plString desc;
                                unsigned nameLen = nc->GetPlayerName().GetSize();
                                if (nc->GetPlayerName().ToLower().CharAt(nameLen - 1) == 's')
                                    desc = plString::Format("%s' %s", nc->GetPlayerName().c_str(), info->GetAgeInstanceName().c_str());
                                else
                                    desc = plString::Format("%s's %s", nc->GetPlayerName().c_str(), info->GetAgeInstanceName().c_str());
                                info->SetAgeDescription( desc.c_str() );
                            }

                            if (!info->HasAgeInstanceGuid()) {
                                plUUID newuuid = plUUID::Generate();
                                info->SetAgeInstanceGuid(&newuuid);
                            }

                            VaultRegisterOwnedAge(link);

                            // Note: We MUST break or the OwnedBook code will fail!
                            success = kLinkDeferred;
                            break;
                        }
                    }
                    else {
                        if (info->GetAgeFilename().CompareI(kNeighborhoodAgeFilename) == 0) {
                            // if we get here then it's because we're linking to a neighborhood that we don't belong to
                            // and our own neighborhood book is not volatile, so really we want to basic link
                            link->SetLinkingRules(plNetCommon::LinkingRules::kBasicLink);
                            success = kLinkImmediately;
                            break;
                        }
                    }
                    linkNode->DecRef();
                }
            }

            link->SetLinkingRules(plNetCommon::LinkingRules::kOwnedBook);
            // falls thru to OWNED BOOK case...

        //--------------------------------------------------------------------
        // OWNED BOOK. Look for the book in our AgesIOwn folder
        case plNetCommon::LinkingRules::kOwnedBook:
            {
                plAgeLinkStruct ownedLink;
                if (VaultGetOwnedAgeLink(info, &ownedLink)) {
                    info->CopyFrom(ownedLink.GetAgeInfo());
                    // Remember spawn point (treasure book support)                     
                    plSpawnPointInfo theSpawnPt = link->SpawnPoint();
                    VaultAddOwnedAgeSpawnPoint(*info->GetAgeInstanceGuid(), theSpawnPt);
                }
                else {
                    success = kLinkFailed;
                }
            }
            break;

        //--------------------------------------------------------------------
        // VISIT BOOK. Look for the book in our AgesICanVisit folder
        case plNetCommon::LinkingRules::kVisitBook:
            {
                plAgeLinkStruct visitLink;
                if (VaultGetVisitAgeLink(info, &visitLink))
                    info->CopyFrom(visitLink.GetAgeInfo());
                else
                    success = kLinkFailed;
            }
            break;

        //--------------------------------------------------------------------
        // SUB-AGE BOOK: Look for an existing sub-age in this age's SubAges folder and use it if found.
        //  plNetClientTaskHandler will add a SubAge back link to our current age once we arrive there.
        case plNetCommon::LinkingRules::kSubAgeBook:
            {
                plAgeLinkStruct subAgeLink;
                if (VaultAgeFindOrCreateSubAgeLink(info, &subAgeLink, NetCommGetAge()->ageInstId))
                    info->CopyFrom(subAgeLink.GetAgeInfo());
                else
                    success = kLinkDeferred;
            }
            break;

        //--------------------------------------------------------------------
        // CHILD-AGE BOOK: Look for an existing child-age in this parent ageinfo ChildAges folder and use it if found.
        //  plNetClientTaskHandler will add a ChildAge back link to our current age once we arrive there.
        case plNetCommon::LinkingRules::kChildAgeBook:
            {
                plAgeLinkStruct childLink;
                wchar_t parentAgeName[MAX_PATH];
                if (link->HasParentAgeFilename())
                    StrToUnicode(parentAgeName, link->GetParentAgeFilename(), arrsize(parentAgeName));

                switch(VaultAgeFindOrCreateChildAgeLink(
                      (link->HasParentAgeFilename() ? parentAgeName : nil),
                      info,
                      &childLink))
                {
                    case static_cast<uint8_t>(hsFail):
                        success = kLinkFailed;
                        break;
                    case false:
                        success = kLinkDeferred;
                        break;
                    case true:
                        success = kLinkImmediately;
                }

                if (success == kLinkImmediately)
                    info->CopyFrom(childLink.GetAgeInfo());
            }
            break;

        //--------------------------------------------------------------------
        // ???
        DEFAULT_FATAL(link->GetLinkingRules());
    }

    hsLogEntry(nc->DebugMsg( "plNetLinkingMgr: Post-Process: Linking with %s rules...",
        plNetCommon::LinkingRules::LinkingRuleStr(link->GetLinkingRules())));

    hsAssert(info->HasAgeFilename(), "AgeLink has no AgeFilename. Link will fail.");

    return success;
}