Skip to content

Commit

Permalink
Merge pull request #256 from Rxup/upstream-sync
Browse files Browse the repository at this point in the history
Upstream sync
  • Loading branch information
KayzelW authored Oct 3, 2023
2 parents 29d2678 + 02be289 commit abcee1b
Show file tree
Hide file tree
Showing 42 changed files with 131 additions and 87 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# Secret
Resources/Prototypes/CorvaxSecrets
Resources/Prototypes/CorvaxSecretsServer
Resources/Textures/CorvaxSecrets
Resources/Locale/ru-RU/corvax-secrets

# Build results
[Dd]ebug/
Expand Down
6 changes: 5 additions & 1 deletion Content.Client/Backmen/DiscordAuth/DiscordAuthGui.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@
<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="Vertical" VerticalAlignment="Bottom" Margin="10 0 0 0">
<Label Text="{Loc 'discord-auth-qrcode'}" Align="Center" />
<TextureRect Name="QrCode" MaxHeight="400" HorizontalAlignment="Center" Margin="10 0 0 0"></TextureRect>
</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>
<TextEdit Name="UrlEdit" HorizontalExpand="True" Editable="False" VerticalExpand="True" MinSize="220 100" Margin="10"></TextEdit>
</BoxContainer>
<Button Name="OpenUrlButton" Text="{Loc 'discord-auth-browser-btn'}" HorizontalExpand="True" StyleClasses="OpenRight" />
</BoxContainer>
Expand Down
9 changes: 8 additions & 1 deletion Content.Client/Backmen/DiscordAuth/DiscordAuthGui.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using Robust.Client.AutoGenerated;
using Robust.Client.Console;
using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Utility;

namespace Content.Client.Backmen.DiscordAuth;

Expand All @@ -23,7 +25,12 @@ public DiscordAuthGui()
_consoleHost.ExecuteCommand("quit");
};

UrlEdit.Text = _discordAuthManager.AuthUrl;
UrlEdit.TextRope = new Rope.Leaf(_discordAuthManager.AuthUrl);
if (_discordAuthManager.Qrcode != null)
{
QrCode.Texture = _discordAuthManager.Qrcode;
}

OpenUrlButton.OnPressed += (_) =>
{
if (_discordAuthManager.AuthUrl != string.Empty)
Expand Down
14 changes: 13 additions & 1 deletion Content.Client/Backmen/DiscordAuth/DiscordAuthManager.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
using System.Threading;
using System.IO;
using System.Threading;
using Content.Shared.Backmen.DiscordAuth;
using Robust.Client.Graphics;
using Robust.Client.ResourceManagement;
using Robust.Client.State;
using Robust.Shared.ContentPack;
using Robust.Shared.Network;
using Robust.Shared.Utility;
using Timer = Robust.Shared.Timing.Timer;

namespace Content.Client.Backmen.DiscordAuth;
Expand All @@ -12,6 +17,7 @@ public sealed class DiscordAuthManager : Content.Corvax.Interfaces.Client.IClien
[Dependency] private readonly IStateManager _stateManager = default!;

public string AuthUrl { get; private set; } = string.Empty;
public Texture? Qrcode { get; private set; }

public void Initialize()
{
Expand All @@ -24,6 +30,12 @@ private void OnDiscordAuthRequired(MsgDiscordAuthRequired message)
if (_stateManager.CurrentState is not DiscordAuthState)
{
AuthUrl = message.AuthUrl;
if (message.QrCode.Length > 0)
{
using var ms = new MemoryStream(message.QrCode);
Qrcode = Texture.LoadFromPNGStream(ms);
}

_stateManager.RequestStateChange<DiscordAuthState>();
}
}
Expand Down
13 changes: 0 additions & 13 deletions Content.Client/Backmen/Sponsors/SponsorsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,13 @@ private void OnUpdate(MsgSponsorInfo message)
return;
}

OocColor = Color.TryFromHex(message.Info.OOCColor);
Prototypes.AddRange(message.Info.AllowedMarkings);
PriorityJoin = message.Info.HavePriorityJoin;
ExtraCharSlots = message.Info.ExtraSlots;
GhostTheme = message.Info.GhostTheme;
}

