Jump to content

Open Community  ·  46 members

Valheim

[Mod Request] Server Config Sync


Cadaver84

Recommended Posts

I would like a mod that allows Servers to send config values to clients for load at run time, similar to how V+ does syncConfigServer, but for any/all mods.

 

I am looking at Valheim+ GitHub and talking to their devs about how they do syncConfigServer, and what they do is have the server send the config values at run time, so that the clients config file isn't changed.

 

What I want is the ability for a server to be able to send config values for all mods loaded on the server.

 

What I would do I think, is pull the code from V+ that does the sync (it basically just reads in the config file, and then sends it to the client stripped of comments), and slightly modify it:

 

The snippet from V+ that does this looks like this:

if (!Configuration.Current.Server.IsEnabled || !Configuration.Current.Server.serverSyncsConfig) return; ZPackage pkg = new ZPackage(); string[] rawConfigData = File.ReadAllLines(ConfigurationExtra.ConfigIniPath); List<string> cleanConfigData = new List<string>(); for (int i = 0; i < rawConfigData.Length; i++) { if (rawConfigData[i].Trim().StartsWith(";") || rawConfigData[i].Trim().StartsWith("#")) continue; //Skip comments if (rawConfigData[i].Trim().IsNullOrWhiteSpace()) continue; //Skip blank lines //Add to clean data cleanConfigData.Add(rawConfigData[i]); } //Add number of clean lines to package pkg.Write(cleanConfigData.Count); //Add each line to the package foreach (string line in cleanConfigData) { pkg.Write(line); } ZRoutedRpc.instance.InvokeRoutedRPC(sender, "VPlusConfigSync", new object[] { pkg });

 

What I think I would do is nest:

for (int i = 0; i < rawConfigData.Length; i++) { if (rawConfigData[i].Trim().StartsWith(";") || rawConfigData[i].Trim().StartsWith("#")) continue; //Skip comments if (rawConfigData[i].Trim().IsNullOrWhiteSpace()) continue; //Skip blank lines //Add to clean data cleanConfigData.Add(rawConfigData[i]); }

 

this part under another for loop that did it for each mod config file in various directories.

 

I assume I would want an API for this mod that allows the user to define the mods in use and the names of their config files, and where to pull the values from on the server. I have someone who is willing to write the API for it, I would just like help writing the Mod part and implementing the config sync. I am willing to help, though I am not familiar with C#.

A 'nice to have' feature would be to allow the creation of different groups of configs so that you can define in game 'character classes' that get different config values published. Example: Everyone else has 270 seconds per ingot on the smelter configured in their V+, but if a whitelisted client is attempting to connect, and their ID is filed under a "Blacksmith" tag, they get a config file where smelter time is set to 60 seconds.

 

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...