Skip to content

Commit

Permalink
test sessions interface, etc
Browse files Browse the repository at this point in the history
* add ERR_FAIL_NULL to EOSG wrappers in options
* fix passing bool to EOS options from Godot
  • Loading branch information
3ddelano committed Dec 22, 2023
1 parent 5e53055 commit 8cac770
Show file tree
Hide file tree
Showing 11 changed files with 138 additions and 51 deletions.
86 changes: 82 additions & 4 deletions sample/Main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ func test_sanctions_interface():

func test_sessions_interface():
var bucket_id = "mode:region01:map01"

var create_sess_mod_opts = EOS.Sessions.CreateSessionModificationOptions.new()
create_sess_mod_opts.session_name = "TestSession001"
create_sess_mod_opts.bucket_id = bucket_id
Expand All @@ -567,9 +567,87 @@ func test_sessions_interface():
var update_sess = await EOS.get_instance().sessions_interface_update_session_callback
print("--- Sessions: update_session: ", update_sess)

var copy_active_session_opts = EOS.Sessions.CopyActiveSessionDetailsOptions.new()
copy_active_session_opts.session_name = "TestSession001"
print("--- Sessions: copy_active_session_details: ", EOS.Sessions.SessionsInterface.copy_active_session_details(copy_active_session_opts))
#var dump_sess_opts = EOS.Sessions.DumpSessionStateOptions.new()
#dump_sess_opts.session_name = "TestSession001"
#print("--- Sessions: dump_session_state: ", EOS.Sessions.SessionsInterface.dump_session_state(dump_sess_opts))

#var copy_active_session_opts = EOS.Sessions.CopyActiveSessionDetailsOptions.new()
#copy_active_session_opts.session_name = "TestSession001"
#var copy_active_session = EOS.Sessions.SessionsInterface.copy_active_session_details(copy_active_session_opts)
#print("--- Sessions: copy_active_session_details: ", copy_active_session)

#var active_session: EOSGActiveSession = copy_active_session.active_session
#print("--- Sessions: ActiveSession: copy_info:", active_session.copy_info())


# Modify session
# var update_sess_mod_opts = EOS.Sessions.UpdateSessionModificationOptions.new()
# update_sess_mod_opts.session_name = "TestSession001"
# var update_sess_mod = EOS.Sessions.SessionsInterface.update_session_modification(update_sess_mod_opts)
# print("--- Sessions: update_session_modification: ", update_sess_mod)
# session_mod = update_sess_mod.session_modification

# print("--- Sessions: SessionModification: set_invites_allowed: ", session_mod.set_invites_allowed(false))

# update_sess_opts = EOS.Sessions.UpdateSessionOptions.new()
# update_sess_opts.session_modification = session_mod
# EOS.Sessions.SessionsInterface.update_session(update_sess_opts)

# update_sess = await EOS.get_instance().sessions_interface_update_session_callback
# print("--- Sessions: update_session: ", update_sess)


# Search session
#var create_search_opts = EOS.Sessions.CreateSessionSearchOptions.new()
#var create_session_search = EOS.Sessions.SessionsInterface.create_session_search(create_search_opts)
#print("--- Sessions: create_session_search: ", create_session_search)

#var session_search: EOSGSessionSearch = create_session_search.session_search
#session_search.set_parameter(EOS.Sessions.SEARCH_BUCKET_ID, bucket_id, EOS.ComparisonOp.Equal)
#session_search.find(EOSGRuntime.local_product_user_id)
#print("--- Sessions: SessionSearch: find: ", await EOS.get_instance().session_search_find_callback)

#var search_result_count = session_search.get_search_result_count()
#print("--- Sessions: SessionSearch: get_search_result_count: ", search_result_count)

#for i in range(search_result_count):
#var search_result = session_search.copy_search_result_by_index(i)
#print("--- Sessions: copy_search_result_by_index(%d): " % i, search_result)

#var session_details: EOSGSessionDetails = search_result.session_details
#print("--- Sessions: SessionDetails: copy_info: ", session_details.copy_info())


# Join session
# var join_sess_opts = EOS.Sessions.JoinSessionOptions.new()
# join_sess_opts.session_name = "TestSession001"
# join_sess_opts.presence_enabled = true
# join_sess_opts.session_details = EOSGSesssionDetails here
# EOS.Sessions.SessionsInterface.join_session(join_sess_opts)
# print("--- Sessions: join_session: ", await EOS.get_instance().sessions_interface_join_session_callback)


