Skip to content

Commit

Permalink
New prime list (SerbiaStrong-220#900)
Browse files Browse the repository at this point in the history
* new prime list

* remove old prime list

* remove prime pgk
  • Loading branch information
Werzet authored Apr 9, 2024
1 parent a4fc117 commit 908c516
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 203 deletions.
1 change: 0 additions & 1 deletion Content.Packaging/ServerPackaging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public static class ServerPackaging
// SS220 extra assemblies begin
"FFMpegCore",
"MySqlConnector",
"Pomelo.EntityFrameworkCore.MySql",
"Instances"
// SS220 extra assemblies end
};
Expand Down
19 changes: 13 additions & 6 deletions Content.Server/Connection/ConnectionManager.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using System.Collections.Immutable;
using System.Text.Json.Nodes;
using System.Threading.Tasks;
using Content.Server.Corvax.Sponsors;
using Content.Server.Database;
using Content.Server.GameTicking;
using Content.Server.Preferences.Managers;
using Content.Server.SS220.PrimeWhitelist;
using Content.Server.SS220.Discord;
using Content.Shared.CCVar;
using Content.Shared.Corvax.CCCVars;
using Content.Shared.GameTicking;
Expand Down Expand Up @@ -35,8 +34,8 @@ public sealed class ConnectionManager : IConnectionManager
[Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly SponsorsManager _sponsorsManager = default!; // Corvax-Sponsors
[Dependency] private readonly ILocalizationManager _loc = default!;
[Dependency] private readonly Primelist _primelist = default!;
[Dependency] private readonly ServerDbEntryManager _serverDbEntry = default!;
[Dependency] private readonly DiscordPlayerManager _discordPlayerManager = default!;

public void Initialize()
{
Expand Down Expand Up @@ -186,14 +185,22 @@ private async Task NetMgrOnConnecting(NetConnectingArgs e)
return (ConnectionDenyReason.Ban, message, bans);
}

// SS220 prime list restriction start
if (_cfg.GetCVar(CCVars.PrimelistEnabled))
{
if (!await _primelist.IsPrimelisted(e.UserName.ToLower()))
var primeAccessStatus = await _discordPlayerManager.GetUserPrimeListStatus(userId);

if (primeAccessStatus is null)
{
var msg = Loc.GetString(_cfg.GetCVar(CCVars.WhitelistReason));
return (ConnectionDenyReason.Whitelist, msg, null);
return (ConnectionDenyReason.Whitelist, "Статус доступа на prime не был получен. Попробуйте переподключиться к серверу.", null);
}

if (!string.IsNullOrWhiteSpace(primeAccessStatus.PrimeAccessNotAvailableReason))
{
return (ConnectionDenyReason.Whitelist, primeAccessStatus.PrimeAccessNotAvailableReason, null);
}
}
// SS220 prime list restriction end
if (_cfg.GetCVar(CCVars.WhitelistEnabled))
{
var min = _cfg.GetCVar(CCVars.WhitelistMinPlayers);
Expand Down
5 changes: 2 additions & 3 deletions Content.Server/Content.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@
<ServerGarbageCollection>true</ServerGarbageCollection>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FFMpegCore"/>
<PackageReference Include="FFMpegCore" />
<PackageReference Include="JetBrains.Annotations" PrivateAssets="All" />
<PackageReference Include="Microsoft.EntityFrameworkCore"/>
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql"/>
<PackageReference Include="Microsoft.EntityFrameworkCore" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Content.Packaging\Content.Packaging.csproj" />
Expand Down
2 changes: 0 additions & 2 deletions Content.Server/Entry/EntryPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
using Content.Server.ServerInfo;
using Content.Server.ServerUpdates;
using Content.Server.SS220.Discord;
using Content.Server.SS220.PrimeWhitelist;
using Content.Server.Voting.Managers;
using Content.Shared.CCVar;
using Content.Shared.Kitchen;
Expand Down Expand Up @@ -113,7 +112,6 @@ public override void Init()
IoCManager.Resolve<JoinQueueManager>().Initialize(); // Corvax-Queue
IoCManager.Resolve<TTSManager>().Initialize(); // Corvax-TTS
IoCManager.Resolve<ServerInfoManager>().Initialize();
IoCManager.Resolve<Primelist>().Initialize();
IoCManager.Resolve<DiscordPlayerManager>().Initialize(); // SS220 discord player manager
IoCManager.Resolve<DiscordBanPostManager>().Initialize(); // SS220 discord ban post manager
IoCManager.Resolve<ServerControlController>().Initialize();
Expand Down
2 changes: 0 additions & 2 deletions Content.Server/IoC/ServerContentIoC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
using Content.Server.ServerUpdates;
using Content.Server.SS220.BackEndApi;
using Content.Server.SS220.Discord;
using Content.Server.SS220.PrimeWhitelist;
using Content.Server.Voting.Managers;
using Content.Server.Worldgen.Tools;
using Content.Shared.Administration.Logs;
Expand Down Expand Up @@ -67,7 +66,6 @@ public static void Register()
IoCManager.Register<DiscordAuthManager>(); // Corvax-DiscordAuth
IoCManager.Register<ServerInfoManager>();
IoCManager.Register<PoissonDiskSampler>();
IoCManager.Register<Primelist>();
IoCManager.Register<DiscordPlayerManager>(); // SS220 discord player manager
IoCManager.Register<DiscordBanPostManager>(); // SS220 discord ban post manager
IoCManager.Register<ServerControlController>();
Expand Down
35 changes: 35 additions & 0 deletions Content.Server/SS220/Discord/DiscordPlayerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,5 +179,40 @@ private static string CreateSecureRandomString(int count = 32)
{
return Convert.ToBase64String(RandomNumberGenerator.GetBytes(count));
}

public async Task<PrimeListUserStatus?> GetUserPrimeListStatus(Guid userId)
{
if (string.IsNullOrEmpty(_apiUrl))
{
return null;
}

try
{
var url = $"{_apiUrl}/checkPrimeAccess/{userId}";

var response = await _httpClient.GetAsync(url);

if (response.StatusCode != HttpStatusCode.OK)
{
var errorText = await response.Content.ReadAsStringAsync();

_sawmill.Error(
"Failed to get user prime list status: [{StatusCode}] {Response}",
response.StatusCode,
errorText);

return null;
}

return await response.Content.ReadFromJsonAsync<PrimeListUserStatus>(GetJsonSerializerOptions());
}
catch (Exception exc)
{
_sawmill.Error(exc.Message);
}

return null;
}
}

6 changes: 6 additions & 0 deletions Content.Server/SS220/Discord/PrimeListUserStatus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Content.Server.SS220.Discord;

public sealed class PrimeListUserStatus
{
public string? PrimeAccessNotAvailableReason { get; set; }
}
156 changes: 0 additions & 156 deletions Content.Server/SS220/PrimeWhitelist/WhitelistSystem.cs

This file was deleted.

36 changes: 3 additions & 33 deletions Content.Shared/CCVar/CCVars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1091,9 +1091,9 @@ public static readonly CVarDef<bool>
/// <summary>
/// Whether monstermos explosive depressurization will rip tiles..
/// Needs <see cref="MonstermosEqualization"/> and <see cref="MonstermosDepressurization"/> to be enabled to work.
/// WARNING: This cvar causes MAJOR contrast issues, and usually tends to make any spaced scene look very cluttered.
/// This not only usually looks strange, but can also reduce playability for people with impaired vision. Please think twice before enabling this on your server.
/// Also looks weird on slow spacing for unrelated reasons. If you do want to enable this, you should probably turn on instaspacing.
/// WARNING: This cvar causes MAJOR contrast issues, and usually tends to make any spaced scene look very cluttered.
/// This not only usually looks strange, but can also reduce playability for people with impaired vision. Please think twice before enabling this on your server.
/// Also looks weird on slow spacing for unrelated reasons. If you do want to enable this, you should probably turn on instaspacing.
/// </summary>
public static readonly CVarDef<bool> MonstermosRipTiles =
CVarDef.Create("atmos.monstermos_rip_tiles", false, CVar.SERVERONLY);
Expand Down Expand Up @@ -1296,36 +1296,6 @@ public static readonly CVarDef<bool>
public static readonly CVarDef<bool> PrimelistEnabled =
CVarDef.Create("primelist.enabled", false, CVar.SERVERONLY);

/// <summary>
/// IP address of the Prime database server
/// </summary>
public static readonly CVarDef<string> PrimelistDatabaseIp =
CVarDef.Create("primelist.ip", string.Empty, CVar.SERVERONLY);

/// <summary>
/// Port of the Prime database server
/// </summary>
public static readonly CVarDef<int> PrimelistDatabasePort =
CVarDef.Create("primelist.port", 3306, CVar.SERVERONLY);

/// <summary>
/// Name of the Prime database server
/// </summary>
public static readonly CVarDef<string> PrimelistDatabaseName =
CVarDef.Create("primelist.database", string.Empty, CVar.SERVERONLY);

/// <summary>
/// Username for the Prime database server
/// </summary>
public static readonly CVarDef<string> PrimelistDatabaseUsername =
CVarDef.Create("primelist.username", string.Empty, CVar.SERVERONLY | CVar.CONFIDENTIAL);

/// <summary>
/// Password for the Prime database server
/// </summary>
public static readonly CVarDef<string> PrimelistDatabasePassword =
CVarDef.Create("primelist.password", string.Empty, CVar.SERVERONLY | CVar.CONFIDENTIAL);

/*
* VOTE
*/
Expand Down

0 comments on commit 908c516

Please sign in to comment.