From e6546fd71069450e073c2fb718caa75d881eb324 Mon Sep 17 00:00:00 2001 From: Dragos Daian Date: Mon, 16 Dec 2024 10:34:18 +0100 Subject: [PATCH] add peer private data to auth client update private peer data remove view lobby as it's unused --- .../doc_classes/AuthoritativeClient.xml | 18 ++++---- .../blazium_sdk/doc_classes/LobbyClient.xml | 9 ---- .../lobby/authoritative_client.cpp | 42 ++++++------------- .../blazium_sdk/lobby/authoritative_client.h | 3 +- modules/blazium_sdk/lobby/lobby_client.cpp | 26 ------------ modules/blazium_sdk/lobby/lobby_client.h | 1 - 6 files changed, 24 insertions(+), 75 deletions(-) diff --git a/modules/blazium_sdk/doc_classes/AuthoritativeClient.xml b/modules/blazium_sdk/doc_classes/AuthoritativeClient.xml index cd48bde1f9de..4534fe92a810 100644 --- a/modules/blazium_sdk/doc_classes/AuthoritativeClient.xml +++ b/modules/blazium_sdk/doc_classes/AuthoritativeClient.xml @@ -15,6 +15,11 @@ - [member peer]: The current peer. Reflects changes to the self peer. - [member peers]: The lobby peers. Reflects changes to all peers. - [member lobby]: The lobby. Reflects changes to the lobby. + - [member peer_data]: The current peer private data. + + [b]Note:[/b] The main difference between this service and the non authoritative [LobbyClient] are: + - The host cannot set any data or notify peer_disconnected. + - The [signal received_lobby_data] signal doesn't have the [code]is_private[/code] parameter. @@ -151,15 +156,6 @@ Generates [signal peer_named] signal if you are in lobby. - - - - - - View data from a lobby. Returns lobby settings and peers. - Returns a [ViewLobbyResponse] object that has a [signal ViewLobbyResponse.finished] signal that is emitted when finished. - - @@ -174,6 +170,9 @@ The current peer. Reflects changes to the self peer. + + The current peer private data. + The lobby peers. Reflects changes to all peers. @@ -298,6 +297,7 @@ + Signal generated after data is sent to peer. diff --git a/modules/blazium_sdk/doc_classes/LobbyClient.xml b/modules/blazium_sdk/doc_classes/LobbyClient.xml index 5b8e44d145f7..b71eb22c5ffe 100644 --- a/modules/blazium_sdk/doc_classes/LobbyClient.xml +++ b/modules/blazium_sdk/doc_classes/LobbyClient.xml @@ -226,15 +226,6 @@ Generates [signal peer_named] signal if you are in lobby. - - - - - - View data from a lobby. Returns lobby settings and peers. - Returns a [ViewLobbyResponse] object that has a [signal ViewLobbyResponse.finished] signal that is emitted when finished. - - diff --git a/modules/blazium_sdk/lobby/authoritative_client.cpp b/modules/blazium_sdk/lobby/authoritative_client.cpp index 699d7fa53257..454fdf101256 100644 --- a/modules/blazium_sdk/lobby/authoritative_client.cpp +++ b/modules/blazium_sdk/lobby/authoritative_client.cpp @@ -57,6 +57,7 @@ void AuthoritativeClient::_bind_methods() { ClassDB::bind_method(D_METHOD("get_lobby"), &AuthoritativeClient::get_lobby); ClassDB::bind_method(D_METHOD("get_peer"), &AuthoritativeClient::get_peer); ClassDB::bind_method(D_METHOD("get_peers"), &AuthoritativeClient::get_peers); + ClassDB::bind_method(D_METHOD("get_peer_data"), &AuthoritativeClient::get_peer_data); ADD_PROPERTY(PropertyInfo(Variant::STRING, "server_url", PROPERTY_HINT_NONE, ""), "set_server_url", "get_server_url"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "reconnection_token", PROPERTY_HINT_NONE, ""), "set_reconnection_token", "get_reconnection_token"); @@ -65,6 +66,7 @@ void AuthoritativeClient::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "lobby", PROPERTY_HINT_RESOURCE_TYPE, "LobbyInfo"), "", "get_lobby"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "peer", PROPERTY_HINT_RESOURCE_TYPE, "LobbyPeer"), "", "get_peer"); ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "peers", PROPERTY_HINT_ARRAY_TYPE, "LobbyPeer"), "", "get_peers"); + ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "peer_data"), "", "get_peer_data"); ADD_PROPERTY_DEFAULT("peers", TypedArray()); ADD_PROPERTY_DEFAULT("peer", Ref()); ADD_PROPERTY_DEFAULT("lobby", Ref()); @@ -77,7 +79,6 @@ void AuthoritativeClient::_bind_methods() { ClassDB::bind_method(D_METHOD("leave_lobby"), &AuthoritativeClient::leave_lobby); ClassDB::bind_method(D_METHOD("lobby_call", "method", "args"), &AuthoritativeClient::lobby_call); ClassDB::bind_method(D_METHOD("list_lobbies", "tags", "start", "count"), &AuthoritativeClient::list_lobby, DEFVAL(Dictionary()), DEFVAL(0), DEFVAL(10)); - ClassDB::bind_method(D_METHOD("view_lobby", "lobby_id", "password"), &AuthoritativeClient::view_lobby, DEFVAL(""), DEFVAL("")); ClassDB::bind_method(D_METHOD("kick_peer", "peer_id"), &AuthoritativeClient::kick_peer); ClassDB::bind_method(D_METHOD("send_chat_message", "chat_message"), &AuthoritativeClient::lobby_chat); ClassDB::bind_method(D_METHOD("set_lobby_ready", "ready"), &AuthoritativeClient::lobby_ready); @@ -90,7 +91,7 @@ void AuthoritativeClient::_bind_methods() { ADD_SIGNAL(MethodInfo("disconnected_from_lobby", PropertyInfo(Variant::STRING, "reason"))); ADD_SIGNAL(MethodInfo("peer_named", PropertyInfo(Variant::OBJECT, "peer", PROPERTY_HINT_RESOURCE_TYPE, "LobbyPeer"))); ADD_SIGNAL(MethodInfo("lobby_notified", PropertyInfo(Variant::OBJECT, "data"), PropertyInfo(Variant::OBJECT, "from_peer", PROPERTY_HINT_RESOURCE_TYPE, "LobbyPeer"))); - ADD_SIGNAL(MethodInfo("received_peer_data", PropertyInfo(Variant::OBJECT, "data"), PropertyInfo(Variant::OBJECT, "to_peer", PROPERTY_HINT_RESOURCE_TYPE, "LobbyPeer"))); + ADD_SIGNAL(MethodInfo("received_peer_data", PropertyInfo(Variant::OBJECT, "data"), PropertyInfo(Variant::OBJECT, "to_peer", PROPERTY_HINT_RESOURCE_TYPE, "LobbyPeer"), PropertyInfo(Variant::BOOL, "is_private"))); ADD_SIGNAL(MethodInfo("received_lobby_data", PropertyInfo(Variant::OBJECT, "data"))); ADD_SIGNAL(MethodInfo("lobby_created", PropertyInfo(Variant::OBJECT, "lobby", PROPERTY_HINT_RESOURCE_TYPE, "LobbyInfo"), PropertyInfo(Variant::ARRAY, "peers", PROPERTY_HINT_ARRAY_TYPE, "LobbyPeer"))); ADD_SIGNAL(MethodInfo("lobby_joined", PropertyInfo(Variant::OBJECT, "lobby", PROPERTY_HINT_RESOURCE_TYPE, "LobbyInfo"), PropertyInfo(Variant::ARRAY, "peers", PROPERTY_HINT_ARRAY_TYPE, "LobbyPeer"))); @@ -119,6 +120,7 @@ Ref AuthoritativeClient::get_lobby() { return lobby; } void AuthoritativeClient::set_peer(const Ref &p_peer) { this->peer = p_peer; } Ref AuthoritativeClient::get_peer() { return peer; } TypedArray AuthoritativeClient::get_peers() { return peers; } +Dictionary AuthoritativeClient::get_peer_data() { return peer_data; } bool AuthoritativeClient::connect_to_lobby() { if (connected) { @@ -261,29 +263,6 @@ Ref AuthoritativeClient::list_lobby(const Dictionary &p_tags, return response; } -Ref AuthoritativeClient::view_lobby(const String &p_lobby_id, const String &p_password) { - String id = _increment_counter(); - Dictionary command; - command["command"] = "view_lobby"; - Dictionary data_dict; - command["data"] = data_dict; - if (p_lobby_id.is_empty()) { - data_dict["lobby_id"] = lobby->get_id(); - } else { - data_dict["lobby_id"] = p_lobby_id; - } - data_dict["password"] = p_password; - data_dict["id"] = id; - Array command_array; - Ref response; - response.instantiate(); - command_array.push_back(LOBBY_VIEW); - command_array.push_back(response); - _commands[id] = command_array; - _send_data(command); - return response; -} - Ref AuthoritativeClient::kick_peer(const String &p_peer_id) { String id = _increment_counter(); Dictionary command; @@ -555,8 +534,6 @@ void AuthoritativeClient::_receive_data(const Dictionary &p_dict) { response->emit_signal("finished", result); } } - } else if (command == "lobby_view") { - // nothing for now } else if (command == "peer_chat") { String peer_id = data_dict.get("from_peer", ""); String chat_data = data_dict.get("chat_data", ""); @@ -666,13 +643,20 @@ void AuthoritativeClient::_receive_data(const Dictionary &p_dict) { // nothing for now } else if (command == "data_to") { String target_peer_id = data_dict.get("target_peer", ""); + bool is_private = data_dict.get("is_private", false); Dictionary peer_data_variant = data_dict.get("peer_data", Dictionary()); for (int i = 0; i < peers.size(); ++i) { Ref updated_peer = peers[i]; if (updated_peer->get_id() == target_peer_id) { // got peer data, update it - updated_peer->set_data(peer_data_variant); - emit_signal("received_peer_data", peer_data_variant, updated_peer); + if (is_private && target_peer_id == peer->get_id()) { + // private data, update self + peer_data = peer_data_variant; + } else { + // public peer data + updated_peer->set_data(peer_data_variant); + } + emit_signal("received_peer_data", peer_data_variant, updated_peer, is_private); break; } } diff --git a/modules/blazium_sdk/lobby/authoritative_client.h b/modules/blazium_sdk/lobby/authoritative_client.h index f173416f66f7..d11e18fe34e2 100644 --- a/modules/blazium_sdk/lobby/authoritative_client.h +++ b/modules/blazium_sdk/lobby/authoritative_client.h @@ -41,6 +41,7 @@ class AuthoritativeClient : public BlaziumClient { String server_url = "wss://authlobby.blazium.app/connect"; String reconnection_token = ""; String game_id = ""; + Dictionary peer_data = Dictionary(); Ref lobby; Ref peer; TypedArray peers = TypedArray(); @@ -75,6 +76,7 @@ class AuthoritativeClient : public BlaziumClient { String get_game_id(); bool is_host(); bool get_connected(); + Dictionary get_peer_data(); void set_lobby(const Ref &p_lobby); Ref get_lobby(); void set_peer(const Ref &p_peer); @@ -87,7 +89,6 @@ class AuthoritativeClient : public BlaziumClient { Ref join_lobby(const String &p_lobby_id, const String &p_password); Ref leave_lobby(); Ref list_lobby(const Dictionary &p_tags, int p_start, int p_count); - Ref view_lobby(const String &p_lobby_id, const String &p_password); Ref kick_peer(const String &p_peer_id); Ref set_lobby_tags(const Dictionary &p_tags); Ref del_lobby_tags(const TypedArray &p_keys); diff --git a/modules/blazium_sdk/lobby/lobby_client.cpp b/modules/blazium_sdk/lobby/lobby_client.cpp index 1571ddef4024..b4964fc7e69a 100644 --- a/modules/blazium_sdk/lobby/lobby_client.cpp +++ b/modules/blazium_sdk/lobby/lobby_client.cpp @@ -80,7 +80,6 @@ void LobbyClient::_bind_methods() { ClassDB::bind_method(D_METHOD("join_lobby", "lobby_id", "password"), &LobbyClient::join_lobby, DEFVAL("")); ClassDB::bind_method(D_METHOD("leave_lobby"), &LobbyClient::leave_lobby); ClassDB::bind_method(D_METHOD("list_lobbies", "tags", "start", "count"), &LobbyClient::list_lobby, DEFVAL(Dictionary()), DEFVAL(0), DEFVAL(10)); - ClassDB::bind_method(D_METHOD("view_lobby", "lobby_id", "password"), &LobbyClient::view_lobby, DEFVAL(""), DEFVAL("")); ClassDB::bind_method(D_METHOD("kick_peer", "peer_id"), &LobbyClient::kick_peer); ClassDB::bind_method(D_METHOD("send_chat_message", "chat_message"), &LobbyClient::lobby_chat); ClassDB::bind_method(D_METHOD("set_lobby_ready", "ready"), &LobbyClient::lobby_ready); @@ -261,29 +260,6 @@ Ref LobbyClient::list_lobby(const Dictionary &p_tags, int p_s return response; } -Ref LobbyClient::view_lobby(const String &p_lobby_id, const String &p_password) { - String id = _increment_counter(); - Dictionary command; - command["command"] = "view_lobby"; - Dictionary data_dict; - command["data"] = data_dict; - if (p_lobby_id.is_empty()) { - data_dict["lobby_id"] = lobby->get_id(); - } else { - data_dict["lobby_id"] = p_lobby_id; - } - data_dict["password"] = p_password; - data_dict["id"] = id; - Array command_array; - Ref response; - response.instantiate(); - command_array.push_back(LOBBY_VIEW); - command_array.push_back(response); - _commands[id] = command_array; - _send_data(command); - return response; -} - Ref LobbyClient::kick_peer(const String &p_peer_id) { String id = _increment_counter(); Dictionary command; @@ -746,8 +722,6 @@ void LobbyClient::_receive_data(const Dictionary &p_dict) { response->emit_signal("finished", result); } } - } else if (command == "lobby_view") { - // nothing for now } else if (command == "peer_chat") { String peer_id = data_dict.get("from_peer", ""); String chat_data = data_dict.get("chat_data", ""); diff --git a/modules/blazium_sdk/lobby/lobby_client.h b/modules/blazium_sdk/lobby/lobby_client.h index f0a1ff4a8185..20b04750ccd2 100644 --- a/modules/blazium_sdk/lobby/lobby_client.h +++ b/modules/blazium_sdk/lobby/lobby_client.h @@ -96,7 +96,6 @@ class LobbyClient : public BlaziumClient { Ref join_lobby(const String &p_lobby_id, const String &p_password); Ref leave_lobby(); Ref list_lobby(const Dictionary &p_tags, int p_start, int p_count); - Ref view_lobby(const String &p_lobby_id, const String &p_password); Ref kick_peer(const String &p_peer_id); Ref set_lobby_tags(const Dictionary &p_tags); Ref del_lobby_tags(const TypedArray &p_keys);