# Register players
var reg_players_opts = EOS.Sessions.RegisterPlayersOptions.new()
reg_players_opts.session_name = "TestSession001"
reg_players_opts.players_to_register = [EOSGRuntime.local_product_user_id]
EOS.Sessions.SessionsInterface.register_players(reg_players_opts)
print("--- Sessions: register_players: ", await EOS.get_instance().sessions_interface_register_players_callback)


# Start session
var start_sess_opts = EOS.Sessions.StartSessionOptions.new()
start_sess_opts.session_name = "TestSession001"

EOS.Sessions.SessionsInterface.start_session(start_sess_opts)
print("--- Sessions: start_session: ", await EOS.get_instance().sessions_interface_start_session_callback)


# Destroy session
var destroy_sess_opts = EOS.Sessions.DestroySessionOptions.new()
destroy_sess_opts.session_name = "TestSession001"
EOS.Sessions.SessionsInterface.destroy_session(destroy_sess_opts)
print("--- Sessions: destroy_session: ", await EOS.get_instance().sessions_interface_destroy_session_callback)



Expand Down
16 changes: 13 additions & 3 deletions sample/addons/epic-online-services-godot/eos.gd
Original file line number Diff line number Diff line change
Expand Up @@ -1634,7 +1634,7 @@ class Lobby:
func _init():
super._init("CreateLobbySearchOptions")

var max_results: int
var max_results = 10

class CopyLobbyDetailsByInviteIdOptions extends BaseClass:
func _init():
Expand Down Expand Up @@ -2874,7 +2874,7 @@ class Sessions:
func _init():
super._init("CreateSessionModificationOptions")

var allowed_platform_ids = [OnlinePlatformType.Epic] # Array[int]
var allowed_platform_ids = [] # Array[int]
var bucket_id: String
var local_user_id = EOSGRuntime.local_product_user_id
var max_players: int
Expand All @@ -2887,7 +2887,7 @@ class Sessions:
func _init():
super._init("CreateSessionSearchOptions")

var max_search_results: int
var max_search_results = 10

class GetInviteIdByIndexOptions extends BaseClass:
func _init():
Expand Down Expand Up @@ -3355,12 +3355,22 @@ enum ExternalCredentialType {
AmazonAccessToken = 17
}

## This seems to be outdated
enum OnlinePlatformType {
Unknown = 0,
Epic = 100,
Steam = 4000
}

# TODO: remove once OnlinePlatformType is documented in EOS docs
enum Undocumented_OnlinePlatformType {
Unknown = 0,
A = 1000,
B = 2000,
C = 3000,
D = 4000,
}

