@@ -5,6 +5,7 @@ using Content.Server.Administration.Logs;
|
||||
using Content.Server.Administration.Managers;
|
||||
using Content.Server.Administration.Systems;
|
||||
using Content.Server.MoMMI;
|
||||
using Content.Server.Players;
|
||||
using Content.Server.Preferences.Managers;
|
||||
using Content.Server.UtkaIntegration;
|
||||
using Content.Server.White.Sponsors;
|
||||
@@ -13,6 +14,7 @@ using Content.Shared.CCVar;
|
||||
using Content.Shared.Chat;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.Mind;
|
||||
using Content.Shared.White;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.Network;
|
||||
@@ -62,6 +64,7 @@ namespace Content.Server.Chat.Managers
|
||||
private bool _adminOocEnabled = true;
|
||||
|
||||
private readonly Dictionary<NetUserId, ChatUser> _players = new();
|
||||
private Dictionary<NetUserId, string> _lastMessages = new();
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
@@ -201,6 +204,29 @@ namespace Content.Server.Chat.Managers
|
||||
|
||||
_utkaSocketWrapper.SendMessageToAll(asayEventMessage);
|
||||
}
|
||||
|
||||
public bool TrySendNewMessage(ICommonSession session, string newMessage)
|
||||
{
|
||||
if (!_configurationManager.GetCVar(WhiteCVars.ChatAntispam))
|
||||
return true;
|
||||
|
||||
if (_lastMessages.TryGetValue(session.Data.UserId, out var value))
|
||||
{
|
||||
if (value == newMessage)
|
||||
{
|
||||
DispatchServerMessage(session, "Не повторяйте сообщение.");
|
||||
return false;
|
||||
}
|
||||
|
||||
_lastMessages[session.Data.UserId] = newMessage;
|
||||
}
|
||||
else
|
||||
{
|
||||
_lastMessages.Add(session.Data.UserId, newMessage);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
//WD-EDIT
|
||||
|
||||
#endregion
|
||||
@@ -254,6 +280,9 @@ namespace Content.Server.Chat.Managers
|
||||
return;
|
||||
}
|
||||
|
||||
if (!TrySendNewMessage(player, message)) // WD
|
||||
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.Admin))
|
||||
|
||||
@@ -21,7 +21,12 @@ namespace Content.Server.Chat.Managers
|
||||
void TrySendOOCMessage(ICommonSession player, string message, OOCChatType type);
|
||||
|
||||
void SendHookOOC(string sender, string message);
|
||||
void SendHookAdminChat(string sender, string message); // WD-EDIT
|
||||
|
||||
// WD-EDIT
|
||||
void SendHookAdminChat(string sender, string message);
|
||||
bool TrySendNewMessage(ICommonSession session, string newMessage);
|
||||
// WD-EDIT
|
||||
|
||||
void SendAdminAnnouncement(string message);
|
||||
void SendAdminAlert(string message);
|
||||
void SendAdminAlert(EntityUid player, string message);
|
||||
|
||||
@@ -6,6 +6,10 @@ using Content.Server.Chat.Managers;
|
||||
using Content.Server.GameTicking;
|
||||
using Content.Server.Speech.Components;
|
||||
using Content.Server.Speech.EntitySystems;
|
||||
using Content.Server.Ghost.Components;
|
||||
using Content.Server.Players;
|
||||
using Content.Server.Popups;
|
||||
using Content.Server.Speech.Components;
|
||||
using Content.Server.Station.Components;
|
||||
using Content.Server.Station.Systems;
|
||||
using Content.Server.UtkaIntegration;
|
||||
@@ -245,6 +249,10 @@ public sealed partial class ChatSystem : SharedChatSystem
|
||||
if (string.IsNullOrEmpty(message))
|
||||
return;
|
||||
|
||||
if (desiredType != InGameICChatType.Emote && player is not null &&
|
||||
!_chatManager.TrySendNewMessage(player, message)) // WD
|
||||
return;
|
||||
|
||||
// This message may have a radio prefix, and should then be whispered to the resolved radio channel
|
||||
if (checkRadioPrefix)
|
||||
{
|
||||
@@ -302,6 +310,9 @@ public sealed partial class ChatSystem : SharedChatSystem
|
||||
if (!_critLoocEnabled && _mobStateSystem.IsCritical(source))
|
||||
return;
|
||||
|
||||
if (!_chatManager.TrySendNewMessage(player, message)) // WD
|
||||
return;
|
||||
|
||||
switch (sendType)
|
||||
{
|
||||
case InGameOOCChatType.Dead:
|
||||
|
||||
35
Content.Server/White/Commands/AntispamCommand.cs
Normal file
35
Content.Server/White/Commands/AntispamCommand.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using Content.Server.Administration;
|
||||
using Content.Server.Chat.Managers;
|
||||
using Content.Shared.Administration;
|
||||
using Content.Shared.CCVar;
|
||||
using Content.Shared.White;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.Console;
|
||||
|
||||
namespace Content.Server.White.Commands;
|
||||
|
||||
[AdminCommand(AdminFlags.Admin)]
|
||||
public sealed class AntispamCommand : IConsoleCommand
|
||||
{
|
||||
public string Command => "setantispam";
|
||||
public string Description => "Переключает антиспам систему.";
|
||||
public string Help => "setantispam <bool>";
|
||||
|
||||
[Dependency] private readonly IConfigurationManager _cfg = default!;
|
||||
|
||||
public void Execute(IConsoleShell shell, string argStr, string[] args)
|
||||
{
|
||||
if (args.Length != 1 || !bool.TryParse(args[0], out var value))
|
||||
{
|
||||
shell.WriteError($"{args[0]} is not a valid boolean.");
|
||||
return;
|
||||
}
|
||||
|
||||
_cfg.SetCVar(WhiteCVars.ChatAntispam, value);
|
||||
|
||||
var toggle = value ? "включил" : "выключил";
|
||||
var announce = $"{shell.Player?.Name} {toggle} антиспам систему";
|
||||
|
||||
IoCManager.Resolve<IChatManager>().DispatchServerAnnouncement(announce, Color.Red);
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,13 @@ public sealed class WhiteCVars
|
||||
public static readonly CVarDef<bool> ChatSlangFilter =
|
||||
CVarDef.Create("ic.slang_filter", true, CVar.SERVER | CVar.REPLICATED | CVar.ARCHIVE);
|
||||
|
||||
/*
|
||||
* Antispam
|
||||
*/
|
||||
|
||||
public static readonly CVarDef<bool> ChatAntispam =
|
||||
CVarDef.Create("ic.antispam", true, CVar.SERVER | CVar.REPLICATED | CVar.ARCHIVE);
|
||||
|
||||
/*
|
||||
* Sponsors
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user