Skip to content

Commit

Permalink
Merge pull request #23 from TaloDev/develop
Browse files Browse the repository at this point in the history
Release 0.8.0
  • Loading branch information
tudddorrr authored Sep 21, 2024
2 parents 58bde26 + 9629104 commit 923b972
Show file tree
Hide file tree
Showing 14 changed files with 213 additions and 686 deletions.
682 changes: 21 additions & 661 deletions LICENSE

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions addons/talo/apis/api.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ class_name TaloAPI extends Node
var client: TaloClient

func _init(base_path: String):
name = "Talo%s" % [base_path]
client = TaloClient.new(base_path)
add_child(client)
15 changes: 14 additions & 1 deletion addons/talo/apis/player_auth_api.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var session_manager = TaloSessionManager.new()
var last_error: Variant = null

func _handle_error(res: Dictionary, ret: Variant = FAILED) -> Variant:
if res.body.has("errorCode"):
if res.body != null and res.body.has("errorCode"):
last_error = TaloAuthError.new(res.body.errorCode)
else:
last_error = TaloAuthError.new("API_ERROR")
Expand Down Expand Up @@ -124,3 +124,16 @@ func toggle_verification(current_password: String, verification_enabled: bool, e
return OK
_:
return _handle_error(res)

func delete_account(current_password: String) -> Error:
var res = await client.make_request(HTTPClient.METHOD_DELETE, "/", {
currentPassword = current_password
})

match (res.status):
204:
session_manager.clear_session()
Talo.current_alias = null
return OK
_:
return _handle_error(res)
2 changes: 1 addition & 1 deletion addons/talo/plugin.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
name="Talo Game Services"
description="Talo (https://trytalo.com) is an open-source game backend with services designed to help you build games faster. You can currently:\n\n- Identify and authenticate players\n- Store persistent data across players\n- Track events (levelling up, finding loot, etc)\n- Display high scores with leaderboards\n- Store and load player saves\n- Load game config options and flags from the cloud\n- Get feedback directly from your players"
author="trytalo"
version="0.7.1"
version="0.8.0"
script="talo_autoload.gd"
9 changes: 7 additions & 2 deletions addons/talo/samples/authentication/authentication.tscn
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
[gd_scene load_steps=10 format=3 uid="uid://bwh4ytfs4g7js"]
[gd_scene load_steps=11 format=3 uid="uid://bwh4ytfs4g7js"]

[ext_resource type="PackedScene" uid="uid://bjopxp3rhpinb" path="res://addons/talo/samples/authentication/states/register.tscn" id="1_5qw25"]
[ext_resource type="Script" path="res://addons/talo/samples/authentication/scripts/authentication.gd" id="1_aqcrf"]
[ext_resource type="PackedScene" uid="uid://co0uou3idf65q" path="res://addons/talo/samples/authentication/states/login.tscn" id="2_fsclp"]
[ext_resource type="PackedScene" uid="uid://dv6o0q01wov2o" path="res://addons/talo/samples/authentication/states/verify.tscn" id="3_njdp7"]
[ext_resource type="PackedScene" uid="uid://b6mypp2qa8m4u" path="res://addons/talo/samples/authentication/states/change_email.tscn" id="4_vngav"]
[ext_resource type="PackedScene" uid="uid://bdfuoxfyblqtw" path="res://addons/talo/samples/authentication/states/change_password.tscn" id="5_q15qy"]
[ext_resource type="PackedScene" uid="uid://hmdhr4bk3v1a" path="res://addons/talo/samples/authentication/states/in_game.tscn" id="7_sxmru"]
[ext_resource type="PackedScene" uid="uid://df6qjcnw1atpn" path="res://addons/talo/samples/authentication/states/in_game.tscn" id="7_sxmru"]
[ext_resource type="PackedScene" uid="uid://b0nvmmnpff27a" path="res://addons/talo/samples/authentication/states/forgot_password.tscn" id="8_tqrpb"]
[ext_resource type="PackedScene" uid="uid://8aqpg6o0a1xx" path="res://addons/talo/samples/authentication/states/reset_password.tscn" id="9_6wobc"]
[ext_resource type="PackedScene" uid="uid://d17bvaxw1qew4" path="res://addons/talo/samples/authentication/states/delete_account.tscn" id="10_gndcp"]

[node name="Authentication" type="Node2D"]
script = ExtResource("1_aqcrf")
Expand Down Expand Up @@ -55,3 +56,7 @@ visible = false
[node name="ResetPassword" parent="UI/States" instance=ExtResource("9_6wobc")]
unique_name_in_owner = true
visible = false

[node name="DeleteAccount" parent="UI/States" instance=ExtResource("10_gndcp")]
unique_name_in_owner = true
visible = false
5 changes: 5 additions & 0 deletions addons/talo/samples/authentication/scripts/authentication.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ extends Node2D
@onready var change_email = %ChangeEmail
@onready var forgot_password = %ForgotPassword
@onready var reset_password = %ResetPassword
@onready var delete_account = %DeleteAccount
@onready var all_states = %States

func _ready() -> void:
Expand All @@ -27,6 +28,7 @@ func _configure_signals():

in_game.go_to_change_password.connect(func (): _make_state_visible(change_password))
in_game.go_to_change_email.connect(func (): _make_state_visible(change_email))
in_game.go_to_delete.connect(func (): _make_state_visible(delete_account))
in_game.logout_success.connect(func (): _make_state_visible(login))

change_password.password_change_success.connect(func (): _make_state_visible(in_game))
Expand All @@ -41,4 +43,7 @@ func _configure_signals():
reset_password.password_reset_success.connect(func (): _make_state_visible(login))
reset_password.go_to_forgot_password.connect(func (): _make_state_visible(forgot_password))

delete_account.delete_account_success.connect(func (): _make_state_visible(login))
delete_account.go_to_game.connect(func (): _make_state_visible(in_game))

Talo.players.identified.connect(func (player): _make_state_visible(in_game))
6 changes: 5 additions & 1 deletion addons/talo/samples/authentication/scripts/in_game.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ extends Node2D

signal go_to_change_password
signal go_to_change_email
signal go_to_delete
signal logout_success

@onready var username: Label = %Username
Expand All @@ -10,7 +11,7 @@ func _ready() -> void:
Talo.players.identified.connect(_on_player_identified)

func _on_player_identified(player: TaloPlayer) -> void:
username.text = username.text.replace("{username}", Talo.current_alias.identifier)
username.text = "What would you like to do,\n%s?" % [Talo.current_alias.identifier]

func _on_change_password_pressed() -> void:
go_to_change_password.emit()
Expand All @@ -21,3 +22,6 @@ func _on_change_email_pressed() -> void:
func _on_logout_pressed() -> void:
await Talo.player_auth.logout()
logout_success.emit()

func _on_delete_pressed() -> void:
go_to_delete.emit()
27 changes: 27 additions & 0 deletions addons/talo/samples/authentication/states/delete_account.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
extends Node2D

signal delete_account_success
signal go_to_game

@onready var current_password: TextEdit = %CurrentPassword
@onready var validation_label: Label = %ValidationLabel

func _on_delete_pressed() -> void:
validation_label.text = ""

if not current_password.text:
validation_label.text = "Current password is required"
return

var res = await Talo.player_auth.delete_account(current_password.text)
if res != OK:
match Talo.player_auth.last_error.get_code():
TaloAuthError.ErrorCode.INVALID_CREDENTIALS:
validation_label.text = "Current password is incorrect"
_:
validation_label.text = Talo.player_auth.last_error.get_string()
else:
delete_account_success.emit()

func _on_cancel_pressed() -> void:
go_to_game.emit()
93 changes: 93 additions & 0 deletions addons/talo/samples/authentication/states/delete_account.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
[gd_scene load_steps=7 format=3 uid="uid://d17bvaxw1qew4"]

[ext_resource type="Script" path="res://addons/talo/samples/authentication/states/delete_account.gd" id="1_ggdf5"]
[ext_resource type="Theme" uid="uid://ce2uyi827vc5x" path="res://addons/talo/samples/authentication/assets/theme.tres" id="2_n2cbx"]

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_xxxlc"]
bg_color = Color(0.784314, 0.156863, 0.156863, 1)

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_fa3fr"]
bg_color = Color(0.690196, 0.129412, 0.129412, 1)

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_hijpl"]
bg_color = Color(0.603922, 0.105882, 0.105882, 1)

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_wems6"]
bg_color = Color(0.603922, 0.105882, 0.105882, 1)

[node name="DeleteAccount" type="Node2D"]
script = ExtResource("1_ggdf5")

[node name="UI" type="Control" parent="."]
layout_mode = 3
anchors_preset = 0
offset_right = 1080.0
offset_bottom = 720.0

[node name="Background" type="ColorRect" parent="UI"]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
color = Color(0.121569, 0.160784, 0.215686, 1)

[node name="MarginContainer" type="MarginContainer" parent="UI"]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
theme_override_constants/margin_left = 40
theme_override_constants/margin_top = 40
theme_override_constants/margin_right = 40
theme_override_constants/margin_bottom = 40

[node name="VBoxContainer" type="VBoxContainer" parent="UI/MarginContainer"]
layout_mode = 2
size_flags_vertical = 4
theme_override_constants/separation = 24

[node name="Title" type="Label" parent="UI/MarginContainer/VBoxContainer"]
layout_mode = 2
size_flags_vertical = 0
theme = ExtResource("2_n2cbx")
text = "Delete account"
horizontal_alignment = 1

[node name="CurrentPassword" type="TextEdit" parent="UI/MarginContainer/VBoxContainer"]
unique_name_in_owner = true
custom_minimum_size = Vector2(400, 40)
layout_mode = 2
size_flags_horizontal = 4
theme = ExtResource("2_n2cbx")
placeholder_text = "Current password"

[node name="Delete" type="Button" parent="UI/MarginContainer/VBoxContainer"]
custom_minimum_size = Vector2(200, 40)
layout_mode = 2
size_flags_horizontal = 4
theme = ExtResource("2_n2cbx")
theme_override_styles/normal = SubResource("StyleBoxFlat_xxxlc")
theme_override_styles/hover = SubResource("StyleBoxFlat_fa3fr")
theme_override_styles/pressed = SubResource("StyleBoxFlat_hijpl")
theme_override_styles/focus = SubResource("StyleBoxFlat_wems6")
text = "Delete account"

[node name="Cancel" type="Button" parent="UI/MarginContainer/VBoxContainer"]
custom_minimum_size = Vector2(200, 40)
layout_mode = 2
size_flags_horizontal = 4
theme = ExtResource("2_n2cbx")
text = "Cancel"

[node name="ValidationLabel" type="Label" parent="UI/MarginContainer/VBoxContainer"]
unique_name_in_owner = true
custom_minimum_size = Vector2(400, 2.08165e-12)
layout_mode = 2
size_flags_horizontal = 4

[connection signal="pressed" from="UI/MarginContainer/VBoxContainer/Delete" to="." method="_on_delete_pressed"]
[connection signal="pressed" from="UI/MarginContainer/VBoxContainer/Cancel" to="." method="_on_cancel_pressed"]
10 changes: 9 additions & 1 deletion addons/talo/samples/authentication/states/in_game.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=3 format=3 uid="uid://hmdhr4bk3v1a"]
[gd_scene load_steps=3 format=3 uid="uid://df6qjcnw1atpn"]