private void Reset()
{
Prototypes.Clear();
PriorityJoin = false;
OocColor = null;
ExtraCharSlots = 0;
GhostTheme = null;
}


public List<string> Prototypes { get; } = new();
public bool PriorityJoin { get; private set; }
public Color? OocColor { get; private set; }
public int ExtraCharSlots { get; private set; }
public string? GhostTheme { get; private set; }
}
2 changes: 2 additions & 0 deletions Content.Client/Corvax/IClientDiscordAuthManager.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using Content.Corvax.Interfaces.Shared;
using Robust.Client.Graphics;

namespace Content.Corvax.Interfaces.Client;

public interface IClientDiscordAuthManager : ISharedDiscordAuthManager
{
public string AuthUrl { get; }
public Texture? Qrcode { get; }
}
4 changes: 0 additions & 4 deletions Content.Client/Corvax/IClientSponsorsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,4 @@ namespace Content.Corvax.Interfaces.Client;
public interface IClientSponsorsManager : ISharedSponsorsManager
{
public List<string> Prototypes { get; }
public bool PriorityJoin { get; }
public Color? OocColor { get; }
public int ExtraCharSlots { get; }
public string? GhostTheme { get; }
}
4 changes: 2 additions & 2 deletions Content.Client/Preferences/ClientPreferencesManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ public void SelectCharacter(int slot)
public void UpdateCharacter(ICharacterProfile profile, int slot)
{
// Corvax-Sponsors-Start
var allowedMarkings = _sponsorsManager?.Prototypes.ToArray() ?? new string[]{};
profile.EnsureValid(allowedMarkings);
var sponsorPrototypes = _sponsorsManager?.Prototypes.ToArray() ?? new string[]{};
profile.EnsureValid(sponsorPrototypes);
// Corvax-Sponsors-End
var characters = new Dictionary<int, ICharacterProfile>(Preferences.Characters) {[slot] = profile};
Preferences = new PlayerPreferences(characters, Preferences.SelectedCharacterIndex, Preferences.AdminOOCColor);
Expand Down
4 changes: 4 additions & 0 deletions Content.Client/Preferences/UI/HumanoidProfileEditor.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ public HumanoidProfileEditor(IClientPreferencesManager preferencesManager, IProt
#region Species

_speciesList = prototypeManager.EnumeratePrototypes<SpeciesPrototype>().Where(o => o.RoundStart).ToList();
// Corvax-Sponsors-Start
if (_sponsorsMgr != null)
_speciesList = _speciesList.Where(p => !p.SponsorOnly || _sponsorsMgr.Prototypes.Contains(p.ID)).ToList();
// Corvax-Sponsors-End
for (var i = 0; i < _speciesList.Count; i++)
{
var name = Loc.GetString(_speciesList[i].Name);
Expand Down
8 changes: 4 additions & 4 deletions Content.Server/Backmen/DiscordAuth/DiscordAuthManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ private async void OnPlayerStatusChanged(object? sender, SessionStatusEventArgs
}

var authUrl = await GenerateAuthLink(e.Session.UserId);
var msg = new MsgDiscordAuthRequired() { AuthUrl = authUrl };
var msg = new MsgDiscordAuthRequired() { AuthUrl = authUrl.Url, QrCode = authUrl.Qrcode };
e.Session.ConnectedClient.SendMessage(msg);
}
}

public async Task<string> GenerateAuthLink(NetUserId userId, CancellationToken cancel = default)
public async Task<DiscordGenerateLinkResponse> GenerateAuthLink(NetUserId userId, CancellationToken cancel = default)
{
_sawmill.Info($"Player {userId} requested generation Discord verification link");

Expand All @@ -94,7 +94,7 @@ public async Task<string> GenerateAuthLink(NetUserId userId, CancellationToken c
}

var data = await response.Content.ReadFromJsonAsync<DiscordGenerateLinkResponse>(cancellationToken: cancel);
return data!.Url;
return data!;
}

public async Task<bool> IsVerified(NetUserId userId, CancellationToken cancel = default)
Expand All @@ -114,7 +114,7 @@ public async Task<bool> IsVerified(NetUserId userId, CancellationToken cancel =
}

[UsedImplicitly]
private sealed record DiscordGenerateLinkResponse(string Url);
public sealed record DiscordGenerateLinkResponse(string Url, byte[] Qrcode);
[UsedImplicitly]
private sealed record DiscordAuthInfoResponse(bool IsLinked);
}
15 changes: 10 additions & 5 deletions Content.Server/Backmen/JoinQueue/JoinQueueManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,29 @@ public sealed class JoinQueueManager : Content.Corvax.Interfaces.Server.IServerJ
/// </summary>
private readonly List<IPlayerSession> _queue = new(); // Real Queue class can't delete disconnected users

