aboutsummaryrefslogtreecommitdiff
path: root/client/server.gd
diff options
context:
space:
mode:
Diffstat (limited to 'client/server.gd')
-rw-r--r--client/server.gd46
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)