[ext_resource type="Script" path="res://addons/talo/samples/authentication/scripts/in_game.gd" id="1_is44q"]
[ext_resource type="Theme" uid="uid://ce2uyi827vc5x" path="res://addons/talo/samples/authentication/assets/theme.tres" id="2_7u3gt"]
Expand Down Expand Up @@ -68,6 +68,14 @@ size_flags_horizontal = 4
theme = ExtResource("2_7u3gt")
text = "Log out"

[node name="Delete" type="Button" parent="UI/MarginContainer/VBoxContainer"]
custom_minimum_size = Vector2(200, 40)
layout_mode = 2
size_flags_horizontal = 4
theme = ExtResource("2_7u3gt")
text = "Delete account"

[connection signal="pressed" from="UI/MarginContainer/VBoxContainer/ChangePassword" to="." method="_on_change_password_pressed"]
[connection signal="pressed" from="UI/MarginContainer/VBoxContainer/ChangeEmail" to="." method="_on_change_email_pressed"]
[connection signal="pressed" from="UI/MarginContainer/VBoxContainer/Logout" to="." method="_on_logout_pressed"]
[connection signal="pressed" from="UI/MarginContainer/VBoxContainer/Delete" to="." method="_on_delete_pressed"]
33 changes: 20 additions & 13 deletions addons/talo/talo_client.gd
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
class_name TaloClient extends HTTPRequest
class_name TaloClient extends Node

