Skip to content

Commit 6159dd2

Browse files
committed
fix(SteamClient): modernize settings and fix steamcmd stderr parsing
1 parent fd641f6 commit 6159dd2

File tree

5 files changed

+72
-37
lines changed

5 files changed

+72
-37
lines changed

core/steam_client.gd

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@ signal install_progressed(app_id: String, current: int, total: int)
3939

4040
var steamcmd_dir := "/".join([OS.get_environment("HOME"), ".steam", "steamcmd"])
4141
var steamcmd := "/".join([steamcmd_dir, "steamcmd.sh"])
42+
var steamcmd_stderr: FileAccess
4243
var proc: InteractiveProcess
4344
var state: STATE = STATE.BOOT
4445
var is_logged_in := false
45-
var client_started := false
46+
var client_started := false
4647

4748
var cmd_queue: Array[String] = []
4849
var current_cmd := ""
@@ -496,6 +497,16 @@ func _thread_process(_delta: float) -> void:
496497
# Read the output from the process
497498
var output := proc.read()
498499

500+
# Also read output from the stderr file
501+
if steamcmd_stderr:
502+
#logger.debug("steamcmd-stderr: Current position:", steamcmd_stderr.get_position(), "Current size:", steamcmd_stderr.get_length())
503+
var remaining_data := steamcmd_stderr.get_length() - steamcmd_stderr.get_position()
504+
if remaining_data > 0:
505+
var data := steamcmd_stderr.get_buffer(remaining_data)
506+
var stderr := data.get_string_from_utf8()
507+
logger.debug("steamcmd-stderr: " + stderr)
508+
output += stderr
509+
499510
# Return if there is no output from the process
500511
if output == "":
501512
return
@@ -509,6 +520,29 @@ func _thread_process(_delta: float) -> void:
509520
for line in lines:
510521
logger.debug("steamcmd: " + line)
511522

523+
# Wait for "Redirecting stderr to" to open stderr file.
524+
# Because of new behavior as of ~2024-06, steamcmd outputs stderr to a file
525+
# instead of to normal stderr.
526+
if not steamcmd_stderr:
527+
for line in lines:
528+
if not line.begins_with("Redirecting stderr to"):
529+
continue
530+
531+
# Parse the line:
532+
# Redirecting stderr to '/home/<user>/.local/share/Steam/logs/stderr.txt'
533+
var parts := line.split("'")
534+
if parts.size() < 2:
535+
logger.error("Unable to parse stderr path for line: " + line)
536+
break
537+
var stderr_path := parts[1]
538+
539+
# Open the stderr file
540+
steamcmd_stderr = FileAccess.open(stderr_path, FileAccess.READ)
541+
if not steamcmd_stderr:
542+
logger.error("Unable to open steamcmd stderr: " + str(FileAccess.get_open_error()))
543+
break
544+
logger.debug("Opened steamcmd stderr file: " + stderr_path)
545+
512546
# Signal when command progress has been made
513547
if current_cmd != "":
514548
var out := lines.duplicate()

core/steam_settings.gd

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
extends Control
22

33
const SteamClient := preload("res://plugins/steam/core/steam_client.gd")
4-
const SettingsManager := preload("res://core/global/settings_manager.tres")
5-
const NotificationManager := preload("res://core/global/notification_manager.tres")
4+
var settings_manager := load("res://core/global/settings_manager.tres") as SettingsManager
5+
var notification_manager := load("res://core/global/notification_manager.tres") as NotificationManager
66
const icon := preload("res://plugins/steam/assets/steam.svg")
77

88
@onready var status := $%Status
99
@onready var connected_status := $%ConnectedStatus
1010
@onready var logged_in_status := $%LoggedInStatus
11-
@onready var user_box := $%UsernameTextInput as ComponentTextInput
11+
@onready var user_box := $%UsernameTextInput
1212
@onready var pass_box := $%PasswordTextInput
1313
@onready var tfa_box := $%TFATextInput
1414
@onready var login_button := $%LoginButton
@@ -18,7 +18,7 @@ const icon := preload("res://plugins/steam/assets/steam.svg")
1818
# Called when the node enters the scene tree for the first time.
1919
func _ready() -> void:
2020
# If we have logged in before, populate the username box
21-
var user := SettingsManager.get_value("plugin.steam", "user", "") as String
21+
var user := settings_manager.get_value("plugin.steam", "user", "") as String
2222
user_box.text = user
2323