enum LoginStatus {
NotLoggedIn = 0,
UsingLocalProfile = 1,
Expand Down
16 changes: 8 additions & 8 deletions sample/components/StyledPopupWindow/StyledPopupWindowTheme.tres

Large diffs are not rendered by default.

27 changes: 0 additions & 27 deletions sample/env.gd

This file was deleted.

2 changes: 2 additions & 0 deletions sample/scripts/Env.gd
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ func load_env(p_path := "res://.env"):
var ret = {}
while not file.eof_reached():
var line = file.get_line()
# skip comment lines
if line.lstrip(" ").begins_with("#"): continue
var tokens = line.split("=", false, 1)
if tokens.size() == 2:
ret[tokens[0]] = tokens[1].lstrip("\"").rstrip("\"");
Expand Down
3 changes: 3 additions & 0 deletions src/auth_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ void IEOS::auth_interface_verify_id_token(Ref<RefCounted> p_options) {

void IEOS::auth_interface_link_account(Ref<RefCounted> p_options) {
Ref<EOSGContinuanceToken> p_continuance_token = Object::cast_to<EOSGContinuanceToken>(p_options->get("continuance_token"));
ERR_FAIL_NULL_MSG(p_continuance_token, "Error linking account. LinkAccountOptions.continuance_token is null.");
ERR_FAIL_NULL_MSG(p_continuance_token->get_internal(), "Error linking account. EOSGContinuanceToken is null.");

CharString p_local_user_id = VARIANT_TO_CHARSTRING(p_options->get("local_user_id"));

EOS_Auth_LinkAccountOptions options;
Expand Down
5 changes: 5 additions & 0 deletions src/connect_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ void IEOS::connect_interface_delete_device_id(Ref<RefCounted> p_options) {

void IEOS::connect_interface_create_user(Ref<RefCounted> p_options) {
Ref<EOSGContinuanceToken> p_continuance_token = Object::cast_to<EOSGContinuanceToken>(p_options->get("continuance_token"));
ERR_FAIL_NULL_MSG(p_continuance_token, "Error linking account. LinkAccountOptions.continuance_token is null.");
ERR_FAIL_NULL_MSG(p_continuance_token->get_internal(), "Error linking account. EOSGContinuanceToken is null.");

EOS_Connect_CreateUserOptions options;
memset(&options, 0, sizeof(options));
Expand Down Expand Up @@ -313,6 +315,9 @@ void IEOS::connect_interface_query_product_user_id_mapping(Ref<RefCounted> p_opt

void IEOS::connect_interface_link_account(Ref<RefCounted> p_options) {
Ref<EOSGContinuanceToken> p_continuance_token = Object::cast_to<EOSGContinuanceToken>(p_options->get("continuance_token"));
ERR_FAIL_NULL_MSG(p_continuance_token, "Error linking account. LinkAccountOptions.continuance_token is null.");
ERR_FAIL_NULL_MSG(p_continuance_token->get_internal(), "Error linking account. EOSGContinuanceToken is null.");

CharString local_user_id = VARIANT_TO_CHARSTRING(p_options->get("local_user_id"));

EOS_Connect_LinkAccountOptions options;
Expand Down
7 changes: 6 additions & 1 deletion src/lobby_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,11 @@ void IEOS::lobby_interface_destroy_lobby(Ref<RefCounted> p_options) {
}

void IEOS::lobby_interface_join_lobby(Ref<RefCounted> p_options) {
CharString local_user_id = VARIANT_TO_CHARSTRING(p_options->get("local_user_id"));
Ref<EOSGLobbyDetails> p_lobby_details = Object::cast_to<EOSGLobbyDetails>(p_options->get("lobby_details"));
ERR_FAIL_NULL_MSG(p_lobby_details, "Error joining lobby. JoinLobbyOptions.lobby_details is null.");
ERR_FAIL_NULL_MSG(p_lobby_details->get_internal(), "Error joining lobby. EOSGLobbyDetails is null.");

CharString local_user_id = VARIANT_TO_CHARSTRING(p_options->get("local_user_id"));

EOS_Lobby_JoinLobbyOptions options;
memset(&options, 0, sizeof(options));
Expand Down Expand Up @@ -163,6 +166,8 @@ Dictionary IEOS::lobby_interface_update_lobby_modification(Ref<RefCounted> p_opt

void IEOS::lobby_interface_update_lobby(Ref<RefCounted> p_options) {
Ref<EOSGLobbyModification> lobby_modification = Object::cast_to<EOSGLobbyModification>(p_options->get("lobby_modification"));
ERR_FAIL_NULL_MSG(lobby_modification, "Error updating lobby. UpdateLobbyOptions.lobby_modification is null.");
ERR_FAIL_NULL_MSG(lobby_modification->get_internal(), "Error updating lobby. EOSGLobbyModification is null.");

EOS_Lobby_UpdateLobbyOptions options;
memset(&options, 0, sizeof(options));
Expand Down
5 changes: 4 additions & 1 deletion src/presence_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,11 @@ void IEOS::presence_interface_query_presence(Ref<RefCounted> p_options) {
}

void IEOS::presence_interface_set_presence(Ref<RefCounted> p_options) {
CharString local_user_id = VARIANT_TO_CHARSTRING(p_options->get("local_user_id"));
Ref<EOSGPresenceModification> presence_modification = Object::cast_to<EOSGPresenceModification>(p_options->get("presence_modification"));
ERR_FAIL_NULL_MSG(presence_modification, "Error setting presence. SetPresenceOptions.presence_modification is null.");
ERR_FAIL_NULL_MSG(presence_modification->get_internal(), "Error setting presence. EOSGPresenceModification is null.");

CharString local_user_id = VARIANT_TO_CHARSTRING(p_options->get("local_user_id"));

EOS_Presence_SetPresenceOptions options;
memset(&options, 0, sizeof(options));
Expand Down
16 changes: 12 additions & 4 deletions src/sessions_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ Dictionary IEOS::sessions_interface_create_session_modification(Ref<RefCounted>
options.BucketId = bucket_id.get_data();
options.MaxPlayers = static_cast<uint32_t>(max_players);
options.LocalUserId = eosg_string_to_product_user_id(local_user_id.get_data());
options.bPresenceEnabled = presence_enabled;
options.bPresenceEnabled = presence_enabled ? EOS_TRUE : EOS_FALSE;
options.SessionId = session_id.get_data();
options.bSanctionsEnabled = sanctions_enabled;
options.bSanctionsEnabled = sanctions_enabled ? EOS_TRUE : EOS_FALSE;
options.AllowedPlatformIdsCount = allowed_platform_ids.size();
if (allowed_platform_ids.size() > 0) {
uint32_t *allowed_platform_ids_array = (uint32_t *)malloc(sizeof(uint32_t) * allowed_platform_ids.size());
Expand Down Expand Up @@ -124,9 +124,12 @@ Dictionary IEOS::sessions_interface_create_session_search(Ref<RefCounted> p_opti
}

int IEOS::sessions_interface_dump_session_state(Ref<RefCounted> p_options) {
CharString session_name = VARIANT_TO_CHARSTRING(p_options->get("session_name"));

EOS_Sessions_DumpSessionStateOptions options;
memset(&options, 0, sizeof(options));
options.ApiVersion = EOS_SESSIONS_DUMPSESSIONSTATE_API_LATEST;
options.SessionName = session_name.get_data();

return static_cast<int>(EOS_Sessions_DumpSessionState(s_sessionsInterface, &options));
}
Expand Down Expand Up @@ -227,8 +230,11 @@ void IEOS::sessions_interface_end_session(Ref<RefCounted> p_options) {
}

void IEOS::sessions_interface_join_session(Ref<RefCounted> p_options) {
CharString session_name = VARIANT_TO_CHARSTRING(p_options->get("session_name"));
Ref<EOSGSessionDetails> session_details = Object::cast_to<EOSGSessionDetails>(p_options->get("session_details"));
ERR_FAIL_NULL_MSG(session_details, "Error joining session. JoinSessionOptions.session_details is null.");
ERR_FAIL_NULL_MSG(session_details->get_internal(), "Error joining session. EOSGSessionDetails is null.");

CharString session_name = VARIANT_TO_CHARSTRING(p_options->get("session_name"));
CharString local_user_id = VARIANT_TO_CHARSTRING(p_options->get("local_user_id"));
bool presence_enabled = p_options->get("presence_enabled");

Expand All @@ -238,7 +244,7 @@ void IEOS::sessions_interface_join_session(Ref<RefCounted> p_options) {
options.SessionName = session_name.get_data();
options.SessionHandle = session_details->get_internal();
options.LocalUserId = eosg_string_to_product_user_id(local_user_id.get_data());
options.bPresenceEnabled = presence_enabled;
options.bPresenceEnabled = presence_enabled ? EOS_TRUE : EOS_FALSE;
p_options->reference();

EOS_Sessions_JoinSession(s_sessionsInterface, &options, (void *)*p_options, [](const EOS_Sessions_JoinSessionCallbackInfo *data) {
Expand Down Expand Up @@ -407,6 +413,8 @@ void IEOS::sessions_interface_unregister_players(Ref<RefCounted> p_options) {

void IEOS::sessions_interface_update_session(Ref<RefCounted> p_options) {
Ref<EOSGSessionModification> session_modification = Object::cast_to<EOSGSessionModification>(p_options->get("session_modification"));
ERR_FAIL_NULL_MSG(session_modification, "Error updating session. UpdateSessionOptions.session_modification is null.");
ERR_FAIL_NULL_MSG(session_modification->get_internal(), "Error updating session. EOSGSessionModification is null.");

EOS_Sessions_UpdateSessionOptions options;
memset(&options, 0, sizeof(options));
Expand Down
6 changes: 3 additions & 3 deletions src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -582,9 +582,9 @@ static EOS_Lobby_LocalRTCOptions eosg_variant_to_lobby_local_rtc_options(Variant
EOS_Lobby_LocalRTCOptions options;
options.ApiVersion = EOS_LOBBY_LOCALRTCOPTIONS_API_LATEST;
options.Flags = flags;
options.bUseManualAudioInput = use_manual_audio_input;
options.bUseManualAudioOutput = use_manual_audio_output;
options.bLocalAudioDeviceInputStartsMuted = local_audio_device_input_starts_muted;
options.bUseManualAudioInput = use_manual_audio_input ? EOS_TRUE : EOS_FALSE;
options.bUseManualAudioOutput = use_manual_audio_output ? EOS_TRUE : EOS_FALSE;
options.bLocalAudioDeviceInputStartsMuted = local_audio_device_input_starts_muted ? EOS_TRUE : EOS_FALSE;

return options;
}
Expand Down

0 comments on commit 8cac770

Please sign in to comment.