Skip to content

Commit f8207d9

Browse files
authored
Add discord link requie (#2356)
1 parent 60a886d commit f8207d9

File tree

12 files changed

+359
-23
lines changed

12 files changed

+359
-23
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt
2+
using System.Threading;
3+
using Content.Client.SS220.UserInterface.DiscordLink;
4+
using Content.Shared.SS220.Discord;
5+
using Robust.Client.State;
6+
using Robust.Client.UserInterface;
7+
using Robust.Shared.Network;
8+
using Timer = Robust.Shared.Timing.Timer;
9+
10+
11+
namespace Content.Client.SS220.Discord;
12+
13+
public sealed class DiscordLinkRequiredState : State
14+
{
15+
[Dependency] private readonly IUserInterfaceManager _userInterfaceManager = default!;
16+
[Dependency] private readonly IClientNetManager _netManager = default!;
17+
18+
private DiscordLinkRequiredGui? _linkGui;
19+
private readonly CancellationTokenSource _timerCancel = new();
20+
21+
protected override void Startup()
22+
{
23+
_linkGui = new DiscordLinkRequiredGui();
24+
_userInterfaceManager.StateRoot.AddChild(_linkGui);
25+
26+
Timer.SpawnRepeating(TimeSpan.FromSeconds(10), () =>
27+
{
28+
_netManager.ClientSendMessage(new MsgRecheckDiscordLink());
29+
},
30+
_timerCancel.Token);
31+
}
32+
33+
protected override void Shutdown()
34+
{
35+
_timerCancel.Cancel();
36+
_linkGui!.Dispose();
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,54 @@
11
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt
22

33
using Content.Shared.SS220.Discord;
4+
using Robust.Client.State;
45
using Robust.Shared.Network;
56

6-
namespace Content.Client.SS220.Discord
7+
namespace Content.Client.SS220.Discord;
8+
9+
public sealed class DiscordPlayerInfoManager
710
{
8-
public sealed class DiscordPlayerInfoManager
9-
{
10-
[Dependency] private readonly IClientNetManager _netMgr = default!;
11+
[Dependency] private readonly IClientNetManager _netMgr = default!;
12+
[Dependency] private readonly IStateManager _stateManager = default!;
1113

12-
private DiscordSponsorInfo? _info;
14+
private DiscordSponsorInfo? _info;
1315

14-
public event Action? SponsorStatusChanged;
16+
public event Action? SponsorStatusChanged;
1517

16-
public void Initialize()
17-
{
18-
_netMgr.RegisterNetMessage<MsgUpdatePlayerDiscordStatus>(UpdateSponsorStatus);
19-
}
18+
public string AuthUrl { get; private set; } = string.Empty;
2019

21-
private void UpdateSponsorStatus(MsgUpdatePlayerDiscordStatus message)
22-
{
23-
_info = message.Info;
20+
public void Initialize()
21+
{
22+
_netMgr.RegisterNetMessage<MsgUpdatePlayerDiscordStatus>(UpdateSponsorStatus);
23+
_netMgr.RegisterNetMessage<MsgDiscordLinkRequired>(OnDiscordLinkRequired);
24+
_netMgr.RegisterNetMessage<MsgRecheckDiscordLink>();
2425

25-
SponsorStatusChanged?.Invoke();
26-
}
26+
_netMgr.RegisterNetMessage<MsgByPassDiscordCheck>();
27+
}
28+
29+
private void UpdateSponsorStatus(MsgUpdatePlayerDiscordStatus message)
30+
{
31+
_info = message.Info;
2732

28-
public SponsorTier[] GetSponsorTier()
33+
SponsorStatusChanged?.Invoke();
34+
}
35+
36+
public SponsorTier[] GetSponsorTier()
37+
{
38+
return _info?.Tiers ?? Array.Empty<SponsorTier>();
39+
}
40+
41+
private void OnDiscordLinkRequired(MsgDiscordLinkRequired msg)
42+
{
43+
if (_stateManager.CurrentState is not DiscordLinkRequiredState)
2944
{
30-
return _info?.Tiers ?? Array.Empty<SponsorTier>();
45+
AuthUrl = msg.AuthUrl;
46+
_stateManager.RequestStateChange<DiscordLinkRequiredState>();
3147
}
3248
}
49+
50+
public void ByPassCheck()
51+
{
52+
_netMgr.ClientSendMessage(new MsgByPassDiscordCheck());
53+
}
3354
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<!-- © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt -->
2+
<Control xmlns="https://spacestation14.io"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:parallax="clr-namespace:Content.Client.Parallax"
5+
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls">
6+
<parallax:ParallaxControl />
7+
<Control HorizontalAlignment="Center" VerticalAlignment="Center">
8+
<PanelContainer StyleClasses="AngleRect" />
9+
<BoxContainer Orientation="Vertical">
10+
<BoxContainer Orientation="Horizontal">
11+
<Label Margin="8 0 0 0" Text="{Loc 'discord-auth-title'}"
12+
StyleClasses="LabelHeading" VAlign="Center" />
13+
<Button Name="QuitButton" Text="{Loc 'discord-auth-quit-btn'}"
14+
HorizontalAlignment="Right" HorizontalExpand="True" />
15+
</BoxContainer>
16+
<controls:HighDivider />
17+
<BoxContainer Orientation="Vertical" Margin="50 20 50 20">
18+
<Label Text="{Loc 'discord-auth-info'}" Align="Center" />
19+
<Label Text="{Loc 'discord-auth-warn'}" Margin="0 5 0 0" Align="Center" StyleClasses="LabelSubText" />
20+
</BoxContainer>
21+
<BoxContainer Orientation="Horizontal" VerticalAlignment="Bottom" Margin="10 0 0 0">
22+
<Label Text="{Loc 'discord-auth-link'}" Align="Center" />
23+
<Label Text=" " />
24+
<LineEdit Name="UrlEdit" HorizontalExpand="True" Editable="False"></LineEdit>
25+
</BoxContainer>
26+
<Button Name="OpenUrlButton" Text="{Loc 'discord-auth-browser-btn'}" HorizontalExpand="True" StyleClasses="OpenRight" />
27+
28+
<Button Name="ByPassCheck" Text="Войти без проверки" HorizontalExpand="True" StyleClasses="OpenRight" />
29+
</BoxContainer>
30+
</Control>
31+
</Control>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt
2+
using Content.Client.SS220.Discord;
3+
using Robust.Client.Console;
4+
using Robust.Client.UserInterface;
5+
using Robust.Client.UserInterface.Controls;
6+
using Robust.Client.UserInterface.XAML;
7+
using Robust.Client.AutoGenerated;
8+
9+
namespace Content.Client.SS220.UserInterface.DiscordLink;
10+
11+
[GenerateTypedNameReferences]
12+
public sealed partial class DiscordLinkRequiredGui : Control
13+
{
14+
[Dependency] private readonly DiscordPlayerInfoManager _discordPlayerInfoManager = default!;
15+
[Dependency] private readonly IClientConsoleHost _consoleHost = default!;
16+
17+
public DiscordLinkRequiredGui()
18+
{
19+
RobustXamlLoader.Load(this);
20+
IoCManager.InjectDependencies(this);
21+
LayoutContainer.SetAnchorPreset(this, LayoutContainer.LayoutPreset.Wide);
22+
23+
QuitButton.OnPressed += (_) =>
24+
{
25+
_consoleHost.ExecuteCommand("quit");
26+
};
27+
28+
UrlEdit.Text = _discordPlayerInfoManager.AuthUrl;
29+
OpenUrlButton.OnPressed += (_) =>
30+
{
31+
if (_discordPlayerInfoManager.AuthUrl != string.Empty)
32+
{
33+
IoCManager.Resolve<IUriOpener>().OpenUri(_discordPlayerInfoManager.AuthUrl);
34+
}
35+
};
36+
37+
ByPassCheck.OnPressed += (_) =>
38+
{
39+
_discordPlayerInfoManager.ByPassCheck();
40+
};
41+
}
42+
}

Content.Server/Corvax/DiscordAuth/DiscordAuthManager.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public void Initialize()
4747
_netMgr.RegisterNetMessage<MsgDiscordAuthRequired>();
4848
_netMgr.RegisterNetMessage<MsgDiscordAuthCheck>(OnAuthCheck);
4949

50-
_playerMgr.PlayerStatusChanged += OnPlayerStatusChanged;
50+
// _playerMgr.PlayerStatusChanged += OnPlayerStatusChanged;
5151
}
5252

5353
private async void OnAuthCheck(MsgDiscordAuthCheck message)

Content.Server/Corvax/JoinQueue/JoinQueueManager.cs

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Linq;
22
using Content.Server.Connection;
33
using Content.Server.Corvax.DiscordAuth;
4+
using Content.Server.SS220.Discord;
45
using Content.Shared.CCVar;
56
using Content.Shared.Corvax.CCCVars;
67
using Content.Shared.Corvax.JoinQueue;
@@ -41,6 +42,7 @@ public sealed class JoinQueueManager
4142
[Dependency] private readonly IConfigurationManager _cfg = default!;
4243
[Dependency] private readonly IServerNetManager _netManager = default!;
4344
[Dependency] private readonly DiscordAuthManager _discordAuthManager = default!;
45+
[Dependency] private readonly DiscordPlayerManager _discordPlayerManager = default!;
4446

4547
/// <summary>
4648
/// Queue of active player sessions
@@ -59,6 +61,8 @@ public void Initialize()
5961
_cfg.OnValueChanged(CCCVars.QueueEnabled, OnQueueCVarChanged, true);
6062
_playerManager.PlayerStatusChanged += OnPlayerStatusChanged;
6163
_discordAuthManager.PlayerVerified += OnPlayerVerified;
64+
65+
_discordPlayerManager.PlayerVerified += OnPlayerVerified;
6266
}
6367

6468
private void OnQueueCVarChanged(bool value)

Content.Server/GameTicking/GameTicker.Player.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ private async void PlayerStatusChanged(object? sender, SessionStatusEventArgs ar
5858
// Make the player actually join the game.
5959
// timer time must be > tick length
6060
// Timer.Spawn(0, args.Session.JoinGame); // Corvax-Queue: Moved to `JoinQueueManager`
61-
// Timer.Spawn(0, () => _playerManager.JoinGame(args.Session));
61+
// Timer.Spawn(0, () => _playerManager.JoinGame(args.Session));
6262

6363
var record = await _db.GetPlayerRecordByUserId(args.Session.UserId);
6464
var firstConnection = record != null &&

0 commit comments

Comments
 (0)