diff options
author | metamuffin <metamuffin@disroot.org> | 2024-06-27 17:21:52 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-06-27 17:21:52 +0200 |
commit | 82408a6d478ed9f7009482c69f1f4d69025c833d (patch) | |
tree | 2d27c799917c2d44417882fd04cfff37e25cd18b /client/server.gd | |
parent | 4fa692dae19789e5e766c50ac31874653d02971a (diff) | |
parent | 86eaa98918760ed829f23a70f15604bf751549be (diff) | |
download | hurrycurry-82408a6d478ed9f7009482c69f1f4d69025c833d.tar hurrycurry-82408a6d478ed9f7009482c69f1f4d69025c833d.tar.bz2 hurrycurry-82408a6d478ed9f7009482c69f1f4d69025c833d.tar.zst |
Merge branch 'master' of https://codeberg.org/metamuffin/undercooked
Diffstat (limited to 'client/server.gd')
-rw-r--r-- | client/server.gd | 46 |
1 files changed, 42 insertions, 4 deletions
diff --git a/client/server.gd b/client/server.gd index 972e1f2d..b0ab5188 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,17 @@ 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) + print(get_server_path(), args) if thread_result >= 0: var ok = false while not ok: @@ -59,6 +83,20 @@ func _server_exec(): break sem.post() +func get_server_path() -> String: + var path: String = Global.settings["server_binary"]["value"] + if path != "": + return path + else: + return "undercooked-server" + +func get_server_data(): + var path: String = Global.settings["server_data"]["value"] + if path != "": + return path + else: + return null + func _process(_delta): match state: State.TESTING: @@ -70,7 +108,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) |