Allow raising event when sending chat message wth API
This commit is contained in:
parent
f22ecb03f2
commit
370247eef2
@ -99,12 +99,13 @@ namespace RageCoop.Server.Scripting
|
||||
}
|
||||
}
|
||||
|
||||
internal void InvokeOnChatMessage(string msg, Client sender)
|
||||
internal void InvokeOnChatMessage(string msg, Client sender, string clamiedSender=null)
|
||||
{
|
||||
OnChatMessage?.Invoke(this, new ChatEventArgs()
|
||||
{
|
||||
Sender=sender,
|
||||
Message=msg
|
||||
Client=sender,
|
||||
Message=msg,
|
||||
ClaimedSender=clamiedSender
|
||||
});
|
||||
}
|
||||
internal void InvokePlayerConnected(Client client)
|
||||
@ -200,8 +201,11 @@ namespace RageCoop.Server.Scripting
|
||||
/// <param name="targets">The clients to send message, leave it null to send to all clients</param>
|
||||
/// <param name="message">The chat message</param>
|
||||
/// <param name="username">The username which send this message (default = "Server")</param>
|
||||
public void SendChatMessage(string message, List<Client> targets = null, string username = "Server")
|
||||
/// <param name="raiseEvent">Weather to raise the <see cref="ServerEvents.OnChatMessage"/> event defined in <see cref="API.Events"/></param>
|
||||
/// <remarks>When <paramref name="raiseEvent"/> is unspecified and <paramref name="targets"/> is null or unspecified, <paramref name="raiseEvent"/> will be set to true</remarks>
|
||||
public void SendChatMessage(string message, List<Client> targets = null, string username = "Server",bool? raiseEvent=null)
|
||||
{
|
||||
raiseEvent ??= targets==null;
|
||||
try
|
||||
{
|
||||
if (Server.MainNetServer.ConnectionsCount == 0)
|
||||
@ -218,6 +222,10 @@ namespace RageCoop.Server.Scripting
|
||||
{
|
||||
Server.Logger?.Error($">> {e.Message} <<>> {e.Source ?? string.Empty} <<>> {e.StackTrace ?? string.Empty} <<");
|
||||
}
|
||||
if (raiseEvent.Value)
|
||||
{
|
||||
Events.InvokeOnChatMessage(message, null, username);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -15,11 +15,16 @@ namespace RageCoop.Server.Scripting
|
||||
/// <summary>
|
||||
/// The client that sent this message
|
||||
/// </summary>
|
||||
public Client Sender { get; set; }
|
||||
public Client Client { get; set; }
|
||||
/// <summary>
|
||||
/// Message
|
||||
/// </summary>
|
||||
public string Message { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Only used when sending a message via <see cref="API.SendChatMessage(string, List{Client}, string, bool?)"/>
|
||||
/// </summary>
|
||||
public string ClaimedSender { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
|
@ -798,6 +798,7 @@ namespace RageCoop.Server
|
||||
}
|
||||
internal void SendChatMessage(string name, string message, Client target)
|
||||
{
|
||||
if(target == null) { return; }
|
||||
var msg = MainNetServer.CreateMessage();
|
||||
new Packets.ChatMessage()
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user