diff --git a/scripts/globals/consoler.gd b/scripts/globals/consoler.gd index c8cef38..048405b 100644 --- a/scripts/globals/consoler.gd +++ b/scripts/globals/consoler.gd @@ -2,25 +2,34 @@ extends Node signal message_sent(message: String) -var input_thread: Thread -var stop: bool = false +const SERVER_CONSOLE_INPUT_PATH := "user://server_console_input" +const READING_INTERVAL: float = 10 + +var reading_timer: float = 0 -func _enter_tree() -> void: - input_thread = Thread.new() - input_thread.start(_process_input) +func _process(delta: float) -> void: + if not Networker.is_dedicated or Referencer.chat == null: + return + reading_timer -= delta -func _exit_tree() -> void: - stop = true - input_thread.wait_to_finish() + if reading_timer > 0: + return + reading_timer = READING_INTERVAL -func _process_input() -> void: - var text := "" - while not stop and text != "quit": - text = OS.read_string_from_stdin().strip_edges() - if text and Referencer.chat: - print("Inserted text: ", text) - message_sent.emit(text) - print("STOPPING!") + var file := FileAccess.open(SERVER_CONSOLE_INPUT_PATH, FileAccess.READ) + if not file: + return + + var text := file.get_as_text() + if not text: + return + + message_sent.emit(text) + + file = FileAccess.open(SERVER_CONSOLE_INPUT_PATH, FileAccess.WRITE) + if not file: + return + file.store_string("") diff --git a/scripts/globals/networker.gd b/scripts/globals/networker.gd index bdd48c9..8f9b02e 100644 --- a/scripts/globals/networker.gd +++ b/scripts/globals/networker.gd @@ -7,6 +7,7 @@ const DEFAULT_PORT: int = 10567 const MAX_PEERS: int = 20 var players := {} +var is_dedicated: bool = false var _peer: ENetMultiplayerPeer var _local_player_info := {"name": ""} @@ -35,6 +36,7 @@ func set_local_player_info(username: String) -> void: func host_game(dedicated: bool = false) -> void: print("Hosting...") + is_dedicated = dedicated _peer = ENetMultiplayerPeer.new() var error := _peer.create_server(DEFAULT_PORT, MAX_PEERS)