Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.

Baton or not baton

Avatar

Former Community Member
Good morning AFCS fans,



I working on a simple mutiplayer game based on AFCS. In this
game, players play after each other so I have to manage turns.

I've tried using the SharedModel of the game to dael with
that. The first player connected to the room gets the owner role
and is responsible to manage the turns. I'm using the AFCS roles to
give and take the right to play: the current player has Publisher's
role and all others have Viewer role on the node.

So, in my application, when someone looses, he looses his
Publisher role and the Owner assigns it to the next player. That's
where I fail...

I'm using the following code to find the next player:


quote:



_collectionNode.setUserRole(p_evt.userID, UserRoles.VIEWER,
NODENAME_SELECT);

var
currentPlayerDesc:UserDescriptor=_userManager.getUserDescriptor(p_evt.userID);

var
currentPlayerIndex:int=_userManager.participantCollection.getItemIndex(currentPlayerDesc);

if
(currentPlayerIndex==_userManager.participantCollection.length-1)
currentPlayerIndex=-1;

var
newPlayer:String=_userManager.userCollection.getItemAt(currentPlayerIndex+1)
as String

_collectionNode.setUserRole(newPlayer, UserRoles.PUBLISHER,
NODENAME_SELECT);





My first problem is that the current player descriptor is
null... So, it can't work.



So, my questions are:

- Should I use the Baton class instead of doing it in my
SharedModel?

- What do I do wrong to get a void descriptor?



Is there an exemple somewhere of a similar token-based access
right?



Thanks a lot in advance,



Axel
3 Replies

Avatar

Former Community Member
Hi ,



I have a couple of questions. You want to change the role of
the user in the app or change the role of the user for your
collection node's node. Because, if you want to change the role of
the user, just use
_userManager.setUserRole(p_evt.userID,UserRoles.VIEWER);

Also, once you set the role, you should wait it for being
updated on listening to UserRoleChange event from usermanager for
this user.

This user will get assigned to audienceCollection and will be
also updated in the usercollection (which has everyone). Now, from
audienceCollection you can search a user to promote to publisher (
you can keep a table of which users have been given chance already
for avoiding same user) . And then call
_userManager.serUserRole(newuserID,UserRole.Publisher) on it.

I could not understand why you need to search in
participantcollection since it will have only one user as per your
description.



Lastly, you can use baton classes to give and take control,
and you won't have to use userrole functions and change useroles in
that case.



Hope this makes clear. If you are not able to get through,
paste the sharedmodel code and I can debug.

Thanks

Hironmay Basu



Avatar

Former Community Member
Hi,



Your question about changing the role in the application or
in the node is very valid. I'll reconsider changing the role in the
whole application.

In the next player selection, my main issue is to find the
current player index in the list of users based on its UserID or
descriptor, to be able to demote him and promote the next one. But,
I can't see a method to find a User in the userCollection by
UserID.

I can keep track of the index of the current player in the
userCollection or a list of the userIDs, but it's a bit risky in
case players leave the room.



For the Baton versus Role in the application, what seems to
you more appropriate?



Thanks a lot for your help,



Axel



PS: I'm indeed using the userCollection and not
participantCollection (I made a mistake when copying the
code).

Avatar

Former Community Member
Hi,

>> But, I can't see a method to find a User in the
userCollection by UserID. What you mean by this ?

The method getUserDescriptor(p_userID) returns the entire
user info(userdescritor) for the user specified by the user id.

Whenever any user is in a room, this method will always
return the userdescritor. Are you getting null for this ? In that
case, put a breakpoint inside this API of UserManager by linking
the source and see whether the _userDescriptor table inside
usermanager has this user or not ?

For keeping a track of user, you can listen to userCreate and
userRemove to update your table locally if players enter/leave.



Lastly, regarding baton, I think it will work for your case.
where you give the baton control to the current user playing the
game. Go over the list of APIs in BatonProperty and Baton classes
and give it a shot. But your current approach should also work.

Update us with the info after doing the steps above.



Thanks

Hironmay Basu