Skip to content

Commit

Permalink
fix: we did need these
Browse files Browse the repository at this point in the history
  • Loading branch information
ArachisH committed Mar 7, 2024
1 parent 2516441 commit 55a3945
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Tanji.Core/Network/ConnectedEventArgs.cs
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;
}
}
48 changes: 48 additions & 0 deletions Tanji.Core/Network/DataInterceptedEventArgs.cs
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);
}

0 comments on commit 55a3945

Please sign in to comment.