Setup and server installation tested on Windows and Linux
This commit is contained in:
parent
a3789e6d74
commit
29bb6d7169
3 changed files with 36 additions and 2 deletions
|
|
@ -17,9 +17,11 @@ function getEnginePath() {
|
||||||
|
|
||||||
// Get the current directory (fairy-chess-server)
|
// Get the current directory (fairy-chess-server)
|
||||||
const currentDir = __dirname;
|
const currentDir = __dirname;
|
||||||
|
console.log(currentDir )
|
||||||
|
|
||||||
// Navigate up to Assets/ChessEngines
|
// Navigate up to Assets/ChessEngines
|
||||||
const engineBaseDir = path.join(currentDir, '..', '..');
|
const engineBaseDir = path.join(currentDir, '..', '..');
|
||||||
|
console.log(engineBaseDir )
|
||||||
|
|
||||||
// Determine OS and set appropriate path
|
// Determine OS and set appropriate path
|
||||||
if (os.platform() === 'win32') {
|
if (os.platform() === 'win32') {
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ var log_dir: String = ""
|
||||||
var log_string: String = ""
|
var log_string: String = ""
|
||||||
var running := false
|
var running := false
|
||||||
var server_process_id: int = -50
|
var server_process_id: int = -50
|
||||||
|
var request_timer: Timer
|
||||||
|
|
||||||
var server_url = "http://localhost:27531"
|
var server_url = "http://localhost:27531"
|
||||||
|
|
||||||
|
|
@ -121,17 +122,48 @@ func start_server() -> bool:
|
||||||
add_child(http_request)
|
add_child(http_request)
|
||||||
# http_request.connect("request_completed", self._on_init_request_completed)
|
# http_request.connect("request_completed", self._on_init_request_completed)
|
||||||
http_request.request_completed.connect(self._on_init_request_completed)
|
http_request.request_completed.connect(self._on_init_request_completed)
|
||||||
|
|
||||||
|
request_timer = Timer.new()
|
||||||
|
add_child(request_timer)
|
||||||
|
request_timer.wait_time = 2.0 # 2 seconds
|
||||||
|
request_timer.one_shot = true
|
||||||
|
request_timer.timeout.connect(self._on_request_timeout)
|
||||||
|
request_timer.start()
|
||||||
http_request.request(server_url + "/health")
|
http_request.request(server_url + "/health")
|
||||||
|
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
|
|
||||||
|
func _on_request_timeout():
|
||||||
|
write_log("Request timed out, starting server manually")
|
||||||
|
# Clean up timer
|
||||||
|
request_timer.queue_free()
|
||||||
|
request_timer = null
|
||||||
|
# Call your secondary processing function here
|
||||||
|
write_log("HTTP Request failed, starting server process")
|
||||||
|
write_log(server_path + "/index.js")
|
||||||
|
server_process_id = OS.create_process("node", [server_path + "/index.js"])
|
||||||
|
write_log("SERVER PATH " + server_path)
|
||||||
|
if server_process_id <= 0:
|
||||||
|
printerr("Failed to start server")
|
||||||
|
write_log("ERROR: Failed to start server, process ID: " + str(server_process_id))
|
||||||
|
|
||||||
|
return false
|
||||||
|
|
||||||
|
running = true
|
||||||
|
write_log("Chess server started with PID: " + str(server_process_id))
|
||||||
|
return
|
||||||
|
|
||||||
func _on_init_request_completed(result: int, response_code: int, headers: PackedStringArray, body: PackedByteArray):
|
func _on_init_request_completed(result: int, response_code: int, headers: PackedStringArray, body: PackedByteArray):
|
||||||
write_log("*****************_on_init_request_completed************")
|
write_log("*****************_on_init_request_completed************")
|
||||||
|
if request_timer:
|
||||||
|
request_timer.stop()
|
||||||
|
request_timer.queue_free()
|
||||||
|
request_timer = null
|
||||||
var json = JSON.new()
|
var json = JSON.new()
|
||||||
json.parse(body.get_string_from_utf8())
|
json.parse(body.get_string_from_utf8())
|
||||||
var response = json.get_data()
|
var response = json.get_data()
|
||||||
# Will write_log the user agent string used by the HTTPRequest node (as recognized by httpbin.org).
|
|
||||||
write_log("Init request completed")
|
write_log("Init request completed")
|
||||||
write_log("Result: " + str(response))
|
write_log("Result: " + str(response))
|
||||||
if response == null:
|
if response == null:
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ advanced_options=true
|
||||||
dedicated_server=false
|
dedicated_server=false
|
||||||
custom_features=""
|
custom_features=""
|
||||||
export_filter="all_resources"
|
export_filter="all_resources"
|
||||||
include_filter=""
|
include_filter="Assets/*"
|
||||||
exclude_filter=""
|
exclude_filter=""
|
||||||
export_path="build/Windows/ChessBuilder.exe"
|
export_path="build/Windows/ChessBuilder.exe"
|
||||||
encryption_include_filters=""
|
encryption_include_filters=""
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue