Sending RoomVariable through ExtensionRequest

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

User avatar
Aet
Posts: 34
Joined: 15 Aug 2019, 23:10

Sending RoomVariable through ExtensionRequest

Postby Aet » 21 Aug 2020, 22:35

Hi, I'm working on swapping all my SetRoomVariablesRequest calls to use a custom extension request so I can better control security and permission-ing of who can change certain RoomVariables.

As far as I can tell I cannot send an array of Room Variables directly with an extension request, adding it to the message object like when I use a SetRoomVariablesRequest directly. Am I correct in this assumption?

To get around this I was working with the ToSFSArray method on my room variables to send them to the server. Here is my client code:

Code: Select all

public static void SendRoomVarUpdateRequest(String roomName, List<RoomVariable> roomVariables)
 {
   SFSArray roomVariablesArray = new SFSArray();
        foreach (RoomVariable rmVar in roomVariables) {
            roomVariablesArray.AddSFSArray(rmVar.ToSFSArray());
        }

        ISFSObject msgObj = new SFSObject();
        msgObj.PutUtfString("room", roomName);
        msgObj.PutSFSArray("rmVars", roomVariablesArray);
        ExtensionRequest request = new ExtensionRequest("rmVar", msgObj);
        CommunicationManager.SendMsg(request);
}


Is this the best approach to solve this problem? Or is there a way to more directly send a room variable to the server?

If this is the best way I was having trouble finding any documentation on what the output of ToSFSArray() actually corresponds to to recreate the room variable on the server side. How can I regenerate the RoomVariable from an SFSArray?

Thanks for the help!
User avatar
Lapo
Site Admin
Posts: 23009
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Sending RoomVariable through ExtensionRequest

Postby Lapo » 24 Aug 2020, 08:05

Hi,
what you're doing is correct. In order to recreate the variable on the server side you can do this:

Code: Select all

SFSRoomVariable var = SFSRoomVariable.newFromSFSArray(arr);


Cheers
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
Aet
Posts: 34
Joined: 15 Aug 2019, 23:10

Re: Sending RoomVariable through ExtensionRequest

Postby Aet » 24 Aug 2020, 16:25

I'm shocked I missed that in the documentation! But glad I am doing things the correct way.

Thanks for the help!

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 58 guests