Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the fake login page #66

Merged
merged 3 commits into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions Networking/ServerConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,25 @@ public override void _Ready()

_serilogger.Debug("ServerConnection.cs: Attempting to load embedded client config");
err = clientConfig.Load("res://Resources/client.cfg");
if (err == Godot.Error.Ok)
{
_serilogger.Information("ServerConnection.cs: Successfully loaded the config from 'res://Resources/client.cfg'");
url = (String)clientConfig.GetValue("amqp", "server_string", "amqp://127.0.0.1:5672");
_serilogger.Debug("ServerConnection.cs: config file: setting url to " + url);
disableCertValidation = (bool)clientConfig.GetValue("amqp", "disable_cert_validation", true);
_serilogger.Debug("ServerConnection.cs: config file: setting cert validation to " + disableCertValidation);
}

_serilogger.Debug("ServerConnection.cs: Overriding with client local/user config");
err = clientConfig.Load("user://client.cfg");
if (err == Godot.Error.Ok)
if (err != Godot.Error.Ok)
{
err = clientConfig.Load("user://client.cfg");
_serilogger.Information("ServerConnection.cs: Successfully loaded the config from 'user://client.cfg'");
url = (String)clientConfig.GetValue("amqp", "server_string", "amqp://127.0.0.1:5672");
_serilogger.Debug("ServerConnection.cs: config file: setting url to " + url);
disableCertValidation = (bool)clientConfig.GetValue("amqp", "disable_cert_validation", true);
_serilogger.Debug("ServerConnection.cs: config file: setting cert validation to " + disableCertValidation);

// If config file failed to load and the game is in debug mode throw an error
if (err != Godot.Error.Ok && OS.IsDebugBuild())
{
throw new Exception("ServerConnection.cs: Failed to load the client configuration file");
}
}

url = OS.GetEnvironment("SERVER_STRING") ?? (String)clientConfig.GetValue("amqp", "server_string", "amqp://127.0.0.1:5672");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't consider the case where the required environment variables are not present, in production

_serilogger.Debug("ServerConnection.cs: config file: setting url to " + url);
var disableCertValidationValue = OS.GetEnvironment("DISABLE_CERT_VALIDAION") ?? clientConfig.GetValue("amqp", "disable_cert_validation", true);
disableCertValidationValue = (bool)disableCertValidationValue;

_serilogger.Debug("ServerConnection.cs: config file: setting cert validation to " + disableCertValidation);

InitializeAMQP();

}
Expand Down
2 changes: 1 addition & 1 deletion Networking/srt-protobufs
Submodule srt-protobufs updated 0 files
25 changes: 13 additions & 12 deletions Scenes/Authorization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,23 @@ public override void _Ready()
var clientConfig = new ConfigFile();

Godot.Error err = clientConfig.Load("res://Resources/client.cfg");
if (err == Godot.Error.Ok)
// If config file failed to load and the game is in debug mode throw an error
if (err != Godot.Error.Ok && OS.IsDebugBuild())
{
var configPort = (string)clientConfig.GetValue("auth", "port");
string configAddress = (string)clientConfig.GetValue("auth", "address");
throw new Exception("Authorization.cs: Failed to load the client configuration file");
}

HOST = configAddress != "" ? configAddress : DEFAULT_ADDRESS;
PORT = Convert.ToInt32(configPort != "" ? configPort : DEFAULT_PORT);
clientID = (string)clientConfig.GetValue("auth", "client_id");
clientSecret = (string)clientConfig.GetValue("auth", "client_secret");
authServer = (string)clientConfig.GetValue("auth", "auth_api_url");
tokenServer = (string)clientConfig.GetValue("auth", "token_api_url");
var configPort = OS.GetEnvironment("PORT") ?? (string)clientConfig.GetValue("auth", "port");
string configAddress = OS.GetEnvironment("ADDRESS") ?? (string)clientConfig.GetValue("auth", "address");

redirectUri = String.Format("http://{0}:{1}", HOST, PORT);
clientID = OS.GetEnvironment("CLIENT_ID") ?? (string)clientConfig.GetValue("auth", "client_id");
clientSecret = OS.GetEnvironment("CLIENT_SECRET") ?? (string)clientConfig.GetValue("auth", "client_secret");
authServer = OS.GetEnvironment("AUTH_API_URL") ?? (string)clientConfig.GetValue("auth", "auth_api_url");
tokenServer = OS.GetEnvironment("TOKEN_API_URL") ?? (string)clientConfig.GetValue("auth", "token_api_url");

authorize();
}
redirectUri = String.Format("http://{0}:{1}", HOST, PORT);

authorize();
}

// Wait for a Oauth callback from the Identity manager to receive an auth code, then ask for a token
Expand Down
43 changes: 38 additions & 5 deletions Scenes/LoginScreen.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,47 @@
using Godot;
using System;

