Skip to content

Commit

Permalink
Merge pull request #195 from ethanmoffat/map_mutate
Browse files Browse the repository at this point in the history
Re-implement map mutate and refactor in-game handling of init packets
  • Loading branch information
ethanmoffat authored May 28, 2022
2 parents 3bc1761 + 3cb7441 commit 2920cd7
Show file tree
Hide file tree
Showing 30 changed files with 443 additions and 352 deletions.
4 changes: 4 additions & 0 deletions EOLib/Domain/Notifiers/IMapChangedNotifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ namespace EOLib.Domain.Notifiers
public interface IMapChangedNotifier
{
void NotifyMapChanged(WarpAnimation warpAnimation, bool differentMapID);

void NotifyMapMutation();
}

[AutoMappedType]
public class NoOpMapChangedNotifier : IMapChangedNotifier
{
public void NotifyMapChanged(WarpAnimation warpAnimation, bool differentMapID) { }

public void NotifyMapMutation() { }
}
}
12 changes: 0 additions & 12 deletions EOLib/Domain/Online/OnlineListData.cs

This file was deleted.

16 changes: 4 additions & 12 deletions EOLib/Domain/Online/OnlinePlayerActions.cs
Original file line number Diff line number Diff line change
@@ -1,36 +1,28 @@
using AutomaticTypeMapper;
using EOLib.Net;
using EOLib.Net.Communication;
using EOLib.Net.Translators;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace EOLib.Domain.Online
{
[AutoMappedType]
public class OnlinePlayerActions : IOnlinePlayerActions
{
private readonly IPacketSendService _packetSendService;
private readonly IPacketTranslator<OnlineListData> _onlineListPacketTranslator;

public OnlinePlayerActions(IPacketSendService packetSendService,
IPacketTranslator<OnlineListData> onlineListPacketTranslator)
public OnlinePlayerActions(IPacketSendService packetSendService)
{
_packetSendService = packetSendService;
_onlineListPacketTranslator = onlineListPacketTranslator;
}

public async Task<IReadOnlyList<OnlinePlayerInfo>> GetOnlinePlayersAsync(bool fullList)
public void RequestOnlinePlayers(bool fullList)
{
var packet = new PacketBuilder(PacketFamily.Players, fullList ? PacketAction.Request : PacketAction.List).Build();
var response = await _packetSendService.SendEncodedPacketAndWaitAsync(packet);

return _onlineListPacketTranslator.TranslatePacket(response).OnlineList;
_packetSendService.SendPacket(packet);
}
}

public interface IOnlinePlayerActions
{
Task<IReadOnlyList<OnlinePlayerInfo>> GetOnlinePlayersAsync(bool fullList);
void RequestOnlinePlayers(bool fullList);
}
}
33 changes: 33 additions & 0 deletions EOLib/Domain/Online/OnlinePlayerRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using AutomaticTypeMapper;
using System.Collections.Generic;

namespace EOLib.Domain.Online
{
public interface IOnlinePlayerRepository : IResettable
{
HashSet<OnlinePlayerInfo> OnlinePlayers { get; }
}

public interface IOnlinePlayerProvider
{
IReadOnlyCollection<OnlinePlayerInfo> OnlinePlayers { get; }
}

[AutoMappedType(IsSingleton = true)]
public class OnlinePlayerRepository : IOnlinePlayerRepository, IOnlinePlayerProvider
{
public HashSet<OnlinePlayerInfo> OnlinePlayers { get; private set; }

IReadOnlyCollection<OnlinePlayerInfo> IOnlinePlayerProvider.OnlinePlayers => OnlinePlayers;

public OnlinePlayerRepository()
{
ResetState();
}

public void ResetState()
{
OnlinePlayers = new HashSet<OnlinePlayerInfo>();
}
}
}
109 changes: 0 additions & 109 deletions EOLib/Net/API/Init.cs

This file was deleted.

8 changes: 0 additions & 8 deletions EOLib/Net/API/PacketAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public PacketAPI(EOClient client)
m_client = client;

