Mass editing of Room Variables

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

Mass editing of Room Variables

Postby Aet » 08 Feb 2023, 20:19

Hi, we are needing to change a number of room variables on our server with some simple logic mapping them.

For example:
Any room variables with a value of "elephant" changed to a value of "giraffe"
Any room variables with a value of "cheetah" changed to a value of "mongoose"
And many other mappings, in the realm of ~100, all of which are String values.

We would ideally not like to add extension code for this one time change, and of course we wouldn't want to manually edit these with a client either.

Editing the values in RoomData appears to result in an Unknown SFSDataType error (ID: 115) causing loading the rooms to fail.

Is it possible to edit these files directly with a bash script or simple find and replace in a tool like Notepad++? That would be easiest, before we would have to have a custom client script that connects and edits these room variables with UpdateRoomVariable requests.
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Mass editing of Room Variables

Postby Lapo » 09 Feb 2023, 08:45

Hi,
it's not very clear if these changes need to be applied in the actual live Rooms or somewhere else?
Since you've mentioned RoomData I assume you're trying to change these values in the room files that are stored locally by the server?

Unfortunately these files are stored as binary data and there's no easy way to edit them just by changing the strings contained inside. This is because every object is also accompanied by some metadata (such as its type and length).

To automate the transfomation of these files you would need to copy the room data files to a local SFS2X and write an extension that loads them up, applies the changes and saves them back to local files. Then you could move the files back to the production server.

It's actually pretty simple to do via the Room Persistence API. Check the first example here:
http://docs2x.smartfoxserver.com/Advanc ... stence-api

It loads all the locally stored Room data files, giving you back a List of CreateRoomSettings objects that you can modify.
The next step would be to create each Room with the new settings and proceed with storing the back to disk, calling the persistence API's saveAllRoom() method.

In other words:
- copy the production Room data to local server
- create a Zone with the same name in the local server and attach your Extension
- in the init() of the Extension load all Rooms
- cycle through each CreateRoomSetting object and
    -- apply the changes
    -- create the Room
- invoke the persistence API saveAllRooms()

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

Re: Mass editing of Room Variables

Postby Aet » 13 Feb 2023, 05:22

Yeah, that's a good potential solution. Yeah we saw we can't simply edit the binary files, we are trying to set room variables in a live server yes.

And yes, we use the Room Persistence API already to save all that data and keep our Room Variables static between restarts,

Our other potential solution would be modifying a stress test client to log in and iterate through each room and send RoomVariableUpdate requests, but I think the custom extension you recommend may be easier.

Return to “SFS2X Questions”

Who is online

Users browsing this forum: Google [Bot] and 100 guests