When exploring ways to better manage the commandline on Arma servers I came by a neat way to modify the commandline via scripts.
To outline the use case I was dealing with. With Arma servers there are a huge number of mod configurations that can be run. In many cases customers want to just click a button without having to deal with commandline editing. However, this becomes an issue with specific mods that have optional pieces that require other mods. An example of this is Arma 3 Epoch using the Esseker map. To run this you must install Epoch, All in Arma Terrain pack and Esseker. The problem here is all of these mods can be used by themselves for different reasons. If you provide an installer for each in the control panel the customer would need to correctly modify their commandline on their own.
However, I discovered that you can directly edit the UnparsedCommandLine variable during mod install and save it. This allows you to implement custom logic during mod install that can parse and modify the commandline.
In it’s simplest form it would look like this in an Iron Python After Mod Install script.
ThisService.UnparsedCommandLine += ' -SomeNewValue' ThisService.Save()
For my specific use the -mod= section needed to be targeted to insert a mod but leave the rest of the commandline intact.
My solution was:
new_mod = "@Esseker" final_cl = "" for arg in ThisService.UnparsedCommandLine.split(): if "=" in arg: param, value = arg.split("="), arg.split("=") if param == "-mod": final_cl += arg + ";" + new_mod else: final_cl += " " + arg else: final_cl += " " + arg ThisService.UnparsedCommandLine = final_cl ThisService.Save()
To maintain the original commandline and insert of new value we need to parse it to location the -mod=. Everything else gets appended to the commandline as is.
Line 3: We split the whole commandline on spaces and loop through each value
Line 4: We check if the argument has = in it. If it does not, we just append it to the final commandline. If it does, we check if it’s the -mod one
Line 5: We split the -param=value on the = sign so we get the -param and the value in separate variables
Line 6: If it’s the -mod= we append our new mod to it and stick it into the final commandline
Line 13: We save the service so our new commandline is written to the database
This can be employed with each mod. This allows customers to click install and not worry about the commandline.
A similar technique can be employed during mod Uninstall to remove mods from the commandline. I will do a writeup on this in a future post.