first commit
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
using NitroxModel.Packets;
|
||||
using NitroxModel.Packets.Processors.Abstract;
|
||||
|
||||
namespace NitroxServer.Communication.Packets.Processors.Abstract
|
||||
{
|
||||
public abstract class AuthenticatedPacketProcessor<T> : PacketProcessor where T : Packet
|
||||
{
|
||||
public override void ProcessPacket(Packet packet, IProcessorContext player)
|
||||
{
|
||||
Process((T)packet, (Player)player);
|
||||
}
|
||||
|
||||
public abstract void Process(T packet, Player player);
|
||||
}
|
||||
}
|
@@ -0,0 +1,49 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NitroxModel.DataStructures;
|
||||
using NitroxModel.DataStructures.GameLogic;
|
||||
using NitroxModel.Packets;
|
||||
using NitroxServer.GameLogic;
|
||||
using NitroxServer.GameLogic.Entities;
|
||||
|
||||
namespace NitroxServer.Communication.Packets.Processors.Abstract;
|
||||
|
||||
public abstract class TransmitIfCanSeePacketProcessor<T> : AuthenticatedPacketProcessor<T> where T : Packet
|
||||
{
|
||||
private readonly PlayerManager playerManager;
|
||||
private readonly EntityRegistry entityRegistry;
|
||||
|
||||
public TransmitIfCanSeePacketProcessor(PlayerManager playerManager, EntityRegistry entityRegistry)
|
||||
{
|
||||
this.playerManager = playerManager;
|
||||
this.entityRegistry = entityRegistry;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Transmits the provided <paramref name="packet"/> to all other players (excluding <paramref name="senderPlayer"/>)
|
||||
/// who can see (<see cref="Player.CanSee"/>) entities corresponding to the provided <paramref name="entityIds"/> only if all those entities are registered.
|
||||
/// </summary>
|
||||
public void TransmitIfCanSeeEntities(Packet packet, Player senderPlayer, List<NitroxId> entityIds)
|
||||
{
|
||||
List<Entity> entities = [];
|
||||
foreach (NitroxId entityId in entityIds)
|
||||
{
|
||||
if (entityRegistry.TryGetEntityById(entityId, out Entity entity))
|
||||
{
|
||||
entities.Add(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (Player player in playerManager.GetConnectedPlayersExcept(senderPlayer))
|
||||
{
|
||||
if (entities.All(player.CanSee))
|
||||
{
|
||||
player.SendPacket(packet);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,15 @@
|
||||
using NitroxModel.Packets;
|
||||
using NitroxModel.Packets.Processors.Abstract;
|
||||
|
||||
namespace NitroxServer.Communication.Packets.Processors.Abstract
|
||||
{
|
||||
public abstract class UnauthenticatedPacketProcessor<T> : PacketProcessor where T : Packet
|
||||
{
|
||||
public override void ProcessPacket(Packet packet, IProcessorContext connection)
|
||||
{
|
||||
Process((T)packet, (INitroxConnection)connection);
|
||||
}
|
||||
|
||||
public abstract void Process(T packet, INitroxConnection connection);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user