Skip to content

Commit

Permalink
Merge pull request #182 from Ughuuu/add-lobby-call
Browse files Browse the repository at this point in the history
add lobby call
Bioblaze authored Dec 8, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents 3279b8d + 7774f21 commit 313f628
Showing 13 changed files with 539 additions and 96 deletions.
3 changes: 3 additions & 0 deletions modules/blazium_sdk/config.py
Original file line number Diff line number Diff line change
@@ -18,6 +18,9 @@ def get_doc_classes():
"ListLobbyResult",
"ViewLobbyResponse",
"ViewLobbyResult",
"AuthoritativeClient",
"LobbyCallResponse",
"LobbyCallResult",
]


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>
125 changes: 94 additions & 31 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. 0 max players means unlimited.
Generates [signal lobby_created] signal.
</description>
</method>
<method name="disconnect_from_lobby">
<return type="void" />
<description>
Disconnect from the lobby server.
</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>
@@ -58,38 +66,45 @@
</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.
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="send_chat_message">
<method name="notify_lobby">
<return type="LobbyResponse" />
<param index="0" name="chat_message" type="String" />
<param index="0" name="data" type="Variant" />
<description>
Send a chat message.
Generates [signal peer_messaged].
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="send_lobby_data">
<method name="notify_peer">
<return type="LobbyResponse" />
<param index="0" name="data" type="Variant" />
<param index="1" name="target_peer" type="String" />
<description>
Send data either to the host, or if you are host send data to all peers.
Generates [signal received_data] signal.
Send a notification to a peer, works only if you are host.
Generates [signal lobby_notified] signal.
</description>
</method>
<method name="send_lobby_data_to">
<method name="send_chat_message">
<return type="LobbyResponse" />
<param index="0" name="data" type="Variant" />
<param index="1" name="target_peer" type="String" />
<param index="0" name="chat_message" type="String" />
<description>
Send a chat message. Only works if you are in a lobby.
Generates [signal peer_messaged].
</description>
</method>
<method name="set_lobby_data">
<return type="LobbyResponse" />
<param index="0" name="data" type="Dictionary" />
<param index="1" name="is_private" type="bool" default="false" />
<description>
Send data either to a peer, works only if you are host.
Generates [signal received_data_to] signal.
Set data on the lobby. Only works if you are host.
Generates [signal received_lobby_data].
</description>
</method>
<method name="set_lobby_ready">
@@ -108,6 +123,24 @@
Generates [signal lobby_sealed].
</description>
</method>
<method name="set_lobby_tags">
<return type="LobbyResponse" />
<param index="0" name="tags" type="Dictionary" />
<description>
Set tags on the lobby. Only works if you are host.
Generates [signal lobby_tagged].
</description>
</method>
<method name="set_peer_data">
<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" />
<description>
Set data on the peer. Only works if you are host.
Generates [signal received_peer_data] signal if you are in lobby.
</description>
</method>
<method name="set_peer_name">
<return type="LobbyResponse" />
<param index="0" name="peer_name" type="String" />
@@ -116,6 +149,15 @@
Generates [signal peer_named] signal if you are in lobby.
</description>
</method>
<method name="set_peers_data">
<return type="LobbyResponse" />
<param index="0" name="data" type="Dictionary" />
<param index="1" name="is_private" type="bool" />
<description>
Set data on the peers. Only works if you are host.
Generates [signal received_peer_data] signal if you are in lobby.
</description>
</method>
<method name="view_lobby">
<return type="ViewLobbyResponse" />
<param index="0" name="lobby_id" type="String" default="&quot;&quot;" />
@@ -130,13 +172,20 @@
True if the client is connected, else false.
</member>
<member name="game_id" type="String" setter="set_game_id" getter="get_game_id" default="&quot;&quot;">
The game id.
</member>
<member name="host_data" type="Dictionary" setter="" getter="get_host_data" default="{}">
The current lobby private data. Only works if you are host.
</member>
<member name="lobby" type="LobbyInfo" setter="" getter="get_lobby">
The current lobby. Reflects changes to the lobby.
</member>
<member name="peer" type="LobbyPeer" setter="" getter="get_peer">
The current peer. Reflects changes to the self peer.
</member>
<member name="peer_data" type="Dictionary" setter="" getter="get_peer_data" default="{}">
The current peer private data.
</member>
<member name="peers" type="LobbyPeer[]" setter="" getter="get_peers" default="[]">
The lobby peers. Reflects changes to all peers.
</member>
@@ -181,12 +230,25 @@
Signal generated after you leave a lobby.
</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="lobby_sealed">
<param index="0" name="sealed" type="bool" />
<description>
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" />
@@ -228,7 +290,7 @@
</signal>
<signal name="peer_ready">
<param index="0" name="peer" type="LobbyPeer" />
<param index="1" name="ready" type="bool" />
<param index="1" name="is_ready" type="bool" />
<description>
Signal generated after a peer is ready.
</description>
@@ -239,18 +301,19 @@
Signal generated after a peer reconnects.
</description>
</signal>
<signal name="received_data">
<signal name="received_lobby_data">
<param index="0" name="data" type="Object" />
<param index="1" name="from_peer" type="LobbyPeer" />
<param index="1" name="is_private" type="bool" />
<description>
Signal generated after a lobby_data call.
Signal generated after data is sent to the lobby.
</description>
</signal>
<signal name="received_data_to">
<signal name="received_peer_data">
<param index="0" name="data" type="Object" />
<param index="1" name="from_peer" type="LobbyPeer" />
<param index="1" name="to_peer" type="LobbyPeer" />
<param index="2" name="is_private" type="bool" />
<description>
Signal generated after a data_to call.
Signal generated after data is sent to peer.
</description>
</signal>
</signals>
7 changes: 5 additions & 2 deletions modules/blazium_sdk/doc_classes/LobbyInfo.xml
Original file line number Diff line number Diff line change
@@ -9,6 +9,9 @@
<tutorials>
</tutorials>
<members>
<member name="data" type="Dictionary" setter="" getter="get_data" default="{}">
The lobby public data.
</member>
<member name="host" type="String" setter="" getter="get_host" default="&quot;&quot;">
The host id of the lobby.
</member>
@@ -22,7 +25,7 @@
The name of the lobby.
</member>
<member name="max_players" type="int" setter="" getter="get_max_players" default="0">
The maximum number of players allowed in the lobby.
The maximum number of players allowed in the lobby. 0 = unlimited
</member>
<member name="password_protected" type="bool" setter="" getter="is_password_protected" default="false">
</member>
@@ -32,7 +35,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>
2 changes: 2 additions & 0 deletions modules/blazium_sdk/doc_classes/LobbyPeer.xml
Original file line number Diff line number Diff line change
@@ -9,6 +9,8 @@
<tutorials>
</tutorials>
<members>
<member name="data" type="Dictionary" setter="" getter="get_data" default="{}">
</member>
<member name="id" type="String" setter="" getter="get_id" default="&quot;&quot;">
Identifier of the peer.
</member>
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>());
}
83 changes: 83 additions & 0 deletions modules/blazium_sdk/lobby/authoritative_client.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/**************************************************************************/
/* lobby_client.h */
/**************************************************************************/
/* This file is part of: */
/* BLAZIUM ENGINE */
/* https://blazium.app */
/**************************************************************************/
/* Copyright (c) 2024-present Blazium Engine contributors. */
/* Copyright (c) 2024 Dragos Daian, Randolph William Aarseth II. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/

#ifndef AUTHORITATIVE_CLIENT_H
#define AUTHORITATIVE_CLIENT_H

#include "lobby_client.h"

class AuthoritativeClient : public LobbyClient {
GDCLASS(AuthoritativeClient, LobbyClient);

public:
class LobbyCallResponse : public RefCounted {
GDCLASS(LobbyCallResponse, RefCounted);

protected:
static void _bind_methods() {
ADD_SIGNAL(MethodInfo("finished", PropertyInfo(Variant::OBJECT, "result", PROPERTY_HINT_RESOURCE_TYPE, "LobbyCallResult")));
}

public:
class LobbyCallResult : public RefCounted {
GDCLASS(LobbyCallResult, RefCounted);
Variant result;
String error;

protected:
static void _bind_methods() {
ClassDB::bind_method(D_METHOD("has_error"), &LobbyCallResult::has_error);
ClassDB::bind_method(D_METHOD("get_error"), &LobbyCallResult::get_error);
ClassDB::bind_method(D_METHOD("get_result"), &LobbyCallResult::get_result);
ADD_PROPERTY(PropertyInfo(Variant::STRING, "error"), "", "get_error");
}

public:
void set_error(String p_error) { this->error = p_error; }
void set_result(Variant p_result) { this->result = p_result; }

bool has_error() const { return !error.is_empty(); }
String get_error() const { return error; }
Variant get_result() const { return result; }
};
};

protected:
static void _bind_methods();

public:
Ref<LobbyCallResponse> lobby_call(const String &p_method, const Array &p_args);

AuthoritativeClient() {
server_url = "wss://authlobby.blazium.app/connect";
}
};

#endif // AUTHORITATIVE_CLIENT_H
247 changes: 206 additions & 41 deletions modules/blazium_sdk/lobby/lobby_client.cpp

Large diffs are not rendered by default.

64 changes: 42 additions & 22 deletions modules/blazium_sdk/lobby/lobby_client.h
Original file line number Diff line number Diff line change
@@ -41,7 +41,8 @@ class LobbyInfo : public Resource {
String lobby_name;
String host;
String host_name;
TypedArray<String> tags;
Dictionary tags;
Dictionary data;
int max_players = 0;
int players = 0;
bool sealed = false;
@@ -58,9 +59,11 @@ class LobbyInfo : public Resource {
ClassDB::bind_method(D_METHOD("get_host_name"), &LobbyInfo::get_host_name);
ClassDB::bind_method(D_METHOD("get_players"), &LobbyInfo::get_players);
ClassDB::bind_method(D_METHOD("get_tags"), &LobbyInfo::get_tags);
ClassDB::bind_method(D_METHOD("get_data"), &LobbyInfo::get_data);

ADD_PROPERTY(PropertyInfo(Variant::STRING, "id"), "", "get_id");
ADD_PROPERTY(PropertyInfo(Variant::STRING, "tags"), "", "get_tags");
ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "data"), "", "get_data");
ADD_PROPERTY(PropertyInfo(Variant::STRING, "lobby_name"), "", "get_lobby_name");
ADD_PROPERTY(PropertyInfo(Variant::STRING, "host_name"), "", "get_host_name");
ADD_PROPERTY(PropertyInfo(Variant::INT, "players"), "", "get_players");
@@ -79,7 +82,8 @@ class LobbyInfo : public Resource {
void set_players(int p_players) { this->players = p_players; }
void set_sealed(bool p_sealed) { this->sealed = p_sealed; }
void set_password_protected(bool p_password_protected) { this->password_protected = p_password_protected; }
void set_tags(const TypedArray<String> &p_tags) { this->tags = p_tags; }
void set_tags(const Dictionary &p_tags) { this->tags = p_tags; }
void set_data(const Dictionary &p_data) { this->data = p_data; }

void set_dict(const Dictionary &p_dict) {
this->set_host(p_dict.get("host", ""));
@@ -90,7 +94,8 @@ class LobbyInfo : public Resource {
this->set_lobby_name(p_dict.get("name", ""));
this->set_host_name(p_dict.get("host_name", ""));
this->set_password_protected(p_dict.get("has_password", false));
this->set_tags(p_dict.get("tags", TypedArray<String>()));
this->set_tags(p_dict.get("tags", Dictionary()));
this->set_data(p_dict.get("public_data", Dictionary()));
}
Dictionary get_dict() const {
Dictionary dict;
@@ -103,10 +108,12 @@ class LobbyInfo : public Resource {
dict["host_name"] = this->get_host_name();
dict["has_password"] = this->is_password_protected();
dict["tags"] = this->get_tags();
dict["public_data"] = this->get_data();
return dict;
}

TypedArray<String> get_tags() const { return tags; }
Dictionary get_data() const { return data; }
Dictionary get_tags() const { return tags; }
String get_id() const { return id; }
String get_lobby_name() const { return lobby_name; }
String get_host() const { return host; }
@@ -123,34 +130,41 @@ class LobbyPeer : public Resource {
String id;
String peer_name;
bool ready = false;
Dictionary data;

protected:
static void _bind_methods() {
ClassDB::bind_method(D_METHOD("get_id"), &LobbyPeer::get_id);
ClassDB::bind_method(D_METHOD("get_peer_name"), &LobbyPeer::get_peer_name);
ClassDB::bind_method(D_METHOD("is_ready"), &LobbyPeer::is_ready);
ClassDB::bind_method(D_METHOD("get_data"), &LobbyPeer::get_data);
ADD_PROPERTY(PropertyInfo(Variant::STRING, "id"), "", "get_id");
ADD_PROPERTY(PropertyInfo(Variant::STRING, "peer_name"), "", "get_peer_name");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "ready"), "", "is_ready");
ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "data"), "", "get_data");
}

public:
void set_id(const String &p_id) { this->id = p_id; }
void set_peer_name(const String &p_peer_name) { this->peer_name = p_peer_name; }
void set_ready(bool p_ready) { this->ready = p_ready; }
void set_data(const Dictionary &p_data) { this->data = p_data; }
void set_dict(const Dictionary &p_dict) {
this->set_id(p_dict.get("id", ""));
this->set_peer_name(p_dict.get("name", ""));
this->set_ready(p_dict.get("ready", ""));
this->set_data(p_dict.get("public_data", Dictionary()));
}
Dictionary get_dict() const {
Dictionary dict;
dict["id"] = this->get_id();
dict["name"] = this->get_peer_name();
dict["ready"] = this->is_ready();
dict["public_data"] = this->get_data();
return dict;
}

Dictionary get_data() const { return data; }
String get_id() const { return id; }
String get_peer_name() const { return peer_name; }
bool is_ready() const { return ready; }
@@ -159,14 +173,13 @@ class LobbyPeer : public Resource {

class LobbyClient : public BlaziumClient {
GDCLASS(LobbyClient, BlaziumClient);
enum CommandType {
LOBBY_REQUEST = 0,
LOBBY_VIEW,
LOBBY_LIST
};
String server_url = "wss://lobby.blazium.app/connect";

protected:
String server_url;
String reconnection_token;
String game_id = "";
Dictionary host_data;
Dictionary peer_data;
Ref<LobbyInfo> lobby;
Ref<LobbyPeer> peer;
TypedArray<LobbyPeer> peers;
@@ -198,9 +211,6 @@ class LobbyClient : public BlaziumClient {

bool has_error() const { return !error.is_empty(); }
String get_error() const { return error; }
LobbyResult(const LobbyResult &p_other) :
error(p_other.error) {}
LobbyResult() {}
};
};

@@ -236,9 +246,6 @@ class LobbyClient : public BlaziumClient {
bool has_error() const { return !error.is_empty(); }
String get_error() const { return error; }
TypedArray<LobbyInfo> get_lobbies() const { return lobbies; }
ListLobbyResult(const ListLobbyResult &p_other) :
error(p_other.error), lobbies(p_other.lobbies) {}
ListLobbyResult() {}
};
};

@@ -287,7 +294,7 @@ class LobbyClient : public BlaziumClient {
};
};

private:
protected:
Ref<WebSocketPeer> _socket;
int _counter = 0;
bool connected = false;
@@ -297,7 +304,13 @@ class LobbyClient : public BlaziumClient {
void _send_data(const Dictionary &p_data);
String _increment_counter();

protected:
enum CommandType {
LOBBY_REQUEST = 0,
LOBBY_VIEW,
LOBBY_LIST,
LOBBY_CALL
};

void _notification(int p_notification);
static void _bind_methods();

@@ -310,6 +323,8 @@ class LobbyClient : public BlaziumClient {
String get_game_id() { return game_id; }
bool is_host() { return lobby->get_host() == peer->get_id(); }
bool get_connected() { return connected; }
Dictionary get_host_data() { return host_data; }
Dictionary get_peer_data() { return peer_data; }
void set_lobby(const Ref<LobbyInfo> &p_lobby) { this->lobby = p_lobby; }
Ref<LobbyInfo> get_lobby() { return lobby; }
void set_peer(const Ref<LobbyPeer> &p_peer) { this->peer = p_peer; }
@@ -318,18 +333,23 @@ class LobbyClient : public BlaziumClient {

bool connect_to_lobby();
void disconnect_from_lobby();
Ref<ViewLobbyResponse> create_lobby(const String &p_lobby_name, const TypedArray<String> &p_tags, int p_max_players, const String &p_password);
Ref<ViewLobbyResponse> create_lobby(const String &p_lobby_name, const Dictionary &p_tags, int p_max_players, const String &p_password);
Ref<ViewLobbyResponse> join_lobby(const String &p_lobby_id, const String &p_password);
Ref<LobbyResponse> leave_lobby();
Ref<ListLobbyResponse> list_lobby(const String &p_title, const int p_max_players, const TypedArray<String> &p_tags, int p_start, int p_count);
Ref<ListLobbyResponse> list_lobby(const Dictionary &p_tags, int p_start, int p_count);
Ref<ViewLobbyResponse> view_lobby(const String &p_lobby_id, const String &p_password);
Ref<LobbyResponse> kick_peer(const String &p_peer_id);
Ref<LobbyResponse> set_lobby_tags(const Dictionary &p_tags);
Ref<LobbyResponse> lobby_chat(const String &chat_message);
Ref<LobbyResponse> lobby_ready(bool p_ready);
Ref<LobbyResponse> set_peer_name(const String &p_peer_name);
Ref<LobbyResponse> seal_lobby(bool seal);
Ref<LobbyResponse> lobby_data(const Variant &p_peer_data);
Ref<LobbyResponse> lobby_data_to(const Variant &p_peer_data, const String &p_target_peer);
Ref<LobbyResponse> lobby_call(const String &p_method, const Array &p_args);
Ref<LobbyResponse> lobby_notify(const Variant &p_peer_data);
Ref<LobbyResponse> peer_notify(const Variant &p_peer_data, const String &p_target_peer);
Ref<LobbyResponse> lobby_data(const Dictionary &p_lobby_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> set_peers_data(const Dictionary &p_peer_data, bool p_is_private);

LobbyClient();
~LobbyClient();
4 changes: 4 additions & 0 deletions modules/blazium_sdk/register_types.cpp
Original file line number Diff line number Diff line change
@@ -30,6 +30,7 @@

#include "register_types.h"
#include "blazium_client.h"
#include "lobby/authoritative_client.h"
#include "lobby/lobby_client.h"

void initialize_blazium_sdk_module(ModuleInitializationLevel p_level) {
@@ -44,6 +45,9 @@ void initialize_blazium_sdk_module(ModuleInitializationLevel p_level) {
GDREGISTER_CLASS(LobbyClient::ListLobbyResponse);
GDREGISTER_CLASS(LobbyClient::ViewLobbyResponse::ViewLobbyResult);
GDREGISTER_CLASS(LobbyClient::ViewLobbyResponse);
GDREGISTER_CLASS(AuthoritativeClient);
GDREGISTER_CLASS(AuthoritativeClient::LobbyCallResponse);
GDREGISTER_CLASS(AuthoritativeClient::LobbyCallResponse::LobbyCallResult);
}
}

0 comments on commit 313f628

Please sign in to comment.