private bool _isEnabled = false;
private bool _isIsEnabled = false;

public bool Enabled => _isEnabled;
public bool IsEnabled => _isIsEnabled;
public int PlayerInQueueCount => _queue.Count;
public int ActualPlayersCount => _playerManager.PlayerCount - PlayerInQueueCount; // Now it's only real value with actual players count that in game

public void Initialize()
{
_netManager.RegisterNetMessage<MsgQueueUpdate>();

_cfg.OnValueChanged(CCCVars.QueueEnabled, OnQueueCVarChanged, true);
_cfg.OnValueChanged(Shared.Backmen.CCVar.CCVars.QueueEnabled, OnQueueCVarChanged, true);
_playerManager.PlayerStatusChanged += OnPlayerStatusChanged;
_discordAuthManager.PlayerVerified += OnPlayerVerified;
}

public void PostInitialize()
{

}

private void OnQueueCVarChanged(bool value)
{
_isEnabled = value;
_isIsEnabled = value;

if (!value)
{
Expand All @@ -73,7 +78,7 @@ private void OnQueueCVarChanged(bool value)

private async void OnPlayerVerified(object? sender, IPlayerSession session)
{
if (!_isEnabled)
if (!_isIsEnabled)
{
SendToGame(session);
return;
Expand Down
2 changes: 1 addition & 1 deletion Content.Server/Connection/ConnectionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ private async Task NetMgrOnConnecting(NetConnectingArgs e)
}

// Corvax-Queue-Start
var isQueueEnabled = _cfg.GetCVar(CCCVars.QueueEnabled);
var isQueueEnabled = IoCManager.Instance!.TryResolveType<IServerJoinQueueManager>(out var mgr) && mgr.IsEnabled;
if (_plyMgr.PlayerCount >= _cfg.GetCVar(CCVars.SoftMaxPlayers) && !isPrivileged && !isQueueEnabled)
// Corvax-Queue-End
{
Expand Down
3 changes: 2 additions & 1 deletion Content.Server/Corvax/IServerDiscordAuthManager.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Threading;
using System.Threading.Tasks;
using Content.Corvax.Interfaces.Shared;
using Content.Server.Backmen.DiscordAuth;
using Robust.Server.Player;
using Robust.Shared.Network;

Expand All @@ -9,6 +10,6 @@ namespace Content.Corvax.Interfaces.Server;
public interface IServerDiscordAuthManager : ISharedDiscordAuthManager
{
public event EventHandler<IPlayerSession>? PlayerVerified;
public Task<string> GenerateAuthLink(NetUserId userId, CancellationToken cancel);
public Task<DiscordAuthManager.DiscordGenerateLinkResponse> GenerateAuthLink(NetUserId userId, CancellationToken cancel);
public Task<bool> IsVerified(NetUserId userId, CancellationToken cancel);
}
3 changes: 2 additions & 1 deletion Content.Server/Corvax/IServerJoinQueueManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

public interface IServerJoinQueueManager
{
public bool Enabled { get; }
public bool IsEnabled { get; }
public int PlayerInQueueCount { get; }
public int ActualPlayersCount { get; }
public void Initialize();
public void PostInitialize();
}
3 changes: 3 additions & 0 deletions Content.Server/Entry/EntryPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ public override void PostInit()
IoCManager.Resolve<IGameMapManager>().Initialize();
IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<GameTicker>().PostInitialize();
IoCManager.Resolve<IBanManager>().Initialize();
// start-backmen: IoC
IoCManager.Resolve<Content.Corvax.Interfaces.Server.IServerJoinQueueManager>().PostInitialize();
// end-backmen: IoC
}
}

Expand Down
4 changes: 2 additions & 2 deletions Content.Server/GameTicking/GameTicker.StatusShell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ private void GetStatusResponse(JsonNode jObject)
lock (_statusShellLock)
{
// Corvax-Queue-Start
var players = _joinQueueManager.Enabled
? _joinQueueManager.ActualPlayersCount
var players = IoCManager.Instance?.TryResolveType<IServerJoinQueueManager>(out var joinQueueManager) ?? false
? joinQueueManager.ActualPlayersCount
: _playerManager.PlayerCount;
// Corvax-Queue-End

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ private async void HandleUpdateCharacterMessage(MsgUpdateCharacter message)

// Corvax-Sponsors-Start: Ensure removing sponsor markings if client somehow bypassed client filtering
// WARN! It's not removing markings from DB!
var allowedMarkings = _sponsors != null && _sponsors.TryGetPrototypes(message.MsgChannel.UserId, out var prototypes)
var sponsorPrototypes = _sponsors != null && _sponsors.TryGetPrototypes(message.MsgChannel.UserId, out var prototypes)
? prototypes.ToArray()
: new string[]{};
profile.EnsureValid(allowedMarkings);
profile.EnsureValid(sponsorPrototypes);
// Corvax-Sponsors-End
var profiles = new Dictionary<int, ICharacterProfile>(curPrefs.Characters)
{
Expand Down Expand Up @@ -204,10 +204,10 @@ async Task LoadPrefs()
// Corvax-Sponsors-Start: Remove sponsor markings from expired sponsors
foreach (var (_, profile) in prefs.Characters)
{
var allowedMarkings = _sponsors != null && _sponsors.TryGetPrototypes(session.UserId, out var prototypes)
var sponsorPrototypes = _sponsors != null && _sponsors.TryGetPrototypes(session.UserId, out var prototypes)
? prototypes.ToArray()
: new string[]{};
profile.EnsureValid(allowedMarkings);
profile.EnsureValid(sponsorPrototypes);
}
// Corvax-Sponsors-End
prefsData.Prefs = prefs;
Expand Down
9 changes: 9 additions & 0 deletions Content.Shared/Backmen/CCVar/CCVars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ namespace Content.Shared.Backmen.CCVar;
[CVarDefs]
public sealed class CCVars
{
/*
* Queue
*/

/// <summary>
/// Controls if the connections queue is enabled. If enabled stop kicking new players after `SoftMaxPlayers` cap and instead add them to queue.
/// </summary>
public static readonly CVarDef<bool>
QueueEnabled = CVarDef.Create("queue.enabled", false, CVar.SERVERONLY);

/*
* Discord Auth
Expand Down
15 changes: 15 additions & 0 deletions Content.Shared/Backmen/DiscordAuth/MsgDiscordAuthRequired.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,29 @@ public sealed class MsgDiscordAuthRequired : NetMessage
public override MsgGroups MsgGroup => MsgGroups.Command;

public string AuthUrl = string.Empty;
public byte[] QrCode = Array.Empty<byte>();

public override void ReadFromBuffer(NetIncomingMessage buffer, IRobustSerializer serializer)
{
AuthUrl = buffer.ReadString();
buffer.ReadPadBits();
var length = buffer.ReadInt32();
if (length == 0)
{
return;
}
QrCode = buffer.ReadBytes(length);
}

public override void WriteToBuffer(NetOutgoingMessage buffer, IRobustSerializer serializer)
{
buffer.Write(AuthUrl);
buffer.WritePadBits();
buffer.Write((int)QrCode.Length);
if (QrCode.Length == 0)
{
return;
}
buffer.Write(QrCode);
}
}
10 changes: 0 additions & 10 deletions Content.Shared/Corvax/CCCVars/CCCVars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,6 @@ namespace Content.Shared.Corvax.CCCVars;
// ReSharper disable once InconsistentNaming
public sealed class CCCVars
{
/*
* Queue
*/

/// <summary>
/// Controls if the connections queue is enabled. If enabled stop kicking new players after `SoftMaxPlayers` cap and instead add them to queue.
/// </summary>
public static readonly CVarDef<bool>
QueueEnabled = CVarDef.Create("queue.enabled", false, CVar.SERVERONLY);

/**
* TTS (Text-To-Speech)
*/
Expand Down
Loading

0 comments on commit abcee1b

Please sign in to comment.