Skip to content

Commit

Permalink
Added per player difficulties and per player modifier packets
Browse files Browse the repository at this point in the history
  • Loading branch information
cubicgraphics committed Apr 1, 2024
1 parent cc72d7c commit 5dd6876
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using BeatTogether.DedicatedServer.Kernel.CommandHandlers;
using BeatTogether.DedicatedServer.Kernel.Configuration;
using BeatTogether.DedicatedServer.Messaging.Packets.MultiplayerSession.MPChatPackets;
using BeatTogether.DedicatedServer.Messaging.Packets.MultiplayerSession.MpCorePackets;

namespace BeatTogether.DedicatedServer.Kernel.Commands.CommandHandlers
{
Expand All @@ -24,6 +25,11 @@ public override void Handle(IPlayer player, SetPerPlayerDifficulties command)
{
Text = "Per player difficulties: " + command.Enabled
}, IgnoranceChannelTypes.Reliable);
_packetDisapatcher.SendToNearbyPlayers(new PerPlayer()
{
PPDEnabled = _Configuration.AllowPerPlayerDifficulties,
PPMEnabled = _Configuration.AllowPerPlayerModifiers,
}, IgnoranceChannelTypes.Reliable);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using BeatTogether.DedicatedServer.Kernel.CommandHandlers;
using BeatTogether.DedicatedServer.Kernel.Configuration;
using BeatTogether.DedicatedServer.Messaging.Packets.MultiplayerSession.MPChatPackets;
using BeatTogether.DedicatedServer.Messaging.Packets.MultiplayerSession.MpCorePackets;
using Microsoft.Extensions.Configuration;

namespace BeatTogether.DedicatedServer.Kernel.Commands.CommandHandlers
{
Expand All @@ -24,6 +26,11 @@ public override void Handle(IPlayer player, SetPerPlayerModifiers command)
{
Text = "Per player modifiers: " + command.Enabled
}, IgnoranceChannelTypes.Reliable);
_packetDisapatcher.SendToNearbyPlayers(new PerPlayer()
{
PPDEnabled = _Configuration.AllowPerPlayerDifficulties,
PPMEnabled = _Configuration.AllowPerPlayerModifiers,
}, IgnoranceChannelTypes.Reliable);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ namespace BeatTogether.DedicatedServer.Kernel.PacketHandlers.MultiplayerSession.
{
class DediPacketSetNewManagerPacketHandler : BasePacketHandler<DediPacketSetNewManagerPacket>
{
public InstanceConfiguration _configuration;
public readonly IPacketDispatcher _packetDispatcher;
public readonly IPlayerRegistry _playerRegistry;
private InstanceConfiguration _configuration;
private readonly IPacketDispatcher _packetDispatcher;
private readonly IPlayerRegistry _playerRegistry;
private readonly ILogger _logger = Log.ForContext<DediPacketSetNewManagerPacketHandler>();

public DediPacketSetNewManagerPacketHandler(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using BeatTogether.DedicatedServer.Ignorance.IgnoranceCore;
using BeatTogether.DedicatedServer.Kernel.Abstractions;
using BeatTogether.DedicatedServer.Kernel.Configuration;
using BeatTogether.DedicatedServer.Messaging.Packets.MultiplayerSession.MpCorePackets;
using Serilog;

namespace BeatTogether.DedicatedServer.Kernel.PacketHandlers.MultiplayerSession.MenuRpc
{
class GetPerPlayerHandler : BasePacketHandler<GetPerPlayer>
{
private InstanceConfiguration _configuration;
private readonly IPacketDispatcher _PacketDispatcher;
private readonly ILogger _logger = Log.ForContext<GetPerPlayerHandler>();

public GetPerPlayerHandler(
IPacketDispatcher PacketDispatcher,
InstanceConfiguration configuration)
{
_PacketDispatcher = PacketDispatcher;
_configuration = configuration;
}

public override void Handle(IPlayer sender, GetPerPlayer packet)
{

_logger.Debug(
$"Handling packet of type '{nameof(GetPerPlayer)}' " +
$"(SenderId={sender.ConnectionId})."
);
_PacketDispatcher.SendToPlayer(sender, new PerPlayer()
{
PPDEnabled = _configuration.AllowPerPlayerDifficulties,
PPMEnabled = _configuration.AllowPerPlayerModifiers,
}, IgnoranceChannelTypes.Reliable);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using BeatTogether.DedicatedServer.Ignorance.IgnoranceCore;
using BeatTogether.DedicatedServer.Kernel.Abstractions;
using BeatTogether.DedicatedServer.Kernel.Configuration;
using BeatTogether.DedicatedServer.Messaging.Packets.MultiplayerSession.MpCorePackets;
using Serilog;

namespace BeatTogether.DedicatedServer.Kernel.PacketHandlers.MultiplayerSession.MenuRpc
{
class PerPlayerHandler : BasePacketHandler<PerPlayer>
{
private InstanceConfiguration _configuration;
private readonly IPacketDispatcher _PacketDispatcher;
private readonly ILogger _logger = Log.ForContext<GetPerPlayerHandler>();

public PerPlayerHandler(
IPacketDispatcher PacketDispatcher,
InstanceConfiguration configuration)
{
_PacketDispatcher = PacketDispatcher;
_configuration = configuration;
}

public override void Handle(IPlayer sender, PerPlayer packet)
{

_logger.Debug(
$"Handling packet of type '{nameof(PerPlayer)}' " +
$"(SenderId={sender.ConnectionId})."
);
if(sender.IsServerOwner)
{
_configuration.AllowPerPlayerDifficulties = packet.PPDEnabled;
_configuration.AllowPerPlayerModifiers = packet.PPMEnabled;
_PacketDispatcher.SendToNearbyPlayers(new PerPlayer()
{
PPDEnabled = _configuration.AllowPerPlayerDifficulties,
PPMEnabled = _configuration.AllowPerPlayerModifiers,
}, IgnoranceChannelTypes.Reliable);
}

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using BeatTogether.DedicatedServer.Messaging.Abstractions;
using BeatTogether.DedicatedServer.Messaging.Util;

namespace BeatTogether.DedicatedServer.Messaging.Packets.MultiplayerSession.MpCorePackets
{
public sealed class GetPerPlayer : INetSerializable
{
public void ReadFrom(ref SpanBuffer bufferReader)
{
}

public void WriteTo(ref SpanBuffer bufferWriter)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using BeatTogether.DedicatedServer.Messaging.Abstractions;
using BeatTogether.DedicatedServer.Messaging.Util;

namespace BeatTogether.DedicatedServer.Messaging.Packets.MultiplayerSession.MpCorePackets
{
public sealed class PerPlayer : INetSerializable
{
public bool PPDEnabled;
public bool PPMEnabled;

public void ReadFrom(ref SpanBuffer bufferReader)
{
PPDEnabled = bufferReader.ReadBool();
PPMEnabled = bufferReader.ReadBool();
}

public void WriteTo(ref SpanBuffer bufferWriter)
{
bufferWriter.WriteBool(PPDEnabled);
bufferWriter.WriteBool(PPMEnabled);
}
}
}

0 comments on commit 5dd6876

Please sign in to comment.