Best way to access build configuration vars (in server.json?)

Hey all!

Been reading the docs and am trying to find the best way to read our build configuration variables into our dedicated server on startup. I also wasn't sure exactly when to do the reading because the docs say the build configuration variables are written to the server.json file after startup.

Basically, our use case is that we'd like to connect to an external data source, and would like to put the host, port, credentials into configuration variables (similar to how we put them into kubernetes secrets in our other services - although I realize these aren't necessarily secrets as GSH build config vars - though would be nice if they were) - and connect to said service when the game server starts up.

A bit surprised I haven't been able to find a sample class for this... although I do see a ServerConfigReader in the Multiplay sdk, then I see a reference "MultiplayService.Instance.ServerConfig.AllocationId" in the BR200 code - but this ServerConfig class won't let me get at my custom variables...

Are there any insights as to best practices in this regard?

1 Like

Also looking for an answer to this. I don't care if I have to parse server.json directly but I can't even find where it is.

Docs state where it is IF you are using a container.

If not using a container, it says the file is relative to the binary in the "Server ID" folder. But doesn't mention what a "server ID folder" is.

Guess I could trawl the filesystem to find out...

I found it, I had an inkling it was there from the docs but didn't trust it.

        var home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
        var serverJsonFile = Path.Join(home, "server.json");
        if (File.Exists(serverJsonFile))
            var serverJson = File.ReadAllText(serverJsonFile);