From 7e97eb1ca7c8594e3dd1961abc5dbf50a3ba4627 Mon Sep 17 00:00:00 2001 From: Dragos Daian Date: Thu, 12 Dec 2024 22:16:25 +0100 Subject: [PATCH] updat with clear/del functions --- .../blazium_sdk/doc_classes/LobbyClient.xml | 57 +++++++- modules/blazium_sdk/lobby/lobby_client.cpp | 135 +++++++++++++++++- modules/blazium_sdk/lobby/lobby_client.h | 9 +- 3 files changed, 187 insertions(+), 14 deletions(-) diff --git a/modules/blazium_sdk/doc_classes/LobbyClient.xml b/modules/blazium_sdk/doc_classes/LobbyClient.xml index 89fa73adfb7e..be21f8da1d46 100644 --- a/modules/blazium_sdk/doc_classes/LobbyClient.xml +++ b/modules/blazium_sdk/doc_classes/LobbyClient.xml @@ -9,6 +9,31 @@ + + + + + Clears the lobby data. Only works if you are host. + Generates [signal received_lobby_data]. + + + + + + + + Clears the peer data. Only works if you are host. + Generates [signal received_peer_data]. + + + + + + + Clears the peers data. Only works if you are host. + Generates [signal received_peer_data]. + + @@ -27,6 +52,34 @@ Generates [signal lobby_created] signal. + + + + + + Delete one key from the lobby data. Only works if you are host. + Generates [signal received_lobby_data]. + + + + + + + + + Delete one key from the peer data. Only works if you are host. + Generates [signal received_peer_data]. + + + + + + + + Delete one key from the peers data. Only works if you are host. + Generates [signal received_peer_data]. + + @@ -135,7 +188,7 @@ - + Set data on the peer. Only works if you are host. Generates [signal received_peer_data] signal if you are in lobby. @@ -152,7 +205,7 @@ - + Set data on the peers. Only works if you are host. Generates [signal received_peer_data] signal if you are in lobby. diff --git a/modules/blazium_sdk/lobby/lobby_client.cpp b/modules/blazium_sdk/lobby/lobby_client.cpp index 79903e0db918..8aa348a473a9 100644 --- a/modules/blazium_sdk/lobby/lobby_client.cpp +++ b/modules/blazium_sdk/lobby/lobby_client.cpp @@ -422,14 +422,12 @@ Ref LobbyClient::peer_notify(const Variant &p_peer_d return response; } -Ref LobbyClient::lobby_data_key_value(const String &p_key, const Variant &p_value, bool p_is_private) { +Ref LobbyClient::lobby_data(const Dictionary &p_lobby_data, bool p_is_private) { String id = _increment_counter(); Dictionary command; command["command"] = "lobby_data"; Dictionary data_dict; - Dictionary key_value_dict; - key_value_dict[p_key] = p_value; - data_dict["lobby_data"] = key_value_dict; + data_dict["lobby_data"] = p_lobby_data; data_dict["is_private"] = p_is_private; data_dict["id"] = id; command["data"] = data_dict; @@ -443,12 +441,40 @@ Ref LobbyClient::lobby_data_key_value(const String & return response; } -Ref LobbyClient::lobby_data(const Dictionary &p_lobby_data, bool p_is_private) { +Ref LobbyClient::del_lobby_data(const String &p_key, bool p_is_private) { String id = _increment_counter(); Dictionary command; command["command"] = "lobby_data"; Dictionary data_dict; - data_dict["lobby_data"] = p_lobby_data; + Dictionary data_object_dict; + data_dict["lobby_data"] = data_object_dict; + // set null value + data_object_dict[p_key] = Variant(); + data_dict["is_private"] = p_is_private; + data_dict["id"] = id; + command["data"] = data_dict; + Array command_array; + Ref response; + response.instantiate(); + command_array.push_back(LOBBY_REQUEST); + command_array.push_back(response); + _commands[id] = command_array; + _send_data(command); + return response; +} + +Ref LobbyClient::clear_lobby_data(bool p_is_private) { + String id = _increment_counter(); + Dictionary command; + command["command"] = "lobby_data"; + Dictionary data_dict; + Dictionary data_object_dict; + data_dict["lobby_data"] = data_object_dict; + Array keys = data_object_dict.keys(); + // set null values + for (int i = 0; i < keys.size(); i++) { + data_object_dict[keys[i]] = Variant(); + } data_dict["is_private"] = p_is_private; data_dict["id"] = id; command["data"] = data_dict; @@ -482,6 +508,55 @@ Ref LobbyClient::set_peer_data(const Dictionary &p_p return response; } +Ref LobbyClient::del_peer_data(const String &p_key, const String &p_target_peer, bool p_is_private) { + String id = _increment_counter(); + Dictionary command; + command["command"] = "data_to"; + Dictionary data_dict; + Dictionary data_object_dict; + data_dict["peer_data"] = data_object_dict; + // set null value + data_object_dict[p_key] = Variant(); + data_dict["target_peer"] = p_target_peer; + data_dict["is_private"] = p_is_private; + data_dict["id"] = id; + command["data"] = data_dict; + Array command_array; + Ref response; + response.instantiate(); + command_array.push_back(LOBBY_REQUEST); + command_array.push_back(response); + _commands[id] = command_array; + _send_data(command); + return response; +} + +Ref LobbyClient::clear_peer_data(const String &p_target_peer, bool p_is_private) { + String id = _increment_counter(); + Dictionary command; + command["command"] = "data_to"; + Dictionary data_dict; + Dictionary data_object_dict; + data_dict["peer_data"] = data_object_dict; + // set null values + Array keys = data_object_dict.keys(); + for (int i = 0; i < keys.size(); i++) { + data_object_dict[keys[i]] = Variant(); + } + data_dict["target_peer"] = p_target_peer; + data_dict["is_private"] = p_is_private; + data_dict["id"] = id; + command["data"] = data_dict; + Array command_array; + Ref response; + response.instantiate(); + command_array.push_back(LOBBY_REQUEST); + command_array.push_back(response); + _commands[id] = command_array; + _send_data(command); + return response; +} + Ref LobbyClient::set_peers_data(const Dictionary &p_peer_data, bool p_is_private) { String id = _increment_counter(); Dictionary command; @@ -501,6 +576,53 @@ Ref LobbyClient::set_peers_data(const Dictionary &p_ return response; } +Ref LobbyClient::del_peers_data(const String &p_key, bool p_is_private) { + String id = _increment_counter(); + Dictionary command; + command["command"] = "data_to_all"; + Dictionary data_dict; + Dictionary data_object_dict; + data_dict["peer_data"] = data_object_dict; + // set null value + data_object_dict[p_key] = Variant(); + data_dict["is_private"] = p_is_private; + data_dict["id"] = id; + command["data"] = data_dict; + Array command_array; + Ref response; + response.instantiate(); + command_array.push_back(LOBBY_REQUEST); + command_array.push_back(response); + _commands[id] = command_array; + _send_data(command); + return response; +} + +Ref LobbyClient::clear_peers_data(bool p_is_private) { + String id = _increment_counter(); + Dictionary command; + command["command"] = "data_to_all"; + Dictionary data_dict; + Dictionary data_object_dict; + data_dict["peer_data"] = data_object_dict; + // set null values + Array keys = data_object_dict.keys(); + for (int i = 0; i < keys.size(); i++) { + data_object_dict[keys[i]] = Variant(); + } + data_dict["is_private"] = p_is_private; + data_dict["id"] = id; + command["data"] = data_dict; + Array command_array; + Ref response; + response.instantiate(); + command_array.push_back(LOBBY_REQUEST); + command_array.push_back(response); + _commands[id] = command_array; + _send_data(command); + return response; +} + void LobbyClient::_notification(int p_what) { switch (p_what) { case NOTIFICATION_INTERNAL_PROCESS: { @@ -606,7 +728,6 @@ void LobbyClient::_receive_data(const Dictionary &p_dict) { peers = peers_info; } } - } if (command == "peer_state") { Dictionary peer_dict = data_dict.get("peer", Dictionary()); diff --git a/modules/blazium_sdk/lobby/lobby_client.h b/modules/blazium_sdk/lobby/lobby_client.h index 3663df649221..01108badcc3d 100644 --- a/modules/blazium_sdk/lobby/lobby_client.h +++ b/modules/blazium_sdk/lobby/lobby_client.h @@ -356,12 +356,11 @@ class LobbyClient : public BlaziumClient { Ref set_peer_data(const Dictionary &p_peer_data, const String &p_target_peer, bool p_is_private); Ref del_peer_data(const String &p_key, const String &p_target_peer, bool p_is_private); - Ref clear_peer_data(const Dictionary &p_peer_data, bool p_is_private); - - Ref set_peer_data(const Dictionary &p_peer_data, const String &p_target_peer, bool p_is_private); - Ref del_peer_data(const String &p_key, const String &p_target_peer, bool p_is_private); - Ref clear_peers_data(const Dictionary &p_peer_data, bool p_is_private); + Ref clear_peer_data(const String &p_target_peer, bool p_is_private); + Ref set_peers_data(const Dictionary &p_peer_data, bool p_is_private); + Ref del_peers_data(const String &p_key, bool p_is_private); + Ref clear_peers_data(bool p_is_private); LobbyClient(); ~LobbyClient();