- Added full implementation of lua event "modifyChatMessage" in IEvents.
This commit is contained in:
@@ -3973,8 +3973,20 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
var hookChatMsg = ChatMessage.Create(senderName, message, (ChatMessageType)type, senderCharacter, senderClient, changeType);
|
var hookChatMsg = ChatMessage.Create(senderName, message, (ChatMessageType)type, senderCharacter, senderClient, changeType);
|
||||||
|
|
||||||
var should = LuaCsSetup.Instance.Hook.Call<bool?>("modifyChatMessage", hookChatMsg, senderRadio);
|
bool shouldSkip = false;
|
||||||
|
LuaCsSetup.Instance.EventService.PublishEvent<IEventModifyChatMessage>(sub =>
|
||||||
|
{
|
||||||
|
if (sub.OnModifyMessagePredicate(hookChatMsg, senderRadio) is true)
|
||||||
|
{
|
||||||
|
shouldSkip = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (shouldSkip)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
//check which clients can receive the message and apply distance effects
|
//check which clients can receive the message and apply distance effects
|
||||||
foreach (Client client in ConnectedClients)
|
foreach (Client client in ConnectedClients)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -79,6 +79,39 @@ internal interface IEventSettingInstanceLifetime : IEvent<IEventSettingInstanceL
|
|||||||
|
|
||||||
#region GameEvents
|
#region GameEvents
|
||||||
|
|
||||||
|
#if SERVER
|
||||||
|
/// <summary>
|
||||||
|
/// Allows the user to modify a chat message on the server before it is sent to clients, or reject the message altogether.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>Legacy Lua Event Name: "modifyChatMessage"</remarks>
|
||||||
|
internal interface IEventModifyChatMessage : IEvent<IEventModifyChatMessage>
|
||||||
|
{
|
||||||
|
bool? OnModifyMessagePredicate(ChatMessage message, WifiComponent senderRadio);
|
||||||
|
|
||||||
|
static IEventModifyChatMessage IEvent<IEventModifyChatMessage>.GetLuaRunner(IDictionary<string, LuaCsFunc> luaFunc) =>
|
||||||
|
new LuaWrapper(luaFunc);
|
||||||
|
|
||||||
|
public sealed class LuaWrapper : LuaWrapperBase, IEventModifyChatMessage
|
||||||
|
{
|
||||||
|
public LuaWrapper(IDictionary<string, LuaCsFunc> luaFuncs) : base(luaFuncs)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Called before a chat message is sent to clients.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="message">Message to be sent.</param>
|
||||||
|
/// <param name="senderRadio"><b>[CanBeNull]</b> The source <see cref="ItemComponent"/>, if any.</param>
|
||||||
|
/// <returns>Whether to <b><i>reject</i></b> the message.</returns>
|
||||||
|
public bool? OnModifyMessagePredicate(ChatMessage message, WifiComponent senderRadio)
|
||||||
|
{
|
||||||
|
return (bool?)LuaFuncs[nameof(OnModifyMessagePredicate)](message, senderRadio);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
internal interface IEventAfflictionUpdate : IEvent<IEventAfflictionUpdate>
|
internal interface IEventAfflictionUpdate : IEvent<IEventAfflictionUpdate>
|
||||||
{
|
{
|
||||||
void OnAfflictionUpdate(Affliction affliction, CharacterHealth characterHealth, Limb targetLimb, float deltaTime);
|
void OnAfflictionUpdate(Affliction affliction, CharacterHealth characterHealth, Limb targetLimb, float deltaTime);
|
||||||
|
|||||||
@@ -312,6 +312,7 @@ class LuaScriptManagementService : ILuaScriptManagementService, ILuaDataService,
|
|||||||
// Compatibility
|
// Compatibility
|
||||||
_eventService.RegisterLuaEventAlias<IEventClientConnected>("clientConnected", nameof(IEventClientConnected.OnClientConnected));
|
_eventService.RegisterLuaEventAlias<IEventClientConnected>("clientConnected", nameof(IEventClientConnected.OnClientConnected));
|
||||||
_eventService.RegisterLuaEventAlias<IEventClientDisconnected>("clientDisconnected", nameof(IEventClientDisconnected.OnClientDisconnected));
|
_eventService.RegisterLuaEventAlias<IEventClientDisconnected>("clientDisconnected", nameof(IEventClientDisconnected.OnClientDisconnected));
|
||||||
|
_eventService.RegisterLuaEventAlias<IEventModifyChatMessage>("modifyChatMessage", nameof(IEventModifyChatMessage.OnModifyMessagePredicate));
|
||||||
#elif CLIENT
|
#elif CLIENT
|
||||||
_eventService.RegisterLuaEventAlias<IEventServerRawNetMessageReceived>("netMessageReceived", nameof(IEventServerRawNetMessageReceived.OnReceivedServerNetMessage));
|
_eventService.RegisterLuaEventAlias<IEventServerRawNetMessageReceived>("netMessageReceived", nameof(IEventServerRawNetMessageReceived.OnReceivedServerNetMessage));
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user