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

Фиксы спонсорки #380

Merged
merged 4 commits into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 0 additions & 1 deletion Content.Client/ADT/RPD/RPDMenu.xaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<ui:RadialMenu xmlns="https://spacestation14.io"
xmlns:ui="clr-namespace:Content.Client.UserInterface.Controls"
xmlns:rpd="clr-namespace:Content.Client.RPD"
BackButtonStyleClass="RadialMenuBackButton"
CloseButtonStyleClass="RadialMenuCloseButton"
VerticalExpand="True"
Expand Down
12 changes: 12 additions & 0 deletions Content.Client/Administration/AdminNameOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ protected override void Draw(in OverlayDrawArgs args)
{
args.ScreenHandle.DrawString(_font, screenCoordinates + (lineoffset * 2), "ANTAG", Color.OrangeRed);
}

if (playerInfo.Sponsor != null)
{
var sponsorOffset = playerInfo.Antag ? lineoffset * 3 : lineoffset * 2;
var sponsorString = $"Sponsor ({playerInfo.Sponsor.Tier})";
if (playerInfo.Sponsor.AllowJob)
sponsorString += " (allJobs)";

sponsorString += $" до {playerInfo.Sponsor.ExpireDate.ToString("dd.MM.yyyy")}";

args.ScreenHandle.DrawString(_font, screenCoordinates + sponsorOffset, sponsorString, Color.GreenYellow);
}
args.ScreenHandle.DrawString(_font, screenCoordinates+lineoffset, playerInfo.Username, playerInfo.Connected ? Color.Yellow : Color.White);
args.ScreenHandle.DrawString(_font, screenCoordinates, playerInfo.CharacterName, playerInfo.Connected ? Color.Aquamarine : Color.White);
}
Expand Down
16 changes: 16 additions & 0 deletions Content.Client/Administration/UI/Tabs/PlayerTab/PlayerTab.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,27 @@ private int Compare(PlayerInfo x, PlayerInfo y)
Header.Character => Compare(x.CharacterName, y.CharacterName),
Header.Job => Compare(x.StartingJob, y.StartingJob),
Header.Antagonist => x.Antag.CompareTo(y.Antag),
Header.Sponsor => Compare(x.Sponsor?.Tier, y.Sponsor?.Tier),
Header.Playtime => TimeSpan.Compare(x.OverallPlaytime ?? default, y.OverallPlaytime ?? default),
_ => 1
};
}

private int Compare(int? x, int? y)
{
if (!x.HasValue)
return -1;
if (!y.HasValue)
return 1;

if (x == y)
return 0;
else if (x > y)
return 1;
else
return -1;
}

private int Compare(string x, string y)
{
return string.Compare(x, y, StringComparison.OrdinalIgnoreCase);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
HorizontalExpand="True"
ClipText="True"/>
<customControls:VSeparator/>
<Label Name="SponsorLabel"
SizeFlagsStretchRatio="1"
HorizontalExpand="True"
ClipText="True"/>
<customControls:VSeparator/>
<Label Name="OverallPlaytimeLabel"
SizeFlagsStretchRatio="1"
HorizontalExpand="True"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public PlayerTabEntry(PlayerInfo player, StyleBoxFlat styleBoxFlat)
if (player.IdentityName != player.CharacterName)
CharacterLabel.Text += $" [{player.IdentityName}]";
AntagonistLabel.Text = Loc.GetString(player.Antag ? "player-tab-is-antag-yes" : "player-tab-is-antag-no");
SponsorLabel.Text = Loc.GetString(player.Sponsor != null ? "player-tab-is-sponsor-yes" : "player-tab-is-sponsor-no");
BackgroundColorPanel.PanelOverride = styleBoxFlat;
OverallPlaytimeLabel.Text = player.PlaytimeString;
PlayerEntity = player.NetEntity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@
Text="{Loc player-tab-antagonist}"
MouseFilter="Pass"/>
<cc:VSeparator/>
<Label Name="SponsorLabel"
SizeFlagsStretchRatio="1"
HorizontalExpand="True"
ClipText="True"
Text="{Loc player-tab-sponsor}"
MouseFilter="Pass"/>
<cc:VSeparator/>
<Label Name="PlaytimeLabel"
SizeFlagsStretchRatio="1"
HorizontalExpand="True"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public PlayerTabHeader()
CharacterLabel.OnKeyBindDown += CharacterClicked;
JobLabel.OnKeyBindDown += JobClicked;
AntagonistLabel.OnKeyBindDown += AntagonistClicked;
SponsorLabel.OnKeyBindDown += SponsorClicked;
PlaytimeLabel.OnKeyBindDown += PlaytimeClicked;
}