2424
# Set the status label based on the steam client status
@@ -74,12 +74,22 @@ func _on_login(login_status: SteamClient.LOGIN_STATUS) -> void:
7474
if login_status == SteamClient.LOGIN_STATUS.TFA_REQUIRED:
7575
tfa_box.visible = true
7676
tfa_box.grab_focus.call_deferred()
77+
78+
var notify := Notification.new("Two-factor authentication required")
79+
notify.icon = icon
80+
notification_manager.show(notify)
81+
7782
return
7883

7984
# If we logged, woo!
8085
if login_status == SteamClient.LOGIN_STATUS.OK:
8186
logged_in_status.status = logged_in_status.STATUS.CLOSED
8287
logged_in_status.color = "green"
88+
89+
var notify := Notification.new("Successfully logged in to Steam")
90+
notify.icon = icon
91+
notification_manager.show(notify)
92+
8393
return
8494

8595

@@ -88,5 +98,5 @@ func _on_login_button() -> void:
8898
var username: String = user_box.text
8999
var password: String = pass_box.text
90100
var tfa_code: String = tfa_box.text
91-
SettingsManager.set_value("plugin.steam", "user", username)
101+
settings_manager.set_value("plugin.steam", "user", username)
92102
steam.login(username, password, tfa_code)

core/steam_settings.tscn

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,82 +3,72 @@
33
[ext_resource type="Script" path="res://plugins/steam/core/steam_settings.gd" id="1_482tk"]
44
[ext_resource type="PackedScene" uid="uid://d1hlp6c8wrqgv" path="res://core/ui/components/status.tscn" id="2_xf1mt"]
55
[ext_resource type="PackedScene" uid="uid://d1rjdfxxrdccf" path="res://core/ui/components/text_input.tscn" id="3_d62ly"]
6-
[ext_resource type="PackedScene" uid="uid://df5o1o2dsik84" path="res://core/ui/components/button.tscn" id="4_5dgjq"]
6+
[ext_resource type="PackedScene" uid="uid://c71ayw7pcw6u6" path="res://core/ui/components/card_button.tscn" id="4_jlnf0"]
77

8-
[node name="SteamSettings" type="ScrollContainer"]
8+
[node name="MarginContainer" type="MarginContainer"]
99
anchors_preset = 15
1010
anchor_right = 1.0
1111
anchor_bottom = 1.0
1212
grow_horizontal = 2
1313
grow_vertical = 2
14-
size_flags_horizontal = 3
15-
size_flags_vertical = 3
16-
follow_focus = true
1714
script = ExtResource("1_482tk")
1815

19-
[node name="MarginContainer" type="MarginContainer" parent="."]
16+
[node name="ContentContainer" type="VBoxContainer" parent="."]
2017
layout_mode = 2
2118
size_flags_horizontal = 3
22-
theme_override_constants/margin_left = 5
23-
theme_override_constants/margin_top = 5
24-
theme_override_constants/margin_right = 5
25-
theme_override_constants/margin_bottom = 5
26-
27-
[node name="ContentContainer" type="VBoxContainer" parent="MarginContainer"]
28-
layout_mode = 2
29-
size_flags_vertical = 3
19+
size_flags_vertical = 0
3020
theme_override_constants/separation = 10
3121

32-
[node name="Status" parent="MarginContainer/ContentContainer" instance=ExtResource("2_xf1mt")]
22+
[node name="Status" parent="ContentContainer" instance=ExtResource("2_xf1mt")]
3323
unique_name_in_owner = true
3424
layout_mode = 2
3525
title = "Status"
3626
description = ""
3727
status = 2
3828
color = "red"
3929

40-
[node name="ConnectedStatus" parent="MarginContainer/ContentContainer" instance=ExtResource("2_xf1mt")]
30+
[node name="ConnectedStatus" parent="ContentContainer" instance=ExtResource("2_xf1mt")]
4131
unique_name_in_owner = true
4232
layout_mode = 2
4333
title = "Connected"
4434
description = ""
4535
color = "gray"
4636

