Add sponsors color (#551)

This commit is contained in:
tau
2026-04-15 16:19:36 +03:00
committed by GitHub
parent 35f8fe5ad1
commit 7713152554
15 changed files with 4791 additions and 16 deletions
@@ -54,7 +54,7 @@ namespace Content.Client.Lobby
public void SelectCharacter(int slot)
{
Preferences = new PlayerPreferences(Preferences.Characters, slot, Preferences.AdminOOCColor, Preferences.ConstructionFavorites);
Preferences = new PlayerPreferences(Preferences.Characters, slot, Preferences.AdminOOCColor, Preferences.ConstructionFavorites/*WL-Changes: Sponsor*/, Preferences.SponsorColor/*WL-Changes: Sponsor*/);
var msg = new MsgSelectCharacter
{
SelectedCharacterIndex = slot
@@ -70,7 +70,7 @@ namespace Content.Client.Lobby
profile.EnsureValid(_playerManager.LocalSession!, collection, sponsorPrototypes);
// Corvax-Sponsors-End
var characters = new Dictionary<int, HumanoidCharacterProfile>(Preferences.Characters) {[slot] = profile};
Preferences = new PlayerPreferences(characters, Preferences.SelectedCharacterIndex, Preferences.AdminOOCColor, Preferences.ConstructionFavorites);
Preferences = new PlayerPreferences(characters, Preferences.SelectedCharacterIndex, Preferences.AdminOOCColor, Preferences.ConstructionFavorites/*WL-Changes: Sponsor*/, Preferences.SponsorColor/*WL-Changes: Sponsor*/);
var msg = new MsgUpdateCharacter
{
Profile = profile,
@@ -93,7 +93,7 @@ namespace Content.Client.Lobby
var l = lowest.Value;
characters.Add(l, profile);
Preferences = new PlayerPreferences(characters, Preferences.SelectedCharacterIndex, Preferences.AdminOOCColor, Preferences.ConstructionFavorites);
Preferences = new PlayerPreferences(characters, Preferences.SelectedCharacterIndex, Preferences.AdminOOCColor, Preferences.ConstructionFavorites/*WL-Changes: Sponsor*/, Preferences.SponsorColor/*WL-Changes: Sponsor*/);
UpdateCharacter(profile, l);
}
@@ -106,7 +106,7 @@ namespace Content.Client.Lobby
public void DeleteCharacter(int slot)
{
var characters = Preferences.Characters.Where(p => p.Key != slot);
Preferences = new PlayerPreferences(characters, Preferences.SelectedCharacterIndex, Preferences.AdminOOCColor, Preferences.ConstructionFavorites);
Preferences = new PlayerPreferences(characters, Preferences.SelectedCharacterIndex, Preferences.AdminOOCColor, Preferences.ConstructionFavorites/*WL-Changes: Sponsor*/, Preferences.SponsorColor/*WL-Changes: Sponsor*/);
var msg = new MsgDeleteCharacter
{
Slot = slot
@@ -116,7 +116,7 @@ namespace Content.Client.Lobby
public void UpdateConstructionFavorites(List<ProtoId<ConstructionPrototype>> favorites)
{
Preferences = new PlayerPreferences(Preferences.Characters, Preferences.SelectedCharacterIndex, Preferences.AdminOOCColor, favorites);
Preferences = new PlayerPreferences(Preferences.Characters, Preferences.SelectedCharacterIndex, Preferences.AdminOOCColor, favorites/*WL-Changes: Sponsor*/, Preferences.SponsorColor/*WL-Changes: Sponsor*/);
var msg = new MsgUpdateConstructionFavorites
{
Favorites = favorites
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,29 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Content.Server.Database.Migrations.Postgres
{
/// <inheritdoc />
public partial class SponsorColor : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "sponsor_color",
table: "preference",
type: "text",
nullable: false,
defaultValue: "");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "sponsor_color",
table: "preference");
}
}
}
@@ -1113,6 +1113,11 @@ namespace Content.Server.Database.Migrations.Postgres
.HasColumnType("integer")
.HasColumnName("selected_character_slot");
b.Property<string>("SponsorColor")
.IsRequired()
.HasColumnType("text")
.HasColumnName("sponsor_color");
b.Property<Guid>("UserId")
.HasColumnType("uuid")
.HasColumnName("user_id");
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,29 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Content.Server.Database.Migrations.Sqlite
{
/// <inheritdoc />
public partial class SponsorColor : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "sponsor_color",
table: "preference",
type: "TEXT",
nullable: false,
defaultValue: "");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "sponsor_color",
table: "preference");
}
}
}
@@ -1046,6 +1046,11 @@ namespace Content.Server.Database.Migrations.Sqlite
.HasColumnType("INTEGER")
.HasColumnName("selected_character_slot");
b.Property<string>("SponsorColor")
.IsRequired()
.HasColumnType("TEXT")
.HasColumnName("sponsor_color");
b.Property<Guid>("UserId")
.HasColumnType("TEXT")
.HasColumnName("user_id");
+3
View File
@@ -377,6 +377,9 @@ namespace Content.Server.Database
public string AdminOOCColor { get; set; } = null!;
public List<string> ConstructionFavorites { get; set; } = new();
public List<Profile> Profiles { get; } = new();
// WL-Changes: Sponsor start
public string SponsorColor { get; set; } = null!;
// WL-Changes: Sponsor end
}
public class Profile
+8 -1
View File
@@ -292,9 +292,9 @@ internal sealed partial class ChatManager : IChatManager
Color? colorOverride = null;
var wrappedMessage = Loc.GetString("chat-manager-send-ooc-wrap-message", ("playerName",player.Name), ("message", FormattedMessage.EscapeText(message)));
var prefs = _preferencesManager.GetPreferences(player.UserId);
if (_adminManager.HasAdminFlag(player, AdminFlags.NameColor))
{
var prefs = _preferencesManager.GetPreferences(player.UserId);
colorOverride = prefs.AdminOOCColor;
}
if ( _netConfigManager.GetClientCVar(player.Channel, CCVars.ShowOocPatronColor) && player.Channel.UserData.PatronTier is { } patron && PatronOocColors.TryGetValue(patron, out var patronColor))
@@ -309,6 +309,13 @@ internal sealed partial class ChatManager : IChatManager
}
// Corvax-Sponsors-End
// WL-Chages: Sponsor start
if (prefs.SponsorColor != Color.Red)
{
wrappedMessage = Loc.GetString("chat-manager-send-ooc-patron-wrap-message", ("patronColor", prefs.SponsorColor),("playerName", player.Name), ("message", FormattedMessage.EscapeText(message)));
}
// WL-Chages: Sponsor 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);
_discordLink.SendMessage(message, player.Name, ChatChannel.OOC);
+17 -1
View File
@@ -217,6 +217,9 @@ namespace Content.Server.Database
SelectedCharacterSlot = 0,
AdminOOCColor = Color.Red.ToHex(),
ConstructionFavorites = [],
//WL-Changes: Sponsor start
SponsorColor = Color.Red.ToHex(),
//WL-Changes: Sponsor end
};
prefs.Profiles.Add(profile);
@@ -238,6 +241,20 @@ namespace Content.Server.Database
await db.DbContext.SaveChangesAsync();
}
//WL-Changes: Sponsor start
public async Task SaveSponsorColorAsync(NetUserId userId, Color color)
{
await using var db = await GetDb();
var prefs = await db.DbContext
.Preference
.Include(p => p.Profiles)
.SingleAsync(p => p.UserId == userId.UserId);
prefs.SponsorColor = color.ToHex();
await db.DbContext.SaveChangesAsync();
}
//WL-Changes: Sponsor start
public async Task SaveAdminOOCColorAsync(NetUserId userId, Color color)
{
await using var db = await GetDb();
@@ -248,7 +265,6 @@ namespace Content.Server.Database
prefs.AdminOOCColor = color.ToHex();
await db.DbContext.SaveChangesAsync();
}
public async Task SaveConstructionFavoritesAsync(NetUserId userId, List<ProtoId<ConstructionPrototype>> constructionFavorites)
@@ -59,6 +59,10 @@ namespace Content.Server.Database
Task SaveAdminOOCColorAsync(NetUserId userId, Color color);
// WL-Changes: Sponsor start
Task SaveSponsorColorAsync(NetUserId userId, Color color);
// WL-Changes: Sponsor end
Task SaveConstructionFavoritesAsync(NetUserId userId, List<ProtoId<ConstructionPrototype>> constructionFavorites);
// Single method for two operations for transaction.
@@ -496,6 +500,14 @@ namespace Content.Server.Database
return RunDbCommand(() => _db.DeleteSlotAndSetSelectedIndex(userId, deleteSlot, newSlot));
}
//WL-Changes: Sponsor start
public Task SaveSponsorColorAsync(NetUserId userId, Color color)
{
DbWriteOpsMetric.Inc();
return RunDbCommand(() => _db.SaveSponsorColorAsync(userId, color));
}
//WL-Changes: Sponsor end
public Task SaveAdminOOCColorAsync(NetUserId userId, Color color)
{
DbWriteOpsMetric.Inc();
@@ -88,7 +88,7 @@ namespace Content.Server.Preferences.Managers
foreach (var favorite in prefs.ConstructionFavorites)
constructionFavorites.Add(new ProtoId<ConstructionPrototype>(favorite));
return new PlayerPreferences(profiles, prefs.SelectedCharacterSlot, Color.FromHex(prefs.AdminOOCColor), constructionFavorites);
return new PlayerPreferences(profiles, prefs.SelectedCharacterSlot, Color.FromHex(prefs.AdminOOCColor), constructionFavorites/*WL-Changes: Sponsor*/, Color.FromHex(prefs.SponsorColor)/*WL-Changes: Sponsor*/);
}
internal HumanoidCharacterProfile ConvertProfiles(Profile profile)
@@ -239,7 +239,7 @@ namespace Content.Server.Preferences.Managers
return;
}
prefsData.Prefs = new PlayerPreferences(curPrefs.Characters, index, curPrefs.AdminOOCColor, curPrefs.ConstructionFavorites);
prefsData.Prefs = new PlayerPreferences(curPrefs.Characters, index, curPrefs.AdminOOCColor, curPrefs.ConstructionFavorites/*WL-Changes: Sponsor*/, curPrefs.SponsorColor/*WL-Changes: Sponsor*/);
if (ShouldStorePrefs(message.MsgChannel.AuthType))
{
@@ -284,7 +284,7 @@ namespace Content.Server.Preferences.Managers
[slot] = profile
};
prefsData.Prefs = new PlayerPreferences(profiles, slot, curPrefs.AdminOOCColor, curPrefs.ConstructionFavorites);
prefsData.Prefs = new PlayerPreferences(profiles, slot, curPrefs.AdminOOCColor, curPrefs.ConstructionFavorites/*WL-Changes: Sponsor*/, curPrefs.SponsorColor/*WL-Changes: Sponsor*/);
if (ShouldStorePrefs(session.Channel.AuthType))
await _db.SaveCharacterSlotAsync(userId, profile, slot);
@@ -299,7 +299,7 @@ namespace Content.Server.Preferences.Managers
}
var curPrefs = prefsData.Prefs!;
prefsData.Prefs = new PlayerPreferences(curPrefs.Characters, curPrefs.SelectedCharacterIndex, curPrefs.AdminOOCColor, favorites);
prefsData.Prefs = new PlayerPreferences(curPrefs.Characters, curPrefs.SelectedCharacterIndex, curPrefs.AdminOOCColor, favorites/*WL-Changes: Sponsor*/, curPrefs.SponsorColor/*WL-Changes: Sponsor*/);
var session = _playerManager.GetSessionById(userId);
if (ShouldStorePrefs(session.Channel.AuthType))
@@ -343,7 +343,7 @@ namespace Content.Server.Preferences.Managers
var arr = new Dictionary<int, HumanoidCharacterProfile>(curPrefs.Characters);
arr.Remove(slot);
prefsData.Prefs = new PlayerPreferences(arr, nextSlot ?? curPrefs.SelectedCharacterIndex, curPrefs.AdminOOCColor, curPrefs.ConstructionFavorites);
prefsData.Prefs = new PlayerPreferences(arr, nextSlot ?? curPrefs.SelectedCharacterIndex, curPrefs.AdminOOCColor, curPrefs.ConstructionFavorites/*WL-Changes: Sponsor*/, curPrefs.SponsorColor/*WL-Changes: Sponsor*/);
if (ShouldStorePrefs(message.MsgChannel.AuthType))
{
@@ -384,7 +384,7 @@ namespace Content.Server.Preferences.Managers
}
var curPrefs = prefsData.Prefs!;
prefsData.Prefs = new PlayerPreferences(curPrefs.Characters, curPrefs.SelectedCharacterIndex, curPrefs.AdminOOCColor, validatedList);
prefsData.Prefs = new PlayerPreferences(curPrefs.Characters, curPrefs.SelectedCharacterIndex, curPrefs.AdminOOCColor, validatedList/*WL-Changes: Sponsor*/, curPrefs.SponsorColor/*WL-Changes: Sponsor*/);
if (ShouldStorePrefs(message.MsgChannel.AuthType))
{
@@ -403,7 +403,7 @@ namespace Content.Server.Preferences.Managers
PrefsLoaded = true,
Prefs = new PlayerPreferences(
new[] { new KeyValuePair<int, HumanoidCharacterProfile>(0, HumanoidCharacterProfile.Random()) },
0, Color.Transparent, [])
0, Color.Transparent, []/*WL-Changes: Sponsor*/, Color.Transparent/*WL-Changes: Sponsor*/)
};
_cachedPlayerPrefs[session.UserId] = prefsData;
@@ -542,7 +542,7 @@ namespace Content.Server.Preferences.Managers
return new PlayerPreferences(prefs.Characters.Select(p =>
{
return new KeyValuePair<int, HumanoidCharacterProfile>(p.Key, p.Value.Validated(session, collection, sponsorPrototypes));// Corvax-Sponsors
}), prefs.SelectedCharacterIndex, prefs.AdminOOCColor, prefs.ConstructionFavorites);
}), prefs.SelectedCharacterIndex, prefs.AdminOOCColor, prefs.ConstructionFavorites/*WL-Changes: Sponsor*/, prefs.SponsorColor/*WL-Changes: Sponsor*/);
}
public IEnumerable<KeyValuePair<NetUserId, HumanoidCharacterProfile>> GetSelectedProfilesForPlayers(
@@ -0,0 +1,49 @@
using Content.Server.Administration;
using Content.Server.Database;
using Content.Server.Preferences.Managers;
using Content.Shared.Administration;
using Content.Shared.Players;
using Robust.Server.Player;
using Robust.Shared.Console;
namespace Content.Server._WL.Administration.Commands
{
[AdminCommand(AdminFlags.NameColor)]
internal sealed class SetSponsorColor: LocalizedCommands
{
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly IServerDbManager _dbManager = default!;
[Dependency] private readonly IServerPreferencesManager _preferenceManager = default!;
public override string Command => "setsponsorcolor";
public override void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length < 2)
{
shell.WriteLine(Loc.GetString("shell-wrong-arguments-number"));
return;
}
if (!_playerManager.TryGetSessionByUsername(args[0], out var session))
{
shell.WriteLine(Loc.GetString("shell-target-player-does-not-exist"));
return;
}
var color = Color.TryFromHex(args[1]);
if (!color.HasValue)
{
shell.WriteError(Loc.GetString("shell-invalid-color-hex"));
return;
}
// Save the DB
_dbManager.SaveSponsorColorAsync(session.UserId, color.Value);
// Update the cached preference
var prefs = _preferenceManager.GetPreferences(session.UserId);
prefs.SponsorColor = color.Value;
}
}
}
@@ -15,12 +15,15 @@ namespace Content.Shared.Preferences
{
private Dictionary<int, HumanoidCharacterProfile> _characters;
public PlayerPreferences(IEnumerable<KeyValuePair<int, HumanoidCharacterProfile>> characters, int selectedCharacterIndex, Color adminOOCColor, List<ProtoId<ConstructionPrototype>> constructionFavorites)
public PlayerPreferences(IEnumerable<KeyValuePair<int, HumanoidCharacterProfile>> characters, int selectedCharacterIndex, Color adminOOCColor, List<ProtoId<ConstructionPrototype>> constructionFavorites, /*WL-Changes: Sponsor*/Color sponsorColor/*WL-Changes: Sponsor*/)
{
_characters = new Dictionary<int, HumanoidCharacterProfile>(characters);
SelectedCharacterIndex = selectedCharacterIndex;
AdminOOCColor = adminOOCColor;
ConstructionFavorites = constructionFavorites;
//WL-Changes: Sponsor start
SponsorColor = sponsorColor;
//WL-Changes: Sponsor end
}
/// <summary>
@@ -45,6 +48,10 @@ namespace Content.Shared.Preferences
public Color AdminOOCColor { get; set; }
//WL-Changes: Sponsor start
public Color SponsorColor { get; set; }
//WL-Changes: Sponsor end
/// <summary>
/// List of favorite items in the construction menu.
/// </summary>
@@ -0,0 +1,2 @@
cmd-setsponsorcolor-desc = Устанавливает спонсорский цвет ника игрока. Цвет должен быть в шестнадцатеричном (HEX) формате, пример: setsponsorcolor tau #c43b23
cmd-setsponsorcolor-help = Использование: setsponsorcolor <ckey> <color>