diff options
| author | nokoe <nokoe@mailbox.org> | 2024-06-27 12:45:45 +0200 | 
|---|---|---|
| committer | nokoe <nokoe@mailbox.org> | 2024-06-27 12:45:45 +0200 | 
| commit | b0363cf5b56837b74308d4335d7f189f843ea770 (patch) | |
| tree | 04c49977df4eaeee4b1a64446cad82e5889c5841 /client/server.gd | |
| parent | beedaa3079119f970fdb1ca51395b343443a6778 (diff) | |
| download | hurrycurry-b0363cf5b56837b74308d4335d7f189f843ea770.tar hurrycurry-b0363cf5b56837b74308d4335d7f189f843ea770.tar.bz2 hurrycurry-b0363cf5b56837b74308d4335d7f189f843ea770.tar.zst  | |
add server data/path setting
Diffstat (limited to 'client/server.gd')
| -rw-r--r-- | client/server.gd | 29 | 
1 files changed, 25 insertions, 4 deletions
diff --git a/client/server.gd b/client/server.gd index 11e8024c..ce8b671c 100644 --- a/client/server.gd +++ b/client/server.gd @@ -22,9 +22,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 +41,16 @@ func stop():  func _test_server():  	var output = [] -	thread_result = OS.execute("undercooked-server", ["version"], output, true, false) +	thread_result = OS.execute(get_server_path(), ["version"], 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 +66,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 +91,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)  |