Skip to content
This repository has been archived by the owner on Nov 1, 2024. It is now read-only.

Commit

Permalink
Add corvax Secrets
Browse files Browse the repository at this point in the history
  • Loading branch information
Morb0 committed Apr 9, 2024
1 parent 89f7872 commit 7219816
Show file tree
Hide file tree
Showing 34 changed files with 371 additions and 22 deletions.
2 changes: 2 additions & 0 deletions Content.Client/Content.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
<ProjectReference Include="..\RobustToolbox\Robust.Shared\Robust.Shared.csproj" />
<ProjectReference Include="..\RobustToolbox\Robust.Client\Robust.Client.csproj" />
<ProjectReference Include="..\Content.Shared\Content.Shared.csproj" />
<ProjectReference Include="..\Corvax\Content.Corvax.Interfaces.Shared\Content.Corvax.Interfaces.Shared.csproj" />
<ProjectReference Include="..\Corvax\Content.Corvax.Interfaces.Client\Content.Corvax.Interfaces.Client.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Spawners\" />
Expand Down
7 changes: 7 additions & 0 deletions Content.Client/Humanoid/MarkingPicker.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Linq;
using Content.Corvax.Interfaces.Client;
using Content.Shared.Humanoid;
using Content.Shared.Humanoid.Markings;
using Content.Shared.Humanoid.Prototypes;
Expand All @@ -18,6 +19,7 @@ public sealed partial class MarkingPicker : Control
{
[Dependency] private readonly MarkingManager _markingManager = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
private IClientSponsorsManager? _sponsorsManager; // Corvax-Sponsors

public Action<MarkingSet>? OnMarkingAdded;
public Action<MarkingSet>? OnMarkingRemoved;
Expand Down Expand Up @@ -123,6 +125,7 @@ public MarkingPicker()
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
IoCManager.Instance!.TryResolveType(out _sponsorsManager); // Corvax-Sponsors

SetupCategoryButtons();
CMarkingCategoryButton.OnItemSelected += OnCategoryChange;
Expand Down Expand Up @@ -202,6 +205,10 @@ public void Populate(string filter)

var item = CMarkingsUnused.AddItem($"{GetMarkingName(marking)}", marking.Sprites[0].Frame0());
item.Metadata = marking;
// Corvax-Sponsors-Start
if (marking.SponsorOnly && _sponsorsManager != null)
item.Disabled = !_sponsorsManager.Prototypes.Contains(marking.ID);
// Corvax-Sponsors-End
}

