aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client/global.gd12
-rw-r--r--client/server.gd29
2 files changed, 34 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 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)