Where should I store MMORoom "config"?

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
Jihaysse
Posts: 11
Joined: 28 Aug 2021, 12:23

Where should I store MMORoom "config"?

Postby Jihaysse » 25 Oct 2021, 21:47

Hello,

I have a JSON file for each of my MMORoom which contains the BattleGrids. A MMORoom is a zone (e.g. Forest) that can have one or more BattleGrids.
BattleGrids are basically an ID and a List<Cell>.

I'd like to store these data as persistant data in a MMORoom. The BattleGrids are not subject to change. They are manually defined in the Unity Editor, saved as JSON and now my goal is to export them to the server so the server knows about the map data.
BattleGrids are:
* Unique to a MMORoom
* One persistant BattleGrid (for monsters spawning, never destroyed) + other instances of the same BattleGrid every time a player starts a fight (otherwise, Cell at index 4 could be taken in another fight but not in ours).
* Used to spawn monsters on it when the server initializes (server-side extension)
* Sent to a player when he enters a fight with a monster

I've searched the forum and it looks like RoomVariables aren't the right place to place this data. Maybe I should place the JSON files in a folder under sfs2x/? Is there a built-in way to load JSON in the server-side extension?

Thank you for your help!

Kind regards,
Jihaysse
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Where should I store MMORoom "config"?

Postby Lapo » 26 Oct 2021, 13:27

Hi,
local file system or a database are probably the best options for storage.
As regards the API for local file system, you can just use Java standard API. Since JSON is text-based you can load the files using one of these code snippets:
https://howtodoinjava.com/java/io/java- ... -examples/
(NOTE: SFS2X uses Java 8 by default)

If you need to associate each JSON map file with an ID and store this data in the MMORoom object (for ease of access) you can do so by using the SFSRoom.getProperty() and SFSRoom.setProperty() methods (MMORoom is a subclass of SFSRoom).

These key/value pairs are server-side only, so they are accessible to your Extension code, but not to clients.

More on this:
docs2x.smartfoxserver.com/api-docs/javadoc/server/com/smartfoxserver/v2/entities/SFSRoom.html

Cheers
Lapo
--
gotoAndPlay()
...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 52 guests