This repository has been archived by the owner on Mar 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
210 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
using Quasar.Common.Enums; | ||
using Quasar.Common.Messages; | ||
using Quasar.Common.Networking; | ||
using xServer.Core.Networking; | ||
|
||
namespace xServer.Core.Commands | ||
{ | ||
public class ClientStatusHandler : MessageProcessorBase<object> | ||
{ | ||
/// <summary> | ||
/// Represents the method that will handle status updates. | ||
/// </summary> | ||
/// <param name="sender">The message handler which raised the event.</param> | ||
/// <param name="client">The client which updated the status.</param> | ||
/// <param name="statusMessage">The new status.</param> | ||
public delegate void StatusUpdatedEventHandler(object sender, Client client, string statusMessage); | ||
|
||
/// <summary> | ||
/// Represents the method that will handle user status updates. | ||
/// </summary> | ||
/// <param name="sender">The message handler which raised the event.</param> | ||
/// <param name="client">The client which updated the user status.</param> | ||
/// <param name="userStatusMessage">The new user status.</param> | ||
public delegate void UserStatusUpdatedEventHandler(object sender, Client client, UserStatus userStatusMessage); | ||
|
||
/// <summary> | ||
/// Raised when a client updated its status. | ||
/// </summary> | ||
/// <remarks> | ||
/// Handlers registered with this event will be invoked on the | ||
/// <see cref="System.Threading.SynchronizationContext"/> chosen when the instance was constructed. | ||
/// </remarks> | ||
public event StatusUpdatedEventHandler StatusUpdated; | ||
|
||
/// <summary> | ||
/// Raised when a client updated its user status. | ||
/// </summary> | ||
/// <remarks> | ||
/// Handlers registered with this event will be invoked on the | ||
/// <see cref="System.Threading.SynchronizationContext"/> chosen when the instance was constructed. | ||
/// </remarks> | ||
public event UserStatusUpdatedEventHandler UserStatusUpdated; | ||
|
||
/// <summary> | ||
/// Reports an updated status. | ||
/// </summary> | ||
/// <param name="client">The client which updated the status.</param> | ||
/// <param name="statusMessage">The new status.</param> | ||
private void OnStatusUpdated(Client client, string statusMessage) | ||
{ | ||
SynchronizationContext.Post(c => | ||
{ | ||
var handler = StatusUpdated; | ||
handler?.Invoke(this, (Client) c, statusMessage); | ||
}, client); | ||
} | ||
|
||
/// <summary> | ||
/// Reports an updated user status. | ||
/// </summary> | ||
/// <param name="client">The client which updated the user status.</param> | ||
/// <param name="userStatusMessage">The new user status.</param> | ||
private void OnUserStatusUpdated(Client client, UserStatus userStatusMessage) | ||
{ | ||
SynchronizationContext.Post(c => | ||
{ | ||
var handler = UserStatusUpdated; | ||
handler?.Invoke(this, (Client) c, userStatusMessage); | ||
}, client); | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="ClientStatusHandler"/> class. | ||
/// </summary> | ||
public ClientStatusHandler() : base(true) | ||
{ | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override bool CanExecute(IMessage message) => message is SetStatus || message is SetUserStatus; | ||
|
||
/// <inheritdoc /> | ||
public override bool CanExecuteFrom(ISender sender) => true; | ||
|
||
/// <inheritdoc /> | ||
public override void Execute(ISender sender, IMessage message) | ||
{ | ||
switch (message) | ||
{ | ||
case SetStatus status: | ||
Execute((Client) sender, status); | ||
break; | ||
case SetUserStatus userStatus: | ||
Execute((Client) sender, userStatus); | ||
break; | ||
} | ||
} | ||
|
||
private void Execute(Client client, SetStatus message) | ||
{ | ||
OnStatusUpdated(client, message.Message); | ||
} | ||
|
||
private void Execute(Client client, SetUserStatus message) | ||
{ | ||
OnUserStatusUpdated(client, message.Message); | ||
} | ||
|
||
protected override void Dispose(bool disposing) | ||
{ | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.