CMarkingPoints.Visible = _currentMarkings.PointsLeft(_selectedMarkingCategory) != -1;
Expand Down
7 changes: 7 additions & 0 deletions Content.Client/Humanoid/SingleMarkingPicker.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Linq;
using Content.Corvax.Interfaces.Client;
using Content.Shared.Humanoid.Markings;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.Controls;
Expand All @@ -11,6 +12,7 @@ namespace Content.Client.Humanoid;
public sealed partial class SingleMarkingPicker : BoxContainer
{
[Dependency] private readonly MarkingManager _markingManager = default!;
private IClientSponsorsManager? _sponsorsManager; // Corvax-Sponsors

/// <summary>
/// What happens if a marking is selected.
Expand Down Expand Up @@ -122,6 +124,7 @@ public SingleMarkingPicker()
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
IoCManager.Instance!.TryResolveType(out _sponsorsManager); // Corvax-Sponsors

MarkingList.OnItemSelected += SelectMarking;
AddButton.OnPressed += _ =>
Expand Down Expand Up @@ -190,6 +193,10 @@ public void PopulateList(string filter)
{
var item = MarkingList.AddItem(Loc.GetString($"marking-{id}"), marking.Sprites[0].Frame0());
item.Metadata = marking.ID;
// Corvax-Sponsors-Start
if (marking.SponsorOnly && _sponsorsManager != null)
item.Disabled = !_sponsorsManager.Prototypes.Contains(marking.ID);
// Corvax-Sponsors-End

if (_markings[Slot].MarkingId == id)
{
Expand Down
8 changes: 7 additions & 1 deletion Content.Client/Preferences/ClientPreferencesManager.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Content.Corvax.Interfaces.Client;
using Content.Shared.Preferences;
using Robust.Client;
using Robust.Shared.Configuration;
Expand All @@ -22,6 +23,7 @@ public sealed class ClientPreferencesManager : IClientPreferencesManager
[Dependency] private readonly IBaseClient _baseClient = default!;
[Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly IPrototypeManager _prototypes = default!;
private IClientSponsorsManager? _sponsorsManager; // Corvax-Sponsors

public event Action? OnServerDataLoaded;

Expand All @@ -30,6 +32,7 @@ public sealed class ClientPreferencesManager : IClientPreferencesManager

public void Initialize()
{
IoCManager.Instance!.TryResolveType(out _sponsorsManager); // Corvax-Sponsors
_netManager.RegisterNetMessage<MsgPreferencesAndSettings>(HandlePreferencesAndSettings);
_netManager.RegisterNetMessage<MsgUpdateCharacter>();
_netManager.RegisterNetMessage<MsgSelectCharacter>();
Expand Down Expand Up @@ -64,7 +67,10 @@ public void SelectCharacter(int slot)

public void UpdateCharacter(ICharacterProfile profile, int slot)
{
profile.EnsureValid(_cfg, _prototypes);
// Corvax-Sponsors-Start
var sponsorPrototypes = _sponsorsManager?.Prototypes.ToArray() ?? [];
profile.EnsureValid(_cfg, _prototypes, sponsorPrototypes);
// Corvax-Sponsors-End
var characters = new Dictionary<int, ICharacterProfile>(Preferences.Characters) {[slot] = profile};
Preferences = new PlayerPreferences(characters, Preferences.SelectedCharacterIndex, Preferences.AdminOOCColor);
var msg = new MsgUpdateCharacter
Expand Down
6 changes: 6 additions & 0 deletions Content.Client/Preferences/UI/CharacterSetupGui.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
Text="{Loc 'character-setup-gui-character-setup-stats-button'}"
StyleClasses="ButtonBig"
HorizontalAlignment="Right" />
<!-- Corvax-Sponsor-Start -->
<Button Name="SponsorButton"
Text="{Loc 'character-setup-gui-character-setup-sponsor-button'}"
Visible="False"
StyleClasses="ButtonBig" />
<!-- Corvax-Sponsor-End -->
<Button Name="RulesButton"
Text="{Loc 'character-setup-gui-character-setup-rules-button'}"
StyleClasses="ButtonBig"/>
Expand Down
8 changes: 8 additions & 0 deletions Content.Client/Preferences/UI/CharacterSetupGui.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Content.Client.Lobby.UI;
using Content.Client.Resources;
using Content.Client.Stylesheets;
using Content.Corvax.Interfaces.Client;
using Content.Shared.Humanoid;
using Content.Shared.Humanoid.Prototypes;
using Content.Shared.Preferences;
Expand Down Expand Up @@ -79,6 +80,13 @@ public CharacterSetupGui(

StatsButton.OnPressed += _ => new PlaytimeStatsWindow().OpenCentered();
preferencesManager.OnServerDataLoaded += UpdateUI;
// Corvax-Sponsors-Start
if (IoCManager.Instance!.TryResolveType<ISponsorWindowCreator>(out var creator))
{
SponsorButton.Visible = true;
SponsorButton.OnPressed += _ => creator.OpenWindow();
}
// Corvax-Sponsors-End
}

protected override void Dispose(bool disposing)
Expand Down
10 changes: 10 additions & 0 deletions Content.Server/Chat/Managers/ChatManager.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Runtime.InteropServices;
using Content.Corvax.Interfaces.Server;
using Content.Server.Administration.Logs;
using Content.Server.Administration.Managers;
using Content.Server.Administration.Systems;
Expand Down Expand Up @@ -45,6 +46,7 @@ internal sealed partial class ChatManager : IChatManager
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
private IServerSponsorsManager? _sponsorsManager; // Corvax-Sponsors

/// <summary>
/// The maximum length a player-sent message can be sent
Expand All @@ -58,6 +60,7 @@ internal sealed partial class ChatManager : IChatManager

public void Initialize()
{
IoCManager.Instance!.TryResolveType(out _sponsorsManager); // Corvax-Sponsors
_netManager.RegisterNetMessage<MsgChatMessage>();
_netManager.RegisterNetMessage<MsgDeleteChatMessagesBy>();

Expand Down Expand Up @@ -236,6 +239,13 @@ private void SendOOC(ICommonSession player, string message)
wrappedMessage = Loc.GetString("chat-manager-send-ooc-patron-wrap-message", ("patronColor", patronColor), ("playerName", player.Name), ("message", FormattedMessage.EscapeText(message)));
}

// Corvax-Sponsors-Start
if (_sponsorsManager != null && _sponsorsManager.TryGetOocColor(player.UserId, out var oocColor))
{
wrappedMessage = Loc.GetString("chat-manager-send-ooc-patron-wrap-message", ("patronColor", oocColor),("playerName", player.Name), ("message", FormattedMessage.EscapeText(message)));
}
// Corvax-Sponsors-End

//TODO: player.Name color, this will need to change the structure of the MsgChatMessage
ChatMessageToAll(ChatChannel.OOC, message, wrappedMessage, EntityUid.Invalid, hideChat: false, recordReplay: true, colorOverride: colorOverride, author: player.UserId);
_mommiLink.SendOOCMessage(player.Name, message);
Expand Down
28 changes: 26 additions & 2 deletions Content.Server/Connection/ConnectionManager.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Immutable;
using System.Threading.Tasks;
using Content.Corvax.Interfaces.Server;
using Content.Server.Database;
using Content.Server.GameTicking;
using Content.Server.Preferences.Managers;
Expand All @@ -16,6 +17,7 @@ namespace Content.Server.Connection
public interface IConnectionManager
{
void Initialize();
Task<bool> HavePrivilegedJoin(NetUserId userId); // Corvax-Queue
}

/// <summary>
Expand All @@ -30,9 +32,11 @@ public sealed class ConnectionManager : IConnectionManager
[Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly ILocalizationManager _loc = default!;
[Dependency] private readonly ServerDbEntryManager _serverDbEntry = default!;
private IServerSponsorsManager? _sponsorsMgr; // Corvax-Sponsors

public void Initialize()
{
IoCManager.Instance!.TryResolveType(out _sponsorsMgr); // Corvax-Sponsors
_netMgr.Connecting += NetMgrOnConnecting;
_netMgr.AssignUserIdCallback = AssignUserIdCallback;
// Approval-based IP bans disabled because they don't play well with Happy Eyeballs.
Expand Down Expand Up @@ -106,7 +110,10 @@ private async Task NetMgrOnConnecting(NetConnectingArgs e)

var adminData = await _dbManager.GetAdminDataForAsync(e.UserId);

if (_cfg.GetCVar(CCVars.PanicBunkerEnabled) && adminData == null)
// Corvax-Start: Allow privileged players bypass bunker
var isPrivileged = await HavePrivilegedJoin(e.UserId);
if (_cfg.GetCVar(CCVars.PanicBunkerEnabled) && adminData == null && !isPrivileged)
// Corvax-End
{
var showReason = _cfg.GetCVar(CCVars.PanicBunkerShowReason);
var customReason = _cfg.GetCVar(CCVars.PanicBunkerCustomReason);
Expand Down Expand Up @@ -156,7 +163,10 @@ private async Task NetMgrOnConnecting(NetConnectingArgs e)
var wasInGame = EntitySystem.TryGet<GameTicker>(out var ticker) &&
ticker.PlayerGameStatuses.TryGetValue(userId, out var status) &&
status == PlayerGameStatus.JoinedGame;
if ((_plyMgr.PlayerCount >= _cfg.GetCVar(CCVars.SoftMaxPlayers) && adminData is null) && !wasInGame)
// Corvax-Queue-Start
var isQueueEnabled = IoCManager.Instance!.TryResolveType<IServerJoinQueueManager>(out var mgr) && mgr.IsEnabled;
if (_plyMgr.PlayerCount >= _cfg.GetCVar(CCVars.SoftMaxPlayers) && !isPrivileged && !isQueueEnabled)
// Corvax-Queue-End
{
return (ConnectionDenyReason.Full, Loc.GetString("soft-player-cap-full"), null);
}
Expand Down Expand Up @@ -206,5 +216,19 @@ private async Task NetMgrOnConnecting(NetConnectingArgs e)
await _db.AssignUserIdAsync(name, assigned);
return assigned;
}

// Corvax-Queue-Start: Make these conditions in one place, for checks in the connection and in the queue
public async Task<bool> HavePrivilegedJoin(NetUserId userId)
{
var adminBypass = await _dbManager.GetAdminDataForAsync(userId) != null;
var havePriorityJoin = _sponsorsMgr != null && _sponsorsMgr.HavePriorityJoin(userId); // Corvax-Sponsors
var wasInGame = EntitySystem.TryGet<GameTicker>(out var ticker) &&
ticker.PlayerGameStatuses.TryGetValue(userId, out var status) &&
status == PlayerGameStatus.JoinedGame;
return adminBypass ||
havePriorityJoin || // Corvax-Sponsors
wasInGame;
}
// Corvax-Queue-End
}
}
1 change: 1 addition & 0 deletions Content.Server/Content.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<ProjectReference Include="..\RobustToolbox\Robust.Shared\Robust.Shared.csproj" />
<ProjectReference Include="..\RobustToolbox\Robust.Server\Robust.Server.csproj" />
<ProjectReference Include="..\Content.Shared\Content.Shared.csproj" />
<ProjectReference Include="..\Corvax\Content.Corvax.Interfaces.Server\Content.Corvax.Interfaces.Server.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Objectives\Interfaces\" />
Expand Down
9 changes: 7 additions & 2 deletions Content.Server/GameTicking/GameTicker.Player.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Content.Corvax.Interfaces.Server;
using Content.Server.Database;
using Content.Shared.GameTicking;
using Content.Shared.GameWindow;
Expand Down Expand Up @@ -59,7 +60,10 @@ private async void PlayerStatusChanged(object? sender, SessionStatusEventArgs ar

// Make the player actually join the game.
// timer time must be > tick length
Timer.Spawn(0, () => _playerManager.JoinGame(args.Session));
// Corvax-Queue-Start
if (!IoCManager.Instance!.TryResolveType<IServerJoinQueueManager>(out _))
Timer.Spawn(0, () => _playerManager.JoinGame(args.Session));
// Corvax-Queue-End

var record = await _dbManager.GetPlayerRecordByUserId(args.Session.UserId);
var firstConnection = record != null &&
Expand Down Expand Up @@ -129,7 +133,8 @@ private async void PlayerStatusChanged(object? sender, SessionStatusEventArgs ar
mind.Session = null;
}

_userDb.ClientDisconnected(session);
if (_playerGameStatuses.ContainsKey(args.Session.UserId)) // Corvax-Queue: Delete data only if player was in game
_userDb.ClientDisconnected(session);
break;
}
}
Expand Down
9 changes: 8 additions & 1 deletion Content.Server/GameTicking/GameTicker.StatusShell.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text.Json.Nodes;
using Content.Corvax.Interfaces.Server;
using Content.Shared.CCVar;
using Content.Shared.GameTicking;
using Robust.Server.ServerStatus;
Expand Down Expand Up @@ -40,10 +41,16 @@ private void GetStatusResponse(JsonNode jObject)
// This method is raised from another thread, so this better be thread safe!
lock (_statusShellLock)
{
// Corvax-Queue-Start
var players = IoCManager.Instance?.TryResolveType<IServerJoinQueueManager>(out var joinQueueManager) ?? false
? joinQueueManager.ActualPlayersCount
: _playerManager.PlayerCount;
// Corvax-Queue-End

jObject["name"] = _baseServer.ServerName;
jObject["map"] = _gameMapManager.GetSelectedMap()?.MapName;
jObject["round_id"] = _gameTicker.RoundId;
jObject["players"] = _playerManager.PlayerCount;
jObject["players"] = players; // Corvax-Queue
jObject["soft_max_players"] = _cfg.GetCVar(CCVars.SoftMaxPlayers);
jObject["panic_bunker"] = _cfg.GetCVar(CCVars.PanicBunkerEnabled);
jObject["run_level"] = (int) _runLevel;
Expand Down
Loading

0 comments on commit 7219816

Please sign in to comment.