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 discord link requie #2356

Merged
merged 23 commits into from
Dec 17, 2024
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
38 changes: 38 additions & 0 deletions Content.Client/SS220/Discord/DiscordLinkRequiredState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt
using System.Threading;
using Content.Client.SS220.UserInterface.DiscordLink;
using Content.Shared.SS220.Discord;
using Robust.Client.State;
using Robust.Client.UserInterface;
using Robust.Shared.Network;
using Timer = Robust.Shared.Timing.Timer;


namespace Content.Client.SS220.Discord;

public sealed class DiscordLinkRequiredState : State
{
[Dependency] private readonly IUserInterfaceManager _userInterfaceManager = default!;
[Dependency] private readonly IClientNetManager _netManager = default!;

private DiscordLinkRequiredGui? _linkGui;
private readonly CancellationTokenSource _timerCancel = new();

protected override void Startup()
{
_linkGui = new DiscordLinkRequiredGui();
_userInterfaceManager.StateRoot.AddChild(_linkGui);

Timer.SpawnRepeating(TimeSpan.FromSeconds(10), () =>
{
_netManager.ClientSendMessage(new MsgRecheckDiscordLink());
},
_timerCancel.Token);
}

protected override void Shutdown()
{
_timerCancel.Cancel();
_linkGui!.Dispose();
}
}
55 changes: 38 additions & 17 deletions Content.Client/SS220/Discord/DiscordPlayerInfoManager.cs
Original file line number Diff line number Diff line change
@@ -1,33 +1,54 @@
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt

using Content.Shared.SS220.Discord;
using Robust.Client.State;
using Robust.Shared.Network;

namespace Content.Client.SS220.Discord
namespace Content.Client.SS220.Discord;