public class LoginScreen : Control
{
private Authorization authorization;

private LineEdit textField;
Boolean activateAuthDev = false;
public Serilog.Core.Logger _serilogger;

[Signal] public delegate void loginSuccess(string userId);

public override void _Ready()
{
authorization = authorization = new Authorization();
this.AddChild(authorization);
var clientConfig = new ConfigFile();
Godot.Error err = clientConfig.Load("res://Resources/client.cfg");

// If config file failed to load and the game is in debug mode throw an error
if (err != Godot.Error.Ok && OS.IsDebugBuild())
{
throw new Exception("LoginScreen.cs: Failed to load the client configuration file");
}

// enable/disable authentication in dev mode
var activateAuthDevVar = OS.GetEnvironment("ACTIVATE_AUTH_DEV") ?? clientConfig.GetValue("auth", "activate_auth_dev");
activateAuthDev = (Boolean)activateAuthDevVar;

// skip the authentication flow in Debug mode and if we don't want to test it
if (OS.IsDebugBuild() && activateAuthDev == false)
{
this.GetNode<TextureRect>("NoAuthorizedRect").Visible = false;
this.GetNode<TextureRect>("AuthLoadingRect").Visible = false;

// listening for the Auth results: fail or success
authorization.Connect("playerAuthenticated", this, "_on_is_player_authenticated");
textField = this.GetNode<LineEdit>("VBoxContainer/HBoxContainer/NameLineEdit");
textField.GrabFocus();
}
else
{
authorization = authorization = new Authorization();
this.AddChild(authorization);

// listening for the Auth results: fail or success
authorization.Connect("playerAuthenticated", this, "_on_is_player_authenticated");
}
}

void _on_is_player_authenticated(bool isAuthenticated)
Expand All @@ -38,4 +65,10 @@ private void _on_RetryButton_pressed()
_serilogger.Debug("LoginScreen.cs: Retry authentication");
authorization.authorize();
}

private void _on_JoinButton_button_up()
{
QueueFree();
EmitSignal("loginSuccess", textField.Text);
}
}
54 changes: 53 additions & 1 deletion Scenes/LoginScreen.tscn
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
[gd_scene load_steps=6 format=2]
[gd_scene load_steps=8 format=2]

[ext_resource path="res://Assets/Artwork/authorizing.png" type="Texture" id=1]
[ext_resource path="res://Scenes/LoginScreen.cs" type="Script" id=2]
[ext_resource path="res://Assets/UIElements/MainTheme.tres" type="Theme" id=3]
[ext_resource path="res://Assets/Artwork/name-your-captain.png" type="Texture" id=4]
[ext_resource path="res://Assets/Artwork/no_authorized.png" type="Texture" id=5]
[ext_resource path="res://Assets/Fonts/RedHatText-Regular.tres" type="DynamicFont" id=6]

Expand All @@ -19,6 +21,55 @@ margin_bottom = 300.0
mouse_filter = 1
script = ExtResource( 2 )

[node name="JoinGameRect" type="TextureRect" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
texture = ExtResource( 4 )
expand = true
stretch_mode = 1
__meta__ = {
"_edit_use_anchors_": true
}

[node name="VBoxContainer" type="VBoxContainer" parent="."]
anchor_left = 0.469
anchor_top = 0.663
anchor_right = 0.487
anchor_bottom = 0.715
margin_right = 449.568
margin_bottom = 50.8
alignment = 1
__meta__ = {
"_edit_use_anchors_": true
}

[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
margin_top = 15.0
margin_right = 468.0
margin_bottom = 66.0
alignment = 1

[node name="Label" type="Label" parent="VBoxContainer/HBoxContainer"]
margin_top = 18.0
margin_bottom = 32.0
valign = 1

[node name="NameLineEdit" type="LineEdit" parent="VBoxContainer/HBoxContainer"]
margin_left = 4.0
margin_right = 304.0
margin_bottom = 51.0
rect_min_size = Vector2( 300, 0 )
focus_neighbour_right = NodePath("../JoinButton")
theme = ExtResource( 3 )

[node name="JoinButton" type="Button" parent="VBoxContainer/HBoxContainer"]
margin_left = 308.0
margin_right = 468.0
margin_bottom = 51.0
focus_neighbour_left = NodePath("../NameLineEdit")
theme = ExtResource( 3 )
text = "Join Game"

[node name="NoAuthorizedRect" type="TextureRect" parent="."]
anchor_left = 0.5
anchor_top = 0.5
Expand Down Expand Up @@ -54,4 +105,5 @@ rect_min_size = Vector2( 1024, 600 )
size_flags_horizontal = 4
texture = ExtResource( 1 )

[connection signal="button_up" from="VBoxContainer/HBoxContainer/JoinButton" to="." method="_on_JoinButton_button_up"]
[connection signal="pressed" from="NoAuthorizedRect/RetryButton" to="." method="_on_RetryButton_pressed"]
14 changes: 0 additions & 14 deletions Scenes/MainScenes/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ public class Game : Node
private Stopwatch GameStopwatch = new Stopwatch();

Boolean inGame = false;
Boolean activateAuthDev = false;

// UI elements
CanvasLayer gameUI;
TextureRect speedometer;
Expand Down Expand Up @@ -91,9 +89,6 @@ public void LoadConfig()
err = clientConfig.Load("Resources/client.cfg");
}

// enable/disable authentication in dev mode
activateAuthDev = (Boolean)clientConfig.GetValue("auth", "activate_auth_dev");

int DesiredLogLevel = 3;

// if the file was loaded successfully, read the vars
Expand Down Expand Up @@ -163,19 +158,10 @@ public override void _Ready()
turnLeftControl = gameUI.GetNode<Label>("ControlIndicators/ControlsBox/TurnLeft");
turnRightControl = gameUI.GetNode<Label>("ControlIndicators/ControlsBox/TurnRight");
fireControl = gameUI.GetNode<Label>("ControlIndicators/ControlsBox/FireButton");

// skip the authentication flow in Debug mode and if we don't want to test it
if (OS.IsDebugBuild() && activateAuthDev == false)
{
this._on_login_success("test-userId");
return;
}

PackedScene packedAuthScene = (PackedScene)ResourceLoader.Load("res://Scenes/LoginScreen.tscn");

loginScreen = (LoginScreen)packedAuthScene.Instance();
this.AddChild(loginScreen);

// wait a notification the login flow
loginScreen.Connect("loginSuccess", this, "_on_login_success");
}
Expand Down