-
Notifications
You must be signed in to change notification settings - Fork 22
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
2 changed files
with
61 additions
and
0 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,13 @@ | ||
using System.ComponentModel; | ||
|
||
namespace Tanji.Core.Network; | ||
|
||
public sealed class ConnectedEventArgs : CancelEventArgs | ||
{ | ||
public HConnectionContext Context { get; set; } | ||
|
||
public ConnectedEventArgs(HConnectionContext context) | ||
{ | ||
Context = context; | ||
} | ||
} |
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,48 @@ | ||
using Tanji.Core.Habbo; | ||
using Tanji.Core.Habbo.Network.Buffers; | ||
using Tanji.Core.Habbo.Network.Formats; | ||
|
||
namespace Tanji.Core.Network; | ||
|
||
/// <summary> | ||
/// Represents an intercepted message that will be returned to the caller with blocking/replacing information. | ||
/// </summary> | ||
public sealed class DataInterceptedEventArgs : EventArgs | ||
{ | ||
private readonly IHFormat _format; | ||
private readonly Func<Task>? _interceptAsync; | ||
private readonly Func<ReadOnlyMemory<byte>, CancellationToken, ValueTask>? _sendAsync; | ||
|
||
public DateTime Timestamp { get; } | ||
public Task WaitUntil { get; set; } | ||
|
||
public int Step { get; init; } | ||
public HMessage Message { get; init; } | ||
public ReadOnlyMemory<byte> Buffer { get; init; } | ||
|
||
public bool IsBlocked { get; set; } | ||
public bool WasRelayed { get; private set; } | ||
public bool HasContinued { get; private set; } | ||
|
||
public DataInterceptedEventArgs(IHFormat format, Func<Task>? interceptAsync, Func<ReadOnlyMemory<byte>, CancellationToken, ValueTask>? sendAsync) | ||
{ | ||
_format = format; | ||
_sendAsync = sendAsync; | ||
_interceptAsync = interceptAsync; | ||
|
||
Timestamp = DateTime.Now; | ||
} | ||
|
||
public async void Continue(bool relay = false) | ||
{ | ||
if (_interceptAsync == null) return; | ||
|
||
// This method should not be awaited | ||
_ = _interceptAsync(); | ||
if (relay && _sendAsync != null) | ||
{ | ||
await _sendAsync(Buffer, default).ConfigureAwait(false); | ||
} | ||
} | ||
public HPacketReader GetPacket() => new(_format, Buffer.Span); | ||
} |