diff options
| -rw-r--r-- | client/global.gd | 12 | ||||
| -rw-r--r-- | client/server.gd | 45 | 
2 files changed, 50 insertions, 7 deletions
| diff --git a/client/global.gd b/client/global.gd index f26a066f..49b5f72e 100644 --- a/client/global.gd +++ b/client/global.gd @@ -28,9 +28,13 @@ var default_settings := {  		"value": true,  		"description": tr("Interpolate the camera rotation")  	}, -	"test": { -		"value": "hehe", -		"description": tr("Just a test value") +	"server_binary": { +		"value": "", +		"description": tr("The path of the server binary (leave empty to search PATH)") +	}, +	"server_data": { +		"value": "", +		"description": tr("The path of the server data directory (leave empty to auto-detect)")  	},  } @@ -68,6 +72,8 @@ func load_dict(path: String, default: Dictionary) -> Dictionary:  		for i in default.keys():  			if saved_dict.has(i):  				res[i] = saved_dict[i] +			else: +				res[i] = default[i]  	print("Loaded dict: ", res)  	return res diff --git a/client/server.gd b/client/server.gd index 972e1f2d..8eaaaecb 100644 --- a/client/server.gd +++ b/client/server.gd @@ -1,3 +1,19 @@ +# Undercooked - a game about cooking +# Copyright 2024 metamuffin +# Copyright 2024 nokoe +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, version 3 of the License only. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program.  If not, see <https://www.gnu.org/licenses/>. +#  class_name GameServer  extends Node @@ -22,9 +38,11 @@ func _ready():  	thread = Thread.new()  	thread.start(_test_server) +func test(): +	pass  func start(): -	if state != State.STOPPED and state != State.FAILED:  +	if state != State.STOPPED and state != State.FAILED:  		push_error("server cant be started")  		return  	state = State.STARTING @@ -39,11 +57,16 @@ func stop():  func _test_server():  	var output = [] -	thread_result = OS.execute("undercooked-server", ["-v"], output, true, false) +	thread_result = OS.execute(get_server_path(), ["-v"], output, true, false)  	sem.post()  func _server_exec(): -	thread_result = OS.create_process("undercooked-server", [], false) +	var args = [] +	var data_path = get_server_data() +	if data_path != null: +		args.push_back("--data-dir") +		args.push_back(data_path) +	thread_result = OS.create_process(get_server_path(), args, false)  	if thread_result >= 0:  		var ok = false  		while not ok: @@ -59,6 +82,20 @@ func _server_exec():  				break  	sem.post() +func get_server_path() -> String: +	var path: String = Global.settings["server_binary"]["value"] +	if FileAccess.file_exists(path): +		return path +	else: +		return "undercooked-server" + +func get_server_data(): +	var path: String = Global.settings["server_data"]["value"] +	if FileAccess.file_exists(path): +		return path +	else: +		return null +  func _process(_delta):  	match state:  		State.TESTING: @@ -70,7 +107,7 @@ func _process(_delta):  				thread = null  		State.STARTING:  			if sem.try_wait(): -				if thread_result >= 0:  +				if thread_result >= 0:  					state = State.RUNNING  					pid = thread_result  					print("Server: Started pid=", thread_result) | 