//each of these sets up members of the partial PacketAPI class relevant to a particular packet family
_createInitMembers();
_createPartyMembers();
_createNPCMembers();
_createSpellMembers();
Expand All @@ -29,13 +28,6 @@ public PacketAPI(EOClient client)

public void Dispose()
{
Dispose(true);
}

private void Dispose(bool disposing)
{
if (disposing)
_disposeInitMembers();
}
}
}
34 changes: 23 additions & 11 deletions EOLib/Net/Handlers/PacketHandlingActions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using AutomaticTypeMapper;
using EOLib.Domain.Login;
using EOLib.Net.Communication;

namespace EOLib.Net.Handlers
Expand All @@ -8,27 +9,38 @@ public class PacketHandlingActions : IPacketHandlingActions
{
private readonly IPacketQueueProvider _packetQueueProvider;
private readonly IPacketHandlingTypeFinder _packetHandlingTypeFinder;
private readonly IPlayerInfoProvider _playerInfoProvider;

public PacketHandlingActions(IPacketQueueProvider packetQueueProvider,
IPacketHandlingTypeFinder packetHandlingTypeFinder)
IPacketHandlingTypeFinder packetHandlingTypeFinder,
IPlayerInfoProvider playerInfoProvider)
{
_packetQueueProvider = packetQueueProvider;
_packetHandlingTypeFinder = packetHandlingTypeFinder;
_playerInfoProvider = playerInfoProvider;
}

public void EnqueuePacketForHandling(IPacket packet)
{
var handleType = _packetHandlingTypeFinder.FindHandlingType(packet.Family, packet.Action);

switch (handleType)
if (_playerInfoProvider.PlayerIsInGame)
{
// all in-game packets should be handled in-band
_packetQueueProvider.HandleOutOfBandPacketQueue.EnqueuePacketForHandling(packet);
}
else
{
case PacketHandlingType.InBand:
_packetQueueProvider.HandleInBandPacketQueue.EnqueuePacketAndSignalConsumer(packet);
break;
case PacketHandlingType.OutOfBand:
_packetQueueProvider.HandleOutOfBandPacketQueue.EnqueuePacketForHandling(packet);
break;
/*default: don't handle the received packet*/
var handleType = _packetHandlingTypeFinder.FindHandlingType(packet.Family, packet.Action);

switch (handleType)
{
case PacketHandlingType.InBand:
_packetQueueProvider.HandleInBandPacketQueue.EnqueuePacketAndSignalConsumer(packet);
break;
case PacketHandlingType.OutOfBand:
_packetQueueProvider.HandleOutOfBandPacketQueue.EnqueuePacketForHandling(packet);
break;
/*default: don't handle the received packet*/
}
}
}
}
Expand Down
70 changes: 0 additions & 70 deletions EOLib/Net/Translators/OnlineListPacketTranslator.cs

This file was deleted.

36 changes: 36 additions & 0 deletions EOLib/PacketHandlers/Init/BasePlayersListHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using EOLib.Domain.Online;
using EOLib.Domain.Protocol;
using EOLib.Net;

namespace EOLib.PacketHandlers.Init
{
public abstract class BasePlayersListHandler : IInitPacketHandler
{
private readonly IOnlinePlayerRepository _onlinePlayerRepository;

public abstract InitReply Reply { get; }

protected BasePlayersListHandler(IOnlinePlayerRepository onlinePlayerRepository)
{
_onlinePlayerRepository = onlinePlayerRepository;
}

public bool HandlePacket(IPacket packet)
{
var numTotal = packet.ReadShort();

if (packet.ReadByte() != 255)
return false;

_onlinePlayerRepository.OnlinePlayers.Clear();
for (int i = 0; i < numTotal; ++i)
{
_onlinePlayerRepository.OnlinePlayers.Add(GetNextRecord(packet));
}

return true;
}

protected abstract OnlinePlayerInfo GetNextRecord(IPacket packet);
}
}
Loading

0 comments on commit 2920cd7

Please sign in to comment.