Expand All @@ -30,6 +31,7 @@ public Label GetHeader(Header header)
Header.Character => CharacterLabel,
Header.Job => JobLabel,
Header.Antagonist => AntagonistLabel,
Header.Sponsor => SponsorLabel,
Header.Playtime => PlaytimeLabel,
_ => throw new ArgumentOutOfRangeException(nameof(header), header, null)
};
Expand All @@ -41,6 +43,7 @@ public void ResetHeaderText()
CharacterLabel.Text = Loc.GetString("player-tab-character");
JobLabel.Text = Loc.GetString("player-tab-job");
AntagonistLabel.Text = Loc.GetString("player-tab-antagonist");
SponsorLabel.Text = Loc.GetString("player-tab-sponsor");
PlaytimeLabel.Text = Loc.GetString("player-tab-playtime");
}

Expand Down Expand Up @@ -75,6 +78,11 @@ private void AntagonistClicked(GUIBoundKeyEventArgs args)
HeaderClicked(args, Header.Antagonist);
}

private void SponsorClicked(GUIBoundKeyEventArgs args)
{
HeaderClicked(args, Header.Sponsor);
}

private void PlaytimeClicked(GUIBoundKeyEventArgs args)
{
HeaderClicked(args, Header.Playtime);
Expand All @@ -90,6 +98,7 @@ protected override void Dispose(bool disposing)
CharacterLabel.OnKeyBindDown -= CharacterClicked;
JobLabel.OnKeyBindDown -= JobClicked;
AntagonistLabel.OnKeyBindDown -= AntagonistClicked;
SponsorLabel.OnKeyBindDown -= SponsorClicked;
PlaytimeLabel.OnKeyBindDown -= PlaytimeClicked;
}
}
Expand All @@ -100,6 +109,7 @@ public enum Header
Character,
Job,
Antagonist,
Sponsor,
Playtime
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ protected override void Up(MigrationBuilder migrationBuilder)
// name: "FK_admin_log_player_admin_log_log_id_round_id",
// table: "admin_log_player");

migrationBuilder.DropPrimaryKey(
name: "PK_admin_log_player",
table: "admin_log_player");

migrationBuilder.DropIndex(
name: "IX_admin_log_player_log_id_round_id",
table: "admin_log_player");

migrationBuilder.DropPrimaryKey(
name: "PK_admin_log",
table: "admin_log");

migrationBuilder.DropIndex(
name: "IX_admin_log_round_id",
table: "admin_log");
// migrationBuilder.DropPrimaryKey(
// name: "PK_admin_log_player",
// table: "admin_log_player");
//
// migrationBuilder.DropIndex(
// name: "IX_admin_log_player_log_id_round_id",
// table: "admin_log_player");
//
// migrationBuilder.DropPrimaryKey(
// name: "PK_admin_log",
// table: "admin_log");
//
// migrationBuilder.DropIndex(
// name: "IX_admin_log_round_id",
// table: "admin_log");

