Skip to content

Commit

Permalink
add lobby call
Browse files Browse the repository at this point in the history
add code for lobby call auth

add set tags

update tags

add set tags

small rename tpo

update lobby call
  • Loading branch information
Ughuuu committed Dec 7, 2024
1 parent e866b0b commit 0540984
Show file tree
Hide file tree
Showing 13 changed files with 440 additions and 94 deletions.
3 changes: 3 additions & 0 deletions modules/blazium_sdk/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ def get_doc_classes():
"ListLobbyResult",
"ViewLobbyResponse",
"ViewLobbyResult",
"AuthoritativeClient",
"LobbyCallResponse",
"LobbyCallResult",
]


Expand Down
24 changes: 24 additions & 0 deletions modules/blazium_sdk/doc_classes/AuthoritativeClient.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="AuthoritativeClient" inherits="LobbyClient" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
A lobby client that is authoritative.
</brief_description>
<description>
A lobby client that is authoritative.
</description>
<tutorials>
</tutorials>
<methods>
<method name="lobby_call">
<return type="LobbyCallResponse" />
<param index="0" name="method" type="String" />
<param index="1" name="args" type="Array" />
<description>
Call a method on the server.
</description>
</method>
</methods>
<members>
<member name="server_url" type="String" setter="set_server_url" getter="get_server_url" overrides="LobbyClient" default="&quot;wss://authlobby.blazium.app/connect&quot;" />
</members>
</class>
19 changes: 19 additions & 0 deletions modules/blazium_sdk/doc_classes/LobbyCallResponse.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="LobbyCallResponse" inherits="RefCounted" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
Response from a lobby call function.
</brief_description>
<description>
Response from a lobby call function. Await on finished to get the [LobbyCallResult].
</description>
<tutorials>
</tutorials>
<signals>
<signal name="finished">
<param index="0" name="result" type="LobbyCallResult" />
<description>
Signal emitted when the request is finished.
</description>
</signal>
</signals>
</class>
30 changes: 30 additions & 0 deletions modules/blazium_sdk/doc_classes/LobbyCallResult.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="LobbyCallResult" inherits="RefCounted" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
A result from a [LobbyCallResponse].
</brief_description>
<description>
A result from a [LobbyCallResponse].
</description>
<tutorials>
</tutorials>
<methods>
<method name="get_result" qualifiers="const">
<return type="Variant" />
<description>
Result of the function call.
</description>
</method>
<method name="has_error" qualifiers="const">
<return type="bool" />
<description>
Returns true if there is an error.
</description>
</method>
</methods>
<members>
<member name="error" type="String" setter="" getter="get_error" default="&quot;&quot;">
Gets the error message.
</member>
</members>
</class>
99 changes: 66 additions & 33 deletions modules/blazium_sdk/doc_classes/LobbyClient.xml
Original file line number Diff line number Diff line change
@@ -1,43 +1,51 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="LobbyClient" inherits="BlaziumClient" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description>
A node used to connect to a blazium lobby websocket server.
A node used to connect to a lobby server.
</brief_description>
<description>
A node used to connect to a lobby server. It can be used to do matchmaking. You care do operations such as create lobbys, join lobbys, etc.
A node used to connect to a lobby server. It can be used to do matchmaking. You can do operations such as create lobby, join lobby, etc. The server is configurable and can either be self deployed or you can use the blazium free matchmaking server.
</description>
<tutorials>
</tutorials>
<methods>
<method name="connect_to_lobby">
<return type="bool" />
<description>
Connect to a Blazium Lobby Server using the game_id and [member server_url].
Connect to a Blazium Lobby Server using the [member game_id] and [member server_url].
</description>
</method>
<method name="create_lobby">
<return type="ViewLobbyResponse" />
<param index="0" name="title" type="String" />
<param index="1" name="tags" type="String[]" default="[]" />
<param index="1" name="tags" type="Dictionary" default="{}" />
<param index="2" name="max_players" type="int" default="4" />
<param index="3" name="password" type="String" default="&quot;&quot;" />
<description>
Create a lobby and become host. If you are already in a lobby, you cannot create one. You need to leave first.
The new lobby can have a title, tags, max players and password.
Generates [signal lobby_created] signal.
</description>
</method>
<method name="get_host_data">
<return type="Variant" />
<description>
Returns the lobby data. Only works if you are host.
</description>
</method>
<method name="is_host">
<return type="bool" />
<description>
Returns true if you are the host.
Returns true if you are the host of the current lobby.
</description>
</method>
<method name="join_lobby">
<return type="ViewLobbyResponse" />
<param index="0" name="lobby_id" type="String" />
<param index="1" name="password" type="String" default="&quot;&quot;" />
<description>
Joint a lobby. If you are already in a lobby, you cannot join another one. You need to leave first.
Join a lobby. If you are already in a lobby, you cannot join another one. You need to leave first.
If the lobby you want to join is password protected, you need to provide the password.
Generates [signal lobby_joined].
</description>
</method>
Expand All @@ -58,38 +66,51 @@
</method>
<method name="list_lobbies">
<return type="ListLobbyResponse" />
<param index="0" name="title" type="String" default="&quot;&quot;" />
<param index="1" name="max_players" type="int" default="-1" />
<param index="2" name="tags" type="String[]" default="[]" />
<param index="3" name="start" type="int" default="0" />
<param index="4" name="count" type="int" default="10" />
<param index="0" name="tags" type="Dictionary" default="{}" />
<param index="1" name="start" type="int" default="0" />
<param index="2" name="count" type="int" default="10" />
<description>
Lists all lobbies. Lobbies that are sealed won't show in the list, except if you disconnected and trying to reconnect to a lobby.
</description>
</method>
<method name="notify_lobby">
<return type="LobbyResponse" />
<param index="0" name="data" type="Variant" />
<description>
Send a notification either to the host, or if you are host send data to all peers.
Generates [signal lobby_notified] signal.
</description>
</method>
<method name="notify_peer">
<return type="LobbyResponse" />
<param index="0" name="data" type="Variant" />
<param index="1" name="target_peer" type="String" />
<description>
Lists all lobbies.
Send a notification to a peer, works only if you are host.
Generates [signal lobby_notified] signal.
</description>
</method>
<method name="send_chat_message">
<return type="LobbyResponse" />
<param index="0" name="chat_message" type="String" />
<description>
Send a chat message.
Send a chat message. Only works if you are in a lobby.
Generates [signal peer_messaged].
</description>
</method>
<method name="send_lobby_data">
<method name="set_lobby_data">
<return type="LobbyResponse" />
<param index="0" name="data" type="Variant" />
<description>
Send data either to the host, or if you are host send data to all peers.
Generates [signal received_data] signal.
Set data on the lobby. Only works if you are host.
</description>
</method>
<method name="send_lobby_data_to">
<method name="send_peer_data">
<return type="LobbyResponse" />
<param index="0" name="data" type="Variant" />
<param index="1" name="target_peer" type="String" />
<description>
Send data either to a peer, works only if you are host.
Generates [signal received_data_to] signal.
Send data to a peer.
</description>
</method>
<method name="set_lobby_ready">
Expand All @@ -108,6 +129,12 @@
Generates [signal lobby_sealed].
</description>
</method>
<method name="set_lobby_tags">
<return type="LobbyResponse" />
<param index="0" name="tags" type="Dictionary" />
<description>
</description>
</method>
<method name="set_peer_name">
<return type="LobbyResponse" />
<param index="0" name="peer_name" type="String" />
Expand Down Expand Up @@ -155,6 +182,13 @@
Signal generated after you connect to the lobby.
</description>
</signal>
<signal name="received_data">
<param index="0" name="data" type="Object" />
<param index="1" name="from_peer" type="LobbyPeer" />
<description>
Signal generated after data is received.
</description>
</signal>
<signal name="disconnected_from_lobby">
<param index="0" name="reason" type="String" />
<description>
Expand Down Expand Up @@ -187,13 +221,26 @@
Signal generated after the host seals the lobby.
</description>
</signal>
<signal name="lobby_tagged">
<param index="0" name="tags" type="Dictionary" />
<description>
Signal generated after the host updated the tags of the lobby
</description>
</signal>
<signal name="log_updated">
<param index="0" name="command" type="String" />
<param index="1" name="logs" type="String" />
<description>
Signals a log from a command.
</description>
</signal>
<signal name="lobby_notified">
<param index="0" name="data" type="Object" />
<param index="1" name="from_peer" type="LobbyPeer" />
<description>
Signal generated after a notification is received.
</description>
</signal>
<signal name="peer_disconnected">
<param index="0" name="peer" type="LobbyPeer" />
<description>
Expand Down Expand Up @@ -239,19 +286,5 @@
Signal generated after a peer reconnects.
</description>
</signal>
<signal name="received_data">
<param index="0" name="data" type="Object" />
<param index="1" name="from_peer" type="LobbyPeer" />
<description>
Signal generated after a lobby_data call.
</description>
</signal>
<signal name="received_data_to">
<param index="0" name="data" type="Object" />
<param index="1" name="from_peer" type="LobbyPeer" />
<description>
Signal generated after a data_to call.
</description>
</signal>
</signals>
</class>
2 changes: 1 addition & 1 deletion modules/blazium_sdk/doc_classes/LobbyInfo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<member name="sealed" type="bool" setter="" getter="is_sealed" default="false">
Whether the lobby is sealed.
</member>
<member name="tags" type="String[]" setter="" getter="get_tags" default="[]">
<member name="tags" type="Dictionary" setter="" getter="get_tags" default="{}">
The tags of the lobby. Used for listing lobbies to filter based on them.
</member>
</members>
Expand Down
3 changes: 3 additions & 0 deletions modules/blazium_sdk/doc_classes/LobbyPeer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
<tutorials>
</tutorials>
<members>
<member name="data" type="Variant" setter="" getter="get_data" default="null">
Data of the peer.
</member>
<member name="id" type="String" setter="" getter="get_id" default="&quot;&quot;">
Identifier of the peer.
</member>
Expand Down
1 change: 1 addition & 0 deletions modules/blazium_sdk/icons/AuthoritativeClient.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions modules/blazium_sdk/lobby/authoritative_client.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "authoritative_client.h"

Ref<AuthoritativeClient::LobbyCallResponse> AuthoritativeClient::lobby_call(const String &p_method, const Array &p_args) {
String id = _increment_counter();
Dictionary command;
command["command"] = "lobby_call";
Dictionary data_dict;
data_dict["function"] = p_method;
data_dict["inputs"] = p_args;
command["data"] = data_dict;
Array command_array;
Ref<LobbyCallResponse> response;
response.instantiate();
command_array.push_back(LobbyClient::LOBBY_CALL);
command_array.push_back(response);
_commands[id] = command_array;
_send_data(command);
return response;
}

void AuthoritativeClient::_bind_methods() {
ClassDB::bind_method(D_METHOD("lobby_call", "method", "args"), &AuthoritativeClient::lobby_call);
ADD_PROPERTY_DEFAULT("peers", TypedArray<LobbyPeer>());
ADD_PROPERTY_DEFAULT("peer", Ref<LobbyPeer>());
ADD_PROPERTY_DEFAULT("lobby", Ref<LobbyInfo>());
}
Loading

0 comments on commit 0540984

Please sign in to comment.