Skip to content

Commit

Permalink
Handle dialog open packets that were not initiated client-side
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanmoffat committed Sep 20, 2022
1 parent 5433ead commit c12bd67
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
5 changes: 5 additions & 0 deletions EOLib/Domain/Notifiers/IUserInterfaceNotifier.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
using AutomaticTypeMapper;
using EOLib.Net;
using System.Collections.Generic;

namespace EOLib.Domain.Notifiers
{
public interface IUserInterfaceNotifier
{
void NotifyPacketDialog(PacketFamily packetFamily);

void NotifyMessageDialog(string title, IReadOnlyList<string> messages);
}

[AutoMappedType]
public class NoOpUserInterfaceNotifier : IUserInterfaceNotifier
{
public void NotifyPacketDialog(PacketFamily packetFamily) { }

public void NotifyMessageDialog(string title, IReadOnlyList<string> messages) { }
}
}
11 changes: 9 additions & 2 deletions EOLib/PacketHandlers/Chest/ChestOpenHandler.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
using AutomaticTypeMapper;
using EOLib.Domain.Character;
using EOLib.Domain.Login;
using EOLib.Domain.Map;
using EOLib.Domain.Notifiers;
using EOLib.Net;
using EOLib.Net.Handlers;
using System.Collections.Generic;

namespace EOLib.PacketHandlers.Chest
{
[AutoMappedType]
public class ChestOpenHandler : InGameOnlyPacketHandler
{
private readonly IChestDataRepository _chestDataRepository;
private readonly IEnumerable<IUserInterfaceNotifier> _userInterfaceNotifiers;

public override PacketFamily Family => PacketFamily.Chest;

public override PacketAction Action => PacketAction.Open;

public ChestOpenHandler(IPlayerInfoProvider playerInfoProvider,
IChestDataRepository chestDataRepository)
IChestDataRepository chestDataRepository,
IEnumerable<IUserInterfaceNotifier> userInterfaceNotifiers)
: base(playerInfoProvider)
{
_chestDataRepository = chestDataRepository;
_userInterfaceNotifiers = userInterfaceNotifiers;
}

public override bool HandlePacket(IPacket packet)
Expand All @@ -35,6 +39,9 @@ public override bool HandlePacket(IPacket packet)
while (packet.ReadPosition < packet.Length)
_chestDataRepository.Items.Add(new ChestItem(packet.ReadShort(), packet.ReadThree(), i++));

foreach (var notifier in _userInterfaceNotifiers)
notifier.NotifyPacketDialog(Family);

return true;
}
}
Expand Down
10 changes: 9 additions & 1 deletion EOLib/PacketHandlers/Locker/LockerOpenHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
using EOLib.Domain.Character;
using EOLib.Domain.Login;
using EOLib.Domain.Map;
using EOLib.Domain.Notifiers;
using EOLib.Net;
using EOLib.Net.Handlers;
using System.Collections.Generic;

namespace EOLib.PacketHandlers.Locker
{
Expand All @@ -14,16 +16,19 @@ namespace EOLib.PacketHandlers.Locker
public class LockerOpenHandler : InGameOnlyPacketHandler
{
private readonly ILockerDataRepository _lockerDataRepository;
private readonly IEnumerable<IUserInterfaceNotifier> _userInterfaceNotifiers;

public override PacketFamily Family => PacketFamily.Locker;

public override PacketAction Action => PacketAction.Open;

public LockerOpenHandler(IPlayerInfoProvider playerInfoProvider,
ILockerDataRepository lockerDataRepository)
ILockerDataRepository lockerDataRepository,
IEnumerable<IUserInterfaceNotifier> userInterfaceNotifiers)
: base(playerInfoProvider)
{
_lockerDataRepository = lockerDataRepository;
_userInterfaceNotifiers = userInterfaceNotifiers;
}

public override bool HandlePacket(IPacket packet)
Expand All @@ -37,6 +42,9 @@ public override bool HandlePacket(IPacket packet)
while (packet.ReadPosition < packet.Length)
_lockerDataRepository.Items.Add(new InventoryItem(packet.ReadShort(), packet.ReadThree()));

foreach (var notifier in _userInterfaceNotifiers)
notifier.NotifyPacketDialog(Family);

return true;
}
}
Expand Down
14 changes: 12 additions & 2 deletions EndlessClient/HUD/ServerMessageActions.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
using AutomaticTypeMapper;
using EndlessClient.Dialogs.Actions;
using EOLib.Domain.Notifiers;
using EOLib.Net;
using System.Collections.Generic;

namespace EndlessClient.HUD
{
[AutoMappedType]
public class ServerMessageActions : IUserInterfaceNotifier
public class UserInterfaceActions : IUserInterfaceNotifier
{
private readonly IInGameDialogActions _inGameDialogActions;

public ServerMessageActions(IInGameDialogActions inGameDialogActions)
public UserInterfaceActions(IInGameDialogActions inGameDialogActions)
{
_inGameDialogActions = inGameDialogActions;
}

public void NotifyPacketDialog(PacketFamily packetFamily)
{
switch (packetFamily)
{
case PacketFamily.Locker: _inGameDialogActions.ShowLockerDialog(); break;
case PacketFamily.Chest: _inGameDialogActions.ShowChestDialog(); break;
}
}

public void NotifyMessageDialog(string title, IReadOnlyList<string> messages)
{
_inGameDialogActions.ShowMessageDialog(title, messages);
Expand Down

0 comments on commit c12bd67

Please sign in to comment.