# Conflicts: # .github/CODEOWNERS # .github/PULL_REQUEST_TEMPLATE.md # Content.Client/Changelog/ChangelogTab.xaml.cs # Content.Client/Chemistry/UI/ChemMasterWindow.xaml # Content.Client/Entry/EntryPoint.cs # Content.Client/GameTicking/Managers/ClientGameTicker.cs # Content.Client/Launcher/LauncherConnectingGui.xaml # Content.Client/Lobby/LobbyState.cs # Content.Client/Lobby/UI/LobbyGui.xaml # Content.Client/Paper/UI/PaperWindow.xaml.cs # Content.Client/StationRecords/GeneralStationRecordConsoleWindow.xaml.cs # Content.Client/Stylesheets/StyleNano.cs # Content.Client/UserInterface/Screens/SeparatedChatGameScreen.xaml # Content.Client/UserInterface/Systems/Ghost/Widgets/GhostGui.xaml.cs # Content.Client/UserInterface/Systems/MenuBar/Widgets/GameTopMenuBar.xaml # Content.IntegrationTests/Tests/Destructible/DestructibleDamageGroupTest.cs # Content.IntegrationTests/Tests/PostMapInitTest.cs # Content.IntegrationTests/Tests/Power/StationPowerTests.cs # Content.Packaging/ServerPackaging.cs # Content.Server/Administration/Systems/AdminVerbSystem.Smites.cs # Content.Server/Administration/Systems/AdminVerbSystem.Tools.cs # Content.Server/Atmos/TileAtmosphere.cs # Content.Server/Bible/BibleSystem.cs # Content.Server/Chat/Systems/ChatSystem.cs # Content.Server/Content.Server.csproj # Content.Server/Discord/DiscordLink/DiscordLink.cs # Content.Server/GameTicking/GameTicker.LobbyBackground.cs # Content.Server/GameTicking/GameTicker.Spawning.cs # Content.Server/Ghost/GhostSystem.cs # Content.Server/Kitchen/Components/MicrowaveComponent.cs # Content.Server/Kitchen/EntitySystems/MicrowaveSystem.cs # Content.Server/Mech/Systems/MechSystem.cs # Content.Server/Medical/CrewMonitoring/CrewMonitoringConsoleSystem.cs # Content.Server/Medical/DefibrillatorSystem.cs # Content.Server/Medical/HealthAnalyzerSystem.cs # Content.Server/Radio/EntitySystems/HeadsetSystem.cs # Content.Server/Remotes/DoorRemoteSystem.cs # Content.Server/RoundEnd/RoundEndSystem.cs # Content.Server/Shuttles/Systems/DockingSystem.Shuttle.cs # Content.Server/Silicons/Borgs/BorgSystem.Transponder.cs # Content.Server/Tips/TipsSystem.cs # Content.Server/Traitor/Uplink/UplinkSystem.cs # Content.Server/Weapons/Ranged/Systems/GunSystem.cs # Content.Server/Zombies/ZombieSystem.Transform.cs # Content.Server/Zombies/ZombieSystem.cs # Content.Shared/Bed/BedSystem.cs # Content.Shared/Blocking/BlockingSystem.User.cs # Content.Shared/Buckle/SharedBuckleSystem.Buckle.cs # Content.Shared/Chat/SharedSuicideSystem.cs # Content.Shared/Chemistry/Components/HyposprayComponent.cs # Content.Shared/Chemistry/EntitySystems/HypospraySystem.cs # Content.Shared/Chemistry/EntitySystems/ScoopableSolutionSystem.cs # Content.Shared/Chemistry/EntitySystems/SolutionTransferSystem.cs # Content.Shared/Chemistry/Events/HyposprayEvents.cs # Content.Shared/Content.Shared.csproj # Content.Shared/Damage/Systems/DamageableSystem.cs # Content.Shared/Friction/TileFrictionController.cs # Content.Shared/GameTicking/SharedGameTicker.cs # Content.Shared/Interaction/InteractHand.cs # Content.Shared/Lock/LockSystem.cs # Content.Shared/Medical/Healing/HealingSystem.cs # Content.Shared/Mobs/Systems/MobStateSystem.Subscribers.cs # Content.Shared/Nutrition/EntitySystems/HungerSystem.cs # Content.Shared/Silicons/StationAi/SharedStationAiSystem.Airlock.cs # Content.Shared/Throwing/ThrowingSystem.cs # Content.Shared/Trigger/Systems/TriggerOnHitscanSystem.cs # Content.Shared/Weapons/Hitscan/Systems/HitscanBasicDamageSystem.cs # Content.Shared/Weapons/Melee/SharedMeleeWeaponSystem.cs # Content.Shared/Weapons/Ranged/Components/BatteryWeaponFireModesComponent.cs # Content.Shared/Weapons/Ranged/Components/HitscanBatteryAmmoProviderComponent.cs # Content.Shared/Weapons/Ranged/Systems/BatteryWeaponFireModesSystem.cs # Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Ballistic.cs # Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Battery.cs # Content.Shared/Zombies/ZombieComponent.cs # Content.Shared/_Sunrise/Lobby/LobbyBackgroundPrototype.cs # README.md # Resources/Locale/en-US/_strings/borg/borg.ftl # Resources/Locale/en-US/_strings/chemistry/components/hypospray-component.ftl # Resources/Locale/en-US/_strings/chemistry/components/injector-component.ftl # Resources/Locale/en-US/_strings/commands/pauseatmos-command.ftl # Resources/Locale/en-US/_strings/commands/quick-inspect-command.ftl # Resources/Locale/en-US/_strings/commands/show-wallmounts-command.ftl # Resources/Locale/en-US/_strings/commands/substepatmos-command.ftl # Resources/Locale/en-US/_strings/fluids/components/equip-spray-component.ftl # Resources/Locale/en-US/_strings/game-ticking/game-presets/preset-revolutionary.ftl # Resources/Locale/en-US/_strings/job/job-names.ftl # Resources/Locale/en-US/_strings/lobby/lobby-state-background.ftl # Resources/Locale/en-US/_strings/reagents/meta/medicine.ftl # Resources/Locale/en-US/_strings/reagents/meta/physical-desc.ftl # Resources/Locale/en-US/_strings/silicons/borg-module.ftl # Resources/Locale/en-US/_strings/store/changeling-catalog.ftl # Resources/Locale/en-US/_strings/store/currency.ftl # Resources/Locale/en-US/_strings/store/store.ftl # Resources/Locale/en-US/_strings/store/uplink-catalog.ftl # Resources/Prototypes/Body/Organs/slime.yml # Resources/Prototypes/Catalog/Fills/Backpacks/backpack.yml # Resources/Prototypes/Catalog/Fills/Backpacks/duffelbag.yml # Resources/Prototypes/Catalog/Fills/Boxes/ammunition.yml # Resources/Prototypes/Catalog/Fills/Boxes/emergency.yml # Resources/Prototypes/Catalog/Fills/Crates/antag.yml # Resources/Prototypes/Catalog/Fills/Crates/armory.yml # Resources/Prototypes/Catalog/Fills/Crates/botany.yml # Resources/Prototypes/Catalog/Fills/Crates/fun.yml # Resources/Prototypes/Catalog/Fills/Crates/medical.yml # Resources/Prototypes/Catalog/Fills/Crates/salvage.yml # Resources/Prototypes/Catalog/Fills/Crates/security.yml # Resources/Prototypes/Catalog/Fills/Crates/service.yml # Resources/Prototypes/Catalog/Fills/Crates/syndicate.yml # Resources/Prototypes/Catalog/Fills/Items/belt.yml # Resources/Prototypes/Catalog/Fills/Items/briefcases.yml # Resources/Prototypes/Catalog/Fills/Items/firstaidkits.yml # Resources/Prototypes/Catalog/Fills/Items/toolboxes.yml # Resources/Prototypes/Catalog/Fills/Lockers/dressers.yml # Resources/Prototypes/Catalog/Fills/Lockers/heads.yml # Resources/Prototypes/Catalog/Fills/Lockers/security.yml # Resources/Prototypes/Catalog/VendingMachines/Inventories/theater.yml # Resources/Prototypes/Catalog/uplink_catalog.yml # Resources/Prototypes/Entities/Clothing/Back/backpacks.yml # Resources/Prototypes/Entities/Clothing/Shoes/magboots.yml # Resources/Prototypes/Entities/Debugging/debug_sweps.yml # Resources/Prototypes/Entities/Debugging/stress_test.yml # Resources/Prototypes/Entities/Markers/Spawners/Random/anomaly.yml # Resources/Prototypes/Entities/Markers/Spawners/Random/toy.yml # Resources/Prototypes/Entities/Mobs/Cyborgs/base_borg_chassis.yml # Resources/Prototypes/Entities/Mobs/Cyborgs/xenoborgs.yml # Resources/Prototypes/Entities/Mobs/NPCs/animals.yml # Resources/Prototypes/Entities/Mobs/NPCs/carp.yml # Resources/Prototypes/Entities/Objects/Devices/base_handheld.yml # Resources/Prototypes/Entities/Objects/Fun/Instruments/instruments_misc.yml # Resources/Prototypes/Entities/Objects/Fun/dice_bag.yml # Resources/Prototypes/Entities/Objects/Fun/snap_pops.yml # Resources/Prototypes/Entities/Objects/Materials/Sheets/other.yml # Resources/Prototypes/Entities/Objects/Materials/parts.yml # Resources/Prototypes/Entities/Objects/Misc/identification_cards.yml # Resources/Prototypes/Entities/Objects/Misc/subdermal_implants.yml # Resources/Prototypes/Entities/Objects/Shields/shields.yml # Resources/Prototypes/Entities/Objects/Specific/Chapel/bibles.yml # Resources/Prototypes/Entities/Objects/Specific/Janitorial/janitor.yml # Resources/Prototypes/Entities/Objects/Specific/Medical/hypospray.yml # Resources/Prototypes/Entities/Objects/Specific/Medical/surgery.yml # Resources/Prototypes/Entities/Objects/Specific/Robotics/borg_modules.yml # Resources/Prototypes/Entities/Objects/Specific/Robotics/mmi.yml # Resources/Prototypes/Entities/Objects/Specific/Service/barber.yml # Resources/Prototypes/Entities/Objects/Tools/glowstick.yml # Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/Boxes/antimateriel.yml # Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/Boxes/magnum.yml # Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/Cartridges/heavy_rifle.yml # Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/Cartridges/light_rifle.yml # Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/Cartridges/magnum.yml # Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/Cartridges/pistol.yml # Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/Cartridges/rifle.yml # Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/Cartridges/shotgun.yml # Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/Magazines/light_rifle.yml # Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/Magazines/magnum.yml # Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/Magazines/pistol.yml # Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/Magazines/rifle.yml # Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/Projectiles/grenade.yml # Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/SpeedLoaders/magnum.yml # Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/SpeedLoaders/pistol.yml # Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/SpeedLoaders/rifle_light.yml # Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/explosives.yml # Resources/Prototypes/Entities/Objects/Weapons/Guns/Battery/battery_guns.yml # Resources/Prototypes/Entities/Objects/Weapons/Guns/LMGs/lmgs.yml # Resources/Prototypes/Entities/Objects/Weapons/Guns/Pistols/pistols.yml # Resources/Prototypes/Entities/Objects/Weapons/Guns/Projectiles/hitscan.yml # Resources/Prototypes/Entities/Objects/Weapons/Guns/Projectiles/projectiles.yml # Resources/Prototypes/Entities/Objects/Weapons/Guns/Rifles/rifles.yml # Resources/Prototypes/Entities/Objects/Weapons/Guns/SMGs/smgs.yml # Resources/Prototypes/Entities/Objects/Weapons/Melee/knife.yml # Resources/Prototypes/Entities/Objects/Weapons/Throwable/grenades.yml # Resources/Prototypes/Entities/Structures/Furniture/dresser.yml # Resources/Prototypes/Entities/Structures/Machines/lathe.yml # Resources/Prototypes/Entities/Structures/Shuttles/cannons.yml # Resources/Prototypes/Entities/Structures/Walls/walls.yml # Resources/Prototypes/GameRules/roundstart.yml # Resources/Prototypes/GameRules/unknown_shuttles.yml # Resources/Prototypes/InventoryTemplates/aghost_inventory_template.yml # Resources/Prototypes/Loadouts/Jobs/Security/security_officer.yml # Resources/Prototypes/Loadouts/loadout_groups.yml # Resources/Prototypes/Loadouts/role_loadouts.yml # Resources/Prototypes/Maps/Pools/default.yml # Resources/Prototypes/Maps/amber.yml # Resources/Prototypes/Maps/oasis.yml # Resources/Prototypes/Maps/reach.yml # Resources/Prototypes/Objectives/objectiveGroups.yml # Resources/Prototypes/Reagents/Consumable/Drink/alcohol.yml # Resources/Prototypes/Reagents/medicine.yml # Resources/Prototypes/Reagents/narcotics.yml # Resources/Prototypes/Reagents/toxins.yml # Resources/Prototypes/Recipes/Reactions/medicine.yml # Resources/Prototypes/Roles/Jobs/Security/head_of_security.yml # Resources/Prototypes/Roles/Jobs/Security/security_cadet.yml # Resources/Prototypes/Roles/Jobs/Security/security_officer.yml # Resources/Prototypes/Roles/Jobs/Security/warden.yml # Resources/Prototypes/Roles/Jobs/Wildcards/zookeeper.yml # Resources/Prototypes/Roles/play_time_trackers.yml # Resources/Prototypes/Shuttles/shuttle_incoming_event.yml # Resources/Prototypes/Species/species_weights.yml # Resources/Prototypes/Store/presets.yml # Resources/Prototypes/ai_factions.yml # Resources/Prototypes/borg_types.yml # Resources/Prototypes/explosion.yml # Resources/Prototypes/game_presets.yml # Resources/Prototypes/lobbyscreens.yml # Resources/Prototypes/silicon-laws.yml # Resources/Textures/Clothing/Back/Duffels/syndicate.rsi/icon-med.png # Resources/Textures/Clothing/Back/Duffels/syndicate.rsi/meta.json # Resources/Textures/Objects/Specific/Mech/mecha.rsi/meta.json # Resources/Textures/Objects/Specific/Mech/mecha.rsi/ripley-broken.png # Resources/Textures/Objects/Specific/Mech/mecha.rsi/ripley-empty.png # Resources/Textures/Objects/Specific/Mech/mecha.rsi/ripley-open.png # Resources/Textures/Objects/Specific/Mech/mecha.rsi/ripley.png # Resources/Textures/Objects/Specific/Mech/ripley_construction.rsi/ripley_chassis.png # Resources/Textures/Objects/Specific/Mech/ripley_construction.rsi/ripley_harness+o.png # Resources/Textures/Objects/Specific/Mech/ripley_construction.rsi/ripley_harness.png # Resources/Textures/Objects/Specific/Medical/hypospray.rsi/meta.json # Resources/Textures/Objects/Specific/Medical/medical.rsi/meta.json # Resources/Textures/Objects/Weapons/Guns/Projectiles/projectiles.rsi/meta.json # Resources/Textures/Objects/Weapons/Guns/Projectiles/projectiles2.rsi/meta.json # Resources/Textures/Structures/Storage/canister.rsi/meta.json # Resources/Textures/Structures/Storage/tanks.rsi/meta.json # Resources/migration.yml # RobustToolbox # SECURITY.md # SpaceStation14.sln
457 lines
19 KiB
C#
457 lines
19 KiB
C#
using System.Diagnostics.CodeAnalysis;
|
|
using System.Linq;
|
|
using System.Runtime.InteropServices;
|
|
using Content.Server.Administration.Logs;
|
|
using Content.Server.Administration.Managers;
|
|
using Content.Server.Administration.Systems;
|
|
using Content.Server.Discord.DiscordLink;
|
|
using Content.Server.Players.RateLimiting;
|
|
using Content.Server.Preferences.Managers;
|
|
using Content.Shared.Administration;
|
|
using Content.Shared.CCVar;
|
|
using Content.Shared.Chat;
|
|
using Content.Shared.Database;
|
|
using Content.Shared.Mind;
|
|
using Content.Shared.Players.RateLimiting;
|
|
using Robust.Server.Player;
|
|
using Robust.Shared.Configuration;
|
|
using Robust.Shared.Network;
|
|
using Robust.Shared.Player;
|
|
using Robust.Shared.Replays;
|
|
using Robust.Shared.Utility;
|
|
using Content.Sunrise.Interfaces.Shared; // Sunrise-Sponsors
|
|
|
|
namespace Content.Server.Chat.Managers;
|
|
|
|
/// <summary>
|
|
/// Dispatches chat messages to clients.
|
|
/// </summary>
|
|
internal sealed partial class ChatManager : IChatManager
|
|
{
|
|
private static readonly Dictionary<string, string> PatronOocColors = new()
|
|
{
|
|
// I had plans for multiple colors and those went nowhere so...
|
|
{ "nuclear_operative", "#aa00ff" },
|
|
{ "syndicate_agent", "#aa00ff" },
|
|
{ "revolutionary", "#aa00ff" }
|
|
};
|
|
|
|
[Dependency] private readonly IReplayRecordingManager _replay = default!;
|
|
[Dependency] private readonly IServerNetManager _netManager = default!;
|
|
[Dependency] private readonly IAdminManager _adminManager = default!;
|
|
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
|
|
[Dependency] private readonly IServerPreferencesManager _preferencesManager = default!;
|
|
[Dependency] private readonly IConfigurationManager _configurationManager = default!;
|
|
[Dependency] private readonly INetConfigurationManager _netConfigManager = default!;
|
|
[Dependency] private readonly IEntityManager _entityManager = default!;
|
|
[Dependency] private readonly PlayerRateLimitManager _rateLimitManager = default!;
|
|
[Dependency] private readonly ISharedPlayerManager _player = default!;
|
|
[Dependency] private readonly DiscordChatLink _discordLink = default!;
|
|
|
|
private ISharedSponsorsManager? _sponsorsManager; // Sunrise-Sponsors
|
|
|
|
/// <summary>
|
|
/// The maximum length a player-sent message can be sent
|
|
/// </summary>
|
|
public int MaxMessageLength => _configurationManager.GetCVar(CCVars.ChatMaxMessageLength);
|
|
|
|
private bool _oocEnabled = true;
|
|
private bool _adminOocEnabled = true;
|
|
|
|
private readonly Dictionary<NetUserId, ChatUser> _players = new();
|
|
|
|
public void Initialize()
|
|
{
|
|
_netManager.RegisterNetMessage<MsgChatMessage>();
|
|
_netManager.RegisterNetMessage<MsgDeleteChatMessagesBy>();
|
|
|
|
_configurationManager.OnValueChanged(CCVars.OocEnabled, OnOocEnabledChanged, true);
|
|
_configurationManager.OnValueChanged(CCVars.AdminOocEnabled, OnAdminOocEnabledChanged, true);
|
|
|
|
RegisterRateLimits();
|
|
|
|
IoCManager.Instance!.TryResolveType(out _sponsorsManager); // Sunrise-Sponsors
|
|
}
|
|
|
|
private void OnOocEnabledChanged(bool val)
|
|
{
|
|
if (_oocEnabled == val) return;
|
|
|
|
_oocEnabled = val;
|
|
DispatchServerAnnouncement(Loc.GetString(val ? "chat-manager-ooc-chat-enabled-message" : "chat-manager-ooc-chat-disabled-message"));
|
|
}
|
|
|
|
private void OnAdminOocEnabledChanged(bool val)
|
|
{
|
|
if (_adminOocEnabled == val) return;
|
|
|
|
_adminOocEnabled = val;
|
|
DispatchServerAnnouncement(Loc.GetString(val ? "chat-manager-admin-ooc-chat-enabled-message" : "chat-manager-admin-ooc-chat-disabled-message"));
|
|
}
|
|
|
|
public void DeleteMessagesBy(NetUserId uid)
|
|
{
|
|
if (!_players.TryGetValue(uid, out var user))
|
|
return;
|
|
|
|
var msg = new MsgDeleteChatMessagesBy { Key = user.Key, Entities = user.Entities };
|
|
_netManager.ServerSendToAll(msg);
|
|
}
|
|
|
|
[return: NotNullIfNotNull(nameof(author))]
|
|
public ChatUser? EnsurePlayer(NetUserId? author)
|
|
{
|
|
if (author == null)
|
|
return null;
|
|
|
|
ref var user = ref CollectionsMarshal.GetValueRefOrAddDefault(_players, author.Value, out var exists);
|
|
if (!exists || user == null)
|
|
user = new ChatUser(_players.Count);
|
|
|
|
return user;
|
|
}
|
|
|
|
#region Server Announcements
|
|
|
|
public void DispatchServerAnnouncement(string message, Color? colorOverride = null)
|
|
{
|
|
var wrappedMessage = Loc.GetString("chat-manager-server-wrap-message", ("message", FormattedMessage.EscapeText(message)));
|
|
ChatMessageToAll(ChatChannel.Server, message, wrappedMessage, EntityUid.Invalid, hideChat: false, recordReplay: true, colorOverride: colorOverride);
|
|
Logger.InfoS("SERVER", message);
|
|
|
|
_adminLogger.Add(LogType.Chat, LogImpact.Low, $"Server announcement: {message}");
|
|
}
|
|
|
|
public void DispatchServerMessage(ICommonSession player, string message, bool suppressLog = false)
|
|
{
|
|
var wrappedMessage = Loc.GetString("chat-manager-server-wrap-message", ("message", FormattedMessage.EscapeText(message)));
|
|
ChatMessageToOne(ChatChannel.Server, message, wrappedMessage, default, false, player.Channel);
|
|
|
|
if (!suppressLog)
|
|
_adminLogger.Add(LogType.Chat, LogImpact.Low, $"Server message to {player:Player}: {message}");
|
|
}
|
|
|
|
public void SendAdminAnnouncement(string message, AdminFlags? flagBlacklist, AdminFlags? flagWhitelist)
|
|
{
|
|
var clients = _adminManager.ActiveAdmins.Where(p =>
|
|
{
|
|
var adminData = _adminManager.GetAdminData(p);
|
|
|
|
DebugTools.AssertNotNull(adminData);
|
|
|
|
if (adminData == null)
|
|
return false;
|
|
|
|
if (flagBlacklist != null && adminData.HasFlag(flagBlacklist.Value))
|
|
return false;
|
|
|
|
return flagWhitelist == null || adminData.HasFlag(flagWhitelist.Value);
|
|
|
|
}).Select(p => p.Channel);
|
|
|
|
var wrappedMessage = Loc.GetString("chat-manager-send-admin-announcement-wrap-message",
|
|
("adminChannelName", Loc.GetString("chat-manager-admin-channel-name")), ("message", FormattedMessage.EscapeText(message)));
|
|
|
|
ChatMessageToMany(ChatChannel.Admin, message, wrappedMessage, default, false, true, clients);
|
|
_adminLogger.Add(LogType.Chat, LogImpact.Low, $"Admin announcement: {message}");
|
|
}
|
|
|
|
public void SendAdminAnnouncementMessage(ICommonSession player, string message, bool suppressLog = true)
|
|
{
|
|
var wrappedMessage = Loc.GetString("chat-manager-send-admin-announcement-wrap-message",
|
|
("adminChannelName", Loc.GetString("chat-manager-admin-channel-name")),
|
|
("message", FormattedMessage.EscapeText(message)));
|
|
ChatMessageToOne(ChatChannel.Admin, message, wrappedMessage, default, false, player.Channel);
|
|
}
|
|
|
|
public void SendAdminAlert(string message)
|
|
{
|
|
var wrappedMessage = Loc.GetString("chat-manager-send-admin-announcement-wrap-message",
|
|
("adminChannelName", Loc.GetString("chat-manager-admin-channel-name")), ("message", FormattedMessage.EscapeText(message)));
|
|
|
|
SendAdminAlertNoFormatOrEscape(wrappedMessage);
|
|
}
|
|
|
|
public void SendAdminAlertNoFormatOrEscape(string message)
|
|
{
|
|
var clients = _adminManager.ActiveAdmins.Select(p => p.Channel);
|
|
|
|
ChatMessageToMany(ChatChannel.AdminAlert, message, message, default, false, true, clients);
|
|
}
|
|
|
|
|
|
public void SendAdminAlert(EntityUid player, string message)
|
|
{
|
|
var mindSystem = _entityManager.System<SharedMindSystem>();
|
|
if (!mindSystem.TryGetMind(player, out var mindId, out var mind))
|
|
{
|
|
SendAdminAlert(message);
|
|
return;
|
|
}
|
|
|
|
var adminSystem = _entityManager.System<AdminSystem>();
|
|
var antag = mind.UserId != null && (adminSystem.GetCachedPlayerInfo(mind.UserId.Value)?.Antag ?? false);
|
|
|
|
// We shouldn't be repeating this but I don't want to touch any more chat code than necessary
|
|
var playerName = mind.UserId is { } userId && _player.TryGetSessionById(userId, out var session)
|
|
? session.Name
|
|
: "Unknown";
|
|
|
|
SendAdminAlert($"{playerName}{(antag ? " (ANTAG)" : "")} {message}");
|
|
}
|
|
|
|
public void SendHookOOC(string sender, string message)
|
|
{
|
|
if (!_oocEnabled && _configurationManager.GetCVar(CCVars.DisablingOOCDisablesRelay))
|
|
{
|
|
return;
|
|
}
|
|
var wrappedMessage = Loc.GetString("chat-manager-send-hook-ooc-wrap-message", ("senderName", sender), ("message", FormattedMessage.EscapeText(message)));
|
|
ChatMessageToAll(ChatChannel.OOC, message, wrappedMessage, source: EntityUid.Invalid, hideChat: false, recordReplay: true);
|
|
_adminLogger.Add(LogType.Chat, LogImpact.Low, $"Hook OOC from {sender}: {message}");
|
|
}
|
|
|
|
public void SendHookAdmin(string sender, string message)
|
|
{
|
|
var clients = _adminManager.ActiveAdmins.Select(p => p.Channel);
|
|
|
|
var wrappedMessage = Loc.GetString("chat-manager-send-hook-admin-wrap-message", ("senderName", sender), ("message", FormattedMessage.EscapeText(message)));
|
|
foreach (var client in clients)
|
|
{
|
|
ChatMessageToOne(
|
|
ChatChannel.AdminChat,
|
|
message,
|
|
wrappedMessage,
|
|
source: EntityUid.Invalid,
|
|
hideChat: false,
|
|
client: client,
|
|
recordReplay: false,
|
|
audioPath: _netConfigManager.GetClientCVar(client, CCVars.AdminChatSoundPath),
|
|
audioVolume: _netConfigManager.GetClientCVar(client, CCVars.AdminChatSoundVolume));
|
|
}
|
|
|
|
_adminLogger.Add(LogType.Chat, LogImpact.Low, $"Hook admin from {sender}: {message}");
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Public OOC Chat API
|
|
|
|
/// <summary>
|
|
/// Called for a player to attempt sending an OOC, out-of-game. message.
|
|
/// </summary>
|
|
/// <param name="player">The player sending the message.</param>
|
|
/// <param name="message">The message.</param>
|
|
/// <param name="type">The type of message.</param>
|
|
public void TrySendOOCMessage(ICommonSession player, string message, OOCChatType type)
|
|
{
|
|
if (HandleRateLimit(player) != RateLimitStatus.Allowed)
|
|
return;
|
|
|
|
// Check if message exceeds the character limit
|
|
if (message.Length > MaxMessageLength)
|
|
{
|
|
DispatchServerMessage(player, Loc.GetString("chat-manager-max-message-length-exceeded-message", ("limit", MaxMessageLength)));
|
|
return;
|
|
}
|
|
|
|
switch (type)
|
|
{
|
|
case OOCChatType.OOC:
|
|
SendOOC(player, message);
|
|
break;
|
|
case OOCChatType.Admin:
|
|
SendAdminChat(player, message);
|
|
break;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Private API
|
|
|
|
private void SendOOC(ICommonSession player, string message)
|
|
{
|
|
if (!_oocEnabled)
|
|
{
|
|
if (_adminManager.IsAdmin(player))
|
|
{
|
|
if (!_adminOocEnabled)
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
|
|
Color? colorOverride = null;
|
|
var wrappedMessage = Loc.GetString("chat-manager-send-ooc-wrap-message", ("playerName",player.Name), ("message", FormattedMessage.EscapeText(message)));
|
|
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))
|
|
{
|
|
wrappedMessage = Loc.GetString("chat-manager-send-ooc-patron-wrap-message", ("patronColor", patronColor),("playerName", player.Name), ("message", FormattedMessage.EscapeText(message)));
|
|
}
|
|
|
|
// Sunrise-start
|
|
if (_sponsorsManager != null && _sponsorsManager.TryGetOocColor(player.UserId, out var oocColor) && _sponsorsManager.TryGetOocTitle(player.UserId, out var sponsorTitle))
|
|
{
|
|
wrappedMessage = Loc.GetString("chat-manager-send-ooc-patron-wrap-message", ("patronColor", oocColor), ("patronTitle", $"\\[{sponsorTitle}\\] "),("playerName", player.Name), ("message", FormattedMessage.EscapeText(message)));
|
|
}
|
|
|
|
var data = _adminManager.GetAdminData(player);
|
|
if (data != null && data.Title != null)
|
|
{
|
|
wrappedMessage = Loc.GetString("chat-manager-send-ooc-admin-wrap-message", ("patronTitle", $"\\[{data.Title}\\] "),("playerName", player.Name), ("message", FormattedMessage.EscapeText(message)));
|
|
}
|
|
// Sunrise-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);
|
|
_adminLogger.Add(LogType.Chat, LogImpact.Low, $"OOC from {player:Player}: {message}");
|
|
}
|
|
|
|
private void SendAdminChat(ICommonSession player, string message)
|
|
{
|
|
if (!_adminManager.IsAdmin(player))
|
|
{
|
|
_adminLogger.Add(LogType.Chat, LogImpact.Extreme, $"{player:Player} attempted to send admin message but was not admin");
|
|
return;
|
|
}
|
|
|
|
var clients = _adminManager.ActiveAdmins.Select(p => p.Channel);
|
|
var wrappedMessage = Loc.GetString("chat-manager-send-admin-chat-wrap-message",
|
|
("adminChannelName", Loc.GetString("chat-manager-admin-channel-name")),
|
|
("playerName", player.Name), ("message", FormattedMessage.EscapeText(message)));
|
|
|
|
foreach (var client in clients)
|
|
{
|
|
var isSource = client != player.Channel;
|
|
ChatMessageToOne(ChatChannel.AdminChat,
|
|
message,
|
|
wrappedMessage,
|
|
default,
|
|
false,
|
|
client,
|
|
audioPath: isSource ? _netConfigManager.GetClientCVar(client, CCVars.AdminChatSoundPath) : default,
|
|
audioVolume: isSource ? _netConfigManager.GetClientCVar(client, CCVars.AdminChatSoundVolume) : default,
|
|
author: player.UserId);
|
|
}
|
|
|
|
_discordLink.SendMessage(message, player.Name, ChatChannel.AdminChat);
|
|
_adminLogger.Add(LogType.Chat, $"Admin chat from {player:Player}: {message}");
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Utility
|
|
|
|
public void ChatMessageToOne(ChatChannel channel, string message, string wrappedMessage, EntityUid source, bool hideChat, INetChannel client, Color? colorOverride = null, bool recordReplay = false, string? audioPath = null, float audioVolume = 0, NetUserId? author = null)
|
|
{
|
|
var user = author == null ? null : EnsurePlayer(author);
|
|
var netSource = _entityManager.GetNetEntity(source);
|
|
user?.AddEntity(netSource);
|
|
|
|
var msg = new ChatMessage(channel, message, wrappedMessage, netSource, user?.Key, hideChat, colorOverride, audioPath, audioVolume);
|
|
_netManager.ServerSendMessage(new MsgChatMessage() { Message = msg }, client);
|
|
|
|
if (!recordReplay)
|
|
return;
|
|
|
|
if ((channel & ChatChannel.AdminRelated) == 0 ||
|
|
_configurationManager.GetCVar(CCVars.ReplayRecordAdminChat))
|
|
{
|
|
_replay.RecordServerMessage(msg);
|
|
}
|
|
}
|
|
|
|
public void ChatMessageToMany(ChatChannel channel, string message, string wrappedMessage, EntityUid source, bool hideChat, bool recordReplay, IEnumerable<INetChannel> clients, Color? colorOverride = null, string? audioPath = null, float audioVolume = 0, NetUserId? author = null)
|
|
=> ChatMessageToMany(channel, message, wrappedMessage, source, hideChat, recordReplay, clients.ToList(), colorOverride, audioPath, audioVolume, author);
|
|
|
|
public void ChatMessageToMany(ChatChannel channel, string message, string wrappedMessage, EntityUid source, bool hideChat, bool recordReplay, List<INetChannel> clients, Color? colorOverride = null, string? audioPath = null, float audioVolume = 0, NetUserId? author = null)
|
|
{
|
|
var user = author == null ? null : EnsurePlayer(author);
|
|
var netSource = _entityManager.GetNetEntity(source);
|
|
user?.AddEntity(netSource);
|
|
|
|
var msg = new ChatMessage(channel, message, wrappedMessage, netSource, user?.Key, hideChat, colorOverride, audioPath, audioVolume);
|
|
_netManager.ServerSendToMany(new MsgChatMessage() { Message = msg }, clients);
|
|
|
|
if (!recordReplay)
|
|
return;
|
|
|
|
if ((channel & ChatChannel.AdminRelated) == 0 ||
|
|
_configurationManager.GetCVar(CCVars.ReplayRecordAdminChat))
|
|
{
|
|
_replay.RecordServerMessage(msg);
|
|
}
|
|
}
|
|
|
|
public void ChatMessageToManyFiltered(Filter filter, ChatChannel channel, string message, string wrappedMessage, EntityUid source,
|
|
bool hideChat, bool recordReplay, Color? colorOverride = null, string? audioPath = null, float audioVolume = 0)
|
|
{
|
|
if (!recordReplay && !filter.Recipients.Any())
|
|
return;
|
|
|
|
var clients = new List<INetChannel>();
|
|
foreach (var recipient in filter.Recipients)
|
|
{
|
|
clients.Add(recipient.Channel);
|
|
}
|
|
|
|
ChatMessageToMany(channel, message, wrappedMessage, source, hideChat, recordReplay, clients, colorOverride, audioPath, audioVolume);
|
|
}
|
|
|
|
public void ChatMessageToAll(ChatChannel channel, string message, string wrappedMessage, EntityUid source, bool hideChat, bool recordReplay, Color? colorOverride = null, string? audioPath = null, float audioVolume = 0, NetUserId? author = null)
|
|
{
|
|
var user = author == null ? null : EnsurePlayer(author);
|
|
var netSource = _entityManager.GetNetEntity(source);
|
|
user?.AddEntity(netSource);
|
|
|
|
var msg = new ChatMessage(channel, message, wrappedMessage, netSource, user?.Key, hideChat, colorOverride, audioPath, audioVolume);
|
|
_netManager.ServerSendToAll(new MsgChatMessage() { Message = msg });
|
|
|
|
if (!recordReplay)
|
|
return;
|
|
|
|
if ((channel & ChatChannel.AdminRelated) == 0 ||
|
|
_configurationManager.GetCVar(CCVars.ReplayRecordAdminChat))
|
|
{
|
|
_replay.RecordServerMessage(msg);
|
|
}
|
|
}
|
|
|
|
public bool MessageCharacterLimit(ICommonSession? player, string message)
|
|
{
|
|
var isOverLength = false;
|
|
|
|
// Non-players don't need to be checked.
|
|
if (player == null)
|
|
return false;
|
|
|
|
// Check if message exceeds the character limit if the sender is a player
|
|
if (message.Length > MaxMessageLength)
|
|
{
|
|
var feedback = Loc.GetString("chat-manager-max-message-length-exceeded-message", ("limit", MaxMessageLength));
|
|
|
|
DispatchServerMessage(player, feedback);
|
|
|
|
isOverLength = true;
|
|
}
|
|
|
|
return isOverLength;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
|
|
public enum OOCChatType : byte
|
|
{
|
|
OOC,
|
|
Admin
|
|
}
|