I need a config file for my game with some values, so if I need to balance my game, users don't need to update the whole client, the server takes care of it.
So I made a txt file and read data from it (in the single player version). In multiplayer, instead of fetching the file from some random url, I want that the server fetch the file from a directory and passes that values. Is this still correct in this architecture?
If everything is ok, should I place the file in the SFS2X root directory or is recommended some location for improved security?
Read custom game config file
Re: Read custom game config file
Hi,
we already provide a simple mechanism for loading custom configs in your Extension, via properties files.
By default the server expects a file called config.properties in the same folder where you deploy your Extension's jar files.
The .properties file is a simple key-value test file such as:
In your init method you can access these values like this:
All values are returned as String, so if you're using numbers or booleans you will need to cast them appropriately.
Check the documentation here for more details:
http://docs2x.smartfoxserver.com/Advanc ... extensions
under the Custom configuration section
cheers
we already provide a simple mechanism for loading custom configs in your Extension, via properties files.
By default the server expects a file called config.properties in the same folder where you deploy your Extension's jar files.
The .properties file is a simple key-value test file such as:
Code: Select all
fruit=apple
color=yellow
taste=sweet
In your init method you can access these values like this:
Code: Select all
@Override
public void init()
{
String fruit = getConfigProperties().get("fruit");
String color = getConfigProperties().get("color");
// etc...
}
All values are returned as String, so if you're using numbers or booleans you will need to cast them appropriately.
Check the documentation here for more details:
http://docs2x.smartfoxserver.com/Advanc ... extensions
under the Custom configuration section
cheers
Re: Read custom game config file
Great! And if I change that file, the extension automatically reloads it or I have to restart the server?
Re: Read custom game config file
And there's a special syntax for this file? JSON? XML? Custom? I need to retrieve an int[][] can I from that .properties file?
I looked into the Unity examples and can't find a .properties file to look how it's done
EDIT: getConfigProperties is not found and no dependency is auto imported on Intellij Idea
I looked into the Unity examples and can't find a .properties file to look how it's done
EDIT: getConfigProperties is not found and no dependency is auto imported on Intellij Idea
Re: Read custom game config file
DarkSlash wrote:Great! And if I change that file, the extension automatically reloads it or I have to restart the server?
No, the file is not automatically reloaded, but you can force an Extension reload which will also trigger the reloading of the file itself.
This is done via the Admin Tool > Zone Manager: choose your Zone, select the Extension tab and hit Reload.
And there's a special syntax for this file? JSON? XML? Custom? I need to retrieve an int[][] can I from that .properties file?
Properties files in java are key,value string pairs. There is no JSON or XML parsing involved.
Every pair of strings is written on one line, as the example I provided earlier.
If you need to define multidimensional arrays of data then you probably need something more advanced, such as JSON. You can store your own text file in the Extension folder and then load it in in the init() method of your code.
Here's an example of how to read a file into a String:
http://jdevelopment.nl/java-7-oneliner- ... le-string/
Then you can decode it with the JSON library included in SFS2X:
Code: Select all
JSONObject jso = JSONObject.fromObject(jsonString);
This in turn requires that you add lib/json-lib-2.2.3-jdk15.jar to your project's dependencies.
hope it helps
Re: Read custom game config file
What would be the path to the Extention folder location? I need to read a file from the extension folder.
Re: Read custom game config file
Hi,
from within your Extension call this method:
Cheers
from within your Extension call this method:
Code: Select all
String path = getCurrentFolder();
Cheers
Re: Read custom game config file
That was simple.
Thanks for the prompt response.
On a different matter, do you know anyone that had successfully implemented Firestore database with an extension. I need to dump some text data, but running in trouble with the Google Credentials and jar dependencies. Willing to pay for the working sample code and proper set of jars I need to add to SFS. When I pull the Google libraries from Maven SFS complains about the version of some of the dependency. It was a pain to go search for each specific version to silence SFS error. I'm running test environment SFS 2.16.3 on MacOS Big Sur.
If I open my Firestore collection for the public to create documents, I have no trouble using Google's RESR API.
Thanks for the prompt response.
On a different matter, do you know anyone that had successfully implemented Firestore database with an extension. I need to dump some text data, but running in trouble with the Google Credentials and jar dependencies. Willing to pay for the working sample code and proper set of jars I need to add to SFS. When I pull the Google libraries from Maven SFS complains about the version of some of the dependency. It was a pain to go search for each specific version to silence SFS error. I'm running test environment SFS 2.16.3 on MacOS Big Sur.
If I open my Firestore collection for the public to create documents, I have no trouble using Google's RESR API.
Re: Read custom game config file
Hi,
I am not aware of customers using Firestore with SFS2X, although many don't tell us what they use
I took a quick look at this:
https://github.com/googleapis/java-firestore
and it says the basic requirement is Java7, so SFS2X should work just fine as it runs with Java8 out of the box.
Shouldn't Maven take care of pulling all the necessary dependencies for the project?
Unfortunately I know very little about Firestore, so I'd recommend checking their docs for further help.
I am not aware of customers using Firestore with SFS2X, although many don't tell us what they use
When I pull the Google libraries from Maven SFS complains about the version of some of the dependency.
I took a quick look at this:
https://github.com/googleapis/java-firestore
and it says the basic requirement is Java7, so SFS2X should work just fine as it runs with Java8 out of the box.
Shouldn't Maven take care of pulling all the necessary dependencies for the project?
Unfortunately I know very little about Firestore, so I'd recommend checking their docs for further help.
Re: Read custom game config file
Thanks and Happy Holidays !!!
Who is online
Users browsing this forum: No registered users and 36 guests