PDA

View Full Version : Database nodes and connected clients



Ken L
July 6th, 2018, 02:40
What exactly is the criteria for connected clients to access database nodes. It most cases, the host needs to have updated it with the client connected just for it to be visible. Absent of an update the client can't access it. Sometimes the clients never get access to it despite the node being public.

This is handled rather haphazardly.

celestian
July 6th, 2018, 05:21
What exactly is the criteria for connected clients to access database nodes. It most cases, the host needs to have updated it with the client connected just for it to be visible. Absent of an update the client can't access it. Sometimes the clients never get access to it despite the node being public.

This is handled rather haphazardly.

Not sure if this will help but it's some code I used to give users access to nodes so they could edit effects as themselves. I've since re-done how I handled this so it's no longer necessary but it sounds similar to what you're trying to do. Maybe this example will help?



--
--
-- Access to nodes managed for certain places here
--
-- Right now this mainly deals with CT nodes so that players can apply effects
-- that are on items or other areas --celestian
--

function onInit()
User.onIdentityActivation = onIdentityActivation;
end

function onIdentityActivation(sIdentity, sUser, bActivated)
-- Debug.console("manager_Access_adnd.lua","onIdentityActivation","sIdentity",sIdentity);
-- Debug.console("manager_Access_adnd.lua","onIdentityActivation","sUser",sUser);
-- Debug.console("manager_Access_adnd.lua","onIdentityActivation","bActivated",bActivated);
-- Debug.console("manager_Access_adnd.lua","onIdentityActivation","User.getAllActiveIdentities()",User.getAllActiveIdentities());
-- Debug.console("manager_Access_adnd.lua","onIdentityActivation","User.getAllActiveIdentities()",User.getAllActiveIdentities());
if bActivated then
-- give access to CT node it character if exists
local nodeCT = CombatManager.getCTFromNode("charsheet." .. sIdentity);
if nodeCT and sUser ~= "" then
local owner = nodeCT.getOwner();
if owner then
nodeCT.removeHolder(owner);
end
DB.setOwner(nodeCT, sUser);
end
else
-- remove access to CT node if character exists
local nodeCT = CombatManager.getCTFromNode("charsheet." .. sIdentity);
if nodeCT and sUser ~= "" then
local owner = nodeCT.getOwner();
if owner then
nodeCT.removeHolder(owner);
end
end
end
end

-- flip through active users and their active identities and if they match
-- the nodeCT we just added then give them ownership
function manageCTOwners(nodeCT)
for _,vUser in ipairs(User.getActiveUsers()) do
for _,vIdentity in ipairs(User.getActiveIdentities(vUser)) do
local _, sRecord = DB.getValue(nodeCT, "link", "", "");
if (sRecord == ("charsheet." .. vIdentity)) then
DB.setOwner(nodeCT, vUser);
end
end
end
end



I can't find it but I think I also had to cope with players disconnecting then reconnecting.

Ken L
July 9th, 2018, 22:37
Adding holders is a way to force accessibility, and is in general more reliable than setting the node as public. In the area of interest to me however, I don't want to grant ownership, and stringing up a list of holders is a bit unnecessary for juggling.

The main issue is that FG doesn't want to save the <public/> variable which in turn doesn't transmit to clients. Even worse it won't save it to the db.xml for the next session. This however isn't a reliable failure, and using 'list' formats where the base node is public as opposed to individual children helps but is also not guaranteed to persist.

Bidmaron
July 31st, 2018, 16:36
Rather than start a thread, I thought I would piggy back on this as my question is related. Now that moon wizard is back from leave maybe he will reply to Ken.

My question is what happens to nodes created on a client instance of FG? I would assume the owner is automatically set to the user of the client instance?

And I would assume that the original new node contents and any changes to it are sent back to the host for permanent recording in campaign database?

Moon Wizard
July 31st, 2018, 19:11
I didn't see a question from Ken above, and I'm not seeing that issue. I figured Ken would smack me with a clear failure case, if he needed that looked at. ;)

For your questions,
* DB nodes can only be automatically created on the client as children of nodes they already own. Any ownership/viewership information is inherited from the parent node.
* When a database node is created on the client, the information is sent to the host. If the node is also viewable by others, then the update is propagated to the other clients.
* There are some cases where non-value database nodes (i.e. empty lists, base records without values) don't get propagated until a value node is added/updated.
* There is a special API call to request a new child node to be created and assigned ownership to the client. (currently only used for creating characters from the client)

Regards,
JPG

Bidmaron
July 31st, 2018, 21:24
Thanks, jpg. I will look at client db to see what standard nodes will always be available on a client (or use the special api)

Bidmaron
August 3rd, 2018, 03:47
Rocking out and I cannot remember nor find where the db.xml is stored when you use localhost to log on to a gm's campaign?

Moon Wizard
August 3rd, 2018, 03:58
There is no db.xml for the layer instance, just a encrypted cache file of the files shared by the GM.

JPG

Bidmaron
August 3rd, 2018, 04:15
Thanks, MW. Now, the problem I am having is that I am trying to install an owned node update handler in the client instance, but the cache doesn't have the node at onDesktopInit time for the client. Is there another event I cannot figure out where the local cache will have the owned node in it? I know the node exists because I installed a slash handler that lets me display the node's name, and that slash handler shows the node's name. However, the code in onDesktopInit shows nil for the node name.

Bidmaron
August 3rd, 2018, 12:58
Nvm. I figured out an alternative (no rocket science - I just don’t set up the resources until the demand arises. By then, all initialization is done)

Moon Wizard
August 3rd, 2018, 19:17
Just to answer your question. The desktop is initialized after the ruleset/extension files are all downloaded; but before the campaign data has been streamed in. So, onDesktopInit on the client side won't have any data yet.

Regards,
JPG

Bidmaron
August 4th, 2018, 00:23
Thanks for taking the time, MW. I appreciate knowing the answer and figured it was something like that. Someday, it might be helpful to have an onCompletelyInitialized handler where you could sign up to handle anything requiring everything set up but I am good for what I am doing now. I would add it to wishlist but no one ever votes for programming stuff and I don’t currently have a need for it.