public sealed class DiscordPlayerInfoManager
{
public sealed class DiscordPlayerInfoManager
{
[Dependency] private readonly IClientNetManager _netMgr = default!;
[Dependency] private readonly IClientNetManager _netMgr = default!;
[Dependency] private readonly IStateManager _stateManager = default!;

private DiscordSponsorInfo? _info;
private DiscordSponsorInfo? _info;

public event Action? SponsorStatusChanged;
public event Action? SponsorStatusChanged;

public void Initialize()
{
_netMgr.RegisterNetMessage<MsgUpdatePlayerDiscordStatus>(UpdateSponsorStatus);
}
public string AuthUrl { get; private set; } = string.Empty;

private void UpdateSponsorStatus(MsgUpdatePlayerDiscordStatus message)
{
_info = message.Info;
public void Initialize()
{
_netMgr.RegisterNetMessage<MsgUpdatePlayerDiscordStatus>(UpdateSponsorStatus);
_netMgr.RegisterNetMessage<MsgDiscordLinkRequired>(OnDiscordLinkRequired);
_netMgr.RegisterNetMessage<MsgRecheckDiscordLink>();

SponsorStatusChanged?.Invoke();
}
_netMgr.RegisterNetMessage<MsgByPassDiscordCheck>();
}

private void UpdateSponsorStatus(MsgUpdatePlayerDiscordStatus message)
{
_info = message.Info;

public SponsorTier[] GetSponsorTier()
SponsorStatusChanged?.Invoke();
}

public SponsorTier[] GetSponsorTier()
{
return _info?.Tiers ?? Array.Empty<SponsorTier>();
}

private void OnDiscordLinkRequired(MsgDiscordLinkRequired msg)
{
if (_stateManager.CurrentState is not DiscordLinkRequiredState)
{
return _info?.Tiers ?? Array.Empty<SponsorTier>();
AuthUrl = msg.AuthUrl;
_stateManager.RequestStateChange<DiscordLinkRequiredState>();
}
}

public void ByPassCheck()
{
_netMgr.ClientSendMessage(new MsgByPassDiscordCheck());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!-- © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt -->
<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">
<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="50 20 50 20">
<Label Text="{Loc 'discord-auth-info'}" Align="Center" />
<Label Text="{Loc 'discord-auth-warn'}" Margin="0 5 0 0" Align="Center" StyleClasses="LabelSubText" />
</BoxContainer>
<BoxContainer Orientation="Horizontal" VerticalAlignment="Bottom" Margin="10 0 0 0">
<Label Text="{Loc 'discord-auth-link'}" Align="Center" />
<Label Text=" " />
<LineEdit Name="UrlEdit" HorizontalExpand="True" Editable="False"></LineEdit>
</BoxContainer>
<Button Name="OpenUrlButton" Text="{Loc 'discord-auth-browser-btn'}" HorizontalExpand="True" StyleClasses="OpenRight" />

<Button Name="ByPassCheck" Text="Войти без проверки" HorizontalExpand="True" StyleClasses="OpenRight" />
</BoxContainer>
</Control>
</Control>
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt
using Content.Client.SS220.Discord;
using Robust.Client.Console;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Robust.Client.AutoGenerated;

namespace Content.Client.SS220.UserInterface.DiscordLink;

[GenerateTypedNameReferences]
public sealed partial class DiscordLinkRequiredGui : Control
{
[Dependency] private readonly DiscordPlayerInfoManager _discordPlayerInfoManager = default!;
[Dependency] private readonly IClientConsoleHost _consoleHost = default!;

public DiscordLinkRequiredGui()
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
LayoutContainer.SetAnchorPreset(this, LayoutContainer.LayoutPreset.Wide);

QuitButton.OnPressed += (_) =>
{
_consoleHost.ExecuteCommand("quit");
};

UrlEdit.Text = _discordPlayerInfoManager.AuthUrl;
OpenUrlButton.OnPressed += (_) =>
{
if (_discordPlayerInfoManager.AuthUrl != string.Empty)
{
IoCManager.Resolve<IUriOpener>().OpenUri(_discordPlayerInfoManager.AuthUrl);
}
};

ByPassCheck.OnPressed += (_) =>
{
_discordPlayerInfoManager.ByPassCheck();
};
}
}
2 changes: 1 addition & 1 deletion Content.Server/Corvax/DiscordAuth/DiscordAuthManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void Initialize()
_netMgr.RegisterNetMessage<MsgDiscordAuthRequired>();
_netMgr.RegisterNetMessage<MsgDiscordAuthCheck>(OnAuthCheck);

_playerMgr.PlayerStatusChanged += OnPlayerStatusChanged;
// _playerMgr.PlayerStatusChanged += OnPlayerStatusChanged;
}

private async void OnAuthCheck(MsgDiscordAuthCheck message)
Expand Down
4 changes: 4 additions & 0 deletions Content.Server/Corvax/JoinQueue/JoinQueueManager.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Linq;
using Content.Server.Connection;
using Content.Server.Corvax.DiscordAuth;
using Content.Server.SS220.Discord;
using Content.Shared.CCVar;
using Content.Shared.Corvax.CCCVars;
using Content.Shared.Corvax.JoinQueue;
Expand Down Expand Up @@ -41,6 +42,7 @@ public sealed class JoinQueueManager
[Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly IServerNetManager _netManager = default!;
[Dependency] private readonly DiscordAuthManager _discordAuthManager = default!;
[Dependency] private readonly DiscordPlayerManager _discordPlayerManager = default!;

/// <summary>
/// Queue of active player sessions
Expand All @@ -59,6 +61,8 @@ public void Initialize()
_cfg.OnValueChanged(CCCVars.QueueEnabled, OnQueueCVarChanged, true);
_playerManager.PlayerStatusChanged += OnPlayerStatusChanged;
_discordAuthManager.PlayerVerified += OnPlayerVerified;

_discordPlayerManager.PlayerVerified += OnPlayerVerified;
}

private void OnQueueCVarChanged(bool value)
Expand Down
2 changes: 1 addition & 1 deletion Content.Server/GameTicking/GameTicker.Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private async void PlayerStatusChanged(object? sender, SessionStatusEventArgs ar
// Make the player actually join the game.
// timer time must be > tick length
// Timer.Spawn(0, args.Session.JoinGame); // Corvax-Queue: Moved to `JoinQueueManager`
// Timer.Spawn(0, () => _playerManager.JoinGame(args.Session));
// Timer.Spawn(0, () => _playerManager.JoinGame(args.Session));

var record = await _db.GetPlayerRecordByUserId(args.Session.UserId);
var firstConnection = record != null &&
Expand Down
Loading
Loading