Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an optional path to factorio server-settings.json #851

Merged
merged 2 commits into from
Aug 1, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion FactorioClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ def _handle_color(self, node: JSONMessagePart):
"Refer to Factorio --help for those.")
parser.add_argument('--rcon-port', default='24242', type=int, help='Port to use to communicate with Factorio')
parser.add_argument('--rcon-password', help='Password to authenticate with RCON.')
parser.add_argument('--server-settings', help='Factorio server settings configuration file.')

args, rest = parser.parse_known_args()
colorama.init()
Expand All @@ -410,6 +411,8 @@ def _handle_color(self, node: JSONMessagePart):
factorio_server_logger = logging.getLogger("FactorioServer")
options = Utils.get_options()
executable = options["factorio_options"]["executable"]
server_settings = args.server_settings if args.server_settings else options["factorio_options"]["server_settings"]
server_settings = os.path.abspath(server_settings)

if not os.path.exists(os.path.dirname(executable)):
raise FileNotFoundError(f"Path {os.path.dirname(executable)} does not exist or could not be accessed.")
Expand All @@ -421,7 +424,10 @@ def _handle_color(self, node: JSONMessagePart):
else:
raise FileNotFoundError(f"Path {executable} is not an executable file.")

server_args = ("--rcon-port", rcon_port, "--rcon-password", rcon_password, *rest)
if os.path.isfile(server_settings):
server_args = ("--rcon-port", rcon_port, "--rcon-password", rcon_password, "--server-settings", server_settings, *rest)
else:
server_args = ("--rcon-port", rcon_port, "--rcon-password", rcon_password, *rest)

asyncio.run(main(args))
colorama.deinit()
1 change: 1 addition & 0 deletions Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ def get_default_options() -> dict:
},
"factorio_options": {
"executable": os.path.join("factorio", "bin", "x64", "factorio"),
"server_settings": os.path.join("factorio", "data", "server-settings.json"),
},
"sm_options": {
"rom_file": "Super Metroid (JU).sfc",
Expand Down
2 changes: 2 additions & 0 deletions host.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ sm_options:
rom_start: true
factorio_options:
executable: "factorio\\bin\\x64\\factorio"
# by default, no settings are loaded if this file does not exist. If this file does exist, then it will be used.
server_settings: "factorio\\data\\server-settings.json"
Copy link
Member

@black-sliver black-sliver Aug 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does forward slash work on windows as well? because then i would prefer it to be forward slash for us linux and mac users.

And secondly is there a reason to set it to the that path and not have it use default by default? If not then i think it should default to None in Utils.py and be changed to a comment in host.yaml.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am guessing backslash doesn't work in linux / mac environments. Forward slashes do work in windows environments, in which case, by extension, the executable path should be converted to forward slashes as well.

minecraft_options:
forge_directory: "Minecraft Forge server"
max_heap_size: "2G"
Expand Down