migrationBuilder.AddPrimaryKey(
name: "PK_admin_log_player",
Expand Down
2 changes: 0 additions & 2 deletions Content.Server.Database/Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ protected ServerDbContext(DbContextOptions options) : base(options)
public DbSet<PlayTime> PlayTime { get; set; } = default!;
public DbSet<UploadedResourceLog> UploadedResourceLog { get; set; } = default!;
public DbSet<AdminNote> AdminNotes { get; set; } = null!;
public DbSet<Sponsor> Sponsors { get; set; } = null!; //ADT-Sponsors

public DbSet<AdminWatchlist> AdminWatchlists { get; set; } = null!;
public DbSet<AdminMessage> AdminMessages { get; set; } = null!;
public DbSet<RoleWhitelist> RoleWhitelists { get; set; } = null!;
Expand Down
10 changes: 9 additions & 1 deletion Content.Server/Administration/Systems/AdminSystem.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Linq;
using Content.Server.Administration.Managers;
using Content.Server.Chat.Managers;
using Content.Server.Corvax.Sponsors;
using Content.Server.Forensics;
using Content.Server.GameTicking;
using Content.Server.Hands.Systems;
Expand All @@ -12,6 +13,7 @@
using Content.Shared.Administration.Events;
using Content.Shared.CCVar;
using Content.Shared.Corvax.CCCVars;
using Content.Shared.Corvax.Sponsors;
using Content.Shared.GameTicking;
using Content.Shared.Hands.Components;
using Content.Shared.IdentityManagement;
Expand Down Expand Up @@ -52,6 +54,9 @@ public sealed class AdminSystem : EntitySystem
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly StationRecordsSystem _stationRecords = default!;
[Dependency] private readonly TransformSystem _transform = default!;
//ADT-SPONSORS
[Dependency] private readonly SponsorsManager _sponsorsManager = default!;
//ADT-SPONSORS

private readonly Dictionary<NetUserId, PlayerInfo> _playerList = new();

Expand Down Expand Up @@ -248,7 +253,10 @@ private PlayerInfo GetPlayerInfo(SessionData data, ICommonSession? session)
overallPlaytime = playTime;
}

return new PlayerInfo(name, entityName, identityName, startingRole, antag, GetNetEntity(session?.AttachedEntity), data.UserId,
SponsorInfo? sponsorInfo = null;
_sponsorsManager.TryGetInfo(data.UserId, out sponsorInfo);

return new PlayerInfo(name, entityName, identityName, startingRole, antag, sponsorInfo, GetNetEntity(session?.AttachedEntity), data.UserId,
connected, _roundActivePlayers.Contains(data.UserId), overallPlaytime);
}

Expand Down
2 changes: 1 addition & 1 deletion Content.Server/Corvax/Sponsors/CheckSponsorSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public bool CheckUser(string player)
else
return false;

if (sponsorData != null && sponsorData.Tier > 0)
if (sponsorData != null && (sponsorData.Tier > 0 || sponsorData.AllowJob))
return true;
else
return false;
Expand Down
24 changes: 2 additions & 22 deletions Content.Server/Corvax/Sponsors/SponsorsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,27 +90,7 @@ private void OnDisconnect(object? sender, NetDisconnectedArgs e)

return await response.Content.ReadFromJsonAsync<SponsorInfo>();
}
else
{
var sponsorInfo = await _dbManager.GetSponsorInfo(userId);
if (sponsorInfo != null)
{
return new SponsorInfo()
{
Tier = sponsorInfo.Tier,
AllowedMarkings = sponsorInfo.AllowedMarkings.Split(";",StringSplitOptions.RemoveEmptyEntries),
CharacterName = string.Empty,
ExtraSlots = sponsorInfo.ExtraSlots,
HavePriorityJoin = sponsorInfo.HavePriorityJoin,
OOCColor = sponsorInfo.OOCColor,
ExpireDate = sponsorInfo.ExpireDate,
AllowJob = sponsorInfo.AllowJob
};
}
else
{
return null;
}
}

return null;
}
}
17 changes: 0 additions & 17 deletions Content.Server/Database/ServerDbBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1608,23 +1608,6 @@ protected async Task<List<ServerRoleBanNoteRecord>> GetGroupedServerRoleBansAsNo

#endregion

//ADT-Sponsors-Start
#region Sponsors

public async Task<Sponsor?> GetSponsorInfo(NetUserId userId)
{
await using var db = await GetDb();
return await db.DbContext.Sponsors.AsNoTracking().FirstOrDefaultAsync(x => x.UserId == userId.UserId);
}

