From d84fdd4d008535926a68faed9cc6c98c4e3a4c01 Mon Sep 17 00:00:00 2001 From: Thorben Date: Fri, 15 May 2020 21:16:48 +0200 Subject: [PATCH] update lobby for online players --- Client/Scenes/Matchmaking/Lobby/Lobby.gd | 15 +++++++ Client/Scenes/Matchmaking/Lobby/Lobby.tscn | 43 +++++++++++++++++++ .../Matchmaking/Networking/Networking_sync.gd | 13 ++++++ Client/export_presets.cfg | 2 +- .../Matchmaking/Networking/Networking_sync.gd | 29 ++++++++----- Server/Scenes/Matchmaking/Server/Server.gd | 5 ++- Server/export_presets.cfg | 2 +- 7 files changed, 94 insertions(+), 15 deletions(-) diff --git a/Client/Scenes/Matchmaking/Lobby/Lobby.gd b/Client/Scenes/Matchmaking/Lobby/Lobby.gd index 9b6a9ec..b7823c4 100644 --- a/Client/Scenes/Matchmaking/Lobby/Lobby.gd +++ b/Client/Scenes/Matchmaking/Lobby/Lobby.gd @@ -5,6 +5,9 @@ const MAX_PLAYERS = 8 const MIN_GAME_NAME_LENGTH = 1 const MAX_GAME_NAME_LENGTH = 20 +func _ready(): + $Lobby/Auto_refresh_timer.start() + func _on_Refresh_button_pressed(): refresh_game_list() @@ -38,10 +41,17 @@ func _on_Cancel_button_pressed(): $Lobby.show() func _on_Exit_button_pressed(): + get_tree().set_network_peer(null) get_tree().change_scene("res://Scenes/Matchmaking/Menu/Menu.tscn") func _on_Lobby_controller_tree_entered(): refresh_game_list() + update_online_players() + +func update_online_players(): + NetworkingSync.update_players_online() + yield(NetworkingSync, "update_players_online") + $Lobby/Online_players/HBoxContainer/Number_of_player.text = str(NetworkingSync.get_number_of_online_players()) func _on_Game_name_line_edit_text_changed(new_text): check_input_fields() @@ -78,3 +88,8 @@ func create_game_room(): var max_players = int($Lobby_game_creation_panel/HBoxContainer2/Number_of_players_line_edit.text) var game_id = get_tree().get_network_unique_id() NetworkingSync.create_game([game_id, game_name, max_players, {}], Player) + + +func _on_Auto_refresh_timer_timeout(): + update_online_players() + refresh_game_list() diff --git a/Client/Scenes/Matchmaking/Lobby/Lobby.tscn b/Client/Scenes/Matchmaking/Lobby/Lobby.tscn index 99cefe5..c30f329 100644 --- a/Client/Scenes/Matchmaking/Lobby/Lobby.tscn +++ b/Client/Scenes/Matchmaking/Lobby/Lobby.tscn @@ -117,6 +117,48 @@ __meta__ = { [node name="Auto_refresh_timer" type="Timer" parent="Lobby"] +[node name="Online_players" type="Control" parent="Lobby"] +margin_left = 902.145 +margin_top = 965.807 +margin_right = 1857.14 +margin_bottom = 1012.81 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="Background" type="ColorRect" parent="Lobby/Online_players"] +anchor_right = 1.0 +anchor_bottom = 1.0 +color = Color( 0.196078, 0.254902, 0.352941, 0.843137 ) +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="HBoxContainer" type="HBoxContainer" parent="Lobby/Online_players"] +anchor_right = 1.0 +anchor_bottom = 1.0 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="Number_of_player" type="Label" parent="Lobby/Online_players/HBoxContainer"] +margin_right = 475.0 +margin_bottom = 47.0 +size_flags_horizontal = 3 +size_flags_vertical = 3 +text = "0" +align = 2 +valign = 1 + +[node name="Player_label" type="Label" parent="Lobby/Online_players/HBoxContainer"] +margin_left = 479.0 +margin_right = 955.0 +margin_bottom = 47.0 +size_flags_horizontal = 3 +size_flags_vertical = 3 +text = "Player" +valign = 1 + [node name="Lobby_game_creation_panel" type="Control" parent="."] visible = false anchor_left = 0.183854 @@ -215,6 +257,7 @@ __meta__ = { [connection signal="pressed" from="Lobby/Lobby_buttons/Create_game_button" to="." method="_on_Create_game_button_pressed"] [connection signal="pressed" from="Lobby/Lobby_buttons/Refresh_button" to="." method="_on_Refresh_button_pressed"] [connection signal="pressed" from="Lobby/Lobby_buttons/Exit_button" to="." method="_on_Exit_button_pressed"] +[connection signal="timeout" from="Lobby/Auto_refresh_timer" to="." method="_on_Auto_refresh_timer_timeout"] [connection signal="text_changed" from="Lobby_game_creation_panel/HBoxContainer/Game_name_line_edit" to="." method="_on_Game_name_line_edit_text_changed"] [connection signal="text_changed" from="Lobby_game_creation_panel/HBoxContainer2/Number_of_players_line_edit" to="." method="_on_Number_of_players_line_edit_text_changed"] [connection signal="pressed" from="Lobby_game_creation_panel/Ok_button" to="." method="_on_Ok_button_pressed"] diff --git a/Client/Scenes/Matchmaking/Networking/Networking_sync.gd b/Client/Scenes/Matchmaking/Networking/Networking_sync.gd index ceaf8df..be8fe43 100644 --- a/Client/Scenes/Matchmaking/Networking/Networking_sync.gd +++ b/Client/Scenes/Matchmaking/Networking/Networking_sync.gd @@ -2,10 +2,12 @@ extends Node signal updated_games signal all_ready +signal update_players_online var _open_games = {} var _player_in_same_game_room_list = [] var _players_ready = [] +var _number_of_online_players func send_open_games_request_to_server(): rpc_id(1, "get_open_games_from_server", get_tree().get_network_unique_id()) @@ -47,3 +49,14 @@ remote func send_host_ready_signal(id): _players_ready.append(id) if len(_players_ready) == len(_player_in_same_game_room_list): emit_signal("all_ready") + +func update_players_online(): + rpc_id(1, "get_online_players", Player.get_player_id()) + + +remote func update_online_players(number_of_players): + _number_of_online_players = number_of_players + emit_signal("update_players_online") + +func get_number_of_online_players(): + return _number_of_online_players diff --git a/Client/export_presets.cfg b/Client/export_presets.cfg index dcceb70..2b02758 100644 --- a/Client/export_presets.cfg +++ b/Client/export_presets.cfg @@ -75,7 +75,7 @@ custom_features="" export_filter="all_resources" include_filter="" exclude_filter="" -export_path="../../Godot_Executables/Godot_client_web/Client_project.html" +export_path="../../Godot_Executables/Client_web/Client_project.html" patch_list=PoolStringArray( ) script_export_mode=1 script_encryption_key="" diff --git a/Server/Scenes/Matchmaking/Networking/Networking_sync.gd b/Server/Scenes/Matchmaking/Networking/Networking_sync.gd index 02f1f82..e8ba620 100644 --- a/Server/Scenes/Matchmaking/Networking/Networking_sync.gd +++ b/Server/Scenes/Matchmaking/Networking/Networking_sync.gd @@ -4,6 +4,13 @@ extends Node var _open_games = {} var _players_online = [] +var _number_of_online_players + +func get_number_of_online_players(): + return len(get_tree().get_network_connected_peers()) + +remote func get_online_players(id): + rpc_id(id, "update_online_players", _number_of_online_players) remote func get_open_games_from_server(id): rpc_id(id, "update_open_games", _open_games) @@ -29,17 +36,17 @@ remote func remove_game_from_game_list(game_id): var _queue = [] var _hidden_games = {} -func _process(delta): - if _queue.empty(): - print("Nothing to do.") - else: - var player_id = dequeue() - - if _hidden_games.empty(): - create_game(player_id) - else: - join_next_hidden_game(player_id) - +#func _process(delta): +# if _queue.empty(): +# print("Nothing to do.") +# else: +# var player_id = dequeue() +# +# if _hidden_games.empty(): +# create_game(player_id) +# else: +# join_next_hidden_game(player_id) +# func create_game(player_id): pass diff --git a/Server/Scenes/Matchmaking/Server/Server.gd b/Server/Scenes/Matchmaking/Server/Server.gd index 5ae7128..140fd99 100644 --- a/Server/Scenes/Matchmaking/Server/Server.gd +++ b/Server/Scenes/Matchmaking/Server/Server.gd @@ -22,11 +22,12 @@ func start_server(): get_tree().set_network_peer(peer) func _player_connected(id): - print(str(id) + " connected to server.") NetworkingSync._players_online.append(id) + NetworkingSync._number_of_online_players = len(get_tree().get_network_connected_peers()) func _player_disconnected(id): - print(str(id) + " left the game.") NetworkingSync._players_online.erase(id) + NetworkingSync._number_of_online_players = len(get_tree().get_network_connected_peers()) if id in NetworkingSync._open_games: NetworkingSync.remove_game_from_game_list(id) + diff --git a/Server/export_presets.cfg b/Server/export_presets.cfg index 565cb9b..d4770cf 100644 --- a/Server/export_presets.cfg +++ b/Server/export_presets.cfg @@ -7,7 +7,7 @@ custom_features="" export_filter="all_resources" include_filter="" exclude_filter="" -export_path="../Executables/Server.x86_64" +export_path="../../Godot_Executables/Server_linux/Server.x86_64" patch_list=PoolStringArray( ) script_export_mode=1 script_encryption_key=""