var _base_url: String

func _init(base_url: String):
_base_url = base_url
name = "Client"

func _get_method_name(method: HTTPClient.Method):
match method:
Expand All @@ -15,7 +16,7 @@ func _get_method_name(method: HTTPClient.Method):

func _simulate_offline_request():
return [
RESULT_CANT_CONNECT,
HTTPRequest.RESULT_CANT_CONNECT,
0,
PackedStringArray(),
PackedByteArray()
Expand All @@ -28,16 +29,19 @@ func make_request(method: HTTPClient.Method, url: String, body: Dictionary = {},
var all_headers = headers if continuity else _build_headers(headers)
var request_body = "" if body.keys().is_empty() else JSON.stringify(body)

request(full_url, all_headers, method, request_body)
var http_request = HTTPRequest.new()
add_child(http_request)
http_request.name = "%s %s" % [_get_method_name(method), url]

var res = _simulate_offline_request() if Talo.offline_mode_enabled() else await request_completed
http_request.request(full_url, all_headers, method, request_body)
var res = _simulate_offline_request() if Talo.offline_mode_enabled() else await http_request.request_completed
var status = res[1]

var response_body = res[3]
var json = JSON.new()
json.parse(response_body.get_string_from_utf8())

if res[0] != RESULT_SUCCESS:
if res[0] != HTTPRequest.RESULT_SUCCESS:
json.set_data({
message =
"Request failed: result %s, details: https://docs.godotengine.org/en/stable/classes/class_httprequest.html#enum-httprequest-result" % res[0]
Expand All @@ -63,9 +67,11 @@ func make_request(method: HTTPClient.Method, url: String, body: Dictionary = {},
if ret.status >= 400:
handle_error(ret)

if res[0] != RESULT_SUCCESS or ret.status >= 500:
if res[0] != HTTPRequest.RESULT_SUCCESS or ret.status >= 500:
Talo.continuity_manager.push_request(method, full_url, body, all_headers, continuity_timestamp)

http_request.queue_free()

return ret

func _build_headers(extra_headers: Array[String] = []) -> Array[String]:
Expand Down Expand Up @@ -99,12 +105,13 @@ func _build_full_url(url: String) -> String:
]

func handle_error(res: Dictionary) -> void:
if res.body.has("message"):
push_error("%s: %s" % [res.status, res.body.message])
return

if res.body.has("errors"):
push_error("%s: %s" % [res.status, res.body.errors])
return
if res.body != null:
if res.body.has("message"):
push_error("%s: %s" % [res.status, res.body.message])
return

if res.body.has("errors"):
push_error("%s: %s" % [res.status, res.body.errors])
return

push_error("%s: Unknown error" % res.status)
3 changes: 2 additions & 1 deletion addons/talo/utils/continuity_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class_name TaloContinuityManager extends Timer
var _client: TaloClient
var _requests: Array = []

const _continuity_path = "user://talo_continuity.bin"
const _continuity_path = "user://tc.bin"
const _continuity_timestamp_header = "X-Talo-Continuity-Timestamp"

const _excluded_endpoints: Array[String] = [
Expand All @@ -13,6 +13,7 @@ const _excluded_endpoints: Array[String] = [
]

func _ready() -> void:
name = "TaloContinuityManager"
_client = TaloClient.new("")
add_child(_client)

Expand Down
11 changes: 7 additions & 4 deletions addons/talo/utils/crypto_manager.gd
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
class_name TaloCryptoManager extends Node

var _key_file_path = "user://talo_init.bin"
var _key_file_path = "user://ti.bin"

func _get_pass() -> String:
return Talo.settings.get_value("", "access_key")
if OS.has_feature("web"):
return Talo.settings.get_value("", "access_key")

return OS.get_unique_id()

func _init() -> void:
if not FileAccess.file_exists(_key_file_path):
if _get_pass().is_empty():
push_error("Talo access_key in settings.cfg is empty")
push_error("Unable to create key file: cannot generate a suitable password")
return

var crypto = Crypto.new()
Expand All @@ -20,7 +23,7 @@ func _init() -> void:

func get_key() -> String:
if not FileAccess.file_exists(_key_file_path):
push_error("Talo key file has not been created: access_key might be empty")
push_error("Talo key file has not been created")
return ""

var file = FileAccess.open_encrypted_with_pass(_key_file_path, FileAccess.READ, _get_pass())
Expand Down
2 changes: 1 addition & 1 deletion addons/talo/utils/saves_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var current_save: TaloGameSave
var _registered_saved_objects: Array[TaloSavedObject]
var _loaded_loadables: Array[String]

const _offline_saves_path = "user://talo_saves.bin"
const _offline_saves_path = "user://ts.bin"

func read_offline_saves() -> Array[TaloGameSave]:
if not FileAccess.file_exists(_offline_saves_path):
Expand Down

0 comments on commit 923b972

Please sign in to comment.