47-
[node name="LoggedInStatus" parent="MarginContainer/ContentContainer" instance=ExtResource("2_xf1mt")]
37+
[node name="LoggedInStatus" parent="ContentContainer" instance=ExtResource("2_xf1mt")]
4838
unique_name_in_owner = true
4939
layout_mode = 2
5040
title = "Logged In"
5141
description = ""
5242
color = "gray"
5343

54-
[node name="HSeparator" type="HSeparator" parent="MarginContainer/ContentContainer"]
44+
[node name="HSeparator" type="HSeparator" parent="ContentContainer"]
5545
layout_mode = 2
5646

57-
[node name="UsernameTextInput" parent="MarginContainer/ContentContainer" instance=ExtResource("3_d62ly")]
47+
[node name="UsernameTextInput" parent="ContentContainer" instance=ExtResource("3_d62ly")]
5848
unique_name_in_owner = true
5949
layout_mode = 2
6050
title = "Username"
6151
description = ""
6252

63-
[node name="PasswordTextInput" parent="MarginContainer/ContentContainer" instance=ExtResource("3_d62ly")]
53+
[node name="PasswordTextInput" parent="ContentContainer" instance=ExtResource("3_d62ly")]
6454
unique_name_in_owner = true
6555
layout_mode = 2
6656
title = "Password"
6757
description = ""
6858
secret = true
6959

70-
[node name="TFATextInput" parent="MarginContainer/ContentContainer" instance=ExtResource("3_d62ly")]
60+
[node name="TFATextInput" parent="ContentContainer" instance=ExtResource("3_d62ly")]
7161
unique_name_in_owner = true
7262
visible = false
7363
layout_mode = 2
7464
title = "SteamGuard Code"
7565
description = "Enter your Steam Guard code to continue"
7666
secret = true
7767

78-
[node name="HSeparatorLogin" type="HSeparator" parent="MarginContainer/ContentContainer"]
68+
[node name="HSeparatorLogin" type="HSeparator" parent="ContentContainer"]
7969
layout_mode = 2
8070

81-
[node name="LoginButton" parent="MarginContainer/ContentContainer" instance=ExtResource("4_5dgjq")]
71+
[node name="LoginButton" parent="ContentContainer" instance=ExtResource("4_jlnf0")]
8272
unique_name_in_owner = true
8373
layout_mode = 2
8474
text = "Login"

plugin.gd

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
extends Plugin
22

33
const SteamClient := preload("res://plugins/steam/core/steam_client.gd")
4-
const SettingsManager := preload("res://core/global/settings_manager.tres")
5-
const NotificationManager := preload("res://core/global/notification_manager.tres")
6-
const settings_menu := preload("res://plugins/steam/core/steam_settings.tscn")
7-
const icon := preload("res://plugins/steam/assets/steam.svg")
4+
5+
var settings_manager := load("res://core/global/settings_manager.tres") as SettingsManager
6+
var notification_manager := load("res://core/global/notification_manager.tres") as NotificationManager
7+
var settings_menu := load("res://plugins/steam/core/steam_settings.tscn") as PackedScene
8+
var icon := preload("res://plugins/steam/assets/steam.svg")
89

910
var steam: SteamClient
10-
var user := SettingsManager.get_value("plugin.steam", "user", "") as String
11+
var user := settings_manager.get_value("plugin.steam", "user", "") as String
1112

1213

1314
# Called when the node enters the scene tree for the first time.
@@ -41,7 +42,7 @@ func _on_client_start():
4142
var notify := Notification.new("Unable to start steam client")
4243
notify.icon = icon
4344
logger.error(notify.text)
44-
NotificationManager.show(notify)
45+
notification_manager.show(notify)
4546
return
4647

4748

@@ -52,7 +53,7 @@ func _on_client_ready():
5253
var notify := Notification.new("Steam login required")
5354
notify.icon = icon
5455
logger.info(notify.text)
55-
NotificationManager.show(notify)
56+
notification_manager.show(notify)
5657
return
5758

5859
# If we have logged in before, try logging in with saved credentials

plugin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"plugin.id": "steam",
33
"plugin.name": "Steam",
4-
"plugin.version": "1.1.10",
4+
"plugin.version": "1.2.0",
55
"plugin.min-api-version": "1.0.0",
66
"plugin.link": "https://github.com/ShadowBlip/OpenGamepadUI-steam",
77
"plugin.source": "https://github.com/ShadowBlip/OpenGamepadUI-steam",

0 commit comments

Comments
 (0)