public async Task<Sponsor[]?> GetSponsorList()
{
await using var db = await GetDb();
return await db.DbContext.Sponsors.AsNoTracking().ToArrayAsync();
}
#endregion
//ADT-Sponsors-End

#region Job Whitelists

public async Task<bool> AddJobWhitelist(Guid player, ProtoId<JobPrototype> job)
Expand Down
21 changes: 0 additions & 21 deletions Content.Server/Database/ServerDbManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -293,13 +293,6 @@ Task<int> AddConnectionLogAsync(

#endregion

//ADT-Sponsors-Start
#region Sponsors
Task<Sponsor?> GetSponsorInfo(NetUserId userId, CancellationToken cancel = default);
Task<Sponsor[]?> GetSponsorList(CancellationToken cancel = default);
#endregion
//ADT-Sponsors-End

#region Job Whitelists

Task AddJobWhitelist(Guid player, ProtoId<JobPrototype> job);
Expand Down Expand Up @@ -969,20 +962,6 @@ private IAsyncEnumerable<T> RunDbCommand<T>(Func<IAsyncEnumerable<T>> command)
return enumerable;
}

//ADT-Sponsors-Start
public async Task<Sponsor?> GetSponsorInfo(NetUserId userId, CancellationToken cancel = default)
{
DbWriteOpsMetric.Inc();
return await _db.GetSponsorInfo(userId);
}

public async Task<Sponsor[]?> GetSponsorList(CancellationToken cancel = default)
{
DbWriteOpsMetric.Inc();
return await _db.GetSponsorList();
}
//ADT-Sponsors-End

private DbContextOptions<PostgresServerDbContext> CreatePostgresOptions()
{
var host = _cfg.GetCVar(CCVars.DatabasePgHost);
Expand Down
2 changes: 2 additions & 0 deletions Content.Shared/Administration/PlayerInfo.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Content.Shared.Corvax.Sponsors;
using Robust.Shared.Network;
using Robust.Shared.Serialization;

Expand All @@ -10,6 +11,7 @@ public sealed record PlayerInfo(
string IdentityName,
string StartingJob,
bool Antag,
SponsorInfo? Sponsor,
NetEntity? NetEntity,
NetUserId SessionId,
bool Connected,
Expand Down
3 changes: 3 additions & 0 deletions Resources/ConfigPresets/Build/debug.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ enabled = false

[shuttle]
auto_call_time = 0

[sponsor]
api_url = "http://5.180.174.139:3080/api"
3 changes: 3 additions & 0 deletions Resources/Locale/en-US/administration/ui/tabs/player-tab.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ player-tab-username = Username
player-tab-character = Character
player-tab-job = Job
player-tab-antagonist = Antagonist
player-tab-sponsor = Sponsor
player-tab-playtime = Playtime
player-tab-show-disconnected = Show Disconnected
player-tab-overlay = Overlay
player-tab-entry-tooltip = Playtime is displayed in days:hours:minutes.
player-tab-filter-line-edit-placeholder = Filter
player-tab-is-antag-yes = YES
player-tab-is-antag-no = NO
player-tab-is-sponsor-yes = YES
player-tab-is-sponsor-no = NO
3 changes: 3 additions & 0 deletions Resources/Locale/ru-RU/administration/ui/tabs/player-tab.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ player-tab-username = Пользователь
player-tab-character = Персонаж
player-tab-job = Должность
player-tab-antagonist = Антагонист
player-tab-sponsor = Спонсор
player-tab-playtime = Игровое время
player-tab-show-disconnected = Показать отключившихся
player-tab-overlay = Оверлей
player-tab-entry-tooltip = Игровое время отображается как дни:часы:минуты.
player-tab-filter-line-edit-placeholder = Фильтр
player-tab-is-antag-yes = ДА
player-tab-is-antag-no = НЕТ
player-tab-is-sponsor-yes = ДА
player-tab-is-sponsor-no = НЕТ
Loading