mirror of
https://github.com/Impostor/Impostor.git
synced 2026-10-20 01:46:11 +00:00
* Added an RPC packet size anti-cheat * Support PackedGameDataTo * Move packet size check to HazelConnection * Update PacketSizeLimit to 1153 and add anti-cheat docs * Change default to value determined on officials Thanks Niko for doing the research --------- Co-authored-by: miniduikboot <mini@duikbo.at> Co-authored-by: NikoCat233 <139348239+NikoCat233@users.noreply.github.com>
81 lines
2.7 KiB
C#
81 lines
2.7 KiB
C#
using System;
|
|
using System.Net;
|
|
using System.Net.Sockets;
|
|
using System.Threading.Tasks;
|
|
using Impostor.Api.Config;
|
|
using Impostor.Api.Events.Managers;
|
|
using Impostor.Api.Net.Messages.C2S;
|
|
using Impostor.Hazel;
|
|
using Impostor.Hazel.Udp;
|
|
using Impostor.Server.Events.Client;
|
|
using Impostor.Server.Net.Hazel;
|
|
using Impostor.Server.Net.Manager;
|
|
using Microsoft.Extensions.Logging;
|
|
using Microsoft.Extensions.ObjectPool;
|
|
using Microsoft.Extensions.Options;
|
|
|
|
namespace Impostor.Server.Net
|
|
{
|
|
internal class Matchmaker
|
|
{
|
|
private readonly IEventManager _eventManager;
|
|
private readonly ClientManager _clientManager;
|
|
private readonly ObjectPool<MessageReader> _readerPool;
|
|
private readonly ILogger<HazelConnection> _connectionLogger;
|
|
private readonly IOptions<AntiCheatConfig> _antiCheatOptions;
|
|
private UdpConnectionListener? _connection;
|
|
|
|
public Matchmaker(
|
|
IEventManager eventManager,
|
|
ClientManager clientManager,
|
|
ObjectPool<MessageReader> readerPool,
|
|
ILogger<HazelConnection> connectionLogger,
|
|
IOptions<AntiCheatConfig> antiCheatOptions)
|
|
{
|
|
_eventManager = eventManager;
|
|
_clientManager = clientManager;
|
|
_readerPool = readerPool;
|
|
_connectionLogger = connectionLogger;
|
|
_antiCheatOptions = antiCheatOptions;
|
|
}
|
|
|
|
public async ValueTask StartAsync(IPEndPoint ipEndPoint)
|
|
{
|
|
var mode = ipEndPoint.AddressFamily switch
|
|
{
|
|
AddressFamily.InterNetwork => IPMode.IPv4,
|
|
AddressFamily.InterNetworkV6 => IPMode.IPv6,
|
|
_ => throw new InvalidOperationException(),
|
|
};
|
|
|
|
_connection = new UdpConnectionListener(ipEndPoint, _readerPool, mode)
|
|
{
|
|
NewConnection = OnNewConnection,
|
|
};
|
|
|
|
await _connection.StartAsync();
|
|
}
|
|
|
|
public async ValueTask StopAsync()
|
|
{
|
|
if (_connection != null)
|
|
{
|
|
await _connection.DisposeAsync();
|
|
}
|
|
}
|
|
|
|
private async ValueTask OnNewConnection(NewConnectionEventArgs e)
|
|
{
|
|
// Handshake.
|
|
HandshakeC2S.Deserialize(e.HandshakeData, out var clientVersion, out var name, out var language, out var chatMode, out var platformSpecificData);
|
|
|
|
var connection = new HazelConnection(e.Connection, _connectionLogger, _antiCheatOptions);
|
|
|
|
await _eventManager.CallAsync(new ClientConnectionEvent(connection, e.HandshakeData));
|
|
|
|
// Register client
|
|
await _clientManager.RegisterConnectionAsync(connection, name, clientVersion, language, chatMode, platformSpecificData);
|
|
}
|
|
}
|
|
}
|