Change Sender to Client in EventArgs

This commit is contained in:
Sardelka
2022-07-29 16:17:33 +08:00
parent 370247eef2
commit 163f342d7a
3 changed files with 12 additions and 12 deletions

View File

@ -72,7 +72,7 @@ namespace RageCoop.Server.Scripting
{ {
Name=cmdName, Name=cmdName,
Args=cmdArgs, Args=cmdArgs,
Sender=sender Client=sender
}; };
OnCommandReceived?.Invoke(this, args); OnCommandReceived?.Invoke(this, args);
if (args.Cancel) if (args.Cancel)
@ -117,7 +117,7 @@ namespace RageCoop.Server.Scripting
internal void InvokeCustomEventReceived(Packets.CustomEvent p, Client sender) internal void InvokeCustomEventReceived(Packets.CustomEvent p, Client sender)
{ {
var args = new CustomEventReceivedArgs() { Hash=p.Hash, Args=p.Args, Sender=sender }; var args = new CustomEventReceivedArgs() { Hash=p.Hash, Args=p.Args, Client=sender };
List<Action<CustomEventReceivedArgs>> handlers; List<Action<CustomEventReceivedArgs>> handlers;
if (CustomEventHandlers.TryGetValue(p.Hash, out handlers)) if (CustomEventHandlers.TryGetValue(p.Hash, out handlers))
{ {

View File

@ -29,7 +29,7 @@ namespace RageCoop.Server.Scripting
{ {
foreach (var c in API.GetAllClients().Values) foreach (var c in API.GetAllClients().Values)
{ {
if (c==e.Sender) if (c==e.Client)
{ {
continue; continue;
} }
@ -39,7 +39,7 @@ namespace RageCoop.Server.Scripting
}); });
API.RegisterCustomEventHandler(CustomEvents.OnPlayerDied, (e) => API.RegisterCustomEventHandler(CustomEvents.OnPlayerDied, (e) =>
{ {
API.SendCustomEventQueued(API.GetAllClients().Values.Where(x=>x!=e.Sender).ToList(),CustomEvents.OnPlayerDied,e.Sender.Username); API.SendCustomEventQueued(API.GetAllClients().Values.Where(x=>x!=e.Client).ToList(),CustomEvents.OnPlayerDied,e.Client.Username);
}); });
} }
public override void OnStop() public override void OnStop()
@ -77,12 +77,12 @@ namespace RageCoop.Server.Scripting
{ {
int id = (int)e.Args[0]; int id = (int)e.Args[0];
Action<object> callback; Action<object> callback;
lock (e.Sender.Callbacks) lock (e.Client.Callbacks)
{ {
if (e.Sender.Callbacks.TryGetValue(id, out callback)) if (e.Client.Callbacks.TryGetValue(id, out callback))
{ {
callback(e.Args[1]); callback(e.Args[1]);
e.Sender.Callbacks.Remove(id); e.Client.Callbacks.Remove(id);
} }
} }
} }

View File

@ -13,7 +13,7 @@ namespace RageCoop.Server.Scripting
public class ChatEventArgs : EventArgs public class ChatEventArgs : EventArgs
{ {
/// <summary> /// <summary>
/// The client that sent this message /// The client that sent this message, will be null if sent from server
/// </summary> /// </summary>
public Client Client { get; set; } public Client Client { get; set; }
/// <summary> /// <summary>
@ -32,9 +32,9 @@ namespace RageCoop.Server.Scripting
public class CustomEventReceivedArgs : EventArgs public class CustomEventReceivedArgs : EventArgs
{ {
/// <summary> /// <summary>
/// The <see cref="Client"/> that triggered this event /// The <see cref="RageCoop.Server.Client"/> that triggered this event
/// </summary> /// </summary>
public Client Sender { get; set; } public Client Client { get; set; }
/// <summary> /// <summary>
/// The event hash /// The event hash
@ -52,9 +52,9 @@ namespace RageCoop.Server.Scripting
public class OnCommandEventArgs : EventArgs public class OnCommandEventArgs : EventArgs
{ {
/// <summary> /// <summary>
/// The <see cref="Client"/> that executed this command. /// The <see cref="RageCoop.Server.Client"/> that executed this command, will be null if sent from server.
/// </summary> /// </summary>
public Client Sender { get; set; } public Client Client { get; set; }
/// <summary> /// <summary>
/// The name of executed command /// The name of executed command
/// </summary> /// </summary>