Skip to content

Commit

Permalink
updat with clear/del functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Ughuuu committed Dec 12, 2024
1 parent a0e8680 commit 7e97eb1
Show file tree
Hide file tree
Showing 3 changed files with 187 additions and 14 deletions.
57 changes: 55 additions & 2 deletions modules/blazium_sdk/doc_classes/LobbyClient.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,31 @@
<tutorials>
</tutorials>
<methods>
<method name="clear_lobby_data">
<return type="LobbyResponse" />
<param index="0" name="is_private" type="bool" default="false" />
<description>
Clears the lobby data. Only works if you are host.
Generates [signal received_lobby_data].
</description>
</method>
<method name="clear_peer_data">
<return type="LobbyResponse" />
<param index="0" name="target_peer" type="String" />
<param index="1" name="is_private" type="bool" default="false" />
<description>
Clears the peer data. Only works if you are host.
Generates [signal received_peer_data].
</description>
</method>
<method name="clear_peers_data">
<return type="LobbyResponse" />
<param index="0" name="is_private" type="bool" default="false" />
<description>
Clears the peers data. Only works if you are host.
Generates [signal received_peer_data].
</description>
</method>
<method name="connect_to_lobby">
<return type="bool" />
<description>
Expand All @@ -27,6 +52,34 @@
Generates [signal lobby_created] signal.
</description>
</method>
<method name="del_lobby_data">
<return type="LobbyResponse" />
<param index="0" name="key" type="String" />
<param index="1" name="is_private" type="bool" default="false" />
<description>
Delete one key from the lobby data. Only works if you are host.
Generates [signal received_lobby_data].
</description>
</method>
<method name="del_peer_data">
<return type="LobbyResponse" />
<param index="0" name="key" type="String" />
<param index="1" name="target_peer" type="String" />
<param index="2" name="is_private" type="bool" default="false" />
<description>
Delete one key from the peer data. Only works if you are host.
Generates [signal received_peer_data].
</description>
</method>
<method name="del_peers_data">
<return type="LobbyResponse" />
<param index="0" name="key" type="String" />
<param index="1" name="is_private" type="bool" default="false" />
<description>
Delete one key from the peers data. Only works if you are host.
Generates [signal received_peer_data].
</description>
</method>
<method name="disconnect_from_lobby">
<return type="void" />
<description>
Expand Down Expand Up @@ -135,7 +188,7 @@
<return type="LobbyResponse" />
<param index="0" name="data" type="Dictionary" />
<param index="1" name="target_peer" type="String" />
<param index="2" name="is_private" type="bool" />
<param index="2" name="is_private" type="bool" default="false" />
<description>
Set data on the peer. Only works if you are host.
Generates [signal received_peer_data] signal if you are in lobby.
Expand All @@ -152,7 +205,7 @@
<method name="set_peers_data">
<return type="LobbyResponse" />
<param index="0" name="data" type="Dictionary" />
<param index="1" name="is_private" type="bool" />
<param index="1" name="is_private" type="bool" default="false" />
<description>
Set data on the peers. Only works if you are host.
Generates [signal received_peer_data] signal if you are in lobby.
Expand Down
135 changes: 128 additions & 7 deletions modules/blazium_sdk/lobby/lobby_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,14 +422,12 @@ Ref<LobbyClient::LobbyResponse> LobbyClient::peer_notify(const Variant &p_peer_d
return response;
}

Ref<LobbyClient::LobbyResponse> LobbyClient::lobby_data_key_value(const String &p_key, const Variant &p_value, bool p_is_private) {
Ref<LobbyClient::LobbyResponse> 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;
Expand All @@ -443,12 +441,40 @@ Ref<LobbyClient::LobbyResponse> LobbyClient::lobby_data_key_value(const String &
return response;
}

Ref<LobbyClient::LobbyResponse> LobbyClient::lobby_data(const Dictionary &p_lobby_data, bool p_is_private) {
Ref<LobbyClient::LobbyResponse> 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<LobbyResponse> 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::LobbyResponse> 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;
Expand Down Expand Up @@ -482,6 +508,55 @@ Ref<LobbyClient::LobbyResponse> LobbyClient::set_peer_data(const Dictionary &p_p
return response;
}

Ref<LobbyClient::LobbyResponse> 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<LobbyResponse> 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::LobbyResponse> 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<LobbyResponse> 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::LobbyResponse> LobbyClient::set_peers_data(const Dictionary &p_peer_data, bool p_is_private) {
String id = _increment_counter();
Dictionary command;
Expand All @@ -501,6 +576,53 @@ Ref<LobbyClient::LobbyResponse> LobbyClient::set_peers_data(const Dictionary &p_
return response;
}

Ref<LobbyClient::LobbyResponse> 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<LobbyResponse> 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::LobbyResponse> 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<LobbyResponse> 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: {
Expand Down Expand Up @@ -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());
Expand Down
9 changes: 4 additions & 5 deletions modules/blazium_sdk/lobby/lobby_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -356,12 +356,11 @@ class LobbyClient : public BlaziumClient {

Ref<LobbyResponse> set_peer_data(const Dictionary &p_peer_data, const String &p_target_peer, bool p_is_private);
Ref<LobbyResponse> del_peer_data(const String &p_key, const String &p_target_peer, bool p_is_private);
Ref<LobbyResponse> clear_peer_data(const Dictionary &p_peer_data, bool p_is_private);

Ref<LobbyResponse> set_peer_data(const Dictionary &p_peer_data, const String &p_target_peer, bool p_is_private);
Ref<LobbyResponse> del_peer_data(const String &p_key, const String &p_target_peer, bool p_is_private);
Ref<LobbyResponse> clear_peers_data(const Dictionary &p_peer_data, bool p_is_private);
Ref<LobbyResponse> clear_peer_data(const String &p_target_peer, bool p_is_private);

Ref<LobbyResponse> set_peers_data(const Dictionary &p_peer_data, bool p_is_private);
Ref<LobbyResponse> del_peers_data(const String &p_key, bool p_is_private);
Ref<LobbyResponse> clear_peers_data(bool p_is_private);

LobbyClient();
~LobbyClient();
Expand Down

0 comments on commit 7e97eb1

Please sign in to comment.