-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
678 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<Control xmlns="https://spacestation14.io" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:parallax="clr-namespace:Content.Client.Parallax" | ||
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls" | ||
xmlns:graphics="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client"> | ||
<parallax:ParallaxControl /> | ||
<Control HorizontalAlignment="Center" VerticalAlignment="Center"> | ||
<PanelContainer StyleClasses="AngleRect" /> | ||
<BoxContainer Orientation="Vertical"> | ||
<BoxContainer Orientation="Horizontal"> | ||
<Label Margin="8 0 0 0" Text="{Loc 'discord-auth-title'}" | ||
StyleClasses="LabelHeading" VAlign="Center" /> | ||
<Button Name="QuitButton" Text="{Loc 'discord-auth-quit-btn'}" | ||
HorizontalAlignment="Right" HorizontalExpand="True" /> | ||
</BoxContainer> | ||
<controls:HighDivider /> | ||
<BoxContainer Orientation="Vertical" Margin="10 25 10 0"> | ||
<Label Text="Для доступа на сервер вам необходимо связать аккаунт SS14 с Discord." Align="Center" /> | ||
</BoxContainer> | ||
<BoxContainer Orientation="Vertical" Margin="10 25 10 0"> | ||
<Label Text="Советуем вам делать привязку на основной аккаунт." Align="Center" StyleClasses="LabelKeyText"/> | ||
<Label Text="Будьте внимательны при выборе аккаунта.{Loc 'discord-auth-warn2'}" Align="Center" StyleClasses="LabelKeyText"/> | ||
</BoxContainer> | ||
<BoxContainer Orientation="Vertical" VerticalAlignment="Bottom" Margin="0 25 0 0"> | ||
<Label Text="QrCode для сканирования на телефоне." Align="Center" /> | ||
<TextureRect Name="QrCode" MaxHeight="400" HorizontalAlignment="Center" Margin="10 10 10 10"></TextureRect> | ||
</BoxContainer> | ||
<PanelContainer Name="InputContainer" | ||
VerticalAlignment="Stretch" | ||
VerticalExpand="True" | ||
HorizontalExpand="True" | ||
Margin="10 0 10 10"> | ||
<PanelContainer.PanelOverride> | ||
<graphics:StyleBoxFlat BackgroundColor="#333237"/> | ||
</PanelContainer.PanelOverride> | ||
<TextEdit Name="UrlEdit" Access="Public" MinSize="300 100"/> | ||
</PanelContainer> | ||
<Button Name="OpenUrlButton" Text="Открыть в браузере" HorizontalExpand="True" StyleClasses="OpenRight" /> | ||
</BoxContainer> | ||
</Control> | ||
</Control> |
41 changes: 41 additions & 0 deletions
41
Content.Client/_Adventure/DiscordAuth/DiscordAuthGui.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using Robust.Client.AutoGenerated; | ||
using Robust.Client.Console; | ||
using Robust.Client.UserInterface.Controls; | ||
using Robust.Client.UserInterface.XAML; | ||
using Robust.Client.UserInterface; | ||
using Robust.Shared.Utility; | ||
|
||
namespace Content.Client._Adventure.DiscordAuth; | ||
|
||
[GenerateTypedNameReferences] | ||
public sealed partial class DiscordAuthGui : Control | ||
{ | ||
[Dependency] private readonly DiscordAuthManager _discordAuth = default!; | ||
[Dependency] private readonly IClientConsoleHost _consoleHost = default!; | ||
|
||
public DiscordAuthGui() | ||
{ | ||
RobustXamlLoader.Load(this); | ||
IoCManager.InjectDependencies(this); | ||
LayoutContainer.SetAnchorPreset(this, LayoutContainer.LayoutPreset.Wide); | ||
|
||
QuitButton.OnPressed += (_) => | ||
{ | ||
_consoleHost.ExecuteCommand("quit"); | ||
}; | ||
|
||
UrlEdit.TextRope = new Rope.Leaf(_discordAuth.AuthUrl); | ||
if (_discordAuth.Qrcode != null) | ||
{ | ||
QrCode.Texture = _discordAuth.Qrcode; | ||
} | ||
|
||
OpenUrlButton.OnPressed += (_) => | ||
{ | ||
if (_discordAuth.AuthUrl != string.Empty) | ||
{ | ||
IoCManager.Resolve<IUriOpener>().OpenUri(_discordAuth.AuthUrl); | ||
} | ||
}; | ||
} | ||
} |
92 changes: 92 additions & 0 deletions
92
Content.Client/_Adventure/DiscordAuth/DiscordAuthManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
using Content.Shared._Adventure.DiscordAuth; | ||
using Content.Shared._Adventure.DiscordMember; | ||
using Robust.Client.Graphics; | ||
using Robust.Client.State; | ||
using Robust.Shared.Network; | ||
using System.IO; | ||
|
||
namespace Content.Client._Adventure.DiscordAuth; | ||
|
||
public sealed class DiscordAuthManager | ||
{ | ||
[Dependency] private readonly IClientNetManager _net = default!; | ||
[Dependency] private readonly IStateManager _state = default!; | ||
|
||
private string _authUrl = string.Empty; | ||
private Texture? _qrcode; | ||
private string _discordUrl = string.Empty; | ||
private Texture? _discordQrcode; | ||
private string _discordUsername = string.Empty; | ||
|
||
public DiscordAuthManager(string authUrl, string discordUrl, string discordUsername) | ||
{ | ||
_authUrl = authUrl; | ||
_discordUrl = discordUrl; | ||
_discordUsername = discordUsername; | ||
} | ||
|
||
public string AuthUrl => _authUrl; | ||
|
||
public Texture? Qrcode => _qrcode; | ||
|
||
public string DiscordUrl => _discordUrl; | ||
|
||
public Texture? DiscordQrcode => _discordQrcode; | ||
|
||
public string DiscordUsername => _discordUsername; | ||
|
||
public void Initialize() | ||
{ | ||
_net.RegisterNetMessage<MsgDiscordAuthCheck>(); | ||
_net.RegisterNetMessage<MsgDiscordAuthRequired>(OnDiscordAuthRequired); | ||
_net.RegisterNetMessage<MsgDiscordMemberCheck>(); | ||
_net.RegisterNetMessage<MsgDiscordMemberRequired>(OnDiscordMemberRequired); | ||
} | ||
|
||
private void OnDiscordAuthRequired(MsgDiscordAuthRequired message) | ||
{ | ||
if (_state.CurrentState is not DiscordAuthState) | ||
{ | ||
_authUrl = message.AuthUrl; | ||
if (message.QrCode.Length > 0) | ||
{ | ||
using var ms = new MemoryStream(message.QrCode); | ||
_qrcode = Texture.LoadFromPNGStream(ms); | ||
} | ||
|
||
_state.RequestStateChange<DiscordAuthState>(); | ||
} | ||
} | ||
|
||
private void OnDiscordMemberRequired(MsgDiscordMemberRequired message) | ||
{ | ||
if (_state.CurrentState is not DiscordMemberState) | ||
{ | ||
_discordUrl = message.AuthUrl; | ||
_discordUsername = message.DiscordUsername; | ||
if (message.QrCode.Length > 0) | ||
{ | ||
using var ms = new MemoryStream(message.QrCode); | ||
_discordQrcode = Texture.LoadFromPNGStream(ms); | ||
} | ||
|
||
_state.RequestStateChange<DiscordMemberState>(); | ||
} | ||
} | ||
|
||
public void UpdateQrcodes(Texture? qrcode, Texture? discordQrcode) | ||
{ | ||
_qrcode = qrcode; | ||
_discordQrcode = discordQrcode; | ||
} | ||
|
||
public void SetAuthUrl(string url) | ||
{ | ||
_authUrl = url; | ||
} | ||
|
||
public void SetDiscordUsername(string username) | ||
{ | ||
_discordUsername = username; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using Content.Shared._Adventure.DiscordAuth; | ||
using Robust.Client.State; | ||
using Robust.Client.UserInterface; | ||
using Robust.Shared.Network; | ||
using System.Threading; | ||
using Timer = Robust.Shared.Timing.Timer; | ||
|
||
namespace Content.Client._Adventure.DiscordAuth; | ||
|
||
public sealed class DiscordAuthState : State | ||
{ | ||
[Dependency] private readonly IUserInterfaceManager _userInterface = default!; | ||
[Dependency] private readonly IClientNetManager _net = default!; | ||
|
||
private DiscordAuthGui? _gui; | ||
private readonly CancellationTokenSource _checkTimerCancel = new(); | ||
|
||
protected override void Startup() | ||
{ | ||
_gui = new DiscordAuthGui(); | ||
_userInterface.StateRoot.AddChild(_gui); | ||
|
||
Timer.SpawnRepeating(TimeSpan.FromSeconds(5), () => | ||
{ | ||
_net.ClientSendMessage(new MsgDiscordAuthCheck()); | ||
}, _checkTimerCancel.Token); | ||
} | ||
|
||
protected override void Shutdown() | ||
{ | ||
_checkTimerCancel.Cancel(); | ||
_gui!.Dispose(); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
Content.Client/_Adventure/DiscordMember/DiscordMemberGui.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<Control xmlns="https://spacestation14.io" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:parallax="clr-namespace:Content.Client.Parallax" | ||
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls" | ||
xmlns:graphics="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client"> | ||
<parallax:ParallaxControl /> | ||
<Control HorizontalAlignment="Center" VerticalAlignment="Center"> | ||
<PanelContainer StyleClasses="AngleRect" /> | ||
<BoxContainer Orientation="Vertical"> | ||
<BoxContainer Orientation="Horizontal"> | ||
<Label Margin="8 0 0 0" Text="Проверка членства в Discord" | ||
StyleClasses="LabelHeading" VAlign="Center" /> | ||
<Button Name="QuitButton" Text="Выйти" | ||
HorizontalAlignment="Right" HorizontalExpand="True" /> | ||
</BoxContainer> | ||
<controls:HighDivider /> | ||
<BoxContainer Orientation="Vertical" Margin="10 25 10 0"> | ||
<Label Text="Для доступа на сервер вам необходимо быть участником нашего Discord сервера." Align="Center" /> | ||
</BoxContainer> | ||
<BoxContainer Orientation="Vertical" Margin="10 25 10 0"> | ||
<Label Text="Учтите что зайти на сервер нужно с того аккаунта на который вы делали подвязку." Align="Center" StyleClasses="LabelKeyText"/> | ||
<BoxContainer Orientation="Horizontal" Align="Center"> | ||
<Label Text="Ваш привязаный аккаунт:" StyleClasses="LabelKeyText"/> | ||
<Label Text=" "/> | ||
<Label Name="DiscordUsername" /> | ||
</BoxContainer> | ||
</BoxContainer> | ||
<BoxContainer Orientation="Vertical" VerticalAlignment="Bottom" Margin="0 25 0 0"> | ||
<Label Text="QrCode для сканирования на телефоне." Align="Center" /> | ||
<TextureRect Name="QrCode" MaxHeight="400" HorizontalAlignment="Center" Margin="10 10 10 10"></TextureRect> | ||
</BoxContainer> | ||
<PanelContainer Name="InputContainer" | ||
VerticalAlignment="Stretch" | ||
VerticalExpand="True" | ||
HorizontalExpand="True" | ||
Margin="10 0 10 10"> | ||
<PanelContainer.PanelOverride> | ||
<graphics:StyleBoxFlat BackgroundColor="#333237"/> | ||
</PanelContainer.PanelOverride> | ||
<TextEdit Name="UrlEdit" Access="Public" MinSize="300 100"/> | ||
</PanelContainer> | ||
<Button Name="OpenUrlButton" Text="Открыть в браузере" HorizontalExpand="True" StyleClasses="OpenRight" /> | ||
</BoxContainer> | ||
</Control> | ||
</Control> |
46 changes: 46 additions & 0 deletions
46
Content.Client/_Adventure/DiscordMember/DiscordMemberGui.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using Robust.Client.AutoGenerated; | ||
using Robust.Client.Console; | ||
using Robust.Client.UserInterface.Controls; | ||
using Robust.Client.UserInterface.XAML; | ||
using Robust.Client.UserInterface; | ||
using Robust.Shared.Utility; | ||
|
||
namespace Content.Client._Adventure.DiscordMember; | ||
|
||
[GenerateTypedNameReferences] | ||
public sealed partial class DiscordMemberGui : Control | ||
{ | ||
[Dependency] private readonly DiscordAuthManager _discordAuth = default!; | ||
[Dependency] private readonly IClientConsoleHost _consoleHost = default!; | ||
|
||
public DiscordMemberGui() | ||
{ | ||
RobustXamlLoader.Load(this); | ||
IoCManager.InjectDependencies(this); | ||
LayoutContainer.SetAnchorPreset(this, LayoutContainer.LayoutPreset.Wide); | ||
|
||
QuitButton.OnPressed += (_) => | ||
{ | ||
_consoleHost.ExecuteCommand("quit"); | ||
}; | ||
|
||
UrlEdit.TextRope = new Rope.Leaf(_discordAuth.DiscordUrl); | ||
if (_discordAuthManager.DiscordQrcode != null) | ||
{ | ||
QrCode.Texture = _discordAuth.DiscordQrcode; | ||
} | ||
|
||
if (_discordAuth.DiscordUsername != string.Empty) | ||
{ | ||
DiscordUsername.Text = _discordAuth.DiscordUsername; | ||
} | ||
|
||
OpenUrlButton.OnPressed += (_) => | ||
{ | ||
if (_discordAuth.DiscordUrl != string.Empty) | ||
{ | ||
IoCManager.Resolve<IUriOpener>().OpenUri(_discordAuth.DiscordUrl); | ||
} | ||
}; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
Content.Client/_Adventure/DiscordMember/DiscordMemberState.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using Content.Shared._Adventure.DiscordMember; | ||
using Robust.Client.State; | ||
using Robust.Client.UserInterface; | ||
using Robust.Shared.Network; | ||
using System.Threading; | ||
using Timer = Robust.Shared.Timing.Timer; | ||
|
||
namespace Content.Client._Adventure.DiscordMember; | ||
|
||
public sealed class DiscordMemberState : State | ||
{ | ||
[Dependency] private readonly IUserInterfaceManager _userInterface = default!; | ||
[Dependency] private readonly IClientNetManager _net = default!; | ||
|
||
private DiscordMemberGui? _gui; | ||
private readonly CancellationTokenSource _checkTimerCancel = new(); | ||
|
||
protected override void Startup() | ||
{ | ||
_gui = new DiscordMemberGui(); | ||
_userInterface.StateRoot.AddChild(_gui); | ||
|
||
Timer.SpawnRepeating(TimeSpan.FromSeconds(5), () => | ||
{ | ||
_net.ClientSendMessage(new MsgDiscordMemberCheck()); | ||
}, _checkTimerCancel.Token); | ||
} | ||
|
||
protected override void Shutdown() | ||
{ | ||
_checkTimerCancel.Cancel(); | ||
_gui!.Dispose(); | ||
} | ||
} |
Oops, something went wrong.